1 /*- 2 * Copyright (c) 1990 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Mike Olson. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11 /* 12 * @(#)lrucache.h 5.1 (Berkeley) 01/23/91 13 */ 14 15 /* 16 * LRU list entries. The head of the list is the most-recently requested 17 * block; the tail is the least-recently requested one. 18 */ 19 20 typedef struct LRU_ENT { 21 char *l_buffer; /* buffer we return to user */ 22 int l_pgno; /* logical page number */ 23 int l_flags; /* FREE and DIRTY bits */ 24 struct LRU_ENT *l_prev; /* predecessor in LRU list */ 25 struct LRU_ENT *l_next; /* successor in LRU list */ 26 } LRU_ENT; 27 28 /* 29 * Cache entries. We use a hash table to avoid a linear walk of the LRU 30 * list when we need to look up blocks by number. The hash table is 31 * chained. 32 */ 33 34 typedef struct CACHE_ENT { 35 int c_pgno; 36 LRU_ENT *c_lruent; 37 struct CACHE_ENT *c_chain; 38 } CACHE_ENT; 39 40 /* 41 * The LRU cache structure. The cache size (lru_csize) is the largest size 42 * the user wants us to grow to; current size (lru_cursz) is always less than 43 * or equal to lru_csize. Note that we will grow the cache (lru_csize) if 44 * it's the only way that we can satisfy a user's block request. 45 */ 46 47 typedef struct LRUCACHE { 48 int lru_fd; 49 int lru_csize; 50 int lru_psize; 51 int lru_cursz; 52 char *lru_opaque; /* passed to inproc, outproc */ 53 int (*lru_inproc)(); 54 int (*lru_outproc)(); 55 LRU_ENT *lru_head; 56 LRU_ENT *lru_tail; 57 CACHE_ENT **lru_cache; 58 } LRUCACHE; 59 60 #ifndef NULL 61 #define NULL 0 62 #endif /* ndef NULL */ 63 64 /* this is the opaque type we return for LRU caches */ 65 typedef char *LRU; 66 67 /* bits for l_flags in LRU_ENT structure */ 68 #define F_DIRTY (1 << 0) 69 #define F_FREE (1 << 1) 70 71 /* lru module routines */ 72 extern CACHE_ENT *lruhashget(); 73 extern CACHE_ENT *lruhashput(); 74 extern int lruhashdel(); 75 extern void lruhead(); 76 extern int lrugrow(); 77 extern LRU lruinit(); 78 extern int lruwrite(); 79 extern int lrusync(); 80 extern char *lruget(); 81 extern char *lrugetnew(); 82 extern char *lrugetpg(); 83 extern int lrurelease(); 84 extern void lrufree(); 85