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",
92 (unsigned long long) num2
,
93 num2
? "" : " (not found)");
94 } else if (!strcmp(cmd
, "dump")) {
95 ext2fs_extent_dump(extent
, out
);
96 } else if (!strcmp(cmd
, "iter_test")) {
97 retval
= ext2fs_iterate_extent(extent
, 0, 0, 0);
101 retval
= ext2fs_iterate_extent(extent
,
102 &num1
, &num2
, &size
);
107 fprintf(out
, "# %llu -> %llu (%llu)\n",
108 (unsigned long long) num1
,
109 (unsigned long long) num2
,
110 (unsigned long long) size
);
113 fputs("# Syntax error\n", out
);
116 ext2fs_free_extent_table(extent
);
120 #define ATTR(x) __attribute__(x)
125 int main(int argc
ATTR((unused
)), char **argv
ATTR((unused
)))
127 do_test(stdin
, stdout
);