From 69a0600d4517a630d47c64d0e82c81768aaf434d Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 14 Sep 2023 22:55:54 +0200 Subject: [PATCH] kernel: Allow performing extra actions when opening an inode --- kernel/src/fs/VFS.h | 5 +++++ kernel/src/sys/open.cpp | 2 ++ 2 files changed, 7 insertions(+) diff --git a/kernel/src/fs/VFS.h b/kernel/src/fs/VFS.h index 2a63f68e..dbe471ee 100644 --- a/kernel/src/fs/VFS.h +++ b/kernel/src/fs/VFS.h @@ -118,6 +118,11 @@ namespace VFS return err(EACCES); } + virtual Result> open() + { + return SharedPtr { this }; + } + // Directory-specific methods virtual Result> find(const char* name) const = 0; diff --git a/kernel/src/sys/open.cpp b/kernel/src/sys/open.cpp index 90d5d84a..0f0d03f2 100644 --- a/kernel/src/sys/open.cpp +++ b/kernel/src/sys/open.cpp @@ -62,6 +62,8 @@ Result sys_openat(Registers*, SyscallArgs args) if ((flags & O_WRONLY) && !VFS::can_write(inode, current->auth)) return err(EACCES); } + inode = TRY(inode->open()); + // This should only be possible if O_NOFOLLOW was in flags. if (inode->type() == VFS::InodeType::Symlink) return err(ELOOP);