When setting a cache path also enable the cache implicitly.
[Rockbox.git] / firmware / include / dircache.h
bloba703d0be413569d80f5709df3e0d4bee68a3a111
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 by Miika Pekkarinen
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #ifndef _DIRCACHE_H
20 #define _DIRCACHE_H
22 #include "dir_uncached.h"
24 #ifdef HAVE_DIRCACHE
26 #define DIRCACHE_RESERVE (1024*64)
27 #define DIRCACHE_LIMIT (1024*1024*6)
28 /* FIXME: We should use ROCKBOX_DIR here but it's defined in apps/ */
29 #define DIRCACHE_FILE "/.rockbox/dircache.dat"
31 #define DIRCACHE_APPFLAG_TAGCACHE 0x0001
33 /* Internal structures. */
34 struct travel_data {
35 struct dircache_entry *first;
36 struct dircache_entry *ce;
37 struct dircache_entry *down_entry;
38 #ifdef SIMULATOR
39 DIR_UNCACHED *dir, *newdir;
40 struct dirent_uncached *entry;
41 #else
42 struct fat_dir *dir;
43 struct fat_dir newdir;
44 struct fat_direntry entry;
45 #endif
46 int pathpos;
49 #define DIRCACHE_MAGIC 0x00d0c0a0
50 struct dircache_maindata {
51 long magic;
52 long size;
53 long entry_count;
54 long appflags;
55 struct dircache_entry *root_entry;
58 #define MAX_PENDING_BINDINGS 2
59 struct fdbind_queue {
60 char path[MAX_PATH];
61 int fd;
64 /* Exported structures. */
65 struct dircache_entry {
66 struct dircache_entry *next;
67 struct dircache_entry *up;
68 struct dircache_entry *down;
69 int attribute;
70 long size;
71 long startcluster;
72 unsigned short wrtdate;
73 unsigned short wrttime;
74 unsigned long name_len;
75 char *d_name;
78 typedef struct {
79 bool busy;
80 struct dircache_entry *entry;
81 struct dircache_entry *internal_entry;
82 struct dircache_entry secondary_entry;
83 DIR_UNCACHED *regulardir;
84 } DIR_CACHED;
86 void dircache_init(void);
87 int dircache_load(void);
88 int dircache_save(void);
89 int dircache_build(int last_size);
90 void* dircache_steal_buffer(long *size);
91 bool dircache_is_enabled(void);
92 bool dircache_is_initializing(void);
93 void dircache_set_appflag(long mask);
94 bool dircache_get_appflag(long mask);
95 int dircache_get_entry_count(void);
96 int dircache_get_cache_size(void);
97 int dircache_get_reserve_used(void);
98 int dircache_get_build_ticks(void);
99 void dircache_disable(void);
100 const struct dircache_entry *dircache_get_entry_ptr(const char *filename);
101 void dircache_copy_path(const struct dircache_entry *entry, char *buf, int size);
103 void dircache_bind(int fd, const char *path);
104 void dircache_update_filesize(int fd, long newsize, long startcluster);
105 void dircache_update_filetime(int fd);
106 void dircache_mkdir(const char *path);
107 void dircache_rmdir(const char *path);
108 void dircache_remove(const char *name);
109 void dircache_rename(const char *oldpath, const char *newpath);
110 void dircache_add_file(const char *path, long startcluster);
112 DIR_CACHED* opendir_cached(const char* name);
113 struct dircache_entry* readdir_cached(DIR_CACHED* dir);
114 int closedir_cached(DIR_CACHED *dir);
115 int mkdir_cached(const char *name);
116 int rmdir_cached(const char* name);
117 #endif /* !HAVE_DIRCACHE */
119 #endif