changeset 595:e6fe9d25377a

fc-fsio: rm-subtree command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 04 Feb 2020 05:30:59 +0000
parents 2c75cf810146
children 3a9b8f9c7225
files rvinterf/etmsync/cleandir.c rvinterf/etmsync/fileio.c rvinterf/etmsync/fscmdtab.c
diffstat 3 files changed, 99 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/etmsync/cleandir.c	Tue Feb 04 05:09:13 2020 +0000
+++ b/rvinterf/etmsync/cleandir.c	Tue Feb 04 05:30:59 2020 +0000
@@ -77,3 +77,50 @@
 	}
 	return cleandir_level(argv[1]);
 }
+
+cmd_rm_subtree(argc, argv)
+	char **argv;
+{
+	char *pathname;
+	int rc, minusf_mode, found;
+	struct stat_info stat;
+
+	if (argc == 2) {
+		pathname = argv[1];
+		minusf_mode = 0;
+	} else {
+		if (strcmp(argv[1], "-f")) {
+			fprintf(stderr,
+				"usage: rm-subtree [-f] ffs_pathname\n");
+			return(ERROR_USAGE);
+		}
+		pathname = argv[2];
+		minusf_mode = 1;
+	}
+	rc = validate_ffs_pathname(pathname);
+	if (rc < 0)
+		return(ERROR_USAGE);	/* err msg already printed */
+	if (rc == 0) {
+		fprintf(stderr, "error: rm-subtree / is not allowed\n");
+		return(ERROR_USAGE);
+	}
+	if (minusf_mode) {
+		rc = do_xlstat_notfoundok(pathname, &found, &stat);
+		if (rc)
+			return(rc);
+		if (!found)
+			return(0);
+	} else {
+		rc = do_xlstat(pathname, &stat);
+		if (rc)
+			return(rc);
+	}
+	if (stat.type != OT_DIR) {
+		printf("error: %s exists and is not a directory\n", pathname);
+		return(ERROR_TARGET);
+	}
+	rc = cleandir_level(pathname);
+	if (rc)
+		return(rc);
+	return do_ffs_remove(pathname, 0);
+}
--- a/rvinterf/etmsync/fileio.c	Tue Feb 04 05:09:13 2020 +0000
+++ b/rvinterf/etmsync/fileio.c	Tue Feb 04 05:30:59 2020 +0000
@@ -357,6 +357,56 @@
 	return(0);
 }
 
+do_xlstat_notfoundok(pathname, found, result)
+	char *pathname;
+	int *found;
+	struct stat_info *result;
+{
+	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
+	int rc, slen;
+
+	slen = strlen(pathname);
+	if (slen >= TMFFS_STRING_SIZE) {
+		printf("error: pathname arg exceeds string length limit\n");
+		return(ERROR_USAGE);
+	}
+	dp = cmdpkt + 1;
+	*dp++ = ETM_FFS2;
+	*dp++ = TMFFS_XLSTAT;
+	*dp++ = slen + 1;
+	strcpy(dp, pathname);
+	dp += slen + 1;
+	rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1);
+	if (rc)
+		return(rc);
+	if (rvi_msg[3] == TMFFS_ERR_NOTFOUND) {
+		*found = 0;
+		return(0);
+	}
+	if (rvi_msg[3]) {
+		report_ffs_err("xlstat", rvi_msg[3]);
+		return(ERROR_TARGET);
+	}
+	if (rvi_msg_len != 30 || rvi_msg[4] != 24) {
+		printf("error: xlstat response has wrong length\n");
+		return(ERROR_TARGET);
+	}
+	*found = 1;
+	result->type = rvi_msg[5];
+	result->flags = rvi_msg[6];
+	result->inode = rvi_msg[7] | rvi_msg[8] << 8;
+	result->size = rvi_msg[9] | rvi_msg[10] << 8 | rvi_msg[11] << 16 |
+			rvi_msg[12] << 24;
+	result->space = rvi_msg[13] | rvi_msg[14] << 8 | rvi_msg[15] << 16 |
+			rvi_msg[16] << 24;
+	result->location = rvi_msg[17] | rvi_msg[18] << 8 | rvi_msg[19] << 16 |
+				rvi_msg[20] << 24;
+	result->block = rvi_msg[22];
+	result->sequence = rvi_msg[23] | rvi_msg[24] << 8;
+	result->updates = rvi_msg[25] | rvi_msg[26] << 8;
+	return(0);
+}
+
 do_mkdir_existok(pathname)
 	char *pathname;
 {
--- a/rvinterf/etmsync/fscmdtab.c	Tue Feb 04 05:09:13 2020 +0000
+++ b/rvinterf/etmsync/fscmdtab.c	Tue Feb 04 05:30:59 2020 +0000
@@ -24,6 +24,7 @@
 extern int cmd_omemdump();
 extern int cmd_preformat();
 extern int cmd_readlink();
+extern int cmd_rm_subtree();
 extern int cmd_set_imeisv();
 extern int cmd_set_pcm_string();
 extern int cmd_set_rfcap();
@@ -66,6 +67,7 @@
 	{"preformat", 0, 0, cmd_preformat},
 	{"readlink", 1, 1, cmd_readlink},
 	{"rm", 1, 2, cmd_delete},
+	{"rm-subtree", 1, 2, cmd_rm_subtree},
 	{"set-imeisv", 2, 2, cmd_set_imeisv},
 	{"set-pcm-string", 2, 2, cmd_set_pcm_string},
 	{"set-rfcap", 1, 1, cmd_set_rfcap},