From: Theodore Ts'o Date: Mon, 5 Jul 2010 18:50:17 +0000 (-0400) Subject: Enhance tst_super_size so that it checks the superblock fields as well X-Git-Tag: v1.41.13~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c5726f1ad7efedcdb24b3b362c84f0d0b402b337;p=thirdparty%2Fe2fsprogs.git Enhance tst_super_size so that it checks the superblock fields as well The test now checks to make sure the superblock fields are correctly aligned and prints them out so they can be manually checked to make sure they are where we expect them to be. Signed-off-by: "Theodore Ts'o" --- diff --git a/lib/ext2fs/tst_super_size.c b/lib/ext2fs/tst_super_size.c index 49a561ff2..606479ca0 100644 --- a/lib/ext2fs/tst_super_size.c +++ b/lib/ext2fs/tst_super_size.c @@ -15,14 +15,127 @@ #include "ext2_fs.h" +#define sb_struct ext2_super_block +#define sb_struct_name "ext2_super_block" + +struct sb_struct sb; + +int verbose = 0; + +#define offsetof(type, member) __builtin_offsetof (type, member) +#define check_field(x) cur_offset = do_field(#x, sizeof(sb.x), \ + offsetof(struct sb_struct, x), \ + cur_offset) + +static int do_field(const char *field, size_t size, int offset, int cur_offset) +{ + if (offset != cur_offset) { + printf("Warning! Unexpected offset at %s\n", field); + exit(1); + } + printf("%8d %-30s %3u\n", offset, field, (unsigned) size); + return offset + size; +} + +void check_superblock_fields() +{ +#if (__GNUC__ >= 4) + int cur_offset = 0; + + printf("%8s %-30s %3s\n", "offset", "field", "size"); + check_field(s_inodes_count); + check_field(s_blocks_count); + check_field(s_r_blocks_count); + check_field(s_free_blocks_count); + check_field(s_free_inodes_count); + check_field(s_first_data_block); + check_field(s_log_block_size); + check_field(s_log_frag_size); + check_field(s_blocks_per_group); + check_field(s_frags_per_group); + check_field(s_inodes_per_group); + check_field(s_mtime); + check_field(s_wtime); + check_field(s_mnt_count); + check_field(s_max_mnt_count); + check_field(s_magic); + check_field(s_state); + check_field(s_errors); + check_field(s_minor_rev_level); + check_field(s_lastcheck); + check_field(s_checkinterval); + check_field(s_creator_os); + check_field(s_rev_level); + check_field(s_def_resuid); + check_field(s_def_resgid); + check_field(s_first_ino); + check_field(s_inode_size); + check_field(s_block_group_nr); + check_field(s_feature_compat); + check_field(s_feature_incompat); + check_field(s_feature_ro_compat); + check_field(s_uuid); + check_field(s_volume_name); + check_field(s_last_mounted); + check_field(s_algorithm_usage_bitmap); + check_field(s_prealloc_blocks); + check_field(s_prealloc_dir_blocks); + check_field(s_reserved_gdt_blocks); + check_field(s_journal_uuid); + check_field(s_journal_inum); + check_field(s_journal_dev); + check_field(s_last_orphan); + check_field(s_hash_seed); + check_field(s_def_hash_version); + check_field(s_jnl_backup_type); + check_field(s_desc_size); + check_field(s_default_mount_opts); + check_field(s_first_meta_bg); + check_field(s_mkfs_time); + check_field(s_jnl_blocks); + check_field(s_blocks_count_hi); + check_field(s_r_blocks_count_hi); + check_field(s_free_blocks_hi); + check_field(s_min_extra_isize); + check_field(s_want_extra_isize); + check_field(s_flags); + check_field(s_raid_stride); + check_field(s_mmp_interval); + check_field(s_mmp_block); + check_field(s_raid_stripe_width); + check_field(s_log_groups_per_flex); + check_field(s_reserved_char_pad); + check_field(s_reserved_pad); + check_field(s_kbytes_written); + check_field(s_snapshot_inum); + check_field(s_snapshot_id); + check_field(s_snapshot_r_blocks_count); + check_field(s_snapshot_list); + check_field(s_error_count); + check_field(s_first_error_time); + check_field(s_first_error_ino); + check_field(s_first_error_block); + check_field(s_first_error_func); + check_field(s_first_error_line); + check_field(s_last_error_time); + check_field(s_last_error_ino); + check_field(s_last_error_line); + check_field(s_last_error_block); + check_field(s_last_error_func); + check_field(s_reserved); + printf("Ending offset is %d\n\n", cur_offset); +#endif +} + + int main(int argc, char **argv) { - int s = sizeof(struct ext2_super_block); + int s = sizeof(struct sb_struct); - printf("Size of struct ext2_super_block is %d\n", s); + check_superblock_fields(); + printf("Size of struct %s is %d\n", sb_struct_name, s); if (s != 1024) { exit(1); } exit(0); } -