Module Name: src Committed By: jdolecek Date: Mon Jan 7 21:04:35 UTC 2019
Modified Files: src/sys/dev: dksubr.c Log Message: convert the sector counts for label sanity checks to use same unit (DEV_BSIZE), so that the check is meaningful if disklabel sector size and disk geometry sector size differ - for example 512 disklabel vs 2048 for sparc cd(4) conversion assumes that the sector sizes are multiples of DEV_BSIZE (512) fixes kern/53833 by Andreas Gustafsson Note: the checks are executed #ifdef DIAGNOSTIC, that's why nothing is printed by 8.0 kernel, or anything built from release branches To generate a diff of this commit: cvs rdiff -u -r1.104 -r1.105 src/sys/dev/dksubr.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/dksubr.c diff -u src/sys/dev/dksubr.c:1.104 src/sys/dev/dksubr.c:1.105 --- src/sys/dev/dksubr.c:1.104 Sat Nov 24 18:09:13 2018 +++ src/sys/dev/dksubr.c Mon Jan 7 21:04:35 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: dksubr.c,v 1.104 2018/11/24 18:09:13 bouyer Exp $ */ +/* $NetBSD: dksubr.c,v 1.105 2019/01/07 21:04:35 jdolecek Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 1999, 2002, 2008 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: dksubr.c,v 1.104 2018/11/24 18:09:13 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dksubr.c,v 1.105 2019/01/07 21:04:35 jdolecek Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -915,7 +915,7 @@ dk_getdisklabel(struct dk_softc *dksc, d struct cpu_disklabel *clp = dksc->sc_dkdev.dk_cpulabel; struct disk_geom *dg = &dksc->sc_dkdev.dk_geom; struct partition *pp; - int i; + int i, lpratio, dgratio; const char *errstring; memset(clp, 0x0, sizeof(*clp)); @@ -932,25 +932,37 @@ dk_getdisklabel(struct dk_softc *dksc, d if ((dksc->sc_flags & DKF_LABELSANITY) == 0) return; + /* Convert sector counts to multiple of DEV_BSIZE for comparison */ + lpratio = dgratio = 1; + if (lp->d_secsize > DEV_BSIZE) + lpratio = lp->d_secsize / DEV_BSIZE; + else if (dg->dg_secsize > DEV_BSIZE) + dgratio = dg->dg_secsize / DEV_BSIZE; + /* Sanity check */ - if (lp->d_secperunit > dg->dg_secperunit) - printf("WARNING: %s: total sector size in disklabel (%ju) " - "!= the size of %s (%ju)\n", dksc->sc_xname, - (uintmax_t)lp->d_secperunit, dksc->sc_xname, - (uintmax_t)dg->dg_secperunit); + if ((uint64_t)lp->d_secperunit * lpratio > dg->dg_secperunit * dgratio) + printf("WARNING: %s: " + "total unit size in disklabel (%" PRIu64 ") " + "!= the size of %s (%" PRIu64 ")\n", dksc->sc_xname, + (uint64_t)lp->d_secperunit * lpratio, dksc->sc_xname, + dg->dg_secperunit * dgratio); else if (lp->d_secperunit < UINT32_MAX && - lp->d_secperunit < dg->dg_secperunit) - printf("%s: %ju trailing sectors not covered by disklabel\n", - dksc->sc_xname, - (uintmax_t)dg->dg_secperunit - lp->d_secperunit); + (uint64_t)lp->d_secperunit * lpratio < dg->dg_secperunit * dgratio) + printf("%s: %" PRIu64 " trailing sectors not covered" + " by disklabel\n", dksc->sc_xname, + (dg->dg_secperunit * dgratio) + - (lp->d_secperunit * lpratio)); for (i=0; i < lp->d_npartitions; i++) { + uint64_t pend; + pp = &lp->d_partitions[i]; - if (pp->p_offset + pp->p_size > dg->dg_secperunit) + pend = pp->p_offset + pp->p_size; + if (pend * lpratio > dg->dg_secperunit * dgratio) printf("WARNING: %s: end of partition `%c' exceeds " - "the size of %s (%ju)\n", dksc->sc_xname, + "the size of %s (%" PRIu64 ")\n", dksc->sc_xname, 'a' + i, dksc->sc_xname, - (uintmax_t)dg->dg_secperunit); + dg->dg_secperunit * dgratio); } }