Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev convert the sector counts for label sanity checks to...



details:   https://anonhg.NetBSD.org/src/rev/e6b2c499cbc6
branches:  trunk
changeset: 995839:e6b2c499cbc6
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Mon Jan 07 21:04:35 2019 +0000

description:
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

diffstat:

 sys/dev/dksubr.c |  42 +++++++++++++++++++++++++++---------------
 1 files changed, 27 insertions(+), 15 deletions(-)

diffs (77 lines):

diff -r b9e4fd57bab9 -r e6b2c499cbc6 sys/dev/dksubr.c
--- a/sys/dev/dksubr.c  Mon Jan 07 18:48:07 2019 +0000
+++ b/sys/dev/dksubr.c  Mon Jan 07 21:04:35 2019 +0000
@@ -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 @@
        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 @@
        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);
        }
 }
 



Home | Main Index | Thread Index | Old Index