Whamcloud - gitweb
Update release notes, etc., for the 1.43.6 release
[tools/e2fsprogs.git] / lib / ext2fs / tst_libext2fs.c
1 /*
2  * tst_libext2fs.c
3  */
4
5 #include "config.h"
6 #include <stdio.h>
7 #include <string.h>
8 #if HAVE_UNISTD_H
9 #include <unistd.h>
10 #endif
11 #if HAVE_ERRNO_H
12 #include <errno.h>
13 #endif
14 #if HAVE_SYS_STAT_H
15 #include <sys/stat.h>
16 #endif
17 #if HAVE_SYS_TYPES_H
18 #include <sys/types.h>
19 #endif
20
21 #include "ext2_fs.h"
22 #include "ext2fsP.h"
23
24 #include "ss/ss.h"
25 #include "debugfs.h"
26
27 /*
28  * Hook in new commands into debugfs
29  * Override debugfs's prompt
30  */
31 const char *debug_prog_name = "tst_libext2fs";
32 extern ss_request_table libext2fs_cmds;
33 ss_request_table *extra_cmds = &libext2fs_cmds;
34
35 static int print_blocks_proc(ext2_filsys fs EXT2FS_ATTR((unused)),
36                              blk64_t *blocknr, e2_blkcnt_t blockcnt,
37                              blk64_t ref_block, int ref_offset,
38                              void *private EXT2FS_ATTR((unused)))
39 {
40         printf("%6lld %8llu (%d %llu)\n", (long long) blockcnt,
41                (unsigned long long)*blocknr, ref_offset, ref_block);
42         return 0;
43 }
44
45
46 void do_block_iterate(int argc, char **argv)
47 {
48         const char      *usage = "block_iterate <file> <flags";
49         ext2_ino_t      ino;
50         int             err = 0;
51         int             flags = 0;
52
53         if (common_args_process(argc, argv, 2, 3, argv[0], usage, 0))
54                 return;
55
56         ino = string_to_inode(argv[1]);
57         if (!ino)
58                 return;
59
60         if (argc > 2) {
61                 flags = parse_ulong(argv[2], argv[0], "flags", &err);
62                 if (err)
63                         return;
64         }
65         flags |= BLOCK_FLAG_READ_ONLY;
66
67         ext2fs_block_iterate3(current_fs, ino, flags, NULL,
68                               print_blocks_proc, NULL);
69         putc('\n', stdout);
70 }