blob: 67c332518bfd60911251795587580a6f850b337a
1 | /* |
2 | * cache.h : deal with indexed LRU caches |
3 | * |
4 | * Copyright (c) 2008-2009 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 | |
27 | struct CACHED_GENERIC { |
28 | struct CACHED_GENERIC *next; |
29 | struct CACHED_GENERIC *previous; |
30 | void *variable; |
31 | size_t varsize; |
32 | void *fixed[0]; |
33 | } ; |
34 | |
35 | struct CACHED_INODE { |
36 | struct CACHED_INODE *next; |
37 | struct CACHED_INODE *previous; |
38 | const char *pathname; |
39 | size_t varsize; |
40 | /* above fields must match "struct CACHED_GENERIC" */ |
41 | u64 inum; |
42 | } ; |
43 | |
44 | struct CACHED_NIDATA { |
45 | struct CACHED_NIDATA *next; |
46 | struct CACHED_NIDATA *previous; |
47 | const char *pathname; /* not used */ |
48 | size_t varsize; /* not used */ |
49 | /* above fields must match "struct CACHED_GENERIC" */ |
50 | u64 inum; |
51 | ntfs_inode *ni; |
52 | } ; |
53 | |
54 | struct CACHED_LOOKUP { |
55 | struct CACHED_LOOKUP *next; |
56 | struct CACHED_LOOKUP *previous; |
57 | const char *name; |
58 | size_t namesize; |
59 | /* above fields must match "struct CACHED_GENERIC" */ |
60 | u64 parent; |
61 | u64 inum; |
62 | } ; |
63 | |
64 | enum { |
65 | CACHE_FREE = 1, |
66 | CACHE_NOHASH = 2 |
67 | } ; |
68 | |
69 | typedef int (*cache_compare)(const struct CACHED_GENERIC *cached, |
70 | const struct CACHED_GENERIC *item); |
71 | typedef void (*cache_free)(const struct CACHED_GENERIC *cached); |
72 | typedef int (*cache_hash)(const struct CACHED_GENERIC *cached); |
73 | |
74 | struct HASH_ENTRY { |
75 | struct HASH_ENTRY *next; |
76 | struct CACHED_GENERIC *entry; |
77 | } ; |
78 | |
79 | struct CACHE_HEADER { |
80 | const char *name; |
81 | struct CACHED_GENERIC *most_recent_entry; |
82 | struct CACHED_GENERIC *oldest_entry; |
83 | struct CACHED_GENERIC *free_entry; |
84 | struct HASH_ENTRY *free_hash; |
85 | struct HASH_ENTRY **first_hash; |
86 | cache_free dofree; |
87 | cache_hash dohash; |
88 | unsigned long reads; |
89 | unsigned long writes; |
90 | unsigned long hits; |
91 | int fixed_size; |
92 | int max_hash; |
93 | struct CACHED_GENERIC entry[0]; |
94 | } ; |
95 | |
96 | /* cast to generic, avoiding gcc warnings */ |
97 | #define GENERIC(pstr) ((const struct CACHED_GENERIC*)(const void*)(pstr)) |
98 | |
99 | struct CACHED_GENERIC *ntfs_fetch_cache(struct CACHE_HEADER *cache, |
100 | const struct CACHED_GENERIC *wanted, |
101 | cache_compare compare); |
102 | struct CACHED_GENERIC *ntfs_enter_cache(struct CACHE_HEADER *cache, |
103 | const struct CACHED_GENERIC *item, |
104 | cache_compare compare); |
105 | int ntfs_invalidate_cache(struct CACHE_HEADER *cache, |
106 | const struct CACHED_GENERIC *item, |
107 | cache_compare compare, int flags); |
108 | int ntfs_remove_cache(struct CACHE_HEADER *cache, |
109 | struct CACHED_GENERIC *item, int flags); |
110 | |
111 | void ntfs_create_lru_caches(ntfs_volume *vol); |
112 | void ntfs_free_lru_caches(ntfs_volume *vol); |
113 | |
114 | #endif /* _NTFS_CACHE_H_ */ |
115 | |
116 |