summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--firmware/test/fat/main.c148
1 files changed, 70 insertions, 78 deletions
diff --git a/firmware/test/fat/main.c b/firmware/test/fat/main.c
index 91e7444999..b7c93f8921 100644
--- a/firmware/test/fat/main.c
+++ b/firmware/test/fat/main.c
@@ -85,7 +85,7 @@ void dbg_dir(char* currdir)
85 85
86void dbg_mkfile(char* name, int num) 86void dbg_mkfile(char* name, int num)
87{ 87{
88 char text[800]; 88 char text[1024];
89 int i; 89 int i;
90 int fd = open(name,O_WRONLY); 90 int fd = open(name,O_WRONLY);
91 if (fd<0) { 91 if (fd<0) {
@@ -147,7 +147,7 @@ void dbg_tail(char* name)
147 if( rc > 0 ) 147 if( rc > 0 )
148 { 148 {
149 buf[rc]=0; 149 buf[rc]=0;
150 printf("%d: %s\n", strlen(buf), buf); 150 printf("%d:\n%s\n", strlen(buf), buf);
151 } 151 }
152 else if ( rc == 0 ) { 152 else if ( rc == 0 ) {
153 DEBUGF("EOF\n"); 153 DEBUGF("EOF\n");
@@ -174,11 +174,11 @@ void dbg_head(char* name)
174 return; 174 return;
175 DEBUGF("Got file descriptor %d\n",fd); 175 DEBUGF("Got file descriptor %d\n",fd);
176 176
177 rc = read(fd, buf, SECTOR_SIZE); 177 rc = read(fd, buf, SECTOR_SIZE*3);
178 if( rc > 0 ) 178 if( rc > 0 )
179 { 179 {
180 buf[rc]=0; 180 buf[rc]=0;
181 printf("%d: %s\n", strlen(buf), buf); 181 printf("%d:\n%s\n", strlen(buf), buf);
182 } 182 }
183 else if ( rc == 0 ) { 183 else if ( rc == 0 ) {
184 DEBUGF("EOF\n"); 184 DEBUGF("EOF\n");
@@ -199,72 +199,76 @@ void dbg_prompt(void)
199 DEBUGF("C:%s> ", current_directory); 199 DEBUGF("C:%s> ", current_directory);
200} 200}
201 201
202void dbg_console(void) 202void dbg_cmd(int argc, char *argv[])
203{ 203{
204 char cmd[32] = ""; 204 char* cmd = NULL;
205 char last_cmd[32] = ""; 205 char* arg1 = NULL;
206 int quit = 0; 206 char* arg2 = NULL;
207 char *s; 207
208 if (argc > 1) {
209 cmd = argv[1];
210 if ( argc > 2 ) {
211 arg1 = argv[2];
212 if ( argc > 3 ) {
213 arg2 = argv[3];
214 }
215 }
216 }
217 else {
218 DEBUGF("usage: fat command [options]\n"
219 "commands:\n"
220 " dir <dir>\n"
221 " ds <sector> - display sector\n"
222 " type <file>\n"
223 " head <file>\n"
224 " tail <file>\n"
225 " mkfile <file> <size (KB)>\n"
226 );
227 return;
228 }
208 229
209 while(!quit) 230 if (!strcasecmp(cmd, "dir"))
210 { 231 {
211 dbg_prompt(); 232 if ( arg1 )
212 if(fgets(cmd, sizeof(cmd) - 1, stdin)) 233 dbg_dir(arg1);
213 { 234 else
214 if(strlen(cmd) == 1) /* empty command? */ 235 dbg_dir("/");
215 { 236 }
216 strcpy(cmd, last_cmd);
217 }
218 237
219 /* Get the first token */ 238 if (!strcasecmp(cmd, "ds"))
220 s = strtok(cmd, " \n"); 239 {
221 if(s) 240 if ( arg1 ) {
222 { 241 DEBUGF("secnum: %d\n", atoi(arg1));
223 if(!strcasecmp(s, "dir")) 242 dbg_dump_sector(atoi(arg1));
224 { 243 }
225 s = strtok(NULL, " \n"); 244 }
226 if (!s) 245
227 s = "/"; 246 if (!strcasecmp(cmd, "type"))
228 dbg_dir(s); 247 {
229 continue; 248 if (arg1)
230 } 249 dbg_type(arg1);
231 250 }
232 if(!strcasecmp(s, "ds")) 251
233 { 252 if (!strcasecmp(cmd, "head"))
234 /* Remember the command */ 253 {
235 strcpy(last_cmd, s); 254 if (arg1)
236 255 dbg_head(arg1);
237 if((s = strtok(NULL, " \n"))) 256 }
238 {
239 last_secnum = atoi(s);
240 }
241 else
242 {
243 last_secnum++;
244 }
245 DEBUGF("secnum: %d\n", last_secnum);
246 dbg_dump_sector(last_secnum);
247 continue;
248 }
249
250 if(!strcasecmp(s, "type"))
251 {
252 s = strtok(NULL, " \n");
253 if (!s)
254 continue;
255 dbg_type(s);
256 continue;
257 }
258 257
259 if(!strcasecmp(s, "exit") || 258 if (!strcasecmp(cmd, "tail"))
260 !strcasecmp(s, "x")) 259 {
261 { 260 if (arg1)
262 quit = 1; 261 dbg_tail(arg1);
263 } 262 }
264 } 263
264 if (!strcasecmp(cmd, "mkfile"))
265 {
266 if (arg1) {
267 if (arg2)
268 dbg_mkfile(arg1,atoi(arg2));
269 else
270 dbg_mkfile(arg1,1);
265 } 271 }
266 else
267 quit = 1;
268 } 272 }
269} 273}
270 274
@@ -275,7 +279,7 @@ int main(int argc, char *argv[])
275 int rc,i; 279 int rc,i;
276 struct partinfo* pinfo; 280 struct partinfo* pinfo;
277 281
278 if(ata_init(argv[1])) { 282 if(ata_init("disk.img")) {
279 DEBUGF("*** Warning! The disk is uninitialized\n"); 283 DEBUGF("*** Warning! The disk is uninitialized\n");
280 return -1; 284 return -1;
281 } 285 }
@@ -285,11 +289,6 @@ int main(int argc, char *argv[])
285 return -1; 289 return -1;
286 } 290 }
287 291
288 if ( argc > 2 ) {
289 dbg_dump_sector(atoi(argv[2]));
290 return 0;
291 }
292
293 for ( i=0; i<4; i++ ) { 292 for ( i=0; i<4; i++ ) {
294 if ( pinfo[i].type == PARTITION_TYPE_FAT32 ) { 293 if ( pinfo[i].type == PARTITION_TYPE_FAT32 ) {
295 DEBUGF("*** Mounting at block %ld\n",pinfo[i].start); 294 DEBUGF("*** Mounting at block %ld\n",pinfo[i].start);
@@ -308,14 +307,7 @@ int main(int argc, char *argv[])
308 } 307 }
309 } 308 }
310 309
311 //dbg_console(); 310 dbg_cmd(argc, argv);
312 //dbg_dir("/");
313#if 1
314 dbg_tail("/depa.txt");
315#else
316 dbg_mkfile("/depa.txt", 10);
317#endif
318 dbg_dir("/");
319 311
320 ata_exit(); 312 ata_exit();
321 313