summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar wwylele2016-11-29 00:52:11 +0200
committerGravatar wwylele2016-11-29 23:50:00 +0200
commit589b6427909dfc7a4b5ee1a64cb86d38d459b0f3 (patch)
treeb6ad186dd5d10ef0aa5db9153962a1c18060f417 /src/core
parentFS: add missing MediaType (diff)
downloadyuzu-589b6427909dfc7a4b5ee1a64cb86d38d459b0f3.tar.gz
yuzu-589b6427909dfc7a4b5ee1a64cb86d38d459b0f3.tar.xz
yuzu-589b6427909dfc7a4b5ee1a64cb86d38d459b0f3.zip
FileSys: Implement OtherSaveData
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/file_sys/archive_other_savedata.cpp145
-rw-r--r--src/core/file_sys/archive_other_savedata.h52
-rw-r--r--src/core/file_sys/errors.h3
-rw-r--r--src/core/hle/result.h1
-rw-r--r--src/core/hle/service/fs/archive.cpp9
-rw-r--r--src/core/hle/service/fs/archive.h2
7 files changed, 214 insertions, 0 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 3f762ed52..8ce141e6a 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -18,6 +18,7 @@ set(SRCS
18 file_sys/archive_backend.cpp 18 file_sys/archive_backend.cpp
19 file_sys/archive_extsavedata.cpp 19 file_sys/archive_extsavedata.cpp
20 file_sys/archive_ncch.cpp 20 file_sys/archive_ncch.cpp
21 file_sys/archive_other_savedata.cpp
21 file_sys/archive_romfs.cpp 22 file_sys/archive_romfs.cpp
22 file_sys/archive_savedata.cpp 23 file_sys/archive_savedata.cpp
23 file_sys/archive_sdmc.cpp 24 file_sys/archive_sdmc.cpp
@@ -164,6 +165,7 @@ set(HEADERS
164 file_sys/archive_backend.h 165 file_sys/archive_backend.h
165 file_sys/archive_extsavedata.h 166 file_sys/archive_extsavedata.h
166 file_sys/archive_ncch.h 167 file_sys/archive_ncch.h
168 file_sys/archive_other_savedata.h
167 file_sys/archive_romfs.h 169 file_sys/archive_romfs.h
168 file_sys/archive_savedata.h 170 file_sys/archive_savedata.h
169 file_sys/archive_sdmc.h 171 file_sys/archive_sdmc.h
diff --git a/src/core/file_sys/archive_other_savedata.cpp b/src/core/file_sys/archive_other_savedata.cpp
new file mode 100644
index 000000000..d3cf080da
--- /dev/null
+++ b/src/core/file_sys/archive_other_savedata.cpp
@@ -0,0 +1,145 @@
1// Copyright 2016 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <tuple>
6#include "core/file_sys/archive_other_savedata.h"
7#include "core/file_sys/errors.h"
8#include "core/hle/kernel/process.h"
9#include "core/hle/service/fs/archive.h"
10
11////////////////////////////////////////////////////////////////////////////////////////////////////
12// FileSys namespace
13
14namespace FileSys {
15
16// TODO(wwylele): The storage info in exheader should be checked before accessing these archives
17
18using Service::FS::MediaType;
19
20namespace {
21
22template <typename T>
23ResultVal<std::tuple<MediaType, u64>> ParsePath(const Path& path, T program_id_reader) {
24 if (path.GetType() != Binary) {
25 LOG_ERROR(Service_FS, "Wrong path type %d", static_cast<int>(path.GetType()));
26 return ERROR_INVALID_PATH;
27 }
28
29 std::vector<u8> vec_data = path.AsBinary();
30
31 if (vec_data.size() != 12) {
32 LOG_ERROR(Service_FS, "Wrong path length %zu", vec_data.size());
33 return ERROR_INVALID_PATH;
34 }
35
36 const u32* data = reinterpret_cast<const u32*>(vec_data.data());
37 auto media_type = static_cast<MediaType>(data[0]);
38
39 if (media_type != MediaType::SDMC && media_type != MediaType::GameCard) {
40 LOG_ERROR(Service_FS, "Unsupported media type %u", static_cast<u32>(media_type));
41
42 // Note: this is strange, but the error code was verified with a real 3DS
43 return ERROR_UNSUPPORTED_OPEN_FLAGS;
44 }
45
46 return MakeResult<std::tuple<MediaType, u64>>(media_type, program_id_reader(data));
47}
48
49ResultVal<std::tuple<MediaType, u64>> ParsePathPermitted(const Path& path) {
50 return ParsePath(path,
51 [](const u32* data) -> u64 { return (data[1] << 8) | 0x0004000000000000ULL; });
52}
53
54ResultVal<std::tuple<MediaType, u64>> ParsePathGeneral(const Path& path) {
55 return ParsePath(
56 path, [](const u32* data) -> u64 { return data[1] | (static_cast<u64>(data[2]) << 32); });
57}
58
59} // namespace
60
61ArchiveFactory_OtherSaveDataPermitted::ArchiveFactory_OtherSaveDataPermitted(
62 std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata)
63 : sd_savedata_source(sd_savedata) {}
64
65ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_OtherSaveDataPermitted::Open(
66 const Path& path) {
67 MediaType media_type;
68 u64 program_id;
69 CASCADE_RESULT(std::tie(media_type, program_id), ParsePathPermitted(path));
70
71 if (media_type == MediaType::GameCard) {
72 LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard");
73 return ERROR_GAMECARD_NOT_INSERTED;
74 }
75
76 return sd_savedata_source->Open(program_id);
77}
78
79ResultCode ArchiveFactory_OtherSaveDataPermitted::Format(
80 const Path& path, const FileSys::ArchiveFormatInfo& format_info) {
81 LOG_ERROR(Service_FS, "Attempted to format a OtherSaveDataPermitted archive.");
82 return ERROR_INVALID_PATH;
83}
84
85ResultVal<ArchiveFormatInfo> ArchiveFactory_OtherSaveDataPermitted::GetFormatInfo(
86 const Path& path) const {
87 MediaType media_type;
88 u64 program_id;
89 CASCADE_RESULT(std::tie(media_type, program_id), ParsePathPermitted(path));
90
91 if (media_type == MediaType::GameCard) {
92 LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard");
93 return ERROR_GAMECARD_NOT_INSERTED;
94 }
95
96 return sd_savedata_source->GetFormatInfo(program_id);
97}
98
99ArchiveFactory_OtherSaveDataGeneral::ArchiveFactory_OtherSaveDataGeneral(
100 std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata)
101 : sd_savedata_source(sd_savedata) {}
102
103ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_OtherSaveDataGeneral::Open(
104 const Path& path) {
105 MediaType media_type;
106 u64 program_id;
107 CASCADE_RESULT(std::tie(media_type, program_id), ParsePathGeneral(path));
108
109 if (media_type == MediaType::GameCard) {
110 LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard");
111 return ERROR_GAMECARD_NOT_INSERTED;
112 }
113
114 return sd_savedata_source->Open(program_id);
115}
116
117ResultCode ArchiveFactory_OtherSaveDataGeneral::Format(
118 const Path& path, const FileSys::ArchiveFormatInfo& format_info) {
119 MediaType media_type;
120 u64 program_id;
121 CASCADE_RESULT(std::tie(media_type, program_id), ParsePathGeneral(path));
122
123 if (media_type == MediaType::GameCard) {
124 LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard");
125 return ERROR_GAMECARD_NOT_INSERTED;
126 }
127
128 return sd_savedata_source->Format(program_id, format_info);
129}
130
131ResultVal<ArchiveFormatInfo> ArchiveFactory_OtherSaveDataGeneral::GetFormatInfo(
132 const Path& path) const {
133 MediaType media_type;
134 u64 program_id;
135 CASCADE_RESULT(std::tie(media_type, program_id), ParsePathGeneral(path));
136
137 if (media_type == MediaType::GameCard) {
138 LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard");
139 return ERROR_GAMECARD_NOT_INSERTED;
140 }
141
142 return sd_savedata_source->GetFormatInfo(program_id);
143}
144
145} // namespace FileSys
diff --git a/src/core/file_sys/archive_other_savedata.h b/src/core/file_sys/archive_other_savedata.h
new file mode 100644
index 000000000..d80725158
--- /dev/null
+++ b/src/core/file_sys/archive_other_savedata.h
@@ -0,0 +1,52 @@
1// Copyright 2016 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "core/file_sys/archive_source_sd_savedata.h"
8
9////////////////////////////////////////////////////////////////////////////////////////////////////
10// FileSys namespace
11
12namespace FileSys {
13
14/// File system interface to the OtherSaveDataPermitted archive
15class ArchiveFactory_OtherSaveDataPermitted final : public ArchiveFactory {
16public:
17 explicit ArchiveFactory_OtherSaveDataPermitted(
18 std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata_source);
19
20 std::string GetName() const override {
21 return "OtherSaveDataPermitted";
22 }
23
24 ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override;
25 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override;
26 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override;
27
28private:
29 std::string mount_point;
30 std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata_source;
31};
32
33/// File system interface to the OtherSaveDataGeneral archive
34class ArchiveFactory_OtherSaveDataGeneral final : public ArchiveFactory {
35public:
36 explicit ArchiveFactory_OtherSaveDataGeneral(
37 std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata_source);
38
39 std::string GetName() const override {
40 return "OtherSaveDataGeneral";
41 }
42
43 ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override;
44 ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override;
45 ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override;
46
47private:
48 std::string mount_point;
49 std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata_source;
50};
51
52} // namespace FileSys
diff --git a/src/core/file_sys/errors.h b/src/core/file_sys/errors.h
index fd1b07df0..4d5f62b08 100644
--- a/src/core/file_sys/errors.h
+++ b/src/core/file_sys/errors.h
@@ -36,5 +36,8 @@ const ResultCode ERROR_ALREADY_EXISTS(ErrorDescription::FS_AlreadyExists, ErrorM
36 ErrorSummary::NothingHappened, ErrorLevel::Status); 36 ErrorSummary::NothingHappened, ErrorLevel::Status);
37const ResultCode ERROR_DIRECTORY_NOT_EMPTY(ErrorDescription::FS_DirectoryNotEmpty, ErrorModule::FS, 37const ResultCode ERROR_DIRECTORY_NOT_EMPTY(ErrorDescription::FS_DirectoryNotEmpty, ErrorModule::FS,
38 ErrorSummary::Canceled, ErrorLevel::Status); 38 ErrorSummary::Canceled, ErrorLevel::Status);
39const ResultCode ERROR_GAMECARD_NOT_INSERTED(ErrorDescription::FS_GameCardNotInserted,
40 ErrorModule::FS, ErrorSummary::NotFound,
41 ErrorLevel::Status);
39 42
40} // namespace FileSys 43} // namespace FileSys
diff --git a/src/core/hle/result.h b/src/core/hle/result.h
index f7356f9d8..8d29117a8 100644
--- a/src/core/hle/result.h
+++ b/src/core/hle/result.h
@@ -22,6 +22,7 @@ enum class ErrorDescription : u32 {
22 FS_ArchiveNotMounted = 101, 22 FS_ArchiveNotMounted = 101,
23 FS_FileNotFound = 112, 23 FS_FileNotFound = 112,
24 FS_PathNotFound = 113, 24 FS_PathNotFound = 113,
25 FS_GameCardNotInserted = 141,
25 FS_NotFound = 120, 26 FS_NotFound = 120,
26 FS_FileAlreadyExists = 180, 27 FS_FileAlreadyExists = 180,
27 FS_DirectoryAlreadyExists = 185, 28 FS_DirectoryAlreadyExists = 185,
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp
index a067e9262..bef75f5df 100644
--- a/src/core/hle/service/fs/archive.cpp
+++ b/src/core/hle/service/fs/archive.cpp
@@ -16,6 +16,7 @@
16#include "core/file_sys/archive_backend.h" 16#include "core/file_sys/archive_backend.h"
17#include "core/file_sys/archive_extsavedata.h" 17#include "core/file_sys/archive_extsavedata.h"
18#include "core/file_sys/archive_ncch.h" 18#include "core/file_sys/archive_ncch.h"
19#include "core/file_sys/archive_other_savedata.h"
19#include "core/file_sys/archive_savedata.h" 20#include "core/file_sys/archive_savedata.h"
20#include "core/file_sys/archive_sdmc.h" 21#include "core/file_sys/archive_sdmc.h"
21#include "core/file_sys/archive_sdmcwriteonly.h" 22#include "core/file_sys/archive_sdmcwriteonly.h"
@@ -538,6 +539,14 @@ void RegisterArchiveTypes() {
538 auto sd_savedata_source = std::make_shared<FileSys::ArchiveSource_SDSaveData>(sdmc_directory); 539 auto sd_savedata_source = std::make_shared<FileSys::ArchiveSource_SDSaveData>(sdmc_directory);
539 auto savedata_factory = std::make_unique<FileSys::ArchiveFactory_SaveData>(sd_savedata_source); 540 auto savedata_factory = std::make_unique<FileSys::ArchiveFactory_SaveData>(sd_savedata_source);
540 RegisterArchiveType(std::move(savedata_factory), ArchiveIdCode::SaveData); 541 RegisterArchiveType(std::move(savedata_factory), ArchiveIdCode::SaveData);
542 auto other_savedata_permitted_factory =
543 std::make_unique<FileSys::ArchiveFactory_OtherSaveDataPermitted>(sd_savedata_source);
544 RegisterArchiveType(std::move(other_savedata_permitted_factory),
545 ArchiveIdCode::OtherSaveDataPermitted);
546 auto other_savedata_general_factory =
547 std::make_unique<FileSys::ArchiveFactory_OtherSaveDataGeneral>(sd_savedata_source);
548 RegisterArchiveType(std::move(other_savedata_general_factory),
549 ArchiveIdCode::OtherSaveDataGeneral);
541 550
542 auto extsavedata_factory = 551 auto extsavedata_factory =
543 std::make_unique<FileSys::ArchiveFactory_ExtSaveData>(sdmc_directory, false); 552 std::make_unique<FileSys::ArchiveFactory_ExtSaveData>(sdmc_directory, false);
diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h
index d0220db17..87089bd92 100644
--- a/src/core/hle/service/fs/archive.h
+++ b/src/core/hle/service/fs/archive.h
@@ -34,6 +34,8 @@ enum class ArchiveIdCode : u32 {
34 SDMC = 0x00000009, 34 SDMC = 0x00000009,
35 SDMCWriteOnly = 0x0000000A, 35 SDMCWriteOnly = 0x0000000A,
36 NCCH = 0x2345678A, 36 NCCH = 0x2345678A,
37 OtherSaveDataGeneral = 0x567890B2,
38 OtherSaveDataPermitted = 0x567890B4,
37}; 39};
38 40
39/// Media types for the archives 41/// Media types for the archives