2 * cache.h : deal with indexed LRU caches
4 * Copyright (c) 2008-2010 Jean-Pierre Andre
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.
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.
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
22 #ifndef _NTFS_CACHE_H_
23 #define _NTFS_CACHE_H_
27 struct CACHED_GENERIC
{
28 struct CACHED_GENERIC
*next
;
29 struct CACHED_GENERIC
*previous
;
32 union ALIGNMENT payload
[0];
36 struct CACHED_INODE
*next
;
37 struct CACHED_INODE
*previous
;
40 union ALIGNMENT payload
[0];
41 /* above fields must match "struct CACHED_GENERIC" */
45 struct 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" */
56 struct CACHED_LOOKUP
{
57 struct CACHED_LOOKUP
*next
;
58 struct CACHED_LOOKUP
*previous
;
61 union ALIGNMENT payload
[0];
62 /* above fields must match "struct CACHED_GENERIC" */
72 typedef int (*cache_compare
)(const struct CACHED_GENERIC
*cached
,
73 const struct CACHED_GENERIC
*item
);
74 typedef void (*cache_free
)(const struct CACHED_GENERIC
*cached
);
75 typedef int (*cache_hash
)(const struct CACHED_GENERIC
*cached
);
78 struct HASH_ENTRY
*next
;
79 struct CACHED_GENERIC
*entry
;
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
;
96 struct CACHED_GENERIC entry
[0];
99 /* cast to generic, avoiding gcc warnings */
100 #define GENERIC(pstr) ((const struct CACHED_GENERIC*)(const void*)(pstr))
102 struct CACHED_GENERIC
*ntfs_fetch_cache(struct CACHE_HEADER
*cache
,
103 const struct CACHED_GENERIC
*wanted
,
104 cache_compare compare
);
105 struct CACHED_GENERIC
*ntfs_enter_cache(struct CACHE_HEADER
*cache
,
106 const struct CACHED_GENERIC
*item
,
107 cache_compare compare
);
108 int ntfs_invalidate_cache(struct CACHE_HEADER
*cache
,
109 const struct CACHED_GENERIC
*item
,
110 cache_compare compare
, int flags
);
111 int ntfs_remove_cache(struct CACHE_HEADER
*cache
,
112 struct CACHED_GENERIC
*item
, int flags
);
114 void ntfs_create_lru_caches(ntfs_volume
*vol
);
115 void ntfs_free_lru_caches(ntfs_volume
*vol
);
117 #endif /* _NTFS_CACHE_H_ */