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
22struct EXPORTED_PUBLIC FilesystemContextSnapshot {
25 uint64_t contextGeneration = 0;
26 uint64_t topologyGeneration = 0;
27};
28
29class EXPORTED_PUBLIC FilesystemContextOwner;
30class 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};
39
41class EXPORTED_PUBLIC FilesystemContextOwner {
42 public:
43 FilesystemContextOwner() = default;
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 }
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) {
71 result.m_Context = pedigree_std::move(context);
72 return result;
73 }
74
75 private:
77 FilesystemContextOwner& operator=(const FilesystemContextOwner&) = delete;
78 FilesystemContextRef m_Context;
79};
80
81#endif
Definition File.h:74