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 extern DIR* opendir(char* name); extern int closedir(DIR* dir); +extern int mkdir(char* name); extern struct dirent* readdir(DIR* dir); 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) return rc; } +int remove(const char* name) +{ + int rc; + int fd = open(name, O_WRONLY); + if ( fd < 0 ) + return fd; + + rc = fat_remove(&(openfiles[fd].fatfile)); + + close(fd); + + return rc; +} + static int readwrite(int fd, void* buf, int count, bool write) { 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) LDEBUGF("update_fat_entry(%x,%x)\n",entry,val); -#ifdef TEST_FAT if (entry==val) panicf("Creating FAT loop: %x,%x\n",entry,val); if ( entry < 2 ) panicf("Updating reserved FAT entry %d.\n",entry); -#endif sec = cache_fat_sector(sector); if (!sec) @@ -491,6 +489,8 @@ static int update_fat_entry(unsigned int entry, unsigned int val) fat_bpb.fsinfo.freecount++; } + LDEBUGF("update_fat_entry: %d free clusters\n", fat_bpb.fsinfo.freecount); + /* don't change top 4 bits */ sec[offset] &= SWAB32(0xf0000000); sec[offset] |= SWAB32(val & 0x0fffffff); @@ -873,13 +873,14 @@ static void update_dir_entry( struct fat_file* file, int size ) unsigned short* clusptr; int err; - LDEBUGF("update_dir_entry(cluster:%x entry:%d size:%d)\n", - file->firstcluster,file->direntry,size); + LDEBUGF("update_dir_entry(cluster:%x entry:%d sector:%x size:%d)\n", + file->firstcluster,file->direntry,sector,size); - if ( file->direntry >= (SECTOR_SIZE / DIR_ENTRY_SIZE) ) { - DEBUGF("update_dir_entry(): Illegal entry %d!\n",file->direntry); - return; - } + if ( file->direntry >= (SECTOR_SIZE / DIR_ENTRY_SIZE) ) + panicf("update_dir_entry(): Illegal entry %d!\n",file->direntry); + + if ( file->direntry < 0 ) + panicf("update_dir_entry(): Illegal entry %d!\n",file->direntry); err = ata_read_sectors(sector, 1, buf); if (err) @@ -949,7 +950,7 @@ int fat_open(unsigned int startcluster, /* remember where the file's dir entry is located */ file->dirsector = dir->cached_sec; - file->direntry = (dir->entry % DIR_ENTRIES_PER_SECTOR) - 1; + file->direntry = dir->entry - 1; LDEBUGF("fat_open(%x), entry %d\n",startcluster,file->direntry); return 0; } @@ -1013,7 +1014,8 @@ int fat_closewrite(struct fat_file *file, int size) else update_fat_entry(endcluster, FAT_EOF_MARK); - update_dir_entry(file, size); + if (file->dirsector) + update_dir_entry(file, size); flush_fat(); #ifdef TEST_FAT @@ -1043,13 +1045,14 @@ int fat_remove(struct fat_file* file) LDEBUGF("fat_remove(%x)\n",last); - while ( last != FAT_EOF_MARK ) { - LDEBUGF("Freeing cluster %x\n",last); + while ( last ) { next = get_next_cluster(last); update_fat_entry(last,0); last = next; } update_dir_entry(file, -1); + file->dirsector = 0; + file->firstcluster = 0; return 0; } 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) DEBUGF("[Reading %d blocks: 0x%lx to 0x%lx]\n", count, start, start+count-1); else - DEBUGF("[Reading block 0x%lx, %d]\n", start, count); + DEBUGF("[Reading block 0x%lx]\n", start); if(fseek(file,start*BLOCK_SIZE,SEEK_SET)) { 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) close(fd); } +int dbg_del(char* name) +{ + return remove(name); +} + char current_directory[256] = "\\"; int last_secnum = 0; @@ -300,6 +305,7 @@ int dbg_cmd(int argc, char *argv[]) " tail <file>\n" " mkfile <file> <size (KB)>\n" " chkfile <file>\n" + " del <file>\n" ); return -1; } @@ -358,6 +364,12 @@ int dbg_cmd(int argc, char *argv[]) } } + if (!strcasecmp(cmd, "del")) + { + if (arg1) + return dbg_del(arg1); + } + return 0; } 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() { } try() { + echo COMMAND: fat $1 $2 $3 >> $RESULT ./fat $1 $2 $3 2>> $RESULT RETVAL=$? [ $RETVAL -ne 0 ] && fail @@ -25,6 +26,7 @@ buildimage() { mount -o loop $IMAGE $MOUNT echo "Filling it with /etc files" find /etc -type f -maxdepth 1 -exec cp {} $MOUNT \; + mkdir $MOUNT/dir umount $MOUNT } @@ -33,8 +35,10 @@ runtests() { echo ---Test: create a 10K file try mkfile /apa.txt 10 + try mkfile /dir/apa.txt 10 check try chkfile /apa.txt 10 + try chkfile /dir/apa.txt 8 echo ---Test: create a 1K file try mkfile /bpa.txt 1 @@ -64,7 +68,7 @@ runtests() { try chkfile /bpa.txt LOOP=50 - SIZE=50 + SIZE=70 echo ---Test: create $LOOP $SIZE k files for i in `seq 1 $LOOP`; @@ -73,10 +77,19 @@ runtests() { try mkfile /rockbox.$i $SIZE check try chkfile /rockbox.$i $SIZE + check + try del /rockbox.$i + check + try mkfile /rockbox.$i $SIZE + check done } +echo "Building test image (4 sector/cluster)" +buildimage 4 +runtests + echo "Building test image (128 sectors/cluster)" buildimage 128 runtests @@ -89,10 +102,6 @@ echo "Building test image (8 sectors/cluster)" buildimage 8 runtests -echo "Building test image (4 sector/cluster)" -buildimage 4 -runtests - echo "Building test image (1 sector/cluster)" buildimage 1 runtests |