changeset 287:211b35db427c

fc-fsio: cpout of single files implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 28 Feb 2014 08:22:50 +0000
parents 146e7bf3fa4e
children e33d71e9033f
files rvinterf/etmsync/fscmdtab.c rvinterf/etmsync/fsread.c
diffstat 2 files changed, 66 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/etmsync/fscmdtab.c	Fri Feb 28 06:45:10 2014 +0000
+++ b/rvinterf/etmsync/fscmdtab.c	Fri Feb 28 08:22:50 2014 +0000
@@ -4,6 +4,7 @@
 
 #include "cmdtab.h"
 
+extern int cmd_cpout();
 extern int cmd_exec();
 extern int cmd_exit();
 extern int cmd_fd();
@@ -14,6 +15,7 @@
 extern int cmd_stat();
 
 struct cmdtab cmdtab[] = {
+	{"cpout", 2, 2, cmd_cpout},
 	{"exec", 1, 1, cmd_exec},
 	{"exit", 0, 0, cmd_exit},
 	{"fd", 2, 3, cmd_fd},
--- a/rvinterf/etmsync/fsread.c	Fri Feb 28 06:45:10 2014 +0000
+++ b/rvinterf/etmsync/fsread.c	Fri Feb 28 08:22:50 2014 +0000
@@ -133,3 +133,67 @@
 	}
 	return(0);
 }
+
+cpout_object(ffspath, hostpath)
+	char *ffspath, *hostpath;
+{
+	struct stat_info stat;
+	int rc;
+
+	rc = do_xlstat(ffspath, &stat);
+	if (rc)
+		return(rc);
+	switch (stat.type) {
+	case OT_FILE:
+		return cpout_file(ffspath, &stat, hostpath);
+	case OT_DIR:
+		printf("cpout dir handling not yet implemented\n");
+		return(ERROR_BUG);
+	case OT_LINK:
+		printf("skipping FFS symlink %s\n", ffspath);
+		return(0);
+	default:
+		printf("error: stat returned bad objtype for %s\n", ffspath);
+		return(ERROR_TARGET);
+	}
+}
+
+cpout_file(ffspath, stat, hostpath)
+	char *ffspath, *hostpath;
+	struct stat_info *stat;
+{
+	int tfd;
+	FILE *of;
+	u_char buf[MAX_READ_DATA];
+	int rc, sz;
+
+	printf("copying %s\n", ffspath);
+	rc = fd_open(ffspath, FFS_O_RDONLY, &tfd);
+	if (rc)
+		return(rc);
+	of = fopen(hostpath, "w");
+	if (!of) {
+		perror(hostpath);
+		fd_close(tfd);
+		return(ERROR_UNIX);
+	}
+	for (;;) {
+		rc = fd_read(tfd, buf, MAX_READ_DATA, &sz);
+		if (rc) {
+			fd_close(tfd);
+			fclose(of);
+			return(rc);
+		}
+		if (!sz)
+			break;
+		fwrite(buf, 1, sz, of);
+	}
+	fclose(of);
+	return fd_close(tfd);
+}
+
+cmd_cpout(argc, argv)
+	char **argv;
+{
+	return cpout_object(argv[1], argv[2]);
+}