Kernel: Make VirtualFileSystem::File non copyable
This commit is contained in:
parent
6060b39548
commit
3a352078de
|
@ -24,6 +24,29 @@ namespace Kernel
|
||||||
|
|
||||||
struct File
|
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::RefPtr<Inode> inode;
|
||||||
BAN::String canonical_path;
|
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_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)
|
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:
|
private:
|
||||||
|
|
|
@ -101,7 +101,7 @@ namespace Kernel
|
||||||
|
|
||||||
BAN::ErrorOr<long> sys_getpid() const { return pid(); }
|
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<void> create_file_or_dir(BAN::StringView name, mode_t mode);
|
||||||
BAN::ErrorOr<long> open_file(BAN::StringView path, int oflag, mode_t = 0);
|
BAN::ErrorOr<long> open_file(BAN::StringView path, int oflag, mode_t = 0);
|
||||||
|
|
|
@ -123,7 +123,7 @@ namespace Kernel
|
||||||
memcpy(address, &connection.target.address, *address_len);
|
memcpy(address, &connection.target.address, *address_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRY(Process::current().open_inode(return_inode, O_RDWR | flags));
|
return TRY(Process::current().open_inode(VirtualFileSystem::File(return_inode, "<tcp socket>"_sv), O_RDWR | flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<void> TCPSocket::connect_impl(const sockaddr* address, socklen_t address_len)
|
BAN::ErrorOr<void> TCPSocket::connect_impl(const sockaddr* address, socklen_t address_len)
|
||||||
|
|
|
@ -104,7 +104,7 @@ namespace Kernel
|
||||||
strncpy(sockaddr_un.sun_path, pending->m_bound_path.data(), copy_len);
|
strncpy(sockaddr_un.sun_path, pending->m_bound_path.data(), copy_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRY(Process::current().open_inode(return_inode, O_RDWR | flags));
|
return TRY(Process::current().open_inode(VirtualFileSystem::File(return_inode, "<unix socket>"_sv), O_RDWR | flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<void> UnixDomainSocket::connect_impl(const sockaddr* address, socklen_t address_len)
|
BAN::ErrorOr<void> UnixDomainSocket::connect_impl(const sockaddr* address, socklen_t address_len)
|
||||||
|
|
|
@ -875,11 +875,11 @@ namespace Kernel
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<long> Process::open_inode(BAN::RefPtr<Inode> inode, int flags)
|
BAN::ErrorOr<long> Process::open_inode(VirtualFileSystem::File&& file, int flags)
|
||||||
{
|
{
|
||||||
ASSERT(inode);
|
ASSERT(file.inode);
|
||||||
LockGuard _(m_process_lock);
|
LockGuard _(m_process_lock);
|
||||||
return TRY(m_open_file_descriptors.open(VirtualFileSystem::File { .inode = inode, .canonical_path = {} }, flags));
|
return TRY(m_open_file_descriptors.open(BAN::move(file), flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
BAN::ErrorOr<long> Process::open_file(BAN::StringView path, int flags, mode_t mode)
|
BAN::ErrorOr<long> Process::open_file(BAN::StringView path, int flags, mode_t mode)
|
||||||
|
|
Loading…
Reference in New Issue