FreeCalypso > hg > freecalypso-tools
comparison rvinterf/tmsh/ffs2.c @ 0:e7502631a0f9
initial import from freecalypso-sw rev 1033:5ab737ac3ad7
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 11 Jun 2016 00:13:35 +0000 |
parents | |
children | 2159f260ed13 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e7502631a0f9 |
---|---|
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 "limits.h" | |
11 #include "localtypes.h" | |
12 #include "etm.h" | |
13 #include "ffs.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: pathname arg 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_mkdir(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: pathname arg exceeds string length limit\n"); | |
83 return; | |
84 } | |
85 dp = cmdpkt + 1; | |
86 *dp++ = ETM_FFS2; | |
87 *dp++ = TMFFS_MKDIR; | |
88 *dp++ = slen + 1; | |
89 strcpy(dp, argv[1]); | |
90 dp += slen + 1; | |
91 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | |
92 } | |
93 | |
94 void | |
95 cmd_ffs2_open(argc, argv) | |
96 char **argv; | |
97 { | |
98 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; | |
99 int slen; | |
100 | |
101 slen = strlen(argv[1]); | |
102 if (slen >= TMFFS_STRING_SIZE) { | |
103 printf("error: pathname arg exceeds string length limit\n"); | |
104 return; | |
105 } | |
106 dp = cmdpkt + 1; | |
107 *dp++ = ETM_FFS2; | |
108 *dp++ = TMFFS_OPEN; | |
109 *dp++ = slen + 1; | |
110 strcpy(dp, argv[1]); | |
111 dp += slen + 1; | |
112 *dp++ = strtoul(argv[2], 0, 16); | |
113 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | |
114 } | |
115 | |
116 void | |
117 cmd_ffs2_opendir(argc, argv) | |
118 char **argv; | |
119 { | |
120 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; | |
121 int slen; | |
122 | |
123 slen = strlen(argv[1]); | |
124 if (slen >= TMFFS_STRING_SIZE) { | |
125 printf("error: pathname arg exceeds string length limit\n"); | |
126 return; | |
127 } | |
128 dp = cmdpkt + 1; | |
129 *dp++ = ETM_FFS2; | |
130 *dp++ = TMFFS_OPENDIR; | |
131 *dp++ = slen + 1; | |
132 strcpy(dp, argv[1]); | |
133 dp += slen + 1; | |
134 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | |
135 } | |
136 | |
137 void | |
138 cmd_ffs2_preformat() | |
139 { | |
140 u_char cmdpkt[6]; | |
141 | |
142 cmdpkt[1] = ETM_FFS2; | |
143 cmdpkt[2] = TMFFS_PREFORMAT; | |
144 /* magic is 0xDEAD, 16-bit little-endian */ | |
145 cmdpkt[3] = 0xAD; | |
146 cmdpkt[4] = 0xDE; | |
147 send_etm_cmd(cmdpkt, 4); | |
148 } | |
149 | |
150 void | |
151 cmd_ffs2_query(argc, argv) | |
152 char **argv; | |
153 { | |
154 u_char cmdpkt[5]; | |
155 | |
156 cmdpkt[1] = ETM_FFS2; | |
157 cmdpkt[2] = TMFFS_QUERY; | |
158 cmdpkt[3] = strtoul(argv[1], 0, 0); | |
159 send_etm_cmd(cmdpkt, 3); | |
160 } | |
161 | |
162 void | |
163 cmd_ffs2_readfd(argc, argv) | |
164 char **argv; | |
165 { | |
166 u_char cmdpkt[6]; | |
167 | |
168 cmdpkt[1] = ETM_FFS2; | |
169 cmdpkt[2] = TMFFS_READ; | |
170 cmdpkt[3] = strtoul(argv[1], 0, 0); | |
171 cmdpkt[4] = strtoul(argv[2], 0, 0); | |
172 send_etm_cmd(cmdpkt, 4); | |
173 } | |
174 | |
175 void | |
176 cmd_ffs2_readfile(argc, argv) | |
177 char **argv; | |
178 { | |
179 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; | |
180 int slen; | |
181 | |
182 slen = strlen(argv[1]); | |
183 if (slen >= TMFFS_STRING_SIZE) { | |
184 printf("error: pathname arg exceeds string length limit\n"); | |
185 return; | |
186 } | |
187 dp = cmdpkt + 1; | |
188 *dp++ = ETM_FFS2; | |
189 *dp++ = TMFFS_FILE_READ; | |
190 *dp++ = slen + 1; | |
191 strcpy(dp, argv[1]); | |
192 dp += slen + 1; | |
193 *dp++ = strtoul(argv[2], 0, 0); | |
194 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | |
195 } | |
196 | |
197 void | |
198 cmd_ffs2_stat(argc, argv) | |
199 char **argv; | |
200 { | |
201 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; | |
202 int slen; | |
203 | |
204 slen = strlen(argv[1]); | |
205 if (slen >= TMFFS_STRING_SIZE) { | |
206 printf("error: pathname arg exceeds string length limit\n"); | |
207 return; | |
208 } | |
209 dp = cmdpkt + 1; | |
210 *dp++ = ETM_FFS2; | |
211 *dp++ = TMFFS_STAT; | |
212 *dp++ = slen + 1; | |
213 strcpy(dp, argv[1]); | |
214 dp += slen + 1; | |
215 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | |
216 } | |
217 | |
218 void | |
219 cmd_ffs2_version() | |
220 { | |
221 u_char cmdpkt[4]; | |
222 | |
223 cmdpkt[1] = ETM_FFS2; | |
224 cmdpkt[2] = TMFFS_VERSION; | |
225 send_etm_cmd(cmdpkt, 2); | |
226 } | |
227 | |
228 void | |
229 cmd_ffs2_wrfile(argc, argv) | |
230 char **argv; | |
231 { | |
232 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; | |
233 int slen, slen2; | |
234 | |
235 slen = strlen(argv[1]); | |
236 if (slen >= TMFFS_STRING_SIZE) { | |
237 printf("error: pathname arg exceeds string length limit\n"); | |
238 return; | |
239 } | |
240 slen2 = strlen(argv[2]); | |
241 if (slen2 > 64) { | |
242 printf("error: write test data argument is too long\n"); | |
243 return; | |
244 } | |
245 dp = cmdpkt + 1; | |
246 *dp++ = ETM_FFS2; | |
247 *dp++ = TMFFS_FILE_WRITE; | |
248 *dp++ = slen + 1; | |
249 strcpy(dp, argv[1]); | |
250 dp += slen + 1; | |
251 *dp++ = slen2; /* no NUL-termination on test data */ | |
252 strcpy(dp, argv[2]); | |
253 dp += slen2; | |
254 *dp++ = FFS_O_CREATE | FFS_O_TRUNC; | |
255 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | |
256 } | |
257 | |
258 void | |
259 cmd_ffs2_writefd(argc, argv) | |
260 char **argv; | |
261 { | |
262 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; | |
263 int slen2; | |
264 | |
265 slen2 = strlen(argv[2]); | |
266 if (slen2 > 64) { | |
267 printf("error: write test data argument is too long\n"); | |
268 return; | |
269 } | |
270 dp = cmdpkt + 1; | |
271 *dp++ = ETM_FFS2; | |
272 *dp++ = TMFFS_WRITE; | |
273 *dp++ = strtoul(argv[1], 0, 0); | |
274 *dp++ = slen2; /* no NUL-termination on test data */ | |
275 strcpy(dp, argv[2]); | |
276 dp += slen2; | |
277 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | |
278 } | |
279 | |
280 void | |
281 cmd_ffs2_xlstat(argc, argv) | |
282 char **argv; | |
283 { | |
284 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; | |
285 int slen; | |
286 | |
287 slen = strlen(argv[1]); | |
288 if (slen >= TMFFS_STRING_SIZE) { | |
289 printf("error: pathname arg exceeds string length limit\n"); | |
290 return; | |
291 } | |
292 dp = cmdpkt + 1; | |
293 *dp++ = ETM_FFS2; | |
294 *dp++ = TMFFS_XLSTAT; | |
295 *dp++ = slen + 1; | |
296 strcpy(dp, argv[1]); | |
297 dp += slen + 1; | |
298 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | |
299 } | |
300 | |
301 static struct cmdtab { | |
302 char *cmd; | |
303 int minargs; | |
304 int maxargs; | |
305 void (*func)(); | |
306 } ffs2_cmds[] = { | |
307 {"close", 1, 1, cmd_ffs2_close}, | |
308 {"delete", 1, 1, cmd_ffs2_delete}, | |
309 {"format", 1, 1, cmd_ffs2_format}, | |
310 {"mkdir", 1, 1, cmd_ffs2_mkdir}, | |
311 {"open", 2, 2, cmd_ffs2_open}, | |
312 {"opendir", 1, 1, cmd_ffs2_opendir}, | |
313 {"preformat", 0, 0, cmd_ffs2_preformat}, | |
314 {"query", 1, 1, cmd_ffs2_query}, | |
315 {"readfd", 2, 2, cmd_ffs2_readfd}, | |
316 {"readfile", 2, 2, cmd_ffs2_readfile}, | |
317 {"stat", 1, 1, cmd_ffs2_stat}, | |
318 {"version", 0, 0, cmd_ffs2_version}, | |
319 {"wrfile", 2, 2, cmd_ffs2_wrfile}, | |
320 {"writefd", 2, 2, cmd_ffs2_writefd}, | |
321 {"xlstat", 1, 1, cmd_ffs2_xlstat}, | |
322 {0, 0, 0, 0} | |
323 }; | |
324 | |
325 void | |
326 cmd_ffs2(argc, argv) | |
327 char **argv; | |
328 { | |
329 struct cmdtab *tp; | |
330 int extargs; | |
331 | |
332 for (tp = ffs2_cmds; tp->cmd; tp++) | |
333 if (!strcmp(tp->cmd, argv[1])) | |
334 break; | |
335 if (!tp->func) { | |
336 printf("error: no such ffs2 command\n"); | |
337 return; | |
338 } | |
339 extargs = argc - 2; | |
340 if (extargs > tp->maxargs) { | |
341 printf("error: too many arguments\n"); | |
342 return; | |
343 } | |
344 if (extargs < tp->minargs) { | |
345 printf("error: too few arguments\n"); | |
346 return; | |
347 } | |
348 tp->func(argc - 1, argv + 1); | |
349 } |