[PATCH] bsd disklabel detection

From: Ion Badulescu (ionut@moisil.cs.columbia.edu)
Date: Thu Mar 23 2000 - 04:52:26 EST


Hi Andries,

I have attached two patches which improve detection of BSD disklabels, in
particular detection of BSDI disklabels, and detection of any BSD
disklabels which are used instead of regular msdos partitions.

The first patch is fairly trivial: it changes the value for the unused
BSDI_PARTITION flag (which was wrong: I have BSDI 2.1 and 4.1 here, and
both of them failed to see their own partitions after changing their flag
to 0xb7). It also trivially changes fs/partition/msdos.c so it actually
uses the flag.

The second patch, which is a superset of the first patch, is a bit more
involved.. Basically, BSD's can install their own disklabel and completely
trash the MBR and the normal dos partition table. Currently, what Linux
sees of such disks is complete garbage. So the patch tries to see if there
is a valid BSD disklabel installed *before* it tries to parse the dos
partition table.

Unfortunately, there is no way to determine these cases just by looking
at the first sector on the disk -- there is nothing but code in there. I
can thus see where this patch can cause problems: when an existing
full-disk installation of BSD is removed without zero-ing out its
disklabel. The code is ifdef CONFIG_BSD_DISKLABEL but still... Perhaps
another config option would help? I'm not sure, especially nowadays when
distributions like to have every option turned on in their shipping
kernels.

In conclusion: the first patch is harmless, the second deserves some
discussion.

Thanks,
Ion

P.S. I didn't bother to produce the trivial patch #1 equivalent for fdisk.
The equivalent for the second patch is a bit more complex and I'm not yes
sure how to implement it cleanly.

-- 
  It is better to keep your mouth shut and be thought a fool,
            than to open it and remove all doubt.

-------------------------------------------- diff -urNX diff_kernel_excludes linux-2.3-vanilla/fs/partitions/msdos.c linux-2.3/fs/partitions/msdos.c --- linux-2.3-vanilla/fs/partitions/msdos.c Thu Mar 16 17:01:05 2000 +++ linux-2.3/fs/partitions/msdos.c Thu Mar 23 02:49:49 2000 @@ -278,6 +278,7 @@ } printk(" %s:", disk_name(hd, minor, buf)); printk((type == OPENBSD_PARTITION) ? " <openbsd:" : + printk((type == BSDI_PARTITION) ? " <bsdi:" : (type == NETBSD_PARTITION) ? " <netbsd:" : " <bsd:"); max_partitions = ((type == OPENBSD_PARTITION) ? OPENBSD_MAXPARTITIONS @@ -479,6 +480,7 @@ #ifdef CONFIG_BSD_DISKLABEL if (SYS_IND(p) == BSD_PARTITION || SYS_IND(p) == NETBSD_PARTITION || + SYS_IND(p) == BSDI_PARTITION || SYS_IND(p) == OPENBSD_PARTITION) bsd_disklabel_partition(hd, minor, SYS_IND(p)); #endif diff -urNX diff_kernel_excludes linux-2.3-vanilla/include/linux/genhd.h linux-2.3/include/linux/genhd.h --- linux-2.3-vanilla/include/linux/genhd.h Sat Mar 18 15:11:01 2000 +++ linux-2.3/include/linux/genhd.h Thu Mar 23 02:51:11 2000 @@ -107,11 +107,12 @@ /* * BSD disklabel support by Yossi Gottlieb <yogo@math.tau.ac.il> * updated by Marc Espie <Marc.Espie@openbsd.org> + * and by Ion Badulescu <ionut@cs.columbia.edu> */ #define FREEBSD_PARTITION 0xa5 /* FreeBSD Partition ID */ #define OPENBSD_PARTITION 0xa6 /* OpenBSD Partition ID */ #define NETBSD_PARTITION 0xa9 /* NetBSD Partition ID */ -#define BSDI_PARTITION 0xb7 /* BSDI Partition ID */ +#define BSDI_PARTITION 0x9f /* BSDI Partition ID */ /* Ours is not to wonder why.. */ #define BSD_PARTITION FREEBSD_PARTITION ----------------------------------------------- diff -urNX diff_kernel_excludes linux-2.3-vanilla/fs/partitions/msdos.c linux-2.3/fs/partitions/msdos.c --- linux-2.3-vanilla/fs/partitions/msdos.c Thu Mar 16 17:01:05 2000 +++ linux-2.3/fs/partitions/msdos.c Thu Mar 23 04:05:13 2000 @@ -261,7 +261,7 @@ * Create devices for BSD partitions listed in a disklabel, under a * dos-like partition. See extended_partition() for more information. */ -static void bsd_disklabel_partition(struct gendisk *hd, int minor, int type) { +static int bsd_disklabel_partition(struct gendisk *hd, int minor, int type) { struct buffer_head *bh; struct bsd_disklabel *l; struct bsd_partition *p; @@ -270,14 +270,16 @@ char buf[40]; if (!(bh = get_partition_table_block(hd, minor, 0))) - return; + return -1; l = (struct bsd_disklabel *) (bh->b_data+512); if (l->d_magic != BSD_DISKMAGIC) { brelse(bh); - return; + return -1; } - printk(" %s:", disk_name(hd, minor, buf)); + if (minor != 0) + printk(" %s:", disk_name(hd, minor, buf)); printk((type == OPENBSD_PARTITION) ? " <openbsd:" : + (type == BSDI_PARTITION) ? " <bsdi:" : (type == NETBSD_PARTITION) ? " <netbsd:" : " <bsd:"); max_partitions = ((type == OPENBSD_PARTITION) ? OPENBSD_MAXPARTITIONS @@ -296,6 +298,7 @@ bforget(bh); printk(" >\n"); + return 0; } #endif @@ -365,6 +368,19 @@ bforget(bh); return 0; } + +#ifdef CONFIG_BSD_DISKLABEL + /* + * BSD can be installed such that it trashes the + * usual msdos partition table and installs its own + * disklabel instead. + */ + if (bsd_disklabel_partition(hd, 0, BSD_PARTITION) == 0) { + bforget(bh); + return 1; + } +#endif /* CONFIG_BSD_DISKLABEL */ + p = (struct partition *) (0x1be + data); #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE) @@ -479,6 +495,7 @@ #ifdef CONFIG_BSD_DISKLABEL if (SYS_IND(p) == BSD_PARTITION || SYS_IND(p) == NETBSD_PARTITION || + SYS_IND(p) == BSDI_PARTITION || SYS_IND(p) == OPENBSD_PARTITION) bsd_disklabel_partition(hd, minor, SYS_IND(p)); #endif diff -urNX diff_kernel_excludes linux-2.3-vanilla/include/linux/genhd.h linux-2.3/include/linux/genhd.h --- linux-2.3-vanilla/include/linux/genhd.h Sat Mar 18 15:11:01 2000 +++ linux-2.3/include/linux/genhd.h Thu Mar 23 02:51:11 2000 @@ -107,11 +107,12 @@ /* * BSD disklabel support by Yossi Gottlieb <yogo@math.tau.ac.il> * updated by Marc Espie <Marc.Espie@openbsd.org> + * and by Ion Badulescu <ionut@cs.columbia.edu> */ #define FREEBSD_PARTITION 0xa5 /* FreeBSD Partition ID */ #define OPENBSD_PARTITION 0xa6 /* OpenBSD Partition ID */ #define NETBSD_PARTITION 0xa9 /* NetBSD Partition ID */ -#define BSDI_PARTITION 0xb7 /* BSDI Partition ID */ +#define BSDI_PARTITION 0x9f /* BSDI Partition ID */ /* Ours is not to wonder why.. */ #define BSD_PARTITION FREEBSD_PARTITION

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Mar 23 2000 - 21:00:38 EST