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

On-demand garbage collection for Recovery entries in BSFS. More...

Classes

struct  rec_item_t
 Internal item wrapper used during Recovery GC traversals. More...

Functions

size_t rec_gc_purge_until (FILE *disk, superblock_t *sb, uint32_t needed_blocks, uint64_t now)
 Purge Recovery entries until at least a target number of blocks are freed.

Detailed Description

On-demand garbage collection for Recovery entries in BSFS.

Implements routines to purge recovery entries in order to free disk space when allocations fail. The GC prefers removing expired entries first; if still insufficient, it removes the oldest non-expired entries until the requested number of blocks is freed.

Function Documentation

◆ rec_gc_purge_until()

size_t rec_gc_purge_until ( FILE * disk,
superblock_t * sb,
uint32_t needed_blocks,
uint64_t now )

Purge Recovery entries until at least a target number of blocks are freed.

Attempts to reclaim space by first removing expired entries (those with retention_until <= now). If that is insufficient, continues by removing the oldest remaining entries (ascending deleted_at) until at least needed_blocks have been freed or there are no more entries.

For each purged entry, this routine deallocates blocks described by its 16 direct spans and, if present, traverses the per-file bspan B-tree to deallocate the remaining spans. Finally, it removes the metadata entry from the Recovery B-tree.

Parameters
diskOpen filesystem image.
sbLoaded superblock (used for bitmap updates and recovery root).
needed_blocksMinimum number of blocks to free.
nowCurrent timestamp used for retention checks.
Returns
Number of blocks actually freed (can be less than requested).