summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/CMakeLists.txt4
-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/archive_savedata.cpp79
-rw-r--r--src/core/file_sys/archive_savedata.h8
-rw-r--r--src/core/file_sys/archive_source_sd_savedata.cpp93
-rw-r--r--src/core/file_sys/archive_source_sd_savedata.h30
-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.cpp12
-rw-r--r--src/core/hle/service/fs/archive.h4
11 files changed, 351 insertions, 80 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 299f1f261..8ce141e6a 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -18,10 +18,12 @@ 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
24 file_sys/archive_sdmcwriteonly.cpp 25 file_sys/archive_sdmcwriteonly.cpp
26 file_sys/archive_source_sd_savedata.cpp
25 file_sys/archive_systemsavedata.cpp 27 file_sys/archive_systemsavedata.cpp
26 file_sys/disk_archive.cpp 28 file_sys/disk_archive.cpp
27 file_sys/ivfc_archive.cpp 29 file_sys/ivfc_archive.cpp
@@ -163,10 +165,12 @@ set(HEADERS
163 file_sys/archive_backend.h 165 file_sys/archive_backend.h
164 file_sys/archive_extsavedata.h 166 file_sys/archive_extsavedata.h
165 file_sys/archive_ncch.h 167 file_sys/archive_ncch.h
168 file_sys/archive_other_savedata.h
166 file_sys/archive_romfs.h 169 file_sys/archive_romfs.h
167 file_sys/archive_savedata.h 170 file_sys/archive_savedata.h
168 file_sys/archive_sdmc.h 171 file_sys/archive_sdmc.h
169 file_sys/archive_sdmcwriteonly.h 172 file_sys/archive_sdmcwriteonly.h
173 file_sys/archive_source_sd_savedata.h
170 file_sys/archive_systemsavedata.h 174 file_sys/archive_systemsavedata.h
171 file_sys/directory_backend.h 175 file_sys/directory_backend.h
172 file_sys/disk_archive.h 176 file_sys/disk_archive.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/archive_savedata.cpp b/src/core/file_sys/archive_savedata.cpp
index ecb44a215..61f7654f7 100644
--- a/src/core/file_sys/archive_savedata.cpp
+++ b/src/core/file_sys/archive_savedata.cpp
@@ -2,96 +2,29 @@
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 <algorithm>
6#include <memory>
7#include "common/common_types.h"
8#include "common/file_util.h"
9#include "common/logging/log.h"
10#include "common/string_util.h"
11#include "core/file_sys/archive_savedata.h" 5#include "core/file_sys/archive_savedata.h"
12#include "core/file_sys/savedata_archive.h"
13#include "core/hle/kernel/process.h" 6#include "core/hle/kernel/process.h"
14#include "core/hle/service/fs/archive.h"
15 7
16//////////////////////////////////////////////////////////////////////////////////////////////////// 8////////////////////////////////////////////////////////////////////////////////////////////////////
17// FileSys namespace 9// FileSys namespace
18 10
19namespace FileSys { 11namespace FileSys {
20 12
21static std::string GetSaveDataContainerPath(const std::string& sdmc_directory) { 13ArchiveFactory_SaveData::ArchiveFactory_SaveData(
22 return Common::StringFromFormat("%sNintendo 3DS/%s/%s/title/", sdmc_directory.c_str(), 14 std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata)
23 SYSTEM_ID.c_str(), SDCARD_ID.c_str()); 15 : sd_savedata_source(sd_savedata) {}
24}
25
26static std::string GetSaveDataPath(const std::string& mount_location, u64 program_id) {
27 u32 high = (u32)(program_id >> 32);
28 u32 low = (u32)(program_id & 0xFFFFFFFF);
29 return Common::StringFromFormat("%s%08x/%08x/data/00000001/", mount_location.c_str(), high,
30 low);
31}
32
33static std::string GetSaveDataMetadataPath(const std::string& mount_location, u64 program_id) {
34 u32 high = (u32)(program_id >> 32);
35 u32 low = (u32)(program_id & 0xFFFFFFFF);
36 return Common::StringFromFormat("%s%08x/%08x/data/00000001.metadata", mount_location.c_str(),
37 high, low);
38}
39
40ArchiveFactory_SaveData::ArchiveFactory_SaveData(const std::string& sdmc_directory)
41 : mount_point(GetSaveDataContainerPath(sdmc_directory)) {
42 LOG_INFO(Service_FS, "Directory %s set as SaveData.", this->mount_point.c_str());
43}
44 16
45ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveData::Open(const Path& path) { 17ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveData::Open(const Path& path) {
46 std::string concrete_mount_point = 18 return sd_savedata_source->Open(Kernel::g_current_process->codeset->program_id);
47 GetSaveDataPath(mount_point, Kernel::g_current_process->codeset->program_id);
48 if (!FileUtil::Exists(concrete_mount_point)) {
49 // When a SaveData archive is created for the first time, it is not yet formatted and the
50 // save file/directory structure expected by the game has not yet been initialized.
51 // Returning the NotFormatted error code will signal the game to provision the SaveData
52 // archive with the files and folders that it expects.
53 return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
54 ErrorSummary::InvalidState, ErrorLevel::Status);
55 }
56
57 auto archive = std::make_unique<SaveDataArchive>(std::move(concrete_mount_point));
58 return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
59} 19}
60 20
61ResultCode ArchiveFactory_SaveData::Format(const Path& path, 21ResultCode ArchiveFactory_SaveData::Format(const Path& path,
62 const FileSys::ArchiveFormatInfo& format_info) { 22 const FileSys::ArchiveFormatInfo& format_info) {
63 std::string concrete_mount_point = 23 return sd_savedata_source->Format(Kernel::g_current_process->codeset->program_id, format_info);
64 GetSaveDataPath(mount_point, Kernel::g_current_process->codeset->program_id);
65 FileUtil::DeleteDirRecursively(concrete_mount_point);
66 FileUtil::CreateFullPath(concrete_mount_point);
67
68 // Write the format metadata
69 std::string metadata_path =
70 GetSaveDataMetadataPath(mount_point, Kernel::g_current_process->codeset->program_id);
71 FileUtil::IOFile file(metadata_path, "wb");
72
73 if (file.IsOpen()) {
74 file.WriteBytes(&format_info, sizeof(format_info));
75 return RESULT_SUCCESS;
76 }
77 return RESULT_SUCCESS;
78} 24}
79 25
80ResultVal<ArchiveFormatInfo> ArchiveFactory_SaveData::GetFormatInfo(const Path& path) const { 26ResultVal<ArchiveFormatInfo> ArchiveFactory_SaveData::GetFormatInfo(const Path& path) const {
81 std::string metadata_path = 27 return sd_savedata_source->GetFormatInfo(Kernel::g_current_process->codeset->program_id);
82 GetSaveDataMetadataPath(mount_point, Kernel::g_current_process->codeset->program_id);
83 FileUtil::IOFile file(metadata_path, "rb");
84
85 if (!file.IsOpen()) {
86 LOG_ERROR(Service_FS, "Could not open metadata information for archive");
87 // TODO(Subv): Verify error code
88 return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
89 ErrorSummary::InvalidState, ErrorLevel::Status);
90 }
91
92 ArchiveFormatInfo info = {};
93 file.ReadBytes(&info, sizeof(info));
94 return MakeResult<ArchiveFormatInfo>(info);
95} 28}
96 29
97} // namespace FileSys 30} // namespace FileSys
diff --git a/src/core/file_sys/archive_savedata.h b/src/core/file_sys/archive_savedata.h
index 6a372865a..41aa6f189 100644
--- a/src/core/file_sys/archive_savedata.h
+++ b/src/core/file_sys/archive_savedata.h
@@ -4,10 +4,7 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <memory> 7#include "core/file_sys/archive_source_sd_savedata.h"
8#include <string>
9#include "core/file_sys/archive_backend.h"
10#include "core/hle/result.h"
11 8
12//////////////////////////////////////////////////////////////////////////////////////////////////// 9////////////////////////////////////////////////////////////////////////////////////////////////////
13// FileSys namespace 10// FileSys namespace
@@ -17,7 +14,7 @@ namespace FileSys {
17/// File system interface to the SaveData archive 14/// File system interface to the SaveData archive
18class ArchiveFactory_SaveData final : public ArchiveFactory { 15class ArchiveFactory_SaveData final : public ArchiveFactory {
19public: 16public:
20 ArchiveFactory_SaveData(const std::string& mount_point); 17 explicit ArchiveFactory_SaveData(std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata_source);
21 18
22 std::string GetName() const override { 19 std::string GetName() const override {
23 return "SaveData"; 20 return "SaveData";
@@ -30,6 +27,7 @@ public:
30 27
31private: 28private:
32 std::string mount_point; 29 std::string mount_point;
30 std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata_source;
33}; 31};
34 32
35} // namespace FileSys 33} // namespace FileSys
diff --git a/src/core/file_sys/archive_source_sd_savedata.cpp b/src/core/file_sys/archive_source_sd_savedata.cpp
new file mode 100644
index 000000000..2d8a950a3
--- /dev/null
+++ b/src/core/file_sys/archive_source_sd_savedata.cpp
@@ -0,0 +1,93 @@
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 "common/file_util.h"
6#include "common/logging/log.h"
7#include "common/string_util.h"
8#include "core/file_sys/archive_source_sd_savedata.h"
9#include "core/file_sys/savedata_archive.h"
10#include "core/hle/service/fs/archive.h"
11
12////////////////////////////////////////////////////////////////////////////////////////////////////
13// FileSys namespace
14
15namespace FileSys {
16
17namespace {
18
19std::string GetSaveDataContainerPath(const std::string& sdmc_directory) {
20 return Common::StringFromFormat("%sNintendo 3DS/%s/%s/title/", sdmc_directory.c_str(),
21 SYSTEM_ID.c_str(), SDCARD_ID.c_str());
22}
23
24std::string GetSaveDataPath(const std::string& mount_location, u64 program_id) {
25 u32 high = static_cast<u32>(program_id >> 32);
26 u32 low = static_cast<u32>(program_id & 0xFFFFFFFF);
27 return Common::StringFromFormat("%s%08x/%08x/data/00000001/", mount_location.c_str(), high,
28 low);
29}
30
31std::string GetSaveDataMetadataPath(const std::string& mount_location, u64 program_id) {
32 u32 high = static_cast<u32>(program_id >> 32);
33 u32 low = static_cast<u32>(program_id & 0xFFFFFFFF);
34 return Common::StringFromFormat("%s%08x/%08x/data/00000001.metadata", mount_location.c_str(),
35 high, low);
36}
37
38} // namespace
39
40ArchiveSource_SDSaveData::ArchiveSource_SDSaveData(const std::string& sdmc_directory)
41 : mount_point(GetSaveDataContainerPath(sdmc_directory)) {
42 LOG_INFO(Service_FS, "Directory %s set as SaveData.", mount_point.c_str());
43}
44
45ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveSource_SDSaveData::Open(u64 program_id) {
46 std::string concrete_mount_point = GetSaveDataPath(mount_point, program_id);
47 if (!FileUtil::Exists(concrete_mount_point)) {
48 // When a SaveData archive is created for the first time, it is not yet formatted and the
49 // 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
51 // archive with the files and folders that it expects.
52 return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
53 ErrorSummary::InvalidState, ErrorLevel::Status);
54 }
55
56 auto archive = std::make_unique<SaveDataArchive>(std::move(concrete_mount_point));
57 return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
58}
59
60ResultCode ArchiveSource_SDSaveData::Format(u64 program_id,
61 const FileSys::ArchiveFormatInfo& format_info) {
62 std::string concrete_mount_point = GetSaveDataPath(mount_point, program_id);
63 FileUtil::DeleteDirRecursively(concrete_mount_point);
64 FileUtil::CreateFullPath(concrete_mount_point);
65
66 // Write the format metadata
67 std::string metadata_path = GetSaveDataMetadataPath(mount_point, program_id);
68 FileUtil::IOFile file(metadata_path, "wb");
69
70 if (file.IsOpen()) {
71 file.WriteBytes(&format_info, sizeof(format_info));
72 return RESULT_SUCCESS;
73 }
74 return RESULT_SUCCESS;
75}
76
77ResultVal<ArchiveFormatInfo> ArchiveSource_SDSaveData::GetFormatInfo(u64 program_id) const {
78 std::string metadata_path = GetSaveDataMetadataPath(mount_point, program_id);
79 FileUtil::IOFile file(metadata_path, "rb");
80
81 if (!file.IsOpen()) {
82 LOG_ERROR(Service_FS, "Could not open metadata information for archive");
83 // TODO(Subv): Verify error code
84 return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS,
85 ErrorSummary::InvalidState, ErrorLevel::Status);
86 }
87
88 ArchiveFormatInfo info = {};
89 file.ReadBytes(&info, sizeof(info));
90 return MakeResult<ArchiveFormatInfo>(info);
91}
92
93} // namespace FileSys
diff --git a/src/core/file_sys/archive_source_sd_savedata.h b/src/core/file_sys/archive_source_sd_savedata.h
new file mode 100644
index 000000000..b33126c31
--- /dev/null
+++ b/src/core/file_sys/archive_source_sd_savedata.h
@@ -0,0 +1,30 @@
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 <memory>
8#include <string>
9#include "core/file_sys/archive_backend.h"
10#include "core/hle/result.h"
11
12////////////////////////////////////////////////////////////////////////////////////////////////////
13// FileSys namespace
14
15namespace FileSys {
16
17/// A common source of SD save data archive
18class ArchiveSource_SDSaveData {
19public:
20 explicit ArchiveSource_SDSaveData(const std::string& mount_point);
21
22 ResultVal<std::unique_ptr<ArchiveBackend>> Open(u64 program_id);
23 ResultCode Format(u64 program_id, const FileSys::ArchiveFormatInfo& format_info);
24 ResultVal<ArchiveFormatInfo> GetFormatInfo(u64 program_id) const;
25
26private:
27 std::string mount_point;
28};
29
30} // 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 4c29784e8..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"
@@ -535,8 +536,17 @@ void RegisterArchiveTypes() {
535 sdmc_directory.c_str()); 536 sdmc_directory.c_str());
536 537
537 // Create the SaveData archive 538 // Create the SaveData archive
538 auto savedata_factory = std::make_unique<FileSys::ArchiveFactory_SaveData>(sdmc_directory); 539 auto sd_savedata_source = std::make_shared<FileSys::ArchiveSource_SDSaveData>(sdmc_directory);
540 auto savedata_factory = std::make_unique<FileSys::ArchiveFactory_SaveData>(sd_savedata_source);
539 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);
540 550
541 auto extsavedata_factory = 551 auto extsavedata_factory =
542 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 21ed9717b..87089bd92 100644
--- a/src/core/hle/service/fs/archive.h
+++ b/src/core/hle/service/fs/archive.h
@@ -34,10 +34,12 @@ 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
40enum class MediaType : u32 { NAND = 0, SDMC = 1 }; 42enum class MediaType : u32 { NAND = 0, SDMC = 1, GameCard = 2 };
41 43
42typedef u64 ArchiveHandle; 44typedef u64 ArchiveHandle;
43 45