Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / fs / fat / cache.h
blobdaf1a489114ab5a3848b7a02740a9a3d6226464a
1 /*
2 * Disk buffer cache
4 * Copyright © 2007 Robert Norris
5 * Copyright © 2008 Pavel Fedin
7 * This program is free software; you can redistribute it and/or modify it
8 * under the same terms as AROS itself.
10 * $Id$
13 #ifndef CACHE_H
14 #define CACHE_H 1
16 #include <exec/types.h>
17 #include <exec/io.h>
19 struct cache_block {
20 struct cache_block *hash_next; /* next block in this hash bucket */
21 struct cache_block *hash_prev; /* previous block in this hash bucket */
23 struct cache_block *free_next; /* next block on free list */
24 struct cache_block *free_prev; /* previous block on free list */
26 struct cache_block *dirty_next; /* next block on dirty list */
28 ULONG use_count; /* number of users of this block */
29 BOOL is_dirty; /* does the block need to be written? */
31 ULONG num; /* block number */
33 UBYTE *data; /* actual block data */
36 struct cache {
37 ULONG hash_size; /* size of hash table */
38 ULONG hash_mask; /* mask applied to block number to find correct hash bucket */
40 ULONG num_blocks; /* number of blocks allocated */
41 ULONG block_size; /* size of block */
43 ULONG flags; /* cache options */
45 struct cache_block **blocks; /* big list of all the blocks */
46 ULONG num_in_use; /* number of blocks currently in use (ie not on the free list) */
48 struct cache_block **hash; /* the hash table itself */
50 struct cache_block *free_head; /* first block in the free list */
51 struct cache_block *free_tail; /* last block in the free list */
53 struct cache_block *dirty; /* list of dirty blocks */
55 ULONG hits; /* number of hits, for stats */
56 ULONG misses; /* number of misses */
59 /* flags for cache_new */
60 #define CACHE_WRITETHROUGH (1<<0) /* write immediately */
61 #define CACHE_WRITEBACK (1<<1) /* defer writes */
63 struct cache *cache_new(ULONG hash_size, ULONG num_blocks, ULONG block_size, ULONG flags);
64 void cache_free(struct cache *c);
66 ULONG cache_get_block(struct cache *c, ULONG num, ULONG flags, struct cache_block **rb);
67 ULONG cache_put_block(struct cache *c, struct cache_block *b, ULONG flags);
69 ULONG cache_get_blocks(struct cache *c, ULONG num, ULONG nblocks, ULONG flags, struct cache_block **rb);
70 ULONG cache_put_blocks(struct cache *c, struct cache_block **b, ULONG nblocks, ULONG flags);
72 ULONG cache_mark_block_dirty(struct cache *c, struct cache_block *b);
73 ULONG cache_mark_blocks_dirty(struct cache *c, struct cache_block **b, ULONG nblocks);
75 ULONG cache_flush(struct cache *c);
77 void cache_stats(struct cache *c);
79 #endif