diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/common/file.c | 7 | ||||
-rw-r--r-- | firmware/drivers/fat.c | 13 | ||||
-rw-r--r-- | firmware/drivers/fat.h | 4 |
3 files changed, 15 insertions, 9 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c index 4477ed10aa..dfbebe1b90 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c | |||
@@ -40,6 +40,7 @@ struct filedesc { | |||
40 | int cacheoffset; | 40 | int cacheoffset; |
41 | int fileoffset; | 41 | int fileoffset; |
42 | int size; | 42 | int size; |
43 | int attr; | ||
43 | struct fat_file fatfile; | 44 | struct fat_file fatfile; |
44 | bool busy; | 45 | bool busy; |
45 | bool write; | 46 | bool write; |
@@ -122,6 +123,7 @@ int open(const char* pathname, int flags) | |||
122 | &(file->fatfile), | 123 | &(file->fatfile), |
123 | &(dir->fatdir)); | 124 | &(dir->fatdir)); |
124 | file->size = entry->size; | 125 | file->size = entry->size; |
126 | file->attr = entry->attribute; | ||
125 | break; | 127 | break; |
126 | } | 128 | } |
127 | } | 129 | } |
@@ -139,6 +141,7 @@ int open(const char* pathname, int flags) | |||
139 | return -5; | 141 | return -5; |
140 | } | 142 | } |
141 | file->size = 0; | 143 | file->size = 0; |
144 | file->attr = 0; | ||
142 | } | 145 | } |
143 | else { | 146 | else { |
144 | DEBUGF("Couldn't find %s in %s\n",name,pathname); | 147 | DEBUGF("Couldn't find %s in %s\n",name,pathname); |
@@ -190,7 +193,7 @@ int close(int fd) | |||
190 | } | 193 | } |
191 | 194 | ||
192 | /* tie up all loose ends */ | 195 | /* tie up all loose ends */ |
193 | if (fat_closewrite(&(file->fatfile), file->size) < 0) | 196 | if (fat_closewrite(&(file->fatfile), file->size, file->attr) < 0) |
194 | return -3; | 197 | return -3; |
195 | } | 198 | } |
196 | file->busy = false; | 199 | file->busy = false; |
@@ -257,7 +260,7 @@ int rename(const char* path, const char* newpath) | |||
257 | nameptr = (char*)newpath; | 260 | nameptr = (char*)newpath; |
258 | 261 | ||
259 | file = &openfiles[fd]; | 262 | file = &openfiles[fd]; |
260 | rc = fat_rename(&file->fatfile, nameptr, file->size); | 263 | rc = fat_rename(&file->fatfile, nameptr, file->size, file->attr); |
261 | if ( rc < 0 ) { | 264 | if ( rc < 0 ) { |
262 | DEBUGF("Failed renaming file: %d\n", rc); | 265 | DEBUGF("Failed renaming file: %d\n", rc); |
263 | errno = EIO; | 266 | errno = EIO; |
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index 020a48bdef..9274a9c339 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c | |||
@@ -1122,7 +1122,7 @@ static int create_dos_name(unsigned char *name, unsigned char *newname) | |||
1122 | return 0; | 1122 | return 0; |
1123 | } | 1123 | } |
1124 | 1124 | ||
1125 | static int update_file_size( struct fat_file* file, int size ) | 1125 | static int update_short_entry( struct fat_file* file, int size, int attr ) |
1126 | { | 1126 | { |
1127 | unsigned char buf[SECTOR_SIZE]; | 1127 | unsigned char buf[SECTOR_SIZE]; |
1128 | int sector = file->direntry / DIR_ENTRIES_PER_SECTOR; | 1128 | int sector = file->direntry / DIR_ENTRIES_PER_SECTOR; |
@@ -1152,6 +1152,8 @@ static int update_file_size( struct fat_file* file, int size ) | |||
1152 | if (!entry[0] || entry[0] == 0xe5) | 1152 | if (!entry[0] || entry[0] == 0xe5) |
1153 | panicf("Updating size on empty dir entry %d\n", file->direntry); | 1153 | panicf("Updating size on empty dir entry %d\n", file->direntry); |
1154 | 1154 | ||
1155 | entry[FATDIR_ATTR] = attr & 0xFF; | ||
1156 | |||
1155 | clusptr = (short*)(entry + FATDIR_FSTCLUSHI); | 1157 | clusptr = (short*)(entry + FATDIR_FSTCLUSHI); |
1156 | *clusptr = SWAB16(file->firstcluster >> 16); | 1158 | *clusptr = SWAB16(file->firstcluster >> 16); |
1157 | 1159 | ||
@@ -1264,7 +1266,7 @@ int fat_truncate(struct fat_file *file) | |||
1264 | return 0; | 1266 | return 0; |
1265 | } | 1267 | } |
1266 | 1268 | ||
1267 | int fat_closewrite(struct fat_file *file, int size) | 1269 | int fat_closewrite(struct fat_file *file, int size, int attr) |
1268 | { | 1270 | { |
1269 | LDEBUGF("fat_closewrite(size=%d)\n",size); | 1271 | LDEBUGF("fat_closewrite(size=%d)\n",size); |
1270 | 1272 | ||
@@ -1277,7 +1279,7 @@ int fat_closewrite(struct fat_file *file, int size) | |||
1277 | } | 1279 | } |
1278 | 1280 | ||
1279 | if (file->dircluster) | 1281 | if (file->dircluster) |
1280 | if (update_file_size(file, size) < 0) | 1282 | if (update_short_entry(file, size, attr) < 0) |
1281 | return -1; | 1283 | return -1; |
1282 | 1284 | ||
1283 | flush_fat(); | 1285 | flush_fat(); |
@@ -1392,7 +1394,8 @@ int fat_remove(struct fat_file* file) | |||
1392 | 1394 | ||
1393 | int fat_rename(struct fat_file* file, | 1395 | int fat_rename(struct fat_file* file, |
1394 | unsigned char* newname, | 1396 | unsigned char* newname, |
1395 | int size) | 1397 | int size, |
1398 | int attr) | ||
1396 | { | 1399 | { |
1397 | int err; | 1400 | int err; |
1398 | struct fat_dir dir; | 1401 | struct fat_dir dir; |
@@ -1414,7 +1417,7 @@ int fat_rename(struct fat_file* file, | |||
1414 | return -3; | 1417 | return -3; |
1415 | 1418 | ||
1416 | /* write size and cluster link */ | 1419 | /* write size and cluster link */ |
1417 | err = update_file_size(&newfile, size); | 1420 | err = update_short_entry(&newfile, size, attr); |
1418 | if (err<0) | 1421 | if (err<0) |
1419 | return -4; | 1422 | return -4; |
1420 | 1423 | ||
diff --git a/firmware/drivers/fat.h b/firmware/drivers/fat.h index 8d2382f57c..6a3e5cf967 100644 --- a/firmware/drivers/fat.h +++ b/firmware/drivers/fat.h | |||
@@ -81,13 +81,13 @@ extern int fat_create_file(char* name, | |||
81 | struct fat_dir* dir); | 81 | struct fat_dir* dir); |
82 | extern int fat_readwrite(struct fat_file *ent, int sectorcount, | 82 | extern int fat_readwrite(struct fat_file *ent, int sectorcount, |
83 | void* buf, bool write ); | 83 | void* buf, bool write ); |
84 | extern int fat_closewrite(struct fat_file *ent, int size); | 84 | extern int fat_closewrite(struct fat_file *ent, int size, int attr); |
85 | extern int fat_seek(struct fat_file *ent, unsigned int sector ); | 85 | extern int fat_seek(struct fat_file *ent, unsigned int sector ); |
86 | extern int fat_remove(struct fat_file *ent); | 86 | extern int fat_remove(struct fat_file *ent); |
87 | extern int fat_truncate(struct fat_file *ent); | 87 | extern int fat_truncate(struct fat_file *ent); |
88 | extern int fat_rename(struct fat_file* file, | 88 | extern int fat_rename(struct fat_file* file, |
89 | unsigned char* newname, | 89 | unsigned char* newname, |
90 | int size); | 90 | int size, int attr); |
91 | 91 | ||
92 | extern int fat_opendir(struct fat_dir *ent, unsigned int currdir); | 92 | extern int fat_opendir(struct fat_dir *ent, unsigned int currdir); |
93 | extern int fat_getnext(struct fat_dir *ent, struct fat_direntry *entry); | 93 | extern int fat_getnext(struct fat_dir *ent, struct fat_direntry *entry); |