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