FreeCalypso > hg > freecalypso-sw
comparison rvinterf/tmsh/ffs2.c @ 261:7f14d7c789a7
fc-tmsh ffs2: most commands implemented
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Wed, 05 Feb 2014 05:48:47 +0000 |
parents | c146f38d2b5f |
children | b5b54feb111a |
comparison
equal
deleted
inserted
replaced
260:c146f38d2b5f | 261:7f14d7c789a7 |
---|---|
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include "pktmux.h" | 10 #include "pktmux.h" |
11 #include "limits.h" | 11 #include "limits.h" |
12 #include "localtypes.h" | 12 #include "localtypes.h" |
13 #include "etm.h" | 13 #include "etm.h" |
14 #include "ffs.h" | |
14 #include "tmffs2.h" | 15 #include "tmffs2.h" |
15 | 16 |
16 void | 17 void |
17 cmd_ffs2_close(argc, argv) | 18 cmd_ffs2_close(argc, argv) |
18 char **argv; | 19 char **argv; |
32 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; | 33 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; |
33 int slen; | 34 int slen; |
34 | 35 |
35 slen = strlen(argv[1]); | 36 slen = strlen(argv[1]); |
36 if (slen >= TMFFS_STRING_SIZE) { | 37 if (slen >= TMFFS_STRING_SIZE) { |
37 printf("error: argument exceeds string length limit\n"); | 38 printf("error: pathname arg exceeds string length limit\n"); |
38 return; | 39 return; |
39 } | 40 } |
40 dp = cmdpkt + 1; | 41 dp = cmdpkt + 1; |
41 *dp++ = ETM_FFS2; | 42 *dp++ = ETM_FFS2; |
42 *dp++ = TMFFS_REMOVE; | 43 *dp++ = TMFFS_REMOVE; |
69 *dp++ = 0x2B; | 70 *dp++ = 0x2B; |
70 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | 71 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); |
71 } | 72 } |
72 | 73 |
73 void | 74 void |
75 cmd_ffs2_mkdir(argc, argv) | |
76 char **argv; | |
77 { | |
78 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; | |
79 int slen; | |
80 | |
81 slen = strlen(argv[1]); | |
82 if (slen >= TMFFS_STRING_SIZE) { | |
83 printf("error: pathname arg exceeds string length limit\n"); | |
84 return; | |
85 } | |
86 dp = cmdpkt + 1; | |
87 *dp++ = ETM_FFS2; | |
88 *dp++ = TMFFS_MKDIR; | |
89 *dp++ = slen + 1; | |
90 strcpy(dp, argv[1]); | |
91 dp += slen + 1; | |
92 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | |
93 } | |
94 | |
95 void | |
74 cmd_ffs2_open(argc, argv) | 96 cmd_ffs2_open(argc, argv) |
75 char **argv; | 97 char **argv; |
76 { | 98 { |
77 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; | 99 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; |
78 int slen; | 100 int slen; |
79 | 101 |
80 slen = strlen(argv[1]); | 102 slen = strlen(argv[1]); |
81 if (slen >= TMFFS_STRING_SIZE) { | 103 if (slen >= TMFFS_STRING_SIZE) { |
82 printf("error: argument exceeds string length limit\n"); | 104 printf("error: pathname arg exceeds string length limit\n"); |
83 return; | 105 return; |
84 } | 106 } |
85 dp = cmdpkt + 1; | 107 dp = cmdpkt + 1; |
86 *dp++ = ETM_FFS2; | 108 *dp++ = ETM_FFS2; |
87 *dp++ = TMFFS_OPEN; | 109 *dp++ = TMFFS_OPEN; |
88 *dp++ = slen + 1; | 110 *dp++ = slen + 1; |
89 strcpy(dp, argv[1]); | 111 strcpy(dp, argv[1]); |
90 dp += slen + 1; | 112 dp += slen + 1; |
91 *dp++ = strtoul(argv[2], 0, 16); | 113 *dp++ = strtoul(argv[2], 0, 16); |
114 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | |
115 } | |
116 | |
117 void | |
118 cmd_ffs2_opendir(argc, argv) | |
119 char **argv; | |
120 { | |
121 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; | |
122 int slen; | |
123 | |
124 slen = strlen(argv[1]); | |
125 if (slen >= TMFFS_STRING_SIZE) { | |
126 printf("error: pathname arg exceeds string length limit\n"); | |
127 return; | |
128 } | |
129 dp = cmdpkt + 1; | |
130 *dp++ = ETM_FFS2; | |
131 *dp++ = TMFFS_OPENDIR; | |
132 *dp++ = slen + 1; | |
133 strcpy(dp, argv[1]); | |
134 dp += slen + 1; | |
92 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | 135 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); |
93 } | 136 } |
94 | 137 |
95 void | 138 void |
96 cmd_ffs2_preformat() | 139 cmd_ffs2_preformat() |
104 cmdpkt[4] = 0xDE; | 147 cmdpkt[4] = 0xDE; |
105 send_etm_cmd(cmdpkt, 4); | 148 send_etm_cmd(cmdpkt, 4); |
106 } | 149 } |
107 | 150 |
108 void | 151 void |
152 cmd_ffs2_query(argc, argv) | |
153 char **argv; | |
154 { | |
155 u_char cmdpkt[5]; | |
156 | |
157 cmdpkt[1] = ETM_FFS2; | |
158 cmdpkt[2] = TMFFS_QUERY; | |
159 cmdpkt[3] = strtoul(argv[1], 0, 0); | |
160 send_etm_cmd(cmdpkt, 3); | |
161 } | |
162 | |
163 void | |
164 cmd_ffs2_readfd(argc, argv) | |
165 char **argv; | |
166 { | |
167 u_char cmdpkt[6]; | |
168 | |
169 cmdpkt[1] = ETM_FFS2; | |
170 cmdpkt[2] = TMFFS_READ; | |
171 cmdpkt[3] = strtoul(argv[1], 0, 0); | |
172 cmdpkt[4] = strtoul(argv[2], 0, 0); | |
173 send_etm_cmd(cmdpkt, 4); | |
174 } | |
175 | |
176 void | |
177 cmd_ffs2_readfile(argc, argv) | |
178 char **argv; | |
179 { | |
180 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; | |
181 int slen; | |
182 | |
183 slen = strlen(argv[1]); | |
184 if (slen >= TMFFS_STRING_SIZE) { | |
185 printf("error: pathname arg exceeds string length limit\n"); | |
186 return; | |
187 } | |
188 dp = cmdpkt + 1; | |
189 *dp++ = ETM_FFS2; | |
190 *dp++ = TMFFS_FILE_READ; | |
191 *dp++ = slen + 1; | |
192 strcpy(dp, argv[1]); | |
193 dp += slen + 1; | |
194 *dp++ = strtoul(argv[2], 0, 0); | |
195 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | |
196 } | |
197 | |
198 void | |
199 cmd_ffs2_stat(argc, argv) | |
200 char **argv; | |
201 { | |
202 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; | |
203 int slen; | |
204 | |
205 slen = strlen(argv[1]); | |
206 if (slen >= TMFFS_STRING_SIZE) { | |
207 printf("error: pathname arg exceeds string length limit\n"); | |
208 return; | |
209 } | |
210 dp = cmdpkt + 1; | |
211 *dp++ = ETM_FFS2; | |
212 *dp++ = TMFFS_STAT; | |
213 *dp++ = slen + 1; | |
214 strcpy(dp, argv[1]); | |
215 dp += slen + 1; | |
216 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | |
217 } | |
218 | |
219 void | |
109 cmd_ffs2_version() | 220 cmd_ffs2_version() |
110 { | 221 { |
111 u_char cmdpkt[4]; | 222 u_char cmdpkt[4]; |
112 | 223 |
113 cmdpkt[1] = ETM_FFS2; | 224 cmdpkt[1] = ETM_FFS2; |
114 cmdpkt[2] = TMFFS_VERSION; | 225 cmdpkt[2] = TMFFS_VERSION; |
115 send_etm_cmd(cmdpkt, 2); | 226 send_etm_cmd(cmdpkt, 2); |
227 } | |
228 | |
229 void | |
230 cmd_ffs2_wrfile(argc, argv) | |
231 char **argv; | |
232 { | |
233 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; | |
234 int slen, slen2; | |
235 | |
236 slen = strlen(argv[1]); | |
237 if (slen >= TMFFS_STRING_SIZE) { | |
238 printf("error: pathname arg exceeds string length limit\n"); | |
239 return; | |
240 } | |
241 slen2 = strlen(argv[2]); | |
242 if (slen2 > 64) { | |
243 printf("error: write test data argument is too long\n"); | |
244 return; | |
245 } | |
246 dp = cmdpkt + 1; | |
247 *dp++ = ETM_FFS2; | |
248 *dp++ = TMFFS_FILE_WRITE; | |
249 *dp++ = slen + 1; | |
250 strcpy(dp, argv[1]); | |
251 dp += slen + 1; | |
252 *dp++ = slen2; /* no NUL-termination on test data */ | |
253 strcpy(dp, argv[2]); | |
254 dp += slen2; | |
255 *dp++ = FFS_O_CREATE | FFS_O_TRUNC; | |
256 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | |
257 } | |
258 | |
259 void | |
260 cmd_ffs2_writefd(argc, argv) | |
261 char **argv; | |
262 { | |
263 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; | |
264 int slen2; | |
265 | |
266 slen2 = strlen(argv[2]); | |
267 if (slen2 > 64) { | |
268 printf("error: write test data argument is too long\n"); | |
269 return; | |
270 } | |
271 dp = cmdpkt + 1; | |
272 *dp++ = ETM_FFS2; | |
273 *dp++ = TMFFS_WRITE; | |
274 *dp++ = strtoul(argv[1], 0, 0); | |
275 *dp++ = slen2; /* no NUL-termination on test data */ | |
276 strcpy(dp, argv[2]); | |
277 dp += slen2; | |
278 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | |
279 } | |
280 | |
281 void | |
282 cmd_ffs2_xlstat(argc, argv) | |
283 char **argv; | |
284 { | |
285 u_char cmdpkt[MAX_PKT_TO_TARGET], *dp; | |
286 int slen; | |
287 | |
288 slen = strlen(argv[1]); | |
289 if (slen >= TMFFS_STRING_SIZE) { | |
290 printf("error: pathname arg exceeds string length limit\n"); | |
291 return; | |
292 } | |
293 dp = cmdpkt + 1; | |
294 *dp++ = ETM_FFS2; | |
295 *dp++ = TMFFS_XLSTAT; | |
296 *dp++ = slen + 1; | |
297 strcpy(dp, argv[1]); | |
298 dp += slen + 1; | |
299 send_etm_cmd(cmdpkt, dp - cmdpkt - 1); | |
116 } | 300 } |
117 | 301 |
118 static struct cmdtab { | 302 static struct cmdtab { |
119 char *cmd; | 303 char *cmd; |
120 int minargs; | 304 int minargs; |
122 void (*func)(); | 306 void (*func)(); |
123 } ffs2_cmds[] = { | 307 } ffs2_cmds[] = { |
124 {"close", 1, 1, cmd_ffs2_close}, | 308 {"close", 1, 1, cmd_ffs2_close}, |
125 {"delete", 1, 1, cmd_ffs2_delete}, | 309 {"delete", 1, 1, cmd_ffs2_delete}, |
126 {"format", 1, 1, cmd_ffs2_format}, | 310 {"format", 1, 1, cmd_ffs2_format}, |
311 {"mkdir", 1, 1, cmd_ffs2_mkdir}, | |
127 {"open", 2, 2, cmd_ffs2_open}, | 312 {"open", 2, 2, cmd_ffs2_open}, |
313 {"opendir", 1, 1, cmd_ffs2_opendir}, | |
128 {"preformat", 0, 0, cmd_ffs2_preformat}, | 314 {"preformat", 0, 0, cmd_ffs2_preformat}, |
315 {"query", 1, 1, cmd_ffs2_query}, | |
316 {"readfd", 2, 2, cmd_ffs2_readfd}, | |
317 {"readfile", 2, 2, cmd_ffs2_readfile}, | |
318 {"stat", 1, 1, cmd_ffs2_stat}, | |
129 {"version", 0, 0, cmd_ffs2_version}, | 319 {"version", 0, 0, cmd_ffs2_version}, |
320 {"wrfile", 2, 2, cmd_ffs2_wrfile}, | |
321 {"writefd", 2, 2, cmd_ffs2_writefd}, | |
322 {"xlstat", 1, 1, cmd_ffs2_xlstat}, | |
130 {0, 0, 0, 0} | 323 {0, 0, 0, 0} |
131 }; | 324 }; |
132 | 325 |
133 void | 326 void |
134 cmd_ffs2(argc, argv) | 327 cmd_ffs2(argc, argv) |