From 184fd554115beb52bb4037ddcd36d8db26d5938d Mon Sep 17 00:00:00 2001 From: Björn Stenberg Date: Mon, 27 Jan 2003 09:32:17 +0000 Subject: Directories can now be renamed too. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3167 a1c6a512-1295-4272-9138-f99709370657 --- firmware/common/file.c | 7 +++++-- firmware/drivers/fat.c | 13 ++++++++----- 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 { int cacheoffset; int fileoffset; int size; + int attr; struct fat_file fatfile; bool busy; bool write; @@ -122,6 +123,7 @@ int open(const char* pathname, int flags) &(file->fatfile), &(dir->fatdir)); file->size = entry->size; + file->attr = entry->attribute; break; } } @@ -139,6 +141,7 @@ int open(const char* pathname, int flags) return -5; } file->size = 0; + file->attr = 0; } else { DEBUGF("Couldn't find %s in %s\n",name,pathname); @@ -190,7 +193,7 @@ int close(int fd) } /* tie up all loose ends */ - if (fat_closewrite(&(file->fatfile), file->size) < 0) + if (fat_closewrite(&(file->fatfile), file->size, file->attr) < 0) return -3; } file->busy = false; @@ -257,7 +260,7 @@ int rename(const char* path, const char* newpath) nameptr = (char*)newpath; file = &openfiles[fd]; - rc = fat_rename(&file->fatfile, nameptr, file->size); + rc = fat_rename(&file->fatfile, nameptr, file->size, file->attr); if ( rc < 0 ) { DEBUGF("Failed renaming file: %d\n", rc); 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) return 0; } -static int update_file_size( struct fat_file* file, int size ) +static int update_short_entry( struct fat_file* file, int size, int attr ) { unsigned char buf[SECTOR_SIZE]; int sector = file->direntry / DIR_ENTRIES_PER_SECTOR; @@ -1152,6 +1152,8 @@ static int update_file_size( struct fat_file* file, int size ) if (!entry[0] || entry[0] == 0xe5) panicf("Updating size on empty dir entry %d\n", file->direntry); + entry[FATDIR_ATTR] = attr & 0xFF; + clusptr = (short*)(entry + FATDIR_FSTCLUSHI); *clusptr = SWAB16(file->firstcluster >> 16); @@ -1264,7 +1266,7 @@ int fat_truncate(struct fat_file *file) return 0; } -int fat_closewrite(struct fat_file *file, int size) +int fat_closewrite(struct fat_file *file, int size, int attr) { LDEBUGF("fat_closewrite(size=%d)\n",size); @@ -1277,7 +1279,7 @@ int fat_closewrite(struct fat_file *file, int size) } if (file->dircluster) - if (update_file_size(file, size) < 0) + if (update_short_entry(file, size, attr) < 0) return -1; flush_fat(); @@ -1392,7 +1394,8 @@ int fat_remove(struct fat_file* file) int fat_rename(struct fat_file* file, unsigned char* newname, - int size) + int size, + int attr) { int err; struct fat_dir dir; @@ -1414,7 +1417,7 @@ int fat_rename(struct fat_file* file, return -3; /* write size and cluster link */ - err = update_file_size(&newfile, size); + err = update_short_entry(&newfile, size, attr); if (err<0) return -4; 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, struct fat_dir* dir); 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_closewrite(struct fat_file *ent, int size, int attr); 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_rename(struct fat_file* file, unsigned char* newname, - int size); + int size, int attr); extern int fat_opendir(struct fat_dir *ent, unsigned int currdir); extern int fat_getnext(struct fat_dir *ent, struct fat_direntry *entry); -- cgit v1.2.3