diff --git a/config_templates/system_settings.ini b/config_templates/system_settings.ini index 58cb606b1..e16fbcd2f 100644 --- a/config_templates/system_settings.ini +++ b/config_templates/system_settings.ini @@ -17,6 +17,9 @@ ; Note that this setting does nothing when log manager is not enabled/sd card logging is not enabled. ; sd_card_log_output_directory = str!atmosphere/binlogs ; Atmosphere custom settings +[erpt] +; Control whether erpt reports should always be preserved, instead of automatically cleaning periodically. +; disable_automatic_report_cleanup = u8!0x0 [atmosphere] ; Reboot from fatal automatically after some number of milliseconds. ; If field is not present or 0, fatal will wait indefinitely for user input. diff --git a/libraries/libstratosphere/include/stratosphere/erpt/srv/erpt_srv_api.hpp b/libraries/libstratosphere/include/stratosphere/erpt/srv/erpt_srv_api.hpp index 9b9e833d6..1feb10eeb 100644 --- a/libraries/libstratosphere/include/stratosphere/erpt/srv/erpt_srv_api.hpp +++ b/libraries/libstratosphere/include/stratosphere/erpt/srv/erpt_srv_api.hpp @@ -27,6 +27,7 @@ namespace ams::erpt::srv { /* Atmosphere extension. */ Result SetRedirectNewReportsToSdCard(bool redirect); + Result SetEnabledAutomaticReportCleanup(bool redirect); void Wait(); diff --git a/libraries/libstratosphere/source/erpt/srv/erpt_srv_main.cpp b/libraries/libstratosphere/source/erpt/srv/erpt_srv_main.cpp index 3413afb5a..abb90d897 100644 --- a/libraries/libstratosphere/source/erpt/srv/erpt_srv_main.cpp +++ b/libraries/libstratosphere/source/erpt/srv/erpt_srv_main.cpp @@ -34,6 +34,8 @@ namespace ams::erpt::srv { constexpr s64 SystemSaveDataSize = 11_MB; constexpr s64 SystemSaveDataJournalSize = 2720_KB; + constinit bool g_automatic_report_cleanup_enabled = true; + Result ExtendSystemSaveData() { s64 cur_journal_size; s64 cur_savedata_size; @@ -81,6 +83,24 @@ namespace ams::erpt::srv { R_ABORT_UNLESS(fs::MountSdCardErrorReportDirectoryForAtmosphere(ReportOnSdStoragePath)); + if (g_automatic_report_cleanup_enabled) { + constexpr s64 MinimumReportCountForCleanup = 1000; + s64 report_count = MinimumReportCountForCleanup; + + fs::DirectoryHandle dir; + if (R_SUCCEEDED(fs::OpenDirectory(std::addressof(dir), ReportOnSdStoragePath, fs::OpenDirectoryMode_All))) { + ON_SCOPE_EXIT { fs::CloseDirectory(dir); }; + + if (R_FAILED(fs::GetDirectoryEntryCount(std::addressof(report_count), dir))) { + report_count = MinimumReportCountForCleanup; + } + } + + if (report_count >= MinimumReportCountForCleanup) { + fs::CleanDirectoryRecursively(ReportOnSdStoragePath); + } + } + R_ABORT_UNLESS(MountSystemSaveData()); g_sf_allocator.Attach(g_heap_handle); @@ -137,6 +157,11 @@ namespace ams::erpt::srv { return ResultSuccess(); } + Result SetEnabledAutomaticReportCleanup(bool en) { + g_automatic_report_cleanup_enabled = en; + return ResultSuccess(); + } + void Wait() { /* Get the update event. */ os::Event *event = GetForcedShutdownUpdateEvent(); diff --git a/stratosphere/ams_mitm/source/set_mitm/settings_sd_kvs.cpp b/stratosphere/ams_mitm/source/set_mitm/settings_sd_kvs.cpp index 3696ddbcd..8d869a4e1 100644 --- a/stratosphere/ams_mitm/source/set_mitm/settings_sd_kvs.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/settings_sd_kvs.cpp @@ -325,6 +325,10 @@ namespace ams::settings::fwdbg { /* Note that this setting does nothing when log manager is not enabled/sd card logging is not enabled. */ R_ABORT_UNLESS(ParseSettingsItemValue("lm", "sd_card_log_output_directory", "str!atmosphere/binlogs")); + /* Control whether erpt reports should always be preserved, instead of automatically cleaning periodically. */ + /* 0 = Disabled, 1 = Enabled */ + R_ABORT_UNLESS(ParseSettingsItemValue("erpt", "disable_automatic_report_cleanup", "u8!0x0")); + /* Atmosphere custom settings. */ /* Reboot from fatal automatically after some number of milliseconds. */ diff --git a/stratosphere/erpt/source/erpt_main.cpp b/stratosphere/erpt/source/erpt_main.cpp index 41577b9a9..91a0e34bf 100644 --- a/stratosphere/erpt/source/erpt_main.cpp +++ b/stratosphere/erpt/source/erpt_main.cpp @@ -84,6 +84,16 @@ namespace ams { /* Atmosphere always wants to redirect new reports to the SD card, to prevent them from being logged. */ erpt::srv::SetRedirectNewReportsToSdCard(true); + /* Decide whether or not to clean up reports periodically. */ + { + u8 disable_report_cleanup = 0; + if (settings::fwdbg::GetSettingsItemValue(std::addressof(disable_report_cleanup), sizeof(disable_report_cleanup), "erpt", "disable_automatic_report_cleanup") == sizeof(disable_report_cleanup)) { + erpt::srv::SetEnabledAutomaticReportCleanup(disable_report_cleanup == 0); + } else { + erpt::srv::SetEnabledAutomaticReportCleanup(true); + } + } + /* Configure the OS version. */ { settings::system::FirmwareVersion firmware_version = {};