2 * test_extent.c --- tester for the extent abstraction
4 * Copyright (C) 1997, 1998 by Theodore Ts'o and
7 * Copyright (C) 1999, 2000 by Theodore Ts'o
10 * This file may be redistributed under the terms of the GNU Public
16 #include "resize2fs.h"
18 void do_test(FILE *in, FILE *out);
20 void do_test(FILE *in, FILE *out)
23 char *cp, *cmd, *arg1, *arg2;
27 ext2_extent extent = 0;
28 const char *no_table = "# No extent table\n";
31 if (!fgets(buf, sizeof(buf), in))
44 cp = strchr(buf, '\n');
49 * Parse command line; simple, at most two arguments
54 cp = strchr(buf, ' ');
58 num1 = strtoul(arg1, 0, 0);
65 num2 = strtoul(arg2, 0, 0);
68 if (!strcmp(cmd, "create")) {
69 retval = ext2fs_create_extent_table(&extent, num1);
72 fprintf(out, "# Error: %s\n",
73 error_message(retval));
82 if (!strcmp(cmd, "free")) {
83 ext2fs_free_extent_table(extent);
85 } else if (!strcmp(cmd, "add")) {
86 retval = ext2fs_add_extent_entry(extent, num1, num2);
89 } else if (!strcmp(cmd, "lookup")) {
90 num2 = ext2fs_extent_translate(extent, num1);
91 fprintf(out, "# Answer: %llu%s\n", num2,
92 num2 ? "" : " (not found)");
93 } else if (!strcmp(cmd, "dump")) {
94 ext2fs_extent_dump(extent, out);
95 } else if (!strcmp(cmd, "iter_test")) {
96 retval = ext2fs_iterate_extent(extent, 0, 0, 0);
100 retval = ext2fs_iterate_extent(extent,
101 &num1, &num2, &size);
106 fprintf(out, "# %llu -> %llu (%llu)\n",
110 fputs("# Syntax error\n", out);
113 ext2fs_free_extent_table(extent);
117 #define ATTR(x) __attribute__(x)
122 int main(int argc ATTR((unused)), char **argv ATTR((unused)))
124 do_test(stdin, stdout);