summaryrefslogtreecommitdiff
path: root/src/core/hle
diff options
context:
space:
mode:
authorGravatar bunnei2015-03-22 14:58:38 -0400
committerGravatar bunnei2015-03-22 14:58:38 -0400
commit03ceb7adf978693728eaae42d4cc8ccb9ff6913b (patch)
treecca5e66af529021ea7a7eedb7a61e56e6dde241c /src/core/hle
parentMerge pull request #669 from lioncash/cruft (diff)
parentService/FS: Document and log some unknown values. (diff)
downloadyuzu-03ceb7adf978693728eaae42d4cc8ccb9ff6913b.tar.gz
yuzu-03ceb7adf978693728eaae42d4cc8ccb9ff6913b.tar.xz
yuzu-03ceb7adf978693728eaae42d4cc8ccb9ff6913b.zip
Merge pull request #656 from Subv/nz
Services/FS: Implemented DeleteExtSaveData, CreateSystemSaveData and Del...
Diffstat (limited to 'src/core/hle')
-rw-r--r--src/core/hle/service/fs/archive.cpp74
-rw-r--r--src/core/hle/service/fs/archive.h34
-rw-r--r--src/core/hle/service/fs/fs_user.cpp105
3 files changed, 189 insertions, 24 deletions
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp
index 9da2e7aa2..b0fd834c7 100644
--- a/src/core/hle/service/fs/archive.cpp
+++ b/src/core/hle/service/fs/archive.cpp
@@ -395,28 +395,72 @@ ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::Path& path) {
395 return archive_itr->second->Format(path); 395 return archive_itr->second->Format(path);
396} 396}
397 397
398ResultCode CreateExtSaveData(u32 high, u32 low) { 398ResultCode CreateExtSaveData(MediaType media_type, u32 high, u32 low) {
399 // Construct the binary path to the archive first 399 // Construct the binary path to the archive first
400 std::vector<u8> binary_path; 400 FileSys::Path path = FileSys::ConstructExtDataBinaryPath(static_cast<u32>(media_type), high, low);
401 binary_path.reserve(12); 401
402 // The first word is all zero to specify a NAND archive 402 std::string media_type_directory;
403 for (unsigned i = 0; i < 4; ++i) 403 if (media_type == MediaType::NAND) {
404 binary_path.push_back(0); 404 media_type_directory = FileUtil::GetUserPath(D_NAND_IDX);
405 // Next is the low word 405 } else if (media_type == MediaType::SDMC) {
406 for (unsigned i = 0; i < 4; ++i) 406 media_type_directory = FileUtil::GetUserPath(D_SDMC_IDX);
407 binary_path.push_back((low >> (8 * i)) & 0xFF); 407 } else {
408 // Next is the high word 408 LOG_ERROR(Service_FS, "Unsupported media type %u", media_type);
409 for (unsigned i = 0; i < 4; ++i) 409 return ResultCode(-1); // TODO(Subv): Find the right error code
410 binary_path.push_back((high >> i) & 0xFF); 410 }
411 FileSys::Path path(binary_path); 411
412 std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX); 412 std::string base_path = FileSys::GetExtDataContainerPath(media_type_directory, media_type == MediaType::NAND);
413 std::string base_path = FileSys::GetExtDataContainerPath(nand_directory, true);
414 std::string extsavedata_path = FileSys::GetExtSaveDataPath(base_path, path); 413 std::string extsavedata_path = FileSys::GetExtSaveDataPath(base_path, path);
415 if (!FileUtil::CreateFullPath(extsavedata_path)) 414 if (!FileUtil::CreateFullPath(extsavedata_path))
416 return ResultCode(-1); // TODO(Subv): Find the right error code 415 return ResultCode(-1); // TODO(Subv): Find the right error code
417 return RESULT_SUCCESS; 416 return RESULT_SUCCESS;
418} 417}
419 418
419ResultCode DeleteExtSaveData(MediaType media_type, u32 high, u32 low) {
420 // Construct the binary path to the archive first
421 FileSys::Path path = FileSys::ConstructExtDataBinaryPath(static_cast<u32>(media_type), high, low);
422
423 std::string media_type_directory;
424 if (media_type == MediaType::NAND) {
425 media_type_directory = FileUtil::GetUserPath(D_NAND_IDX);
426 } else if (media_type == MediaType::SDMC) {
427 media_type_directory = FileUtil::GetUserPath(D_SDMC_IDX);
428 } else {
429 LOG_ERROR(Service_FS, "Unsupported media type %u", media_type);
430 return ResultCode(-1); // TODO(Subv): Find the right error code
431 }
432
433 std::string base_path = FileSys::GetExtDataContainerPath(media_type_directory, media_type == MediaType::NAND);
434 std::string extsavedata_path = FileSys::GetExtSaveDataPath(base_path, path);
435 if (!FileUtil::DeleteDirRecursively(extsavedata_path))
436 return ResultCode(-1); // TODO(Subv): Find the right error code
437 return RESULT_SUCCESS;
438}
439
440ResultCode DeleteSystemSaveData(u32 high, u32 low) {
441 // Construct the binary path to the archive first
442 FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
443
444 std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
445 std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
446 std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
447 if (!FileUtil::DeleteDirRecursively(systemsavedata_path))
448 return ResultCode(-1); // TODO(Subv): Find the right error code
449 return RESULT_SUCCESS;
450}
451
452ResultCode CreateSystemSaveData(u32 high, u32 low) {
453 // Construct the binary path to the archive first
454 FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
455
456 std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
457 std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
458 std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
459 if (!FileUtil::CreateFullPath(systemsavedata_path))
460 return ResultCode(-1); // TODO(Subv): Find the right error code
461 return RESULT_SUCCESS;
462}
463
420/// Initialize archives 464/// Initialize archives
421void ArchiveInit() { 465void ArchiveInit() {
422 next_handle = 1; 466 next_handle = 1;
diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h
index c490327d0..b00f0fd60 100644
--- a/src/core/hle/service/fs/archive.h
+++ b/src/core/hle/service/fs/archive.h
@@ -35,6 +35,12 @@ enum class ArchiveIdCode : u32 {
35 SaveDataCheck = 0x2345678A, 35 SaveDataCheck = 0x2345678A,
36}; 36};
37 37
38/// Media types for the archives
39enum class MediaType : u32 {
40 NAND = 0,
41 SDMC = 1
42};
43
38typedef u64 ArchiveHandle; 44typedef u64 ArchiveHandle;
39 45
40class File : public Kernel::Session { 46class File : public Kernel::Session {
@@ -172,11 +178,37 @@ ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::Path& path = File
172 178
173/** 179/**
174 * Creates a blank SharedExtSaveData archive for the specified extdata ID 180 * Creates a blank SharedExtSaveData archive for the specified extdata ID
181 * @param media_type The media type of the archive to create (NAND / SDMC)
175 * @param high The high word of the extdata id to create 182 * @param high The high word of the extdata id to create
176 * @param low The low word of the extdata id to create 183 * @param low The low word of the extdata id to create
177 * @return ResultCode 0 on success or the corresponding code on error 184 * @return ResultCode 0 on success or the corresponding code on error
178 */ 185 */
179ResultCode CreateExtSaveData(u32 high, u32 low); 186ResultCode CreateExtSaveData(MediaType media_type, u32 high, u32 low);
187
188/**
189 * Deletes the SharedExtSaveData archive for the specified extdata ID
190 * @param media_type The media type of the archive to delete (NAND / SDMC)
191 * @param high The high word of the extdata id to delete
192 * @param low The low word of the extdata id to delete
193 * @return ResultCode 0 on success or the corresponding code on error
194 */
195ResultCode DeleteExtSaveData(MediaType media_type, u32 high, u32 low);
196
197/**
198 * Deletes the SystemSaveData archive folder for the specified save data id
199 * @param high The high word of the SystemSaveData archive to delete
200 * @param low The low word of the SystemSaveData archive to delete
201 * @return ResultCode 0 on success or the corresponding code on error
202 */
203ResultCode DeleteSystemSaveData(u32 high, u32 low);
204
205/**
206 * Creates the SystemSaveData archive folder for the specified save data id
207 * @param high The high word of the SystemSaveData archive to create
208 * @param low The low word of the SystemSaveData archive to create
209 * @return ResultCode 0 on success or the corresponding code on error
210 */
211ResultCode CreateSystemSaveData(u32 high, u32 low);
180 212
181/// Initialize archives 213/// Initialize archives
182void ArchiveInit(); 214void ArchiveInit();
diff --git a/src/core/hle/service/fs/fs_user.cpp b/src/core/hle/service/fs/fs_user.cpp
index eb312496e..d8d1d5547 100644
--- a/src/core/hle/service/fs/fs_user.cpp
+++ b/src/core/hle/service/fs/fs_user.cpp
@@ -490,25 +490,65 @@ static void FormatThisUserSaveData(Service::Interface* self) {
490/** 490/**
491 * FS_User::CreateExtSaveData service function 491 * FS_User::CreateExtSaveData service function
492 * Inputs: 492 * Inputs:
493 * 0: 0x08510242 493 * 0 : 0x08510242
494 * 1: High word of the saveid to create 494 * 1 : Media type (NAND / SDMC)
495 * 2: Low word of the saveid to create 495 * 2 : Low word of the saveid to create
496 * 3 : High word of the saveid to create
497 * 4 : Unknown
498 * 5 : Unknown
499 * 6 : Unknown
500 * 7 : Unknown
501 * 8 : Unknown
502 * 9 : Unknown
503 * 10: Unknown
504 * 11: Unknown
496 * Outputs: 505 * Outputs:
497 * 1 : Result of function, 0 on success, otherwise error code 506 * 1 : Result of function, 0 on success, otherwise error code
498 */ 507 */
499static void CreateExtSaveData(Service::Interface* self) { 508static void CreateExtSaveData(Service::Interface* self) {
500 // TODO(Subv): Figure out the other parameters. 509 // TODO(Subv): Figure out the other parameters.
501 u32* cmd_buff = Kernel::GetCommandBuffer(); 510 u32* cmd_buff = Kernel::GetCommandBuffer();
502 u32 save_high = cmd_buff[1]; 511 MediaType media_type = static_cast<MediaType>(cmd_buff[1] & 0xFF);
503 u32 save_low = cmd_buff[2]; 512 u32 save_low = cmd_buff[2];
504 // TODO(Subv): For now it is assumed that only SharedExtSaveData can be created like this 513 u32 save_high = cmd_buff[3];
505 cmd_buff[1] = CreateExtSaveData(save_high, save_low).raw; 514
515 LOG_WARNING(Service_FS, "(STUBBED) savedata_high=%08X savedata_low=%08X cmd_buff[3]=%08X "
516 "cmd_buff[4]=%08X cmd_buff[5]=%08X cmd_buff[6]=%08X cmd_buff[7]=%08X cmd_buff[8]=%08X "
517 "cmd_buff[9]=%08X cmd_buff[10]=%08X cmd_buff[11]=%08X", save_high, save_low,
518 cmd_buff[3], cmd_buff[4], cmd_buff[5], cmd_buff[6], cmd_buff[7], cmd_buff[8], cmd_buff[9],
519 cmd_buff[10], cmd_buff[11]);
520
521 cmd_buff[1] = CreateExtSaveData(media_type, save_high, save_low).raw;
522}
523
524/**
525 * FS_User::DeleteExtSaveData service function
526 * Inputs:
527 * 0 : 0x08520100
528 * 1 : Media type (NAND / SDMC)
529 * 2 : Low word of the saveid to create
530 * 3 : High word of the saveid to create
531 * 4 : Unknown
532 * Outputs:
533 * 1 : Result of function, 0 on success, otherwise error code
534 */
535static void DeleteExtSaveData(Service::Interface* self) {
536 u32* cmd_buff = Kernel::GetCommandBuffer();
537 MediaType media_type = static_cast<MediaType>(cmd_buff[1] & 0xFF);
538 u32 save_low = cmd_buff[2];
539 u32 save_high = cmd_buff[3];
540 u32 unknown = cmd_buff[4]; // TODO(Subv): Figure out what this is
541
542 LOG_WARNING(Service_FS, "(STUBBED) save_low=%08X save_high=%08X media_type=%08X unknown=%08X",
543 save_low, save_high, cmd_buff[1] & 0xFF, unknown);
544
545 cmd_buff[1] = DeleteExtSaveData(media_type, save_high, save_low).raw;
506} 546}
507 547
508/** 548/**
509 * FS_User::CardSlotIsInserted service function. 549 * FS_User::CardSlotIsInserted service function.
510 * Inputs: 550 * Inputs:
511 * 0: 0x08210000 551 * 0 : 0x08210000
512 * Outputs: 552 * Outputs:
513 * 1 : Result of function, 0 on success, otherwise error code 553 * 1 : Result of function, 0 on success, otherwise error code
514 * 2 : Whether there is a game card inserted into the slot or not. 554 * 2 : Whether there is a game card inserted into the slot or not.
@@ -520,6 +560,53 @@ static void CardSlotIsInserted(Service::Interface* self) {
520 LOG_WARNING(Service_FS, "(STUBBED) called"); 560 LOG_WARNING(Service_FS, "(STUBBED) called");
521} 561}
522 562
563/**
564 * FS_User::DeleteSystemSaveData service function.
565 * Inputs:
566 * 0 : 0x08570080
567 * 1 : High word of the SystemSaveData id to delete
568 * 2 : Low word of the SystemSaveData id to delete
569 * Outputs:
570 * 1 : Result of function, 0 on success, otherwise error code
571 */
572static void DeleteSystemSaveData(Service::Interface* self) {
573 u32* cmd_buff = Kernel::GetCommandBuffer();
574 u32 savedata_high = cmd_buff[1];
575 u32 savedata_low = cmd_buff[2];
576
577 cmd_buff[1] = DeleteSystemSaveData(savedata_high, savedata_low).raw;
578}
579
580/**
581 * FS_User::CreateSystemSaveData service function.
582 * Inputs:
583 * 0 : 0x08560240
584 * 1 : High word of the SystemSaveData id to create
585 * 2 : Low word of the SystemSaveData id to create
586 * 3 : Unknown
587 * 4 : Unknown
588 * 5 : Unknown
589 * 6 : Unknown
590 * 7 : Unknown
591 * 8 : Unknown
592 * 9 : Unknown (Memory address)
593 * Outputs:
594 * 1 : Result of function, 0 on success, otherwise error code
595 */
596static void CreateSystemSaveData(Service::Interface* self) {
597 // TODO(Subv): Figure out the other parameters.
598 u32* cmd_buff = Kernel::GetCommandBuffer();
599 u32 savedata_high = cmd_buff[1];
600 u32 savedata_low = cmd_buff[2];
601
602 LOG_WARNING(Service_FS, "(STUBBED) savedata_high=%08X savedata_low=%08X cmd_buff[3]=%08X "
603 "cmd_buff[4]=%08X cmd_buff[5]=%08X cmd_buff[6]=%08X cmd_buff[7]=%08X cmd_buff[8]=%08X "
604 "cmd_buff[9]=%08X", savedata_high, savedata_low, cmd_buff[3], cmd_buff[4], cmd_buff[5],
605 cmd_buff[6], cmd_buff[7], cmd_buff[8], cmd_buff[9]);
606
607 cmd_buff[1] = CreateSystemSaveData(savedata_high, savedata_low).raw;
608}
609
523const Interface::FunctionInfo FunctionTable[] = { 610const Interface::FunctionInfo FunctionTable[] = {
524 {0x000100C6, nullptr, "Dummy1"}, 611 {0x000100C6, nullptr, "Dummy1"},
525 {0x040100C4, nullptr, "Control"}, 612 {0x040100C4, nullptr, "Control"},
@@ -604,7 +691,9 @@ const Interface::FunctionInfo FunctionTable[] = {
604 {0x084F0102, nullptr, "ReadSpecialFile"}, 691 {0x084F0102, nullptr, "ReadSpecialFile"},
605 {0x08500040, nullptr, "GetSpecialFileSize"}, 692 {0x08500040, nullptr, "GetSpecialFileSize"},
606 {0x08510242, CreateExtSaveData, "CreateExtSaveData"}, 693 {0x08510242, CreateExtSaveData, "CreateExtSaveData"},
607 {0x08520100, nullptr, "DeleteExtSaveData"}, 694 {0x08520100, DeleteExtSaveData, "DeleteExtSaveData"},
695 {0x08560240, CreateSystemSaveData, "CreateSystemSaveData"},
696 {0x08570080, DeleteSystemSaveData, "DeleteSystemSaveData"},
608 {0x08580000, nullptr, "GetMovableSedHashedKeyYRandomData"}, 697 {0x08580000, nullptr, "GetMovableSedHashedKeyYRandomData"},
609 {0x08610042, nullptr, "InitializeWithSdkVersion"}, 698 {0x08610042, nullptr, "InitializeWithSdkVersion"},
610 {0x08620040, nullptr, "SetPriority"}, 699 {0x08620040, nullptr, "SetPriority"},