diff options
Diffstat (limited to 'src/core/file_sys')
| -rw-r--r-- | src/core/file_sys/bis_factory.cpp | 3 | ||||
| -rw-r--r-- | src/core/file_sys/directory.h | 39 | ||||
| -rw-r--r-- | src/core/file_sys/fs_directory.h | 33 | ||||
| -rw-r--r-- | src/core/file_sys/fs_filesystem.h | 39 | ||||
| -rw-r--r-- | src/core/file_sys/mode.h | 23 | ||||
| -rw-r--r-- | src/core/file_sys/vfs/vfs.cpp | 27 | ||||
| -rw-r--r-- | src/core/file_sys/vfs/vfs.h | 11 | ||||
| -rw-r--r-- | src/core/file_sys/vfs/vfs_real.cpp | 51 | ||||
| -rw-r--r-- | src/core/file_sys/vfs/vfs_real.h | 25 |
9 files changed, 130 insertions, 121 deletions
diff --git a/src/core/file_sys/bis_factory.cpp b/src/core/file_sys/bis_factory.cpp index f275f5fe4..db667438e 100644 --- a/src/core/file_sys/bis_factory.cpp +++ b/src/core/file_sys/bis_factory.cpp | |||
| @@ -4,7 +4,6 @@ | |||
| 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/vfs.h" | 8 | #include "core/file_sys/vfs/vfs.h" |
| 10 | 9 | ||
| @@ -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/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 | |||
| 13 | namespace FileSys { | ||
| 14 | |||
| 15 | enum 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 | ||
| 22 | struct 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 | }; | ||
| 35 | static_assert(sizeof(Entry) == 0x310, "Directory Entry struct isn't exactly 0x310 bytes long!"); | ||
| 36 | static_assert(offsetof(Entry, type) == 0x304, "Wrong offset for type in Entry."); | ||
| 37 | static_assert(offsetof(Entry, file_size) == 0x308, "Wrong offset for file_size in Entry."); | ||
| 38 | |||
| 39 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/fs_directory.h b/src/core/file_sys/fs_directory.h new file mode 100644 index 000000000..cba6155f8 --- /dev/null +++ b/src/core/file_sys/fs_directory.h | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | #pragma once | ||
| 5 | |||
| 6 | namespace FileSys { | ||
| 7 | |||
| 8 | constexpr inline size_t EntryNameLengthMax = 0x300; | ||
| 9 | |||
| 10 | struct 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 | |||
| 24 | static_assert(sizeof(DirectoryEntry) == 0x310, | ||
| 25 | "Directory Entry struct isn't exactly 0x310 bytes long!"); | ||
| 26 | static_assert(offsetof(DirectoryEntry, type) == 0x304, "Wrong offset for type in Entry."); | ||
| 27 | static_assert(offsetof(DirectoryEntry, file_size) == 0x308, "Wrong offset for file_size in Entry."); | ||
| 28 | |||
| 29 | struct DirectoryHandle { | ||
| 30 | void* handle; | ||
| 31 | }; | ||
| 32 | |||
| 33 | } // 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..436d6c731 --- /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 | namespace FileSys { | ||
| 7 | |||
| 8 | enum class OpenMode : u32 { | ||
| 9 | Read = (1 << 0), | ||
| 10 | Write = (1 << 1), | ||
| 11 | AllowAppend = (1 << 2), | ||
| 12 | |||
| 13 | ReadWrite = (Read | Write), | ||
| 14 | All = (ReadWrite | AllowAppend), | ||
| 15 | }; | ||
| 16 | DECLARE_ENUM_FLAG_OPERATORS(OpenMode) | ||
| 17 | |||
| 18 | enum class OpenDirectoryMode : u64 { | ||
| 19 | Directory = (1 << 0), | ||
| 20 | File = (1 << 1), | ||
| 21 | |||
| 22 | All = (Directory | File), | ||
| 23 | |||
| 24 | /* TODO: Separate enum, like N? */ | ||
| 25 | _NotRequireFileSize = (1 << 31), | ||
| 26 | }; | ||
| 27 | DECLARE_ENUM_FLAG_OPERATORS(OpenDirectoryMode) | ||
| 28 | |||
| 29 | enum class DirectoryEntryType : u8 { | ||
| 30 | Directory = 0, | ||
| 31 | File = 1, | ||
| 32 | }; | ||
| 33 | |||
| 34 | enum class CreateOption : u8 { | ||
| 35 | None = (0 << 0), | ||
| 36 | BigFile = (1 << 0), | ||
| 37 | }; | ||
| 38 | |||
| 39 | } // namespace FileSys | ||
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 | |||
| 9 | namespace FileSys { | ||
| 10 | |||
| 11 | enum 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 | |||
| 21 | DECLARE_ENUM_FLAG_OPERATORS(Mode) | ||
| 22 | |||
| 23 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/vfs/vfs.cpp b/src/core/file_sys/vfs/vfs.cpp index b88a5f91d..a04292760 100644 --- a/src/core/file_sys/vfs/vfs.cpp +++ b/src/core/file_sys/vfs/vfs.cpp | |||
| @@ -5,7 +5,6 @@ | |||
| 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" | ||
| 9 | #include "core/file_sys/vfs/vfs.h" | 8 | #include "core/file_sys/vfs/vfs.h" |
| 10 | 9 | ||
| 11 | namespace FileSys { | 10 | namespace FileSys { |
| @@ -36,12 +35,12 @@ VfsEntryType VfsFilesystem::GetEntryType(std::string_view path_) const { | |||
| 36 | return VfsEntryType::None; | 35 | return VfsEntryType::None; |
| 37 | } | 36 | } |
| 38 | 37 | ||
| 39 | VirtualFile VfsFilesystem::OpenFile(std::string_view path_, Mode perms) { | 38 | VirtualFile 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 | ||
| 44 | VirtualFile VfsFilesystem::CreateFile(std::string_view path_, Mode perms) { | 43 | VirtualFile 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 | ||
| 88 | bool VfsFilesystem::DeleteFile(std::string_view path_) { | 87 | bool 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 | ||
| 96 | VirtualDir VfsFilesystem::OpenDirectory(std::string_view path_, Mode perms) { | 95 | VirtualDir 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 | ||
| 101 | VirtualDir VfsFilesystem::CreateDirectory(std::string_view path_, Mode perms) { | 100 | VirtualDir 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 | ||
| 150 | bool VfsFilesystem::DeleteDirectory(std::string_view path_) { | 149 | bool 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/vfs.h b/src/core/file_sys/vfs/vfs.h index 6830244e3..f846a9669 100644 --- a/src/core/file_sys/vfs/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/fs_filesystem.h" | ||
| 16 | #include "core/file_sys/vfs/vfs_types.h" | 17 | #include "core/file_sys/vfs/vfs_types.h" |
| 17 | 18 | ||
| 18 | namespace FileSys { | 19 | namespace FileSys { |
| 19 | 20 | ||
| 20 | enum 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 |
| 23 | enum class VfsEntryType { | 22 | enum 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/vfs_real.cpp b/src/core/file_sys/vfs/vfs_real.cpp index 1e6d8163b..627d5d251 100644 --- a/src/core/file_sys/vfs/vfs_real.cpp +++ b/src/core/file_sys/vfs/vfs_real.cpp | |||
| @@ -28,16 +28,14 @@ namespace { | |||
| 28 | 28 | ||
| 29 | constexpr size_t MaxOpenFiles = 512; | 29 | constexpr size_t MaxOpenFiles = 512; |
| 30 | 30 | ||
| 31 | constexpr FS::FileAccessMode ModeFlagsToFileAccessMode(Mode mode) { | 31 | constexpr 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 | ||
| 76 | VirtualFile RealVfsFilesystem::OpenFileFromEntry(std::string_view path_, std::optional<u64> size, | 74 | VirtualFile 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 | ||
| 101 | VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, Mode perms) { | 99 | VirtualFile RealVfsFilesystem::OpenFile(std::string_view path_, OpenMode perms) { |
| 102 | return OpenFileFromEntry(path_, {}, perms); | 100 | return OpenFileFromEntry(path_, {}, perms); |
| 103 | } | 101 | } |
| 104 | 102 | ||
| 105 | VirtualFile RealVfsFilesystem::CreateFile(std::string_view path_, Mode perms) { | 103 | VirtualFile 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 | ||
| 151 | bool RealVfsFilesystem::DeleteFile(std::string_view path_) { | 149 | bool 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 | ||
| 160 | VirtualDir RealVfsFilesystem::OpenDirectory(std::string_view path_, Mode perms) { | 158 | VirtualDir 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 | ||
| 165 | VirtualDir RealVfsFilesystem::CreateDirectory(std::string_view path_, Mode perms) { | 163 | VirtualDir 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 | ||
| 190 | bool RealVfsFilesystem::DeleteDirectory(std::string_view path_) { | 188 | bool RealVfsFilesystem::DeleteDirectory(std::string_view path_) { |
| @@ -193,7 +191,7 @@ bool RealVfsFilesystem::DeleteDirectory(std::string_view path_) { | |||
| 193 | } | 191 | } |
| 194 | 192 | ||
| 195 | std::unique_lock<std::mutex> RealVfsFilesystem::RefreshReference(const std::string& path, | 193 | std::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 | ||
| 268 | RealVfsFile::RealVfsFile(RealVfsFilesystem& base_, std::unique_ptr<FileReference> reference_, | 266 | RealVfsFile::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 | ||
| 300 | bool RealVfsFile::IsWritable() const { | 298 | bool RealVfsFile::IsWritable() const { |
| 301 | return True(perms & Mode::Write); | 299 | return True(perms & OpenMode::Write); |
| 302 | } | 300 | } |
| 303 | 301 | ||
| 304 | bool RealVfsFile::IsReadable() const { | 302 | bool RealVfsFile::IsReadable() const { |
| 305 | return True(perms & Mode::Read); | 303 | return True(perms & OpenMode::Read); |
| 306 | } | 304 | } |
| 307 | 305 | ||
| 308 | std::size_t RealVfsFile::Read(u8* data, std::size_t length, std::size_t offset) const { | 306 | std::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 | ||
| 332 | template <> | 330 | template <> |
| 333 | std::vector<VirtualFile> RealVfsDirectory::IterateEntries<RealVfsFile, VfsFile>() const { | 331 | std::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 | ||
| 354 | template <> | 352 | template <> |
| 355 | std::vector<VirtualDir> RealVfsDirectory::IterateEntries<RealVfsDirectory, VfsDirectory>() const { | 353 | std::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 | ||
| 376 | RealVfsDirectory::RealVfsDirectory(RealVfsFilesystem& base_, const std::string& path_, Mode perms_) | 374 | RealVfsDirectory::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 | ||
| 458 | bool RealVfsDirectory::IsWritable() const { | 457 | bool RealVfsDirectory::IsWritable() const { |
| 459 | return True(perms & Mode::Write); | 458 | return True(perms & OpenMode::Write); |
| 460 | } | 459 | } |
| 461 | 460 | ||
| 462 | bool RealVfsDirectory::IsReadable() const { | 461 | bool RealVfsDirectory::IsReadable() const { |
| 463 | return True(perms & Mode::Read); | 462 | return True(perms & OpenMode::Read); |
| 464 | } | 463 | } |
| 465 | 464 | ||
| 466 | std::string RealVfsDirectory::GetName() const { | 465 | std::string RealVfsDirectory::GetName() const { |
| @@ -507,7 +506,7 @@ std::string RealVfsDirectory::GetFullPath() const { | |||
| 507 | } | 506 | } |
| 508 | 507 | ||
| 509 | std::map<std::string, VfsEntryType, std::less<>> RealVfsDirectory::GetEntries() const { | 508 | std::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/vfs_real.h b/src/core/file_sys/vfs/vfs_real.h index 1560bc1f9..5c2172cce 100644 --- a/src/core/file_sys/vfs/vfs_real.h +++ b/src/core/file_sys/vfs/vfs_real.h | |||
| @@ -8,7 +8,7 @@ | |||
| 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/vfs.h" | 12 | #include "core/file_sys/vfs/vfs.h" |
| 13 | 13 | ||
| 14 | namespace Common::FS { | 14 | namespace Common::FS { |
| @@ -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 | ||
| 55 | private: | 56 | private: |
| 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 | ||
| 61 | private: | 62 | private: |
| 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 | ||
| 66 | private: | 67 | private: |
| 67 | void EvictSingleReferenceLocked(); | 68 | void EvictSingleReferenceLocked(); |
| @@ -89,7 +90,8 @@ public: | |||
| 89 | 90 | ||
| 90 | private: | 91 | private: |
| 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 | ||
| 132 | private: | 134 | private: |
| 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 |