mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-08 20:55:17 -05:00
Reduce the amount of stack space needed by fat_rename and mkdir_uncached.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28576 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
47bbd6a466
commit
79d26ed7f9
2 changed files with 29 additions and 16 deletions
|
|
@ -204,13 +204,28 @@ int mkdir_uncached(const char *name)
|
||||||
char *basename;
|
char *basename;
|
||||||
char *parent;
|
char *parent;
|
||||||
struct dirent_uncached *entry;
|
struct dirent_uncached *entry;
|
||||||
struct fat_dir newdir;
|
int dd;
|
||||||
|
DIR_UNCACHED* pdir = opendirs;
|
||||||
|
struct fat_dir *newdir;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if ( name[0] != '/' ) {
|
if ( name[0] != '/' ) {
|
||||||
DEBUGF("mkdir: Only absolute paths supported right now\n");
|
DEBUGF("mkdir: Only absolute paths supported right now\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
/* find a free dir descriptor */
|
||||||
|
for ( dd=0; dd<MAX_OPEN_DIRS; dd++, pdir++)
|
||||||
|
if ( !pdir->busy )
|
||||||
|
break;
|
||||||
|
|
||||||
|
if ( dd == MAX_OPEN_DIRS ) {
|
||||||
|
DEBUGF("Too many dirs open\n");
|
||||||
|
errno = EMFILE;
|
||||||
|
return -5;
|
||||||
|
}
|
||||||
|
|
||||||
|
pdir->busy = true;
|
||||||
|
newdir = &pdir->fatdir;
|
||||||
|
|
||||||
strlcpy(namecopy, name, sizeof(namecopy));
|
strlcpy(namecopy, name, sizeof(namecopy));
|
||||||
|
|
||||||
|
|
@ -230,11 +245,13 @@ int mkdir_uncached(const char *name)
|
||||||
|
|
||||||
if(!dir) {
|
if(!dir) {
|
||||||
DEBUGF("mkdir: can't open parent dir\n");
|
DEBUGF("mkdir: can't open parent dir\n");
|
||||||
|
pdir->busy = false;
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(basename[0] == 0) {
|
if(basename[0] == 0) {
|
||||||
DEBUGF("mkdir: Empty dir name\n");
|
DEBUGF("mkdir: Empty dir name\n");
|
||||||
|
pdir->busy = false;
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
|
|
@ -245,14 +262,16 @@ int mkdir_uncached(const char *name)
|
||||||
DEBUGF("mkdir error: file exists\n");
|
DEBUGF("mkdir error: file exists\n");
|
||||||
errno = EEXIST;
|
errno = EEXIST;
|
||||||
closedir_uncached(dir);
|
closedir_uncached(dir);
|
||||||
|
pdir->busy = false;
|
||||||
return - 4;
|
return - 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(&newdir, 0, sizeof(struct fat_dir));
|
memset(newdir, 0, sizeof(struct fat_dir));
|
||||||
|
|
||||||
rc = fat_create_dir(basename, &newdir, &(dir->fatdir));
|
rc = fat_create_dir(basename, newdir, &(dir->fatdir));
|
||||||
closedir_uncached(dir);
|
closedir_uncached(dir);
|
||||||
|
pdir->busy = false;
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1967,7 +1967,7 @@ int fat_rename(struct fat_file* file,
|
||||||
int attr)
|
int attr)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
struct fat_dir olddir;
|
struct fat_file olddir_file;
|
||||||
struct fat_file newfile = *file;
|
struct fat_file newfile = *file;
|
||||||
unsigned char* entry = NULL;
|
unsigned char* entry = NULL;
|
||||||
unsigned short* clusptr = NULL;
|
unsigned short* clusptr = NULL;
|
||||||
|
|
@ -1988,11 +1988,6 @@ int fat_rename(struct fat_file* file,
|
||||||
return -2;
|
return -2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create a temporary file handle */
|
|
||||||
rc = fat_opendir(IF_MV2(file->volume,) &olddir, file->dircluster, NULL);
|
|
||||||
if (rc < 0)
|
|
||||||
return rc * 10 - 1;
|
|
||||||
|
|
||||||
/* create new name */
|
/* create new name */
|
||||||
rc = add_dir_entry(dir, &newfile, newname, false, false);
|
rc = add_dir_entry(dir, &newfile, newname, false, false);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
|
|
@ -2016,18 +2011,17 @@ int fat_rename(struct fat_file* file,
|
||||||
it points to its parent directory (we don't check if it was a move) */
|
it points to its parent directory (we don't check if it was a move) */
|
||||||
if(FAT_ATTR_DIRECTORY == attr) {
|
if(FAT_ATTR_DIRECTORY == attr) {
|
||||||
unsigned char buf[SECTOR_SIZE];
|
unsigned char buf[SECTOR_SIZE];
|
||||||
/* open the dir that was renamed, we re-use the olddir struct */
|
/* open the dir that was renamed, we re-use the olddir_file struct */
|
||||||
rc = fat_opendir(IF_MV2(file->volume,) &olddir, newfile.firstcluster,
|
rc = fat_open(IF_MV2(volume,) newfile.firstcluster, &olddir_file, NULL);
|
||||||
NULL);
|
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
return rc * 10 - 6;
|
return rc * 10 - 6;
|
||||||
|
|
||||||
/* get the first sector of the dir */
|
/* get the first sector of the dir */
|
||||||
rc = fat_seek(&olddir.file, 0);
|
rc = fat_seek(&olddir_file, 0);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
return rc * 10 - 7;
|
return rc * 10 - 7;
|
||||||
|
|
||||||
rc = fat_readwrite(&olddir.file, 1, buf, false);
|
rc = fat_readwrite(&olddir_file, 1, buf, false);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
return rc * 10 - 8;
|
return rc * 10 - 8;
|
||||||
|
|
||||||
|
|
@ -2051,11 +2045,11 @@ int fat_rename(struct fat_file* file,
|
||||||
*clusptr = htole16(parentcluster & 0xffff);
|
*clusptr = htole16(parentcluster & 0xffff);
|
||||||
|
|
||||||
/* write back this sector */
|
/* write back this sector */
|
||||||
rc = fat_seek(&olddir.file, 0);
|
rc = fat_seek(&olddir_file, 0);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
return rc * 10 - 7;
|
return rc * 10 - 7;
|
||||||
|
|
||||||
rc = fat_readwrite(&olddir.file, 1, buf, true);
|
rc = fat_readwrite(&olddir_file, 1, buf, true);
|
||||||
if (rc < 1)
|
if (rc < 1)
|
||||||
return rc * 10 - 8;
|
return rc * 10 - 8;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue