Implement or skeleton some mounting code

This commit is contained in:
Alex Barney 2021-02-13 17:45:05 -07:00
parent 596a8bef7c
commit 61654298d2
28 changed files with 394 additions and 112 deletions

View File

@ -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<IFileSystemProxy> 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<IFileSystemProxy> 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<SdkMutexType> 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);
}
}
}

View File

@ -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<IFileSystemProxy> fsProxy = this.GetFileSystemProxyServiceObject();
return fsProxy.Target.GetGlobalAccessLogMode(out mode);
}
mode = GlobalAccessLogMode;
return Result.Success;
}
public Result SetGlobalAccessLogMode(GlobalAccessLogMode mode)
{
if (HasFileSystemServer())
{
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = this.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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
}
}

View File

@ -1,4 +1,5 @@
using System;
using LibHac.Fs.Impl;
namespace LibHac.Fs
{

View File

@ -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; }

View File

@ -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<FileSystemAccessor> _fileSystemList;
private SdkMutexType _mutex;
public MountTable(FileSystemClient fsClient)
{
_fileSystemList = new LinkedList<FileSystemAccessor>();
_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<FileSystemAccessor> 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<FileSystemAccessor> 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<FileSystemAccessor> 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<MountName>()) == 0;
}
}
}

View File

@ -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();
}
}
}

View File

@ -41,7 +41,7 @@ namespace LibHac.Fs.Shim
FspPath.FromSpan(out FspPath sfPath, path);
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
rc = fsProxy.Target.OpenFileSystemWithId(out ReferenceCountedDisposable<IFileSystemSf> fileSystem,
in sfPath, default, FileSystemProxyType.Package);

View File

@ -41,7 +41,7 @@ namespace LibHac.Fs.Shim
Result rc = MountHelpers.CheckMountName(mountName);
if (rc.IsFailure()) return rc;
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
var attribute = new SaveDataAttribute(applicationId, SaveDataType.Bcat, UserId.InvalidId, 0);

View File

@ -92,7 +92,7 @@ namespace LibHac.Fs.Shim
Result rc = MountHelpers.CheckMountNameAcceptingReservedMountName(mountName);
if (rc.IsFailure()) return rc;
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
return fsProxy.Target.SetBisRootForHost(partitionId, in sfPath);
}
@ -176,7 +176,7 @@ namespace LibHac.Fs.Shim
{
partitionStorage = default;
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
Result rc = fsProxy.Target.OpenBisStorage(out ReferenceCountedDisposable<IStorageSf> storage, partitionId);
if (rc.IsFailure()) return rc;
@ -191,7 +191,7 @@ namespace LibHac.Fs.Shim
public static Result InvalidateBisCache(this FileSystemClient fs)
{
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
return fsProxy.Target.InvalidateBisCache();
}
}

View File

@ -48,7 +48,7 @@ namespace LibHac.Fs.Shim
if (rc.IsFailure()) return rc;
using ReferenceCountedDisposable<IFileSystemProxyForLoader> fsProxy =
fs.GetFileSystemProxyForLoaderServiceObject();
fs.Impl.GetFileSystemProxyForLoaderServiceObject();
rc = fsProxy.Target.OpenCodeFileSystem(out ReferenceCountedDisposable<IFileSystemSf> codeFs,
out verificationData, in fsPath, programId);

View File

@ -25,7 +25,7 @@ namespace LibHac.Fs.Shim
FileSystemProxyType fspType = ConvertToFileSystemProxyType(type);
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
rc = fsProxy.Target.OpenFileSystemWithPatch(out ReferenceCountedDisposable<IFileSystemSf> fileSystem,
programId, fspType);
@ -63,7 +63,7 @@ namespace LibHac.Fs.Shim
{
FspPath.FromSpan(out FspPath fsPath, path);
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
Result rc = fsProxy.Target.OpenFileSystemWithId(out ReferenceCountedDisposable<IFileSystemSf> fileSystem,
in fsPath, id, type);

View File

@ -20,7 +20,7 @@ namespace LibHac.Fs.Shim
Result rc = MountHelpers.CheckMountNameAcceptingReservedMountName(mountName);
if (rc.IsFailure()) return rc;
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
rc = fsProxy.Target.OpenContentStorageFileSystem(out ReferenceCountedDisposable<IFileSystemSf> contentFs,
storageId);

View File

@ -17,7 +17,7 @@ namespace LibHac.Fs.Shim
ReferenceCountedDisposable<IFileSystemSf> customFs = null;
try
{
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
rc = fsProxy.Target.OpenCustomStorageFileSystem(out customFs, storageId);
if (rc.IsFailure()) return rc;

View File

@ -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<IFileSystemProxy> 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<IFileSystemProxy> GetFileSystemProxyServiceObjectImpl(
FileSystemClient fs)
FileSystemClientImpl fs)
{
ReferenceCountedDisposable<IFileSystemProxy> dfcServiceObject =
fs.Globals.FileSystemProxyServiceObject.DfcFileSystemProxyServiceObject;
@ -66,7 +66,7 @@ namespace LibHac.Fs.Shim
}
public static ReferenceCountedDisposable<IFileSystemProxyForLoader> 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<IFileSystemProxyForLoader>
GetFileSystemProxyForLoaderServiceObjectImpl(FileSystemClient fs)
GetFileSystemProxyForLoaderServiceObjectImpl(FileSystemClientImpl fs)
{
if (!HasFileSystemServer(fs))
{
@ -101,7 +101,7 @@ namespace LibHac.Fs.Shim
}
public static ReferenceCountedDisposable<IProgramRegistry> 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<IProgramRegistry> GetProgramRegistryServiceObjectImpl(
FileSystemClient fs)
FileSystemClientImpl fs)
{
if (!HasFileSystemServer(fs))
{
@ -141,7 +141,7 @@ namespace LibHac.Fs.Shim
/// </summary>
/// <param name="fs">The <see cref="FileSystemClient"/> to use.</param>
/// <param name="serviceObject">The service object this <see cref="FileSystemClient"/> will use.</param>
public static void InitializeDfcFileSystemProxyServiceObject(this FileSystemClient fs,
public static void InitializeDfcFileSystemProxyServiceObject(this FileSystemClientImpl fs,
ReferenceCountedDisposable<IFileSystemProxy> serviceObject)
{
fs.Globals.FileSystemProxyServiceObject.DfcFileSystemProxyServiceObject = serviceObject.AddReference();

View File

@ -18,7 +18,7 @@ namespace LibHac.Fs.Shim
ReferenceCountedDisposable<IDeviceOperator> deviceOperator = null;
try
{
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IDeviceOperator> deviceOperator = null;
try
{
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IStorageSf> sfStorage = null;
try
{
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
rc = fsProxy.Target.OpenGameCardFileSystem(out ReferenceCountedDisposable<IFileSystemSf> cardFs, handle,
partitionId);

View File

@ -363,7 +363,7 @@ namespace LibHac.Fs.Shim
{
fileSystem = default;
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
ReferenceCountedDisposable<IFileSystemSf> hostFs = null;
try

View File

@ -8,7 +8,7 @@ namespace LibHac.Fs.Shim
public static Result IsArchivedProgram(this FileSystemClient fs, out bool isArchived, ProcessId processId)
{
using ReferenceCountedDisposable<IFileSystemProxyForLoader> fsProxy =
fs.GetFileSystemProxyForLoaderServiceObject();
fs.Impl.GetFileSystemProxyForLoaderServiceObject();
return fsProxy.Target.IsArchivedProgram(out isArchived, processId.Value);
}

View File

@ -20,7 +20,7 @@ namespace LibHac.Fs.Shim
if (mapInfo.IsEmpty)
return Result.Success;
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
var mapInfoBuffer = new InBuffer(MemoryMarshal.Cast<ProgramIndexMapInfo, byte>(mapInfo));

View File

@ -12,7 +12,7 @@ namespace LibHac.Fs.Shim
public static Result RegisterProgram(this FileSystemClient fs, ulong processId, ProgramId programId,
StorageId storageId, ReadOnlySpan<byte> accessControlData, ReadOnlySpan<byte> accessControlDescriptor)
{
using ReferenceCountedDisposable<IProgramRegistry> registry = fs.GetProgramRegistryServiceObject();
using ReferenceCountedDisposable<IProgramRegistry> 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
/// <inheritdoc cref="ProgramRegistryImpl.UnregisterProgram"/>
public static Result UnregisterProgram(this FileSystemClient fs, ulong processId)
{
using ReferenceCountedDisposable<IProgramRegistry> registry = fs.GetProgramRegistryServiceObject();
using ReferenceCountedDisposable<IProgramRegistry> registry = fs.Impl.GetProgramRegistryServiceObject();
Result rc = registry.Target.SetCurrentProcess(fs.Hos.ProcessId.Value);
if (rc.IsFailure()) return rc;

View File

@ -11,7 +11,7 @@ namespace LibHac.Fs.Shim
public static Result GetRightsId(this FileSystemClient fs, out FsRightsId rightsId, ProgramId programId,
StorageId storageId)
{
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
return fsProxy.Target.GetRightsId(out rightsId, programId, storageId);
}
@ -20,7 +20,7 @@ namespace LibHac.Fs.Shim
{
rightsId = default;
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
return fsProxy.Target.RegisterExternalKey(in rightsId, in key);
}
public static Result UnregisterExternalKey(this FileSystemClient fs, ref FsRightsId rightsId)
{
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
return fsProxy.Target.UnregisterExternalKey(in rightsId);
}
public static Result UnregisterAllExternalKey(this FileSystemClient fs)
{
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
return fsProxy.Target.UnregisterAllExternalKey();
}

View File

@ -189,7 +189,7 @@ namespace LibHac.Fs.Shim
Result rc = MountHelpers.CheckMountName(mountName);
if (rc.IsFailure()) return rc;
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
var attribute = new SaveDataAttribute(programId, type, userId, 0, index);

View File

@ -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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
tempInfo = new SaveDataInfo();
@ -311,7 +312,7 @@ namespace LibHac.Fs.Shim
Result result = fs.RunOperationWithAccessLog(AccessLogTarget.System,
() =>
{
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
Result rc = fsProxy.Target.OpenSaveDataInfoReaderBySaveDataSpaceId(
out ReferenceCountedDisposable<ISaveDataInfoReader> reader, spaceId);
@ -368,7 +369,7 @@ namespace LibHac.Fs.Shim
Result result = fs.RunOperationWithAccessLog(AccessLogTarget.System,
() =>
{
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fsClient.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fsClient.Impl.GetFileSystemProxyServiceObject();
Result rc = fsProxy.Target.DisableAutoSaveDataCreation();

View File

@ -39,7 +39,7 @@ namespace LibHac.Fs.Shim
Result rc = MountHelpers.CheckMountName(mountName);
if (rc.IsFailure()) return rc;
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
rc = fsProxy.Target.OpenSdCardFileSystem(out ReferenceCountedDisposable<IFileSystemSf> fileSystem);
if (rc.IsFailure()) return rc;
@ -58,7 +58,7 @@ namespace LibHac.Fs.Shim
ReferenceCountedDisposable<IDeviceOperator> deviceOperator = null;
try
{
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> 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<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
Result rc = fsProxy.Target.IsSdCardAccessible(out bool isAccessible);
if (rc.IsFailure()) throw new HorizonResultException(rc, "Abort");

View File

@ -20,7 +20,7 @@ namespace LibHac.Fs.Shim
Result rc = MountHelpers.CheckMountName(mountName);
if (rc.IsFailure()) return rc;
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
var attribute = new SaveDataAttribute(ProgramId.InvalidId, SaveDataType.System, userId, saveDataId);

View File

@ -22,7 +22,7 @@ namespace LibHac.Fs.Shim
ReferenceCountedDisposable<IFileSystemSf> fileSystem = null;
try
{
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = fs.Impl.GetFileSystemProxyServiceObject();
Result rc = fsProxy.Target.OpenMultiCommitManager(out commitManager);
if (rc.IsFailure()) return rc;

View File

@ -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);

View File

@ -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);

View File

@ -41,7 +41,7 @@ namespace LibHac.Tests.FsSrv
for (int i = 0; i < programs.Length; i++)
{
using ReferenceCountedDisposable<LibHac.FsSrv.Sf.IFileSystemProxy> 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);