summaryrefslogtreecommitdiff
path: root/firmware/test/fat/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/test/fat/main.c')
-rw-r--r--firmware/test/fat/main.c97
1 files changed, 50 insertions, 47 deletions
diff --git a/firmware/test/fat/main.c b/firmware/test/fat/main.c
index 13c30b2ed5..0cf06bdac3 100644
--- a/firmware/test/fat/main.c
+++ b/firmware/test/fat/main.c
@@ -6,6 +6,7 @@
6#include "debug.h" 6#include "debug.h"
7#include "disk.h" 7#include "disk.h"
8#include "dir.h" 8#include "dir.h"
9#include "file.h"
9 10
10void dbg_dump_sector(int sec); 11void dbg_dump_sector(int sec);
11void dbg_dump_buffer(unsigned char *buf); 12void dbg_dump_buffer(unsigned char *buf);
@@ -17,7 +18,7 @@ void dbg_dump_sector(int sec)
17 unsigned char buf[512]; 18 unsigned char buf[512];
18 19
19 ata_read_sectors(sec,1,buf); 20 ata_read_sectors(sec,1,buf);
20 printf("---< Sector %d >-----------------------------------------\n", sec); 21 DEBUGF("---< Sector %d >-----------------------------------------\n", sec);
21 dbg_dump_buffer(buf); 22 dbg_dump_buffer(buf);
22} 23}
23 24
@@ -33,7 +34,7 @@ void dbg_dump_buffer(unsigned char *buf)
33 { 34 {
34 c = buf[i*16+j]; 35 c = buf[i*16+j];
35 36
36 printf("%02x ", c); 37 DEBUGF("%02x ", c);
37 if(c < 32 || c > 127) 38 if(c < 32 || c > 127)
38 { 39 {
39 ascii[j] = '.'; 40 ascii[j] = '.';
@@ -45,39 +46,39 @@ void dbg_dump_buffer(unsigned char *buf)
45 } 46 }
46 47
47 ascii[j] = 0; 48 ascii[j] = 0;
48 printf("%s\n", ascii); 49 DEBUGF("%s\n", ascii);
49 } 50 }
50} 51}
51 52
52void dbg_print_bpb(struct bpb *bpb) 53void dbg_print_bpb(struct bpb *bpb)
53{ 54{
54 printf("bpb_oemname = \"%s\"\n", bpb->bs_oemname); 55 DEBUGF("bpb_oemname = \"%s\"\n", bpb->bs_oemname);
55 printf("bpb_bytspersec = %d\n", bpb->bpb_bytspersec); 56 DEBUGF("bpb_bytspersec = %d\n", bpb->bpb_bytspersec);
56 printf("bpb_secperclus = %d\n", bpb->bpb_secperclus); 57 DEBUGF("bpb_secperclus = %d\n", bpb->bpb_secperclus);
57 printf("bpb_rsvdseccnt = %d\n", bpb->bpb_rsvdseccnt); 58 DEBUGF("bpb_rsvdseccnt = %d\n", bpb->bpb_rsvdseccnt);
58 printf("bpb_numfats = %d\n", bpb->bpb_numfats); 59 DEBUGF("bpb_numfats = %d\n", bpb->bpb_numfats);
59 printf("bpb_rootentcnt = %d\n", bpb->bpb_rootentcnt); 60 DEBUGF("bpb_rootentcnt = %d\n", bpb->bpb_rootentcnt);
60 printf("bpb_totsec16 = %d\n", bpb->bpb_totsec16); 61 DEBUGF("bpb_totsec16 = %d\n", bpb->bpb_totsec16);
61 printf("bpb_media = %02x\n", bpb->bpb_media); 62 DEBUGF("bpb_media = %02x\n", bpb->bpb_media);
62 printf("bpb_fatsz16 = %d\n", bpb->bpb_fatsz16); 63 DEBUGF("bpb_fatsz16 = %d\n", bpb->bpb_fatsz16);
63 printf("bpb_secpertrk = %d\n", bpb->bpb_secpertrk); 64 DEBUGF("bpb_secpertrk = %d\n", bpb->bpb_secpertrk);
64 printf("bpb_numheads = %d\n", bpb->bpb_numheads); 65 DEBUGF("bpb_numheads = %d\n", bpb->bpb_numheads);
65 printf("bpb_hiddsec = %u\n", bpb->bpb_hiddsec); 66 DEBUGF("bpb_hiddsec = %u\n", bpb->bpb_hiddsec);
66 printf("bpb_totsec32 = %u\n", bpb->bpb_totsec32); 67 DEBUGF("bpb_totsec32 = %u\n", bpb->bpb_totsec32);
67 68
68 printf("bs_drvnum = %d\n", bpb->bs_drvnum); 69 DEBUGF("bs_drvnum = %d\n", bpb->bs_drvnum);
69 printf("bs_bootsig = %02x\n", bpb->bs_bootsig); 70 DEBUGF("bs_bootsig = %02x\n", bpb->bs_bootsig);
70 if(bpb->bs_bootsig == 0x29) 71 if(bpb->bs_bootsig == 0x29)
71 { 72 {
72 printf("bs_volid = %xl\n", bpb->bs_volid); 73 DEBUGF("bs_volid = %xl\n", bpb->bs_volid);
73 printf("bs_vollab = \"%s\"\n", bpb->bs_vollab); 74 DEBUGF("bs_vollab = \"%s\"\n", bpb->bs_vollab);
74 printf("bs_filsystype = \"%s\"\n", bpb->bs_filsystype); 75 DEBUGF("bs_filsystype = \"%s\"\n", bpb->bs_filsystype);
75 } 76 }
76 77
77 printf("bpb_fatsz32 = %u\n", bpb->bpb_fatsz32); 78 DEBUGF("bpb_fatsz32 = %u\n", bpb->bpb_fatsz32);
78 printf("last_word = %04x\n", bpb->last_word); 79 DEBUGF("last_word = %04x\n", bpb->last_word);
79 80
80 printf("fat_type = FAT32\n"); 81 DEBUGF("fat_type = FAT32\n");
81} 82}
82 83
83void dbg_dir(char* currdir) 84void dbg_dir(char* currdir)
@@ -88,38 +89,40 @@ void dbg_dir(char* currdir)
88 dir = opendir(currdir); 89 dir = opendir(currdir);
89 if (dir) 90 if (dir)
90 { 91 {
91 for ( entry = readdir(dir); 92 while ( (entry = readdir(dir)) ) {
92 entry; 93 DEBUGF("%15s (%d bytes)\n", entry->d_name, entry->size);
93 entry = readdir(dir) )
94 {
95 printf("%s (%08x)\n", entry->d_name, entry->size);
96 } 94 }
97 } 95 }
98 else 96 else
99 { 97 {
100 fprintf(stderr, "Could not open dir %s\n", currdir); 98 DEBUGF( "Could not open dir %s\n", currdir);
101 } 99 }
102 closedir(dir); 100 closedir(dir);
103} 101}
104 102
105void dbg_type(int cluster) 103void dbg_type(char* name)
106{ 104{
107 unsigned char buf[SECTOR_SIZE*5]; 105 unsigned char buf[SECTOR_SIZE*5];
108 struct fat_file ent; 106 int i,fd,rc;
109 int i;
110 107
111 fat_open(cluster,&ent); 108 fd = open(name,O_RDONLY);
109 if (fd<0)
110 return;
111 DEBUGF("Got file descriptor %d\n",fd);
112 112
113 for (i=0;i<5;i++) 113 for (i=0;i<5;i++) {
114 if(fat_read(&ent, 1, buf) >= 0) 114 rc = read(fd, buf, SECTOR_SIZE/3);
115 if( rc >= 0 )
115 { 116 {
116 buf[SECTOR_SIZE]=0; 117 buf[SECTOR_SIZE]=0;
117 printf("%s\n", buf); 118 DEBUGF("%d: %d\n", i, rc);
118 } 119 }
119 else 120 else
120 { 121 {
121 fprintf(stderr, "Could not read file on cluster %d\n", cluster); 122 DEBUGF("Failed reading file\n");
122 } 123 }
124 }
125 close(fd);
123} 126}
124 127
125char current_directory[256] = "\\"; 128char current_directory[256] = "\\";
@@ -127,7 +130,7 @@ int last_secnum = 0;
127 130
128void dbg_prompt(void) 131void dbg_prompt(void)
129{ 132{
130 printf("C:%s> ", current_directory); 133 DEBUGF("C:%s> ", current_directory);
131} 134}
132 135
133void dbg_console(void) 136void dbg_console(void)
@@ -173,19 +176,17 @@ void dbg_console(void)
173 { 176 {
174 last_secnum++; 177 last_secnum++;
175 } 178 }
176 printf("secnum: %d\n", last_secnum); 179 DEBUGF("secnum: %d\n", last_secnum);
177 dbg_dump_sector(last_secnum); 180 dbg_dump_sector(last_secnum);
178 continue; 181 continue;
179 } 182 }
180 183
181 if(!strcasecmp(s, "type")) 184 if(!strcasecmp(s, "type"))
182 { 185 {
183 int cluster = 0; 186 s = strtok(NULL, " \n");
184 if((s = strtok(NULL, " \n"))) 187 if (!s)
185 { 188 continue;
186 cluster = atoi(s); 189 dbg_type(s);
187 }
188 dbg_type(cluster);
189 continue; 190 continue;
190 } 191 }
191 192
@@ -196,6 +197,8 @@ void dbg_console(void)
196 } 197 }
197 } 198 }
198 } 199 }
200 else
201 quit = 1;
199 } 202 }
200} 203}
201 204