summaryrefslogtreecommitdiff
path: root/src/core/file_sys
diff options
context:
space:
mode:
authorGravatar Emmanuel Gil Peyrot2016-09-18 09:38:01 +0900
committerGravatar Emmanuel Gil Peyrot2016-09-18 09:38:01 +0900
commitdc8479928c5aee4c6ad6fe4f59006fb604cee701 (patch)
tree569a7f13128450bbab973236615587ff00bced5f /src/core/file_sys
parentTravis: Import Dolphin’s clang-format hook. (diff)
downloadyuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.tar.gz
yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.tar.xz
yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.zip
Sources: Run clang-format on everything.
Diffstat (limited to 'src/core/file_sys')
-rw-r--r--src/core/file_sys/archive_backend.cpp33
-rw-r--r--src/core/file_sys/archive_backend.h37
-rw-r--r--src/core/file_sys/archive_extsavedata.cpp21
-rw-r--r--src/core/file_sys/archive_extsavedata.h14
-rw-r--r--src/core/file_sys/archive_romfs.cpp7
-rw-r--r--src/core/file_sys/archive_romfs.h4
-rw-r--r--src/core/file_sys/archive_savedata.cpp33
-rw-r--r--src/core/file_sys/archive_savedata.h4
-rw-r--r--src/core/file_sys/archive_savedatacheck.cpp15
-rw-r--r--src/core/file_sys/archive_savedatacheck.h4
-rw-r--r--src/core/file_sys/archive_sdmc.cpp6
-rw-r--r--src/core/file_sys/archive_sdmc.h4
-rw-r--r--src/core/file_sys/archive_systemsavedata.cpp9
-rw-r--r--src/core/file_sys/archive_systemsavedata.h7
-rw-r--r--src/core/file_sys/directory_backend.h21
-rw-r--r--src/core/file_sys/disk_archive.cpp49
-rw-r--r--src/core/file_sys/disk_archive.h10
-rw-r--r--src/core/file_sys/file_backend.h9
-rw-r--r--src/core/file_sys/ivfc_archive.cpp34
-rw-r--r--src/core/file_sys/ivfc_archive.h32
20 files changed, 217 insertions, 136 deletions
diff --git a/src/core/file_sys/archive_backend.cpp b/src/core/file_sys/archive_backend.cpp
index cc0aa7022..6ea920ec1 100644
--- a/src/core/file_sys/archive_backend.cpp
+++ b/src/core/file_sys/archive_backend.cpp
@@ -12,27 +12,23 @@
12#include "core/file_sys/archive_backend.h" 12#include "core/file_sys/archive_backend.h"
13#include "core/memory.h" 13#include "core/memory.h"
14 14
15
16namespace FileSys { 15namespace FileSys {
17 16
18Path::Path(LowPathType type, u32 size, u32 pointer) : type(type) { 17Path::Path(LowPathType type, u32 size, u32 pointer) : type(type) {
19 switch (type) { 18 switch (type) {
20 case Binary: 19 case Binary: {
21 {
22 binary.resize(size); 20 binary.resize(size);
23 Memory::ReadBlock(pointer, binary.data(), binary.size()); 21 Memory::ReadBlock(pointer, binary.data(), binary.size());
24 break; 22 break;
25 } 23 }
26 24
27 case Char: 25 case Char: {
28 {
29 string.resize(size - 1); // Data is always null-terminated. 26 string.resize(size - 1); // Data is always null-terminated.
30 Memory::ReadBlock(pointer, &string[0], string.size()); 27 Memory::ReadBlock(pointer, &string[0], string.size());
31 break; 28 break;
32 } 29 }
33 30
34 case Wchar: 31 case Wchar: {
35 {
36 u16str.resize(size / 2 - 1); // Data is always null-terminated. 32 u16str.resize(size / 2 - 1); // Data is always null-terminated.
37 Memory::ReadBlock(pointer, &u16str[0], u16str.size() * sizeof(char16_t)); 33 Memory::ReadBlock(pointer, &u16str[0], u16str.size() * sizeof(char16_t));
38 break; 34 break;
@@ -50,8 +46,7 @@ std::string Path::DebugStr() const {
50 return "[Invalid]"; 46 return "[Invalid]";
51 case Empty: 47 case Empty:
52 return "[Empty]"; 48 return "[Empty]";
53 case Binary: 49 case Binary: {
54 {
55 std::stringstream res; 50 std::stringstream res;
56 res << "[Binary: "; 51 res << "[Binary: ";
57 for (unsigned byte : binary) 52 for (unsigned byte : binary)
@@ -73,13 +68,13 @@ std::string Path::AsString() const {
73 case Wchar: 68 case Wchar:
74 return Common::UTF16ToUTF8(u16str); 69 return Common::UTF16ToUTF8(u16str);
75 case Empty: 70 case Empty:
76 return{}; 71 return {};
77 case Invalid: 72 case Invalid:
78 case Binary: 73 case Binary:
79 default: 74 default:
80 // TODO(yuriks): Add assert 75 // TODO(yuriks): Add assert
81 LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!"); 76 LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!");
82 return{}; 77 return {};
83 } 78 }
84} 79}
85 80
@@ -90,12 +85,12 @@ std::u16string Path::AsU16Str() const {
90 case Wchar: 85 case Wchar:
91 return u16str; 86 return u16str;
92 case Empty: 87 case Empty:
93 return{}; 88 return {};
94 case Invalid: 89 case Invalid:
95 case Binary: 90 case Binary:
96 // TODO(yuriks): Add assert 91 // TODO(yuriks): Add assert
97 LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!"); 92 LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!");
98 return{}; 93 return {};
99 } 94 }
100} 95}
101 96
@@ -105,25 +100,23 @@ std::vector<u8> Path::AsBinary() const {
105 return binary; 100 return binary;
106 case Char: 101 case Char:
107 return std::vector<u8>(string.begin(), string.end()); 102 return std::vector<u8>(string.begin(), string.end());
108 case Wchar: 103 case Wchar: {
109 {
110 // use two u8 for each character of u16str 104 // use two u8 for each character of u16str
111 std::vector<u8> to_return(u16str.size() * 2); 105 std::vector<u8> to_return(u16str.size() * 2);
112 for (size_t i = 0; i < u16str.size(); ++i) { 106 for (size_t i = 0; i < u16str.size(); ++i) {
113 u16 tmp_char = u16str.at(i); 107 u16 tmp_char = u16str.at(i);
114 to_return[i*2] = (tmp_char & 0xFF00) >> 8; 108 to_return[i * 2] = (tmp_char & 0xFF00) >> 8;
115 to_return[i*2 + 1] = (tmp_char & 0x00FF); 109 to_return[i * 2 + 1] = (tmp_char & 0x00FF);
116 } 110 }
117 return to_return; 111 return to_return;
118 } 112 }
119 case Empty: 113 case Empty:
120 return{}; 114 return {};
121 case Invalid: 115 case Invalid:
122 default: 116 default:
123 // TODO(yuriks): Add assert 117 // TODO(yuriks): Add assert
124 LOG_ERROR(Service_FS, "LowPathType cannot be converted to binary!"); 118 LOG_ERROR(Service_FS, "LowPathType cannot be converted to binary!");
125 return{}; 119 return {};
126 } 120 }
127} 121}
128
129} 122}
diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h
index 5d91e47f3..79fde9710 100644
--- a/src/core/file_sys/archive_backend.h
+++ b/src/core/file_sys/archive_backend.h
@@ -15,20 +15,13 @@
15 15
16#include "core/hle/result.h" 16#include "core/hle/result.h"
17 17
18
19namespace FileSys { 18namespace FileSys {
20 19
21class FileBackend; 20class FileBackend;
22class DirectoryBackend; 21class DirectoryBackend;
23 22
24// Path string type 23// Path string type
25enum LowPathType : u32 { 24enum LowPathType : u32 { Invalid = 0, Empty = 1, Binary = 2, Char = 3, Wchar = 4 };
26 Invalid = 0,
27 Empty = 1,
28 Binary = 2,
29 Char = 3,
30 Wchar = 4
31};
32 25
33union Mode { 26union Mode {
34 u32 hex; 27 u32 hex;
@@ -39,12 +32,17 @@ union Mode {
39 32
40class Path { 33class Path {
41public: 34public:
42 Path() : type(Invalid) {} 35 Path() : type(Invalid) {
43 Path(const char* path) : type(Char), string(path) {} 36 }
44 Path(std::vector<u8> binary_data) : type(Binary), binary(std::move(binary_data)) {} 37 Path(const char* path) : type(Char), string(path) {
38 }
39 Path(std::vector<u8> binary_data) : type(Binary), binary(std::move(binary_data)) {
40 }
45 Path(LowPathType type, u32 size, u32 pointer); 41 Path(LowPathType type, u32 size, u32 pointer);
46 42
47 LowPathType GetType() const { return type; } 43 LowPathType GetType() const {
44 return type;
45 }
48 46
49 /** 47 /**
50 * Gets the string representation of the path for debugging 48 * Gets the string representation of the path for debugging
@@ -64,10 +62,14 @@ private:
64}; 62};
65 63
66struct ArchiveFormatInfo { 64struct ArchiveFormatInfo {
67 u32_le total_size; ///< The pre-defined size of the archive, as specified in the Create or Format call 65 u32_le total_size; ///< The pre-defined size of the archive, as specified in the Create or
68 u32_le number_directories; ///< The pre-defined number of directories in the archive, as specified in the Create or Format call 66 /// Format call
69 u32_le number_files; ///< The pre-defined number of files in the archive, as specified in the Create or Format call 67 u32_le number_directories; ///< The pre-defined number of directories in the archive, as
70 u8 duplicate_data; ///< Whether the archive should duplicate the data, as specified in the Create or Format call 68 /// specified in the Create or Format call
69 u32_le number_files; ///< The pre-defined number of files in the archive, as specified in the
70 /// Create or Format call
71 u8 duplicate_data; ///< Whether the archive should duplicate the data, as specified in the
72 /// Create or Format call
71}; 73};
72static_assert(std::is_pod<ArchiveFormatInfo>::value, "ArchiveFormatInfo is not POD"); 74static_assert(std::is_pod<ArchiveFormatInfo>::value, "ArchiveFormatInfo is not POD");
73 75
@@ -87,7 +89,8 @@ public:
87 * @param mode Mode to open the file with 89 * @param mode Mode to open the file with
88 * @return Opened file, or error code 90 * @return Opened file, or error code
89 */ 91 */
90 virtual ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, const Mode mode) const = 0; 92 virtual ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
93 const Mode mode) const = 0;
91 94
92 /** 95 /**
93 * Delete a file specified by its path 96 * Delete a file specified by its path
diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp
index 1d9eaefcb..6b4af28bf 100644
--- a/src/core/file_sys/archive_extsavedata.cpp
+++ b/src/core/file_sys/archive_extsavedata.cpp
@@ -30,10 +30,11 @@ std::string GetExtSaveDataPath(const std::string& mount_point, const Path& path)
30 30
31std::string GetExtDataContainerPath(const std::string& mount_point, bool shared) { 31std::string GetExtDataContainerPath(const std::string& mount_point, bool shared) {
32 if (shared) 32 if (shared)
33 return Common::StringFromFormat("%sdata/%s/extdata/", mount_point.c_str(), SYSTEM_ID.c_str()); 33 return Common::StringFromFormat("%sdata/%s/extdata/", mount_point.c_str(),
34 SYSTEM_ID.c_str());
34 35
35 return Common::StringFromFormat("%sNintendo 3DS/%s/%s/extdata/", mount_point.c_str(), 36 return Common::StringFromFormat("%sNintendo 3DS/%s/%s/extdata/", mount_point.c_str(),
36 SYSTEM_ID.c_str(), SDCARD_ID.c_str()); 37 SYSTEM_ID.c_str(), SDCARD_ID.c_str());
37} 38}
38 39
39Path ConstructExtDataBinaryPath(u32 media_type, u32 high, u32 low) { 40Path ConstructExtDataBinaryPath(u32 media_type, u32 high, u32 low) {
@@ -54,11 +55,12 @@ Path ConstructExtDataBinaryPath(u32 media_type, u32 high, u32 low) {
54 for (unsigned i = 0; i < 4; ++i) 55 for (unsigned i = 0; i < 4; ++i)
55 binary_path.push_back((high >> (8 * i)) & 0xFF); 56 binary_path.push_back((high >> (8 * i)) & 0xFF);
56 57
57 return { binary_path }; 58 return {binary_path};
58} 59}
59 60
60ArchiveFactory_ExtSaveData::ArchiveFactory_ExtSaveData(const std::string& mount_location, bool shared) 61ArchiveFactory_ExtSaveData::ArchiveFactory_ExtSaveData(const std::string& mount_location,
61 : shared(shared), mount_point(GetExtDataContainerPath(mount_location, shared)) { 62 bool shared)
63 : shared(shared), mount_point(GetExtDataContainerPath(mount_location, shared)) {
62 LOG_INFO(Service_FS, "Directory %s set as base for ExtSaveData.", mount_point.c_str()); 64 LOG_INFO(Service_FS, "Directory %s set as base for ExtSaveData.", mount_point.c_str());
63} 65}
64 66
@@ -88,7 +90,8 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_ExtSaveData::Open(cons
88 return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); 90 return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
89} 91}
90 92
91ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { 93ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path,
94 const FileSys::ArchiveFormatInfo& format_info) {
92 // These folders are always created with the ExtSaveData 95 // These folders are always created with the ExtSaveData
93 std::string user_path = GetExtSaveDataPath(mount_point, path) + "user/"; 96 std::string user_path = GetExtSaveDataPath(mount_point, path) + "user/";
94 std::string boss_path = GetExtSaveDataPath(mount_point, path) + "boss/"; 97 std::string boss_path = GetExtSaveDataPath(mount_point, path) + "boss/";
@@ -115,7 +118,8 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_ExtSaveData::GetFormatInfo(const Pat
115 if (!file.IsOpen()) { 118 if (!file.IsOpen()) {
116 LOG_ERROR(Service_FS, "Could not open metadata information for archive"); 119 LOG_ERROR(Service_FS, "Could not open metadata information for archive");
117 // TODO(Subv): Verify error code 120 // TODO(Subv): Verify error code
118 return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, ErrorSummary::InvalidState, ErrorLevel::Status); 121 return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
122 ErrorSummary::InvalidState, ErrorLevel::Status);
119 } 123 }
120 124
121 ArchiveFormatInfo info = {}; 125 ArchiveFormatInfo info = {};
@@ -123,7 +127,8 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_ExtSaveData::GetFormatInfo(const Pat
123 return MakeResult<ArchiveFormatInfo>(info); 127 return MakeResult<ArchiveFormatInfo>(info);
124} 128}
125 129
126void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, const u8* icon_data, size_t icon_size) { 130void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, const u8* icon_data,
131 size_t icon_size) {
127 std::string game_path = FileSys::GetExtSaveDataPath(GetMountPoint(), path); 132 std::string game_path = FileSys::GetExtSaveDataPath(GetMountPoint(), path);
128 FileUtil::IOFile icon_file(game_path + "icon", "wb"); 133 FileUtil::IOFile icon_file(game_path + "icon", "wb");
129 icon_file.WriteBytes(icon_data, icon_size); 134 icon_file.WriteBytes(icon_data, icon_size);
diff --git a/src/core/file_sys/archive_extsavedata.h b/src/core/file_sys/archive_extsavedata.h
index e9a72850d..2b942817e 100644
--- a/src/core/file_sys/archive_extsavedata.h
+++ b/src/core/file_sys/archive_extsavedata.h
@@ -28,13 +28,17 @@ public:
28 */ 28 */
29 bool Initialize(); 29 bool Initialize();
30 30
31 std::string GetName() const override { return "ExtSaveData"; } 31 std::string GetName() const override {
32 return "ExtSaveData";
33 }
32 34
33 ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; 35 ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override;
34 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; 36 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override;
35 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; 37 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override;
36 38
37 const std::string& GetMountPoint() const { return mount_point; } 39 const std::string& GetMountPoint() const {
40 return mount_point;
41 }
38 42
39 /** 43 /**
40 * Writes the SMDH icon of the ExtSaveData to file 44 * Writes the SMDH icon of the ExtSaveData to file
@@ -45,7 +49,8 @@ public:
45 void WriteIcon(const Path& path, const u8* icon_data, size_t icon_size); 49 void WriteIcon(const Path& path, const u8* icon_data, size_t icon_size);
46 50
47private: 51private:
48 bool shared; ///< Whether this archive represents an ExtSaveData archive or a SharedExtSaveData archive 52 bool shared; ///< Whether this archive represents an ExtSaveData archive or a SharedExtSaveData
53 /// archive
49 54
50 /** 55 /**
51 * This holds the full directory path for this archive, it is only set after a successful call 56 * This holds the full directory path for this archive, it is only set after a successful call
@@ -65,7 +70,8 @@ private:
65std::string GetExtSaveDataPath(const std::string& mount_point, const Path& path); 70std::string GetExtSaveDataPath(const std::string& mount_point, const Path& path);
66 71
67/** 72/**
68 * Constructs a path to the base folder to hold concrete ExtSaveData archives in the host file system. 73 * Constructs a path to the base folder to hold concrete ExtSaveData archives in the host file
74 * system.
69 * @param mount_point The base folder where this folder resides, ie. SDMC or NAND. 75 * @param mount_point The base folder where this folder resides, ie. SDMC or NAND.
70 * @param shared Whether this ExtSaveData container is for SharedExtSaveDatas or not. 76 * @param shared Whether this ExtSaveData container is for SharedExtSaveDatas or not.
71 * @returns The path to the base ExtSaveData archives' folder in the host file system 77 * @returns The path to the base ExtSaveData archives' folder in the host file system
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
index 38828b546..87455eb95 100644
--- a/src/core/file_sys/archive_romfs.cpp
+++ b/src/core/file_sys/archive_romfs.cpp
@@ -28,11 +28,12 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_RomFS::Open(const Path
28 return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); 28 return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
29} 29}
30 30
31ResultCode ArchiveFactory_RomFS::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { 31ResultCode ArchiveFactory_RomFS::Format(const Path& path,
32 const FileSys::ArchiveFormatInfo& format_info) {
32 LOG_ERROR(Service_FS, "Attempted to format a RomFS archive."); 33 LOG_ERROR(Service_FS, "Attempted to format a RomFS archive.");
33 // TODO: Verify error code 34 // TODO: Verify error code
34 return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, 35 return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported,
35 ErrorSummary::NotSupported, ErrorLevel::Permanent); 36 ErrorLevel::Permanent);
36} 37}
37 38
38ResultVal<ArchiveFormatInfo> ArchiveFactory_RomFS::GetFormatInfo(const Path& path) const { 39ResultVal<ArchiveFormatInfo> ArchiveFactory_RomFS::GetFormatInfo(const Path& path) const {
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h
index c5a329122..3c68a6b1c 100644
--- a/src/core/file_sys/archive_romfs.h
+++ b/src/core/file_sys/archive_romfs.h
@@ -24,7 +24,9 @@ class ArchiveFactory_RomFS final : public ArchiveFactory {
24public: 24public:
25 ArchiveFactory_RomFS(Loader::AppLoader& app_loader); 25 ArchiveFactory_RomFS(Loader::AppLoader& app_loader);
26 26
27 std::string GetName() const override { return "RomFS"; } 27 std::string GetName() const override {
28 return "RomFS";
29 }
28 ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; 30 ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override;
29 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; 31 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override;
30 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; 32 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override;
diff --git a/src/core/file_sys/archive_savedata.cpp b/src/core/file_sys/archive_savedata.cpp
index fd5711e14..9a264091f 100644
--- a/src/core/file_sys/archive_savedata.cpp
+++ b/src/core/file_sys/archive_savedata.cpp
@@ -22,48 +22,55 @@ namespace FileSys {
22 22
23static std::string GetSaveDataContainerPath(const std::string& sdmc_directory) { 23static std::string GetSaveDataContainerPath(const std::string& sdmc_directory) {
24 return Common::StringFromFormat("%sNintendo 3DS/%s/%s/title/", sdmc_directory.c_str(), 24 return Common::StringFromFormat("%sNintendo 3DS/%s/%s/title/", sdmc_directory.c_str(),
25 SYSTEM_ID.c_str(), SDCARD_ID.c_str()); 25 SYSTEM_ID.c_str(), SDCARD_ID.c_str());
26} 26}
27 27
28static std::string GetSaveDataPath(const std::string& mount_location, u64 program_id) { 28static std::string GetSaveDataPath(const std::string& mount_location, u64 program_id) {
29 u32 high = (u32)(program_id >> 32); 29 u32 high = (u32)(program_id >> 32);
30 u32 low = (u32)(program_id & 0xFFFFFFFF); 30 u32 low = (u32)(program_id & 0xFFFFFFFF);
31 return Common::StringFromFormat("%s%08x/%08x/data/00000001/", mount_location.c_str(), high, low); 31 return Common::StringFromFormat("%s%08x/%08x/data/00000001/", mount_location.c_str(), high,
32 low);
32} 33}
33 34
34static std::string GetSaveDataMetadataPath(const std::string& mount_location, u64 program_id) { 35static std::string GetSaveDataMetadataPath(const std::string& mount_location, u64 program_id) {
35 u32 high = (u32)(program_id >> 32); 36 u32 high = (u32)(program_id >> 32);
36 u32 low = (u32)(program_id & 0xFFFFFFFF); 37 u32 low = (u32)(program_id & 0xFFFFFFFF);
37 return Common::StringFromFormat("%s%08x/%08x/data/00000001.metadata", mount_location.c_str(), high, low); 38 return Common::StringFromFormat("%s%08x/%08x/data/00000001.metadata", mount_location.c_str(),
39 high, low);
38} 40}
39 41
40ArchiveFactory_SaveData::ArchiveFactory_SaveData(const std::string& sdmc_directory) 42ArchiveFactory_SaveData::ArchiveFactory_SaveData(const std::string& sdmc_directory)
41 : mount_point(GetSaveDataContainerPath(sdmc_directory)) { 43 : mount_point(GetSaveDataContainerPath(sdmc_directory)) {
42 LOG_INFO(Service_FS, "Directory %s set as SaveData.", this->mount_point.c_str()); 44 LOG_INFO(Service_FS, "Directory %s set as SaveData.", this->mount_point.c_str());
43} 45}
44 46
45ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveData::Open(const Path& path) { 47ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveData::Open(const Path& path) {
46 std::string concrete_mount_point = GetSaveDataPath(mount_point, Kernel::g_current_process->codeset->program_id); 48 std::string concrete_mount_point =
49 GetSaveDataPath(mount_point, Kernel::g_current_process->codeset->program_id);
47 if (!FileUtil::Exists(concrete_mount_point)) { 50 if (!FileUtil::Exists(concrete_mount_point)) {
48 // When a SaveData archive is created for the first time, it is not yet formatted 51 // When a SaveData archive is created for the first time, it is not yet formatted
49 // and the save file/directory structure expected by the game has not yet been initialized. 52 // and the save file/directory structure expected by the game has not yet been initialized.
50 // Returning the NotFormatted error code will signal the game to provision the SaveData archive 53 // Returning the NotFormatted error code will signal the game to provision the SaveData
54 // archive
51 // with the files and folders that it expects. 55 // with the files and folders that it expects.
52 return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, 56 return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
53 ErrorSummary::InvalidState, ErrorLevel::Status); 57 ErrorSummary::InvalidState, ErrorLevel::Status);
54 } 58 }
55 59
56 auto archive = std::make_unique<DiskArchive>(std::move(concrete_mount_point)); 60 auto archive = std::make_unique<DiskArchive>(std::move(concrete_mount_point));
57 return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); 61 return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
58} 62}
59 63
60ResultCode ArchiveFactory_SaveData::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { 64ResultCode ArchiveFactory_SaveData::Format(const Path& path,
61 std::string concrete_mount_point = GetSaveDataPath(mount_point, Kernel::g_current_process->codeset->program_id); 65 const FileSys::ArchiveFormatInfo& format_info) {
66 std::string concrete_mount_point =
67 GetSaveDataPath(mount_point, Kernel::g_current_process->codeset->program_id);
62 FileUtil::DeleteDirRecursively(concrete_mount_point); 68 FileUtil::DeleteDirRecursively(concrete_mount_point);
63 FileUtil::CreateFullPath(concrete_mount_point); 69 FileUtil::CreateFullPath(concrete_mount_point);
64 70
65 // Write the format metadata 71 // Write the format metadata
66 std::string metadata_path = GetSaveDataMetadataPath(mount_point, Kernel::g_current_process->codeset->program_id); 72 std::string metadata_path =
73 GetSaveDataMetadataPath(mount_point, Kernel::g_current_process->codeset->program_id);
67 FileUtil::IOFile file(metadata_path, "wb"); 74 FileUtil::IOFile file(metadata_path, "wb");
68 75
69 if (file.IsOpen()) { 76 if (file.IsOpen()) {
@@ -74,13 +81,15 @@ ResultCode ArchiveFactory_SaveData::Format(const Path& path, const FileSys::Arch
74} 81}
75 82
76ResultVal<ArchiveFormatInfo> ArchiveFactory_SaveData::GetFormatInfo(const Path& path) const { 83ResultVal<ArchiveFormatInfo> ArchiveFactory_SaveData::GetFormatInfo(const Path& path) const {
77 std::string metadata_path = GetSaveDataMetadataPath(mount_point, Kernel::g_current_process->codeset->program_id); 84 std::string metadata_path =
85 GetSaveDataMetadataPath(mount_point, Kernel::g_current_process->codeset->program_id);
78 FileUtil::IOFile file(metadata_path, "rb"); 86 FileUtil::IOFile file(metadata_path, "rb");
79 87
80 if (!file.IsOpen()) { 88 if (!file.IsOpen()) {
81 LOG_ERROR(Service_FS, "Could not open metadata information for archive"); 89 LOG_ERROR(Service_FS, "Could not open metadata information for archive");
82 // TODO(Subv): Verify error code 90 // TODO(Subv): Verify error code
83 return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, ErrorSummary::InvalidState, ErrorLevel::Status); 91 return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
92 ErrorSummary::InvalidState, ErrorLevel::Status);
84 } 93 }
85 94
86 ArchiveFormatInfo info = {}; 95 ArchiveFormatInfo info = {};
diff --git a/src/core/file_sys/archive_savedata.h b/src/core/file_sys/archive_savedata.h
index 7a5a24089..4ac324985 100644
--- a/src/core/file_sys/archive_savedata.h
+++ b/src/core/file_sys/archive_savedata.h
@@ -20,7 +20,9 @@ class ArchiveFactory_SaveData final : public ArchiveFactory {
20public: 20public:
21 ArchiveFactory_SaveData(const std::string& mount_point); 21 ArchiveFactory_SaveData(const std::string& mount_point);
22 22
23 std::string GetName() const override { return "SaveData"; } 23 std::string GetName() const override {
24 return "SaveData";
25 }
24 26
25 ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; 27 ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override;
26 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; 28 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override;
diff --git a/src/core/file_sys/archive_savedatacheck.cpp b/src/core/file_sys/archive_savedatacheck.cpp
index 9f65e5455..fd9b84302 100644
--- a/src/core/file_sys/archive_savedatacheck.cpp
+++ b/src/core/file_sys/archive_savedatacheck.cpp
@@ -25,12 +25,12 @@ static std::string GetSaveDataCheckContainerPath(const std::string& nand_directo
25} 25}
26 26
27static std::string GetSaveDataCheckPath(const std::string& mount_point, u32 high, u32 low) { 27static std::string GetSaveDataCheckPath(const std::string& mount_point, u32 high, u32 low) {
28 return Common::StringFromFormat("%s%08x/%08x/content/00000000.app.romfs", 28 return Common::StringFromFormat("%s%08x/%08x/content/00000000.app.romfs", mount_point.c_str(),
29 mount_point.c_str(), high, low); 29 high, low);
30} 30}
31 31
32ArchiveFactory_SaveDataCheck::ArchiveFactory_SaveDataCheck(const std::string& nand_directory) : 32ArchiveFactory_SaveDataCheck::ArchiveFactory_SaveDataCheck(const std::string& nand_directory)
33 mount_point(GetSaveDataCheckContainerPath(nand_directory)) { 33 : mount_point(GetSaveDataCheckContainerPath(nand_directory)) {
34} 34}
35 35
36ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveDataCheck::Open(const Path& path) { 36ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveDataCheck::Open(const Path& path) {
@@ -48,11 +48,12 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveDataCheck::Open(co
48 return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); 48 return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
49} 49}
50 50
51ResultCode ArchiveFactory_SaveDataCheck::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { 51ResultCode ArchiveFactory_SaveDataCheck::Format(const Path& path,
52 const FileSys::ArchiveFormatInfo& format_info) {
52 LOG_ERROR(Service_FS, "Attempted to format a SaveDataCheck archive."); 53 LOG_ERROR(Service_FS, "Attempted to format a SaveDataCheck archive.");
53 // TODO: Verify error code 54 // TODO: Verify error code
54 return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, 55 return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported,
55 ErrorSummary::NotSupported, ErrorLevel::Permanent); 56 ErrorLevel::Permanent);
56} 57}
57 58
58ResultVal<ArchiveFormatInfo> ArchiveFactory_SaveDataCheck::GetFormatInfo(const Path& path) const { 59ResultVal<ArchiveFormatInfo> ArchiveFactory_SaveDataCheck::GetFormatInfo(const Path& path) const {
diff --git a/src/core/file_sys/archive_savedatacheck.h b/src/core/file_sys/archive_savedatacheck.h
index ea2624d64..4a4259260 100644
--- a/src/core/file_sys/archive_savedatacheck.h
+++ b/src/core/file_sys/archive_savedatacheck.h
@@ -20,7 +20,9 @@ class ArchiveFactory_SaveDataCheck final : public ArchiveFactory {
20public: 20public:
21 ArchiveFactory_SaveDataCheck(const std::string& mount_point); 21 ArchiveFactory_SaveDataCheck(const std::string& mount_point);
22 22
23 std::string GetName() const override { return "SaveDataCheck"; } 23 std::string GetName() const override {
24 return "SaveDataCheck";
25 }
24 26
25 ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; 27 ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override;
26 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; 28 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override;
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp
index 9b218af58..c1a28df6c 100644
--- a/src/core/file_sys/archive_sdmc.cpp
+++ b/src/core/file_sys/archive_sdmc.cpp
@@ -17,7 +17,8 @@
17 17
18namespace FileSys { 18namespace FileSys {
19 19
20ArchiveFactory_SDMC::ArchiveFactory_SDMC(const std::string& sdmc_directory) : sdmc_directory(sdmc_directory) { 20ArchiveFactory_SDMC::ArchiveFactory_SDMC(const std::string& sdmc_directory)
21 : sdmc_directory(sdmc_directory) {
21 LOG_INFO(Service_FS, "Directory %s set as SDMC.", sdmc_directory.c_str()); 22 LOG_INFO(Service_FS, "Directory %s set as SDMC.", sdmc_directory.c_str());
22} 23}
23 24
@@ -40,7 +41,8 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SDMC::Open(const Path&
40 return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); 41 return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
41} 42}
42 43
43ResultCode ArchiveFactory_SDMC::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { 44ResultCode ArchiveFactory_SDMC::Format(const Path& path,
45 const FileSys::ArchiveFormatInfo& format_info) {
44 // This is kind of an undesirable operation, so let's just ignore it. :) 46 // This is kind of an undesirable operation, so let's just ignore it. :)
45 return RESULT_SUCCESS; 47 return RESULT_SUCCESS;
46} 48}
diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h
index 35c0f3725..2523c3979 100644
--- a/src/core/file_sys/archive_sdmc.h
+++ b/src/core/file_sys/archive_sdmc.h
@@ -26,7 +26,9 @@ public:
26 */ 26 */
27 bool Initialize(); 27 bool Initialize();
28 28
29 std::string GetName() const override { return "SDMC"; } 29 std::string GetName() const override {
30 return "SDMC";
31 }
30 32
31 ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; 33 ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override;
32 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; 34 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override;
diff --git a/src/core/file_sys/archive_systemsavedata.cpp b/src/core/file_sys/archive_systemsavedata.cpp
index 1bcc228a1..1fb858247 100644
--- a/src/core/file_sys/archive_systemsavedata.cpp
+++ b/src/core/file_sys/archive_systemsavedata.cpp
@@ -45,11 +45,11 @@ Path ConstructSystemSaveDataBinaryPath(u32 high, u32 low) {
45 for (unsigned i = 0; i < 4; ++i) 45 for (unsigned i = 0; i < 4; ++i)
46 binary_path.push_back((low >> (8 * i)) & 0xFF); 46 binary_path.push_back((low >> (8 * i)) & 0xFF);
47 47
48 return { binary_path }; 48 return {binary_path};
49} 49}
50 50
51ArchiveFactory_SystemSaveData::ArchiveFactory_SystemSaveData(const std::string& nand_path) 51ArchiveFactory_SystemSaveData::ArchiveFactory_SystemSaveData(const std::string& nand_path)
52 : base_path(GetSystemSaveDataContainerPath(nand_path)) { 52 : base_path(GetSystemSaveDataContainerPath(nand_path)) {
53} 53}
54 54
55ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(const Path& path) { 55ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(const Path& path) {
@@ -57,13 +57,14 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(c
57 if (!FileUtil::Exists(fullpath)) { 57 if (!FileUtil::Exists(fullpath)) {
58 // TODO(Subv): Check error code, this one is probably wrong 58 // TODO(Subv): Check error code, this one is probably wrong
59 return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, 59 return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
60 ErrorSummary::InvalidState, ErrorLevel::Status); 60 ErrorSummary::InvalidState, ErrorLevel::Status);
61 } 61 }
62 auto archive = std::make_unique<DiskArchive>(fullpath); 62 auto archive = std::make_unique<DiskArchive>(fullpath);
63 return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); 63 return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
64} 64}
65 65
66ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { 66ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path,
67 const FileSys::ArchiveFormatInfo& format_info) {
67 std::string fullpath = GetSystemSaveDataPath(base_path, path); 68 std::string fullpath = GetSystemSaveDataPath(base_path, path);
68 FileUtil::DeleteDirRecursively(fullpath); 69 FileUtil::DeleteDirRecursively(fullpath);
69 FileUtil::CreateFullPath(fullpath); 70 FileUtil::CreateFullPath(fullpath);
diff --git a/src/core/file_sys/archive_systemsavedata.h b/src/core/file_sys/archive_systemsavedata.h
index 2bc13d4ee..61a002a7d 100644
--- a/src/core/file_sys/archive_systemsavedata.h
+++ b/src/core/file_sys/archive_systemsavedata.h
@@ -26,7 +26,9 @@ public:
26 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; 26 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override;
27 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; 27 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override;
28 28
29 std::string GetName() const override { return "SystemSaveData"; } 29 std::string GetName() const override {
30 return "SystemSaveData";
31 }
30 32
31private: 33private:
32 std::string base_path; 34 std::string base_path;
@@ -42,7 +44,8 @@ private:
42std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& path); 44std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& path);
43 45
44/** 46/**
45 * Constructs a path to the base folder to hold concrete SystemSaveData archives in the host file system. 47 * Constructs a path to the base folder to hold concrete SystemSaveData archives in the host file
48 * system.
46 * @param mount_point The base folder where this folder resides, ie. SDMC or NAND. 49 * @param mount_point The base folder where this folder resides, ie. SDMC or NAND.
47 * @returns The path to the base SystemSaveData archives' folder in the host file system 50 * @returns The path to the base SystemSaveData archives' folder in the host file system
48 */ 51 */
diff --git a/src/core/file_sys/directory_backend.h b/src/core/file_sys/directory_backend.h
index a25dc0cfa..c402ee60b 100644
--- a/src/core/file_sys/directory_backend.h
+++ b/src/core/file_sys/directory_backend.h
@@ -19,15 +19,16 @@ const size_t FILENAME_LENGTH = 0x20C / 2;
19struct Entry { 19struct Entry {
20 char16_t filename[FILENAME_LENGTH]; // Entry name (UTF-16, null-terminated) 20 char16_t filename[FILENAME_LENGTH]; // Entry name (UTF-16, null-terminated)
21 std::array<char, 9> short_name; // 8.3 file name ('longfilename' -> 'LONGFI~1', null-terminated) 21 std::array<char, 9> short_name; // 8.3 file name ('longfilename' -> 'LONGFI~1', null-terminated)
22 char unknown1; // unknown (observed values: 0x0A, 0x70, 0xFD) 22 char unknown1; // unknown (observed values: 0x0A, 0x70, 0xFD)
23 std::array<char, 4> extension; // 8.3 file extension (set to spaces for directories, null-terminated) 23 std::array<char, 4>
24 char unknown2; // unknown (always 0x01) 24 extension; // 8.3 file extension (set to spaces for directories, null-terminated)
25 char unknown3; // unknown (0x00 or 0x08) 25 char unknown2; // unknown (always 0x01)
26 char unknown3; // unknown (0x00 or 0x08)
26 char is_directory; // directory flag 27 char is_directory; // directory flag
27 char is_hidden; // hidden flag 28 char is_hidden; // hidden flag
28 char is_archive; // archive flag 29 char is_archive; // archive flag
29 char is_read_only; // read-only flag 30 char is_read_only; // read-only flag
30 u64 file_size; // file size (for files only) 31 u64 file_size; // file size (for files only)
31}; 32};
32static_assert(sizeof(Entry) == 0x228, "Directory Entry struct isn't exactly 0x228 bytes long!"); 33static_assert(sizeof(Entry) == 0x228, "Directory Entry struct isn't exactly 0x228 bytes long!");
33static_assert(offsetof(Entry, short_name) == 0x20C, "Wrong offset for short_name in Entry."); 34static_assert(offsetof(Entry, short_name) == 0x20C, "Wrong offset for short_name in Entry.");
@@ -37,8 +38,10 @@ static_assert(offsetof(Entry, file_size) == 0x220, "Wrong offset for file_size i
37 38
38class DirectoryBackend : NonCopyable { 39class DirectoryBackend : NonCopyable {
39public: 40public:
40 DirectoryBackend() { } 41 DirectoryBackend() {
41 virtual ~DirectoryBackend() { } 42 }
43 virtual ~DirectoryBackend() {
44 }
42 45
43 /** 46 /**
44 * Open the directory 47 * Open the directory
diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp
index 489cc96fb..c084303c1 100644
--- a/src/core/file_sys/disk_archive.cpp
+++ b/src/core/file_sys/disk_archive.cpp
@@ -17,7 +17,8 @@
17 17
18namespace FileSys { 18namespace FileSys {
19 19
20ResultVal<std::unique_ptr<FileBackend>> DiskArchive::OpenFile(const Path& path, const Mode mode) const { 20ResultVal<std::unique_ptr<FileBackend>> DiskArchive::OpenFile(const Path& path,
21 const Mode mode) const {
21 LOG_DEBUG(Service_FS, "called path=%s mode=%01X", path.DebugStr().c_str(), mode.hex); 22 LOG_DEBUG(Service_FS, "called path=%s mode=%01X", path.DebugStr().c_str(), mode.hex);
22 auto file = std::make_unique<DiskFile>(*this, path, mode); 23 auto file = std::make_unique<DiskFile>(*this, path, mode);
23 ResultCode result = file->Open(); 24 ResultCode result = file->Open();
@@ -30,15 +31,18 @@ ResultCode DiskArchive::DeleteFile(const Path& path) const {
30 std::string file_path = mount_point + path.AsString(); 31 std::string file_path = mount_point + path.AsString();
31 32
32 if (FileUtil::IsDirectory(file_path)) 33 if (FileUtil::IsDirectory(file_path))
33 return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); 34 return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled,
35 ErrorLevel::Status);
34 36
35 if (!FileUtil::Exists(file_path)) 37 if (!FileUtil::Exists(file_path))
36 return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Status); 38 return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound,
39 ErrorLevel::Status);
37 40
38 if (FileUtil::Delete(file_path)) 41 if (FileUtil::Delete(file_path))
39 return RESULT_SUCCESS; 42 return RESULT_SUCCESS;
40 43
41 return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); 44 return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled,
45 ErrorLevel::Status);
42} 46}
43 47
44bool DiskArchive::RenameFile(const Path& src_path, const Path& dest_path) const { 48bool DiskArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
@@ -53,10 +57,12 @@ ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u64 size) const {
53 std::string full_path = mount_point + path.AsString(); 57 std::string full_path = mount_point + path.AsString();
54 58
55 if (FileUtil::IsDirectory(full_path)) 59 if (FileUtil::IsDirectory(full_path))
56 return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); 60 return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled,
61 ErrorLevel::Status);
57 62
58 if (FileUtil::Exists(full_path)) 63 if (FileUtil::Exists(full_path))
59 return ResultCode(ErrorDescription::FS_AlreadyExists, ErrorModule::FS, ErrorSummary::NothingHappened, ErrorLevel::Status); 64 return ResultCode(ErrorDescription::FS_AlreadyExists, ErrorModule::FS,
65 ErrorSummary::NothingHappened, ErrorLevel::Status);
60 66
61 if (size == 0) { 67 if (size == 0) {
62 FileUtil::CreateEmptyFile(full_path); 68 FileUtil::CreateEmptyFile(full_path);
@@ -69,10 +75,10 @@ ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u64 size) const {
69 if (file.Seek(size - 1, SEEK_SET) && file.WriteBytes("", 1) == 1) 75 if (file.Seek(size - 1, SEEK_SET) && file.WriteBytes("", 1) == 1)
70 return RESULT_SUCCESS; 76 return RESULT_SUCCESS;
71 77
72 return ResultCode(ErrorDescription::TooLarge, ErrorModule::FS, ErrorSummary::OutOfResource, ErrorLevel::Info); 78 return ResultCode(ErrorDescription::TooLarge, ErrorModule::FS, ErrorSummary::OutOfResource,
79 ErrorLevel::Info);
73} 80}
74 81
75
76bool DiskArchive::CreateDirectory(const Path& path) const { 82bool DiskArchive::CreateDirectory(const Path& path) const {
77 return FileUtil::CreateDir(mount_point + path.AsString()); 83 return FileUtil::CreateDir(mount_point + path.AsString());
78} 84}
@@ -106,17 +112,21 @@ DiskFile::DiskFile(const DiskArchive& archive, const Path& path, const Mode mode
106 112
107ResultCode DiskFile::Open() { 113ResultCode DiskFile::Open() {
108 if (FileUtil::IsDirectory(path)) 114 if (FileUtil::IsDirectory(path))
109 return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); 115 return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled,
116 ErrorLevel::Status);
110 117
111 // Specifying only the Create flag is invalid 118 // Specifying only the Create flag is invalid
112 if (mode.create_flag && !mode.read_flag && !mode.write_flag) { 119 if (mode.create_flag && !mode.read_flag && !mode.write_flag) {
113 return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); 120 return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS,
121 ErrorSummary::Canceled, ErrorLevel::Status);
114 } 122 }
115 123
116 if (!FileUtil::Exists(path)) { 124 if (!FileUtil::Exists(path)) {
117 if (!mode.create_flag) { 125 if (!mode.create_flag) {
118 LOG_ERROR(Service_FS, "Non-existing file %s can't be open without mode create.", path.c_str()); 126 LOG_ERROR(Service_FS, "Non-existing file %s can't be open without mode create.",
119 return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Status); 127 path.c_str());
128 return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS,
129 ErrorSummary::NotFound, ErrorLevel::Status);
120 } else { 130 } else {
121 // Create the file 131 // Create the file
122 FileUtil::CreateEmptyFile(path); 132 FileUtil::CreateEmptyFile(path);
@@ -135,20 +145,24 @@ ResultCode DiskFile::Open() {
135 file = std::make_unique<FileUtil::IOFile>(path, mode_string.c_str()); 145 file = std::make_unique<FileUtil::IOFile>(path, mode_string.c_str());
136 if (file->IsOpen()) 146 if (file->IsOpen())
137 return RESULT_SUCCESS; 147 return RESULT_SUCCESS;
138 return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Status); 148 return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound,
149 ErrorLevel::Status);
139} 150}
140 151
141ResultVal<size_t> DiskFile::Read(const u64 offset, const size_t length, u8* buffer) const { 152ResultVal<size_t> DiskFile::Read(const u64 offset, const size_t length, u8* buffer) const {
142 if (!mode.read_flag && !mode.write_flag) 153 if (!mode.read_flag && !mode.write_flag)
143 return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); 154 return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS,
155 ErrorSummary::Canceled, ErrorLevel::Status);
144 156
145 file->Seek(offset, SEEK_SET); 157 file->Seek(offset, SEEK_SET);
146 return MakeResult<size_t>(file->ReadBytes(buffer, length)); 158 return MakeResult<size_t>(file->ReadBytes(buffer, length));
147} 159}
148 160
149ResultVal<size_t> DiskFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const { 161ResultVal<size_t> DiskFile::Write(const u64 offset, const size_t length, const bool flush,
162 const u8* buffer) const {
150 if (!mode.write_flag) 163 if (!mode.write_flag)
151 return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); 164 return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS,
165 ErrorSummary::Canceled, ErrorLevel::Status);
152 166
153 file->Seek(offset, SEEK_SET); 167 file->Seek(offset, SEEK_SET);
154 size_t written = file->WriteBytes(buffer, length); 168 size_t written = file->WriteBytes(buffer, length);
@@ -198,7 +212,8 @@ u32 DiskDirectory::Read(const u32 count, Entry* entries) {
198 const std::string& filename = file.virtualName; 212 const std::string& filename = file.virtualName;
199 Entry& entry = entries[entries_read]; 213 Entry& entry = entries[entries_read];
200 214
201 LOG_TRACE(Service_FS, "File %s: size=%llu dir=%d", filename.c_str(), file.size, file.isDirectory); 215 LOG_TRACE(Service_FS, "File %s: size=%llu dir=%d", filename.c_str(), file.size,
216 file.isDirectory);
202 217
203 // TODO(Link Mauve): use a proper conversion to UTF-16. 218 // TODO(Link Mauve): use a proper conversion to UTF-16.
204 for (size_t j = 0; j < FILENAME_LENGTH; ++j) { 219 for (size_t j = 0; j < FILENAME_LENGTH; ++j) {
diff --git a/src/core/file_sys/disk_archive.h b/src/core/file_sys/disk_archive.h
index b4cc2f702..3f620128f 100644
--- a/src/core/file_sys/disk_archive.h
+++ b/src/core/file_sys/disk_archive.h
@@ -29,11 +29,15 @@ namespace FileSys {
29 */ 29 */
30class DiskArchive : public ArchiveBackend { 30class DiskArchive : public ArchiveBackend {
31public: 31public:
32 DiskArchive(const std::string& mount_point_) : mount_point(mount_point_) {} 32 DiskArchive(const std::string& mount_point_) : mount_point(mount_point_) {
33 }
33 34
34 virtual std::string GetName() const override { return "DiskArchive: " + mount_point; } 35 virtual std::string GetName() const override {
36 return "DiskArchive: " + mount_point;
37 }
35 38
36 ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, const Mode mode) const override; 39 ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
40 const Mode mode) const override;
37 ResultCode DeleteFile(const Path& path) const override; 41 ResultCode DeleteFile(const Path& path) const override;
38 bool RenameFile(const Path& src_path, const Path& dest_path) const override; 42 bool RenameFile(const Path& src_path, const Path& dest_path) const override;
39 bool DeleteDirectory(const Path& path) const override; 43 bool DeleteDirectory(const Path& path) const override;
diff --git a/src/core/file_sys/file_backend.h b/src/core/file_sys/file_backend.h
index 9137bbbad..9eae697c2 100644
--- a/src/core/file_sys/file_backend.h
+++ b/src/core/file_sys/file_backend.h
@@ -16,8 +16,10 @@ namespace FileSys {
16 16
17class FileBackend : NonCopyable { 17class FileBackend : NonCopyable {
18public: 18public:
19 FileBackend() { } 19 FileBackend() {
20 virtual ~FileBackend() { } 20 }
21 virtual ~FileBackend() {
22 }
21 23
22 /** 24 /**
23 * Open the file 25 * Open the file
@@ -42,7 +44,8 @@ public:
42 * @param buffer Buffer to read data from 44 * @param buffer Buffer to read data from
43 * @return Number of bytes written, or error code 45 * @return Number of bytes written, or error code
44 */ 46 */
45 virtual ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) const = 0; 47 virtual ResultVal<size_t> Write(u64 offset, size_t length, bool flush,
48 const u8* buffer) const = 0;
46 49
47 /** 50 /**
48 * Get the size of the file in bytes 51 * Get the size of the file in bytes
diff --git a/src/core/file_sys/ivfc_archive.cpp b/src/core/file_sys/ivfc_archive.cpp
index c61791ef7..235a962e9 100644
--- a/src/core/file_sys/ivfc_archive.cpp
+++ b/src/core/file_sys/ivfc_archive.cpp
@@ -19,40 +19,49 @@ std::string IVFCArchive::GetName() const {
19 return "IVFC"; 19 return "IVFC";
20} 20}
21 21
22ResultVal<std::unique_ptr<FileBackend>> IVFCArchive::OpenFile(const Path& path, const Mode mode) const { 22ResultVal<std::unique_ptr<FileBackend>> IVFCArchive::OpenFile(const Path& path,
23 return MakeResult<std::unique_ptr<FileBackend>>(std::make_unique<IVFCFile>(romfs_file, data_offset, data_size)); 23 const Mode mode) const {
24 return MakeResult<std::unique_ptr<FileBackend>>(
25 std::make_unique<IVFCFile>(romfs_file, data_offset, data_size));
24} 26}
25 27
26ResultCode IVFCArchive::DeleteFile(const Path& path) const { 28ResultCode IVFCArchive::DeleteFile(const Path& path) const {
27 LOG_CRITICAL(Service_FS, "Attempted to delete a file from an IVFC archive (%s).", GetName().c_str()); 29 LOG_CRITICAL(Service_FS, "Attempted to delete a file from an IVFC archive (%s).",
30 GetName().c_str());
28 // TODO(Subv): Verify error code 31 // TODO(Subv): Verify error code
29 return ResultCode(ErrorDescription::NoData, ErrorModule::FS, 32 return ResultCode(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled,
30 ErrorSummary::Canceled, ErrorLevel::Status); 33 ErrorLevel::Status);
31} 34}
32 35
33bool IVFCArchive::RenameFile(const Path& src_path, const Path& dest_path) const { 36bool IVFCArchive::RenameFile(const Path& src_path, const Path& dest_path) const {
34 LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive (%s).", GetName().c_str()); 37 LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive (%s).",
38 GetName().c_str());
35 return false; 39 return false;
36} 40}
37 41
38bool IVFCArchive::DeleteDirectory(const Path& path) const { 42bool IVFCArchive::DeleteDirectory(const Path& path) const {
39 LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive (%s).", GetName().c_str()); 43 LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive (%s).",
44 GetName().c_str());
40 return false; 45 return false;
41} 46}
42 47
43ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const { 48ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const {
44 LOG_CRITICAL(Service_FS, "Attempted to create a file in an IVFC archive (%s).", GetName().c_str()); 49 LOG_CRITICAL(Service_FS, "Attempted to create a file in an IVFC archive (%s).",
50 GetName().c_str());
45 // TODO: Verify error code 51 // TODO: Verify error code
46 return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, ErrorLevel::Permanent); 52 return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported,
53 ErrorLevel::Permanent);
47} 54}
48 55
49bool IVFCArchive::CreateDirectory(const Path& path) const { 56bool IVFCArchive::CreateDirectory(const Path& path) const {
50 LOG_CRITICAL(Service_FS, "Attempted to create a directory in an IVFC archive (%s).", GetName().c_str()); 57 LOG_CRITICAL(Service_FS, "Attempted to create a directory in an IVFC archive (%s).",
58 GetName().c_str());
51 return false; 59 return false;
52} 60}
53 61
54bool IVFCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { 62bool IVFCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const {
55 LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive (%s).", GetName().c_str()); 63 LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive (%s).",
64 GetName().c_str());
56 return false; 65 return false;
57} 66}
58 67
@@ -75,7 +84,8 @@ ResultVal<size_t> IVFCFile::Read(const u64 offset, const size_t length, u8* buff
75 return MakeResult<size_t>(romfs_file->ReadBytes(buffer, read_length)); 84 return MakeResult<size_t>(romfs_file->ReadBytes(buffer, read_length));
76} 85}
77 86
78ResultVal<size_t> IVFCFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const { 87ResultVal<size_t> IVFCFile::Write(const u64 offset, const size_t length, const bool flush,
88 const u8* buffer) const {
79 LOG_ERROR(Service_FS, "Attempted to write to IVFC file"); 89 LOG_ERROR(Service_FS, "Attempted to write to IVFC file");
80 // TODO(Subv): Find error code 90 // TODO(Subv): Find error code
81 return MakeResult<size_t>(0); 91 return MakeResult<size_t>(0);
diff --git a/src/core/file_sys/ivfc_archive.h b/src/core/file_sys/ivfc_archive.h
index 19d32dcca..dab1958f6 100644
--- a/src/core/file_sys/ivfc_archive.h
+++ b/src/core/file_sys/ivfc_archive.h
@@ -30,11 +30,13 @@ namespace FileSys {
30class IVFCArchive : public ArchiveBackend { 30class IVFCArchive : public ArchiveBackend {
31public: 31public:
32 IVFCArchive(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size) 32 IVFCArchive(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size)
33 : romfs_file(file), data_offset(offset), data_size(size) {} 33 : romfs_file(file), data_offset(offset), data_size(size) {
34 }
34 35
35 std::string GetName() const override; 36 std::string GetName() const override;
36 37
37 ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, const Mode mode) const override; 38 ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path,
39 const Mode mode) const override;
38 ResultCode DeleteFile(const Path& path) const override; 40 ResultCode DeleteFile(const Path& path) const override;
39 bool RenameFile(const Path& src_path, const Path& dest_path) const override; 41 bool RenameFile(const Path& src_path, const Path& dest_path) const override;
40 bool DeleteDirectory(const Path& path) const override; 42 bool DeleteDirectory(const Path& path) const override;
@@ -53,15 +55,21 @@ protected:
53class IVFCFile : public FileBackend { 55class IVFCFile : public FileBackend {
54public: 56public:
55 IVFCFile(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size) 57 IVFCFile(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size)
56 : romfs_file(file), data_offset(offset), data_size(size) {} 58 : romfs_file(file), data_offset(offset), data_size(size) {
59 }
57 60
58 ResultCode Open() override { return RESULT_SUCCESS; } 61 ResultCode Open() override {
62 return RESULT_SUCCESS;
63 }
59 ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override; 64 ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override;
60 ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) const override; 65 ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) const override;
61 u64 GetSize() const override; 66 u64 GetSize() const override;
62 bool SetSize(u64 size) const override; 67 bool SetSize(u64 size) const override;
63 bool Close() const override { return false; } 68 bool Close() const override {
64 void Flush() const override { } 69 return false;
70 }
71 void Flush() const override {
72 }
65 73
66private: 74private:
67 std::shared_ptr<FileUtil::IOFile> romfs_file; 75 std::shared_ptr<FileUtil::IOFile> romfs_file;
@@ -71,9 +79,15 @@ private:
71 79
72class IVFCDirectory : public DirectoryBackend { 80class IVFCDirectory : public DirectoryBackend {
73public: 81public:
74 bool Open() override { return false; } 82 bool Open() override {
75 u32 Read(const u32 count, Entry* entries) override { return 0; } 83 return false;
76 bool Close() const override { return false; } 84 }
85 u32 Read(const u32 count, Entry* entries) override {
86 return 0;
87 }
88 bool Close() const override {
89 return false;
90 }
77}; 91};
78 92
79} // namespace FileSys 93} // namespace FileSys