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

Implementation of file restoration from the Recovery tree in BSFS. More...

Functions

int restore_file_by_id (FILE *disk, superblock_t *sb, btree_handle_t *inode_tree, btree_handle_t *rec_tree, uint32_t recovery_id, const char *dest_dir_path, dir_t *cwd)
 Restore a file from the Recovery tree by its recovery ID.

Detailed Description

Implementation of file restoration from the Recovery tree in BSFS.

This module provides the routines necessary to restore a deleted file using its snapshot stored in the Recovery B-tree. Restoration consists of recreating the inode (reusing recorded data block mappings), linking a new directory entry in the chosen destination directory, and removing the snapshot from the Recovery tree upon success.

Function Documentation

◆ restore_file_by_id()

int restore_file_by_id ( FILE * disk,
superblock_t * sb,
btree_handle_t * inode_tree,
btree_handle_t * rec_tree,
uint32_t recovery_id,
const char * dest_dir_path,
dir_t * cwd )

Restore a file from the Recovery tree by its recovery ID.

Semantics:

  • Loads the snapshot from the Recovery B-tree using recovery_id.
  • Determines the destination directory: if dest_dir_path is non-NULL, resolves it to a directory inode (relative to cwd if needed). If NULL or resolution fails, attempts to use the original parent recorded in the snapshot; if that is not available, falls back to cwd.
  • Resolves name conflicts by appending a suffix containing the recovery ID, ensuring a unique filename in the destination directory.
  • Recreates the inode from the snapshot (reusing its block mapping) and inserts it into the inode B-tree, updating sb->inode_root if the insertion creates the tree root.
  • Creates a directory entry in the destination directory and updates its metadata timestamps.
  • Removes the entry from the Recovery tree.
Parameters
diskOpen filesystem image.
sbLoaded superblock (may be updated if inode root is first created during restore).
inode_treeInode B-tree handle (handle->root_block should be set from sb->inode_root if it already exists).
rec_treeRecovery B-tree handle (handle->root_block should be set from sb->recovery_root).
recovery_idUnique ID of the recovery snapshot to restore.
dest_dir_pathOptional destination directory path (absolute or relative to cwd). If NULL, attempt original parent then cwd.
cwdCurrent working directory context for resolving relative paths and as a fallback destination.
Returns
0 on success; -1 on failure (snapshot not found, invalid destination, insertion or linking errors).