/* * Copyright (c) 2018-2021, Andreas Kling * Copyright (c) 2021, sin-ack * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include namespace Kernel { enum class ShouldBlock { No = 0, Yes = 1 }; class Inode : public ListedRefCounted , public LockWeakable { friend class VirtualFileSystem; friend class FileSystem; friend class InodeFile; public: virtual ~Inode(); virtual void remove_from_secondary_lists() { } FileSystem& fs() { return m_file_system; } FileSystem const& fs() const { return m_file_system; } FileSystemID fsid() const { return m_file_system.fsid(); } InodeIndex index() const { return m_index; } size_t size() const { return metadata().size; } bool is_symlink() const { return metadata().is_symlink(); } bool is_directory() const { return metadata().is_directory(); } bool is_character_device() const { return metadata().is_character_device(); } mode_t mode() const { return metadata().mode; } InodeIdentifier identifier() const { return { fsid(), index() }; } virtual InodeMetadata metadata() const = 0; ErrorOr> read_entire(OpenFileDescription* = nullptr) const; ErrorOr write_bytes(off_t, size_t, UserOrKernelBuffer const& data, OpenFileDescription*); ErrorOr read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const; virtual ErrorOr attach(OpenFileDescription&) { return {}; } virtual void detach(OpenFileDescription&) { } virtual void did_seek(OpenFileDescription&, off_t) { } virtual ErrorOr traverse_as_directory(Function(FileSystem::DirectoryEntryView const&)>) const = 0; virtual ErrorOr> lookup(StringView name) = 0; virtual ErrorOr> create_child(StringView name, mode_t, dev_t, UserID, GroupID) = 0; virtual ErrorOr add_child(Inode&, StringView name, mode_t) = 0; virtual ErrorOr remove_child(StringView name) = 0; /// Replace child atomically, incrementing the link count of the replacement /// inode and decrementing the older inode's. virtual ErrorOr replace_child(StringView name, Inode&) = 0; virtual ErrorOr chmod(mode_t) = 0; virtual ErrorOr chown(UserID, GroupID) = 0; virtual ErrorOr truncate(u64) { return {}; } ErrorOr> resolve_as_link(Credentials const&, Custody& base, RefPtr* out_parent, int options, int symlink_recursion_level) const; virtual ErrorOr get_block_address(int) { return ENOTSUP; } LockRefPtr bound_socket() const; bool bind_socket(LocalSocket&); bool unbind_socket(); bool is_metadata_dirty() const { return m_metadata_dirty; } virtual ErrorOr update_timestamps(Optional