diff options
| author | Björn Stenberg <bjorn@haxx.se> | 2002-11-11 10:21:51 +0000 |
|---|---|---|
| committer | Björn Stenberg <bjorn@haxx.se> | 2002-11-11 10:21:51 +0000 |
| commit | 11a09e632ceb5513aad54aa6b2c6031bb28b4533 (patch) | |
| tree | e0f1a0d93d40dbeab2c0e20fa240880e5ad67d0c /firmware/drivers | |
| parent | 7912a6d39d73a73022feee41ba5fce8ee3ae6019 (diff) | |
| download | rockbox-11a09e632ceb5513aad54aa6b2c6031bb28b4533.zip rockbox-11a09e632ceb5513aad54aa6b2c6031bb28b4533.tar.gz rockbox-11a09e632ceb5513aad54aa6b2c6031bb28b4533.tar.bz2 rockbox-11a09e632ceb5513aad54aa6b2c6031bb28b4533.tar.xz | |
close() now does not truncate the file.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2821 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers')
| -rw-r--r-- | firmware/drivers/fat.c | 36 | ||||
| -rw-r--r-- | firmware/drivers/fat.h | 3 |
2 files changed, 19 insertions, 20 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 47bfd1a..74bdbd3 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c @@ -167,7 +167,7 @@ static unsigned int getcurrdostime(unsigned short *dosdate, unsigned short *dostime, unsigned char *dostenth); static int create_dos_name(unsigned char *name, unsigned char *newname); -static int find_free_cluster(int start); +static unsigned int find_free_cluster(unsigned int start); #endif #define FAT_CACHE_SIZE 0x20 @@ -438,10 +438,10 @@ static void *cache_fat_sector(int fatsector) return sectorbuf; } -static int find_free_cluster(int startcluster) +static unsigned int find_free_cluster(unsigned int startcluster) { - int sector = startcluster / CLUSTERS_PER_FAT_SECTOR; - int offset = startcluster % CLUSTERS_PER_FAT_SECTOR; + unsigned int sector = startcluster / CLUSTERS_PER_FAT_SECTOR; + unsigned int offset = startcluster % CLUSTERS_PER_FAT_SECTOR; int i; /* don't waste time scanning if the disk is already full */ @@ -511,7 +511,7 @@ static int update_fat_entry(unsigned int entry, unsigned int val) return 0; } -static int read_fat_entry(int entry) +static int read_fat_entry(unsigned int entry) { int sector = entry / CLUSTERS_PER_FAT_SECTOR; int offset = entry % CLUSTERS_PER_FAT_SECTOR; @@ -998,24 +998,23 @@ int fat_create_file(char* name, return err; } -int fat_closewrite(struct fat_file *file, int size) +int fat_truncate(struct fat_file *file) { - int next, last = file->lastcluster; - int endcluster = last; - - LDEBUGF("fat_closewrite(size=%d, last=%x)\n",size, last); - /* truncate trailing clusters */ - last = get_next_cluster(last); + int next; + int last = get_next_cluster(file->lastcluster); while ( last && last != FAT_EOF_MARK ) { next = get_next_cluster(last); update_fat_entry(last,0); last = next; } - /* if no cluster was written, size is 0 */ - if (!endcluster) - size = 0; + return 0; +} + +int fat_closewrite(struct fat_file *file, int size) +{ + LDEBUGF("fat_closewrite(size=%d)\n",size); if (!size) { /* empty file */ @@ -1024,18 +1023,17 @@ int fat_closewrite(struct fat_file *file, int size) file->firstcluster = 0; } } - else - update_fat_entry(endcluster, FAT_EOF_MARK); if (file->dirsector) update_dir_entry(file, size); flush_fat(); #ifdef TEST_FAT - { + if ( file->firstcluster ) { /* debug */ int count = 0; int len; + int next; for ( next = file->firstcluster; next; next = get_next_cluster(next) ) LDEBUGF("cluster %d: %x\n", count++, next); @@ -1213,7 +1211,7 @@ int fat_readwrite( struct fat_file *file, int sectorcount, return i; } -int fat_seek(struct fat_file *file, int seeksector ) +int fat_seek(struct fat_file *file, unsigned int seeksector ) { int clusternum=0, sectornum=0, sector=0; int cluster = file->firstcluster; diff --git a/firmware/drivers/fat.h b/firmware/drivers/fat.h index 6ed68ad..b23d8df 100644 --- a/firmware/drivers/fat.h +++ b/firmware/drivers/fat.h @@ -79,8 +79,9 @@ extern int fat_create_file(char* name, extern int fat_readwrite(struct fat_file *ent, int sectorcount, void* buf, bool write ); extern int fat_closewrite(struct fat_file *ent, int size); -extern int fat_seek(struct fat_file *ent, int sector ); +extern int fat_seek(struct fat_file *ent, unsigned int sector ); extern int fat_remove(struct fat_file *ent); +extern int fat_truncate(struct fat_file *ent); extern int fat_opendir(struct fat_dir *ent, unsigned int currdir); extern int fat_getnext(struct fat_dir *ent, struct fat_direntry *entry); |