From 2ed8450446c88af403316790c578971961132ce3 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Wed, 25 Oct 2023 14:21:27 -0700 Subject: [PATCH] erpt: SubmitFileSystemProxyErrorInfo --- .../stratosphere/fat/fat_file_system.hpp | 10 +-- .../include/stratosphere/fs/fs_error_info.hpp | 14 ++-- .../fssrv/fssrv_file_system_proxy_impl.hpp | 1 + .../fssrv/sf/fssrv_sf_i_file_system_proxy.hpp | 3 +- .../erpt/srv/erpt_srv_fs_info.os.horizon.cpp | 67 ++++++++++++++++++- .../source/fs/fs_error_info.cpp | 35 ++++++++++ .../source/fs/fs_remote_file_system_proxy.hpp | 5 ++ .../fssrv/fssrv_file_system_proxy_impl.cpp | 4 ++ 8 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 libraries/libstratosphere/source/fs/fs_error_info.cpp diff --git a/libraries/libstratosphere/include/stratosphere/fat/fat_file_system.hpp b/libraries/libstratosphere/include/stratosphere/fat/fat_file_system.hpp index 2be687b83..46212a109 100644 --- a/libraries/libstratosphere/include/stratosphere/fat/fat_file_system.hpp +++ b/libraries/libstratosphere/include/stratosphere/fat/fat_file_system.hpp @@ -23,7 +23,7 @@ namespace ams::fat { struct FatError { int error; int extra_error; - int device_id; + int drive_id; char name[FatErrorNameMaxLength]; u8 reserved[4]; }; @@ -31,15 +31,15 @@ namespace ams::fat { static_assert(util::is_pod::value); struct FatReportInfo1 { - u16 file_peak_open_count; - u16 directory_peak_open_count; + u16 open_file_peak_count; + u16 open_directory_peak_count; }; static_assert(sizeof(FatReportInfo1) == 4); static_assert(util::is_pod::value); struct FatReportInfo2 { - u16 unique_file_entry_peak_open_count; - u16 unique_directory_entry_peak_open_count; + u16 open_unique_file_entry_peak_count; + u16 open_unique_directory_entry_peak_count; }; static_assert(sizeof(FatReportInfo2) == 4); static_assert(util::is_pod::value); diff --git a/libraries/libstratosphere/include/stratosphere/fs/fs_error_info.hpp b/libraries/libstratosphere/include/stratosphere/fs/fs_error_info.hpp index 71ed0d8d2..06044631e 100644 --- a/libraries/libstratosphere/include/stratosphere/fs/fs_error_info.hpp +++ b/libraries/libstratosphere/include/stratosphere/fs/fs_error_info.hpp @@ -29,17 +29,17 @@ namespace ams::fs { static_assert(util::is_pod::value); struct FileSystemProxyErrorInfo { - u32 rom_fs_remont_for_data_corruption_count; + u32 rom_fs_remount_for_data_corruption_count; u32 rom_fs_unrecoverable_data_corruption_by_remount_count; fat::FatError fat_fs_error; u32 rom_fs_recovered_by_invalidate_cache_count; u32 save_data_index_count; - fat::FatReportInfo1 bis_system_report1; - fat::FatReportInfo1 bis_user_report1; - fat::FatReportInfo1 sd_card_report1; - fat::FatReportInfo2 bis_system_report2; - fat::FatReportInfo2 bis_user_report2; - fat::FatReportInfo2 sd_card_report2; + fat::FatReportInfo1 bis_system_fat_report_info_1; + fat::FatReportInfo1 bis_user_fat_report_info_1; + fat::FatReportInfo1 sd_card_fat_report_info_1; + fat::FatReportInfo2 bis_system_fat_report_info_2; + fat::FatReportInfo2 bis_user_fat_report_info_2; + fat::FatReportInfo2 sd_card_fat_report_info_2; u32 rom_fs_deep_retry_start_count; u32 rom_fs_unrecoverable_by_game_card_access_failed_count; fat::FatSafeInfo bis_system_fat_safe_info; diff --git a/libraries/libstratosphere/include/stratosphere/fssrv/fssrv_file_system_proxy_impl.hpp b/libraries/libstratosphere/include/stratosphere/fssrv/fssrv_file_system_proxy_impl.hpp index 64d43c1d2..e8f1be65d 100644 --- a/libraries/libstratosphere/include/stratosphere/fssrv/fssrv_file_system_proxy_impl.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssrv/fssrv_file_system_proxy_impl.hpp @@ -121,6 +121,7 @@ namespace ams::fssrv { Result IsSignedSystemPartitionOnSdCardValid(ams::sf::Out out); Result OpenAccessFailureDetectionEventNotifier(); /* ... */ + Result GetAndClearErrorInfo(ams::sf::Out out); Result RegisterProgramIndexMapInfo(const ams::sf::InBuffer &buffer, s32 count); Result SetBisRootForHost(u32 id, const fssrv::sf::FspPath &path); Result SetSaveDataSize(s64 size, s64 journal_size); diff --git a/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_i_file_system_proxy.hpp b/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_i_file_system_proxy.hpp index ba41abb80..6d00f9bf8 100644 --- a/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_i_file_system_proxy.hpp +++ b/libraries/libstratosphere/include/stratosphere/fssrv/sf/fssrv_sf_i_file_system_proxy.hpp @@ -20,6 +20,7 @@ #include #include #include +#include /* ACCURATE_TO_VERSION: 13.4.0.0 */ #define AMS_FSSRV_I_FILE_SYSTEM_PROXY_INTERFACE_INFO(C, H) \ @@ -125,7 +126,7 @@ /* AMS_SF_METHOD_INFO(C, H, 702, Result, IsAccessFailureDetected, (), (), hos::Version_5_0_0) */ \ /* AMS_SF_METHOD_INFO(C, H, 710, Result, ResolveAccessFailure, (), (), hos::Version_5_0_0) */ \ /* AMS_SF_METHOD_INFO(C, H, 720, Result, AbandonAccessFailure, (), (), hos::Version_5_0_0) */ \ - /* AMS_SF_METHOD_INFO(C, H, 800, Result, GetAndClearErrorInfo, (), (), hos::Version_2_0_0) */ \ + AMS_SF_METHOD_INFO(C, H, 800, Result, GetAndClearErrorInfo, (ams::sf::Out out), (out), hos::Version_2_0_0) \ AMS_SF_METHOD_INFO(C, H, 810, Result, RegisterProgramIndexMapInfo, (const ams::sf::InBuffer &buffer, s32 count), (buffer, count), hos::Version_7_0_0) \ AMS_SF_METHOD_INFO(C, H, 1000, Result, SetBisRootForHost, (u32 id, const fssrv::sf::FspPath &path), (id, path), hos::Version_Min, hos::Version_9_2_0) \ AMS_SF_METHOD_INFO(C, H, 1001, Result, SetSaveDataSize, (s64 size, s64 journal_size), (size, journal_size)) \ diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_fs_info.os.horizon.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_fs_info.os.horizon.cpp index 0290b2fd3..cdb70324b 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_fs_info.os.horizon.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_fs_info.os.horizon.cpp @@ -318,7 +318,72 @@ namespace ams::erpt::srv { } Result SubmitFileSystemErrorInfo() { - /* TODO */ + /* Get the fsp error info. */ + fs::FileSystemProxyErrorInfo ei = {}; + if (R_SUCCEEDED(fs::GetAndClearFileSystemProxyErrorInfo(std::addressof(ei)))) { + /* Submit FsProxyErrorInfo. */ + { + /* Create a record. */ + auto record = std::make_unique(CategoryId_FsProxyErrorInfo, fat::FatErrorNameMaxLength); + R_UNLESS(record != nullptr, erpt::ResultOutOfMemory()); + + /* Add fields. */ + R_ABORT_UNLESS(record->Add(FieldId_FsRemountForDataCorruptCount, ei.rom_fs_remount_for_data_corruption_count)); + R_ABORT_UNLESS(record->Add(FieldId_FsRemountForDataCorruptRetryOutCount, ei.rom_fs_unrecoverable_data_corruption_by_remount_count)); + + R_ABORT_UNLESS(record->Add(FieldId_FatFsError, ei.fat_fs_error.error)); + R_ABORT_UNLESS(record->Add(FieldId_FatFsExtraError, ei.fat_fs_error.extra_error)); + R_ABORT_UNLESS(record->Add(FieldId_FatFsErrorDrive, ei.fat_fs_error.drive_id)); + R_ABORT_UNLESS(record->Add(FieldId_FatFsErrorName, ei.fat_fs_error.name, fat::FatErrorNameMaxLength)); + + R_ABORT_UNLESS(record->Add(FieldId_FsRecoveredByInvalidateCacheCount, ei.rom_fs_recovered_by_invalidate_cache_count)); + R_ABORT_UNLESS(record->Add(FieldId_FsSaveDataIndexCount, ei.save_data_index_count)); + + R_ABORT_UNLESS(record->Add(FieldId_FatFsBisSystemFilePeakOpenCount, ei.bis_system_fat_report_info_1.open_file_peak_count)); + R_ABORT_UNLESS(record->Add(FieldId_FatFsBisSystemDirectoryPeakOpenCount, ei.bis_system_fat_report_info_1.open_directory_peak_count)); + + R_ABORT_UNLESS(record->Add(FieldId_FatFsBisUserFilePeakOpenCount, ei.bis_user_fat_report_info_1.open_file_peak_count)); + R_ABORT_UNLESS(record->Add(FieldId_FatFsBisUserDirectoryPeakOpenCount, ei.bis_user_fat_report_info_1.open_directory_peak_count)); + + R_ABORT_UNLESS(record->Add(FieldId_FatFsSdCardFilePeakOpenCount, ei.sd_card_fat_report_info_1.open_file_peak_count)); + R_ABORT_UNLESS(record->Add(FieldId_FatFsSdCardDirectoryPeakOpenCount, ei.sd_card_fat_report_info_1.open_directory_peak_count)); + + R_ABORT_UNLESS(record->Add(FieldId_FatFsBisSystemUniqueFileEntryPeakOpenCount, ei.bis_system_fat_report_info_2.open_unique_file_entry_peak_count)); + R_ABORT_UNLESS(record->Add(FieldId_FatFsBisSystemUniqueDirectoryEntryPeakOpenCount, ei.bis_system_fat_report_info_2.open_unique_directory_entry_peak_count)); + + R_ABORT_UNLESS(record->Add(FieldId_FatFsBisUserUniqueFileEntryPeakOpenCount, ei.bis_user_fat_report_info_2.open_unique_file_entry_peak_count)); + R_ABORT_UNLESS(record->Add(FieldId_FatFsBisUserUniqueDirectoryEntryPeakOpenCount, ei.bis_user_fat_report_info_2.open_unique_directory_entry_peak_count)); + + R_ABORT_UNLESS(record->Add(FieldId_FatFsSdCardUniqueFileEntryPeakOpenCount, ei.sd_card_fat_report_info_2.open_unique_file_entry_peak_count)); + R_ABORT_UNLESS(record->Add(FieldId_FatFsSdCardUniqueDirectoryEntryPeakOpenCount, ei.sd_card_fat_report_info_2.open_unique_directory_entry_peak_count)); + + /* Submit the record. */ + R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record))); + } + + /* Submit FsProxyErrorInfo2. */ + { + /* Create a record. */ + auto record = std::make_unique(CategoryId_FsProxyErrorInfo2, 0); + R_UNLESS(record != nullptr, erpt::ResultOutOfMemory()); + + /* Add fields. */ + R_ABORT_UNLESS(record->Add(FieldId_FsDeepRetryStartCount, ei.rom_fs_deep_retry_start_count)); + R_ABORT_UNLESS(record->Add(FieldId_FsUnrecoverableByGameCardAccessFailedCount, ei.rom_fs_unrecoverable_by_game_card_access_failed_count)); + + R_ABORT_UNLESS(record->Add(FieldId_FatFsBisSystemFatSafeControlResult, static_cast(ei.bis_system_fat_safe_info.result))); + R_ABORT_UNLESS(record->Add(FieldId_FatFsBisSystemFatErrorNumber, ei.bis_system_fat_safe_info.error_number)); + R_ABORT_UNLESS(record->Add(FieldId_FatFsBisSystemFatSafeErrorNumber, ei.bis_system_fat_safe_info.safe_error_number)); + + R_ABORT_UNLESS(record->Add(FieldId_FatFsBisUserFatSafeControlResult, static_cast(ei.bis_user_fat_safe_info.result))); + R_ABORT_UNLESS(record->Add(FieldId_FatFsBisUserFatErrorNumber, ei.bis_user_fat_safe_info.error_number)); + R_ABORT_UNLESS(record->Add(FieldId_FatFsBisUserFatSafeErrorNumber, ei.bis_user_fat_safe_info.safe_error_number)); + + /* Submit the record. */ + R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record))); + } + } + R_SUCCEED(); } diff --git a/libraries/libstratosphere/source/fs/fs_error_info.cpp b/libraries/libstratosphere/source/fs/fs_error_info.cpp new file mode 100644 index 000000000..a6dab78e4 --- /dev/null +++ b/libraries/libstratosphere/source/fs/fs_error_info.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) Atmosphère-NX + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include +#include "fsa/fs_mount_utils.hpp" +#include "impl/fs_file_system_proxy_service_object.hpp" +#include "impl/fs_file_system_service_object_adapter.hpp" + +namespace ams::fs { + + Result GetAndClearFileSystemProxyErrorInfo(FileSystemProxyErrorInfo *out) { + /* Check pre-conditions. */ + AMS_FS_R_UNLESS(out != nullptr, fs::ResultNullptrArgument()); + + auto fsp = impl::GetFileSystemProxyServiceObject(); + + /* Get the error info. */ + AMS_FS_R_TRY(fsp->GetAndClearErrorInfo(out)); + + R_SUCCEED(); + } + +} diff --git a/libraries/libstratosphere/source/fs/fs_remote_file_system_proxy.hpp b/libraries/libstratosphere/source/fs/fs_remote_file_system_proxy.hpp index ae9b8b492..4a284bd1c 100644 --- a/libraries/libstratosphere/source/fs/fs_remote_file_system_proxy.hpp +++ b/libraries/libstratosphere/source/fs/fs_remote_file_system_proxy.hpp @@ -389,6 +389,11 @@ namespace ams::fs { /* ... */ + Result GetAndClearErrorInfo(ams::sf::Out out) { + static_assert(sizeof(fs::FileSystemProxyErrorInfo) == sizeof(::FsFileSystemProxyErrorInfo)); + R_RETURN(::fsGetAndClearErrorInfo(reinterpret_cast<::FsFileSystemProxyErrorInfo *>(out.GetPointer()))); + } + Result RegisterProgramIndexMapInfo(const ams::sf::InBuffer &buffer, s32 count) { AMS_ABORT("TODO"); } diff --git a/libraries/libstratosphere/source/fssrv/fssrv_file_system_proxy_impl.cpp b/libraries/libstratosphere/source/fssrv/fssrv_file_system_proxy_impl.cpp index eabc29e34..34df93942 100644 --- a/libraries/libstratosphere/source/fssrv/fssrv_file_system_proxy_impl.cpp +++ b/libraries/libstratosphere/source/fssrv/fssrv_file_system_proxy_impl.cpp @@ -373,6 +373,10 @@ namespace ams::fssrv { /* ... */ + Result FileSystemProxyImpl::GetAndClearErrorInfo(ams::sf::Out out) { + AMS_ABORT("TODO"); + } + Result FileSystemProxyImpl::RegisterProgramIndexMapInfo(const ams::sf::InBuffer &buffer, s32 count) { AMS_ABORT("TODO"); }