diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 15:49:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 15:49:25 +0000 |
commit | 464df1d5e5ab1322e2dd0a7796939fff1aeefa9a (patch) | |
tree | 6a403684e0978f0287d7f0ec0e5aab1fd31a59e1 /lib/ext2fs/tst_inode_size.c | |
parent | Initial commit. (diff) | |
download | e2fsprogs-upstream.tar.xz e2fsprogs-upstream.zip |
Adding upstream version 1.47.0.upstream/1.47.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/ext2fs/tst_inode_size.c')
-rw-r--r-- | lib/ext2fs/tst_inode_size.c | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/lib/ext2fs/tst_inode_size.c b/lib/ext2fs/tst_inode_size.c new file mode 100644 index 0000000..cc5d165 --- /dev/null +++ b/lib/ext2fs/tst_inode_size.c @@ -0,0 +1,89 @@ +/* + * This testing program makes sure the ext2_inode structure is 1024 bytes long + * + * 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 "config.h" +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> + +#include "ext2_fs.h" + +struct ext2_inode_large inode; + +#ifndef offsetof +#define offsetof(type, member) __builtin_offsetof(type, member) +#endif + +#define check_field(x, s) cur_offset = do_field(#x, s, sizeof(inode.x), \ + offsetof(struct ext2_inode_large, x), \ + cur_offset) + +static int do_field(const char *field, unsigned size, unsigned cur_size, + unsigned offset, unsigned cur_offset) +{ + if (size != cur_size) { + printf("error: %s size %u should be %u\n", + field, cur_size, size); + exit(1); + } + if (offset != cur_offset) { + printf("error: %s offset %u should be %u\n", + field, cur_offset, offset); + exit(1); + } + 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(i_mode, 2); + check_field(i_uid, 2); + check_field(i_size, 4); + check_field(i_atime, 4); + check_field(i_ctime, 4); + check_field(i_mtime, 4); + check_field(i_dtime, 4); + check_field(i_gid, 2); + check_field(i_links_count, 2); + check_field(i_blocks, 4); + check_field(i_flags, 4); + check_field(osd1.linux1.l_i_version, 4); + check_field(i_block, 15 * 4); + check_field(i_generation, 4); + check_field(i_file_acl, 4); + check_field(i_size_high, 4); + check_field(i_faddr, 4); + check_field(osd2.linux2.l_i_blocks_hi, 2); + check_field(osd2.linux2.l_i_file_acl_high, 2); + check_field(osd2.linux2.l_i_uid_high, 2); + check_field(osd2.linux2.l_i_gid_high, 2); + check_field(osd2.linux2.l_i_checksum_lo, 2); + check_field(osd2.linux2.l_i_reserved, 2); + do_field("Small inode end", 0, 0, cur_offset, 128); + check_field(i_extra_isize, 2); + check_field(i_checksum_hi, 2); + check_field(i_ctime_extra, 4); + check_field(i_mtime_extra, 4); + check_field(i_atime_extra, 4); + check_field(i_crtime, 4); + check_field(i_crtime_extra, 4); + check_field(i_version_hi, 4); + check_field(i_projid, 4); + /* This size will change as new fields are added */ + do_field("Large inode end", 0, 0, cur_offset, sizeof(inode)); +#endif + return 0; +} |