The disk cache reduces the number of accesses made to the physical drive.
struct CACHE-INFO \ -- len
Data structure controlling each cached disk sector.
int ->cache-link \ link to next structure in chain; MUST be first int ->mem-block \ pointer to data int ->disk-block \ disk block number int ->cache-valid \ nz = cache valid int ->cache-time \ last read/write time int ->cache-dirty \ nz = modified end-struct
CACHE_SIZE buffer: cache-memory \ -- addr
The cache data blocks.
CACHE_HDR_SIZE buffer: cache-hdr-table \ -- addr
The cache lookup table.
variable active-c-block \ -- addr
Anchors active block chain.
variable free-c-blocks \ -- addr
Anchors free block chain.
: init-cache \ --
Initialise the disk cache.
: release-cache \ struct --
Put the given cache structure back onto the free chain.
Exit quietly if the structure cannot be found.
: release-all-cache \ --
Put all cache structures back on the free chain.
: (get-cache) \ -- struct|0
Get a new cache structure, or return 0 if one cannot be found.
: get-oldest-cache \ struct --
If the cache item is dirty (needs to be written back), write
it back and mark it as unused.
: get-cache \ ?struct -- struct
If there is a free cache block, discard the given one and
use a free one, otherwise reuse it.
: blk-in-cache? \ blk# -- struct t/f
If the given block is in the disk cache, return its cache
structure and true, otherwise return the oldest cache
structure and false.
: read-blk>c \ blk struct -- cache
Read the given block into cache, returning the actual cache
structure used, or zero if no cache is available.
: (read-blk) \ blk -- struct
If the block is already in cache, return its cache structure,
otherwise read it into cache, returning the cache structure
used or zero for failure.
: read-p-blk \ lba buff start size -- t/f
Read a partial block/sector into the given buffer.
Return true for success.
: read-f-blk \ lba buff -- t/f
Read a full block/sector into the given buffer.
Return true for success.
: write-p-blk \ blk buffer start end -- t/f
Write a partial block/sector from the given buffer.
Return true for success.
: write-f-blk \ lba buff -- t/f
Does a full block write to disk, replaces WRITE-BLOCK.
Return true for success.
: sync_vol \ --
Synchronise the cache and the disk by writing out any modified
blocks.
: time_sync_vol \ --
Write out any modified cache blocks that have been in cache
loger than VOL_TIMEOUT milliseconds.
This code is only compiled if the equate FSdiags? is set non-zero.
: (show-cache) \ anchor --
Display the cache blocks in a particular chain.
: show-cache \ --
Display the cache blocks in the active chain.
: show-f-cache \ --
Display the cache blocks in the free chain.