FileSystem.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (c) 2022, Undefine <undefine@undefine.pl>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/OwnPtr.h>
  8. #include <AK/RefPtr.h>
  9. #include <AK/Types.h>
  10. #include <Kernel/FileSystem/BlockBasedFileSystem.h>
  11. #include <Kernel/FileSystem/FATFS/Definitions.h>
  12. #include <Kernel/FileSystem/Inode.h>
  13. #include <Kernel/Forward.h>
  14. #include <Kernel/Library/KBuffer.h>
  15. namespace Kernel {
  16. class FATFS final : public BlockBasedFileSystem {
  17. friend FATInode;
  18. public:
  19. static ErrorOr<NonnullRefPtr<FileSystem>> try_create(OpenFileDescription&, ReadonlyBytes);
  20. virtual ~FATFS() override = default;
  21. virtual StringView class_name() const override { return "FATFS"sv; }
  22. virtual Inode& root_inode() override;
  23. private:
  24. virtual ErrorOr<void> initialize_while_locked() override;
  25. virtual bool is_initialized_while_locked() override;
  26. // FIXME: This is not a proper way to clear last mount of a FAT filesystem,
  27. // but for now we simply have no other way to properly do it.
  28. virtual ErrorOr<void> prepare_to_clear_last_mount() override { return {}; }
  29. FATFS(OpenFileDescription&);
  30. static constexpr u8 signature_1 = 0x28;
  31. static constexpr u8 signature_2 = 0x29;
  32. static constexpr u32 first_data_cluster = 2;
  33. FAT32BootRecord const* boot_record() const { return reinterpret_cast<FAT32BootRecord const*>(m_boot_record->data()); }
  34. BlockBasedFileSystem::BlockIndex first_block_of_cluster(u32 cluster) const;
  35. OwnPtr<KBuffer> m_boot_record {};
  36. RefPtr<FATInode> m_root_inode;
  37. u32 m_first_data_sector { 0 };
  38. };
  39. }