diff --git a/src/ext2_common.c b/src/ext2_common.c index 0cf36d2a..d3d557a1 100644 --- a/src/ext2_common.c +++ b/src/ext2_common.c @@ -50,23 +50,26 @@ uint64_t td_ext2fs_free_blocks_count(const struct ext2_super_block *super) int test_EXT2(const struct ext2_super_block *sb, const partition_t *partition) { + const unsigned int s_errors=le16(sb->s_errors); + const uint64_t blocks_count=td_ext2fs_blocks_count(sb); + const uint32_t s_log_block_size=le32(sb->s_log_block_size); /* There is a little offset ... */ if(le16(sb->s_magic)!=EXT2_SUPER_MAGIC) return 1; - if (td_ext2fs_free_blocks_count(sb) > td_ext2fs_blocks_count(sb)) + if (td_ext2fs_free_blocks_count(sb) > blocks_count) return 2; if (le32(sb->s_free_inodes_count) > le32(sb->s_inodes_count)) return 3; - if (le16(sb->s_errors)!=0 && - (le16(sb->s_errors) != EXT2_ERRORS_CONTINUE) && - (le16(sb->s_errors) != EXT2_ERRORS_RO) && - (le16(sb->s_errors) != EXT2_ERRORS_PANIC)) + if (s_errors!=0 && + (s_errors != EXT2_ERRORS_CONTINUE) && + (s_errors != EXT2_ERRORS_RO) && + (s_errors != EXT2_ERRORS_PANIC)) return 4; if ((le16(sb->s_state) & ~(EXT2_VALID_FS | EXT2_ERROR_FS))!=0) return 5; - if(td_ext2fs_blocks_count(sb) == 0) /* reject empty filesystem */ + if(blocks_count == 0) /* reject empty filesystem */ return 6; - switch(le32(sb->s_log_block_size)) + switch(s_log_block_size) { case 0: case 1: @@ -84,7 +87,7 @@ int test_EXT2(const struct ext2_super_block *sb, const partition_t *partition) if(partition==NULL) return 0; if(partition->part_size!=0 && - partition->part_size < td_ext2fs_blocks_count(sb) * + partition->part_size < blocks_count * (EXT2_MIN_BLOCK_SIZE<s_log_block_size))) return 8; return 0;