From 068cd1d7986d8de608fdbefc39f2ab8e2f08aaa4 Mon Sep 17 00:00:00 2001 From: Willy TARREAU Date: Thu, 20 Apr 2006 11:08:08 +0200 Subject: [PATCH] [PATCH] fix /proc/partitions display with USB-FDD geometry When an USB flash disk is formatted under as a floppy (without partitions), random partitions appear in /proc/partitions depending on the code and data used by the boot loader at the offset where the partition table is expected : 8 0 128000 sda 8 1 985184692 sda1 8 2 271759162 sda2 8 3 1093808825 sda3 8 4 26721 sda4 Such layout appears when Windows is used to format the USB stick, or when putting a boot-loader such as syslinux on an device. A patch was introduced in 2.6 to fix this by ensuring that all 4 partitions boot flags are either 0x00 or 0x80 before interpreting the boot sector as an MBR. This fix has been back-ported to 2.4 by Gilles Espinasse. The behaviour has been carefully tested, and 2.4.32 with this patch now behaves as 2.6.16 in that such USB sticks are correctly detected without partitions, while others still work correctly : 8 0 128000 sda => 128 MB USB stick formatted under windows 8 0 261216 sdb => 256 MB USB stick which contains a real partition 8 1 261040 sdb1 --- fs/partitions/msdos.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/partitions/msdos.c b/fs/partitions/msdos.c index 46b15a4e..1ef6a8fe 100644 --- a/fs/partitions/msdos.c +++ b/fs/partitions/msdos.c @@ -572,6 +572,19 @@ int msdos_partition(struct gendisk *hd, struct block_device *bdev, put_dev_sector(sect); return 0; } + /* + * Now that the 55aa signature is present, this is probably + * either the boot sector of a FAT filesystem or a DOS-type + * partition table. Reject this in case the boot indicator + * is not 0 or 0x80. + */ + p = (struct partition *) (data + 0x1be); + for (i = 1; i <= 4; i++, p++) { + if (p->boot_ind != 0 && p->boot_ind != 0x80) { + put_dev_sector(sect); + return 0; + } + } p = (struct partition *) (data + 0x1be); /* -- 2.11.0