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>
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 struct cache_block
*dirty_next
; /* next block on dirty list */
27 ULONG use_count
; /* number of users of this block */
28 BOOL is_dirty
; /* does the block need to be written? */
30 ULONG num
; /* block number */
32 UBYTE
*data
; /* actual block data */
36 struct IOStdReq
*req
; /* io request for disk access. this hold the device and unit pointers */
38 ULONG hash_size
; /* size of hash table */
39 ULONG hash_mask
; /* mask applied to block number to find correct hash bucket */
41 ULONG num_blocks
; /* number of blocks allocated */
42 ULONG block_size
; /* size of block */
44 ULONG flags
; /* cache options */
46 struct cache_block
**blocks
; /* big list of all the blocks */
47 ULONG num_in_use
; /* number of blocks currently in use (ie not on the free list) */
49 struct cache_block
**hash
; /* the hash table itself */
51 struct cache_block
*free_head
; /* first block in the free list */
52 struct cache_block
*free_tail
; /* last block in the free list */
54 struct cache_block
*dirty
; /* list of dirty blocks */
56 ULONG hits
; /* number of hits, for stats */
57 ULONG misses
; /* number of misses */
60 /* flags for cache_new */
61 #define CACHE_WRITETHROUGH (1<<0) /* write immediately */
62 #define CACHE_WRITEBACK (1<<1) /* defer writes */
65 #define CACHE_64_TD64 (1<<2) /* have 64-bit via trackdisk64 requests */
66 #define CACHE_64_NSD (1<<3) /* have 64-bit via new-style device requests */
67 #define CACHE_64_SCSI (1<<4) /* have 64-bit via DirectSCSI requests */
68 #define CACHE_64_MASK (CACHE_64_NSD | CACHE_64_TD64 | CACHE_64_SCSI)
70 struct cache
*cache_new(struct IOStdReq
*req
, ULONG hash_size
, ULONG num_blocks
, ULONG block_size
, ULONG flags
);
71 void cache_free(struct cache
*c
);
73 ULONG
cache_get_block(struct cache
*c
, ULONG num
, ULONG flags
, struct cache_block
**rb
);
74 ULONG
cache_put_block(struct cache
*c
, struct cache_block
*b
, ULONG flags
);
76 ULONG
cache_get_blocks(struct cache
*c
, ULONG num
, ULONG nblocks
, ULONG flags
, struct cache_block
**rb
);
77 ULONG
cache_put_blocks(struct cache
*c
, struct cache_block
**b
, ULONG nblocks
, ULONG flags
);
79 ULONG
cache_mark_block_dirty(struct cache
*c
, struct cache_block
*b
);
80 ULONG
cache_mark_blocks_dirty(struct cache
*c
, struct cache_block
**b
, ULONG nblocks
);
82 ULONG
cache_flush(struct cache
*c
);
84 void cache_stats(struct cache
*c
);