Message ID | 1593643176-6206-4-git-send-email-bmarzins@redhat.com (mailing list archive) |
---|---|
State | Not Applicable, archived |
Delegated to: | christophe varoqui |
Headers | show |
Series | misc patches | expand |
On Wed, 2020-07-01 at 17:39 -0500, Benjamin Marzinski wrote: > bsd disk labels can either be at the start of the second sector, or > 64 > bytes into the first sector, but kpartx only handled the first case. > However the second case is what parted creates, and what the linux > kernel partition code expects. kpartx should handle both cases. > > Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> I can see that for parted, but not for the kernel (https://elixir.bootlin.com/linux/latest/source/block/partitions/msdos.c#L368) Anyway: Reviewed-by: Martin Wilck <mwilck@suse.com>
On Thu, Jul 02, 2020 at 03:12:58PM +0000, Martin Wilck wrote: > On Wed, 2020-07-01 at 17:39 -0500, Benjamin Marzinski wrote: > > bsd disk labels can either be at the start of the second sector, or > > 64 > > bytes into the first sector, but kpartx only handled the first case. > > However the second case is what parted creates, and what the linux > > kernel partition code expects. kpartx should handle both cases. > > > > Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> > > I can see that for parted, but not for the kernel > (https://elixir.bootlin.com/linux/latest/source/block/partitions/msdos.c#L368) https://elixir.bootlin.com/linux/latest/source/block/partitions/osf.c -Ben > Anyway: > > Reviewed-by: Martin Wilck <mwilck@suse.com> > > > -- > Dr. Martin Wilck <mwilck@suse.com>, Tel. +49 (0)911 74053 2107 > SUSE Software Solutions Germany GmbH > HRB 36809, AG Nürnberg GF: Felix > Imendörffer > -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel
diff --git a/kpartx/bsd.c b/kpartx/bsd.c index 0e661fbc..950b0f92 100644 --- a/kpartx/bsd.c +++ b/kpartx/bsd.c @@ -1,6 +1,7 @@ #include "kpartx.h" #include <stdio.h> +#define BSD_LABEL_OFFSET 64 #define BSD_DISKMAGIC (0x82564557UL) /* The disk magic number */ #define XBSD_MAXPARTITIONS 16 #define BSD_FS_UNUSED 0 @@ -60,8 +61,19 @@ read_bsd_pt(int fd, struct slice all, struct slice *sp, unsigned int ns) { return -1; l = (struct bsd_disklabel *) bp; - if (l->d_magic != BSD_DISKMAGIC) - return -1; + if (l->d_magic != BSD_DISKMAGIC) { + /* + * BSD disklabels can also start 64 bytes offset from the + * start of the first sector + */ + bp = getblock(fd, offset); + if (bp == NULL) + return -1; + + l = (struct bsd_disklabel *)(bp + 64); + if (l->d_magic != BSD_DISKMAGIC) + return -1; + } max_partitions = 16; if (l->d_npartitions < max_partitions)
bsd disk labels can either be at the start of the second sector, or 64 bytes into the first sector, but kpartx only handled the first case. However the second case is what parted creates, and what the linux kernel partition code expects. kpartx should handle both cases. Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> --- kpartx/bsd.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)