erpt: GetMmcErrorInfo, GetSdCard*Info

This commit is contained in:
Michael Scire
2023-10-25 12:41:18 -07:00
parent fa384fd920
commit 60974a5f4e
10 changed files with 472 additions and 10 deletions

View File

@@ -127,17 +127,183 @@ namespace ams::erpt::srv {
}
Result SubmitMmcErrorInfo() {
/* TODO */
/* Get the mmc error info. */
fs::StorageErrorInfo sei = {};
char log_buffer[erpt::ArrayBufferSizeDefault] = {};
size_t log_size = 0;
if (R_SUCCEEDED(fs::GetAndClearMmcErrorInfo(std::addressof(sei), std::addressof(log_size), log_buffer, sizeof(log_buffer)))) {
/* Submit the error info. */
{
/* Create a record. */
auto record = std::make_unique<ContextRecord>(CategoryId_NANDErrorInfo, 0);
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
/* Add fields. */
R_ABORT_UNLESS(record->Add(FieldId_NANDNumActivationFailures, sei.num_activation_failures));
R_ABORT_UNLESS(record->Add(FieldId_NANDNumActivationErrorCorrections, sei.num_activation_error_corrections));
R_ABORT_UNLESS(record->Add(FieldId_NANDNumReadWriteFailures, sei.num_read_write_failures));
R_ABORT_UNLESS(record->Add(FieldId_NANDNumReadWriteErrorCorrections, sei.num_read_write_error_corrections));
/* Submit the record. */
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
}
/* If we have a log, submit it. */
if (log_size > 0) {
/* Create a record. */
auto record = std::make_unique<ContextRecord>(CategoryId_NANDDriverLog, log_size);
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
/* Add fields. */
R_ABORT_UNLESS(record->Add(FieldId_NANDErrorLog, log_buffer, log_size));
/* Submit the record. */
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
}
}
R_SUCCEED();
}
Result SubmitSdCardDetailInfo() {
/* TODO */
/* Submit the sd card cid. */
{
u8 sd_cid[fs::SdCardCidSize] = {};
if (R_SUCCEEDED(fs::GetSdCardCid(sd_cid, sizeof(sd_cid)))) {
/* Clear the serial number from the cid. */
fs::ClearSdCardCidSerialNumber(sd_cid);
/* Create a record. */
auto record = std::make_unique<ContextRecord>(CategoryId_MicroSDTypeInfo, sizeof(sd_cid));
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
/* Add the cid. */
R_ABORT_UNLESS(record->Add(FieldId_MicroSDType, sd_cid, sizeof(sd_cid)));
/* Submit the record. */
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
}
}
/* Submit the sd card speed mode. */
{
/* Create a record. */
auto record = std::make_unique<ContextRecord>(CategoryId_MicroSDSpeedModeInfo, 0x20);
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
/* Get the speed mode. */
fs::SdCardSpeedMode speed_mode{};
const auto res = fs::GetSdCardSpeedMode(std::addressof(speed_mode));
if (R_SUCCEEDED(res)) {
const char *speed_mode_name = "None";
switch (speed_mode) {
case fs::SdCardSpeedMode_Identification:
speed_mode_name = "Identification";
break;
case fs::SdCardSpeedMode_DefaultSpeed:
speed_mode_name = "DefaultSpeed";
break;
case fs::SdCardSpeedMode_HighSpeed:
speed_mode_name = "HighSpeed";
break;
case fs::SdCardSpeedMode_Sdr12:
speed_mode_name = "Sdr12";
break;
case fs::SdCardSpeedMode_Sdr25:
speed_mode_name = "Sdr25";
break;
case fs::SdCardSpeedMode_Sdr50:
speed_mode_name = "Sdr50";
break;
case fs::SdCardSpeedMode_Sdr104:
speed_mode_name = "Sdr104";
break;
case fs::SdCardSpeedMode_Ddr50:
speed_mode_name = "Ddr50";
break;
case fs::SdCardSpeedMode_Unknown:
speed_mode_name = "Unknown";
break;
default:
speed_mode_name = "UnDefined";
break;
}
R_ABORT_UNLESS(record->Add(FieldId_MicroSDSpeedMode, speed_mode_name, std::strlen(speed_mode_name)));
} else {
/* Getting speed mode failed, so add the result. */
char res_str[0x20];
util::SNPrintf(res_str, sizeof(res_str), "0x%08X", res.GetValue());
R_ABORT_UNLESS(record->Add(FieldId_MicroSDSpeedMode, res_str, std::strlen(res_str)));
}
/* Submit the record. */
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
}
/* Submit the area sizes. */
{
s64 user_area_size = 0;
s64 prot_area_size = 0;
const Result res_user = fs::GetSdCardUserAreaSize(std::addressof(user_area_size));
const Result res_prot = fs::GetSdCardProtectedAreaSize(std::addressof(prot_area_size));
if (R_SUCCEEDED(res_user) || R_SUCCEEDED(res_prot)) {
/* Create a record. */
auto record = std::make_unique<ContextRecord>(CategoryId_SdCardSizeSpec, 0);
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
/* Add sizes. */
if (R_SUCCEEDED(res_user)) {
R_ABORT_UNLESS(record->Add(FieldId_SdCardUserAreaSize, user_area_size));
}
if (R_SUCCEEDED(res_prot)) {
R_ABORT_UNLESS(record->Add(FieldId_SdCardProtectedAreaSize, prot_area_size));
}
/* Submit the record. */
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
}
}
R_SUCCEED();
}
Result SubmitSdCardErrorInfo() {
/* TODO */
/* Get the sd card error info. */
fs::StorageErrorInfo sei = {};
char log_buffer[erpt::ArrayBufferSizeDefault] = {};
size_t log_size = 0;
if (R_SUCCEEDED(fs::GetAndClearSdCardErrorInfo(std::addressof(sei), std::addressof(log_size), log_buffer, sizeof(log_buffer)))) {
/* Submit the error info. */
{
/* Create a record. */
auto record = std::make_unique<ContextRecord>(CategoryId_SdCardErrorInfo, 0);
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
/* Add fields. */
R_ABORT_UNLESS(record->Add(FieldId_SdCardNumActivationFailures, sei.num_activation_failures));
R_ABORT_UNLESS(record->Add(FieldId_SdCardNumActivationErrorCorrections, sei.num_activation_error_corrections));
R_ABORT_UNLESS(record->Add(FieldId_SdCardNumReadWriteFailures, sei.num_read_write_failures));
R_ABORT_UNLESS(record->Add(FieldId_SdCardNumReadWriteErrorCorrections, sei.num_read_write_error_corrections));
/* Submit the record. */
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
}
/* If we have a log, submit it. */
if (log_size > 0) {
/* Create a record. */
auto record = std::make_unique<ContextRecord>(CategoryId_SdCardDriverLog, log_size);
R_UNLESS(record != nullptr, erpt::ResultOutOfMemory());
/* Add fields. */
R_ABORT_UNLESS(record->Add(FieldId_SdCardErrorLog, log_buffer, log_size));
/* Submit the record. */
R_ABORT_UNLESS(Context::SubmitContextRecord(std::move(record)));
}
}
R_SUCCEED();
}

View File

@@ -70,6 +70,26 @@ namespace ams::fs {
R_SUCCEED();
}
Result GetAndClearMmcErrorInfo(StorageErrorInfo *out_sei, size_t *out_log_size, char *out_log_buffer, size_t log_buffer_size) {
/* Check pre-conditions. */
AMS_FS_R_UNLESS(out_sei != nullptr, fs::ResultNullptrArgument());
AMS_FS_R_UNLESS(out_log_size != nullptr, fs::ResultNullptrArgument());
AMS_FS_R_UNLESS(out_log_buffer != nullptr, fs::ResultNullptrArgument());
auto fsp = impl::GetFileSystemProxyServiceObject();
/* Open a device operator. */
sf::SharedPointer<fssrv::sf::IDeviceOperator> device_operator;
AMS_FS_R_TRY(fsp->OpenDeviceOperator(std::addressof(device_operator)));
/* Get the error info. */
s64 log_size = 0;
AMS_FS_R_TRY(device_operator->GetAndClearMmcErrorInfo(out_sei, std::addressof(log_size), sf::OutBuffer(out_log_buffer, log_buffer_size), static_cast<s64>(log_buffer_size)));
*out_log_size = static_cast<size_t>(log_size);
R_SUCCEED();
}
Result GetMmcExtendedCsd(void *dst, size_t size) {
/* Check pre-conditions. */
AMS_FS_R_UNLESS(dst != nullptr, fs::ResultNullptrArgument());

View File

@@ -124,4 +124,90 @@ namespace ams::fs {
return inserted;
}
Result GetSdCardSpeedMode(SdCardSpeedMode *out) {
/* Check pre-conditions. */
AMS_FS_R_UNLESS(out != nullptr, fs::ResultNullptrArgument());
auto fsp = impl::GetFileSystemProxyServiceObject();
/* Open a device operator. */
sf::SharedPointer<fssrv::sf::IDeviceOperator> device_operator;
AMS_FS_R_TRY(fsp->OpenDeviceOperator(std::addressof(device_operator)));
/* Get the speed mode. */
s64 speed_mode = 0;
AMS_FS_R_TRY(device_operator->GetSdCardSpeedMode(std::addressof(speed_mode)));
*out = static_cast<SdCardSpeedMode>(speed_mode);
R_SUCCEED();
}
Result GetSdCardCid(void *dst, size_t size) {
/* Check pre-conditions. */
AMS_FS_R_UNLESS(dst != nullptr, fs::ResultNullptrArgument());
auto fsp = impl::GetFileSystemProxyServiceObject();
/* Open a device operator. */
sf::SharedPointer<fssrv::sf::IDeviceOperator> device_operator;
AMS_FS_R_TRY(fsp->OpenDeviceOperator(std::addressof(device_operator)));
/* Get the cid. */
AMS_FS_R_TRY(device_operator->GetSdCardCid(sf::OutBuffer(dst, size), static_cast<s64>(size)));
R_SUCCEED();
}
Result GetSdCardUserAreaSize(s64 *out) {
/* Check pre-conditions. */
AMS_FS_R_UNLESS(out != nullptr, fs::ResultNullptrArgument());
auto fsp = impl::GetFileSystemProxyServiceObject();
/* Open a device operator. */
sf::SharedPointer<fssrv::sf::IDeviceOperator> device_operator;
AMS_FS_R_TRY(fsp->OpenDeviceOperator(std::addressof(device_operator)));
/* Get the size. */
AMS_FS_R_TRY(device_operator->GetSdCardUserAreaSize(out));
R_SUCCEED();
}
Result GetSdCardProtectedAreaSize(s64 *out) {
/* Check pre-conditions. */
AMS_FS_R_UNLESS(out != nullptr, fs::ResultNullptrArgument());
auto fsp = impl::GetFileSystemProxyServiceObject();
/* Open a device operator. */
sf::SharedPointer<fssrv::sf::IDeviceOperator> device_operator;
AMS_FS_R_TRY(fsp->OpenDeviceOperator(std::addressof(device_operator)));
/* Get the size. */
AMS_FS_R_TRY(device_operator->GetSdCardProtectedAreaSize(out));
R_SUCCEED();
}
Result GetAndClearSdCardErrorInfo(StorageErrorInfo *out_sei, size_t *out_log_size, char *out_log_buffer, size_t log_buffer_size) {
/* Check pre-conditions. */
AMS_FS_R_UNLESS(out_sei != nullptr, fs::ResultNullptrArgument());
AMS_FS_R_UNLESS(out_log_size != nullptr, fs::ResultNullptrArgument());
AMS_FS_R_UNLESS(out_log_buffer != nullptr, fs::ResultNullptrArgument());
auto fsp = impl::GetFileSystemProxyServiceObject();
/* Open a device operator. */
sf::SharedPointer<fssrv::sf::IDeviceOperator> device_operator;
AMS_FS_R_TRY(fsp->OpenDeviceOperator(std::addressof(device_operator)));
/* Get the error info. */
s64 log_size = 0;
AMS_FS_R_TRY(device_operator->GetAndClearSdCardErrorInfo(out_sei, std::addressof(log_size), sf::OutBuffer(out_log_buffer, log_buffer_size), static_cast<s64>(log_buffer_size)));
*out_log_size = static_cast<size_t>(log_size);
R_SUCCEED();
}
}

View File

@@ -33,6 +33,27 @@ namespace ams::fs::impl {
R_RETURN(fsDeviceOperatorIsSdCardInserted(std::addressof(m_operator), out.GetPointer()));
}
Result GetSdCardSpeedMode(ams::sf::Out<s64> out) {
R_RETURN(fsDeviceOperatorGetSdCardSpeedMode(std::addressof(m_operator), out.GetPointer()));
}
Result GetSdCardCid(ams::sf::OutBuffer out, s64 size) {
R_RETURN(fsDeviceOperatorGetSdCardCid(std::addressof(m_operator), out.GetPointer(), out.GetSize(), size));
}
Result GetSdCardUserAreaSize(ams::sf::Out<s64> out) {
R_RETURN(fsDeviceOperatorGetSdCardUserAreaSize(std::addressof(m_operator), out.GetPointer()));
}
Result GetSdCardProtectedAreaSize(ams::sf::Out<s64> out) {
R_RETURN(fsDeviceOperatorGetSdCardProtectedAreaSize(std::addressof(m_operator), out.GetPointer()));
}
Result GetAndClearSdCardErrorInfo(ams::sf::Out<fs::StorageErrorInfo> out_sei, ams::sf::Out<s64> out_size, ams::sf::OutBuffer out_buf, s64 size) {
static_assert(sizeof(::FsStorageErrorInfo) == sizeof(fs::StorageErrorInfo));
R_RETURN(fsDeviceOperatorGetAndClearSdCardErrorInfo(std::addressof(m_operator), reinterpret_cast<::FsStorageErrorInfo *>(out_sei.GetPointer()), out_size.GetPointer(), out_buf.GetPointer(), out_buf.GetSize(), size));
}
Result GetMmcCid(ams::sf::OutBuffer out, s64 size) {
R_RETURN(fsDeviceOperatorGetMmcCid(std::addressof(m_operator), out.GetPointer(), out.GetSize(), size));
}
@@ -45,6 +66,11 @@ namespace ams::fs::impl {
R_RETURN(fsDeviceOperatorGetMmcPatrolCount(std::addressof(m_operator), out.GetPointer()));
}
Result GetAndClearMmcErrorInfo(ams::sf::Out<fs::StorageErrorInfo> out_sei, ams::sf::Out<s64> out_size, ams::sf::OutBuffer out_buf, s64 size) {
static_assert(sizeof(::FsStorageErrorInfo) == sizeof(fs::StorageErrorInfo));
R_RETURN(fsDeviceOperatorGetAndClearMmcErrorInfo(std::addressof(m_operator), reinterpret_cast<::FsStorageErrorInfo *>(out_sei.GetPointer()), out_size.GetPointer(), out_buf.GetPointer(), out_buf.GetSize(), size));
}
Result GetMmcExtendedCsd(ams::sf::OutBuffer out, s64 size) {
R_RETURN(fsDeviceOperatorGetMmcExtendedCsd(std::addressof(m_operator), out.GetPointer(), out.GetSize(), size));
}