diff options
author | Jeff Garzik <jeff@garzik.org> | 2006-11-07 21:45:57 -0500 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2006-11-07 21:45:57 -0500 |
commit | e5145d5497a2b3f405efd83d460834371c5bff9c (patch) | |
tree | 1dbf3b7f4271aab0ecef987de088baa2efaaf470 | |
parent | 914034a19cbc8be1ccc588971fc5539451e101d4 (diff) | |
download | dbfs-e5145d5497a2b3f405efd83d460834371c5bff9c.tar.gz |
Add stub for new program, dbdebugfs, a filesystem debugger.
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.am | 5 | ||||
-rw-r--r-- | dbdebugfs.c | 107 |
3 files changed, 112 insertions, 1 deletions
@@ -23,6 +23,7 @@ stamp-h1 mkdbfs dbfs dbfsck +dbdebugfs dbfs-config.h* libdbfs.a diff --git a/Makefile.am b/Makefile.am index 4c5c52b..5aaf74b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,7 +6,7 @@ INCLUDES = @GLIB_CFLAGS@ @FUSE_CFLAGS@ noinst_LIBRARIES = libdbfs.a -sbin_PROGRAMS = dbfs mkdbfs dbfsck +sbin_PROGRAMS = dbfs mkdbfs dbfsck dbdebugfs libdbfs_a_SOURCES = libdbfs.c @@ -19,5 +19,8 @@ mkdbfs_LDADD = @GLIB_LIBS@ @DB_LIBS@ libdbfs.a dbfsck_SOURCES = dbfsck.c dbfsck_LDADD = @GLIB_LIBS@ @DB_LIBS@ libdbfs.a +dbdebugfs_SOURCES = dbdebugfs.c +dbdebugfs_LDADD = @GLIB_LIBS@ @DB_LIBS@ libdbfs.a + EXTRA_DIST = autogen.sh SCHEMA diff --git a/dbdebugfs.c b/dbdebugfs.c new file mode 100644 index 0000000..863da36 --- /dev/null +++ b/dbdebugfs.c @@ -0,0 +1,107 @@ + +/* + * Copyright 2006 Jeff Garzik <jgarzik@pobox.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include <string.h> +#include <stdio.h> +#include <ctype.h> +#include <db.h> +#include "dbfs.h" + +#if 0 +static guint64 cwd = DBFS_ROOT_INO; +#endif + +static int op_cd(const char *path) +{ + return 1; /* FIXME */ +} + +static void unknown_cmd(void) +{ + printf("error: unknown command\n"); +} + +static void print_help(void) +{ + + printf( +"commands:\n" +"cd PATH Change current working directory to PATH\n" +"exit Exit program\n" +"help Print summary of supported commands\n" + ); + +} + +static int main_loop(struct dbfs *fs) +{ + char buf[512], s[512]; + int rc = 0; + + while (1) { + printf("dbdebugfs: "); + fflush(stdout); + + if (fgets(buf, sizeof(buf), stdin) == NULL) + break; + + /* trim trailing whitespace */ + while (buf[0] && (isspace(buf[strlen(buf) - 1]))) + buf[strlen(buf) - 1] = 0; + + if (!strcmp(buf, "help")) + print_help(); + else if (!strcmp(buf, "exit")) + break; + else if (sscanf(buf, "cd %s", s) == 1) + rc = op_cd(s); + else + unknown_cmd(); + + if (rc) + break; + } + + return rc; +} + +int main (int argc, char *argv[]) +{ + struct dbfs *fs; + int rc; + + fs = dbfs_new(); + + gfs = fs; + + if (!fs) + return 1; + + rc = dbfs_open(fs, DB_RECOVER | DB_CREATE, DB_CREATE, "dbdebugfs"); + if (rc) { + perror("dbfsck"); + return 1; + } + + rc = main_loop(fs); + + dbfs_close(fs); + return rc; +} + |