1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 by Miika Pekkarinen
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
24 #include "dir_uncached.h"
28 #define DIRCACHE_RESERVE (1024*64)
29 #define DIRCACHE_LIMIT (1024*1024*6)
30 #define DIRCACHE_FILE ROCKBOX_DIR"/dircache.dat"
32 #define DIRCACHE_APPFLAG_TAGCACHE 0x0001
34 /* Internal structures. */
36 struct dircache_entry
*first
;
37 struct dircache_entry
*ce
;
38 struct dircache_entry
*down_entry
;
40 DIR_UNCACHED
*dir
, *newdir
;
41 struct dirent_uncached
*entry
;
44 struct fat_dir newdir
;
45 struct fat_direntry entry
;
50 #define DIRCACHE_MAGIC 0x00d0c0a0
51 struct dircache_maindata
{
56 struct dircache_entry
*root_entry
;
59 #define MAX_PENDING_BINDINGS 2
65 /* Exported structures. */
66 struct dircache_entry
{
67 struct dircache_entry
*next
;
68 struct dircache_entry
*up
;
69 struct dircache_entry
*down
;
73 unsigned short wrtdate
;
74 unsigned short wrttime
;
75 unsigned long name_len
;
79 struct dirent_cached
{
84 unsigned short wrtdate
; /* Last write date */
85 unsigned short wrttime
; /* Last write time */
90 struct dirent_cached theent
; /* .attribute is set to -1 on init(opendir) */
91 struct dircache_entry
*internal_entry
; /* the current entry in the directory */
92 DIR_UNCACHED
*regulardir
;
95 void dircache_init(void) INIT_ATTR
;
96 int dircache_load(void);
97 int dircache_save(void);
98 int dircache_build(int last_size
);
99 void* dircache_steal_buffer(long *size
);
100 bool dircache_is_enabled(void);
101 bool dircache_is_initializing(void);
102 void dircache_set_appflag(long mask
);
103 bool dircache_get_appflag(long mask
);
104 int dircache_get_entry_count(void);
105 int dircache_get_cache_size(void);
106 int dircache_get_reserve_used(void);
107 int dircache_get_build_ticks(void);
108 void dircache_disable(void);
109 const struct dircache_entry
*dircache_get_entry_ptr(const char *filename
);
110 void dircache_copy_path(const struct dircache_entry
*entry
, char *buf
, int size
);
112 void dircache_bind(int fd
, const char *path
);
113 void dircache_update_filesize(int fd
, long newsize
, long startcluster
);
114 void dircache_update_filetime(int fd
);
115 void dircache_mkdir(const char *path
);
116 void dircache_rmdir(const char *path
);
117 void dircache_remove(const char *name
);
118 void dircache_rename(const char *oldpath
, const char *newpath
);
119 void dircache_add_file(const char *path
, long startcluster
);
121 DIR_CACHED
* opendir_cached(const char* name
);
122 struct dirent_cached
* readdir_cached(DIR_CACHED
* dir
);
123 int closedir_cached(DIR_CACHED
*dir
);
124 int mkdir_cached(const char *name
);
125 int rmdir_cached(const char* name
);
126 #endif /* !HAVE_DIRCACHE */