diff options
author | Sergey Bugaev <bugaevc@serenityos.org> | 2020-05-28 17:32:20 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-29 07:53:30 +0200 |
commit | a9946a99f24e17644b2b7796ec8be10c8913f38b (patch) | |
tree | 99ea01a7690b0cccc86648e69c4a397a54fb1111 /Kernel/FileSystem | |
parent | 67cbc015d53df09b7ef4e70ee818e3f16e6c37dc (diff) | |
download | serenity-a9946a99f24e17644b2b7796ec8be10c8913f38b.zip |
Kernel: Pass a FileDescription to File::chmod() and File::chown()
We're going to make use of it in the next commit. But the idea is we want to
know how this File (more specifically, InodeFile) was opened in order to decide
how chown()/chmod() should behave, in particular whether it should be allowed or
not. Note that many other File operations, such as read(), write(), and ioctl(),
already require the caller to pass a FileDescription.
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r-- | Kernel/FileSystem/File.h | 4 | ||||
-rw-r--r-- | Kernel/FileSystem/FileDescription.cpp | 4 | ||||
-rw-r--r-- | Kernel/FileSystem/InodeFile.cpp | 6 | ||||
-rw-r--r-- | Kernel/FileSystem/InodeFile.h | 4 |
4 files changed, 10 insertions, 8 deletions
diff --git a/Kernel/FileSystem/File.h b/Kernel/FileSystem/File.h index 0ba1fb239f..02fc614326 100644 --- a/Kernel/FileSystem/File.h +++ b/Kernel/FileSystem/File.h @@ -82,8 +82,8 @@ public: virtual String absolute_path(const FileDescription&) const = 0; virtual KResult truncate(u64) { return KResult(-EINVAL); } - virtual KResult chown(uid_t, gid_t) { return KResult(-EBADF); } - virtual KResult chmod(mode_t) { return KResult(-EBADF); } + virtual KResult chown(FileDescription&, uid_t, gid_t) { return KResult(-EBADF); } + virtual KResult chmod(FileDescription&, mode_t) { return KResult(-EBADF); } virtual const char* class_name() const = 0; diff --git a/Kernel/FileSystem/FileDescription.cpp b/Kernel/FileSystem/FileDescription.cpp index 6b7e4a507a..984eadfd50 100644 --- a/Kernel/FileSystem/FileDescription.cpp +++ b/Kernel/FileSystem/FileDescription.cpp @@ -330,13 +330,13 @@ void FileDescription::set_file_flags(u32 flags) KResult FileDescription::chmod(mode_t mode) { LOCKER(m_lock); - return m_file->chmod(mode); + return m_file->chmod(*this, mode); } KResult FileDescription::chown(uid_t uid, gid_t gid) { LOCKER(m_lock); - return m_file->chown(uid, gid); + return m_file->chown(*this, uid, gid); } } diff --git a/Kernel/FileSystem/InodeFile.cpp b/Kernel/FileSystem/InodeFile.cpp index a5f8550c3d..3e24434506 100644 --- a/Kernel/FileSystem/InodeFile.cpp +++ b/Kernel/FileSystem/InodeFile.cpp @@ -97,13 +97,15 @@ KResult InodeFile::truncate(u64 size) return KSuccess; } -KResult InodeFile::chown(uid_t uid, gid_t gid) +KResult InodeFile::chown(FileDescription& description, uid_t uid, gid_t gid) { + ASSERT(description.inode() == m_inode); return VFS::the().chown(*m_inode, uid, gid); } -KResult InodeFile::chmod(mode_t mode) +KResult InodeFile::chmod(FileDescription& description, mode_t mode) { + ASSERT(description.inode() == m_inode); return VFS::the().chmod(*m_inode, mode); } diff --git a/Kernel/FileSystem/InodeFile.h b/Kernel/FileSystem/InodeFile.h index 14e8f335ed..46ddc9e86e 100644 --- a/Kernel/FileSystem/InodeFile.h +++ b/Kernel/FileSystem/InodeFile.h @@ -54,8 +54,8 @@ public: virtual String absolute_path(const FileDescription&) const override; virtual KResult truncate(u64) override; - virtual KResult chown(uid_t, gid_t) override; - virtual KResult chmod(mode_t) override; + virtual KResult chown(FileDescription&, uid_t, gid_t) override; + virtual KResult chmod(FileDescription&, mode_t) override; virtual const char* class_name() const override { return "InodeFile"; } |