From 0e26c31a2ff5c82f12873bf201f2f5bfe03a6cd9 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Mon, 16 Mar 2020 15:01:26 -0700 Subject: [PATCH] Enable OpenHostFileSystem in FileSystemProxy and add XML docs --- src/LibHac/Fs/FsEnums.cs | 1 + src/LibHac/Fs/Shim/Host.cs | 70 +++++++++++++++++++++ src/LibHac/FsService/FileSystemProxy.cs | 6 +- src/LibHac/FsService/FileSystemProxyCore.cs | 3 +- tests/LibHac.Tests/PathToolsTests.cs | 1 - 5 files changed, 77 insertions(+), 4 deletions(-) diff --git a/src/LibHac/Fs/FsEnums.cs b/src/LibHac/Fs/FsEnums.cs index 941cf84c..4704a82d 100644 --- a/src/LibHac/Fs/FsEnums.cs +++ b/src/LibHac/Fs/FsEnums.cs @@ -188,6 +188,7 @@ namespace LibHac.Fs SdCard = 2 } + [Flags] public enum MountHostOption { None = 0, diff --git a/src/LibHac/Fs/Shim/Host.cs b/src/LibHac/Fs/Shim/Host.cs index e45bb44b..1164dbbb 100644 --- a/src/LibHac/Fs/Shim/Host.cs +++ b/src/LibHac/Fs/Shim/Host.cs @@ -8,6 +8,12 @@ using static LibHac.Fs.CommonMountNames; namespace LibHac.Fs.Shim { + /// + /// Contains functions for mounting file systems from a host computer. + /// + /// + /// All functions in this file are based on SDK 9.3 + /// public static class Host { private static ReadOnlySpan HostRootFileSystemPath => new[] @@ -59,6 +65,11 @@ namespace LibHac.Fs.Shim } } + /// + /// Mounts the C:\ drive of a host Windows computer at @Host:/ + /// + /// The to use. + /// The of the operation. public static Result MountHostRoot(this FileSystemClient fs) { IFileSystem hostFileSystem = default; @@ -87,6 +98,12 @@ namespace LibHac.Fs.Shim return Result.Success; } + /// + /// Mounts the C:\ drive of a host Windows computer at @Host:/ + /// + /// The to use. + /// Options for mounting the host file system. + /// The of the operation. public static Result MountHostRoot(this FileSystemClient fs, MountHostOption option) { IFileSystem hostFileSystem = default; @@ -116,21 +133,49 @@ namespace LibHac.Fs.Shim return Result.Success; } + /// + /// Unmounts the file system at @Host:/ + /// + /// The to use. public static void UnmountHostRoot(this FileSystemClient fs) { fs.Unmount(HostRootFileSystemMountName); } + /// + /// Mounts a directory on a host Windows computer at the specified mount point. + /// + /// The to use. + /// The mount name at which the file system will be mounted. + /// The path on the host computer to mount. e.g. C:\Windows\System32 + /// The of the operation. public static Result MountHost(this FileSystemClient fs, U8Span mountName, U8Span path) { return MountHostImpl(fs, mountName, path, null); } + /// + /// Mounts a directory on a host Windows computer at the specified mount point. + /// + /// The to use. + /// The mount name at which the file system will be mounted. + /// The path on the host computer to mount. e.g. C:\Windows\System32 + /// Options for mounting the host file system. + /// The of the operation. public static Result MountHost(this FileSystemClient fs, U8Span mountName, U8Span path, MountHostOption option) { return MountHostImpl(fs, mountName, path, option); } + /// + /// Mounts a directory on a host Windows computer at the specified mount point. + /// + /// The to use. + /// The mount name at which the file system will be mounted. + /// The path on the host computer to mount. e.g. C:\Windows\System32 + /// Options for mounting the host file system. Specifying this parameter is optional. + /// The caller of this function. + /// The of the operation. private static Result MountHostImpl(this FileSystemClient fs, U8Span mountName, U8Span path, MountHostOption? optionalOption, [CallerMemberName] string caller = "") { @@ -210,6 +255,14 @@ namespace LibHac.Fs.Shim return Result.Success; } + /// + /// Creates an based on the and + /// , and verifies the . + /// + /// If successful, the created . + /// The mount name at which the file system will be mounted. + /// The path that will be opened on the host computer. e.g. C:\Windows\System32 + /// The of the operation. private static Result PreMountHost(out ICommonMountNameGenerator nameGenerator, U8Span mountName, U8Span path) { nameGenerator = default; @@ -224,6 +277,15 @@ namespace LibHac.Fs.Shim return Result.Success; } + /// + /// Verifies parameters and opens a host file system. + /// + /// The to use. + /// If successful, the opened host file system. + /// The mount name to be verified. + /// The path on the host computer to open. e.g. C:\Windows\System32 + /// Options for opening the host file system. + /// The of the operation. private static Result OpenHostFileSystem(FileSystemClient fs, out IFileSystem fileSystem, U8Span mountName, U8Span path, MountHostOption option) { @@ -279,6 +341,14 @@ namespace LibHac.Fs.Shim return OpenHostFileSystemImpl(fs, out fileSystem, ref fullPath, option); } + /// + /// Opens a host file system via . + /// + /// The to use. + /// If successful, the opened host file system. + /// The path on the host computer to open. e.g. /C:\Windows\System32/ + /// Options for opening the host file system. + /// The of the operation. private static Result OpenHostFileSystemImpl(FileSystemClient fs, out IFileSystem fileSystem, ref FsPath path, MountHostOption option) { fileSystem = default; diff --git a/src/LibHac/FsService/FileSystemProxy.cs b/src/LibHac/FsService/FileSystemProxy.cs index f418b7f5..266be3ad 100644 --- a/src/LibHac/FsService/FileSystemProxy.cs +++ b/src/LibHac/FsService/FileSystemProxy.cs @@ -684,12 +684,14 @@ namespace LibHac.FsService public Result OpenHostFileSystemWithOption(out IFileSystem fileSystem, ref FsPath path, MountHostOption option) { - throw new NotImplementedException(); + // Missing permission check + + return FsProxyCore.OpenHostFileSystem(out fileSystem, new U8Span(path.Str), option.HasFlag(MountHostOption.PseudoCaseSensitive)); } public Result OpenHostFileSystem(out IFileSystem fileSystem, ref FsPath path) { - throw new NotImplementedException(); + return OpenHostFileSystemWithOption(out fileSystem, ref path, MountHostOption.None); } public Result OpenSdCardFileSystem(out IFileSystem fileSystem) diff --git a/src/LibHac/FsService/FileSystemProxyCore.cs b/src/LibHac/FsService/FileSystemProxyCore.cs index 9c6aefe9..3531c222 100644 --- a/src/LibHac/FsService/FileSystemProxyCore.cs +++ b/src/LibHac/FsService/FileSystemProxyCore.cs @@ -772,7 +772,8 @@ namespace LibHac.FsService if (path.IsEmpty()) { - rc = hostFs.GetEntryType(out _, "C:/".ToU8Span()); + ReadOnlySpan rootHostPath = new[] { (byte)'C', (byte)':', (byte)'/' }; + rc = hostFs.GetEntryType(out _, new U8Span(rootHostPath)); // Nintendo ignores all results other than this one if (ResultFs.TargetNotFound.Includes(rc)) diff --git a/tests/LibHac.Tests/PathToolsTests.cs b/tests/LibHac.Tests/PathToolsTests.cs index 3929e9cf..16d59c18 100644 --- a/tests/LibHac.Tests/PathToolsTests.cs +++ b/tests/LibHac.Tests/PathToolsTests.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using LibHac.Common; -using LibHac.Fs; using LibHac.FsSystem; using Xunit;