summaryrefslogtreecommitdiff
path: root/src/core/file_sys
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/file_sys')
-rw-r--r--src/core/file_sys/bis_factory.cpp3
-rw-r--r--src/core/file_sys/directory.h39
-rw-r--r--src/core/file_sys/fs_directory.h33
-rw-r--r--src/core/file_sys/fs_filesystem.h39
-rw-r--r--src/core/file_sys/mode.h23
-rw-r--r--src/core/file_sys/vfs/vfs.cpp27
-rw-r--r--src/core/file_sys/vfs/vfs.h11
-rw-r--r--src/core/file_sys/vfs/vfs_real.cpp51
-rw-r--r--src/core/file_sys/vfs/vfs_real.h25
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
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/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
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_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
6namespace FileSys {
7
8enum 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};
16DECLARE_ENUM_FLAG_OPERATORS(OpenMode)
17
18enum 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};
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/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/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
11namespace FileSys { 10namespace 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
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/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
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/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
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/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
14namespace Common::FS { 14namespace 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
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