Kernel: Make VirtualFileSystem::File non copyable

This commit is contained in:
2024-09-14 19:44:51 +03:00
parent 6060b39548
commit 3a352078de
5 changed files with 30 additions and 7 deletions

View File

@@ -24,6 +24,29 @@ namespace Kernel
struct File
{
File() = default;
explicit File(BAN::RefPtr<Inode> inode)
: inode(BAN::move(inode))
{ }
explicit File(BAN::RefPtr<Inode> inode, BAN::String&& canonical_path)
: inode(BAN::move(inode))
, canonical_path(BAN::move(canonical_path))
{ }
File(const File&) = delete;
File(File&& other)
: inode(BAN::move(other.inode))
, canonical_path(BAN::move(other.canonical_path))
{ }
File& operator=(const File&) = delete;
File& operator=(File&& other)
{
inode = BAN::move(other.inode);
canonical_path = BAN::move(other.canonical_path);
return *this;
}
BAN::RefPtr<Inode> inode;
BAN::String canonical_path;
};
@@ -31,7 +54,7 @@ namespace Kernel
BAN::ErrorOr<File> file_from_relative_path(const File& parent, const Credentials&, BAN::StringView, int);
BAN::ErrorOr<File> file_from_absolute_path(const Credentials& credentials, BAN::StringView path, int flags)
{
return file_from_relative_path({ .inode = root_inode(), .canonical_path = {} }, credentials, path, flags);
return file_from_relative_path(File(root_inode()), credentials, path, flags);
}
private:

View File

@@ -101,7 +101,7 @@ namespace Kernel
BAN::ErrorOr<long> sys_getpid() const { return pid(); }
BAN::ErrorOr<long> open_inode(BAN::RefPtr<Inode>, int flags);
BAN::ErrorOr<long> open_inode(VirtualFileSystem::File&&, int flags);
BAN::ErrorOr<void> create_file_or_dir(BAN::StringView name, mode_t mode);
BAN::ErrorOr<long> open_file(BAN::StringView path, int oflag, mode_t = 0);