|
Basic Solution File System - BSFS
|
Directory entry B-tree operations for BSFS. More...
Functions | |
| dir_t * | open_dir (FILE *disk, btree_handle_t *inode_tree, uint32_t inode_number) |
| Opens a directory given its inode number. | |
| int | close_dir (dir_t *dir) |
| Closes a directory and frees allocated resources. | |
| int | add_dir_entry (FILE *disk, superblock_t *sb, dir_t *dir, dir_entry_t *entry) |
| Adds a new entry to a directory. | |
| int | scan_dir_tree_find (FILE *disk, btree_handle_t *handle, uint32_t node_block, const char *name, dir_entry_t *out) |
| Recursively search a directory B-tree for an exact filename match. | |
| int | remove_dir_entry (FILE *disk, superblock_t *sb, dir_t *dir, const char *filename) |
| Collect all directory entries in-order into a dynamic array. | |
| int | update_dir_entry (FILE *disk, superblock_t *sb, dir_t *dir, dir_entry_t *entry) |
| Updates an existing directory entry in the B-tree. | |
| int | lookup_dir_entry (FILE *disk, superblock_t *sb, dir_t *dir, const char *name, dir_entry_t *result) |
| Looks up a directory entry by name in a given directory. | |
| int | read_dir_entry (FILE *disk, superblock_t *sb, dir_t *dir, btree_handle_t *handle, dir_entry_t *out) |
| Reads the next directory entry from a directory. | |
Directory entry B-tree operations for BSFS.
Provides the in-memory directory descriptor (dir_t) and the set of operations for creating, removing, updating, looking up, and iterating directory entries backed by a B-tree stored in the filesystem image.
| int add_dir_entry | ( | FILE * | disk, |
| superblock_t * | sb, | ||
| dir_t * | dir, | ||
| dir_entry_t * | entry ) |
Adds a new entry to a directory.
Inserts a new dir_entry_t into the directory's B-tree. If this is the first insertion in the directory (i.e., the directory had no B-tree root), the function persists the newly created root into the directory inode.
| disk | Pointer to the filesystem image file. |
| sb | Pointer to the loaded superblock. |
| dir | Pointer to the open directory structure. |
| entry | Pointer to the directory entry to insert. |
| int close_dir | ( | dir_t * | dir | ) |
Closes a directory and frees allocated resources.
This function deallocates the memory used by the dir_t structure and its associated B-tree handle.
| dir | Pointer to the open directory to be closed. |
| int lookup_dir_entry | ( | FILE * | disk, |
| superblock_t * | sb, | ||
| dir_t * | dir, | ||
| const char * | name, | ||
| dir_entry_t * | result ) |
Looks up a directory entry by name in a given directory.
| disk | Pointer to the disk image. |
| sb | Pointer to the superblock. |
| dir | Pointer to the open directory (dir_t). |
| name | Name of the entry to look for. |
| result | Output parameter: filled with the entry if found. |
| dir_t * open_dir | ( | FILE * | disk, |
| btree_handle_t * | inode_tree, | ||
| uint32_t | inode_number ) |
Opens a directory given its inode number.
Loads the directory inode from the inode B-tree, initializes a dir_t structure and prepares the B-tree handle for reading directory entries.
| disk | Pointer to the open filesystem image. |
| inode_tree | Pointer to the B-tree containing inodes. |
| inode_number | The inode number of the directory to open. |
| int read_dir_entry | ( | FILE * | disk, |
| superblock_t * | sb, | ||
| dir_t * | dir, | ||
| btree_handle_t * | handle, | ||
| dir_entry_t * | out ) |
Reads the next directory entry from a directory.
This function traverses the B-tree of a directory and returns the next valid entry. It uses the dir_index field to keep track of position across calls.
| disk | Pointer to the open disk file. |
| sb | Pointer to the superblock. |
| dir | Pointer to the open directory structure (dir_t). |
| handle | B-tree handler for the directory entries. |
| out | Output parameter to hold the directory entry read. |
| int remove_dir_entry | ( | FILE * | disk, |
| superblock_t * | sb, | ||
| dir_t * | dir, | ||
| const char * | filename ) |
Collect all directory entries in-order into a dynamic array.
Removes an entry from a directory by name.
Removes an entry from a directory by name.
Looks up the entry in the B-tree and removes it if found.
| disk | Pointer to the filesystem image file. |
| sb | Pointer to the loaded superblock. |
| dir | Pointer to the open directory structure. |
| filename | Name of the entry to remove. |
| int scan_dir_tree_find | ( | FILE * | disk, |
| btree_handle_t * | handle, | ||
| uint32_t | node_block, | ||
| const char * | name, | ||
| dir_entry_t * | out ) |
Recursively search a directory B-tree for an exact filename match.
Traverses the directory entries B-tree in depth-first order starting at node_block, comparing each entry's name against name. Copies the first matching entry into out and returns 1 when found.
| disk | Pointer to the open disk file. |
| handle | B-tree handle for directory entries. |
| node_block | Root block of the subtree to scan. |
| name | Null-terminated filename to match exactly. |
| out | Output parameter to receive the matching entry on success. |
| int update_dir_entry | ( | FILE * | disk, |
| superblock_t * | sb, | ||
| dir_t * | dir, | ||
| dir_entry_t * | entry ) |
Updates an existing directory entry in the B-tree.
Searches for an existing directory entry using the hash of the filename and replaces its contents with entry.
| disk | Pointer to the filesystem image. |
| sb | Pointer to the superblock (unused). |
| dir | Pointer to the open directory structure. |
| entry | Pointer to the updated directory entry. |