| 59 | } |
| 60 | |
| 61 | int test_EXT2(const struct ext2_super_block *sb, const partition_t *partition) |
| 62 | { |
| 63 | const unsigned int s_errors=le16(sb->s_errors); |
| 64 | const uint64_t blocks_count=td_ext2fs_blocks_count(sb); |
| 65 | const uint32_t s_log_block_size=le32(sb->s_log_block_size); |
| 66 | /* There is a little offset ... */ |
| 67 | if(le16(sb->s_magic)!=EXT2_SUPER_MAGIC) |
| 68 | return 1; |
| 69 | if (td_ext2fs_free_blocks_count(sb) > blocks_count) |
| 70 | return 2; |
| 71 | if (le32(sb->s_free_inodes_count) > le32(sb->s_inodes_count)) |
| 72 | return 3; |
| 73 | if (s_errors!=0 && |
| 74 | (s_errors != EXT2_ERRORS_CONTINUE) && |
| 75 | (s_errors != EXT2_ERRORS_RO) && |
| 76 | (s_errors != EXT2_ERRORS_PANIC)) |
| 77 | return 4; |
| 78 | if ((le16(sb->s_state) & ~(EXT2_VALID_FS | EXT2_ERROR_FS))!=0) |
| 79 | return 5; |
| 80 | if(blocks_count == 0) /* reject empty filesystem */ |
| 81 | return 6; |
| 82 | switch(s_log_block_size) |
| 83 | { |
| 84 | case 0: |
| 85 | case 1: |
| 86 | case 2: /* block size = 4096 (default) */ |
| 87 | case 3: /* can be 8192 on alpha */ |
| 88 | case 4: /* non standard blocksize */ |
| 89 | case 5: /* non standard blocksize */ |
| 90 | case 6: /* 64 KiB */ |
| 91 | break; |
| 92 | default: |
| 93 | return 7; |
| 94 | } |
| 95 | /*@ assert 0 <= s_log_block_size <= 6; */ |
| 96 | if(le32(sb->s_blocks_per_group)==0) |
| 97 | return 8; |
| 98 | if(partition==NULL) |
| 99 | return 0; |
| 100 | /*@ assert 0 <= EXT2_MIN_BLOCK_SIZE<<s_log_block_size <= EXT2_MIN_BLOCK_SIZE<<6; */ |
| 101 | /*@ assert 0 ≤ 64-10-s_log_block_size ≤ 64-10-6; */ ; |
| 102 | if(blocks_count >= (uint64_t)1 << (64-10-s_log_block_size)) |
| 103 | return 9; |
| 104 | /*@ assert blocks_count < 1 << (64-10-s_log_block_size); */ |
| 105 | if(partition->part_size!=0 && |
| 106 | partition->part_size < blocks_count * ((uint64_t)EXT2_MIN_BLOCK_SIZE<<s_log_block_size)) |
| 107 | return 8; |
| 108 | return 0; |
| 109 | } |
no test coverage detected