summaryrefslogtreecommitdiff
path: root/src/core/file_sys
diff options
context:
space:
mode:
authorGravatar liamwhite2024-01-26 09:55:25 -0500
committerGravatar GitHub2024-01-26 09:55:25 -0500
commit55482ab5dce463d5014498b006c18a90d0d004e6 (patch)
treeb343faa9cadc692265efb4b6b88e157c97ef76d2 /src/core/file_sys
parentMerge pull request #12796 from t895/controller-optimizations (diff)
parentAddress review comments and fix compilation problems (diff)
downloadyuzu-55482ab5dce463d5014498b006c18a90d0d004e6.tar.gz
yuzu-55482ab5dce463d5014498b006c18a90d0d004e6.tar.xz
yuzu-55482ab5dce463d5014498b006c18a90d0d004e6.zip
Merge pull request #12707 from FearlessTobi/fs-housekeeping
fs: Various cleanups & add path class for later use
Diffstat (limited to 'src/core/file_sys')
-rw-r--r--src/core/file_sys/bis_factory.cpp5
-rw-r--r--src/core/file_sys/bis_factory.h2
-rw-r--r--src/core/file_sys/card_image.cpp4
-rw-r--r--src/core/file_sys/card_image.h2
-rw-r--r--src/core/file_sys/content_archive.cpp2
-rw-r--r--src/core/file_sys/content_archive.h2
-rw-r--r--src/core/file_sys/control_metadata.cpp2
-rw-r--r--src/core/file_sys/control_metadata.h2
-rw-r--r--src/core/file_sys/directory.h39
-rw-r--r--src/core/file_sys/errors.h26
-rw-r--r--src/core/file_sys/fs_directory.h33
-rw-r--r--src/core/file_sys/fs_file.h65
-rw-r--r--src/core/file_sys/fs_filesystem.h39
-rw-r--r--src/core/file_sys/fs_memory_management.h40
-rw-r--r--src/core/file_sys/fs_operate_range.h22
-rw-r--r--src/core/file_sys/fs_path.h566
-rw-r--r--src/core/file_sys/fs_path_utility.h1239
-rw-r--r--src/core/file_sys/fs_string_util.h226
-rw-r--r--src/core/file_sys/fsmitm_romfsbuild.cpp4
-rw-r--r--src/core/file_sys/fsmitm_romfsbuild.h2
-rw-r--r--src/core/file_sys/fssystem/fs_i_storage.h2
-rw-r--r--src/core/file_sys/fssystem/fssystem_aes_ctr_counter_extended_storage.cpp2
-rw-r--r--src/core/file_sys/fssystem/fssystem_aes_ctr_storage.h2
-rw-r--r--src/core/file_sys/fssystem/fssystem_bucket_tree.h2
-rw-r--r--src/core/file_sys/fssystem/fssystem_compressed_storage.h2
-rw-r--r--src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.cpp2
-rw-r--r--src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.h2
-rw-r--r--src/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.h2
-rw-r--r--src/core/file_sys/fssystem/fssystem_indirect_storage.h4
-rw-r--r--src/core/file_sys/fssystem/fssystem_integrity_romfs_storage.h2
-rw-r--r--src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp4
-rw-r--r--src/core/file_sys/fssystem/fssystem_nca_file_system_driver.h2
-rw-r--r--src/core/file_sys/fssystem/fssystem_nca_reader.cpp2
-rw-r--r--src/core/file_sys/ips_layer.cpp2
-rw-r--r--src/core/file_sys/ips_layer.h2
-rw-r--r--src/core/file_sys/kernel_executable.cpp2
-rw-r--r--src/core/file_sys/kernel_executable.h2
-rw-r--r--src/core/file_sys/mode.h23
-rw-r--r--src/core/file_sys/nca_metadata.cpp2
-rw-r--r--src/core/file_sys/nca_metadata.h2
-rw-r--r--src/core/file_sys/partition_filesystem.cpp2
-rw-r--r--src/core/file_sys/partition_filesystem.h2
-rw-r--r--src/core/file_sys/patch_manager.cpp6
-rw-r--r--src/core/file_sys/patch_manager.h2
-rw-r--r--src/core/file_sys/program_metadata.cpp2
-rw-r--r--src/core/file_sys/program_metadata.h2
-rw-r--r--src/core/file_sys/registered_cache.cpp2
-rw-r--r--src/core/file_sys/registered_cache.h2
-rw-r--r--src/core/file_sys/romfs.cpp10
-rw-r--r--src/core/file_sys/romfs.h2
-rw-r--r--src/core/file_sys/romfs_factory.h2
-rw-r--r--src/core/file_sys/savedata_factory.cpp2
-rw-r--r--src/core/file_sys/savedata_factory.h2
-rw-r--r--src/core/file_sys/sdmc_factory.cpp2
-rw-r--r--src/core/file_sys/sdmc_factory.h2
-rw-r--r--src/core/file_sys/submission_package.h2
-rw-r--r--src/core/file_sys/system_archive/mii_model.cpp2
-rw-r--r--src/core/file_sys/system_archive/mii_model.h2
-rw-r--r--src/core/file_sys/system_archive/ng_word.cpp2
-rw-r--r--src/core/file_sys/system_archive/ng_word.h2
-rw-r--r--src/core/file_sys/system_archive/shared_font.cpp2
-rw-r--r--src/core/file_sys/system_archive/shared_font.h2
-rw-r--r--src/core/file_sys/system_archive/system_archive.h2
-rw-r--r--src/core/file_sys/system_archive/system_version.cpp2
-rw-r--r--src/core/file_sys/system_archive/system_version.h2
-rw-r--r--src/core/file_sys/system_archive/time_zone_binary.cpp2
-rw-r--r--src/core/file_sys/system_archive/time_zone_binary.h2
-rw-r--r--src/core/file_sys/vfs/vfs.cpp (renamed from src/core/file_sys/vfs.cpp)29
-rw-r--r--src/core/file_sys/vfs/vfs.h (renamed from src/core/file_sys/vfs.h)13
-rw-r--r--src/core/file_sys/vfs/vfs_cached.cpp (renamed from src/core/file_sys/vfs_cached.cpp)4
-rw-r--r--src/core/file_sys/vfs/vfs_cached.h (renamed from src/core/file_sys/vfs_cached.h)2
-rw-r--r--src/core/file_sys/vfs/vfs_concat.cpp (renamed from src/core/file_sys/vfs_concat.cpp)4
-rw-r--r--src/core/file_sys/vfs/vfs_concat.h (renamed from src/core/file_sys/vfs_concat.h)2
-rw-r--r--src/core/file_sys/vfs/vfs_layered.cpp (renamed from src/core/file_sys/vfs_layered.cpp)2
-rw-r--r--src/core/file_sys/vfs/vfs_layered.h (renamed from src/core/file_sys/vfs_layered.h)2
-rw-r--r--src/core/file_sys/vfs/vfs_offset.cpp (renamed from src/core/file_sys/vfs_offset.cpp)2
-rw-r--r--src/core/file_sys/vfs/vfs_offset.h (renamed from src/core/file_sys/vfs_offset.h)2
-rw-r--r--src/core/file_sys/vfs/vfs_real.cpp (renamed from src/core/file_sys/vfs_real.cpp)55
-rw-r--r--src/core/file_sys/vfs/vfs_real.h (renamed from src/core/file_sys/vfs_real.h)27
-rw-r--r--src/core/file_sys/vfs/vfs_static.h (renamed from src/core/file_sys/vfs_static.h)2
-rw-r--r--src/core/file_sys/vfs/vfs_types.h (renamed from src/core/file_sys/vfs_types.h)0
-rw-r--r--src/core/file_sys/vfs/vfs_vector.cpp (renamed from src/core/file_sys/vfs_vector.cpp)2
-rw-r--r--src/core/file_sys/vfs/vfs_vector.h (renamed from src/core/file_sys/vfs_vector.h)2
-rw-r--r--src/core/file_sys/xts_archive.cpp2
-rw-r--r--src/core/file_sys/xts_archive.h2
85 files changed, 2390 insertions, 217 deletions
diff --git a/src/core/file_sys/bis_factory.cpp b/src/core/file_sys/bis_factory.cpp
index c750c0da7..db667438e 100644
--- a/src/core/file_sys/bis_factory.cpp
+++ b/src/core/file_sys/bis_factory.cpp
@@ -4,9 +4,8 @@
4#include <fmt/format.h> 4#include <fmt/format.h>
5#include "common/fs/path_util.h" 5#include "common/fs/path_util.h"
6#include "core/file_sys/bis_factory.h" 6#include "core/file_sys/bis_factory.h"
7#include "core/file_sys/mode.h"
8#include "core/file_sys/registered_cache.h" 7#include "core/file_sys/registered_cache.h"
9#include "core/file_sys/vfs.h" 8#include "core/file_sys/vfs/vfs.h"
10 9
11namespace FileSys { 10namespace FileSys {
12 11
@@ -84,7 +83,7 @@ VirtualFile BISFactory::OpenPartitionStorage(BisPartitionId id,
84 VirtualFilesystem file_system) const { 83 VirtualFilesystem file_system) const {
85 auto& keys = Core::Crypto::KeyManager::Instance(); 84 auto& keys = Core::Crypto::KeyManager::Instance();
86 Core::Crypto::PartitionDataManager pdm{file_system->OpenDirectory( 85 Core::Crypto::PartitionDataManager pdm{file_system->OpenDirectory(
87 Common::FS::GetYuzuPathString(Common::FS::YuzuPath::NANDDir), Mode::Read)}; 86 Common::FS::GetYuzuPathString(Common::FS::YuzuPath::NANDDir), OpenMode::Read)};
88 keys.PopulateFromPartitionData(pdm); 87 keys.PopulateFromPartitionData(pdm);
89 88
90 switch (id) { 89 switch (id) {
diff --git a/src/core/file_sys/bis_factory.h b/src/core/file_sys/bis_factory.h
index 26f0c6e5e..23680b60c 100644
--- a/src/core/file_sys/bis_factory.h
+++ b/src/core/file_sys/bis_factory.h
@@ -6,7 +6,7 @@
6#include <memory> 6#include <memory>
7 7
8#include "common/common_types.h" 8#include "common/common_types.h"
9#include "core/file_sys/vfs_types.h" 9#include "core/file_sys/vfs/vfs_types.h"
10 10
11namespace FileSys { 11namespace FileSys {
12 12
diff --git a/src/core/file_sys/card_image.cpp b/src/core/file_sys/card_image.cpp
index 8b9a4fc5a..0bcf40cf8 100644
--- a/src/core/file_sys/card_image.cpp
+++ b/src/core/file_sys/card_image.cpp
@@ -13,8 +13,8 @@
13#include "core/file_sys/nca_metadata.h" 13#include "core/file_sys/nca_metadata.h"
14#include "core/file_sys/partition_filesystem.h" 14#include "core/file_sys/partition_filesystem.h"
15#include "core/file_sys/submission_package.h" 15#include "core/file_sys/submission_package.h"
16#include "core/file_sys/vfs_offset.h" 16#include "core/file_sys/vfs/vfs_offset.h"
17#include "core/file_sys/vfs_vector.h" 17#include "core/file_sys/vfs/vfs_vector.h"
18#include "core/loader/loader.h" 18#include "core/loader/loader.h"
19 19
20namespace FileSys { 20namespace FileSys {
diff --git a/src/core/file_sys/card_image.h b/src/core/file_sys/card_image.h
index 9886123e7..97871da4a 100644
--- a/src/core/file_sys/card_image.h
+++ b/src/core/file_sys/card_image.h
@@ -8,7 +8,7 @@
8#include <vector> 8#include <vector>
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "common/swap.h" 10#include "common/swap.h"
11#include "core/file_sys/vfs.h" 11#include "core/file_sys/vfs/vfs.h"
12 12
13namespace Core::Crypto { 13namespace Core::Crypto {
14class KeyManager; 14class KeyManager;
diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp
index 7d2f0abb8..285fe4db6 100644
--- a/src/core/file_sys/content_archive.cpp
+++ b/src/core/file_sys/content_archive.cpp
@@ -13,7 +13,7 @@
13#include "core/crypto/key_manager.h" 13#include "core/crypto/key_manager.h"
14#include "core/file_sys/content_archive.h" 14#include "core/file_sys/content_archive.h"
15#include "core/file_sys/partition_filesystem.h" 15#include "core/file_sys/partition_filesystem.h"
16#include "core/file_sys/vfs_offset.h" 16#include "core/file_sys/vfs/vfs_offset.h"
17#include "core/loader/loader.h" 17#include "core/loader/loader.h"
18 18
19#include "core/file_sys/fssystem/fssystem_compression_configuration.h" 19#include "core/file_sys/fssystem/fssystem_compression_configuration.h"
diff --git a/src/core/file_sys/content_archive.h b/src/core/file_sys/content_archive.h
index af521d453..f68464eb0 100644
--- a/src/core/file_sys/content_archive.h
+++ b/src/core/file_sys/content_archive.h
@@ -13,7 +13,7 @@
13#include "common/common_types.h" 13#include "common/common_types.h"
14#include "common/swap.h" 14#include "common/swap.h"
15#include "core/crypto/key_manager.h" 15#include "core/crypto/key_manager.h"
16#include "core/file_sys/vfs.h" 16#include "core/file_sys/vfs/vfs.h"
17 17
18namespace Loader { 18namespace Loader {
19enum class ResultStatus : u16; 19enum class ResultStatus : u16;
diff --git a/src/core/file_sys/control_metadata.cpp b/src/core/file_sys/control_metadata.cpp
index 0697c29ae..f98594335 100644
--- a/src/core/file_sys/control_metadata.cpp
+++ b/src/core/file_sys/control_metadata.cpp
@@ -5,7 +5,7 @@
5#include "common/string_util.h" 5#include "common/string_util.h"
6#include "common/swap.h" 6#include "common/swap.h"
7#include "core/file_sys/control_metadata.h" 7#include "core/file_sys/control_metadata.h"
8#include "core/file_sys/vfs.h" 8#include "core/file_sys/vfs/vfs.h"
9 9
10namespace FileSys { 10namespace FileSys {
11 11
diff --git a/src/core/file_sys/control_metadata.h b/src/core/file_sys/control_metadata.h
index c98efb00d..555b9d8f7 100644
--- a/src/core/file_sys/control_metadata.h
+++ b/src/core/file_sys/control_metadata.h
@@ -8,7 +8,7 @@
8#include "common/common_funcs.h" 8#include "common/common_funcs.h"
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "common/swap.h" 10#include "common/swap.h"
11#include "core/file_sys/vfs_types.h" 11#include "core/file_sys/vfs/vfs_types.h"
12 12
13namespace FileSys { 13namespace FileSys {
14 14
diff --git a/src/core/file_sys/directory.h b/src/core/file_sys/directory.h
deleted file mode 100644
index a853c00f3..000000000
--- a/src/core/file_sys/directory.h
+++ /dev/null
@@ -1,39 +0,0 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <cstddef>
7#include "common/common_funcs.h"
8#include "common/common_types.h"
9
10////////////////////////////////////////////////////////////////////////////////////////////////////
11// FileSys namespace
12
13namespace FileSys {
14
15enum class EntryType : u8 {
16 Directory = 0,
17 File = 1,
18};
19
20// Structure of a directory entry, from
21// http://switchbrew.org/index.php?title=Filesystem_services#DirectoryEntry
22struct Entry {
23 Entry(std::string_view view, EntryType entry_type, u64 entry_size)
24 : type{entry_type}, file_size{entry_size} {
25 const std::size_t copy_size = view.copy(filename, std::size(filename) - 1);
26 filename[copy_size] = '\0';
27 }
28
29 char filename[0x301];
30 INSERT_PADDING_BYTES(3);
31 EntryType type;
32 INSERT_PADDING_BYTES(3);
33 u64 file_size;
34};
35static_assert(sizeof(Entry) == 0x310, "Directory Entry struct isn't exactly 0x310 bytes long!");
36static_assert(offsetof(Entry, type) == 0x304, "Wrong offset for type in Entry.");
37static_assert(offsetof(Entry, file_size) == 0x308, "Wrong offset for file_size in Entry.");
38
39} // namespace FileSys
diff --git a/src/core/file_sys/errors.h b/src/core/file_sys/errors.h
index 2f5045a67..d4e0eb6f4 100644
--- a/src/core/file_sys/errors.h
+++ b/src/core/file_sys/errors.h
@@ -7,18 +7,13 @@
7 7
8namespace FileSys { 8namespace FileSys {
9 9
10constexpr Result ERROR_PATH_NOT_FOUND{ErrorModule::FS, 1}; 10constexpr Result ResultPathNotFound{ErrorModule::FS, 1};
11constexpr Result ERROR_PATH_ALREADY_EXISTS{ErrorModule::FS, 2}; 11constexpr Result ResultPathAlreadyExists{ErrorModule::FS, 2};
12constexpr Result ERROR_ENTITY_NOT_FOUND{ErrorModule::FS, 1002};
13constexpr Result ERROR_SD_CARD_NOT_FOUND{ErrorModule::FS, 2001};
14constexpr Result ERROR_OUT_OF_BOUNDS{ErrorModule::FS, 3005};
15constexpr Result ERROR_FAILED_MOUNT_ARCHIVE{ErrorModule::FS, 3223};
16constexpr Result ERROR_INVALID_ARGUMENT{ErrorModule::FS, 6001};
17constexpr Result ERROR_INVALID_OFFSET{ErrorModule::FS, 6061};
18constexpr Result ERROR_INVALID_SIZE{ErrorModule::FS, 6062};
19
20constexpr Result ResultUnsupportedSdkVersion{ErrorModule::FS, 50}; 12constexpr Result ResultUnsupportedSdkVersion{ErrorModule::FS, 50};
21constexpr Result ResultPartitionNotFound{ErrorModule::FS, 1001}; 13constexpr Result ResultPartitionNotFound{ErrorModule::FS, 1001};
14constexpr Result ResultTargetNotFound{ErrorModule::FS, 1002};
15constexpr Result ResultPortSdCardNoDevice{ErrorModule::FS, 2001};
16constexpr Result ResultNotImplemented{ErrorModule::FS, 3001};
22constexpr Result ResultUnsupportedVersion{ErrorModule::FS, 3002}; 17constexpr Result ResultUnsupportedVersion{ErrorModule::FS, 3002};
23constexpr Result ResultOutOfRange{ErrorModule::FS, 3005}; 18constexpr Result ResultOutOfRange{ErrorModule::FS, 3005};
24constexpr Result ResultAllocationMemoryFailedInFileSystemBuddyHeapA{ErrorModule::FS, 3294}; 19constexpr Result ResultAllocationMemoryFailedInFileSystemBuddyHeapA{ErrorModule::FS, 3294};
@@ -78,10 +73,21 @@ constexpr Result ResultUnexpectedInCompressedStorageA{ErrorModule::FS, 5324};
78constexpr Result ResultUnexpectedInCompressedStorageB{ErrorModule::FS, 5325}; 73constexpr Result ResultUnexpectedInCompressedStorageB{ErrorModule::FS, 5325};
79constexpr Result ResultUnexpectedInCompressedStorageC{ErrorModule::FS, 5326}; 74constexpr Result ResultUnexpectedInCompressedStorageC{ErrorModule::FS, 5326};
80constexpr Result ResultUnexpectedInCompressedStorageD{ErrorModule::FS, 5327}; 75constexpr Result ResultUnexpectedInCompressedStorageD{ErrorModule::FS, 5327};
76constexpr Result ResultUnexpectedInPathA{ErrorModule::FS, 5328};
81constexpr Result ResultInvalidArgument{ErrorModule::FS, 6001}; 77constexpr Result ResultInvalidArgument{ErrorModule::FS, 6001};
78constexpr Result ResultInvalidPath{ErrorModule::FS, 6002};
79constexpr Result ResultTooLongPath{ErrorModule::FS, 6003};
80constexpr Result ResultInvalidCharacter{ErrorModule::FS, 6004};
81constexpr Result ResultInvalidPathFormat{ErrorModule::FS, 6005};
82constexpr Result ResultDirectoryUnobtainable{ErrorModule::FS, 6006};
83constexpr Result ResultNotNormalized{ErrorModule::FS, 6007};
82constexpr Result ResultInvalidOffset{ErrorModule::FS, 6061}; 84constexpr Result ResultInvalidOffset{ErrorModule::FS, 6061};
83constexpr Result ResultInvalidSize{ErrorModule::FS, 6062}; 85constexpr Result ResultInvalidSize{ErrorModule::FS, 6062};
84constexpr Result ResultNullptrArgument{ErrorModule::FS, 6063}; 86constexpr Result ResultNullptrArgument{ErrorModule::FS, 6063};
87constexpr Result ResultInvalidOpenMode{ErrorModule::FS, 6072};
88constexpr Result ResultFileExtensionWithoutOpenModeAllowAppend{ErrorModule::FS, 6201};
89constexpr Result ResultReadNotPermitted{ErrorModule::FS, 6202};
90constexpr Result ResultWriteNotPermitted{ErrorModule::FS, 6203};
85constexpr Result ResultUnsupportedSetSizeForIndirectStorage{ErrorModule::FS, 6325}; 91constexpr Result ResultUnsupportedSetSizeForIndirectStorage{ErrorModule::FS, 6325};
86constexpr Result ResultUnsupportedWriteForCompressedStorage{ErrorModule::FS, 6387}; 92constexpr Result ResultUnsupportedWriteForCompressedStorage{ErrorModule::FS, 6387};
87constexpr Result ResultUnsupportedOperateRangeForCompressedStorage{ErrorModule::FS, 6388}; 93constexpr Result ResultUnsupportedOperateRangeForCompressedStorage{ErrorModule::FS, 6388};
diff --git a/src/core/file_sys/fs_directory.h b/src/core/file_sys/fs_directory.h
new file mode 100644
index 000000000..25c9cb18a
--- /dev/null
+++ b/src/core/file_sys/fs_directory.h
@@ -0,0 +1,33 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6namespace FileSys {
7
8constexpr inline size_t EntryNameLengthMax = 0x300;
9
10struct DirectoryEntry {
11 DirectoryEntry(std::string_view view, s8 entry_type, u64 entry_size)
12 : type{entry_type}, file_size{static_cast<s64>(entry_size)} {
13 const std::size_t copy_size = view.copy(name, std::size(name) - 1);
14 name[copy_size] = '\0';
15 }
16
17 char name[EntryNameLengthMax + 1];
18 INSERT_PADDING_BYTES(3);
19 s8 type;
20 INSERT_PADDING_BYTES(3);
21 s64 file_size;
22};
23
24static_assert(sizeof(DirectoryEntry) == 0x310,
25 "Directory Entry struct isn't exactly 0x310 bytes long!");
26static_assert(offsetof(DirectoryEntry, type) == 0x304, "Wrong offset for type in Entry.");
27static_assert(offsetof(DirectoryEntry, file_size) == 0x308, "Wrong offset for file_size in Entry.");
28
29struct DirectoryHandle {
30 void* handle;
31};
32
33} // namespace FileSys
diff --git a/src/core/file_sys/fs_file.h b/src/core/file_sys/fs_file.h
new file mode 100644
index 000000000..4fb77e8db
--- /dev/null
+++ b/src/core/file_sys/fs_file.h
@@ -0,0 +1,65 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include "common/common_types.h"
7
8namespace FileSys {
9
10struct ReadOption {
11 u32 value;
12
13 static const ReadOption None;
14};
15
16enum ReadOptionFlag : u32 {
17 ReadOptionFlag_None = (0 << 0),
18};
19
20inline constexpr const ReadOption ReadOption::None = {ReadOptionFlag_None};
21
22inline constexpr bool operator==(const ReadOption& lhs, const ReadOption& rhs) {
23 return lhs.value == rhs.value;
24}
25
26inline constexpr bool operator!=(const ReadOption& lhs, const ReadOption& rhs) {
27 return !(lhs == rhs);
28}
29
30static_assert(sizeof(ReadOption) == sizeof(u32));
31
32enum WriteOptionFlag : u32 {
33 WriteOptionFlag_None = (0 << 0),
34 WriteOptionFlag_Flush = (1 << 0),
35};
36
37struct WriteOption {
38 u32 value;
39
40 constexpr inline bool HasFlushFlag() const {
41 return value & WriteOptionFlag_Flush;
42 }
43
44 static const WriteOption None;
45 static const WriteOption Flush;
46};
47
48inline constexpr const WriteOption WriteOption::None = {WriteOptionFlag_None};
49inline constexpr const WriteOption WriteOption::Flush = {WriteOptionFlag_Flush};
50
51inline constexpr bool operator==(const WriteOption& lhs, const WriteOption& rhs) {
52 return lhs.value == rhs.value;
53}
54
55inline constexpr bool operator!=(const WriteOption& lhs, const WriteOption& rhs) {
56 return !(lhs == rhs);
57}
58
59static_assert(sizeof(WriteOption) == sizeof(u32));
60
61struct FileHandle {
62 void* handle;
63};
64
65} // namespace FileSys
diff --git a/src/core/file_sys/fs_filesystem.h b/src/core/file_sys/fs_filesystem.h
new file mode 100644
index 000000000..7f237b7fa
--- /dev/null
+++ b/src/core/file_sys/fs_filesystem.h
@@ -0,0 +1,39 @@
1// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include "common/common_funcs.h"
7#include "common/common_types.h"
8
9namespace FileSys {
10
11enum class OpenMode : u32 {
12 Read = (1 << 0),
13 Write = (1 << 1),
14 AllowAppend = (1 << 2),
15
16 ReadWrite = (Read | Write),
17 All = (ReadWrite | AllowAppend),
18};
19DECLARE_ENUM_FLAG_OPERATORS(OpenMode)
20
21enum class OpenDirectoryMode : u64 {
22 Directory = (1 << 0),
23 File = (1 << 1),
24
25 All = (Directory | File),
26};
27DECLARE_ENUM_FLAG_OPERATORS(OpenDirectoryMode)
28
29enum class DirectoryEntryType : u8 {
30 Directory = 0,
31 File = 1,
32};
33
34enum class CreateOption : u8 {
35 None = (0 << 0),
36 BigFile = (1 << 0),
37};
38
39} // namespace FileSys
diff --git a/src/core/file_sys/fs_memory_management.h b/src/core/file_sys/fs_memory_management.h
new file mode 100644
index 000000000..f03c6354b
--- /dev/null
+++ b/src/core/file_sys/fs_memory_management.h
@@ -0,0 +1,40 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include <mutex>
7#include "common/alignment.h"
8
9namespace FileSys {
10
11constexpr size_t RequiredAlignment = alignof(u64);
12
13void* AllocateUnsafe(size_t size) {
14 // Allocate
15 void* const ptr = ::operator new(size, std::align_val_t{RequiredAlignment});
16
17 // Check alignment
18 ASSERT(Common::IsAligned(reinterpret_cast<uintptr_t>(ptr), RequiredAlignment));
19
20 // Return allocated pointer
21 return ptr;
22}
23
24void DeallocateUnsafe(void* ptr, size_t size) {
25 // Deallocate the pointer
26 ::operator delete(ptr, std::align_val_t{RequiredAlignment});
27}
28
29void* Allocate(size_t size) {
30 return AllocateUnsafe(size);
31}
32
33void Deallocate(void* ptr, size_t size) {
34 // If the pointer is non-null, deallocate it
35 if (ptr != nullptr) {
36 DeallocateUnsafe(ptr, size);
37 }
38}
39
40} // namespace FileSys
diff --git a/src/core/file_sys/fs_operate_range.h b/src/core/file_sys/fs_operate_range.h
new file mode 100644
index 000000000..04ea64cc0
--- /dev/null
+++ b/src/core/file_sys/fs_operate_range.h
@@ -0,0 +1,22 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include "common/common_types.h"
7
8namespace FileSys {
9
10enum class OperationId : s64 {
11 FillZero = 0,
12 DestroySignature = 1,
13 Invalidate = 2,
14 QueryRange = 3,
15 QueryUnpreparedRange = 4,
16 QueryLazyLoadCompletionRate = 5,
17 SetLazyLoadPriority = 6,
18
19 ReadLazyLoadFileForciblyForDebug = 10001,
20};
21
22} // namespace FileSys
diff --git a/src/core/file_sys/fs_path.h b/src/core/file_sys/fs_path.h
new file mode 100644
index 000000000..56ba08a6a
--- /dev/null
+++ b/src/core/file_sys/fs_path.h
@@ -0,0 +1,566 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include "common/alignment.h"
7#include "common/common_funcs.h"
8#include "core/file_sys/errors.h"
9#include "core/file_sys/fs_memory_management.h"
10#include "core/file_sys/fs_path_utility.h"
11#include "core/file_sys/fs_string_util.h"
12#include "core/hle/result.h"
13
14namespace FileSys {
15class DirectoryPathParser;
16
17class Path {
18 YUZU_NON_COPYABLE(Path);
19 YUZU_NON_MOVEABLE(Path);
20
21private:
22 static constexpr const char* EmptyPath = "";
23 static constexpr size_t WriteBufferAlignmentLength = 8;
24
25private:
26 friend class DirectoryPathParser;
27
28public:
29 class WriteBuffer {
30 YUZU_NON_COPYABLE(WriteBuffer);
31
32 private:
33 char* m_buffer;
34 size_t m_length_and_is_normalized;
35
36 public:
37 constexpr WriteBuffer() : m_buffer(nullptr), m_length_and_is_normalized(0) {}
38
39 constexpr ~WriteBuffer() {
40 if (m_buffer != nullptr) {
41 Deallocate(m_buffer, this->GetLength());
42 this->ResetBuffer();
43 }
44 }
45
46 constexpr WriteBuffer(WriteBuffer&& rhs)
47 : m_buffer(rhs.m_buffer), m_length_and_is_normalized(rhs.m_length_and_is_normalized) {
48 rhs.ResetBuffer();
49 }
50
51 constexpr WriteBuffer& operator=(WriteBuffer&& rhs) {
52 if (m_buffer != nullptr) {
53 Deallocate(m_buffer, this->GetLength());
54 }
55
56 m_buffer = rhs.m_buffer;
57 m_length_and_is_normalized = rhs.m_length_and_is_normalized;
58
59 rhs.ResetBuffer();
60
61 return *this;
62 }
63
64 constexpr void ResetBuffer() {
65 m_buffer = nullptr;
66 this->SetLength(0);
67 }
68
69 constexpr char* Get() const {
70 return m_buffer;
71 }
72
73 constexpr size_t GetLength() const {
74 return m_length_and_is_normalized >> 1;
75 }
76
77 constexpr bool IsNormalized() const {
78 return static_cast<bool>(m_length_and_is_normalized & 1);
79 }
80
81 constexpr void SetNormalized() {
82 m_length_and_is_normalized |= static_cast<size_t>(1);
83 }
84
85 constexpr void SetNotNormalized() {
86 m_length_and_is_normalized &= ~static_cast<size_t>(1);
87 }
88
89 private:
90 constexpr WriteBuffer(char* buffer, size_t length)
91 : m_buffer(buffer), m_length_and_is_normalized(0) {
92 this->SetLength(length);
93 }
94
95 public:
96 static WriteBuffer Make(size_t length) {
97 if (void* alloc = Allocate(length); alloc != nullptr) {
98 return WriteBuffer(static_cast<char*>(alloc), length);
99 } else {
100 return WriteBuffer();
101 }
102 }
103
104 private:
105 constexpr void SetLength(size_t size) {
106 m_length_and_is_normalized = (m_length_and_is_normalized & 1) | (size << 1);
107 }
108 };
109
110private:
111 const char* m_str;
112 WriteBuffer m_write_buffer;
113
114public:
115 constexpr Path() : m_str(EmptyPath), m_write_buffer() {}
116
117 constexpr Path(const char* s) : m_str(s), m_write_buffer() {
118 m_write_buffer.SetNormalized();
119 }
120
121 constexpr ~Path() = default;
122
123 constexpr Result SetShallowBuffer(const char* buffer) {
124 // Check pre-conditions
125 ASSERT(m_write_buffer.GetLength() == 0);
126
127 // Check the buffer is valid
128 R_UNLESS(buffer != nullptr, ResultNullptrArgument);
129
130 // Set buffer
131 this->SetReadOnlyBuffer(buffer);
132
133 // Note that we're normalized
134 this->SetNormalized();
135
136 R_SUCCEED();
137 }
138
139 constexpr const char* GetString() const {
140 // Check pre-conditions
141 ASSERT(this->IsNormalized());
142
143 return m_str;
144 }
145
146 constexpr size_t GetLength() const {
147 if (std::is_constant_evaluated()) {
148 return Strlen(this->GetString());
149 } else {
150 return std::strlen(this->GetString());
151 }
152 }
153
154 constexpr bool IsEmpty() const {
155 return *m_str == '\x00';
156 }
157
158 constexpr bool IsMatchHead(const char* p, size_t len) const {
159 return Strncmp(this->GetString(), p, len) == 0;
160 }
161
162 Result Initialize(const Path& rhs) {
163 // Check the other path is normalized
164 const bool normalized = rhs.IsNormalized();
165 R_UNLESS(normalized, ResultNotNormalized);
166
167 // Allocate buffer for our path
168 const auto len = rhs.GetLength();
169 R_TRY(this->Preallocate(len + 1));
170
171 // Copy the path
172 const size_t copied = Strlcpy<char>(m_write_buffer.Get(), rhs.GetString(), len + 1);
173 R_UNLESS(copied == len, ResultUnexpectedInPathA);
174
175 // Set normalized
176 this->SetNormalized();
177 R_SUCCEED();
178 }
179
180 Result Initialize(const char* path, size_t len) {
181 // Check the path is valid
182 R_UNLESS(path != nullptr, ResultNullptrArgument);
183
184 // Initialize
185 R_TRY(this->InitializeImpl(path, len));
186
187 // Set not normalized
188 this->SetNotNormalized();
189
190 R_SUCCEED();
191 }
192
193 Result Initialize(const char* path) {
194 // Check the path is valid
195 R_UNLESS(path != nullptr, ResultNullptrArgument);
196
197 R_RETURN(this->Initialize(path, std::strlen(path)));
198 }
199
200 Result InitializeWithReplaceBackslash(const char* path) {
201 // Check the path is valid
202 R_UNLESS(path != nullptr, ResultNullptrArgument);
203
204 // Initialize
205 R_TRY(this->InitializeImpl(path, std::strlen(path)));
206
207 // Replace slashes as desired
208 if (const auto write_buffer_length = m_write_buffer.GetLength(); write_buffer_length > 1) {
209 Replace(m_write_buffer.Get(), write_buffer_length - 1, '\\', '/');
210 }
211
212 // Set not normalized
213 this->SetNotNormalized();
214
215 R_SUCCEED();
216 }
217
218 Result InitializeWithReplaceForwardSlashes(const char* path) {
219 // Check the path is valid
220 R_UNLESS(path != nullptr, ResultNullptrArgument);
221
222 // Initialize
223 R_TRY(this->InitializeImpl(path, std::strlen(path)));
224
225 // Replace slashes as desired
226 if (m_write_buffer.GetLength() > 1) {
227 if (auto* p = m_write_buffer.Get(); p[0] == '/' && p[1] == '/') {
228 p[0] = '\\';
229 p[1] = '\\';
230 }
231 }
232
233 // Set not normalized
234 this->SetNotNormalized();
235
236 R_SUCCEED();
237 }
238
239 Result InitializeWithNormalization(const char* path, size_t size) {
240 // Check the path is valid
241 R_UNLESS(path != nullptr, ResultNullptrArgument);
242
243 // Initialize
244 R_TRY(this->InitializeImpl(path, size));
245
246 // Set not normalized
247 this->SetNotNormalized();
248
249 // Perform normalization
250 PathFlags path_flags;
251 if (IsPathRelative(m_str)) {
252 path_flags.AllowRelativePath();
253 } else if (IsWindowsPath(m_str, true)) {
254 path_flags.AllowWindowsPath();
255 } else {
256 /* NOTE: In this case, Nintendo checks is normalized, then sets is normalized, then
257 * returns success. */
258 /* This seems like a bug. */
259 size_t dummy;
260 bool normalized;
261 R_TRY(PathFormatter::IsNormalized(std::addressof(normalized), std::addressof(dummy),
262 m_str));
263
264 this->SetNormalized();
265 R_SUCCEED();
266 }
267
268 // Normalize
269 R_TRY(this->Normalize(path_flags));
270
271 this->SetNormalized();
272 R_SUCCEED();
273 }
274
275 Result InitializeWithNormalization(const char* path) {
276 // Check the path is valid
277 R_UNLESS(path != nullptr, ResultNullptrArgument);
278
279 R_RETURN(this->InitializeWithNormalization(path, std::strlen(path)));
280 }
281
282 Result InitializeAsEmpty() {
283 // Clear our buffer
284 this->ClearBuffer();
285
286 // Set normalized
287 this->SetNormalized();
288
289 R_SUCCEED();
290 }
291
292 Result AppendChild(const char* child) {
293 // Check the path is valid
294 R_UNLESS(child != nullptr, ResultNullptrArgument);
295
296 // Basic checks. If we have a path and the child is empty, we have nothing to do
297 const char* c = child;
298 if (m_str[0]) {
299 // Skip an early separator
300 if (*c == '/') {
301 ++c;
302 }
303
304 R_SUCCEED_IF(*c == '\x00');
305 }
306
307 // If we don't have a string, we can just initialize
308 auto cur_len = std::strlen(m_str);
309 if (cur_len == 0) {
310 R_RETURN(this->Initialize(child));
311 }
312
313 // Remove a trailing separator
314 if (m_str[cur_len - 1] == '/' || m_str[cur_len - 1] == '\\') {
315 --cur_len;
316 }
317
318 // Get the child path's length
319 auto child_len = std::strlen(c);
320
321 // Reset our write buffer
322 WriteBuffer old_write_buffer;
323 if (m_write_buffer.Get() != nullptr) {
324 old_write_buffer = std::move(m_write_buffer);
325 this->ClearBuffer();
326 }
327
328 // Pre-allocate the new buffer
329 R_TRY(this->Preallocate(cur_len + 1 + child_len + 1));
330
331 // Get our write buffer
332 auto* dst = m_write_buffer.Get();
333 if (old_write_buffer.Get() != nullptr && cur_len > 0) {
334 Strlcpy<char>(dst, old_write_buffer.Get(), cur_len + 1);
335 }
336
337 // Add separator
338 dst[cur_len] = '/';
339
340 // Copy the child path
341 const size_t copied = Strlcpy<char>(dst + cur_len + 1, c, child_len + 1);
342 R_UNLESS(copied == child_len, ResultUnexpectedInPathA);
343
344 R_SUCCEED();
345 }
346
347 Result AppendChild(const Path& rhs) {
348 R_RETURN(this->AppendChild(rhs.GetString()));
349 }
350
351 Result Combine(const Path& parent, const Path& child) {
352 // Get the lengths
353 const auto p_len = parent.GetLength();
354 const auto c_len = child.GetLength();
355
356 // Allocate our buffer
357 R_TRY(this->Preallocate(p_len + c_len + 1));
358
359 // Initialize as parent
360 R_TRY(this->Initialize(parent));
361
362 // If we're empty, we can just initialize as child
363 if (this->IsEmpty()) {
364 R_TRY(this->Initialize(child));
365 } else {
366 // Otherwise, we should append the child
367 R_TRY(this->AppendChild(child));
368 }
369
370 R_SUCCEED();
371 }
372
373 Result RemoveChild() {
374 // If we don't have a write-buffer, ensure that we have one
375 if (m_write_buffer.Get() == nullptr) {
376 if (const auto len = std::strlen(m_str); len > 0) {
377 R_TRY(this->Preallocate(len));
378 Strlcpy<char>(m_write_buffer.Get(), m_str, len + 1);
379 }
380 }
381
382 // Check that it's possible for us to remove a child
383 auto* p = m_write_buffer.Get();
384 s32 len = std::strlen(p);
385 R_UNLESS(len != 1 || (p[0] != '/' && p[0] != '.'), ResultNotImplemented);
386
387 // Handle a trailing separator
388 if (len > 0 && (p[len - 1] == '\\' || p[len - 1] == '/')) {
389 --len;
390 }
391
392 // Remove the child path segment
393 while ((--len) >= 0 && p[len]) {
394 if (p[len] == '/' || p[len] == '\\') {
395 if (len > 0) {
396 p[len] = 0;
397 } else {
398 p[1] = 0;
399 len = 1;
400 }
401 break;
402 }
403 }
404
405 // Check that length remains > 0
406 R_UNLESS(len > 0, ResultNotImplemented);
407
408 R_SUCCEED();
409 }
410
411 Result Normalize(const PathFlags& flags) {
412 // If we're already normalized, nothing to do
413 R_SUCCEED_IF(this->IsNormalized());
414
415 // Check if we're normalized
416 bool normalized;
417 size_t dummy;
418 R_TRY(PathFormatter::IsNormalized(std::addressof(normalized), std::addressof(dummy), m_str,
419 flags));
420
421 // If we're not normalized, normalize
422 if (!normalized) {
423 // Determine necessary buffer length
424 auto len = m_write_buffer.GetLength();
425 if (flags.IsRelativePathAllowed() && IsPathRelative(m_str)) {
426 len += 2;
427 }
428 if (flags.IsWindowsPathAllowed() && IsWindowsPath(m_str, true)) {
429 len += 1;
430 }
431
432 // Allocate a new buffer
433 const size_t size = Common::AlignUp(len, WriteBufferAlignmentLength);
434 auto buf = WriteBuffer::Make(size);
435 R_UNLESS(buf.Get() != nullptr, ResultAllocationMemoryFailedMakeUnique);
436
437 // Normalize into it
438 R_TRY(PathFormatter::Normalize(buf.Get(), size, m_write_buffer.Get(),
439 m_write_buffer.GetLength(), flags));
440
441 // Set the normalized buffer as our buffer
442 this->SetModifiableBuffer(std::move(buf));
443 }
444
445 // Set normalized
446 this->SetNormalized();
447 R_SUCCEED();
448 }
449
450private:
451 void ClearBuffer() {
452 m_write_buffer.ResetBuffer();
453 m_str = EmptyPath;
454 }
455
456 void SetModifiableBuffer(WriteBuffer&& buffer) {
457 // Check pre-conditions
458 ASSERT(buffer.Get() != nullptr);
459 ASSERT(buffer.GetLength() > 0);
460 ASSERT(Common::IsAligned(buffer.GetLength(), WriteBufferAlignmentLength));
461
462 // Get whether we're normalized
463 if (m_write_buffer.IsNormalized()) {
464 buffer.SetNormalized();
465 } else {
466 buffer.SetNotNormalized();
467 }
468
469 // Set write buffer
470 m_write_buffer = std::move(buffer);
471 m_str = m_write_buffer.Get();
472 }
473
474 constexpr void SetReadOnlyBuffer(const char* buffer) {
475 m_str = buffer;
476 m_write_buffer.ResetBuffer();
477 }
478
479 Result Preallocate(size_t length) {
480 // Allocate additional space, if needed
481 if (length > m_write_buffer.GetLength()) {
482 // Allocate buffer
483 const size_t size = Common::AlignUp(length, WriteBufferAlignmentLength);
484 auto buf = WriteBuffer::Make(size);
485 R_UNLESS(buf.Get() != nullptr, ResultAllocationMemoryFailedMakeUnique);
486
487 // Set write buffer
488 this->SetModifiableBuffer(std::move(buf));
489 }
490
491 R_SUCCEED();
492 }
493
494 Result InitializeImpl(const char* path, size_t size) {
495 if (size > 0 && path[0]) {
496 // Pre allocate a buffer for the path
497 R_TRY(this->Preallocate(size + 1));
498
499 // Copy the path
500 const size_t copied = Strlcpy<char>(m_write_buffer.Get(), path, size + 1);
501 R_UNLESS(copied >= size, ResultUnexpectedInPathA);
502 } else {
503 // We can just clear the buffer
504 this->ClearBuffer();
505 }
506
507 R_SUCCEED();
508 }
509
510 constexpr char* GetWriteBuffer() {
511 ASSERT(m_write_buffer.Get() != nullptr);
512 return m_write_buffer.Get();
513 }
514
515 constexpr size_t GetWriteBufferLength() const {
516 return m_write_buffer.GetLength();
517 }
518
519 constexpr bool IsNormalized() const {
520 return m_write_buffer.IsNormalized();
521 }
522
523 constexpr void SetNormalized() {
524 m_write_buffer.SetNormalized();
525 }
526
527 constexpr void SetNotNormalized() {
528 m_write_buffer.SetNotNormalized();
529 }
530
531public:
532 bool operator==(const FileSys::Path& rhs) const {
533 return std::strcmp(this->GetString(), rhs.GetString()) == 0;
534 }
535 bool operator!=(const FileSys::Path& rhs) const {
536 return !(*this == rhs);
537 }
538 bool operator==(const char* p) const {
539 return std::strcmp(this->GetString(), p) == 0;
540 }
541 bool operator!=(const char* p) const {
542 return !(*this == p);
543 }
544};
545
546inline Result SetUpFixedPath(FileSys::Path* out, const char* s) {
547 // Verify the path is normalized
548 bool normalized;
549 size_t dummy;
550 R_TRY(PathNormalizer::IsNormalized(std::addressof(normalized), std::addressof(dummy), s));
551
552 R_UNLESS(normalized, ResultInvalidPathFormat);
553
554 // Set the fixed path
555 R_RETURN(out->SetShallowBuffer(s));
556}
557
558constexpr inline bool IsWindowsDriveRootPath(const FileSys::Path& path) {
559 const char* const str = path.GetString();
560 return IsWindowsDrive(str) &&
561 (str[2] == StringTraits::DirectorySeparator ||
562 str[2] == StringTraits::AlternateDirectorySeparator) &&
563 str[3] == StringTraits::NullTerminator;
564}
565
566} // namespace FileSys
diff --git a/src/core/file_sys/fs_path_utility.h b/src/core/file_sys/fs_path_utility.h
new file mode 100644
index 000000000..e9011d065
--- /dev/null
+++ b/src/core/file_sys/fs_path_utility.h
@@ -0,0 +1,1239 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include "common/assert.h"
7#include "common/common_funcs.h"
8#include "common/common_types.h"
9#include "common/scope_exit.h"
10#include "core/file_sys/fs_directory.h"
11#include "core/file_sys/fs_memory_management.h"
12#include "core/file_sys/fs_string_util.h"
13#include "core/hle/result.h"
14
15namespace FileSys {
16
17constexpr inline size_t MountNameLengthMax = 15;
18
19namespace StringTraits {
20
21constexpr inline char DirectorySeparator = '/';
22constexpr inline char DriveSeparator = ':';
23constexpr inline char Dot = '.';
24constexpr inline char NullTerminator = '\x00';
25
26constexpr inline char AlternateDirectorySeparator = '\\';
27
28constexpr inline const char InvalidCharacters[6] = {':', '*', '?', '<', '>', '|'};
29constexpr inline const char InvalidCharactersForHostName[6] = {':', '*', '<', '>', '|', '$'};
30constexpr inline const char InvalidCharactersForMountName[5] = {'*', '?', '<', '>', '|'};
31
32namespace impl {
33
34template <const char* InvalidCharacterSet, size_t NumInvalidCharacters>
35consteval u64 MakeInvalidCharacterMask(size_t n) {
36 u64 mask = 0;
37 for (size_t i = 0; i < NumInvalidCharacters; ++i) {
38 if ((static_cast<u64>(InvalidCharacterSet[i]) >> 6) == n) {
39 mask |= static_cast<u64>(1) << (static_cast<u64>(InvalidCharacterSet[i]) & 0x3F);
40 }
41 }
42 return mask;
43}
44
45template <const char* InvalidCharacterSet, size_t NumInvalidCharacters>
46constexpr bool IsInvalidCharacterImpl(char c) {
47 constexpr u64 Masks[4] = {
48 MakeInvalidCharacterMask<InvalidCharacterSet, NumInvalidCharacters>(0),
49 MakeInvalidCharacterMask<InvalidCharacterSet, NumInvalidCharacters>(1),
50 MakeInvalidCharacterMask<InvalidCharacterSet, NumInvalidCharacters>(2),
51 MakeInvalidCharacterMask<InvalidCharacterSet, NumInvalidCharacters>(3)};
52
53 return (Masks[static_cast<u64>(c) >> 6] &
54 (static_cast<u64>(1) << (static_cast<u64>(c) & 0x3F))) != 0;
55}
56
57} // namespace impl
58
59constexpr bool IsInvalidCharacter(char c) {
60 return impl::IsInvalidCharacterImpl<InvalidCharacters, Common::Size(InvalidCharacters)>(c);
61}
62constexpr bool IsInvalidCharacterForHostName(char c) {
63 return impl::IsInvalidCharacterImpl<InvalidCharactersForHostName,
64 Common::Size(InvalidCharactersForHostName)>(c);
65}
66constexpr bool IsInvalidCharacterForMountName(char c) {
67 return impl::IsInvalidCharacterImpl<InvalidCharactersForMountName,
68 Common::Size(InvalidCharactersForMountName)>(c);
69}
70
71} // namespace StringTraits
72
73constexpr inline size_t WindowsDriveLength = 2;
74constexpr inline size_t UncPathPrefixLength = 2;
75constexpr inline size_t DosDevicePathPrefixLength = 4;
76
77class PathFlags {
78private:
79 static constexpr u32 WindowsPathFlag = (1 << 0);
80 static constexpr u32 RelativePathFlag = (1 << 1);
81 static constexpr u32 EmptyPathFlag = (1 << 2);
82 static constexpr u32 MountNameFlag = (1 << 3);
83 static constexpr u32 BackslashFlag = (1 << 4);
84 static constexpr u32 AllCharactersFlag = (1 << 5);
85
86private:
87 u32 m_value;
88
89public:
90 constexpr PathFlags() : m_value(0) { /* ... */
91 }
92
93#define DECLARE_PATH_FLAG_HANDLER(__WHICH__) \
94 constexpr bool Is##__WHICH__##Allowed() const { return (m_value & __WHICH__##Flag) != 0; } \
95 constexpr void Allow##__WHICH__() { m_value |= __WHICH__##Flag; }
96
97 DECLARE_PATH_FLAG_HANDLER(WindowsPath)
98 DECLARE_PATH_FLAG_HANDLER(RelativePath)
99 DECLARE_PATH_FLAG_HANDLER(EmptyPath)
100 DECLARE_PATH_FLAG_HANDLER(MountName)
101 DECLARE_PATH_FLAG_HANDLER(Backslash)
102 DECLARE_PATH_FLAG_HANDLER(AllCharacters)
103
104#undef DECLARE_PATH_FLAG_HANDLER
105};
106
107template <typename T>
108 requires(std::same_as<T, char> || std::same_as<T, wchar_t>)
109constexpr inline bool IsDosDevicePath(const T* path) {
110 ASSERT(path != nullptr);
111
112 using namespace StringTraits;
113
114 return path[0] == AlternateDirectorySeparator && path[1] == AlternateDirectorySeparator &&
115 (path[2] == Dot || path[2] == '?') &&
116 (path[3] == DirectorySeparator || path[3] == AlternateDirectorySeparator);
117}
118
119template <typename T>
120 requires(std::same_as<T, char> || std::same_as<T, wchar_t>)
121constexpr inline bool IsUncPath(const T* path, bool allow_forward_slash = true,
122 bool allow_back_slash = true) {
123 ASSERT(path != nullptr);
124
125 using namespace StringTraits;
126
127 return (allow_forward_slash && path[0] == DirectorySeparator &&
128 path[1] == DirectorySeparator) ||
129 (allow_back_slash && path[0] == AlternateDirectorySeparator &&
130 path[1] == AlternateDirectorySeparator);
131}
132
133constexpr inline bool IsWindowsDrive(const char* path) {
134 ASSERT(path != nullptr);
135
136 return (('a' <= path[0] && path[0] <= 'z') || ('A' <= path[0] && path[0] <= 'Z')) &&
137 path[1] == StringTraits::DriveSeparator;
138}
139
140constexpr inline bool IsWindowsPath(const char* path, bool allow_forward_slash_unc) {
141 return IsWindowsDrive(path) || IsDosDevicePath(path) ||
142 IsUncPath(path, allow_forward_slash_unc, true);
143}
144
145constexpr inline int GetWindowsSkipLength(const char* path) {
146 if (IsDosDevicePath(path)) {
147 return DosDevicePathPrefixLength;
148 } else if (IsWindowsDrive(path)) {
149 return WindowsDriveLength;
150 } else if (IsUncPath(path)) {
151 return UncPathPrefixLength;
152 } else {
153 return 0;
154 }
155}
156
157constexpr inline bool IsPathAbsolute(const char* path) {
158 return IsWindowsPath(path, false) || path[0] == StringTraits::DirectorySeparator;
159}
160
161constexpr inline bool IsPathRelative(const char* path) {
162 return path[0] && !IsPathAbsolute(path);
163}
164
165constexpr inline bool IsCurrentDirectory(const char* path) {
166 return path[0] == StringTraits::Dot &&
167 (path[1] == StringTraits::NullTerminator || path[1] == StringTraits::DirectorySeparator);
168}
169
170constexpr inline bool IsParentDirectory(const char* path) {
171 return path[0] == StringTraits::Dot && path[1] == StringTraits::Dot &&
172 (path[2] == StringTraits::NullTerminator || path[2] == StringTraits::DirectorySeparator);
173}
174
175constexpr inline bool IsPathStartWithCurrentDirectory(const char* path) {
176 return IsCurrentDirectory(path) || IsParentDirectory(path);
177}
178
179constexpr inline bool IsSubPath(const char* lhs, const char* rhs) {
180 // Check pre-conditions
181 ASSERT(lhs != nullptr);
182 ASSERT(rhs != nullptr);
183
184 // Import StringTraits names for current scope
185 using namespace StringTraits;
186
187 // Special case certain paths
188 if (IsUncPath(lhs) && !IsUncPath(rhs)) {
189 return false;
190 }
191 if (!IsUncPath(lhs) && IsUncPath(rhs)) {
192 return false;
193 }
194
195 if (lhs[0] == DirectorySeparator && lhs[1] == NullTerminator && rhs[0] == DirectorySeparator &&
196 rhs[1] != NullTerminator) {
197 return true;
198 }
199 if (rhs[0] == DirectorySeparator && rhs[1] == NullTerminator && lhs[0] == DirectorySeparator &&
200 lhs[1] != NullTerminator) {
201 return true;
202 }
203
204 // Check subpath
205 for (size_t i = 0; /* ... */; ++i) {
206 if (lhs[i] == NullTerminator) {
207 return rhs[i] == DirectorySeparator;
208 } else if (rhs[i] == NullTerminator) {
209 return lhs[i] == DirectorySeparator;
210 } else if (lhs[i] != rhs[i]) {
211 return false;
212 }
213 }
214}
215
216// Path utilities
217constexpr inline void Replace(char* dst, size_t dst_size, char old_char, char new_char) {
218 ASSERT(dst != nullptr);
219 for (char* cur = dst; cur < dst + dst_size && *cur; ++cur) {
220 if (*cur == old_char) {
221 *cur = new_char;
222 }
223 }
224}
225
226constexpr inline Result CheckUtf8(const char* s) {
227 // Check pre-conditions
228 ASSERT(s != nullptr);
229
230 // Iterate, checking for utf8-validity
231 while (*s) {
232 char utf8_buf[4] = {};
233
234 const auto pick_res = PickOutCharacterFromUtf8String(utf8_buf, std::addressof(s));
235 R_UNLESS(pick_res == CharacterEncodingResult_Success, ResultInvalidPathFormat);
236
237 u32 dummy;
238 const auto cvt_res = ConvertCharacterUtf8ToUtf32(std::addressof(dummy), utf8_buf);
239 R_UNLESS(cvt_res == CharacterEncodingResult_Success, ResultInvalidPathFormat);
240 }
241
242 R_SUCCEED();
243}
244
245// Path formatting
246class PathNormalizer {
247private:
248 enum class PathState {
249 Start,
250 Normal,
251 FirstSeparator,
252 Separator,
253 CurrentDir,
254 ParentDir,
255 };
256
257private:
258 static constexpr void ReplaceParentDirectoryPath(char* dst, const char* src) {
259 // Use StringTraits names for remainder of scope
260 using namespace StringTraits;
261
262 // Start with a dir-separator
263 dst[0] = DirectorySeparator;
264
265 auto i = 1;
266 while (src[i] != NullTerminator) {
267 if ((src[i - 1] == DirectorySeparator || src[i - 1] == AlternateDirectorySeparator) &&
268 src[i + 0] == Dot && src[i + 1] == Dot &&
269 (src[i + 2] == DirectorySeparator || src[i + 2] == AlternateDirectorySeparator)) {
270 dst[i - 1] = DirectorySeparator;
271 dst[i + 0] = Dot;
272 dst[i + 1] = Dot;
273 dst[i + 2] = DirectorySeparator;
274 i += 3;
275 } else {
276 if (src[i - 1] == AlternateDirectorySeparator && src[i + 0] == Dot &&
277 src[i + 1] == Dot && src[i + 2] == NullTerminator) {
278 dst[i - 1] = DirectorySeparator;
279 dst[i + 0] = Dot;
280 dst[i + 1] = Dot;
281 i += 2;
282 break;
283 }
284
285 dst[i] = src[i];
286 ++i;
287 }
288 }
289
290 dst[i] = StringTraits::NullTerminator;
291 }
292
293public:
294 static constexpr bool IsParentDirectoryPathReplacementNeeded(const char* path) {
295 // Use StringTraits names for remainder of scope
296 using namespace StringTraits;
297
298 if (path[0] != DirectorySeparator && path[0] != AlternateDirectorySeparator) {
299 return false;
300 }
301
302 // Check to find a parent reference using alternate separators
303 if (path[0] != NullTerminator && path[1] != NullTerminator && path[2] != NullTerminator) {
304 size_t i;
305 for (i = 0; path[i + 3] != NullTerminator; ++path) {
306 if (path[i + 1] != Dot || path[i + 2] != Dot) {
307 continue;
308 }
309
310 const char c0 = path[i + 0];
311 const char c3 = path[i + 3];
312
313 if (c0 == AlternateDirectorySeparator &&
314 (c3 == DirectorySeparator || c3 == AlternateDirectorySeparator ||
315 c3 == NullTerminator)) {
316 return true;
317 }
318
319 if (c3 == AlternateDirectorySeparator &&
320 (c0 == DirectorySeparator || c0 == AlternateDirectorySeparator)) {
321 return true;
322 }
323 }
324
325 if (path[i + 0] == AlternateDirectorySeparator && path[i + 1] == Dot &&
326 path[i + 2] == Dot /* && path[i + 3] == NullTerminator */) {
327 return true;
328 }
329 }
330
331 return false;
332 }
333
334 static constexpr Result IsNormalized(bool* out, size_t* out_len, const char* path,
335 bool allow_all_characters = false) {
336 // Use StringTraits names for remainder of scope
337 using namespace StringTraits;
338
339 // Parse the path
340 auto state = PathState::Start;
341 size_t len = 0;
342 while (path[len] != NullTerminator) {
343 // Get the current character
344 const char c = path[len++];
345
346 // Check the current character is valid
347 if (!allow_all_characters && state != PathState::Start) {
348 R_UNLESS(!IsInvalidCharacter(c), ResultInvalidCharacter);
349 }
350
351 // Process depending on current state
352 switch (state) {
353 // Import the PathState enums for convenience
354 using enum PathState;
355
356 case Start:
357 R_UNLESS(c == DirectorySeparator, ResultInvalidPathFormat);
358 state = FirstSeparator;
359 break;
360 case Normal:
361 if (c == DirectorySeparator) {
362 state = Separator;
363 }
364 break;
365 case FirstSeparator:
366 case Separator:
367 if (c == DirectorySeparator) {
368 *out = false;
369 R_SUCCEED();
370 }
371
372 if (c == Dot) {
373 state = CurrentDir;
374 } else {
375 state = Normal;
376 }
377 break;
378 case CurrentDir:
379 if (c == DirectorySeparator) {
380 *out = false;
381 R_SUCCEED();
382 }
383
384 if (c == Dot) {
385 state = ParentDir;
386 } else {
387 state = Normal;
388 }
389 break;
390 case ParentDir:
391 if (c == DirectorySeparator) {
392 *out = false;
393 R_SUCCEED();
394 }
395
396 state = Normal;
397 break;
398 default:
399 UNREACHABLE();
400 break;
401 }
402 }
403
404 // Check the final state
405 switch (state) {
406 // Import the PathState enums for convenience
407 using enum PathState;
408 case Start:
409 R_THROW(ResultInvalidPathFormat);
410 case Normal:
411 case FirstSeparator:
412 *out = true;
413 break;
414 case Separator:
415 case CurrentDir:
416 case ParentDir:
417 *out = false;
418 break;
419 default:
420 UNREACHABLE();
421 break;
422 }
423
424 // Set the output length
425 *out_len = len;
426 R_SUCCEED();
427 }
428
429 static Result Normalize(char* dst, size_t* out_len, const char* path, size_t max_out_size,
430 bool is_windows_path, bool is_drive_relative_path,
431 bool allow_all_characters = false) {
432 // Use StringTraits names for remainder of scope
433 using namespace StringTraits;
434
435 // Prepare to iterate
436 const char* cur_path = path;
437 size_t total_len = 0;
438
439 // If path begins with a separator, check that we're not drive relative
440 if (cur_path[0] != DirectorySeparator) {
441 R_UNLESS(is_drive_relative_path, ResultInvalidPathFormat);
442
443 dst[total_len++] = DirectorySeparator;
444 }
445
446 // We're going to need to do path replacement, potentially
447 char* replacement_path = nullptr;
448 size_t replacement_path_size = 0;
449
450 SCOPE_EXIT({
451 if (replacement_path != nullptr) {
452 if (std::is_constant_evaluated()) {
453 delete[] replacement_path;
454 } else {
455 Deallocate(replacement_path, replacement_path_size);
456 }
457 }
458 });
459
460 // Perform path replacement, if necessary
461 if (IsParentDirectoryPathReplacementNeeded(cur_path)) {
462 if (std::is_constant_evaluated()) {
463 replacement_path_size = EntryNameLengthMax + 1;
464 replacement_path = new char[replacement_path_size];
465 } else {
466 replacement_path_size = EntryNameLengthMax + 1;
467 replacement_path = static_cast<char*>(Allocate(replacement_path_size));
468 }
469
470 ReplaceParentDirectoryPath(replacement_path, cur_path);
471
472 cur_path = replacement_path;
473 }
474
475 // Iterate, normalizing path components
476 bool skip_next_sep = false;
477 size_t i = 0;
478
479 while (cur_path[i] != NullTerminator) {
480 // Process a directory separator, if we run into one
481 if (cur_path[i] == DirectorySeparator) {
482 // Swallow separators
483 do {
484 ++i;
485 } while (cur_path[i] == DirectorySeparator);
486
487 // Check if we hit end of string
488 if (cur_path[i] == NullTerminator) {
489 break;
490 }
491
492 // If we aren't skipping the separator, write it, checking that we remain in bounds.
493 if (!skip_next_sep) {
494 if (total_len + 1 == max_out_size) {
495 dst[total_len] = NullTerminator;
496 *out_len = total_len;
497 R_THROW(ResultTooLongPath);
498 }
499
500 dst[total_len++] = DirectorySeparator;
501 }
502
503 // Don't skip the next separator
504 skip_next_sep = false;
505 }
506
507 // Get the length of the current directory component
508 size_t dir_len = 0;
509 while (cur_path[i + dir_len] != DirectorySeparator &&
510 cur_path[i + dir_len] != NullTerminator) {
511 // Check for validity
512 if (!allow_all_characters) {
513 R_UNLESS(!IsInvalidCharacter(cur_path[i + dir_len]), ResultInvalidCharacter);
514 }
515
516 ++dir_len;
517 }
518
519 // Handle the current dir component
520 if (IsCurrentDirectory(cur_path + i)) {
521 skip_next_sep = true;
522 } else if (IsParentDirectory(cur_path + i)) {
523 // We should have just written a separator
524 ASSERT(dst[total_len - 1] == DirectorySeparator);
525
526 // We should have started with a separator, for non-windows paths
527 if (!is_windows_path) {
528 ASSERT(dst[0] == DirectorySeparator);
529 }
530
531 // Remove the previous component
532 if (total_len == 1) {
533 R_UNLESS(is_windows_path, ResultDirectoryUnobtainable);
534
535 --total_len;
536 } else {
537 total_len -= 2;
538
539 do {
540 if (dst[total_len] == DirectorySeparator) {
541 break;
542 }
543 } while ((--total_len) != 0);
544 }
545
546 // We should be pointing to a directory separator, for non-windows paths
547 if (!is_windows_path) {
548 ASSERT(dst[total_len] == DirectorySeparator);
549 }
550
551 // We should remain in bounds
552 ASSERT(total_len < max_out_size);
553 } else {
554 // Copy, possibly truncating
555 if (total_len + dir_len + 1 > max_out_size) {
556 const size_t copy_len = max_out_size - (total_len + 1);
557
558 for (size_t j = 0; j < copy_len; ++j) {
559 dst[total_len++] = cur_path[i + j];
560 }
561
562 dst[total_len] = NullTerminator;
563 *out_len = total_len;
564 R_THROW(ResultTooLongPath);
565 }
566
567 for (size_t j = 0; j < dir_len; ++j) {
568 dst[total_len++] = cur_path[i + j];
569 }
570 }
571
572 // Advance past the current directory component
573 i += dir_len;
574 }
575
576 if (skip_next_sep) {
577 --total_len;
578 }
579
580 if (total_len == 0 && max_out_size != 0) {
581 total_len = 1;
582 dst[0] = DirectorySeparator;
583 }
584
585 // NOTE: Probable nintendo bug, as max_out_size must be at least total_len + 1 for the null
586 // terminator.
587 R_UNLESS(max_out_size >= total_len - 1, ResultTooLongPath);
588
589 dst[total_len] = NullTerminator;
590
591 // Check that the result path is normalized
592 bool is_normalized;
593 size_t dummy;
594 R_TRY(IsNormalized(std::addressof(is_normalized), std::addressof(dummy), dst,
595 allow_all_characters));
596
597 // Assert that the result path is normalized
598 ASSERT(is_normalized);
599
600 // Set the output length
601 *out_len = total_len;
602 R_SUCCEED();
603 }
604};
605
606class PathFormatter {
607private:
608 static constexpr Result CheckSharedName(const char* name, size_t len) {
609 // Use StringTraits names for remainder of scope
610 using namespace StringTraits;
611
612 if (len == 1) {
613 R_UNLESS(name[0] != Dot, ResultInvalidPathFormat);
614 } else if (len == 2) {
615 R_UNLESS(name[0] != Dot || name[1] != Dot, ResultInvalidPathFormat);
616 }
617
618 for (size_t i = 0; i < len; ++i) {
619 R_UNLESS(!IsInvalidCharacter(name[i]), ResultInvalidCharacter);
620 }
621
622 R_SUCCEED();
623 }
624
625 static constexpr Result CheckHostName(const char* name, size_t len) {
626 // Use StringTraits names for remainder of scope
627 using namespace StringTraits;
628
629 if (len == 2) {
630 R_UNLESS(name[0] != Dot || name[1] != Dot, ResultInvalidPathFormat);
631 }
632
633 for (size_t i = 0; i < len; ++i) {
634 R_UNLESS(!IsInvalidCharacterForHostName(name[i]), ResultInvalidCharacter);
635 }
636
637 R_SUCCEED();
638 }
639
640 static constexpr Result CheckInvalidBackslash(bool* out_contains_backslash, const char* path,
641 bool allow_backslash) {
642 // Use StringTraits names for remainder of scope
643 using namespace StringTraits;
644
645 // Default to no backslashes, so we can just write if we see one
646 *out_contains_backslash = false;
647
648 while (*path != NullTerminator) {
649 if (*(path++) == AlternateDirectorySeparator) {
650 *out_contains_backslash = true;
651
652 R_UNLESS(allow_backslash, ResultInvalidCharacter);
653 }
654 }
655
656 R_SUCCEED();
657 }
658
659public:
660 static constexpr Result CheckPathFormat(const char* path, const PathFlags& flags) {
661 bool normalized;
662 size_t len;
663 R_RETURN(IsNormalized(std::addressof(normalized), std::addressof(len), path, flags));
664 }
665
666 static constexpr Result SkipMountName(const char** out, size_t* out_len, const char* path) {
667 R_RETURN(ParseMountName(out, out_len, nullptr, 0, path));
668 }
669
670 static constexpr Result ParseMountName(const char** out, size_t* out_len, char* out_mount_name,
671 size_t out_mount_name_buffer_size, const char* path) {
672 // Check pre-conditions
673 ASSERT(path != nullptr);
674 ASSERT(out_len != nullptr);
675 ASSERT(out != nullptr);
676 ASSERT((out_mount_name == nullptr) == (out_mount_name_buffer_size == 0));
677
678 // Use StringTraits names for remainder of scope
679 using namespace StringTraits;
680
681 // Determine max mount length
682 const auto max_mount_len =
683 out_mount_name_buffer_size == 0
684 ? MountNameLengthMax + 1
685 : std::min(MountNameLengthMax + 1, out_mount_name_buffer_size);
686
687 // Parse the path until we see a drive separator
688 size_t mount_len = 0;
689 for (/* ... */; mount_len < max_mount_len && path[mount_len]; ++mount_len) {
690 const char c = path[mount_len];
691
692 // If we see a drive separator, advance, then we're done with the pre-drive separator
693 // part of the mount.
694 if (c == DriveSeparator) {
695 ++mount_len;
696 break;
697 }
698
699 // If we see a directory separator, we're not in a mount name
700 if (c == DirectorySeparator || c == AlternateDirectorySeparator) {
701 *out = path;
702 *out_len = 0;
703 R_SUCCEED();
704 }
705 }
706
707 // Check to be sure we're actually looking at a mount name
708 if (mount_len <= 2 || path[mount_len - 1] != DriveSeparator) {
709 *out = path;
710 *out_len = 0;
711 R_SUCCEED();
712 }
713
714 // Check that all characters in the mount name are allowable
715 for (size_t i = 0; i < mount_len; ++i) {
716 R_UNLESS(!IsInvalidCharacterForMountName(path[i]), ResultInvalidCharacter);
717 }
718
719 // Copy out the mount name
720 if (out_mount_name_buffer_size > 0) {
721 R_UNLESS(mount_len < out_mount_name_buffer_size, ResultTooLongPath);
722
723 for (size_t i = 0; i < mount_len; ++i) {
724 out_mount_name[i] = path[i];
725 }
726 out_mount_name[mount_len] = NullTerminator;
727 }
728
729 // Set the output
730 *out = path + mount_len;
731 *out_len = mount_len;
732 R_SUCCEED();
733 }
734
735 static constexpr Result SkipRelativeDotPath(const char** out, size_t* out_len,
736 const char* path) {
737 R_RETURN(ParseRelativeDotPath(out, out_len, nullptr, 0, path));
738 }
739
740 static constexpr Result ParseRelativeDotPath(const char** out, size_t* out_len,
741 char* out_relative,
742 size_t out_relative_buffer_size,
743 const char* path) {
744 // Check pre-conditions
745 ASSERT(path != nullptr);
746 ASSERT(out_len != nullptr);
747 ASSERT(out != nullptr);
748 ASSERT((out_relative == nullptr) == (out_relative_buffer_size == 0));
749
750 // Use StringTraits names for remainder of scope
751 using namespace StringTraits;
752
753 // Initialize the output buffer, if we have one
754 if (out_relative_buffer_size > 0) {
755 out_relative[0] = NullTerminator;
756 }
757
758 // Check if the path is relative
759 if (path[0] == Dot && (path[1] == NullTerminator || path[1] == DirectorySeparator ||
760 path[1] == AlternateDirectorySeparator)) {
761 if (out_relative_buffer_size > 0) {
762 R_UNLESS(out_relative_buffer_size >= 2, ResultTooLongPath);
763
764 out_relative[0] = Dot;
765 out_relative[1] = NullTerminator;
766 }
767
768 *out = path + 1;
769 *out_len = 1;
770 R_SUCCEED();
771 }
772
773 // Ensure the path isn't a parent directory
774 R_UNLESS(!(path[0] == Dot && path[1] == Dot), ResultDirectoryUnobtainable);
775
776 // There was no relative dot path
777 *out = path;
778 *out_len = 0;
779 R_SUCCEED();
780 }
781
782 static constexpr Result SkipWindowsPath(const char** out, size_t* out_len, bool* out_normalized,
783 const char* path, bool has_mount_name) {
784 // We're normalized if and only if the parsing doesn't throw ResultNotNormalized()
785 *out_normalized = true;
786
787 R_TRY_CATCH(ParseWindowsPath(out, out_len, nullptr, 0, path, has_mount_name)) {
788 R_CATCH(ResultNotNormalized) {
789 *out_normalized = false;
790 }
791 }
792 R_END_TRY_CATCH;
793 ON_RESULT_INCLUDED(ResultNotNormalized) {
794 *out_normalized = false;
795 };
796
797 R_SUCCEED();
798 }
799
800 static constexpr Result ParseWindowsPath(const char** out, size_t* out_len, char* out_win,
801 size_t out_win_buffer_size, const char* path,
802 bool has_mount_name) {
803 // Check pre-conditions
804 ASSERT(path != nullptr);
805 ASSERT(out_len != nullptr);
806 ASSERT(out != nullptr);
807 ASSERT((out_win == nullptr) == (out_win_buffer_size == 0));
808
809 // Use StringTraits names for remainder of scope
810 using namespace StringTraits;
811
812 // Initialize the output buffer, if we have one
813 if (out_win_buffer_size > 0) {
814 out_win[0] = NullTerminator;
815 }
816
817 // Handle path start
818 const char* cur_path = path;
819 if (has_mount_name && path[0] == DirectorySeparator) {
820 if (path[1] == AlternateDirectorySeparator && path[2] == AlternateDirectorySeparator) {
821 R_UNLESS(out_win_buffer_size > 0, ResultNotNormalized);
822
823 ++cur_path;
824 } else if (IsWindowsDrive(path + 1)) {
825 R_UNLESS(out_win_buffer_size > 0, ResultNotNormalized);
826
827 ++cur_path;
828 }
829 }
830
831 // Handle windows drive
832 if (IsWindowsDrive(cur_path)) {
833 // Parse up to separator
834 size_t win_path_len = WindowsDriveLength;
835 for (/* ... */; cur_path[win_path_len] != NullTerminator; ++win_path_len) {
836 R_UNLESS(!IsInvalidCharacter(cur_path[win_path_len]), ResultInvalidCharacter);
837
838 if (cur_path[win_path_len] == DirectorySeparator ||
839 cur_path[win_path_len] == AlternateDirectorySeparator) {
840 break;
841 }
842 }
843
844 // Ensure that we're normalized, if we're required to be
845 if (out_win_buffer_size == 0) {
846 for (size_t i = 0; i < win_path_len; ++i) {
847 R_UNLESS(cur_path[i] != AlternateDirectorySeparator, ResultNotNormalized);
848 }
849 } else {
850 // Ensure we can copy into the normalized buffer
851 R_UNLESS(win_path_len < out_win_buffer_size, ResultTooLongPath);
852
853 for (size_t i = 0; i < win_path_len; ++i) {
854 out_win[i] = cur_path[i];
855 }
856 out_win[win_path_len] = NullTerminator;
857
858 Replace(out_win, win_path_len, AlternateDirectorySeparator, DirectorySeparator);
859 }
860
861 *out = cur_path + win_path_len;
862 *out_len = win_path_len;
863 R_SUCCEED();
864 }
865
866 // Handle DOS device
867 if (IsDosDevicePath(cur_path)) {
868 size_t dos_prefix_len = DosDevicePathPrefixLength;
869
870 if (IsWindowsDrive(cur_path + dos_prefix_len)) {
871 dos_prefix_len += WindowsDriveLength;
872 } else {
873 --dos_prefix_len;
874 }
875
876 if (out_win_buffer_size > 0) {
877 // Ensure we can copy into the normalized buffer
878 R_UNLESS(dos_prefix_len < out_win_buffer_size, ResultTooLongPath);
879
880 for (size_t i = 0; i < dos_prefix_len; ++i) {
881 out_win[i] = cur_path[i];
882 }
883 out_win[dos_prefix_len] = NullTerminator;
884
885 Replace(out_win, dos_prefix_len, DirectorySeparator, AlternateDirectorySeparator);
886 }
887
888 *out = cur_path + dos_prefix_len;
889 *out_len = dos_prefix_len;
890 R_SUCCEED();
891 }
892
893 // Handle UNC path
894 if (IsUncPath(cur_path, false, true)) {
895 const char* final_path = cur_path;
896
897 R_UNLESS(cur_path[UncPathPrefixLength] != DirectorySeparator, ResultInvalidPathFormat);
898 R_UNLESS(cur_path[UncPathPrefixLength] != AlternateDirectorySeparator,
899 ResultInvalidPathFormat);
900
901 size_t cur_component_offset = 0;
902 size_t pos = UncPathPrefixLength;
903 for (/* ... */; cur_path[pos] != NullTerminator; ++pos) {
904 if (cur_path[pos] == DirectorySeparator ||
905 cur_path[pos] == AlternateDirectorySeparator) {
906 if (cur_component_offset != 0) {
907 R_TRY(CheckSharedName(cur_path + cur_component_offset,
908 pos - cur_component_offset));
909
910 final_path = cur_path + pos;
911 break;
912 }
913
914 R_UNLESS(cur_path[pos + 1] != DirectorySeparator, ResultInvalidPathFormat);
915 R_UNLESS(cur_path[pos + 1] != AlternateDirectorySeparator,
916 ResultInvalidPathFormat);
917
918 R_TRY(CheckHostName(cur_path + 2, pos - 2));
919
920 cur_component_offset = pos + 1;
921 }
922 }
923
924 R_UNLESS(cur_component_offset != pos, ResultInvalidPathFormat);
925
926 if (cur_component_offset != 0 && final_path == cur_path) {
927 R_TRY(CheckSharedName(cur_path + cur_component_offset, pos - cur_component_offset));
928
929 final_path = cur_path + pos;
930 }
931
932 size_t unc_prefix_len = final_path - cur_path;
933
934 // Ensure that we're normalized, if we're required to be
935 if (out_win_buffer_size == 0) {
936 for (size_t i = 0; i < unc_prefix_len; ++i) {
937 R_UNLESS(cur_path[i] != DirectorySeparator, ResultNotNormalized);
938 }
939 } else {
940 // Ensure we can copy into the normalized buffer
941 R_UNLESS(unc_prefix_len < out_win_buffer_size, ResultTooLongPath);
942
943 for (size_t i = 0; i < unc_prefix_len; ++i) {
944 out_win[i] = cur_path[i];
945 }
946 out_win[unc_prefix_len] = NullTerminator;
947
948 Replace(out_win, unc_prefix_len, DirectorySeparator, AlternateDirectorySeparator);
949 }
950
951 *out = cur_path + unc_prefix_len;
952 *out_len = unc_prefix_len;
953 R_SUCCEED();
954 }
955
956 // There's no windows path to parse
957 *out = path;
958 *out_len = 0;
959 R_SUCCEED();
960 }
961
962 static constexpr Result IsNormalized(bool* out, size_t* out_len, const char* path,
963 const PathFlags& flags = {}) {
964 // Ensure nothing is null
965 R_UNLESS(out != nullptr, ResultNullptrArgument);
966 R_UNLESS(out_len != nullptr, ResultNullptrArgument);
967 R_UNLESS(path != nullptr, ResultNullptrArgument);
968
969 // Verify that the path is valid utf-8
970 R_TRY(CheckUtf8(path));
971
972 // Use StringTraits names for remainder of scope
973 using namespace StringTraits;
974
975 // Handle the case where the path is empty
976 if (path[0] == NullTerminator) {
977 R_UNLESS(flags.IsEmptyPathAllowed(), ResultInvalidPathFormat);
978
979 *out = true;
980 *out_len = 0;
981 R_SUCCEED();
982 }
983
984 // All normalized paths start with a directory separator...unless they're windows paths,
985 // relative paths, or have mount names.
986 if (path[0] != DirectorySeparator) {
987 R_UNLESS(flags.IsWindowsPathAllowed() || flags.IsRelativePathAllowed() ||
988 flags.IsMountNameAllowed(),
989 ResultInvalidPathFormat);
990 }
991
992 // Check that the path is allowed to be a windows path, if it is
993 if (IsWindowsPath(path, false)) {
994 R_UNLESS(flags.IsWindowsPathAllowed(), ResultInvalidPathFormat);
995 }
996
997 // Skip past the mount name, if one is present
998 size_t total_len = 0;
999 size_t mount_name_len = 0;
1000 R_TRY(SkipMountName(std::addressof(path), std::addressof(mount_name_len), path));
1001
1002 // If we had a mount name, check that that was allowed
1003 if (mount_name_len > 0) {
1004 R_UNLESS(flags.IsMountNameAllowed(), ResultInvalidPathFormat);
1005
1006 total_len += mount_name_len;
1007 }
1008
1009 // Check that the path starts as a normalized path should
1010 if (path[0] != DirectorySeparator && !IsPathStartWithCurrentDirectory(path) &&
1011 !IsWindowsPath(path, false)) {
1012 R_UNLESS(flags.IsRelativePathAllowed(), ResultInvalidPathFormat);
1013 R_UNLESS(!IsInvalidCharacter(path[0]), ResultInvalidPathFormat);
1014
1015 *out = false;
1016 R_SUCCEED();
1017 }
1018
1019 // Process relative path
1020 size_t relative_len = 0;
1021 R_TRY(SkipRelativeDotPath(std::addressof(path), std::addressof(relative_len), path));
1022
1023 // If we have a relative path, check that was allowed
1024 if (relative_len > 0) {
1025 R_UNLESS(flags.IsRelativePathAllowed(), ResultInvalidPathFormat);
1026
1027 total_len += relative_len;
1028
1029 if (path[0] == NullTerminator) {
1030 *out = true;
1031 *out_len = total_len;
1032 R_SUCCEED();
1033 }
1034 }
1035
1036 // Process windows path
1037 size_t windows_len = 0;
1038 bool normalized_win = false;
1039 R_TRY(SkipWindowsPath(std::addressof(path), std::addressof(windows_len),
1040 std::addressof(normalized_win), path, mount_name_len > 0));
1041
1042 // If the windows path wasn't normalized, we're not normalized
1043 if (!normalized_win) {
1044 R_UNLESS(flags.IsWindowsPathAllowed(), ResultInvalidPathFormat);
1045
1046 *out = false;
1047 R_SUCCEED();
1048 }
1049
1050 // If we had a windows path, check that was allowed
1051 if (windows_len > 0) {
1052 R_UNLESS(flags.IsWindowsPathAllowed(), ResultInvalidPathFormat);
1053
1054 total_len += windows_len;
1055
1056 // We can't have both a relative path and a windows path
1057 R_UNLESS(relative_len == 0, ResultInvalidPathFormat);
1058
1059 // A path ending in a windows path isn't normalized
1060 if (path[0] == NullTerminator) {
1061 *out = false;
1062 R_SUCCEED();
1063 }
1064
1065 // Check that there are no windows directory separators in the path
1066 for (size_t i = 0; path[i] != NullTerminator; ++i) {
1067 if (path[i] == AlternateDirectorySeparator) {
1068 *out = false;
1069 R_SUCCEED();
1070 }
1071 }
1072 }
1073
1074 // Check that parent directory replacement is not needed if backslashes are allowed
1075 if (flags.IsBackslashAllowed() &&
1076 PathNormalizer::IsParentDirectoryPathReplacementNeeded(path)) {
1077 *out = false;
1078 R_SUCCEED();
1079 }
1080
1081 // Check that the backslash state is valid
1082 bool is_backslash_contained = false;
1083 R_TRY(CheckInvalidBackslash(std::addressof(is_backslash_contained), path,
1084 flags.IsWindowsPathAllowed() || flags.IsBackslashAllowed()));
1085
1086 // Check that backslashes are contained only if allowed
1087 if (is_backslash_contained && !flags.IsBackslashAllowed()) {
1088 *out = false;
1089 R_SUCCEED();
1090 }
1091
1092 // Check that the final result path is normalized
1093 size_t normal_len = 0;
1094 R_TRY(PathNormalizer::IsNormalized(out, std::addressof(normal_len), path,
1095 flags.IsAllCharactersAllowed()));
1096
1097 // Add the normal length
1098 total_len += normal_len;
1099
1100 // Set the output length
1101 *out_len = total_len;
1102 R_SUCCEED();
1103 }
1104
1105 static Result Normalize(char* dst, size_t dst_size, const char* path, size_t path_len,
1106 const PathFlags& flags) {
1107 // Use StringTraits names for remainder of scope
1108 using namespace StringTraits;
1109
1110 // Prepare to iterate
1111 const char* src = path;
1112 size_t cur_pos = 0;
1113 bool is_windows_path = false;
1114
1115 // Check if the path is empty
1116 if (src[0] == NullTerminator) {
1117 if (dst_size != 0) {
1118 dst[0] = NullTerminator;
1119 }
1120
1121 R_UNLESS(flags.IsEmptyPathAllowed(), ResultInvalidPathFormat);
1122
1123 R_SUCCEED();
1124 }
1125
1126 // Handle a mount name
1127 size_t mount_name_len = 0;
1128 if (flags.IsMountNameAllowed()) {
1129 R_TRY(ParseMountName(std::addressof(src), std::addressof(mount_name_len), dst + cur_pos,
1130 dst_size - cur_pos, src));
1131
1132 cur_pos += mount_name_len;
1133 }
1134
1135 // Handle a drive-relative prefix
1136 bool is_drive_relative = false;
1137 if (src[0] != DirectorySeparator && !IsPathStartWithCurrentDirectory(src) &&
1138 !IsWindowsPath(src, false)) {
1139 R_UNLESS(flags.IsRelativePathAllowed(), ResultInvalidPathFormat);
1140 R_UNLESS(!IsInvalidCharacter(src[0]), ResultInvalidPathFormat);
1141
1142 dst[cur_pos++] = Dot;
1143 is_drive_relative = true;
1144 }
1145
1146 size_t relative_len = 0;
1147 if (flags.IsRelativePathAllowed()) {
1148 R_UNLESS(cur_pos < dst_size, ResultTooLongPath);
1149
1150 R_TRY(ParseRelativeDotPath(std::addressof(src), std::addressof(relative_len),
1151 dst + cur_pos, dst_size - cur_pos, src));
1152
1153 cur_pos += relative_len;
1154
1155 if (src[0] == NullTerminator) {
1156 R_UNLESS(cur_pos < dst_size, ResultTooLongPath);
1157
1158 dst[cur_pos] = NullTerminator;
1159 R_SUCCEED();
1160 }
1161 }
1162
1163 // Handle a windows path
1164 if (flags.IsWindowsPathAllowed()) {
1165 const char* const orig = src;
1166
1167 R_UNLESS(cur_pos < dst_size, ResultTooLongPath);
1168
1169 size_t windows_len = 0;
1170 R_TRY(ParseWindowsPath(std::addressof(src), std::addressof(windows_len), dst + cur_pos,
1171 dst_size - cur_pos, src, mount_name_len != 0));
1172
1173 cur_pos += windows_len;
1174
1175 if (src[0] == NullTerminator) {
1176 /* NOTE: Bug in original code here repeated, should be checking cur_pos + 2. */
1177 R_UNLESS(cur_pos + 1 < dst_size, ResultTooLongPath);
1178
1179 dst[cur_pos + 0] = DirectorySeparator;
1180 dst[cur_pos + 1] = NullTerminator;
1181 R_SUCCEED();
1182 }
1183
1184 if ((src - orig) > 0) {
1185 is_windows_path = true;
1186 }
1187 }
1188
1189 // Check for invalid backslash
1190 bool backslash_contained = false;
1191 R_TRY(CheckInvalidBackslash(std::addressof(backslash_contained), src,
1192 flags.IsWindowsPathAllowed() || flags.IsBackslashAllowed()));
1193
1194 // Handle backslash replacement as necessary
1195 if (backslash_contained && flags.IsWindowsPathAllowed()) {
1196 // Create a temporary buffer holding a slash-replaced version of the path.
1197 // NOTE: Nintendo unnecessarily allocates and replaces here a fully copy of the path,
1198 // despite having skipped some of it already.
1199 const size_t replaced_src_len = path_len - (src - path);
1200
1201 char* replaced_src = nullptr;
1202 SCOPE_EXIT({
1203 if (replaced_src != nullptr) {
1204 if (std::is_constant_evaluated()) {
1205 delete[] replaced_src;
1206 } else {
1207 Deallocate(replaced_src, replaced_src_len);
1208 }
1209 }
1210 });
1211
1212 if (std::is_constant_evaluated()) {
1213 replaced_src = new char[replaced_src_len];
1214 } else {
1215 replaced_src = static_cast<char*>(Allocate(replaced_src_len));
1216 }
1217
1218 Strlcpy<char>(replaced_src, src, replaced_src_len);
1219
1220 Replace(replaced_src, replaced_src_len, AlternateDirectorySeparator,
1221 DirectorySeparator);
1222
1223 size_t dummy;
1224 R_TRY(PathNormalizer::Normalize(dst + cur_pos, std::addressof(dummy), replaced_src,
1225 dst_size - cur_pos, is_windows_path, is_drive_relative,
1226 flags.IsAllCharactersAllowed()));
1227 } else {
1228 // We can just do normalization
1229 size_t dummy;
1230 R_TRY(PathNormalizer::Normalize(dst + cur_pos, std::addressof(dummy), src,
1231 dst_size - cur_pos, is_windows_path, is_drive_relative,
1232 flags.IsAllCharactersAllowed()));
1233 }
1234
1235 R_SUCCEED();
1236 }
1237};
1238
1239} // namespace FileSys
diff --git a/src/core/file_sys/fs_string_util.h b/src/core/file_sys/fs_string_util.h
new file mode 100644
index 000000000..874e09054
--- /dev/null
+++ b/src/core/file_sys/fs_string_util.h
@@ -0,0 +1,226 @@
1// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include "common/assert.h"
7
8namespace FileSys {
9
10template <typename T>
11constexpr int Strlen(const T* str) {
12 ASSERT(str != nullptr);
13
14 int length = 0;
15 while (*str++) {
16 ++length;
17 }
18
19 return length;
20}
21
22template <typename T>
23constexpr int Strnlen(const T* str, int count) {
24 ASSERT(str != nullptr);
25 ASSERT(count >= 0);
26
27 int length = 0;
28 while (count-- && *str++) {
29 ++length;
30 }
31
32 return length;
33}
34
35template <typename T>
36constexpr int Strncmp(const T* lhs, const T* rhs, int count) {
37 ASSERT(lhs != nullptr);
38 ASSERT(rhs != nullptr);
39 ASSERT(count >= 0);
40
41 if (count == 0) {
42 return 0;
43 }
44
45 T l, r;
46 do {
47 l = *(lhs++);
48 r = *(rhs++);
49 } while (l && (l == r) && (--count));
50
51 return l - r;
52}
53
54template <typename T>
55static constexpr int Strlcpy(T* dst, const T* src, int count) {
56 ASSERT(dst != nullptr);
57 ASSERT(src != nullptr);
58
59 const T* cur = src;
60 if (count > 0) {
61 while ((--count) && *cur) {
62 *(dst++) = *(cur++);
63 }
64 *dst = 0;
65 }
66
67 while (*cur) {
68 cur++;
69 }
70
71 return static_cast<int>(cur - src);
72}
73
74enum CharacterEncodingResult {
75 CharacterEncodingResult_Success = 0,
76 CharacterEncodingResult_InsufficientLength = 1,
77 CharacterEncodingResult_InvalidFormat = 2,
78};
79
80namespace impl {
81
82class CharacterEncodingHelper {
83public:
84 static constexpr int8_t Utf8NBytesInnerTable[0x100 + 1] = {
85 -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
86 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
87 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
88 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
89 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
90 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
91 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
92 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3,
93 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 8,
94 };
95
96 static constexpr char GetUtf8NBytes(size_t i) {
97 return static_cast<char>(Utf8NBytesInnerTable[1 + i]);
98 }
99};
100
101} // namespace impl
102
103constexpr inline CharacterEncodingResult ConvertCharacterUtf8ToUtf32(u32* dst, const char* src) {
104 // Check pre-conditions
105 ASSERT(dst != nullptr);
106 ASSERT(src != nullptr);
107
108 // Perform the conversion
109 const auto* p = src;
110 switch (impl::CharacterEncodingHelper::GetUtf8NBytes(static_cast<unsigned char>(p[0]))) {
111 case 1:
112 *dst = static_cast<u32>(p[0]);
113 return CharacterEncodingResult_Success;
114 case 2:
115 if ((static_cast<u32>(p[0]) & 0x1E) != 0) {
116 if (impl::CharacterEncodingHelper::GetUtf8NBytes(static_cast<unsigned char>(p[1])) ==
117 0) {
118 *dst = (static_cast<u32>(p[0] & 0x1F) << 6) | (static_cast<u32>(p[1] & 0x3F) << 0);
119 return CharacterEncodingResult_Success;
120 }
121 }
122 break;
123 case 3:
124 if (impl::CharacterEncodingHelper::GetUtf8NBytes(static_cast<unsigned char>(p[1])) == 0 &&
125 impl::CharacterEncodingHelper::GetUtf8NBytes(static_cast<unsigned char>(p[2])) == 0) {
126 const u32 c = (static_cast<u32>(p[0] & 0xF) << 12) |
127 (static_cast<u32>(p[1] & 0x3F) << 6) |
128 (static_cast<u32>(p[2] & 0x3F) << 0);
129 if ((c & 0xF800) != 0 && (c & 0xF800) != 0xD800) {
130 *dst = c;
131 return CharacterEncodingResult_Success;
132 }
133 }
134 return CharacterEncodingResult_InvalidFormat;
135 case 4:
136 if (impl::CharacterEncodingHelper::GetUtf8NBytes(static_cast<unsigned char>(p[1])) == 0 &&
137 impl::CharacterEncodingHelper::GetUtf8NBytes(static_cast<unsigned char>(p[2])) == 0 &&
138 impl::CharacterEncodingHelper::GetUtf8NBytes(static_cast<unsigned char>(p[3])) == 0) {
139 const u32 c =
140 (static_cast<u32>(p[0] & 0x7) << 18) | (static_cast<u32>(p[1] & 0x3F) << 12) |
141 (static_cast<u32>(p[2] & 0x3F) << 6) | (static_cast<u32>(p[3] & 0x3F) << 0);
142 if (c >= 0x10000 && c < 0x110000) {
143 *dst = c;
144 return CharacterEncodingResult_Success;
145 }
146 }
147 return CharacterEncodingResult_InvalidFormat;
148 default:
149 break;
150 }
151
152 // We failed to convert
153 return CharacterEncodingResult_InvalidFormat;
154}
155
156constexpr inline CharacterEncodingResult PickOutCharacterFromUtf8String(char* dst,
157 const char** str) {
158 // Check pre-conditions
159 ASSERT(dst != nullptr);
160 ASSERT(str != nullptr);
161 ASSERT(*str != nullptr);
162
163 // Clear the output
164 dst[0] = 0;
165 dst[1] = 0;
166 dst[2] = 0;
167 dst[3] = 0;
168
169 // Perform the conversion
170 const auto* p = *str;
171 u32 c = static_cast<u32>(*p);
172 switch (impl::CharacterEncodingHelper::GetUtf8NBytes(c)) {
173 case 1:
174 dst[0] = (*str)[0];
175 ++(*str);
176 break;
177 case 2:
178 if ((p[0] & 0x1E) != 0) {
179 if (impl::CharacterEncodingHelper::GetUtf8NBytes(static_cast<unsigned char>(p[1])) ==
180 0) {
181 c = (static_cast<u32>(p[0] & 0x1F) << 6) | (static_cast<u32>(p[1] & 0x3F) << 0);
182 dst[0] = (*str)[0];
183 dst[1] = (*str)[1];
184 (*str) += 2;
185 break;
186 }
187 }
188 return CharacterEncodingResult_InvalidFormat;
189 case 3:
190 if (impl::CharacterEncodingHelper::GetUtf8NBytes(static_cast<unsigned char>(p[1])) == 0 &&
191 impl::CharacterEncodingHelper::GetUtf8NBytes(static_cast<unsigned char>(p[2])) == 0) {
192 c = (static_cast<u32>(p[0] & 0xF) << 12) | (static_cast<u32>(p[1] & 0x3F) << 6) |
193 (static_cast<u32>(p[2] & 0x3F) << 0);
194 if ((c & 0xF800) != 0 && (c & 0xF800) != 0xD800) {
195 dst[0] = (*str)[0];
196 dst[1] = (*str)[1];
197 dst[2] = (*str)[2];
198 (*str) += 3;
199 break;
200 }
201 }
202 return CharacterEncodingResult_InvalidFormat;
203 case 4:
204 if (impl::CharacterEncodingHelper::GetUtf8NBytes(static_cast<unsigned char>(p[1])) == 0 &&
205 impl::CharacterEncodingHelper::GetUtf8NBytes(static_cast<unsigned char>(p[2])) == 0 &&
206 impl::CharacterEncodingHelper::GetUtf8NBytes(static_cast<unsigned char>(p[3])) == 0) {
207 c = (static_cast<u32>(p[0] & 0x7) << 18) | (static_cast<u32>(p[1] & 0x3F) << 12) |
208 (static_cast<u32>(p[2] & 0x3F) << 6) | (static_cast<u32>(p[3] & 0x3F) << 0);
209 if (c >= 0x10000 && c < 0x110000) {
210 dst[0] = (*str)[0];
211 dst[1] = (*str)[1];
212 dst[2] = (*str)[2];
213 dst[3] = (*str)[3];
214 (*str) += 4;
215 break;
216 }
217 }
218 return CharacterEncodingResult_InvalidFormat;
219 default:
220 return CharacterEncodingResult_InvalidFormat;
221 }
222
223 return CharacterEncodingResult_Success;
224}
225
226} // namespace FileSys
diff --git a/src/core/file_sys/fsmitm_romfsbuild.cpp b/src/core/file_sys/fsmitm_romfsbuild.cpp
index dd9cca103..8807bbd0f 100644
--- a/src/core/file_sys/fsmitm_romfsbuild.cpp
+++ b/src/core/file_sys/fsmitm_romfsbuild.cpp
@@ -8,8 +8,8 @@
8#include "common/assert.h" 8#include "common/assert.h"
9#include "core/file_sys/fsmitm_romfsbuild.h" 9#include "core/file_sys/fsmitm_romfsbuild.h"
10#include "core/file_sys/ips_layer.h" 10#include "core/file_sys/ips_layer.h"
11#include "core/file_sys/vfs.h" 11#include "core/file_sys/vfs/vfs.h"
12#include "core/file_sys/vfs_vector.h" 12#include "core/file_sys/vfs/vfs_vector.h"
13 13
14namespace FileSys { 14namespace FileSys {
15 15
diff --git a/src/core/file_sys/fsmitm_romfsbuild.h b/src/core/file_sys/fsmitm_romfsbuild.h
index f387c79f1..dd7ed4a7b 100644
--- a/src/core/file_sys/fsmitm_romfsbuild.h
+++ b/src/core/file_sys/fsmitm_romfsbuild.h
@@ -7,7 +7,7 @@
7#include <memory> 7#include <memory>
8#include <string> 8#include <string>
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "core/file_sys/vfs.h" 10#include "core/file_sys/vfs/vfs.h"
11 11
12namespace FileSys { 12namespace FileSys {
13 13
diff --git a/src/core/file_sys/fssystem/fs_i_storage.h b/src/core/file_sys/fssystem/fs_i_storage.h
index 416dd57b8..37336c9ae 100644
--- a/src/core/file_sys/fssystem/fs_i_storage.h
+++ b/src/core/file_sys/fssystem/fs_i_storage.h
@@ -5,7 +5,7 @@
5 5
6#include "common/overflow.h" 6#include "common/overflow.h"
7#include "core/file_sys/errors.h" 7#include "core/file_sys/errors.h"
8#include "core/file_sys/vfs.h" 8#include "core/file_sys/vfs/vfs.h"
9 9
10namespace FileSys { 10namespace FileSys {
11 11
diff --git a/src/core/file_sys/fssystem/fssystem_aes_ctr_counter_extended_storage.cpp b/src/core/file_sys/fssystem/fssystem_aes_ctr_counter_extended_storage.cpp
index f25c95472..bc1cddbb0 100644
--- a/src/core/file_sys/fssystem/fssystem_aes_ctr_counter_extended_storage.cpp
+++ b/src/core/file_sys/fssystem/fssystem_aes_ctr_counter_extended_storage.cpp
@@ -4,7 +4,7 @@
4#include "core/file_sys/fssystem/fssystem_aes_ctr_counter_extended_storage.h" 4#include "core/file_sys/fssystem/fssystem_aes_ctr_counter_extended_storage.h"
5#include "core/file_sys/fssystem/fssystem_aes_ctr_storage.h" 5#include "core/file_sys/fssystem/fssystem_aes_ctr_storage.h"
6#include "core/file_sys/fssystem/fssystem_nca_header.h" 6#include "core/file_sys/fssystem/fssystem_nca_header.h"
7#include "core/file_sys/vfs_offset.h" 7#include "core/file_sys/vfs/vfs_offset.h"
8 8
9namespace FileSys { 9namespace FileSys {
10 10
diff --git a/src/core/file_sys/fssystem/fssystem_aes_ctr_storage.h b/src/core/file_sys/fssystem/fssystem_aes_ctr_storage.h
index 339e49697..5abd93d33 100644
--- a/src/core/file_sys/fssystem/fssystem_aes_ctr_storage.h
+++ b/src/core/file_sys/fssystem/fssystem_aes_ctr_storage.h
@@ -9,7 +9,7 @@
9#include "core/crypto/key_manager.h" 9#include "core/crypto/key_manager.h"
10#include "core/file_sys/errors.h" 10#include "core/file_sys/errors.h"
11#include "core/file_sys/fssystem/fs_i_storage.h" 11#include "core/file_sys/fssystem/fs_i_storage.h"
12#include "core/file_sys/vfs.h" 12#include "core/file_sys/vfs/vfs.h"
13 13
14namespace FileSys { 14namespace FileSys {
15 15
diff --git a/src/core/file_sys/fssystem/fssystem_bucket_tree.h b/src/core/file_sys/fssystem/fssystem_bucket_tree.h
index 46850cd48..3a5e21d1a 100644
--- a/src/core/file_sys/fssystem/fssystem_bucket_tree.h
+++ b/src/core/file_sys/fssystem/fssystem_bucket_tree.h
@@ -10,7 +10,7 @@
10#include "common/common_types.h" 10#include "common/common_types.h"
11#include "common/literals.h" 11#include "common/literals.h"
12 12
13#include "core/file_sys/vfs.h" 13#include "core/file_sys/vfs/vfs.h"
14#include "core/hle/result.h" 14#include "core/hle/result.h"
15 15
16namespace FileSys { 16namespace FileSys {
diff --git a/src/core/file_sys/fssystem/fssystem_compressed_storage.h b/src/core/file_sys/fssystem/fssystem_compressed_storage.h
index 33d93938e..74c98630e 100644
--- a/src/core/file_sys/fssystem/fssystem_compressed_storage.h
+++ b/src/core/file_sys/fssystem/fssystem_compressed_storage.h
@@ -10,7 +10,7 @@
10#include "core/file_sys/fssystem/fssystem_bucket_tree.h" 10#include "core/file_sys/fssystem/fssystem_bucket_tree.h"
11#include "core/file_sys/fssystem/fssystem_compression_common.h" 11#include "core/file_sys/fssystem/fssystem_compression_common.h"
12#include "core/file_sys/fssystem/fssystem_pooled_buffer.h" 12#include "core/file_sys/fssystem/fssystem_pooled_buffer.h"
13#include "core/file_sys/vfs.h" 13#include "core/file_sys/vfs/vfs.h"
14 14
15namespace FileSys { 15namespace FileSys {
16 16
diff --git a/src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.cpp b/src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.cpp
index 4a75b5308..39bb7b808 100644
--- a/src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.cpp
+++ b/src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.cpp
@@ -2,7 +2,7 @@
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.h" 4#include "core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.h"
5#include "core/file_sys/vfs_offset.h" 5#include "core/file_sys/vfs/vfs_offset.h"
6 6
7namespace FileSys { 7namespace FileSys {
8 8
diff --git a/src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.h b/src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.h
index 5cf697efe..bd129db47 100644
--- a/src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.h
+++ b/src/core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.h
@@ -8,7 +8,7 @@
8#include "core/file_sys/fssystem/fs_types.h" 8#include "core/file_sys/fssystem/fs_types.h"
9#include "core/file_sys/fssystem/fssystem_alignment_matching_storage.h" 9#include "core/file_sys/fssystem/fssystem_alignment_matching_storage.h"
10#include "core/file_sys/fssystem/fssystem_integrity_verification_storage.h" 10#include "core/file_sys/fssystem/fssystem_integrity_verification_storage.h"
11#include "core/file_sys/vfs_offset.h" 11#include "core/file_sys/vfs/vfs_offset.h"
12 12
13namespace FileSys { 13namespace FileSys {
14 14
diff --git a/src/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.h b/src/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.h
index 18df400af..41d3960b8 100644
--- a/src/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.h
+++ b/src/core/file_sys/fssystem/fssystem_hierarchical_sha256_storage.h
@@ -7,7 +7,7 @@
7 7
8#include "core/file_sys/errors.h" 8#include "core/file_sys/errors.h"
9#include "core/file_sys/fssystem/fs_i_storage.h" 9#include "core/file_sys/fssystem/fs_i_storage.h"
10#include "core/file_sys/vfs.h" 10#include "core/file_sys/vfs/vfs.h"
11 11
12namespace FileSys { 12namespace FileSys {
13 13
diff --git a/src/core/file_sys/fssystem/fssystem_indirect_storage.h b/src/core/file_sys/fssystem/fssystem_indirect_storage.h
index 7854335bf..d4b95fd27 100644
--- a/src/core/file_sys/fssystem/fssystem_indirect_storage.h
+++ b/src/core/file_sys/fssystem/fssystem_indirect_storage.h
@@ -7,8 +7,8 @@
7#include "core/file_sys/fssystem/fs_i_storage.h" 7#include "core/file_sys/fssystem/fs_i_storage.h"
8#include "core/file_sys/fssystem/fssystem_bucket_tree.h" 8#include "core/file_sys/fssystem/fssystem_bucket_tree.h"
9#include "core/file_sys/fssystem/fssystem_bucket_tree_template_impl.h" 9#include "core/file_sys/fssystem/fssystem_bucket_tree_template_impl.h"
10#include "core/file_sys/vfs.h" 10#include "core/file_sys/vfs/vfs.h"
11#include "core/file_sys/vfs_offset.h" 11#include "core/file_sys/vfs/vfs_offset.h"
12 12
13namespace FileSys { 13namespace FileSys {
14 14
diff --git a/src/core/file_sys/fssystem/fssystem_integrity_romfs_storage.h b/src/core/file_sys/fssystem/fssystem_integrity_romfs_storage.h
index 5f8512b2a..240d1e388 100644
--- a/src/core/file_sys/fssystem/fssystem_integrity_romfs_storage.h
+++ b/src/core/file_sys/fssystem/fssystem_integrity_romfs_storage.h
@@ -5,7 +5,7 @@
5 5
6#include "core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.h" 6#include "core/file_sys/fssystem/fssystem_hierarchical_integrity_verification_storage.h"
7#include "core/file_sys/fssystem/fssystem_nca_header.h" 7#include "core/file_sys/fssystem/fssystem_nca_header.h"
8#include "core/file_sys/vfs_vector.h" 8#include "core/file_sys/vfs/vfs_vector.h"
9 9
10namespace FileSys { 10namespace FileSys {
11 11
diff --git a/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp b/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp
index 0f5432203..ab5a7984e 100644
--- a/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp
+++ b/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.cpp
@@ -14,8 +14,8 @@
14#include "core/file_sys/fssystem/fssystem_nca_file_system_driver.h" 14#include "core/file_sys/fssystem/fssystem_nca_file_system_driver.h"
15#include "core/file_sys/fssystem/fssystem_sparse_storage.h" 15#include "core/file_sys/fssystem/fssystem_sparse_storage.h"
16#include "core/file_sys/fssystem/fssystem_switch_storage.h" 16#include "core/file_sys/fssystem/fssystem_switch_storage.h"
17#include "core/file_sys/vfs_offset.h" 17#include "core/file_sys/vfs/vfs_offset.h"
18#include "core/file_sys/vfs_vector.h" 18#include "core/file_sys/vfs/vfs_vector.h"
19 19
20namespace FileSys { 20namespace FileSys {
21 21
diff --git a/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.h b/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.h
index 5771a21fc..5bc838de6 100644
--- a/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.h
+++ b/src/core/file_sys/fssystem/fssystem_nca_file_system_driver.h
@@ -5,7 +5,7 @@
5 5
6#include "core/file_sys/fssystem/fssystem_compression_common.h" 6#include "core/file_sys/fssystem/fssystem_compression_common.h"
7#include "core/file_sys/fssystem/fssystem_nca_header.h" 7#include "core/file_sys/fssystem/fssystem_nca_header.h"
8#include "core/file_sys/vfs.h" 8#include "core/file_sys/vfs/vfs.h"
9 9
10namespace FileSys { 10namespace FileSys {
11 11
diff --git a/src/core/file_sys/fssystem/fssystem_nca_reader.cpp b/src/core/file_sys/fssystem/fssystem_nca_reader.cpp
index a3714ab37..08924e2a6 100644
--- a/src/core/file_sys/fssystem/fssystem_nca_reader.cpp
+++ b/src/core/file_sys/fssystem/fssystem_nca_reader.cpp
@@ -3,7 +3,7 @@
3 3
4#include "core/file_sys/fssystem/fssystem_aes_xts_storage.h" 4#include "core/file_sys/fssystem/fssystem_aes_xts_storage.h"
5#include "core/file_sys/fssystem/fssystem_nca_file_system_driver.h" 5#include "core/file_sys/fssystem/fssystem_nca_file_system_driver.h"
6#include "core/file_sys/vfs_offset.h" 6#include "core/file_sys/vfs/vfs_offset.h"
7 7
8namespace FileSys { 8namespace FileSys {
9 9
diff --git a/src/core/file_sys/ips_layer.cpp b/src/core/file_sys/ips_layer.cpp
index 31033634c..d1ac24072 100644
--- a/src/core/file_sys/ips_layer.cpp
+++ b/src/core/file_sys/ips_layer.cpp
@@ -12,7 +12,7 @@
12#include "common/logging/log.h" 12#include "common/logging/log.h"
13#include "common/swap.h" 13#include "common/swap.h"
14#include "core/file_sys/ips_layer.h" 14#include "core/file_sys/ips_layer.h"
15#include "core/file_sys/vfs_vector.h" 15#include "core/file_sys/vfs/vfs_vector.h"
16 16
17namespace FileSys { 17namespace FileSys {
18 18
diff --git a/src/core/file_sys/ips_layer.h b/src/core/file_sys/ips_layer.h
index f2717bae7..d81378e8a 100644
--- a/src/core/file_sys/ips_layer.h
+++ b/src/core/file_sys/ips_layer.h
@@ -8,7 +8,7 @@
8#include <vector> 8#include <vector>
9 9
10#include "common/common_types.h" 10#include "common/common_types.h"
11#include "core/file_sys/vfs.h" 11#include "core/file_sys/vfs/vfs.h"
12 12
13namespace FileSys { 13namespace FileSys {
14 14
diff --git a/src/core/file_sys/kernel_executable.cpp b/src/core/file_sys/kernel_executable.cpp
index 70c062f4c..b84492d30 100644
--- a/src/core/file_sys/kernel_executable.cpp
+++ b/src/core/file_sys/kernel_executable.cpp
@@ -5,7 +5,7 @@
5 5
6#include "common/string_util.h" 6#include "common/string_util.h"
7#include "core/file_sys/kernel_executable.h" 7#include "core/file_sys/kernel_executable.h"
8#include "core/file_sys/vfs_offset.h" 8#include "core/file_sys/vfs/vfs_offset.h"
9#include "core/loader/loader.h" 9#include "core/loader/loader.h"
10 10
11namespace FileSys { 11namespace FileSys {
diff --git a/src/core/file_sys/kernel_executable.h b/src/core/file_sys/kernel_executable.h
index d5b9199b5..928ba2d99 100644
--- a/src/core/file_sys/kernel_executable.h
+++ b/src/core/file_sys/kernel_executable.h
@@ -10,7 +10,7 @@
10#include "common/common_funcs.h" 10#include "common/common_funcs.h"
11#include "common/common_types.h" 11#include "common/common_types.h"
12#include "common/swap.h" 12#include "common/swap.h"
13#include "core/file_sys/vfs_types.h" 13#include "core/file_sys/vfs/vfs_types.h"
14 14
15namespace Loader { 15namespace Loader {
16enum class ResultStatus : u16; 16enum class ResultStatus : u16;
diff --git a/src/core/file_sys/mode.h b/src/core/file_sys/mode.h
deleted file mode 100644
index 9596ef4fd..000000000
--- a/src/core/file_sys/mode.h
+++ /dev/null
@@ -1,23 +0,0 @@
1// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#pragma once
5
6#include "common/common_funcs.h"
7#include "common/common_types.h"
8
9namespace FileSys {
10
11enum class Mode : u32 {
12 Read = 1 << 0,
13 Write = 1 << 1,
14 ReadWrite = Read | Write,
15 Append = 1 << 2,
16 ReadAppend = Read | Append,
17 WriteAppend = Write | Append,
18 All = ReadWrite | Append,
19};
20
21DECLARE_ENUM_FLAG_OPERATORS(Mode)
22
23} // namespace FileSys
diff --git a/src/core/file_sys/nca_metadata.cpp b/src/core/file_sys/nca_metadata.cpp
index f4a774675..9e855c50d 100644
--- a/src/core/file_sys/nca_metadata.cpp
+++ b/src/core/file_sys/nca_metadata.cpp
@@ -6,7 +6,7 @@
6#include "common/logging/log.h" 6#include "common/logging/log.h"
7#include "common/swap.h" 7#include "common/swap.h"
8#include "core/file_sys/nca_metadata.h" 8#include "core/file_sys/nca_metadata.h"
9#include "core/file_sys/vfs.h" 9#include "core/file_sys/vfs/vfs.h"
10 10
11namespace FileSys { 11namespace FileSys {
12 12
diff --git a/src/core/file_sys/nca_metadata.h b/src/core/file_sys/nca_metadata.h
index 68e463b5f..6243b822a 100644
--- a/src/core/file_sys/nca_metadata.h
+++ b/src/core/file_sys/nca_metadata.h
@@ -8,7 +8,7 @@
8#include "common/common_funcs.h" 8#include "common/common_funcs.h"
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "common/swap.h" 10#include "common/swap.h"
11#include "core/file_sys/vfs_types.h" 11#include "core/file_sys/vfs/vfs_types.h"
12 12
13namespace FileSys { 13namespace FileSys {
14class CNMT; 14class CNMT;
diff --git a/src/core/file_sys/partition_filesystem.cpp b/src/core/file_sys/partition_filesystem.cpp
index 2422cb51b..dd8de9d8a 100644
--- a/src/core/file_sys/partition_filesystem.cpp
+++ b/src/core/file_sys/partition_filesystem.cpp
@@ -9,7 +9,7 @@
9 9
10#include "common/logging/log.h" 10#include "common/logging/log.h"
11#include "core/file_sys/partition_filesystem.h" 11#include "core/file_sys/partition_filesystem.h"
12#include "core/file_sys/vfs_offset.h" 12#include "core/file_sys/vfs/vfs_offset.h"
13#include "core/loader/loader.h" 13#include "core/loader/loader.h"
14 14
15namespace FileSys { 15namespace FileSys {
diff --git a/src/core/file_sys/partition_filesystem.h b/src/core/file_sys/partition_filesystem.h
index b6e3a2b0c..777b9ead9 100644
--- a/src/core/file_sys/partition_filesystem.h
+++ b/src/core/file_sys/partition_filesystem.h
@@ -9,7 +9,7 @@
9#include "common/common_funcs.h" 9#include "common/common_funcs.h"
10#include "common/common_types.h" 10#include "common/common_types.h"
11#include "common/swap.h" 11#include "common/swap.h"
12#include "core/file_sys/vfs.h" 12#include "core/file_sys/vfs/vfs.h"
13 13
14namespace Loader { 14namespace Loader {
15enum class ResultStatus : u16; 15enum class ResultStatus : u16;
diff --git a/src/core/file_sys/patch_manager.cpp b/src/core/file_sys/patch_manager.cpp
index 612122224..21d45235e 100644
--- a/src/core/file_sys/patch_manager.cpp
+++ b/src/core/file_sys/patch_manager.cpp
@@ -21,9 +21,9 @@
21#include "core/file_sys/patch_manager.h" 21#include "core/file_sys/patch_manager.h"
22#include "core/file_sys/registered_cache.h" 22#include "core/file_sys/registered_cache.h"
23#include "core/file_sys/romfs.h" 23#include "core/file_sys/romfs.h"
24#include "core/file_sys/vfs_cached.h" 24#include "core/file_sys/vfs/vfs_cached.h"
25#include "core/file_sys/vfs_layered.h" 25#include "core/file_sys/vfs/vfs_layered.h"
26#include "core/file_sys/vfs_vector.h" 26#include "core/file_sys/vfs/vfs_vector.h"
27#include "core/hle/service/filesystem/filesystem.h" 27#include "core/hle/service/filesystem/filesystem.h"
28#include "core/hle/service/ns/language.h" 28#include "core/hle/service/ns/language.h"
29#include "core/hle/service/set/settings_server.h" 29#include "core/hle/service/set/settings_server.h"
diff --git a/src/core/file_sys/patch_manager.h b/src/core/file_sys/patch_manager.h
index 2601b8217..552c0fbe2 100644
--- a/src/core/file_sys/patch_manager.h
+++ b/src/core/file_sys/patch_manager.h
@@ -9,7 +9,7 @@
9#include <string> 9#include <string>
10#include "common/common_types.h" 10#include "common/common_types.h"
11#include "core/file_sys/nca_metadata.h" 11#include "core/file_sys/nca_metadata.h"
12#include "core/file_sys/vfs_types.h" 12#include "core/file_sys/vfs/vfs_types.h"
13#include "core/memory/dmnt_cheat_types.h" 13#include "core/memory/dmnt_cheat_types.h"
14 14
15namespace Core { 15namespace Core {
diff --git a/src/core/file_sys/program_metadata.cpp b/src/core/file_sys/program_metadata.cpp
index 539c7f7af..ae4e441c9 100644
--- a/src/core/file_sys/program_metadata.cpp
+++ b/src/core/file_sys/program_metadata.cpp
@@ -7,7 +7,7 @@
7#include "common/logging/log.h" 7#include "common/logging/log.h"
8#include "common/scope_exit.h" 8#include "common/scope_exit.h"
9#include "core/file_sys/program_metadata.h" 9#include "core/file_sys/program_metadata.h"
10#include "core/file_sys/vfs.h" 10#include "core/file_sys/vfs/vfs.h"
11#include "core/loader/loader.h" 11#include "core/loader/loader.h"
12 12
13namespace FileSys { 13namespace FileSys {
diff --git a/src/core/file_sys/program_metadata.h b/src/core/file_sys/program_metadata.h
index a53092b87..115e6d6cd 100644
--- a/src/core/file_sys/program_metadata.h
+++ b/src/core/file_sys/program_metadata.h
@@ -10,7 +10,7 @@
10#include "common/common_funcs.h" 10#include "common/common_funcs.h"
11#include "common/common_types.h" 11#include "common/common_types.h"
12#include "common/swap.h" 12#include "common/swap.h"
13#include "core/file_sys/vfs_types.h" 13#include "core/file_sys/vfs/vfs_types.h"
14 14
15namespace Loader { 15namespace Loader {
16enum class ResultStatus : u16; 16enum class ResultStatus : u16;
diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp
index 1cc77ad14..85d30543c 100644
--- a/src/core/file_sys/registered_cache.cpp
+++ b/src/core/file_sys/registered_cache.cpp
@@ -17,7 +17,7 @@
17#include "core/file_sys/nca_metadata.h" 17#include "core/file_sys/nca_metadata.h"
18#include "core/file_sys/registered_cache.h" 18#include "core/file_sys/registered_cache.h"
19#include "core/file_sys/submission_package.h" 19#include "core/file_sys/submission_package.h"
20#include "core/file_sys/vfs_concat.h" 20#include "core/file_sys/vfs/vfs_concat.h"
21#include "core/loader/loader.h" 21#include "core/loader/loader.h"
22 22
23namespace FileSys { 23namespace FileSys {
diff --git a/src/core/file_sys/registered_cache.h b/src/core/file_sys/registered_cache.h
index 64815a845..a7fc55673 100644
--- a/src/core/file_sys/registered_cache.h
+++ b/src/core/file_sys/registered_cache.h
@@ -11,7 +11,7 @@
11#include <boost/container/flat_map.hpp> 11#include <boost/container/flat_map.hpp>
12#include "common/common_types.h" 12#include "common/common_types.h"
13#include "core/crypto/key_manager.h" 13#include "core/crypto/key_manager.h"
14#include "core/file_sys/vfs.h" 14#include "core/file_sys/vfs/vfs.h"
15 15
16namespace FileSys { 16namespace FileSys {
17class CNMT; 17class CNMT;
diff --git a/src/core/file_sys/romfs.cpp b/src/core/file_sys/romfs.cpp
index 6182598ae..a2b280973 100644
--- a/src/core/file_sys/romfs.cpp
+++ b/src/core/file_sys/romfs.cpp
@@ -9,11 +9,11 @@
9#include "common/swap.h" 9#include "common/swap.h"
10#include "core/file_sys/fsmitm_romfsbuild.h" 10#include "core/file_sys/fsmitm_romfsbuild.h"
11#include "core/file_sys/romfs.h" 11#include "core/file_sys/romfs.h"
12#include "core/file_sys/vfs.h" 12#include "core/file_sys/vfs/vfs.h"
13#include "core/file_sys/vfs_cached.h" 13#include "core/file_sys/vfs/vfs_cached.h"
14#include "core/file_sys/vfs_concat.h" 14#include "core/file_sys/vfs/vfs_concat.h"
15#include "core/file_sys/vfs_offset.h" 15#include "core/file_sys/vfs/vfs_offset.h"
16#include "core/file_sys/vfs_vector.h" 16#include "core/file_sys/vfs/vfs_vector.h"
17 17
18namespace FileSys { 18namespace FileSys {
19namespace { 19namespace {
diff --git a/src/core/file_sys/romfs.h b/src/core/file_sys/romfs.h
index b75ff1aad..3c0aca291 100644
--- a/src/core/file_sys/romfs.h
+++ b/src/core/file_sys/romfs.h
@@ -3,7 +3,7 @@
3 3
4#pragma once 4#pragma once
5 5
6#include "core/file_sys/vfs.h" 6#include "core/file_sys/vfs/vfs.h"
7 7
8namespace FileSys { 8namespace FileSys {
9 9
diff --git a/src/core/file_sys/romfs_factory.h b/src/core/file_sys/romfs_factory.h
index e4809bc94..11ecfabdf 100644
--- a/src/core/file_sys/romfs_factory.h
+++ b/src/core/file_sys/romfs_factory.h
@@ -6,7 +6,7 @@
6#include <memory> 6#include <memory>
7 7
8#include "common/common_types.h" 8#include "common/common_types.h"
9#include "core/file_sys/vfs_types.h" 9#include "core/file_sys/vfs/vfs_types.h"
10#include "core/hle/result.h" 10#include "core/hle/result.h"
11 11
12namespace Loader { 12namespace Loader {
diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp
index 23196cd5f..cbf411a20 100644
--- a/src/core/file_sys/savedata_factory.cpp
+++ b/src/core/file_sys/savedata_factory.cpp
@@ -8,7 +8,7 @@
8#include "common/uuid.h" 8#include "common/uuid.h"
9#include "core/core.h" 9#include "core/core.h"
10#include "core/file_sys/savedata_factory.h" 10#include "core/file_sys/savedata_factory.h"
11#include "core/file_sys/vfs.h" 11#include "core/file_sys/vfs/vfs.h"
12 12
13namespace FileSys { 13namespace FileSys {
14 14
diff --git a/src/core/file_sys/savedata_factory.h b/src/core/file_sys/savedata_factory.h
index 30d96928e..5ab7e4d32 100644
--- a/src/core/file_sys/savedata_factory.h
+++ b/src/core/file_sys/savedata_factory.h
@@ -7,7 +7,7 @@
7#include <string> 7#include <string>
8#include "common/common_funcs.h" 8#include "common/common_funcs.h"
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "core/file_sys/vfs.h" 10#include "core/file_sys/vfs/vfs.h"
11#include "core/hle/result.h" 11#include "core/hle/result.h"
12 12
13namespace Core { 13namespace Core {
diff --git a/src/core/file_sys/sdmc_factory.cpp b/src/core/file_sys/sdmc_factory.cpp
index d5158cd64..f3e2e21f4 100644
--- a/src/core/file_sys/sdmc_factory.cpp
+++ b/src/core/file_sys/sdmc_factory.cpp
@@ -4,7 +4,7 @@
4#include <memory> 4#include <memory>
5#include "core/file_sys/registered_cache.h" 5#include "core/file_sys/registered_cache.h"
6#include "core/file_sys/sdmc_factory.h" 6#include "core/file_sys/sdmc_factory.h"
7#include "core/file_sys/vfs.h" 7#include "core/file_sys/vfs/vfs.h"
8#include "core/file_sys/xts_archive.h" 8#include "core/file_sys/xts_archive.h"
9 9
10namespace FileSys { 10namespace FileSys {
diff --git a/src/core/file_sys/sdmc_factory.h b/src/core/file_sys/sdmc_factory.h
index a445fdb16..ee69ccd07 100644
--- a/src/core/file_sys/sdmc_factory.h
+++ b/src/core/file_sys/sdmc_factory.h
@@ -4,7 +4,7 @@
4#pragma once 4#pragma once
5 5
6#include <memory> 6#include <memory>
7#include "core/file_sys/vfs_types.h" 7#include "core/file_sys/vfs/vfs_types.h"
8#include "core/hle/result.h" 8#include "core/hle/result.h"
9 9
10namespace FileSys { 10namespace FileSys {
diff --git a/src/core/file_sys/submission_package.h b/src/core/file_sys/submission_package.h
index 915bffca9..935e9589d 100644
--- a/src/core/file_sys/submission_package.h
+++ b/src/core/file_sys/submission_package.h
@@ -9,7 +9,7 @@
9#include <vector> 9#include <vector>
10#include "common/common_types.h" 10#include "common/common_types.h"
11#include "core/file_sys/nca_metadata.h" 11#include "core/file_sys/nca_metadata.h"
12#include "core/file_sys/vfs.h" 12#include "core/file_sys/vfs/vfs.h"
13 13
14namespace Core::Crypto { 14namespace Core::Crypto {
15class KeyManager; 15class KeyManager;
diff --git a/src/core/file_sys/system_archive/mii_model.cpp b/src/core/file_sys/system_archive/mii_model.cpp
index 5c87b42f8..a96cb2cd2 100644
--- a/src/core/file_sys/system_archive/mii_model.cpp
+++ b/src/core/file_sys/system_archive/mii_model.cpp
@@ -2,7 +2,7 @@
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "core/file_sys/system_archive/mii_model.h" 4#include "core/file_sys/system_archive/mii_model.h"
5#include "core/file_sys/vfs_vector.h" 5#include "core/file_sys/vfs/vfs_vector.h"
6 6
7namespace FileSys::SystemArchive { 7namespace FileSys::SystemArchive {
8 8
diff --git a/src/core/file_sys/system_archive/mii_model.h b/src/core/file_sys/system_archive/mii_model.h
index b6cbefe24..61723ed0d 100644
--- a/src/core/file_sys/system_archive/mii_model.h
+++ b/src/core/file_sys/system_archive/mii_model.h
@@ -3,7 +3,7 @@
3 3
4#pragma once 4#pragma once
5 5
6#include "core/file_sys/vfs_types.h" 6#include "core/file_sys/vfs/vfs_types.h"
7 7
8namespace FileSys::SystemArchive { 8namespace FileSys::SystemArchive {
9 9
diff --git a/src/core/file_sys/system_archive/ng_word.cpp b/src/core/file_sys/system_archive/ng_word.cpp
index 5cf6749da..1fa67877d 100644
--- a/src/core/file_sys/system_archive/ng_word.cpp
+++ b/src/core/file_sys/system_archive/ng_word.cpp
@@ -4,7 +4,7 @@
4#include <fmt/format.h> 4#include <fmt/format.h>
5#include "common/common_types.h" 5#include "common/common_types.h"
6#include "core/file_sys/system_archive/ng_word.h" 6#include "core/file_sys/system_archive/ng_word.h"
7#include "core/file_sys/vfs_vector.h" 7#include "core/file_sys/vfs/vfs_vector.h"
8 8
9namespace FileSys::SystemArchive { 9namespace FileSys::SystemArchive {
10 10
diff --git a/src/core/file_sys/system_archive/ng_word.h b/src/core/file_sys/system_archive/ng_word.h
index 1d7b49532..51bcc3327 100644
--- a/src/core/file_sys/system_archive/ng_word.h
+++ b/src/core/file_sys/system_archive/ng_word.h
@@ -3,7 +3,7 @@
3 3
4#pragma once 4#pragma once
5 5
6#include "core/file_sys/vfs_types.h" 6#include "core/file_sys/vfs/vfs_types.h"
7 7
8namespace FileSys::SystemArchive { 8namespace FileSys::SystemArchive {
9 9
diff --git a/src/core/file_sys/system_archive/shared_font.cpp b/src/core/file_sys/system_archive/shared_font.cpp
index 3210583f0..deb52069d 100644
--- a/src/core/file_sys/system_archive/shared_font.cpp
+++ b/src/core/file_sys/system_archive/shared_font.cpp
@@ -8,7 +8,7 @@
8#include "core/file_sys/system_archive/data/font_nintendo_extended.h" 8#include "core/file_sys/system_archive/data/font_nintendo_extended.h"
9#include "core/file_sys/system_archive/data/font_standard.h" 9#include "core/file_sys/system_archive/data/font_standard.h"
10#include "core/file_sys/system_archive/shared_font.h" 10#include "core/file_sys/system_archive/shared_font.h"
11#include "core/file_sys/vfs_vector.h" 11#include "core/file_sys/vfs/vfs_vector.h"
12#include "core/hle/service/ns/iplatform_service_manager.h" 12#include "core/hle/service/ns/iplatform_service_manager.h"
13 13
14namespace FileSys::SystemArchive { 14namespace FileSys::SystemArchive {
diff --git a/src/core/file_sys/system_archive/shared_font.h b/src/core/file_sys/system_archive/shared_font.h
index d1cd1dc44..2d19fcde3 100644
--- a/src/core/file_sys/system_archive/shared_font.h
+++ b/src/core/file_sys/system_archive/shared_font.h
@@ -3,7 +3,7 @@
3 3
4#pragma once 4#pragma once
5 5
6#include "core/file_sys/vfs_types.h" 6#include "core/file_sys/vfs/vfs_types.h"
7 7
8namespace FileSys::SystemArchive { 8namespace FileSys::SystemArchive {
9 9
diff --git a/src/core/file_sys/system_archive/system_archive.h b/src/core/file_sys/system_archive/system_archive.h
index 02d9157bb..2f64247bc 100644
--- a/src/core/file_sys/system_archive/system_archive.h
+++ b/src/core/file_sys/system_archive/system_archive.h
@@ -4,7 +4,7 @@
4#pragma once 4#pragma once
5 5
6#include "common/common_types.h" 6#include "common/common_types.h"
7#include "core/file_sys/vfs_types.h" 7#include "core/file_sys/vfs/vfs_types.h"
8 8
9namespace FileSys::SystemArchive { 9namespace FileSys::SystemArchive {
10 10
diff --git a/src/core/file_sys/system_archive/system_version.cpp b/src/core/file_sys/system_archive/system_version.cpp
index e4751c2b4..5662004b7 100644
--- a/src/core/file_sys/system_archive/system_version.cpp
+++ b/src/core/file_sys/system_archive/system_version.cpp
@@ -3,7 +3,7 @@
3 3
4#include "common/logging/log.h" 4#include "common/logging/log.h"
5#include "core/file_sys/system_archive/system_version.h" 5#include "core/file_sys/system_archive/system_version.h"
6#include "core/file_sys/vfs_vector.h" 6#include "core/file_sys/vfs/vfs_vector.h"
7#include "core/hle/api_version.h" 7#include "core/hle/api_version.h"
8 8
9namespace FileSys::SystemArchive { 9namespace FileSys::SystemArchive {
diff --git a/src/core/file_sys/system_archive/system_version.h b/src/core/file_sys/system_archive/system_version.h
index 21b5514a9..e5f7b952e 100644
--- a/src/core/file_sys/system_archive/system_version.h
+++ b/src/core/file_sys/system_archive/system_version.h
@@ -4,7 +4,7 @@
4#pragma once 4#pragma once
5 5
6#include <string> 6#include <string>
7#include "core/file_sys/vfs_types.h" 7#include "core/file_sys/vfs/vfs_types.h"
8 8
9namespace FileSys::SystemArchive { 9namespace FileSys::SystemArchive {
10 10
diff --git a/src/core/file_sys/system_archive/time_zone_binary.cpp b/src/core/file_sys/system_archive/time_zone_binary.cpp
index d4d2eae76..316ff0dc6 100644
--- a/src/core/file_sys/system_archive/time_zone_binary.cpp
+++ b/src/core/file_sys/system_archive/time_zone_binary.cpp
@@ -5,7 +5,7 @@
5 5
6#include "common/swap.h" 6#include "common/swap.h"
7#include "core/file_sys/system_archive/time_zone_binary.h" 7#include "core/file_sys/system_archive/time_zone_binary.h"
8#include "core/file_sys/vfs_vector.h" 8#include "core/file_sys/vfs/vfs_vector.h"
9 9
10#include "nx_tzdb.h" 10#include "nx_tzdb.h"
11 11
diff --git a/src/core/file_sys/system_archive/time_zone_binary.h b/src/core/file_sys/system_archive/time_zone_binary.h
index d0e1a4acd..e44fc5007 100644
--- a/src/core/file_sys/system_archive/time_zone_binary.h
+++ b/src/core/file_sys/system_archive/time_zone_binary.h
@@ -3,7 +3,7 @@
3 3
4#pragma once 4#pragma once
5 5
6#include "core/file_sys/vfs_types.h" 6#include "core/file_sys/vfs/vfs_types.h"
7 7
8namespace FileSys::SystemArchive { 8namespace FileSys::SystemArchive {
9 9
diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs/vfs.cpp
index b7105c8ff..a04292760 100644
--- a/src/core/file_sys/vfs.cpp
+++ b/src/core/file_sys/vfs/vfs.cpp
@@ -5,8 +5,7 @@
5#include <numeric> 5#include <numeric>
6#include <string> 6#include <string>
7#include "common/fs/path_util.h" 7#include "common/fs/path_util.h"
8#include "core/file_sys/mode.h" 8#include "core/file_sys/vfs/vfs.h"
9#include "core/file_sys/vfs.h"
10 9
11namespace FileSys { 10namespace FileSys {
12 11
@@ -36,12 +35,12 @@ VfsEntryType VfsFilesystem::GetEntryType(std::string_view path_) const {
36 return VfsEntryType::None; 35 return VfsEntryType::None;
37} 36}
38 37
39VirtualFile VfsFilesystem::OpenFile(std::string_view path_, Mode perms) { 38VirtualFile VfsFilesystem::OpenFile(std::string_view path_, OpenMode perms) {
40 const auto path = Common::FS::SanitizePath(path_); 39 const auto path = Common::FS::SanitizePath(path_);
41 return root->GetFileRelative(path); 40 return root->GetFileRelative(path);
42} 41}
43 42
44VirtualFile VfsFilesystem::CreateFile(std::string_view path_, Mode perms) { 43VirtualFile VfsFilesystem::CreateFile(std::string_view path_, OpenMode perms) {
45 const auto path = Common::FS::SanitizePath(path_); 44 const auto path = Common::FS::SanitizePath(path_);
46 return root->CreateFileRelative(path); 45 return root->CreateFileRelative(path);
47} 46}
@@ -54,17 +53,17 @@ VirtualFile VfsFilesystem::CopyFile(std::string_view old_path_, std::string_view
54 if (Common::FS::GetParentPath(old_path) == Common::FS::GetParentPath(new_path)) { 53 if (Common::FS::GetParentPath(old_path) == Common::FS::GetParentPath(new_path)) {
55 if (!root->Copy(Common::FS::GetFilename(old_path), Common::FS::GetFilename(new_path))) 54 if (!root->Copy(Common::FS::GetFilename(old_path), Common::FS::GetFilename(new_path)))
56 return nullptr; 55 return nullptr;
57 return OpenFile(new_path, Mode::ReadWrite); 56 return OpenFile(new_path, OpenMode::ReadWrite);
58 } 57 }
59 58
60 // Do it using RawCopy. Non-default impls are encouraged to optimize this. 59 // Do it using RawCopy. Non-default impls are encouraged to optimize this.
61 const auto old_file = OpenFile(old_path, Mode::Read); 60 const auto old_file = OpenFile(old_path, OpenMode::Read);
62 if (old_file == nullptr) 61 if (old_file == nullptr)
63 return nullptr; 62 return nullptr;
64 auto new_file = OpenFile(new_path, Mode::Read); 63 auto new_file = OpenFile(new_path, OpenMode::Read);
65 if (new_file != nullptr) 64 if (new_file != nullptr)
66 return nullptr; 65 return nullptr;
67 new_file = CreateFile(new_path, Mode::Write); 66 new_file = CreateFile(new_path, OpenMode::Write);
68 if (new_file == nullptr) 67 if (new_file == nullptr)
69 return nullptr; 68 return nullptr;
70 if (!VfsRawCopy(old_file, new_file)) 69 if (!VfsRawCopy(old_file, new_file))
@@ -87,18 +86,18 @@ VirtualFile VfsFilesystem::MoveFile(std::string_view old_path, std::string_view
87 86
88bool VfsFilesystem::DeleteFile(std::string_view path_) { 87bool VfsFilesystem::DeleteFile(std::string_view path_) {
89 const auto path = Common::FS::SanitizePath(path_); 88 const auto path = Common::FS::SanitizePath(path_);
90 auto parent = OpenDirectory(Common::FS::GetParentPath(path), Mode::Write); 89 auto parent = OpenDirectory(Common::FS::GetParentPath(path), OpenMode::Write);
91 if (parent == nullptr) 90 if (parent == nullptr)
92 return false; 91 return false;
93 return parent->DeleteFile(Common::FS::GetFilename(path)); 92 return parent->DeleteFile(Common::FS::GetFilename(path));
94} 93}
95 94
96VirtualDir VfsFilesystem::OpenDirectory(std::string_view path_, Mode perms) { 95VirtualDir VfsFilesystem::OpenDirectory(std::string_view path_, OpenMode perms) {
97 const auto path = Common::FS::SanitizePath(path_); 96 const auto path = Common::FS::SanitizePath(path_);
98 return root->GetDirectoryRelative(path); 97 return root->GetDirectoryRelative(path);
99} 98}
100 99
101VirtualDir VfsFilesystem::CreateDirectory(std::string_view path_, Mode perms) { 100VirtualDir VfsFilesystem::CreateDirectory(std::string_view path_, OpenMode perms) {
102 const auto path = Common::FS::SanitizePath(path_); 101 const auto path = Common::FS::SanitizePath(path_);
103 return root->CreateDirectoryRelative(path); 102 return root->CreateDirectoryRelative(path);
104} 103}
@@ -108,13 +107,13 @@ VirtualDir VfsFilesystem::CopyDirectory(std::string_view old_path_, std::string_
108 const auto new_path = Common::FS::SanitizePath(new_path_); 107 const auto new_path = Common::FS::SanitizePath(new_path_);
109 108
110 // Non-default impls are highly encouraged to provide a more optimized version of this. 109 // Non-default impls are highly encouraged to provide a more optimized version of this.
111 auto old_dir = OpenDirectory(old_path, Mode::Read); 110 auto old_dir = OpenDirectory(old_path, OpenMode::Read);
112 if (old_dir == nullptr) 111 if (old_dir == nullptr)
113 return nullptr; 112 return nullptr;
114 auto new_dir = OpenDirectory(new_path, Mode::Read); 113 auto new_dir = OpenDirectory(new_path, OpenMode::Read);
115 if (new_dir != nullptr) 114 if (new_dir != nullptr)
116 return nullptr; 115 return nullptr;
117 new_dir = CreateDirectory(new_path, Mode::Write); 116 new_dir = CreateDirectory(new_path, OpenMode::Write);
118 if (new_dir == nullptr) 117 if (new_dir == nullptr)
119 return nullptr; 118 return nullptr;
120 119
@@ -149,7 +148,7 @@ VirtualDir VfsFilesystem::MoveDirectory(std::string_view old_path, std::string_v
149 148
150bool VfsFilesystem::DeleteDirectory(std::string_view path_) { 149bool VfsFilesystem::DeleteDirectory(std::string_view path_) {
151 const auto path = Common::FS::SanitizePath(path_); 150 const auto path = Common::FS::SanitizePath(path_);
152 auto parent = OpenDirectory(Common::FS::GetParentPath(path), Mode::Write); 151 auto parent = OpenDirectory(Common::FS::GetParentPath(path), OpenMode::Write);
153 if (parent == nullptr) 152 if (parent == nullptr)
154 return false; 153 return false;
155 return parent->DeleteSubdirectoryRecursive(Common::FS::GetFilename(path)); 154 return parent->DeleteSubdirectoryRecursive(Common::FS::GetFilename(path));
diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs/vfs.h
index a7cd1cae3..f846a9669 100644
--- a/src/core/file_sys/vfs.h
+++ b/src/core/file_sys/vfs/vfs.h
@@ -13,12 +13,11 @@
13 13
14#include "common/common_funcs.h" 14#include "common/common_funcs.h"
15#include "common/common_types.h" 15#include "common/common_types.h"
16#include "core/file_sys/vfs_types.h" 16#include "core/file_sys/fs_filesystem.h"
17#include "core/file_sys/vfs/vfs_types.h"
17 18
18namespace FileSys { 19namespace FileSys {
19 20
20enum class Mode : u32;
21
22// An enumeration representing what can be at the end of a path in a VfsFilesystem 21// An enumeration representing what can be at the end of a path in a VfsFilesystem
23enum class VfsEntryType { 22enum class VfsEntryType {
24 None, 23 None,
@@ -49,9 +48,9 @@ public:
49 virtual VfsEntryType GetEntryType(std::string_view path) const; 48 virtual VfsEntryType GetEntryType(std::string_view path) const;
50 49
51 // Opens the file with path relative to root. If it doesn't exist, returns nullptr. 50 // Opens the file with path relative to root. If it doesn't exist, returns nullptr.
52 virtual VirtualFile OpenFile(std::string_view path, Mode perms); 51 virtual VirtualFile OpenFile(std::string_view path, OpenMode perms);
53 // Creates a new, empty file at path 52 // Creates a new, empty file at path
54 virtual VirtualFile CreateFile(std::string_view path, Mode perms); 53 virtual VirtualFile CreateFile(std::string_view path, OpenMode perms);
55 // Copies the file from old_path to new_path, returning the new file on success and nullptr on 54 // Copies the file from old_path to new_path, returning the new file on success and nullptr on
56 // failure. 55 // failure.
57 virtual VirtualFile CopyFile(std::string_view old_path, std::string_view new_path); 56 virtual VirtualFile CopyFile(std::string_view old_path, std::string_view new_path);
@@ -62,9 +61,9 @@ public:
62 virtual bool DeleteFile(std::string_view path); 61 virtual bool DeleteFile(std::string_view path);
63 62
64 // Opens the directory with path relative to root. If it doesn't exist, returns nullptr. 63 // Opens the directory with path relative to root. If it doesn't exist, returns nullptr.
65 virtual VirtualDir OpenDirectory(std::string_view path, Mode perms); 64 virtual VirtualDir OpenDirectory(std::string_view path, OpenMode perms);
66 // Creates a new, empty directory at path 65 // Creates a new, empty directory at path
67 virtual VirtualDir CreateDirectory(std::string_view path, Mode perms); 66 virtual VirtualDir CreateDirectory(std::string_view path, OpenMode perms);
68 // Copies the directory from old_path to new_path, returning the new directory on success and 67 // Copies the directory from old_path to new_path, returning the new directory on success and
69 // nullptr on failure. 68 // nullptr on failure.
70 virtual VirtualDir CopyDirectory(std::string_view old_path, std::string_view new_path); 69 virtual VirtualDir CopyDirectory(std::string_view old_path, std::string_view new_path);
diff --git a/src/core/file_sys/vfs_cached.cpp b/src/core/file_sys/vfs/vfs_cached.cpp
index 7ee5300e5..01cd0f1e0 100644
--- a/src/core/file_sys/vfs_cached.cpp
+++ b/src/core/file_sys/vfs/vfs_cached.cpp
@@ -1,8 +1,8 @@
1// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project 1// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
2// SPDX-License-Identifier: GPL-2.0-or-later 2// SPDX-License-Identifier: GPL-2.0-or-later
3 3
4#include "core/file_sys/vfs_cached.h" 4#include "core/file_sys/vfs/vfs_cached.h"
5#include "core/file_sys/vfs_types.h" 5#include "core/file_sys/vfs/vfs_types.h"
6 6
7namespace FileSys { 7namespace FileSys {
8 8
diff --git a/src/core/file_sys/vfs_cached.h b/src/core/file_sys/vfs/vfs_cached.h
index 1e5300784..47dff7224 100644
--- a/src/core/file_sys/vfs_cached.h
+++ b/src/core/file_sys/vfs/vfs_cached.h
@@ -5,7 +5,7 @@
5 5
6#include <string_view> 6#include <string_view>
7#include <vector> 7#include <vector>
8#include "core/file_sys/vfs.h" 8#include "core/file_sys/vfs/vfs.h"
9 9
10namespace FileSys { 10namespace FileSys {
11 11
diff --git a/src/core/file_sys/vfs_concat.cpp b/src/core/file_sys/vfs/vfs_concat.cpp
index 7c7298527..b5cc9a9e9 100644
--- a/src/core/file_sys/vfs_concat.cpp
+++ b/src/core/file_sys/vfs/vfs_concat.cpp
@@ -5,8 +5,8 @@
5#include <utility> 5#include <utility>
6 6
7#include "common/assert.h" 7#include "common/assert.h"
8#include "core/file_sys/vfs_concat.h" 8#include "core/file_sys/vfs/vfs_concat.h"
9#include "core/file_sys/vfs_static.h" 9#include "core/file_sys/vfs/vfs_static.h"
10 10
11namespace FileSys { 11namespace FileSys {
12 12
diff --git a/src/core/file_sys/vfs_concat.h b/src/core/file_sys/vfs/vfs_concat.h
index b5f3d72e3..6d12af762 100644
--- a/src/core/file_sys/vfs_concat.h
+++ b/src/core/file_sys/vfs/vfs_concat.h
@@ -6,7 +6,7 @@
6#include <compare> 6#include <compare>
7#include <map> 7#include <map>
8#include <memory> 8#include <memory>
9#include "core/file_sys/vfs.h" 9#include "core/file_sys/vfs/vfs.h"
10 10
11namespace FileSys { 11namespace FileSys {
12 12
diff --git a/src/core/file_sys/vfs_layered.cpp b/src/core/file_sys/vfs/vfs_layered.cpp
index 5551743fb..47b2a3c78 100644
--- a/src/core/file_sys/vfs_layered.cpp
+++ b/src/core/file_sys/vfs/vfs_layered.cpp
@@ -5,7 +5,7 @@
5#include <set> 5#include <set>
6#include <unordered_set> 6#include <unordered_set>
7#include <utility> 7#include <utility>
8#include "core/file_sys/vfs_layered.h" 8#include "core/file_sys/vfs/vfs_layered.h"
9 9
10namespace FileSys { 10namespace FileSys {
11 11
diff --git a/src/core/file_sys/vfs_layered.h b/src/core/file_sys/vfs/vfs_layered.h
index a62112e9d..0027ffa9a 100644
--- a/src/core/file_sys/vfs_layered.h
+++ b/src/core/file_sys/vfs/vfs_layered.h
@@ -4,7 +4,7 @@
4#pragma once 4#pragma once
5 5
6#include <memory> 6#include <memory>
7#include "core/file_sys/vfs.h" 7#include "core/file_sys/vfs/vfs.h"
8 8
9namespace FileSys { 9namespace FileSys {
10 10
diff --git a/src/core/file_sys/vfs_offset.cpp b/src/core/file_sys/vfs/vfs_offset.cpp
index d950a6633..1a37d2670 100644
--- a/src/core/file_sys/vfs_offset.cpp
+++ b/src/core/file_sys/vfs/vfs_offset.cpp
@@ -4,7 +4,7 @@
4#include <algorithm> 4#include <algorithm>
5#include <utility> 5#include <utility>
6 6
7#include "core/file_sys/vfs_offset.h" 7#include "core/file_sys/vfs/vfs_offset.h"
8 8
9namespace FileSys { 9namespace FileSys {
10 10
diff --git a/src/core/file_sys/vfs_offset.h b/src/core/file_sys/vfs/vfs_offset.h
index 6c051ca00..4abe41d8e 100644
--- a/src/core/file_sys/vfs_offset.h
+++ b/src/core/file_sys/vfs/vfs_offset.h
@@ -5,7 +5,7 @@
5 5
6#include <memory> 6#include <memory>
7 7
8#include "core/file_sys/vfs.h" 8#include "core/file_sys/vfs/vfs.h"
9 9
10namespace FileSys { 10namespace FileSys {
11 11
diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs/vfs_real.cpp
index cd9b79786..627d5d251 100644
--- a/src/core/file_sys/vfs_real.cpp
+++ b/src/core/file_sys/vfs/vfs_real.cpp
@@ -10,8 +10,8 @@
10#include "common/fs/fs.h" 10#include "common/fs/fs.h"
11#include "common/fs/path_util.h" 11#include "common/fs/path_util.h"
12#include "common/logging/log.h" 12#include "common/logging/log.h"
13#include "core/file_sys/vfs.h" 13#include "core/file_sys/vfs/vfs.h"
14#include "core/file_sys/vfs_real.h" 14#include "core/file_sys/vfs/vfs_real.h"
15 15
16// For FileTimeStampRaw 16// For FileTimeStampRaw
17#include <sys/stat.h> 17#include <sys/stat.h>
@@ -28,16 +28,14 @@ namespace {
28 28
29constexpr size_t MaxOpenFiles = 512; 29constexpr size_t MaxOpenFiles = 512;
30 30
31constexpr FS::FileAccessMode ModeFlagsToFileAccessMode(Mode mode) { 31constexpr FS::FileAccessMode ModeFlagsToFileAccessMode(OpenMode mode) {
32 switch (mode) { 32 switch (mode) {
33 case Mode::Read: 33 case OpenMode::Read:
34 return FS::FileAccessMode::Read; 34 return FS::FileAccessMode::Read;
35 case Mode::Write: 35 case OpenMode::Write:
36 case Mode::ReadWrite: 36 case OpenMode::ReadWrite:
37 case Mode::Append: 37 case OpenMode::AllowAppend:
38 case Mode::ReadAppend: 38 case OpenMode::All:
39 case Mode::WriteAppend:
40 case Mode::All:
41 return FS::FileAccessMode::ReadWrite; 39 return FS::FileAccessMode::ReadWrite;
42 default: 40 default:
43 return {}; 41 return {};
@@ -74,7 +72,7 @@ VfsEntryType RealVfsFilesystem::GetEntryType(std::string_view path_) const {
74} 72}
75 73
76VirtualFile RealVfsFilesystem::OpenFileFromEntry(std::string_view path_, std::optional<u64> size, 74VirtualFile RealVfsFilesystem::OpenFileFromEntry(std::string_view path_, std::optional<u64> size,
77 Mode perms) { 75 OpenMode perms) {
78 const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); 76 const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault);
79 std::scoped_lock lk{list_lock}; 77 std::scoped_lock lk{list_lock};
80 78
@@ -98,11 +96,11 @@ VirtualFile RealVfsFilesystem::OpenFileFromEntry(std::string_view path_, std::op
98 return file; 96 return file;
99} 97}
100 98
101VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) { 99VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, OpenMode perms) {
102 return OpenFileFromEntry(path_, {}, perms); 100 return OpenFileFromEntry(path_, {}, perms);
103} 101}
104 102
105VirtualFile RealVfsFilesystem::CreateFile(std::string_view path_, Mode perms) { 103VirtualFile RealVfsFilesystem::CreateFile(std::string_view path_, OpenMode perms) {
106 const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); 104 const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault);
107 { 105 {
108 std::scoped_lock lk{list_lock}; 106 std::scoped_lock lk{list_lock};
@@ -145,7 +143,7 @@ VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_
145 if (!FS::RenameFile(old_path, new_path)) { 143 if (!FS::RenameFile(old_path, new_path)) {
146 return nullptr; 144 return nullptr;
147 } 145 }
148 return OpenFile(new_path, Mode::ReadWrite); 146 return OpenFile(new_path, OpenMode::ReadWrite);
149} 147}
150 148
151bool RealVfsFilesystem::DeleteFile(std::string_view path_) { 149bool RealVfsFilesystem::DeleteFile(std::string_view path_) {
@@ -157,12 +155,12 @@ bool RealVfsFilesystem::DeleteFile(std::string_view path_) {
157 return FS::RemoveFile(path); 155 return FS::RemoveFile(path);
158} 156}
159 157
160VirtualDir RealVfsFilesystem::OpenDirectory(std::string_view path_, Mode perms) { 158VirtualDir RealVfsFilesystem::OpenDirectory(std::string_view path_, OpenMode perms) {
161 const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); 159 const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault);
162 return std::shared_ptr<RealVfsDirectory>(new RealVfsDirectory(*this, path, perms)); 160 return std::shared_ptr<RealVfsDirectory>(new RealVfsDirectory(*this, path, perms));
163} 161}
164 162
165VirtualDir RealVfsFilesystem::CreateDirectory(std::string_view path_, Mode perms) { 163VirtualDir RealVfsFilesystem::CreateDirectory(std::string_view path_, OpenMode perms) {
166 const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault); 164 const auto path = FS::SanitizePath(path_, FS::DirectorySeparator::PlatformDefault);
167 if (!FS::CreateDirs(path)) { 165 if (!FS::CreateDirs(path)) {
168 return nullptr; 166 return nullptr;
@@ -184,7 +182,7 @@ VirtualDir RealVfsFilesystem::MoveDirectory(std::string_view old_path_,
184 if (!FS::RenameDir(old_path, new_path)) { 182 if (!FS::RenameDir(old_path, new_path)) {
185 return nullptr; 183 return nullptr;
186 } 184 }
187 return OpenDirectory(new_path, Mode::ReadWrite); 185 return OpenDirectory(new_path, OpenMode::ReadWrite);
188} 186}
189 187
190bool RealVfsFilesystem::DeleteDirectory(std::string_view path_) { 188bool RealVfsFilesystem::DeleteDirectory(std::string_view path_) {
@@ -193,7 +191,7 @@ bool RealVfsFilesystem::DeleteDirectory(std::string_view path_) {
193} 191}
194 192
195std::unique_lock<std::mutex> RealVfsFilesystem::RefreshReference(const std::string& path, 193std::unique_lock<std::mutex> RealVfsFilesystem::RefreshReference(const std::string& path,
196 Mode perms, 194 OpenMode perms,
197 FileReference& reference) { 195 FileReference& reference) {
198 std::unique_lock lk{list_lock}; 196 std::unique_lock lk{list_lock};
199 197
@@ -266,7 +264,7 @@ void RealVfsFilesystem::RemoveReferenceFromListLocked(FileReference& reference)
266} 264}
267 265
268RealVfsFile::RealVfsFile(RealVfsFilesystem& base_, std::unique_ptr<FileReference> reference_, 266RealVfsFile::RealVfsFile(RealVfsFilesystem& base_, std::unique_ptr<FileReference> reference_,
269 const std::string& path_, Mode perms_, std::optional<u64> size_) 267 const std::string& path_, OpenMode perms_, std::optional<u64> size_)
270 : base(base_), reference(std::move(reference_)), path(path_), 268 : base(base_), reference(std::move(reference_)), path(path_),
271 parent_path(FS::GetParentPath(path_)), path_components(FS::SplitPathComponentsCopy(path_)), 269 parent_path(FS::GetParentPath(path_)), path_components(FS::SplitPathComponentsCopy(path_)),
272 size(size_), perms(perms_) {} 270 size(size_), perms(perms_) {}
@@ -298,11 +296,11 @@ VirtualDir RealVfsFile::GetContainingDirectory() const {
298} 296}
299 297
300bool RealVfsFile::IsWritable() const { 298bool RealVfsFile::IsWritable() const {
301 return True(perms & Mode::Write); 299 return True(perms & OpenMode::Write);
302} 300}
303 301
304bool RealVfsFile::IsReadable() const { 302bool RealVfsFile::IsReadable() const {
305 return True(perms & Mode::Read); 303 return True(perms & OpenMode::Read);
306} 304}
307 305
308std::size_t RealVfsFile::Read(u8* data, std::size_t length, std::size_t offset) const { 306std::size_t RealVfsFile::Read(u8* data, std::size_t length, std::size_t offset) const {
@@ -331,7 +329,7 @@ bool RealVfsFile::Rename(std::string_view name) {
331 329
332template <> 330template <>
333std::vector<VirtualFile> RealVfsDirectory::IterateEntries<RealVfsFile, VfsFile>() const { 331std::vector<VirtualFile> RealVfsDirectory::IterateEntries<RealVfsFile, VfsFile>() const {
334 if (perms == Mode::Append) { 332 if (perms == OpenMode::AllowAppend) {
335 return {}; 333 return {};
336 } 334 }
337 335
@@ -353,7 +351,7 @@ std::vector<VirtualFile> RealVfsDirectory::IterateEntries<RealVfsFile, VfsFile>(
353 351
354template <> 352template <>
355std::vector<VirtualDir> RealVfsDirectory::IterateEntries<RealVfsDirectory, VfsDirectory>() const { 353std::vector<VirtualDir> RealVfsDirectory::IterateEntries<RealVfsDirectory, VfsDirectory>() const {
356 if (perms == Mode::Append) { 354 if (perms == OpenMode::AllowAppend) {
357 return {}; 355 return {};
358 } 356 }
359 357
@@ -373,10 +371,11 @@ std::vector<VirtualDir> RealVfsDirectory::IterateEntries<RealVfsDirectory, VfsDi
373 return out; 371 return out;
374} 372}
375 373
376RealVfsDirectory::RealVfsDirectory(RealVfsFilesystem& base_, const std::string& path_, Mode perms_) 374RealVfsDirectory::RealVfsDirectory(RealVfsFilesystem& base_, const std::string& path_,
375 OpenMode perms_)
377 : base(base_), path(FS::RemoveTrailingSlash(path_)), parent_path(FS::GetParentPath(path)), 376 : base(base_), path(FS::RemoveTrailingSlash(path_)), parent_path(FS::GetParentPath(path)),
378 path_components(FS::SplitPathComponentsCopy(path)), perms(perms_) { 377 path_components(FS::SplitPathComponentsCopy(path)), perms(perms_) {
379 if (!FS::Exists(path) && True(perms & Mode::Write)) { 378 if (!FS::Exists(path) && True(perms & OpenMode::Write)) {
380 void(FS::CreateDirs(path)); 379 void(FS::CreateDirs(path));
381 } 380 }
382} 381}
@@ -456,11 +455,11 @@ std::vector<VirtualDir> RealVfsDirectory::GetSubdirectories() const {
456} 455}
457 456
458bool RealVfsDirectory::IsWritable() const { 457bool RealVfsDirectory::IsWritable() const {
459 return True(perms & Mode::Write); 458 return True(perms & OpenMode::Write);
460} 459}
461 460
462bool RealVfsDirectory::IsReadable() const { 461bool RealVfsDirectory::IsReadable() const {
463 return True(perms & Mode::Read); 462 return True(perms & OpenMode::Read);
464} 463}
465 464
466std::string RealVfsDirectory::GetName() const { 465std::string RealVfsDirectory::GetName() const {
@@ -507,7 +506,7 @@ std::string RealVfsDirectory::GetFullPath() const {
507} 506}
508 507
509std::map<std::string, VfsEntryType, std::less<>> RealVfsDirectory::GetEntries() const { 508std::map<std::string, VfsEntryType, std::less<>> RealVfsDirectory::GetEntries() const {
510 if (perms == Mode::Append) { 509 if (perms == OpenMode::AllowAppend) {
511 return {}; 510 return {};
512 } 511 }
513 512
diff --git a/src/core/file_sys/vfs_real.h b/src/core/file_sys/vfs/vfs_real.h
index 26ea7df62..5c2172cce 100644
--- a/src/core/file_sys/vfs_real.h
+++ b/src/core/file_sys/vfs/vfs_real.h
@@ -8,8 +8,8 @@
8#include <optional> 8#include <optional>
9#include <string_view> 9#include <string_view>
10#include "common/intrusive_list.h" 10#include "common/intrusive_list.h"
11#include "core/file_sys/mode.h" 11#include "core/file_sys/fs_filesystem.h"
12#include "core/file_sys/vfs.h" 12#include "core/file_sys/vfs/vfs.h"
13 13
14namespace Common::FS { 14namespace Common::FS {
15class IOFile; 15class IOFile;
@@ -33,13 +33,14 @@ public:
33 bool IsReadable() const override; 33 bool IsReadable() const override;
34 bool IsWritable() const override; 34 bool IsWritable() const override;
35 VfsEntryType GetEntryType(std::string_view path) const override; 35 VfsEntryType GetEntryType(std::string_view path) const override;
36 VirtualFile OpenFile(std::string_view path, Mode perms = Mode::Read) override; 36 VirtualFile OpenFile(std::string_view path, OpenMode perms = OpenMode::Read) override;
37 VirtualFile CreateFile(std::string_view path, Mode perms = Mode::ReadWrite) override; 37 VirtualFile CreateFile(std::string_view path, OpenMode perms = OpenMode::ReadWrite) override;
38 VirtualFile CopyFile(std::string_view old_path, std::string_view new_path) override; 38 VirtualFile CopyFile(std::string_view old_path, std::string_view new_path) override;
39 VirtualFile MoveFile(std::string_view old_path, std::string_view new_path) override; 39 VirtualFile MoveFile(std::string_view old_path, std::string_view new_path) override;
40 bool DeleteFile(std::string_view path) override; 40 bool DeleteFile(std::string_view path) override;
41 VirtualDir OpenDirectory(std::string_view path, Mode perms = Mode::Read) override; 41 VirtualDir OpenDirectory(std::string_view path, OpenMode perms = OpenMode::Read) override;
42 VirtualDir CreateDirectory(std::string_view path, Mode perms = Mode::ReadWrite) override; 42 VirtualDir CreateDirectory(std::string_view path,
43 OpenMode perms = OpenMode::ReadWrite) override;
43 VirtualDir CopyDirectory(std::string_view old_path, std::string_view new_path) override; 44 VirtualDir CopyDirectory(std::string_view old_path, std::string_view new_path) override;
44 VirtualDir MoveDirectory(std::string_view old_path, std::string_view new_path) override; 45 VirtualDir MoveDirectory(std::string_view old_path, std::string_view new_path) override;
45 bool DeleteDirectory(std::string_view path) override; 46 bool DeleteDirectory(std::string_view path) override;
@@ -54,14 +55,14 @@ private:
54 55
55private: 56private:
56 friend class RealVfsFile; 57 friend class RealVfsFile;
57 std::unique_lock<std::mutex> RefreshReference(const std::string& path, Mode perms, 58 std::unique_lock<std::mutex> RefreshReference(const std::string& path, OpenMode perms,
58 FileReference& reference); 59 FileReference& reference);
59 void DropReference(std::unique_ptr<FileReference>&& reference); 60 void DropReference(std::unique_ptr<FileReference>&& reference);
60 61
61private: 62private:
62 friend class RealVfsDirectory; 63 friend class RealVfsDirectory;
63 VirtualFile OpenFileFromEntry(std::string_view path, std::optional<u64> size, 64 VirtualFile OpenFileFromEntry(std::string_view path, std::optional<u64> size,
64 Mode perms = Mode::Read); 65 OpenMode perms = OpenMode::Read);
65 66
66private: 67private:
67 void EvictSingleReferenceLocked(); 68 void EvictSingleReferenceLocked();
@@ -89,7 +90,8 @@ public:
89 90
90private: 91private:
91 RealVfsFile(RealVfsFilesystem& base, std::unique_ptr<FileReference> reference, 92 RealVfsFile(RealVfsFilesystem& base, std::unique_ptr<FileReference> reference,
92 const std::string& path, Mode perms = Mode::Read, std::optional<u64> size = {}); 93 const std::string& path, OpenMode perms = OpenMode::Read,
94 std::optional<u64> size = {});
93 95
94 RealVfsFilesystem& base; 96 RealVfsFilesystem& base;
95 std::unique_ptr<FileReference> reference; 97 std::unique_ptr<FileReference> reference;
@@ -97,7 +99,7 @@ private:
97 std::string parent_path; 99 std::string parent_path;
98 std::vector<std::string> path_components; 100 std::vector<std::string> path_components;
99 std::optional<u64> size; 101 std::optional<u64> size;
100 Mode perms; 102 OpenMode perms;
101}; 103};
102 104
103// An implementation of VfsDirectory that represents a directory on the user's computer. 105// An implementation of VfsDirectory that represents a directory on the user's computer.
@@ -130,7 +132,8 @@ public:
130 std::map<std::string, VfsEntryType, std::less<>> GetEntries() const override; 132 std::map<std::string, VfsEntryType, std::less<>> GetEntries() const override;
131 133
132private: 134private:
133 RealVfsDirectory(RealVfsFilesystem& base, const std::string& path, Mode perms = Mode::Read); 135 RealVfsDirectory(RealVfsFilesystem& base, const std::string& path,
136 OpenMode perms = OpenMode::Read);
134 137
135 template <typename T, typename R> 138 template <typename T, typename R>
136 std::vector<std::shared_ptr<R>> IterateEntries() const; 139 std::vector<std::shared_ptr<R>> IterateEntries() const;
@@ -139,7 +142,7 @@ private:
139 std::string path; 142 std::string path;
140 std::string parent_path; 143 std::string parent_path;
141 std::vector<std::string> path_components; 144 std::vector<std::string> path_components;
142 Mode perms; 145 OpenMode perms;
143}; 146};
144 147
145} // namespace FileSys 148} // namespace FileSys
diff --git a/src/core/file_sys/vfs_static.h b/src/core/file_sys/vfs/vfs_static.h
index ca3f989ef..bb53560ac 100644
--- a/src/core/file_sys/vfs_static.h
+++ b/src/core/file_sys/vfs/vfs_static.h
@@ -7,7 +7,7 @@
7#include <memory> 7#include <memory>
8#include <string_view> 8#include <string_view>
9 9
10#include "core/file_sys/vfs.h" 10#include "core/file_sys/vfs/vfs.h"
11 11
12namespace FileSys { 12namespace FileSys {
13 13
diff --git a/src/core/file_sys/vfs_types.h b/src/core/file_sys/vfs/vfs_types.h
index 4a583ed64..4a583ed64 100644
--- a/src/core/file_sys/vfs_types.h
+++ b/src/core/file_sys/vfs/vfs_types.h
diff --git a/src/core/file_sys/vfs_vector.cpp b/src/core/file_sys/vfs/vfs_vector.cpp
index 251d9d7c9..0d54461c8 100644
--- a/src/core/file_sys/vfs_vector.cpp
+++ b/src/core/file_sys/vfs/vfs_vector.cpp
@@ -3,7 +3,7 @@
3 3
4#include <algorithm> 4#include <algorithm>
5#include <utility> 5#include <utility>
6#include "core/file_sys/vfs_vector.h" 6#include "core/file_sys/vfs/vfs_vector.h"
7 7
8namespace FileSys { 8namespace FileSys {
9VectorVfsFile::VectorVfsFile(std::vector<u8> initial_data, std::string name_, VirtualDir parent_) 9VectorVfsFile::VectorVfsFile(std::vector<u8> initial_data, std::string name_, VirtualDir parent_)
diff --git a/src/core/file_sys/vfs_vector.h b/src/core/file_sys/vfs/vfs_vector.h
index bfedb6e42..587187dd2 100644
--- a/src/core/file_sys/vfs_vector.h
+++ b/src/core/file_sys/vfs/vfs_vector.h
@@ -8,7 +8,7 @@
8#include <memory> 8#include <memory>
9#include <string> 9#include <string>
10#include <vector> 10#include <vector>
11#include "core/file_sys/vfs.h" 11#include "core/file_sys/vfs/vfs.h"
12 12
13namespace FileSys { 13namespace FileSys {
14 14
diff --git a/src/core/file_sys/xts_archive.cpp b/src/core/file_sys/xts_archive.cpp
index ede0aa11a..6692211e1 100644
--- a/src/core/file_sys/xts_archive.cpp
+++ b/src/core/file_sys/xts_archive.cpp
@@ -17,7 +17,7 @@
17#include "core/crypto/key_manager.h" 17#include "core/crypto/key_manager.h"
18#include "core/crypto/xts_encryption_layer.h" 18#include "core/crypto/xts_encryption_layer.h"
19#include "core/file_sys/content_archive.h" 19#include "core/file_sys/content_archive.h"
20#include "core/file_sys/vfs_offset.h" 20#include "core/file_sys/vfs/vfs_offset.h"
21#include "core/file_sys/xts_archive.h" 21#include "core/file_sys/xts_archive.h"
22#include "core/loader/loader.h" 22#include "core/loader/loader.h"
23 23
diff --git a/src/core/file_sys/xts_archive.h b/src/core/file_sys/xts_archive.h
index abbe5f716..7589b7c38 100644
--- a/src/core/file_sys/xts_archive.h
+++ b/src/core/file_sys/xts_archive.h
@@ -8,7 +8,7 @@
8#include "common/common_types.h" 8#include "common/common_types.h"
9#include "common/swap.h" 9#include "common/swap.h"
10#include "core/crypto/key_manager.h" 10#include "core/crypto/key_manager.h"
11#include "core/file_sys/vfs.h" 11#include "core/file_sys/vfs/vfs.h"
12 12
13namespace Loader { 13namespace Loader {
14enum class ResultStatus : u16; 14enum class ResultStatus : u16;