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

ext2: reading and writing the disk, the block group descriptors, and allocating and freeing blocks in the groups' block bitmaps. More...

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

Go to the source code of this file.

Functions

int ext2_io (struct ext2 *desc, int write, off_t off, size_t size, void *buf)
 Reads or writes bytes of the filesystem's disk, all of them.
int ext2_bgd_table_rewrite (struct ext2 *desc)
 Writes the block group descriptor table back to the disk, after a change to a group's counts.
int ext2_block_read (struct ext2 *desc, uint32_t number, void *buf)
 Reads a block from the disk.
int ext2_block_write (struct ext2 *desc, uint32_t number, void *buf)
 Writes a block to the disk.
int ext2_block_alloc (struct ext2 *desc, uint32_t *block)
 Allocates a free block: its bit is set in its group's block bitmap, the free counts go down, and the block is zeroed.
int ext2_block_free (struct ext2 *desc, uint32_t block)
 Frees a block: its bit is cleared in its group's block bitmap, and the free counts go up.

Detailed Description

ext2: reading and writing the disk, the block group descriptors, and allocating and freeing blocks in the groups' block bitmaps.

Definition in file block.c.

Function Documentation

◆ ext2_bgd_table_rewrite()

int ext2_bgd_table_rewrite ( struct ext2 * desc)

Writes the block group descriptor table back to the disk, after a change to a group's counts.

Parameters
descthe mounted filesystem
Returns
0, or a negative errno

Definition at line 34 of file block.c.

References ext2::bs, ext2_bgd_table_rewrite(), ext2_io(), ext2::groups, and ext2::ngroups.

Referenced by ext2_bgd_table_rewrite(), ext2_block_alloc(), ext2_block_free(), ext2_inode_alloc(), ext2_inode_free(), and ext2_vmknod().

◆ ext2_block_alloc()

int ext2_block_alloc ( struct ext2 * desc,
uint32_t * block )

Allocates a free block: its bit is set in its group's block bitmap, the free counts go down, and the block is zeroed.

A bitmap that couldn't be read isn't written back.

Parameters
descthe mounted filesystem
blockset to the block's number
Returns
0, -ENOSPC if the filesystem is full, -ENOMEM, or an I/O error

Definition at line 77 of file block.c.

References ext2_group::bmap, ext2::bs, ext2_superblock::dblock, ext2_bgd_table_rewrite(), ext2_block_alloc(), ext2_block_read(), ext2_block_write(), ext2_superblock_rewrite(), ext2_group::free_blocks, ext2_superblock::free_blocks, ext2_superblock::gblocks, ext2::groups, kfree(), kmalloc(), bitmap::map, bitmap::max_idx, memset(), ext2::ngroups, and ext2::superblock.

Referenced by ext2_block_alloc(), and ext2_inode_block_alloc().

◆ ext2_block_free()

int ext2_block_free ( struct ext2 * desc,
uint32_t block )

Frees a block: its bit is cleared in its group's block bitmap, and the free counts go up.

If the bitmap can't be read, the block stays used.

Parameters
descthe mounted filesystem
blockthe block's number
Returns
0, -EINVAL for a block outside the filesystem, -ENOMEM, or an I/O error

Definition at line 145 of file block.c.

References ext2_group::bmap, ext2::bs, ext2_superblock::dblock, ext2_bgd_table_rewrite(), ext2_block_free(), ext2_block_read(), ext2_block_write(), ext2_superblock_rewrite(), ext2_group::free_blocks, ext2_superblock::free_blocks, ext2_superblock::gblocks, ext2::groups, kfree(), kmalloc(), bitmap::map, ext2_superblock::nblocks, and ext2::superblock.

Referenced by ext2_block_free(), and free_tree().

◆ ext2_block_read()

int ext2_block_read ( struct ext2 * desc,
uint32_t number,
void * buf )

Reads a block from the disk.

Parameters
descthe mounted filesystem
numberthe block number
bufwhere it goes, a block's size
Returns
0, or a negative errno

Definition at line 49 of file block.c.

References ext2::bs, ext2_block_read(), and ext2_io().

Referenced by ext2_block_alloc(), ext2_block_free(), ext2_block_read(), ext2_indirect_block_get(), ext2_inode_alloc(), ext2_inode_block_read(), ext2_inode_free(), and free_tree().

◆ ext2_block_write()

int ext2_block_write ( struct ext2 * desc,
uint32_t number,
void * buf )

Writes a block to the disk.

Parameters
descthe mounted filesystem
numberthe block number
bufthe block's new contents
Returns
0, or a negative errno

Definition at line 62 of file block.c.

References ext2::bs, ext2_block_write(), and ext2_io().

Referenced by ext2_block_alloc(), ext2_block_free(), ext2_block_write(), ext2_indirect_block_get(), ext2_inode_alloc(), ext2_inode_block_write(), ext2_inode_free(), and free_tree().

◆ ext2_io()

int ext2_io ( struct ext2 * desc,
int write,
off_t off,
size_t size,
void * buf )

Reads or writes bytes of the filesystem's disk, all of them.

Parameters
descthe mounted filesystem
writewhether to write (1) or read (0)
offwhere on the disk, in bytes
sizehow many bytes
bufthe data
Returns
0, the device's error, or -EIO if fewer bytes went

Definition at line 19 of file block.c.

References ext2_io(), ext2::supernode, vfs_read(), and vfs_write().

Referenced by ext2_bgd_table_rewrite(), ext2_block_read(), ext2_block_write(), ext2_inode_read(), ext2_inode_write(), ext2_io(), and ext2_superblock_rewrite().