summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2016-01-27 14:20:00 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2016-01-27 14:20:00 +0000
commit3b6ad71d7f02bcaede85a9105c3d7c89b8b9aca8 (patch)
tree42141e5e6ba49bb56a2e075cf6ab4b7f9218cfed /sbin
parent4bfaaf42ae643e13a5ef2037af83095bac63555d (diff)
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.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/pdisk/Makefile6
-rw-r--r--sbin/pdisk/dpme.h8
-rw-r--r--sbin/pdisk/partition_map.c62
-rw-r--r--sbin/pdisk/pdisk.86
-rw-r--r--sbin/pdisk/pdisk.c7
5 files changed, 66 insertions, 23 deletions
diff --git a/sbin/pdisk/Makefile b/sbin/pdisk/Makefile
index 5d0783710c1..16dc18c87e9 100644
--- a/sbin/pdisk/Makefile
+++ b/sbin/pdisk/Makefile
@@ -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
diff --git a/sbin/pdisk/dpme.h b/sbin/pdisk/dpme.h
index e1e946a715e..68771dc6db8 100644
--- a/sbin/pdisk/dpme.h
+++ b/sbin/pdisk/dpme.h
@@ -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 */
diff --git a/sbin/pdisk/partition_map.c b/sbin/pdisk/partition_map.c
index 820ca9960b4..0ba92790ba9 100644
--- a/sbin/pdisk/partition_map.c
+++ b/sbin/pdisk/partition_map.c
@@ -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;
}
diff --git a/sbin/pdisk/pdisk.8 b/sbin/pdisk/pdisk.8
index 26e3188ad44..58fbdb81936 100644
--- a/sbin/pdisk/pdisk.8
+++ b/sbin/pdisk/pdisk.8
@@ -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
diff --git a/sbin/pdisk/pdisk.c b/sbin/pdisk/pdisk.c
index 56927b1aed8..c0d3f462410 100644
--- a/sbin/pdisk/pdisk.c
+++ b/sbin/pdisk/pdisk.c
@@ -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;