Add FsSrv.Impl.FileSystemProxyServiceObject

This commit is contained in:
Alex Barney 2021-02-06 22:04:00 -07:00
parent e3c14dfa4f
commit a94bb81c54
5 changed files with 109 additions and 30 deletions

View file

@ -661,6 +661,7 @@ Module,DescriptionStart,DescriptionEnd,Flags,Namespace,Name,Summary
2,6400,6449,,,PermissionDenied,
2,6450,,,,PortAcceptableCountLimited,
2,6452,,,,ExternalKeyAlreadyRegistered,
2,6454,,,,NeedFlush,
2,6455,,,,FileNotClosed,

1 Module DescriptionStart DescriptionEnd Flags Namespace Name Summary
661 5 110 100 InvalidContentMetaDatabase InvalidContentStorage
662 5 130 110 InvalidPackageFormat InvalidContentMetaDatabase
663 5 140 130 InvalidContentHash InvalidPackageFormat
664 5 140 InvalidContentHash
665 5 160 InvalidInstallTaskState
666 5 170 InvalidPlaceHolderFile
667 5 180 BufferInsufficient

View file

@ -1182,6 +1182,8 @@ namespace LibHac.Fs
/// <summary>Error code: 2002-6400; Range: 6400-6449; Inner value: 0x320002</summary>
public static Result.Base PermissionDenied { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ModuleFs, 6400, 6449); }
/// <summary>Error code: 2002-6450; Inner value: 0x326402</summary>
public static Result.Base PortAcceptableCountLimited => new Result.Base(ModuleFs, 6450);
/// <summary>Error code: 2002-6452; Inner value: 0x326802</summary>
public static Result.Base ExternalKeyAlreadyRegistered => new Result.Base(ModuleFs, 6452);
/// <summary>Error code: 2002-6454; Inner value: 0x326c02</summary>

View file

@ -54,15 +54,15 @@ namespace LibHac.Fs.Shim
throw new InvalidOperationException("Client was not initialized with a server object.");
}
Result rc = fs.Hos.Sm.GetService(out IFileSystemProxy fsProxy, "fsp-srv");
Result rc = fs.Hos.Sm.GetService(out ReferenceCountedDisposable<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<IFileSystemProxy>(fsProxy);
fsProxy.Target.SetCurrentProcess(fs.Hos.Os.GetCurrentProcessId().Value).IgnoreResult();
return fsProxy;
}
public static ReferenceCountedDisposable<IFileSystemProxyForLoader> GetFileSystemProxyForLoaderServiceObject(
@ -88,15 +88,16 @@ namespace LibHac.Fs.Shim
throw new InvalidOperationException("Client was not initialized with a server object.");
}
Result rc = fs.Hos.Sm.GetService(out IFileSystemProxyForLoader fsProxy, "fsp-ldr");
Result rc = fs.Hos.Sm.GetService(out ReferenceCountedDisposable<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<IFileSystemProxyForLoader>(fsProxy);
fsProxy.Target.SetCurrentProcess(fs.Hos.Os.GetCurrentProcessId().Value).IgnoreResult();
return fsProxy;
}
public static ReferenceCountedDisposable<IProgramRegistry> GetProgramRegistryServiceObject(
@ -122,19 +123,19 @@ namespace LibHac.Fs.Shim
throw new InvalidOperationException("Client was not initialized with a server object.");
}
Result rc = fs.Hos.Sm.GetService(out IProgramRegistry registry, "fsp-pr");
Result rc = fs.Hos.Sm.GetService(out ReferenceCountedDisposable<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<IProgramRegistry>(registry);
registry.Target.SetCurrentProcess(fs.Hos.Os.GetCurrentProcessId().Value).IgnoreResult();
return registry;
}
/// <summary>
/// Sets a <see cref="IFileSystemProxy"/> service object to use for direct function calls
/// Sets an <see cref="IFileSystemProxy"/> 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 <see cref="GetFileSystemProxyServiceObject"/>.
/// </summary>

View file

@ -41,9 +41,11 @@ namespace LibHac.FsSrv
FileSystemProxyConfiguration fspConfig = InitializeFileSystemProxyConfiguration(config);
this.InitializeFileSystemProxy(fspConfig);
FileSystemProxyImpl fsProxy = GetFileSystemProxyServiceObject();
using ReferenceCountedDisposable<IFileSystemProxy> fsProxy = Impl.GetFileSystemProxyServiceObject();
ulong processId = Hos.Os.GetCurrentProcessId().Value;
fsProxy.SetCurrentProcess(processId).IgnoreResult();
fsProxy.Target.SetCurrentProcess(processId).IgnoreResult();
Hos.Fs.InitializeDfcFileSystemProxyServiceObject(fsProxy);
var saveService = new SaveDataFileSystemService(fspConfig.SaveDataFileSystemService, processId);
@ -164,21 +166,6 @@ namespace LibHac.FsSrv
return fspConfig;
}
private FileSystemProxyImpl GetFileSystemProxyServiceObject()
{
return new FileSystemProxyImpl(this);
}
private FileSystemProxyImpl GetFileSystemProxyForLoaderServiceObject()
{
return new FileSystemProxyImpl(this);
}
private ProgramRegistryImpl GetProgramRegistryServiceObject()
{
return new ProgramRegistryImpl(this);
}
private class FileSystemProxyService : IServiceObject
{
private readonly FileSystemServer _server;
@ -190,7 +177,7 @@ namespace LibHac.FsSrv
public Result GetServiceObject(out object serviceObject)
{
serviceObject = _server.GetFileSystemProxyServiceObject();
serviceObject = _server.Impl.GetFileSystemProxyServiceObject();
return Result.Success;
}
}
@ -206,7 +193,7 @@ namespace LibHac.FsSrv
public Result GetServiceObject(out object serviceObject)
{
serviceObject = _server.GetFileSystemProxyForLoaderServiceObject();
serviceObject = _server.Impl.GetFileSystemProxyForLoaderServiceObject();
return Result.Success;
}
}
@ -222,7 +209,7 @@ namespace LibHac.FsSrv
public Result GetServiceObject(out object serviceObject)
{
serviceObject = _server.GetProgramRegistryServiceObject();
serviceObject = _server.Impl.GetProgramRegistryServiceObject();
return Result.Success;
}
}

View file

@ -0,0 +1,88 @@
using System.Runtime.CompilerServices;
using LibHac.Fs;
using LibHac.FsSrv.Sf;
using LibHac.Ncm;
using LibHac.Sf;
namespace LibHac.FsSrv.Impl
{
public static class FileSystemProxyServiceObject
{
public static ReferenceCountedDisposable<IFileSystemProxy> GetFileSystemProxyServiceObject(
this FileSystemServerImpl fsSrv)
{
return new ReferenceCountedDisposable<IFileSystemProxy>(new FileSystemProxyImpl(fsSrv.FsSrv));
}
public static ReferenceCountedDisposable<IFileSystemProxyForLoader> GetFileSystemProxyForLoaderServiceObject(
this FileSystemServerImpl fsSrv)
{
return new ReferenceCountedDisposable<IFileSystemProxyForLoader>(new FileSystemProxyImpl(fsSrv.FsSrv));
}
public static ReferenceCountedDisposable<IFileSystemProxyForLoader>
GetInvalidFileSystemProxyForLoaderServiceObject(this FileSystemServerImpl fsSrv)
{
return new ReferenceCountedDisposable<IFileSystemProxyForLoader>(new InvalidFileSystemProxyImplForLoader());
}
public static ReferenceCountedDisposable<IProgramRegistry> GetProgramRegistryServiceObject(
this FileSystemServerImpl fsSrv)
{
return new ReferenceCountedDisposable<IProgramRegistry>(new ProgramRegistryImpl(fsSrv.FsSrv));
}
public static ReferenceCountedDisposable<IProgramRegistry> GetInvalidProgramRegistryServiceObject(
this FileSystemServerImpl fsSrv)
{
return new ReferenceCountedDisposable<IProgramRegistry>(new InvalidProgramRegistryImpl());
}
private class InvalidFileSystemProxyImplForLoader : IFileSystemProxyForLoader
{
public void Dispose() { }
public Result IsArchivedProgram(out bool isArchived, ulong processId)
{
Unsafe.SkipInit(out isArchived);
return ResultFs.PortAcceptableCountLimited.Log();
}
public Result OpenCodeFileSystem(out ReferenceCountedDisposable<IFileSystem> fileSystem,
out CodeVerificationData verificationData, in FspPath path, ProgramId programId)
{
fileSystem = default;
Unsafe.SkipInit(out verificationData);
return ResultFs.PortAcceptableCountLimited.Log();
}
public Result SetCurrentProcess(ulong processId)
{
return ResultFs.PortAcceptableCountLimited.Log();
}
}
private class InvalidProgramRegistryImpl : IProgramRegistry
{
public void Dispose() { }
public Result RegisterProgram(ulong processId, ProgramId programId, StorageId storageId,
InBuffer accessControlData, InBuffer accessControlDescriptor)
{
return ResultFs.PortAcceptableCountLimited.Log();
}
public Result SetCurrentProcess(ulong processId)
{
return ResultFs.PortAcceptableCountLimited.Log();
}
public Result UnregisterProgram(ulong processId)
{
return ResultFs.PortAcceptableCountLimited.Log();
}
}
}
}