summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/SOURCES2
-rw-r--r--firmware/common/dir_uncached.c (renamed from firmware/common/dir.c)60
-rw-r--r--firmware/common/dircache.c48
-rw-r--r--firmware/common/disk.c4
-rw-r--r--firmware/common/file.c28
-rw-r--r--firmware/include/dir.h88
-rw-r--r--firmware/include/dir_uncached.h91
-rw-r--r--firmware/include/dircache.h26
8 files changed, 194 insertions, 153 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index d899551a37..6e7762ac75 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -28,7 +28,7 @@ common/crc32-mi4.c
28#endif 28#endif
29common/ctype.c 29common/ctype.c
30#ifndef SIMULATOR 30#ifndef SIMULATOR
31common/dir.c 31common/dir_uncached.c
32common/file.c 32common/file.c
33#endif /* SIMULATOR */ 33#endif /* SIMULATOR */
34#ifdef HAVE_DIRCACHE 34#ifdef HAVE_DIRCACHE
diff --git a/firmware/common/dir.c b/firmware/common/dir_uncached.c
index 0f46652b3c..e6b59c30ec 100644
--- a/firmware/common/dir.c
+++ b/firmware/common/dir_uncached.c
@@ -5,7 +5,7 @@
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id$ 8 * $Id: dir.c 13741 2007-06-30 02:08:27Z jethead71 $
9 * 9 *
10 * Copyright (C) 2002 by Björn Stenberg 10 * Copyright (C) 2002 by Björn Stenberg
11 * 11 *
@@ -24,11 +24,11 @@
24#include "dir.h" 24#include "dir.h"
25#include "debug.h" 25#include "debug.h"
26#include "atoi.h" 26#include "atoi.h"
27#include "dircache.h" 27//#include "dircache.h"
28 28
29#define MAX_OPEN_DIRS 8 29#define MAX_OPEN_DIRS 8
30 30
31static DIR opendirs[MAX_OPEN_DIRS]; 31static DIR_UNCACHED opendirs[MAX_OPEN_DIRS];
32 32
33#ifdef HAVE_MULTIVOLUME 33#ifdef HAVE_MULTIVOLUME
34 34
@@ -78,7 +78,7 @@ static int strip_volume(const char* name, char* namecopy)
78// release all dir handles on a given volume "by force", to avoid leaks 78// release all dir handles on a given volume "by force", to avoid leaks
79int release_dirs(int volume) 79int release_dirs(int volume)
80{ 80{
81 DIR* pdir = opendirs; 81 DIR_UNCACHED* pdir = opendirs;
82 int dd; 82 int dd;
83 int closed = 0; 83 int closed = 0;
84 for ( dd=0; dd<MAX_OPEN_DIRS; dd++, pdir++) 84 for ( dd=0; dd<MAX_OPEN_DIRS; dd++, pdir++)
@@ -93,14 +93,14 @@ int release_dirs(int volume)
93} 93}
94#endif /* #ifdef HAVE_HOTSWAP */ 94#endif /* #ifdef HAVE_HOTSWAP */
95 95
96DIR* opendir(const char* name) 96DIR_UNCACHED* opendir_uncached(const char* name)
97{ 97{
98 char namecopy[MAX_PATH]; 98 char namecopy[MAX_PATH];
99 char* part; 99 char* part;
100 char* end; 100 char* end;
101 struct fat_direntry entry; 101 struct fat_direntry entry;
102 int dd; 102 int dd;
103 DIR* pdir = opendirs; 103 DIR_UNCACHED* pdir = opendirs;
104#ifdef HAVE_MULTIVOLUME 104#ifdef HAVE_MULTIVOLUME
105 int volume; 105 int volume;
106#endif 106#endif
@@ -170,16 +170,16 @@ DIR* opendir(const char* name)
170 return pdir; 170 return pdir;
171} 171}
172 172
173int closedir(DIR* dir) 173int closedir_uncached(DIR_UNCACHED* dir)
174{ 174{
175 dir->busy=false; 175 dir->busy=false;
176 return 0; 176 return 0;
177} 177}
178 178
179struct dirent* readdir(DIR* dir) 179struct dirent_uncached* readdir_uncached(DIR_UNCACHED* dir)
180{ 180{
181 struct fat_direntry entry; 181 struct fat_direntry entry;
182 struct dirent* theent = &(dir->theent); 182 struct dirent_uncached* theent = &(dir->theent);
183 183
184 if (!dir->busy) 184 if (!dir->busy)
185 return NULL; 185 return NULL;
@@ -191,7 +191,7 @@ struct dirent* readdir(DIR* dir)
191 && dir->volumecounter < NUM_VOLUMES /* in range */ 191 && dir->volumecounter < NUM_VOLUMES /* in range */
192 && dir->fatdir.file.volume == 0) /* at volume 0 */ 192 && dir->fatdir.file.volume == 0) /* at volume 0 */
193 { /* fake special directories, which don't really exist, but 193 { /* fake special directories, which don't really exist, but
194 will get redirected upon opendir() */ 194 will get redirected upon opendir_uncached() */
195 while (++dir->volumecounter < NUM_VOLUMES) 195 while (++dir->volumecounter < NUM_VOLUMES)
196 { 196 {
197 if (fat_ismounted(dir->volumecounter)) 197 if (fat_ismounted(dir->volumecounter))
@@ -222,14 +222,14 @@ struct dirent* readdir(DIR* dir)
222 return theent; 222 return theent;
223} 223}
224 224
225int mkdir(const char *name) 225int mkdir_uncached(const char *name)
226{ 226{
227 DIR *dir; 227 DIR_UNCACHED *dir;
228 char namecopy[MAX_PATH]; 228 char namecopy[MAX_PATH];
229 char* end; 229 char* end;
230 char *basename; 230 char *basename;
231 char *parent; 231 char *parent;
232 struct dirent *entry; 232 struct dirent_uncached *entry;
233 struct fat_dir newdir; 233 struct fat_dir newdir;
234 int rc; 234 int rc;
235 235
@@ -253,7 +253,7 @@ int mkdir(const char *name)
253 253
254 DEBUGF("mkdir: parent: %s, name: %s\n", parent, basename); 254 DEBUGF("mkdir: parent: %s, name: %s\n", parent, basename);
255 255
256 dir = opendir(parent); 256 dir = opendir_uncached(parent);
257 257
258 if(!dir) { 258 if(!dir) {
259 DEBUGF("mkdir: can't open parent dir\n"); 259 DEBUGF("mkdir: can't open parent dir\n");
@@ -267,11 +267,11 @@ int mkdir(const char *name)
267 } 267 }
268 268
269 /* Now check if the name already exists */ 269 /* Now check if the name already exists */
270 while ((entry = readdir(dir))) { 270 while ((entry = readdir_uncached(dir))) {
271 if ( !strcasecmp(basename, entry->d_name) ) { 271 if ( !strcasecmp(basename, entry->d_name) ) {
272 DEBUGF("mkdir error: file exists\n"); 272 DEBUGF("mkdir error: file exists\n");
273 errno = EEXIST; 273 errno = EEXIST;
274 closedir(dir); 274 closedir_uncached(dir);
275 return - 4; 275 return - 4;
276 } 276 }
277 } 277 }
@@ -279,23 +279,18 @@ int mkdir(const char *name)
279 memset(&newdir, sizeof(struct fat_dir), 0); 279 memset(&newdir, sizeof(struct fat_dir), 0);
280 280
281 rc = fat_create_dir(basename, &newdir, &(dir->fatdir)); 281 rc = fat_create_dir(basename, &newdir, &(dir->fatdir));
282#ifdef HAVE_DIRCACHE 282 closedir_uncached(dir);
283 if (rc >= 0)
284 dircache_mkdir(name);
285#endif
286
287 closedir(dir);
288 283
289 return rc; 284 return rc;
290} 285}
291 286
292int rmdir(const char* name) 287int rmdir_uncached(const char* name)
293{ 288{
294 int rc; 289 int rc;
295 DIR* dir; 290 DIR_UNCACHED* dir;
296 struct dirent* entry; 291 struct dirent_uncached* entry;
297 292
298 dir = opendir(name); 293 dir = opendir_uncached(name);
299 if (!dir) 294 if (!dir)
300 { 295 {
301 errno = ENOENT; /* open error */ 296 errno = ENOENT; /* open error */
@@ -303,14 +298,14 @@ int rmdir(const char* name)
303 } 298 }
304 299
305 /* check if the directory is empty */ 300 /* check if the directory is empty */
306 while ((entry = readdir(dir))) 301 while ((entry = readdir_uncached(dir)))
307 { 302 {
308 if (strcmp(entry->d_name, ".") && 303 if (strcmp(entry->d_name, ".") &&
309 strcmp(entry->d_name, "..")) 304 strcmp(entry->d_name, ".."))
310 { 305 {
311 DEBUGF("rmdir error: not empty\n"); 306 DEBUGF("rmdir error: not empty\n");
312 errno = ENOTEMPTY; 307 errno = ENOTEMPTY;
313 closedir(dir); 308 closedir_uncached(dir);
314 return -2; 309 return -2;
315 } 310 }
316 } 311 }
@@ -321,14 +316,7 @@ int rmdir(const char* name)
321 errno = EIO; 316 errno = EIO;
322 rc = rc * 10 - 3; 317 rc = rc * 10 - 3;
323 } 318 }
324#ifdef HAVE_DIRCACHE
325 else
326 {
327 dircache_rmdir(name);
328 }
329#endif
330 319
331 closedir(dir); 320 closedir_uncached(dir);
332
333 return rc; 321 return rc;
334} 322}
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
47DIRCACHED opendirs[MAX_OPEN_DIRS]; 46DIR_CACHED opendirs[MAX_OPEN_DIRS];
48 47
49static struct dircache_entry *fd_bindings[MAX_OPEN_FILES]; 48static struct dircache_entry *fd_bindings[MAX_OPEN_FILES];
50static struct dircache_entry *dircache_root; 49static struct dircache_entry *dircache_root;
@@ -165,7 +164,7 @@ static bool check_event_queue(void)
165static int dircache_scan(struct travel_data *td) 164static 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
272static int dircache_travel(DIR *dir, struct dircache_entry *ce) 271static int dircache_travel(DIR_UNCACHED *dir, struct dircache_entry *ce)
273#else 272#else
274static int dircache_travel(struct fat_dir *dir, struct dircache_entry *ce) 273static 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)
519static int dircache_do_rebuild(void) 518static 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
1085DIRCACHED* opendir_cached(const char* name) 1084DIR_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
1133struct dircache_entry* readdir_cached(DIRCACHED* dir) 1132struct 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
1184int closedir_cached(DIRCACHED* dir) 1183int 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
1195int 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
1203int rmdir_cached(const char* name)
1204{
1205 int rc=rmdir_uncached(name);
1206 if(rc>=0)
1207 dircache_rmdir(name);
1208 return(rc);
1209}
diff --git a/firmware/common/disk.c b/firmware/common/disk.c
index f491c9b26a..563bb05ec1 100644
--- a/firmware/common/disk.c
+++ b/firmware/common/disk.c
@@ -22,9 +22,9 @@
22#include "fat.h" 22#include "fat.h"
23#ifdef HAVE_HOTSWAP 23#ifdef HAVE_HOTSWAP
24#include "hotswap.h" 24#include "hotswap.h"
25#include "dir.h" /* for release_dirs() */
26#include "file.h" /* for release_files() */
25#endif 27#endif
26#include "file.h" /* for release_dirs() */
27#include "dir.h" /* for release_files() */
28#include "disk.h" 28#include "disk.h"
29 29
30/* Partition table entry layout: 30/* Partition table entry layout:
diff --git a/firmware/common/file.c b/firmware/common/file.c
index bc57d556b3..d526f28859 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -21,7 +21,7 @@
21#include <stdbool.h> 21#include <stdbool.h>
22#include "file.h" 22#include "file.h"
23#include "fat.h" 23#include "fat.h"
24#include "dir.h" 24#include "dir_uncached.h"
25#include "debug.h" 25#include "debug.h"
26#include "dircache.h" 26#include "dircache.h"
27#include "system.h" 27#include "system.h"
@@ -59,8 +59,8 @@ int creat(const char *pathname)
59 59
60static int open_internal(const char* pathname, int flags, bool use_cache) 60static int open_internal(const char* pathname, int flags, bool use_cache)
61{ 61{
62 DIR* dir; 62 DIR_UNCACHED* dir;
63 struct dirent* entry; 63 struct dirent_uncached* entry;
64 int fd; 64 int fd;
65 char pathnamecopy[MAX_PATH]; 65 char pathnamecopy[MAX_PATH];
66 char* name; 66 char* name;
@@ -134,12 +134,12 @@ static int open_internal(const char* pathname, int flags, bool use_cache)
134 name=strrchr(pathnamecopy+1,'/'); 134 name=strrchr(pathnamecopy+1,'/');
135 if ( name ) { 135 if ( name ) {
136 *name = 0; 136 *name = 0;
137 dir = opendir(pathnamecopy); 137 dir = opendir_uncached(pathnamecopy);
138 *name = '/'; 138 *name = '/';
139 name++; 139 name++;
140 } 140 }
141 else { 141 else {
142 dir = opendir("/"); 142 dir = opendir_uncached("/");
143 name = pathnamecopy+1; 143 name = pathnamecopy+1;
144 } 144 }
145 if (!dir) { 145 if (!dir) {
@@ -153,12 +153,12 @@ static int open_internal(const char* pathname, int flags, bool use_cache)
153 DEBUGF("Empty file name\n"); 153 DEBUGF("Empty file name\n");
154 errno = EINVAL; 154 errno = EINVAL;
155 file->busy = false; 155 file->busy = false;
156 closedir(dir); 156 closedir_uncached(dir);
157 return -5; 157 return -5;
158 } 158 }
159 159
160 /* scan dir for name */ 160 /* scan dir for name */
161 while ((entry = readdir(dir))) { 161 while ((entry = readdir_uncached(dir))) {
162 if ( !strcasecmp(name, entry->d_name) ) { 162 if ( !strcasecmp(name, entry->d_name) ) {
163 fat_open(IF_MV2(dir->fatdir.file.volume,) 163 fat_open(IF_MV2(dir->fatdir.file.volume,)
164 entry->startcluster, 164 entry->startcluster,
@@ -180,7 +180,7 @@ static int open_internal(const char* pathname, int flags, bool use_cache)
180 DEBUGF("Couldn't create %s in %s\n",name,pathnamecopy); 180 DEBUGF("Couldn't create %s in %s\n",name,pathnamecopy);
181 errno = EIO; 181 errno = EIO;
182 file->busy = false; 182 file->busy = false;
183 closedir(dir); 183 closedir_uncached(dir);
184 return rc * 10 - 6; 184 return rc * 10 - 6;
185 } 185 }
186#ifdef HAVE_DIRCACHE 186#ifdef HAVE_DIRCACHE
@@ -193,18 +193,18 @@ static int open_internal(const char* pathname, int flags, bool use_cache)
193 DEBUGF("Couldn't find %s in %s\n",name,pathnamecopy); 193 DEBUGF("Couldn't find %s in %s\n",name,pathnamecopy);
194 errno = ENOENT; 194 errno = ENOENT;
195 file->busy = false; 195 file->busy = false;
196 closedir(dir); 196 closedir_uncached(dir);
197 return -7; 197 return -7;
198 } 198 }
199 } else { 199 } else {
200 if(file->write && (file->attr & FAT_ATTR_DIRECTORY)) { 200 if(file->write && (file->attr & FAT_ATTR_DIRECTORY)) {
201 errno = EISDIR; 201 errno = EISDIR;
202 file->busy = false; 202 file->busy = false;
203 closedir(dir); 203 closedir_uncached(dir);
204 return -8; 204 return -8;
205 } 205 }
206 } 206 }
207 closedir(dir); 207 closedir_uncached(dir);
208 208
209 file->cacheoffset = -1; 209 file->cacheoffset = -1;
210 file->fileoffset = 0; 210 file->fileoffset = 0;
@@ -327,7 +327,7 @@ int remove(const char* name)
327int rename(const char* path, const char* newpath) 327int rename(const char* path, const char* newpath)
328{ 328{
329 int rc, fd; 329 int rc, fd;
330 DIR* dir; 330 DIR_UNCACHED* dir;
331 char* nameptr; 331 char* nameptr;
332 char* dirptr; 332 char* dirptr;
333 struct filedesc* file; 333 struct filedesc* file;
@@ -371,7 +371,7 @@ int rename(const char* path, const char* newpath)
371 dirptr = "/"; 371 dirptr = "/";
372 } 372 }
373 373
374 dir = opendir(dirptr); 374 dir = opendir_uncached(dirptr);
375 if(!dir) 375 if(!dir)
376 return - 5; 376 return - 5;
377 377
@@ -401,7 +401,7 @@ int rename(const char* path, const char* newpath)
401 return rc * 10 - 8; 401 return rc * 10 - 8;
402 } 402 }
403 403
404 rc = closedir(dir); 404 rc = closedir_uncached(dir);
405 if (rc<0) { 405 if (rc<0) {
406 errno = EIO; 406 errno = EIO;
407 return rc * 10 - 9; 407 return rc * 10 - 9;
diff --git a/firmware/include/dir.h b/firmware/include/dir.h
index 020b24a502..8778d0be02 100644
--- a/firmware/include/dir.h
+++ b/firmware/include/dir.h
@@ -7,7 +7,7 @@
7 * \/ \/ \/ \/ \/ 7 * \/ \/ \/ \/ \/
8 * $Id$ 8 * $Id$
9 * 9 *
10 * Copyright (C) 2002 by Björn Stenberg 10 * Copyright (C) 2007 by Kévin Ferrare
11 * 11 *
12 * All files in this archive are subject to the GNU General Public License. 12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement. 13 * See the file COPYING in the source tree root for full license agreement.
@@ -16,76 +16,30 @@
16 * KIND, either express or implied. 16 * KIND, either express or implied.
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19
19#ifndef _DIR_H_ 20#ifndef _DIR_H_
20#define _DIR_H_ 21#define _DIR_H_
21 22
22#include <stdbool.h> 23#ifdef HAVE_DIRCACHE
23#include "file.h" 24# include "dircache.h"
24 25# define DIR DIR_CACHED
25#define ATTR_READ_ONLY 0x01 26# define dirent dircache_entry
26#define ATTR_HIDDEN 0x02 27# define opendir opendir_cached
27#define ATTR_SYSTEM 0x04 28# define closedir closedir_cached
28#define ATTR_VOLUME_ID 0x08 29# define readdir readdir_cached
29#define ATTR_DIRECTORY 0x10 30# define closedir closedir_cached
30#define ATTR_ARCHIVE 0x20 31# define mkdir mkdir_cached
31#define ATTR_VOLUME 0x40 /* this is a volume, not a real directory */ 32# define rmdir rmdir_cached
32
33#ifdef SIMULATOR
34#define dirent sim_dirent
35#define DIR SIM_DIR
36#define opendir(x) sim_opendir(x)
37#define readdir(x) sim_readdir(x)
38#define closedir(x) sim_closedir(x)
39#define mkdir(x) sim_mkdir(x)
40#define rmdir(x) sim_rmdir(x)
41#endif
42
43#ifndef DIRENT_DEFINED
44
45struct dirent {
46 unsigned char d_name[MAX_PATH];
47 int attribute;
48 long size;
49 long startcluster;
50 unsigned short wrtdate; /* Last write date */
51 unsigned short wrttime; /* Last write time */
52};
53#endif
54
55#include "fat.h"
56
57typedef struct {
58#ifndef SIMULATOR
59 bool busy;
60 long startcluster;
61 struct fat_dir fatdir;
62 struct fat_dir parent_dir;
63 struct dirent theent;
64#ifdef HAVE_MULTIVOLUME
65 int volumecounter; /* running counter for faked volume entries */
66#endif
67#else 33#else
68 /* simulator: */ 34#include "dir_uncached.h"
69 void *dir; /* actually a DIR* dir */ 35# define DIR DIR_UNCACHED
70 char *name; 36# define dirent dirent_uncached
71#endif 37# define opendir opendir_uncached
72} DIR; 38# define closedir closedir_uncached
73 39# define readdir readdir_uncached
74#ifdef HAVE_HOTSWAP 40# define closedir closedir_uncached
75char *get_volume_name(int volume); 41# define mkdir mkdir_uncached
42# define rmdir rmdir_uncached
76#endif 43#endif
77 44
78#ifndef DIRFUNCTIONS_DEFINED
79
80extern DIR* opendir(const char* name);
81extern int closedir(DIR* dir);
82extern int mkdir(const char* name);
83extern int rmdir(const char* name);
84
85extern struct dirent* readdir(DIR* dir);
86
87extern int release_dirs(int volume);
88
89#endif /* DIRFUNCTIONS_DEFINED */
90
91#endif 45#endif
diff --git a/firmware/include/dir_uncached.h b/firmware/include/dir_uncached.h
new file mode 100644
index 0000000000..575c3b67e4
--- /dev/null
+++ b/firmware/include/dir_uncached.h
@@ -0,0 +1,91 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: dir.h 13741 2007-06-30 02:08:27Z jethead71 $
9 *
10 * Copyright (C) 2002 by Björn Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#ifndef _DIR_UNCACHED_H_
20#define _DIR_UNCACHED_H_
21
22#include <stdbool.h>
23#include "file.h"
24
25#define ATTR_READ_ONLY 0x01
26#define ATTR_HIDDEN 0x02
27#define ATTR_SYSTEM 0x04
28#define ATTR_VOLUME_ID 0x08
29#define ATTR_DIRECTORY 0x10
30#define ATTR_ARCHIVE 0x20
31#define ATTR_VOLUME 0x40 /* this is a volume, not a real directory */
32
33#ifdef SIMULATOR
34#define dirent_uncached sim_dirent
35#define DIR_UNCACHED SIM_DIR
36#define opendir_uncached sim_opendir
37#define readdir_uncached sim_readdir
38#define closedir_uncached sim_closedir
39#define mkdir_uncached sim_mkdir
40#define rmdir_uncached sim_rmdir
41#endif
42
43#ifndef DIRENT_DEFINED
44
45struct dirent_uncached {
46 unsigned char d_name[MAX_PATH];
47 int attribute;
48 long size;
49 long startcluster;
50 unsigned short wrtdate; /* Last write date */
51 unsigned short wrttime; /* Last write time */
52};
53#endif
54
55#include "fat.h"
56
57typedef struct {
58#ifndef SIMULATOR
59 bool busy;
60 long startcluster;
61 struct fat_dir fatdir;
62 struct fat_dir parent_dir;
63 struct dirent_uncached theent;
64#ifdef HAVE_MULTIVOLUME
65 int volumecounter; /* running counter for faked volume entries */
66#endif
67#else
68 /* simulator: */
69 void *dir; /* actually a DIR* dir */
70 char *name;
71#endif
72} DIR_UNCACHED;
73
74#ifdef HAVE_HOTSWAP
75char *get_volume_name(int volume);
76#endif
77
78#ifndef DIRFUNCTIONS_DEFINED
79
80extern DIR_UNCACHED* opendir_uncached(const char* name);
81extern int closedir_uncached(DIR_UNCACHED* dir);
82extern int mkdir_uncached(const char* name);
83extern int rmdir_uncached(const char* name);
84
85extern struct dirent_uncached* readdir_uncached(DIR_UNCACHED* dir);
86
87extern int release_dirs(int volume);
88
89#endif /* DIRFUNCTIONS_DEFINED */
90
91#endif
diff --git a/firmware/include/dircache.h b/firmware/include/dircache.h
index 1483843a73..6b47f3f1bb 100644
--- a/firmware/include/dircache.h
+++ b/firmware/include/dircache.h
@@ -19,7 +19,7 @@
19#ifndef _DIRCACHE_H 19#ifndef _DIRCACHE_H
20#define _DIRCACHE_H 20#define _DIRCACHE_H
21 21
22#include "dir.h" 22#include "dir_uncached.h"
23 23
24#ifdef HAVE_DIRCACHE 24#ifdef HAVE_DIRCACHE
25 25
@@ -34,8 +34,8 @@ struct travel_data {
34 struct dircache_entry *ce; 34 struct dircache_entry *ce;
35 struct dircache_entry *down_entry; 35 struct dircache_entry *down_entry;
36#ifdef SIMULATOR 36#ifdef SIMULATOR
37 DIR *dir, *newdir; 37 DIR_UNCACHED *dir, *newdir;
38 struct dirent *entry; 38 struct dirent_uncached *entry;
39#else 39#else
40 struct fat_dir *dir; 40 struct fat_dir *dir;
41 struct fat_dir newdir; 41 struct fat_dir newdir;
@@ -77,8 +77,8 @@ typedef struct {
77 struct dircache_entry *entry; 77 struct dircache_entry *entry;
78 struct dircache_entry *internal_entry; 78 struct dircache_entry *internal_entry;
79 struct dircache_entry secondary_entry; 79 struct dircache_entry secondary_entry;
80 DIR *regulardir; 80 DIR_UNCACHED *regulardir;
81} DIRCACHED; 81} DIR_CACHED;
82 82
83void dircache_init(void); 83void dircache_init(void);
84int dircache_load(void); 84int dircache_load(void);
@@ -103,17 +103,11 @@ void dircache_remove(const char *name);
103void dircache_rename(const char *oldpath, const char *newpath); 103void dircache_rename(const char *oldpath, const char *newpath);
104void dircache_add_file(const char *path, long startcluster); 104void dircache_add_file(const char *path, long startcluster);
105 105
106DIRCACHED* opendir_cached(const char* name); 106DIR_CACHED* opendir_cached(const char* name);
107struct dircache_entry* readdir_cached(DIRCACHED* dir); 107struct dircache_entry* readdir_cached(DIR_CACHED* dir);
108int closedir_cached(DIRCACHED *dir); 108int closedir_cached(DIR_CACHED *dir);
109 109int mkdir_cached(const char *name);
110#else /* HAVE_DIRCACHE */ 110int rmdir_cached(const char* name);
111# define DIRCACHED DIR
112# define dircache_entry dirent
113# define opendir_cached opendir
114# define closedir_cached closedir
115# define readdir_cached readdir
116# define closedir_cached closedir
117#endif /* !HAVE_DIRCACHE */ 111#endif /* !HAVE_DIRCACHE */
118 112
119#endif 113#endif