From: Andre Noll Date: Wed, 19 Sep 2007 20:41:15 +0000 (+0200) Subject: Gengetoptify para_fsck. X-Git-Tag: v0.3.0~383^2~3 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=6c3da3d98f13377c20b6ade64480e7bb9f6f7320 Gengetoptify para_fsck. Basic fsck works, but some options are not yet implemented, and dump is busted. --- diff --git a/Makefile.in b/Makefile.in index 0cce0a77..cd2f9c3e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -97,7 +97,7 @@ dbadm_objs = dbadm.o exec.o close_on_fork.o string.o fade_objs = fade.cmdline.o fade.o exec.o close_on_fork.o string.o fd.o krell_objs = krell.o string.o slider_objs = slider.o string.o -fsck_objs = osl.o rbtree.o fsck.o string.o sha1.o +fsck_objs = osl.o rbtree.o fsck.o string.o sha1.o fsck.cmdline.o *.o: para.h config.h gcc-compat.h @@ -139,10 +139,11 @@ grab_client.cmdline.h grab_client.cmdline.c: grab_client.ggo %.cmdline.h %.cmdline.c: %.ggo case $< in client.ggo) O="--unamed-opts=command";; \ audioc.ggo) O="--unamed-opts=command";; \ + fsck.ggo) O="--unamed-opts=table";; \ esac; \ + echo "$O"; if test $< != fsck.ggo; then O="$$O --conf-parser "; fi; \ gengetopt $$O \ --no-handle-version \ - --conf-parser \ --file-name=$(*F).cmdline \ --func-name $(*F)_cmdline_parser \ --arg-struct-name=$(*F)_args_info \ @@ -245,8 +246,8 @@ para_fade: $(fade_objs) para_server: @server_objs@ $(CC) -o $@ @server_objs@ @server_ldflags@ -para_fsck: $(fsck_objs) - $(CC) -o $@ $(fsck_objs) -lssl +para_fsck: @fsck_objs@ + $(CC) -o $@ @fsck_objs@ @fsck_ldflags@ para_sdl_gui: $(sdl_gui_objs) $(CC) -o $@ $(sdl_gui_objs) -lSDL_image diff --git a/configure.ac b/configure.ac index 1c9bee43..36cf3c39 100644 --- a/configure.ac +++ b/configure.ac @@ -124,6 +124,10 @@ client_cmdline_objs="client.cmdline" client_errlist_objs="client net string crypt fd sched stdin stdout client_common" client_ldflags="" +fsck_cmdline_objs="fsck.cmdline" +fsck_errlist_objs="osl rbtree fsck string sha1" + + ########################################################################### ssl dnl @synopsis CHECK_SSL dnl @@ -173,6 +177,7 @@ CHECK_SSL($enable_ssldir) server_ldflags="$srver_ldflags $SSL_LDFLAGS $SSL_LIBS" client_ldflags="$client_ldflags $SSL_LDFLAGS $SSL_LIBS" audiod_ldflags="$audiod_ldflags $SSL_LDFLAGS $SSL_LIBS" +fsck_ldflags="$fsck_ldflags $SSL_LDFLAGS $SSL_LIBS" ########################################################################### ucred AC_MSG_CHECKING(for struct ucred) @@ -524,6 +529,7 @@ audiod_objs="$audiod_cmdline_objs $audiod_errlist_objs" server_objs="$server_cmdline_objs $server_errlist_objs" write_objs="$write_cmdline_objs $write_errlist_objs" client_objs="$client_cmdline_objs $client_errlist_objs" +fsck_objs="$fsck_cmdline_objs $fsck_errlist_objs" audioc_objs="$audioc_cmdline_objs $audioc_errlist_objs" AC_SUBST(recv_objs, add_dot_o($recv_objs)) @@ -556,6 +562,11 @@ AC_SUBST(client_ldflags, $client_ldflags) AC_DEFINE_UNQUOTED(INIT_CLIENT_ERRLISTS, objlist_to_errlist($client_errlist_objs), errors used by para_client) +AC_SUBST(fsck_objs, add_dot_o($fsck_objs)) +AC_SUBST(fsck_ldflags, $fsck_ldflags) +AC_DEFINE_UNQUOTED(INIT_FSCK_ERRLISTS, + objlist_to_errlist($fsck_errlist_objs), errors used by para_fsck) + AC_SUBST(audioc_objs, add_dot_o($audioc_objs)) AC_DEFINE_UNQUOTED(INIT_AUDIOC_ERRLISTS, objlist_to_errlist($audioc_errlist_objs), errors used by para_audioc) diff --git a/error.h b/error.h index ee8cff34..7dafc606 100644 --- a/error.h +++ b/error.h @@ -74,6 +74,7 @@ enum para_subsystem { SS_PLAYLIST, SS_SHA1, SS_RBTREE, + SS_FSCK, NUM_SS }; @@ -94,6 +95,12 @@ enum para_subsystem { extern const char **para_errlist[]; /** \endcond */ +#define FSCK_ERRORS \ + PARA_ERROR(FSCK_SYNTAX, "fsck syntax error"), \ + PARA_ERROR(RANGE_VIOLATION, "range violation detected, very bad"), \ + PARA_ERROR(NOT_A_REGULAR_FILE, "not a regular file"), \ + + #define OSL_ERRORS \ PARA_ERROR(OSL_OPENDIR, "can not open directory"), \ PARA_ERROR(OSL_CHDIR, "failed to change directory"), \ @@ -686,6 +693,7 @@ SS_ENUM(BLOB); SS_ENUM(PLAYLIST); SS_ENUM(SHA1); SS_ENUM(RBTREE); +SS_ENUM(FSCK); /** \endcond */ #undef PARA_ERROR /* rest of the world only sees the error text */ diff --git a/fsck.c b/fsck.c index bc4083ae..7bca0163 100644 --- a/fsck.c +++ b/fsck.c @@ -1,18 +1,12 @@ #include "para.h" #include "error.h" #include "osl_core.h" +#include "fsck.cmdline.h" -#define OSL_DUMP_DIR "/tmp/osldump" +static struct fsck_args_info conf; -enum errors { - E_FSCK_SYNTAX = 501, - E_RANGE_VIOLATION, - E_NO_DS_FILE, - E_NOT_A_REGULAR_FILE, - E_BAD_HASH_PATH, -}; - -INIT_STDERR_LOGGING(1); +INIT_FSCK_ERRLISTS; +INIT_STDERR_LOGGING(conf.loglevel_arg); /* taken from git */ signed char hexval_table[256] = { @@ -93,7 +87,8 @@ static int check_range(struct osl_table *t, uint32_t row_num, uint32_t col_num) // PARA_INFO_LOG("obj: %p..%p\n", obj_start, obj_start + obj.size); // PARA_INFO_LOG("map: %p..%p\n", map_start, map_start + col->data_map.size); if (obj_start < map_start || obj_start + obj.size > map_start + col->data_map.size) { - PARA_CRIT_LOG("row %u, col %u: range violation, very bad\n", row_num, col_num); + PARA_CRIT_LOG("range violation in row %u, col %u\n", row_num, + col_num); return -E_RANGE_VIOLATION; } PARA_DEBUG_LOG("col %u: ok\n", col_num); @@ -568,10 +563,6 @@ out: return ret; } -#define FSCK 1 -#define FORCE 1 -#define DUMP 0 - static void set_dummy_contents(struct osl_table_description *desc) { int i; @@ -603,7 +594,7 @@ static int fsck_init(struct osl_table_description *desc, struct osl_table **t) } PARA_INFO_LOG("unmapping index\n"); para_munmap(map.data, map.size); - if (FORCE) + if (conf.force_given) ret = map_table(*t, (MAP_TBL_FL_IGNORE_DIRTY)); else ret = map_table(*t, 0); @@ -864,25 +855,48 @@ out: fsck_cleanup(t); return ret; } -int main(__a_unused int argc, __a_unused char **argv) + +int main(__a_unused int argc, char **argv) { - int ret; + int i, ret; struct osl_table_description desc = {.column_descriptions = NULL}; + char *base_dir = NULL; - ret = -E_FSCK_SYNTAX; - if (argc < 3) + ret = fsck_cmdline_parser(argc, argv, &conf); + if (ret < 0) { + ret = -E_FSCK_SYNTAX; goto out; - desc.dir = argv[1]; - desc.name = argv[2]; - if (FSCK) { - ret = fsck(&desc); - if (ret < 0) - goto out; } - if (DUMP) - ret = dump_table(OSL_DUMP_DIR, &desc); + HANDLE_VERSION_FLAG("fsck", conf); + if (!conf.inputs_num) { + /* FIXME: Find all subdirs */ + ret = -E_FSCK_SYNTAX; + goto out; + } + desc.dir = conf.base_dir_arg; + if (!conf.base_dir_given) { + char *home = para_homedir(); + base_dir = make_message("%s/.paraslash/afs_database", home); + free(home); + desc.dir = base_dir; + } + for (i = 0; i < conf.inputs_num; i++) { + desc.name = conf.inputs[i]; + if (!conf.no_fsck_given) { + ret = fsck(&desc); + if (ret < 0) + break; + } + if (conf.dump_dir_given && *conf.dump_dir_arg) { + ret = dump_table(conf.dump_dir_arg, &desc); + if (ret < 0) + break; + } + } + free(base_dir); + ret = 1; out: if (ret < 0) - PARA_ERROR_LOG("error %d\n", ret); - return ret < 0? EXIT_FAILURE: EXIT_SUCCESS; + PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret)); + return ret < 0? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/fsck.ggo b/fsck.ggo new file mode 100644 index 00000000..207bc853 --- /dev/null +++ b/fsck.ggo @@ -0,0 +1,47 @@ +option "loglevel" l +#~~~~~~~~~~~~~~~~~~ + +"set loglevel (0-6)" + + int typestr="level" + default="4" + optional + +option "base_dir" b +#~~~~~~~~~~~~~~~~~~ +"Full path to the database directory +containing the table(s) to be checked. +(default='~/.paraslash/afs_database'" + + string typestr="path" + optional + +option "dump_dir" d +#~~~~~~~~~~~~~~~~~~ +"If path is non-empty, para_fsck will write a +dump of all given tables to the specified +path." + + string typestr="path" + optional + default="" + +option "no_fsck" n +#~~~~~~~~~~~~~~~~~ +"Disable fsck mode." + + flag off + +option "force" f +#~~~~~~~~~~~~~~~ +"Force fsck even if the table is dirty. +Ignored if -n is given." + + flag off + +option "dry_run" - +#~~~~~~~~~~~~~~~~~ +"Only report problems, don't try to fix them." + + flag off +