]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
Allow debugfs to be extended for use by test programs
authorTheodore Ts'o <tytso@mit.edu>
Fri, 31 Aug 2007 17:39:23 +0000 (13:39 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 18 Feb 2008 20:27:04 +0000 (15:27 -0500)
This change allows debugfs to be reused as the base for e2fsprogs
internal test programs, by linking debugfs object files with
additional object file(s) that define additional commands.  The test
program's object file(s) should define their own comand table, and
define the symbol extra_cmds to be a pointer to the ss_request_table.
In addition, the symbol debug_prog_name can be used to override the
name of the program printed in the version banner and in the ss
prompt.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
debugfs/debugfs.c

index 8fa24123918152fdd9371f241113e4ee68c0a043..bcd9a9be6e219cb3478e1ce7979bbdc022f2ed7c 100644 (file)
@@ -38,6 +38,8 @@ extern char *optarg;
 #include "../version.h"
 
 extern ss_request_table debug_cmds;
+ss_request_table *extra_cmds;
+char *debug_prog_name;
 
 ext2_filsys    current_fs = NULL;
 ext2_ino_t     root, cwd;
@@ -1798,7 +1800,7 @@ int main(int argc, char **argv)
 {
        int             retval;
        int             sci_idx;
-       const char      *usage = "Usage: debugfs [-b blocksize] [-s superblock] [-f cmd_file] [-R request] [-V] [[-w] [-c] device]";
+       const char      *usage = "Usage: %s [-b blocksize] [-s superblock] [-f cmd_file] [-R request] [-V] [[-w] [-c] device]";
        int             c;
        int             open_flags = EXT2_FLAG_SOFTSUPP_FEATURES;
        char            *request = 0;
@@ -1809,9 +1811,12 @@ int main(int argc, char **argv)
        int             catastrophic = 0;
        char            *data_filename = 0;
        
+       if (debug_prog_name == 0)
+               debug_prog_name = "debugfs";
+
        add_error_table(&et_ext2_error_table);
-       fprintf (stderr, "debugfs %s (%s)\n", E2FSPROGS_VERSION,
-                E2FSPROGS_DATE);
+       fprintf (stderr, "%s %s (%s)\n", debug_prog_name,
+                E2FSPROGS_VERSION, E2FSPROGS_DATE);
 
        while ((c = getopt (argc, argv, "iwcR:f:b:s:Vd:")) != EOF) {
                switch (c) {
@@ -1847,7 +1852,7 @@ int main(int argc, char **argv)
                                error_message(EXT2_ET_BASE));
                        exit(0);
                default:
-                       com_err(argv[0], 0, usage);
+                       com_err(argv[0], 0, usage, debug_prog_name);
                        return 1;
                }
        }
@@ -1856,7 +1861,7 @@ int main(int argc, char **argv)
                                superblock, blocksize, catastrophic,
                                data_filename);
        
-       sci_idx = ss_create_invocation("debugfs", "0.0", (char *) NULL,
+       sci_idx = ss_create_invocation(debug_prog_name, "0.0", (char *) NULL,
                                       &debug_cmds, &retval);
        if (retval) {
                ss_perror(sci_idx, retval, "creating invocation");
@@ -1869,6 +1874,12 @@ int main(int argc, char **argv)
                ss_perror(sci_idx, retval, "adding standard requests");
                exit (1);
        }
+       if (extra_cmds)
+               ss_add_request_table (sci_idx, extra_cmds, 1, &retval);
+       if (retval) {
+               ss_perror(sci_idx, retval, "adding extra requests");
+               exit (1);
+       }
        if (request) {
                retval = 0;
                retval = ss_execute_line(sci_idx, request);