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

Interface for logical file removal in BSFS. More...

Functions

int remove_file (FILE *disk, superblock_t *sb, btree_handle_t *inode_tree, btree_handle_t *rec_tree, const char *path, dir_t *cwd, uint16_t uid)
 Logically remove a file and snapshot it into the Recovery tree.

Detailed Description

Interface for logical file removal in BSFS.

This header defines the API to "remove" a file in BSFS. Removal in this context is logical: the file is unlinked from its parent directory and its inode is removed from the inode B-tree, but its data blocks are NOT freed. Instead, a snapshot is inserted into the Recovery B-tree, enabling later restoration of the file or eventual purging by a garbage collector.

Function Documentation

◆ remove_file()

int remove_file ( FILE * disk,
superblock_t * sb,
btree_handle_t * inode_tree,
btree_handle_t * rec_tree,
const char * path,
dir_t * cwd,
uint16_t uid )

Logically remove a file and snapshot it into the Recovery tree.

Unlinks the directory entry for path, removes the file's inode from the inode tree (without freeing its data blocks), and inserts a snapshot of the file metadata into the Recovery B-tree to enable later restoration or purge.

Steps: 1) Resolve the parent directory and basename from path. 2) Lookup the file inode (must not be a directory). 3) Build and insert a rec_entry_t snapshot into the Recovery tree. 4) Remove the directory entry from its parent. 5) Remove the inode from the inode tree. 6) Update parent directory timestamps.

Rollback: If step 4 or 5 fails, the inserted recovery entry is removed to keep metadata consistent.

Parameters
diskOpen filesystem image.
sbLoaded superblock.
inode_treeInode B-tree handle.
rec_treeRecovery B-tree handle.
pathAbsolute or relative path of the file to remove.
cwdCurrent working directory (for resolving relative paths).
uidCaller user id (currently unused; permission checks may use it).
Returns
0 on success; -1 on error.