The Pedigree Project
0.1
src
system
include
pedigree
kernel
process
FilesystemContext.h
1
/* Copyright (c) 2026, Pedigree Developers. */
2
#ifndef PEDIGREE_PROCESS_FILESYSTEMCONTEXT_H
3
#define PEDIGREE_PROCESS_FILESYSTEMCONTEXT_H
4
5
#include "pedigree/kernel/compiler.h"
6
#include "pedigree/kernel/processor/types.h"
7
#include "pedigree/kernel/utilities/SharedPointer.h"
8
#include "pedigree/kernel/utilities/utility.h"
9
10
class
File
;
11
13
class
EXPORTED_PUBLIC
FilesystemPath
{
14
public
:
15
virtual
~FilesystemPath
() =
default
;
16
// Borrowed for the lifetime of the path reference, including after detach.
17
virtual
File
* node()
const
= 0;
18
virtual
const
void
* provider()
const
= 0;
19
};
20
using
FilesystemPathRef
=
SharedPointer<FilesystemPath>
;
21
22
struct
EXPORTED_PUBLIC
FilesystemContextSnapshot
{
23
FilesystemPathRef
root;
24
FilesystemPathRef
cwd;
25
uint64_t contextGeneration = 0;
26
uint64_t topologyGeneration = 0;
27
};
28
29
class
EXPORTED_PUBLIC
FilesystemContextOwner
;
30
class
EXPORTED_PUBLIC
FilesystemContext
{
31
public
:
32
virtual
~FilesystemContext
() =
default
;
33
virtual
bool
snapshot(
FilesystemContextSnapshot
& result)
const
= 0;
34
// The provider enrolls the unpublished child before returning success.
35
virtual
bool
forkForProcess(
FilesystemContextOwner
& result)
const
= 0;
36
virtual
void
retireProcessOwner() = 0;
37
};
38
using
FilesystemContextRef
=
SharedPointer<FilesystemContext>
;
39
41
class
EXPORTED_PUBLIC
FilesystemContextOwner
{
42
public
:
43
FilesystemContextOwner
() =
default
;
44
FilesystemContextOwner
(
FilesystemContextOwner
&& other) noexcept
45
: m_Context(pedigree_std::move(other.m_Context)) {}
46
FilesystemContextOwner
& operator=(
FilesystemContextOwner
&& other)
noexcept
{
47
if
(
this
!= &other) {
48
reset();
49
m_Context = pedigree_std::move(other.m_Context);
50
}
51
return
*
this
;
52
}
53
~FilesystemContextOwner
() {
54
reset();
55
}
56
57
FilesystemContextRef
reference()
const
{
58
return
m_Context;
59
}
60
explicit
operator
bool()
const
{
61
return
static_cast<
bool
>
(m_Context);
62
}
63
void
reset() {
64
FilesystemContextRef
retired(pedigree_std::move(m_Context));
65
if
(retired)
66
retired->retireProcessOwner();
67
}
68
// Providers call this only after enrollment, with the original control block.
69
static
FilesystemContextOwner
adopt(
FilesystemContextRef
&& context) {
70
FilesystemContextOwner
result;
71
result.m_Context = pedigree_std::move(context);
72
return
result;
73
}
74
75
private
:
76
FilesystemContextOwner
(
const
FilesystemContextOwner
&) =
delete
;
77
FilesystemContextOwner
& operator=(
const
FilesystemContextOwner
&) =
delete
;
78
FilesystemContextRef
m_Context;
79
};
80
81
#endif
File
Definition
File.h:74
FilesystemContextOwner
Definition
FilesystemContext.h:41
FilesystemContext
Definition
FilesystemContext.h:30
FilesystemPath
Definition
FilesystemContext.h:13
SharedPointer< FilesystemPath >
FilesystemContextSnapshot
Definition
FilesystemContext.h:22
Generated on Tue Sep 22 2026 06:05:49 for The Pedigree Project by
1.9.8