|
Basic Solution File System - BSFS
|
Implementation of path resolution utilities for BSFS. More...
Functions | |
| int | resolve_path (FILE *disk, superblock_t *sb, const char *path, dir_t *cwd, dir_t *parent_out, char *final_name) |
| Resolves a path to its parent directory and the final component name. | |
| int | lookup_file (FILE *disk, superblock_t *sb, const char *path, dir_t *cwd, inode_t *out_inode) |
| Looks up a file or directory by path and loads its inode. | |
| int | resolve_parent_dir (FILE *disk, superblock_t *sb, const char *path, dir_t *cwd, dir_t *out_parent, char *out_basename, size_t basename_cap) |
| Resolve the parent directory and basename from a path. | |
Implementation of path resolution utilities for BSFS.
This file provides the core logic for resolving filesystem paths, including functions for navigating directories, extracting final components, and retrieving inodes based on path strings.
| int lookup_file | ( | FILE * | disk, |
| superblock_t * | sb, | ||
| const char * | path, | ||
| dir_t * | cwd, | ||
| inode_t * | out_inode ) |
Looks up a file or directory by path and loads its inode.
This function resolves the given path and attempts to locate the corresponding inode (for either a file or directory). It internally uses resolve_path and lookup_dir_entry.
| disk | Pointer to the filesystem image. |
| sb | Pointer to the superblock. |
| path | Input path string (absolute or relative). |
| cwd | Pointer to current working directory (used for relative paths). |
| out_inode | Output parameter to receive the found inode. |
| int resolve_parent_dir | ( | FILE * | disk, |
| superblock_t * | sb, | ||
| const char * | path, | ||
| dir_t * | cwd, | ||
| dir_t * | out_parent, | ||
| char * | out_basename, | ||
| size_t | basename_cap ) |
Resolve the parent directory and basename from a path.
This function takes an absolute or relative path, normalizes it, validates it, splits it into parent directory path and basename, and resolves the parent directory into a dir_t structure.
Workflow:
out_parent and the basename in out_basename.Error handling:
Memory:
| disk | Pointer to the open filesystem image. |
| sb | Pointer to the loaded superblock. |
| path | Absolute or relative path of the file. |
| cwd | Current working directory for relative path resolution. |
| out_parent | Output: resolved parent directory (as dir_t). |
| out_basename | Output: buffer that will receive the final component (basename) of the path. |
| basename_cap | Capacity of out_basename buffer (in bytes). |
| int resolve_path | ( | FILE * | disk, |
| superblock_t * | sb, | ||
| const char * | path, | ||
| dir_t * | cwd, | ||
| dir_t * | parent_out, | ||
| char * | final_name ) |
Resolves a path to its parent directory and the final component name.
This function traverses the file system path starting from either the root (for absolute paths) or the given current working directory (cwd), and returns:
| disk | Pointer to the filesystem image. |
| sb | Pointer to the superblock. |
| path | Input path string (absolute or relative). |
| cwd | Pointer to current working directory (used for relative paths). |
| parent_out | Output parameter to receive the parent directory. |
| final_name | Output parameter to receive the final name. |