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

Bitmap management utilities for the BSFS file system. More...

Functions

int init_bitmap_list (FILE *disk, uint32_t start_block, uint32_t num_blocks)
 Initializes a linked list of bitmap blocks on disk.
uint8_t * load_bitmap (FILE *disk, uint32_t bitmap_start_block)
 Loads a bitmap from the specified file.
int write_bitmap (FILE *disk, uint8_t *bitmap, uint32_t bitmap_start_block)
 Writes the bitmap to disk starting at the given block.
uint32_t is_bit_free (uint8_t *bitmap, uint32_t index)
 Checks if a given block is free in the bitmap.
void set_bit (uint8_t *bitmap, uint32_t index)
 Marks a block as allocated in the bitmap.
void clear_bit (uint8_t *bitmap, uint32_t index)
 Marks a block as free in the bitmap.

Detailed Description

Bitmap management utilities for the BSFS file system.

This header provides the core functions to manage the block allocation bitmap in the Basic Solution File System (BSFS). The bitmap tracks which blocks on the disk are allocated or free, and is essential for operations such as:

  • Block allocation and deallocation
  • File creation and deletion
  • Space management and consistency

The bitmap is stored on disk as a linked list of fixed-size blocks and is loaded into memory for manipulation during runtime. These functions abstract the bitmap I/O and provide low-level access to set, clear, and query bit status.

Key functionalities:

  • Initialization of the bitmap block list on disk
  • Loading and saving the bitmap from/to disk
  • Marking individual blocks as free or occupied
  • Querying the state of specific blocks

This interface is used internally by the allocator and file system logic to ensure efficient space tracking and integrity of data block usage.

Function Documentation

◆ clear_bit()

void clear_bit ( uint8_t * bitmap,
uint32_t index )

Marks a block as free in the bitmap.

This function clears the bit corresponding to a given block to indicate that it is now free (available for allocation).

Parameters
bitmapThe pointer to the bitmap.
indexThe index of the block to mark as free.

◆ init_bitmap_list()

int init_bitmap_list ( FILE * disk,
uint32_t start_block,
uint32_t num_blocks )

Initializes a linked list of bitmap blocks on disk.

This function creates and writes a series of bitmap blocks to the disk, starting at a specified block number. Each bitmap block contains a byte array representing the bitmap data (used to track free/allocated blocks) and a pointer to the next bitmap block. The last block in the list will have its next_block field set to INVALID_BLOCK, indicating the end of the list.

Parameters
diskPointer to the file representing the disk (filesystem image).
start_blockThe starting block number where the bitmap list begins.
num_blocksThe total number of blocks to be initialized in the list.
Returns
0 on success, or -1 if an error occurs during disk write operations.

◆ is_bit_free()

uint32_t is_bit_free ( uint8_t * bitmap,
uint32_t index )

Checks if a given block is free in the bitmap.

This function checks the status of a specific block in the bitmap to determine if it is free (available for allocation) or occupied.

Parameters
bitmapThe pointer to the bitmap.
indexThe index of the block to check.
Returns
1 if the block is free, 0 if the block is occupied.

◆ load_bitmap()

uint8_t * load_bitmap ( FILE * disk,
uint32_t bitmap_start_block )

Loads a bitmap from the specified file.

This function reads the bitmap from the disk, starting at the given position and using the block size to determine the number of bytes to read.

Parameters
diskThe file pointer to the filesystem image.
bitmap_start_blockThe block where the bitmap starts.
Returns
A pointer to the loaded bitmap in memory, or NULL if loading fails.

◆ set_bit()

void set_bit ( uint8_t * bitmap,
uint32_t index )

Marks a block as allocated in the bitmap.

This function sets the bit corresponding to a given block to indicate that it is now allocated (occupied).

Parameters
bitmapThe pointer to the bitmap.
indexThe index of the block to mark as allocated.

◆ write_bitmap()

int write_bitmap ( FILE * disk,
uint8_t * bitmap,
uint32_t bitmap_start_block )

Writes the bitmap to disk starting at the given block.

This function traverses the linked list of bitmap blocks on disk and writes the corresponding segments of the bitmap array to each block. It ensures the updated bitmap is persisted for future allocations.

Parameters
diskFile pointer to the filesystem image.
bitmapPointer to the in-memory bitmap data.
bitmap_start_blockLogical block number where the bitmap begins.
Returns
0 on success, or -1 if an error occurs during reading or writing.