From a45c541aca4ee5781ba803fa1b511bf25e2ac200 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Thu, 7 Jul 2022 23:14:06 -0700 Subject: [PATCH] Replace the old EmulatedSdCard class --- src/LibHac/FsSrv/DefaultFsServerObjects.cs | 7 +- src/LibHac/FsSrv/EmulatedDeviceOperator.cs | 250 ------------------ src/LibHac/FsSrv/EmulatedSdCard.cs | 16 -- .../EmulatedSdCardFileSystemCreator.cs | 13 +- src/LibHac/Sdmmc/Common.cs | 6 + src/LibHac/Sdmmc/SdCard.cs | 21 +- .../FileSystemServerFactory.cs | 2 +- 7 files changed, 34 insertions(+), 281 deletions(-) delete mode 100644 src/LibHac/FsSrv/EmulatedDeviceOperator.cs delete mode 100644 src/LibHac/FsSrv/EmulatedSdCard.cs diff --git a/src/LibHac/FsSrv/DefaultFsServerObjects.cs b/src/LibHac/FsSrv/DefaultFsServerObjects.cs index c97c046a..3e9f71ef 100644 --- a/src/LibHac/FsSrv/DefaultFsServerObjects.cs +++ b/src/LibHac/FsSrv/DefaultFsServerObjects.cs @@ -13,7 +13,7 @@ public class DefaultFsServerObjects { public FileSystemCreatorInterfaces FsCreators { get; set; } public EmulatedGameCard GameCard { get; set; } - public EmulatedSdCard SdCard { get; set; } + public SdmmcApi Sdmmc { get; set; } public GameCardDummy GameCardNew { get; set; } public EmulatedStorageDeviceManagerFactory StorageDeviceManagerFactory { get; set; } @@ -22,7 +22,6 @@ public class DefaultFsServerObjects { var creators = new FileSystemCreatorInterfaces(); var gameCard = new EmulatedGameCard(keySet); - var sdCard = new EmulatedSdCard(); var gameCardNew = new GameCardDummy(); var sdmmcNew = new SdmmcApi(fsServer); @@ -43,7 +42,7 @@ public class DefaultFsServerObjects creators.GameCardFileSystemCreator = new EmulatedGameCardFsCreator(gcStorageCreator, gameCard); creators.EncryptedFileSystemCreator = new EncryptedFileSystemCreator(keySet); creators.BuiltInStorageFileSystemCreator = new EmulatedBisFileSystemCreator(ref sharedRootFileSystem.Ref); - creators.SdCardFileSystemCreator = new EmulatedSdCardFileSystemCreator(sdCard, ref sharedRootFileSystemCopy.Ref); + creators.SdCardFileSystemCreator = new EmulatedSdCardFileSystemCreator(sdmmcNew, ref sharedRootFileSystemCopy.Ref); var storageDeviceManagerFactory = new EmulatedStorageDeviceManagerFactory(fsServer, sdmmcNew, gameCardNew, hasGameCard: true); @@ -51,7 +50,7 @@ public class DefaultFsServerObjects { FsCreators = creators, GameCard = gameCard, - SdCard = sdCard, + Sdmmc = sdmmcNew, GameCardNew = gameCardNew, StorageDeviceManagerFactory = storageDeviceManagerFactory }; diff --git a/src/LibHac/FsSrv/EmulatedDeviceOperator.cs b/src/LibHac/FsSrv/EmulatedDeviceOperator.cs deleted file mode 100644 index e1793966..00000000 --- a/src/LibHac/FsSrv/EmulatedDeviceOperator.cs +++ /dev/null @@ -1,250 +0,0 @@ -using System; -using LibHac.Common; -using LibHac.Fs; -using LibHac.FsSrv.Sf; -using LibHac.Sf; - -namespace LibHac.FsSrv; - -public class EmulatedDeviceOperator : IDeviceOperator -{ - private EmulatedGameCard GameCard { get; set; } - private EmulatedSdCard SdCard { get; set; } - - public EmulatedDeviceOperator(EmulatedGameCard gameCard, EmulatedSdCard sdCard) - { - GameCard = gameCard; - SdCard = sdCard; - } - - public void Dispose() { } - - public Result IsSdCardInserted(out bool outIsInserted) - { - outIsInserted = SdCard.IsSdCardInserted(); - return Result.Success; - } - - public Result GetSdCardSpeedMode(out long outSpeedMode) - { - throw new NotImplementedException(); - } - - public Result GetSdCardCid(OutBuffer outBuffer, long outBufferSize) - { - throw new NotImplementedException(); - } - - public Result GetSdCardUserAreaSize(out long outSize) - { - throw new NotImplementedException(); - } - - public Result GetSdCardProtectedAreaSize(out long outSize) - { - throw new NotImplementedException(); - } - - public Result GetAndClearSdCardErrorInfo(out StorageErrorInfo outStorageErrorInfo, out long outLogSize, - OutBuffer logBuffer, long logBufferSize) - { - throw new NotImplementedException(); - } - - public Result GetMmcCid(OutBuffer outBuffer, long outBufferSize) - { - throw new NotImplementedException(); - } - - public Result GetMmcSpeedMode(out long outSpeedMode) - { - throw new NotImplementedException(); - } - - public Result EraseMmc(uint partitionId) - { - throw new NotImplementedException(); - } - - public Result GetMmcPartitionSize(out long outSize, uint partitionId) - { - throw new NotImplementedException(); - } - - public Result GetMmcPatrolCount(out uint outCount) - { - throw new NotImplementedException(); - } - - public Result GetAndClearMmcErrorInfo(out StorageErrorInfo outStorageErrorInfo, out long outLogSize, - OutBuffer logBuffer, long logBufferSize) - { - throw new NotImplementedException(); - } - - public Result GetMmcExtendedCsd(OutBuffer outBuffer, long outBufferSize) - { - throw new NotImplementedException(); - } - - public Result SuspendMmcPatrol() - { - throw new NotImplementedException(); - } - - public Result ResumeMmcPatrol() - { - throw new NotImplementedException(); - } - - public Result IsGameCardInserted(out bool outIsInserted) - { - outIsInserted = GameCard.IsGameCardInserted(); - return Result.Success; - } - - public Result EraseGameCard(uint gameCardSize, ulong romAreaStartPageAddress) - { - throw new NotImplementedException(); - } - - public Result GetGameCardUpdatePartitionInfo(out uint outCupVersion, out ulong outCupId, uint handle) - { - throw new NotImplementedException(); - } - - public Result FinalizeGameCardDriver() - { - throw new NotImplementedException(); - } - - public Result GetGameCardAttribute(out byte outAttribute, uint handle) - { - throw new NotImplementedException(); - } - - public Result GetGameCardDeviceCertificate(OutBuffer outBuffer, long outBufferSize, uint handle) - { - throw new NotImplementedException(); - } - - public Result GetGameCardAsicInfo(OutBuffer outRmaInfoBuffer, long rmaInfoBufferSize, InBuffer asicFirmwareBuffer, - long asicFirmwareBufferSize) - { - throw new NotImplementedException(); - } - - public Result GetGameCardIdSet(OutBuffer outBuffer, long outBufferSize) - { - throw new NotImplementedException(); - } - - public Result WriteToGameCardDirectly(long offset, OutBuffer buffer, long bufferSize) - { - throw new NotImplementedException(); - } - - public Result SetVerifyWriteEnableFlag(bool isEnabled) - { - throw new NotImplementedException(); - } - - public Result GetGameCardImageHash(OutBuffer outBuffer, long outBufferSize, uint handle) - { - throw new NotImplementedException(); - } - - public Result GetGameCardDeviceIdForProdCard(OutBuffer outBuffer, long outBufferSize, InBuffer devHeaderBuffer, - long devHeaderBufferSize) - { - throw new NotImplementedException(); - } - - public Result EraseAndWriteParamDirectly(InBuffer inBuffer, long inBufferSize) - { - throw new NotImplementedException(); - } - - public Result ReadParamDirectly(OutBuffer outBuffer, long outBufferSize) - { - throw new NotImplementedException(); - } - - public Result ForceEraseGameCard() - { - throw new NotImplementedException(); - } - - public Result GetGameCardErrorInfo(out GameCardErrorInfo outErrorInfo) - { - throw new NotImplementedException(); - } - - public Result GetGameCardErrorReportInfo(out GameCardErrorReportInfo outErrorInfo) - { - throw new NotImplementedException(); - } - - public Result GetGameCardDeviceId(OutBuffer outBuffer, long outBufferSize) - { - throw new NotImplementedException(); - } - - public Result ChallengeCardExistence(OutBuffer outResponseBuffer, InBuffer challengeSeedBuffer, - InBuffer challengeValueBuffer, uint handle) - { - throw new NotImplementedException(); - } - - public Result GetGameCardCompatibilityType(out byte outCompatibilityType, uint handle) - { - throw new NotImplementedException(); - } - - public Result SetSpeedEmulationMode(int mode) - { - throw new NotImplementedException(); - } - - public Result GetSpeedEmulationMode(out int outMode) - { - throw new NotImplementedException(); - } - - public Result SuspendSdmmcControl() - { - throw new NotImplementedException(); - } - - public Result ResumeSdmmcControl() - { - throw new NotImplementedException(); - } - - public Result GetSdmmcConnectionStatus(out int outSpeedMode, out int outBusWidth, int port) - { - throw new NotImplementedException(); - } - - public Result SetDeviceSimulationEvent(uint port, uint simulatedOperationType, uint simulatedFailureType, - uint failureResult, bool autoClearEvent) - { - throw new NotImplementedException(); - } - - public Result ClearDeviceSimulationEvent(uint port) - { - throw new NotImplementedException(); - } - - public Result GetGameCardHandle(out GameCardHandle handle) - { - UnsafeHelpers.SkipParamInit(out handle); - - if (!GameCard.IsGameCardInserted()) - return ResultFs.GameCardFsGetHandleFailure.Log(); - - handle = GameCard.GetGameCardHandle(); - return Result.Success; - } -} \ No newline at end of file diff --git a/src/LibHac/FsSrv/EmulatedSdCard.cs b/src/LibHac/FsSrv/EmulatedSdCard.cs deleted file mode 100644 index d8c007d9..00000000 --- a/src/LibHac/FsSrv/EmulatedSdCard.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace LibHac.FsSrv; - -public class EmulatedSdCard -{ - private bool IsInserted { get; set; } - - public bool IsSdCardInserted() - { - return IsInserted; - } - - public void SetSdCardInsertionStatus(bool isInserted) - { - IsInserted = isInserted; - } -} \ No newline at end of file diff --git a/src/LibHac/FsSrv/FsCreator/EmulatedSdCardFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/EmulatedSdCardFileSystemCreator.cs index 6c9f87ef..84aeb46c 100644 --- a/src/LibHac/FsSrv/FsCreator/EmulatedSdCardFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/EmulatedSdCardFileSystemCreator.cs @@ -2,6 +2,7 @@ using LibHac.Common; using LibHac.Fs; using LibHac.Fs.Fsa; +using LibHac.Sdmmc; using LibHac.Util; using Utility = LibHac.FsSrv.Impl.Utility; @@ -11,20 +12,20 @@ public class EmulatedSdCardFileSystemCreator : ISdCardProxyFileSystemCreator, ID { private const string DefaultPath = "/sdcard"; - private EmulatedSdCard _sdCard; + private SdmmcApi _sdmmc; private SharedRef _rootFileSystem; private SharedRef _sdCardFileSystem; private string _path; - public EmulatedSdCardFileSystemCreator(EmulatedSdCard sdCard, ref SharedRef rootFileSystem) + public EmulatedSdCardFileSystemCreator(SdmmcApi sdmmc, ref SharedRef rootFileSystem) { - _sdCard = sdCard; + _sdmmc = sdmmc; _rootFileSystem = SharedRef.CreateMove(ref rootFileSystem); } - public EmulatedSdCardFileSystemCreator(EmulatedSdCard sdCard, ref SharedRef rootFileSystem, string path) + public EmulatedSdCardFileSystemCreator(SdmmcApi sdmmc, ref SharedRef rootFileSystem, string path) { - _sdCard = sdCard; + _sdmmc = sdmmc; _rootFileSystem = SharedRef.CreateMove(ref rootFileSystem); _path = path; } @@ -37,7 +38,7 @@ public class EmulatedSdCardFileSystemCreator : ISdCardProxyFileSystemCreator, ID public Result Create(ref SharedRef outFileSystem, bool openCaseSensitive) { - if (!_sdCard.IsSdCardInserted()) + if (!_sdmmc.IsSdCardInserted(Port.SdCard0)) { return ResultFs.PortSdCardNoDevice.Log(); } diff --git a/src/LibHac/Sdmmc/Common.cs b/src/LibHac/Sdmmc/Common.cs index 30b35194..67e5f600 100644 --- a/src/LibHac/Sdmmc/Common.cs +++ b/src/LibHac/Sdmmc/Common.cs @@ -96,6 +96,12 @@ public partial class SdmmcApi public Result Activate(Port port) { + if (port == Port.SdCard0) + { + _isSdCardRemoved = false; + return Result.Success; + } + throw new NotImplementedException(); } diff --git a/src/LibHac/Sdmmc/SdCard.cs b/src/LibHac/Sdmmc/SdCard.cs index b2dfabcb..8015af67 100644 --- a/src/LibHac/Sdmmc/SdCard.cs +++ b/src/LibHac/Sdmmc/SdCard.cs @@ -20,6 +20,19 @@ public partial class SdmmcApi public const int SdCardWorkBufferSize = SdCardSdStatusSize; + private bool _isSdCardInserted; + private bool _isSdCardRemoved; + + public void SetSdCardInserted(bool isInserted) + { + if (_isSdCardInserted && isInserted == false) + { + _isSdCardRemoved = true; + } + + _isSdCardInserted = isInserted; + } + public void SetSdCardWorkBuffer(Port port, Memory workBuffer) { throw new NotImplementedException(); @@ -67,21 +80,21 @@ public partial class SdmmcApi public void RegisterSdCardDetectionEventCallback(Port port, DeviceDetectionEventCallback callback, object args) { - throw new NotImplementedException(); + } public void UnregisterSdCardDetectionEventCallback(Port port) { - throw new NotImplementedException(); + } public bool IsSdCardInserted(Port port) { - throw new NotImplementedException(); + return _isSdCardInserted; } public bool IsSdCardRemoved(Port port) { - throw new NotImplementedException(); + return _isSdCardRemoved; } } \ No newline at end of file diff --git a/tests/LibHac.Tests/Fs/FileSystemClientTests/FileSystemServerFactory.cs b/tests/LibHac.Tests/Fs/FileSystemClientTests/FileSystemServerFactory.cs index 9fa21fb6..b030a5ed 100644 --- a/tests/LibHac.Tests/Fs/FileSystemClientTests/FileSystemServerFactory.cs +++ b/tests/LibHac.Tests/Fs/FileSystemClientTests/FileSystemServerFactory.cs @@ -42,7 +42,7 @@ public static class FileSystemServerFactory DefaultFsServerObjects.GetDefaultEmulatedCreators(hos.RootFileSystem, keySet, hos.FsServer, randomGenerator); - defaultObjects.SdCard.SetSdCardInsertionStatus(sdCardInserted); + defaultObjects.Sdmmc.SetSdCardInserted(sdCardInserted); var config = new FileSystemServerConfig(); config.FsCreators = defaultObjects.FsCreators;