Basic Solution File System - BSFS
Loading...
Searching...
No Matches
block_operations_bsfs.h File Reference

Low-level block read/write operations for the BSFS file system. More...

Functions

int write_block (FILE *disk, uint32_t block_number, const void *data, size_t size)
 Writes data to a single block.
int read_block (FILE *disk, uint32_t block_number, void *data, size_t size)
 Reads data from a single block.
int free_block (FILE *disk, superblock_t *sb, uint32_t block_number, uint8_t *bitmap, uint32_t bitmap_size)
 Marks a block as free in the file system.

Detailed Description

Low-level block read/write operations for the BSFS file system.

This header defines the interface for manipulating raw disk blocks in the BSFS file system. It provides low-level functions for reading from and writing to specific blocks on disk, as well as a utility function for freeing blocks based on the bitmap.

These operations are fundamental for interacting with file system structures stored on disk, such as inodes, B-tree nodes, and user data.

Functions declared here are intended to be used by higher-level components such as allocation logic, metadata management, and file read/write APIs.

The block operations are aligned with the block size defined in the superblock and rely on bitmap status to maintain consistency.

Function Documentation

◆ free_block()

int free_block ( FILE * disk,
superblock_t * sb,
uint32_t block_number,
uint8_t * bitmap,
uint32_t bitmap_size )

Marks a block as free in the file system.

Clears the bit corresponding to block_number in the allocation bitmap and writes the updated bitmap to disk. The bitmap region location is obtained from the superblock (sb->block_bitmap_start).

Parameters
diskPointer to the disk file where the block is located.
sbPointer to the superblock providing bitmap location metadata.
block_numberThe block number to be marked as free.
bitmapPointer to the in-memory bitmap buffer to update and write.
bitmap_sizeUnused parameter (reserved for future validation).
Returns
0 on success, -1 on failure.

◆ read_block()

int read_block ( FILE * disk,
uint32_t block_number,
void * data,
size_t size )

Reads data from a single block.

This function reads a block of data from the specified block number on the disk. It ensures the size of the data to be read does not exceed the block size.

Parameters
diskPointer to the disk file where data will be read from.
block_numberThe block number from which the data will be read.
dataPointer to the buffer where the read data will be stored.
sizeThe size of the data to be read.
Returns
0 on success, -1 if there is an error in the reading process.

◆ write_block()

int write_block ( FILE * disk,
uint32_t block_number,
const void * data,
size_t size )

Writes data to a single block.

This function writes a block of data to the specified block number on the disk. It ensures the size of the data does not exceed the block size. The data is written to the block with a full write of the block size.

Parameters
diskPointer to the disk file where data will be written.
block_numberThe block number where the data will be written.
dataPointer to the data to be written.
sizeThe size of the data to be written.
Returns
0 on success, -1 if there is an error in the writing process.