Merge master.kernel.org:/pub/scm/linux/kernel/git/davem/sparc-2.6
[sfrench/cifs-2.6.git] / fs / partitions / msdos.c
index 4f8df71e49d330038614c4f81a300f477b6f9a95..4ccec4cd1367a304bac2c784d0ba7e794b3e98cc 100644 (file)
 #include <asm/unaligned.h>
 
 #define SYS_IND(p)     (get_unaligned(&p->sys_ind))
-#define NR_SECTS(p)    ({ __typeof__(p->nr_sects) __a =        \
-                               get_unaligned(&p->nr_sects);    \
+#define NR_SECTS(p)    ({ __le32 __a = get_unaligned(&p->nr_sects);    \
                                le32_to_cpu(__a); \
                        })
 
-#define START_SECT(p)  ({ __typeof__(p->start_sect) __a =      \
-                               get_unaligned(&p->start_sect);  \
+#define START_SECT(p)  ({ __le32 __a = get_unaligned(&p->start_sect);  \
                                le32_to_cpu(__a); \
                        })
 
@@ -65,15 +63,25 @@ msdos_magic_present(unsigned char *p)
 #define AIX_LABEL_MAGIC4       0xC1
 static int aix_magic_present(unsigned char *p, struct block_device *bdev)
 {
+       struct partition *pt = (struct partition *) (p + 0x1be);
        Sector sect;
        unsigned char *d;
-       int ret = 0;
+       int slot, ret = 0;
 
-       if (p[0] != AIX_LABEL_MAGIC1 &&
-               p[1] != AIX_LABEL_MAGIC2 &&
-               p[2] != AIX_LABEL_MAGIC3 &&
-               p[3] != AIX_LABEL_MAGIC4)
+       if (!(p[0] == AIX_LABEL_MAGIC1 &&
+               p[1] == AIX_LABEL_MAGIC2 &&
+               p[2] == AIX_LABEL_MAGIC3 &&
+               p[3] == AIX_LABEL_MAGIC4))
                return 0;
+       /* Assume the partition table is valid if Linux partitions exists */
+       for (slot = 1; slot <= 4; slot++, pt++) {
+               if (pt->sys_ind == LINUX_SWAP_PARTITION ||
+                       pt->sys_ind == LINUX_RAID_PARTITION ||
+                       pt->sys_ind == LINUX_DATA_PARTITION ||
+                       pt->sys_ind == LINUX_LVM_PARTITION ||
+                       is_extended_partition(pt))
+                       return 0;
+       }
        d = read_dev_sector(bdev, 7, &sect);
        if (d) {
                if (d[0] == '_' && d[1] == 'L' && d[2] == 'V' && d[3] == 'M')
@@ -157,7 +165,7 @@ parse_extended(struct parsed_partitions *state, struct block_device *bdev,
 
                        put_partition(state, state->next, next, size);
                        if (SYS_IND(p) == LINUX_RAID_PARTITION)
-                               state->parts[state->next].flags = 1;
+                               state->parts[state->next].flags = ADDPART_FLAG_RAID;
                        loopct = 0;
                        if (++state->next == state->limit)
                                goto done;