Whamcloud - gitweb
libext2fs: don't use O_DIRECT for files on tmpfs
[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, int sci_idx EXT2FS_ATTR((unused)),
47                       void *infop EXT2FS_ATTR((unused)))
48 {
49         const char      *usage = "block_iterate <file> <flags";
50         ext2_ino_t      ino;
51         int             err = 0;
52         int             flags = 0;
53
54         if (common_args_process(argc, argv, 2, 3, argv[0], usage, 0))
55                 return;
56
57         ino = string_to_inode(argv[1]);
58         if (!ino)
59                 return;
60
61         if (argc > 2) {
62                 flags = parse_ulong(argv[2], argv[0], "flags", &err);
63                 if (err)
64                         return;
65         }
66         flags |= BLOCK_FLAG_READ_ONLY;
67
68         ext2fs_block_iterate3(current_fs, ino, flags, NULL,
69                               print_blocks_proc, NULL);
70         putc('\n', stdout);
71 }