Theodore Ts'o | a2b2ff6 | 2007-05-31 12:39:02 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This testing program makes sure superblock size is 1024 bytes long |
| 3 | * |
| 4 | * Copyright (C) 2007 by Theodore Ts'o. |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 5 | * |
Theodore Ts'o | a2b2ff6 | 2007-05-31 12:39:02 -0400 | [diff] [blame] | 6 | * %Begin-Header% |
Theodore Ts'o | 543547a | 2010-05-17 21:31:56 -0400 | [diff] [blame] | 7 | * This file may be redistributed under the terms of the GNU Library |
| 8 | * General Public License, version 2. |
Theodore Ts'o | a2b2ff6 | 2007-05-31 12:39:02 -0400 | [diff] [blame] | 9 | * %End-Header% |
| 10 | */ |
| 11 | |
Theodore Ts'o | d1154eb | 2011-09-18 17:34:37 -0400 | [diff] [blame] | 12 | #include "config.h" |
Theodore Ts'o | a2b2ff6 | 2007-05-31 12:39:02 -0400 | [diff] [blame] | 13 | #include <stdio.h> |
| 14 | #include <unistd.h> |
| 15 | #include <stdlib.h> |
| 16 | |
| 17 | #include "ext2_fs.h" |
| 18 | |
Theodore Ts'o | c5726f1 | 2010-07-05 14:50:17 -0400 | [diff] [blame] | 19 | #define sb_struct ext2_super_block |
| 20 | #define sb_struct_name "ext2_super_block" |
| 21 | |
| 22 | struct sb_struct sb; |
| 23 | |
Theodore Ts'o | ab3f5c5 | 2012-09-09 21:35:39 -0400 | [diff] [blame] | 24 | #ifndef offsetof |
Theodore Ts'o | c5726f1 | 2010-07-05 14:50:17 -0400 | [diff] [blame] | 25 | #define offsetof(type, member) __builtin_offsetof (type, member) |
Theodore Ts'o | ab3f5c5 | 2012-09-09 21:35:39 -0400 | [diff] [blame] | 26 | #endif |
| 27 | |
Andreas Dilger | 963d0f1 | 2012-03-19 23:54:03 -0400 | [diff] [blame] | 28 | #define check_field(x, s) cur_offset = do_field(#x, s, sizeof(sb.x), \ |
| 29 | offsetof(struct sb_struct, x), \ |
| 30 | cur_offset) |
Theodore Ts'o | c5726f1 | 2010-07-05 14:50:17 -0400 | [diff] [blame] | 31 | |
Andreas Dilger | 963d0f1 | 2012-03-19 23:54:03 -0400 | [diff] [blame] | 32 | static int do_field(const char *field, unsigned size, unsigned cur_size, |
| 33 | unsigned offset, unsigned cur_offset) |
Theodore Ts'o | c5726f1 | 2010-07-05 14:50:17 -0400 | [diff] [blame] | 34 | { |
Andreas Dilger | 963d0f1 | 2012-03-19 23:54:03 -0400 | [diff] [blame] | 35 | if (size != cur_size) { |
| 36 | printf("error: %s size %u should be %u\n", |
| 37 | field, cur_size, size); |
Theodore Ts'o | c5726f1 | 2010-07-05 14:50:17 -0400 | [diff] [blame] | 38 | exit(1); |
| 39 | } |
Andreas Dilger | 963d0f1 | 2012-03-19 23:54:03 -0400 | [diff] [blame] | 40 | if (offset != cur_offset) { |
| 41 | printf("error: %s offset %u should be %u\n", |
| 42 | field, cur_offset, offset); |
| 43 | exit(1); |
| 44 | } |
| 45 | printf("%8d %-30s %3u\n", offset, field, size); |
Theodore Ts'o | c5726f1 | 2010-07-05 14:50:17 -0400 | [diff] [blame] | 46 | return offset + size; |
| 47 | } |
| 48 | |
Andreas Dilger | 963d0f1 | 2012-03-19 23:54:03 -0400 | [diff] [blame] | 49 | int main(int argc, char **argv) |
Theodore Ts'o | c5726f1 | 2010-07-05 14:50:17 -0400 | [diff] [blame] | 50 | { |
| 51 | #if (__GNUC__ >= 4) |
| 52 | int cur_offset = 0; |
| 53 | |
| 54 | printf("%8s %-30s %3s\n", "offset", "field", "size"); |
Andreas Dilger | 963d0f1 | 2012-03-19 23:54:03 -0400 | [diff] [blame] | 55 | check_field(s_inodes_count, 4); |
| 56 | check_field(s_blocks_count, 4); |
| 57 | check_field(s_r_blocks_count, 4); |
| 58 | check_field(s_free_blocks_count, 4); |
| 59 | check_field(s_free_inodes_count, 4); |
| 60 | check_field(s_first_data_block, 4); |
| 61 | check_field(s_log_block_size, 4); |
| 62 | check_field(s_log_cluster_size, 4); |
| 63 | check_field(s_blocks_per_group, 4); |
| 64 | check_field(s_clusters_per_group, 4); |
| 65 | check_field(s_inodes_per_group, 4); |
| 66 | check_field(s_mtime, 4); |
| 67 | check_field(s_wtime, 4); |
| 68 | check_field(s_mnt_count, 2); |
| 69 | check_field(s_max_mnt_count, 2); |
| 70 | check_field(s_magic, 2); |
| 71 | check_field(s_state, 2); |
| 72 | check_field(s_errors, 2); |
| 73 | check_field(s_minor_rev_level, 2); |
| 74 | check_field(s_lastcheck, 4); |
| 75 | check_field(s_checkinterval, 4); |
| 76 | check_field(s_creator_os, 4); |
| 77 | check_field(s_rev_level, 4); |
| 78 | check_field(s_def_resuid, 2); |
| 79 | check_field(s_def_resgid, 2); |
| 80 | check_field(s_first_ino, 4); |
| 81 | check_field(s_inode_size, 2); |
| 82 | check_field(s_block_group_nr, 2); |
| 83 | check_field(s_feature_compat, 4); |
| 84 | check_field(s_feature_incompat, 4); |
| 85 | check_field(s_feature_ro_compat, 4); |
| 86 | check_field(s_uuid, 16); |
| 87 | check_field(s_volume_name, 16); |
| 88 | check_field(s_last_mounted, 64); |
| 89 | check_field(s_algorithm_usage_bitmap, 4); |
| 90 | check_field(s_prealloc_blocks, 1); |
| 91 | check_field(s_prealloc_dir_blocks, 1); |
| 92 | check_field(s_reserved_gdt_blocks, 2); |
| 93 | check_field(s_journal_uuid, 16); |
| 94 | check_field(s_journal_inum, 4); |
| 95 | check_field(s_journal_dev, 4); |
| 96 | check_field(s_last_orphan, 4); |
| 97 | check_field(s_hash_seed, 4 * 4); |
| 98 | check_field(s_def_hash_version, 1); |
| 99 | check_field(s_jnl_backup_type, 1); |
| 100 | check_field(s_desc_size, 2); |
| 101 | check_field(s_default_mount_opts, 4); |
| 102 | check_field(s_first_meta_bg, 4); |
| 103 | check_field(s_mkfs_time, 4); |
| 104 | check_field(s_jnl_blocks, 17 * 4); |
| 105 | check_field(s_blocks_count_hi, 4); |
| 106 | check_field(s_r_blocks_count_hi, 4); |
| 107 | check_field(s_free_blocks_hi, 4); |
| 108 | check_field(s_min_extra_isize, 2); |
| 109 | check_field(s_want_extra_isize, 2); |
| 110 | check_field(s_flags, 4); |
| 111 | check_field(s_raid_stride, 2); |
| 112 | check_field(s_mmp_update_interval, 2); |
| 113 | check_field(s_mmp_block, 8); |
| 114 | check_field(s_raid_stripe_width, 4); |
| 115 | check_field(s_log_groups_per_flex, 1); |
| 116 | check_field(s_reserved_char_pad, 1); |
| 117 | check_field(s_reserved_pad, 2); |
| 118 | check_field(s_kbytes_written, 8); |
| 119 | check_field(s_snapshot_inum, 4); |
| 120 | check_field(s_snapshot_id, 4); |
| 121 | check_field(s_snapshot_r_blocks_count, 8); |
| 122 | check_field(s_snapshot_list, 4); |
| 123 | check_field(s_error_count, 4); |
| 124 | check_field(s_first_error_time, 4); |
| 125 | check_field(s_first_error_ino, 4); |
| 126 | check_field(s_first_error_block, 8); |
| 127 | check_field(s_first_error_func, 32); |
| 128 | check_field(s_first_error_line, 4); |
| 129 | check_field(s_last_error_time, 4); |
| 130 | check_field(s_last_error_ino, 4); |
| 131 | check_field(s_last_error_line, 4); |
| 132 | check_field(s_last_error_block, 8); |
| 133 | check_field(s_last_error_func, 32); |
| 134 | check_field(s_mount_opts, 64); |
| 135 | check_field(s_usr_quota_inum, 4); |
| 136 | check_field(s_grp_quota_inum, 4); |
| 137 | check_field(s_overhead_blocks, 4); |
| 138 | check_field(s_reserved, 108 * 4); |
| 139 | check_field(s_checksum, 4); |
| 140 | do_field("Superblock end", 0, 0, cur_offset, 1024); |
Theodore Ts'o | c5726f1 | 2010-07-05 14:50:17 -0400 | [diff] [blame] | 141 | #endif |
Andreas Dilger | 963d0f1 | 2012-03-19 23:54:03 -0400 | [diff] [blame] | 142 | return 0; |
Theodore Ts'o | a2b2ff6 | 2007-05-31 12:39:02 -0400 | [diff] [blame] | 143 | } |