The Pedigree Project 0.1
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
10class File;
11
13class 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};
21
23class EXPORTED_PUBLIC FilesystemWriteLease {
24 public:
25 virtual ~FilesystemWriteLease() = default;
26};
27
28struct EXPORTED_PUBLIC FilesystemContextSnapshot {
31 uint64_t contextGeneration = 0;
32 uint64_t topologyGeneration = 0;
33};
34
35class EXPORTED_PUBLIC FilesystemContextOwner;
36class EXPORTED_PUBLIC FilesystemContext {
37 public:
38 virtual ~FilesystemContext() = default;
39 virtual const void* provider() const {
40 return nullptr;
41 }
42 virtual bool snapshot(FilesystemContextSnapshot& result) const = 0;
43 // The provider enrolls the unpublished child before returning success.
44 virtual bool forkForProcess(FilesystemContextOwner& result) const = 0;
45 virtual void retireProcessOwner() = 0;
46};
48
50class EXPORTED_PUBLIC FilesystemContextOwner {
51 public:
52 FilesystemContextOwner() = default;
54 : m_Context(pedigree_std::move(other.m_Context)) {}
55 FilesystemContextOwner& operator=(FilesystemContextOwner&& other) noexcept {
56 if (this != &other) {
57 reset();
58 m_Context = pedigree_std::move(other.m_Context);
59 }
60 return *this;
61 }
63 reset();
64 }
65
66 FilesystemContextRef reference() const {
67 return m_Context;
68 }
69 explicit operator bool() const {
70 return static_cast<bool>(m_Context);
71 }
72 void reset() {
73 FilesystemContextRef retired(pedigree_std::move(m_Context));
74 if (retired)
75 retired->retireProcessOwner();
76 }
77 // Providers call this only after enrollment, with the original control block.
78 static FilesystemContextOwner adopt(FilesystemContextRef&& context) {
80 result.m_Context = pedigree_std::move(context);
81 return result;
82 }
83
84 private:
86 FilesystemContextOwner& operator=(const FilesystemContextOwner&) = delete;
87 FilesystemContextRef m_Context;
88};
89
90#endif
Definition File.h:75