summaryrefslogtreecommitdiff
path: root/src/core
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
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')
-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
-rw-r--r--src/core/hle/service/am/am.cpp22
-rw-r--r--src/core/hle/service/filesystem/filesystem.cpp13
-rw-r--r--src/core/hle/service/filesystem/filesystem.h7
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.cpp14
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.h1
12 files changed, 91 insertions, 43 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
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index d3a674cf6..d9f003ed4 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -2,12 +2,15 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <cinttypes>
6#include "core/file_sys/filesystem.h"
5#include "core/hle/ipc_helpers.h" 7#include "core/hle/ipc_helpers.h"
6#include "core/hle/kernel/event.h" 8#include "core/hle/kernel/event.h"
7#include "core/hle/service/am/am.h" 9#include "core/hle/service/am/am.h"
8#include "core/hle/service/am/applet_ae.h" 10#include "core/hle/service/am/applet_ae.h"
9#include "core/hle/service/am/applet_oe.h" 11#include "core/hle/service/am/applet_oe.h"
10#include "core/hle/service/apm/apm.h" 12#include "core/hle/service/apm/apm.h"
13#include "core/hle/service/filesystem/filesystem.h"
11#include "core/hle/service/nvflinger/nvflinger.h" 14#include "core/hle/service/nvflinger/nvflinger.h"
12 15
13namespace Service { 16namespace Service {
@@ -416,9 +419,24 @@ void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) {
416} 419}
417 420
418void IApplicationFunctions::EnsureSaveData(Kernel::HLERequestContext& ctx) { 421void IApplicationFunctions::EnsureSaveData(Kernel::HLERequestContext& ctx) {
419 LOG_WARNING(Service, "(STUBBED) called"); 422 IPC::RequestParser rp{ctx};
423 u128 uid = rp.PopRaw<u128>();
424
425 LOG_WARNING(Service, "(STUBBED) called uid = %016" PRIX64 "%016" PRIX64, uid[1], uid[0]);
426
420 IPC::ResponseBuilder rb{ctx, 4}; 427 IPC::ResponseBuilder rb{ctx, 4};
421 rb.Push(RESULT_SUCCESS); 428
429 FileSys::Path unused;
430 auto savedata = FileSystem::OpenFileSystem(FileSystem::Type::SaveData, unused);
431 if (savedata.Failed()) {
432 // Create the save data and return an error indicating that the operation was performed.
433 FileSystem::FormatFileSystem(FileSystem::Type::SaveData);
434 // TODO(Subv): Find out the correct error code for this.
435 rb.Push(ResultCode(ErrorModule::FS, 40));
436 } else {
437 rb.Push(RESULT_SUCCESS);
438 }
439
422 rb.Push<u64>(0); 440 rb.Push<u64>(0);
423} 441}
424 442
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp
index 32752aea5..ef05955b9 100644
--- a/src/core/hle/service/filesystem/filesystem.cpp
+++ b/src/core/hle/service/filesystem/filesystem.cpp
@@ -43,6 +43,19 @@ ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenFileSystem(Type type,
43 return itr->second->Open(path); 43 return itr->second->Open(path);
44} 44}
45 45
46ResultCode FormatFileSystem(Type type) {
47 LOG_TRACE(Service_FS, "Formatting FileSystem with type=%d", type);
48
49 auto itr = filesystem_map.find(type);
50 if (itr == filesystem_map.end()) {
51 // TODO(bunnei): Find a better error code for this
52 return ResultCode(-1);
53 }
54
55 FileSys::Path unused;
56 return itr->second->Format(unused);
57}
58
46void RegisterFileSystems() { 59void RegisterFileSystems() {
47 filesystem_map.clear(); 60 filesystem_map.clear();
48 61
diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h
index 80f318676..8d30e94a1 100644
--- a/src/core/hle/service/filesystem/filesystem.h
+++ b/src/core/hle/service/filesystem/filesystem.h
@@ -44,6 +44,13 @@ ResultCode RegisterFileSystem(std::unique_ptr<FileSys::FileSystemFactory>&& fact
44ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenFileSystem(Type type, 44ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenFileSystem(Type type,
45 FileSys::Path& path); 45 FileSys::Path& path);
46 46
47/**
48 * Formats a file system
49 * @param type Type of the file system to format
50 * @return ResultCode of the operation
51 */
52ResultCode FormatFileSystem(Type type);
53
47/// Registers all Filesystem services with the specified service manager. 54/// Registers all Filesystem services with the specified service manager.
48void InstallInterfaces(SM::ServiceManager& service_manager); 55void InstallInterfaces(SM::ServiceManager& service_manager);
49 56
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp
index 3ac5a96cb..97b3fa290 100644
--- a/src/core/hle/service/filesystem/fsp_srv.cpp
+++ b/src/core/hle/service/filesystem/fsp_srv.cpp
@@ -245,6 +245,7 @@ FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") {
245 static const FunctionInfo functions[] = { 245 static const FunctionInfo functions[] = {
246 {1, &FSP_SRV::Initalize, "Initalize"}, 246 {1, &FSP_SRV::Initalize, "Initalize"},
247 {18, &FSP_SRV::MountSdCard, "MountSdCard"}, 247 {18, &FSP_SRV::MountSdCard, "MountSdCard"},
248 {22, &FSP_SRV::CreateSaveData, "CreateSaveData"},
248 {51, &FSP_SRV::MountSaveData, "MountSaveData"}, 249 {51, &FSP_SRV::MountSaveData, "MountSaveData"},
249 {200, &FSP_SRV::OpenDataStorageByCurrentProcess, "OpenDataStorageByCurrentProcess"}, 250 {200, &FSP_SRV::OpenDataStorageByCurrentProcess, "OpenDataStorageByCurrentProcess"},
250 {202, nullptr, "OpenDataStorageByDataId"}, 251 {202, nullptr, "OpenDataStorageByDataId"},
@@ -279,6 +280,19 @@ void FSP_SRV::MountSdCard(Kernel::HLERequestContext& ctx) {
279 rb.Push(RESULT_SUCCESS); 280 rb.Push(RESULT_SUCCESS);
280} 281}
281 282
283void FSP_SRV::CreateSaveData(Kernel::HLERequestContext& ctx) {
284 IPC::RequestParser rp{ctx};
285
286 auto save_struct = rp.PopRaw<std::array<u8, 0x40>>();
287 auto save_create_struct = rp.PopRaw<std::array<u8, 0x40>>();
288 u128 uid = rp.PopRaw<u128>();
289
290 LOG_WARNING(Service_FS, "(STUBBED) called uid = %016" PRIX64 "%016" PRIX64, uid[1], uid[0]);
291
292 IPC::ResponseBuilder rb{ctx, 2};
293 rb.Push(RESULT_SUCCESS);
294}
295
282void FSP_SRV::MountSaveData(Kernel::HLERequestContext& ctx) { 296void FSP_SRV::MountSaveData(Kernel::HLERequestContext& ctx) {
283 LOG_WARNING(Service_FS, "(STUBBED) called"); 297 LOG_WARNING(Service_FS, "(STUBBED) called");
284 298
diff --git a/src/core/hle/service/filesystem/fsp_srv.h b/src/core/hle/service/filesystem/fsp_srv.h
index f19b2f2c4..e15ba4375 100644
--- a/src/core/hle/service/filesystem/fsp_srv.h
+++ b/src/core/hle/service/filesystem/fsp_srv.h
@@ -24,6 +24,7 @@ private:
24 24
25 void Initalize(Kernel::HLERequestContext& ctx); 25 void Initalize(Kernel::HLERequestContext& ctx);
26 void MountSdCard(Kernel::HLERequestContext& ctx); 26 void MountSdCard(Kernel::HLERequestContext& ctx);
27 void CreateSaveData(Kernel::HLERequestContext& ctx);
27 void MountSaveData(Kernel::HLERequestContext& ctx); 28 void MountSaveData(Kernel::HLERequestContext& ctx);
28 void GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx); 29 void GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx);
29 void OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx); 30 void OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx);