Merge pull request #656 from Subv/nz

Services/FS: Implemented DeleteExtSaveData, CreateSystemSaveData and Del...
This commit is contained in:
bunnei 2015-03-22 14:58:38 -04:00
commit 03ceb7adf9
7 changed files with 265 additions and 26 deletions

View file

@ -34,6 +34,27 @@ std::string GetExtDataContainerPath(const std::string& mount_point, bool shared)
SYSTEM_ID.c_str(), SDCARD_ID.c_str()); SYSTEM_ID.c_str(), SDCARD_ID.c_str());
} }
Path ConstructExtDataBinaryPath(u32 media_type, u32 high, u32 low) {
std::vector<u8> binary_path;
binary_path.reserve(12);
// Append each word byte by byte
// The first word is the media type
for (unsigned i = 0; i < 4; ++i)
binary_path.push_back((media_type >> (8 * i)) & 0xFF);
// Next is the low word
for (unsigned i = 0; i < 4; ++i)
binary_path.push_back((low >> (8 * i)) & 0xFF);
// Next is the high word
for (unsigned i = 0; i < 4; ++i)
binary_path.push_back((high >> (8 * i)) & 0xFF);
return { binary_path };
}
ArchiveFactory_ExtSaveData::ArchiveFactory_ExtSaveData(const std::string& mount_location, bool shared) ArchiveFactory_ExtSaveData::ArchiveFactory_ExtSaveData(const std::string& mount_location, bool shared)
: mount_point(GetExtDataContainerPath(mount_location, shared)) { : mount_point(GetExtDataContainerPath(mount_location, shared)) {
LOG_INFO(Service_FS, "Directory %s set as base for ExtSaveData.", mount_point.c_str()); LOG_INFO(Service_FS, "Directory %s set as base for ExtSaveData.", mount_point.c_str());

View file

@ -58,4 +58,14 @@ std::string GetExtSaveDataPath(const std::string& mount_point, const Path& path)
*/ */
std::string GetExtDataContainerPath(const std::string& mount_point, bool shared); std::string GetExtDataContainerPath(const std::string& mount_point, bool shared);
/**
* Constructs a FileSys::Path object that refers to the ExtData archive identified by
* the specified media type, high save id and low save id.
* @param media_type The media type where the archive is located (NAND / SDMC)
* @param high The high word of the save id for the archive
* @param low The low word of the save id for the archive
* @returns A FileSys::Path to the wanted archive
*/
Path ConstructExtDataBinaryPath(u32 media_type, u32 high, u32 low);
} // namespace FileSys } // namespace FileSys

View file

@ -17,7 +17,7 @@
namespace FileSys { namespace FileSys {
static std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& path) { std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& path) {
std::vector<u8> vec_data = path.AsBinary(); std::vector<u8> vec_data = path.AsBinary();
const u32* data = reinterpret_cast<const u32*>(vec_data.data()); const u32* data = reinterpret_cast<const u32*>(vec_data.data());
u32 save_low = data[1]; u32 save_low = data[1];
@ -25,10 +25,27 @@ static std::string GetSystemSaveDataPath(const std::string& mount_point, const P
return Common::StringFromFormat("%s%08X/%08X/", mount_point.c_str(), save_low, save_high); return Common::StringFromFormat("%s%08X/%08X/", mount_point.c_str(), save_low, save_high);
} }
static std::string GetSystemSaveDataContainerPath(const std::string& mount_point) { std::string GetSystemSaveDataContainerPath(const std::string& mount_point) {
return Common::StringFromFormat("%sdata/%s/sysdata/", mount_point.c_str(), SYSTEM_ID.c_str()); return Common::StringFromFormat("%sdata/%s/sysdata/", mount_point.c_str(), SYSTEM_ID.c_str());
} }
Path ConstructSystemSaveDataBinaryPath(u32 high, u32 low) {
std::vector<u8> binary_path;
binary_path.reserve(8);
// Append each word byte by byte
// First is the high word
for (unsigned i = 0; i < 4; ++i)
binary_path.push_back((high >> (8 * i)) & 0xFF);
// Next is the low word
for (unsigned i = 0; i < 4; ++i)
binary_path.push_back((low >> (8 * i)) & 0xFF);
return { binary_path };
}
ArchiveFactory_SystemSaveData::ArchiveFactory_SystemSaveData(const std::string& nand_path) ArchiveFactory_SystemSaveData::ArchiveFactory_SystemSaveData(const std::string& nand_path)
: base_path(GetSystemSaveDataContainerPath(nand_path)) { : base_path(GetSystemSaveDataContainerPath(nand_path)) {
} }
@ -46,6 +63,7 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(c
ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path) { ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path) {
std::string fullpath = GetSystemSaveDataPath(base_path, path); std::string fullpath = GetSystemSaveDataPath(base_path, path);
FileUtil::DeleteDirRecursively(fullpath);
FileUtil::CreateFullPath(fullpath); FileUtil::CreateFullPath(fullpath);
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }

View file

@ -28,4 +28,29 @@ private:
std::string base_path; std::string base_path;
}; };
/**
* Constructs a path to the concrete SystemSaveData archive in the host filesystem based on the
* input Path and base mount point.
* @param mount_point The base mount point of the SystemSaveData archives.
* @param path The path that identifies the requested concrete SystemSaveData archive.
* @returns The complete path to the specified SystemSaveData archive in the host filesystem
*/
std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& path);
/**
* Constructs a path to the base folder to hold concrete SystemSaveData archives in the host file system.
* @param mount_point The base folder where this folder resides, ie. SDMC or NAND.
* @returns The path to the base SystemSaveData archives' folder in the host file system
*/
std::string GetSystemSaveDataContainerPath(const std::string& mount_point);
/**
* Constructs a FileSys::Path object that refers to the SystemSaveData archive identified by
* the specified high save id and low save id.
* @param high The high word of the save id for the archive
* @param low The low word of the save id for the archive
* @returns A FileSys::Path to the wanted archive
*/
Path ConstructSystemSaveDataBinaryPath(u32 high, u32 low);
} // namespace FileSys } // namespace FileSys

View file

@ -395,28 +395,72 @@ ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::Path& path) {
return archive_itr->second->Format(path); return archive_itr->second->Format(path);
} }
ResultCode CreateExtSaveData(u32 high, u32 low) { ResultCode CreateExtSaveData(MediaType media_type, u32 high, u32 low) {
// Construct the binary path to the archive first // Construct the binary path to the archive first
std::vector<u8> binary_path; FileSys::Path path = FileSys::ConstructExtDataBinaryPath(static_cast<u32>(media_type), high, low);
binary_path.reserve(12);
// The first word is all zero to specify a NAND archive std::string media_type_directory;
for (unsigned i = 0; i < 4; ++i) if (media_type == MediaType::NAND) {
binary_path.push_back(0); media_type_directory = FileUtil::GetUserPath(D_NAND_IDX);
// Next is the low word } else if (media_type == MediaType::SDMC) {
for (unsigned i = 0; i < 4; ++i) media_type_directory = FileUtil::GetUserPath(D_SDMC_IDX);
binary_path.push_back((low >> (8 * i)) & 0xFF); } else {
// Next is the high word LOG_ERROR(Service_FS, "Unsupported media type %u", media_type);
for (unsigned i = 0; i < 4; ++i) return ResultCode(-1); // TODO(Subv): Find the right error code
binary_path.push_back((high >> i) & 0xFF); }
FileSys::Path path(binary_path);
std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX); std::string base_path = FileSys::GetExtDataContainerPath(media_type_directory, media_type == MediaType::NAND);
std::string base_path = FileSys::GetExtDataContainerPath(nand_directory, true);
std::string extsavedata_path = FileSys::GetExtSaveDataPath(base_path, path); std::string extsavedata_path = FileSys::GetExtSaveDataPath(base_path, path);
if (!FileUtil::CreateFullPath(extsavedata_path)) if (!FileUtil::CreateFullPath(extsavedata_path))
return ResultCode(-1); // TODO(Subv): Find the right error code return ResultCode(-1); // TODO(Subv): Find the right error code
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
ResultCode DeleteExtSaveData(MediaType media_type, u32 high, u32 low) {
// Construct the binary path to the archive first
FileSys::Path path = FileSys::ConstructExtDataBinaryPath(static_cast<u32>(media_type), high, low);
std::string media_type_directory;
if (media_type == MediaType::NAND) {
media_type_directory = FileUtil::GetUserPath(D_NAND_IDX);
} else if (media_type == MediaType::SDMC) {
media_type_directory = FileUtil::GetUserPath(D_SDMC_IDX);
} else {
LOG_ERROR(Service_FS, "Unsupported media type %u", media_type);
return ResultCode(-1); // TODO(Subv): Find the right error code
}
std::string base_path = FileSys::GetExtDataContainerPath(media_type_directory, media_type == MediaType::NAND);
std::string extsavedata_path = FileSys::GetExtSaveDataPath(base_path, path);
if (!FileUtil::DeleteDirRecursively(extsavedata_path))
return ResultCode(-1); // TODO(Subv): Find the right error code
return RESULT_SUCCESS;
}
ResultCode DeleteSystemSaveData(u32 high, u32 low) {
// Construct the binary path to the archive first
FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
if (!FileUtil::DeleteDirRecursively(systemsavedata_path))
return ResultCode(-1); // TODO(Subv): Find the right error code
return RESULT_SUCCESS;
}
ResultCode CreateSystemSaveData(u32 high, u32 low) {
// Construct the binary path to the archive first
FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
if (!FileUtil::CreateFullPath(systemsavedata_path))
return ResultCode(-1); // TODO(Subv): Find the right error code
return RESULT_SUCCESS;
}
/// Initialize archives /// Initialize archives
void ArchiveInit() { void ArchiveInit() {
next_handle = 1; next_handle = 1;

View file

@ -35,6 +35,12 @@ enum class ArchiveIdCode : u32 {
SaveDataCheck = 0x2345678A, SaveDataCheck = 0x2345678A,
}; };
/// Media types for the archives
enum class MediaType : u32 {
NAND = 0,
SDMC = 1
};
typedef u64 ArchiveHandle; typedef u64 ArchiveHandle;
class File : public Kernel::Session { class File : public Kernel::Session {
@ -172,11 +178,37 @@ ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::Path& path = File
/** /**
* Creates a blank SharedExtSaveData archive for the specified extdata ID * Creates a blank SharedExtSaveData archive for the specified extdata ID
* @param media_type The media type of the archive to create (NAND / SDMC)
* @param high The high word of the extdata id to create * @param high The high word of the extdata id to create
* @param low The low word of the extdata id to create * @param low The low word of the extdata id to create
* @return ResultCode 0 on success or the corresponding code on error * @return ResultCode 0 on success or the corresponding code on error
*/ */
ResultCode CreateExtSaveData(u32 high, u32 low); ResultCode CreateExtSaveData(MediaType media_type, u32 high, u32 low);
/**
* Deletes the SharedExtSaveData archive for the specified extdata ID
* @param media_type The media type of the archive to delete (NAND / SDMC)
* @param high The high word of the extdata id to delete
* @param low The low word of the extdata id to delete
* @return ResultCode 0 on success or the corresponding code on error
*/
ResultCode DeleteExtSaveData(MediaType media_type, u32 high, u32 low);
/**
* Deletes the SystemSaveData archive folder for the specified save data id
* @param high The high word of the SystemSaveData archive to delete
* @param low The low word of the SystemSaveData archive to delete
* @return ResultCode 0 on success or the corresponding code on error
*/
ResultCode DeleteSystemSaveData(u32 high, u32 low);
/**
* Creates the SystemSaveData archive folder for the specified save data id
* @param high The high word of the SystemSaveData archive to create
* @param low The low word of the SystemSaveData archive to create
* @return ResultCode 0 on success or the corresponding code on error
*/
ResultCode CreateSystemSaveData(u32 high, u32 low);
/// Initialize archives /// Initialize archives
void ArchiveInit(); void ArchiveInit();

View file

@ -491,18 +491,58 @@ static void FormatThisUserSaveData(Service::Interface* self) {
* FS_User::CreateExtSaveData service function * FS_User::CreateExtSaveData service function
* Inputs: * Inputs:
* 0 : 0x08510242 * 0 : 0x08510242
* 1: High word of the saveid to create * 1 : Media type (NAND / SDMC)
* 2 : Low word of the saveid to create * 2 : Low word of the saveid to create
* 3 : High word of the saveid to create
* 4 : Unknown
* 5 : Unknown
* 6 : Unknown
* 7 : Unknown
* 8 : Unknown
* 9 : Unknown
* 10: Unknown
* 11: Unknown
* Outputs: * Outputs:
* 1 : Result of function, 0 on success, otherwise error code * 1 : Result of function, 0 on success, otherwise error code
*/ */
static void CreateExtSaveData(Service::Interface* self) { static void CreateExtSaveData(Service::Interface* self) {
// TODO(Subv): Figure out the other parameters. // TODO(Subv): Figure out the other parameters.
u32* cmd_buff = Kernel::GetCommandBuffer(); u32* cmd_buff = Kernel::GetCommandBuffer();
u32 save_high = cmd_buff[1]; MediaType media_type = static_cast<MediaType>(cmd_buff[1] & 0xFF);
u32 save_low = cmd_buff[2]; u32 save_low = cmd_buff[2];
// TODO(Subv): For now it is assumed that only SharedExtSaveData can be created like this u32 save_high = cmd_buff[3];
cmd_buff[1] = CreateExtSaveData(save_high, save_low).raw;
LOG_WARNING(Service_FS, "(STUBBED) savedata_high=%08X savedata_low=%08X cmd_buff[3]=%08X "
"cmd_buff[4]=%08X cmd_buff[5]=%08X cmd_buff[6]=%08X cmd_buff[7]=%08X cmd_buff[8]=%08X "
"cmd_buff[9]=%08X cmd_buff[10]=%08X cmd_buff[11]=%08X", save_high, save_low,
cmd_buff[3], cmd_buff[4], cmd_buff[5], cmd_buff[6], cmd_buff[7], cmd_buff[8], cmd_buff[9],
cmd_buff[10], cmd_buff[11]);
cmd_buff[1] = CreateExtSaveData(media_type, save_high, save_low).raw;
}
/**
* FS_User::DeleteExtSaveData service function
* Inputs:
* 0 : 0x08520100
* 1 : Media type (NAND / SDMC)
* 2 : Low word of the saveid to create
* 3 : High word of the saveid to create
* 4 : Unknown
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
static void DeleteExtSaveData(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
MediaType media_type = static_cast<MediaType>(cmd_buff[1] & 0xFF);
u32 save_low = cmd_buff[2];
u32 save_high = cmd_buff[3];
u32 unknown = cmd_buff[4]; // TODO(Subv): Figure out what this is
LOG_WARNING(Service_FS, "(STUBBED) save_low=%08X save_high=%08X media_type=%08X unknown=%08X",
save_low, save_high, cmd_buff[1] & 0xFF, unknown);
cmd_buff[1] = DeleteExtSaveData(media_type, save_high, save_low).raw;
} }
/** /**
@ -520,6 +560,53 @@ static void CardSlotIsInserted(Service::Interface* self) {
LOG_WARNING(Service_FS, "(STUBBED) called"); LOG_WARNING(Service_FS, "(STUBBED) called");
} }
/**
* FS_User::DeleteSystemSaveData service function.
* Inputs:
* 0 : 0x08570080
* 1 : High word of the SystemSaveData id to delete
* 2 : Low word of the SystemSaveData id to delete
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
static void DeleteSystemSaveData(Service::Interface* self) {
u32* cmd_buff = Kernel::GetCommandBuffer();
u32 savedata_high = cmd_buff[1];
u32 savedata_low = cmd_buff[2];
cmd_buff[1] = DeleteSystemSaveData(savedata_high, savedata_low).raw;
}
/**
* FS_User::CreateSystemSaveData service function.
* Inputs:
* 0 : 0x08560240
* 1 : High word of the SystemSaveData id to create
* 2 : Low word of the SystemSaveData id to create
* 3 : Unknown
* 4 : Unknown
* 5 : Unknown
* 6 : Unknown
* 7 : Unknown
* 8 : Unknown
* 9 : Unknown (Memory address)
* Outputs:
* 1 : Result of function, 0 on success, otherwise error code
*/
static void CreateSystemSaveData(Service::Interface* self) {
// TODO(Subv): Figure out the other parameters.
u32* cmd_buff = Kernel::GetCommandBuffer();
u32 savedata_high = cmd_buff[1];
u32 savedata_low = cmd_buff[2];
LOG_WARNING(Service_FS, "(STUBBED) savedata_high=%08X savedata_low=%08X cmd_buff[3]=%08X "
"cmd_buff[4]=%08X cmd_buff[5]=%08X cmd_buff[6]=%08X cmd_buff[7]=%08X cmd_buff[8]=%08X "
"cmd_buff[9]=%08X", savedata_high, savedata_low, cmd_buff[3], cmd_buff[4], cmd_buff[5],
cmd_buff[6], cmd_buff[7], cmd_buff[8], cmd_buff[9]);
cmd_buff[1] = CreateSystemSaveData(savedata_high, savedata_low).raw;
}
const Interface::FunctionInfo FunctionTable[] = { const Interface::FunctionInfo FunctionTable[] = {
{0x000100C6, nullptr, "Dummy1"}, {0x000100C6, nullptr, "Dummy1"},
{0x040100C4, nullptr, "Control"}, {0x040100C4, nullptr, "Control"},
@ -604,7 +691,9 @@ const Interface::FunctionInfo FunctionTable[] = {
{0x084F0102, nullptr, "ReadSpecialFile"}, {0x084F0102, nullptr, "ReadSpecialFile"},
{0x08500040, nullptr, "GetSpecialFileSize"}, {0x08500040, nullptr, "GetSpecialFileSize"},
{0x08510242, CreateExtSaveData, "CreateExtSaveData"}, {0x08510242, CreateExtSaveData, "CreateExtSaveData"},
{0x08520100, nullptr, "DeleteExtSaveData"}, {0x08520100, DeleteExtSaveData, "DeleteExtSaveData"},
{0x08560240, CreateSystemSaveData, "CreateSystemSaveData"},
{0x08570080, DeleteSystemSaveData, "DeleteSystemSaveData"},
{0x08580000, nullptr, "GetMovableSedHashedKeyYRandomData"}, {0x08580000, nullptr, "GetMovableSedHashedKeyYRandomData"},
{0x08610042, nullptr, "InitializeWithSdkVersion"}, {0x08610042, nullptr, "InitializeWithSdkVersion"},
{0x08620040, nullptr, "SetPriority"}, {0x08620040, nullptr, "SetPriority"},