From 930d7a7fb777c4558b5417ae00a4cf57b10169a2 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 25 Nov 2011 21:16:38 -0500 Subject: tst_fs_struct: add program to help check ABI compatibility of ext2fs_filsys Signed-off-by: "Theodore Ts'o" --- lib/ext2fs/Makefile.in | 6 ++++ lib/ext2fs/tst_fs_struct.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 lib/ext2fs/tst_fs_struct.c diff --git a/lib/ext2fs/Makefile.in b/lib/ext2fs/Makefile.in index a9795a36..d9b04f9e 100644 --- a/lib/ext2fs/Makefile.in +++ b/lib/ext2fs/Makefile.in @@ -267,6 +267,12 @@ tst_super_size: tst_super_size.o $(E) " LD $@" $(Q) $(CC) -o tst_super_size tst_super_size.o +tst_fs_struct.o: $(srcdir)/tst_fs_struct.c $(srcdir)/ext2fs.h + +tst_fs_struct: tst_fs_struct.o + $(E) " LD $@" + $(Q) $(CC) -o tst_fs_struct tst_fs_struct.o + tst_inode_size.o: $(srcdir)/tst_inode_size.c $(srcdir)/ext2_fs.h tst_inode_size: tst_inode_size.o diff --git a/lib/ext2fs/tst_fs_struct.c b/lib/ext2fs/tst_fs_struct.c new file mode 100644 index 00000000..6f44df18 --- /dev/null +++ b/lib/ext2fs/tst_fs_struct.c @@ -0,0 +1,81 @@ +/* + * This testing program checks the offset of the ext2_filsys structure + * + * Copyright (C) 2007 by Theodore Ts'o. + * + * %Begin-Header% + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. + * %End-Header% + */ + +#include +#include +#include + +#include "ext2fs.h" + +struct struct_ext2_filsys fs; + +#ifndef offsetof +#define offsetof(type, member) __builtin_offsetof (type, member) +#endif +#define check_field(x) cur_offset = do_field(#x, sizeof(fs.x), \ + offsetof(struct struct_ext2_filsys, x), \ + cur_offset) + +static int do_field(const char *field, size_t size, int offset, int cur_offset) +{ + if (offset != cur_offset) { + printf("\t(padding %d bytes?)\n", offset - cur_offset); + } + printf("%8d %-30s %3u\n", offset, field, (unsigned) size); + return offset + size; +} + +int main(int argc, char **argv) +{ +#if (__GNUC__ >= 4) + int cur_offset = 0; + + printf("%8s %-30s %3s\n", "offset", "field", "size"); + check_field(magic); + check_field(io); + check_field(flags); + check_field(device_name); + check_field(super); + check_field(blocksize); + check_field(fragsize); + check_field(group_desc_count); + check_field(desc_blocks); + check_field(group_desc); + check_field(inode_blocks_per_group); + check_field(inode_map); + check_field(block_map); + check_field(get_blocks); + check_field(check_directory); + check_field(write_bitmaps); + check_field(read_inode); + check_field(write_inode); + check_field(badblocks); + check_field(dblist); + check_field(stride); + check_field(orig_super); + check_field(image_header); + check_field(umask); + check_field(now); + check_field(cluster_ratio_bits); + check_field(reserved); + check_field(priv_data); + check_field(icache); + check_field(image_io); + check_field(get_alloc_block); + check_field(block_alloc_stats); + check_field(mmp_buf); + check_field(mmp_cmp); + check_field(mmp_fd); + check_field(mmp_last_written); + printf("Ending offset is %d\n\n", cur_offset); +#endif + exit(0); +} -- cgit v1.2.1