# HG changeset patch # User Mychaela Falconia # Date 1580792953 0 # Node ID 2c75cf8101464e0d8afe7e8d89335cd83707b0e7 # Parent f315cdb1555ff6e02f07b86aeb394faa25bd0876 fc-fsio: cleandir command implemented diff -r f315cdb1555f -r 2c75cf810146 rvinterf/etmsync/Makefile --- a/rvinterf/etmsync/Makefile Tue Feb 04 03:52:50 2020 +0000 +++ b/rvinterf/etmsync/Makefile Tue Feb 04 05:09:13 2020 +0000 @@ -13,11 +13,11 @@ DSPDUMP_OBJS= dspapidump.o interf.o memops.o simplemain.o ${LIBINTERF} -FSIO_OBJS= cl_des.o dispatch.o fdcmd.o fileio.o fsbasics.o fscmdtab.o \ - fserr.o fsiomain.o fsmisc.o fsnew.o fspath.o fsread.o \ - fsupload.o fsuploadrf.o fswrite.o help.o hostmkdir.o interf.o \ - memcmd.o memops.o pirimei.o pirmagnetite.o rfcap.o stddirs.o \ - symlink.o ${LIBINTERF} ${LIBRFTAB} +FSIO_OBJS= cl_des.o cleandir.o dispatch.o fdcmd.o fileio.o fsbasics.o \ + fscmdtab.o fserr.o fsiomain.o fsmisc.o fsnew.o fspath.o \ + fsread.o fsupload.o fsuploadrf.o fswrite.o help.o hostmkdir.o \ + interf.o memcmd.o memops.o pirimei.o pirmagnetite.o rfcap.o \ + stddirs.o symlink.o ${LIBINTERF} ${LIBRFTAB} MEMDUMP_OBJS= interf.o memdump.o memops.o ${LIBINTERF} diff -r f315cdb1555f -r 2c75cf810146 rvinterf/etmsync/cleandir.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/etmsync/cleandir.c Tue Feb 04 05:09:13 2020 +0000 @@ -0,0 +1,79 @@ +/* + * The implementation of cleandir and rm-subtree commands lives here. + */ + +#include +#include +#include +#include +#include +#include "etm.h" +#include "ffs.h" +#include "tmffs2.h" +#include "limits.h" +#include "ffslimits.h" +#include "localtypes.h" +#include "localstruct.h" +#include "exitcodes.h" + +extern char *pathname_for_ffs_child(); + +cleandir_level(ffspath_dir) + char *ffspath_dir; +{ + u_char rdstate[4]; + char rdbuf[MAX_FN_COMPONENT+1], ffspath_child[MAX_FULL_PATHNAME+1]; + char *childp; + int nument, i, rc; + struct stat_info stat; + + rc = do_opendir(ffspath_dir, rdstate, &nument); + if (rc) + return(rc); + if (!nument) + return(0); + childp = pathname_for_ffs_child(ffspath_dir, ffspath_child); + if (!childp) { + printf("error: non-empty dir at the limit of pathname depth\n"); + return(ERROR_TARGET); + } + for (i = 0; i < nument; i++) { + rc = do_readdir(rdstate, rdbuf, MAX_FN_COMPONENT+1); + if (rc) + return(rc); + if (index(rdbuf, '/')) { + printf("error: readdir result contains a slash\n"); + return(ERROR_TARGET); + } + strcpy(childp, rdbuf); + rc = do_xlstat(ffspath_child, &stat); + if (rc) { + printf("xlstat failed on %s\n", ffspath_child); + return(rc); + } + if (stat.type == OT_DIR) { + rc = cleandir_level(ffspath_child); + if (rc) + return(rc); + } + rc = do_ffs_remove(ffspath_child, 0); + if (rc) + return(rc); + } + return(0); +} + +cmd_cleandir(argc, argv) + char **argv; +{ + int rc; + + rc = validate_ffs_pathname(argv[1]); + if (rc < 0) + return(ERROR_USAGE); /* err msg already printed */ + if (rc == 0) { + fprintf(stderr, "error: cleandir / is not allowed\n"); + return(ERROR_USAGE); + } + return cleandir_level(argv[1]); +} diff -r f315cdb1555f -r 2c75cf810146 rvinterf/etmsync/fscmdtab.c --- a/rvinterf/etmsync/fscmdtab.c Tue Feb 04 03:52:50 2020 +0000 +++ b/rvinterf/etmsync/fscmdtab.c Tue Feb 04 05:09:13 2020 +0000 @@ -4,6 +4,7 @@ #include "cmdtab.h" +extern int cmd_cleandir(); extern int cmd_cpout(); extern int cmd_cpout_file(); extern int cmd_delete(); @@ -40,6 +41,7 @@ extern int pirelli_magnetite_init(); struct cmdtab cmdtab[] = { + {"cleandir", 1, 1, cmd_cleandir}, {"cpout", 2, 2, cmd_cpout}, {"cpout-file", 2, 2, cmd_cpout_file}, {"create-std-dirs", 0, 0, create_std_dirs},