fs: move cache_init() into fs_init, to handle special needs
authorH. Peter Anvin <hpa@zytor.com>
Tue, 16 Feb 2010 20:22:12 +0000 (12:22 -0800)
committerH. Peter Anvin <hpa@zytor.com>
Tue, 16 Feb 2010 20:22:12 +0000 (12:22 -0800)
Move cache_init() into the fs_init methods, to accommodate special
handling, e.g. the all-zero zero block for ext2.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
core/fs/btrfs/btrfs.c
core/fs/ext2/ext2.c
core/fs/fat/fat.c
core/fs/iso9660/iso9660.c

index 5557c87..4389302 100644 (file)
@@ -691,8 +691,15 @@ static void btrfs_get_fs_tree(void)
 /* init. the fs meta data, return the block size shift bits. */
 static int btrfs_fs_init(struct fs_info *_fs)
 {
+       struct disk *disk = fs->fs_dev->disk;
+    
        btrfs_init_crc32c();
 
+       fs->sector_shift = disk->sector_shift;
+       fs->sector_size  = 1 << fs->sector_shift;
+       fs->block_shift  = BTRFS_BLOCK_SHIFT;
+       fs->block_size   = 1 << fs->block_shift;
+
        fs = _fs;
        btrfs_read_super_block();
        if (strncmp((char *)(&sb.magic), BTRFS_MAGIC, sizeof(sb.magic)))
@@ -702,7 +709,11 @@ static int btrfs_fs_init(struct fs_info *_fs)
        btrfs_get_fs_tree();
        btrfs_set_cwd();
        cache_ready = 1;
-       return BTRFS_BLOCK_SHIFT;/* to determine cache size */
+
+       /* Initialize the block cache */
+       cache_init(fs->fs_dev, fs->block_size);
+
+       return fs->block_size;
 }
 
 const struct fs_ops btrfs_fs_ops = {
index 020cefe..fcf5cb9 100644 (file)
@@ -358,6 +358,7 @@ static int ext2_fs_init(struct fs_info *fs)
     struct disk *disk = fs->fs_dev->disk;
     struct ext2_sb_info *sbi;
     struct ext2_super_block sb;
+    struct cache *cs;
 
     /* read the super block */
     disk->rdwr_sectors(disk, &sb, 2, 2, 0);
@@ -395,6 +396,12 @@ static int ext2_fs_init(struct fs_info *fs)
     sbi->s_first_data_block = sb.s_first_data_block;
     sbi->s_inode_size = sb.s_inode_size;
 
+    /* Initialize the cache, and force block zero to all zero */
+    cache_init(fs->fs_dev, fs->block_shift);
+    cs = _get_cache_block(fs->fs_dev, 0);
+    memset(cs->data, 0, fs->block_size);
+    cache_lock_block(cs);
+
     return fs->block_shift;
 }
 
index bea6a89..ba4ae1a 100644 (file)
@@ -824,8 +824,10 @@ static int vfat_fs_init(struct fs_info *fs)
     }
     sbi->clusters = clusters;
 
-    /* for SYSLINUX, the cache is based on sector size */
-    return fs->sector_shift;
+    /* Initialize the cache */
+    cache_init(fs->fs_dev, fs->block_shift);
+
+    return fs->block_shift;
 }
 
 const struct fs_ops vfat_fs_ops = {
index a7c70a3..6186041 100644 (file)
@@ -423,6 +423,9 @@ static int iso_fs_init(struct fs_info *fs)
     fs->sector_size  = 1 << fs->sector_shift;
     fs->block_size   = 1 << fs->block_shift;
 
+    /* Initialize the cache */
+    cache_init(fs->fs_dev, fs->block_shift);
+
     return fs->block_shift;
 }