mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
Check block 0 signature, physical block size and physical block count when
reading partition map. Check for unmapped physical blocks and overlapping partitions when reading partition map. No need for duplicate checks in validate_map(), so remove validate.c from build and 'v' command from code and docs.
This commit is contained in:
parent
b1512104e5
commit
fd5008378f
@ -1,4 +1,4 @@
|
||||
# $Id: Makefile,v 1.9 2016/01/25 23:43:20 krw Exp $
|
||||
# $Id: Makefile,v 1.10 2016/01/27 14:19:59 krw Exp $
|
||||
|
||||
.if ${MACHINE} == "macppc"
|
||||
PROG= pdisk
|
||||
@ -6,9 +6,7 @@ LDADD= -lutil
|
||||
DPADD= ${LIBUTIL}
|
||||
CFLAGS+=-Wall
|
||||
|
||||
SRCS= dump.c \
|
||||
file_media.c io.c partition_map.c \
|
||||
pdisk.c validate.c
|
||||
SRCS= dump.c file_media.c io.c partition_map.c pdisk.c
|
||||
|
||||
.else
|
||||
NOPROG=yes
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $Id: Makefile,v 1.22 2016/01/25 23:43:20 krw Exp $
|
||||
# $Id: Makefile,v 1.23 2016/01/27 14:19:59 krw Exp $
|
||||
|
||||
.if ${MACHINE} == "macppc"
|
||||
PROG= pdisk
|
||||
@ -6,9 +6,7 @@ LDADD= -lutil
|
||||
DPADD= ${LIBUTIL}
|
||||
CFLAGS+=-Wall
|
||||
|
||||
SRCS= dump.c \
|
||||
file_media.c io.c partition_map.c \
|
||||
pdisk.c validate.c
|
||||
SRCS= dump.c file_media.c io.c partition_map.c pdisk.c
|
||||
|
||||
.else
|
||||
NOPROG=yes
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: dpme.h,v 1.21 2016/01/25 23:43:20 krw Exp $ */
|
||||
/* $OpenBSD: dpme.h,v 1.22 2016/01/27 14:19:59 krw Exp $ */
|
||||
|
||||
/*
|
||||
* dpme.h - Disk Partition Map Entry (dpme)
|
||||
@ -54,9 +54,9 @@ struct ddmap {
|
||||
};
|
||||
|
||||
struct block0 {
|
||||
uint16_t sbSig; /* unique value for SCSI block 0 */
|
||||
uint16_t sbBlkSize; /* block size of device */
|
||||
uint32_t sbBlkCount; /* number of blocks on device */
|
||||
uint16_t sbSig; /* "ER" */
|
||||
uint16_t sbBlkSize; /* physical block size of device */
|
||||
uint32_t sbBlkCount; /* # of physical blocks on device */
|
||||
uint16_t sbDevType; /* device type */
|
||||
uint16_t sbDevId; /* device id */
|
||||
uint32_t sbData; /* not used */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: partition_map.c,v 1.69 2016/01/27 00:03:52 krw Exp $ */
|
||||
/* $OpenBSD: partition_map.c,v 1.70 2016/01/27 14:19:59 krw Exp $ */
|
||||
|
||||
/*
|
||||
* partition_map.c - partition map routines
|
||||
@ -107,9 +107,24 @@ open_partition_map(int fd, char *name, uint64_t mediasz, uint32_t sectorsz)
|
||||
free_partition_map(map);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (read_partition_map(map) == 0)
|
||||
return map;
|
||||
if (map->block0->sbSig == BLOCK0_SIGNATURE &&
|
||||
map->block0->sbBlkSize == sectorsz &&
|
||||
map->block0->sbBlkCount == mediasz) {
|
||||
if (read_partition_map(map) == 0)
|
||||
return map;
|
||||
} else {
|
||||
if (map->block0->sbSig != BLOCK0_SIGNATURE)
|
||||
warnx("Block 0 signature: Expected 0x%04x, "
|
||||
"got 0x%04x", BLOCK0_SIGNATURE,
|
||||
map->block0->sbSig);
|
||||
else if (map->block0->sbBlkSize != sectorsz)
|
||||
warnx("Block 0 sbBlkSize (%u) != sector size (%u)",
|
||||
map->block0->sbBlkSize, sectorsz);
|
||||
else if (map->block0->sbBlkCount != mediasz)
|
||||
warnx("Block 0 sbBlkCount (%u) != media size (%llu)",
|
||||
map->block0->sbBlkCount,
|
||||
(unsigned long long)mediasz);
|
||||
}
|
||||
|
||||
if (!lflag) {
|
||||
my_ungetch('\n');
|
||||
@ -148,9 +163,10 @@ free_partition_map(struct partition_map_header *map)
|
||||
int
|
||||
read_partition_map(struct partition_map_header *map)
|
||||
{
|
||||
struct partition_map *cur;
|
||||
struct dpme *dpme;
|
||||
int ix;
|
||||
uint32_t limit;
|
||||
uint32_t limit, base, next, nextbase;
|
||||
|
||||
limit = 1; /* There has to be at least one, which has actual value. */
|
||||
for (ix = 1; ix <= limit; ix++) {
|
||||
@ -180,11 +196,47 @@ read_partition_map(struct partition_map_header *map)
|
||||
free(dpme);
|
||||
return 1;
|
||||
}
|
||||
if (dpme->dpme_lblock_start >= dpme->dpme_pblocks) {
|
||||
warnx("\tlogical start (%u) >= block count"
|
||||
"count (%u).", dpme->dpme_lblock_start,
|
||||
dpme->dpme_pblocks);
|
||||
free(dpme);
|
||||
return 1;
|
||||
}
|
||||
if (dpme->dpme_lblocks > dpme->dpme_pblocks -
|
||||
dpme->dpme_lblock_start) {
|
||||
warnx("\tlogical blocks (%u) > available blocks (%u).",
|
||||
dpme->dpme_lblocks,
|
||||
dpme->dpme_pblocks - dpme->dpme_lblock_start);
|
||||
free(dpme);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (add_data_to_map(dpme, ix, map) == 0) {
|
||||
free(dpme);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Traverse base_order looking for
|
||||
*
|
||||
* 1) Overlapping partitions
|
||||
* 2) Unmapped space
|
||||
*/
|
||||
for (cur = map->base_order; cur != NULL; cur = cur->next_on_disk) {
|
||||
base = cur->dpme->dpme_pblock_start;
|
||||
next = base + cur->dpme->dpme_pblocks;
|
||||
if (cur->next_on_disk != NULL)
|
||||
nextbase = cur->next_on_disk->dpme->dpme_pblock_start;
|
||||
else
|
||||
nextbase = map->media_size;
|
||||
if (next != nextbase)
|
||||
warnx("Unmapped pblocks: %u -> %u", next, nextbase);
|
||||
if (next > nextbase)
|
||||
warnx("Partition %ld overlaps next partition",
|
||||
cur->disk_address);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
.\" $OpenBSD: pdisk.8,v 1.23 2016/01/22 07:41:14 jmc Exp $
|
||||
.\" $OpenBSD: pdisk.8,v 1.24 2016/01/27 14:19:59 krw Exp $
|
||||
.\"
|
||||
.\" Copyright 1996,1997,1998 by Apple Computer, Inc.
|
||||
.\" All Rights Reserved
|
||||
@ -19,7 +19,7 @@
|
||||
.\" NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
|
||||
.\" WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
.\"
|
||||
.Dd $Mdocdate: January 22 2016 $
|
||||
.Dd $Mdocdate: January 27 2016 $
|
||||
.Dt PDISK 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
@ -95,8 +95,6 @@ reorder an entry in the partition map
|
||||
change the size of the partition map
|
||||
.It Em t
|
||||
change the specified partition's type
|
||||
.It Em v
|
||||
validate the partition map
|
||||
.It Em w
|
||||
write the partition map
|
||||
.El
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: pdisk.c,v 1.72 2016/01/26 23:41:48 krw Exp $ */
|
||||
/* $OpenBSD: pdisk.c,v 1.73 2016/01/27 14:19:59 krw Exp $ */
|
||||
|
||||
/*
|
||||
* pdisk - an editor for Apple format partition tables
|
||||
@ -47,7 +47,6 @@
|
||||
#include "io.h"
|
||||
#include "partition_map.h"
|
||||
#include "dump.h"
|
||||
#include "validate.h"
|
||||
|
||||
int lflag; /* list the device */
|
||||
int rflag; /* open device read Only */
|
||||
@ -170,7 +169,6 @@ edit(struct partition_map_header **mapp)
|
||||
" r reorder an entry in the partition map\n"
|
||||
" s change the size of the partition map\n"
|
||||
" t change the specified partition's type\n"
|
||||
" v validate the partition map\n"
|
||||
" w write the partition map\n");
|
||||
break;
|
||||
case 'P':
|
||||
@ -227,9 +225,6 @@ edit(struct partition_map_header **mapp)
|
||||
case 'f':
|
||||
do_display_entry(map);
|
||||
break;
|
||||
case 'v':
|
||||
validate_map(map);
|
||||
break;
|
||||
default:
|
||||
bad_input("No such command (%c)", command);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user