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