Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Factor out the magic checking code for the label, a...



details:   https://anonhg.NetBSD.org/src/rev/c6194b9c1643
branches:  trunk
changeset: 451358:c6194b9c1643
user:      christos <christos%NetBSD.org@localhost>
date:      Fri May 17 18:50:40 2019 +0000

description:
Factor out the magic checking code for the label, and make it not depend
on alignment.

diffstat:

 sys/kern/subr_disk_mbr.c |  15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diffs (45 lines):

diff -r b0c2c3f12cb3 -r c6194b9c1643 sys/kern/subr_disk_mbr.c
--- a/sys/kern/subr_disk_mbr.c  Fri May 17 18:34:33 2019 +0000
+++ b/sys/kern/subr_disk_mbr.c  Fri May 17 18:50:40 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_disk_mbr.c,v 1.50 2019/04/03 22:10:52 christos Exp $      */
+/*     $NetBSD: subr_disk_mbr.c,v 1.51 2019/05/17 18:50:40 christos Exp $      */
 
 /*
  * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
@@ -54,7 +54,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_disk_mbr.c,v 1.50 2019/04/03 22:10:52 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_disk_mbr.c,v 1.51 2019/05/17 18:50:40 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -568,6 +568,12 @@
        return SCAN_CONTINUE;
 }
 
+static bool
+check_label_magic(const struct disklabel *dlp, uint32_t diskmagic)
+{
+       return memcmp(&dlp->d_magic, &diskmagic, sizeof(diskmagic)) == 0 &&
+           memcmp(&dlp->d_magic2, &diskmagic, sizeof(diskmagic)) == 0;
+}
 
 #ifdef DISKLABEL_EI
 /*
@@ -617,11 +623,10 @@
                        dlp = (void *)dlp_byte;
                        break;
                }
-               if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC)
+               if (!check_label_magic(dlp, DISKMAGIC))
 #ifdef DISKLABEL_EI
                {
-                       if (bswap32(dlp->d_magic)  != DISKMAGIC ||
-                           bswap32(dlp->d_magic2) != DISKMAGIC)
+                       if (!check_label_magic(dlp, bswap32(DISKMAGIC)))
                                continue;
 
                        /*



Home | Main Index | Thread Index | Old Index