The Pedigree Project 0.1
MemoryExtendedAttributes.h
1/* Copyright (c) 2026, Pedigree Developers. */
2#ifndef PEDIGREE_VFS_MEMORYEXTENDEDATTRIBUTES_H
3#define PEDIGREE_VFS_MEMORYEXTENDEDATTRIBUTES_H
4
5#include "pedigree/kernel/compiler.h"
6#include "pedigree/kernel/process/Mutex.h"
7#include "pedigree/kernel/utilities/StringView.h"
8
9#include "ExtendedAttributes.h"
10
11class EXPORTED_PUBLIC MemoryExtendedAttributes {
12 public:
13 static constexpr size_t MaximumEntries = 128;
14 static constexpr size_t MaximumStoreBytes = 256 * 1024;
15 static constexpr size_t MaximumTotalBytes = 16 * 1024 * 1024;
16
17 class EXPORTED_PUBLIC Quota {
18 public:
19 explicit Quota(size_t limit = MaximumTotalBytes) : m_Limit(limit) {}
20 size_t used() const;
21
22 private:
23 friend class MemoryExtendedAttributes;
24 NOT_COPYABLE_OR_ASSIGNABLE(Quota);
25 bool increase(size_t amount);
26 void decrease(size_t amount);
27 const size_t m_Limit;
28 size_t m_Used = 0;
29 };
30
31 static Quota& globalQuota();
32 explicit MemoryExtendedAttributes(Quota& quota = globalQuota());
34
35 XattrStatus get(const StringView& name, void* buffer, size_t capacity, size_t& required);
36 XattrStatus list(void* buffer, size_t capacity, size_t& required);
37 XattrStatus set(const StringView& name, const void* value, size_t length, unsigned flags);
38 XattrStatus remove(const StringView& name);
39
40 private:
41 NOT_COPYABLE_OR_ASSIGNABLE(MemoryExtendedAttributes);
42 struct Entry;
43 struct PreparedEntry;
44 Entry** find(const StringView& name);
45 Mutex m_Lock;
46 Quota& m_Quota;
47 Entry* m_Entries = nullptr;
48 size_t m_Count = 0;
49 size_t m_Bytes = 0;
50};
51
52#endif
Definition Mutex.h:56