From c4e30c3029885c54707841496a28e779e0eb3508 Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 27 Jul 2023 16:36:36 +0200 Subject: [PATCH] kernel: Add functionality to allow external inodes (such as sockets) to acquire an inode number from a file system This is only implemented in tmpfs. --- kernel/src/fs/VFS.h | 5 +++++ kernel/src/fs/tmpfs/FileSystem.cpp | 5 +++++ kernel/src/fs/tmpfs/FileSystem.h | 2 ++ 3 files changed, 12 insertions(+) diff --git a/kernel/src/fs/VFS.h b/kernel/src/fs/VFS.h index 3dc369fb..b38dc171 100644 --- a/kernel/src/fs/VFS.h +++ b/kernel/src/fs/VFS.h @@ -35,6 +35,11 @@ namespace VFS virtual Result> create_symlink_inode(StringView link) = 0; + virtual Result allocate_inode_number() + { + return err(ENOTSUP); + } + virtual Result set_mount_dir(SharedPtr parent) = 0; virtual Result reset_mount_dir() = 0; diff --git a/kernel/src/fs/tmpfs/FileSystem.cpp b/kernel/src/fs/tmpfs/FileSystem.cpp index e871e2b5..71d0488c 100644 --- a/kernel/src/fs/tmpfs/FileSystem.cpp +++ b/kernel/src/fs/tmpfs/FileSystem.cpp @@ -16,6 +16,11 @@ namespace TmpFS return (SharedPtr)fs; } + Result FileSystem::allocate_inode_number() + { + return m_next_inode_number++; + } + Result> FileSystem::create_file_inode() { SharedPtr inode = TRY(make_shared()); diff --git a/kernel/src/fs/tmpfs/FileSystem.h b/kernel/src/fs/tmpfs/FileSystem.h index 2542c740..2d598a9c 100644 --- a/kernel/src/fs/tmpfs/FileSystem.h +++ b/kernel/src/fs/tmpfs/FileSystem.h @@ -18,6 +18,8 @@ namespace TmpFS Result> create_device_inode(u32 major, u32 minor) override; Result> create_symlink_inode(StringView link) override; + Result allocate_inode_number() override; + Result set_mount_dir(SharedPtr parent) override; Result reset_mount_dir() override;