From 6db064f3b5beb8c471ae4f814748d5fb5c802dad Mon Sep 17 00:00:00 2001 From: krw Date: Tue, 11 Oct 2022 23:39:07 +0000 Subject: [PATCH] Give checkdisklabel() a new parameter supplying the dev_t of the device whose disklabel is being checked. Within checkdisklabel() use this information to discover a device name iff (sic) the label is an obsolete version. Use the name to generate a meaningful warning message asking the user to rewrite the disklabel and thus promote it to the current version. Suggested by, feedback from and ok deraadt@ --- sys/arch/alpha/alpha/disksubr.c | 4 ++-- sys/arch/hppa/hppa/disksubr.c | 5 +++-- sys/arch/luna88k/luna88k/disksubr.c | 12 ++++++------ sys/arch/macppc/macppc/disksubr.c | 6 +++--- sys/arch/sparc64/sparc64/disksubr.c | 14 ++++++++------ sys/kern/subr_disk.c | 14 +++++++++++--- sys/sys/disklabel.h | 4 ++-- 7 files changed, 35 insertions(+), 24 deletions(-) diff --git a/sys/arch/alpha/alpha/disksubr.c b/sys/arch/alpha/alpha/disksubr.c index 5f0334388ba..f44b71b4be4 100644 --- a/sys/arch/alpha/alpha/disksubr.c +++ b/sys/arch/alpha/alpha/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.100 2017/02/28 10:49:37 natano Exp $ */ +/* $OpenBSD: disksubr.c,v 1.101 2022/10/11 23:39:07 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -67,7 +67,7 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *), if (error) goto done; - error = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0, + error = checkdisklabel(bp->b_dev, bp->b_data + LABELOFFSET, lp, 0, DL_GETDSIZE(lp)); if (error == 0) goto done; diff --git a/sys/arch/hppa/hppa/disksubr.c b/sys/arch/hppa/hppa/disksubr.c index 807e6b0916e..f255c074384 100644 --- a/sys/arch/hppa/hppa/disksubr.c +++ b/sys/arch/hppa/hppa/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.90 2022/09/01 13:45:26 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.91 2022/10/11 23:39:07 krw Exp $ */ /* * Copyright (c) 1999 Michael Shalayeff @@ -210,7 +210,8 @@ finished: if (error) goto done; - error = checkdisklabel(bp->b_data, lp, openbsdstart, DL_GETDSIZE(lp)); + error = checkdisklabel(bp->b_dev, bp->b_data, lp, openbsdstart, + DL_GETDSIZE(lp)); done: return (error); diff --git a/sys/arch/luna88k/luna88k/disksubr.c b/sys/arch/luna88k/luna88k/disksubr.c index c9dc9c9b741..ce22593f0a7 100644 --- a/sys/arch/luna88k/luna88k/disksubr.c +++ b/sys/arch/luna88k/luna88k/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.60 2022/09/01 13:45:26 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.61 2022/10/11 23:39:07 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.12 2002/02/19 17:09:44 wiz Exp $ */ /* @@ -88,7 +88,7 @@ #error "Default value of LABELSECTOR no longer zero?" #endif -int disklabel_om_to_bsd(struct sun_disklabel *, struct disklabel *); +int disklabel_om_to_bsd(dev_t, struct sun_disklabel *, struct disklabel *); int disklabel_bsd_to_om(struct disklabel *, struct sun_disklabel *); static __inline u_int sun_extended_sum(struct sun_disklabel *, void *); @@ -125,11 +125,11 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *), slp = (struct sun_disklabel *)bp->b_data; if (slp->sl_magic == SUN_DKMAGIC) { - error = disklabel_om_to_bsd(slp, lp); + error = disklabel_om_to_bsd(bp->b_dev, slp, lp); goto done; } - error = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0, + error = checkdisklabel(bp->b_dev, bp->b_data + LABELOFFSET, lp, 0, DL_GETDSIZE(lp)); if (error == 0) goto done; @@ -240,7 +240,7 @@ sun_extended_sum(struct sun_disklabel *sl, void *end) * The BSD label is cleared out before this is called. */ int -disklabel_om_to_bsd(struct sun_disklabel *sl, struct disklabel *lp) +disklabel_om_to_bsd(dev_t dev, struct sun_disklabel *sl, struct disklabel *lp) { struct partition *npp; struct sun_dkpart *spp; @@ -361,7 +361,7 @@ disklabel_om_to_bsd(struct sun_disklabel *sl, struct disklabel *lp) lp->d_checksum = 0; lp->d_checksum = dkcksum(lp); - return (checkdisklabel(lp, lp, 0, DL_GETDSIZE(lp))); + return (checkdisklabel(dev, lp, lp, 0, DL_GETDSIZE(lp))); } /* diff --git a/sys/arch/macppc/macppc/disksubr.c b/sys/arch/macppc/macppc/disksubr.c index d4ebd4968c2..1d879663e87 100644 --- a/sys/arch/macppc/macppc/disksubr.c +++ b/sys/arch/macppc/macppc/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.82 2017/02/28 10:49:37 natano Exp $ */ +/* $OpenBSD: disksubr.c,v 1.83 2022/10/11 23:39:08 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.21 1996/05/03 19:42:03 christos Exp $ */ /* @@ -172,8 +172,8 @@ readdpmelabel(struct buf *bp, void (*strat)(struct buf *), if (error) return (error); - error = checkdisklabel(bp->b_data + LABELOFFSET, lp, hfspartoff, - hfspartend); + error = checkdisklabel(bp->b_dev, bp->b_data + LABELOFFSET, lp, + hfspartoff, hfspartend); return (error); } diff --git a/sys/arch/sparc64/sparc64/disksubr.c b/sys/arch/sparc64/sparc64/disksubr.c index 8b49ef94887..311eb8a10ac 100644 --- a/sys/arch/sparc64/sparc64/disksubr.c +++ b/sys/arch/sparc64/sparc64/disksubr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: disksubr.c,v 1.73 2022/09/01 13:45:26 krw Exp $ */ +/* $OpenBSD: disksubr.c,v 1.74 2022/10/11 23:39:08 krw Exp $ */ /* $NetBSD: disksubr.c,v 1.13 2000/12/17 22:39:18 pk Exp $ */ /* @@ -39,7 +39,8 @@ #include "cd.h" -static int disklabel_sun_to_bsd(struct sun_disklabel *, struct disklabel *); +static int disklabel_sun_to_bsd(dev_t dev, struct sun_disklabel *, + struct disklabel *); static int disklabel_bsd_to_sun(struct disklabel *, struct sun_disklabel *); static __inline u_int sun_extended_sum(struct sun_disklabel *, void *); @@ -99,11 +100,12 @@ readdisklabel(dev_t dev, void (*strat)(struct buf *), slp = (struct sun_disklabel *)bp->b_data; if (slp->sl_magic == SUN_DKMAGIC) { - error = disklabel_sun_to_bsd(slp, lp); + error = disklabel_sun_to_bsd(bp->b_dev, slp, lp); goto done; } - error = checkdisklabel(bp->b_data + LABELOFFSET, lp, 0, DL_GETDSIZE(lp)); + error = checkdisklabel(bp->b_dev, bp->b_data + LABELOFFSET, lp, 0, + DL_GETDSIZE(lp)); if (error == 0) goto done; @@ -218,7 +220,7 @@ sun_extended_sum(struct sun_disklabel *sl, void *end) * The BSD label is cleared out before this is called. */ static int -disklabel_sun_to_bsd(struct sun_disklabel *sl, struct disklabel *lp) +disklabel_sun_to_bsd(dev_t dev, struct sun_disklabel *sl, struct disklabel *lp) { struct sun_preamble *preamble = (struct sun_preamble *)sl; struct sun_partinfo *ppp; @@ -369,7 +371,7 @@ disklabel_sun_to_bsd(struct sun_disklabel *sl, struct disklabel *lp) lp->d_checksum = 0; lp->d_checksum = dkcksum(lp); - return (checkdisklabel(lp, lp, 0, DL_GETDSIZE(lp))); + return (checkdisklabel(dev, lp, lp, 0, DL_GETDSIZE(lp))); } /* diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index c6272fd2359..7ff23bc77ea 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_disk.c,v 1.264 2022/09/23 12:32:50 krw Exp $ */ +/* $OpenBSD: subr_disk.c,v 1.265 2022/10/11 23:39:08 krw Exp $ */ /* $NetBSD: subr_disk.c,v 1.17 1996/03/16 23:17:08 christos Exp $ */ /* @@ -164,12 +164,13 @@ initdisklabel(struct disklabel *lp) * a newer version if needed, etc etc. */ int -checkdisklabel(void *rlp, struct disklabel *lp, u_int64_t boundstart, +checkdisklabel(dev_t dev, void *rlp, struct disklabel *lp, u_int64_t boundstart, u_int64_t boundend) { struct disklabel *dlp = rlp; struct __partitionv0 *v0pp; struct partition *pp; + const char *blkname; u_int64_t disksize; int error = 0; int i; @@ -265,6 +266,12 @@ checkdisklabel(void *rlp, struct disklabel *lp, u_int64_t boundstart, *lp = *dlp; if (lp->d_version == 0) { + blkname = findblkname(major(dev)); + if (blkname == NULL) + blkname = findblkname(major(chrtoblk(dev))); + printf("%s%d has legacy label, please rewrite using " + "disklabel(8)\n", blkname, DISKUNIT(dev)); + lp->d_version = 1; lp->d_secperunith = 0; @@ -409,7 +416,8 @@ readdoslabel(struct buf *bp, void (*strat)(struct buf *), struct disklabel *lp, } rlp = (struct disklabel *)(bp->b_data + DL_BLKOFFSET(lp, partoff)); - error = checkdisklabel(rlp, lp, DL_GETBSTART(rlp), DL_GETBEND(rlp)); + error = checkdisklabel(bp->b_dev, rlp, lp, DL_GETBSTART(rlp), + DL_GETBEND(rlp)); DPRINTF("readdoslabel return: %s, %d, checkdisklabel() of daddr_t " "%lld %s\n", devname, error, partoff, error ? "failed" : "ok"); diff --git a/sys/sys/disklabel.h b/sys/sys/disklabel.h index dba3aa46131..cdfff074ee0 100644 --- a/sys/sys/disklabel.h +++ b/sys/sys/disklabel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: disklabel.h,v 1.83 2022/10/07 19:34:40 krw Exp $ */ +/* $OpenBSD: disklabel.h,v 1.84 2022/10/11 23:39:08 krw Exp $ */ /* $NetBSD: disklabel.h,v 1.41 1996/05/10 23:07:37 mark Exp $ */ /* @@ -492,7 +492,7 @@ struct dos_mbr { void diskerr(struct buf *, char *, char *, int, int, struct disklabel *); u_int dkcksum(struct disklabel *); int initdisklabel(struct disklabel *); -int checkdisklabel(void *, struct disklabel *, u_int64_t, u_int64_t); +int checkdisklabel(dev_t, void *, struct disklabel *, u_int64_t, u_int64_t); int setdisklabel(struct disklabel *, struct disklabel *, u_int); int readdisklabel(dev_t, void (*)(struct buf *), struct disklabel *, int); int writedisklabel(dev_t, void (*)(struct buf *), struct disklabel *); -- 2.20.1