summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-11-11 10:21:51 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-11-11 10:21:51 +0000
commit11a09e632ceb5513aad54aa6b2c6031bb28b4533 (patch)
treee0f1a0d93d40dbeab2c0e20fa240880e5ad67d0c /firmware/drivers
parent7912a6d39d73a73022feee41ba5fce8ee3ae6019 (diff)
downloadrockbox-11a09e632ceb5513aad54aa6b2c6031bb28b4533.tar.gz
rockbox-11a09e632ceb5513aad54aa6b2c6031bb28b4533.zip
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.c36
-rw-r--r--firmware/drivers/fat.h3
2 files changed, 19 insertions, 20 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index 47bfd1afef..74bdbd3491 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -167,7 +167,7 @@ static unsigned int getcurrdostime(unsigned short *dosdate,
167 unsigned short *dostime, 167 unsigned short *dostime,
168 unsigned char *dostenth); 168 unsigned char *dostenth);
169static int create_dos_name(unsigned char *name, unsigned char *newname); 169static int create_dos_name(unsigned char *name, unsigned char *newname);
170static int find_free_cluster(int start); 170static unsigned int find_free_cluster(unsigned int start);
171#endif 171#endif
172 172
173#define FAT_CACHE_SIZE 0x20 173#define FAT_CACHE_SIZE 0x20
@@ -438,10 +438,10 @@ static void *cache_fat_sector(int fatsector)
438 return sectorbuf; 438 return sectorbuf;
439} 439}
440 440
441static int find_free_cluster(int startcluster) 441static unsigned int find_free_cluster(unsigned int startcluster)
442{ 442{
443 int sector = startcluster / CLUSTERS_PER_FAT_SECTOR; 443 unsigned int sector = startcluster / CLUSTERS_PER_FAT_SECTOR;
444 int offset = startcluster % CLUSTERS_PER_FAT_SECTOR; 444 unsigned int offset = startcluster % CLUSTERS_PER_FAT_SECTOR;
445 int i; 445 int i;
446 446
447 /* don't waste time scanning if the disk is already full */ 447 /* 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)
511 return 0; 511 return 0;
512} 512}
513 513
514static int read_fat_entry(int entry) 514static int read_fat_entry(unsigned int entry)
515{ 515{
516 int sector = entry / CLUSTERS_PER_FAT_SECTOR; 516 int sector = entry / CLUSTERS_PER_FAT_SECTOR;
517 int offset = entry % CLUSTERS_PER_FAT_SECTOR; 517 int offset = entry % CLUSTERS_PER_FAT_SECTOR;
@@ -998,24 +998,23 @@ int fat_create_file(char* name,
998 return err; 998 return err;
999} 999}
1000 1000
1001int fat_closewrite(struct fat_file *file, int size) 1001int fat_truncate(struct fat_file *file)
1002{ 1002{
1003 int next, last = file->lastcluster;
1004 int endcluster = last;
1005
1006 LDEBUGF("fat_closewrite(size=%d, last=%x)\n",size, last);
1007
1008 /* truncate trailing clusters */ 1003 /* truncate trailing clusters */
1009 last = get_next_cluster(last); 1004 int next;
1005 int last = get_next_cluster(file->lastcluster);
1010 while ( last && last != FAT_EOF_MARK ) { 1006 while ( last && last != FAT_EOF_MARK ) {
1011 next = get_next_cluster(last); 1007 next = get_next_cluster(last);
1012 update_fat_entry(last,0); 1008 update_fat_entry(last,0);
1013 last = next; 1009 last = next;
1014 } 1010 }
1015 1011
1016 /* if no cluster was written, size is 0 */ 1012 return 0;
1017 if (!endcluster) 1013}
1018 size = 0; 1014
1015int fat_closewrite(struct fat_file *file, int size)
1016{
1017 LDEBUGF("fat_closewrite(size=%d)\n",size);
1019 1018
1020 if (!size) { 1019 if (!size) {
1021 /* empty file */ 1020 /* empty file */
@@ -1024,18 +1023,17 @@ int fat_closewrite(struct fat_file *file, int size)
1024 file->firstcluster = 0; 1023 file->firstcluster = 0;
1025 } 1024 }
1026 } 1025 }
1027 else
1028 update_fat_entry(endcluster, FAT_EOF_MARK);
1029 1026
1030 if (file->dirsector) 1027 if (file->dirsector)
1031 update_dir_entry(file, size); 1028 update_dir_entry(file, size);
1032 flush_fat(); 1029 flush_fat();
1033 1030
1034#ifdef TEST_FAT 1031#ifdef TEST_FAT
1035 { 1032 if ( file->firstcluster ) {
1036 /* debug */ 1033 /* debug */
1037 int count = 0; 1034 int count = 0;
1038 int len; 1035 int len;
1036 int next;
1039 for ( next = file->firstcluster; next; 1037 for ( next = file->firstcluster; next;
1040 next = get_next_cluster(next) ) 1038 next = get_next_cluster(next) )
1041 LDEBUGF("cluster %d: %x\n", count++, next); 1039 LDEBUGF("cluster %d: %x\n", count++, next);
@@ -1213,7 +1211,7 @@ int fat_readwrite( struct fat_file *file, int sectorcount,
1213 return i; 1211 return i;
1214} 1212}
1215 1213
1216int fat_seek(struct fat_file *file, int seeksector ) 1214int fat_seek(struct fat_file *file, unsigned int seeksector )
1217{ 1215{
1218 int clusternum=0, sectornum=0, sector=0; 1216 int clusternum=0, sectornum=0, sector=0;
1219 int cluster = file->firstcluster; 1217 int cluster = file->firstcluster;
diff --git a/firmware/drivers/fat.h b/firmware/drivers/fat.h
index 6ed68ad8d8..b23d8dfa08 100644
--- a/firmware/drivers/fat.h
+++ b/firmware/drivers/fat.h
@@ -79,8 +79,9 @@ extern int fat_create_file(char* name,
79extern int fat_readwrite(struct fat_file *ent, int sectorcount, 79extern int fat_readwrite(struct fat_file *ent, int sectorcount,
80 void* buf, bool write ); 80 void* buf, bool write );
81extern int fat_closewrite(struct fat_file *ent, int size); 81extern int fat_closewrite(struct fat_file *ent, int size);
82extern int fat_seek(struct fat_file *ent, int sector ); 82extern int fat_seek(struct fat_file *ent, unsigned int sector );
83extern int fat_remove(struct fat_file *ent); 83extern int fat_remove(struct fat_file *ent);
84extern int fat_truncate(struct fat_file *ent);
84 85
85extern int fat_opendir(struct fat_dir *ent, unsigned int currdir); 86extern int fat_opendir(struct fat_dir *ent, unsigned int currdir);
86extern int fat_getnext(struct fat_dir *ent, struct fat_direntry *entry); 87extern int fat_getnext(struct fat_dir *ent, struct fat_direntry *entry);