PatchworkOS
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
5#include <stdlib.h>
6
7static void mount_free(mount_t* mount)
8{
9 if (mount == NULL)
10 {
11 return;
12 }
13
14 if (mount->superblock != NULL)
15 {
18 }
19
20 if (mount->mountpoint != NULL)
21 {
24 }
25
26 if (mount->root != NULL)
27 {
29 }
30
31 if (mount->parent != NULL)
32 {
34 }
35
36 free(mount);
37}
38
39mount_t* mount_new(superblock_t* superblock, dentry_t* root, dentry_t* mountpoint, mount_t* parent)
40{
41 if (superblock == NULL)
42 {
43 errno = EINVAL;
44 return NULL;
45 }
46
47 mount_t* mount = malloc(sizeof(mount_t));
48 if (mount == NULL)
49 {
50 return NULL;
51 }
52
56 mount->superblock = REF(superblock);
58 if (mountpoint != NULL)
59 {
60 mount->mountpoint = REF(mountpoint);
61 dentry_inc_mount_count(mountpoint);
62 }
63 else
64 {
66 }
67 mount->root = root != NULL ? REF(root) : NULL;
68 mount->parent = parent != NULL ? REF(parent) : NULL;
69
70 return mount;
71}
static mount_t * mount
Definition acpi.c:15
void dentry_dec_mount_count(dentry_t *dentry)
Decrements the mount count of a dentry.
Definition dentry.c:133
void dentry_inc_mount_count(dentry_t *dentry)
Increments the mount count of a dentry.
Definition dentry.c:128
mount_t * mount_new(superblock_t *superblock, dentry_t *root, dentry_t *mountpoint, mount_t *parent)
Create a new mount.
Definition mount.c:39
void superblock_inc_mount_count(superblock_t *superblock)
Increment the mount count of a superblock.
Definition superblock.c:57
void superblock_dec_mount_count(superblock_t *superblock)
Decrement the mount count of a superblock.
Definition superblock.c:62
uint64_t vfs_get_new_id(void)
Generates a new unique ID.
Definition vfs.c:97
void map_entry_init(map_entry_t *entry)
Initialize a map entry.
Definition map.c:71
static void ref_init(ref_t *ref, void *free)
Initialize a reference counter.
Definition ref.h:92
#define REF(ptr)
Increment reference count.
Definition ref.h:65
#define DEREF(ptr)
Decrement reference count.
Definition ref.h:80
#define EINVAL
Invalid argument.
Definition errno.h:142
#define errno
Error number variable.
Definition errno.h:27
#define NULL
Pointer error value.
Definition NULL.h:23
static void mount_free(mount_t *mount)
Definition mount.c:7
_PUBLIC void * malloc(size_t size)
Definition malloc.c:5
_PUBLIC void free(void *ptr)
Definition free.c:11
Directory entry structure.
Definition dentry.h:83
Mount structure.
Definition mount.h:36
superblock_t * superblock
The superblock of the mounted filesystem.
Definition mount.h:40
dentry_t * mountpoint
The dentry that this filesystem is mounted on, can be NULL for the root filesystem.
Definition mount.h:41
map_entry_t mapEntry
Definition mount.h:39
dentry_t * root
The root dentry of the mounted filesystem.
Definition mount.h:42
mount_t * parent
The parent mount, can be NULL for the root filesystem.
Definition mount.h:43
ref_t ref
Definition mount.h:37
mount_id_t id
Definition mount.h:38
Superblock structure.
Definition superblock.h:44