Theodore Ts'o | 897fbaa | 2011-09-14 13:13:07 -0400 | [diff] [blame] | 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 | |
Theodore Ts'o | d1154eb | 2011-09-18 17:34:37 -0400 | [diff] [blame] | 12 | #include "config.h" |
Theodore Ts'o | 897fbaa | 2011-09-14 13:13:07 -0400 | [diff] [blame] | 13 | #include <stdio.h> |
| 14 | #include <unistd.h> |
| 15 | #include <stdlib.h> |
| 16 | |
| 17 | #include "ext2_fs.h" |
| 18 | |
Andreas Dilger | 963d0f1 | 2012-03-19 23:54:03 -0400 | [diff] [blame] | 19 | struct ext2_inode_large inode; |
Theodore Ts'o | 897fbaa | 2011-09-14 13:13:07 -0400 | [diff] [blame] | 20 | |
Theodore Ts'o | ab3f5c5 | 2012-09-09 21:35:39 -0400 | [diff] [blame] | 21 | #ifndef offsetof |
Andreas Dilger | 963d0f1 | 2012-03-19 23:54:03 -0400 | [diff] [blame] | 22 | #define offsetof(type, member) __builtin_offsetof(type, member) |
Theodore Ts'o | ab3f5c5 | 2012-09-09 21:35:39 -0400 | [diff] [blame] | 23 | #endif |
| 24 | |
Andreas Dilger | 963d0f1 | 2012-03-19 23:54:03 -0400 | [diff] [blame] | 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) |
Theodore Ts'o | 897fbaa | 2011-09-14 13:13:07 -0400 | [diff] [blame] | 28 | |
Andreas Dilger | 963d0f1 | 2012-03-19 23:54:03 -0400 | [diff] [blame] | 29 | static int do_field(const char *field, unsigned size, unsigned cur_size, |
| 30 | unsigned offset, unsigned cur_offset) |
Theodore Ts'o | 897fbaa | 2011-09-14 13:13:07 -0400 | [diff] [blame] | 31 | { |
Andreas Dilger | 963d0f1 | 2012-03-19 23:54:03 -0400 | [diff] [blame] | 32 | 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'o | 897fbaa | 2011-09-14 13:13:07 -0400 | [diff] [blame] | 37 | if (offset != cur_offset) { |
Andreas Dilger | 963d0f1 | 2012-03-19 23:54:03 -0400 | [diff] [blame] | 38 | printf("error: %s offset %u should be %u\n", |
| 39 | field, cur_offset, offset); |
Theodore Ts'o | 897fbaa | 2011-09-14 13:13:07 -0400 | [diff] [blame] | 40 | exit(1); |
| 41 | } |
| 42 | printf("%8d %-30s %3u\n", offset, field, (unsigned) size); |
| 43 | return offset + size; |
| 44 | } |
| 45 | |
Andreas Dilger | 963d0f1 | 2012-03-19 23:54:03 -0400 | [diff] [blame] | 46 | int main(int argc, char **argv) |
Theodore Ts'o | 897fbaa | 2011-09-14 13:13:07 -0400 | [diff] [blame] | 47 | { |
| 48 | #if (__GNUC__ >= 4) |
| 49 | int cur_offset = 0; |
| 50 | |
| 51 | printf("%8s %-30s %3s\n", "offset", "field", "size"); |
Andreas Dilger | 963d0f1 | 2012-03-19 23:54:03 -0400 | [diff] [blame] | 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 | /* This size will change as new fields are added */ |
| 85 | do_field("Large inode end", 0, 0, cur_offset, sizeof(inode)); |
Theodore Ts'o | 897fbaa | 2011-09-14 13:13:07 -0400 | [diff] [blame] | 86 | #endif |
Andreas Dilger | 963d0f1 | 2012-03-19 23:54:03 -0400 | [diff] [blame] | 87 | return 0; |
Theodore Ts'o | 897fbaa | 2011-09-14 13:13:07 -0400 | [diff] [blame] | 88 | } |