PatchworkOS
19e446b
A non-POSIX operating system.
Theme:
Default
Round
Robot
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
11
typedef
struct
filesystem
filesystem_t
;
12
typedef
struct
superblock
superblock_t
;
13
typedef
struct
superblock_ops
superblock_ops_t
;
14
typedef
struct
dentry_ops
dentry_ops_t
;
15
typedef
struct
vnode
vnode_t
;
16
typedef
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
*/
32
typedef
struct
superblock
33
{
34
ref_t
ref
;
35
list_entry_t
entry
;
36
sbid_t
id
;
37
uint64_t
blockSize
;
38
uint64_t
maxFileSize
;
39
void
*
data
;
40
dentry_t
*
root
;
///< Root dentry of the filesystem, should not take a reference.
41
const
superblock_ops_t
*
ops
;
42
const
dentry_ops_t
*
dentryOps
;
43
const
irp_vtable_t
*
vtable
;
44
filesystem_t
*
fs
;
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
;
52
}
superblock_t
;
53
54
/**
55
* @brief Superblock operations structure.
56
* @struct superblock_ops_t
57
*/
58
typedef
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);
69
}
superblock_ops_t
;
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
*/
88
superblock_t
*
superblock_new
(
filesystem_t
* fs,
const
superblock_ops_t
*
ops
,
const
dentry_ops_t
*
dentryOps
);
89
90
/**
91
* @brief Increment the mount count of a superblock.
92
*
93
* @param superblock Pointer to the superblock.
94
*/
95
void
superblock_inc_mount_count
(
superblock_t
* superblock);
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
*/
104
void
superblock_dec_mount_count
(
superblock_t
* superblock);
105
106
/** @} */
dentryOps
static dentry_ops_t dentryOps
Definition
devfs.c:27
devfs.h
ops
static fb_ops_t ops
Definition
gop.c:80
superblock_inc_mount_count
void superblock_inc_mount_count(superblock_t *superblock)
Increment the mount count of a superblock.
Definition
superblock.c:68
superblock_new
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
superblock_dec_mount_count
void superblock_dec_mount_count(superblock_t *superblock)
Decrement the mount count of a superblock.
Definition
superblock.c:73
sbid_t
uint64_t sbid_t
A suberblock identifier that uniquely identifies a superblock within the system.
Definition
fs.h:353
unmount
uint64_t unmount(const char *mountpoint)
System call for unmounting a filesystem.
Definition
unmount.c:5
fs.h
irp.h
list.h
ref.h
stdint.h
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
dentry_ops_t
Dentry operations structure.
Definition
dentry.h:122
dentry_t
Directory entry structure.
Definition
dentry.h:155
filesystem_t
Filesystem structure, represents a filesystem type, e.g. fat32, tmpfs, devfs, etc.
Definition
filesystem.h:53
irp_vtable_t
IRP vtable structure.
Definition
irp.h:234
list_entry_t
A entry in a doubly linked list.
Definition
list.h:37
ref_t
Reference counting structure.
Definition
ref.h:52
superblock_ops_t
Superblock operations structure.
Definition
superblock.h:59
superblock_t
Superblock structure.
Definition
superblock.h:33
superblock_t::blockSize
uint64_t blockSize
Definition
superblock.h:37
superblock_t::maxFileSize
uint64_t maxFileSize
Definition
superblock.h:38
superblock_t::ops
const superblock_ops_t * ops
Definition
superblock.h:41
superblock_t::mountCount
atomic_uint64_t mountCount
Definition
superblock.h:51
superblock_t::ref
ref_t ref
Definition
superblock.h:34
superblock_t::id
sbid_t id
Definition
superblock.h:36
superblock_t::fs
filesystem_t * fs
Definition
superblock.h:44
superblock_t::entry
list_entry_t entry
Definition
superblock.h:35
superblock_t::root
dentry_t * root
Root dentry of the filesystem, should not take a reference.
Definition
superblock.h:40
superblock_t::dentryOps
const dentry_ops_t * dentryOps
Definition
superblock.h:42
superblock_t::data
void * data
Definition
superblock.h:39
superblock_t::vtable
const irp_vtable_t * vtable
Definition
superblock.h:43
vnode_t
vnode structure.
Definition
vnode.h:48
include
kernel
fs
superblock.h
Generated on Sat Jan 24 2026 10:59:24 for PatchworkOS by
1.9.8