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
%.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 \
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
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
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)
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))
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)
SS_PLAYLIST,
SS_SHA1,
SS_RBTREE,
+ SS_FSCK,
NUM_SS
};
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"), \
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 */
#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] = {
// 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);
return ret;
}
-#define FSCK 1
-#define FORCE 1
-#define DUMP 0
-
static void set_dummy_contents(struct osl_table_description *desc)
{
int i;
}
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);
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;
}
--- /dev/null
+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
+