changeset 594:2c75cf810146

fc-fsio: cleandir command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 04 Feb 2020 05:09:13 +0000
parents f315cdb1555f
children e6fe9d25377a
files rvinterf/etmsync/Makefile rvinterf/etmsync/cleandir.c rvinterf/etmsync/fscmdtab.c
diffstat 3 files changed, 86 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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}
 
--- /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 <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#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]);
+}
--- 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},