tst_inode_size.c revision 89efc88e65136ece22708cc28ec4124a33feeecd
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 <stdio.h> 13#include <unistd.h> 14#include <stdlib.h> 15 16#include "ext2_fs.h" 17 18struct ext2_inode inode; 19 20int verbose = 0; 21 22#define offsetof(type, member) __builtin_offsetof (type, member) 23#define check_field(x) cur_offset = do_field(#x, sizeof(inode.x), \ 24 offsetof(struct ext2_inode, x), \ 25 cur_offset) 26 27static int do_field(const char *field, size_t size, int offset, int cur_offset) 28{ 29 if (offset != cur_offset) { 30 printf("Warning! Unexpected offset at %s\n", field); 31 exit(1); 32 } 33 printf("%8d %-30s %3u\n", offset, field, (unsigned) size); 34 return offset + size; 35} 36 37void check_structure_fields() 38{ 39#if (__GNUC__ >= 4) 40 int cur_offset = 0; 41 42 printf("%8s %-30s %3s\n", "offset", "field", "size"); 43 check_field(i_mode); 44 check_field(i_uid); 45 check_field(i_size); 46 check_field(i_atime); 47 check_field(i_ctime); 48 check_field(i_mtime); 49 check_field(i_dtime); 50 check_field(i_gid); 51 check_field(i_links_count); 52 check_field(i_blocks); 53 check_field(i_flags); 54 check_field(osd1.linux1.l_i_version); 55 check_field(i_block); 56 check_field(i_generation); 57 check_field(i_file_acl); 58 check_field(i_size_high); 59 check_field(i_faddr); 60 check_field(osd2.linux2.l_i_blocks_hi); 61 check_field(osd2.linux2.l_i_file_acl_high); 62 check_field(osd2.linux2.l_i_uid_high); 63 check_field(osd2.linux2.l_i_gid_high); 64 check_field(osd2.linux2.l_i_checksum_lo); 65 check_field(osd2.linux2.l_i_reserved); 66 printf("Ending offset is %d\n\n", cur_offset); 67#endif 68} 69 70 71int main(int argc, char **argv) 72{ 73 int l = sizeof(struct ext2_inode); 74 75 check_structure_fields(); 76 printf("Size of struct ext2_inode is %d\n", l); 77 if (l != 128) { 78 exit(1); 79 } 80 exit(0); 81} 82