The Pedigree Project 0.1
namespace-file.cc
1/* Copyright (c) 2026, Pedigree Developers. */
2#include "namespace-file.h"
3#include "pedigree/kernel/syscallError.h"
4
6#include "modules/system/vfs/VFS.h"
7
8namespace {
9class NamespaceFilesystem final : public RamFs {
10 public:
11 NamespaceFilesystem() {
12 setProcessOwnership(false);
13 }
14};
15NamespaceFilesystem filesystem;
16
17class NamespaceFile final : public File {
18 public:
19 explicit NamespaceFile(const UtsRef& space)
20 : File(String("uts"), 0, 0, 0, static_cast<uintptr_t>(space->identity()), &filesystem, 0,
21 nullptr),
22 m_Space(space) {
23 Attributes attributes;
24 attributes.uid = attributes.gid = 0;
25 attributes.permissions = FILE_UR | FILE_GR | FILE_OR;
26 updateAttributes(attributes, Owner | Group | Permissions);
27 }
28 const UtsRef& space() const {
29 return m_Space;
30 }
31 bool isSeekable() const override {
32 return false;
33 }
34 bool allowMapping(bool, bool, bool&) override {
35 SYSCALL_ERROR(NoSuchDevice);
36 return false;
37 }
38
39 protected:
40 bool allowResize(size_t, size_t) override {
41 SYSCALL_ERROR(InvalidArgument);
42 return false;
43 }
44 bool isBytewise() const override {
45 return true;
46 }
47 uint64_t readBytewise(uint64_t, uint64_t, uintptr_t, bool) override {
48 SYSCALL_ERROR(InvalidArgument);
49 return 0;
50 }
51 uint64_t writeBytewise(uint64_t, uint64_t, uintptr_t, bool) override {
52 SYSCALL_ERROR(InvalidArgument);
53 return 0;
54 }
55
56 private:
57 UtsRef m_Space;
58};
59} // namespace
60
61UtsStatus posix_uts_make_file(const UtsRef& space, RetainedFile& result) {
62 if (!space)
63 return UtsStatus::Missing;
64 auto* file = new NamespaceFile(space);
65 if (!file)
66 return UtsStatus::NoMemory;
67 if (!VFS::instance().tryTrackFile(file)) {
68 delete file;
69 return UtsStatus::NoMemory;
70 }
71 result.adopt(file);
72 return UtsStatus::Success;
73}
74
75bool posix_uts_file_namespace(File* file, UtsRef& result) {
76 if (!file || file->getFilesystem() != &filesystem)
77 return false;
78 result = static_cast<NamespaceFile*>(file)->space();
79 return true;
80}
An in-RAM filesystem.
Definition File.h:75
virtual uint64_t readBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
Definition File.cc:1369
virtual bool isSeekable() const
Definition File.cc:820
virtual bool isBytewise() const
Definition File.cc:1365
virtual bool allowMapping(bool shared, bool writeRequested, bool &mayWrite)
Definition File.cc:1177
virtual uint64_t writeBytewise(uint64_t location, uint64_t size, uintptr_t buffer, bool bCanBlock=true)
Definition File.cc:1376
Definition Group.h:32
Definition RamFs.h:118
static VFS & instance()
Definition VFS.cc:311