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