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(); } }
public static Result OpenSdStorage(this StorageService service, out ReferenceCountedDisposable <IStorage> storage) { UnsafeHelpers.SkipParamInit(out storage); ReferenceCountedDisposable <IStorageDeviceManager> deviceManager = null; try { Result rc = service.GetSdCardManager(out deviceManager); if (rc.IsFailure()) { return(rc); } ReferenceCountedDisposable <IStorageSf> sdCardStorage = null; ReferenceCountedDisposable <IStorage> tempStorage = null; try { rc = deviceManager.Target.OpenStorage(out sdCardStorage, 0); if (rc.IsFailure()) { return(rc); } tempStorage = StorageServiceObjectAdapter.CreateShared(ref sdCardStorage); SdCardEventSimulator eventSimulator = service.FsSrv.Impl.GetSdCardEventSimulator(); tempStorage = DeviceEventSimulationStorage.CreateShared(ref tempStorage, eventSimulator); tempStorage = SpeedEmulationStorage.CreateShared(ref tempStorage); storage = Shared.Move(ref tempStorage); return(Result.Success); } finally { sdCardStorage?.Dispose(); tempStorage?.Dispose(); } } finally { deviceManager?.Dispose(); } }