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
VfsNodeReference
(
VfsNodeReference
&& other)
noexcept
;
16
VfsNodeReference
& operator=(
VfsNodeReference
&& other)
noexcept
;
17
~VfsNodeReference
();
18
bool
retain(
File
* node,
Filesystem
* backing);
19
bool
retainAnonymous(
File
* node);
20
void
reset();
21
File
* get()
const
{
22
return
m_Node;
23
}
24
25
private
:
26
VfsNodeReference
(
const
VfsNodeReference
&) =
delete
;
27
VfsNodeReference
& operator=(
const
VfsNodeReference
&) =
delete
;
28
File
* m_Node =
nullptr
;
29
bool
m_Tracked =
false
;
30
};
31
32
class
VfsAttachment
{
33
public
:
34
VfsAttachment
(
VFS::FilesystemPin
&& pin, uint64_t
identity
)
35
: backing(pedigree_std::move(pin)), root(backing.filesystem()->getRoot()), id(
identity
) {}
36
~VfsAttachment
();
37
VFS
* owningRegistry =
nullptr
;
38
VFS::FilesystemPin
backing;
39
File
*
const
root;
40
const
uint64_t id;
41
Atomic<size_t>
paths
{0};
42
};
43
using
VfsAttachmentRef
=
SharedPointer<VfsAttachment>
;
44
45
class
VfsPath
final :
public
FilesystemPath
{
46
public
:
47
enum class
Kind { Mounted, Anonymous };
48
VfsPath
(
VfsMountView
& owner,
const
VfsAttachmentRef
& attachment,
VfsNodeReference
&& node);
49
VfsPath
(
VfsMountView
& owner,
VfsNodeReference
&& anonymousNode);
50
const
Kind kind;
51
~VfsPath
()
override
;
52
File
* node()
const override
{
53
return
file.get();
54
}
55
const
void
* provider()
const override
{
56
return
&view;
57
}
58
VfsMountView
& view;
59
VfsAttachmentRef
attachment;
60
VfsNodeReference
file;
61
};
62
63
struct
VfsAttachmentRow
{
64
VfsAttachmentRef
attachment;
65
VfsAttachmentRef
parent;
66
SharedPointer<VfsNodeReference>
covered;
67
VfsAttachmentRow
* next =
nullptr
;
68
};
69
struct
VfsContextRow
{
70
FilesystemContextRef
context;
71
VfsContextRow
* next =
nullptr
;
72
};
73
74
class
VfsFilesystemContext
final :
public
FilesystemContext
{
75
public
:
76
explicit
VfsFilesystemContext
(
VfsMountView
& owner) : view(owner) {}
77
~VfsFilesystemContext
()
override
;
78
bool
snapshot(
FilesystemContextSnapshot
& result)
const override
;
79
bool
forkForProcess(
FilesystemContextOwner
& result)
const override
;
80
void
retireProcessOwner()
override
;
81
82
VfsMountView
& view;
83
FilesystemPathRef
root;
84
FilesystemPathRef
cwd;
85
uint64_t generation = 1;
86
VfsContextRow
* registration =
nullptr
;
87
};
88
89
struct
VfsMountView::State
{
90
explicit
State
(
VfsMountView
& owner) : view(owner) {}
91
~State
();
92
VfsMountView
& view;
93
Mutex
graph;
94
Atomic<size_t>
anonymousPaths{0};
95
VfsAttachmentRow
* attachments =
nullptr
;
96
VfsContextRow
* contexts =
nullptr
;
97
size_t
contextCount = 0;
98
uint64_t topology = 1;
99
uint64_t rootId = 0;
100
uint64_t nextId = 1;
101
102
VfsAttachmentRow
* find(uint64_t
id
)
const
;
103
VfsAttachmentRow
* at(
const
VfsPath
& path)
const
;
104
bool
contains(
const
FilesystemPathRef
& path)
const
;
105
VfsPath
* nodePath(
const
FilesystemPathRef
& reference)
const
;
106
VfsPath
* path(
const
FilesystemPathRef
& reference)
const
;
107
bool
makePath(
const
VfsAttachmentRef
& attachment,
File
* node,
FilesystemPathRef
& result);
108
bool
context(
const
FilesystemContextRef
& reference,
VfsFilesystemContext
*& result)
const
;
109
bool
createContext(
const
VfsFilesystemContext
* parent,
FilesystemContextOwner
& result);
110
bool
cross(
const
FilesystemPathRef
& path,
FilesystemPathRef
& result);
111
bool
parent(
const
FilesystemPathRef
& path,
FilesystemPathRef
& result,
112
const
FilesystemPathRef
& boundary =
FilesystemPathRef
());
113
bool
beneath(
const
FilesystemPathRef
& descendant,
const
FilesystemPathRef
& ancestor);
114
bool
format(
const
FilesystemContextSnapshot
& context,
const
FilesystemPathRef
& path,
115
String
& result,
const
VFS::NamespaceMutation
& writer);
116
bool
resolve(
const
FilesystemContextSnapshot
& context,
const
FilesystemPathRef
& start,
117
const
String
& pathname,
const
ResolveOptions
&
options
,
FilesystemPathRef
& result,
118
const
VFS::NamespaceMutation
* writer =
nullptr
);
119
bool
follow(
const
FilesystemContextSnapshot
& context,
const
FilesystemPathRef
& selected,
120
const
ResolveOptions
&
options
,
FilesystemPathRef
& result,
size_t
& links);
121
bool
walk(
const
FilesystemContextSnapshot
& context,
const
FilesystemPathRef
& start,
122
const
String
& pathname,
const
ResolveOptions
&
options
,
FilesystemPathRef
& result,
123
size_t
& links);
124
bool
attach(
const
FilesystemPathRef
& covered,
VFS::FilesystemPin
&& pin,
125
const
VFS::NamespaceMutation
& writer, BackingOwnership ownership);
126
void
reapDetached();
127
};
128
#endif
Atomic
Definition
Atomic.h:35
File
Definition
File.h:74
FilesystemContextOwner
Definition
FilesystemContext.h:41
FilesystemContext
Definition
FilesystemContext.h:30
FilesystemPath
Definition
FilesystemContext.h:13
Filesystem
Definition
Filesystem.h:40
Mutex
Definition
Mutex.h:56
SharedPointer< VfsAttachment >
String
Definition
String.h:43
VFS::FilesystemPin
Definition
VFS.h:138
VFS::NamespaceMutation
Definition
VFS.h:60
VFS
Definition
VFS.h:58
VfsAttachment
Definition
MountView-internal.h:32
VfsFilesystemContext
Definition
MountView-internal.h:74
VfsMountView
Definition
MountView.h:17
VfsNodeReference
Definition
MountView-internal.h:12
VfsPath
Definition
MountView-internal.h:45
FilesystemContextSnapshot
Definition
FilesystemContext.h:22
VfsAttachmentRow
Definition
MountView-internal.h:63
VfsContextRow
Definition
MountView-internal.h:69
VfsMountView::ResolveOptions
Definition
MountView.h:19
VfsMountView::State
Definition
MountView-internal.h:89
identity
Definition
futex-contracts.c:32
options
Definition
vfork-benchmark/main.c:28
paths
Definition
xattr-contract-test/persistence.c:10
Generated on Thu Sep 24 2026 06:24:01 for The Pedigree Project by
1.9.8