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.
15 #include <exec/types.h>
16 #include <exec/devices.h>
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 */
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
);