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)
31 #define DIRCACHE_APPFLAG_TAGCACHE 0x0001
33 /* Internal structures. */
35 struct dircache_entry
*first
;
36 struct dircache_entry
*ce
;
37 struct dircache_entry
*down_entry
;
38 #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
39 DIR_UNCACHED
*dir
, *newdir
;
40 struct dirent_uncached
*entry
;
43 struct fat_dir newdir
;
44 struct fat_direntry entry
;
49 #define DIRCACHE_MAGIC 0x00d0c0a0
50 struct dircache_maindata
{
55 struct dircache_entry
*root_entry
;
58 #define MAX_PENDING_BINDINGS 2
64 /* Exported structures. */
65 struct dircache_entry
{
66 struct dircache_entry
*next
;
67 struct dircache_entry
*up
;
68 struct dircache_entry
*down
;
72 unsigned short wrtdate
;
73 unsigned short wrttime
;
74 unsigned long name_len
;
78 struct dirent_cached
{
83 unsigned short wrtdate
; /* Last write date */
84 unsigned short wrttime
; /* Last write time */
89 struct dirent_cached theent
; /* .attribute is set to -1 on init(opendir) */
90 struct dircache_entry
*internal_entry
; /* the current entry in the directory */
91 DIR_UNCACHED
*regulardir
;
94 void dircache_init(void) INIT_ATTR
;
95 int dircache_load(void);
96 int dircache_save(void);
97 int dircache_build(int last_size
);
98 void* dircache_steal_buffer(long *size
);
99 bool dircache_is_enabled(void);
100 bool dircache_is_initializing(void);
101 void dircache_set_appflag(long mask
);
102 bool dircache_get_appflag(long mask
);
103 int dircache_get_entry_count(void);
104 int dircache_get_cache_size(void);
105 int dircache_get_reserve_used(void);
106 int dircache_get_build_ticks(void);
107 void dircache_disable(void);
108 const struct dircache_entry
*dircache_get_entry_ptr(const char *filename
);
109 void dircache_copy_path(const struct dircache_entry
*entry
, char *buf
, int size
);
111 void dircache_bind(int fd
, const char *path
);
112 void dircache_update_filesize(int fd
, long newsize
, long startcluster
);
113 void dircache_update_filetime(int fd
);
114 void dircache_mkdir(const char *path
);
115 void dircache_rmdir(const char *path
);
116 void dircache_remove(const char *name
);
117 void dircache_rename(const char *oldpath
, const char *newpath
);
118 void dircache_add_file(const char *path
, long startcluster
);
120 DIR_CACHED
* opendir_cached(const char* name
);
121 struct dirent_cached
* readdir_cached(DIR_CACHED
* dir
);
122 int closedir_cached(DIR_CACHED
*dir
);
123 int mkdir_cached(const char *name
);
124 int rmdir_cached(const char* name
);
125 #endif /* !HAVE_DIRCACHE */