|
Basic Solution File System - BSFS
|
Block allocation interface for the BSFS file system. More...
Functions | |
| int | allocate_bspan_queue (FILE *disk, superblock_t *sb, bspan_queue_t *queue, uint32_t blocks_needed, uint32_t offset) |
| Allocates a sequence of free blocks and fills a bspan queue. | |
| uint32_t | allocate_single_block (FILE *disk, superblock_t *sb) |
| Allocates a single free block and updates the block bitmap. | |
| int | deallocate_single_block (FILE *disk, superblock_t *sb, uint32_t block_index) |
| Deallocates a single block in the filesystem. | |
| int | deallocate_bspan (FILE *disk, superblock_t *sb, const bspan_t *bspan) |
| Frees a contiguous range of disk blocks described by a bspan and updates the bitmap on disk. | |
Block allocation interface for the BSFS file system.
This header defines the interface for block allocation and deallocation operations used in the BSFS file system. It provides functions to allocate individual blocks and block spans (bspan_t), as well as their corresponding deallocation routines.
All functions ensure synchronization with the block bitmap on disk, preserving the consistency of allocation metadata across the file system. The allocation logic supports both sequential and sparse data layouts, which can be used in conjunction with B-tree indexing or file write operations.
Functions declared here operate on structures defined in:
| int allocate_bspan_queue | ( | FILE * | disk, |
| superblock_t * | sb, | ||
| bspan_queue_t * | queue, | ||
| uint32_t | blocks_needed, | ||
| uint32_t | offset ) |
Allocates a sequence of free blocks and fills a bspan queue.
This function scans the block bitmap on disk to find available (free) blocks and groups them into spans (bspan_t), which are enqueued into a queue. It uses a first-fit strategy and continues recursively if the entire allocation cannot be fulfilled in a single span.
The function internally loads the bitmap, updates it, and writes the updated bitmap back to disk after allocation.
| disk | Pointer to the FILE representing the filesystem image. |
| sb | Pointer to the superblock containing block and bitmap information. |
| queue | Pointer to the bspan queue where allocated spans will be enqueued. |
| blocks_needed | Total number of blocks required for allocation. |
| offset | Starting block index for the allocation scan (typically 0). |
| uint32_t allocate_single_block | ( | FILE * | disk, |
| superblock_t * | sb ) |
Allocates a single free block and updates the block bitmap.
This function scans the block bitmap to find the first available (free) block. Once found, it marks the block as occupied in the in-memory bitmap and persists the updated bitmap back to disk to ensure consistency.
The bitmap must be previously formatted as a linked list of blocks starting from the block number indicated by the superblock. This function assumes that each block in the bitmap contains a pointer to the next block.
| disk | Pointer to the FILE representing the filesystem image. |
| sb | Pointer to the superblock structure containing metadata about the filesystem. |
| int deallocate_bspan | ( | FILE * | disk, |
| superblock_t * | sb, | ||
| const bspan_t * | bspan ) |
Frees a contiguous range of disk blocks described by a bspan and updates the bitmap on disk.
This function loads the block allocation bitmap from disk, marks all blocks covered by the specified bspan as free, and writes the updated bitmap back to the disk. It is used to reclaim storage space when a file or segment is removed from the filesystem.
The bitmap is read and written based on the starting block specified in the superblock. Any failure to read or write the bitmap will be reported as an error.
| disk | Pointer to the open FILE representing the filesystem image. |
| sb | Pointer to the superblock structure containing bitmap metadata. |
| bspan | Pointer to the bspan structure indicating which disk blocks to free. |
| int deallocate_single_block | ( | FILE * | disk, |
| superblock_t * | sb, | ||
| uint32_t | block_index ) |
Deallocates a single block in the filesystem.
This function marks the specified block as free in the block allocation bitmap and updates the bitmap on disk. It should be used whenever a block is no longer needed (e.g., during file truncation or deletion).
| disk | Pointer to the FILE representing the filesystem image. |
| sb | Pointer to the superblock with bitmap location information. |
| block_index | Index of the block to be deallocated. |