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