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>
This commit is contained in:
marcel 2004-11-12 04:34:46 +00:00
parent 1db017cf8c
commit 3dc93f0071
2 changed files with 8 additions and 8 deletions

View File

@ -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;

View File

@ -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);
}