summaryrefslogtreecommitdiffstats
path: root/firmware/include/dircache.h
blob: 87aaa008a7d40b65c5b51634c5ce5b1f33607b30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2005 by Miika Pekkarinen
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * 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 "config.h"
#include "dir_uncached.h"

#ifdef HAVE_DIRCACHE

#define DIRCACHE_RESERVE  (1024*64)
#define DIRCACHE_LIMIT    (1024*1024*6)

#define DIRCACHE_APPFLAG_TAGCACHE  0x0001

/* Internal structures. */
struct travel_data {
    struct dircache_entry *first;
    struct dircache_entry *ce;
    struct dircache_entry *down_entry;
#if (CONFIG_PLATFORM & PLATFORM_HOSTED)
    DIR_UNCACHED *dir, *newdir;
    struct dirent_uncached *entry;
#else
    struct fat_dir *dir;
    struct fat_dir newdir;
    struct fat_direntry entry;
#endif
    int pathpos;
};

#define DIRCACHE_MAGIC  0x00d0c0a0
struct dircache_maindata {
    long magic;
    long size;
    long entry_count;
    long appflags;
    struct dircache_entry *root_entry;
};

#define MAX_PENDING_BINDINGS 2
struct fdbind_queue {
    char path[MAX_PATH];
    int fd;
};

/* Exported structures. */
struct dircache_entry {
    struct dirinfo info;
    struct dircache_entry *next;
    struct dircache_entry *up;
    struct dircache_entry *down;
    long startcluster;
    unsigned long name_len;
    char *d_name;
};

struct dirent_cached {
    struct dirinfo info;
    char *d_name;
    long startcluster;
};

typedef struct {
    bool busy;
    struct dirent_cached theent; /* .attribute is set to -1 on init(opendir) */
    struct dircache_entry *internal_entry; /* the current entry in the directory */
    DIR_UNCACHED *regulardir;
} DIR_CACHED;

void dircache_init(void) INIT_ATTR;
int dircache_load(void);
int dircache_save(void);
int dircache_build(int last_size);
void* dircache_steal_buffer(long *size);
bool dircache_is_enabled(void);
bool dircache_is_initializing(void);
void dircache_set_appflag(long mask);
bool dircache_get_appflag(long mask);
int dircache_get_entry_count(void);
int dircache_get_cache_size(void);
int dircache_get_reserve_used(void);
int dircache_get_build_ticks(void);
void dircache_disable(void);
const struct dircache_entry *dircache_get_entry_ptr(const char *filename);
void dircache_copy_path(const struct dircache_entry *entry, char *buf, int size);

void dircache_bind(int fd, const char *path);
void dircache_update_filesize(int fd, long newsize, long startcluster);
void dircache_update_filetime(int fd);
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, long startcluster);

DIR_CACHED* opendir_cached(const char* name);
struct dirent_cached* readdir_cached(DIR_CACHED* dir);
int closedir_cached(DIR_CACHED *dir);
int mkdir_cached(const char *name);
int rmdir_cached(const char* name);
#endif /* !HAVE_DIRCACHE */

#endif