PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
mount.h
Go to the documentation of this file.
1#pragma once
2
3#include <kernel/fs/path.h>
4#include <kernel/sync/rcu.h>
5#include <kernel/utils/map.h>
6#include <kernel/utils/ref.h>
7#include <sys/list.h>
8
9#include <stdatomic.h>
10#include <stdint.h>
11
12typedef struct mount mount_t;
13typedef struct superblock superblock_t;
14typedef struct dentry dentry_t;
15typedef struct path path_t;
16
17/**
18 * @brief Mount point.
19 * @defgroup kernel_fs_mount Mount
20 * @ingroup kernel_fs
21 *
22 * A mount represents a location that a superblock is mounted to. It links a superblock (the mounted filesystem) to a
23 * mountpoint (a dentry in another filesystem).
24 *
25 * @{
26 */
27
28/**
29 * @brief Check if a mount is a root mount within its namespace.
30 *
31 * @param mount The mount to check.
32 * @return `true` if the mount is a root mount, `false` otherwise.
33 */
34#define MOUNT_IS_ROOT(mount) ((mount)->parent == NULL)
35
36/**
37 * @brief Mount ID type.
38 */
40
41/**
42 * @brief Mount structure.
43 * @struct mount_t
44 *
45 * Mounts are owned by the VFS, not the filesystem.
46 */
47typedef struct mount
48{
52 source; ///< The dentry to appear at target once mounted, usually the root dentry of the mounted filesystem.
53 dentry_t* target; ///< The dentry which the source is mounted to, can be `NULL` for the root filesystem.
54 superblock_t* superblock; ///< The superblock of the mounted filesystem.
55 mount_t* parent; ///< The parent mount, can be `NULL` for the root filesystem.
56 mode_t mode; ///< Specifies the maximum permissions for this mount and if it is a directory or a file.
57 rcu_entry_t rcu; ///< RCU entry for deferred cleanup.
58} mount_t;
59
60/**
61 * @brief Create a new mount.
62 *
63 * This does not add the mount to the mount cache, that must be done separately with `vfs_add_mount()`.
64 *
65 * There is no `mount_free()` instead use `UNREF()`.
66 *
67 * @param superblock The superblock of the mounted filesystem.
68 * @param source The dentry to appear at target once mounted, usually the root dentry of the mounted filesystem.
69 * @param target The dentry which the source is mounted to, can be `NULL` for the root filesystem.
70 * @param parent The parent mount, can be `NULL` for the root filesystem.
71 * @param mode Specifies the maximum permissions for this mount and if it is a directory or a file.
72 * @return On success, the new mount. On failure, returns `NULL` and `errno` is set to:
73 * - `EINVAL`: Invalid parameters.
74 * - `ENOENT`: Source or target dentry is negative.
75 * - `ENOMEM`: Out of memory.
76 */
77mount_t* mount_new(superblock_t* superblock, dentry_t* source, dentry_t* target, mount_t* parent, mode_t mode);
78
79/** @} */
static clock_source_t source
Structure to describe the HPET to the sys time subsystem.
Definition hpet.c:193
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
uint64_t mount_id_t
Mount ID type.
Definition mount.h:39
mode_t
Path flags and permissions.
Definition path.h:79
uint64_t mount(const char *mountpoint, const char *fs, const char *options)
System call for mounting a filesystem.
Definition mount.c:5
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
Directory entry structure.
Definition dentry.h:155
Mount structure.
Definition mount.h:48
superblock_t * superblock
The superblock of the mounted filesystem.
Definition mount.h:54
rcu_entry_t rcu
RCU entry for deferred cleanup.
Definition mount.h:57
dentry_t * target
The dentry which the source is mounted to, can be NULL for the root filesystem.
Definition mount.h:53
mode_t mode
Specifies the maximum permissions for this mount and if it is a directory or a file.
Definition mount.h:56
mount_t * parent
The parent mount, can be NULL for the root filesystem.
Definition mount.h:55
dentry_t * source
The dentry to appear at target once mounted, usually the root dentry of the mounted filesystem.
Definition mount.h:52
ref_t ref
Definition mount.h:49
mount_id_t id
Definition mount.h:50
Path structure.
Definition path.h:127
Intrusive RCU head structure.
Definition rcu.h:65
Reference counting structure.
Definition ref.h:52
Superblock structure.
Definition superblock.h:33