xref: /haiku/src/add-ons/kernel/file_systems/ntfs/libntfs/cache.h (revision 25a7b01d15612846f332751841da3579db313082)
10d2c294fSGerasim Troeglazov /*
20d2c294fSGerasim Troeglazov  * cache.h : deal with indexed LRU caches
30d2c294fSGerasim Troeglazov  *
4*a814d850Sthreedeyes  * Copyright (c) 2008-2010 Jean-Pierre Andre
50d2c294fSGerasim Troeglazov  *
60d2c294fSGerasim Troeglazov  * This program/include file is free software; you can redistribute it and/or
70d2c294fSGerasim Troeglazov  * modify it under the terms of the GNU General Public License as published
80d2c294fSGerasim Troeglazov  * by the Free Software Foundation; either version 2 of the License, or
90d2c294fSGerasim Troeglazov  * (at your option) any later version.
100d2c294fSGerasim Troeglazov  *
110d2c294fSGerasim Troeglazov  * This program/include file is distributed in the hope that it will be
120d2c294fSGerasim Troeglazov  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
130d2c294fSGerasim Troeglazov  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
140d2c294fSGerasim Troeglazov  * GNU General Public License for more details.
150d2c294fSGerasim Troeglazov  *
160d2c294fSGerasim Troeglazov  * You should have received a copy of the GNU General Public License
170d2c294fSGerasim Troeglazov  * along with this program (in the main directory of the NTFS-3G
180d2c294fSGerasim Troeglazov  * distribution in the file COPYING); if not, write to the Free Software
190d2c294fSGerasim Troeglazov  * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
200d2c294fSGerasim Troeglazov  */
210d2c294fSGerasim Troeglazov 
220d2c294fSGerasim Troeglazov #ifndef _NTFS_CACHE_H_
230d2c294fSGerasim Troeglazov #define _NTFS_CACHE_H_
240d2c294fSGerasim Troeglazov 
250d2c294fSGerasim Troeglazov #include "volume.h"
260d2c294fSGerasim Troeglazov 
270d2c294fSGerasim Troeglazov struct CACHED_GENERIC {
280d2c294fSGerasim Troeglazov 	struct CACHED_GENERIC *next;
290d2c294fSGerasim Troeglazov 	struct CACHED_GENERIC *previous;
300d2c294fSGerasim Troeglazov 	void *variable;
310d2c294fSGerasim Troeglazov 	size_t varsize;
32*a814d850Sthreedeyes 	union ALIGNMENT payload[0];
330d2c294fSGerasim Troeglazov } ;
340d2c294fSGerasim Troeglazov 
350d2c294fSGerasim Troeglazov struct CACHED_INODE {
360d2c294fSGerasim Troeglazov 	struct CACHED_INODE *next;
370d2c294fSGerasim Troeglazov 	struct CACHED_INODE *previous;
380d2c294fSGerasim Troeglazov 	const char *pathname;
390d2c294fSGerasim Troeglazov 	size_t varsize;
40*a814d850Sthreedeyes 	union ALIGNMENT payload[0];
410d2c294fSGerasim Troeglazov 		/* above fields must match "struct CACHED_GENERIC" */
420d2c294fSGerasim Troeglazov 	u64 inum;
430d2c294fSGerasim Troeglazov } ;
440d2c294fSGerasim Troeglazov 
450d2c294fSGerasim Troeglazov struct CACHED_NIDATA {
460d2c294fSGerasim Troeglazov 	struct CACHED_NIDATA *next;
470d2c294fSGerasim Troeglazov 	struct CACHED_NIDATA *previous;
480d2c294fSGerasim Troeglazov 	const char *pathname;	/* not used */
490d2c294fSGerasim Troeglazov 	size_t varsize;		/* not used */
50*a814d850Sthreedeyes 	union ALIGNMENT payload[0];
510d2c294fSGerasim Troeglazov 		/* above fields must match "struct CACHED_GENERIC" */
520d2c294fSGerasim Troeglazov 	u64 inum;
530d2c294fSGerasim Troeglazov 	ntfs_inode *ni;
540d2c294fSGerasim Troeglazov } ;
550d2c294fSGerasim Troeglazov 
560d2c294fSGerasim Troeglazov struct CACHED_LOOKUP {
570d2c294fSGerasim Troeglazov 	struct CACHED_LOOKUP *next;
580d2c294fSGerasim Troeglazov 	struct CACHED_LOOKUP *previous;
590d2c294fSGerasim Troeglazov 	const char *name;
600d2c294fSGerasim Troeglazov 	size_t namesize;
61*a814d850Sthreedeyes 	union ALIGNMENT payload[0];
620d2c294fSGerasim Troeglazov 		/* above fields must match "struct CACHED_GENERIC" */
630d2c294fSGerasim Troeglazov 	u64 parent;
640d2c294fSGerasim Troeglazov 	u64 inum;
650d2c294fSGerasim Troeglazov } ;
660d2c294fSGerasim Troeglazov 
670d2c294fSGerasim Troeglazov enum {
680d2c294fSGerasim Troeglazov 	CACHE_FREE = 1,
690d2c294fSGerasim Troeglazov 	CACHE_NOHASH = 2
700d2c294fSGerasim Troeglazov } ;
710d2c294fSGerasim Troeglazov 
720d2c294fSGerasim Troeglazov typedef int (*cache_compare)(const struct CACHED_GENERIC *cached,
730d2c294fSGerasim Troeglazov 				const struct CACHED_GENERIC *item);
740d2c294fSGerasim Troeglazov typedef void (*cache_free)(const struct CACHED_GENERIC *cached);
750d2c294fSGerasim Troeglazov typedef int (*cache_hash)(const struct CACHED_GENERIC *cached);
760d2c294fSGerasim Troeglazov 
770d2c294fSGerasim Troeglazov struct HASH_ENTRY {
780d2c294fSGerasim Troeglazov 	struct HASH_ENTRY *next;
790d2c294fSGerasim Troeglazov 	struct CACHED_GENERIC *entry;
800d2c294fSGerasim Troeglazov } ;
810d2c294fSGerasim Troeglazov 
820d2c294fSGerasim Troeglazov struct CACHE_HEADER {
830d2c294fSGerasim Troeglazov 	const char *name;
840d2c294fSGerasim Troeglazov 	struct CACHED_GENERIC *most_recent_entry;
850d2c294fSGerasim Troeglazov 	struct CACHED_GENERIC *oldest_entry;
860d2c294fSGerasim Troeglazov 	struct CACHED_GENERIC *free_entry;
870d2c294fSGerasim Troeglazov 	struct HASH_ENTRY *free_hash;
880d2c294fSGerasim Troeglazov 	struct HASH_ENTRY **first_hash;
890d2c294fSGerasim Troeglazov 	cache_free dofree;
900d2c294fSGerasim Troeglazov 	cache_hash dohash;
910d2c294fSGerasim Troeglazov 	unsigned long reads;
920d2c294fSGerasim Troeglazov 	unsigned long writes;
930d2c294fSGerasim Troeglazov 	unsigned long hits;
940d2c294fSGerasim Troeglazov 	int fixed_size;
950d2c294fSGerasim Troeglazov 	int max_hash;
960d2c294fSGerasim Troeglazov 	struct CACHED_GENERIC entry[0];
970d2c294fSGerasim Troeglazov } ;
980d2c294fSGerasim Troeglazov 
990d2c294fSGerasim Troeglazov 	/* cast to generic, avoiding gcc warnings */
1000d2c294fSGerasim Troeglazov #define GENERIC(pstr) ((const struct CACHED_GENERIC*)(const void*)(pstr))
1010d2c294fSGerasim Troeglazov 
1020d2c294fSGerasim Troeglazov struct CACHED_GENERIC *ntfs_fetch_cache(struct CACHE_HEADER *cache,
1030d2c294fSGerasim Troeglazov 			const struct CACHED_GENERIC *wanted,
1040d2c294fSGerasim Troeglazov 			cache_compare compare);
1050d2c294fSGerasim Troeglazov struct CACHED_GENERIC *ntfs_enter_cache(struct CACHE_HEADER *cache,
1060d2c294fSGerasim Troeglazov 			const struct CACHED_GENERIC *item,
1070d2c294fSGerasim Troeglazov 			cache_compare compare);
1080d2c294fSGerasim Troeglazov int ntfs_invalidate_cache(struct CACHE_HEADER *cache,
1090d2c294fSGerasim Troeglazov 			const struct CACHED_GENERIC *item,
1100d2c294fSGerasim Troeglazov 			cache_compare compare, int flags);
1110d2c294fSGerasim Troeglazov int ntfs_remove_cache(struct CACHE_HEADER *cache,
1120d2c294fSGerasim Troeglazov 			struct CACHED_GENERIC *item, int flags);
1130d2c294fSGerasim Troeglazov 
1140d2c294fSGerasim Troeglazov void ntfs_create_lru_caches(ntfs_volume *vol);
1150d2c294fSGerasim Troeglazov void ntfs_free_lru_caches(ntfs_volume *vol);
1160d2c294fSGerasim Troeglazov 
1170d2c294fSGerasim Troeglazov #endif /* _NTFS_CACHE_H_ */
1180d2c294fSGerasim Troeglazov 
119