PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
mount.c
Go to the documentation of this file.
1#include <kernel/fs/mount.h>
2
3#include <kernel/fs/vfs.h>
4#include <kernel/log/log.h>
5#include <stdlib.h>
6#include <sys/list.h>
7
8static void mount_free(mount_t* mount)
9{
10 if (mount == NULL)
11 {
12 return;
13 }
14
15 if (mount->superblock != NULL)
16 {
18 UNREF(mount->superblock);
19 }
20
21 if (mount->target != NULL)
22 {
24 UNREF(mount->target);
25 }
26
27 if (mount->source != NULL)
28 {
29 UNREF(mount->source);
30 }
31
32 if (mount->parent != NULL)
33 {
34 UNREF(mount->parent);
35 }
36
38}
39
40mount_t* mount_new(superblock_t* superblock, dentry_t* source, dentry_t* target, mount_t* parent, mode_t mode)
41{
42 if (superblock == NULL || source == NULL || (target != NULL && parent == NULL))
43 {
44 errno = EINVAL;
45 return NULL;
46 }
47
48 if (!DENTRY_IS_POSITIVE(source) || (target != NULL && !DENTRY_IS_POSITIVE(target)))
49 {
50 errno = ENOENT;
51 return NULL;
52 }
53
54 mount_t* mount = malloc(sizeof(mount_t));
55 if (mount == NULL)
56 {
57 errno = ENOMEM;
58 return NULL;
59 }
60
62 mount->id = vfs_id_get();
63 mount->source = REF(source);
64 if (target != NULL)
65 {
66 mount->target = REF(target);
67 atomic_fetch_add_explicit(&target->mountCount, 1, memory_order_relaxed);
68 }
69 else
70 {
71 mount->target = NULL;
72 }
74 mount->superblock = REF(superblock);
75 mount->parent = parent != NULL ? REF(parent) : NULL;
76 mount->mode = mode;
77
78 return mount;
79}
static clock_source_t source
Structure to describe the HPET to the sys time subsystem.
Definition hpet.c:193
#define DENTRY_IS_POSITIVE(dentry)
Check if a dentry is positive.
Definition dentry.h:67
mount_t * mount_new(superblock_t *superblock, dentry_t *source, dentry_t *target, mount_t *parent, mode_t mode)
Create a new mount.
Definition mount.c:40
mode_t
Path flags and permissions.
Definition path.h:79
void superblock_inc_mount_count(superblock_t *superblock)
Increment the mount count of a superblock.
Definition superblock.c:68
void superblock_dec_mount_count(superblock_t *superblock)
Decrement the mount count of a superblock.
Definition superblock.c:73
void rcu_call_free(void *arg)
Helper callback to free a pointer.
Definition rcu.c:188
void rcu_call(rcu_entry_t *entry, rcu_callback_t func, void *arg)
Add a callback to be executed after a grace period.
Definition rcu.c:72
#define REF(ptr)
Increment reference count.
Definition ref.h:82
static void ref_init(ref_t *ref, void *callback)
Initialize a reference counter.
Definition ref.h:130
#define UNREF(ptr)
Decrement reference count.
Definition ref.h:109
uint64_t vfs_id_get(void)
Generates a new unique ID, to be used for any VFS object.
Definition vfs.c:1236
#define ENOENT
No such file or directory.
Definition errno.h:42
#define EINVAL
Invalid argument.
Definition errno.h:142
#define ENOMEM
Out of memory.
Definition errno.h:92
#define errno
Error number variable.
Definition errno.h:27
uint64_t mount(const char *mountpoint, const char *fs, const char *options)
System call for mounting a filesystem.
Definition mount.c:5
#define NULL
Pointer error value.
Definition NULL.h:25
static void mount_free(mount_t *mount)
Definition mount.c:8
@ memory_order_relaxed
Definition stdatomic.h:116
#define atomic_fetch_add_explicit(object, operand, order)
Definition stdatomic.h:259
#define atomic_fetch_sub_explicit(object, operand, order)
Definition stdatomic.h:262
_PUBLIC void * malloc(size_t size)
Definition malloc.c:5
Directory entry structure.
Definition dentry.h:155
Mount structure.
Definition mount.h:48
Superblock structure.
Definition superblock.h:33