PatchworkOS
966e257
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/sysfs.h
>
4
#include <
kernel/utils/ref.h
>
5
6
#include <
stdint.h
>
7
#include <
sys/io.h
>
8
#include <
sys/list.h
>
9
10
typedef
struct
filesystem
filesystem_t
;
11
typedef
struct
superblock
superblock_t
;
12
typedef
struct
superblock_ops
superblock_ops_t
;
13
typedef
struct
dentry_ops
dentry_ops_t
;
14
typedef
struct
inode
inode_t
;
15
typedef
struct
dentry
dentry_t
;
16
17
/**
18
* @brief Mountable filesystem.
19
* @defgroup kernel_fs_superblock Superblock
20
* @ingroup kernel_fs
21
*
22
* A superblock represents a mounted filesystem, it can be thought of as "filesystem + device". The filesystem is
23
* just the format of the data, e.g. fat32, ramfs, sysfs, etc. and the device provides the data. The superblock is the
24
* combination of both, e.g. a fat32 filesystem on /dev/sda1.
25
*
26
* In the case of certain special filesystems like ramfs or sysfs there is no underlying device, in this case
27
* the device name is simply set to `VFS_DEVICE_NAME_NONE`.
28
*
29
* @{
30
*/
31
32
/**
33
* @brief Superblock ID type.
34
*/
35
typedef
uint64_t
superblock_id_t
;
36
37
/**
38
* @brief Superblock structure.
39
* @struct superblock_t
40
*
41
* Superblocks are owned by the VFS, not the filesystem.
42
*/
43
typedef
struct
superblock
44
{
45
ref_t
ref
;
46
list_entry_t
entry
;
47
superblock_id_t
id
;
48
uint64_t
blockSize
;
49
uint64_t
maxFileSize
;
50
void
*
private
;
51
dentry_t
*
root
;
52
const
superblock_ops_t
*
ops
;
53
const
dentry_ops_t
*
dentryOps
;
54
filesystem_t
*
fs
;
55
char
deviceName[
MAX_NAME
];
56
/**
57
* The number of mounts of this superblock.
58
*
59
* Note that this does need to be separate from the reference count as a superblock is referenced by mounts,
60
* but it can also be referenced by other things like open files.
61
*/
62
atomic_uint64_t
mountCount
;
63
}
superblock_t
;
64
65
/**
66
* @brief Superblock operations structure.
67
* @struct superblock_ops_t
68
*/
69
typedef
struct
superblock_ops
70
{
71
/**
72
* Called when the VFS needs to create a new inode, if not specified `heap_alloc()` is used.
73
* This is usefull as it lets filesystems allocate a structure larget than `inode_t` and use the additional
74
* space for private data in addition to the `private` pointer in `inode_t`.
75
*/
76
inode_t
* (*allocInode)(
superblock_t
* superblock);
77
/**
78
* Called when the VFS wants to free an inode, if not specified `free()` is used.
79
*/
80
void (*freeInode)(
superblock_t
* superblock,
inode_t
* inode);
81
/**
82
* Called when the filesystem is superblock is being freed to give the filesystem a chance to clean up any private
83
* data.
84
*/
85
void (*cleanup)(
superblock_t
* superblock);
86
/**
87
* Called when the the superblocks `mountCount` reaches zero, meaning it is not visible anywhere in any namespace.
88
*/
89
void (*unmount)(
superblock_t
* superblock);
90
}
superblock_ops_t
;
91
92
/**
93
* @brief Create a new superblock.
94
*
95
* This does not add the superblock to the superblock cache, the `vfs_mount()` function will do that using
96
* `vfs_add_superblock()`.
97
*
98
* There is no `superblock_free()` instead use `UNREF()`.
99
*
100
* Note that the superblock's `root` dentry must be created and assigned after calling this function.
101
*
102
* @param fs The filesystem type of the superblock.
103
* @param deviceName The device name, or `VFS_DEVICE_NAME_NONE` for no device.
104
* @param ops The superblock operations, can be NULL.
105
* @param dentryOps The dentry operations for dentries in this superblock, can be NULL.
106
* @return On success, the new superblock. On failure, returns `NULL` and `errno` is set.
107
*/
108
superblock_t
*
superblock_new
(
filesystem_t
* fs,
const
char
* deviceName,
const
superblock_ops_t
*
ops
,
109
const
dentry_ops_t
*
dentryOps
);
110
111
/**
112
* @brief Increment the mount count of a superblock.
113
*
114
* @param superblock Pointer to the superblock.
115
*/
116
void
superblock_inc_mount_count
(
superblock_t
* superblock);
117
118
/**
119
* @brief Decrement the mount count of a superblock.
120
*
121
* If the mount count reaches zero, the `unmount` operation is called if its not `NULL`.
122
*
123
* @param superblock Pointer to the superblock.
124
*/
125
void
superblock_dec_mount_count
(
superblock_t
* superblock);
126
127
/** @} */
MAX_NAME
#define MAX_NAME
Maximum length of names.
Definition
MAX_NAME.h:11
superblock_inc_mount_count
void superblock_inc_mount_count(superblock_t *superblock)
Increment the mount count of a superblock.
Definition
superblock.c:60
superblock_id_t
uint64_t superblock_id_t
Superblock ID type.
Definition
superblock.h:35
superblock_new
superblock_t * superblock_new(filesystem_t *fs, const char *deviceName, const superblock_ops_t *ops, const dentry_ops_t *dentryOps)
Create a new superblock.
Definition
superblock.c:35
superblock_dec_mount_count
void superblock_dec_mount_count(superblock_t *superblock)
Decrement the mount count of a superblock.
Definition
superblock.c:65
io.h
list.h
ops
static socket_family_ops_t ops
Definition
local.c:505
dentryOps
static dentry_ops_t dentryOps
Definition
ramfs.c:181
ref.h
stdint.h
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
dentry_ops_t
Dentry operations structure.
Definition
dentry.h:72
dentry_t
Directory entry structure.
Definition
dentry.h:84
filesystem_t
Filesystem structure, represents a filesystem type, e.g. fat32, ramfs, sysfs, etc.
Definition
filesystem.h:31
inode_t
Inode structure.
Definition
inode.h:56
list_entry_t
A entry in a doubly linked list.
Definition
list.h:36
ref_t
Reference counting structure.
Definition
ref.h:30
superblock_ops_t
Superblock operations structure.
Definition
superblock.h:70
superblock_t
Superblock structure.
Definition
superblock.h:44
superblock_t::blockSize
uint64_t blockSize
Definition
superblock.h:48
superblock_t::maxFileSize
uint64_t maxFileSize
Definition
superblock.h:49
superblock_t::ops
const superblock_ops_t * ops
Definition
superblock.h:52
superblock_t::mountCount
atomic_uint64_t mountCount
Definition
superblock.h:62
superblock_t::ref
ref_t ref
Definition
superblock.h:45
superblock_t::fs
filesystem_t * fs
Definition
superblock.h:54
superblock_t::entry
list_entry_t entry
Definition
superblock.h:46
superblock_t::root
dentry_t * root
Definition
superblock.h:51
superblock_t::dentryOps
const dentry_ops_t * dentryOps
Definition
superblock.h:53
superblock_t::id
superblock_id_t id
Definition
superblock.h:47
sysfs.h
include
kernel
fs
superblock.h
Generated on Mon Dec 15 2025 21:55:53 for PatchworkOS by
1.9.8