PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
cwd.h
Go to the documentation of this file.
1#pragma once
2
4#include <kernel/fs/path.h>
5#include <kernel/sync/lock.h>
6/**
7 * @brief Current Working Directory
8 * @defgroup kernel_fs_cwd Current Working Directory
9 * @ingroup kernel_fs
10 *
11 * The current working directory (CWD) is a per-process structure to track the current location in the filesystem for
12 * the process.
13 *
14 * @{
15 */
16
17typedef struct cwd
18{
21} cwd_t;
22
23/**
24 * @brief Initialize a CWD structure.
25 *
26 * Will by default lazily resolve to the root path of the namespace until set to another path.
27 *
28 * @param cwd The CWD structure to initialize.
29 */
30void cwd_init(cwd_t* cwd);
31
32/**
33 * @brief Deinitialize a CWD structure.
34 *
35 * @param cwd The CWD structure to deinitialize.
36 */
37void cwd_deinit(cwd_t* cwd);
38
39/**
40 * @brief Get the current working directory.
41 *
42 * @note If the cwd has not been set, this will return the root path of the namespace. This is to solve
43 * a circular dependency where the kernel process needs to be initialized before the vfs.
44 *
45 * @param cwd The CWD structure.
46 * @param ns The namespace to get the root path from if the cwd is not set.
47 * @return The current working directory path.
48 */
50
51/**
52 * @brief Set the current working directory.
53 *
54 * @param cwd The CWD structure.
55 * @param newPath The new current working directory.
56 */
57void cwd_set(cwd_t* cwd, const path_t* newPath);
58
59/**
60 * @brief Clear the current working directory.
61 *
62 * Needed as a process might have its working directory inside its own `/proc/[pid]` directory which, since that
63 * directory holds references to the process itself, would result in a memory leak.
64 *
65 * @param cwd The CWD structure.
66 */
67void cwd_clear(cwd_t* cwd);
68
69/** @} */
void cwd_set(cwd_t *cwd, const path_t *newPath)
Set the current working directory.
Definition cwd.c:39
void cwd_init(cwd_t *cwd)
Initialize a CWD structure.
Definition cwd.c:6
void cwd_clear(cwd_t *cwd)
Clear the current working directory.
Definition cwd.c:46
path_t cwd_get(cwd_t *cwd, namespace_t *ns)
Get the current working directory.
Definition cwd.c:19
void cwd_deinit(cwd_t *cwd)
Deinitialize a CWD structure.
Definition cwd.c:12
Definition cwd.h:18
path_t path
Definition cwd.h:19
lock_t lock
Definition cwd.h:20
A simple ticket lock implementation.
Definition lock.h:44
Namespace structure.
Definition namespace.h:57
Path structure.
Definition path.h:127