Lines Matching refs:cache
2 * cache.c : deal with LRU caches
35 #include "cache.h"
48 * in the cache. Another function may be provided for invalidating
63 static void inserthashindex(struct CACHE_HEADER *cache,
70 if (cache->dohash) {
71 h = cache->dohash(current);
72 if ((h >= 0) && (h < cache->max_hash)) {
74 link = cache->free_hash;
76 cache->free_hash = link->next;
77 first = cache->first_hash[h];
83 cache->first_hash[h] = link;
86 " cache %s hashing dropped\n",
87 cache->name);
88 cache->dohash = (cache_hash)NULL;
92 " cache %s hashing dropped\n",
93 cache->name);
94 cache->dohash = (cache_hash)NULL;
103 static void drophashindex(struct CACHE_HEADER *cache,
109 if (cache->dohash) {
110 if ((hash >= 0) && (hash < cache->max_hash)) {
112 link = cache->first_hash[hash];
122 cache->first_hash[hash] = link->next;
123 link->next = cache->free_hash;
124 cache->free_hash = link;
127 " cache %s hashing dropped\n",
128 cache->name);
129 cache->dohash = (cache_hash)NULL;
133 " cache %s hashing dropped\n",
134 cache->name);
135 cache->dohash = (cache_hash)NULL;
141 * Fetch an entry from cache
143 * returns the cache entry, or NULL if not available
147 struct CACHED_GENERIC *ntfs_fetch_cache(struct CACHE_HEADER *cache,
156 if (cache) {
157 if (cache->dohash) {
162 h = cache->dohash(wanted);
163 link = cache->first_hash[h];
169 if (!cache->dohash) {
174 current = cache->most_recent_entry;
182 cache->hits++;
193 cache->oldest_entry
195 current->next = cache->most_recent_entry;
198 cache->most_recent_entry->previous = current;
199 cache->most_recent_entry = current;
202 cache->reads++;
208 * Enter an inode number into cache
209 * returns the cache entry or NULL if not possible
212 struct CACHED_GENERIC *ntfs_enter_cache(struct CACHE_HEADER *cache,
222 if (cache) {
223 if (cache->dohash) {
228 h = cache->dohash(item);
229 link = cache->first_hash[h];
236 if (!cache->dohash) {
243 current = cache->most_recent_entry;
259 if (cache->free_entry) {
260 current = cache->free_entry;
261 cache->free_entry = cache->free_entry->next;
268 if (!cache->oldest_entry)
269 cache->oldest_entry = current;
272 current = cache->oldest_entry;
275 if (cache->dohash)
276 drophashindex(cache,current,
277 cache->dohash(current));
278 if (cache->dofree)
279 cache->dofree(current);
280 cache->oldest_entry = current->previous;
296 current->next = cache->most_recent_entry;
298 if (cache->most_recent_entry)
299 cache->most_recent_entry->previous = current;
300 cache->most_recent_entry = current;
301 memcpy(current->payload, item->payload, cache->fixed_size);
312 cache->most_recent_entry = current->next;
313 current->next = cache->free_entry;
314 cache->free_entry = current;
321 if (cache->dohash && current)
322 inserthashindex(cache,current);
324 cache->writes++;
330 * Invalidate a cache entry
335 static void do_invalidate(struct CACHE_HEADER *cache,
341 if ((flags & CACHE_FREE) && cache->dofree)
342 cache->dofree(current);
349 cache->oldest_entry = current->previous;
353 cache->most_recent_entry = current->next;
354 current->next = cache->free_entry;
355 cache->free_entry = current;
363 * Invalidate entries in cache
370 * the caller to signal a cache corruption if the entry was
374 int ntfs_invalidate_cache(struct CACHE_HEADER *cache,
386 if (cache) {
387 if (!(flags & CACHE_NOHASH) && cache->dohash) {
392 h = cache->dohash(item);
393 link = cache->first_hash[h];
401 drophashindex(cache,current,h);
402 do_invalidate(cache,
409 if ((flags & CACHE_NOHASH) || !cache->dohash) {
413 current = cache->most_recent_entry;
417 if (cache->dohash)
418 drophashindex(cache,current,
419 cache->dohash(current));
420 do_invalidate(cache,current,flags);
432 int ntfs_remove_cache(struct CACHE_HEADER *cache,
438 if (cache) {
439 if (cache->dohash)
440 drophashindex(cache,item,cache->dohash(item));
441 do_invalidate(cache,item,flags);
448 * Free memory allocated to a cache
451 static void ntfs_free_cache(struct CACHE_HEADER *cache)
455 if (cache) {
456 for (entry=cache->most_recent_entry; entry; entry=entry->next) {
457 if (cache->dofree)
458 cache->dofree(entry);
462 free(cache);
467 * Create a cache
469 * Returns the cache header, or NULL if the cache could not be created
477 struct CACHE_HEADER *cache;
490 cache = (struct CACHE_HEADER*)ntfs_malloc(size);
491 if (cache) {
493 cache->name = name;
494 cache->dofree = dofree;
496 cache->dohash = dohash;
497 cache->max_hash = max_hash;
499 cache->dohash = (cache_hash)NULL;
500 cache->max_hash = 0;
502 cache->fixed_size = full_item_size - sizeof(struct CACHED_GENERIC);
503 cache->reads = 0;
504 cache->writes = 0;
505 cache->hits = 0;
507 cache->most_recent_entry = (struct CACHED_GENERIC*)NULL;
508 cache->oldest_entry = (struct CACHED_GENERIC*)NULL;
509 cache->free_entry = &cache->entry[0];
510 pc = &cache->entry[0];
527 cache->free_hash = ph;
539 cache->first_hash = px;
543 cache->free_hash = (struct HASH_ENTRY*)NULL;
544 cache->first_hash = (struct HASH_ENTRY**)NULL;
547 return (cache);
560 /* inode cache */
566 /* idata cache */
573 /* lookup cache */