From: Liu Aleaxander Date: Fri, 20 Nov 2009 05:53:45 +0000 (+0800) Subject: EXTLINUX: simplify the ext2_fs_init function X-Git-Tag: syslinux-4.00-pre9~2^2~11 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fbd988fa9f5d35b34e7b5431e17fc06da48d9995;p=profile%2Fivi%2Fsyslinux.git EXTLINUX: simplify the ext2_fs_init function And also simplified the ext2_sb_info structure. Signed-off-by: Liu Aleaxander --- diff --git a/core/fs/ext2/ext2.c b/core/fs/ext2/ext2.c index 385cacf..799f1db 100644 --- a/core/fs/ext2/ext2.c +++ b/core/fs/ext2/ext2.c @@ -378,7 +378,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 *esb; + struct ext2_super_block sb; int block_size; int block_shift; int db_count; @@ -386,15 +386,8 @@ static int ext2_fs_init(struct fs_info *fs) int desc_block; char *desc_buffer; - esb = malloc(sizeof(struct ext2_super_block)); - if (!esb) { - malloc_error("ext2_super_block structure"); - return -1; - } - /* read the super block */ - disk->rdwr_sectors(disk, esb, 2, 2, 0); - + disk->rdwr_sectors(disk, &sb, 2, 2, 0); sbi = malloc(sizeof(*sbi)); if (!sbi) { @@ -402,35 +395,31 @@ static int ext2_fs_init(struct fs_info *fs) return -1; } fs->fs_info = sbi; - sbi->s_es = esb; - if (esb->s_magic != EXT2_SUPER_MAGIC) { - printf("ext2 mount error: can't found ext2 file system!\n"); + if (sb.s_magic != EXT2_SUPER_MAGIC) { + printf("ext2 mount error: it's not a EXT2/3/4 file system!\n"); return 0; } - block_shift = esb->s_log_block_size + 10; + block_shift = sb.s_log_block_size + 10; block_size = 1 << block_shift; fs->blk_bits = block_shift - SECTOR_SHIFT; - - sbi->s_inodes_per_group = esb->s_inodes_per_group; - sbi->s_blocks_per_group = esb->s_blocks_per_group; - sbi->s_inodes_per_block = block_size / esb->s_inode_size; - sbi->s_itb_per_group = sbi->s_inodes_per_group / - sbi->s_inodes_per_block; - if (esb->s_desc_size < sizeof(struct ext2_group_desc)) - esb->s_desc_size = sizeof(struct ext2_group_desc); - sbi->s_desc_per_block = block_size / esb->s_desc_size; - sbi->s_groups_count = (esb->s_blocks_count - esb->s_first_data_block + + sbi->s_inodes_per_group = sb.s_inodes_per_group; + sbi->s_blocks_per_group = sb.s_blocks_per_group; + sbi->s_inodes_per_block = block_size / sb.s_inode_size; + if (sb.s_desc_size < sizeof(struct ext2_group_desc)) + sb.s_desc_size = sizeof(struct ext2_group_desc); + sbi->s_desc_per_block = block_size / sb.s_desc_size; + sbi->s_groups_count = (sb.s_blocks_count - sb.s_first_data_block + EXT2_BLOCKS_PER_GROUP(fs) - 1) / EXT2_BLOCKS_PER_GROUP(fs); db_count = (sbi->s_groups_count + EXT2_DESC_PER_BLOCK(fs) - 1) / EXT2_DESC_PER_BLOCK(fs); - sbi->s_gdb_count = db_count; - sbi->s_inode_size = esb->s_inode_size; + sbi->s_inode_size = sb.s_inode_size; /* read the descpritors */ - desc_block = esb->s_first_data_block + 1; + desc_block = sb.s_first_data_block + 1; desc_buffer = malloc(db_count * block_size); if (!desc_buffer) { malloc_error("desc_buffer"); @@ -446,7 +435,7 @@ static int ext2_fs_init(struct fs_info *fs) } for (i = 0; i < (int)sbi->s_groups_count; i++) { sbi->s_group_desc[i] = (struct ext2_group_desc *)desc_buffer; - desc_buffer += esb->s_desc_size; + desc_buffer += sb.s_desc_size; } return block_shift; diff --git a/core/fs/ext2/ext2_fs.h b/core/fs/ext2/ext2_fs.h index 0df983b..0249ee1 100644 --- a/core/fs/ext2/ext2_fs.h +++ b/core/fs/ext2/ext2_fs.h @@ -270,24 +270,19 @@ struct ext4_extent_header { * The ext2 super block information in memory */ struct ext2_sb_info { - uint32_t s_inodes_per_block;/* Number of inodes per block */ - uint32_t s_blocks_per_group;/* Number of blocks in a group */ - uint32_t s_inodes_per_group;/* Number of inodes in a group */ - uint32_t s_itb_per_group; /* Number of inode table blocks per group */ - uint32_t s_gdb_count; /* Number of group descriptor blocks */ - uint32_t s_desc_per_block; /* Number of group descriptors per block */ - uint32_t s_groups_count; /* Number of groups in the fs */ - int s_addr_per_block_bits; - int s_desc_per_block_bits; - int s_inode_size; - int s_first_ino; - struct ext2_super_block * s_es; - /* - * Here did not like Linux Kernel did; the group descriptor cache - * here is based on ext2_group_desc structure, instead of buffer - * head structure in Linux Kernel, where cache one block data. - */ - struct ext2_group_desc ** s_group_desc; + uint32_t s_inodes_per_block;/* Number of inodes per block */ + uint32_t s_inodes_per_group;/* Number of inodes in a group */ + uint32_t s_blocks_per_group;/* Number of blocks in a group */ + uint32_t s_desc_per_block; /* Number of group descriptors per block */ + uint32_t s_groups_count; /* Number of groups in the fs */ + int s_inode_size; + + /* + * Here did not like Linux Kernel did; the group descriptor cache + * here is based on ext2_group_desc structure, instead of buffer + * head structure in Linux Kernel, where cache one block data. + */ + struct ext2_group_desc ** s_group_desc; }; static inline struct ext2_sb_info *EXT2_SB(struct fs_info *fs) diff --git a/core/include/fs.h b/core/include/fs.h index 28b6679..72138be 100644 --- a/core/include/fs.h +++ b/core/include/fs.h @@ -23,8 +23,8 @@ struct fs_info { const struct fs_ops *fs_ops; struct device *fs_dev; - void *fs_info; /* The fs-specific information */ - int blk_bits; /* block_size = 1 << (blk_bits + SECTOR_SHIFT */ + void *fs_info; /* The fs-specific information */ + int blk_bits; /* block_size = 1 << (blk_bits + SECTOR_SHIFT) */ }; extern struct fs_info *this_fs;