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

High-level operations for directory management in the BSFS file system. More...

Functions

int create_directory (FILE *disk, superblock_t *sb, const char *path, dir_t *cwd)
 Creates a new directory at the given path.
int remove_directory (FILE *disk, superblock_t *sb, const char *path, dir_t *cwd)
 Deletes a directory at the given path, if it is empty.
int move_dir_entry (FILE *disk, superblock_t *sb, dir_t *src_dir, const char *src_name, dir_t *dest_dir, const char *dest_name)
 Moves or renames a directory entry from one directory to another.
int create_root_directory (FILE *disk, superblock_t *sb)
 Initialize and persist the root directory ("/") on a fresh image.

Detailed Description

High-level operations for directory management in the BSFS file system.

This header defines functions to create, delete, rename, and move directories and files by manipulating their directory entries and associated inodes.

Function Documentation

◆ create_directory()

int create_directory ( FILE * disk,
superblock_t * sb,
const char * path,
dir_t * cwd )

Creates a new directory at the given path.

This function allocates a new inode of type directory and inserts it as an entry into the parent directory determined by the path.

Parameters
diskPointer to the disk file.
sbPointer to the loaded superblock.
pathAbsolute or relative path for the new directory.
cwdCurrent working directory (for resolving relative paths).
Returns
0 on success, -1 on error.

◆ create_root_directory()

int create_root_directory ( FILE * disk,
superblock_t * sb )

Initialize and persist the root directory ("/") on a fresh image.

Creates the root inode with default ownership and permissions, allocates a directory B-tree for entries, inserts the mandatory "." and ".." entries, and ensures the inode tree contains the root inode.

Parameters
diskOpen filesystem image.
sbLoaded superblock (root inode and tree roots may be updated).
Returns
0 on success; -1 on error.

◆ move_dir_entry()

int move_dir_entry ( FILE * disk,
superblock_t * sb,
dir_t * src_dir,
const char * src_name,
dir_t * dest_dir,
const char * dest_name )

Moves or renames a directory entry from one directory to another.

This function removes an existing directory entry from the source directory and inserts it into the destination directory. The entry can also be renamed in the process.

Parameters
diskPointer to the disk file.
sbPointer to the superblock.
src_dirPointer to the source directory.
src_nameName of the entry to move (existing name).
dest_dirPointer to the destination directory.
dest_nameNew name for the entry in the destination (can be same as src_name).
Returns
0 on success, -1 on failure.

◆ remove_directory()

int remove_directory ( FILE * disk,
superblock_t * sb,
const char * path,
dir_t * cwd )

Deletes a directory at the given path, if it is empty.

This function removes the directory entry and deallocates the associated inode.

Parameters
diskPointer to the disk file.
sbPointer to the loaded superblock.
pathAbsolute or relative path of the directory to remove.
cwdCurrent working directory (for resolving relative paths).
Returns
0 on success, -1 if the directory is not empty or cannot be removed.