From: krw Date: Sat, 15 May 2021 22:06:43 +0000 (+0000) Subject: Nuke some Capt. Obvious and soon to be obsolete comments in X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=d24614728b548c2e54e7e14071eb3065687ca982;p=openbsd Nuke some Capt. Obvious and soon to be obsolete comments in GPT_write(). Add local variables prigh and prigp, mirroring altgh and altp, to GPT_write(), eliminating some magic numbers to make clear the relationship between the various primary and alternative GPT lba fields. No intentional functional change. --- diff --git a/sbin/fdisk/gpt.c b/sbin/fdisk/gpt.c index e145bb0457e..f68d2cdea6e 100644 --- a/sbin/fdisk/gpt.c +++ b/sbin/fdisk/gpt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gpt.c,v 1.15 2021/05/15 00:01:21 krw Exp $ */ +/* $OpenBSD: gpt.c,v 1.16 2021/05/15 22:06:43 krw Exp $ */ /* * Copyright (c) 2015 Markus Muller * Copyright (c) 2015 Kenneth R Westerback @@ -388,33 +388,31 @@ GPT_write(void) const int secsize = unit_types[SECTORS].conversion; ssize_t len; off_t off; - uint64_t altgh, altgp; + uint64_t altgh, altgp, prigh, prigp; /* Assume we always write full-size partition table. XXX */ + prigh = GPTSECTOR; + prigp = prigh + 1; altgh = DL_GETDSIZE(&dl) - 1; altgp = DL_GETDSIZE(&dl) - 1 - (sizeof(gp) / secsize); - /* - * Place the new GPT header at the start of sectors 1 and - * DL_GETDSIZE(lp)-1 and write the sectors back. - */ - gh.gh_lba_self = htole64(1); + gh.gh_lba_self = htole64(prigh); gh.gh_lba_alt = htole64(altgh); - gh.gh_part_lba = htole64(2); + gh.gh_part_lba = htole64(prigp); gh.gh_part_csum = crc32((unsigned char *)&gp, sizeof(gp)); gh.gh_csum = 0; gh.gh_csum = crc32((unsigned char *)&gh, letoh32(gh.gh_size)); - secbuf = DISK_readsector(1); + secbuf = DISK_readsector(prigh); if (secbuf == NULL) return (-1); memcpy(secbuf, &gh, sizeof(gh)); - DISK_writesector(secbuf, 1); + DISK_writesector(secbuf, prigh); free(secbuf); gh.gh_lba_self = htole64(altgh); - gh.gh_lba_alt = htole64(1); + gh.gh_lba_alt = htole64(prigh); gh.gh_part_lba = htole64(altgp); gh.gh_csum = 0; gh.gh_csum = crc32((unsigned char *)&gh, letoh32(gh.gh_size)); @@ -428,14 +426,11 @@ GPT_write(void) free(secbuf); /* - * Write partition table after primary header - * (i.e. at sector 1) and before alt header - * (i.e. ending in sector before alt header. * XXX ALWAYS NGPTPARTITIONS! * XXX ASSUME gp is multiple of sector size! */ - off = lseek(disk.fd, secsize * 2, SEEK_SET); - if (off == secsize * 2) + off = lseek(disk.fd, secsize * prigp, SEEK_SET); + if (off == secsize * prigp) len = write(disk.fd, &gp, sizeof(gp)); else len = -1;