fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / fs / sysv / super.c
index f0e99fc..6f9707a 100644 (file)
@@ -178,16 +178,22 @@ static void detected_v7(struct sysv_sb_info *sbi)
 static int detect_xenix(struct sysv_sb_info *sbi, struct buffer_head *bh)
 {
        struct xenix_super_block *sbd = (struct xenix_super_block *)bh->b_data;
-       if (sbd->s_magic == cpu_to_le32(0x2b5544))
+       if (*(__le32 *)&sbd->s_magic == cpu_to_le32(0x2b5544))
                sbi->s_bytesex = BYTESEX_LE;
-       else if (sbd->s_magic == cpu_to_be32(0x2b5544))
+       else if (*(__be32 *)&sbd->s_magic == cpu_to_be32(0x2b5544))
                sbi->s_bytesex = BYTESEX_BE;
        else
                return 0;
-       if (sbd->s_type > 2 || sbd->s_type < 1)
+       switch (fs32_to_cpu(sbi, sbd->s_type)) {
+       case 1:
+               sbi->s_type = FSTYPE_XENIX;
+               return 1;
+       case 2:
+               sbi->s_type = FSTYPE_XENIX;
+               return 2;
+       default:
                return 0;
-       sbi->s_type = FSTYPE_XENIX;
-       return sbd->s_type;
+       }
 }
 
 static int detect_sysv(struct sysv_sb_info *sbi, struct buffer_head *bh)
@@ -195,14 +201,17 @@ static int detect_sysv(struct sysv_sb_info *sbi, struct buffer_head *bh)
        struct super_block *sb = sbi->s_sb;
        /* All relevant fields are at the same offsets in R2 and R4 */
        struct sysv4_super_block * sbd;
+       u32 type;
 
        sbd = (struct sysv4_super_block *) (bh->b_data + BLOCK_SIZE/2);
-       if (sbd->s_magic == cpu_to_le32(0xfd187e20))
+       if (*(__le32 *)&sbd->s_magic == cpu_to_le32(0xfd187e20))
                sbi->s_bytesex = BYTESEX_LE;
-       else if (sbd->s_magic == cpu_to_be32(0xfd187e20))
+       else if (*(__be32 *)&sbd->s_magic == cpu_to_be32(0xfd187e20))
                sbi->s_bytesex = BYTESEX_BE;
        else
                return 0;
+
+       type = fs32_to_cpu(sbi, sbd->s_type);
  
        if (fs16_to_cpu(sbi, sbd->s_nfree) == 0xffff) {
                sbi->s_type = FSTYPE_AFS;
@@ -212,18 +221,17 @@ static int detect_sysv(struct sysv_sb_info *sbi, struct buffer_head *bh)
                                "forcing read-only mode.\n", 
                                sb->s_id);
                }
-               return sbd->s_type;
+               return type;
        }
  
        if (fs32_to_cpu(sbi, sbd->s_time) < JAN_1_1980) {
                /* this is likely to happen on SystemV2 FS */
-               if (sbd->s_type > 3 || sbd->s_type < 1)
+               if (type > 3 || type < 1)
                        return 0;
                sbi->s_type = FSTYPE_SYSV2;
-               return sbd->s_type;
+               return type;
        }
-       if ((sbd->s_type > 3 || sbd->s_type < 1) &&
-           (sbd->s_type > 0x30 || sbd->s_type < 0x10))
+       if ((type > 3 || type < 1) && (type > 0x30 || type < 0x10))
                return 0;
 
        /* On Interactive Unix (ISC) Version 4.0/3.x s_type field = 0x10,
@@ -231,14 +239,14 @@ static int detect_sysv(struct sysv_sb_info *sbi, struct buffer_head *bh)
           filename limit is gone. Due to lack of information about this
            feature read-only mode seems to be a reasonable approach... -KGB */
 
-       if (sbd->s_type >= 0x10) {
+       if (type >= 0x10) {
                printk("SysV FS: can't handle long file names on %s, "
                       "forcing read-only mode.\n", sb->s_id);
                sbi->s_forced_ro = 1;
        }
 
        sbi->s_type = FSTYPE_SYSV4;
-       return sbd->s_type >= 0x10 ? (sbd->s_type >> 4) : sbd->s_type;
+       return type >= 0x10 ? type >> 4 : type;
 }
 
 static int detect_coherent(struct sysv_sb_info *sbi, struct buffer_head *bh)
@@ -350,29 +358,23 @@ static int sysv_fill_super(struct super_block *sb, void *data, int silent)
        unsigned long blocknr;
        int size = 0, i;
        
-       if (1024 != sizeof (struct xenix_super_block))
-               panic("Xenix FS: bad superblock size");
-       if (512 != sizeof (struct sysv4_super_block))
-               panic("SystemV FS: bad superblock size");
-       if (512 != sizeof (struct sysv2_super_block))
-               panic("SystemV FS: bad superblock size");
-       if (500 != sizeof (struct coh_super_block))
-               panic("Coherent FS: bad superblock size");
-       if (64 != sizeof (struct sysv_inode))
-               panic("sysv fs: bad inode size");
+       BUILD_BUG_ON(1024 != sizeof (struct xenix_super_block));
+       BUILD_BUG_ON(512 != sizeof (struct sysv4_super_block));
+       BUILD_BUG_ON(512 != sizeof (struct sysv2_super_block));
+       BUILD_BUG_ON(500 != sizeof (struct coh_super_block));
+       BUILD_BUG_ON(64 != sizeof (struct sysv_inode));
 
-       sbi = kmalloc(sizeof(struct sysv_sb_info), GFP_KERNEL);
+       sbi = kzalloc(sizeof(struct sysv_sb_info), GFP_KERNEL);
        if (!sbi)
                return -ENOMEM;
-       memset(sbi, 0, sizeof(struct sysv_sb_info));
 
        sbi->s_sb = sb;
        sbi->s_block_base = 0;
        sb->s_fs_info = sbi;
-       
+
        sb_set_blocksize(sb, BLOCK_SIZE);
 
-       for (i = 0; i < sizeof(flavours)/sizeof(flavours[0]) && !size; i++) {
+       for (i = 0; i < ARRAY_SIZE(flavours) && !size; i++) {
                brelse(bh);
                bh = sb_bread(sb, flavours[i].block);
                if (!bh)
@@ -445,10 +447,9 @@ static int v7_fill_super(struct super_block *sb, void *data, int silent)
        if (64 != sizeof (struct sysv_inode))
                panic("sysv fs: bad i-node size");
 
-       sbi = kmalloc(sizeof(struct sysv_sb_info), GFP_KERNEL);
+       sbi = kzalloc(sizeof(struct sysv_sb_info), GFP_KERNEL);
        if (!sbi)
                return -ENOMEM;
-       memset(sbi, 0, sizeof(struct sysv_sb_info));
 
        sbi->s_sb = sb;
        sbi->s_block_base = 0;
@@ -498,16 +499,17 @@ failed:
 
 /* Every kernel module contains stuff like this. */
 
-static struct super_block *sysv_get_sb(struct file_system_type *fs_type,
-       int flags, const char *dev_name, void *data)
+static int sysv_get_sb(struct file_system_type *fs_type,
+       int flags, const char *dev_name, void *data, struct vfsmount *mnt)
 {
-       return get_sb_bdev(fs_type, flags, dev_name, data, sysv_fill_super);
+       return get_sb_bdev(fs_type, flags, dev_name, data, sysv_fill_super,
+                          mnt);
 }
 
-static struct super_block *v7_get_sb(struct file_system_type *fs_type,
-       int flags, const char *dev_name, void *data)
+static int v7_get_sb(struct file_system_type *fs_type,
+       int flags, const char *dev_name, void *data, struct vfsmount *mnt)
 {
-       return get_sb_bdev(fs_type, flags, dev_name, data, v7_fill_super);
+       return get_sb_bdev(fs_type, flags, dev_name, data, v7_fill_super, mnt);
 }
 
 static struct file_system_type sysv_fs_type = {
@@ -526,9 +528,6 @@ static struct file_system_type v7_fs_type = {
        .fs_flags       = FS_REQUIRES_DEV,
 };
 
-extern int sysv_init_icache(void) __init;
-extern void sysv_destroy_icache(void);
-
 static int __init init_sysv_fs(void)
 {
        int error;