1*6a54128fSAndroid Build Coastguard Worker /*
2*6a54128fSAndroid Build Coastguard Worker * This testing program checks the offset of the ext2_filsys structure
3*6a54128fSAndroid Build Coastguard Worker *
4*6a54128fSAndroid Build Coastguard Worker * Copyright (C) 2007 by Theodore Ts'o.
5*6a54128fSAndroid Build Coastguard Worker *
6*6a54128fSAndroid Build Coastguard Worker * %Begin-Header%
7*6a54128fSAndroid Build Coastguard Worker * This file may be redistributed under the terms of the GNU Library
8*6a54128fSAndroid Build Coastguard Worker * General Public License, version 2.
9*6a54128fSAndroid Build Coastguard Worker * %End-Header%
10*6a54128fSAndroid Build Coastguard Worker */
11*6a54128fSAndroid Build Coastguard Worker
12*6a54128fSAndroid Build Coastguard Worker #include <stdio.h>
13*6a54128fSAndroid Build Coastguard Worker #include <unistd.h>
14*6a54128fSAndroid Build Coastguard Worker #include <stdlib.h>
15*6a54128fSAndroid Build Coastguard Worker
16*6a54128fSAndroid Build Coastguard Worker #include "ext2fs.h"
17*6a54128fSAndroid Build Coastguard Worker
18*6a54128fSAndroid Build Coastguard Worker struct struct_ext2_filsys fs;
19*6a54128fSAndroid Build Coastguard Worker
20*6a54128fSAndroid Build Coastguard Worker #ifndef offsetof
21*6a54128fSAndroid Build Coastguard Worker #define offsetof(type, member) __builtin_offsetof (type, member)
22*6a54128fSAndroid Build Coastguard Worker #endif
23*6a54128fSAndroid Build Coastguard Worker #define check_field(x) cur_offset = do_field(#x, sizeof(fs.x), \
24*6a54128fSAndroid Build Coastguard Worker offsetof(struct struct_ext2_filsys, x), \
25*6a54128fSAndroid Build Coastguard Worker cur_offset)
26*6a54128fSAndroid Build Coastguard Worker
do_field(const char * field,size_t size,int offset,int cur_offset)27*6a54128fSAndroid Build Coastguard Worker static int do_field(const char *field, size_t size, int offset, int cur_offset)
28*6a54128fSAndroid Build Coastguard Worker {
29*6a54128fSAndroid Build Coastguard Worker if (offset != cur_offset) {
30*6a54128fSAndroid Build Coastguard Worker printf("\t(padding %d bytes?)\n", offset - cur_offset);
31*6a54128fSAndroid Build Coastguard Worker }
32*6a54128fSAndroid Build Coastguard Worker printf("%8d %-30s %3u\n", offset, field, (unsigned) size);
33*6a54128fSAndroid Build Coastguard Worker return offset + size;
34*6a54128fSAndroid Build Coastguard Worker }
35*6a54128fSAndroid Build Coastguard Worker
main(int argc,char ** argv)36*6a54128fSAndroid Build Coastguard Worker int main(int argc, char **argv)
37*6a54128fSAndroid Build Coastguard Worker {
38*6a54128fSAndroid Build Coastguard Worker #if (__GNUC__ >= 4)
39*6a54128fSAndroid Build Coastguard Worker int cur_offset = 0;
40*6a54128fSAndroid Build Coastguard Worker
41*6a54128fSAndroid Build Coastguard Worker printf("%8s %-30s %3s\n", "offset", "field", "size");
42*6a54128fSAndroid Build Coastguard Worker check_field(magic);
43*6a54128fSAndroid Build Coastguard Worker check_field(io);
44*6a54128fSAndroid Build Coastguard Worker check_field(flags);
45*6a54128fSAndroid Build Coastguard Worker check_field(device_name);
46*6a54128fSAndroid Build Coastguard Worker check_field(super);
47*6a54128fSAndroid Build Coastguard Worker check_field(blocksize);
48*6a54128fSAndroid Build Coastguard Worker check_field(fragsize);
49*6a54128fSAndroid Build Coastguard Worker check_field(group_desc_count);
50*6a54128fSAndroid Build Coastguard Worker check_field(desc_blocks);
51*6a54128fSAndroid Build Coastguard Worker check_field(group_desc);
52*6a54128fSAndroid Build Coastguard Worker check_field(inode_blocks_per_group);
53*6a54128fSAndroid Build Coastguard Worker check_field(inode_map);
54*6a54128fSAndroid Build Coastguard Worker check_field(block_map);
55*6a54128fSAndroid Build Coastguard Worker check_field(get_blocks);
56*6a54128fSAndroid Build Coastguard Worker check_field(check_directory);
57*6a54128fSAndroid Build Coastguard Worker check_field(write_bitmaps);
58*6a54128fSAndroid Build Coastguard Worker check_field(read_inode);
59*6a54128fSAndroid Build Coastguard Worker check_field(write_inode);
60*6a54128fSAndroid Build Coastguard Worker check_field(badblocks);
61*6a54128fSAndroid Build Coastguard Worker check_field(dblist);
62*6a54128fSAndroid Build Coastguard Worker check_field(stride);
63*6a54128fSAndroid Build Coastguard Worker check_field(orig_super);
64*6a54128fSAndroid Build Coastguard Worker check_field(image_header);
65*6a54128fSAndroid Build Coastguard Worker check_field(umask);
66*6a54128fSAndroid Build Coastguard Worker check_field(now);
67*6a54128fSAndroid Build Coastguard Worker check_field(cluster_ratio_bits);
68*6a54128fSAndroid Build Coastguard Worker check_field(reserved);
69*6a54128fSAndroid Build Coastguard Worker check_field(priv_data);
70*6a54128fSAndroid Build Coastguard Worker check_field(icache);
71*6a54128fSAndroid Build Coastguard Worker check_field(image_io);
72*6a54128fSAndroid Build Coastguard Worker check_field(get_alloc_block);
73*6a54128fSAndroid Build Coastguard Worker check_field(block_alloc_stats);
74*6a54128fSAndroid Build Coastguard Worker check_field(mmp_buf);
75*6a54128fSAndroid Build Coastguard Worker check_field(mmp_cmp);
76*6a54128fSAndroid Build Coastguard Worker check_field(mmp_fd);
77*6a54128fSAndroid Build Coastguard Worker check_field(mmp_last_written);
78*6a54128fSAndroid Build Coastguard Worker printf("Ending offset is %d\n\n", cur_offset);
79*6a54128fSAndroid Build Coastguard Worker #endif
80*6a54128fSAndroid Build Coastguard Worker exit(0);
81*6a54128fSAndroid Build Coastguard Worker }
82