Skeleton most of sdmmcsrv

This commit is contained in:
Alex Barney 2022-06-29 13:32:11 -07:00
parent e76166d6d0
commit 6b2ee7a54d
15 changed files with 831 additions and 33 deletions

View file

@ -4,6 +4,7 @@ using LibHac.FsSrv.FsCreator;
using LibHac.FsSrv.Storage;
using LibHac.FsSystem;
using LibHac.Gc;
using LibHac.Sdmmc;
using IFileSystem = LibHac.Fs.Fsa.IFileSystem;
namespace LibHac.FsSrv;
@ -24,6 +25,7 @@ public class DefaultFsServerObjects
var sdCard = new EmulatedSdCard();
var gameCardNew = new GameCardDummy();
var sdmmcNew = new SdmmcApi();
var gcStorageCreator = new EmulatedGameCardStorageCreator(gameCard);
@ -43,7 +45,7 @@ public class DefaultFsServerObjects
creators.BuiltInStorageFileSystemCreator = new EmulatedBisFileSystemCreator(ref sharedRootFileSystem.Ref);
creators.SdCardFileSystemCreator = new EmulatedSdCardFileSystemCreator(sdCard, ref sharedRootFileSystemCopy.Ref);
var storageDeviceManagerFactory = new EmulatedStorageDeviceManagerFactory(fsServer, gameCardNew, hasGameCard: true);
var storageDeviceManagerFactory = new EmulatedStorageDeviceManagerFactory(fsServer, sdmmcNew, gameCardNew, hasGameCard: true);
return new DefaultFsServerObjects
{

View file

@ -4,6 +4,7 @@ using LibHac.FsSrv.Storage.Sf;
using LibHac.Gc;
using LibHac.GcSrv;
using LibHac.Os;
using LibHac.Sdmmc;
using LibHac.SdmmcSrv;
using LibHac.Sf;
@ -23,11 +24,14 @@ public class EmulatedStorageDeviceManagerFactory : IStorageDeviceManagerFactory
private readonly bool _hasGameCard;
private readonly FileSystemServer _fsServer;
private readonly SdmmcApi _sdmmc;
private readonly GameCardDummy _gc;
public EmulatedStorageDeviceManagerFactory(FileSystemServer fsServer, GameCardDummy gc, bool hasGameCard)
public EmulatedStorageDeviceManagerFactory(FileSystemServer fsServer, SdmmcApi sdmmc, GameCardDummy gc,
bool hasGameCard)
{
_fsServer = fsServer;
_sdmmc = sdmmc;
_gc = gc;
_hasGameCard = hasGameCard;
@ -195,7 +199,7 @@ public class EmulatedStorageDeviceManagerFactory : IStorageDeviceManagerFactory
if (!_sdCardDeviceManager.HasValue)
{
_sdCardDeviceManager.Reset(new SdCardManager());
_sdCardDeviceManager.Reset(new SdCardManager(_sdmmc));
// Todo: BuiltInStorageFileSystemCreator::SetSdCardPortReady
}

View file

@ -11,4 +11,9 @@ public static class Common
return Result.Success;
}
public static uint BytesToSectors(long byteCount)
{
return (uint)((ulong)byteCount / SdmmcApi.SectorSize);
}
}

View file

@ -1,11 +1,14 @@
using LibHac.Fs;
using System;
using LibHac.Fs;
using LibHac.Os;
using LibHac.Sdmmc;
namespace LibHac.SdmmcSrv;
internal interface ISdmmcDeviceManager
internal interface ISdmmcDeviceManager : IDisposable
{
Result Lock(out object locker, uint handle);
Result Lock(ref UniqueLockRef<SdkMutexType> outLock, SdmmcHandle handle);
IStorage GetStorage();
SdmmcPort GetPortId();
Result NotifyCloseStorageDevice(uint handle);
Port GetPort();
void NotifyCloseStorageDevice(SdmmcHandle handle);
}

View file

@ -0,0 +1,54 @@
using System;
using LibHac.Common;
using LibHac.FsSrv.Storage.Sf;
using LibHac.Sf;
namespace LibHac.SdmmcSrv;
internal class MmcDeviceOperator : IStorageDeviceOperator
{
private SharedRef<MmcPartitionStorageDevice> _baseDevice;
public MmcDeviceOperator(ref SharedRef<MmcPartitionStorageDevice> baseDevice)
{
_baseDevice = SharedRef<MmcPartitionStorageDevice>.CreateMove(ref baseDevice);
}
public void Dispose()
{
_baseDevice.Destroy();
}
public Result Operate(int operationId)
{
throw new NotImplementedException();
}
public Result OperateIn(InBuffer buffer, long offset, long size, int operationId)
{
throw new NotImplementedException();
}
public Result OperateOut(out long bytesWritten, OutBuffer buffer, int operationId)
{
throw new NotImplementedException();
}
public Result OperateOut2(out long bytesWrittenBuffer1, OutBuffer buffer1, out long bytesWrittenBuffer2,
OutBuffer buffer2, int operationId)
{
throw new NotImplementedException();
}
public Result OperateInOut(out long bytesWritten, OutBuffer outBuffer, InBuffer inBuffer, long offset, long size,
int operationId)
{
throw new NotImplementedException();
}
public Result OperateIn2Out(out long bytesWritten, OutBuffer outBuffer, InBuffer inBuffer1, InBuffer inBuffer2,
long offset, long size, int operationId)
{
throw new NotImplementedException();
}
}

View file

@ -2,11 +2,20 @@
using LibHac.Common;
using LibHac.FsSrv.Sf;
using LibHac.FsSrv.Storage.Sf;
using LibHac.Os;
using LibHac.Sdmmc;
using LibHac.Sf;
using IStorage = LibHac.FsSrv.Sf.IStorage;
namespace LibHac.SdmmcSrv;
public class MmcManager : IStorageDeviceManager
public class MmcManager : IStorageDeviceManager, IStorageDeviceOperator, ISdmmcDeviceManager
{
private Port _port;
private bool _isInitialized;
private bool _isActivated;
private SdkMutexType _mutex;
public MmcManager()
{
throw new NotImplementedException();
@ -17,12 +26,17 @@ public class MmcManager : IStorageDeviceManager
throw new NotImplementedException();
}
public void InitializeMmc()
{
throw new NotImplementedException();
}
public Result IsInserted(out bool isInserted)
{
throw new NotImplementedException();
}
public Result IsHandleValid(out bool isValid, uint handle)
public Result IsHandleValid(out bool isValid, SdmmcHandle handle)
{
throw new NotImplementedException();
}
@ -47,6 +61,11 @@ public class MmcManager : IStorageDeviceManager
throw new NotImplementedException();
}
private Result OpenStorageDevice(ref SharedRef<IStorageDevice> outStorageDevice, ulong attribute)
{
throw new NotImplementedException();
}
public Result PutToSleep()
{
throw new NotImplementedException();
@ -66,4 +85,57 @@ public class MmcManager : IStorageDeviceManager
{
throw new NotImplementedException();
}
public Result Lock(ref UniqueLockRef<SdkMutexType> outLock, SdmmcHandle handle)
{
throw new NotImplementedException();
}
public Fs.IStorage GetStorage()
{
throw new NotImplementedException();
}
public Port GetPort()
{
throw new NotImplementedException();
}
public void NotifyCloseStorageDevice(SdmmcHandle handle)
{
throw new NotImplementedException();
}
public Result Operate(int operationId)
{
throw new NotImplementedException();
}
public Result OperateIn(InBuffer buffer, long offset, long size, int operationId)
{
throw new NotImplementedException();
}
public Result OperateOut(out long bytesWritten, OutBuffer buffer, int operationId)
{
throw new NotImplementedException();
}
public Result OperateOut2(out long bytesWrittenBuffer1, OutBuffer buffer1, out long bytesWrittenBuffer2,
OutBuffer buffer2, int operationId)
{
throw new NotImplementedException();
}
public Result OperateInOut(out long bytesWritten, OutBuffer outBuffer, InBuffer inBuffer, long offset, long size,
int operationId)
{
throw new NotImplementedException();
}
public Result OperateIn2Out(out long bytesWritten, OutBuffer outBuffer, InBuffer inBuffer1, InBuffer inBuffer2,
long offset, long size, int operationId)
{
throw new NotImplementedException();
}
}

View file

@ -0,0 +1,255 @@
using System;
using LibHac.Common;
using LibHac.Diag;
using LibHac.Fs;
using LibHac.FsSrv.Storage.Sf;
using LibHac.Os;
using LibHac.Sdmmc;
using LibHac.Sf;
using MmcPartition = LibHac.Sdmmc.MmcPartition;
namespace LibHac.SdmmcSrv;
internal class MmcPartitionStorageDevice : IDisposable
{
private SharedRef<ISdmmcDeviceManager> _manager;
private SdmmcHandle _handle;
private MmcPartition _partition;
public MmcPartitionStorageDevice(ref SharedRef<ISdmmcDeviceManager> manager, SdmmcHandle handle, MmcPartition partition)
{
_manager = SharedRef<ISdmmcDeviceManager>.CreateMove(ref manager);
_handle = handle;
_partition = partition;
}
public void Dispose() { }
public Result GetHandle(out SdmmcHandle handle)
{
handle = _handle;
return Result.Success;
}
public Result IsHandleValid(out bool isValid)
{
using var scopedLock = new UniqueLockRef<SdkMutexType>();
isValid = _manager.Get.Lock(ref scopedLock.Ref(), _handle).IsSuccess();
return Result.Success;
}
public Result OpenOperator(ref SharedRef<IStorageDeviceOperator> outDeviceOperator)
{
throw new NotImplementedException();
}
public Result Lock(ref UniqueLockRef<SdkMutexType> outLock)
{
return _manager.Get.Lock(ref outLock.Ref(), _handle).Ret();
}
public Port GetPort()
{
return _manager.Get.GetPort();
}
public MmcPartition GetPartition()
{
return _partition;
}
}
// The Mmc*PartitionStorageDevice classes inherit both from SdmmcStorageInterfaceAdapter and MmcPartitionStorageDevice
// Because C# doesn't have multiple inheritance, we make a copy of the SdmmcStorageInterfaceAdapter class that inherits
// from MmcPartitionStorageDevice. This class must mirror any changes made to SdmmcStorageInterfaceAdapter.
internal class MmcPartitionStorageDeviceInterfaceAdapter : MmcPartitionStorageDevice, IStorageDevice
{
private IStorage _baseStorage;
public MmcPartitionStorageDeviceInterfaceAdapter(IStorage baseStorage, ref SharedRef<ISdmmcDeviceManager> manager,
SdmmcHandle handle, MmcPartition partition) : base(ref manager, handle, partition)
{
_baseStorage = baseStorage;
}
public virtual Result Read(long offset, OutBuffer destination, long size)
{
return _baseStorage.Read(offset, destination.Buffer.Slice(0, (int)size)).Ret();
}
public virtual Result Write(long offset, InBuffer source, long size)
{
return _baseStorage.Write(offset, source.Buffer.Slice(0, (int)size)).Ret();
}
public virtual Result Flush()
{
return _baseStorage.Flush().Ret();
}
public virtual Result SetSize(long size)
{
return _baseStorage.SetSize(size).Ret();
}
public virtual Result GetSize(out long size)
{
return _baseStorage.GetSize(out size).Ret();
}
public virtual Result OperateRange(out QueryRangeInfo rangeInfo, int operationId, long offset, long size)
{
UnsafeHelpers.SkipParamInit(out rangeInfo);
return _baseStorage.OperateRange(SpanHelpers.AsByteSpan(ref rangeInfo), (OperationId)operationId, offset,
size, ReadOnlySpan<byte>.Empty).Ret();
}
}
internal class MmcUserDataPartitionStorageDevice : MmcPartitionStorageDeviceInterfaceAdapter
{
public MmcUserDataPartitionStorageDevice(ref SharedRef<ISdmmcDeviceManager> manager, SdmmcHandle handle)
: base(manager.Get.GetStorage(), ref manager, handle, MmcPartition.UserData)
{ }
public override Result Read(long offset, OutBuffer destination, long size)
{
using var scopedLock = new UniqueLockRef<SdkMutexType>();
Result res = Lock(ref scopedLock.Ref());
if (res.IsFailure()) return res.Miss();
base.Read(offset, destination, size);
if (res.IsFailure()) return res.Miss();
return Result.Success;
}
public override Result Write(long offset, InBuffer source, long size)
{
using var scopedLock = new UniqueLockRef<SdkMutexType>();
Result res = Lock(ref scopedLock.Ref());
if (res.IsFailure()) return res.Miss();
res = base.Write(offset, source, size);
if (res.IsFailure()) return res.Miss();
return Result.Success;
}
public override Result GetSize(out long size)
{
UnsafeHelpers.SkipParamInit(out size);
using var scopedLock = new UniqueLockRef<SdkMutexType>();
Result res = Lock(ref scopedLock.Ref());
if (res.IsFailure()) return res.Miss();
res = base.GetSize(out size);
if (res.IsFailure()) return res.Miss();
return Result.Success;
}
}
internal class MmcBootPartitionStorageDevice : MmcPartitionStorageDeviceInterfaceAdapter
{
private SdmmcApi _sdmmc;
public MmcBootPartitionStorageDevice(ref SharedRef<ISdmmcDeviceManager> manager, Fs.MmcPartition partition,
SdmmcHandle handle, SdmmcApi sdmmc) : base(manager.Get.GetStorage(), ref manager, handle, GetPartition(partition))
{
_sdmmc = sdmmc;
}
private static MmcPartition GetPartition(Fs.MmcPartition partition)
{
switch (partition)
{
case Fs.MmcPartition.UserData:
return MmcPartition.UserData;
case Fs.MmcPartition.BootPartition1:
return MmcPartition.BootPartition1;
case Fs.MmcPartition.BootPartition2:
return MmcPartition.BootPartition2;
default:
Abort.UnexpectedDefault();
return default;
}
}
public override Result Read(long offset, OutBuffer destination, long size)
{
using var scopedLock = new UniqueLockRef<SdkMutexType>();
Result res = Lock(ref scopedLock.Ref());
if (res.IsFailure()) return res.Miss();
Abort.DoAbortUnlessSuccess(_sdmmc.SelectMmcPartition(GetPort(), GetPartition()));
try
{
base.Read(offset, destination, size);
if (res.IsFailure()) return res.Miss();
return Result.Success;
}
finally
{
Abort.DoAbortUnlessSuccess(_sdmmc.SelectMmcPartition(GetPort(), MmcPartition.UserData));
}
}
public override Result Write(long offset, InBuffer source, long size)
{
using var scopedLock = new UniqueLockRef<SdkMutexType>();
Result res = Lock(ref scopedLock.Ref());
if (res.IsFailure()) return res.Miss();
Abort.DoAbortUnlessSuccess(_sdmmc.SelectMmcPartition(GetPort(), GetPartition()));
try
{
base.Write(offset, source, size);
if (res.IsFailure()) return res.Miss();
return Result.Success;
}
finally
{
Abort.DoAbortUnlessSuccess(_sdmmc.SelectMmcPartition(GetPort(), MmcPartition.UserData));
}
}
public override Result GetSize(out long size)
{
UnsafeHelpers.SkipParamInit(out size);
using var scopedLock = new UniqueLockRef<SdkMutexType>();
Result res = Lock(ref scopedLock.Ref());
if (res.IsFailure()) return res.Miss();
Port port = GetPort();
Abort.DoAbortUnlessSuccess(_sdmmc.SelectMmcPartition(port, GetPartition()));
try
{
res = SdmmcResultConverter.GetFsResult(port, _sdmmc.GetMmcBootPartitionCapacity(out uint numSectors, port));
if (res.IsFailure()) return res.Miss();
size = numSectors * SdmmcApi.SectorSize;
return Result.Success;
}
finally
{
Abort.DoAbortUnlessSuccess(_sdmmc.SelectMmcPartition(GetPort(), MmcPartition.UserData));
}
}
}

View file

@ -0,0 +1,72 @@
using System;
using LibHac.Os;
namespace LibHac.SdmmcSrv;
internal class PatrolReader
{
public PatrolReader(SdkMutex mutex)
{
throw new NotImplementedException();
}
public void Dispose()
{
throw new NotImplementedException();
}
public static void PatrolReaderThreadEntry(object args)
{
throw new NotImplementedException();
}
public void FinalizeObject()
{
throw new NotImplementedException();
}
public Result GetPatrolCount(out uint outCount)
{
throw new NotImplementedException();
}
public void GetAndClearAllocateCount(out long outSuccessCount, out long outFailureCount)
{
throw new NotImplementedException();
}
public bool LoadState()
{
throw new NotImplementedException();
}
public bool SaveState()
{
throw new NotImplementedException();
}
public void Start()
{
throw new NotImplementedException();
}
public void Stop()
{
throw new NotImplementedException();
}
public void Sleep()
{
throw new NotImplementedException();
}
public void Resume()
{
throw new NotImplementedException();
}
public void PatrolReaderThread()
{
throw new NotImplementedException();
}
}

View file

@ -0,0 +1,25 @@
using LibHac.FsSystem;
using LibHac.Sdmmc;
namespace LibHac.SdmmcSrv;
internal class SdCardDetectionEventManager : CardDeviceDetectionEventManager
{
// LibHac addition
private SdmmcApi _sdmmc;
public SdCardDetectionEventManager(Port port, SdmmcApi sdmmc)
{
CallbackArgs.Port = port;
_sdmmc = sdmmc;
_sdmmc.RegisterSdCardDetectionEventCallback(port, DetectionEventCallback, CallbackArgs);
}
public override void Dispose()
{
_sdmmc.UnregisterSdCardDetectionEventCallback(CallbackArgs.Port);
base.Dispose();
}
}

View file

@ -1,19 +0,0 @@
using System;
using LibHac.FsSystem;
namespace LibHac.SdmmcSrv;
internal class SdCardDeviceDetectionEventManager : CardDeviceDetectionEventManager
{
public SdCardDeviceDetectionEventManager(Sdmmc.Port port)
{
CallbackArgs.Port = port;
throw new NotImplementedException();
}
public override void Dispose()
{
throw new NotImplementedException();
}
}

View file

@ -0,0 +1,54 @@
using System;
using LibHac.Common;
using LibHac.FsSrv.Storage.Sf;
using LibHac.Sf;
namespace LibHac.SdmmcSrv;
internal class SdCardDeviceOperator : IStorageDeviceOperator
{
private SharedRef<SdCardStorageDevice> _storageDevice;
public SdCardDeviceOperator(ref SharedRef<SdCardStorageDevice> storageDevice)
{
throw new NotImplementedException();
}
public void Dispose()
{
_storageDevice.Destroy();
}
public Result Operate(int operationId)
{
throw new NotImplementedException();
}
public Result OperateIn(InBuffer buffer, long offset, long size, int operationId)
{
throw new NotImplementedException();
}
public Result OperateOut(out long bytesWritten, OutBuffer buffer, int operationId)
{
throw new NotImplementedException();
}
public Result OperateOut2(out long bytesWrittenBuffer1, OutBuffer buffer1, out long bytesWrittenBuffer2,
OutBuffer buffer2, int operationId)
{
throw new NotImplementedException();
}
public Result OperateInOut(out long bytesWritten, OutBuffer outBuffer, InBuffer inBuffer, long offset, long size,
int operationId)
{
throw new NotImplementedException();
}
public Result OperateIn2Out(out long bytesWritten, OutBuffer outBuffer, InBuffer inBuffer1, InBuffer inBuffer2,
long offset, long size, int operationId)
{
throw new NotImplementedException();
}
}

View file

@ -2,17 +2,39 @@
using LibHac.Common;
using LibHac.FsSrv.Sf;
using LibHac.FsSrv.Storage.Sf;
using LibHac.Os;
using LibHac.Sdmmc;
using LibHac.Sf;
using LibHac.Util;
namespace LibHac.SdmmcSrv;
public class SdCardManager : IStorageDeviceManager
{
public SdCardManager()
public class SdCardManager : IStorageDeviceManager, IStorageDeviceOperator, ISdmmcDeviceManager
{
private Port _port;
private bool _isInitialized;
private SdkMutexType _mutex;
private SdmmcStorage _sdStorage;
private SdmmcHandle _handle;
private Optional<SdCardDetectionEventManager> _detectionEventManager;
public SdCardManager(SdmmcApi sdmmc)
{
_port = Port.SdCard0;
_mutex = new SdkMutexType();
_sdStorage = new SdmmcStorage(_port, sdmmc);
}
public void Dispose()
{
if (_detectionEventManager.HasValue)
{
_detectionEventManager.Value.Dispose();
_detectionEventManager = default;
}
}
public void InitializeSd()
{
throw new NotImplementedException();
}
@ -22,7 +44,7 @@ public class SdCardManager : IStorageDeviceManager
throw new NotImplementedException();
}
public Result IsHandleValid(out bool isValid, uint handle)
public Result IsHandleValid(out bool isValid, SdmmcHandle handle)
{
throw new NotImplementedException();
}
@ -47,6 +69,11 @@ public class SdCardManager : IStorageDeviceManager
throw new NotImplementedException();
}
private Result OpenStorageDevice(ref SharedRef<IStorageDevice> outStorageDevice, ulong attribute)
{
throw new NotImplementedException();
}
public Result PutToSleep()
{
throw new NotImplementedException();
@ -66,4 +93,57 @@ public class SdCardManager : IStorageDeviceManager
{
throw new NotImplementedException();
}
public Result Lock(ref UniqueLockRef<SdkMutexType> outLock, SdmmcHandle handle)
{
throw new NotImplementedException();
}
public Fs.IStorage GetStorage()
{
throw new NotImplementedException();
}
public Port GetPort()
{
throw new NotImplementedException();
}
public void NotifyCloseStorageDevice(uint handle)
{
throw new NotImplementedException();
}
public Result Operate(int operationId)
{
throw new NotImplementedException();
}
public Result OperateIn(InBuffer buffer, long offset, long size, int operationId)
{
throw new NotImplementedException();
}
public Result OperateOut(out long bytesWritten, OutBuffer buffer, int operationId)
{
throw new NotImplementedException();
}
public Result OperateOut2(out long bytesWrittenBuffer1, OutBuffer buffer1, out long bytesWrittenBuffer2,
OutBuffer buffer2, int operationId)
{
throw new NotImplementedException();
}
public Result OperateInOut(out long bytesWritten, OutBuffer outBuffer, InBuffer inBuffer, long offset, long size,
int operationId)
{
throw new NotImplementedException();
}
public Result OperateIn2Out(out long bytesWritten, OutBuffer outBuffer, InBuffer inBuffer1, InBuffer inBuffer2,
long offset, long size, int operationId)
{
throw new NotImplementedException();
}
}

View file

@ -0,0 +1,61 @@
using System;
using LibHac.Common;
using LibHac.FsSrv.Storage.Sf;
using LibHac.Os;
using LibHac.Sdmmc;
using LibHac.Sf;
namespace LibHac.SdmmcSrv;
internal class SdCardStorageDevice : SdmmcStorageInterfaceAdapter, IStorageDevice
{
private SharedRef<ISdmmcDeviceManager> _manager;
private SdmmcHandle _handle;
public SdCardStorageDevice(ref SharedRef<ISdmmcDeviceManager> manager, SdmmcHandle handle)
: base(manager.Get.GetStorage())
{
_manager = SharedRef<ISdmmcDeviceManager>.CreateMove(ref manager);
_handle = handle;
}
public Port GetPort()
{
throw new NotImplementedException();
}
public Result GetHandle(out uint handle)
{
throw new NotImplementedException();
}
public Result IsHandleValid(out bool isValid)
{
throw new NotImplementedException();
}
public Result OpenOperator(ref SharedRef<IStorageDeviceOperator> outDeviceOperator)
{
throw new NotImplementedException();
}
public Result Lock(ref UniqueLockRef<SdkMutexType> outLock)
{
throw new NotImplementedException();
}
public override Result Read(long offset, OutBuffer destination, long size)
{
throw new NotImplementedException();
}
public override Result Write(long offset, InBuffer source, long size)
{
throw new NotImplementedException();
}
public override Result GetSize(out long size)
{
throw new NotImplementedException();
}
}

View file

@ -0,0 +1,32 @@
using System;
using LibHac.Sdmmc;
namespace LibHac.SdmmcSrv;
public static class SdmmcResultConverter
{
public static Result GetFsResult(Port port, Result result)
{
if (result.IsSuccess())
return Result.Success;
if (port == Port.Mmc0)
{
return GetFsResultFromMmcResult(result).Ret();
}
else
{
return GetFsResultFromSdCardResult(result).Ret();
}
}
private static Result GetFsResultFromMmcResult(Result result)
{
throw new NotImplementedException();
}
private static Result GetFsResultFromSdCardResult(Result result)
{
throw new NotImplementedException();
}
}

View file

@ -0,0 +1,98 @@
using System;
using LibHac.Common;
using LibHac.Fs;
using LibHac.Sdmmc;
using LibHac.Sf;
using IStorageSf = LibHac.FsSrv.Sf.IStorage;
namespace LibHac.SdmmcSrv;
internal class SdmmcStorage : IStorage
{
private Port _port;
// LibHac additions
private SdmmcApi _sdmmc;
public SdmmcStorage(Port port, SdmmcApi sdmmc)
{
_port = port;
_sdmmc = sdmmc;
}
public override Result Read(long offset, Span<byte> destination)
{
throw new NotImplementedException();
}
public override Result Write(long offset, ReadOnlySpan<byte> source)
{
throw new NotImplementedException();
}
public override Result Flush()
{
throw new NotImplementedException();
}
public override Result SetSize(long size)
{
throw new NotImplementedException();
}
public override Result GetSize(out long size)
{
throw new NotImplementedException();
}
public override Result OperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
ReadOnlySpan<byte> inBuffer)
{
throw new NotImplementedException();
}
}
internal class SdmmcStorageInterfaceAdapter : IStorageSf
{
private IStorage _baseStorage;
public SdmmcStorageInterfaceAdapter(IStorage baseStorage)
{
_baseStorage = baseStorage;
}
public virtual void Dispose() { }
public virtual Result Read(long offset, OutBuffer destination, long size)
{
return _baseStorage.Read(offset, destination.Buffer.Slice(0, (int)size)).Ret();
}
public virtual Result Write(long offset, InBuffer source, long size)
{
return _baseStorage.Write(offset, source.Buffer.Slice(0, (int)size)).Ret();
}
public virtual Result Flush()
{
return _baseStorage.Flush().Ret();
}
public virtual Result SetSize(long size)
{
return _baseStorage.SetSize(size).Ret();
}
public virtual Result GetSize(out long size)
{
return _baseStorage.GetSize(out size).Ret();
}
public virtual Result OperateRange(out QueryRangeInfo rangeInfo, int operationId, long offset, long size)
{
UnsafeHelpers.SkipParamInit(out rangeInfo);
return _baseStorage.OperateRange(SpanHelpers.AsByteSpan(ref rangeInfo), (OperationId)operationId, offset,
size, ReadOnlySpan<byte>.Empty).Ret();
}
}