changeset 290:76228aecf0d9

fc-fsio: mkdir and delete implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 28 Feb 2014 23:41:53 +0000
parents 244f08f58e51
children 69e8ae2b5ba2
files rvinterf/etmsync/Makefile rvinterf/etmsync/fscmdtab.c rvinterf/etmsync/fswrite.c
diffstat 3 files changed, 105 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/etmsync/Makefile	Fri Feb 28 23:12:52 2014 +0000
+++ b/rvinterf/etmsync/Makefile	Fri Feb 28 23:41:53 2014 +0000
@@ -4,7 +4,7 @@
 INSTBIN=/usr/local/bin
 
 FSIO_OBJS=	connect.o dispatch.o fdcmd.o fileio.o fsbasics.o fscmdtab.o \
-		fserr.o fsiomain.o fsread.o interf.o launchrvif.o
+		fserr.o fsiomain.o fsread.o fswrite.o interf.o launchrvif.o
 
 all:	${PROGS}
 
--- a/rvinterf/etmsync/fscmdtab.c	Fri Feb 28 23:12:52 2014 +0000
+++ b/rvinterf/etmsync/fscmdtab.c	Fri Feb 28 23:41:53 2014 +0000
@@ -5,6 +5,7 @@
 #include "cmdtab.h"
 
 extern int cmd_cpout();
+extern int cmd_delete();
 extern int cmd_exec();
 extern int cmd_exit();
 extern int cmd_fd();
@@ -12,10 +13,12 @@
 extern int cmd_hd();
 extern int cmd_ll();
 extern int cmd_ls();
+extern int cmd_mkdir();
 extern int cmd_stat();
 
 struct cmdtab cmdtab[] = {
 	{"cpout", 2, 2, cmd_cpout},
+	{"delete", 1, 1, cmd_delete},
 	{"exec", 1, 1, cmd_exec},
 	{"exit", 0, 0, cmd_exit},
 	{"fd", 2, 3, cmd_fd},
@@ -23,6 +26,7 @@
 	{"hd", 1, 1, cmd_hd},
 	{"ll", 1, 1, cmd_ll},
 	{"ls", 1, 1, cmd_ls},
+	{"mkdir", 1, 1, cmd_mkdir},
 	{"stat", 1, 1, cmd_stat},
 	{0, 0, 0, 0}
 };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/etmsync/fswrite.c	Fri Feb 28 23:41:53 2014 +0000
@@ -0,0 +1,100 @@
+/*
+ * FFS write operation commands
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "etm.h"
+#include "ffs.h"
+#include "ffserr.h"
+#include "tmffs2.h"
+#include "limits.h"
+#include "localtypes.h"
+#include "localstruct.h"
+#include "exitcodes.h"
+
+extern u_char rvi_msg[];
+extern int rvi_msg_len;
+
+do_mkdir_existok(pathname)
+	char *pathname;
+{
+	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
+	int rc, slen;
+	struct stat_info stat;
+
+	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_MKDIR;
+	*dp++ = slen + 1;
+	strcpy(dp, pathname);
+	dp += slen + 1;
+	rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1);
+	if (rc)
+		return(rc);
+	if (rvi_msg_len != 5) {
+		printf("error: mkdir response has wrong length\n");
+		return(ERROR_TARGET);
+	}
+	if (!rvi_msg[3])	/* success */
+		return(0);
+	if (rvi_msg[3] != TMFFS_ERR_EXISTS) {
+		report_ffs_err("mkdir", rvi_msg[3]);
+		return(ERROR_TARGET);
+	}
+	/* object already exists: OK if it's a directory, error otherwise */
+	rc = do_xlstat(pathname, &stat);
+	if (rc)
+		return(rc);
+	if (stat.type == OT_DIR)
+		return(0);
+	else {
+		printf("error: %s exists and is not a directory\n", pathname);
+		return(ERROR_TARGET);
+	}
+}
+
+cmd_mkdir(argc, argv)
+	char **argv;
+{
+	return do_mkdir_existok(argv[1]);
+}
+
+cmd_delete(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
+	int rc, slen;
+
+	slen = strlen(argv[1]);
+	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_REMOVE;
+	*dp++ = slen + 1;
+	strcpy(dp, argv[1]);
+	dp += slen + 1;
+	rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1);
+	if (rc)
+		return(rc);
+	if (rvi_msg_len != 5) {
+		printf("error: TMFFS_REMOVE response has wrong length\n");
+		return(ERROR_TARGET);
+	}
+	if (rvi_msg[3]) {
+		report_ffs_err("ffs_remove", rvi_msg[3]);
+		return(ERROR_TARGET);
+	}
+	return(0);
+}