changeset 303:61c68a55f2a2

fc-fsio: readlink implemented
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 02 Mar 2014 04:48:33 +0000
parents cd5068cf0551
children e0ca3ca46a06
files rvinterf/etmsync/fscmdtab.c rvinterf/etmsync/symlink.c
diffstat 2 files changed, 62 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/etmsync/fscmdtab.c	Sun Mar 02 04:34:49 2014 +0000
+++ b/rvinterf/etmsync/fscmdtab.c	Sun Mar 02 04:48:33 2014 +0000
@@ -18,6 +18,7 @@
 extern int cmd_ls();
 extern int cmd_mkdir();
 extern int cmd_preformat();
+extern int cmd_readlink();
 extern int cmd_set_imeisv();
 extern int cmd_set_pcm_string();
 extern int cmd_stat();
@@ -41,6 +42,7 @@
 	{"ls", 1, 1, cmd_ls},
 	{"mkdir", 1, 1, cmd_mkdir},
 	{"preformat", 0, 0, cmd_preformat},
+	{"readlink", 1, 1, cmd_readlink},
 	{"set-imeisv", 2, 2, cmd_set_imeisv},
 	{"set-pcm-string", 2, 2, cmd_set_pcm_string},
 	{"stat", 1, 1, cmd_stat},
--- a/rvinterf/etmsync/symlink.c	Sun Mar 02 04:34:49 2014 +0000
+++ b/rvinterf/etmsync/symlink.c	Sun Mar 02 04:48:33 2014 +0000
@@ -63,3 +63,63 @@
 {
 	return do_symlink(argv[1], argv[2]);
 }
+
+do_readlink(pathname, databuf, rdret)
+	char *pathname;
+	u_char *databuf;
+	int *rdret;
+{
+	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
+	int rc, slen, sz;
+
+	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_READLINK;
+	*dp++ = slen + 1;
+	strcpy(dp, pathname);
+	dp += slen + 1;
+	*dp++ = 0;	/* dummy 2nd buffer */
+	rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1);
+	if (rc)
+		return(rc);
+	if (rvi_msg[3]) {
+		report_ffs_err("readlink", rvi_msg[3]);
+		return(ERROR_TARGET);
+	}
+	if (rvi_msg_len < 6) {
+		*rdret = 0;
+		return(0);
+	}
+	sz = rvi_msg[4];
+	if (rvi_msg_len != sz + 6) {
+		printf("error: readlink response has wrong length\n");
+		return(ERROR_TARGET);
+	}
+	bcopy(rvi_msg + 5, databuf, sz);
+	*rdret = sz;
+	return(0);
+}
+
+cmd_readlink(argc, argv)
+	char **argv;
+{
+	u_char databuf[256];
+	int rc, sz, off, l;
+
+	rc = do_readlink(argv[1], databuf, &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);
+}