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 Theosore Ts'o
10 * This file may be redistributed under the terms of the GNU Public
15 #include "resize2fs.h"
17 void do_test(FILE *in, FILE *out);
19 void do_test(FILE *in, FILE *out)
22 char *cp, *cmd, *arg1, *arg2;
26 ext2_extent extent = 0;
27 const char *no_table = "# No extent table\n";
30 if (!fgets(buf, sizeof(buf), in))
43 cp = strchr(buf, '\n');
48 * Parse command line; simple, at most two arguments
53 cp = strchr(buf, ' ');
57 num1 = strtoul(arg1, 0, 0);
64 num2 = strtoul(arg2, 0, 0);
67 if (!strcmp(cmd, "create")) {
68 retval = ext2fs_create_extent_table(&extent, num1);
71 fprintf(out, "# Error: %s\n",
72 error_message(retval));
81 if (!strcmp(cmd, "free")) {
82 ext2fs_free_extent_table(extent);
84 } else if (!strcmp(cmd, "add")) {
85 retval = ext2fs_add_extent_entry(extent, num1, num2);
88 } else if (!strcmp(cmd, "lookup")) {
89 num2 = ext2fs_extent_translate(extent, num1);
90 fprintf(out, "# Answer: %u%s\n", num2,
91 num2 ? "" : " (not found)");
92 } else if (!strcmp(cmd, "dump")) {
93 ext2fs_extent_dump(extent, out);
94 } else if (!strcmp(cmd, "iter_test")) {
95 retval = ext2fs_iterate_extent(extent, 0, 0, 0);
99 retval = ext2fs_iterate_extent(extent,
100 &num1, &num2, &size);
105 fprintf(out, "# %u -> %u (%d)\n",
109 fputs("# Syntax error\n", out);
114 #define ATTR(x) __attribute__(x)
119 int main(int argc ATTR((unused)), char **argv ATTR((unused)))
121 do_test(stdin, stdout);