diff --git a/src/LibHac/Fs/FileSystemClient.AccessLog.cs b/src/LibHac/Fs/FileSystemClient.AccessLog.cs index 5b6ce51f..2a555d65 100644 --- a/src/LibHac/Fs/FileSystemClient.AccessLog.cs +++ b/src/LibHac/Fs/FileSystemClient.AccessLog.cs @@ -2,6 +2,7 @@ using System.Runtime.CompilerServices; using LibHac.Common; using LibHac.Fs.Accessors; +using LibHac.Fs.Shim; using LibHac.FsSrv.Sf; using LibHac.Sf; @@ -19,9 +20,9 @@ namespace LibHac.Fs { if (HasFileSystemServer()) { - IFileSystemProxy fsProxy = GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = this.GetFileSystemProxyServiceObject(); - return fsProxy.GetGlobalAccessLogMode(out mode); + return fsProxy.Target.GetGlobalAccessLogMode(out mode); } mode = GlobalAccessLogMode; @@ -32,9 +33,9 @@ namespace LibHac.Fs { if (HasFileSystemServer()) { - IFileSystemProxy fsProxy = GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = this.GetFileSystemProxyServiceObject(); - return fsProxy.SetGlobalAccessLogMode(mode); + return fsProxy.Target.SetGlobalAccessLogMode(mode); } GlobalAccessLogMode = mode; @@ -69,9 +70,10 @@ namespace LibHac.Fs { if (HasFileSystemServer()) { - IFileSystemProxy fsProxy = GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = + this.GetFileSystemProxyServiceObject(); - Result rc = fsProxy.GetGlobalAccessLogMode(out GlobalAccessLogMode globalMode); + Result rc = fsProxy.Target.GetGlobalAccessLogMode(out GlobalAccessLogMode globalMode); GlobalAccessLogMode = globalMode; if (rc.IsFailure()) @@ -187,8 +189,8 @@ namespace LibHac.Fs { string logString = AccessLogHelpers.BuildDefaultLogLine(result, startTime, endTime, handleId, message, caller); - IFileSystemProxy fsProxy = GetFileSystemProxyServiceObject(); - fsProxy.OutputAccessLogToSdCard(new InBuffer(logString.ToU8Span())).IgnoreResult(); + using ReferenceCountedDisposable fsProxy = this.GetFileSystemProxyServiceObject(); + fsProxy.Target.OutputAccessLogToSdCard(new InBuffer(logString.ToU8Span())).IgnoreResult(); } } diff --git a/src/LibHac/Fs/FileSystemClient.cs b/src/LibHac/Fs/FileSystemClient.cs index 2ab04a80..25e89262 100644 --- a/src/LibHac/Fs/FileSystemClient.cs +++ b/src/LibHac/Fs/FileSystemClient.cs @@ -5,7 +5,7 @@ using LibHac.Common; using LibHac.Diag; using LibHac.Fs.Accessors; using LibHac.Fs.Fsa; -using LibHac.FsSrv.Sf; +using LibHac.Fs.Shim; using LibHac.FsSystem; using LibHac.Util; using IFileSystem = LibHac.Fs.Fsa.IFileSystem; @@ -14,16 +14,9 @@ namespace LibHac.Fs { public partial class FileSystemClient { - internal HorizonClient Hos { get; } + internal FileSystemClientGlobals Globals; - private IFileSystemProxy FsProxy { get; set; } - private readonly object _fspInitLocker = new object(); - - private IFileSystemProxyForLoader FsProxyForLoader { get; set; } - private readonly object _fsplInitLocker = new object(); - - private IProgramRegistry ProgramRegistry { get; set; } - private readonly object _progRegInitLocker = new object(); + internal HorizonClient Hos => Globals.Hos; internal ITimeSpanGenerator Time { get; } private IAccessLog AccessLog { get; set; } @@ -37,96 +30,26 @@ namespace LibHac.Fs public FileSystemClient(HorizonClient horizonClient) { - Hos = horizonClient; Time = horizonClient.Time; + Globals.Hos = horizonClient; + Globals.InitMutex = new object(); + Assert.NotNull(Time); } + internal struct FileSystemClientGlobals + { + public HorizonClient Hos; + public object InitMutex; + public FileSystemProxyServiceObjectGlobals FileSystemProxyServiceObject; + } + public bool HasFileSystemServer() { return Hos != null; } - public IFileSystemProxy GetFileSystemProxyServiceObject() - { - if (FsProxy != null) return FsProxy; - - lock (_fsplInitLocker) - { - if (FsProxy != null) return FsProxy; - - if (!HasFileSystemServer()) - { - throw new InvalidOperationException("Client was not initialized with a server object."); - } - - Result rc = Hos.Sm.GetService(out IFileSystemProxy fsProxy, "fsp-srv"); - - if (rc.IsFailure()) - { - throw new HorizonResultException(rc, "Failed to get file system proxy service object."); - } - - fsProxy.SetCurrentProcess(Hos.Os.GetCurrentProcessId().Value).IgnoreResult(); - - FsProxy = fsProxy; - return FsProxy; - } - } - - public IFileSystemProxyForLoader GetFileSystemProxyForLoaderServiceObject() - { - if (FsProxyForLoader != null) return FsProxyForLoader; - - lock (_fspInitLocker) - { - if (FsProxyForLoader != null) return FsProxyForLoader; - - if (!HasFileSystemServer()) - { - throw new InvalidOperationException("Client was not initialized with a server object."); - } - - Result rc = Hos.Sm.GetService(out IFileSystemProxyForLoader fsProxy, "fsp-ldr"); - - if (rc.IsFailure()) - { - throw new HorizonResultException(rc, "Failed to get file system proxy service object."); - } - - fsProxy.SetCurrentProcess(Hos.Os.GetCurrentProcessId().Value).IgnoreResult(); - - FsProxyForLoader = fsProxy; - return FsProxyForLoader; - } - } - - public IProgramRegistry GetProgramRegistryServiceObject() - { - if (ProgramRegistry != null) return ProgramRegistry; - - lock (_progRegInitLocker) - { - if (ProgramRegistry != null) return ProgramRegistry; - - if (!HasFileSystemServer()) - { - throw new InvalidOperationException("Client was not initialized with a server object."); - } - - Result rc = Hos.Sm.GetService(out IProgramRegistry registry, "fsp-pr"); - - if (rc.IsFailure()) - { - throw new HorizonResultException(rc, "Failed to get registry service object."); - } - - ProgramRegistry = registry; - return ProgramRegistry; - } - } - public Result Register(U8Span mountName, IFileSystem fileSystem) { return Register(mountName, fileSystem, null); diff --git a/src/LibHac/Fs/Shim/Application.cs b/src/LibHac/Fs/Shim/Application.cs index d2fb94ba..74de94ca 100644 --- a/src/LibHac/Fs/Shim/Application.cs +++ b/src/LibHac/Fs/Shim/Application.cs @@ -41,10 +41,10 @@ namespace LibHac.Fs.Shim FspPath.FromSpan(out FspPath sfPath, path); - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - rc = fsProxy.OpenFileSystemWithId(out ReferenceCountedDisposable fileSystem, in sfPath, - default, FileSystemProxyType.Package); + rc = fsProxy.Target.OpenFileSystemWithId(out ReferenceCountedDisposable fileSystem, + in sfPath, default, FileSystemProxyType.Package); if (rc.IsFailure()) return rc; using (fileSystem) diff --git a/src/LibHac/Fs/Shim/BcatSaveData.cs b/src/LibHac/Fs/Shim/BcatSaveData.cs index 7568b072..f4d0c3ca 100644 --- a/src/LibHac/Fs/Shim/BcatSaveData.cs +++ b/src/LibHac/Fs/Shim/BcatSaveData.cs @@ -41,7 +41,7 @@ namespace LibHac.Fs.Shim Result rc = MountHelpers.CheckMountName(mountName); if (rc.IsFailure()) return rc; - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(applicationId, SaveDataType.Bcat, UserId.InvalidId, 0); @@ -49,7 +49,7 @@ namespace LibHac.Fs.Shim try { - rc = fsProxy.OpenSaveDataFileSystem(out saveFs, SaveDataSpaceId.User, in attribute); + rc = fsProxy.Target.OpenSaveDataFileSystem(out saveFs, SaveDataSpaceId.User, in attribute); if (rc.IsFailure()) return rc; var fileSystemAdapter = new FileSystemServiceObjectAdapter(saveFs); diff --git a/src/LibHac/Fs/Shim/Bis.cs b/src/LibHac/Fs/Shim/Bis.cs index eedf15fe..99fb53fd 100644 --- a/src/LibHac/Fs/Shim/Bis.cs +++ b/src/LibHac/Fs/Shim/Bis.cs @@ -89,12 +89,12 @@ namespace LibHac.Fs.Shim Result rc = MountHelpers.CheckMountNameAcceptingReservedMountName(mountName); if (rc.IsFailure()) return rc; - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); // Nintendo doesn't use the provided rootPath FspPath.CreateEmpty(out FspPath sfPath); - rc = fsProxy.OpenBisFileSystem(out ReferenceCountedDisposable fileSystem, in sfPath, + rc = fsProxy.Target.OpenBisFileSystem(out ReferenceCountedDisposable fileSystem, in sfPath, partitionId); if (rc.IsFailure()) return rc; @@ -163,9 +163,9 @@ namespace LibHac.Fs.Shim FspPath.FromSpan(out FspPath sfPath, path.Str); - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - return fsProxy.SetBisRootForHost(partitionId, in sfPath); + return fsProxy.Target.SetBisRootForHost(partitionId, in sfPath); } public static Result OpenBisPartition(this FileSystemClient fs, out IStorage partitionStorage, @@ -173,8 +173,8 @@ namespace LibHac.Fs.Shim { partitionStorage = default; - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fsProxy.OpenBisStorage(out ReferenceCountedDisposable storage, partitionId); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + Result rc = fsProxy.Target.OpenBisStorage(out ReferenceCountedDisposable storage, partitionId); if (rc.IsFailure()) return rc; using (storage) @@ -188,8 +188,8 @@ namespace LibHac.Fs.Shim public static Result InvalidateBisCache(this FileSystemClient fs) { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); - return fsProxy.InvalidateBisCache(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + return fsProxy.Target.InvalidateBisCache(); } } } diff --git a/src/LibHac/Fs/Shim/Code.cs b/src/LibHac/Fs/Shim/Code.cs index 854feee0..04c70127 100644 --- a/src/LibHac/Fs/Shim/Code.cs +++ b/src/LibHac/Fs/Shim/Code.cs @@ -47,10 +47,11 @@ namespace LibHac.Fs.Shim rc = FspPath.FromSpan(out FspPath fsPath, path); if (rc.IsFailure()) return rc; - IFileSystemProxyForLoader fsProxy = fs.GetFileSystemProxyForLoaderServiceObject(); + using ReferenceCountedDisposable fsProxy = + fs.GetFileSystemProxyForLoaderServiceObject(); - rc = fsProxy.OpenCodeFileSystem(out ReferenceCountedDisposable codeFs, out verificationData, - in fsPath, programId); + rc = fsProxy.Target.OpenCodeFileSystem(out ReferenceCountedDisposable codeFs, + out verificationData, in fsPath, programId); if (rc.IsFailure()) return rc; using (codeFs) diff --git a/src/LibHac/Fs/Shim/Content.cs b/src/LibHac/Fs/Shim/Content.cs index f5418482..d521f74c 100644 --- a/src/LibHac/Fs/Shim/Content.cs +++ b/src/LibHac/Fs/Shim/Content.cs @@ -25,10 +25,10 @@ namespace LibHac.Fs.Shim FileSystemProxyType fspType = ConvertToFileSystemProxyType(type); - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - rc = fsProxy.OpenFileSystemWithPatch(out ReferenceCountedDisposable fileSystem, programId, - fspType); + rc = fsProxy.Target.OpenFileSystemWithPatch(out ReferenceCountedDisposable fileSystem, + programId, fspType); if (rc.IsFailure()) return rc; using (fileSystem) @@ -63,10 +63,10 @@ namespace LibHac.Fs.Shim { FspPath.FromSpan(out FspPath fsPath, path); - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fsProxy.OpenFileSystemWithId(out ReferenceCountedDisposable fileSystem, in fsPath, - id, type); + Result rc = fsProxy.Target.OpenFileSystemWithId(out ReferenceCountedDisposable fileSystem, + in fsPath, id, type); if (rc.IsFailure()) return rc; using (fileSystem) diff --git a/src/LibHac/Fs/Shim/ContentStorage.cs b/src/LibHac/Fs/Shim/ContentStorage.cs index ebd80193..bc3dc90d 100644 --- a/src/LibHac/Fs/Shim/ContentStorage.cs +++ b/src/LibHac/Fs/Shim/ContentStorage.cs @@ -19,9 +19,10 @@ namespace LibHac.Fs.Shim Result rc = MountHelpers.CheckMountNameAcceptingReservedMountName(mountName); if (rc.IsFailure()) return rc; - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - rc = fsProxy.OpenContentStorageFileSystem(out ReferenceCountedDisposable contentFs, storageId); + rc = fsProxy.Target.OpenContentStorageFileSystem(out ReferenceCountedDisposable contentFs, + storageId); if (rc.IsFailure()) return rc; using (contentFs) diff --git a/src/LibHac/Fs/Shim/CustomStorage.cs b/src/LibHac/Fs/Shim/CustomStorage.cs index aa3d2de5..e260a1fd 100644 --- a/src/LibHac/Fs/Shim/CustomStorage.cs +++ b/src/LibHac/Fs/Shim/CustomStorage.cs @@ -17,9 +17,9 @@ namespace LibHac.Fs.Shim ReferenceCountedDisposable customFs = null; try { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - rc = fsProxy.OpenCustomStorageFileSystem(out customFs, storageId); + rc = fsProxy.Target.OpenCustomStorageFileSystem(out customFs, storageId); if (rc.IsFailure()) return rc; var adapter = new FileSystemServiceObjectAdapter(customFs); diff --git a/src/LibHac/Fs/Shim/FileSystemProxyServiceObject.cs b/src/LibHac/Fs/Shim/FileSystemProxyServiceObject.cs new file mode 100644 index 00000000..a5241506 --- /dev/null +++ b/src/LibHac/Fs/Shim/FileSystemProxyServiceObject.cs @@ -0,0 +1,149 @@ +using System; +using LibHac.Common; +using LibHac.FsSrv.Sf; + +namespace LibHac.Fs.Shim +{ + internal struct FileSystemProxyServiceObjectGlobals + { + public nint FileSystemProxyServiceObjectInitGuard; + public ReferenceCountedDisposable FileSystemProxyServiceObject; + + public nint FileSystemProxyForLoaderServiceObjectInitGuard; + public ReferenceCountedDisposable FileSystemProxyForLoaderServiceObject; + + public nint ProgramRegistryServiceObjectInitGuard; + public ReferenceCountedDisposable ProgramRegistryServiceObject; + + public ReferenceCountedDisposable DfcFileSystemProxyServiceObject; + } + + public static class FileSystemProxyServiceObject + { + private static bool HasFileSystemServer(FileSystemClient fs) + { + return fs.Hos is not null; + } + + public static ReferenceCountedDisposable GetFileSystemProxyServiceObject( + this FileSystemClient fs) + { + ref FileSystemProxyServiceObjectGlobals g = ref fs.Globals.FileSystemProxyServiceObject; + using var guard = new InitializationGuard(ref g.FileSystemProxyServiceObjectInitGuard, + fs.Globals.InitMutex); + + if (!guard.IsInitialized) + { + g.FileSystemProxyServiceObject = GetFileSystemProxyServiceObjectImpl(fs); + } + + return g.FileSystemProxyServiceObject.AddReference(); + } + + private static ReferenceCountedDisposable GetFileSystemProxyServiceObjectImpl( + FileSystemClient fs) + { + ReferenceCountedDisposable dfcServiceObject = + fs.Globals.FileSystemProxyServiceObject.DfcFileSystemProxyServiceObject; + + if (dfcServiceObject is not null) + return dfcServiceObject.AddReference(); + + if (!HasFileSystemServer(fs)) + { + throw new InvalidOperationException("Client was not initialized with a server object."); + } + + Result rc = fs.Hos.Sm.GetService(out IFileSystemProxy fsProxy, "fsp-srv"); + + if (rc.IsFailure()) + { + throw new HorizonResultException(rc, "Failed to get file system proxy service object."); + } + + fsProxy.SetCurrentProcess(fs.Hos.Os.GetCurrentProcessId().Value).IgnoreResult(); + return new ReferenceCountedDisposable(fsProxy); + } + + public static ReferenceCountedDisposable GetFileSystemProxyForLoaderServiceObject( + this FileSystemClient fs) + { + ref FileSystemProxyServiceObjectGlobals g = ref fs.Globals.FileSystemProxyServiceObject; + using var guard = new InitializationGuard(ref g.FileSystemProxyForLoaderServiceObjectInitGuard, + fs.Globals.InitMutex); + + if (!guard.IsInitialized) + { + g.FileSystemProxyForLoaderServiceObject = GetFileSystemProxyForLoaderServiceObjectImpl(fs); + } + + return g.FileSystemProxyForLoaderServiceObject.AddReference(); + } + + private static ReferenceCountedDisposable + GetFileSystemProxyForLoaderServiceObjectImpl(FileSystemClient fs) + { + if (!HasFileSystemServer(fs)) + { + throw new InvalidOperationException("Client was not initialized with a server object."); + } + + Result rc = fs.Hos.Sm.GetService(out IFileSystemProxyForLoader fsProxy, "fsp-ldr"); + + if (rc.IsFailure()) + { + throw new HorizonResultException(rc, "Failed to get file system proxy service object."); + } + + fsProxy.SetCurrentProcess(fs.Hos.Os.GetCurrentProcessId().Value).IgnoreResult(); + return new ReferenceCountedDisposable(fsProxy); + } + + public static ReferenceCountedDisposable GetProgramRegistryServiceObject( + this FileSystemClient fs) + { + ref FileSystemProxyServiceObjectGlobals g = ref fs.Globals.FileSystemProxyServiceObject; + using var guard = new InitializationGuard(ref g.ProgramRegistryServiceObjectInitGuard, + fs.Globals.InitMutex); + + if (!guard.IsInitialized) + { + g.ProgramRegistryServiceObject = GetProgramRegistryServiceObjectImpl(fs); + } + + return g.ProgramRegistryServiceObject.AddReference(); + } + + private static ReferenceCountedDisposable GetProgramRegistryServiceObjectImpl( + FileSystemClient fs) + { + if (!HasFileSystemServer(fs)) + { + throw new InvalidOperationException("Client was not initialized with a server object."); + } + + Result rc = fs.Hos.Sm.GetService(out IProgramRegistry registry, "fsp-pr"); + + if (rc.IsFailure()) + { + throw new HorizonResultException(rc, "Failed to get registry service object."); + } + + registry.SetCurrentProcess(fs.Hos.Os.GetCurrentProcessId().Value).IgnoreResult(); + return new ReferenceCountedDisposable(registry); + } + + /// + /// Sets a service object to use for direct function calls + /// instead of going over IPC. If using a DFC service object, this function should be + /// called before calling . + /// + /// The to use. + /// The service object this will use. + public static void InitializeDfcFileSystemProxyServiceObject(this FileSystemClient fs, + ReferenceCountedDisposable serviceObject) + { + fs.Globals.FileSystemProxyServiceObject.DfcFileSystemProxyServiceObject = serviceObject.AddReference(); + } + } +} diff --git a/src/LibHac/Fs/Shim/GameCard.cs b/src/LibHac/Fs/Shim/GameCard.cs index d8071058..6ef4e071 100644 --- a/src/LibHac/Fs/Shim/GameCard.cs +++ b/src/LibHac/Fs/Shim/GameCard.cs @@ -17,9 +17,9 @@ namespace LibHac.Fs.Shim ReferenceCountedDisposable deviceOperator = null; try { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fsProxy.OpenDeviceOperator(out deviceOperator); + Result rc = fsProxy.Target.OpenDeviceOperator(out deviceOperator); if (rc.IsFailure()) return rc; return deviceOperator.Target.GetGameCardHandle(out handle); @@ -35,9 +35,9 @@ namespace LibHac.Fs.Shim ReferenceCountedDisposable deviceOperator = null; try { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fsProxy.OpenDeviceOperator(out deviceOperator); + Result rc = fsProxy.Target.OpenDeviceOperator(out deviceOperator); if (rc.IsFailure()) throw new LibHacException("Abort"); rc = deviceOperator.Target.IsGameCardInserted(out bool isInserted); @@ -59,9 +59,9 @@ namespace LibHac.Fs.Shim ReferenceCountedDisposable sfStorage = null; try { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fsProxy.OpenGameCardStorage(out sfStorage, handle, partitionType); + Result rc = fsProxy.Target.OpenGameCardStorage(out sfStorage, handle, partitionType); if (rc.IsFailure()) return rc; storage = new StorageServiceObjectAdapter(sfStorage); @@ -79,9 +79,10 @@ namespace LibHac.Fs.Shim Result rc = MountHelpers.CheckMountNameAcceptingReservedMountName(mountName); if (rc.IsFailure()) return rc; - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - rc = fsProxy.OpenGameCardFileSystem(out ReferenceCountedDisposable cardFs, handle, partitionId); + rc = fsProxy.Target.OpenGameCardFileSystem(out ReferenceCountedDisposable cardFs, handle, + partitionId); if (rc.IsFailure()) return rc; using (cardFs) diff --git a/src/LibHac/Fs/Shim/Host.cs b/src/LibHac/Fs/Shim/Host.cs index 21cea589..c8e6301b 100644 --- a/src/LibHac/Fs/Shim/Host.cs +++ b/src/LibHac/Fs/Shim/Host.cs @@ -358,19 +358,19 @@ namespace LibHac.Fs.Shim { fileSystem = default; - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); ReferenceCountedDisposable hostFs = null; try { if (option == MountHostOption.None) { - Result rc = fsProxy.OpenHostFileSystem(out hostFs, in path); + Result rc = fsProxy.Target.OpenHostFileSystem(out hostFs, in path); if (rc.IsFailure()) return rc; } else { - Result rc = fsProxy.OpenHostFileSystemWithOption(out hostFs, in path, option); + Result rc = fsProxy.Target.OpenHostFileSystemWithOption(out hostFs, in path, option); if (rc.IsFailure()) return rc; } diff --git a/src/LibHac/Fs/Shim/LoaderApi.cs b/src/LibHac/Fs/Shim/LoaderApi.cs index c4e06bba..9ccc2bfe 100644 --- a/src/LibHac/Fs/Shim/LoaderApi.cs +++ b/src/LibHac/Fs/Shim/LoaderApi.cs @@ -7,9 +7,10 @@ namespace LibHac.Fs.Shim { public static Result IsArchivedProgram(this FileSystemClient fs, out bool isArchived, ProcessId processId) { - IFileSystemProxyForLoader fsProxy = fs.GetFileSystemProxyForLoaderServiceObject(); + using ReferenceCountedDisposable fsProxy = + fs.GetFileSystemProxyForLoaderServiceObject(); - return fsProxy.IsArchivedProgram(out isArchived, processId.Value); + return fsProxy.Target.IsArchivedProgram(out isArchived, processId.Value); } } } diff --git a/src/LibHac/Fs/Shim/ProgramIndexMapInfo.cs b/src/LibHac/Fs/Shim/ProgramIndexMapInfo.cs index 43c06b14..7e1597f5 100644 --- a/src/LibHac/Fs/Shim/ProgramIndexMapInfo.cs +++ b/src/LibHac/Fs/Shim/ProgramIndexMapInfo.cs @@ -20,11 +20,11 @@ namespace LibHac.Fs.Shim if (mapInfo.IsEmpty) return Result.Success; - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); var mapInfoBuffer = new InBuffer(MemoryMarshal.Cast(mapInfo)); - return fsProxy.RegisterProgramIndexMapInfo(mapInfoBuffer, mapInfo.Length); + return fsProxy.Target.RegisterProgramIndexMapInfo(mapInfoBuffer, mapInfo.Length); } } } diff --git a/src/LibHac/Fs/Shim/ProgramRegistry.cs b/src/LibHac/Fs/Shim/ProgramRegistry.cs index c4bdced5..5df3859a 100644 --- a/src/LibHac/Fs/Shim/ProgramRegistry.cs +++ b/src/LibHac/Fs/Shim/ProgramRegistry.cs @@ -12,24 +12,24 @@ namespace LibHac.Fs.Shim public static Result RegisterProgram(this FileSystemClient fs, ulong processId, ProgramId programId, StorageId storageId, ReadOnlySpan accessControlData, ReadOnlySpan accessControlDescriptor) { - IProgramRegistry registry = fs.GetProgramRegistryServiceObject(); + using ReferenceCountedDisposable registry = fs.GetProgramRegistryServiceObject(); - Result rc = registry.SetCurrentProcess(fs.Hos.ProcessId.Value); + Result rc = registry.Target.SetCurrentProcess(fs.Hos.ProcessId.Value); if (rc.IsFailure()) return rc; - return registry.RegisterProgram(processId, programId, storageId, new InBuffer(accessControlData), + return registry.Target.RegisterProgram(processId, programId, storageId, new InBuffer(accessControlData), new InBuffer(accessControlDescriptor)); } /// public static Result UnregisterProgram(this FileSystemClient fs, ulong processId) { - IProgramRegistry registry = fs.GetProgramRegistryServiceObject(); + using ReferenceCountedDisposable registry = fs.GetProgramRegistryServiceObject(); - Result rc = registry.SetCurrentProcess(fs.Hos.ProcessId.Value); + Result rc = registry.Target.SetCurrentProcess(fs.Hos.ProcessId.Value); if (rc.IsFailure()) return rc; - return registry.UnregisterProgram(processId); + return registry.Target.UnregisterProgram(processId); } } } diff --git a/src/LibHac/Fs/Shim/RightsId.cs b/src/LibHac/Fs/Shim/RightsId.cs index 910f7be4..cd172e07 100644 --- a/src/LibHac/Fs/Shim/RightsId.cs +++ b/src/LibHac/Fs/Shim/RightsId.cs @@ -11,21 +11,21 @@ namespace LibHac.Fs.Shim public static Result GetRightsId(this FileSystemClient fs, out FsRightsId rightsId, ProgramId programId, StorageId storageId) { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - return fsProxy.GetRightsId(out rightsId, programId, storageId); + return fsProxy.Target.GetRightsId(out rightsId, programId, storageId); } public static Result GetRightsId(this FileSystemClient fs, out FsRightsId rightsId, U8Span path) { rightsId = default; - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); Result rc = FspPath.FromSpan(out FspPath sfPath, path); if (rc.IsFailure()) return rc; - return fsProxy.GetRightsIdByPath(out rightsId, in sfPath); + return fsProxy.Target.GetRightsIdByPath(out rightsId, in sfPath); } public static Result GetRightsId(this FileSystemClient fs, out FsRightsId rightsId, out byte keyGeneration, U8Span path) @@ -33,33 +33,33 @@ namespace LibHac.Fs.Shim rightsId = default; keyGeneration = default; - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); Result rc = FspPath.FromSpan(out FspPath sfPath, path); if (rc.IsFailure()) return rc; - return fsProxy.GetRightsIdAndKeyGenerationByPath(out rightsId, out keyGeneration, in sfPath); + return fsProxy.Target.GetRightsIdAndKeyGenerationByPath(out rightsId, out keyGeneration, in sfPath); } public static Result RegisterExternalKey(this FileSystemClient fs, in FsRightsId rightsId, in AccessKey key) { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - return fsProxy.RegisterExternalKey(in rightsId, in key); + return fsProxy.Target.RegisterExternalKey(in rightsId, in key); } public static Result UnregisterExternalKey(this FileSystemClient fs, ref FsRightsId rightsId) { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - return fsProxy.UnregisterExternalKey(in rightsId); + return fsProxy.Target.UnregisterExternalKey(in rightsId); } public static Result UnregisterAllExternalKey(this FileSystemClient fs) { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - return fsProxy.UnregisterAllExternalKey(); + return fsProxy.Target.UnregisterAllExternalKey(); } } } diff --git a/src/LibHac/Fs/Shim/SaveData.cs b/src/LibHac/Fs/Shim/SaveData.cs index 7a2d39c2..dd5777f6 100644 --- a/src/LibHac/Fs/Shim/SaveData.cs +++ b/src/LibHac/Fs/Shim/SaveData.cs @@ -189,7 +189,7 @@ namespace LibHac.Fs.Shim Result rc = MountHelpers.CheckMountName(mountName); if (rc.IsFailure()) return rc; - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(programId, type, userId, 0, index); @@ -199,11 +199,11 @@ namespace LibHac.Fs.Shim { if (openReadOnly) { - rc = fsProxy.OpenReadOnlySaveDataFileSystem(out saveFs, spaceId, in attribute); + rc = fsProxy.Target.OpenReadOnlySaveDataFileSystem(out saveFs, spaceId, in attribute); } else { - rc = fsProxy.OpenSaveDataFileSystem(out saveFs, spaceId, in attribute); + rc = fsProxy.Target.OpenSaveDataFileSystem(out saveFs, spaceId, in attribute); } if (rc.IsFailure()) return rc; diff --git a/src/LibHac/Fs/Shim/SaveDataManagement.cs b/src/LibHac/Fs/Shim/SaveDataManagement.cs index 61a17e3d..fe521980 100644 --- a/src/LibHac/Fs/Shim/SaveDataManagement.cs +++ b/src/LibHac/Fs/Shim/SaveDataManagement.cs @@ -15,7 +15,7 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(applicationId, SaveDataType.Account, userId, 0); @@ -35,7 +35,7 @@ namespace LibHac.Fs.Shim Size = 0x40060 }; - return fsProxy.CreateSaveDataFileSystem(in attribute, in createInfo, in metaInfo); + return fsProxy.Target.CreateSaveDataFileSystem(in attribute, in createInfo, in metaInfo); }, () => $", applicationid: 0x{applicationId.Value:X}, userid: 0x{userId}, save_data_owner_id: 0x{ownerId:X}, save_data_size: {size}, save_data_journal_size: {journalSize}, save_data_flags: 0x{(int)flags:X8}"); @@ -47,7 +47,7 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(applicationId, SaveDataType.Account, userId, 0); @@ -67,7 +67,7 @@ namespace LibHac.Fs.Shim Size = 0x40060 }; - return fsProxy.CreateSaveDataFileSystemWithHashSalt(in attribute, in createInfo, in metaInfo, + return fsProxy.Target.CreateSaveDataFileSystemWithHashSalt(in attribute, in createInfo, in metaInfo, in hashSalt); }, () => @@ -79,7 +79,7 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(applicationId, SaveDataType.Bcat, UserId.InvalidId, 0); @@ -95,7 +95,7 @@ namespace LibHac.Fs.Shim var metaInfo = new SaveDataMetaInfo(); - return fsProxy.CreateSaveDataFileSystem(in attribute, in createInfo, in metaInfo); + return fsProxy.Target.CreateSaveDataFileSystem(in attribute, in createInfo, in metaInfo); }, () => $", applicationid: 0x{applicationId.Value:X}, save_data_size: {size}"); } @@ -106,7 +106,7 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(applicationId, SaveDataType.Device, UserId.InvalidId, 0); @@ -122,7 +122,7 @@ namespace LibHac.Fs.Shim var metaInfo = new SaveDataMetaInfo(); - return fsProxy.CreateSaveDataFileSystem(in attribute, in createInfo, in metaInfo); + return fsProxy.Target.CreateSaveDataFileSystem(in attribute, in createInfo, in metaInfo); }, () => $", applicationid: 0x{applicationId.Value:X}, save_data_owner_id: 0x{ownerId:X}, save_data_size: {size}, save_data_journal_size: {journalSize}, save_data_flags: 0x{(int)flags:X8}"); } @@ -132,7 +132,7 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(applicationId, SaveDataType.Temporary, UserId.InvalidId, 0); @@ -147,7 +147,7 @@ namespace LibHac.Fs.Shim var metaInfo = new SaveDataMetaInfo(); - return fsProxy.CreateSaveDataFileSystem(in attribute, in createInfo, in metaInfo); + return fsProxy.Target.CreateSaveDataFileSystem(in attribute, in createInfo, in metaInfo); }, () => $", applicationid: 0x{applicationId.Value:X}, save_data_owner_id: 0x{ownerId:X}, save_data_size: {size}, save_data_flags: 0x{(int)flags:X8}"); } @@ -158,7 +158,7 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(applicationId, SaveDataType.Cache, UserId.InvalidId, 0, index); @@ -174,7 +174,7 @@ namespace LibHac.Fs.Shim var metaInfo = new SaveDataMetaInfo(); - return fsProxy.CreateSaveDataFileSystem(in attribute, in creationInfo, in metaInfo); + return fsProxy.Target.CreateSaveDataFileSystem(in attribute, in creationInfo, in metaInfo); }, () => $", applicationid: 0x{applicationId.Value:X}, savedataspaceid: {spaceId}, save_data_owner_id: 0x{ownerId:X}, save_data_size: {size}, save_data_journal_size: {journalSize}, save_data_flags: 0x{(int)flags:X8}"); } @@ -197,7 +197,7 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(ProgramId.InvalidId, SaveDataType.System, userId, saveDataId); @@ -211,7 +211,7 @@ namespace LibHac.Fs.Shim SpaceId = spaceId }; - return fsProxy.CreateSaveDataFileSystemBySystemSaveDataId(in attribute, in createInfo); + return fsProxy.Target.CreateSaveDataFileSystemBySystemSaveDataId(in attribute, in createInfo); }, () => $", savedataspaceid: {spaceId}, savedataid: 0x{saveDataId:X}, userid: 0x{userId.Id.High:X16}{userId.Id.Low:X16}, save_data_owner_id: 0x{ownerId:X}, save_data_size: {size}, save_data_journal_size: {journalSize}, save_data_flags: 0x{(int)flags:x8}"); } @@ -251,8 +251,8 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); - return fsProxy.DeleteSaveDataFileSystem(saveDataId); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + return fsProxy.Target.DeleteSaveDataFileSystem(saveDataId); }, () => $", savedataid: 0x{saveDataId:X}"); } @@ -262,8 +262,8 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); - return fsProxy.DeleteSaveDataFileSystemBySaveDataSpaceId(spaceId, saveDataId); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + return fsProxy.Target.DeleteSaveDataFileSystemBySaveDataSpaceId(spaceId, saveDataId); }, () => $", savedataspaceid: {spaceId}, savedataid: 0x{saveDataId:X}"); } @@ -279,12 +279,12 @@ namespace LibHac.Fs.Shim Result result = fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); tempInfo = new SaveDataInfo(); - Result rc = fsProxy.FindSaveDataWithFilter(out long count, OutBuffer.FromStruct(ref tempInfo), - spaceId, in tempFilter); + Result rc = fsProxy.Target.FindSaveDataWithFilter(out long count, + OutBuffer.FromStruct(ref tempInfo), spaceId, in tempFilter); if (rc.IsFailure()) return rc; if (count == 0) @@ -311,9 +311,9 @@ namespace LibHac.Fs.Shim Result result = fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - return fsProxy.QuerySaveDataTotalSize(out totalSizeTemp, size, journalSize); + return fsProxy.Target.QuerySaveDataTotalSize(out totalSizeTemp, size, journalSize); }, () => $", save_data_size: {size}, save_data_journal_size: {journalSize}"); @@ -334,9 +334,9 @@ namespace LibHac.Fs.Shim Result result = fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fsProxy.OpenSaveDataInfoReaderBySaveDataSpaceId( + Result rc = fsProxy.Target.OpenSaveDataInfoReaderBySaveDataSpaceId( out ReferenceCountedDisposable reader, spaceId); if (rc.IsFailure()) return rc; @@ -368,9 +368,9 @@ namespace LibHac.Fs.Shim Result result = fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fsProxy.OpenSaveDataInfoReaderWithFilter(out reader, spaceId, in tempFilter); + Result rc = fsProxy.Target.OpenSaveDataInfoReaderWithFilter(out reader, spaceId, in tempFilter); if (rc.IsFailure()) return rc; tempIterator = new SaveDataIterator(fs, reader); @@ -391,9 +391,9 @@ namespace LibHac.Fs.Shim public static void DisableAutoSaveDataCreation(this FileSystemClient fsClient) { - IFileSystemProxy fsProxy = fsClient.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fsClient.GetFileSystemProxyServiceObject(); - Result rc = fsProxy.DisableAutoSaveDataCreation(); + Result rc = fsProxy.Target.DisableAutoSaveDataCreation(); if (rc.IsFailure()) { diff --git a/src/LibHac/Fs/Shim/SdCard.cs b/src/LibHac/Fs/Shim/SdCard.cs index ee42663c..a0235431 100644 --- a/src/LibHac/Fs/Shim/SdCard.cs +++ b/src/LibHac/Fs/Shim/SdCard.cs @@ -39,9 +39,9 @@ namespace LibHac.Fs.Shim Result rc = MountHelpers.CheckMountName(mountName); if (rc.IsFailure()) return rc; - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - rc = fsProxy.OpenSdCardFileSystem(out ReferenceCountedDisposable fileSystem); + rc = fsProxy.Target.OpenSdCardFileSystem(out ReferenceCountedDisposable fileSystem); if (rc.IsFailure()) return rc; using (fileSystem) @@ -58,9 +58,9 @@ namespace LibHac.Fs.Shim ReferenceCountedDisposable deviceOperator = null; try { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fsProxy.OpenDeviceOperator(out deviceOperator); + Result rc = fsProxy.Target.OpenDeviceOperator(out deviceOperator); if (rc.IsFailure()) throw new HorizonResultException(rc, "Abort"); rc = deviceOperator.Target.IsSdCardInserted(out bool isInserted); @@ -76,9 +76,9 @@ namespace LibHac.Fs.Shim public static Result SetSdCardEncryptionSeed(this FileSystemClient fs, in EncryptionSeed seed) { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fsProxy.SetSdCardEncryptionSeed(in seed); + Result rc = fsProxy.Target.SetSdCardEncryptionSeed(in seed); if (rc.IsFailure()) throw new HorizonResultException(rc, "Abort"); return Result.Success; @@ -86,17 +86,17 @@ namespace LibHac.Fs.Shim public static void SetSdCardAccessibility(this FileSystemClient fs, bool isAccessible) { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fsProxy.SetSdCardAccessibility(isAccessible); + Result rc = fsProxy.Target.SetSdCardAccessibility(isAccessible); if (rc.IsFailure()) throw new HorizonResultException(rc, "Abort"); } public static bool IsSdCardAccessible(this FileSystemClient fs) { - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fsProxy.IsSdCardAccessible(out bool isAccessible); + Result rc = fsProxy.Target.IsSdCardAccessible(out bool isAccessible); if (rc.IsFailure()) throw new HorizonResultException(rc, "Abort"); return isAccessible; diff --git a/src/LibHac/Fs/Shim/SystemSaveData.cs b/src/LibHac/Fs/Shim/SystemSaveData.cs index a2481f58..03389a7a 100644 --- a/src/LibHac/Fs/Shim/SystemSaveData.cs +++ b/src/LibHac/Fs/Shim/SystemSaveData.cs @@ -20,7 +20,7 @@ namespace LibHac.Fs.Shim Result rc = MountHelpers.CheckMountName(mountName); if (rc.IsFailure()) return rc; - IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(ProgramId.InvalidId, SaveDataType.System, userId, saveDataId); @@ -28,7 +28,7 @@ namespace LibHac.Fs.Shim try { - rc = fsProxy.OpenSaveDataFileSystemBySystemSaveDataId(out saveFs, spaceId, in attribute); + rc = fsProxy.Target.OpenSaveDataFileSystemBySystemSaveDataId(out saveFs, spaceId, in attribute); if (rc.IsFailure()) return rc; var fileSystemAdapter = new FileSystemServiceObjectAdapter(saveFs); diff --git a/src/LibHac/Fs/Shim/UserFileSystem.cs b/src/LibHac/Fs/Shim/UserFileSystem.cs index 57e1bca6..7cf84e9c 100644 --- a/src/LibHac/Fs/Shim/UserFileSystem.cs +++ b/src/LibHac/Fs/Shim/UserFileSystem.cs @@ -22,7 +22,9 @@ namespace LibHac.Fs.Shim ReferenceCountedDisposable fileSystem = null; try { - Result rc = fs.GetFileSystemProxyServiceObject().OpenMultiCommitManager(out commitManager); + using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + + Result rc = fsProxy.Target.OpenMultiCommitManager(out commitManager); if (rc.IsFailure()) return rc; for (int i = 0; i < mountNames.Length; i++) diff --git a/src/LibHac/FsSrv/FileSystemProxyImpl.cs b/src/LibHac/FsSrv/FileSystemProxyImpl.cs index d3c70b0c..2899b182 100644 --- a/src/LibHac/FsSrv/FileSystemProxyImpl.cs +++ b/src/LibHac/FsSrv/FileSystemProxyImpl.cs @@ -69,6 +69,12 @@ namespace LibHac.FsSrv CurrentProcess = ulong.MaxValue; } + public void Dispose() + { + NcaFsService?.Dispose(); + SaveFsService?.Dispose(); + } + private Result GetProgramInfo(out ProgramInfo programInfo) { var registry = new ProgramRegistryImpl(FsServer); diff --git a/src/LibHac/FsSrv/ProgramRegistryImpl.cs b/src/LibHac/FsSrv/ProgramRegistryImpl.cs index 4e705d32..605975b1 100644 --- a/src/LibHac/FsSrv/ProgramRegistryImpl.cs +++ b/src/LibHac/FsSrv/ProgramRegistryImpl.cs @@ -41,6 +41,8 @@ namespace LibHac.FsSrv _processId = ulong.MaxValue; } + public void Dispose() { } + /// : The operation was successful.
/// : The process ID is already registered.
/// : Insufficient permissions.
diff --git a/src/LibHac/FsSrv/Sf/IFileSystemProxy.cs b/src/LibHac/FsSrv/Sf/IFileSystemProxy.cs index 726687ae..cc46a315 100644 --- a/src/LibHac/FsSrv/Sf/IFileSystemProxy.cs +++ b/src/LibHac/FsSrv/Sf/IFileSystemProxy.cs @@ -1,4 +1,5 @@ -using LibHac.Fs; +using System; +using LibHac.Fs; using LibHac.Ncm; using LibHac.Sf; using LibHac.Spl; @@ -8,7 +9,7 @@ using IStorageSf = LibHac.FsSrv.Sf.IStorage; namespace LibHac.FsSrv.Sf { - public interface IFileSystemProxy + public interface IFileSystemProxy : IDisposable { Result SetCurrentProcess(ulong processId); Result OpenDataFileSystemByCurrentProcess(out ReferenceCountedDisposable fileSystem); diff --git a/src/LibHac/FsSrv/Sf/IFileSystemProxyForLoader.cs b/src/LibHac/FsSrv/Sf/IFileSystemProxyForLoader.cs index 4e03762b..806e804e 100644 --- a/src/LibHac/FsSrv/Sf/IFileSystemProxyForLoader.cs +++ b/src/LibHac/FsSrv/Sf/IFileSystemProxyForLoader.cs @@ -1,10 +1,11 @@ -using LibHac.Fs; +using System; +using LibHac.Fs; using LibHac.Ncm; using IFileSystemSf = LibHac.FsSrv.Sf.IFileSystem; namespace LibHac.FsSrv.Sf { - public interface IFileSystemProxyForLoader + public interface IFileSystemProxyForLoader : IDisposable { Result OpenCodeFileSystem(out ReferenceCountedDisposable fileSystem, out CodeVerificationData verificationData, in FspPath path, ProgramId programId); diff --git a/src/LibHac/FsSrv/Sf/IProgramRegistry.cs b/src/LibHac/FsSrv/Sf/IProgramRegistry.cs index 78e34586..47e4211b 100644 --- a/src/LibHac/FsSrv/Sf/IProgramRegistry.cs +++ b/src/LibHac/FsSrv/Sf/IProgramRegistry.cs @@ -1,9 +1,10 @@ -using LibHac.Ncm; +using System; +using LibHac.Ncm; using LibHac.Sf; namespace LibHac.FsSrv.Sf { - public interface IProgramRegistry + public interface IProgramRegistry : IDisposable { Result RegisterProgram(ulong processId, ProgramId programId, StorageId storageId, InBuffer accessControlData, InBuffer accessControlDescriptor); diff --git a/tests/LibHac.Tests/FsSrv/ProgramIndexMapInfoTests.cs b/tests/LibHac.Tests/FsSrv/ProgramIndexMapInfoTests.cs index e299c82a..092009ba 100644 --- a/tests/LibHac.Tests/FsSrv/ProgramIndexMapInfoTests.cs +++ b/tests/LibHac.Tests/FsSrv/ProgramIndexMapInfoTests.cs @@ -40,8 +40,9 @@ namespace LibHac.Tests.FsSrv for (int i = 0; i < programs.Length; i++) { - Assert.Success(programs[i].Fs.GetFileSystemProxyServiceObject() - .GetProgramIndexForAccessLog(out int programIndex, out int programCount)); + using ReferenceCountedDisposable fsProxy = + programs[i].Fs.GetFileSystemProxyServiceObject(); + Assert.Success(fsProxy.Target.GetProgramIndexForAccessLog(out int programIndex, out int programCount)); Assert.Equal(i, programIndex); Assert.Equal(count, programCount);