r25972@plastic: rob | 2007-04-15 01:04:52 +1000
[cake.git] / workbench / fs / fat / cache.h
blob582fa42a328240ab6a236d51719c5bec902e23b9
1 /*
2 * Disk buffer cache
4 * Copyright © 2007 Robert Norris
6 * This program is free software; you can redistribute it and/or modify it
7 * under the same terms as AROS itself.
9 * $Id$
12 #ifndef CACHE_H
13 #define CACHE_H 1
15 #include <exec/types.h>
16 #include <exec/devices.h>
18 struct cache_block {
19 struct cache_block *hash_next; /* next block in this hash bucket */
20 struct cache_block *hash_prev; /* previous block in this hash bucket */
22 struct cache_block *free_next; /* next block on free list */
23 struct cache_block *free_prev; /* previous block on free list */
25 ULONG use_count; /* number of users of this block */
26 BOOL is_dirty; /* does the block need to be written? */
28 struct Device *device; /* device this block was loaded from */
29 struct Unit *unit; /* unit of aforementioned device */
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 block_size; /* size of block */
42 ULONG flags; /* cache options */
44 struct cache_block **blocks; /* big list of all the blocks */
45 ULONG num_blocks; /* number of blocks in the list */
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 */
54 struct cache *cache_new(ULONG hash_size, ULONG num_blocks, ULONG block_size, ULONG flags);
55 void cache_free(struct cache *c);
57 ULONG cache_get_block(struct cache *c, struct Device *dev, struct Unit *unit, ULONG num, ULONG flags, struct cache_block **rb);
58 ULONG cache_put_block(struct cache *c, struct cache_block *b, ULONG flags);
60 ULONG cache_get_blocks(struct cache *c, struct Device *dev, struct Unit *unit, ULONG num, ULONG nblocks, ULONG flags, struct cache_block **rb);
61 ULONG cache_put_blocks(struct cache *c, struct cache_block **b, ULONG nblocks, ULONG flags);
63 ULONG cache_mark_block_dirty(struct cache *c, struct cache_block *b);
64 ULONG cache_mark_blocks_dirty(struct cache *c, struct cache_block **b, ULONG nblocks);
66 #endif