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