Factor out the magic checking code for the label, and make it not depend trunk
authorchristos <christos@NetBSD.org>
Fri, 17 May 2019 18:50:40 +0000
branchtrunk
changeset 451358 c6194b9c1643
parent 451357 b0c2c3f12cb3
child 451359 efceab0edae9
Factor out the magic checking code for the label, and make it not depend on alignment.
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;
 
 			/*