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