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