Re: [PATCH] bsd disklabel detection

From: Andrzej Krzysztofowicz (ankry@pg.gda.pl)
Date: Sun Mar 26 2000 - 14:40:16 EST


Hi,

> So I pull out the bsd bits from msdos.c into their own file, made both
> msdos and osf call them, and added another config option for stand-alone
> bsd disklabels.
>
> The resulting patch is attached below.

While you are modifying the bsd disklabel code, maybe it would be good
to make it endianness-independent ?
I assube BSD is for ix86 only, so it is little-endian.
Linux code is not little endian: it should support both little- and
big-endian.

Look, how it is done in msdos partition and/or unixware disklabel code.

>
> --------------------------------
[...]
> diff -urNX diff_kernel_excludes linux-2.3-vanilla/fs/partitions/bsd.c linux-2.3.bad/fs/partitions/bsd.c
> --- linux-2.3-vanilla/fs/partitions/bsd.c Wed Dec 31 19:00:00 1969
> +++ linux-2.3.bad/fs/partitions/bsd.c Sun Mar 26 11:21:01 2000
> @@ -0,0 +1,133 @@
[...]
> +int bsd_disklabel_partition(struct gendisk *hd, u_long offset, u_long first_sector,
> + int minor, int *current_minor, int type) {
> + struct buffer_head *bh;
> + struct bsd_disklabel *l;
> + struct bsd_partition *p;
> + int max_partitions;
> + int mask = (1 << hd->minor_shift) - 1;
> + char buf[40];
> +
> + if (!(bh = get_partition_table_block(hd, minor, 0)))
> + return 0;
> + l = (struct bsd_disklabel *) (bh->b_data + offset);
> + if (l->d_magic != BSD_DISKMAGIC) {
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Eg. this is not endianness independent ...

> + brelse(bh);
> + return 0;
> + }
> + if (minor != 0)
> + printk(" %s:", disk_name(hd, minor, buf));
> + printk((type == OPENBSD_PARTITION) ? " <openbsd:" :
> + (type == BSDI_PARTITION || type == OLDBSDI_PARTITION) ? " <bsdi:" :
> + (type == NETBSD_PARTITION) ? " <netbsd:" :
> + (type == OSF_PARTITION) ? " <osf:" : " <bsd:");
> +
> + max_partitions = ((type == OPENBSD_PARTITION) ? OPENBSD_MAXPARTITIONS
> + : BSD_MAXPARTITIONS);
> + if (l->d_npartitions < max_partitions)
> + max_partitions = l->d_npartitions;
> + for (p = l->d_partitions; p - l->d_partitions < max_partitions; p++) {
> + if ((*current_minor & mask) == 0)
> + break;
> +
> + /* osf has p->p_size !=0 -- is that needed as well? */
> + if (p->p_fstype != BSD_FS_UNUSED) {
> + check_and_add_bsd_partition(hd, p, first_sector, minor, *current_minor);
> + (*current_minor)++;
> + }
> +
> + }
> +
> + /* Use bforget(), as we have changed the disk setup */
> + bforget(bh);
> +
> + printk(" >\n");
> + return 1;
> +}
> +

Andrzej

--
=======================================================================
  Andrzej M. Krzysztofowicz               ankry@mif.pg.gda.pl
  phone (48)(58) 347 14 61
Faculty of Applied Phys. & Math.,   Technical University of Gdansk

- 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 : Fri Mar 31 2000 - 21:00:17 EST