1#ifndef VFS_CACHE_H 2#define VFS_CACHE_H 3 4#include <stddef.h> 5#include <errors/errno.h> 6 7struct fs_cache; 8 9// Initialize cache. 10// Errors: 11// - LIB_ERR_MALLOC_FAIL: Allocation failed / out of heap memory. 12errval_t fs_cache_init(size_t max_capacity, size_t map_size, struct fs_cache **cache); 13 14// Free cache. 15void fs_cache_free(struct fs_cache *cache); 16 17// Acquire a reference to a cache entry. The reference must be released with 18// fs_cache_release. 19// Errors: 20// - FS_CACHE_NOTPRESENT: There is no item with the given key in the cache. 21errval_t fs_cache_acquire(struct fs_cache *cache, uint32_t key, void **item); 22 23// Put an entry into the cache. The reference must be released with 24// fs_cache_release. Calling put multiple times with the same (key, item) pair 25// is not an error. 26// Errors: 27// - FS_CACHE_CONFLICT: An item with same key but different data pointer is 28// already present. 29// - FS_CACHE_FULL: Cache is at max capacity and all entries are referenced. 30// - LIB_ERR_MALLOC_FAIL: Increasing capacity failed. 31errval_t fs_cache_put(struct fs_cache *cache, uint32_t key, void *item); 32 33// Release an acquired reference. Every call to fs_cache_acquire and 34// fs_cache_put should have a matching fs_cache_release. 35// Errors: 36// - FS_CACHE_NOTPRESENT: There is no item with the given key in the cache. 37errval_t fs_cache_release(struct fs_cache *cache, uint32_t key); 38 39#endif 40