diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2021-07-18 21:40:14 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2021-07-18 21:40:14 +0000 |
commit | 6abd62aee76a1637185997383e88914b9ea1b1fe (patch) | |
tree | a0a83ce51f8cbccb520cb15b6612ffc4a8e0525c | |
parent | c93d850d138320329d2c0c2a489b5bb667437b0a (diff) |
Don't save the prt_scyl/prt_ecyl values, change them, use them
and then restore them. Just change/use the saved values and skip
the restoring.
Allows PRT_make() to add 'const' to its struct mbr parameter, and
thus allows MBR_make() to add 'const' to its struct mbr
parameter.
No intentional functional change.
-rw-r--r-- | sbin/fdisk/mbr.c | 4 | ||||
-rw-r--r-- | sbin/fdisk/mbr.h | 4 | ||||
-rw-r--r-- | sbin/fdisk/part.c | 28 | ||||
-rw-r--r-- | sbin/fdisk/part.h | 4 |
4 files changed, 15 insertions, 25 deletions
diff --git a/sbin/fdisk/mbr.c b/sbin/fdisk/mbr.c index 812b098d5b7..a13ccd6ae7d 100644 --- a/sbin/fdisk/mbr.c +++ b/sbin/fdisk/mbr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.c,v 1.88 2021/07/18 12:41:00 krw Exp $ */ +/* $OpenBSD: mbr.c,v 1.89 2021/07/18 21:40:13 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -170,7 +170,7 @@ MBR_parse(const struct dos_mbr *dos_mbr, const uint64_t lba_self, } void -MBR_make(struct mbr *mbr, struct dos_mbr *dos_mbr) +MBR_make(const struct mbr *mbr, struct dos_mbr *dos_mbr) { struct dos_partition dos_partition; int i; diff --git a/sbin/fdisk/mbr.h b/sbin/fdisk/mbr.h index d097e9c1d3b..bc58b4a2cdd 100644 --- a/sbin/fdisk/mbr.h +++ b/sbin/fdisk/mbr.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mbr.h,v 1.36 2021/07/18 12:41:00 krw Exp $ */ +/* $OpenBSD: mbr.h,v 1.37 2021/07/18 21:40:13 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -32,7 +32,7 @@ extern struct mbr initial_mbr; void MBR_print(const struct mbr *, const char *); void MBR_parse(const struct dos_mbr *, const uint64_t, const uint64_t, struct mbr *); -void MBR_make(struct mbr *, struct dos_mbr *); +void MBR_make(const struct mbr *, struct dos_mbr *); void MBR_init(struct mbr *); void MBR_init_GPT(struct mbr *); int MBR_read(const uint64_t, const uint64_t, struct mbr *); diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c index 14e8ba92f6d..c062cc003c6 100644 --- a/sbin/fdisk/part.c +++ b/sbin/fdisk/part.c @@ -1,4 +1,4 @@ -/* $OpenBSD: part.c,v 1.99 2021/07/16 22:50:43 krw Exp $ */ +/* $OpenBSD: part.c,v 1.100 2021/07/18 21:40:13 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -275,20 +275,15 @@ check_chs(const struct prt *prt) } void -PRT_make(struct prt *prt, const uint64_t lba_self, const uint64_t lba_firstembr, +PRT_make(const struct prt *prt, const uint64_t lba_self, const uint64_t lba_firstembr, struct dos_partition *dp) { uint64_t off, t; - uint32_t ecsave, scsave; + uint32_t ecyl, scyl; - /* Save (and restore below) cylinder info we may fiddle with. */ - scsave = prt->prt_scyl; - ecsave = prt->prt_ecyl; + scyl = (prt->prt_scyl > 1023) ? 1023 : prt->prt_scyl; + ecyl = (prt->prt_ecyl > 1023) ? 1023 : prt->prt_ecyl; - if ((prt->prt_scyl > 1023) || (prt->prt_ecyl > 1023)) { - prt->prt_scyl = (prt->prt_scyl > 1023)? 1023: prt->prt_scyl; - prt->prt_ecyl = (prt->prt_ecyl > 1023)? 1023: prt->prt_ecyl; - } if ((prt->prt_id == DOSPTYP_EXTEND) || (prt->prt_id == DOSPTYP_EXTENDL)) off = lba_firstembr; else @@ -296,13 +291,11 @@ PRT_make(struct prt *prt, const uint64_t lba_self, const uint64_t lba_firstembr, if (check_chs(prt) == 0) { dp->dp_shd = prt->prt_shead & 0xFF; - dp->dp_ssect = (prt->prt_ssect & 0x3F) | - ((prt->prt_scyl & 0x300) >> 2); - dp->dp_scyl = prt->prt_scyl & 0xFF; + dp->dp_ssect = (prt->prt_ssect & 0x3F) | ((scyl & 0x300) >> 2); + dp->dp_scyl = scyl & 0xFF; dp->dp_ehd = prt->prt_ehead & 0xFF; - dp->dp_esect = (prt->prt_esect & 0x3F) | - ((prt->prt_ecyl & 0x300) >> 2); - dp->dp_ecyl = prt->prt_ecyl & 0xFF; + dp->dp_esect = (prt->prt_esect & 0x3F) | ((ecyl & 0x300) >> 2); + dp->dp_ecyl = ecyl & 0xFF; } else { memset(dp, 0xFF, sizeof(*dp)); } @@ -318,9 +311,6 @@ PRT_make(struct prt *prt, const uint64_t lba_self, const uint64_t lba_firstembr, else t = htole64(prt->prt_ns); memcpy(&dp->dp_size, &t, sizeof(uint32_t)); - - prt->prt_scyl = scsave; - prt->prt_ecyl = ecsave; } void diff --git a/sbin/fdisk/part.h b/sbin/fdisk/part.h index 08cfa9240c5..71baa85a4a1 100644 --- a/sbin/fdisk/part.h +++ b/sbin/fdisk/part.h @@ -1,4 +1,4 @@ -/* $OpenBSD: part.h,v 1.28 2021/07/13 15:03:34 krw Exp $ */ +/* $OpenBSD: part.h,v 1.29 2021/07/18 21:40:13 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -31,7 +31,7 @@ struct prt { void PRT_printall(void); void PRT_parse(const struct dos_partition *, const uint64_t, const uint64_t, struct prt *); -void PRT_make(struct prt *,const uint64_t, const uint64_t, +void PRT_make(const struct prt *,const uint64_t, const uint64_t, struct dos_partition *); void PRT_print(const int, const struct prt *, const char *); char *PRT_uuid_to_typename(const struct uuid *); |