diff options
Diffstat (limited to 'firmware/common/dircache.c')
-rw-r--r-- | firmware/common/dircache.c | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/firmware/common/dircache.c b/firmware/common/dircache.c index be356e1ddf..97c58842d5 100644 --- a/firmware/common/dircache.c +++ b/firmware/common/dircache.c | |||
@@ -27,7 +27,6 @@ | |||
27 | #include <errno.h> | 27 | #include <errno.h> |
28 | #include <string.h> | 28 | #include <string.h> |
29 | #include <stdbool.h> | 29 | #include <stdbool.h> |
30 | #include "dir.h" | ||
31 | #include "debug.h" | 30 | #include "debug.h" |
32 | #include "atoi.h" | 31 | #include "atoi.h" |
33 | #include "system.h" | 32 | #include "system.h" |
@@ -44,7 +43,7 @@ | |||
44 | #define DIRCACHE_STOP 2 | 43 | #define DIRCACHE_STOP 2 |
45 | 44 | ||
46 | #define MAX_OPEN_DIRS 8 | 45 | #define MAX_OPEN_DIRS 8 |
47 | DIRCACHED opendirs[MAX_OPEN_DIRS]; | 46 | DIR_CACHED opendirs[MAX_OPEN_DIRS]; |
48 | 47 | ||
49 | static struct dircache_entry *fd_bindings[MAX_OPEN_FILES]; | 48 | static struct dircache_entry *fd_bindings[MAX_OPEN_FILES]; |
50 | static struct dircache_entry *dircache_root; | 49 | static struct dircache_entry *dircache_root; |
@@ -165,7 +164,7 @@ static bool check_event_queue(void) | |||
165 | static int dircache_scan(struct travel_data *td) | 164 | static int dircache_scan(struct travel_data *td) |
166 | { | 165 | { |
167 | #ifdef SIMULATOR | 166 | #ifdef SIMULATOR |
168 | while ( ( td->entry = readdir(td->dir) ) ) | 167 | while ( ( td->entry = readdir_uncached(td->dir) ) ) |
169 | #else | 168 | #else |
170 | while ( (fat_getnext(td->dir, &td->entry) >= 0) && (td->entry.name[0])) | 169 | while ( (fat_getnext(td->dir, &td->entry) >= 0) && (td->entry.name[0])) |
171 | #endif | 170 | #endif |
@@ -221,10 +220,10 @@ static int dircache_scan(struct travel_data *td) | |||
221 | strncpy(&dircache_cur_path[td->pathpos+1], td->entry->d_name, | 220 | strncpy(&dircache_cur_path[td->pathpos+1], td->entry->d_name, |
222 | sizeof(dircache_cur_path) - td->pathpos - 2); | 221 | sizeof(dircache_cur_path) - td->pathpos - 2); |
223 | 222 | ||
224 | td->newdir = opendir(dircache_cur_path); | 223 | td->newdir = opendir_uncached(dircache_cur_path); |
225 | if (td->newdir == NULL) | 224 | if (td->newdir == NULL) |
226 | { | 225 | { |
227 | logf("Failed to opendir(): %s", dircache_cur_path); | 226 | logf("Failed to opendir_uncached(): %s", dircache_cur_path); |
228 | return -3; | 227 | return -3; |
229 | } | 228 | } |
230 | #else | 229 | #else |
@@ -269,7 +268,7 @@ static int dircache_scan(struct travel_data *td) | |||
269 | * Recursively scan the hard disk and build the cache. | 268 | * Recursively scan the hard disk and build the cache. |
270 | */ | 269 | */ |
271 | #ifdef SIMULATOR | 270 | #ifdef SIMULATOR |
272 | static int dircache_travel(DIR *dir, struct dircache_entry *ce) | 271 | static int dircache_travel(DIR_UNCACHED *dir, struct dircache_entry *ce) |
273 | #else | 272 | #else |
274 | static int dircache_travel(struct fat_dir *dir, struct dircache_entry *ce) | 273 | static int dircache_travel(struct fat_dir *dir, struct dircache_entry *ce) |
275 | #endif | 274 | #endif |
@@ -292,7 +291,7 @@ static int dircache_travel(struct fat_dir *dir, struct dircache_entry *ce) | |||
292 | ce->d_name = "."; | 291 | ce->d_name = "."; |
293 | ce->name_len = 2; | 292 | ce->name_len = 2; |
294 | #ifdef SIMULATOR | 293 | #ifdef SIMULATOR |
295 | closedir(dir_recursion[depth].dir); | 294 | closedir_uncached(dir_recursion[depth].dir); |
296 | ce->attribute = ATTR_DIRECTORY; | 295 | ce->attribute = ATTR_DIRECTORY; |
297 | #else | 296 | #else |
298 | ce->attribute = FAT_ATTR_DIRECTORY; | 297 | ce->attribute = FAT_ATTR_DIRECTORY; |
@@ -519,7 +518,7 @@ int dircache_save(void) | |||
519 | static int dircache_do_rebuild(void) | 518 | static int dircache_do_rebuild(void) |
520 | { | 519 | { |
521 | #ifdef SIMULATOR | 520 | #ifdef SIMULATOR |
522 | DIR *pdir; | 521 | DIR_UNCACHED *pdir; |
523 | #else | 522 | #else |
524 | struct fat_dir dir, *pdir; | 523 | struct fat_dir dir, *pdir; |
525 | #endif | 524 | #endif |
@@ -532,7 +531,7 @@ static int dircache_do_rebuild(void) | |||
532 | dircache_initializing = true; | 531 | dircache_initializing = true; |
533 | 532 | ||
534 | #ifdef SIMULATOR | 533 | #ifdef SIMULATOR |
535 | pdir = opendir("/"); | 534 | pdir = opendir_uncached("/"); |
536 | if (pdir == NULL) | 535 | if (pdir == NULL) |
537 | { | 536 | { |
538 | logf("Failed to open rootdir"); | 537 | logf("Failed to open rootdir"); |
@@ -1082,11 +1081,11 @@ void dircache_add_file(const char *path, long startcluster) | |||
1082 | entry->startcluster = startcluster; | 1081 | entry->startcluster = startcluster; |
1083 | } | 1082 | } |
1084 | 1083 | ||
1085 | DIRCACHED* opendir_cached(const char* name) | 1084 | DIR_CACHED* opendir_cached(const char* name) |
1086 | { | 1085 | { |
1087 | struct dircache_entry *cache_entry; | 1086 | struct dircache_entry *cache_entry; |
1088 | int dd; | 1087 | int dd; |
1089 | DIRCACHED* pdir = opendirs; | 1088 | DIR_CACHED* pdir = opendirs; |
1090 | 1089 | ||
1091 | if ( name[0] != '/' ) | 1090 | if ( name[0] != '/' ) |
1092 | { | 1091 | { |
@@ -1108,7 +1107,7 @@ DIRCACHED* opendir_cached(const char* name) | |||
1108 | 1107 | ||
1109 | if (!dircache_initialized) | 1108 | if (!dircache_initialized) |
1110 | { | 1109 | { |
1111 | pdir->regulardir = opendir(name); | 1110 | pdir->regulardir = opendir_uncached(name); |
1112 | if (!pdir->regulardir) | 1111 | if (!pdir->regulardir) |
1113 | return NULL; | 1112 | return NULL; |
1114 | 1113 | ||
@@ -1130,9 +1129,9 @@ DIRCACHED* opendir_cached(const char* name) | |||
1130 | return pdir; | 1129 | return pdir; |
1131 | } | 1130 | } |
1132 | 1131 | ||
1133 | struct dircache_entry* readdir_cached(DIRCACHED* dir) | 1132 | struct dircache_entry* readdir_cached(DIR_CACHED* dir) |
1134 | { | 1133 | { |
1135 | struct dirent *regentry; | 1134 | struct dirent_uncached *regentry; |
1136 | struct dircache_entry *ce; | 1135 | struct dircache_entry *ce; |
1137 | 1136 | ||
1138 | if (!dir->busy) | 1137 | if (!dir->busy) |
@@ -1140,7 +1139,7 @@ struct dircache_entry* readdir_cached(DIRCACHED* dir) | |||
1140 | 1139 | ||
1141 | if (dir->regulardir != NULL) | 1140 | if (dir->regulardir != NULL) |
1142 | { | 1141 | { |
1143 | regentry = readdir(dir->regulardir); | 1142 | regentry = readdir_uncached(dir->regulardir); |
1144 | if (regentry == NULL) | 1143 | if (regentry == NULL) |
1145 | return NULL; | 1144 | return NULL; |
1146 | 1145 | ||
@@ -1181,15 +1180,30 @@ struct dircache_entry* readdir_cached(DIRCACHED* dir) | |||
1181 | return &dir->secondary_entry; | 1180 | return &dir->secondary_entry; |
1182 | } | 1181 | } |
1183 | 1182 | ||
1184 | int closedir_cached(DIRCACHED* dir) | 1183 | int closedir_cached(DIR_CACHED* dir) |
1185 | { | 1184 | { |
1186 | if (!dir->busy) | 1185 | if (!dir->busy) |
1187 | return -1; | 1186 | return -1; |
1188 | 1187 | ||
1189 | dir->busy=false; | 1188 | dir->busy=false; |
1190 | if (dir->regulardir != NULL) | 1189 | if (dir->regulardir != NULL) |
1191 | return closedir(dir->regulardir); | 1190 | return closedir_uncached(dir->regulardir); |
1192 | 1191 | ||
1193 | return 0; | 1192 | return 0; |
1194 | } | 1193 | } |
1195 | 1194 | ||
1195 | int mkdir_cached(const char *name) | ||
1196 | { | ||
1197 | int rc=mkdir_uncached(name); | ||
1198 | if (rc >= 0) | ||
1199 | dircache_mkdir(name); | ||
1200 | return(rc); | ||
1201 | } | ||
1202 | |||
1203 | int rmdir_cached(const char* name) | ||
1204 | { | ||
1205 | int rc=rmdir_uncached(name); | ||
1206 | if(rc>=0) | ||
1207 | dircache_rmdir(name); | ||
1208 | return(rc); | ||
1209 | } | ||