patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / fs / partitions / msdos.c
index 3ed5cb5..e98505b 100644 (file)
@@ -389,8 +389,23 @@ int msdos_partition(struct parsed_partitions *state, 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 (slot = 1; slot <= 4; slot++, p++) {
+               if (p->boot_ind != 0 && p->boot_ind != 0x80) {
+                       put_dev_sector(sect);
+                       return 0;
+               }
+       }
+
 #ifdef CONFIG_EFI_PARTITION
+       p = (struct partition *) (data + 0x1be);
        for (slot = 1 ; slot <= 4 ; slot++, p++) {
                /* If this is an EFI GPT disk, msdos should ignore it. */
                if (SYS_IND(p) == EFI_PMBR_OSTYPE_EFI_GPT) {
@@ -398,8 +413,8 @@ int msdos_partition(struct parsed_partitions *state, struct block_device *bdev)
                        return 0;
                }
        }
-       p = (struct partition *) (data + 0x1be);
 #endif
+       p = (struct partition *) (data + 0x1be);
 
        /*
         * Look for partitions in two passes:
@@ -407,8 +422,8 @@ int msdos_partition(struct parsed_partitions *state, struct block_device *bdev)
         * On the second pass look inside *BSD, Unixware and Solaris partitions.
         */
 
-       state->next = 5;
-       for (slot = 1 ; slot <= 4 ; slot++, p++) {
+       state->next = DOS_EXTENDED_PARTITION;
+       for (slot = 1 ; slot < DOS_EXTENDED_PARTITION ; slot++, p++) {
                u32 start = START_SECT(p)*sector_size;
                u32 size = NR_SECTS(p)*sector_size;
                if (!size)
@@ -435,7 +450,7 @@ int msdos_partition(struct parsed_partitions *state, struct block_device *bdev)
 
        /* second pass - output for each on a separate line */
        p = (struct partition *) (0x1be + data);
-       for (slot = 1 ; slot <= 4 ; slot++, p++) {
+       for (slot = 1 ; slot < DOS_EXTENDED_PARTITION ; slot++, p++) {
                unsigned char id = SYS_IND(p);
                int n;