|
Basic Solution File System - BSFS
|
Interface for file creation operations in the BSFS filesystem. More...
Functions | |
| int | create_file (FILE *disk, superblock_t *sb, btree_handle_t *inode_tree, const char *path, dir_t *cwd, uint16_t uid, uint16_t gid, uint16_t permissions) |
| Creates an empty regular file at the given path. | |
Interface for file creation operations in the BSFS filesystem.
This header exposes functions to create new files in the BSFS filesystem. File creation involves resolving the parent directory, validating uniqueness of the filename, allocating and initializing a new inode, inserting it into the inode B-tree, and linking the inode into the directory hierarchy with a directory entry.
Provided functions:
This header is part of the public API for higher-level file operations.
| int create_file | ( | FILE * | disk, |
| superblock_t * | sb, | ||
| btree_handle_t * | inode_tree, | ||
| const char * | path, | ||
| dir_t * | cwd, | ||
| uint16_t | uid, | ||
| uint16_t | gid, | ||
| uint16_t | permissions ) |
Creates an empty regular file at the given path.
This function initializes a fresh inode_t (size = 0, no data blocks), inserts it into the inode B-tree, and then adds a directory entry in the parent directory resolved from path. It prevents duplicate names in the parent directory and updates the parent's metadata (timestamps).
Workflow: 1) Resolve the parent directory and basename from path (relative to cwd if needed) using resolve_parent_dir(). 2) Allocate a new inode number and initialize a zero-sized regular file inode. 3) Insert the inode into the inode B-tree via insert_inode(). 4) Build a dir_entry_t and insert it into the parent directory using add_dir_entry(). 5) Update the parent directory's timestamps and persist them via update_inode().
Notes:
| disk | Open filesystem image. |
| sb | Loaded superblock. |
| inode_tree | Handle for the inode B-tree. |
| path | Absolute or relative path of the new file. |
| cwd | Current working directory for resolving relative paths. |
| uid | Owner user ID for the new inode. |
| gid | Owner group ID for the new inode. |
| permissions | Mode bits (e.g., 0644). |