changeset 910:d1333db6385f

rvinterf/etmsync refactoring: operation functions consolidated in fileio.c
author Space Falcon <falcon@ivan.Harhan.ORG>
date Tue, 08 Sep 2015 06:34:02 +0000
parents 16ed75e266f2
children 42719fa3e6af
files rvinterf/etmsync/fileio.c rvinterf/etmsync/fsbasics.c rvinterf/etmsync/fswrite.c
diffstat 3 files changed, 162 insertions(+), 161 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/etmsync/fileio.c	Mon Sep 07 17:25:30 2015 +0000
+++ b/rvinterf/etmsync/fileio.c	Tue Sep 08 06:34:02 2015 +0000
@@ -9,6 +9,7 @@
 #include <strings.h>
 #include "etm.h"
 #include "ffs.h"
+#include "ffserr.h"
 #include "tmffs2.h"
 #include "limits.h"
 #include "localtypes.h"
@@ -237,3 +238,164 @@
 	}
 	return(0);
 }
+
+do_opendir(pathname, statertn, countrtn)
+	char *pathname;
+	u_char *statertn;
+	int *countrtn;
+{
+	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_OPENDIR;
+	*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]) {
+		report_ffs_err("opendir", rvi_msg[3]);
+		return(ERROR_TARGET);
+	}
+	if (rvi_msg_len != 11 || rvi_msg[5] != 4) {
+		printf("error: opendir response has wrong length\n");
+		return(ERROR_TARGET);
+	}
+	*countrtn = rvi_msg[4];
+	bcopy(rvi_msg + 6, statertn, 4);
+	return(0);
+}
+
+do_readdir(state, namebuf, namebuflen)
+	u_char *state;
+	char *namebuf;
+{
+	u_char cmdpkt[10];
+	int rc, slen;
+
+	cmdpkt[1] = ETM_FFS2;
+	cmdpkt[2] = TMFFS_READDIR;
+	cmdpkt[3] = 4;
+	bcopy(state, cmdpkt+4, 4);
+	cmdpkt[8] = TMFFS_STRING_SIZE;
+	rc = etm_pkt_exch(cmdpkt, 8);
+	if (rc)
+		return(rc);
+	if (rvi_msg[3]) {
+		report_ffs_err("readdir", rvi_msg[3]);
+		return(ERROR_TARGET);
+	}
+	if (rvi_msg_len < 14) {
+malformed:	printf("error: readdir response is malformed\n");
+		return(ERROR_TARGET);
+	}
+	if (rvi_msg[5] != 4)
+		goto malformed;
+	slen = rvi_msg[10];
+	if (slen < 2 || rvi_msg_len != slen + 12)
+		goto malformed;
+	if (slen > namebuflen) {
+		printf("error: readdir response exceeds provided buffer\n");
+		return(ERROR_TARGET);
+	}
+	if (rvi_msg[11 + slen - 1])	/* must be terminating NUL */
+		goto malformed;
+	bcopy(rvi_msg + 6, state, 4);
+	strcpy(namebuf, rvi_msg + 11);
+	return(0);
+}
+
+do_xlstat(pathname, result)
+	char *pathname;
+	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]) {
+		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);
+	}
+	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;
+{
+	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);
+	}
+}
--- a/rvinterf/etmsync/fsbasics.c	Mon Sep 07 17:25:30 2015 +0000
+++ b/rvinterf/etmsync/fsbasics.c	Tue Sep 08 06:34:02 2015 +0000
@@ -41,80 +41,6 @@
 	return(0);
 }
 
-do_opendir(pathname, statertn, countrtn)
-	char *pathname;
-	u_char *statertn;
-	int *countrtn;
-{
-	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_OPENDIR;
-	*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]) {
-		report_ffs_err("opendir", rvi_msg[3]);
-		return(ERROR_TARGET);
-	}
-	if (rvi_msg_len != 11 || rvi_msg[5] != 4) {
-		printf("error: opendir response has wrong length\n");
-		return(ERROR_TARGET);
-	}
-	*countrtn = rvi_msg[4];
-	bcopy(rvi_msg + 6, statertn, 4);
-	return(0);
-}
-
-do_readdir(state, namebuf, namebuflen)
-	u_char *state;
-	char *namebuf;
-{
-	u_char cmdpkt[10];
-	int rc, slen;
-
-	cmdpkt[1] = ETM_FFS2;
-	cmdpkt[2] = TMFFS_READDIR;
-	cmdpkt[3] = 4;
-	bcopy(state, cmdpkt+4, 4);
-	cmdpkt[8] = TMFFS_STRING_SIZE;
-	rc = etm_pkt_exch(cmdpkt, 8);
-	if (rc)
-		return(rc);
-	if (rvi_msg[3]) {
-		report_ffs_err("readdir", rvi_msg[3]);
-		return(ERROR_TARGET);
-	}
-	if (rvi_msg_len < 14) {
-malformed:	printf("error: readdir response is malformed\n");
-		return(ERROR_TARGET);
-	}
-	if (rvi_msg[5] != 4)
-		goto malformed;
-	slen = rvi_msg[10];
-	if (slen < 2 || rvi_msg_len != slen + 12)
-		goto malformed;
-	if (slen > namebuflen) {
-		printf("error: readdir response exceeds provided buffer\n");
-		return(ERROR_TARGET);
-	}
-	if (rvi_msg[11 + slen - 1])	/* must be terminating NUL */
-		goto malformed;
-	bcopy(rvi_msg + 6, state, 4);
-	strcpy(namebuf, rvi_msg + 11);
-	return(0);
-}
-
 cmd_ls(argc, argv)
 	char **argv;
 {
@@ -138,50 +64,6 @@
 	return(0);
 }
 
-do_xlstat(pathname, result)
-	char *pathname;
-	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]) {
-		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);
-	}
-	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);
-}
-
 cmd_stat(argc, argv)
 	char **argv;
 {
--- a/rvinterf/etmsync/fswrite.c	Mon Sep 07 17:25:30 2015 +0000
+++ b/rvinterf/etmsync/fswrite.c	Tue Sep 08 06:34:02 2015 +0000
@@ -20,49 +20,6 @@
 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;
 {