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