changeset 282:517e8a428fde

fc-fsio: xlstat operation implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 25 Feb 2014 07:42:21 +0000
parents 082d12a1651e
children 88eed3327682
files rvinterf/etmsync/fsbasics.c rvinterf/etmsync/fscmdtab.c rvinterf/etmsync/localstruct.h rvinterf/include/ffs.h
diffstat 4 files changed, 107 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/etmsync/fsbasics.c	Mon Feb 24 07:44:33 2014 +0000
+++ b/rvinterf/etmsync/fsbasics.c	Tue Feb 25 07:42:21 2014 +0000
@@ -11,6 +11,8 @@
 #include "ffs.h"
 #include "tmffs2.h"
 #include "limits.h"
+#include "localtypes.h"
+#include "localstruct.h"
 #include "exitcodes.h"
 
 extern u_char rvi_msg[];
@@ -130,3 +132,78 @@
 	}
 	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]) {
+		printf("xlstat: FFS error %d\n", 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;
+{
+	struct stat_info stat;
+	int rc;
+	char *type;
+
+	rc = do_xlstat(argv[1], &stat);
+	if (rc)
+		return(rc);
+	switch (stat.type) {
+	case OT_FILE:
+		type = "file";
+		break;
+	case OT_DIR:
+		type = "directory";
+		break;
+	case OT_LINK:
+		type = "symlink";
+		break;
+	default:
+		type = "???";
+	}
+	printf("Type: %s%s\n", type,
+		stat.flags & OF_READONLY ? ", read-only" : "");
+	printf("inode %x\n", stat.inode);
+	printf("size %u, space %u\n", stat.size, stat.space);
+	printf("location=%x, block %d\n", stat.location, stat.block);
+	return(0);
+}
--- a/rvinterf/etmsync/fscmdtab.c	Mon Feb 24 07:44:33 2014 +0000
+++ b/rvinterf/etmsync/fscmdtab.c	Tue Feb 25 07:42:21 2014 +0000
@@ -8,11 +8,13 @@
 extern int cmd_exit();
 extern int cmd_ffs2ver();
 extern int cmd_ls();
+extern int cmd_stat();
 
 struct cmdtab cmdtab[] = {
 	{"exec", 1, 1, cmd_exec},
 	{"exit", 0, 0, cmd_exit},
 	{"ffs2ver", 0, 0, cmd_ffs2ver},
 	{"ls", 1, 1, cmd_ls},
+	{"stat", 1, 1, cmd_stat},
 	{0, 0, 0, 0}
 };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/etmsync/localstruct.h	Tue Feb 25 07:42:21 2014 +0000
@@ -0,0 +1,17 @@
+/*
+ * The struct defined below captures the results of a stat (actually xlstat)
+ * operation on the target; it is a host (aka local) struct, with host byte
+ * ordering, alignment and data types.
+ */
+
+struct stat_info {
+	u8	type;
+	u8	flags;
+	int	inode;
+	u32	size;     // size of data space occupied by object
+	u32	space;    // size of physical data space occupied by object
+	u32	location;
+	u8	block;
+	u16	sequence;
+	u16	updates;
+};
--- a/rvinterf/include/ffs.h	Mon Feb 24 07:44:33 2014 +0000
+++ b/rvinterf/include/ffs.h	Tue Feb 25 07:42:21 2014 +0000
@@ -2,6 +2,17 @@
  * A few generic FFS API definitions which apply to both TMFFS1 and TMFFS2
  */
 
+enum FFS_OBJECT_TYPE {
+    OT_FILE    = 1,
+    OT_DIR     = 2,
+    OT_LINK    = 3,
+    OT_SEGMENT = 4
+};
+
+enum FFS_OBJECT_FLAGS {
+    OF_READONLY = 1<<4  // object cannot be modified
+};
+
 enum FFS_OPEN {
     FFS_O_EMPTY  = 0x00,  // Okay?
     FFS_O_CREATE = 0x01,