/* * Copyright (c) 2022, Undefine * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace Kernel { class FATInode final : public Inode { friend FATFS; public: virtual ~FATInode() override = default; static ErrorOr> create(FATFS&, FATEntry, Vector const& = {}); FATFS& fs() { return static_cast(Inode::fs()); } FATFS const& fs() const { return static_cast(Inode::fs()); } private: FATInode(FATFS&, FATEntry, NonnullOwnPtr filename); static constexpr u32 no_more_clusters = 0x0FFFFFF8; static constexpr u32 cluster_number_mask = 0x0FFFFFFF; static constexpr u8 end_entry_byte = 0x00; static constexpr u8 unused_entry_byte = 0xE5; static constexpr u8 lfn_entry_text_termination = 0xFF; static constexpr u16 first_fat_year = 1980; static constexpr u8 normal_filename_length = 8; static constexpr u8 normal_extension_length = 3; static ErrorOr> compute_filename(FATEntry&, Vector const& = {}); static StringView byte_terminated_string(StringView, u8); static Time fat_date_time(FATPackedDate, FATPackedTime); ErrorOr> compute_block_list(); ErrorOr> read_block_list(); ErrorOr> traverse(Function(LockRefPtr)> callback); u32 first_cluster() const; // ^Inode virtual ErrorOr write_bytes_locked(off_t, size_t, UserOrKernelBuffer const& data, OpenFileDescription*) override; virtual ErrorOr read_bytes_locked(off_t, size_t, UserOrKernelBuffer& buffer, OpenFileDescription*) const override; virtual InodeMetadata metadata() const override; virtual ErrorOr traverse_as_directory(Function(FileSystem::DirectoryEntryView const&)>) const override; virtual ErrorOr> lookup(StringView name) override; virtual ErrorOr> create_child(StringView name, mode_t, dev_t, UserID, GroupID) override; virtual ErrorOr add_child(Inode&, StringView name, mode_t) override; virtual ErrorOr remove_child(StringView name) override; virtual ErrorOr replace_child(StringView name, Inode& child) override; virtual ErrorOr chmod(mode_t) override; virtual ErrorOr chown(UserID, GroupID) override; virtual ErrorOr flush_metadata() override; Vector m_block_list; FATEntry m_entry; NonnullOwnPtr m_filename; InodeMetadata m_metadata; }; }