public static Result EraseMmc(this StorageService service, MmcPartition partition) { ReferenceCountedDisposable <IStorageDeviceOperator> mmcOperator = null; try { Result rc = service.GetMmcOperator(out mmcOperator, partition); if (rc.IsFailure()) { return(rc); } int operationId = MakeOperationId(MmcOperationIdValue.Erase); return(mmcOperator.Target.Operate(operationId)); } finally { mmcOperator?.Dispose(); } }
private static Result GetAttribute(out ulong attribute, MmcPartition partition) { UnsafeHelpers.SkipParamInit(out attribute); switch (partition) { case MmcPartition.UserData: attribute = 0; return(Result.Success); case MmcPartition.BootPartition1: attribute = 1; return(Result.Success); case MmcPartition.BootPartition2: attribute = 2; return(Result.Success); default: return(ResultFs.InvalidArgument.Log()); } }
private static Result GetMmcOperator(this StorageService service, out ReferenceCountedDisposable <IStorageDeviceOperator> mmcOperator, MmcPartition partition) { UnsafeHelpers.SkipParamInit(out mmcOperator); ReferenceCountedDisposable <IStorageDeviceManager> deviceManager = null; try { Result rc = service.GetMmcManager(out deviceManager); if (rc.IsFailure()) { return(rc); } rc = GetAttribute(out ulong attribute, partition); if (rc.IsFailure()) { return(rc); } ReferenceCountedDisposable <IStorageDevice> storageDevice = null; try { rc = deviceManager.Target.OpenDevice(out storageDevice, attribute); if (rc.IsFailure()) { return(rc); } return(storageDevice.Target.OpenOperator(out mmcOperator)); } finally { storageDevice?.Dispose(); } } finally { deviceManager?.Dispose(); } }
private static bool IsSpeedEmulationNeeded(MmcPartition partition) { return(partition == MmcPartition.UserData); }
public static Result GetMmcPartitionSize(this StorageService service, out long size, MmcPartition partition) { UnsafeHelpers.SkipParamInit(out size); ReferenceCountedDisposable <IStorageDeviceOperator> mmcOperator = null; try { Result rc = service.GetMmcOperator(out mmcOperator, partition); if (rc.IsFailure()) { return(rc); } int operationId = MakeOperationId(MmcOperationIdValue.GetPartitionSize); OutBuffer outBuffer = OutBuffer.FromStruct(ref size); return(mmcOperator.Target.OperateOut(out _, outBuffer, operationId)); } finally { mmcOperator?.Dispose(); } }
public static Result OpenMmcStorage(this StorageService service, out ReferenceCountedDisposable <IStorage> storage, MmcPartition partition) { UnsafeHelpers.SkipParamInit(out storage); ReferenceCountedDisposable <IStorageDeviceManager> deviceManager = null; try { Result rc = service.GetMmcManager(out deviceManager); if (rc.IsFailure()) { return(rc); } rc = GetAttribute(out ulong attribute, partition); if (rc.IsFailure()) { return(rc); } ReferenceCountedDisposable <IStorageSf> mmcStorage = null; ReferenceCountedDisposable <IStorage> tempStorage = null; try { rc = deviceManager.Target.OpenStorage(out mmcStorage, attribute); if (rc.IsFailure()) { return(rc); } tempStorage = StorageServiceObjectAdapter.CreateShared(ref mmcStorage); if (IsSpeedEmulationNeeded(partition)) { tempStorage = SpeedEmulationStorage.CreateShared(ref tempStorage); if (tempStorage is null) { return(ResultFs.AllocationMemoryFailedCreateShared.Log()); } } storage = Shared.Move(ref tempStorage); return(Result.Success); } finally { mmcStorage?.Dispose(); tempStorage?.Dispose(); } } finally { deviceManager?.Dispose(); } }