|
PatchworkOS
|
Virtual File System context. More...
Data Structures | |
| struct | vfs_ctx_t |
| VFS context structure. More... | |
Functions | |
| void | vfs_ctx_init (vfs_ctx_t *ctx, const path_t *cwd) |
| Initialize a VFS context. | |
| void | vfs_ctx_deinit (vfs_ctx_t *ctx) |
| Deinitialize a VFS context. | |
| file_t * | vfs_ctx_get_file (vfs_ctx_t *ctx, fd_t fd) |
| Get a file from a VFS context. | |
| uint64_t | vfs_ctx_get_cwd (vfs_ctx_t *ctx, path_t *outCwd) |
| uint64_t | vfs_ctx_set_cwd (vfs_ctx_t *ctx, const path_t *cwd) |
| Set the current working directory of a VFS context. | |
| fd_t | vfs_ctx_alloc_fd (vfs_ctx_t *ctx, file_t *file) |
| Allocate a new file descriptor in a VFS context. | |
| fd_t | vfs_ctx_set_fd (vfs_ctx_t *ctx, fd_t fd, file_t *file) |
| Allocate a specific file descriptor in a VFS context. | |
| uint64_t | vfs_ctx_free_fd (vfs_ctx_t *ctx, fd_t fd) |
| Free a file descriptor in a VFS context. | |
| fd_t | vfs_ctx_dup (vfs_ctx_t *ctx, fd_t oldFd) |
| Duplicate a file descriptor in a VFS context. | |
| fd_t | vfs_ctx_dup2 (vfs_ctx_t *ctx, fd_t oldFd, fd_t newFd) |
| Duplicate a file descriptor in a VFS context to a specific file descriptor. | |
Virtual File System context.
A VFS context represents the state of the VFS for a single process. It contains the current working directory and the open file descriptors.
Allocate a new file descriptor in a VFS context.
Will create a new reference to the file.
| ctx | The context to open the file descriptor in. |
| file | The file to open. |
ERR and errno is set. Definition at line 142 of file vfs_ctx.c.
References vfs_ctx_t::allocBitmap, bitmap_find_first_clear(), bitmap_set(), CONFIG_MAX_FD, EBUSY, EMFILE, ERR, errno, file, vfs_ctx_t::files, vfs_ctx_t::initalized, vfs_ctx_t::lock, LOCK_SCOPE, and REF.
Referenced by SYSCALL_DEFINE(), SYSCALL_DEFINE(), and SYSCALL_DEFINE().
| void vfs_ctx_deinit | ( | vfs_ctx_t * | ctx | ) |
Deinitialize a VFS context.
This will close all open file descriptors and release the current working directory.
| ctx | The context to deinitialize. |
Definition at line 30 of file vfs_ctx.c.
References CONFIG_MAX_FD, vfs_ctx_t::cwd, DEREF, vfs_ctx_t::files, vfs_ctx_t::initalized, vfs_ctx_t::lock, LOCK_SCOPE, NULL, and path_put().
Referenced by process_kill().
Duplicate a file descriptor in a VFS context.
Will create a new reference to the file.
| ctx | The context to duplicate the file descriptor in. |
| oldFd | The file descriptor to duplicate. |
ERR and errno is set. Definition at line 218 of file vfs_ctx.c.
References vfs_ctx_t::allocBitmap, bitmap_find_first_clear(), bitmap_set(), CONFIG_MAX_FD, EBADF, EBUSY, EMFILE, ERR, errno, vfs_ctx_t::files, vfs_ctx_t::initalized, vfs_ctx_t::lock, LOCK_SCOPE, NULL, and REF.
Referenced by SYSCALL_DEFINE().
Duplicate a file descriptor in a VFS context to a specific file descriptor.
Will create a new reference to the file and if the newFd is already in use, it will be closed first.
| ctx | The context to duplicate the file descriptor in. |
| oldFd | The file descriptor to duplicate. |
| newFd | The file descriptor to duplicate to. |
ERR and errno is set. Definition at line 251 of file vfs_ctx.c.
References vfs_ctx_t::allocBitmap, bitmap_set(), CONFIG_MAX_FD, DEREF, EBADF, EBUSY, ERR, errno, vfs_ctx_t::files, vfs_ctx_t::initalized, vfs_ctx_t::lock, LOCK_SCOPE, NULL, and REF.
Referenced by SYSCALL_DEFINE().
Free a file descriptor in a VFS context.
Will release the reference to the file.
| ctx | The context to close the file descriptor in. |
| fd | The file descriptor to close. |
0. On failure, ERR and errno is set. Definition at line 191 of file vfs_ctx.c.
References vfs_ctx_t::allocBitmap, bitmap_clear(), CONFIG_MAX_FD, DEREF, EBADF, EBUSY, ERR, errno, vfs_ctx_t::files, vfs_ctx_t::initalized, vfs_ctx_t::lock, LOCK_SCOPE, and NULL.
Referenced by SYSCALL_DEFINE(), and SYSCALL_DEFINE().
@Get the current working directory of a VFS context.
If the current directory is NULL, then returns a reference to the root of the kernel process's namespace.
Will create a new reference to the cwd.
| ctx | The context to get the current working directory of. |
| outCwd | The output path to store the current working directory in. |
0. On failure, ERR and errno is set. Definition at line 67 of file vfs_ctx.c.
References assert, vfs_ctx_t::cwd, path_t::dentry, EBUSY, ERR, errno, vfs_ctx_t::initalized, vfs_ctx_t::lock, LOCK_SCOPE, path_t::mount, namespace_get_root_path(), NULL, path_copy(), and process_get_kernel().
Referenced by process_cwd_read(), process_init(), vfs_walk(), and vfs_walk_parent().
Get a file from a VFS context.
| ctx | The context to get the file from. |
| fd | The file descriptor to get. |
NULL and errno is set. Definition at line 48 of file vfs_ctx.c.
References CONFIG_MAX_FD, EBADF, EBUSY, errno, vfs_ctx_t::files, vfs_ctx_t::initalized, vfs_ctx_t::lock, LOCK_SCOPE, NULL, and REF.
Referenced by SYSCALL_DEFINE(), SYSCALL_DEFINE(), SYSCALL_DEFINE(), SYSCALL_DEFINE(), SYSCALL_DEFINE(), SYSCALL_DEFINE(), SYSCALL_DEFINE(), SYSCALL_DEFINE(), SYSCALL_DEFINE(), and SYSCALL_DEFINE().
Initialize a VFS context.
| ctx | The context to initialize. |
| cwd | The initial current working directory, can be NULL. |
Definition at line 11 of file vfs_ctx.c.
References vfs_ctx_t::allocBitmap, vfs_ctx_t::allocBitmapBuffer, bitmap_init(), CONFIG_MAX_FD, vfs_ctx_t::cwd, vfs_ctx_t::files, vfs_ctx_t::initalized, vfs_ctx_t::lock, lock_init(), memset(), NULL, path_copy(), and PATH_EMPTY.
Referenced by process_init().
Set the current working directory of a VFS context.
Will create a new reference to the cwd and release the old one.
| ctx | The context to set the current working directory of. |
| cwd | The new current working directory. |
0. On failure, ERR and errno is set. Definition at line 93 of file vfs_ctx.c.
References vfs_ctx_t::cwd, path_t::dentry, EBUSY, EINVAL, ENOTDIR, ERR, errno, vfs_ctx_t::initalized, dentry_t::inode, INODE_DIR, vfs_ctx_t::lock, LOCK_SCOPE, NULL, path_copy(), path_put(), and inode_t::type.
Referenced by SYSCALL_DEFINE().
Allocate a specific file descriptor in a VFS context.
Will create a new reference to the file and release the old one if it exists.
| ctx | The context to open the file descriptor in. |
| fd | The file descriptor to set. |
| file | The file to open. |
ERR and errno is set. Definition at line 164 of file vfs_ctx.c.
References vfs_ctx_t::allocBitmap, bitmap_set(), CONFIG_MAX_FD, DEREF, EBUSY, EINVAL, ERR, errno, file, vfs_ctx_t::files, vfs_ctx_t::initalized, vfs_ctx_t::lock, LOCK_SCOPE, NULL, and REF.
Referenced by init_process_spawn(), and SYSCALL_DEFINE().