summaryrefslogtreecommitdiff
path: root/include/ntfs-3g/cache.h (plain)
blob: be63b1a4bd7f37907e5f83745fd8500763aa26a5
1/*
2 * cache.h : deal with indexed LRU caches
3 *
4 * Copyright (c) 2008-2010 Jean-Pierre Andre
5 *
6 * This program/include file is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as published
8 * by the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program/include file is distributed in the hope that it will be
12 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program (in the main directory of the NTFS-3G
18 * distribution in the file COPYING); if not, write to the Free Software
19 * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#ifndef _NTFS_CACHE_H_
23#define _NTFS_CACHE_H_
24
25#include "volume.h"
26
27struct CACHED_GENERIC {
28 struct CACHED_GENERIC *next;
29 struct CACHED_GENERIC *previous;
30 void *variable;
31 size_t varsize;
32 union ALIGNMENT payload[0];
33} ;
34
35struct CACHED_INODE {
36 struct CACHED_INODE *next;
37 struct CACHED_INODE *previous;
38 const char *pathname;
39 size_t varsize;
40 union ALIGNMENT payload[0];
41 /* above fields must match "struct CACHED_GENERIC" */
42 u64 inum;
43} ;
44
45struct CACHED_NIDATA {
46 struct CACHED_NIDATA *next;
47 struct CACHED_NIDATA *previous;
48 const char *pathname; /* not used */
49 size_t varsize; /* not used */
50 union ALIGNMENT payload[0];
51 /* above fields must match "struct CACHED_GENERIC" */
52 u64 inum;
53 ntfs_inode *ni;
54} ;
55
56struct CACHED_LOOKUP {
57 struct CACHED_LOOKUP *next;
58 struct CACHED_LOOKUP *previous;
59 const char *name;
60 size_t namesize;
61 union ALIGNMENT payload[0];
62 /* above fields must match "struct CACHED_GENERIC" */
63 u64 parent;
64 u64 inum;
65} ;
66
67enum {
68 CACHE_FREE = 1,
69 CACHE_NOHASH = 2
70} ;
71
72typedef int (*cache_compare)(const struct CACHED_GENERIC *cached,
73 const struct CACHED_GENERIC *item);
74typedef void (*cache_free)(const struct CACHED_GENERIC *cached);
75typedef int (*cache_hash)(const struct CACHED_GENERIC *cached);
76
77struct HASH_ENTRY {
78 struct HASH_ENTRY *next;
79 struct CACHED_GENERIC *entry;
80} ;
81
82struct CACHE_HEADER {
83 const char *name;
84 struct CACHED_GENERIC *most_recent_entry;
85 struct CACHED_GENERIC *oldest_entry;
86 struct CACHED_GENERIC *free_entry;
87 struct HASH_ENTRY *free_hash;
88 struct HASH_ENTRY **first_hash;
89 cache_free dofree;
90 cache_hash dohash;
91 unsigned long reads;
92 unsigned long writes;
93 unsigned long hits;
94 int fixed_size;
95 int max_hash;
96 struct CACHED_GENERIC entry[0];
97} ;
98
99 /* cast to generic, avoiding gcc warnings */
100#define GENERIC(pstr) ((const struct CACHED_GENERIC*)(const void*)(pstr))
101
102struct CACHED_GENERIC *ntfs_fetch_cache(struct CACHE_HEADER *cache,
103 const struct CACHED_GENERIC *wanted,
104 cache_compare compare);
105struct CACHED_GENERIC *ntfs_enter_cache(struct CACHE_HEADER *cache,
106 const struct CACHED_GENERIC *item,
107 cache_compare compare);
108int ntfs_invalidate_cache(struct CACHE_HEADER *cache,
109 const struct CACHED_GENERIC *item,
110 cache_compare compare, int flags);
111int ntfs_remove_cache(struct CACHE_HEADER *cache,
112 struct CACHED_GENERIC *item, int flags);
113
114void ntfs_create_lru_caches(ntfs_volume *vol);
115void ntfs_free_lru_caches(ntfs_volume *vol);
116
117#endif /* _NTFS_CACHE_H_ */
118
119