blob: e20ec981111a58363fd19a2f4f067667aade8c89 [file] [log] [blame]
Theodore Ts'o897fbaa2011-09-14 13:13:07 -04001/*
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
Theodore Ts'od1154eb2011-09-18 17:34:37 -040012#include "config.h"
Theodore Ts'o897fbaa2011-09-14 13:13:07 -040013#include <stdio.h>
14#include <unistd.h>
15#include <stdlib.h>
16
17#include "ext2_fs.h"
18
Andreas Dilger963d0f12012-03-19 23:54:03 -040019struct ext2_inode_large inode;
Theodore Ts'o897fbaa2011-09-14 13:13:07 -040020
Theodore Ts'oab3f5c52012-09-09 21:35:39 -040021#ifndef offsetof
Andreas Dilger963d0f12012-03-19 23:54:03 -040022#define offsetof(type, member) __builtin_offsetof(type, member)
Theodore Ts'oab3f5c52012-09-09 21:35:39 -040023#endif
24
Andreas Dilger963d0f12012-03-19 23:54:03 -040025#define check_field(x, s) cur_offset = do_field(#x, s, sizeof(inode.x), \
26 offsetof(struct ext2_inode_large, x), \
27 cur_offset)
Theodore Ts'o897fbaa2011-09-14 13:13:07 -040028
Andreas Dilger963d0f12012-03-19 23:54:03 -040029static int do_field(const char *field, unsigned size, unsigned cur_size,
30 unsigned offset, unsigned cur_offset)
Theodore Ts'o897fbaa2011-09-14 13:13:07 -040031{
Andreas Dilger963d0f12012-03-19 23:54:03 -040032 if (size != cur_size) {
33 printf("error: %s size %u should be %u\n",
34 field, cur_size, size);
35 exit(1);
36 }
Theodore Ts'o897fbaa2011-09-14 13:13:07 -040037 if (offset != cur_offset) {
Andreas Dilger963d0f12012-03-19 23:54:03 -040038 printf("error: %s offset %u should be %u\n",
39 field, cur_offset, offset);
Theodore Ts'o897fbaa2011-09-14 13:13:07 -040040 exit(1);
41 }
42 printf("%8d %-30s %3u\n", offset, field, (unsigned) size);
43 return offset + size;
44}
45
Andreas Dilger963d0f12012-03-19 23:54:03 -040046int main(int argc, char **argv)
Theodore Ts'o897fbaa2011-09-14 13:13:07 -040047{
48#if (__GNUC__ >= 4)
49 int cur_offset = 0;
50
51 printf("%8s %-30s %3s\n", "offset", "field", "size");
Andreas Dilger963d0f12012-03-19 23:54:03 -040052 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 /* This size will change as new fields are added */
85 do_field("Large inode end", 0, 0, cur_offset, sizeof(inode));
Theodore Ts'o897fbaa2011-09-14 13:13:07 -040086#endif
Andreas Dilger963d0f12012-03-19 23:54:03 -040087 return 0;
Theodore Ts'o897fbaa2011-09-14 13:13:07 -040088}