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