changeset 297:0242d5facf7b

fc-fsio: upload-fs implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sat, 01 Mar 2014 09:07:03 +0000
parents 792f164b63a6
children 100192a92472
files rvinterf/etmsync/Makefile rvinterf/etmsync/fscmdtab.c rvinterf/etmsync/fsupload.c
diffstat 3 files changed, 116 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/etmsync/Makefile	Sat Mar 01 08:19:15 2014 +0000
+++ b/rvinterf/etmsync/Makefile	Sat Mar 01 09:07:03 2014 +0000
@@ -4,8 +4,8 @@
 INSTBIN=/usr/local/bin
 
 FSIO_OBJS=	connect.o dispatch.o fdcmd.o fileio.o fsbasics.o fscmdtab.o \
-		fserr.o fsiomain.o fspath.o fsread.o fswrite.o interf.o \
-		launchrvif.o
+		fserr.o fsiomain.o fspath.o fsread.o fsupload.o fswrite.o \
+		interf.o launchrvif.o
 
 all:	${PROGS}
 
--- a/rvinterf/etmsync/fscmdtab.c	Sat Mar 01 08:19:15 2014 +0000
+++ b/rvinterf/etmsync/fscmdtab.c	Sat Mar 01 09:07:03 2014 +0000
@@ -17,6 +17,7 @@
 extern int cmd_ls();
 extern int cmd_mkdir();
 extern int cmd_stat();
+extern int cmd_uploadfs();
 
 struct cmdtab cmdtab[] = {
 	{"cpout", 2, 2, cmd_cpout},
@@ -32,5 +33,6 @@
 	{"ls", 1, 1, cmd_ls},
 	{"mkdir", 1, 1, cmd_mkdir},
 	{"stat", 1, 1, cmd_stat},
+	{"upload-fs", 1, 1, cmd_uploadfs},
 	{0, 0, 0, 0}
 };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/etmsync/fsupload.c	Sat Mar 01 09:07:03 2014 +0000
@@ -0,0 +1,112 @@
+/*
+ * upload-fs implementation
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <ctype.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 "ffslimits.h"
+#include "localtypes.h"
+#include "localstruct.h"
+#include "exitcodes.h"
+
+uploadfs_level(srcpath, depth, prefix)
+	char *srcpath, *prefix;
+{
+	char ffs_childpath[MAX_FULL_PATHNAME+1], *ffs_childp;
+	DIR *rdd;
+	struct dirent *dirent;
+	char hostpath_child[MAXPATHLEN];
+	struct stat hst;
+	int rc;
+
+	strcpy(ffs_childpath, prefix);
+	ffs_childp = index(ffs_childpath, '\0');
+	*ffs_childp++ = '/';
+	rdd = opendir(srcpath);
+	if (!rdd) {
+		perror(srcpath);
+		return(ERROR_UNIX);
+	}
+	while (dirent = readdir(rdd)) {
+		if (dirent->d_name[0] == '.')
+			continue;
+		if (strlen(dirent->d_name) > MAX_FN_COMPONENT) {
+			fprintf(stderr,
+		"error: \"%s\" in %s exceeds the FFS component name limit\n",
+				dirent->d_name, srcpath);
+			closedir(rdd);
+			return(ERROR_USAGE);
+		}
+		if (strlen(srcpath) + strlen(dirent->d_name) + 2 >
+		    sizeof hostpath_child) {
+			fprintf(stderr,
+				"error: host side pathname buffer overflow\n");
+			closedir(rdd);
+			return(ERROR_UNIX);
+		}
+		sprintf(hostpath_child, "%s/%s", srcpath, dirent->d_name);
+		if (lstat(hostpath_child, &hst) < 0) {
+			perror(hostpath_child);
+			closedir(rdd);
+			return(ERROR_UNIX);
+		}
+		strcpy(ffs_childp, dirent->d_name);
+		switch (hst.st_mode & S_IFMT) {
+		case S_IFREG:
+			printf("uploading %s\n", ffs_childpath);
+			rc = fwrite_from_file(ffs_childpath, hostpath_child);
+			if (rc) {
+				closedir(rdd);
+				return(rc);
+			}
+			break;
+		case S_IFDIR:
+			if (depth >= MAX_NAME_DEPTH-1) {
+				fprintf(stderr,
+				"error: directory nesting too deep at %s\n",
+					hostpath_child);
+				closedir(rdd);
+				return(ERROR_USAGE);
+			}
+			printf("mkdir %s\n", ffs_childpath);
+			rc = do_mkdir_existok(ffs_childpath);
+			if (rc) {
+				closedir(rdd);
+				return(rc);
+			}
+			rc = uploadfs_level(hostpath_child, depth + 1,
+						ffs_childpath);
+			if (rc) {
+				closedir(rdd);
+				return(rc);
+			}
+			break;
+		default:
+			fprintf(stderr,
+			"error: %s is neither a regular file nor a directory\n",
+				hostpath_child);
+			closedir(rdd);
+			return(ERROR_USAGE);
+		}
+	}
+	closedir(rdd);
+	return(0);
+}
+
+cmd_uploadfs(argc, argv)
+	char **argv;
+{
+	return uploadfs_level(argv[1], 0, "");
+}