diff --git a/src/LibHac/Fs/AccessLog.cs b/src/LibHac/Fs/AccessLog.cs index 39c54aeb..22e01ae6 100644 --- a/src/LibHac/Fs/AccessLog.cs +++ b/src/LibHac/Fs/AccessLog.cs @@ -1,7 +1,22 @@ -using System.Runtime.InteropServices; +using System; +using System.Runtime.InteropServices; +using LibHac.Diag; +using LibHac.Fs.Impl; +using LibHac.Fs.Shim; +using LibHac.FsSrv.Sf; +using LibHac.Os; namespace LibHac.Fs { + internal struct AccessLogGlobals + { + public GlobalAccessLogMode GlobalAccessLogMode; + public AccessLogTarget LocalAccessLogTarget; + + public bool IsAccessLogInitialized; + public SdkMutexType MutexForAccessLogInitialization; + } + [StructLayout(LayoutKind.Sequential, Size = 0x20)] public struct ApplicationInfo { @@ -10,4 +25,160 @@ namespace LibHac.Fs public byte LaunchType; public bool IsMultiProgram; } + + [Flags] + public enum GlobalAccessLogMode + { + None = 0, + Log = 1 << 0, + SdCard = 1 << 1, + All = Log | SdCard + } + + public static class AccessLog + { + private static bool HasFileSystemServer(FileSystemClient fs) + { + return fs.Hos is not null; + } + + public static Result GetGlobalAccessLogMode(this FileSystemClient fs, out GlobalAccessLogMode mode) + { + if (HasFileSystemServer(fs)) + { + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); + + return fsProxy.Target.GetGlobalAccessLogMode(out mode); + } + + mode = fs.Globals.AccessLog.GlobalAccessLogMode; + return Result.Success; + } + + public static Result SetGlobalAccessLogMode(this FileSystemClient fs, GlobalAccessLogMode mode) + { + if (HasFileSystemServer(fs)) + { + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); + + return fsProxy.Target.SetGlobalAccessLogMode(mode); + } + + fs.Globals.AccessLog.GlobalAccessLogMode = mode; + return Result.Success; + } + + public static void SetLocalAccessLog(this FileSystemClient fs, bool enabled) + { + SetLocalAccessLogImpl(fs, enabled); + } + + public static void SetLocalApplicationAccessLog(this FileSystemClient fs, bool enabled) + { + SetLocalAccessLogImpl(fs, enabled); + } + + public static void SetLocalSystemAccessLogForDebug(this FileSystemClient fs, bool enabled) + { + if (enabled) + { + fs.Globals.AccessLog.LocalAccessLogTarget |= AccessLogTarget.All; + } + else + { + fs.Globals.AccessLog.LocalAccessLogTarget &= ~AccessLogTarget.All; + } + } + + private static void SetLocalAccessLogImpl(FileSystemClient fs, bool enabled) + { + if (enabled) + { + fs.Globals.AccessLog.LocalAccessLogTarget |= AccessLogTarget.Application; + } + else + { + fs.Globals.AccessLog.LocalAccessLogTarget &= ~AccessLogTarget.Application; + } + } + } +} + +namespace LibHac.Fs.Impl +{ + [Flags] + public enum AccessLogTarget + { + None = 0, + Application = 1 << 0, + System = 1 << 1, + All = Application | System + } + + internal static class AccessLogImpl + { + private static void GetProgramIndexForAccessLog(FileSystemClient fs, out int index, out int count) + { + throw new NotImplementedException(); + } + + private static void OutputAccessLogStart(FileSystemClient fs) + { + throw new NotImplementedException(); + } + + private static void OutputAccessLogStartForSystem(FileSystemClient fs) + { + throw new NotImplementedException(); + } + + private static void OutputAccessLogStartGeneratedByCallback(FileSystemClient fs) + { + throw new NotImplementedException(); + } + + internal static bool IsEnabledAccessLog(this FileSystemClientImpl fs, AccessLogTarget target) + { + ref AccessLogGlobals g = ref fs.Globals.AccessLog; + + if ((g.LocalAccessLogTarget & target) == 0) + return false; + + if (!g.IsAccessLogInitialized) + { + using ScopedLock lk = ScopedLock.Lock(ref g.MutexForAccessLogInitialization); + + // ReSharper disable once ConditionIsAlwaysTrueOrFalse + if (!g.IsAccessLogInitialized) + { + if (g.LocalAccessLogTarget.HasFlag(AccessLogTarget.System)) + { + g.GlobalAccessLogMode = GlobalAccessLogMode.Log; + OutputAccessLogStartForSystem(fs.Fs); + OutputAccessLogStartGeneratedByCallback(fs.Fs); + } + else + { + Result rc = fs.Fs.GetGlobalAccessLogMode(out g.GlobalAccessLogMode); + if (rc.IsFailure()) Abort.DoAbort(rc); + + if (g.GlobalAccessLogMode != GlobalAccessLogMode.None) + { + OutputAccessLogStart(fs.Fs); + OutputAccessLogStartGeneratedByCallback(fs.Fs); + } + } + + g.IsAccessLogInitialized = true; + } + } + + return g.GlobalAccessLogMode != GlobalAccessLogMode.None; + } + + internal static bool IsEnabledAccessLog(this FileSystemClientImpl fs) + { + return fs.IsEnabledAccessLog(AccessLogTarget.All); + } + } } diff --git a/src/LibHac/Fs/FileSystemClient.AccessLog.cs b/src/LibHac/Fs/FileSystemClient.AccessLog.cs index 2a555d65..93744c5e 100644 --- a/src/LibHac/Fs/FileSystemClient.AccessLog.cs +++ b/src/LibHac/Fs/FileSystemClient.AccessLog.cs @@ -1,10 +1,11 @@ using System; using System.Runtime.CompilerServices; using LibHac.Common; -using LibHac.Fs.Accessors; +using LibHac.Fs.Impl; using LibHac.Fs.Shim; using LibHac.FsSrv.Sf; using LibHac.Sf; +using FileSystemAccessor = LibHac.Fs.Accessors.FileSystemAccessor; namespace LibHac.Fs { @@ -16,37 +17,6 @@ namespace LibHac.Fs private readonly object _accessLogInitLocker = new object(); - public Result GetGlobalAccessLogMode(out GlobalAccessLogMode mode) - { - if (HasFileSystemServer()) - { - using ReferenceCountedDisposable fsProxy = this.GetFileSystemProxyServiceObject(); - - return fsProxy.Target.GetGlobalAccessLogMode(out mode); - } - - mode = GlobalAccessLogMode; - return Result.Success; - } - - public Result SetGlobalAccessLogMode(GlobalAccessLogMode mode) - { - if (HasFileSystemServer()) - { - using ReferenceCountedDisposable fsProxy = this.GetFileSystemProxyServiceObject(); - - return fsProxy.Target.SetGlobalAccessLogMode(mode); - } - - GlobalAccessLogMode = mode; - return Result.Success; - } - - public void SetAccessLogTarget(AccessLogTarget target) - { - AccessLogTarget = target; - } - public void SetAccessLogObject(IAccessLog accessLog) { AccessLog = accessLog; @@ -71,7 +41,7 @@ namespace LibHac.Fs if (HasFileSystemServer()) { using ReferenceCountedDisposable fsProxy = - this.GetFileSystemProxyServiceObject(); + Impl.GetFileSystemProxyServiceObject(); Result rc = fsProxy.Target.GetGlobalAccessLogMode(out GlobalAccessLogMode globalMode); GlobalAccessLogMode = globalMode; @@ -189,7 +159,7 @@ namespace LibHac.Fs { string logString = AccessLogHelpers.BuildDefaultLogLine(result, startTime, endTime, handleId, message, caller); - using ReferenceCountedDisposable fsProxy = this.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = Impl.GetFileSystemProxyServiceObject(); fsProxy.Target.OutputAccessLogToSdCard(new InBuffer(logString.ToU8Span())).IgnoreResult(); } } @@ -257,22 +227,4 @@ namespace LibHac.Fs return rc; } } - - [Flags] - public enum AccessLogTarget - { - None = 0, - Application = 1 << 0, - System = 1 << 1, - All = Application | System - } - - [Flags] - public enum GlobalAccessLogMode - { - None = 0, - Log = 1 << 0, - SdCard = 1 << 1, - All = Log | SdCard - } } diff --git a/src/LibHac/Fs/FileSystemClient.File.cs b/src/LibHac/Fs/FileSystemClient.File.cs index b61df30f..915f564c 100644 --- a/src/LibHac/Fs/FileSystemClient.File.cs +++ b/src/LibHac/Fs/FileSystemClient.File.cs @@ -1,4 +1,5 @@ using System; +using LibHac.Fs.Impl; namespace LibHac.Fs { diff --git a/src/LibHac/Fs/FileSystemClient.cs b/src/LibHac/Fs/FileSystemClient.cs index c1ee578b..bc8b0f61 100644 --- a/src/LibHac/Fs/FileSystemClient.cs +++ b/src/LibHac/Fs/FileSystemClient.cs @@ -26,6 +26,7 @@ namespace LibHac.Fs { public HorizonClient Hos; public object InitMutex; + public AccessLogGlobals AccessLog; public FileSystemProxyServiceObjectGlobals FileSystemProxyServiceObject; } @@ -33,6 +34,7 @@ namespace LibHac.Fs { internal FileSystemClientGlobals Globals; + public FileSystemClientImpl Impl => new FileSystemClientImpl(this); internal HorizonClient Hos => Globals.Hos; internal ITimeSpanGenerator Time { get; } diff --git a/src/LibHac/Fs/Fsa/MountTable.cs b/src/LibHac/Fs/Fsa/MountTable.cs new file mode 100644 index 00000000..b867e1a9 --- /dev/null +++ b/src/LibHac/Fs/Fsa/MountTable.cs @@ -0,0 +1,88 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using LibHac.Common; +using LibHac.Diag; +using LibHac.Os; +using LibHac.Util; + +// ReSharper disable once CheckNamespace +namespace LibHac.Fs.Impl +{ + internal class MountTable + { + private LinkedList _fileSystemList; + private SdkMutexType _mutex; + + public MountTable(FileSystemClient fsClient) + { + _fileSystemList = new LinkedList(); + _mutex = new SdkMutexType(); + } + + public Result Mount(FileSystemAccessor fileSystem) + { + ScopedLock.Lock(ref _mutex); + + if (!CanAcceptMountName(fileSystem.GetName())) + return ResultFs.MountNameAlreadyExists.Log(); + + _fileSystemList.AddLast(fileSystem); + return Result.Success; + } + + public Result Find(out FileSystemAccessor accessor, U8Span name) + { + accessor = default; + ScopedLock.Lock(ref _mutex); + + for (LinkedListNode currentNode = _fileSystemList.First; + currentNode is not null; + currentNode = currentNode.Next) + { + if (!Matches(currentNode.Value, name)) continue; + accessor = currentNode.Value; + return Result.Success; + } + + return ResultFs.NotMounted.Log(); + } + + public void Unmount(U8Span name) + { + ScopedLock.Lock(ref _mutex); + + LinkedListNode currentNode; + for (currentNode = _fileSystemList.First; currentNode is not null; currentNode = currentNode.Next) + { + if (Matches(currentNode.Value, name)) + break; + } + + if (currentNode is null) + Abort.DoAbort(ResultFs.NotMounted.Log(), $"{name.ToString()} is not mounted."); + + _fileSystemList.Remove(currentNode); + currentNode.Value.Dispose(); + } + + public bool CanAcceptMountName(U8Span name) + { + Assert.True(_mutex.IsLockedByCurrentThread()); + + for (LinkedListNode currentNode = _fileSystemList.First; + currentNode is not null; + currentNode = currentNode.Next) + { + if (Matches(currentNode.Value, name)) + return false; + } + + return true; + } + + private static bool Matches(FileSystemAccessor accessor, U8Span name) + { + return StringUtils.Compare(accessor.GetName(), name, Unsafe.SizeOf()) == 0; + } + } +} diff --git a/src/LibHac/Fs/Fsa/MountUtility.cs b/src/LibHac/Fs/Fsa/MountUtility.cs new file mode 100644 index 00000000..302c137d --- /dev/null +++ b/src/LibHac/Fs/Fsa/MountUtility.cs @@ -0,0 +1,66 @@ +using System; +using LibHac.Common; +using LibHac.Fs.Impl; + +namespace LibHac.Fs.Fsa +{ + public static class MountUtility + { + internal static Result GetMountNameAndSubPath(out MountName mountName, out U8Span subPath, U8Span path) + { + throw new NotImplementedException(); + } + + public static bool IsValidMountName(this FileSystemClientImpl fs, U8Span name) + { + throw new NotImplementedException(); + } + + public static bool IsUsedReservedMountName(this FileSystemClientImpl fs, U8Span name) + { + throw new NotImplementedException(); + } + + internal static Result FindFileSystem(this FileSystemClientImpl fs, out FileSystemAccessor fileSystem, + out U8Span subPath, U8Span path) + { + throw new NotImplementedException(); + } + + public static Result CheckMountName(this FileSystemClientImpl fs, U8Span name) + { + throw new NotImplementedException(); + } + + public static Result CheckMountNameAcceptingReservedMountName(this FileSystemClientImpl fs, U8Span name) + { + throw new NotImplementedException(); + } + + public static Result Unmount(this FileSystemClientImpl fs, U8Span mountName) + { + throw new NotImplementedException(); + } + + public static Result IsMounted(this FileSystemClientImpl fs, out bool isMounted, U8Span mountName) + { + throw new NotImplementedException(); + } + + public static Result Unmount(this FileSystemClient fs, U8Span mountName) + { + throw new NotImplementedException(); + } + + public static Result IsMounted(this FileSystemClient fs, out bool isMounted, U8Span mountName) + { + throw new NotImplementedException(); + } + + public static Result ConvertToFsCommonPath(this FileSystemClient fs, U8SpanMutable commonPathBuffer, + U8Span path) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/LibHac/Fs/Shim/Application.cs b/src/LibHac/Fs/Shim/Application.cs index 74de94ca..9dec2866 100644 --- a/src/LibHac/Fs/Shim/Application.cs +++ b/src/LibHac/Fs/Shim/Application.cs @@ -41,7 +41,7 @@ namespace LibHac.Fs.Shim FspPath.FromSpan(out FspPath sfPath, path); - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); rc = fsProxy.Target.OpenFileSystemWithId(out ReferenceCountedDisposable fileSystem, in sfPath, default, FileSystemProxyType.Package); diff --git a/src/LibHac/Fs/Shim/BcatSaveData.cs b/src/LibHac/Fs/Shim/BcatSaveData.cs index f4d0c3ca..d3575e02 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; - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(applicationId, SaveDataType.Bcat, UserId.InvalidId, 0); diff --git a/src/LibHac/Fs/Shim/Bis.cs b/src/LibHac/Fs/Shim/Bis.cs index 11bccacd..c65df51e 100644 --- a/src/LibHac/Fs/Shim/Bis.cs +++ b/src/LibHac/Fs/Shim/Bis.cs @@ -92,7 +92,7 @@ namespace LibHac.Fs.Shim Result rc = MountHelpers.CheckMountNameAcceptingReservedMountName(mountName); if (rc.IsFailure()) return rc; - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); // Nintendo doesn't use the provided rootPath FspPath.CreateEmpty(out FspPath sfPath); @@ -166,7 +166,7 @@ namespace LibHac.Fs.Shim FspPath.FromSpan(out FspPath sfPath, path.Str); - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); return fsProxy.Target.SetBisRootForHost(partitionId, in sfPath); } @@ -176,7 +176,7 @@ namespace LibHac.Fs.Shim { partitionStorage = default; - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); Result rc = fsProxy.Target.OpenBisStorage(out ReferenceCountedDisposable storage, partitionId); if (rc.IsFailure()) return rc; @@ -191,7 +191,7 @@ namespace LibHac.Fs.Shim public static Result InvalidateBisCache(this FileSystemClient fs) { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); return fsProxy.Target.InvalidateBisCache(); } } diff --git a/src/LibHac/Fs/Shim/Code.cs b/src/LibHac/Fs/Shim/Code.cs index 04c70127..481e0360 100644 --- a/src/LibHac/Fs/Shim/Code.cs +++ b/src/LibHac/Fs/Shim/Code.cs @@ -48,7 +48,7 @@ namespace LibHac.Fs.Shim if (rc.IsFailure()) return rc; using ReferenceCountedDisposable fsProxy = - fs.GetFileSystemProxyForLoaderServiceObject(); + fs.Impl.GetFileSystemProxyForLoaderServiceObject(); rc = fsProxy.Target.OpenCodeFileSystem(out ReferenceCountedDisposable codeFs, out verificationData, in fsPath, programId); diff --git a/src/LibHac/Fs/Shim/Content.cs b/src/LibHac/Fs/Shim/Content.cs index d521f74c..aeab7787 100644 --- a/src/LibHac/Fs/Shim/Content.cs +++ b/src/LibHac/Fs/Shim/Content.cs @@ -25,7 +25,7 @@ namespace LibHac.Fs.Shim FileSystemProxyType fspType = ConvertToFileSystemProxyType(type); - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); rc = fsProxy.Target.OpenFileSystemWithPatch(out ReferenceCountedDisposable fileSystem, programId, fspType); @@ -63,7 +63,7 @@ namespace LibHac.Fs.Shim { FspPath.FromSpan(out FspPath fsPath, path); - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); Result rc = fsProxy.Target.OpenFileSystemWithId(out ReferenceCountedDisposable fileSystem, in fsPath, id, type); diff --git a/src/LibHac/Fs/Shim/ContentStorage.cs b/src/LibHac/Fs/Shim/ContentStorage.cs index 09dfcc16..786ee8ff 100644 --- a/src/LibHac/Fs/Shim/ContentStorage.cs +++ b/src/LibHac/Fs/Shim/ContentStorage.cs @@ -20,7 +20,7 @@ namespace LibHac.Fs.Shim Result rc = MountHelpers.CheckMountNameAcceptingReservedMountName(mountName); if (rc.IsFailure()) return rc; - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); rc = fsProxy.Target.OpenContentStorageFileSystem(out ReferenceCountedDisposable contentFs, storageId); diff --git a/src/LibHac/Fs/Shim/CustomStorage.cs b/src/LibHac/Fs/Shim/CustomStorage.cs index e260a1fd..176a27e6 100644 --- a/src/LibHac/Fs/Shim/CustomStorage.cs +++ b/src/LibHac/Fs/Shim/CustomStorage.cs @@ -17,7 +17,7 @@ namespace LibHac.Fs.Shim ReferenceCountedDisposable customFs = null; try { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); rc = fsProxy.Target.OpenCustomStorageFileSystem(out customFs, storageId); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/Fs/Shim/FileSystemProxyServiceObject.cs b/src/LibHac/Fs/Shim/FileSystemProxyServiceObject.cs index ac71b78f..1c498c7d 100644 --- a/src/LibHac/Fs/Shim/FileSystemProxyServiceObject.cs +++ b/src/LibHac/Fs/Shim/FileSystemProxyServiceObject.cs @@ -20,13 +20,13 @@ namespace LibHac.Fs.Shim public static class FileSystemProxyServiceObject { - private static bool HasFileSystemServer(FileSystemClient fs) + private static bool HasFileSystemServer(FileSystemClientImpl fs) { return fs.Hos is not null; } public static ReferenceCountedDisposable GetFileSystemProxyServiceObject( - this FileSystemClient fs) + this FileSystemClientImpl fs) { ref FileSystemProxyServiceObjectGlobals g = ref fs.Globals.FileSystemProxyServiceObject; using var guard = new InitializationGuard(ref g.FileSystemProxyServiceObjectInitGuard, @@ -41,7 +41,7 @@ namespace LibHac.Fs.Shim } private static ReferenceCountedDisposable GetFileSystemProxyServiceObjectImpl( - FileSystemClient fs) + FileSystemClientImpl fs) { ReferenceCountedDisposable dfcServiceObject = fs.Globals.FileSystemProxyServiceObject.DfcFileSystemProxyServiceObject; @@ -66,7 +66,7 @@ namespace LibHac.Fs.Shim } public static ReferenceCountedDisposable GetFileSystemProxyForLoaderServiceObject( - this FileSystemClient fs) + this FileSystemClientImpl fs) { ref FileSystemProxyServiceObjectGlobals g = ref fs.Globals.FileSystemProxyServiceObject; using var guard = new InitializationGuard(ref g.FileSystemProxyForLoaderServiceObjectInitGuard, @@ -81,7 +81,7 @@ namespace LibHac.Fs.Shim } private static ReferenceCountedDisposable - GetFileSystemProxyForLoaderServiceObjectImpl(FileSystemClient fs) + GetFileSystemProxyForLoaderServiceObjectImpl(FileSystemClientImpl fs) { if (!HasFileSystemServer(fs)) { @@ -101,7 +101,7 @@ namespace LibHac.Fs.Shim } public static ReferenceCountedDisposable GetProgramRegistryServiceObject( - this FileSystemClient fs) + this FileSystemClientImpl fs) { ref FileSystemProxyServiceObjectGlobals g = ref fs.Globals.FileSystemProxyServiceObject; using var guard = new InitializationGuard(ref g.ProgramRegistryServiceObjectInitGuard, @@ -116,7 +116,7 @@ namespace LibHac.Fs.Shim } private static ReferenceCountedDisposable GetProgramRegistryServiceObjectImpl( - FileSystemClient fs) + FileSystemClientImpl fs) { if (!HasFileSystemServer(fs)) { @@ -141,7 +141,7 @@ namespace LibHac.Fs.Shim /// /// The to use. /// The service object this will use. - public static void InitializeDfcFileSystemProxyServiceObject(this FileSystemClient fs, + public static void InitializeDfcFileSystemProxyServiceObject(this FileSystemClientImpl 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 1b9e1842..ba8b18a0 100644 --- a/src/LibHac/Fs/Shim/GameCard.cs +++ b/src/LibHac/Fs/Shim/GameCard.cs @@ -18,7 +18,7 @@ namespace LibHac.Fs.Shim ReferenceCountedDisposable deviceOperator = null; try { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); Result rc = fsProxy.Target.OpenDeviceOperator(out deviceOperator); if (rc.IsFailure()) return rc; @@ -36,7 +36,7 @@ namespace LibHac.Fs.Shim ReferenceCountedDisposable deviceOperator = null; try { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); Result rc = fsProxy.Target.OpenDeviceOperator(out deviceOperator); if (rc.IsFailure()) throw new LibHacException("Abort"); @@ -60,7 +60,7 @@ namespace LibHac.Fs.Shim ReferenceCountedDisposable sfStorage = null; try { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); Result rc = fsProxy.Target.OpenGameCardStorage(out sfStorage, handle, partitionType); if (rc.IsFailure()) return rc; @@ -80,7 +80,7 @@ namespace LibHac.Fs.Shim Result rc = MountHelpers.CheckMountNameAcceptingReservedMountName(mountName); if (rc.IsFailure()) return rc; - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); rc = fsProxy.Target.OpenGameCardFileSystem(out ReferenceCountedDisposable cardFs, handle, partitionId); diff --git a/src/LibHac/Fs/Shim/Host.cs b/src/LibHac/Fs/Shim/Host.cs index 8d361704..30244401 100644 --- a/src/LibHac/Fs/Shim/Host.cs +++ b/src/LibHac/Fs/Shim/Host.cs @@ -363,7 +363,7 @@ namespace LibHac.Fs.Shim { fileSystem = default; - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); ReferenceCountedDisposable hostFs = null; try diff --git a/src/LibHac/Fs/Shim/LoaderApi.cs b/src/LibHac/Fs/Shim/LoaderApi.cs index 9ccc2bfe..83303b8d 100644 --- a/src/LibHac/Fs/Shim/LoaderApi.cs +++ b/src/LibHac/Fs/Shim/LoaderApi.cs @@ -8,7 +8,7 @@ namespace LibHac.Fs.Shim public static Result IsArchivedProgram(this FileSystemClient fs, out bool isArchived, ProcessId processId) { using ReferenceCountedDisposable fsProxy = - fs.GetFileSystemProxyForLoaderServiceObject(); + fs.Impl.GetFileSystemProxyForLoaderServiceObject(); 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 7e1597f5..a174b8b2 100644 --- a/src/LibHac/Fs/Shim/ProgramIndexMapInfo.cs +++ b/src/LibHac/Fs/Shim/ProgramIndexMapInfo.cs @@ -20,7 +20,7 @@ namespace LibHac.Fs.Shim if (mapInfo.IsEmpty) return Result.Success; - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); var mapInfoBuffer = new InBuffer(MemoryMarshal.Cast(mapInfo)); diff --git a/src/LibHac/Fs/Shim/ProgramRegistry.cs b/src/LibHac/Fs/Shim/ProgramRegistry.cs index 5df3859a..3b73c0c9 100644 --- a/src/LibHac/Fs/Shim/ProgramRegistry.cs +++ b/src/LibHac/Fs/Shim/ProgramRegistry.cs @@ -12,7 +12,7 @@ namespace LibHac.Fs.Shim public static Result RegisterProgram(this FileSystemClient fs, ulong processId, ProgramId programId, StorageId storageId, ReadOnlySpan accessControlData, ReadOnlySpan accessControlDescriptor) { - using ReferenceCountedDisposable registry = fs.GetProgramRegistryServiceObject(); + using ReferenceCountedDisposable registry = fs.Impl.GetProgramRegistryServiceObject(); Result rc = registry.Target.SetCurrentProcess(fs.Hos.ProcessId.Value); if (rc.IsFailure()) return rc; @@ -24,7 +24,7 @@ namespace LibHac.Fs.Shim /// public static Result UnregisterProgram(this FileSystemClient fs, ulong processId) { - using ReferenceCountedDisposable registry = fs.GetProgramRegistryServiceObject(); + using ReferenceCountedDisposable registry = fs.Impl.GetProgramRegistryServiceObject(); Result rc = registry.Target.SetCurrentProcess(fs.Hos.ProcessId.Value); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/Fs/Shim/RightsId.cs b/src/LibHac/Fs/Shim/RightsId.cs index cd172e07..0d8c1981 100644 --- a/src/LibHac/Fs/Shim/RightsId.cs +++ b/src/LibHac/Fs/Shim/RightsId.cs @@ -11,7 +11,7 @@ namespace LibHac.Fs.Shim public static Result GetRightsId(this FileSystemClient fs, out FsRightsId rightsId, ProgramId programId, StorageId storageId) { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); return fsProxy.Target.GetRightsId(out rightsId, programId, storageId); } @@ -20,7 +20,7 @@ namespace LibHac.Fs.Shim { rightsId = default; - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); Result rc = FspPath.FromSpan(out FspPath sfPath, path); if (rc.IsFailure()) return rc; @@ -33,7 +33,7 @@ namespace LibHac.Fs.Shim rightsId = default; keyGeneration = default; - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); Result rc = FspPath.FromSpan(out FspPath sfPath, path); if (rc.IsFailure()) return rc; @@ -43,21 +43,21 @@ namespace LibHac.Fs.Shim public static Result RegisterExternalKey(this FileSystemClient fs, in FsRightsId rightsId, in AccessKey key) { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); return fsProxy.Target.RegisterExternalKey(in rightsId, in key); } public static Result UnregisterExternalKey(this FileSystemClient fs, ref FsRightsId rightsId) { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); return fsProxy.Target.UnregisterExternalKey(in rightsId); } public static Result UnregisterAllExternalKey(this FileSystemClient fs) { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); return fsProxy.Target.UnregisterAllExternalKey(); } diff --git a/src/LibHac/Fs/Shim/SaveData.cs b/src/LibHac/Fs/Shim/SaveData.cs index dd5777f6..02b2d45b 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; - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(programId, type, userId, 0, index); diff --git a/src/LibHac/Fs/Shim/SaveDataManagement.cs b/src/LibHac/Fs/Shim/SaveDataManagement.cs index 06302a6e..91608b72 100644 --- a/src/LibHac/Fs/Shim/SaveDataManagement.cs +++ b/src/LibHac/Fs/Shim/SaveDataManagement.cs @@ -1,6 +1,7 @@ using System; using System.Runtime.InteropServices; using LibHac.Diag; +using LibHac.Fs.Impl; using LibHac.FsSrv.Sf; using LibHac.Ncm; using LibHac.Sf; @@ -15,7 +16,7 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(applicationId, SaveDataType.Account, userId, 0); @@ -47,7 +48,7 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(applicationId, SaveDataType.Account, userId, 0); @@ -79,7 +80,7 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(applicationId, SaveDataType.Bcat, UserId.InvalidId, 0); @@ -106,7 +107,7 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(applicationId, SaveDataType.Device, UserId.InvalidId, 0); @@ -132,7 +133,7 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(applicationId, SaveDataType.Temporary, UserId.InvalidId, 0); @@ -158,7 +159,7 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(applicationId, SaveDataType.Cache, UserId.InvalidId, 0, index); @@ -197,7 +198,7 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(ProgramId.InvalidId, SaveDataType.System, userId, saveDataId); @@ -251,7 +252,7 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); return fsProxy.Target.DeleteSaveDataFileSystem(saveDataId); }, () => $", savedataid: 0x{saveDataId:X}"); @@ -262,7 +263,7 @@ namespace LibHac.Fs.Shim return fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); return fsProxy.Target.DeleteSaveDataFileSystemBySaveDataSpaceId(spaceId, saveDataId); }, () => $", savedataspaceid: {spaceId}, savedataid: 0x{saveDataId:X}"); @@ -279,7 +280,7 @@ namespace LibHac.Fs.Shim Result result = fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); tempInfo = new SaveDataInfo(); @@ -311,7 +312,7 @@ namespace LibHac.Fs.Shim Result result = fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); return fsProxy.Target.QuerySaveDataTotalSize(out totalSizeTemp, size, journalSize); }, @@ -334,7 +335,7 @@ namespace LibHac.Fs.Shim Result result = fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); Result rc = fsProxy.Target.OpenSaveDataInfoReaderBySaveDataSpaceId( out ReferenceCountedDisposable reader, spaceId); @@ -368,7 +369,7 @@ namespace LibHac.Fs.Shim Result result = fs.RunOperationWithAccessLog(AccessLogTarget.System, () => { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); Result rc = fsProxy.Target.OpenSaveDataInfoReaderWithFilter(out reader, spaceId, in tempFilter); if (rc.IsFailure()) return rc; @@ -391,7 +392,7 @@ namespace LibHac.Fs.Shim public static void DisableAutoSaveDataCreation(this FileSystemClient fsClient) { - using ReferenceCountedDisposable fsProxy = fsClient.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fsClient.Impl.GetFileSystemProxyServiceObject(); Result rc = fsProxy.Target.DisableAutoSaveDataCreation(); diff --git a/src/LibHac/Fs/Shim/SdCard.cs b/src/LibHac/Fs/Shim/SdCard.cs index a0235431..91163f2e 100644 --- a/src/LibHac/Fs/Shim/SdCard.cs +++ b/src/LibHac/Fs/Shim/SdCard.cs @@ -39,7 +39,7 @@ namespace LibHac.Fs.Shim Result rc = MountHelpers.CheckMountName(mountName); if (rc.IsFailure()) return rc; - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); rc = fsProxy.Target.OpenSdCardFileSystem(out ReferenceCountedDisposable fileSystem); if (rc.IsFailure()) return rc; @@ -58,7 +58,7 @@ namespace LibHac.Fs.Shim ReferenceCountedDisposable deviceOperator = null; try { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); Result rc = fsProxy.Target.OpenDeviceOperator(out deviceOperator); if (rc.IsFailure()) throw new HorizonResultException(rc, "Abort"); @@ -76,7 +76,7 @@ namespace LibHac.Fs.Shim public static Result SetSdCardEncryptionSeed(this FileSystemClient fs, in EncryptionSeed seed) { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); Result rc = fsProxy.Target.SetSdCardEncryptionSeed(in seed); if (rc.IsFailure()) throw new HorizonResultException(rc, "Abort"); @@ -86,7 +86,7 @@ namespace LibHac.Fs.Shim public static void SetSdCardAccessibility(this FileSystemClient fs, bool isAccessible) { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); Result rc = fsProxy.Target.SetSdCardAccessibility(isAccessible); if (rc.IsFailure()) throw new HorizonResultException(rc, "Abort"); @@ -94,7 +94,7 @@ namespace LibHac.Fs.Shim public static bool IsSdCardAccessible(this FileSystemClient fs) { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); Result rc = fsProxy.Target.IsSdCardAccessible(out bool isAccessible); if (rc.IsFailure()) throw new HorizonResultException(rc, "Abort"); diff --git a/src/LibHac/Fs/Shim/SystemSaveData.cs b/src/LibHac/Fs/Shim/SystemSaveData.cs index 03389a7a..22d05b45 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; - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); var attribute = new SaveDataAttribute(ProgramId.InvalidId, SaveDataType.System, userId, saveDataId); diff --git a/src/LibHac/Fs/Shim/UserFileSystem.cs b/src/LibHac/Fs/Shim/UserFileSystem.cs index 7cf84e9c..ea2eed62 100644 --- a/src/LibHac/Fs/Shim/UserFileSystem.cs +++ b/src/LibHac/Fs/Shim/UserFileSystem.cs @@ -22,7 +22,7 @@ namespace LibHac.Fs.Shim ReferenceCountedDisposable fileSystem = null; try { - using ReferenceCountedDisposable fsProxy = fs.GetFileSystemProxyServiceObject(); + using ReferenceCountedDisposable fsProxy = fs.Impl.GetFileSystemProxyServiceObject(); Result rc = fsProxy.Target.OpenMultiCommitManager(out commitManager); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/FsSrv/FileSystemServerInitializer.cs b/src/LibHac/FsSrv/FileSystemServerInitializer.cs index 1bfb2a86..7c13ba50 100644 --- a/src/LibHac/FsSrv/FileSystemServerInitializer.cs +++ b/src/LibHac/FsSrv/FileSystemServerInitializer.cs @@ -37,7 +37,7 @@ namespace LibHac.FsSrv ulong processId = client.Os.GetCurrentProcessId().Value; fsProxy.Target.SetCurrentProcess(processId).IgnoreResult(); - client.Fs.InitializeDfcFileSystemProxyServiceObject(fsProxy); + client.Fs.Impl.InitializeDfcFileSystemProxyServiceObject(fsProxy); InitializeFileSystemProxyServer(client, server); diff --git a/src/hactoolnet/Program.cs b/src/hactoolnet/Program.cs index 3c778b22..73207a17 100644 --- a/src/hactoolnet/Program.cs +++ b/src/hactoolnet/Program.cs @@ -4,6 +4,7 @@ using System.Text; using LibHac; using LibHac.Common.Keys; using LibHac.Fs; +using LibHac.Fs.Impl; using LibHac.Util; namespace hactoolnet @@ -74,7 +75,7 @@ namespace hactoolnet logWriter = new StreamWriter(ctx.Options.AccessLog); var accessLog = new TextWriterAccessLog(logWriter); - ctx.FsClient.SetAccessLogTarget(AccessLogTarget.All); + ctx.FsClient.SetLocalSystemAccessLogForDebug(true); ctx.FsClient.SetGlobalAccessLogMode(GlobalAccessLogMode.Log); ctx.FsClient.SetAccessLogObject(accessLog); diff --git a/tests/LibHac.Tests/FsSrv/ProgramIndexMapInfoTests.cs b/tests/LibHac.Tests/FsSrv/ProgramIndexMapInfoTests.cs index 092009ba..16a6df74 100644 --- a/tests/LibHac.Tests/FsSrv/ProgramIndexMapInfoTests.cs +++ b/tests/LibHac.Tests/FsSrv/ProgramIndexMapInfoTests.cs @@ -41,7 +41,7 @@ namespace LibHac.Tests.FsSrv for (int i = 0; i < programs.Length; i++) { using ReferenceCountedDisposable fsProxy = - programs[i].Fs.GetFileSystemProxyServiceObject(); + programs[i].Fs.Impl.GetFileSystemProxyServiceObject(); Assert.Success(fsProxy.Target.GetProgramIndexForAccessLog(out int programIndex, out int programCount)); Assert.Equal(i, programIndex);