diff options
author | Theodore Ts'o <tytso@mit.edu> | 1997-06-17 03:52:12 +0000 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 1997-06-17 03:52:12 +0000 |
commit | c762c8e63216a301c9de7d24c6136d8370378a08 (patch) | |
tree | 35c13a7d13ebee6431d29047407917c1bc46654b /resize/test_extent.c | |
parent | 05e112a11b6508c2b12d5d4ee0c322171db9b538 (diff) | |
download | e2fsprogs-c762c8e63216a301c9de7d24c6136d8370378a08.tar.gz |
Many files:
Checkin of work to date. (Pretty much completely working now.)
Diffstat (limited to 'resize/test_extent.c')
-rw-r--r-- | resize/test_extent.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/resize/test_extent.c b/resize/test_extent.c new file mode 100644 index 00000000..dc3a584e --- /dev/null +++ b/resize/test_extent.c @@ -0,0 +1,113 @@ +/* + * test_extent.c --- tester for the extent abstraction + * + * Copyright (C) 1997 Theodore Ts'o + * + * %Begin-Header% + * All rights reserved. + * %End-Header% + */ + +#include "resize2fs.h" + +void do_test(FILE *in, FILE *out); + +void do_test(FILE *in, FILE *out) +{ + char buf[128]; + char *cp, *cmd, *arg1, *arg2; + __u32 num1, num2; + int size; + errcode_t retval; + ext2_extent extent = 0; + const char *no_table = "# No extent table\n"; + + while (!feof(in)) { + if (!fgets(buf, sizeof(buf), in)) + break; + /* + * Ignore comments + */ + if (buf[0] =='#') + continue; + + /* + * Echo command + */ + fputs(buf, out); + + cp = strchr(buf, '\n'); + if (cp) + *cp = '\0'; + + /* + * Parse command line; simple, at most two arguments + */ + cmd = buf; + num1 = num2 = 0; + arg1 = arg2 = 0; + cp = strchr(buf, ' '); + if (cp) { + *cp++ = '\0'; + arg1 = cp; + num1 = strtoul(arg1, 0, 0); + + cp = strchr(cp, ' '); + } + if (cp) { + *cp++ = '\0'; + arg2 = cp; + num2 = strtoul(arg2, 0, 0); + } + + if (!strcmp(cmd, "create")) { + retval = ext2fs_create_extent_table(&extent, num1); + if (retval) { + handle_error: + fprintf(out, "# Error: %s\n", + error_message(retval)); + continue; + } + continue; + } + if (!extent) { + fputs(no_table, out); + continue; + } + if (!strcmp(cmd, "free")) { + ext2fs_free_extent_table(extent); + extent = 0; + } else if (!strcmp(cmd, "add")) { + retval = ext2fs_add_extent_entry(extent, num1, num2); + if (retval) + goto handle_error; + } else if (!strcmp(cmd, "lookup")) { + num2 = ext2fs_extent_translate(extent, num1); + fprintf(out, "# Answer: %u%s\n", num2, + num2 ? "" : " (not found)"); + } else if (!strcmp(cmd, "dump")) { + ext2fs_extent_dump(extent, out); + } else if (!strcmp(cmd, "iter_test")) { + retval = ext2fs_iterate_extent(extent, 0, 0, 0); + if (retval) + goto handle_error; + while (1) { + retval = ext2fs_iterate_extent(extent, + &num1, &num2, &size); + if (retval) + goto handle_error; + if (!size) + break; + fprintf(out, "# %u -> %u (%d)\n", + num1, num2, size); + } + } else + fputs("# Syntax error\n", out); + } +} + +int main(int argc, char **argv) +{ + do_test(stdin, stdout); + exit(0); +} |