The Pedigree Project
0.1
src
modules
system
vfs
MountView-internal.h
1
/* Copyright (c) 2026, Pedigree Developers. */
2
#ifndef PEDIGREE_VFS_MOUNTVIEW_INTERNAL_H
3
#define PEDIGREE_VFS_MOUNTVIEW_INTERNAL_H
4
#include "pedigree/kernel/Atomic.h"
5
#include "pedigree/kernel/LockGuard.h"
6
#include "pedigree/kernel/process/TerminationDeferral.h"
7
#include "pedigree/kernel/utilities/Pointers.h"
8
9
#include "MountView.h"
10
11
// Unlike ChildLease/RetainedFile, this owner may outlive the acquiring thread.
12
class
VfsNodeReference
{
13
public
:
14
VfsNodeReference
() =
default
;
15
explicit
VfsNodeReference
(
Directory::ChildLease
& child);
16
VfsNodeReference
(
VfsNodeReference
&& other)
noexcept
;
17
VfsNodeReference
& operator=(
VfsNodeReference
&& other)
noexcept
;
18
~VfsNodeReference
();
19
bool
retain(
File
* node,
Filesystem
* backing);
20
bool
retainAnonymous(
File
* node);
21
void
reset();
22
File
* get()
const
{
23
return
m_Node;
24
}
25
26
private
:
27
VfsNodeReference
(
const
VfsNodeReference
&) =
delete
;
28
VfsNodeReference
& operator=(
const
VfsNodeReference
&) =
delete
;
29
enum class
Ownership { Borrowed, Tracked, Virtual };
30
File
* m_Node =
nullptr
;
31
Ownership m_Ownership = Ownership::Borrowed;
32
};
33
34
class
VfsBacking
{
35
public
:
36
explicit
VfsBacking
(
VFS::FilesystemPin
&& retained) : pin(pedigree_std::move(retained)) {}
37
~VfsBacking
();
38
VFS
* owningRegistry =
nullptr
;
39
VFS::FilesystemPin
pin;
40
};
41
using
VfsBackingRef
=
SharedPointer<VfsBacking>
;
42
43
class
VfsAttachment
{
44
public
:
45
VfsAttachment
(
const
VfsBackingRef
& retained, uint64_t
identity
,
VfsNodeReference
&& selected,
46
uint64_t
options
)
47
: backing(retained),
48
root(selected.get()),
49
id(
identity
),
50
flags(
options
),
51
rootReference(pedigree_std::move(selected)) {}
52
VfsBackingRef
backing;
53
File
*
const
root;
54
const
uint64_t id;
55
Atomic<uint64_t>
flags;
56
uint64_t lockedFlags = 0;
57
bool
lockedMount =
false
;
58
Atomic<size_t>
writers{0};
59
VfsNodeReference
rootReference;
60
Atomic<size_t>
paths
{0};
61
};
62
using
VfsAttachmentRef
=
SharedPointer<VfsAttachment>
;
63
64
class
VfsPath
final :
public
FilesystemPath
{
65
public
:
66
enum class
Kind { Mounted, Anonymous };
67
VfsPath
(
VfsMountView
& owner,
const
VfsAttachmentRef
& attachment,
VfsNodeReference
&& node);
68
VfsPath
(
VfsMountView
& owner,
VfsNodeReference
&& anonymousNode);
69
const
Kind kind;
70
~VfsPath
()
override
;
71
File
* node()
const override
{
72
return
file.get();
73
}
74
const
void
* provider()
const override
{
75
return
&view;
76
}
77
VfsMountView
& view;
78
VfsAttachmentRef
attachment;
79
VfsNodeReference
file;
80
// A regular inode can have several names with different directory ancestry.
81
FilesystemPathRef
lookupParent;
82
String
lookupName;
83
};
84
85
struct
VfsAttachmentRow
{
86
VfsAttachmentRef
attachment;
87
VfsAttachmentRef
parent;
88
SharedPointer<VfsNodeReference>
covered;
89
VfsAttachmentRow
* next =
nullptr
;
90
};
91
struct
VfsContextRow
{
92
FilesystemContextRef
context;
93
VfsContextRow
* next =
nullptr
;
94
};
95
96
class
VfsFilesystemContext
final :
public
FilesystemContext
{
97
public
:
98
explicit
VfsFilesystemContext
(
VfsMountView
& owner) : view(owner) {
99
view.retain();
100
}
101
~VfsFilesystemContext
()
override
;
102
bool
snapshot(
FilesystemContextSnapshot
& result)
const override
;
103
bool
forkForProcess(
FilesystemContextOwner
& result)
const override
;
104
void
retireProcessOwner()
override
;
105
const
void
* provider()
const override
{
106
return
&view;
107
}
108
109
VfsMountView
& view;
110
FilesystemPathRef
root;
111
FilesystemPathRef
cwd;
112
uint64_t generation = 1;
113
VfsContextRow
* registration =
nullptr
;
114
};
115
116
struct
VfsMountView::State
{
117
explicit
State
(
VfsMountView
& owner) : view(owner) {}
118
~State
();
119
VfsMountView
& view;
120
Mutex
graph;
121
Atomic<size_t>
anonymousPaths{0};
122
VfsAttachmentRow
* attachments =
nullptr
;
123
VfsContextRow
* contexts =
nullptr
;
124
size_t
contextCount = 0;
125
uint64_t topology = 1;
126
uint64_t rootId = 0;
127
uint64_t nextId = 1;
128
129
VfsAttachmentRow
* find(uint64_t
id
)
const
;
130
VfsAttachmentRow
* at(
const
VfsPath
& path)
const
;
131
bool
snapshotRows(
Vector<VfsAttachmentRow>
& result);
132
bool
contains(
const
FilesystemPathRef
& path)
const
;
133
VfsPath
* nodePath(
const
FilesystemPathRef
& reference)
const
;
134
VfsPath
* path(
const
FilesystemPathRef
& reference)
const
;
135
bool
makePath(
const
VfsAttachmentRef
& attachment,
File
* node,
FilesystemPathRef
& result);
136
bool
makePath(
const
VfsAttachmentRef
& attachment,
VfsNodeReference
&& node,
137
FilesystemPathRef
& result);
138
bool
makeAttachment(
const
VfsBackingRef
& backing,
File
* root, uint64_t flags,
139
VfsAttachmentRef
& result);
140
bool
ancestors(
const
FilesystemPathRef
& path,
Vector<FilesystemPathRef>
& result);
141
bool
context(
const
FilesystemContextRef
& reference,
VfsFilesystemContext
*& result)
const
;
142
bool
createContext(
const
VfsFilesystemContext
* parent,
FilesystemContextOwner
& result);
143
bool
cross(
const
FilesystemPathRef
& path,
FilesystemPathRef
& result);
144
bool
parent(
const
FilesystemPathRef
& path,
FilesystemPathRef
& result,
145
const
FilesystemPathRef
& boundary =
FilesystemPathRef
());
146
bool
beneath(
const
FilesystemPathRef
& descendant,
const
FilesystemPathRef
& ancestor);
147
bool
format(
const
FilesystemContextSnapshot
& context,
const
FilesystemPathRef
& path,
148
String
& result,
const
VFS::NamespaceMutation
& writer);
149
bool
resolve(
const
FilesystemContextSnapshot
& context,
const
FilesystemPathRef
& start,
150
const
String
& pathname,
const
ResolveOptions
&
options
,
FilesystemPathRef
& result,
151
const
VFS::NamespaceMutation
* writer =
nullptr
);
152
bool
follow(
const
FilesystemContextSnapshot
& context,
const
FilesystemPathRef
& selected,
153
const
ResolveOptions
&
options
,
FilesystemPathRef
& result,
size_t
& links);
154
bool
walk(
const
FilesystemContextSnapshot
& context,
const
FilesystemPathRef
& start,
155
const
String
& pathname,
const
ResolveOptions
&
options
,
FilesystemPathRef
& result,
156
size_t
& links);
157
bool
attach(
const
FilesystemPathRef
& covered,
VFS::FilesystemPin
&& pin,
158
const
VFS::NamespaceMutation
& writer, BackingOwnership ownership, uint64_t flags);
159
void
reapDetached();
160
};
161
#endif
Atomic
Definition
Atomic.h:35
Directory::ChildLease
Definition
Directory.h:81
File
Definition
File.h:75
FilesystemContextOwner
Definition
FilesystemContext.h:50
FilesystemContext
Definition
FilesystemContext.h:36
FilesystemPath
Definition
FilesystemContext.h:13
Filesystem
Definition
Filesystem.h:44
Mutex
Definition
Mutex.h:56
SharedPointer< VfsBacking >
String
Definition
String.h:43
VFS::FilesystemPin
Definition
VFS.h:139
VFS::NamespaceMutation
Definition
VFS.h:60
VFS
Definition
VFS.h:58
Vector
A vector / dynamic array.
Definition
Vector.h:33
VfsAttachment
Definition
MountView-internal.h:43
VfsBacking
Definition
MountView-internal.h:34
VfsFilesystemContext
Definition
MountView-internal.h:96
VfsMountView
Definition
MountView.h:17
VfsNodeReference
Definition
MountView-internal.h:12
VfsPath
Definition
MountView-internal.h:64
FilesystemContextSnapshot
Definition
FilesystemContext.h:28
VfsAttachmentRow
Definition
MountView-internal.h:85
VfsContextRow
Definition
MountView-internal.h:91
VfsMountView::ResolveOptions
Definition
MountView.h:19
VfsMountView::State
Definition
MountView-internal.h:116
identity
Definition
futex-contracts.c:32
options
Definition
vfork-benchmark/main.c:28
paths
Definition
xattr-contract-test/persistence.c:10
Generated on Sat Oct 3 2026 06:38:07 for The Pedigree Project by
1.9.8