/* * Copyright (c) 2018-2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include namespace Kernel { class Inode; class InodeFile final : public File { public: static ErrorOr> create(NonnullRefPtr&& inode) { auto file = adopt_ref_if_nonnull(new (nothrow) InodeFile(move(inode))); if (!file) return ENOMEM; return file.release_nonnull(); } virtual ~InodeFile() override; const Inode& inode() const { return *m_inode; } Inode& inode() { return *m_inode; } virtual bool can_read(const OpenFileDescription&, size_t) const override { return true; } virtual bool can_write(const OpenFileDescription&, size_t) const override { return true; } virtual ErrorOr read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override; virtual ErrorOr write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override; virtual ErrorOr ioctl(OpenFileDescription&, unsigned request, Userspace arg) override; virtual ErrorOr mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override; virtual ErrorOr stat(::stat& buffer) const override { return inode().metadata().stat(buffer); } virtual ErrorOr> pseudo_path(const OpenFileDescription&) const override; virtual ErrorOr truncate(u64) override; virtual ErrorOr sync() override; virtual ErrorOr chown(OpenFileDescription&, UserID, GroupID) override; virtual ErrorOr chmod(OpenFileDescription&, mode_t) override; virtual StringView class_name() const override { return "InodeFile"sv; } virtual bool is_seekable() const override { return true; } virtual bool is_inode() const override { return true; } private: explicit InodeFile(NonnullRefPtr&&); NonnullRefPtr m_inode; }; }