|
Basic Solution File System - BSFS
|
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. | |
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:
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.
This interface is used internally by the allocator and file system logic to ensure efficient space tracking and integrity of data block usage.
| 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).
| bitmap | The pointer to the bitmap. |
| index | The index of the block to mark as free. |
| 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.
| disk | Pointer to the file representing the disk (filesystem image). |
| start_block | The starting block number where the bitmap list begins. |
| num_blocks | The total number of blocks to be initialized in the list. |
| 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.
| bitmap | The pointer to the bitmap. |
| index | The index of the block to check. |
| 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.
| disk | The file pointer to the filesystem image. |
| bitmap_start_block | The block where the bitmap starts. |
| 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).
| bitmap | The pointer to the bitmap. |
| index | The index of the block to mark as allocated. |
| 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.
| disk | File pointer to the filesystem image. |
| bitmap | Pointer to the in-memory bitmap data. |
| bitmap_start_block | Logical block number where the bitmap begins. |