summaryrefslogtreecommitdiff
path: root/src/core/file_sys
diff options
context:
space:
mode:
authorGravatar bunnei2018-03-04 15:49:42 -0500
committerGravatar GitHub2018-03-04 15:49:42 -0500
commit80562aaf64413f5740138dba70393789d10de580 (patch)
tree01b8f6a28202295b25eaa90e8cbbef5a9b3c0c6f /src/core/file_sys
parentMerge pull request #228 from Subv/unschedule_events (diff)
parentFS: Use the correct error code when trying to open files that don't exist. (diff)
downloadyuzu-80562aaf64413f5740138dba70393789d10de580.tar.gz
yuzu-80562aaf64413f5740138dba70393789d10de580.tar.xz
yuzu-80562aaf64413f5740138dba70393789d10de580.zip
Merge pull request #229 from Subv/ensuresavedata_impl
FS: Make EnsureSaveData create the save data if it doesn't already exist.
Diffstat (limited to 'src/core/file_sys')
-rw-r--r--src/core/file_sys/disk_filesystem.cpp7
-rw-r--r--src/core/file_sys/errors.h25
-rw-r--r--src/core/file_sys/filesystem.h3
-rw-r--r--src/core/file_sys/romfs_factory.cpp2
-rw-r--r--src/core/file_sys/romfs_factory.h2
-rw-r--r--src/core/file_sys/savedata_factory.cpp34
-rw-r--r--src/core/file_sys/savedata_factory.h4
7 files changed, 36 insertions, 41 deletions
diff --git a/src/core/file_sys/disk_filesystem.cpp b/src/core/file_sys/disk_filesystem.cpp
index be7574fdb..22b17ba04 100644
--- a/src/core/file_sys/disk_filesystem.cpp
+++ b/src/core/file_sys/disk_filesystem.cpp
@@ -7,6 +7,7 @@
7#include "common/common_types.h" 7#include "common/common_types.h"
8#include "common/logging/log.h" 8#include "common/logging/log.h"
9#include "core/file_sys/disk_filesystem.h" 9#include "core/file_sys/disk_filesystem.h"
10#include "core/file_sys/errors.h"
10 11
11namespace FileSys { 12namespace FileSys {
12 13
@@ -22,8 +23,7 @@ ResultVal<std::unique_ptr<StorageBackend>> Disk_FileSystem::OpenFile(const std::
22 auto file = std::make_shared<FileUtil::IOFile>(full_path, mode == Mode::Read ? "rb" : "wb"); 23 auto file = std::make_shared<FileUtil::IOFile>(full_path, mode == Mode::Read ? "rb" : "wb");
23 24
24 if (!file->IsOpen()) { 25 if (!file->IsOpen()) {
25 // TODO(Subv): Find out the correct error code. 26 return ERROR_PATH_NOT_FOUND;
26 return ResultCode(-1);
27 } 27 }
28 28
29 return MakeResult<std::unique_ptr<StorageBackend>>( 29 return MakeResult<std::unique_ptr<StorageBackend>>(
@@ -100,8 +100,7 @@ u64 Disk_FileSystem::GetFreeSpaceSize() const {
100ResultVal<FileSys::EntryType> Disk_FileSystem::GetEntryType(const std::string& path) const { 100ResultVal<FileSys::EntryType> Disk_FileSystem::GetEntryType(const std::string& path) const {
101 std::string full_path = base_directory + path; 101 std::string full_path = base_directory + path;
102 if (!FileUtil::Exists(full_path)) { 102 if (!FileUtil::Exists(full_path)) {
103 // TODO(Subv): Find out what this actually means 103 return ERROR_PATH_NOT_FOUND;
104 return ResultCode(ErrorModule::FS, 1);
105 } 104 }
106 105
107 // TODO(Subv): Find out the EntryType values 106 // TODO(Subv): Find out the EntryType values
diff --git a/src/core/file_sys/errors.h b/src/core/file_sys/errors.h
index be3224ef8..0ed7d2a0c 100644
--- a/src/core/file_sys/errors.h
+++ b/src/core/file_sys/errors.h
@@ -10,36 +10,17 @@ namespace FileSys {
10 10
11namespace ErrCodes { 11namespace ErrCodes {
12enum { 12enum {
13 RomFSNotFound = 100, 13 NotFound = 1,
14 ArchiveNotMounted = 101,
15 FileNotFound = 112,
16 PathNotFound = 113,
17 GameCardNotInserted = 141,
18 NotFound = 120,
19 FileAlreadyExists = 180,
20 DirectoryAlreadyExists = 185,
21 AlreadyExists = 190,
22 InvalidOpenFlags = 230,
23 DirectoryNotEmpty = 240,
24 NotAFile = 250,
25 NotFormatted = 340, ///< This is used by the FS service when creating a SaveData archive
26 ExeFSSectionNotFound = 567,
27 CommandNotAllowed = 630,
28 InvalidReadFlag = 700,
29 InvalidPath = 702,
30 WriteBeyondEnd = 705,
31 UnsupportedOpenFlags = 760,
32 IncorrectExeFSReadSize = 761,
33 UnexpectedFileOrDirectory = 770,
34}; 14};
35} 15}
36 16
17constexpr ResultCode ERROR_PATH_NOT_FOUND(ErrorModule::FS, ErrCodes::NotFound);
18
37// TODO(bunnei): Replace these with correct errors for Switch OS 19// TODO(bunnei): Replace these with correct errors for Switch OS
38constexpr ResultCode ERROR_INVALID_PATH(ResultCode(-1)); 20constexpr ResultCode ERROR_INVALID_PATH(ResultCode(-1));
39constexpr ResultCode ERROR_UNSUPPORTED_OPEN_FLAGS(ResultCode(-1)); 21constexpr ResultCode ERROR_UNSUPPORTED_OPEN_FLAGS(ResultCode(-1));
40constexpr ResultCode ERROR_INVALID_OPEN_FLAGS(ResultCode(-1)); 22constexpr ResultCode ERROR_INVALID_OPEN_FLAGS(ResultCode(-1));
41constexpr ResultCode ERROR_FILE_NOT_FOUND(ResultCode(-1)); 23constexpr ResultCode ERROR_FILE_NOT_FOUND(ResultCode(-1));
42constexpr ResultCode ERROR_PATH_NOT_FOUND(ResultCode(-1));
43constexpr ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY(ResultCode(-1)); 24constexpr ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY(ResultCode(-1));
44constexpr ResultCode ERROR_DIRECTORY_ALREADY_EXISTS(ResultCode(-1)); 25constexpr ResultCode ERROR_DIRECTORY_ALREADY_EXISTS(ResultCode(-1));
45constexpr ResultCode ERROR_FILE_ALREADY_EXISTS(ResultCode(-1)); 26constexpr ResultCode ERROR_FILE_ALREADY_EXISTS(ResultCode(-1));
diff --git a/src/core/file_sys/filesystem.h b/src/core/file_sys/filesystem.h
index df4e66a0b..94ad2abf2 100644
--- a/src/core/file_sys/filesystem.h
+++ b/src/core/file_sys/filesystem.h
@@ -183,10 +183,9 @@ public:
183 /** 183 /**
184 * Deletes the archive contents and then re-creates the base folder 184 * Deletes the archive contents and then re-creates the base folder
185 * @param path Path to the archive 185 * @param path Path to the archive
186 * @param format_info Format information for the new archive
187 * @return ResultCode of the operation, 0 on success 186 * @return ResultCode of the operation, 0 on success
188 */ 187 */
189 virtual ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) = 0; 188 virtual ResultCode Format(const Path& path) = 0;
190 189
191 /** 190 /**
192 * Retrieves the format info about the archive with the specified path 191 * Retrieves the format info about the archive with the specified path
diff --git a/src/core/file_sys/romfs_factory.cpp b/src/core/file_sys/romfs_factory.cpp
index e0de49f05..b21427948 100644
--- a/src/core/file_sys/romfs_factory.cpp
+++ b/src/core/file_sys/romfs_factory.cpp
@@ -23,7 +23,7 @@ ResultVal<std::unique_ptr<FileSystemBackend>> RomFS_Factory::Open(const Path& pa
23 return MakeResult<std::unique_ptr<FileSystemBackend>>(std::move(archive)); 23 return MakeResult<std::unique_ptr<FileSystemBackend>>(std::move(archive));
24} 24}
25 25
26ResultCode RomFS_Factory::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { 26ResultCode RomFS_Factory::Format(const Path& path) {
27 LOG_ERROR(Service_FS, "Unimplemented Format archive %s", GetName().c_str()); 27 LOG_ERROR(Service_FS, "Unimplemented Format archive %s", GetName().c_str());
28 // TODO(bunnei): Find the right error code for this 28 // TODO(bunnei): Find the right error code for this
29 return ResultCode(-1); 29 return ResultCode(-1);
diff --git a/src/core/file_sys/romfs_factory.h b/src/core/file_sys/romfs_factory.h
index 10ea13966..e0698e642 100644
--- a/src/core/file_sys/romfs_factory.h
+++ b/src/core/file_sys/romfs_factory.h
@@ -23,7 +23,7 @@ public:
23 return "ArchiveFactory_RomFS"; 23 return "ArchiveFactory_RomFS";
24 } 24 }
25 ResultVal<std::unique_ptr<FileSystemBackend>> Open(const Path& path) override; 25 ResultVal<std::unique_ptr<FileSystemBackend>> Open(const Path& path) override;
26 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; 26 ResultCode Format(const Path& path) override;
27 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; 27 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override;
28 28
29private: 29private:
diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp
index 4d83e100f..c3329ce52 100644
--- a/src/core/file_sys/savedata_factory.cpp
+++ b/src/core/file_sys/savedata_factory.cpp
@@ -17,20 +17,26 @@ SaveData_Factory::SaveData_Factory(std::string nand_directory)
17 : nand_directory(std::move(nand_directory)) {} 17 : nand_directory(std::move(nand_directory)) {}
18 18
19ResultVal<std::unique_ptr<FileSystemBackend>> SaveData_Factory::Open(const Path& path) { 19ResultVal<std::unique_ptr<FileSystemBackend>> SaveData_Factory::Open(const Path& path) {
20 u64 title_id = Kernel::g_current_process->program_id; 20 std::string save_directory = GetFullPath();
21 // TODO(Subv): Somehow obtain this value. 21 // Return an error if the save data doesn't actually exist.
22 u32 user = 0; 22 if (!FileUtil::IsDirectory(save_directory)) {
23 std::string save_directory = Common::StringFromFormat("%ssave/%016" PRIX64 "/%08X", 23 // TODO(Subv): Find out correct error code.
24 nand_directory.c_str(), title_id, user); 24 return ResultCode(-1);
25 }
26
25 auto archive = std::make_unique<Disk_FileSystem>(save_directory); 27 auto archive = std::make_unique<Disk_FileSystem>(save_directory);
26 return MakeResult<std::unique_ptr<FileSystemBackend>>(std::move(archive)); 28 return MakeResult<std::unique_ptr<FileSystemBackend>>(std::move(archive));
27} 29}
28 30
29ResultCode SaveData_Factory::Format(const Path& path, 31ResultCode SaveData_Factory::Format(const Path& path) {
30 const FileSys::ArchiveFormatInfo& format_info) { 32 LOG_WARNING(Service_FS, "Format archive %s", GetName().c_str());
31 LOG_ERROR(Service_FS, "Unimplemented Format archive %s", GetName().c_str()); 33 // Create the save data directory.
32 // TODO(bunnei): Find the right error code for this 34 if (!FileUtil::CreateFullPath(GetFullPath())) {
33 return ResultCode(-1); 35 // TODO(Subv): Find the correct error code.
36 return ResultCode(-1);
37 }
38
39 return RESULT_SUCCESS;
34} 40}
35 41
36ResultVal<ArchiveFormatInfo> SaveData_Factory::GetFormatInfo(const Path& path) const { 42ResultVal<ArchiveFormatInfo> SaveData_Factory::GetFormatInfo(const Path& path) const {
@@ -39,4 +45,12 @@ ResultVal<ArchiveFormatInfo> SaveData_Factory::GetFormatInfo(const Path& path) c
39 return ResultCode(-1); 45 return ResultCode(-1);
40} 46}
41 47
48std::string SaveData_Factory::GetFullPath() const {
49 u64 title_id = Kernel::g_current_process->program_id;
50 // TODO(Subv): Somehow obtain this value.
51 u32 user = 0;
52 return Common::StringFromFormat("%ssave/%016" PRIX64 "/%08X/", nand_directory.c_str(), title_id,
53 user);
54}
55
42} // namespace FileSys 56} // namespace FileSys
diff --git a/src/core/file_sys/savedata_factory.h b/src/core/file_sys/savedata_factory.h
index 726743fde..73a42aab6 100644
--- a/src/core/file_sys/savedata_factory.h
+++ b/src/core/file_sys/savedata_factory.h
@@ -21,11 +21,13 @@ public:
21 return "SaveData_Factory"; 21 return "SaveData_Factory";
22 } 22 }
23 ResultVal<std::unique_ptr<FileSystemBackend>> Open(const Path& path) override; 23 ResultVal<std::unique_ptr<FileSystemBackend>> Open(const Path& path) override;
24 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; 24 ResultCode Format(const Path& path) override;
25 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; 25 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override;
26 26
27private: 27private:
28 std::string nand_directory; 28 std::string nand_directory;
29
30 std::string GetFullPath() const;
29}; 31};
30 32
31} // namespace FileSys 33} // namespace FileSys