changeset 286:146e7bf3fa4e

fc-fsio: fd debug commands implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 28 Feb 2014 06:45:10 +0000
parents bb28ba9e82c5
children 211b35db427c
files rvinterf/etmsync/Makefile rvinterf/etmsync/fdcmd.c rvinterf/etmsync/fileio.c rvinterf/etmsync/fscmdtab.c
diffstat 4 files changed, 97 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/etmsync/Makefile	Fri Feb 28 06:16:02 2014 +0000
+++ b/rvinterf/etmsync/Makefile	Fri Feb 28 06:45:10 2014 +0000
@@ -3,8 +3,8 @@
 PROGS=	fc-fsio
 INSTBIN=/usr/local/bin
 
-FSIO_OBJS=	connect.o dispatch.o fileio.o fsbasics.o fscmdtab.o fsiomain.o \
-		fsread.o interf.o launchrvif.o
+FSIO_OBJS=	connect.o dispatch.o fdcmd.o fileio.o fsbasics.o fscmdtab.o \
+		fsiomain.o fsread.o interf.o launchrvif.o
 
 all:	${PROGS}
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/etmsync/fdcmd.c	Fri Feb 28 06:45:10 2014 +0000
@@ -0,0 +1,87 @@
+/*
+ * File descriptor debug commands
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "etm.h"
+#include "ffs.h"
+#include "tmffs2.h"
+#include "limits.h"
+#include "localtypes.h"
+#include "localstruct.h"
+#include "cmdtab.h"
+#include "exitcodes.h"
+
+cmd_fd_open(argc, argv)
+	char **argv;
+{
+	int rc, fd;
+
+	rc = fd_open(argv[1], strtoul(argv[2], 0, 0), &fd);
+	if (rc)
+		return(rc);
+	printf("%d\n", fd);
+	return(0);
+}
+
+cmd_fd_read(argc, argv)
+	char **argv;
+{
+	u_char databuf[MAX_READ_DATA];
+	int rc, sz, off, l;
+
+	rc = fd_read(strtoul(argv[1], 0, 0), databuf, strtoul(argv[2], 0, 0),
+			&sz);
+	if (rc)
+		return(rc);
+	printf("%d bytes read\n", sz);
+	for (off = 0; off < sz; off += 16) {
+		l = sz - off;
+		if (l > 16)
+			l = 16;
+		hexdump_line(off, databuf + off, l);
+	}
+	return(0);
+}
+
+cmd_fd_close(argc, argv)
+	char **argv;
+{
+	return fd_close(strtoul(argv[1], 0, 0));
+}
+
+struct cmdtab fd_cmds[] = {
+	{"close", 1, 1, cmd_fd_close},
+	{"open", 2, 2, cmd_fd_open},
+	{"read", 2, 2, cmd_fd_read},
+	{0, 0, 0, 0}
+};
+
+cmd_fd(argc, argv)
+	char **argv;
+{
+	struct cmdtab *tp;
+	int extargs;
+
+	for (tp = fd_cmds; tp->cmd; tp++)
+		if (!strcmp(tp->cmd, argv[1]))
+			break;
+	if (!tp->func) {
+		fprintf(stderr, "error: no such fd command\n");
+		return(ERROR_USAGE);
+	}
+	extargs = argc - 2;
+	if (extargs > tp->maxargs) {
+		fprintf(stderr, "error: too many arguments\n");
+		return(ERROR_USAGE);
+	}
+	if (extargs < tp->minargs) {
+		fprintf(stderr, "error: too few arguments\n");
+		return(ERROR_USAGE);
+	}
+	return tp->func(argc - 1, argv + 1);
+}
--- a/rvinterf/etmsync/fileio.c	Fri Feb 28 06:16:02 2014 +0000
+++ b/rvinterf/etmsync/fileio.c	Fri Feb 28 06:45:10 2014 +0000
@@ -60,9 +60,9 @@
 	int rc, sz;
 
 	if (rdsize > MAX_READ_DATA) {
-		fprintf(stderr,
-	"BUG: attempt to read more than possible per TMFFS2 protocol\n");
-		exit(ERROR_BUG);
+		printf("error: # of bytes to read may not exceed %d\n",
+			MAX_READ_DATA);
+		return(ERROR_USAGE);
 	}
 	cmdpkt[1] = ETM_FFS2;
 	cmdpkt[2] = TMFFS_READ;
@@ -125,9 +125,9 @@
 		return(ERROR_USAGE);
 	}
 	if (rdsize > MAX_READ_DATA) {
-		fprintf(stderr,
-	"BUG: attempt to read more than possible per TMFFS2 protocol\n");
-		exit(ERROR_BUG);
+		printf("error: # of bytes to read may not exceed %d\n",
+			MAX_READ_DATA);
+		return(ERROR_USAGE);
 	}
 	dp = cmdpkt + 1;
 	*dp++ = ETM_FFS2;
--- a/rvinterf/etmsync/fscmdtab.c	Fri Feb 28 06:16:02 2014 +0000
+++ b/rvinterf/etmsync/fscmdtab.c	Fri Feb 28 06:45:10 2014 +0000
@@ -6,6 +6,7 @@
 
 extern int cmd_exec();
 extern int cmd_exit();
+extern int cmd_fd();
 extern int cmd_ffs2ver();
 extern int cmd_hd();
 extern int cmd_ll();
@@ -15,6 +16,7 @@
 struct cmdtab cmdtab[] = {
 	{"exec", 1, 1, cmd_exec},
 	{"exit", 0, 0, cmd_exit},
+	{"fd", 2, 3, cmd_fd},
 	{"ffs2ver", 0, 0, cmd_ffs2ver},
 	{"hd", 1, 1, cmd_hd},
 	{"ll", 1, 1, cmd_ll},