PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
superblock.h
Go to the documentation of this file.
1#pragma once
2
3#include <kernel/fs/devfs.h>
4#include <kernel/io/irp.h>
5#include <kernel/utils/ref.h>
6
7#include <stdint.h>
8#include <sys/fs.h>
9#include <sys/list.h>
10
11typedef struct filesystem filesystem_t;
12typedef struct superblock superblock_t;
13typedef struct superblock_ops superblock_ops_t;
14typedef struct dentry_ops dentry_ops_t;
15typedef struct vnode vnode_t;
16typedef struct dentry dentry_t;
17
18/**
19 * @brief Mounted filesystem.
20 * @defgroup kernel_fs_superblock Superblock
21 * @ingroup kernel_fs
22 *
23 * A superblock represents a mounted filesystem.
24 *
25 * @{
26 */
27
28/**
29 * @brief Superblock structure.
30 * @struct superblock_t
31 */
32typedef struct superblock
33{
39 void* data;
40 dentry_t* root; ///< Root dentry of the filesystem, should not take a reference.
45 /**
46 * The number of mounts of this superblock.
47 *
48 * Note that this does need to be separate from the reference count as a superblock is referenced by mounts,
49 * but it can also be referenced by other things like open files.
50 */
51 atomic_uint64_t mountCount;
53
54/**
55 * @brief Superblock operations structure.
56 * @struct superblock_ops_t
57 */
58typedef struct superblock_ops
59{
60 /**
61 * Called when the filesystem is superblock is being freed to give the filesystem a chance to clean up any private
62 * data.
63 */
64 void (*cleanup)(superblock_t* superblock);
65 /**
66 * Called when the the superblocks `mountCount` reaches zero, meaning it is not visible anywhere in any namespace.
67 */
68 void (*unmount)(superblock_t* superblock);
70
71/**
72 * @brief Create a new superblock.
73 *
74 * This does not add the superblock to the superblock cache, the `vfs_mount()` function will do that using
75 * `vfs_add_superblock()`.
76 *
77 * There is no `superblock_free()` instead use `UNREF()`.
78 *
79 * Note that the superblock's `root` dentry must be created and assigned after calling this function.
80 *
81 * @param fs The filesystem type of the superblock.
82 * @param ops The superblock operations, can be NULL.
83 * @param dentryOps The dentry operations for dentries in this superblock, can be NULL.
84 * @return On success, the new superblock. On failure, returns `NULL` and `errno` is set to:
85 * - `EINVAL`: Invalid parameters.
86 * - `ENOMEM`: Out of memory.
87 */
89
90/**
91 * @brief Increment the mount count of a superblock.
92 *
93 * @param superblock Pointer to the superblock.
94 */
96
97/**
98 * @brief Decrement the mount count of a superblock.
99 *
100 * If the mount count reaches zero, the `unmount` operation is called if its not `NULL`.
101 *
102 * @param superblock Pointer to the superblock.
103 */
105
106/** @} */
static dentry_ops_t dentryOps
Definition devfs.c:27
static fb_ops_t ops
Definition gop.c:80
void superblock_inc_mount_count(superblock_t *superblock)
Increment the mount count of a superblock.
Definition superblock.c:68
superblock_t * superblock_new(filesystem_t *fs, const superblock_ops_t *ops, const dentry_ops_t *dentryOps)
Create a new superblock.
Definition superblock.c:33
void superblock_dec_mount_count(superblock_t *superblock)
Decrement the mount count of a superblock.
Definition superblock.c:73
uint64_t sbid_t
A suberblock identifier that uniquely identifies a superblock within the system.
Definition fs.h:353
uint64_t unmount(const char *mountpoint)
System call for unmounting a filesystem.
Definition unmount.c:5
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
Dentry operations structure.
Definition dentry.h:122
Directory entry structure.
Definition dentry.h:155
Filesystem structure, represents a filesystem type, e.g. fat32, tmpfs, devfs, etc.
Definition filesystem.h:53
IRP vtable structure.
Definition irp.h:234
A entry in a doubly linked list.
Definition list.h:37
Reference counting structure.
Definition ref.h:52
Superblock operations structure.
Definition superblock.h:59
Superblock structure.
Definition superblock.h:33
uint64_t blockSize
Definition superblock.h:37
uint64_t maxFileSize
Definition superblock.h:38
const superblock_ops_t * ops
Definition superblock.h:41
atomic_uint64_t mountCount
Definition superblock.h:51
filesystem_t * fs
Definition superblock.h:44
list_entry_t entry
Definition superblock.h:35
dentry_t * root
Root dentry of the filesystem, should not take a reference.
Definition superblock.h:40
const dentry_ops_t * dentryOps
Definition superblock.h:42
void * data
Definition superblock.h:39
const irp_vtable_t * vtable
Definition superblock.h:43
vnode structure.
Definition vnode.h:48