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

minix: allocating and freeing data blocks (zones), and reading and writing them, through the block cache for the ones read often. More...

#include <ds/bitmap.h>
#include <minix.h>

Go to the source code of this file.

Functions

blk_t minix_block_alloc (struct minix *desc)
 Allocates a free zone: its bit is set in the zone bitmap, which is written back to the disk at once.
void minix_block_free (struct minix *desc, blk_t blk)
 Frees a zone: its bit is cleared in the zone bitmap, which is written back at once, and its copy in the block cache goes.
ssize_t minix_block_read (struct minix *desc, blk_t blk, void *buf)
 Reads a block from the disk.
ssize_t minix_block_write (struct minix *desc, blk_t blk, void *buf)
 Writes a block to the disk.
int minix_bcache_get (struct minix *desc, blk_t blk, void **data)
 Gets a block from the block cache, reading it from the disk into the cache if it isn't there.

Detailed Description

minix: allocating and freeing data blocks (zones), and reading and writing them, through the block cache for the ones read often.

Definition in file block.c.

Function Documentation

◆ minix_bcache_get()

int minix_bcache_get ( struct minix * desc,
blk_t blk,
void ** data )

Gets a block from the block cache, reading it from the disk into the cache if it isn't there.

The cache keeps the block's memory.

Parameters
descthe mounted filesystem
blkthe block number
dataset to the cached block
Returns
0, -ENOMEM, or a negative errno from the read

Definition at line 97 of file block.c.

References minix::bcache, bcache_find(), bcache_insert(), minix::bs, kmalloc(), minix_bcache_get(), minix_block_read(), and NULL.

Referenced by free_tree(), minix_bcache_get(), minix_inode_block_read(), and minix_inode_block_write().

◆ minix_block_alloc()

blk_t minix_block_alloc ( struct minix * desc)

Allocates a free zone: its bit is set in the zone bitmap, which is written back to the disk at once.

Parameters
descthe mounted filesystem
Returns
the zone's block number, or 0 if the filesystem is full

Definition at line 16 of file block.c.

References minix::bs, minix_superblock::firstdatazone, bitmap::map, bitmap::max_idx, minix_block_alloc(), minix::superblock, minix::supernode, vfs_write(), minix::zmap, minix_superblock::zmap_blocks, and minix::zmap_off.

Referenced by minix_block_alloc(), minix_inode_block_write(), and table_alloc().

◆ minix_block_free()

void minix_block_free ( struct minix * desc,
blk_t blk )

Frees a zone: its bit is cleared in the zone bitmap, which is written back at once, and its copy in the block cache goes.

Parameters
descthe mounted filesystem
blkthe zone's block number

Definition at line 42 of file block.c.

References minix::bcache, bcache_remove(), minix::bs, minix_superblock::firstdatazone, bitmap::map, bitmap::max_idx, minix_block_free(), minix::superblock, minix::supernode, vfs_write(), minix::zmap, minix_superblock::zmap_blocks, and minix::zmap_off.

Referenced by free_tree(), and minix_block_free().

◆ minix_block_read()

ssize_t minix_block_read ( struct minix * desc,
blk_t blk,
void * buf )

Reads a block from the disk.

Parameters
descthe mounted filesystem
blkthe block number
bufwhere it goes, a block's size
Returns
the number of bytes read, or a negative errno

Definition at line 70 of file block.c.

References minix::bs, minix_block_read(), minix::supernode, and vfs_read().

Referenced by minix_bcache_get(), minix_block_read(), and minix_inode_block_read().

◆ minix_block_write()

ssize_t minix_block_write ( struct minix * desc,
blk_t blk,
void * buf )

Writes a block to the disk.

Parameters
descthe mounted filesystem
blkthe block number
bufthe block's new contents
Returns
the number of bytes written, or a negative errno

Definition at line 83 of file block.c.

References minix::bs, minix_block_write(), minix::supernode, and vfs_write().

Referenced by free_tree(), minix_block_write(), minix_inode_block_write(), and table_alloc().