changeset 291:69e8ae2b5ba2

fc-fsio: fwrite implementation started
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 01 Mar 2014 02:36:25 +0000
parents 76228aecf0d9
children 3aa03b9519c0
files rvinterf/etmsync/dispatch.c rvinterf/etmsync/fdcmd.c rvinterf/etmsync/fileio.c rvinterf/etmsync/fscmdtab.c rvinterf/etmsync/fswrite.c
diffstat 5 files changed, 96 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/etmsync/dispatch.c	Fri Feb 28 23:41:53 2014 +0000
+++ b/rvinterf/etmsync/dispatch.c	Sat Mar 01 02:36:25 2014 +0000
@@ -47,11 +47,23 @@
 			fprintf(stderr, "error: too many arguments\n");
 			return(ERROR_USAGE);
 		}
-		*ap++ = cp;
-		while (*cp && !isspace(*cp))
-			cp++;
-		if (*cp)
+		if (*cp == '"') {
+			*ap++ = ++cp;
+			while (*cp && *cp != '"')
+				cp++;
+			if (*cp != '"') {
+				fprintf(stderr,
+					"error: unterminated quoted string\n");
+				return(ERROR_USAGE);
+			}
 			*cp++ = '\0';
+		} else {
+			*ap++ = cp;
+			while (*cp && !isspace(*cp))
+				cp++;
+			if (*cp)
+				*cp++ = '\0';
+		}
 	}
 	if (ap - argv - 1 < tp->minargs) {
 		fprintf(stderr, "error: too few arguments\n");
--- a/rvinterf/etmsync/fdcmd.c	Fri Feb 28 23:41:53 2014 +0000
+++ b/rvinterf/etmsync/fdcmd.c	Sat Mar 01 02:36:25 2014 +0000
@@ -21,7 +21,7 @@
 {
 	int rc, fd;
 
-	rc = fd_open(argv[1], strtoul(argv[2], 0, 0), &fd);
+	rc = fd_open(argv[1], strtoul(argv[2], 0, 16), &fd);
 	if (rc)
 		return(rc);
 	printf("%d\n", fd);
--- a/rvinterf/etmsync/fileio.c	Fri Feb 28 23:41:53 2014 +0000
+++ b/rvinterf/etmsync/fileio.c	Sat Mar 01 02:36:25 2014 +0000
@@ -156,3 +156,49 @@
 	*rdret = sz;
 	return(0);
 }
+
+max_short_file_write(pathname)
+	char *pathname;
+{
+	return MAX_PKT_TO_TARGET - 3 - (strlen(pathname) + 2) - 3;
+}
+
+do_short_fwrite(pathname, data, datalen)
+	char *pathname;
+	u_char *data;
+{
+	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);
+	}
+	if (datalen > max_short_file_write(pathname)) {
+		printf("error: short write data fails to fit in the packet\n");
+		return(ERROR_USAGE);
+	}
+	dp = cmdpkt + 1;
+	*dp++ = ETM_FFS2;
+	*dp++ = TMFFS_FILE_WRITE;
+	*dp++ = slen + 1;
+	strcpy(dp, pathname);
+	dp += slen + 1;
+	*dp++ = datalen;
+	bcopy(data, dp, datalen);
+	dp += datalen;
+	*dp++ = FFS_O_CREATE | FFS_O_TRUNC;
+	rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1);
+	if (rc)
+		return(rc);
+	if (rvi_msg_len != 5) {
+		printf("error: TMFFS_FILE_WRITE response has wrong length\n");
+		return(ERROR_TARGET);
+	}
+	if (rvi_msg[3]) {
+		report_ffs_err("short file write", rvi_msg[3]);
+		return(ERROR_TARGET);
+	}
+	return(0);
+}
--- a/rvinterf/etmsync/fscmdtab.c	Fri Feb 28 23:41:53 2014 +0000
+++ b/rvinterf/etmsync/fscmdtab.c	Sat Mar 01 02:36:25 2014 +0000
@@ -10,6 +10,7 @@
 extern int cmd_exit();
 extern int cmd_fd();
 extern int cmd_ffs2ver();
+extern int cmd_fwrite();
 extern int cmd_hd();
 extern int cmd_ll();
 extern int cmd_ls();
@@ -23,6 +24,7 @@
 	{"exit", 0, 0, cmd_exit},
 	{"fd", 2, 3, cmd_fd},
 	{"ffs2ver", 0, 0, cmd_ffs2ver},
+	{"fwrite", 3, 3, cmd_fwrite},
 	{"hd", 1, 1, cmd_hd},
 	{"ll", 1, 1, cmd_ll},
 	{"ls", 1, 1, cmd_ls},
--- a/rvinterf/etmsync/fswrite.c	Fri Feb 28 23:41:53 2014 +0000
+++ b/rvinterf/etmsync/fswrite.c	Sat Mar 01 02:36:25 2014 +0000
@@ -98,3 +98,34 @@
 	}
 	return(0);
 }
+
+fwrite_hex_string(pathname, strarg)
+	char *pathname, *strarg;
+{
+	fprintf(stderr, "This function is not yet implemented\n");
+	return(ERROR_BUG);
+}
+
+fwrite_from_file(pathname, srcfile)
+	char *pathname, *srcfile;
+{
+	fprintf(stderr, "This function is not yet implemented\n");
+	return(ERROR_BUG);
+}
+
+cmd_fwrite(argc, argv)
+	char **argv;
+{
+	if (!strcmp(argv[2], "ascii"))
+		return do_short_fwrite(argv[1], argv[3], strlen(argv[3]));
+	else if (!strcmp(argv[2], "hex"))
+		return fwrite_hex_string(argv[1], argv[3]);
+	else if (!strcmp(argv[2], "file"))
+		return fwrite_from_file(argv[1], argv[3]);
+	else {
+		fprintf(stderr,
+"error: middle argument to fwrite cmd must be \"ascii\", \"hex\" or \"file\"\n"
+			);
+		return(ERROR_USAGE);
+	}
+}