aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/kernel/filesystems/fat32/directory_entry.cpp81
-rw-r--r--kernel/kernel/filesystems/fat32/directory_entry.hpp100
-rw-r--r--kernel/kernel/filesystems/fat32/directory_iterator.cpp9
-rw-r--r--kernel/kernel/filesystems/fat32/directory_iterator.tests.cpp40
-rw-r--r--kernel/kernel/filesystems/fat32/file_allocation_table.tests.cpp2
-rw-r--r--kernel/kernel/filesystems/fat32/filesystem.cpp16
-rw-r--r--kernel/kernel/filesystems/fat32/filesystem.tests.cpp18
-rw-r--r--kernel/kernel/filesystems/fat32/inode.cpp82
-rw-r--r--kernel/kernel/filesystems/fat32/inode.hpp42
-rw-r--r--kernel/kernel/filesystems/fat32/inode.tests.cpp83
-rw-r--r--kernel/kernel/test_support/filesystems/fat32.cpp32
-rw-r--r--kernel/kernel/test_support/filesystems/fat32.hpp14
12 files changed, 288 insertions, 231 deletions
diff --git a/kernel/kernel/filesystems/fat32/directory_entry.cpp b/kernel/kernel/filesystems/fat32/directory_entry.cpp
index 3b448962..24b43474 100644
--- a/kernel/kernel/filesystems/fat32/directory_entry.cpp
+++ b/kernel/kernel/filesystems/fat32/directory_entry.cpp
@@ -1,12 +1,21 @@
#include <kernel/filesystems/fat32/directory_entry.hpp>
+#include <kapi/system.hpp>
+
+#include <kstd/result.hpp>
+#include <kstd/span.hpp>
#include <kstd/string.hpp>
+#include <kstd/units.hpp>
#include <cstdint>
+#include <optional>
#include <string_view>
namespace kernel::filesystems::fat32
{
+ using kstd::bytes;
+ using std::optional;
+
namespace
{
constexpr auto base_name_length = 8uz;
@@ -32,14 +41,64 @@ namespace kernel::filesystems::fat32
}
} // namespace
+ directory_entry::directory_entry(directory_entry_data const & data, std::uint32_t root_directory_cluster_index,
+ optional<bytes> disk_offset)
+ : m_data(data)
+ , m_first_cluster(0)
+ , m_disk_offset(disk_offset)
+ {
+ // A ".." entry pointing to the root directory stores cluster 0 instead of the root cluster.
+ auto cluster_index_raw = (static_cast<std::uint32_t>(m_data.first_cluster_high) << 16) | m_data.first_cluster_low;
+
+ m_first_cluster = short_name() == ".." && cluster_index_raw == 0 ? root_directory_cluster_index : cluster_index_raw;
+ }
+
+ auto directory_entry::create(inode_ptr const & backing_inode, std::uint32_t root_directory_cluster_index,
+ kstd::bytes disk_offset) -> kstd::result<directory_entry>
+ {
+ auto data = directory_entry_data{};
+
+ if (auto read_result = backing_inode->read(kstd::raw_bytes(data), disk_offset); !read_result)
+ {
+ return kstd::failure(read_result.error());
+ }
+
+ return directory_entry{data, root_directory_cluster_index, disk_offset};
+ }
+
+ auto directory_entry::create_root(uint32_t first_cluster) -> directory_entry
+ {
+ auto data = directory_entry_data{};
+ data.attributes = constants::attribute_directory;
+ data.first_cluster_high = static_cast<std::uint16_t>(first_cluster >> 16);
+ data.first_cluster_low = static_cast<std::uint16_t>(first_cluster);
+ return directory_entry{data, first_cluster, std::nullopt}; // todo
+ }
+
+ auto directory_entry::write_first_cluster(inode_ptr const & backing_inode, std::uint32_t first_cluster)
+ -> kstd::result<void>
+ {
+ // todo maybe transactional
+ m_data.first_cluster_high = static_cast<std::uint16_t>(first_cluster >> 16);
+ m_data.first_cluster_low = static_cast<std::uint16_t>(first_cluster);
+ return write_data(backing_inode);
+ }
+
+ auto directory_entry::write_file_size(inode_ptr const & backing_inode, kstd::bytes file_size) -> kstd::result<void>
+ {
+ // todo maybe transactional
+ m_data.file_size = file_size;
+ return write_data(backing_inode);
+ }
+
auto directory_entry::short_name() const -> kstd::string
{
- auto const raw_name = std::string_view{name.data(), name.size()};
+ auto const raw_name = std::string_view{m_data.name.data(), m_data.name.size()};
auto const base_name = trim_padding(raw_name.substr(0, base_name_length));
auto const extension = trim_padding(raw_name.substr(base_name_length));
auto result = kstd::string{};
- append_component(result, base_name, (nt_reserved & constants::lowercase_base_name) != 0);
+ append_component(result, base_name, (m_data.nt_reserved & constants::lowercase_base_name) != 0);
// A leading 0xE5 is a valid character in some code pages and is escaped as 0x05 to not mark the entry as deleted.
if (!result.empty() && static_cast<std::uint8_t>(result[0]) == constants::escaped_deleted_entry_marker)
@@ -50,9 +109,25 @@ namespace kernel::filesystems::fat32
if (!extension.empty())
{
result.push_back('.');
- append_component(result, extension, (nt_reserved & constants::lowercase_extension) != 0);
+ append_component(result, extension, (m_data.nt_reserved & constants::lowercase_extension) != 0);
}
return result;
}
+
+ auto directory_entry::write_data(inode_ptr const & backing_inode) -> kstd::result<void>
+ {
+ if (!m_disk_offset.has_value())
+ {
+ kapi::system::panic("[OS:FAT32] Can't write to root-directory."); // todo allowed to panic
+ }
+
+ if (auto result = backing_inode->write(kstd::raw_bytes(m_data), m_disk_offset.value()); !result)
+ {
+ return kstd::failure(result.error());
+ }
+
+ return kstd::success();
+ }
+
} // namespace kernel::filesystems::fat32
diff --git a/kernel/kernel/filesystems/fat32/directory_entry.hpp b/kernel/kernel/filesystems/fat32/directory_entry.hpp
index 54b00e57..f9a538fc 100644
--- a/kernel/kernel/filesystems/fat32/directory_entry.hpp
+++ b/kernel/kernel/filesystems/fat32/directory_entry.hpp
@@ -1,15 +1,18 @@
#ifndef TEACHOS_KERNEL_FILESYSTEMS_FAT32_DIRECTORY_ENTRY_HPP
#define TEACHOS_KERNEL_FILESYSTEMS_FAT32_DIRECTORY_ENTRY_HPP
+#include <kernel/vfs/filesystem.hpp>
+
+#include <kstd/result.hpp>
#include <kstd/string.hpp>
#include <kstd/units.hpp>
#include <array>
#include <cstdint>
+#include <optional>
namespace kernel::filesystems::fat32
{
- //! Constants related to fat32 directory entries.
namespace constants
{
constexpr std::uint8_t inline attribute_read_only = 0x01;
@@ -33,43 +36,72 @@ namespace kernel::filesystems::fat32
constexpr kstd::bytes inline directory_entry_size = kstd::bytes{32};
} // namespace constants
- //! A short (8.3) directory entry in the fat32 filesystem.
- //!
- //! The layout follows the "Microsoft Extensible Firmware Initiative FAT32 File System Specification" (fatgen103).
- //! The name is stored as an 8 character base name followed by a 3 character extension, both space padded.
- // cspell:ignore fatgen
- struct [[gnu::packed]] directory_entry
+ struct [[gnu::packed]] directory_entry_data
{
- //! Check if this entry marks the end of its directory, i.e. if it and all following entries are unused.
+ std::array<char, 11> name; // NOLINT(readability-magic-numbers)
+ std::uint8_t attributes;
+ std::uint8_t nt_reserved;
+ std::uint8_t creation_time_tenth;
+ std::uint16_t creation_time;
+ std::uint16_t creation_date;
+ std::uint16_t last_access_date;
+ std::uint16_t first_cluster_high;
+ std::uint16_t write_time;
+ std::uint16_t write_date;
+ std::uint16_t first_cluster_low;
+ std::uint32_t file_size;
+ };
+
+ static_assert(sizeof(directory_entry_data) == constants::directory_entry_size.value,
+ "A fat32 directory entry must be exactly 32 bytes in size.");
+
+ struct directory_entry
+ {
+ using inode_ptr = kernel::vfs::filesystem::inode_ptr;
+
+ directory_entry() = default; // todo currently needed because of iterator, maybe in future unnecessary
+ explicit directory_entry(directory_entry_data const & data, std::uint32_t root_directory_cluster_index,
+ std::optional<kstd::bytes> disk_offset);
+
+ // todo maybe take driver-state as argument
+ auto static create(inode_ptr const & backing_inode, std::uint32_t root_directory_cluster_index,
+ kstd::bytes disk_offset) -> kstd::result<directory_entry>;
+
+ auto static create_root(uint32_t first_cluster) -> directory_entry;
+
[[nodiscard]] constexpr auto is_end_of_directory() const noexcept -> bool
{
- return static_cast<std::uint8_t>(name[0]) == constants::end_of_directory_marker;
+ return static_cast<std::uint8_t>(m_data.name[0]) == constants::end_of_directory_marker;
}
- //! Check if this entry has been deleted and is free to be reused.
[[nodiscard]] constexpr auto is_deleted() const noexcept -> bool
{
- return static_cast<std::uint8_t>(name[0]) == constants::deleted_entry_marker;
+ return static_cast<std::uint8_t>(m_data.name[0]) == constants::deleted_entry_marker;
}
- //! Check if this entry is part of a long file name.
[[nodiscard]] constexpr auto is_long_name() const noexcept -> bool
{
- return (attributes & constants::long_name_mask) == constants::attribute_long_name;
+ return (m_data.attributes & constants::long_name_mask) == constants::attribute_long_name;
}
- //! Check if this entry holds the label of the volume.
[[nodiscard]] constexpr auto is_volume_label() const noexcept -> bool
{
- return !is_long_name() && (attributes & constants::attribute_volume_id) != 0;
+ return !is_long_name() && (m_data.attributes & constants::attribute_volume_id) != 0;
}
- //! Get the first cluster of the data described by this entry.
- //!
- //! @return The first cluster, or 0 if no cluster is allocated (e.g. for empty files).
[[nodiscard]] constexpr auto first_cluster() const noexcept -> std::uint32_t
{
- return (static_cast<std::uint32_t>(first_cluster_high) << 16) | first_cluster_low;
+ return m_first_cluster;
+ }
+
+ auto set_first_cluster(std::uint32_t first_cluster) -> void
+ {
+ m_first_cluster = first_cluster;
+ }
+
+ [[nodiscard]] constexpr auto attributes() const noexcept -> std::uint8_t
+ {
+ return m_data.attributes;
}
//! Get the name of this entry in its displayed form, e.g. "HELLO.TXT".
@@ -78,22 +110,22 @@ namespace kernel::filesystems::fat32
//! @p nt_reserved are honored.
[[nodiscard]] auto short_name() const -> kstd::string;
- std::array<char, 11> name; // NOLINT(readability-magic-numbers)
- std::uint8_t attributes;
- std::uint8_t nt_reserved;
- std::uint8_t creation_time_tenth;
- std::uint16_t creation_time;
- std::uint16_t creation_date;
- std::uint16_t last_access_date;
- std::uint16_t first_cluster_high;
- std::uint16_t write_time;
- std::uint16_t write_date;
- std::uint16_t first_cluster_low;
- std::uint32_t file_size;
- };
+ [[nodiscard]] auto file_size() const noexcept -> kstd::bytes
+ {
+ return kstd::bytes{m_data.file_size};
+ }
- static_assert(sizeof(directory_entry) == constants::directory_entry_size.value,
- "A fat32 directory entry must be exactly 32 bytes in size.");
+ auto write_first_cluster(inode_ptr const & backing_inode, std::uint32_t first_cluster) -> kstd::result<void>;
+
+ auto write_file_size(inode_ptr const & backing_inode, kstd::bytes file_size) -> kstd::result<void>;
+
+ private:
+ directory_entry_data m_data{};
+ std::uint32_t m_first_cluster{};
+ std::optional<kstd::bytes> m_disk_offset{};
+
+ auto write_data(inode_ptr const & backing_inode) -> kstd::result<void>;
+ };
} // namespace kernel::filesystems::fat32
#endif
diff --git a/kernel/kernel/filesystems/fat32/directory_iterator.cpp b/kernel/kernel/filesystems/fat32/directory_iterator.cpp
index c6bd8988..ac586151 100644
--- a/kernel/kernel/filesystems/fat32/directory_iterator.cpp
+++ b/kernel/kernel/filesystems/fat32/directory_iterator.cpp
@@ -6,7 +6,6 @@
#include <kernel/filesystems/fat32/file_allocation_table.hpp>
#include <kstd/memory.hpp>
-#include <kstd/span.hpp>
#include <kstd/system_error.hpp>
#include <kstd/units.hpp>
@@ -97,12 +96,14 @@ namespace kernel::filesystems::fat32
{
auto const location = cluster_offset(*m_cluster, *m_state) + m_offset % m_state->boot_sector.cluster_size();
- auto entry = directory_entry{};
- if (auto read_result = m_state->backing_inode->read(kstd::raw_bytes(entry), location); !read_result)
+ auto entry_result = directory_entry::create(m_state->backing_inode,
+ m_state->boot_sector.root_directory_cluster_index(), location);
+ if (!entry_result)
{
- finish(read_result.error());
+ finish(entry_result.error());
return;
}
+ auto entry = entry_result.value();
if (entry.is_end_of_directory())
{
diff --git a/kernel/kernel/filesystems/fat32/directory_iterator.tests.cpp b/kernel/kernel/filesystems/fat32/directory_iterator.tests.cpp
index e0f2d29f..a6711a90 100644
--- a/kernel/kernel/filesystems/fat32/directory_iterator.tests.cpp
+++ b/kernel/kernel/filesystems/fat32/directory_iterator.tests.cpp
@@ -19,7 +19,6 @@
#include <algorithm>
#include <array>
-#include <cstddef>
#include <cstdint>
#include <filesystem>
#include <span>
@@ -33,15 +32,16 @@ using namespace kstd::units_literals;
namespace
{
- using kernel::filesystems::fat32::directory_entry;
+ using kernel::filesystems::fat32::directory_entry_data;
using kernel::filesystems::fat32::directory_iterator;
using kernel::tests::filesystems::fat32::make_entry;
+ using kernel::tests::filesystems::fat32::make_entry_data;
constexpr auto entries_per_cluster = 16uz;
- auto file_entry(std::string_view name) -> directory_entry
+ auto file_entry(std::string_view name) -> directory_entry_data
{
- return make_entry(name, kernel::filesystems::fat32::constants::attribute_archive);
+ return make_entry_data(name, kernel::filesystems::fat32::constants::attribute_archive);
}
auto collect_names(directory_iterator it) -> std::vector<std::string>
@@ -80,22 +80,22 @@ SCENARIO("Fat32 short names are formatted for display", "[filesystem][fat32][rea
THEN("the lowercase flags are honored per component")
{
- auto entry = make_entry("HELLO TXT", 0);
-
- entry.nt_reserved = constants::lowercase_base_name;
+ auto entry = make_entry("HELLO TXT", 0, 0, 0, constants::lowercase_base_name);
REQUIRE(entry.short_name() == "hello.TXT");
- entry.nt_reserved = constants::lowercase_extension;
+ entry = make_entry("HELLO TXT", 0, 0, 0, constants::lowercase_extension);
REQUIRE(entry.short_name() == "HELLO.txt");
- entry.nt_reserved = constants::lowercase_base_name | constants::lowercase_extension;
+ entry = make_entry("HELLO TXT", 0, 0, 0, constants::lowercase_base_name | constants::lowercase_extension);
REQUIRE(entry.short_name() == "hello.txt");
}
THEN("an escaped leading 0xE5 is restored")
{
- auto entry = make_entry("XAB", 0);
- entry.name[0] = static_cast<char>(constants::escaped_deleted_entry_marker);
+ // todo
+ auto entry = make_entry("\xE5"
+ "AB",
+ 0);
auto const name = entry.short_name();
REQUIRE(static_cast<std::uint8_t>(name[0]) == constants::deleted_entry_marker);
REQUIRE(std::string_view{name.data() + 1, name.size() - 1} == "AB");
@@ -139,7 +139,7 @@ SCENARIO_METHOD(kernel::tests::vfs::storage_boot_module_fixture, "Fat32 director
auto it = directory_iterator{root_cluster, *driver_state};
REQUIRE(it != directory_iterator{});
REQUIRE(it->entry.first_cluster() == 3);
- REQUIRE(it->entry.file_size == 12);
+ REQUIRE(it->entry.file_size() == 12_B);
REQUIRE(it->offset == 32_B);
REQUIRE(it->location == kernel::filesystems::fat32::cluster_offset(root_cluster, *driver_state) + 32_B);
REQUIRE(it->inode_number() == it->location.value);
@@ -177,12 +177,12 @@ SCENARIO("Fat32 directory_iterator on a mock layout", "[filesystem][fat32][readd
deleted.name[0] = static_cast<char>(constants::deleted_entry_marker);
auto const entries = std::array{
- make_entry("LABEL", constants::attribute_volume_id),
- make_entry("Ah\0e\0l\0l\0o", constants::attribute_long_name),
+ make_entry_data("LABEL", constants::attribute_volume_id),
+ make_entry_data("Ah\0e\0l\0l\0o", constants::attribute_long_name),
file_entry("HELLO TXT"),
deleted,
- make_entry("SUBDIR", constants::attribute_directory, 5),
- directory_entry{},
+ make_entry_data("SUBDIR", constants::attribute_directory, 5),
+ directory_entry_data{},
file_entry("HIDDEN TXT"),
};
kernel::tests::filesystems::fat32::write_directory_entries(*device, 2, entries);
@@ -228,7 +228,7 @@ SCENARIO("Fat32 directory_iterator on a mock layout", "[filesystem][fat32][readd
WHEN("the directory spans two clusters")
{
- auto first_cluster_entries = std::array<directory_entry, entries_per_cluster>{};
+ auto first_cluster_entries = std::array<directory_entry_data, entries_per_cluster>{};
for (auto i = 0uz; i < first_cluster_entries.size(); ++i)
{
first_cluster_entries[i] = file_entry(std::string{"FILE"} + static_cast<char>('A' + i));
@@ -264,7 +264,7 @@ SCENARIO("Fat32 directory_iterator on a mock layout", "[filesystem][fat32][readd
WHEN("a full directory has no end marker")
{
- auto entries = std::array<directory_entry, entries_per_cluster>{};
+ auto entries = std::array<directory_entry_data, entries_per_cluster>{};
std::ranges::fill(entries, file_entry("FILE"));
kernel::tests::filesystems::fat32::write_directory_entries(*device, 6, entries);
write_fat_entry(*device, 6, 0x0FFF'FFFF);
@@ -301,7 +301,7 @@ SCENARIO("Fat32 directory_iterator on a mock layout", "[filesystem][fat32][readd
driver_state->boot_sector = kernel::filesystems::fat32::boot_sector{data};
- auto entries = std::array<directory_entry, entries_per_cluster>{};
+ auto entries = std::array<directory_entry_data, entries_per_cluster>{};
std::ranges::fill(entries, file_entry("LOOP"));
kernel::tests::filesystems::fat32::write_directory_entries(*device, 13, entries);
kernel::tests::filesystems::fat32::write_directory_entries(*device, 14, entries);
@@ -323,7 +323,7 @@ SCENARIO("Fat32 directory_iterator on a mock layout", "[filesystem][fat32][readd
WHEN("the directory's chain runs into a free cluster")
{
- auto entries = std::array<directory_entry, entries_per_cluster>{};
+ auto entries = std::array<directory_entry_data, entries_per_cluster>{};
std::ranges::fill(entries, file_entry("FILE"));
kernel::tests::filesystems::fat32::write_directory_entries(*device, 8, entries);
kernel::tests::filesystems::fat32::write_directory_entries(*device, 9, entries);
diff --git a/kernel/kernel/filesystems/fat32/file_allocation_table.tests.cpp b/kernel/kernel/filesystems/fat32/file_allocation_table.tests.cpp
index 3b45e38f..41a9169c 100644
--- a/kernel/kernel/filesystems/fat32/file_allocation_table.tests.cpp
+++ b/kernel/kernel/filesystems/fat32/file_allocation_table.tests.cpp
@@ -85,7 +85,7 @@ SCENARIO_METHOD(kernel::tests::vfs::storage_boot_module_fixture, "Fat32 cluster
{
using namespace kernel::filesystems::fat32;
- auto entries = std::array<directory_entry, 3>{};
+ auto entries = std::array<directory_entry_data, 3>{};
auto const buffer = std::as_writable_bytes(std::span{entries});
auto const read_result =
read_cluster_chain(driver_state->boot_sector.root_directory_cluster_index(), buffer, 0_B, *driver_state);
diff --git a/kernel/kernel/filesystems/fat32/filesystem.cpp b/kernel/kernel/filesystems/fat32/filesystem.cpp
index 4fc9cd84..59621022 100644
--- a/kernel/kernel/filesystems/fat32/filesystem.cpp
+++ b/kernel/kernel/filesystems/fat32/filesystem.cpp
@@ -17,7 +17,6 @@
#include <kstd/mutex.hpp>
#include <kstd/result.hpp>
#include <kstd/system_error.hpp>
-#include <kstd/units.hpp>
#include <algorithm>
#include <array>
@@ -98,8 +97,8 @@ namespace kernel::filesystems::fat32
return kstd::failure(errc::invalid_cluster);
}
- auto root = kstd::make_shared<inode>(root_cluster, constants::attribute_directory, kstd::bytes{},
- constants::root_inode_number);
+ auto root_directory_entry = directory_entry::create_root(root_cluster);
+ auto root = kstd::make_shared<inode>(root_directory_entry, constants::root_inode_number);
return mount_result{root, driver_state};
}
@@ -134,14 +133,11 @@ namespace kernel::filesystems::fat32
continue;
}
- // A ".." entry pointing to the root directory stores cluster 0 instead of the root cluster.
- if (it->entry.first_cluster() == 0 && (it->entry.attributes & constants::attribute_directory) != 0)
- {
- return kstd::make_shared<inode>(state->boot_sector.root_directory_cluster_index(),
- constants::attribute_directory, kstd::bytes{}, constants::root_inode_number);
- }
+ auto const inode_number = it->entry.first_cluster() == state->boot_sector.root_directory_cluster_index()
+ ? constants::root_inode_number
+ : it->inode_number();
- return kstd::make_shared<inode>(*it);
+ return kstd::make_shared<inode>(it->entry, inode_number);
}
if (it.error())
diff --git a/kernel/kernel/filesystems/fat32/filesystem.tests.cpp b/kernel/kernel/filesystems/fat32/filesystem.tests.cpp
index d25bbe3d..ae11de39 100644
--- a/kernel/kernel/filesystems/fat32/filesystem.tests.cpp
+++ b/kernel/kernel/filesystems/fat32/filesystem.tests.cpp
@@ -202,7 +202,7 @@ SCENARIO("Fat32 filesystem lookup on a mock layout", "[filesystem][fat32][filesy
GIVEN("a mounted minimal fat32 layout with a file and a subdirectory")
{
using namespace kernel::filesystems::fat32;
- using kernel::tests::filesystems::fat32::make_entry;
+ using kernel::tests::filesystems::fat32::make_entry_data;
using kernel::tests::filesystems::fat32::write_directory_entries;
using kernel::tests::filesystems::fat32::write_fat_entry;
@@ -211,16 +211,16 @@ SCENARIO("Fat32 filesystem lookup on a mock layout", "[filesystem][fat32][filesy
write_directory_entries(*device, 2,
std::array{
- make_entry("LABEL", constants::attribute_volume_id),
- make_entry("HELLO TXT", constants::attribute_archive, 3, 5),
- make_entry("SUBDIR", constants::attribute_directory, 4),
+ make_entry_data("LABEL", constants::attribute_volume_id),
+ make_entry_data("HELLO TXT", constants::attribute_archive, 3, 5),
+ make_entry_data("SUBDIR", constants::attribute_directory, 4),
});
write_fat_entry(*device, 3, 0x0FFF'FFFF);
write_directory_entries(*device, 4,
std::array{
- make_entry(".", constants::attribute_directory, 4),
- make_entry("..", constants::attribute_directory, 0),
- make_entry("INNER TXT", constants::attribute_archive, 5, 7),
+ make_entry_data(".", constants::attribute_directory, 4),
+ make_entry_data("..", constants::attribute_directory, 0),
+ make_entry_data("INNER TXT", constants::attribute_archive, 5, 7),
});
write_fat_entry(*device, 4, 0x0FFF'FFFF);
write_fat_entry(*device, 5, 0x0FFF'FFFF);
@@ -305,8 +305,8 @@ SCENARIO("Fat32 filesystem lookup on a mock layout", "[filesystem][fat32][filesy
WHEN("the full root directory cluster is marked as free in the file allocation table")
{
- auto entries = std::array<directory_entry, 16>{};
- entries.fill(make_entry("FILLER TXT", constants::attribute_archive));
+ auto entries = std::array<directory_entry_data, 16>{};
+ entries.fill(make_entry_data("FILLER TXT", constants::attribute_archive));
write_directory_entries(*device, 2, entries);
write_fat_entry(*device, 2, 0);
diff --git a/kernel/kernel/filesystems/fat32/inode.cpp b/kernel/kernel/filesystems/fat32/inode.cpp
index f7365eeb..556635e3 100644
--- a/kernel/kernel/filesystems/fat32/inode.cpp
+++ b/kernel/kernel/filesystems/fat32/inode.cpp
@@ -38,20 +38,11 @@ namespace kernel::filesystems::fat32
constexpr auto zero_fill_chunk_size = 512_B;
} // namespace
- inode::inode(std::uint32_t first_cluster, std::uint8_t attributes, kstd::bytes size, std::uint64_t inode_number)
- : m_first_cluster(first_cluster)
- , m_attributes(attributes)
- , m_size(size)
+ inode::inode(directory_entry const & directory_entry, std::uint64_t inode_number)
+ : m_directory_entry(directory_entry)
, m_inode_number(inode_number)
{}
- inode::inode(directory_record const & record)
- : inode(record.entry.first_cluster(), record.entry.attributes, kstd::bytes{record.entry.file_size},
- record.inode_number())
- {
- m_entry_location = record.location;
- }
-
auto inode::read(std::span<std::byte> buffer, kstd::bytes offset) const -> kstd::result<kstd::bytes>
{
if (is_directory())
@@ -65,16 +56,17 @@ namespace kernel::filesystems::fat32
return kstd::failure(vfs::errc::not_mounted);
}
- if (offset >= m_size || buffer.empty())
+ if (offset >= m_directory_entry.file_size() || buffer.empty())
{
return 0_B;
}
// The last cluster of a file is padded up to the cluster size, so the read must be limited to the file size.
- auto const requested_size = std::min(kstd::bytes{buffer.size()}, m_size - offset);
+ auto const requested_size = std::min(kstd::bytes{buffer.size()}, m_directory_entry.file_size() - offset);
auto guard = kstd::lock_guard{state->lock};
- auto const read_result = read_cluster_chain(m_first_cluster, buffer.first(requested_size.value), offset, *state);
+ auto const read_result =
+ read_cluster_chain(m_directory_entry.first_cluster(), buffer.first(requested_size.value), offset, *state);
if (!read_result)
{
return kstd::failure(read_result.error());
@@ -107,12 +99,6 @@ namespace kernel::filesystems::fat32
return kstd::failure(vfs::errc::not_mounted);
}
- // Without its directory entry, the new size of the file could not be persisted.
- if (!m_entry_location)
- {
- return kstd::failure(vfs::errc::invalid_inode);
- }
-
if (buffer.empty())
{
return 0_B;
@@ -127,7 +113,7 @@ namespace kernel::filesystems::fat32
auto guard = kstd::lock_guard{state->lock};
// An empty file owns no cluster, so the chain has to be started first.
- if (m_first_cluster == 0)
+ if (m_directory_entry.first_cluster() == 0)
{
auto const first_cluster = allocate_cluster(std::nullopt, *state);
if (!first_cluster)
@@ -135,8 +121,10 @@ namespace kernel::filesystems::fat32
return kstd::failure(first_cluster.error());
}
- m_first_cluster = *first_cluster;
- if (auto const entry_result = write_directory_entry(*state); !entry_result)
+ m_directory_entry.set_first_cluster(first_cluster.value());
+
+ if (auto const entry_result = m_directory_entry.write_first_cluster(state->backing_inode, first_cluster.value());
+ !entry_result)
{
return kstd::failure(entry_result.error());
}
@@ -144,18 +132,19 @@ namespace kernel::filesystems::fat32
auto const cluster_count =
(write_end + state->boot_sector.cluster_size() - 1_B) / state->boot_sector.cluster_size();
- if (auto const allocation_result = ensure_clusters_allocated(m_first_cluster, cluster_count, *state);
+ if (auto const allocation_result =
+ ensure_clusters_allocated(m_directory_entry.first_cluster(), cluster_count, *state);
!allocation_result)
{
return kstd::failure(allocation_result.error());
}
// Writing behind the end of the file leaves a gap, which must read as zeros instead of stale cluster contents.
- for (auto gap_offset = m_size; gap_offset < offset;)
+ for (auto gap_offset = m_directory_entry.file_size(); gap_offset < offset;)
{
auto const zeros = std::array<std::byte, zero_fill_chunk_size.value>{};
auto const chunk = std::span{zeros}.first(std::min(offset - gap_offset, zero_fill_chunk_size).value);
- auto const fill_result = write_cluster_chain(m_first_cluster, chunk, gap_offset, *state);
+ auto const fill_result = write_cluster_chain(m_directory_entry.first_cluster(), chunk, gap_offset, *state);
if (!fill_result)
{
return kstd::failure(fill_result.error());
@@ -170,16 +159,15 @@ namespace kernel::filesystems::fat32
gap_offset += *fill_result;
}
- auto const write_result = write_cluster_chain(m_first_cluster, buffer, offset, *state);
+ auto const write_result = write_cluster_chain(m_directory_entry.first_cluster(), buffer, offset, *state);
if (!write_result)
{
return kstd::failure(write_result.error());
}
- if (auto const new_size = offset + *write_result; new_size > m_size)
+ if (auto const new_size = offset + *write_result; new_size > m_directory_entry.file_size())
{
- m_size = new_size;
- if (auto const entry_result = write_directory_entry(*state); !entry_result)
+ if (auto const entry_result = m_directory_entry.write_file_size(state->backing_inode, new_size); !entry_result)
{
return kstd::failure(entry_result.error());
}
@@ -190,12 +178,12 @@ namespace kernel::filesystems::fat32
auto inode::is_directory() const -> bool
{
- return (m_attributes & constants::attribute_directory) != 0;
+ return (m_directory_entry.attributes() & constants::attribute_directory) != 0;
}
auto inode::is_regular() const -> bool
{
- return (m_attributes & (constants::attribute_directory | constants::attribute_volume_id)) == 0;
+ return (m_directory_entry.attributes() & (constants::attribute_directory | constants::attribute_volume_id)) == 0;
}
auto inode::status() const -> kstd::result<kapi::filesystem::file_status>
@@ -206,7 +194,7 @@ namespace kernel::filesystems::fat32
return status;
}
- status->size = m_size;
+ status->size = m_directory_entry.file_size();
status->inode_number = m_inode_number;
status->link_count = 1;
return status;
@@ -235,10 +223,10 @@ namespace kernel::filesystems::fat32
auto guard = kstd::lock_guard{state->lock};
auto count = 0uz;
- auto it = directory_iterator{m_first_cluster, kstd::bytes{position.value}, *state};
+ auto it = directory_iterator{m_directory_entry.first_cluster(), kstd::bytes{position.value}, *state};
for (; it != directory_iterator{}; ++it)
{
- auto const is_directory_entry = (it->entry.attributes & constants::attribute_directory) != 0;
+ auto const is_directory_entry = (it->entry.attributes() & constants::attribute_directory) != 0;
entries[count++] = kapi::filesystem::directory_entry{
.name = it->entry.short_name(),
.type = is_directory_entry ? kapi::filesystem::file_type::directory : kapi::filesystem::file_type::regular,
@@ -262,31 +250,11 @@ namespace kernel::filesystems::fat32
auto inode::first_cluster() const -> std::uint32_t
{
- return m_first_cluster;
+ return m_directory_entry.first_cluster();
}
auto inode::size() const -> kstd::bytes
{
- return m_size;
- }
-
- auto inode::write_directory_entry(fat32::driver_state const & state) const -> kstd::result<void>
- {
- auto entry = directory_entry{};
- if (auto const read_result = state.backing_inode->read(kstd::raw_bytes(entry), *m_entry_location); !read_result)
- {
- return kstd::failure(read_result.error());
- }
-
- entry.first_cluster_high = static_cast<std::uint16_t>(m_first_cluster >> 16);
- entry.first_cluster_low = static_cast<std::uint16_t>(m_first_cluster);
- entry.file_size = static_cast<std::uint32_t>(m_size.value);
-
- if (auto const write_result = state.backing_inode->write(kstd::raw_bytes(entry), *m_entry_location); !write_result)
- {
- return kstd::failure(write_result.error());
- }
-
- return {};
+ return m_directory_entry.file_size();
}
} // namespace kernel::filesystems::fat32
diff --git a/kernel/kernel/filesystems/fat32/inode.hpp b/kernel/kernel/filesystems/fat32/inode.hpp
index 55fc1d13..3a5a88d4 100644
--- a/kernel/kernel/filesystems/fat32/inode.hpp
+++ b/kernel/kernel/filesystems/fat32/inode.hpp
@@ -1,21 +1,16 @@
#ifndef TEACHOS_KERNEL_FILESYSTEMS_FAT32_INODE_HPP
#define TEACHOS_KERNEL_FILESYSTEMS_FAT32_INODE_HPP
-#include <kernel/filesystems/fat32/directory_iterator.hpp>
-#include <kernel/filesystems/fat32/driver_state.hpp>
+#include <kernel/filesystems/fat32/directory_entry.hpp>
#include <kernel/vfs/inode.hpp>
#include <kapi/filesystem.hpp>
-#include <kstd/memory.hpp>
#include <kstd/result.hpp>
-#include <kstd/string.hpp>
#include <kstd/units.hpp>
-#include <kstd/vector.hpp>
#include <cstddef>
#include <cstdint>
-#include <optional>
#include <span>
#include <utility>
@@ -23,22 +18,7 @@ namespace kernel::filesystems::fat32
{
struct inode : kernel::vfs::inode
{
- //! Create a fat32 inode.
- //!
- //! @param first_cluster The first cluster of the inode's data.
- //! @param attributes The attributes of the directory entry describing the inode.
- //! @param size The size of the inode's data in bytes.
- //! @param inode_number The inode number reported in the inode's status.
- explicit inode(std::uint32_t first_cluster, std::uint8_t attributes, kstd::bytes size = {},
- std::uint64_t inode_number = {});
-
- //! Create a fat32 inode for the file described by a directory record.
- //!
- //! Only inodes created from a record can be written to, since the record locates the directory entry that has to be
- //! updated when the file grows.
- //!
- //! @param record The record describing the inode.
- explicit inode(directory_record const & record);
+ explicit inode(directory_entry const & directory_entry, std::uint64_t inode_number);
[[nodiscard]] auto read(std::span<std::byte> buffer, kstd::bytes offset) const
-> kstd::result<kstd::bytes> override;
@@ -56,29 +36,13 @@ namespace kernel::filesystems::fat32
std::span<kapi::filesystem::directory_entry> entries) const
-> kstd::result<std::pair<std::size_t, kapi::filesystem::directory_cursor>> override;
- //! Get the first cluster of the inode's data.
- //!
- //! @return The first cluster number.
[[nodiscard]] auto first_cluster() const -> std::uint32_t;
- //! Get the size of the inode's data.
- //!
- //! @return The size in bytes, which is always 0 for directories.
[[nodiscard]] auto size() const -> kstd::bytes;
private:
- //! Store the first cluster and size of this inode in the directory entry describing it.
- //!
- //! @param state The driver state to operate on.
- //! @return Nothing on success, an error otherwise.
- [[nodiscard]] auto write_directory_entry(fat32::driver_state const & state) const -> kstd::result<void>;
-
- std::uint32_t m_first_cluster{};
- std::uint8_t m_attributes{};
- kstd::bytes m_size{};
+ directory_entry m_directory_entry{};
std::uint64_t m_inode_number{};
- //! The offset of the directory entry describing this inode on the backing inode, if it has one.
- std::optional<kstd::bytes> m_entry_location{};
};
} // namespace kernel::filesystems::fat32
diff --git a/kernel/kernel/filesystems/fat32/inode.tests.cpp b/kernel/kernel/filesystems/fat32/inode.tests.cpp
index 7c9a5727..e3578b42 100644
--- a/kernel/kernel/filesystems/fat32/inode.tests.cpp
+++ b/kernel/kernel/filesystems/fat32/inode.tests.cpp
@@ -80,6 +80,20 @@ namespace
}
return bytes;
}
+
+ auto create_inode(std::uint32_t first_cluster, std::uint8_t attributes, std::uint32_t file_size = {},
+ std::uint64_t inode_number = {}) -> kernel::filesystems::fat32::inode
+ {
+ auto data = kernel::filesystems::fat32::directory_entry_data{};
+ data.first_cluster_high = static_cast<std::uint16_t>(first_cluster >> 16);
+ data.first_cluster_low = static_cast<std::uint16_t>(first_cluster);
+ data.file_size = file_size;
+ data.attributes = attributes;
+ return kernel::filesystems::fat32::inode{
+ kernel::filesystems::fat32::directory_entry{data, 2, 0_B}, // todo
+ inode_number
+ };
+ }
} // namespace
SCENARIO("Fat32 inode attributes", "[filesystem][fat32][inode]")
@@ -88,19 +102,20 @@ SCENARIO("Fat32 inode attributes", "[filesystem][fat32][inode]")
GIVEN("a fat32 inode with the directory attribute")
{
- auto inode = kernel::filesystems::fat32::inode{2, constants::attribute_directory};
+ auto entry = create_inode(3, constants::attribute_directory);
+ auto inode = kernel::filesystems::fat32::inode{entry};
THEN("it is a directory and keeps its first cluster")
{
REQUIRE(inode.is_directory());
REQUIRE_FALSE(inode.is_regular());
- REQUIRE(inode.first_cluster() == 2);
+ REQUIRE(inode.first_cluster() == 3);
}
}
GIVEN("a fat32 inode without the directory attribute")
{
- auto inode = kernel::filesystems::fat32::inode{3, 0};
+ auto inode = create_inode(3, 0);
THEN("it is a regular file")
{
@@ -111,7 +126,7 @@ SCENARIO("Fat32 inode attributes", "[filesystem][fat32][inode]")
GIVEN("a fat32 inode with the read only and archive attributes")
{
- auto inode = kernel::filesystems::fat32::inode{3, constants::attribute_read_only | constants::attribute_archive};
+ auto inode = create_inode(3, constants::attribute_read_only | constants::attribute_archive);
THEN("it is a regular file")
{
@@ -121,7 +136,7 @@ SCENARIO("Fat32 inode attributes", "[filesystem][fat32][inode]")
GIVEN("a fat32 inode with the volume id attribute")
{
- auto inode = kernel::filesystems::fat32::inode{0, constants::attribute_volume_id};
+ auto inode = create_inode(3, constants::attribute_volume_id);
THEN("it is neither a directory nor a regular file")
{
@@ -130,16 +145,17 @@ SCENARIO("Fat32 inode attributes", "[filesystem][fat32][inode]")
}
}
- GIVEN("a fat32 inode created from a directory record")
+ GIVEN("a fat32 inode created from a directory entry")
{
- auto record = directory_record{};
- record.entry.attributes = constants::attribute_archive;
- record.entry.first_cluster_high = 0x0001;
- record.entry.first_cluster_low = 0x0002;
- record.entry.file_size = 1234;
- record.location = 4096_B;
+ auto data = directory_entry_data{};
+ data.attributes = constants::attribute_archive;
+ data.first_cluster_high = 0x0001;
+ data.first_cluster_low = 0x0002;
+ data.file_size = 1234;
+
+ auto entry = directory_entry{data, 3, 4096_B};
- auto inode = kernel::filesystems::fat32::inode{record};
+ auto inode = kernel::filesystems::fat32::inode{entry, 4096_B};
THEN("it takes its first cluster, size and inode number from the record")
{
@@ -164,7 +180,7 @@ SCENARIO("Fat32 inode read/write without a mount", "[filesystem][fat32][inode]")
{
GIVEN("a fat32 file inode that does not belong to a mount")
{
- auto inode = kernel::filesystems::fat32::inode{3, 0, 10_B};
+ auto inode = create_inode(3, 0, 10_B);
WHEN("reading from the inode")
{
@@ -209,8 +225,8 @@ SCENARIO("Fat32 inode reads file data on a mock layout", "[filesystem][fat32][in
using namespace kernel::filesystems::fat32;
auto const make_file = [&](std::uint32_t first_cluster, kstd::bytes size) {
- auto inode =
- kstd::make_shared<kernel::filesystems::fat32::inode>(first_cluster, constants::attribute_archive, size);
+ auto inode = kstd::make_shared<kernel::filesystems::fat32::inode>(
+ create_inode(first_cluster, constants::attribute_archive, size));
inode->set_driver_state(mount->second);
return inode;
};
@@ -385,22 +401,22 @@ SCENARIO("Fat32 inode lists directories on a mock layout", "[filesystem][fat32][
GIVEN("a mounted minimal fat32 layout with a populated root directory")
{
using namespace kernel::filesystems::fat32;
- using kernel::tests::filesystems::fat32::make_entry;
+ using kernel::tests::filesystems::fat32::make_entry_data;
auto device = kstd::make_shared<kernel::tests::devices::block_device>("mock", block_size, 18 * block_size);
kernel::tests::filesystems::fat32::setup_mock_fat32_layout(*device);
- auto deleted = make_entry("GONE TXT", constants::attribute_archive);
+ auto deleted = make_entry_data("GONE TXT", constants::attribute_archive);
deleted.name[0] = static_cast<char>(constants::deleted_entry_marker);
kernel::tests::filesystems::fat32::write_directory_entries(
*device, 2,
std::array{
- make_entry("LABEL", constants::attribute_volume_id),
- make_entry("A TXT", constants::attribute_archive, 3, 1),
+ make_entry_data("LABEL", constants::attribute_volume_id),
+ make_entry_data("A TXT", constants::attribute_archive, 3, 1),
deleted,
- make_entry("B TXT", constants::attribute_archive, 4, 1),
- make_entry("DIR", constants::attribute_directory, 5),
+ make_entry_data("B TXT", constants::attribute_archive, 4, 1),
+ make_entry_data("DIR", constants::attribute_directory, 5),
});
auto dev_inode = kstd::make_shared<kernel::vfs::device_inode>(device);
@@ -485,7 +501,7 @@ SCENARIO("Fat32 inode lists directories on a mock layout", "[filesystem][fat32][
THEN("listing a directory that does not belong to a mount fails")
{
- auto const directory = kernel::filesystems::fat32::inode{2, constants::attribute_directory};
+ auto const directory = create_inode(2, constants::attribute_directory);
auto entries = std::vector<kapi::filesystem::directory_entry>(1);
REQUIRE(directory.read_directory(kapi::filesystem::directory_cursor{0}, entries).error() ==
kernel::vfs::errc::not_mounted);
@@ -564,16 +580,16 @@ SCENARIO("Fat32 inode writes file data on a mock layout", "[filesystem][fat32][i
GIVEN("a mounted minimal fat32 layout with a file in the root directory")
{
using namespace kernel::filesystems::fat32;
- using kernel::tests::filesystems::fat32::make_entry;
+ using kernel::tests::filesystems::fat32::make_entry_data;
auto device = kstd::make_shared<kernel::tests::devices::block_device>("mock", block_size, 18 * block_size);
kernel::tests::filesystems::fat32::setup_mock_fat32_layout(*device);
kernel::tests::filesystems::fat32::write_directory_entries(
*device, 2,
std::array{
- make_entry("HELLO TXT", constants::attribute_archive, 3),
- make_entry("EMPTY TXT", constants::attribute_archive),
- make_entry("DIR", constants::attribute_directory, 5),
+ make_entry_data("HELLO TXT", constants::attribute_archive, 3),
+ make_entry_data("EMPTY TXT", constants::attribute_archive),
+ make_entry_data("DIR", constants::attribute_directory, 5),
});
kernel::tests::filesystems::fat32::write_fat_entry(*device, 3, 0x0FFF'FFFF);
kernel::tests::filesystems::fat32::write_fat_entry(*device, 5, 0x0FFF'FFFF);
@@ -794,19 +810,6 @@ SCENARIO("Fat32 inode writes file data on a mock layout", "[filesystem][fat32][i
REQUIRE(result.error() == kernel::vfs::errc::is_a_directory);
}
}
-
- WHEN("writing to a file inode without a directory entry")
- {
- auto orphan = kstd::make_shared<kernel::filesystems::fat32::inode>(3, constants::attribute_archive);
- orphan->set_driver_state(driver_data);
- auto const result = orphan->write(as_bytes("x"), 0_B);
-
- THEN("the write fails because the size could not be persisted")
- {
- REQUIRE_FALSE(result);
- REQUIRE(result.error() == kernel::vfs::errc::invalid_inode);
- }
- }
}
}
diff --git a/kernel/kernel/test_support/filesystems/fat32.cpp b/kernel/kernel/test_support/filesystems/fat32.cpp
index 118f5624..3d131482 100644
--- a/kernel/kernel/test_support/filesystems/fat32.cpp
+++ b/kernel/kernel/test_support/filesystems/fat32.cpp
@@ -102,26 +102,36 @@ namespace kernel::tests::filesystems::fat32
write_bytes(device, offset, data.data(), kstd::bytes{data.size()});
}
- auto make_entry(std::string_view name, std::uint8_t attributes, std::uint32_t first_cluster, std::uint32_t file_size)
+ auto make_entry_data(std::string_view name, std::uint8_t attributes, std::uint32_t first_cluster,
+ std::uint32_t file_size, std::uint8_t nt_reserved)
+ -> kernel::filesystems::fat32::directory_entry_data
+ {
+ auto data = kernel::filesystems::fat32::directory_entry_data{};
+ std::ranges::fill(data.name, ' ');
+ std::ranges::copy(name.substr(0, data.name.size()), data.name.begin());
+ data.attributes = attributes;
+ data.first_cluster_high = static_cast<std::uint16_t>(first_cluster >> 16);
+ data.first_cluster_low = static_cast<std::uint16_t>(first_cluster & 0xFFFF);
+ data.file_size = file_size;
+ data.nt_reserved = nt_reserved;
+ return data;
+ }
+
+ auto make_entry(std::string_view name, std::uint8_t attributes, std::uint32_t first_cluster, std::uint32_t file_size,
+ std::uint8_t nt_reserved, std::uint32_t root_dir_cluster_index, kstd::bytes disk_offset)
-> kernel::filesystems::fat32::directory_entry
{
- auto entry = kernel::filesystems::fat32::directory_entry{};
- std::ranges::fill(entry.name, ' ');
- std::ranges::copy(name.substr(0, entry.name.size()), entry.name.begin());
- entry.attributes = attributes;
- entry.first_cluster_high = static_cast<std::uint16_t>(first_cluster >> 16);
- entry.first_cluster_low = static_cast<std::uint16_t>(first_cluster & 0xFFFF);
- entry.file_size = file_size;
- return entry;
+ auto data = make_entry_data(name, attributes, first_cluster, file_size, nt_reserved);
+ return kernel::filesystems::fat32::directory_entry{data, root_dir_cluster_index, disk_offset};
}
auto write_directory_entries(kernel::tests::devices::block_device & device, std::uint32_t cluster,
- std::span<kernel::filesystems::fat32::directory_entry const> entries) -> void
+ std::span<kernel::filesystems::fat32::directory_entry_data const> entries) -> void
{
constexpr auto entries_per_cluster =
sector_size.value / kernel::filesystems::fat32::constants::directory_entry_size.value;
- auto cluster_entries = std::array<kernel::filesystems::fat32::directory_entry, entries_per_cluster>{};
+ auto cluster_entries = std::array<kernel::filesystems::fat32::directory_entry_data, entries_per_cluster>{};
std::ranges::copy(entries, cluster_entries.begin());
write_cluster_data(device, cluster, std::as_bytes(std::span{cluster_entries}));
}
diff --git a/kernel/kernel/test_support/filesystems/fat32.hpp b/kernel/kernel/test_support/filesystems/fat32.hpp
index 00ba399c..f111d01d 100644
--- a/kernel/kernel/test_support/filesystems/fat32.hpp
+++ b/kernel/kernel/test_support/filesystems/fat32.hpp
@@ -5,6 +5,8 @@
#include <kernel/filesystems/fat32/directory_entry.hpp>
#include <kernel/test_support/devices/block_device.hpp>
+#include <kstd/units.hpp>
+
#include <cstddef>
#include <cstdint>
#include <span>
@@ -15,7 +17,8 @@ namespace kernel::tests::filesystems::fat32
{
//! The boot sector of the mock layout: 512 byte sectors, 1 sector per cluster, 1 reserved sector, a single FAT of
//! 1 sector and 16 data clusters (2 to 17). The root directory starts at cluster 2.
- auto mock_boot_sector() -> std::tuple<kernel::filesystems::fat32::boot_sector_data, kernel::filesystems::fat32::boot_sector>;
+ auto mock_boot_sector()
+ -> std::tuple<kernel::filesystems::fat32::boot_sector_data, kernel::filesystems::fat32::boot_sector>;
auto setup_mock_fat32_layout(kernel::tests::devices::block_device & device) -> void;
auto setup_mock_fat32_layout(kernel::tests::devices::block_device & device,
kernel::filesystems::fat32::boot_sector_data const & boot_sector) -> void;
@@ -27,13 +30,18 @@ namespace kernel::tests::filesystems::fat32
//! Create a short directory entry.
//!
//! @param name The raw 11 character name, i.e. the space padded base name directly followed by the extension.
+ auto make_entry_data(std::string_view name, std::uint8_t attributes, std::uint32_t first_cluster = 0,
+ std::uint32_t file_size = 0, std::uint8_t nt_reserved = 0)
+ -> kernel::filesystems::fat32::directory_entry_data;
+
auto make_entry(std::string_view name, std::uint8_t attributes, std::uint32_t first_cluster = 0,
- std::uint32_t file_size = 0) -> kernel::filesystems::fat32::directory_entry;
+ std::uint32_t file_size = 0, std::uint8_t nt_reserved = 0, std::uint32_t root_dir_cluster_index = 0,
+ kstd::bytes disk_offset = kstd::bytes{0}) -> kernel::filesystems::fat32::directory_entry;
//! Fill a cluster of the mock layout with directory entries, terminated by an end of directory marker if they do not
//! fill the whole cluster.
auto write_directory_entries(kernel::tests::devices::block_device & device, std::uint32_t cluster,
- std::span<kernel::filesystems::fat32::directory_entry const> entries) -> void;
+ std::span<kernel::filesystems::fat32::directory_entry_data const> entries) -> void;
} // namespace kernel::tests::filesystems::fat32