From 06e95d0fd74a93858e5f4d0e1d32e92631e649ff Mon Sep 17 00:00:00 2001 From: Liav A Date: Sat, 11 Sep 2021 12:03:44 +0300 Subject: [PATCH] Kernel/SysFS: Make it possible to have custom permissions for nodes --- Kernel/FileSystem/SysFS.cpp | 2 +- Kernel/FileSystem/SysFSComponent.cpp | 5 +++++ Kernel/FileSystem/SysFSComponent.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Kernel/FileSystem/SysFS.cpp b/Kernel/FileSystem/SysFS.cpp index d0447ee4f8..bedf3d6353 100644 --- a/Kernel/FileSystem/SysFS.cpp +++ b/Kernel/FileSystem/SysFS.cpp @@ -140,7 +140,7 @@ InodeMetadata SysFSInode::metadata() const // NOTE: No locking required as m_associated_component or its component index will never change during our lifetime. InodeMetadata metadata; metadata.inode = { fsid(), m_associated_component->component_index() }; - metadata.mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH; + metadata.mode = S_IFREG | m_associated_component->permissions(); metadata.uid = 0; metadata.gid = 0; metadata.size = 0; diff --git a/Kernel/FileSystem/SysFSComponent.cpp b/Kernel/FileSystem/SysFSComponent.cpp index 1df44166b3..a2cd1db4e6 100644 --- a/Kernel/FileSystem/SysFSComponent.cpp +++ b/Kernel/FileSystem/SysFSComponent.cpp @@ -26,6 +26,11 @@ SysFSComponent::SysFSComponent(StringView name) { } +mode_t SysFSComponent::permissions() const +{ + return S_IRUSR | S_IRGRP | S_IROTH; +} + KResult SysFSDirectory::traverse_as_directory(unsigned fsid, Function callback) const { MutexLocker locker(SysFSComponentRegistry::the().get_lock()); diff --git a/Kernel/FileSystem/SysFSComponent.h b/Kernel/FileSystem/SysFSComponent.h index 1525014bf7..c6711a3c47 100644 --- a/Kernel/FileSystem/SysFSComponent.h +++ b/Kernel/FileSystem/SysFSComponent.h @@ -29,6 +29,7 @@ public: virtual KResultOr read_bytes(off_t, size_t, UserOrKernelBuffer&, OpenFileDescription*) const { VERIFY_NOT_REACHED(); } virtual KResult traverse_as_directory(unsigned, Function) const { VERIFY_NOT_REACHED(); } virtual RefPtr lookup(StringView) { VERIFY_NOT_REACHED(); }; + virtual mode_t permissions() const; virtual KResultOr write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) { return EROFS; } virtual KResult refresh_data(OpenFileDescription&) const { return KSuccess; }