summaryrefslogtreecommitdiff
path: root/sbin/pdisk
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2016-01-26 02:38:06 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2016-01-26 02:38:06 +0000
commit6997f77706a8c518a9c9cd84e1291b93f2065cc4 (patch)
tree6e171122c0bdc2ab1414d719f216cb2f9f37f250 /sbin/pdisk
parent99bb42d77280db4760f30617bba05483fc8109cf (diff)
Simplify logic of read_partition_map(), junking retries with various sizes
of logical block. Rely on read_dpme() to do the correct thing.
Diffstat (limited to 'sbin/pdisk')
-rw-r--r--sbin/pdisk/partition_map.c83
1 files changed, 27 insertions, 56 deletions
diff --git a/sbin/pdisk/partition_map.c b/sbin/pdisk/partition_map.c
index dd75ec753e8..b79e7ce2941 100644
--- a/sbin/pdisk/partition_map.c
+++ b/sbin/pdisk/partition_map.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: partition_map.c,v 1.64 2016/01/25 23:43:20 krw Exp $ */
+/* $OpenBSD: partition_map.c,v 1.65 2016/01/26 02:38:05 krw Exp $ */
/*
* partition_map.c - partition map routines
@@ -108,7 +108,7 @@ open_partition_map(int fd, char *name, uint64_t mediasz, uint32_t sectorsz)
return NULL;
}
- if (read_partition_map(map) != -1)
+ if (read_partition_map(map) == 0)
return map;
if (!lflag) {
@@ -149,69 +149,40 @@ int
read_partition_map(struct partition_map_header *map)
{
struct dpme *dpme;
- double d;
- int ix, old_logical;
+ int ix;
uint32_t limit;
- dpme = malloc(sizeof(struct dpme));
- if (dpme == NULL) {
- warn("can't allocate memory for disk buffers");
- return -1;
- }
- if (read_dpme(map->fd, 1, dpme) == 0) {
- warnx("Can't read block 1 from '%s'", map->name);
- free(dpme);
- return -1;
- } else if (dpme->dpme_signature != DPME_SIGNATURE) {
- old_logical = map->logical_block;
- map->logical_block = 512;
- while (map->logical_block <= map->physical_block) {
- if (read_dpme(map->fd, 1, dpme) == 0) {
- warnx("Can't read block 1 from '%s'",
- map->name);
- free(dpme);
- return -1;
- } else if (dpme->dpme_signature == DPME_SIGNATURE) {
- d = map->media_size;
- map->media_size = (d * old_logical) /
- map->logical_block;
- break;
- }
- map->logical_block *= 2;
- }
- if (map->logical_block > map->physical_block) {
- warnx("No valid block 1 on '%s'", map->name);
- free(dpme);
- return -1;
- }
- }
- limit = dpme->dpme_map_entries;
- ix = 1;
- while (1) {
- if (add_data_to_map(dpme, ix, map) == 0) {
- free(dpme);
- return -1;
- }
- if (ix >= limit) {
- break;
- } else {
- ix++;
- }
-
+ limit = 1; /* There has to be at least one, which has actual value. */
+ for (ix = 1; ix <= limit; ix++) {
dpme = malloc(sizeof(struct dpme));
if (dpme == NULL) {
- warn("can't allocate memory for disk buffers");
- return -1;
+ warn("can't allocate memory for partition entry");
+ return 1;
}
if (read_dpme(map->fd, ix, dpme) == 0) {
warnx("Can't read block %u from '%s'", ix, map->name);
free(dpme);
- return -1;
- } else if ((dpme->dpme_signature != DPME_SIGNATURE) ||
- (dpme->dpme_map_entries != limit)) {
- warnx("Bad dpme in block %u from '%s'", ix, map->name);
+ return 1;
+ }
+ if (dpme->dpme_signature != DPME_SIGNATURE) {
+ warnx("Invalid signature on block %d. Expected %x, "
+ "got %x", ix, DPME_SIGNATURE,
+ dpme->dpme_signature);
+ free(dpme);
+ return 1;
+ }
+ if (ix == 1)
+ limit = dpme->dpme_map_entries;
+ if (limit != dpme->dpme_map_entries) {
+ warnx("Invalid entry count on block %d. "
+ "Expected %d, got %d", ix, limit,
+ dpme->dpme_map_entries);
+ free(dpme);
+ return 1;
+ }
+ if (add_data_to_map(dpme, ix, map) == 0) {
free(dpme);
- return -1;
+ return 1;
}
}
return 0;