2 * Test program to trigger various ext4 ioctl's
10 #include <sys/ioctl.h>
12 #if (!defined(EXT4_IOC_ALLOC_DA_BLKS) && defined(__linux__))
13 #define EXT4_IOC_ALLOC_DA_BLKS _IO('f', 12)
16 #if (!defined(EXT4_IOC_SWAP_BOOT) && defined(__linux__))
17 #define EXT4_IOC_SWAP_BOOT _IO('f', 17)
20 #if (!defined(EXT4_IOC_PRECACHE_EXTENTS) && defined(__linux__))
21 #define EXT4_IOC_PRECACHE_EXTENTS _IO('f', 18)
24 #if (!defined(EXT4_IOC_CLEAR_ES_CACHE) && defined(__linux__))
25 #define EXT4_IOC_CLEAR_ES_CACHE _IO('f', 40)
29 #define EXT4_F_RW 0x0001
38 { "alloc_da_blks", EXT4_IOC_ALLOC_DA_BLKS, EXT4_F_RW },
39 { "precache", EXT4_IOC_PRECACHE_EXTENTS, 0 },
40 { "swap_boot", EXT4_IOC_SWAP_BOOT, EXT4_F_RW },
41 { "clear_es_cache", EXT4_IOC_CLEAR_ES_CACHE, EXT4_F_RW },
51 fprintf(stderr, "Usage: %s <cmd> <file>\n\n", progname);
52 fprintf(stderr, "Available commands:\n");
53 for (p = cmds; p->cmd; p++) {
54 fprintf(stderr, "\t%s\n", p->cmd);
59 int do_single_cmd(const char *fn, struct cmd *p)
62 int oflags = O_RDONLY;
64 if (p->flags & EXT4_F_RW)
66 fd = open(fn, oflags, 0);
71 if (ioctl(fd, p->ioc) < 0) {
79 int main(int argc, char **argv)
85 if (argc < 3 || strcmp(argv[1], "help") == 0)
87 for (p = cmds; p->cmd; p++) {
88 if (strcmp(argv[1], p->cmd) == 0)
92 fprintf(stderr, "Invalid command: %s\n", argv[1]);
95 for (i = 2; i < argc; i++)
96 fails += do_single_cmd(argv[i], p);