forked from len0rd/rockbox
Added remove()
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2801 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
54d5e2cb27
commit
307f5d846e
6 changed files with 57 additions and 18 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,6 +1014,7 @@ int fat_closewrite(struct fat_file *file, int size)
|
|||
else
|
||||
update_fat_entry(endcluster, FAT_EOF_MARK);
|
||||
|
||||
if (file->dirsector)
|
||||
update_dir_entry(file, size);
|
||||
flush_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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue