diff options
author | Kevin Ferrare <kevin@rockbox.org> | 2007-07-20 17:06:55 +0000 |
---|---|---|
committer | Kevin Ferrare <kevin@rockbox.org> | 2007-07-20 17:06:55 +0000 |
commit | 011a325e32c05f6e4817dcdc555615e6b7b6c102 (patch) | |
tree | ab22ab91b99524dba823cda861b17520db030911 /firmware | |
parent | 930278bcc0fd944ec50f30074b53b4c7cf0e3ccf (diff) | |
download | rockbox-011a325e32c05f6e4817dcdc555615e6b7b6c102.tar.gz rockbox-011a325e32c05f6e4817dcdc555615e6b7b6c102.zip |
Makes apps and plugins interract with directories using a posix-like api instead of calling dircache / simulator functions (no additionnal layer added, only a cosmetic change)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13943 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/SOURCES | 2 | ||||
-rw-r--r-- | firmware/common/dir_uncached.c (renamed from firmware/common/dir.c) | 60 | ||||
-rw-r--r-- | firmware/common/dircache.c | 48 | ||||
-rw-r--r-- | firmware/common/disk.c | 4 | ||||
-rw-r--r-- | firmware/common/file.c | 28 | ||||
-rw-r--r-- | firmware/include/dir.h | 88 | ||||
-rw-r--r-- | firmware/include/dir_uncached.h | 91 | ||||
-rw-r--r-- | firmware/include/dircache.h | 26 |
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 #endif common/ctype.c #ifndef SIMULATOR -common/dir.c +common/dir_uncached.c common/file.c #endif /* SIMULATOR */ #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 @@ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ - * $Id$ + * $Id: dir.c 13741 2007-06-30 02:08:27Z jethead71 $ * * Copyright (C) 2002 by Björn Stenberg * @@ -24,11 +24,11 @@ #include "dir.h" #include "debug.h" #include "atoi.h" -#include "dircache.h" +//#include "dircache.h" #define MAX_OPEN_DIRS 8 -static DIR opendirs[MAX_OPEN_DIRS]; +static DIR_UNCACHED opendirs[MAX_OPEN_DIRS]; #ifdef HAVE_MULTIVOLUME @@ -78,7 +78,7 @@ static int strip_volume(const char* name, char* namecopy) // release all dir handles on a given volume "by force", to avoid leaks int release_dirs(int volume) { - DIR* pdir = opendirs; + DIR_UNCACHED* pdir = opendirs; int dd; int closed = 0; for ( dd=0; dd<MAX_OPEN_DIRS; dd++, pdir++) @@ -93,14 +93,14 @@ int release_dirs(int volume) } #endif /* #ifdef HAVE_HOTSWAP */ -DIR* opendir(const char* name) +DIR_UNCACHED* opendir_uncached(const char* name) { char namecopy[MAX_PATH]; char* part; char* end; struct fat_direntry entry; int dd; - DIR* pdir = opendirs; + DIR_UNCACHED* pdir = opendirs; #ifdef HAVE_MULTIVOLUME int volume; #endif @@ -170,16 +170,16 @@ DIR* opendir(const char* name) return pdir; } -int closedir(DIR* dir) +int closedir_uncached(DIR_UNCACHED* dir) { dir->busy=false; return 0; } -struct dirent* readdir(DIR* dir) +struct dirent_uncached* readdir_uncached(DIR_UNCACHED* dir) { struct fat_direntry entry; - struct dirent* theent = &(dir->theent); + struct dirent_uncached* theent = &(dir->theent); if (!dir->busy) return NULL; @@ -191,7 +191,7 @@ struct dirent* readdir(DIR* dir) && dir->volumecounter < NUM_VOLUMES /* in range */ && dir->fatdir.file.volume == 0) /* at volume 0 */ { /* fake special directories, which don't really exist, but - will get redirected upon opendir() */ + will get redirected upon opendir_uncached() */ while (++dir->volumecounter < NUM_VOLUMES) { if (fat_ismounted(dir->volumecounter)) @@ -222,14 +222,14 @@ struct dirent* readdir(DIR* dir) return theent; } -int mkdir(const char *name) +int mkdir_uncached(const char *name) { - DIR *dir; + DIR_UNCACHED *dir; char namecopy[MAX_PATH]; char* end; char *basename; char *parent; - struct dirent *entry; + struct dirent_uncached *entry; struct fat_dir newdir; int rc; @@ -253,7 +253,7 @@ int mkdir(const char *name) DEBUGF("mkdir: parent: %s, name: %s\n", parent, basename); - dir = opendir(parent); + dir = opendir_uncached(parent); if(!dir) { DEBUGF("mkdir: can't open parent dir\n"); @@ -267,11 +267,11 @@ int mkdir(const char *name) } /* Now check if the name already exists */ - while ((entry = readdir(dir))) { + while ((entry = readdir_uncached(dir))) { if ( !strcasecmp(basename, entry->d_name) ) { DEBUGF("mkdir error: file exists\n"); errno = EEXIST; - closedir(dir); + closedir_uncached(dir); return - 4; } } @@ -279,23 +279,18 @@ int mkdir(const char *name) memset(&newdir, sizeof(struct fat_dir), 0); rc = fat_create_dir(basename, &newdir, &(dir->fatdir)); -#ifdef HAVE_DIRCACHE - if (rc >= 0) - dircache_mkdir(name); -#endif - - closedir(dir); + closedir_uncached(dir); return rc; } -int rmdir(const char* name) +int rmdir_uncached(const char* name) { int rc; - DIR* dir; - struct dirent* entry; + DIR_UNCACHED* dir; + struct dirent_uncached* entry; - dir = opendir(name); + dir = opendir_uncached(name); if (!dir) { errno = ENOENT; /* open error */ @@ -303,14 +298,14 @@ int rmdir(const char* name) } /* check if the directory is empty */ - while ((entry = readdir(dir))) + while ((entry = readdir_uncached(dir))) { if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) { DEBUGF("rmdir error: not empty\n"); errno = ENOTEMPTY; - closedir(dir); + closedir_uncached(dir); return -2; } } @@ -321,14 +316,7 @@ int rmdir(const char* name) errno = EIO; rc = rc * 10 - 3; } -#ifdef HAVE_DIRCACHE - else - { - dircache_rmdir(name); - } -#endif - closedir(dir); - + closedir_uncached(dir); return rc; } 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 @@ #include <errno.h> #include <string.h> #include <stdbool.h> -#include "dir.h" #include "debug.h" #include "atoi.h" #include "system.h" @@ -44,7 +43,7 @@ #define DIRCACHE_STOP 2 #define MAX_OPEN_DIRS 8 -DIRCACHED opendirs[MAX_OPEN_DIRS]; +DIR_CACHED opendirs[MAX_OPEN_DIRS]; static struct dircache_entry *fd_bindings[MAX_OPEN_FILES]; static struct dircache_entry *dircache_root; @@ -165,7 +164,7 @@ static bool check_event_queue(void) static int dircache_scan(struct travel_data *td) { #ifdef SIMULATOR - while ( ( td->entry = readdir(td->dir) ) ) + while ( ( td->entry = readdir_uncached(td->dir) ) ) #else while ( (fat_getnext(td->dir, &td->entry) >= 0) && (td->entry.name[0])) #endif @@ -221,10 +220,10 @@ static int dircache_scan(struct travel_data *td) strncpy(&dircache_cur_path[td->pathpos+1], td->entry->d_name, sizeof(dircache_cur_path) - td->pathpos - 2); - td->newdir = opendir(dircache_cur_path); + td->newdir = opendir_uncached(dircache_cur_path); if (td->newdir == NULL) { - logf("Failed to opendir(): %s", dircache_cur_path); + logf("Failed to opendir_uncached(): %s", dircache_cur_path); return -3; } #else @@ -269,7 +268,7 @@ static int dircache_scan(struct travel_data *td) * Recursively scan the hard disk and build the cache. */ #ifdef SIMULATOR -static int dircache_travel(DIR *dir, struct dircache_entry *ce) +static int dircache_travel(DIR_UNCACHED *dir, struct dircache_entry *ce) #else static int dircache_travel(struct fat_dir *dir, struct dircache_entry *ce) #endif @@ -292,7 +291,7 @@ static int dircache_travel(struct fat_dir *dir, struct dircache_entry *ce) ce->d_name = "."; ce->name_len = 2; #ifdef SIMULATOR - closedir(dir_recursion[depth].dir); + closedir_uncached(dir_recursion[depth].dir); ce->attribute = ATTR_DIRECTORY; #else ce->attribute = FAT_ATTR_DIRECTORY; @@ -519,7 +518,7 @@ int dircache_save(void) static int dircache_do_rebuild(void) { #ifdef SIMULATOR - DIR *pdir; + DIR_UNCACHED *pdir; #else struct fat_dir dir, *pdir; #endif @@ -532,7 +531,7 @@ static int dircache_do_rebuild(void) dircache_initializing = true; #ifdef SIMULATOR - pdir = opendir("/"); + pdir = opendir_uncached("/"); if (pdir == NULL) { logf("Failed to open rootdir"); @@ -1082,11 +1081,11 @@ void dircache_add_file(const char *path, long startcluster) entry->startcluster = startcluster; } -DIRCACHED* opendir_cached(const char* name) +DIR_CACHED* opendir_cached(const char* name) { struct dircache_entry *cache_entry; int dd; - DIRCACHED* pdir = opendirs; + DIR_CACHED* pdir = opendirs; if ( name[0] != '/' ) { @@ -1108,7 +1107,7 @@ DIRCACHED* opendir_cached(const char* name) if (!dircache_initialized) { - pdir->regulardir = opendir(name); + pdir->regulardir = opendir_uncached(name); if (!pdir->regulardir) return NULL; @@ -1130,9 +1129,9 @@ DIRCACHED* opendir_cached(const char* name) return pdir; } -struct dircache_entry* readdir_cached(DIRCACHED* dir) +struct dircache_entry* readdir_cached(DIR_CACHED* dir) { - struct dirent *regentry; + struct dirent_uncached *regentry; struct dircache_entry *ce; if (!dir->busy) @@ -1140,7 +1139,7 @@ struct dircache_entry* readdir_cached(DIRCACHED* dir) if (dir->regulardir != NULL) { - regentry = readdir(dir->regulardir); + regentry = readdir_uncached(dir->regulardir); if (regentry == NULL) return NULL; @@ -1181,15 +1180,30 @@ struct dircache_entry* readdir_cached(DIRCACHED* dir) return &dir->secondary_entry; } -int closedir_cached(DIRCACHED* dir) +int closedir_cached(DIR_CACHED* dir) { if (!dir->busy) return -1; dir->busy=false; if (dir->regulardir != NULL) - return closedir(dir->regulardir); + return closedir_uncached(dir->regulardir); return 0; } +int mkdir_cached(const char *name) +{ + int rc=mkdir_uncached(name); + if (rc >= 0) + dircache_mkdir(name); + return(rc); +} + +int rmdir_cached(const char* name) +{ + int rc=rmdir_uncached(name); + if(rc>=0) + dircache_rmdir(name); + return(rc); +} 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 @@ #include "fat.h" #ifdef HAVE_HOTSWAP #include "hotswap.h" +#include "dir.h" /* for release_dirs() */ +#include "file.h" /* for release_files() */ #endif -#include "file.h" /* for release_dirs() */ -#include "dir.h" /* for release_files() */ #include "disk.h" /* 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 @@ #include <stdbool.h> #include "file.h" #include "fat.h" -#include "dir.h" +#include "dir_uncached.h" #include "debug.h" #include "dircache.h" #include "system.h" @@ -59,8 +59,8 @@ int creat(const char *pathname) static int open_internal(const char* pathname, int flags, bool use_cache) { - DIR* dir; - struct dirent* entry; + DIR_UNCACHED* dir; + struct dirent_uncached* entry; int fd; char pathnamecopy[MAX_PATH]; char* name; @@ -134,12 +134,12 @@ static int open_internal(const char* pathname, int flags, bool use_cache) name=strrchr(pathnamecopy+1,'/'); if ( name ) { *name = 0; - dir = opendir(pathnamecopy); + dir = opendir_uncached(pathnamecopy); *name = '/'; name++; } else { - dir = opendir("/"); + dir = opendir_uncached("/"); name = pathnamecopy+1; } if (!dir) { @@ -153,12 +153,12 @@ static int open_internal(const char* pathname, int flags, bool use_cache) DEBUGF("Empty file name\n"); errno = EINVAL; file->busy = false; - closedir(dir); + closedir_uncached(dir); return -5; } /* scan dir for name */ - while ((entry = readdir(dir))) { + while ((entry = readdir_uncached(dir))) { if ( !strcasecmp(name, entry->d_name) ) { fat_open(IF_MV2(dir->fatdir.file.volume,) entry->startcluster, @@ -180,7 +180,7 @@ static int open_internal(const char* pathname, int flags, bool use_cache) DEBUGF("Couldn't create %s in %s\n",name,pathnamecopy); errno = EIO; file->busy = false; - closedir(dir); + closedir_uncached(dir); return rc * 10 - 6; } #ifdef HAVE_DIRCACHE @@ -193,18 +193,18 @@ static int open_internal(const char* pathname, int flags, bool use_cache) DEBUGF("Couldn't find %s in %s\n",name,pathnamecopy); errno = ENOENT; file->busy = false; - closedir(dir); + closedir_uncached(dir); return -7; } } else { if(file->write && (file->attr & FAT_ATTR_DIRECTORY)) { errno = EISDIR; file->busy = false; - closedir(dir); + closedir_uncached(dir); return -8; } } - closedir(dir); + closedir_uncached(dir); file->cacheoffset = -1; file->fileoffset = 0; @@ -327,7 +327,7 @@ int remove(const char* name) int rename(const char* path, const char* newpath) { int rc, fd; - DIR* dir; + DIR_UNCACHED* dir; char* nameptr; char* dirptr; struct filedesc* file; @@ -371,7 +371,7 @@ int rename(const char* path, const char* newpath) dirptr = "/"; } - dir = opendir(dirptr); + dir = opendir_uncached(dirptr); if(!dir) return - 5; @@ -401,7 +401,7 @@ int rename(const char* path, const char* newpath) return rc * 10 - 8; } - rc = closedir(dir); + rc = closedir_uncached(dir); if (rc<0) { errno = EIO; 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 @@ * \/ \/ \/ \/ \/ * $Id$ * - * Copyright (C) 2002 by Björn Stenberg + * Copyright (C) 2007 by Kévin Ferrare * * All files in this archive are subject to the GNU General Public License. * See the file COPYING in the source tree root for full license agreement. @@ -16,76 +16,30 @@ * KIND, either express or implied. * ****************************************************************************/ + #ifndef _DIR_H_ #define _DIR_H_ -#include <stdbool.h> -#include "file.h" - -#define ATTR_READ_ONLY 0x01 -#define ATTR_HIDDEN 0x02 -#define ATTR_SYSTEM 0x04 -#define ATTR_VOLUME_ID 0x08 -#define ATTR_DIRECTORY 0x10 -#define ATTR_ARCHIVE 0x20 -#define ATTR_VOLUME 0x40 /* this is a volume, not a real directory */ - -#ifdef SIMULATOR -#define dirent sim_dirent -#define DIR SIM_DIR -#define opendir(x) sim_opendir(x) -#define readdir(x) sim_readdir(x) -#define closedir(x) sim_closedir(x) -#define mkdir(x) sim_mkdir(x) -#define rmdir(x) sim_rmdir(x) -#endif - -#ifndef DIRENT_DEFINED - -struct dirent { - unsigned char d_name[MAX_PATH]; - int attribute; - long size; - long startcluster; - unsigned short wrtdate; /* Last write date */ - unsigned short wrttime; /* Last write time */ -}; -#endif - -#include "fat.h" - -typedef struct { -#ifndef SIMULATOR - bool busy; - long startcluster; - struct fat_dir fatdir; - struct fat_dir parent_dir; - struct dirent theent; -#ifdef HAVE_MULTIVOLUME - int volumecounter; /* running counter for faked volume entries */ -#endif +#ifdef HAVE_DIRCACHE +# include "dircache.h" +# define DIR DIR_CACHED +# define dirent dircache_entry +# define opendir opendir_cached +# define closedir closedir_cached +# define readdir readdir_cached +# define closedir closedir_cached +# define mkdir mkdir_cached +# define rmdir rmdir_cached #else - /* simulator: */ - void *dir; /* actually a DIR* dir */ - char *name; -#endif -} DIR; - -#ifdef HAVE_HOTSWAP -char *get_volume_name(int volume); +#include "dir_uncached.h" +# define DIR DIR_UNCACHED +# define dirent dirent_uncached +# define opendir opendir_uncached +# define closedir closedir_uncached +# define readdir readdir_uncached +# define closedir closedir_uncached +# define mkdir mkdir_uncached +# define rmdir rmdir_uncached #endif -#ifndef DIRFUNCTIONS_DEFINED - -extern DIR* opendir(const char* name); -extern int closedir(DIR* dir); -extern int mkdir(const char* name); -extern int rmdir(const char* name); - -extern struct dirent* readdir(DIR* dir); - -extern int release_dirs(int volume); - -#endif /* DIRFUNCTIONS_DEFINED */ - #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 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: dir.h 13741 2007-06-30 02:08:27Z jethead71 $ + * + * Copyright (C) 2002 by Björn Stenberg + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef _DIR_UNCACHED_H_ +#define _DIR_UNCACHED_H_ + +#include <stdbool.h> +#include "file.h" + +#define ATTR_READ_ONLY 0x01 +#define ATTR_HIDDEN 0x02 +#define ATTR_SYSTEM 0x04 +#define ATTR_VOLUME_ID 0x08 +#define ATTR_DIRECTORY 0x10 +#define ATTR_ARCHIVE 0x20 +#define ATTR_VOLUME 0x40 /* this is a volume, not a real directory */ + +#ifdef SIMULATOR +#define dirent_uncached sim_dirent +#define DIR_UNCACHED SIM_DIR +#define opendir_uncached sim_opendir +#define readdir_uncached sim_readdir +#define closedir_uncached sim_closedir +#define mkdir_uncached sim_mkdir +#define rmdir_uncached sim_rmdir +#endif + +#ifndef DIRENT_DEFINED + +struct dirent_uncached { + unsigned char d_name[MAX_PATH]; + int attribute; + long size; + long startcluster; + unsigned short wrtdate; /* Last write date */ + unsigned short wrttime; /* Last write time */ +}; +#endif + +#include "fat.h" + +typedef struct { +#ifndef SIMULATOR + bool busy; + long startcluster; + struct fat_dir fatdir; + struct fat_dir parent_dir; + struct dirent_uncached theent; +#ifdef HAVE_MULTIVOLUME + int volumecounter; /* running counter for faked volume entries */ +#endif +#else + /* simulator: */ + void *dir; /* actually a DIR* dir */ + char *name; +#endif +} DIR_UNCACHED; + +#ifdef HAVE_HOTSWAP +char *get_volume_name(int volume); +#endif + +#ifndef DIRFUNCTIONS_DEFINED + +extern DIR_UNCACHED* opendir_uncached(const char* name); +extern int closedir_uncached(DIR_UNCACHED* dir); +extern int mkdir_uncached(const char* name); +extern int rmdir_uncached(const char* name); + +extern struct dirent_uncached* readdir_uncached(DIR_UNCACHED* dir); + +extern int release_dirs(int volume); + +#endif /* DIRFUNCTIONS_DEFINED */ + +#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 @@ #ifndef _DIRCACHE_H #define _DIRCACHE_H -#include "dir.h" +#include "dir_uncached.h" #ifdef HAVE_DIRCACHE @@ -34,8 +34,8 @@ struct travel_data { struct dircache_entry *ce; struct dircache_entry *down_entry; #ifdef SIMULATOR - DIR *dir, *newdir; - struct dirent *entry; + DIR_UNCACHED *dir, *newdir; + struct dirent_uncached *entry; #else struct fat_dir *dir; struct fat_dir newdir; @@ -77,8 +77,8 @@ typedef struct { struct dircache_entry *entry; struct dircache_entry *internal_entry; struct dircache_entry secondary_entry; - DIR *regulardir; -} DIRCACHED; + DIR_UNCACHED *regulardir; +} DIR_CACHED; void dircache_init(void); int dircache_load(void); @@ -103,17 +103,11 @@ void dircache_remove(const char *name); void dircache_rename(const char *oldpath, const char *newpath); void dircache_add_file(const char *path, long startcluster); -DIRCACHED* opendir_cached(const char* name); -struct dircache_entry* readdir_cached(DIRCACHED* dir); -int closedir_cached(DIRCACHED *dir); - -#else /* HAVE_DIRCACHE */ -# define DIRCACHED DIR -# define dircache_entry dirent -# define opendir_cached opendir -# define closedir_cached closedir -# define readdir_cached readdir -# define closedir_cached closedir +DIR_CACHED* opendir_cached(const char* name); +struct dircache_entry* readdir_cached(DIR_CACHED* dir); +int closedir_cached(DIR_CACHED *dir); +int mkdir_cached(const char *name); +int rmdir_cached(const char* name); #endif /* !HAVE_DIRCACHE */ #endif |