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
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)))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,
42 (unsigned long long) ref_block);
43 return 0;
44 }
45
46
do_block_iterate(int argc,char ** argv,int sci_idx EXT2FS_ATTR ((unused)),void * infop EXT2FS_ATTR ((unused)))47 void do_block_iterate(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
48 void *infop EXT2FS_ATTR((unused)))
49 {
50 const char *usage = "block_iterate <file> <flags";
51 ext2_ino_t ino;
52 int err = 0;
53 int flags = 0;
54
55 if (common_args_process(argc, argv, 2, 3, argv[0], usage, 0))
56 return;
57
58 ino = string_to_inode(argv[1]);
59 if (!ino)
60 return;
61
62 if (argc > 2) {
63 flags = parse_ulong(argv[2], argv[0], "flags", &err);
64 if (err)
65 return;
66 }
67 flags |= BLOCK_FLAG_READ_ONLY;
68
69 ext2fs_block_iterate3(current_fs, ino, flags, NULL,
70 print_blocks_proc, NULL);
71 putc('\n', stdout);
72 }
73