Directories can now be renamed too.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3167 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
b6a4f2fb2c
commit
184fd55411
3 changed files with 15 additions and 9 deletions
|
@ -40,6 +40,7 @@ struct filedesc {
|
||||||
int cacheoffset;
|
int cacheoffset;
|
||||||
int fileoffset;
|
int fileoffset;
|
||||||
int size;
|
int size;
|
||||||
|
int attr;
|
||||||
struct fat_file fatfile;
|
struct fat_file fatfile;
|
||||||
bool busy;
|
bool busy;
|
||||||
bool write;
|
bool write;
|
||||||
|
@ -122,6 +123,7 @@ int open(const char* pathname, int flags)
|
||||||
&(file->fatfile),
|
&(file->fatfile),
|
||||||
&(dir->fatdir));
|
&(dir->fatdir));
|
||||||
file->size = entry->size;
|
file->size = entry->size;
|
||||||
|
file->attr = entry->attribute;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,6 +141,7 @@ int open(const char* pathname, int flags)
|
||||||
return -5;
|
return -5;
|
||||||
}
|
}
|
||||||
file->size = 0;
|
file->size = 0;
|
||||||
|
file->attr = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DEBUGF("Couldn't find %s in %s\n",name,pathname);
|
DEBUGF("Couldn't find %s in %s\n",name,pathname);
|
||||||
|
@ -190,7 +193,7 @@ int close(int fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* tie up all loose ends */
|
/* 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;
|
return -3;
|
||||||
}
|
}
|
||||||
file->busy = false;
|
file->busy = false;
|
||||||
|
@ -257,7 +260,7 @@ int rename(const char* path, const char* newpath)
|
||||||
nameptr = (char*)newpath;
|
nameptr = (char*)newpath;
|
||||||
|
|
||||||
file = &openfiles[fd];
|
file = &openfiles[fd];
|
||||||
rc = fat_rename(&file->fatfile, nameptr, file->size);
|
rc = fat_rename(&file->fatfile, nameptr, file->size, file->attr);
|
||||||
if ( rc < 0 ) {
|
if ( rc < 0 ) {
|
||||||
DEBUGF("Failed renaming file: %d\n", rc);
|
DEBUGF("Failed renaming file: %d\n", rc);
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
|
|
|
@ -1122,7 +1122,7 @@ static int create_dos_name(unsigned char *name, unsigned char *newname)
|
||||||
return 0;
|
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];
|
unsigned char buf[SECTOR_SIZE];
|
||||||
int sector = file->direntry / DIR_ENTRIES_PER_SECTOR;
|
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)
|
if (!entry[0] || entry[0] == 0xe5)
|
||||||
panicf("Updating size on empty dir entry %d\n", file->direntry);
|
panicf("Updating size on empty dir entry %d\n", file->direntry);
|
||||||
|
|
||||||
|
entry[FATDIR_ATTR] = attr & 0xFF;
|
||||||
|
|
||||||
clusptr = (short*)(entry + FATDIR_FSTCLUSHI);
|
clusptr = (short*)(entry + FATDIR_FSTCLUSHI);
|
||||||
*clusptr = SWAB16(file->firstcluster >> 16);
|
*clusptr = SWAB16(file->firstcluster >> 16);
|
||||||
|
|
||||||
|
@ -1264,7 +1266,7 @@ int fat_truncate(struct fat_file *file)
|
||||||
return 0;
|
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);
|
LDEBUGF("fat_closewrite(size=%d)\n",size);
|
||||||
|
|
||||||
|
@ -1277,7 +1279,7 @@ int fat_closewrite(struct fat_file *file, int size)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file->dircluster)
|
if (file->dircluster)
|
||||||
if (update_file_size(file, size) < 0)
|
if (update_short_entry(file, size, attr) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
flush_fat();
|
flush_fat();
|
||||||
|
@ -1392,7 +1394,8 @@ int fat_remove(struct fat_file* file)
|
||||||
|
|
||||||
int fat_rename(struct fat_file* file,
|
int fat_rename(struct fat_file* file,
|
||||||
unsigned char* newname,
|
unsigned char* newname,
|
||||||
int size)
|
int size,
|
||||||
|
int attr)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
struct fat_dir dir;
|
struct fat_dir dir;
|
||||||
|
@ -1414,7 +1417,7 @@ int fat_rename(struct fat_file* file,
|
||||||
return -3;
|
return -3;
|
||||||
|
|
||||||
/* write size and cluster link */
|
/* write size and cluster link */
|
||||||
err = update_file_size(&newfile, size);
|
err = update_short_entry(&newfile, size, attr);
|
||||||
if (err<0)
|
if (err<0)
|
||||||
return -4;
|
return -4;
|
||||||
|
|
||||||
|
|
|
@ -81,13 +81,13 @@ extern int fat_create_file(char* name,
|
||||||
struct fat_dir* dir);
|
struct fat_dir* dir);
|
||||||
extern int fat_readwrite(struct fat_file *ent, int sectorcount,
|
extern int fat_readwrite(struct fat_file *ent, int sectorcount,
|
||||||
void* buf, bool write );
|
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_seek(struct fat_file *ent, unsigned int sector );
|
||||||
extern int fat_remove(struct fat_file *ent);
|
extern int fat_remove(struct fat_file *ent);
|
||||||
extern int fat_truncate(struct fat_file *ent);
|
extern int fat_truncate(struct fat_file *ent);
|
||||||
extern int fat_rename(struct fat_file* file,
|
extern int fat_rename(struct fat_file* file,
|
||||||
unsigned char* newname,
|
unsigned char* newname,
|
||||||
int size);
|
int size, int attr);
|
||||||
|
|
||||||
extern int fat_opendir(struct fat_dir *ent, unsigned int currdir);
|
extern int fat_opendir(struct fat_dir *ent, unsigned int currdir);
|
||||||
extern int fat_getnext(struct fat_dir *ent, struct fat_direntry *entry);
|
extern int fat_getnext(struct fat_dir *ent, struct fat_direntry *entry);
|
||||||
|
|
Loading…
Reference in a new issue