Dircache: Don't expose struct dircache_entry and pointers into the cache, use IDs...
[kugel-rb.git] / firmware / include / dircache.h
blob585bb10fbc711ba4047f90bd43514183bb761cd5
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #ifndef _DIRCACHE_H
22 #define _DIRCACHE_H
24 #include "config.h"
25 #include "dir_uncached.h"
27 #ifdef HAVE_DIRCACHE
29 #define DIRCACHE_RESERVE (1024*64)
30 #define DIRCACHE_LIMIT (1024*1024*6)
32 #define DIRCACHE_APPFLAG_TAGCACHE 0x0001
34 /* Internal structures. */
35 struct travel_data {
36 struct dircache_entry *first;
37 struct dircache_entry *ce;
38 struct dircache_entry *down_entry;
39 #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
40 DIR_UNCACHED *dir, *newdir;
41 struct dirent_uncached *entry;
42 #else
43 struct fat_dir *dir;
44 struct fat_dir newdir;
45 struct fat_direntry entry;
46 #endif
47 int pathpos;
50 struct dirent_cached {
51 struct dirinfo info;
52 char *d_name;
53 long startcluster;
56 typedef struct {
57 bool busy;
58 struct dirent_cached theent; /* .attribute is set to -1 on init(opendir) */
59 int internal_entry; /* the current entry in the directory */
60 DIR_UNCACHED *regulardir;
61 } DIR_CACHED;
63 void dircache_init(void) INIT_ATTR;
64 int dircache_load(void);
65 int dircache_save(void);
66 int dircache_build(int last_size);
67 void* dircache_steal_buffer(long *size);
68 bool dircache_is_enabled(void);
69 bool dircache_is_initializing(void);
70 void dircache_set_appflag(long mask);
71 bool dircache_get_appflag(long mask);
72 int dircache_get_entry_count(void);
73 int dircache_get_cache_size(void);
74 int dircache_get_reserve_used(void);
75 int dircache_get_build_ticks(void);
76 void dircache_disable(void);
77 int dircache_get_entry_id(const char *filename);
78 size_t dircache_copy_path(int index, char *buf, size_t size);
80 /* the next two are internal for file.c */
81 long _dircache_get_entry_startcluster(int id);
82 struct dirinfo* _dircache_get_entry_dirinfo(int id);
84 void dircache_bind(int fd, const char *path);
85 void dircache_update_filesize(int fd, long newsize, long startcluster);
86 void dircache_update_filetime(int fd);
87 void dircache_mkdir(const char *path);
88 void dircache_rmdir(const char *path);
89 void dircache_remove(const char *name);
90 void dircache_rename(const char *oldpath, const char *newpath);
91 void dircache_add_file(const char *path, long startcluster);
93 DIR_CACHED* opendir_cached(const char* name);
94 struct dirent_cached* readdir_cached(DIR_CACHED* dir);
95 int closedir_cached(DIR_CACHED *dir);
96 int mkdir_cached(const char *name);
97 int rmdir_cached(const char* name);
98 #endif /* !HAVE_DIRCACHE */
100 #endif