AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
bcache.h File Reference
#include <fs/vfs.h>
#include <ds/hashmap.h>

Go to the source code of this file.

Data Structures

struct  bcache
 A filesystem's block cache (fs/bcache.c): its blocks that were read, by their offset. More...

Functions

void bcache_init (struct bcache *bcache)
 Sets up an empty block cache.
int bcache_insert (struct bcache *bcache, uint64_t off, void *data)
 Adds a block to a cache, which keeps its memory from now on.
int bcache_remove (struct bcache *bcache, uint64_t off)
 Takes a block out of a cache.
void * bcache_find (struct bcache *bcache, uint64_t off)
 Finds a cached block.

Function Documentation

◆ bcache_find()

void * bcache_find ( struct bcache * bcache,
uint64_t off )

Finds a cached block.

Parameters
bcachethe cache
offthe block's number
Returns
its contents, or NULL if it isn't cached

Definition at line 100 of file bcache.c.

References bcache_find(), cache_block::data, hashmap_node::entry, hashmap_node::hash, bcache::hashmap, and NULL.

Referenced by bcache_find(), and minix_bcache_get().

◆ bcache_init()

void bcache_init ( struct bcache * bcache)

Sets up an empty block cache.

Parameters
bcachethe cache

Definition at line 35 of file bcache.c.

References bcache_eq(), bcache_init(), and bcache::hashmap.

Referenced by bcache_init(), bcache_insert(), and minix_load().

◆ bcache_insert()

int bcache_insert ( struct bcache * bcache,
uint64_t off,
void * data )

Adds a block to a cache, which keeps its memory from now on.

Parameters
bcachethe cache, set up on first use
offthe block's number
dataits contents
Returns
0, -EINVAL if bcache is NULL, or -ENOMEM

Definition at line 48 of file bcache.c.

References bcache_init(), bcache_insert(), cache_block::data, bcache::hashmap, kmalloc(), M_ZERO, and cache_block::off.

Referenced by bcache_insert(), and minix_bcache_get().

◆ bcache_remove()

int bcache_remove ( struct bcache * bcache,
uint64_t off )

Takes a block out of a cache.

Parameters
bcachethe cache
offthe block's number
Returns
0, or -1 if the block wasn't cached

Definition at line 73 of file bcache.c.

References bcache_remove(), hashmap_node::entry, hashmap_node::hash, bcache::hashmap, kfree(), NULL, and cache_block::off.

Referenced by bcache_remove(), minix_block_free(), and table_alloc().