diff options
author | Miika Pekkarinen <miipekk@ihme.org> | 2005-10-07 17:38:05 +0000 |
---|---|---|
committer | Miika Pekkarinen <miipekk@ihme.org> | 2005-10-07 17:38:05 +0000 |
commit | ab78b0468088e9011273edc32d59145db9030a7e (patch) | |
tree | 5dc785c1f3eec456592b210d1aad39b6f5cf6880 /firmware/include | |
parent | 86e31d5558704b8ab83d2e5d5c9dca691a5f768a (diff) |
Implemented directory caching. No more waiting for disk to spin up while
browsing when cache is enabled (system -> disk -> enable directory
cache). Cache building on boot is transparent except the first boot.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7588 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/include')
-rw-r--r-- | firmware/include/dircache.h | 96 | ||||
-rw-r--r-- | firmware/include/file.h | 2 |
2 files changed, 98 insertions, 0 deletions
diff --git a/firmware/include/dircache.h b/firmware/include/dircache.h new file mode 100644 index 0000000000..48b74e0220 --- /dev/null +++ b/firmware/include/dircache.h @@ -0,0 +1,96 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2005 by Miika Pekkarinen + * + * 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 _DIRCACHE_H +#define _DIRCACHE_H + +#include "dir.h" + +#ifdef HAVE_DIRCACHE + +#define DIRCACHE_RESERVE (1024*64) +#define DIRCACHE_LIMIT (1024*1024*2) +#define DIRCACHE_FILE ROCKBOX_DIR "/dircache.dat" + +/* Internal structures. */ +struct travel_data { + struct dircache_entry *ce; + struct dircache_entry *down_entry; + struct fat_dir *dir; + struct fat_dir newdir; + struct fat_direntry entry; + int pathpos; +}; + +#define DIRCACHE_MAGIC 0x00d0c0a0 +struct dircache_maindata { + long magic; + long size; + struct dircache_entry *root_entry; +}; + +/* Exported structures. */ +struct dircache_entry { + struct dircache_entry *next; + struct dircache_entry *down; + int attribute; + long size; + long startcluster; + unsigned short wrtdate; + unsigned short wrttime; + unsigned char name_len; + char *d_name; +}; + +typedef struct { + bool busy; + struct dircache_entry *entry; + struct dircache_entry secondary_entry; + DIR *regulardir; +} DIRCACHED; + +void dircache_init(void); +int dircache_load(const char *path); +int dircache_save(const char *path); +int dircache_build(int last_size); +bool dircache_is_enabled(void); +int dircache_get_cache_size(void); +void dircache_disable(void); + +void dircache_bind(int fd, const char *path); +void dircache_update_filesize(int fd, long newsize); +void dircache_mkdir(const char *path); +void dircache_rmdir(const char *path); +void dircache_remove(const char *name); +void dircache_rename(const char *oldpath, const char *newpath); +void dircache_add_file(const char *path); + +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 +#endif /* !HAVE_DIRCACHE */ + +#endif diff --git a/firmware/include/file.h b/firmware/include/file.h index d497ede23c..3db6507290 100644 --- a/firmware/include/file.h +++ b/firmware/include/file.h @@ -25,6 +25,8 @@ #undef MAX_PATH /* this avoids problems when building simulator */ #define MAX_PATH 260 +#define MAX_OPEN_FILES 8 + #ifndef SEEK_SET #define SEEK_SET 0 #endif |