diff options
author | Björn Stenberg <bjorn@haxx.se> | 2002-05-03 15:36:52 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2002-05-03 15:36:52 +0000 |
commit | 4d4ec3aa0b2c0bb45e7c004885accee303f1277f (patch) | |
tree | fd6432a02c7f2c0e9e0124c51f678ee5f4c1edb1 /firmware/test | |
parent | 924164e6a7b4a97d248a07928b8b9f22bf5aec0b (diff) | |
download | rockbox-4d4ec3aa0b2c0bb45e7c004885accee303f1277f.tar.gz rockbox-4d4ec3aa0b2c0bb45e7c004885accee303f1277f.zip |
Added opendir, closedir and readdir
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@412 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/test')
-rw-r--r-- | firmware/test/fat/Makefile | 5 | ||||
-rw-r--r-- | firmware/test/fat/main.c | 49 |
2 files changed, 29 insertions, 25 deletions
diff --git a/firmware/test/fat/Makefile b/firmware/test/fat/Makefile index 6b253fe16c..48bddb9630 100644 --- a/firmware/test/fat/Makefile +++ b/firmware/test/fat/Makefile | |||
@@ -5,7 +5,7 @@ CFLAGS = -g -Wall -DTEST_FAT -I$(DRIVERS) -I$(FIRMWARE)/common -I$(FIRMWARE) -I. | |||
5 | 5 | ||
6 | TARGET = fat | 6 | TARGET = fat |
7 | 7 | ||
8 | $(TARGET): fat.o ata-sim.o debug.o main.o disk.o | 8 | $(TARGET): fat.o ata-sim.o main.o disk.o debug.o dir.o |
9 | gcc -g -o fat $+ -lfl | 9 | gcc -g -o fat $+ -lfl |
10 | 10 | ||
11 | fat.o: $(DRIVERS)/fat.c $(DRIVERS)/fat.h $(DRIVERS)/ata.h | 11 | fat.o: $(DRIVERS)/fat.c $(DRIVERS)/fat.h $(DRIVERS)/ata.h |
@@ -14,6 +14,9 @@ fat.o: $(DRIVERS)/fat.c $(DRIVERS)/fat.h $(DRIVERS)/ata.h | |||
14 | disk.o: $(FIRMWARE)/common/disk.c | 14 | disk.o: $(FIRMWARE)/common/disk.c |
15 | $(CC) $(CFLAGS) -c $< -o $@ | 15 | $(CC) $(CFLAGS) -c $< -o $@ |
16 | 16 | ||
17 | dir.o: $(FIRMWARE)/common/dir.c | ||
18 | $(CC) $(CFLAGS) -c $< -o $@ | ||
19 | |||
17 | debug.o: $(FIRMWARE)/debug.c | 20 | debug.o: $(FIRMWARE)/debug.c |
18 | $(CC) $(CFLAGS) -c $< -o $@ | 21 | $(CC) $(CFLAGS) -c $< -o $@ |
19 | 22 | ||
diff --git a/firmware/test/fat/main.c b/firmware/test/fat/main.c index ffe3dd8764..13c30b2ed5 100644 --- a/firmware/test/fat/main.c +++ b/firmware/test/fat/main.c | |||
@@ -5,11 +5,12 @@ | |||
5 | #include "ata.h" | 5 | #include "ata.h" |
6 | #include "debug.h" | 6 | #include "debug.h" |
7 | #include "disk.h" | 7 | #include "disk.h" |
8 | #include "dir.h" | ||
8 | 9 | ||
9 | void dbg_dump_sector(int sec); | 10 | void dbg_dump_sector(int sec); |
10 | void dbg_dump_buffer(unsigned char *buf); | 11 | void dbg_dump_buffer(unsigned char *buf); |
11 | void dbg_print_bpb(struct bpb *bpb); | 12 | void dbg_print_bpb(struct bpb *bpb); |
12 | void dbg_console(struct bpb *bpb); | 13 | void dbg_console(void); |
13 | 14 | ||
14 | void dbg_dump_sector(int sec) | 15 | void dbg_dump_sector(int sec) |
15 | { | 16 | { |
@@ -79,34 +80,38 @@ void dbg_print_bpb(struct bpb *bpb) | |||
79 | printf("fat_type = FAT32\n"); | 80 | printf("fat_type = FAT32\n"); |
80 | } | 81 | } |
81 | 82 | ||
82 | void dbg_dir(struct bpb *bpb, int currdir) | 83 | void dbg_dir(char* currdir) |
83 | { | 84 | { |
84 | struct fat_dirent dent; | 85 | DIR* dir; |
85 | struct fat_direntry de; | 86 | struct dirent* entry; |
86 | 87 | ||
87 | if(fat_opendir(bpb, &dent, currdir) >= 0) | 88 | dir = opendir(currdir); |
89 | if (dir) | ||
88 | { | 90 | { |
89 | while(fat_getnext(bpb, &dent, &de) >= 0) | 91 | for ( entry = readdir(dir); |
92 | entry; | ||
93 | entry = readdir(dir) ) | ||
90 | { | 94 | { |
91 | printf("%s (%d)\n", de.name,de.firstcluster); | 95 | printf("%s (%08x)\n", entry->d_name, entry->size); |
92 | } | 96 | } |
93 | } | 97 | } |
94 | else | 98 | else |
95 | { | 99 | { |
96 | fprintf(stderr, "Could not read dir on cluster %d\n", currdir); | 100 | fprintf(stderr, "Could not open dir %s\n", currdir); |
97 | } | 101 | } |
102 | closedir(dir); | ||
98 | } | 103 | } |
99 | 104 | ||
100 | void dbg_type(struct bpb *bpb, int cluster) | 105 | void dbg_type(int cluster) |
101 | { | 106 | { |
102 | unsigned char buf[SECTOR_SIZE*5]; | 107 | unsigned char buf[SECTOR_SIZE*5]; |
103 | struct fat_fileent ent; | 108 | struct fat_file ent; |
104 | int i; | 109 | int i; |
105 | 110 | ||
106 | fat_open(bpb,cluster,&ent); | 111 | fat_open(cluster,&ent); |
107 | 112 | ||
108 | for (i=0;i<5;i++) | 113 | for (i=0;i<5;i++) |
109 | if(fat_read(bpb, &ent, 1, buf) >= 0) | 114 | if(fat_read(&ent, 1, buf) >= 0) |
110 | { | 115 | { |
111 | buf[SECTOR_SIZE]=0; | 116 | buf[SECTOR_SIZE]=0; |
112 | printf("%s\n", buf); | 117 | printf("%s\n", buf); |
@@ -125,7 +130,7 @@ void dbg_prompt(void) | |||
125 | printf("C:%s> ", current_directory); | 130 | printf("C:%s> ", current_directory); |
126 | } | 131 | } |
127 | 132 | ||
128 | void dbg_console(struct bpb* bpb) | 133 | void dbg_console(void) |
129 | { | 134 | { |
130 | char cmd[32] = ""; | 135 | char cmd[32] = ""; |
131 | char last_cmd[32] = ""; | 136 | char last_cmd[32] = ""; |
@@ -148,12 +153,10 @@ void dbg_console(struct bpb* bpb) | |||
148 | { | 153 | { |
149 | if(!strcasecmp(s, "dir")) | 154 | if(!strcasecmp(s, "dir")) |
150 | { | 155 | { |
151 | int secnum = 0; | 156 | s = strtok(NULL, " \n"); |
152 | if((s = strtok(NULL, " \n"))) | 157 | if (!s) |
153 | { | 158 | s = "/"; |
154 | secnum = atoi(s); | 159 | dbg_dir(s); |
155 | } | ||
156 | dbg_dir(bpb, secnum); | ||
157 | continue; | 160 | continue; |
158 | } | 161 | } |
159 | 162 | ||
@@ -182,7 +185,7 @@ void dbg_console(struct bpb* bpb) | |||
182 | { | 185 | { |
183 | cluster = atoi(s); | 186 | cluster = atoi(s); |
184 | } | 187 | } |
185 | dbg_type(bpb,cluster); | 188 | dbg_type(cluster); |
186 | continue; | 189 | continue; |
187 | } | 190 | } |
188 | 191 | ||
@@ -198,8 +201,6 @@ void dbg_console(struct bpb* bpb) | |||
198 | 201 | ||
199 | int main(int argc, char *argv[]) | 202 | int main(int argc, char *argv[]) |
200 | { | 203 | { |
201 | struct bpb bpb; | ||
202 | |||
203 | if(ata_init()) { | 204 | if(ata_init()) { |
204 | DEBUGF("*** Warning! The disk is uninitialized\n"); | 205 | DEBUGF("*** Warning! The disk is uninitialized\n"); |
205 | return -1; | 206 | return -1; |
@@ -209,11 +210,11 @@ int main(int argc, char *argv[]) | |||
209 | return -1; | 210 | return -1; |
210 | } | 211 | } |
211 | 212 | ||
212 | if(fat_mount(&bpb,part[0].start)) { | 213 | if(fat_mount(part[0].start)) { |
213 | DEBUGF("*** Failed mounting fat\n"); | 214 | DEBUGF("*** Failed mounting fat\n"); |
214 | } | 215 | } |
215 | 216 | ||
216 | dbg_console(&bpb); | 217 | dbg_console(); |
217 | return 0; | 218 | return 0; |
218 | } | 219 | } |
219 | 220 | ||