summaryrefslogtreecommitdiffstats
path: root/sbin/gpt
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2004-11-12 04:34:46 +0000
committermarcel <marcel@FreeBSD.org>2004-11-12 04:34:46 +0000
commit3dc93f0071f529bc54cdd1677206626cabaaa3c7 (patch)
treef0934159aa703ebdf3c01f9fe2b9a4d7255cea07 /sbin/gpt
parent1db017cf8c8ba08c9818c167cdb032b4658f75cb (diff)
downloadFreeBSD-src-3dc93f0071f529bc54cdd1677206626cabaaa3c7.zip
FreeBSD-src-3dc93f0071f529bc54cdd1677206626cabaaa3c7.tar.gz
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 <markarian at apple dot com>
Diffstat (limited to 'sbin/gpt')
-rw-r--r--sbin/gpt/create.c10
-rw-r--r--sbin/gpt/migrate.c6
2 files changed, 8 insertions, 8 deletions
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);
}
OpenPOWER on IntegriCloud