From 8203fe506a06524587c18940b6cd19a0592a4bd2 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Thu, 23 Apr 2009 01:30:42 -0400 Subject: [PATCH] libext2fs: read the block group descriptors more efficiently When opening a filesystem, make ext2fs_open2() much more efficient by reading the normal block group descriptors all at once, instead of one block at a time. Signed-off-by: "Theodore Ts'o" --- lib/ext2fs/openfs.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c index f6fe3f0..1ca63db 100644 --- a/lib/ext2fs/openfs.c +++ b/lib/ext2fs/openfs.c @@ -84,7 +84,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, { ext2_filsys fs; errcode_t retval; - unsigned long i; + unsigned long i, first_meta_bg; __u32 features; int groups_per_block, blocks_per_group, io_flags; blk_t group_block, blk; @@ -304,7 +304,23 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, group_block = fs->super->s_first_data_block; dest = (char *) fs->group_desc; groups_per_block = EXT2_DESC_PER_BLOCK(fs->super); - for (i=0 ; i < fs->desc_blocks; i++) { + if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) + first_meta_bg = fs->super->s_first_meta_bg; + else + first_meta_bg = fs->desc_blocks; + if (first_meta_bg) { + retval = io_channel_read_blk(fs->io, group_block+1, + first_meta_bg, dest); + if (retval) + goto cleanup; +#ifdef WORDS_BIGENDIAN + gdp = (struct ext2_group_desc *) dest; + for (j=0; j < groups_per_block*first_meta_bg; j++) + ext2fs_swap_group_desc(gdp++); +#endif + dest += fs->blocksize*first_meta_bg; + } + for (i=first_meta_bg ; i < fs->desc_blocks; i++) { blk = ext2fs_descriptor_block_loc(fs, group_block, i); retval = io_channel_read_blk(fs->io, blk, 1, dest); if (retval) -- 1.8.3.1