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_libext2fs.c | |
parent | Initial commit. (diff) | |
download | e2fsprogs-464df1d5e5ab1322e2dd0a7796939fff1aeefa9a.tar.xz e2fsprogs-464df1d5e5ab1322e2dd0a7796939fff1aeefa9a.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_libext2fs.c')
-rw-r--r-- | lib/ext2fs/tst_libext2fs.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/lib/ext2fs/tst_libext2fs.c b/lib/ext2fs/tst_libext2fs.c new file mode 100644 index 0000000..4c86464 --- /dev/null +++ b/lib/ext2fs/tst_libext2fs.c @@ -0,0 +1,72 @@ +/* + * tst_libext2fs.c + */ + +#include "config.h" +#include <stdio.h> +#include <string.h> +#if HAVE_UNISTD_H +#include <unistd.h> +#endif +#if HAVE_ERRNO_H +#include <errno.h> +#endif +#if HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif +#if HAVE_SYS_TYPES_H +#include <sys/types.h> +#endif + +#include "ext2_fs.h" +#include "ext2fsP.h" + +#include "ss/ss.h" +#include "debugfs.h" + +/* + * Hook in new commands into debugfs + * Override debugfs's prompt + */ +const char *debug_prog_name = "tst_libext2fs"; +extern ss_request_table libext2fs_cmds; +ss_request_table *extra_cmds = &libext2fs_cmds; + +static int print_blocks_proc(ext2_filsys fs EXT2FS_ATTR((unused)), + blk64_t *blocknr, e2_blkcnt_t blockcnt, + blk64_t ref_block, int ref_offset, + void *private EXT2FS_ATTR((unused))) +{ + printf("%6lld %8llu (%d %llu)\n", (long long) blockcnt, + (unsigned long long) *blocknr, ref_offset, + (unsigned long long) ref_block); + return 0; +} + + +void do_block_iterate(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)), + void *infop EXT2FS_ATTR((unused))) +{ + const char *usage = "block_iterate <file> <flags"; + ext2_ino_t ino; + int err = 0; + int flags = 0; + + if (common_args_process(argc, argv, 2, 3, argv[0], usage, 0)) + return; + + ino = string_to_inode(argv[1]); + if (!ino) + return; + + if (argc > 2) { + flags = parse_ulong(argv[2], argv[0], "flags", &err); + if (err) + return; + } + flags |= BLOCK_FLAG_READ_ONLY; + + ext2fs_block_iterate3(current_fs, ino, flags, NULL, + print_blocks_proc, NULL); + putc('\n', stdout); +} |