diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2021-07-11 19:43:20 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2021-07-11 19:43:20 +0000 |
commit | 7a6fcbfdd0b32a7fa5a9687874e5cc2001d28cdb (patch) | |
tree | 728d2d2744de9ec2687b2e2aa4e6fd83c520e36b /sbin | |
parent | 0f7b27036c20fef9b9dc50f0bd6d6c4b0f7bdf4b (diff) |
Add 'mbr_' prefix to struct mbr field names.
Change 'offset' to mbr_lba_self and 'reloffset'
to mbr_lba_firstembr to make their use more evident.
Adjust a few parameter names to match.
Change 'part[]' to mbr_prt[] to reflect that it is an
array of struct prt.
No functional change.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/fdisk/cmd.c | 38 | ||||
-rw-r--r-- | sbin/fdisk/fdisk.c | 5 | ||||
-rw-r--r-- | sbin/fdisk/mbr.c | 118 | ||||
-rw-r--r-- | sbin/fdisk/mbr.h | 12 | ||||
-rw-r--r-- | sbin/fdisk/part.c | 8 | ||||
-rw-r--r-- | sbin/fdisk/user.c | 8 |
6 files changed, 96 insertions, 93 deletions
diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index 5ecc2f49413..a548874339e 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.121 2021/07/11 13:51:42 krw Exp $ */ +/* $OpenBSD: cmd.c,v 1.122 2021/07/11 19:43:19 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -66,7 +66,7 @@ Xreinit(char *args, struct mbr *mbr) } MBR_make(&initial_mbr, &dos_mbr); - MBR_parse(&dos_mbr, mbr->offset, mbr->reloffset, mbr); + MBR_parse(&dos_mbr, mbr->mbr_lba_self, mbr->mbr_lba_firstembr, mbr); if (dogpt) { MBR_init_GPT(mbr); @@ -143,9 +143,9 @@ Xswap(char *args, struct mbr *mbr) gp[pt] = gp[pf]; gp[pf] = gg; } else { - pp = mbr->part[pt]; - mbr->part[pt] = mbr->part[pf]; - mbr->part[pf] = pp; + pp = mbr->mbr_prt[pt]; + mbr->mbr_prt[pt] = mbr->mbr_prt[pf]; + mbr->mbr_prt[pf] = pp; } return CMD_DIRTY; @@ -237,7 +237,7 @@ edit(int pn, struct mbr *mbr) struct prt oldpp; struct prt *pp; - pp = &mbr->part[pn]; + pp = &mbr->mbr_prt[pn]; oldpp = *pp; setpid(pn, mbr); @@ -359,7 +359,7 @@ setpid(int pn, struct mbr *mbr) struct prt *pp; int num; - pp = &mbr->part[pn]; + pp = &mbr->mbr_prt[pn]; /* Print out current table entry */ PRT_print(0, NULL, NULL); @@ -401,11 +401,11 @@ Xselect(char *args, struct mbr *mbr) if (pn == -1) return CMD_CONT; - off = mbr->part[pn].bs; + off = mbr->mbr_prt[pn].bs; /* Sanity checks */ - if ((mbr->part[pn].id != DOSPTYP_EXTEND) && - (mbr->part[pn].id != DOSPTYP_EXTENDL)) { + if ((mbr->mbr_prt[pn].id != DOSPTYP_EXTEND) && + (mbr->mbr_prt[pn].id != DOSPTYP_EXTENDL)) { printf("Partition %d is not an extended partition.\n", pn); return CMD_CONT; } @@ -448,7 +448,7 @@ Xwrite(char *args, struct mbr *mbr) int efi, i, n; for (i = 0, n = 0; i < NDOSPART; i++) - if (mbr->part[i].id == 0xA6) + if (mbr->mbr_prt[i].id == 0xA6) n++; if (n >= 2) { warnx("MBR contains more than one OpenBSD partition!"); @@ -458,8 +458,8 @@ Xwrite(char *args, struct mbr *mbr) MBR_make(mbr, &dos_mbr); - printf("Writing MBR at offset %lld.\n", (long long)mbr->offset); - if (MBR_write(mbr->offset, &dos_mbr) == -1) { + printf("Writing MBR at offset %lld.\n", (long long)mbr->mbr_lba_self); + if (MBR_write(mbr->mbr_lba_self, &dos_mbr) == -1) { warn("error writing MBR"); return CMD_CONT; } @@ -476,7 +476,7 @@ Xwrite(char *args, struct mbr *mbr) } /* Refresh in memory copy to reflect what was just written. */ - MBR_parse(&dos_mbr, mbr->offset, mbr->reloffset, mbr); + MBR_parse(&dos_mbr, mbr->mbr_lba_self, mbr->mbr_lba_firstembr, mbr); return CMD_CLEAN; } @@ -525,8 +525,8 @@ int Xupdate(char *args, struct mbr *mbr) { /* Update code */ - memcpy(mbr->code, initial_mbr.code, sizeof(mbr->code)); - mbr->signature = DOSMBR_SIGNATURE; + memcpy(mbr->mbr_code, initial_mbr.mbr_code, sizeof(mbr->mbr_code)); + mbr->mbr_signature = DOSMBR_SIGNATURE; printf("Machine code updated.\n"); return CMD_DIRTY; } @@ -559,7 +559,7 @@ Xflag(char *args, struct mbr *mbr) if (letoh64(gh.gh_sig) == GPTSIGNATURE) gp[pn].gp_attrs = htole64(val); else - mbr->part[pn].flag = val; + mbr->mbr_prt[pn].flag = val; printf("Partition %d flag value set to 0x%llx.\n", pn, val); } else { /* Set active flag */ @@ -573,9 +573,9 @@ Xflag(char *args, struct mbr *mbr) } else { for (i = 0; i < NDOSPART; i++) { if (i == pn) - mbr->part[i].flag = DOSACTIVE; + mbr->mbr_prt[i].flag = DOSACTIVE; else - mbr->part[i].flag = 0x00; + mbr->mbr_prt[i].flag = 0x00; } } printf("Partition %d marked active.\n", pn); diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c index 2c507b3f7f0..66631802887 100644 --- a/sbin/fdisk/fdisk.c +++ b/sbin/fdisk/fdisk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdisk.c,v 1.117 2021/07/11 13:51:42 krw Exp $ */ +/* $OpenBSD: fdisk.c,v 1.118 2021/07/11 19:43:19 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -241,7 +241,8 @@ main(int argc, char *argv[]) "partition table?"; } } else if (u_flag) { - memcpy(initial_mbr.part, mbr.part, sizeof(initial_mbr.part)); + memcpy(initial_mbr.mbr_prt, mbr.mbr_prt, + sizeof(initial_mbr.mbr_prt)); query = "Do you wish to write new MBR?"; } if (query && ask_yn(query)) diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c index aba1a3c740e..37246b444d6 100644 --- a/sbin/fdisk/mbr.c +++ b/sbin/fdisk/mbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.c,v 1.80 2021/07/11 13:38:27 krw Exp $ */ +/* $OpenBSD: mbr.c,v 1.81 2021/07/11 19:43:19 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -42,11 +42,11 @@ MBR_protective_mbr(struct mbr *mbr) struct dos_partition dp[NDOSPART], dos_partition; int i; - if (mbr->offset != 0) + if (mbr->mbr_lba_self != 0) return -1; for (i = 0; i < NDOSPART; i++) { - PRT_make(&mbr->part[i], mbr->offset, mbr->reloffset, + PRT_make(&mbr->mbr_prt[i], mbr->mbr_lba_self, mbr->mbr_lba_firstembr, &dos_partition); memcpy(&dp[i], &dos_partition, sizeof(dp[i])); } @@ -57,7 +57,7 @@ MBR_protective_mbr(struct mbr *mbr) void MBR_init_GPT(struct mbr *mbr) { - memset(&mbr->part, 0, sizeof(mbr->part)); + memset(&mbr->mbr_prt, 0, sizeof(mbr->mbr_prt)); /* Use whole disk, starting after MBR. * @@ -66,12 +66,12 @@ MBR_init_GPT(struct mbr *mbr) * about the size of the disk, thus making it impossible to boot * such devices. */ - mbr->part[0].id = DOSPTYP_EFI; - mbr->part[0].bs = 1; - mbr->part[0].ns = UINT32_MAX; + mbr->mbr_prt[0].id = DOSPTYP_EFI; + mbr->mbr_prt[0].bs = 1; + mbr->mbr_prt[0].ns = UINT32_MAX; /* Fix up start/length fields. */ - PRT_fix_CHS(&mbr->part[0]); + PRT_fix_CHS(&mbr->mbr_prt[0]); } void @@ -90,87 +90,89 @@ MBR_init(struct mbr *mbr) * from disk!! Just mark them inactive until -b goodness spreads * further. */ - mbr->part[0].flag = 0; - mbr->part[1].flag = 0; - mbr->part[2].flag = 0; + mbr->mbr_prt[0].flag = 0; + mbr->mbr_prt[1].flag = 0; + mbr->mbr_prt[2].flag = 0; - mbr->part[3].flag = DOSACTIVE; - mbr->signature = DOSMBR_SIGNATURE; + mbr->mbr_prt[3].flag = DOSACTIVE; + mbr->mbr_signature = DOSMBR_SIGNATURE; /* Use whole disk. Reserve first track, or first cyl, if possible. */ - mbr->part[3].id = DOSPTYP_OPENBSD; + mbr->mbr_prt[3].id = DOSPTYP_OPENBSD; if (disk.heads > 1) - mbr->part[3].shead = 1; + mbr->mbr_prt[3].shead = 1; else - mbr->part[3].shead = 0; + mbr->mbr_prt[3].shead = 0; if (disk.heads < 2 && disk.cylinders > 1) - mbr->part[3].scyl = 1; + mbr->mbr_prt[3].scyl = 1; else - mbr->part[3].scyl = 0; - mbr->part[3].ssect = 1; + mbr->mbr_prt[3].scyl = 0; + mbr->mbr_prt[3].ssect = 1; /* Go right to the end */ - mbr->part[3].ecyl = disk.cylinders - 1; - mbr->part[3].ehead = disk.heads - 1; - mbr->part[3].esect = disk.sectors; + mbr->mbr_prt[3].ecyl = disk.cylinders - 1; + mbr->mbr_prt[3].ehead = disk.heads - 1; + mbr->mbr_prt[3].esect = disk.sectors; /* Fix up start/length fields */ - PRT_fix_BN(&mbr->part[3], 3); + PRT_fix_BN(&mbr->mbr_prt[3], 3); #if defined(__powerpc__) || defined(__mips__) /* Now fix up for the MS-DOS boot partition on PowerPC. */ - mbr->part[0].flag = DOSACTIVE; /* Boot from dos part */ - mbr->part[3].flag = 0; - mbr->part[3].ns += mbr->part[3].bs; - mbr->part[3].bs = mbr->part[0].bs + mbr->part[0].ns; - mbr->part[3].ns -= mbr->part[3].bs; - PRT_fix_CHS(&mbr->part[3]); - if ((mbr->part[3].shead != 1) || (mbr->part[3].ssect != 1)) { + mbr->mbr_prt[0].flag = DOSACTIVE; /* Boot from dos part */ + mbr->mbr_prt[3].flag = 0; + mbr->mbr_prt[3].ns += mbr->mbr_prt[3].bs; + mbr->mbr_prt[3].bs = mbr->mbr_prt[0].bs + mbr->mbr_prt[0].ns; + mbr->mbr_prt[3].ns -= mbr->mbr_prt[3].bs; + PRT_fix_CHS(&mbr->mbr_prt[3]); + if ((mbr->mbr_prt[3].shead != 1) || (mbr->mbr_prt[3].ssect != 1)) { /* align the partition on a cylinder boundary */ - mbr->part[3].shead = 0; - mbr->part[3].ssect = 1; - mbr->part[3].scyl += 1; + mbr->mbr_prt[3].shead = 0; + mbr->mbr_prt[3].ssect = 1; + mbr->mbr_prt[3].scyl += 1; } /* Fix up start/length fields */ - PRT_fix_BN(&mbr->part[3], 3); + PRT_fix_BN(&mbr->mbr_prt[3], 3); #else if (b_sectors > 0) { - mbr->part[0].id = b_type; - mbr->part[0].bs = b_offset; - mbr->part[0].ns = b_sectors; - PRT_fix_CHS(&mbr->part[0]); - mbr->part[3].ns += mbr->part[3].bs; - mbr->part[3].bs = mbr->part[0].bs + mbr->part[0].ns; - mbr->part[3].ns -= mbr->part[3].bs; - PRT_fix_CHS(&mbr->part[3]); + mbr->mbr_prt[0].id = b_type; + mbr->mbr_prt[0].bs = b_offset; + mbr->mbr_prt[0].ns = b_sectors; + PRT_fix_CHS(&mbr->mbr_prt[0]); + mbr->mbr_prt[3].ns += mbr->mbr_prt[3].bs; + mbr->mbr_prt[3].bs = mbr->mbr_prt[0].bs + mbr->mbr_prt[0].ns; + mbr->mbr_prt[3].ns -= mbr->mbr_prt[3].bs; + PRT_fix_CHS(&mbr->mbr_prt[3]); } #endif /* Start OpenBSD MBR partition on a power of 2 block number. */ daddr = 1; - while (daddr < DL_SECTOBLK(&dl, mbr->part[3].bs)) + while (daddr < DL_SECTOBLK(&dl, mbr->mbr_prt[3].bs)) daddr *= 2; - adj = DL_BLKTOSEC(&dl, daddr) - mbr->part[3].bs; - mbr->part[3].bs += adj; - mbr->part[3].ns -= adj; - PRT_fix_CHS(&mbr->part[3]); + adj = DL_BLKTOSEC(&dl, daddr) - mbr->mbr_prt[3].bs; + mbr->mbr_prt[3].bs += adj; + mbr->mbr_prt[3].ns -= adj; + PRT_fix_CHS(&mbr->mbr_prt[3]); } void -MBR_parse(struct dos_mbr *dos_mbr, off_t offset, off_t reloff, struct mbr *mbr) +MBR_parse(struct dos_mbr *dos_mbr, off_t lba_self, off_t lba_firstembr, + struct mbr *mbr) { struct dos_partition dos_parts[NDOSPART]; int i; - memcpy(mbr->code, dos_mbr->dmbr_boot, sizeof(mbr->code)); - mbr->offset = offset; - mbr->reloffset = reloff; - mbr->signature = letoh16(dos_mbr->dmbr_sign); + memcpy(mbr->mbr_code, dos_mbr->dmbr_boot, sizeof(mbr->mbr_code)); + mbr->mbr_lba_self = lba_self; + mbr->mbr_lba_firstembr = lba_firstembr; + mbr->mbr_signature = letoh16(dos_mbr->dmbr_sign); memcpy(dos_parts, dos_mbr->dmbr_parts, sizeof(dos_parts)); for (i = 0; i < NDOSPART; i++) - PRT_parse(&dos_parts[i], offset, reloff, &mbr->part[i]); + PRT_parse(&dos_parts[i], lba_self, lba_firstembr, + &mbr->mbr_prt[i]); } void @@ -179,11 +181,11 @@ MBR_make(struct mbr *mbr, struct dos_mbr *dos_mbr) struct dos_partition dos_partition; int i; - memcpy(dos_mbr->dmbr_boot, mbr->code, sizeof(dos_mbr->dmbr_boot)); + memcpy(dos_mbr->dmbr_boot, mbr->mbr_code, sizeof(dos_mbr->dmbr_boot)); dos_mbr->dmbr_sign = htole16(DOSMBR_SIGNATURE); for (i = 0; i < NDOSPART; i++) { - PRT_make(&mbr->part[i], mbr->offset, mbr->reloffset, + PRT_make(&mbr->mbr_prt[i], mbr->mbr_lba_self, mbr->mbr_lba_firstembr, &dos_partition); memcpy(&dos_mbr->dmbr_parts[i], &dos_partition, sizeof(dos_mbr->dmbr_parts[i])); @@ -198,13 +200,13 @@ MBR_print(struct mbr *mbr, char *units) DISK_printgeometry(NULL); /* Header */ - printf("Offset: %lld\t", (long long)mbr->offset); - printf("Signature: 0x%X\n", (int)mbr->signature); + printf("Offset: %lld\t", (long long)mbr->mbr_lba_self); + printf("Signature: 0x%X\n", (int)mbr->mbr_signature); PRT_print(0, NULL, units); /* Entries */ for (i = 0; i < NDOSPART; i++) - PRT_print(i, &mbr->part[i], units); + PRT_print(i, &mbr->mbr_prt[i], units); } int diff --git a/sbin/fdisk/mbr.h b/sbin/fdisk/mbr.h index 42fd39f4f98..7fb39efc05a 100644 --- a/sbin/fdisk/mbr.h +++ b/sbin/fdisk/mbr.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.h,v 1.32 2021/07/11 13:23:18 krw Exp $ */ +/* $OpenBSD: mbr.h,v 1.33 2021/07/11 19:43:19 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -20,11 +20,11 @@ #define _MBR_H struct mbr { - off_t reloffset; - off_t offset; - unsigned char code[DOSPARTOFF]; - struct prt part[NDOSPART]; - uint16_t signature; + off_t mbr_lba_firstembr; + off_t mbr_lba_self; + unsigned char mbr_code[DOSPARTOFF]; + struct prt mbr_prt[NDOSPART]; + uint16_t mbr_signature; }; extern struct mbr initial_mbr; diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c index 1d21ee09730..929b5f14033 100644 --- a/sbin/fdisk/part.c +++ b/sbin/fdisk/part.c @@ -1,4 +1,4 @@ -/* $OpenBSD: part.c,v 1.89 2021/07/11 13:38:27 krw Exp $ */ +/* $OpenBSD: part.c,v 1.90 2021/07/11 19:43:19 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -222,7 +222,7 @@ ascii_id(int id) } void -PRT_parse(struct dos_partition *prt, off_t offset, off_t reloff, +PRT_parse(struct dos_partition *prt, off_t lba_self, off_t lba_firstembr, struct prt *partn) { off_t off; @@ -240,9 +240,9 @@ PRT_parse(struct dos_partition *prt, off_t offset, off_t reloff, partn->ecyl = ((prt->dp_esect << 2) & 0xFF00) | prt->dp_ecyl; if ((partn->id == DOSPTYP_EXTEND) || (partn->id == DOSPTYP_EXTENDL)) - off = reloff; + off = lba_firstembr; else - off = offset; + off = lba_self; #if 0 /* XXX */ partn->bs = letoh32(prt->dp_start) + off; diff --git a/sbin/fdisk/user.c b/sbin/fdisk/user.c index 0c9621d6daa..70d3e6554b6 100644 --- a/sbin/fdisk/user.c +++ b/sbin/fdisk/user.c @@ -1,4 +1,4 @@ -/* $OpenBSD: user.c,v 1.57 2021/07/11 13:51:42 krw Exp $ */ +/* $OpenBSD: user.c,v 1.58 2021/07/11 19:43:19 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -192,9 +192,9 @@ USER_print_disk(int verbosity) /* Print out extended partitions too */ for (offset = i = 0; i < 4; i++) - if (mbr.part[i].id == DOSPTYP_EXTEND || - mbr.part[i].id == DOSPTYP_EXTENDL) { - offset = (off_t)mbr.part[i].bs; + if (mbr.mbr_prt[i].id == DOSPTYP_EXTEND || + mbr.mbr_prt[i].id == DOSPTYP_EXTENDL) { + offset = (off_t)mbr.mbr_prt[i].bs; if (firstoff == 0) firstoff = offset; } |