1 /*
2 * This testing program makes sure the ext2_inode structure 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 struct ext2_inode_large inode;
19
20 #ifndef offsetof
21 #define offsetof(type, member) __builtin_offsetof(type, member)
22 #endif
23
24 #define check_field(x, s) cur_offset = do_field(#x, s, sizeof(inode.x), \
25 offsetof(struct ext2_inode_large, x), \
26 cur_offset)
27
do_field(const char * field,unsigned size,unsigned cur_size,unsigned offset,unsigned cur_offset)28 static int do_field(const char *field, unsigned size, unsigned cur_size,
29 unsigned offset, unsigned cur_offset)
30 {
31 if (size != cur_size) {
32 printf("error: %s size %u should be %u\n",
33 field, cur_size, size);
34 exit(1);
35 }
36 if (offset != cur_offset) {
37 printf("error: %s offset %u should be %u\n",
38 field, cur_offset, offset);
39 exit(1);
40 }
41 printf("%8d %-30s %3u\n", offset, field, (unsigned) size);
42 return offset + size;
43 }
44
main(int argc,char ** argv)45 int main(int argc, char **argv)
46 {
47 #if (__GNUC__ >= 4)
48 int cur_offset = 0;
49
50 printf("%8s %-30s %3s\n", "offset", "field", "size");
51 check_field(i_mode, 2);
52 check_field(i_uid, 2);
53 check_field(i_size, 4);
54 check_field(i_atime, 4);
55 check_field(i_ctime, 4);
56 check_field(i_mtime, 4);
57 check_field(i_dtime, 4);
58 check_field(i_gid, 2);
59 check_field(i_links_count, 2);
60 check_field(i_blocks, 4);
61 check_field(i_flags, 4);
62 check_field(osd1.linux1.l_i_version, 4);
63 check_field(i_block, 15 * 4);
64 check_field(i_generation, 4);
65 check_field(i_file_acl, 4);
66 check_field(i_size_high, 4);
67 check_field(i_faddr, 4);
68 check_field(osd2.linux2.l_i_blocks_hi, 2);
69 check_field(osd2.linux2.l_i_file_acl_high, 2);
70 check_field(osd2.linux2.l_i_uid_high, 2);
71 check_field(osd2.linux2.l_i_gid_high, 2);
72 check_field(osd2.linux2.l_i_checksum_lo, 2);
73 check_field(osd2.linux2.l_i_reserved, 2);
74 do_field("Small inode end", 0, 0, cur_offset, 128);
75 check_field(i_extra_isize, 2);
76 check_field(i_checksum_hi, 2);
77 check_field(i_ctime_extra, 4);
78 check_field(i_mtime_extra, 4);
79 check_field(i_atime_extra, 4);
80 check_field(i_crtime, 4);
81 check_field(i_crtime_extra, 4);
82 check_field(i_version_hi, 4);
83 /* This size will change as new fields are added */
84 do_field("Large inode end", 0, 0, cur_offset, sizeof(inode));
85 #endif
86 return 0;
87 }
88