From 3dc93f0071f529bc54cdd1677206626cabaaa3c7 Mon Sep 17 00:00:00 2001 From: marcel Date: Fri, 12 Nov 2004 04:34:46 +0000 Subject: Fix a braino: the partition size in the PMBR is in sectors, not bytes and 'mediasz' is in bytes. As it so happens, we define 'last' as the sector number of the last sector on the medium which also is the size of the PMBR partition. Therefore, use 'last' instead of 'mediasz'. Submitted by: Dan Markarian --- sbin/gpt/create.c | 10 +++++----- sbin/gpt/migrate.c | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'sbin') diff --git a/sbin/gpt/create.c b/sbin/gpt/create.c index 47c47fd..6591b93 100644 --- a/sbin/gpt/create.c +++ b/sbin/gpt/create.c @@ -63,6 +63,8 @@ create(int fd) struct gpt_ent *ent; unsigned int i; + last = mediasz / secsz - 1LL; + if (map_find(MAP_TYPE_PRI_GPT_HDR) != NULL || map_find(MAP_TYPE_SEC_GPT_HDR) != NULL) { warnx("%s: error: device already contains a GPT", device_name); @@ -92,12 +94,12 @@ create(int fd) mbr->mbr_part[0].part_esect = 0xff; mbr->mbr_part[0].part_ecyl = 0xff; mbr->mbr_part[0].part_start_lo = htole16(1); - if (mediasz > 0xffffffff) { + if (last > 0xffffffff) { mbr->mbr_part[0].part_size_lo = htole16(0xffff); mbr->mbr_part[0].part_size_hi = htole16(0xffff); } else { - mbr->mbr_part[0].part_size_lo = htole16(mediasz); - mbr->mbr_part[0].part_size_hi = htole16(mediasz >> 16); + mbr->mbr_part[0].part_size_lo = htole16(last); + mbr->mbr_part[0].part_size_hi = htole16(last >> 16); } map = map_add(0LL, 1LL, MAP_TYPE_PMBR, mbr); gpt_write(fd, map); @@ -118,8 +120,6 @@ create(int fd) blocks++; /* Don't forget the header itself */ } - last = mediasz / secsz - 1LL; - /* Never cross the median of the device. */ if ((blocks + 1LL) > ((last + 1LL) >> 1)) blocks = ((last + 1LL) >> 1) - 1LL; diff --git a/sbin/gpt/migrate.c b/sbin/gpt/migrate.c index d9f4074..d0f1485 100644 --- a/sbin/gpt/migrate.c +++ b/sbin/gpt/migrate.c @@ -313,12 +313,12 @@ migrate(int fd) mbr->mbr_part[0].part_esect = 0xff; mbr->mbr_part[0].part_ecyl = 0xff; mbr->mbr_part[0].part_start_lo = htole16(1); - if (mediasz > 0xffffffff) { + if (last > 0xffffffff) { mbr->mbr_part[0].part_size_lo = htole16(0xffff); mbr->mbr_part[0].part_size_hi = htole16(0xffff); } else { - mbr->mbr_part[0].part_size_lo = htole16(mediasz); - mbr->mbr_part[0].part_size_hi = htole16(mediasz >> 16); + mbr->mbr_part[0].part_size_lo = htole16(last); + mbr->mbr_part[0].part_size_hi = htole16(last >> 16); } gpt_write(fd, map); } -- cgit v1.1