|
Basic Solution File System - BSFS
|
Implementation of file creation routines 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. | |
Implementation of file creation routines in the BSFS filesystem.
This module provides the implementation of functions to create new empty files in the BSFS filesystem. A new inode is initialized, inserted into the inode B-tree, and linked into its parent directory via a directory entry. No data blocks are allocated at creation time; they are allocated on demand during writes.
Responsibilities:
This file is part of the higher-level file management interface for BSFS.
| 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). |