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

Implementation of low-level block I/O operations for BSFS. 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

Implementation of low-level block I/O operations for BSFS.

This module provides basic functions for reading and writing fixed-size blocks on disk in the BSFS file system. It also includes a utility function to free blocks and mark them as available in the block bitmap.

  • write_block() writes a full block of data to a given block number.
  • read_block() reads a full block of data from a given block number.
  • free_block() clears the content of a block and marks it as free in the bitmap.

These functions form the foundation for all I/O operations involving disk-resident structures, including metadata trees, inodes, and data files.

All access respects the BLOCK_SIZE defined in the superblock and integrates with the bitmap for block availability tracking.

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.