diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/common/dir.h | 1 | ||||
-rw-r--r-- | firmware/common/file.c | 14 | ||||
-rw-r--r-- | firmware/drivers/fat.c | 27 | ||||
-rw-r--r-- | firmware/test/fat/ata-sim.c | 2 | ||||
-rw-r--r-- | firmware/test/fat/main.c | 12 | ||||
-rw-r--r-- | firmware/test/fat/test.sh | 19 |
6 files changed, 57 insertions, 18 deletions
diff --git a/firmware/common/dir.h b/firmware/common/dir.h index 1ac8fcd312..6b275abda8 100644 --- a/firmware/common/dir.h +++ b/firmware/common/dir.h | |||
@@ -72,6 +72,7 @@ typedef struct DIRtag | |||
72 | 72 | ||
73 | extern DIR* opendir(char* name); | 73 | extern DIR* opendir(char* name); |
74 | extern int closedir(DIR* dir); | 74 | extern int closedir(DIR* dir); |
75 | extern int mkdir(char* name); | ||
75 | 76 | ||
76 | extern struct dirent* readdir(DIR* dir); | 77 | extern struct dirent* readdir(DIR* dir); |
77 | 78 | ||
diff --git a/firmware/common/file.c b/firmware/common/file.c index ae5560407b..7f0e0cd9bd 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c | |||
@@ -184,6 +184,20 @@ int close(int fd) | |||
184 | return rc; | 184 | return rc; |
185 | } | 185 | } |
186 | 186 | ||
187 | int remove(const char* name) | ||
188 | { | ||
189 | int rc; | ||
190 | int fd = open(name, O_WRONLY); | ||
191 | if ( fd < 0 ) | ||
192 | return fd; | ||
193 | |||
194 | rc = fat_remove(&(openfiles[fd].fatfile)); | ||
195 | |||
196 | close(fd); | ||
197 | |||
198 | return rc; | ||
199 | } | ||
200 | |||
187 | static int readwrite(int fd, void* buf, int count, bool write) | 201 | static int readwrite(int fd, void* buf, int count, bool write) |
188 | { | 202 | { |
189 | int sectors; | 203 | int sectors; |
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 694a7727c3..74f61c2552 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c | |||
@@ -466,13 +466,11 @@ static int update_fat_entry(unsigned int entry, unsigned int val) | |||
466 | 466 | ||
467 | LDEBUGF("update_fat_entry(%x,%x)\n",entry,val); | 467 | LDEBUGF("update_fat_entry(%x,%x)\n",entry,val); |
468 | 468 | ||
469 | #ifdef TEST_FAT | ||
470 | if (entry==val) | 469 | if (entry==val) |
471 | panicf("Creating FAT loop: %x,%x\n",entry,val); | 470 | panicf("Creating FAT loop: %x,%x\n",entry,val); |
472 | 471 | ||
473 | if ( entry < 2 ) | 472 | if ( entry < 2 ) |
474 | panicf("Updating reserved FAT entry %d.\n",entry); | 473 | panicf("Updating reserved FAT entry %d.\n",entry); |
475 | #endif | ||
476 | 474 | ||
477 | sec = cache_fat_sector(sector); | 475 | sec = cache_fat_sector(sector); |
478 | if (!sec) | 476 | if (!sec) |
@@ -491,6 +489,8 @@ static int update_fat_entry(unsigned int entry, unsigned int val) | |||
491 | fat_bpb.fsinfo.freecount++; | 489 | fat_bpb.fsinfo.freecount++; |
492 | } | 490 | } |
493 | 491 | ||
492 | LDEBUGF("update_fat_entry: %d free clusters\n", fat_bpb.fsinfo.freecount); | ||
493 | |||
494 | /* don't change top 4 bits */ | 494 | /* don't change top 4 bits */ |
495 | sec[offset] &= SWAB32(0xf0000000); | 495 | sec[offset] &= SWAB32(0xf0000000); |
496 | sec[offset] |= SWAB32(val & 0x0fffffff); | 496 | sec[offset] |= SWAB32(val & 0x0fffffff); |
@@ -873,13 +873,14 @@ static void update_dir_entry( struct fat_file* file, int size ) | |||
873 | unsigned short* clusptr; | 873 | unsigned short* clusptr; |
874 | int err; | 874 | int err; |
875 | 875 | ||
876 | LDEBUGF("update_dir_entry(cluster:%x entry:%d size:%d)\n", | 876 | LDEBUGF("update_dir_entry(cluster:%x entry:%d sector:%x size:%d)\n", |
877 | file->firstcluster,file->direntry,size); | 877 | file->firstcluster,file->direntry,sector,size); |
878 | 878 | ||
879 | if ( file->direntry >= (SECTOR_SIZE / DIR_ENTRY_SIZE) ) { | 879 | if ( file->direntry >= (SECTOR_SIZE / DIR_ENTRY_SIZE) ) |
880 | DEBUGF("update_dir_entry(): Illegal entry %d!\n",file->direntry); | 880 | panicf("update_dir_entry(): Illegal entry %d!\n",file->direntry); |
881 | return; | 881 | |
882 | } | 882 | if ( file->direntry < 0 ) |
883 | panicf("update_dir_entry(): Illegal entry %d!\n",file->direntry); | ||
883 | 884 | ||
884 | err = ata_read_sectors(sector, 1, buf); | 885 | err = ata_read_sectors(sector, 1, buf); |
885 | if (err) | 886 | if (err) |
@@ -949,7 +950,7 @@ int fat_open(unsigned int startcluster, | |||
949 | 950 | ||
950 | /* remember where the file's dir entry is located */ | 951 | /* remember where the file's dir entry is located */ |
951 | file->dirsector = dir->cached_sec; | 952 | file->dirsector = dir->cached_sec; |
952 | file->direntry = (dir->entry % DIR_ENTRIES_PER_SECTOR) - 1; | 953 | file->direntry = dir->entry - 1; |
953 | LDEBUGF("fat_open(%x), entry %d\n",startcluster,file->direntry); | 954 | LDEBUGF("fat_open(%x), entry %d\n",startcluster,file->direntry); |
954 | return 0; | 955 | return 0; |
955 | } | 956 | } |
@@ -1013,7 +1014,8 @@ int fat_closewrite(struct fat_file *file, int size) | |||
1013 | else | 1014 | else |
1014 | update_fat_entry(endcluster, FAT_EOF_MARK); | 1015 | update_fat_entry(endcluster, FAT_EOF_MARK); |
1015 | 1016 | ||
1016 | update_dir_entry(file, size); | 1017 | if (file->dirsector) |
1018 | update_dir_entry(file, size); | ||
1017 | flush_fat(); | 1019 | flush_fat(); |
1018 | 1020 | ||
1019 | #ifdef TEST_FAT | 1021 | #ifdef TEST_FAT |
@@ -1043,13 +1045,14 @@ int fat_remove(struct fat_file* file) | |||
1043 | 1045 | ||
1044 | LDEBUGF("fat_remove(%x)\n",last); | 1046 | LDEBUGF("fat_remove(%x)\n",last); |
1045 | 1047 | ||
1046 | while ( last != FAT_EOF_MARK ) { | 1048 | while ( last ) { |
1047 | LDEBUGF("Freeing cluster %x\n",last); | ||
1048 | next = get_next_cluster(last); | 1049 | next = get_next_cluster(last); |
1049 | update_fat_entry(last,0); | 1050 | update_fat_entry(last,0); |
1050 | last = next; | 1051 | last = next; |
1051 | } | 1052 | } |
1052 | update_dir_entry(file, -1); | 1053 | update_dir_entry(file, -1); |
1054 | file->dirsector = 0; | ||
1055 | file->firstcluster = 0; | ||
1053 | 1056 | ||
1054 | return 0; | 1057 | return 0; |
1055 | } | 1058 | } |
diff --git a/firmware/test/fat/ata-sim.c b/firmware/test/fat/ata-sim.c index 04cdadb6ce..63abc58084 100644 --- a/firmware/test/fat/ata-sim.c +++ b/firmware/test/fat/ata-sim.c | |||
@@ -14,7 +14,7 @@ int ata_read_sectors(unsigned long start, unsigned char count, void* buf) | |||
14 | DEBUGF("[Reading %d blocks: 0x%lx to 0x%lx]\n", | 14 | DEBUGF("[Reading %d blocks: 0x%lx to 0x%lx]\n", |
15 | count, start, start+count-1); | 15 | count, start, start+count-1); |
16 | else | 16 | else |
17 | DEBUGF("[Reading block 0x%lx, %d]\n", start, count); | 17 | DEBUGF("[Reading block 0x%lx]\n", start); |
18 | 18 | ||
19 | if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) { | 19 | if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) { |
20 | perror("fseek"); | 20 | perror("fseek"); |
diff --git a/firmware/test/fat/main.c b/firmware/test/fat/main.c index 68cef1f08c..58f83f45dc 100644 --- a/firmware/test/fat/main.c +++ b/firmware/test/fat/main.c | |||
@@ -267,6 +267,11 @@ void dbg_head(char* name) | |||
267 | close(fd); | 267 | close(fd); |
268 | } | 268 | } |
269 | 269 | ||
270 | int dbg_del(char* name) | ||
271 | { | ||
272 | return remove(name); | ||
273 | } | ||
274 | |||
270 | char current_directory[256] = "\\"; | 275 | char current_directory[256] = "\\"; |
271 | int last_secnum = 0; | 276 | int last_secnum = 0; |
272 | 277 | ||
@@ -300,6 +305,7 @@ int dbg_cmd(int argc, char *argv[]) | |||
300 | " tail <file>\n" | 305 | " tail <file>\n" |
301 | " mkfile <file> <size (KB)>\n" | 306 | " mkfile <file> <size (KB)>\n" |
302 | " chkfile <file>\n" | 307 | " chkfile <file>\n" |
308 | " del <file>\n" | ||
303 | ); | 309 | ); |
304 | return -1; | 310 | return -1; |
305 | } | 311 | } |
@@ -358,6 +364,12 @@ int dbg_cmd(int argc, char *argv[]) | |||
358 | } | 364 | } |
359 | } | 365 | } |
360 | 366 | ||
367 | if (!strcasecmp(cmd, "del")) | ||
368 | { | ||
369 | if (arg1) | ||
370 | return dbg_del(arg1); | ||
371 | } | ||
372 | |||
361 | return 0; | 373 | return 0; |
362 | } | 374 | } |
363 | 375 | ||
diff --git a/firmware/test/fat/test.sh b/firmware/test/fat/test.sh index f723f69ec3..7d9435b85d 100644 --- a/firmware/test/fat/test.sh +++ b/firmware/test/fat/test.sh | |||
@@ -15,6 +15,7 @@ check() { | |||
15 | } | 15 | } |
16 | 16 | ||
17 | try() { | 17 | try() { |
18 | echo COMMAND: fat $1 $2 $3 >> $RESULT | ||
18 | ./fat $1 $2 $3 2>> $RESULT | 19 | ./fat $1 $2 $3 2>> $RESULT |
19 | RETVAL=$? | 20 | RETVAL=$? |
20 | [ $RETVAL -ne 0 ] && fail | 21 | [ $RETVAL -ne 0 ] && fail |
@@ -25,6 +26,7 @@ buildimage() { | |||
25 | mount -o loop $IMAGE $MOUNT | 26 | mount -o loop $IMAGE $MOUNT |
26 | echo "Filling it with /etc files" | 27 | echo "Filling it with /etc files" |
27 | find /etc -type f -maxdepth 1 -exec cp {} $MOUNT \; | 28 | find /etc -type f -maxdepth 1 -exec cp {} $MOUNT \; |
29 | mkdir $MOUNT/dir | ||
28 | umount $MOUNT | 30 | umount $MOUNT |
29 | } | 31 | } |
30 | 32 | ||
@@ -33,8 +35,10 @@ runtests() { | |||
33 | 35 | ||
34 | echo ---Test: create a 10K file | 36 | echo ---Test: create a 10K file |
35 | try mkfile /apa.txt 10 | 37 | try mkfile /apa.txt 10 |
38 | try mkfile /dir/apa.txt 10 | ||
36 | check | 39 | check |
37 | try chkfile /apa.txt 10 | 40 | try chkfile /apa.txt 10 |
41 | try chkfile /dir/apa.txt 8 | ||
38 | 42 | ||
39 | echo ---Test: create a 1K file | 43 | echo ---Test: create a 1K file |
40 | try mkfile /bpa.txt 1 | 44 | try mkfile /bpa.txt 1 |
@@ -64,7 +68,7 @@ runtests() { | |||
64 | try chkfile /bpa.txt | 68 | try chkfile /bpa.txt |
65 | 69 | ||
66 | LOOP=50 | 70 | LOOP=50 |
67 | SIZE=50 | 71 | SIZE=70 |
68 | 72 | ||
69 | echo ---Test: create $LOOP $SIZE k files | 73 | echo ---Test: create $LOOP $SIZE k files |
70 | for i in `seq 1 $LOOP`; | 74 | for i in `seq 1 $LOOP`; |
@@ -73,10 +77,19 @@ runtests() { | |||
73 | try mkfile /rockbox.$i $SIZE | 77 | try mkfile /rockbox.$i $SIZE |
74 | check | 78 | check |
75 | try chkfile /rockbox.$i $SIZE | 79 | try chkfile /rockbox.$i $SIZE |
80 | check | ||
81 | try del /rockbox.$i | ||
82 | check | ||
83 | try mkfile /rockbox.$i $SIZE | ||
84 | check | ||
76 | done | 85 | done |
77 | 86 | ||
78 | } | 87 | } |
79 | 88 | ||
89 | echo "Building test image (4 sector/cluster)" | ||
90 | buildimage 4 | ||
91 | runtests | ||
92 | |||
80 | echo "Building test image (128 sectors/cluster)" | 93 | echo "Building test image (128 sectors/cluster)" |
81 | buildimage 128 | 94 | buildimage 128 |
82 | runtests | 95 | runtests |
@@ -89,10 +102,6 @@ echo "Building test image (8 sectors/cluster)" | |||
89 | buildimage 8 | 102 | buildimage 8 |
90 | runtests | 103 | runtests |
91 | 104 | ||
92 | echo "Building test image (4 sector/cluster)" | ||
93 | buildimage 4 | ||
94 | runtests | ||
95 | |||
96 | echo "Building test image (1 sector/cluster)" | 105 | echo "Building test image (1 sector/cluster)" |
97 | buildimage 1 | 106 | buildimage 1 |
98 | runtests | 107 | runtests |