summaryrefslogtreecommitdiff
path: root/firmware/test/fat/main.c
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-08-08 20:32:09 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-08-08 20:32:09 +0000
commite46af01bc4269d8278beceea336381410510d7cd (patch)
treeb484a6d260dc2fde05de37fa84d163a8277090fd /firmware/test/fat/main.c
parent514a3fbbbefad9552ff7806362e834d94bd60fd5 (diff)
downloadrockbox-e46af01bc4269d8278beceea336381410510d7cd.tar.gz
rockbox-e46af01bc4269d8278beceea336381410510d7cd.zip
Storing the latest fat32 test code
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1624 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/test/fat/main.c')
-rw-r--r--firmware/test/fat/main.c73
1 files changed, 34 insertions, 39 deletions
diff --git a/firmware/test/fat/main.c b/firmware/test/fat/main.c
index 6d05dbe600..fcd2dcc5eb 100644
--- a/firmware/test/fat/main.c
+++ b/firmware/test/fat/main.c
@@ -2,15 +2,16 @@
2#include <stdlib.h> 2#include <stdlib.h>
3#include <string.h> 3#include <string.h>
4#include "fat.h" 4#include "fat.h"
5#include "ata.h"
6#include "debug.h" 5#include "debug.h"
7#include "disk.h" 6#include "disk.h"
8#include "dir.h" 7#include "dir.h"
9#include "file.h" 8#include "file.h"
10 9
10extern int ata_init(char*);
11extern void ata_read_sectors(int, int, char*);
12
11void dbg_dump_sector(int sec); 13void dbg_dump_sector(int sec);
12void dbg_dump_buffer(unsigned char *buf); 14void dbg_dump_buffer(unsigned char *buf);
13void dbg_print_bpb(struct bpb *bpb);
14void dbg_console(void); 15void dbg_console(void);
15 16
16void dbg_dump_sector(int sec) 17void dbg_dump_sector(int sec)
@@ -30,6 +31,7 @@ void dbg_dump_buffer(unsigned char *buf)
30 31
31 for(i = 0;i < 512/16;i++) 32 for(i = 0;i < 512/16;i++)
32 { 33 {
34 DEBUGF("%03x: ", i*16);
33 for(j = 0;j < 16;j++) 35 for(j = 0;j < 16;j++)
34 { 36 {
35 c = buf[i*16+j]; 37 c = buf[i*16+j];
@@ -50,37 +52,6 @@ void dbg_dump_buffer(unsigned char *buf)
50 } 52 }
51} 53}
52 54
53void dbg_print_bpb(struct bpb *bpb)
54{
55 DEBUGF("bpb_oemname = \"%s\"\n", bpb->bs_oemname);
56 DEBUGF("bpb_bytspersec = %d\n", bpb->bpb_bytspersec);
57 DEBUGF("bpb_secperclus = %d\n", bpb->bpb_secperclus);
58 DEBUGF("bpb_rsvdseccnt = %d\n", bpb->bpb_rsvdseccnt);
59 DEBUGF("bpb_numfats = %d\n", bpb->bpb_numfats);
60 DEBUGF("bpb_rootentcnt = %d\n", bpb->bpb_rootentcnt);
61 DEBUGF("bpb_totsec16 = %d\n", bpb->bpb_totsec16);
62 DEBUGF("bpb_media = %02x\n", bpb->bpb_media);
63 DEBUGF("bpb_fatsz16 = %d\n", bpb->bpb_fatsz16);
64 DEBUGF("bpb_secpertrk = %d\n", bpb->bpb_secpertrk);
65 DEBUGF("bpb_numheads = %d\n", bpb->bpb_numheads);
66 DEBUGF("bpb_hiddsec = %u\n", bpb->bpb_hiddsec);
67 DEBUGF("bpb_totsec32 = %u\n", bpb->bpb_totsec32);
68
69 DEBUGF("bs_drvnum = %d\n", bpb->bs_drvnum);
70 DEBUGF("bs_bootsig = %02x\n", bpb->bs_bootsig);
71 if(bpb->bs_bootsig == 0x29)
72 {
73 DEBUGF("bs_volid = %xl\n", bpb->bs_volid);
74 DEBUGF("bs_vollab = \"%s\"\n", bpb->bs_vollab);
75 DEBUGF("bs_filsystype = \"%s\"\n", bpb->bs_filsystype);
76 }
77
78 DEBUGF("bpb_fatsz32 = %u\n", bpb->bpb_fatsz32);
79 DEBUGF("last_word = %04x\n", bpb->last_word);
80
81 DEBUGF("fat_type = FAT32\n");
82}
83
84void dbg_dir(char* currdir) 55void dbg_dir(char* currdir)
85{ 56{
86 DIR* dir; 57 DIR* dir;
@@ -92,12 +63,12 @@ void dbg_dir(char* currdir)
92 while ( (entry = readdir(dir)) ) { 63 while ( (entry = readdir(dir)) ) {
93 DEBUGF("%15s (%d bytes)\n", entry->d_name, entry->size); 64 DEBUGF("%15s (%d bytes)\n", entry->d_name, entry->size);
94 } 65 }
66 closedir(dir);
95 } 67 }
96 else 68 else
97 { 69 {
98 DEBUGF( "Could not open dir %s\n", currdir); 70 DEBUGF( "Could not open dir %s\n", currdir);
99 } 71 }
100 closedir(dir);
101} 72}
102 73
103void dbg_type(char* name) 74void dbg_type(char* name)
@@ -261,21 +232,45 @@ void dbg_console(void)
261 232
262int main(int argc, char *argv[]) 233int main(int argc, char *argv[])
263{ 234{
264 if(ata_init()) { 235 int rc,i;
236 struct partinfo* pinfo;
237
238 if(ata_init(argv[1])) {
265 DEBUGF("*** Warning! The disk is uninitialized\n"); 239 DEBUGF("*** Warning! The disk is uninitialized\n");
266 return -1; 240 return -1;
267 } 241 }
268 if (disk_init()) { 242 pinfo = disk_init();
243 if (!pinfo) {
269 DEBUGF("*** Failed reading partitions\n"); 244 DEBUGF("*** Failed reading partitions\n");
270 return -1; 245 return -1;
271 } 246 }
272 247
273 if(fat_mount(part[0].start)) { 248 if ( argc > 2 ) {
274 DEBUGF("*** Failed mounting fat\n"); 249 dbg_dump_sector(atoi(argv[2]));
250 return 0;
251 }
252
253 for ( i=0; i<4; i++ ) {
254 if ( pinfo[i].type == PARTITION_TYPE_FAT32 ) {
255 DEBUGF("*** Mounting at block %ld\n",pinfo[i].start);
256 rc = fat_mount(pinfo[i].start);
257 if(rc) {
258 DEBUGF("mount: %d",rc);
259 return 0;
260 }
261 break;
262 }
263 }
264 if ( i==4 ) {
265 if(fat_mount(0)) {
266 DEBUGF("No FAT32 partition!");
267 return 0;
268 }
275 } 269 }
276 270
277 //dbg_console(); 271 //dbg_console();
278 dbg_tail("/fat.h"); 272 //dbg_tail("/fat.h");
273 dbg_dir("/");
279 274
280 return 0; 275 return 0;
281} 276}