Blame SOURCES/0033-kpartx-handle-alternate-bsd-disklabel-location.patch

96a22b
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
96a22b
From: Benjamin Marzinski <bmarzins@redhat.com>
96a22b
Date: Tue, 30 Jun 2020 10:49:59 -0500
96a22b
Subject: [PATCH] kpartx: handle alternate bsd disklabel location
96a22b
96a22b
bsd disk labels can either be at the start of the second sector, or 64
96a22b
bytes into the first sector, but kpartx only handled the first case.
96a22b
However the second case is what parted creates, and what the linux
96a22b
kernel partition code expects.  kpartx should handle both cases.
96a22b
96a22b
Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
96a22b
---
96a22b
 kpartx/bsd.c | 16 ++++++++++++++--
96a22b
 1 file changed, 14 insertions(+), 2 deletions(-)
96a22b
96a22b
diff --git a/kpartx/bsd.c b/kpartx/bsd.c
96a22b
index 0e661fbc..950b0f92 100644
96a22b
--- a/kpartx/bsd.c
96a22b
+++ b/kpartx/bsd.c
96a22b
@@ -1,6 +1,7 @@
96a22b
 #include "kpartx.h"
96a22b
 #include <stdio.h>
96a22b
 
96a22b
+#define BSD_LABEL_OFFSET	64
96a22b
 #define BSD_DISKMAGIC	(0x82564557UL)	/* The disk magic number */
96a22b
 #define XBSD_MAXPARTITIONS	16
96a22b
 #define BSD_FS_UNUSED		0
96a22b
@@ -60,8 +61,19 @@ read_bsd_pt(int fd, struct slice all, struct slice *sp, unsigned int ns) {
96a22b
 		return -1;
96a22b
 
96a22b
 	l = (struct bsd_disklabel *) bp;
96a22b
-	if (l->d_magic != BSD_DISKMAGIC)
96a22b
-		return -1;
96a22b
+	if (l->d_magic != BSD_DISKMAGIC) {
96a22b
+		/*
96a22b
+		 * BSD disklabels can also start 64 bytes offset from the
96a22b
+		 * start of the first sector
96a22b
+		 */
96a22b
+		bp = getblock(fd, offset);
96a22b
+		if (bp == NULL)
96a22b
+			return -1;
96a22b
+
96a22b
+		l = (struct bsd_disklabel *)(bp + 64);
96a22b
+		if (l->d_magic != BSD_DISKMAGIC)
96a22b
+			return -1;
96a22b
+	}
96a22b
 
96a22b
 	max_partitions = 16;
96a22b
 	if (l->d_npartitions < max_partitions)
96a22b
-- 
96a22b
2.17.2
96a22b