2006-03-24 22:56:00 +01:00
|
|
|
#ifndef FILE_CACHE_H__
|
|
|
|
#define FILE_CACHE_H__
|
2006-01-23 21:05:09 +01:00
|
|
|
|
2006-01-28 23:19:42 +01:00
|
|
|
struct BlockId
|
|
|
|
{
|
|
|
|
const char* atom_fn;
|
|
|
|
u32 block_num;
|
|
|
|
};
|
2006-01-23 21:05:09 +01:00
|
|
|
|
2006-01-28 23:19:42 +01:00
|
|
|
extern bool block_eq(BlockId b1, BlockId b2);
|
2006-01-23 21:05:09 +01:00
|
|
|
|
|
|
|
// create an id for use with the cache that uniquely identifies
|
2006-01-28 23:19:42 +01:00
|
|
|
// the block from the file <atom_fn> starting at <ofs>.
|
2006-01-23 21:05:09 +01:00
|
|
|
extern BlockId block_cache_make_id(const char* atom_fn, const off_t ofs);
|
|
|
|
|
|
|
|
extern void* block_cache_alloc(BlockId id);
|
|
|
|
|
|
|
|
extern void block_cache_mark_completed(BlockId id);
|
|
|
|
|
|
|
|
extern void* block_cache_find(BlockId id);
|
2006-01-28 23:19:42 +01:00
|
|
|
extern void block_cache_release(BlockId id);
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-03-24 22:56:00 +01:00
|
|
|
|
2006-03-03 07:03:16 +01:00
|
|
|
// interpret file_io parameters (pbuf, size, flags, cb) and allocate a
|
|
|
|
// file buffer if necessary.
|
|
|
|
// called by file_io and afile_read.
|
2006-04-03 23:28:10 +02:00
|
|
|
extern LibError file_io_get_buf(FileIOBuf* pbuf, size_t size,
|
2006-01-31 04:47:52 +01:00
|
|
|
const char* atom_fn, uint flags, FileIOCB cb);
|
2006-01-28 23:19:42 +01:00
|
|
|
|
2006-03-03 07:03:16 +01:00
|
|
|
// inform us that the buffer address will be increased by <padding>-bytes.
|
|
|
|
// this happens when reading uncompressed files from archive: they
|
|
|
|
// start at unaligned offsets and file_io rounds offset down to
|
|
|
|
// next block boundary. the buffer therefore starts with padding, which
|
|
|
|
// is skipped so the user only sees their data.
|
|
|
|
// we make note of the new buffer address so that it can be freed correctly
|
|
|
|
// by passing the new padded buffer.
|
|
|
|
extern void file_buf_add_padding(FileIOBuf exact_buf, size_t exact_size, size_t padding);
|
|
|
|
|
|
|
|
// if buf is not in extant list, complain; otherwise, mark it as
|
|
|
|
// coming from the file <atom_fn>.
|
|
|
|
// this is needed in the following case: uncompressed reads from archive
|
|
|
|
// boil down to a file_io of the archive file. the buffer is therefore
|
|
|
|
// tagged with the archive filename instead of the desired filename.
|
|
|
|
// afile_read sets things right by calling this.
|
2006-01-28 23:19:42 +01:00
|
|
|
extern LibError file_buf_set_real_fn(FileIOBuf buf, const char* atom_fn);
|
|
|
|
|
2006-03-03 07:03:16 +01:00
|
|
|
// "give" <buf> to the cache, specifying its size and owner filename.
|
|
|
|
// since this data may be shared among users of the cache, it is made
|
|
|
|
// read-only (via MMU) to make sure no one can corrupt/change it.
|
|
|
|
//
|
|
|
|
// note: the reference added by file_buf_alloc still exists! it must
|
|
|
|
// still be file_buf_free-d after calling this.
|
2006-04-03 23:28:10 +02:00
|
|
|
extern LibError file_cache_add(FileIOBuf buf, size_t size,
|
|
|
|
const char* atom_fn, uint file_flags);
|
2006-01-25 08:21:45 +01:00
|
|
|
|
2006-03-24 22:56:00 +01:00
|
|
|
|
2006-03-03 07:03:16 +01:00
|
|
|
|
|
|
|
// check if the contents of the file <atom_fn> are in file cache.
|
|
|
|
// if not, return 0; otherwise, return buffer address and optionally
|
|
|
|
// pass back its size.
|
2006-03-24 22:56:00 +01:00
|
|
|
//
|
|
|
|
// note: does not call stats_cache because it does not know the file size
|
|
|
|
// in case of cache miss! doing so is left to the caller.
|
2006-04-03 23:28:10 +02:00
|
|
|
extern FileIOBuf file_cache_retrieve(const char* atom_fn, size_t* psize, uint fb_flags = 0);
|
2006-03-03 07:03:16 +01:00
|
|
|
|
|
|
|
// invalidate all data loaded from the file <fn>. this ensures the next
|
|
|
|
// load of this file gets the (presumably new) contents of the file,
|
|
|
|
// not previous stale cache contents.
|
|
|
|
// call after hotloading code detects file has been changed.
|
|
|
|
extern LibError file_cache_invalidate(const char* P_fn);
|
|
|
|
|
|
|
|
// reset entire state of the file cache to what it was after initialization.
|
|
|
|
// that means completely emptying the extant list and cache.
|
|
|
|
// used after simulating cache operation, which fills the cache with
|
|
|
|
// invalid data.
|
2006-03-01 23:31:11 +01:00
|
|
|
extern void file_cache_reset();
|
2006-02-09 06:59:33 +01:00
|
|
|
|
2006-01-25 08:21:45 +01:00
|
|
|
extern void file_cache_init();
|
|
|
|
extern void file_cache_shutdown();
|
2006-03-24 22:56:00 +01:00
|
|
|
|
|
|
|
#endif // #ifndef FILE_CACHE_H__
|