comparison rvinterf/tmsh/ffs2.c @ 260:c146f38d2b5f

rvinterf subdir structure made a little more sensible
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Wed, 05 Feb 2014 04:02:13 +0000
parents rvinterf/etm/ffs2.c@35113b1964d3
children 7f14d7c789a7
comparison
equal deleted inserted replaced
259:35113b1964d3 260:c146f38d2b5f
1 /*
2 * In this module we are going to implement TMFFS2 functionality.
3 */
4
5 #include <sys/types.h>
6 #include <stdio.h>
7 #include <string.h>
8 #include <strings.h>
9 #include <stdlib.h>
10 #include "pktmux.h"
11 #include "limits.h"
12 #include "localtypes.h"
13 #include "etm.h"
14 #include "tmffs2.h"
15
16 void
17 cmd_ffs2_close(argc, argv)
18 char **argv;
19 {
20 u_char cmdpkt[5];
21
22 cmdpkt[1] = ETM_FFS2;
23 cmdpkt[2] = TMFFS_CLOSE;
24 cmdpkt[3] = strtoul(argv[1], 0, 0);
25 send_etm_cmd(cmdpkt, 3);
26 }
27
28 void
29 cmd_ffs2_delete(argc, argv)
30 char **argv;
31 {
32 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
33 int slen;
34
35 slen = strlen(argv[1]);
36 if (slen >= TMFFS_STRING_SIZE) {
37 printf("error: argument exceeds string length limit\n");
38 return;
39 }
40 dp = cmdpkt + 1;
41 *dp++ = ETM_FFS2;
42 *dp++ = TMFFS_REMOVE;
43 *dp++ = slen + 1;
44 strcpy(dp, argv[1]);
45 dp += slen + 1;
46 send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
47 }
48
49 void
50 cmd_ffs2_format(argc, argv)
51 char **argv;
52 {
53 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
54 int slen;
55
56 slen = strlen(argv[1]);
57 if (slen >= TMFFS_STRING_SIZE) {
58 printf("error: argument exceeds string length limit\n");
59 return;
60 }
61 dp = cmdpkt + 1;
62 *dp++ = ETM_FFS2;
63 *dp++ = TMFFS_FORMAT;
64 *dp++ = slen + 1;
65 strcpy(dp, argv[1]);
66 dp += slen + 1;
67 /* magic is 0x2BAD, 16-bit little-endian */
68 *dp++ = 0xAD;
69 *dp++ = 0x2B;
70 send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
71 }
72
73 void
74 cmd_ffs2_open(argc, argv)
75 char **argv;
76 {
77 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp;
78 int slen;
79
80 slen = strlen(argv[1]);
81 if (slen >= TMFFS_STRING_SIZE) {
82 printf("error: argument exceeds string length limit\n");
83 return;
84 }
85 dp = cmdpkt + 1;
86 *dp++ = ETM_FFS2;
87 *dp++ = TMFFS_OPEN;
88 *dp++ = slen + 1;
89 strcpy(dp, argv[1]);
90 dp += slen + 1;
91 *dp++ = strtoul(argv[2], 0, 16);
92 send_etm_cmd(cmdpkt, dp - cmdpkt - 1);
93 }
94
95 void
96 cmd_ffs2_preformat()
97 {
98 u_char cmdpkt[6];
99
100 cmdpkt[1] = ETM_FFS2;
101 cmdpkt[2] = TMFFS_PREFORMAT;
102 /* magic is 0xDEAD, 16-bit little-endian */
103 cmdpkt[3] = 0xAD;
104 cmdpkt[4] = 0xDE;
105 send_etm_cmd(cmdpkt, 4);
106 }
107
108 void
109 cmd_ffs2_version()
110 {
111 u_char cmdpkt[4];
112
113 cmdpkt[1] = ETM_FFS2;
114 cmdpkt[2] = TMFFS_VERSION;
115 send_etm_cmd(cmdpkt, 2);
116 }
117
118 static struct cmdtab {
119 char *cmd;
120 int minargs;
121 int maxargs;
122 void (*func)();
123 } ffs2_cmds[] = {
124 {"close", 1, 1, cmd_ffs2_close},
125 {"delete", 1, 1, cmd_ffs2_delete},
126 {"format", 1, 1, cmd_ffs2_format},
127 {"open", 2, 2, cmd_ffs2_open},
128 {"preformat", 0, 0, cmd_ffs2_preformat},
129 {"version", 0, 0, cmd_ffs2_version},
130 {0, 0, 0, 0}
131 };
132
133 void
134 cmd_ffs2(argc, argv)
135 char **argv;
136 {
137 struct cmdtab *tp;
138 int extargs;
139
140 for (tp = ffs2_cmds; tp->cmd; tp++)
141 if (!strcmp(tp->cmd, argv[1]))
142 break;
143 if (!tp->func) {
144 printf("error: no such ffs2 command\n");
145 return;
146 }
147 extargs = argc - 2;
148 if (extargs > tp->maxargs) {
149 printf("error: too many arguments\n");
150 return;
151 }
152 if (extargs < tp->minargs) {
153 printf("error: too few arguments\n");
154 return;
155 }
156 tp->func(argc - 1, argv + 1);
157 }