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

Implementation of inode manipulation operations for BSFS. More...

Functions

int read_inode (FILE *disk, btree_handle_t *handle, uint32_t inode_number, inode_t *out_inode)
 Reads an inode from the inode B-tree.
int insert_inode (FILE *disk, superblock_t *sb, btree_handle_t *handle, const inode_t *inode)
 Inserts a new inode into the inode B-tree.
int update_inode (FILE *disk, btree_handle_t *handle, const inode_t *inode)
 Updates an existing inode in the B-tree.
int remove_inode (FILE *disk, superblock_t *sb, btree_handle_t *handle, uint32_t inode_number)
 Removes an inode from the inode B-tree.
uint32_t get_next_inode_number (FILE *disk, btree_handle_t *inode_tree)
 Finds the next available inode number by scanning the inode B-tree.
int inode_exists (FILE *disk, btree_handle_t *inode_tree, uint32_t inode_number)
 Checks if an inode with the given number exists in the inode B-tree.
int inode_tree_init (FILE *disk, superblock_t *sb, btree_handle_t *out)
 Initialize (or load) the inode B-tree handle.

Detailed Description

Implementation of inode manipulation operations for BSFS.

This source file provides functions to manage inode entries within the inode B-tree in the BSFS file system.

It implements:

  • Insertion of new inodes into the tree
  • Lookup and reading of inodes by their inode number
  • Inode updates that overwrite existing metadata
  • Deletion of inodes from the tree

These functions encapsulate the B-tree logic and provide a clean interface for interacting with inodes without requiring direct manipulation of tree internals.

Function Documentation

◆ get_next_inode_number()

uint32_t get_next_inode_number ( FILE * disk,
btree_handle_t * inode_tree )

Finds the next available inode number by scanning the inode B-tree.

This function scans the inode tree to find the highest inode number in use and returns the next available one. This ensures uniqueness of inode numbers without reusing deleted ones.

Parameters
diskPointer to the disk file.
inode_treePointer to the B-tree handle for inodes.
Returns
The next available (unused) inode number.

◆ inode_exists()

int inode_exists ( FILE * disk,
btree_handle_t * inode_tree,
uint32_t inode_number )

Checks if an inode with the given number exists in the inode B-tree.

This function performs a lookup in the inode B-tree to determine whether an inode with the specified number is currently present in the file system.

Parameters
diskPointer to the file representing the disk.
inode_treePointer to the B-tree handle managing inodes.
inode_numberThe inode number to check for existence.
Returns
1 if the inode exists, 0 if it does not.

◆ inode_tree_init()

int inode_tree_init ( FILE * disk,
superblock_t * sb,
btree_handle_t * out )

Initialize (or load) the inode B-tree handle.

If the inode root does not exist yet in the superblock, this function allocates a fresh root node on disk (empty leaf), persists it, and stores the block number in both the handle and the superblock (via write_superblock). If the root already exists, the handle is configured to point to it.

Parameters
diskOpen filesystem image.
sbLoaded superblock (may be updated/persisted if creating root).
outOutput: initialized inode B-tree handle (by value).
Returns
1 on success, 0 on failure.

◆ insert_inode()

int insert_inode ( FILE * disk,
superblock_t * sb,
btree_handle_t * handle,
const inode_t * inode )

Inserts a new inode into the inode B-tree.

Parameters
diskPointer to the open filesystem image.
sbPointer to the superblock (for block allocation).
handlePointer to the B-tree handle for inode management.
inodePointer to the inode to be inserted.

◆ read_inode()

int read_inode ( FILE * disk,
btree_handle_t * handle,
uint32_t inode_number,
inode_t * out_inode )

Reads an inode from the inode B-tree.

Parameters
diskPointer to the open filesystem image.
handlePointer to the B-tree handle for inode management.
inode_numberThe unique identifier of the inode to read.
out_inodePointer to the inode_t structure to store the result.
Returns
1 if the inode was found, 0 otherwise.

◆ remove_inode()

int remove_inode ( FILE * disk,
superblock_t * sb,
btree_handle_t * handle,
uint32_t inode_number )

Removes an inode from the inode B-tree.

This function removes the inode entry with the specified inode number from the B-tree structure.

Parameters
diskPointer to the open filesystem image.
sbPointer to the superblock (needed for possible deallocations).
handlePointer to the B-tree handle for inode management.
inode_numberThe inode number to be removed.
Returns
1 if the inode was found and removed, 0 otherwise.

◆ update_inode()

int update_inode ( FILE * disk,
btree_handle_t * handle,
const inode_t * inode )

Updates an existing inode in the B-tree.

Parameters
diskPointer to the open filesystem image.
handlePointer to the B-tree handle for inode management.
inodePointer to the modified inode to be written back.
Returns
1 if the inode was updated, 0 if not found.