AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
bcache.c File Reference

The block cache: a filesystem's blocks kept in memory, by a number the filesystem chooses (minix uses the block number), so that a block read again and again is read once. More...

#include <core/system.h>
#include <fs/bcache.h>

Go to the source code of this file.

Data Structures

struct  cache_block
 A cached block. More...

Functions

static int bcache_eq (void *_a, void *_b)
 Says whether a cached block is the one whose number _b points to.
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.
void bcache_dirty (struct bcache *bcache, uint64_t off)
 Marks a cached block as changed.

Detailed Description

The block cache: a filesystem's blocks kept in memory, by a number the filesystem chooses (minix uses the block number), so that a block read again and again is read once.

minix keeps its indirect zones there.

Definition in file bcache.c.

Function Documentation

◆ bcache_dirty()

void bcache_dirty ( struct bcache * bcache,
uint64_t off )

Marks a cached block as changed.

Nothing writes dirty blocks back yet: the filesystems write their changes through at once.

Parameters
bcachethe cache
offthe block's number

Definition at line 124 of file bcache.c.

References bcache_dirty(), cache_block::dirty, hashmap_node::entry, hashmap_node::hash, bcache::hashmap, and cache_block::off.

Referenced by bcache_dirty().

◆ bcache_eq()

int bcache_eq ( void * _a,
void * _b )
static

Says whether a cached block is the one whose number _b points to.

Definition at line 22 of file bcache.c.

References bcache_eq(), and cache_block::off.

Referenced by bcache_eq(), and bcache_init().

◆ 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().