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