PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
cwd.c
Go to the documentation of this file.
1#include <kernel/fs/cwd.h>
2
5
6void cwd_init(cwd_t* cwd)
7{
8 cwd->path = PATH_EMPTY;
9 lock_init(&cwd->lock);
10}
11
12void cwd_deinit(cwd_t* cwd)
13{
14 lock_acquire(&cwd->lock);
15 path_put(&cwd->path);
16 lock_release(&cwd->lock);
17}
18
20{
21 path_t result = PATH_EMPTY;
22
23 lock_acquire(&cwd->lock);
24
25 if (cwd->path.dentry == NULL || cwd->path.mount == NULL)
26 {
27 assert(cwd->path.dentry == NULL && cwd->path.mount == NULL);
28 namespace_get_root(ns, &result);
29 lock_release(&cwd->lock);
30 return result;
31 }
32
33 path_copy(&result, &cwd->path);
34 lock_release(&cwd->lock);
35
36 return result;
37}
38
39void cwd_set(cwd_t* cwd, const path_t* newPath)
40{
41 lock_acquire(&cwd->lock);
42 path_copy(&cwd->path, newPath);
43 lock_release(&cwd->lock);
44}
45
46void cwd_clear(cwd_t* cwd)
47{
48 lock_acquire(&cwd->lock);
49 path_put(&cwd->path);
50 lock_release(&cwd->lock);
51}
#define assert(expression)
Definition assert.h:29
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
void namespace_get_root(namespace_t *ns, path_t *out)
Get the root path of a namespace.
Definition namespace.c:470
void path_put(path_t *path)
Put a path.
Definition path.c:273
void path_copy(path_t *dest, const path_t *src)
Copy a path.
Definition path.c:268
#define PATH_EMPTY
Helper to create an empty path.
Definition path.h:163
static void lock_init(lock_t *lock)
Initializes a lock.
Definition lock.h:79
static void lock_release(lock_t *lock)
Releases a lock.
Definition lock.h:175
static void lock_acquire(lock_t *lock)
Acquires a lock, blocking until it is available.
Definition lock.h:96
#define NULL
Pointer error value.
Definition NULL.h:25
Definition cwd.h:18
path_t path
Definition cwd.h:19
lock_t lock
Definition cwd.h:20
Namespace structure.
Definition namespace.h:57
Path structure.
Definition path.h:127
mount_t * mount
Definition path.h:128
dentry_t * dentry
Definition path.h:129