diff options
Diffstat (limited to 'src/core/hle')
-rw-r--r-- | src/core/hle/kernel/session.h | 12 | ||||
-rw-r--r-- | src/core/hle/result.h | 6 | ||||
-rw-r--r-- | src/core/hle/service/cfg/cfg.cpp | 5 | ||||
-rw-r--r-- | src/core/hle/service/fs/archive.cpp | 90 | ||||
-rw-r--r-- | src/core/hle/service/fs/archive.h | 17 | ||||
-rw-r--r-- | src/core/hle/service/fs/fs_user.cpp | 113 | ||||
-rw-r--r-- | src/core/hle/service/ptm/ptm.cpp | 2 | ||||
-rw-r--r-- | src/core/hle/service/soc_u.cpp | 13 |
8 files changed, 175 insertions, 83 deletions
diff --git a/src/core/hle/kernel/session.h b/src/core/hle/kernel/session.h index adaffcafe..6ddaf970e 100644 --- a/src/core/hle/kernel/session.h +++ b/src/core/hle/kernel/session.h @@ -16,23 +16,23 @@ namespace IPC { -inline u32 MakeHeader(u16 command_id, unsigned int regular_params, unsigned int translate_params) { +constexpr u32 MakeHeader(u16 command_id, unsigned int regular_params, unsigned int translate_params) { return ((u32)command_id << 16) | (((u32)regular_params & 0x3F) << 6) | (((u32)translate_params & 0x3F) << 0); } -inline u32 MoveHandleDesc(unsigned int num_handles = 1) { +constexpr u32 MoveHandleDesc(unsigned int num_handles = 1) { return 0x0 | ((num_handles - 1) << 26); } -inline u32 CopyHandleDesc(unsigned int num_handles = 1) { +constexpr u32 CopyHandleDesc(unsigned int num_handles = 1) { return 0x10 | ((num_handles - 1) << 26); } -inline u32 CallingPidDesc() { +constexpr u32 CallingPidDesc() { return 0x20; } -inline u32 StaticBufferDesc(u32 size, unsigned int buffer_id) { +constexpr u32 StaticBufferDesc(u32 size, unsigned int buffer_id) { return 0x2 | (size << 14) | ((buffer_id & 0xF) << 10); } @@ -42,7 +42,7 @@ enum MappedBufferPermissions { RW = R | W, }; -inline u32 MappedBufferDesc(u32 size, MappedBufferPermissions perms) { +constexpr u32 MappedBufferDesc(u32 size, MappedBufferPermissions perms) { return 0x8 | (size << 4) | (u32)perms; } diff --git a/src/core/hle/result.h b/src/core/hle/result.h index 69613fbbb..0cb76ba1c 100644 --- a/src/core/hle/result.h +++ b/src/core/hle/result.h @@ -19,8 +19,12 @@ enum class ErrorDescription : u32 { Success = 0, WrongAddress = 53, - FS_NotFound = 100, + FS_NotFound = 120, + FS_AlreadyExists = 190, + FS_InvalidOpenFlags = 230, + FS_NotAFile = 250, FS_NotFormatted = 340, ///< This is used by the FS service when creating a SaveData archive + FS_InvalidPath = 702, InvalidSection = 1000, TooLarge = 1001, NotAuthorized = 1002, diff --git a/src/core/hle/service/cfg/cfg.cpp b/src/core/hle/service/cfg/cfg.cpp index 4c82a58e4..525432957 100644 --- a/src/core/hle/service/cfg/cfg.cpp +++ b/src/core/hle/service/cfg/cfg.cpp @@ -310,7 +310,8 @@ ResultCode UpdateConfigNANDSavegame() { ResultCode FormatConfig() { ResultCode res = DeleteConfigNANDSaveFile(); - if (!res.IsSuccess()) + // The delete command fails if the file doesn't exist, so we have to check that too + if (!res.IsSuccess() && res.description != ErrorDescription::FS_NotFound) return res; // Delete the old data cfg_config_file_buffer.fill(0); @@ -407,7 +408,7 @@ void Init() { // If the archive didn't exist, create the files inside if (archive_result.Code().description == ErrorDescription::FS_NotFormatted) { // Format the archive to create the directories - Service::FS::FormatArchive(Service::FS::ArchiveIdCode::SystemSaveData, archive_path); + Service::FS::FormatArchive(Service::FS::ArchiveIdCode::SystemSaveData, FileSys::ArchiveFormatInfo(), archive_path); // Open it again to get a valid archive now that the folder exists archive_result = Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SystemSaveData, archive_path); diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index d64b3656a..590697e76 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -103,7 +103,18 @@ ResultVal<bool> File::SyncRequest() { u32 address = cmd_buff[5]; LOG_TRACE(Service_FS, "Read %s %s: offset=0x%llx length=%d address=0x%x", GetTypeName().c_str(), GetName().c_str(), offset, length, address); - cmd_buff[2] = static_cast<u32>(backend->Read(offset, length, Memory::GetPointer(address))); + + if (offset + length > backend->GetSize()) { + LOG_ERROR(Service_FS, "Reading from out of bounds offset=0x%llX length=0x%08X file_size=0x%llX", + offset, length, backend->GetSize()); + } + + ResultVal<size_t> read = backend->Read(offset, length, Memory::GetPointer(address)); + if (read.Failed()) { + cmd_buff[1] = read.Code().raw; + return read.Code(); + } + cmd_buff[2] = static_cast<u32>(*read); break; } @@ -116,7 +127,13 @@ ResultVal<bool> File::SyncRequest() { u32 address = cmd_buff[6]; LOG_TRACE(Service_FS, "Write %s %s: offset=0x%llx length=%d address=0x%x, flush=0x%x", GetTypeName().c_str(), GetName().c_str(), offset, length, address, flush); - cmd_buff[2] = static_cast<u32>(backend->Write(offset, length, flush != 0, Memory::GetPointer(address))); + + ResultVal<size_t> written = backend->Write(offset, length, flush != 0, Memory::GetPointer(address)); + if (written.Failed()) { + cmd_buff[1] = written.Code().raw; + return written.Code(); + } + cmd_buff[2] = static_cast<u32>(*written); break; } @@ -294,13 +311,11 @@ ResultVal<Kernel::SharedPtr<File>> OpenFileFromArchive(ArchiveHandle archive_han if (archive == nullptr) return ERR_INVALID_HANDLE; - std::unique_ptr<FileSys::FileBackend> backend = archive->OpenFile(path, mode); - if (backend == nullptr) { - return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, - ErrorSummary::NotFound, ErrorLevel::Status); - } + auto backend = archive->OpenFile(path, mode); + if (backend.Failed()) + return backend.Code(); - auto file = Kernel::SharedPtr<File>(new File(std::move(backend), path)); + auto file = Kernel::SharedPtr<File>(new File(backend.MoveFrom(), path)); return MakeResult<Kernel::SharedPtr<File>>(std::move(file)); } @@ -309,10 +324,7 @@ ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Pa if (archive == nullptr) return ERR_INVALID_HANDLE; - if (archive->DeleteFile(path)) - return RESULT_SUCCESS; - return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description - ErrorSummary::Canceled, ErrorLevel::Status); + return archive->DeleteFile(path); } ResultCode RenameFileBetweenArchives(ArchiveHandle src_archive_handle, const FileSys::Path& src_path, @@ -347,7 +359,7 @@ ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSy ErrorSummary::Canceled, ErrorLevel::Status); } -ResultCode CreateFileInArchive(ArchiveHandle archive_handle, const FileSys::Path& path, u32 file_size) { +ResultCode CreateFileInArchive(ArchiveHandle archive_handle, const FileSys::Path& path, u64 file_size) { ArchiveBackend* archive = GetArchive(archive_handle); if (archive == nullptr) return ERR_INVALID_HANDLE; @@ -395,7 +407,7 @@ ResultVal<Kernel::SharedPtr<Directory>> OpenDirectoryFromArchive(ArchiveHandle a std::unique_ptr<FileSys::DirectoryBackend> backend = archive->OpenDirectory(path); if (backend == nullptr) { - return ResultCode(ErrorDescription::NotFound, ErrorModule::FS, + return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Permanent); } @@ -410,49 +422,45 @@ ResultVal<u64> GetFreeBytesInArchive(ArchiveHandle archive_handle) { return MakeResult<u64>(archive->GetFreeBytes()); } -ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::Path& path) { +ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::ArchiveFormatInfo& format_info, const FileSys::Path& path) { auto archive_itr = id_code_map.find(id_code); if (archive_itr == id_code_map.end()) { return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error } - return archive_itr->second->Format(path); + return archive_itr->second->Format(path, format_info); +} + +ResultVal<FileSys::ArchiveFormatInfo> GetArchiveFormatInfo(ArchiveIdCode id_code, FileSys::Path& archive_path) { + auto archive = id_code_map.find(id_code); + if (archive == id_code_map.end()) { + return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error + } + + return archive->second->GetFormatInfo(archive_path); } -ResultCode CreateExtSaveData(MediaType media_type, u32 high, u32 low, VAddr icon_buffer, u32 icon_size) { +ResultCode CreateExtSaveData(MediaType media_type, u32 high, u32 low, VAddr icon_buffer, u32 icon_size, const FileSys::ArchiveFormatInfo& format_info) { // 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 + auto archive = id_code_map.find(media_type == MediaType::NAND ? ArchiveIdCode::SharedExtSaveData : ArchiveIdCode::ExtSaveData); + + if (archive == id_code_map.end()) { + return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error } - std::string base_path = FileSys::GetExtDataContainerPath(media_type_directory, media_type == MediaType::NAND); - std::string game_path = FileSys::GetExtSaveDataPath(base_path, path); - // These two folders are always created with the ExtSaveData - std::string user_path = game_path + "user/"; - std::string boss_path = game_path + "boss/"; - if (!FileUtil::CreateFullPath(user_path)) - return ResultCode(-1); // TODO(Subv): Find the right error code - if (!FileUtil::CreateFullPath(boss_path)) - return ResultCode(-1); // TODO(Subv): Find the right error code + auto ext_savedata = static_cast<FileSys::ArchiveFactory_ExtSaveData*>(archive->second.get()); + + ResultCode result = ext_savedata->Format(path, format_info); + if (result.IsError()) + return result; u8* smdh_icon = Memory::GetPointer(icon_buffer); if (!smdh_icon) return ResultCode(-1); // TODO(Subv): Find the right error code - // Create the icon - FileUtil::IOFile icon_file(game_path + "icon", "wb+"); - if (!icon_file.IsGood()) - return ResultCode(-1); // TODO(Subv): Find the right error code - - icon_file.WriteBytes(smdh_icon, icon_size); + ext_savedata->WriteIcon(path, smdh_icon, icon_size); return RESULT_SUCCESS; } @@ -473,7 +481,7 @@ ResultCode DeleteExtSaveData(MediaType media_type, u32 high, u32 low) { // Delete all directories (/user, /boss) and the icon file. 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)) + if (FileUtil::Exists(extsavedata_path) && !FileUtil::DeleteDirRecursively(extsavedata_path)) return ResultCode(-1); // TODO(Subv): Find the right error code return RESULT_SUCCESS; } diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h index 952deb4d4..006606740 100644 --- a/src/core/hle/service/fs/archive.h +++ b/src/core/hle/service/fs/archive.h @@ -136,7 +136,7 @@ ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSy * @param file_size The size of the new file, filled with zeroes * @return File creation result code */ -ResultCode CreateFileInArchive(ArchiveHandle archive_handle, const FileSys::Path& path, u32 file_size); +ResultCode CreateFileInArchive(ArchiveHandle archive_handle, const FileSys::Path& path, u64 file_size); /** * Create a Directory from an Archive @@ -177,10 +177,20 @@ ResultVal<u64> GetFreeBytesInArchive(ArchiveHandle archive_handle); * Erases the contents of the physical folder that contains the archive * identified by the specified id code and path * @param id_code The id of the archive to format + * @param format_info Format information about the new archive * @param path The path to the archive, if relevant. * @return ResultCode 0 on success or the corresponding code on error */ -ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::Path& path = FileSys::Path()); +ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::ArchiveFormatInfo& format_info, const FileSys::Path& path = FileSys::Path()); + +/** + * Retrieves the format info about the archive of the specified type and path. + * The format info is supplied by the client code when creating archives. + * @param id_code The id of the archive + * @param archive_path The path of the archive, if relevant + * @return The format info of the archive, or the corresponding error code if failed. + */ +ResultVal<FileSys::ArchiveFormatInfo> GetArchiveFormatInfo(ArchiveIdCode id_code, FileSys::Path& archive_path); /** * Creates a blank SharedExtSaveData archive for the specified extdata ID @@ -189,9 +199,10 @@ ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::Path& path = File * @param low The low word of the extdata id to create * @param icon_buffer VAddr of the SMDH icon for this ExtSaveData * @param icon_size Size of the SMDH icon + * @param format_info Format information about the new archive * @return ResultCode 0 on success or the corresponding code on error */ -ResultCode CreateExtSaveData(MediaType media_type, u32 high, u32 low, VAddr icon_buffer, u32 icon_size); +ResultCode CreateExtSaveData(MediaType media_type, u32 high, u32 low, VAddr icon_buffer, u32 icon_size, const FileSys::ArchiveFormatInfo& format_info); /** * Deletes the SharedExtSaveData archive for the specified extdata ID diff --git a/src/core/hle/service/fs/fs_user.cpp b/src/core/hle/service/fs/fs_user.cpp index e6c1f3616..3ec7ceb30 100644 --- a/src/core/hle/service/fs/fs_user.cpp +++ b/src/core/hle/service/fs/fs_user.cpp @@ -234,7 +234,7 @@ static void DeleteDirectory(Service::Interface* self) { * 3 : Archive handle upper word * 4 : File path string type * 5 : File path string size - * 7 : File size (filled with zeroes) + * 7-8 : File size * 10: File path string data * Outputs: * 1 : Result of function, 0 on success, otherwise error code @@ -245,12 +245,12 @@ static void CreateFile(Service::Interface* self) { ArchiveHandle archive_handle = MakeArchiveHandle(cmd_buff[2], cmd_buff[3]); auto filename_type = static_cast<FileSys::LowPathType>(cmd_buff[4]); u32 filename_size = cmd_buff[5]; - u32 file_size = cmd_buff[7]; + u64 file_size = ((u64)cmd_buff[8] << 32) | cmd_buff[7]; u32 filename_ptr = cmd_buff[10]; FileSys::Path file_path(filename_type, filename_size, filename_ptr); - LOG_DEBUG(Service_FS, "type=%d size=%d data=%s", filename_type, filename_size, file_path.DebugStr().c_str()); + LOG_DEBUG(Service_FS, "type=%d size=%llu data=%s", filename_type, filename_size, file_path.DebugStr().c_str()); cmd_buff[1] = CreateFileInArchive(archive_handle, file_path, file_size).raw; } @@ -443,17 +443,22 @@ static void IsSdmcWriteable(Service::Interface* self) { * Inputs: * 0 : 0x084C0242 * 1 : Archive ID - * 2 : Archive low path type - * 3 : Archive low path size - * 10 : (LowPathSize << 14) | 2 + * 2 : Archive path type + * 3 : Archive path size + * 4 : Size in Blocks (1 block = 512 bytes) + * 5 : Number of directories + * 6 : Number of files + * 7 : Directory bucket count + * 8 : File bucket count + * 9 : Duplicate data + * 10 : (PathSize << 14) | 2 * 11 : Archive low path * Outputs: * 1 : Result of function, 0 on success, otherwise error code */ static void FormatSaveData(Service::Interface* self) { - // TODO(Subv): Find out what the other inputs and outputs of this function are u32* cmd_buff = Kernel::GetCommandBuffer(); - LOG_DEBUG(Service_FS, "(STUBBED)"); + LOG_WARNING(Service_FS, "(STUBBED)"); auto archive_id = static_cast<FS::ArchiveIdCode>(cmd_buff[1]); auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[2]); @@ -464,9 +469,9 @@ static void FormatSaveData(Service::Interface* self) { LOG_DEBUG(Service_FS, "archive_path=%s", archive_path.DebugStr().c_str()); if (archive_id != FS::ArchiveIdCode::SaveData) { - // TODO(Subv): What should happen if somebody attempts to format a different archive? - LOG_ERROR(Service_FS, "tried to format an archive different than SaveData, %u", cmd_buff[1]); - cmd_buff[1] = UnimplementedFunction(ErrorModule::FS).raw; + LOG_ERROR(Service_FS, "tried to format an archive different than SaveData, %u", archive_id); + cmd_buff[1] = ResultCode(ErrorDescription::FS_InvalidPath, ErrorModule::FS, + ErrorSummary::InvalidArgument, ErrorLevel::Usage).raw; return; } @@ -477,23 +482,40 @@ static void FormatSaveData(Service::Interface* self) { return; } - cmd_buff[1] = FormatArchive(ArchiveIdCode::SaveData).raw; + FileSys::ArchiveFormatInfo format_info; + format_info.duplicate_data = cmd_buff[9] & 0xFF; + format_info.number_directories = cmd_buff[5]; + format_info.number_files = cmd_buff[6]; + format_info.total_size = cmd_buff[4] * 512; + + cmd_buff[1] = FormatArchive(ArchiveIdCode::SaveData, format_info).raw; } /** * FS_User::FormatThisUserSaveData service function * Inputs: * 0: 0x080F0180 + * 1 : Size in Blocks (1 block = 512 bytes) + * 2 : Number of directories + * 3 : Number of files + * 4 : Directory bucket count + * 5 : File bucket count + * 6 : Duplicate data * Outputs: * 1 : Result of function, 0 on success, otherwise error code */ static void FormatThisUserSaveData(Service::Interface* self) { u32* cmd_buff = Kernel::GetCommandBuffer(); - LOG_DEBUG(Service_FS, "(STUBBED)"); - // TODO(Subv): Find out what the inputs and outputs of this function are + FileSys::ArchiveFormatInfo format_info; + format_info.duplicate_data = cmd_buff[6] & 0xFF; + format_info.number_directories = cmd_buff[2]; + format_info.number_files = cmd_buff[3]; + format_info.total_size = cmd_buff[1] * 512; - cmd_buff[1] = FormatArchive(ArchiveIdCode::SaveData).raw; + cmd_buff[1] = FormatArchive(ArchiveIdCode::SaveData, format_info).raw; + + LOG_TRACE(Service_FS, "called"); } /** @@ -531,10 +553,9 @@ static void GetFreeBytes(Service::Interface* self) { * 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 + * 5 : Number of directories + * 6 : Number of files + * 7-8 : Size limit * 9 : Size of the SMDH icon * 10: (SMDH Size << 4) | 0x0000000A * 11: Pointer to the SMDH icon for the new ExtSaveData @@ -556,7 +577,12 @@ static void CreateExtSaveData(Service::Interface* self) { cmd_buff[3], cmd_buff[4], cmd_buff[5], cmd_buff[6], cmd_buff[7], cmd_buff[8], icon_size, cmd_buff[10], icon_buffer); - cmd_buff[1] = CreateExtSaveData(media_type, save_high, save_low, icon_buffer, icon_size).raw; + FileSys::ArchiveFormatInfo format_info; + format_info.number_directories = cmd_buff[5]; + format_info.number_files = cmd_buff[6]; + format_info.duplicate_data = false; + format_info.total_size = 0; + cmd_buff[1] = CreateExtSaveData(media_type, save_high, save_low, icon_buffer, icon_size, format_info).raw; } /** @@ -731,6 +757,51 @@ static void GetArchiveResource(Service::Interface* self) { cmd_buff[5] = 0x80000; // 8GiB free } +/** + * FS_User::GetFormatInfo service function. + * Inputs: + * 0 : 0x084500C2 + * 1 : Archive ID + * 2 : Archive path type + * 3 : Archive path size + * 4 : (PathSize << 14) | 2 + * 5 : Archive low path + * Outputs: + * 0 : 0x08450140 + * 1 : Result of function, 0 on success, otherwise error code + * 2 : Total size + * 3 : Number of directories + * 4 : Number of files + * 5 : Duplicate data + */ +static void GetFormatInfo(Service::Interface* self) { + u32* cmd_buff = Kernel::GetCommandBuffer(); + + auto archive_id = static_cast<FS::ArchiveIdCode>(cmd_buff[1]); + auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[2]); + u32 archivename_size = cmd_buff[3]; + u32 archivename_ptr = cmd_buff[5]; + FileSys::Path archive_path(archivename_type, archivename_size, archivename_ptr); + + LOG_DEBUG(Service_FS, "archive_path=%s", archive_path.DebugStr().c_str()); + + cmd_buff[0] = IPC::MakeHeader(0x0845, 5, 0); + + auto format_info = GetArchiveFormatInfo(archive_id, archive_path); + + if (format_info.Failed()) { + LOG_ERROR(Service_FS, "Failed to retrieve the format info"); + cmd_buff[1] = format_info.Code().raw; + return; + } + + cmd_buff[1] = RESULT_SUCCESS.raw; + cmd_buff[2] = format_info->total_size; + cmd_buff[3] = format_info->number_directories; + cmd_buff[4] = format_info->number_files; + cmd_buff[5] = format_info->duplicate_data; +} + const Interface::FunctionInfo FunctionTable[] = { {0x000100C6, nullptr, "Dummy1"}, {0x040100C4, nullptr, "Control"}, @@ -802,7 +873,7 @@ const Interface::FunctionInfo FunctionTable[] = { {0x08420040, nullptr, "DeleteAllExtSaveDataOnNand"}, {0x08430000, nullptr, "InitializeCtrFileSystem"}, {0x08440000, nullptr, "CreateSeed"}, - {0x084500C2, nullptr, "GetFormatInfo"}, + {0x084500C2, GetFormatInfo, "GetFormatInfo"}, {0x08460102, nullptr, "GetLegacyRomHeader2"}, {0x08470180, nullptr, "FormatCtrCardUserSaveData"}, {0x08480042, nullptr, "GetSdmcCtrRootPath"}, diff --git a/src/core/hle/service/ptm/ptm.cpp b/src/core/hle/service/ptm/ptm.cpp index 6bdee4d9e..94f494690 100644 --- a/src/core/hle/service/ptm/ptm.cpp +++ b/src/core/hle/service/ptm/ptm.cpp @@ -103,7 +103,7 @@ void Init() { // If the archive didn't exist, create the files inside if (archive_result.Code().description == ErrorDescription::FS_NotFormatted) { // Format the archive to create the directories - Service::FS::FormatArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, archive_path); + Service::FS::FormatArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, FileSys::ArchiveFormatInfo(), archive_path); // Open it again to get a valid archive now that the folder exists archive_result = Service::FS::OpenArchive(Service::FS::ArchiveIdCode::SharedExtSaveData, archive_path); ASSERT_MSG(archive_result.Succeeded(), "Could not open the PTM SharedExtSaveData archive!"); diff --git a/src/core/hle/service/soc_u.cpp b/src/core/hle/service/soc_u.cpp index b52e52d4a..ff0af8f12 100644 --- a/src/core/hle/service/soc_u.cpp +++ b/src/core/hle/service/soc_u.cpp @@ -5,6 +5,7 @@ #include <algorithm> #include <cstring> #include <unordered_map> +#include <vector> #include "common/assert.h" #include "common/bit_field.h" @@ -593,17 +594,13 @@ static void Poll(Service::Interface* self) { // The 3ds_pollfd and the pollfd structures may be different (Windows/Linux have different sizes) // so we have to copy the data - pollfd* platform_pollfd = new pollfd[nfds]; - for (unsigned current_fds = 0; current_fds < nfds; ++current_fds) - platform_pollfd[current_fds] = CTRPollFD::ToPlatform(input_fds[current_fds]); + std::vector<pollfd> platform_pollfd(nfds); + std::transform(input_fds, input_fds + nfds, platform_pollfd.begin(), CTRPollFD::ToPlatform); - int ret = ::poll(platform_pollfd, nfds, timeout); + const int ret = ::poll(platform_pollfd.data(), nfds, timeout); // Now update the output pollfd structure - for (unsigned current_fds = 0; current_fds < nfds; ++current_fds) - output_fds[current_fds] = CTRPollFD::FromPlatform(platform_pollfd[current_fds]); - - delete[] platform_pollfd; + std::transform(platform_pollfd.begin(), platform_pollfd.end(), output_fds, CTRPollFD::FromPlatform); int result = 0; if (ret == SOCKET_ERROR_VALUE) |