diff rvinterf/etmsync/fsmisc.c @ 300:19b846c8abed

fc-fsio: format and preformat commands added
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 02 Mar 2014 01:32:55 +0000
parents
children 8dd522a8d60e
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rvinterf/etmsync/fsmisc.c	Sun Mar 02 01:32:55 2014 +0000
@@ -0,0 +1,78 @@
+/*
+ * Miscellaneous (dangerous!) FFS2 operations
+ */
+
+#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 "ffslimits.h"
+#include "localtypes.h"
+#include "localstruct.h"
+#include "exitcodes.h"
+
+extern u_char rvi_msg[];
+extern int rvi_msg_len;
+
+cmd_format(argc, argv)
+	char **argv;
+{
+	u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
+	int rc, slen;
+
+	slen = strlen(argv[1]);
+	if (slen >= TMFFS_STRING_SIZE) {
+		printf("error: argument exceeds string length limit\n");
+		return;
+	}
+	dp = cmdpkt + 1;
+	*dp++ = ETM_FFS2;
+	*dp++ = TMFFS_FORMAT;
+	*dp++ = slen + 1;
+	strcpy(dp, argv[1]);
+	dp += slen + 1;
+	/* magic is 0x2BAD, 16-bit little-endian */
+	*dp++ = 0xAD;
+	*dp++ = 0x2B;
+	rc = etm_pkt_exch(cmdpkt, dp - cmdpkt - 1);
+	if (rc)
+		return(rc);
+	if (rvi_msg_len != 5) {
+		printf("error: TMFFS_FORMAT response has wrong length\n");
+		return(ERROR_TARGET);
+	}
+	if (rvi_msg[3]) {
+		report_ffs_err("format", rvi_msg[3]);
+		return(ERROR_TARGET);
+	}
+	return(0);
+}
+
+cmd_preformat()
+{
+	u_char cmdpkt[6];
+	int rc;
+
+	cmdpkt[1] = ETM_FFS2;
+	cmdpkt[2] = TMFFS_PREFORMAT;
+	/* magic is 0xDEAD, 16-bit little-endian */
+	cmdpkt[3] = 0xAD;
+	cmdpkt[4] = 0xDE;
+	rc = etm_pkt_exch(cmdpkt, 4);
+	if (rc)
+		return(rc);
+	if (rvi_msg_len != 5) {
+		printf("error: TMFFS_PREFORMAT response has wrong length\n");
+		return(ERROR_TARGET);
+	}
+	if (rvi_msg[3]) {
+		report_ffs_err("preformat", rvi_msg[3]);
+		return(ERROR_TARGET);
+	}
+	return(0);
+}