mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Add MMC shim functions
This commit is contained in:
parent
934e9af9a4
commit
2f0a2eabf5
1 changed files with 171 additions and 0 deletions
171
src/LibHac/Fs/Shim/Mmc.cs
Normal file
171
src/LibHac/Fs/Shim/Mmc.cs
Normal file
|
@ -0,0 +1,171 @@
|
||||||
|
using System;
|
||||||
|
using LibHac.Common;
|
||||||
|
using LibHac.FsSrv.Sf;
|
||||||
|
using LibHac.Sf;
|
||||||
|
|
||||||
|
namespace LibHac.Fs.Shim;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Contains functions used for interacting with the MMC.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>Based on nnSdk 14.3.0</remarks>
|
||||||
|
public static class Mmc
|
||||||
|
{
|
||||||
|
public static Result GetMmcSpeedMode(this FileSystemClient fs, out MmcSpeedMode outSpeedMode)
|
||||||
|
{
|
||||||
|
UnsafeHelpers.SkipParamInit(out outSpeedMode);
|
||||||
|
|
||||||
|
using SharedRef<IFileSystemProxy> fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject();
|
||||||
|
using var deviceOperator = new SharedRef<IDeviceOperator>();
|
||||||
|
|
||||||
|
Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref());
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
rc = deviceOperator.Get.GetMmcSpeedMode(out long speedMode);
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
outSpeedMode = (MmcSpeedMode)speedMode;
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result GetMmcCid(this FileSystemClient fs, Span<byte> outCidBuffer)
|
||||||
|
{
|
||||||
|
using SharedRef<IFileSystemProxy> fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject();
|
||||||
|
using var deviceOperator = new SharedRef<IDeviceOperator>();
|
||||||
|
|
||||||
|
Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref());
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
rc = deviceOperator.Get.GetMmcCid(new OutBuffer(outCidBuffer), outCidBuffer.Length);
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result EraseMmc(this FileSystemClient fs, MmcPartition partition)
|
||||||
|
{
|
||||||
|
using SharedRef<IFileSystemProxy> fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject();
|
||||||
|
using var deviceOperator = new SharedRef<IDeviceOperator>();
|
||||||
|
|
||||||
|
Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref());
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
rc = deviceOperator.Get.EraseMmc((uint)partition);
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result GetMmcPartitionSize(this FileSystemClient fs, out long outPartitionSize,
|
||||||
|
MmcPartition partition)
|
||||||
|
{
|
||||||
|
UnsafeHelpers.SkipParamInit(out outPartitionSize);
|
||||||
|
|
||||||
|
using SharedRef<IFileSystemProxy> fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject();
|
||||||
|
using var deviceOperator = new SharedRef<IDeviceOperator>();
|
||||||
|
|
||||||
|
Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref());
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
rc = deviceOperator.Get.GetMmcPartitionSize(out outPartitionSize, (uint)partition);
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result GetMmcPatrolCount(this FileSystemClient fs, out uint outPatrolCount)
|
||||||
|
{
|
||||||
|
UnsafeHelpers.SkipParamInit(out outPatrolCount);
|
||||||
|
|
||||||
|
using SharedRef<IFileSystemProxy> fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject();
|
||||||
|
using var deviceOperator = new SharedRef<IDeviceOperator>();
|
||||||
|
|
||||||
|
Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref());
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
rc = deviceOperator.Get.GetMmcPatrolCount(out outPatrolCount);
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result GetAndClearMmcErrorInfo(this FileSystemClient fs, out StorageErrorInfo outErrorInfo,
|
||||||
|
out long outLogSize, Span<byte> logBuffer)
|
||||||
|
{
|
||||||
|
UnsafeHelpers.SkipParamInit(out outErrorInfo, out outLogSize);
|
||||||
|
|
||||||
|
using SharedRef<IFileSystemProxy> fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject();
|
||||||
|
using var deviceOperator = new SharedRef<IDeviceOperator>();
|
||||||
|
|
||||||
|
Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref());
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
rc = deviceOperator.Get.GetAndClearMmcErrorInfo(out outErrorInfo, out long logSize, new OutBuffer(logBuffer),
|
||||||
|
logBuffer.Length);
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
outLogSize = logSize;
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result GetMmcExtendedCsd(this FileSystemClient fs, Span<byte> outBuffer)
|
||||||
|
{
|
||||||
|
using SharedRef<IFileSystemProxy> fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject();
|
||||||
|
using var deviceOperator = new SharedRef<IDeviceOperator>();
|
||||||
|
|
||||||
|
Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref());
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
rc = deviceOperator.Get.GetMmcExtendedCsd(new OutBuffer(outBuffer), outBuffer.Length);
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result SuspendMmcPatrol(this FileSystemClient fs)
|
||||||
|
{
|
||||||
|
using SharedRef<IFileSystemProxy> fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject();
|
||||||
|
using var deviceOperator = new SharedRef<IDeviceOperator>();
|
||||||
|
|
||||||
|
Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref());
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
rc = deviceOperator.Get.SuspendMmcPatrol();
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result ResumeMmcPatrol(this FileSystemClient fs)
|
||||||
|
{
|
||||||
|
using SharedRef<IFileSystemProxy> fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject();
|
||||||
|
using var deviceOperator = new SharedRef<IDeviceOperator>();
|
||||||
|
|
||||||
|
Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref());
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
rc = deviceOperator.Get.ResumeMmcPatrol();
|
||||||
|
fs.Impl.AbortIfNeeded(rc);
|
||||||
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue