The Pedigree Project 0.1
MountView.h
1/* Copyright (c) 2026, Pedigree Developers. */
2#ifndef PEDIGREE_VFS_MOUNTVIEW_H
3#define PEDIGREE_VFS_MOUNTVIEW_H
4
5#include "pedigree/kernel/process/FilesystemContext.h"
6#include "pedigree/kernel/process/Mutex.h"
7#include "pedigree/kernel/utilities/String.h"
8#include "pedigree/kernel/utilities/Vector.h"
9
10#include "VFS.h"
11
12class VfsPath;
14class VfsAttachment;
15
17class EXPORTED_PUBLIC VfsMountView {
18 public:
20 bool followFinal = true;
21 bool requireDirectory = false;
22 bool crossFinalMount = true;
23 };
25 uint64_t id = 0;
26 uint64_t parentId = 0;
27 VFS::MountIdentity backing;
28 String path;
29 String root;
30 uint64_t flags = 0;
31 };
32 enum MountFlags : uint64_t { ReadOnly = 1, NoSuid = 2, NoDev = 4, NoExec = 8 };
33 static constexpr uint64_t SupportedMountFlags = ReadOnly | NoSuid | NoDev | NoExec;
34 class WriteLease final : public FilesystemWriteLease {
35 public:
36 WriteLease() = default;
37 ~WriteLease() override;
38 bool acquire(const FilesystemPathRef& path);
39
40 private:
41 WriteLease(const WriteLease&) = delete;
42 WriteLease& operator=(const WriteLease&) = delete;
43 FilesystemPathRef m_Path;
44 };
45 static bool retainWrite(const FilesystemPathRef& path,
47
48 explicit VfsMountView(VFS& vfs);
50 bool initialise(Filesystem* bootRoot);
51 bool createBootContext(FilesystemContextOwner& result);
52 static VfsMountView* fromContext(const FilesystemContextRef& context);
53 static VfsMountView* fromPath(const FilesystemPathRef& path);
54 bool forkNamespace(const FilesystemContextRef& context, FilesystemContextOwner& result,
55 uint64_t ownerNamespace = 0);
56 uint64_t ownerNamespace() const {
57 return m_OwnerNamespace;
58 }
59 bool resolve(const FilesystemContextRef& context, const FilesystemPathRef& start,
60 const String& path, const ResolveOptions& options, FilesystemPathRef& result);
61 bool follow(const FilesystemContextRef& context, const FilesystemPathRef& selected,
62 FilesystemPathRef& result);
63 bool resolveParent(const FilesystemContextRef& context, const FilesystemPathRef& start,
64 const String& path, FilesystemPathRef& parent, String& basename);
65 bool changeCwd(const FilesystemContextRef& context, const FilesystemPathRef& path);
66 bool changeRoot(const FilesystemContextRef& context, const FilesystemPathRef& path);
67 bool formatPath(const FilesystemContextSnapshot& context, const FilesystemPathRef& path,
68 String& result);
69 bool snapshotMounts(const FilesystemContextRef& context, Vector<MountSnapshot>& result);
70
71 enum class BackingOwnership { External, Attachment };
72 // Attachment ownership transfers only after successful graph publication.
73 // Attachments identify a mounted root, independently of backing identity.
74 bool attach(const FilesystemContextRef& context, const FilesystemPathRef& covered,
75 Filesystem* backing, BackingOwnership ownership = BackingOwnership::External,
76 uint64_t flags = 0);
77 bool bind(const FilesystemContextRef& context, const FilesystemPathRef& source,
78 const FilesystemPathRef& target, bool recursive);
79 bool remount(const FilesystemContextRef& context, const FilesystemPathRef& target, uint64_t flags,
80 bool recursive = false);
81 uint64_t mountFlags(const FilesystemPathRef& path) const;
82 bool writable(const FilesystemPathRef& path) const;
83 bool detach(const FilesystemContextRef& context, const String& target, bool lazy);
84 bool detachBackingForShutdown(Filesystem* backing);
85 bool detachBackingForRemoval(Filesystem* backing);
86 bool shutdown(Vector<Filesystem*>& ownedBackings);
87 bool pivot(const FilesystemContextRef& context, const String& newRoot, const String& putOld);
88 uint64_t attachmentId(const FilesystemPathRef& path) const;
89 bool isMountpoint(File* node) const;
90 bool createFile(const FilesystemPathRef& parent, const String& name, uint32_t mask);
91 bool createDirectory(const FilesystemPathRef& parent, const String& name, uint32_t mask);
92 bool createSymlink(const FilesystemPathRef& parent, const String& name, const String& value);
93 bool createLink(const FilesystemPathRef& parent, const String& name,
94 const FilesystemPathRef& target);
95 bool remove(const FilesystemPathRef& parent, const String& name, File* expected = nullptr);
96 bool rename(const FilesystemPathRef& oldParent, const String& oldName,
97 const FilesystemPathRef& newParent, const String& newName, bool noReplace,
98 bool sourceMustBeDirectory = false);
99 bool anonymousPath(File* retainedNode, FilesystemPathRef& result);
100 bool pathForNode(const FilesystemPathRef& sameAttachment, File* retainedNode,
101 FilesystemPathRef& result);
102 bool samePath(const FilesystemPathRef& first, const FilesystemPathRef& second) const;
103 uint64_t filesystemAccess(const FilesystemPathRef& path,
104 const VFS::NamespaceMutation* writer = nullptr);
105 bool checkFilesystemAccess(const FilesystemPathRef& path, uint64_t access,
106 const VFS::NamespaceMutation* writer = nullptr);
107 bool authorizeRemove(const FilesystemPathRef& parent, File* node,
108 const VFS::NamespaceMutation& writer);
109 bool authorizeLink(const FilesystemPathRef& parent, const FilesystemPathRef& target,
110 const VFS::NamespaceMutation& writer);
111 bool authorizeRename(const FilesystemPathRef& oldParent, File* source,
112 const FilesystemPathRef& newParent, File* replaced,
113 const VFS::NamespaceMutation& writer, bool removeSource = true);
114 Directory::AddStatus createEphemeral(const FilesystemPathRef& parent, File* node,
115 uint64_t access);
116
117 // Boot/fixture enrollment only; never resolves a raw File to a guessed mount.
118 bool bootRootPath(FilesystemPathRef& result);
119#if HOSTED && PEDIGREE_HOSTED_SMOKE_TESTS
120 bool quiescentForHostedTest() const;
121#endif
122
123 private:
124 friend class VfsPath;
125 friend class VfsFilesystemContext;
126 struct State;
127 State* m_State;
128 VFS& m_Vfs;
129 size_t m_References = 1;
130 bool m_Automatic = false;
131 uint64_t m_OwnerNamespace = 0;
132 void retain();
133 void release();
134 VfsMountView(const VfsMountView&) = delete;
135 VfsMountView& operator=(const VfsMountView&) = delete;
136};
137
138#endif
Definition File.h:75
Definition VFS.h:58
A vector / dynamic array.
Definition Vector.h:33