diff options
author | Michael Sparmann <theseven@rockbox.org> | 2010-11-13 15:41:18 +0000 |
---|---|---|
committer | Michael Sparmann <theseven@rockbox.org> | 2010-11-13 15:41:18 +0000 |
commit | 79d26ed7f96537363ee752068d080e4416c14086 (patch) | |
tree | eb0f614d6039d4d6a469f8e6c1854bb9687c09cb | |
parent | 47bbd6a4662d122b00a95bbb7a2e3d80cc45648e (diff) | |
download | rockbox-79d26ed7f96537363ee752068d080e4416c14086.tar.gz rockbox-79d26ed7f96537363ee752068d080e4416c14086.zip |
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
-rw-r--r-- | firmware/common/dir_uncached.c | 25 | ||||
-rw-r--r-- | firmware/drivers/fat.c | 20 |
2 files changed, 29 insertions, 16 deletions
diff --git a/firmware/common/dir_uncached.c b/firmware/common/dir_uncached.c index 2ce23e8b8e..e4c4397fe2 100644 --- a/firmware/common/dir_uncached.c +++ b/firmware/common/dir_uncached.c | |||
@@ -204,13 +204,28 @@ int mkdir_uncached(const char *name) | |||
204 | char *basename; | 204 | char *basename; |
205 | char *parent; | 205 | char *parent; |
206 | struct dirent_uncached *entry; | 206 | struct dirent_uncached *entry; |
207 | struct fat_dir newdir; | 207 | int dd; |
208 | DIR_UNCACHED* pdir = opendirs; | ||
209 | struct fat_dir *newdir; | ||
208 | int rc; | 210 | int rc; |
209 | 211 | ||
210 | if ( name[0] != '/' ) { | 212 | if ( name[0] != '/' ) { |
211 | DEBUGF("mkdir: Only absolute paths supported right now\n"); | 213 | DEBUGF("mkdir: Only absolute paths supported right now\n"); |
212 | return -1; | 214 | return -1; |
213 | } | 215 | } |
216 | /* find a free dir descriptor */ | ||
217 | for ( dd=0; dd<MAX_OPEN_DIRS; dd++, pdir++) | ||
218 | if ( !pdir->busy ) | ||
219 | break; | ||
220 | |||
221 | if ( dd == MAX_OPEN_DIRS ) { | ||
222 | DEBUGF("Too many dirs open\n"); | ||
223 | errno = EMFILE; | ||
224 | return -5; | ||
225 | } | ||
226 | |||
227 | pdir->busy = true; | ||
228 | newdir = &pdir->fatdir; | ||
214 | 229 | ||
215 | strlcpy(namecopy, name, sizeof(namecopy)); | 230 | strlcpy(namecopy, name, sizeof(namecopy)); |
216 | 231 | ||
@@ -230,11 +245,13 @@ int mkdir_uncached(const char *name) | |||
230 | 245 | ||
231 | if(!dir) { | 246 | if(!dir) { |
232 | DEBUGF("mkdir: can't open parent dir\n"); | 247 | DEBUGF("mkdir: can't open parent dir\n"); |
248 | pdir->busy = false; | ||
233 | return -2; | 249 | return -2; |
234 | } | 250 | } |
235 | 251 | ||
236 | if(basename[0] == 0) { | 252 | if(basename[0] == 0) { |
237 | DEBUGF("mkdir: Empty dir name\n"); | 253 | DEBUGF("mkdir: Empty dir name\n"); |
254 | pdir->busy = false; | ||
238 | errno = EINVAL; | 255 | errno = EINVAL; |
239 | return -3; | 256 | return -3; |
240 | } | 257 | } |
@@ -245,14 +262,16 @@ int mkdir_uncached(const char *name) | |||
245 | DEBUGF("mkdir error: file exists\n"); | 262 | DEBUGF("mkdir error: file exists\n"); |
246 | errno = EEXIST; | 263 | errno = EEXIST; |
247 | closedir_uncached(dir); | 264 | closedir_uncached(dir); |
265 | pdir->busy = false; | ||
248 | return - 4; | 266 | return - 4; |
249 | } | 267 | } |
250 | } | 268 | } |
251 | 269 | ||
252 | memset(&newdir, 0, sizeof(struct fat_dir)); | 270 | memset(newdir, 0, sizeof(struct fat_dir)); |
253 | 271 | ||
254 | rc = fat_create_dir(basename, &newdir, &(dir->fatdir)); | 272 | rc = fat_create_dir(basename, newdir, &(dir->fatdir)); |
255 | closedir_uncached(dir); | 273 | closedir_uncached(dir); |
274 | pdir->busy = false; | ||
256 | 275 | ||
257 | return rc; | 276 | return rc; |
258 | } | 277 | } |
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index c97772361e..c640e6e737 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c | |||
@@ -1967,7 +1967,7 @@ int fat_rename(struct fat_file* file, | |||
1967 | int attr) | 1967 | int attr) |
1968 | { | 1968 | { |
1969 | int rc; | 1969 | int rc; |
1970 | struct fat_dir olddir; | 1970 | struct fat_file olddir_file; |
1971 | struct fat_file newfile = *file; | 1971 | struct fat_file newfile = *file; |
1972 | unsigned char* entry = NULL; | 1972 | unsigned char* entry = NULL; |
1973 | unsigned short* clusptr = NULL; | 1973 | unsigned short* clusptr = NULL; |
@@ -1988,11 +1988,6 @@ int fat_rename(struct fat_file* file, | |||
1988 | return -2; | 1988 | return -2; |
1989 | } | 1989 | } |
1990 | 1990 | ||
1991 | /* create a temporary file handle */ | ||
1992 | rc = fat_opendir(IF_MV2(file->volume,) &olddir, file->dircluster, NULL); | ||
1993 | if (rc < 0) | ||
1994 | return rc * 10 - 1; | ||
1995 | |||
1996 | /* create new name */ | 1991 | /* create new name */ |
1997 | rc = add_dir_entry(dir, &newfile, newname, false, false); | 1992 | rc = add_dir_entry(dir, &newfile, newname, false, false); |
1998 | if (rc < 0) | 1993 | if (rc < 0) |
@@ -2016,18 +2011,17 @@ int fat_rename(struct fat_file* file, | |||
2016 | it points to its parent directory (we don't check if it was a move) */ | 2011 | it points to its parent directory (we don't check if it was a move) */ |
2017 | if(FAT_ATTR_DIRECTORY == attr) { | 2012 | if(FAT_ATTR_DIRECTORY == attr) { |
2018 | unsigned char buf[SECTOR_SIZE]; | 2013 | unsigned char buf[SECTOR_SIZE]; |
2019 | /* open the dir that was renamed, we re-use the olddir struct */ | 2014 | /* open the dir that was renamed, we re-use the olddir_file struct */ |
2020 | rc = fat_opendir(IF_MV2(file->volume,) &olddir, newfile.firstcluster, | 2015 | rc = fat_open(IF_MV2(volume,) newfile.firstcluster, &olddir_file, NULL); |
2021 | NULL); | ||
2022 | if (rc < 0) | 2016 | if (rc < 0) |
2023 | return rc * 10 - 6; | 2017 | return rc * 10 - 6; |
2024 | 2018 | ||
2025 | /* get the first sector of the dir */ | 2019 | /* get the first sector of the dir */ |
2026 | rc = fat_seek(&olddir.file, 0); | 2020 | rc = fat_seek(&olddir_file, 0); |
2027 | if (rc < 0) | 2021 | if (rc < 0) |
2028 | return rc * 10 - 7; | 2022 | return rc * 10 - 7; |
2029 | 2023 | ||
2030 | rc = fat_readwrite(&olddir.file, 1, buf, false); | 2024 | rc = fat_readwrite(&olddir_file, 1, buf, false); |
2031 | if (rc < 0) | 2025 | if (rc < 0) |
2032 | return rc * 10 - 8; | 2026 | return rc * 10 - 8; |
2033 | 2027 | ||
@@ -2051,11 +2045,11 @@ int fat_rename(struct fat_file* file, | |||
2051 | *clusptr = htole16(parentcluster & 0xffff); | 2045 | *clusptr = htole16(parentcluster & 0xffff); |
2052 | 2046 | ||
2053 | /* write back this sector */ | 2047 | /* write back this sector */ |
2054 | rc = fat_seek(&olddir.file, 0); | 2048 | rc = fat_seek(&olddir_file, 0); |
2055 | if (rc < 0) | 2049 | if (rc < 0) |
2056 | return rc * 10 - 7; | 2050 | return rc * 10 - 7; |
2057 | 2051 | ||
2058 | rc = fat_readwrite(&olddir.file, 1, buf, true); | 2052 | rc = fat_readwrite(&olddir_file, 1, buf, true); |
2059 | if (rc < 1) | 2053 | if (rc < 1) |
2060 | return rc * 10 - 8; | 2054 | return rc * 10 - 8; |
2061 | } | 2055 | } |