diff --git a/src/LibHac/Fs/FsEnums.cs b/src/LibHac/Fs/FsEnums.cs index a6714b59..02ef7768 100644 --- a/src/LibHac/Fs/FsEnums.cs +++ b/src/LibHac/Fs/FsEnums.cs @@ -63,7 +63,16 @@ namespace LibHac.Fs SdCard = 1 } - public enum FileSystemType + public enum ContentType + { + Meta = 0, + Control = 1, + Manual = 2, + Logo = 3, + Data = 4, + } + + public enum FileSystemProxyType { Code = 0, Data = 1, diff --git a/src/LibHac/Fs/Shim/Content.cs b/src/LibHac/Fs/Shim/Content.cs new file mode 100644 index 00000000..13c78108 --- /dev/null +++ b/src/LibHac/Fs/Shim/Content.cs @@ -0,0 +1,65 @@ +using System; +using LibHac.Common; +using LibHac.FsService; +using LibHac.FsSystem; +using LibHac.Ncm; + +namespace LibHac.Fs.Shim +{ + public static class Content + { + public static Result MountContent(this FileSystemClient fs, U8Span mountName, U8Span path, ContentType type) + { + if (type == ContentType.Meta) + return ResultFs.InvalidArgument.Log(); + + return MountContent(fs, mountName, path, TitleId.Zero, type); + } + + public static Result MountContent(this FileSystemClient fs, U8Span mountName, TitleId programId, ContentType type) + { + Result rc = MountHelpers.CheckMountNameAcceptingReservedMountName(mountName); + if (rc.IsFailure()) return rc; + + FileSystemProxyType fspType = ConvertToFileSystemProxyType(type); + + IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + + rc = fsProxy.OpenFileSystemWithPatch(out IFileSystem fileSystem, programId, fspType); + if (rc.IsFailure()) return rc; + + return fs.Register(mountName, fileSystem); + } + + public static Result MountContent(this FileSystemClient fs, U8Span mountName, U8Span path, TitleId titleId, ContentType type) + { + Result rc = MountHelpers.CheckMountNameAcceptingReservedMountName(mountName); + if (rc.IsFailure()) return rc; + + FileSystemProxyType fspType = ConvertToFileSystemProxyType(type); + + return MountContentImpl(fs, mountName, path, titleId, fspType); + } + + private static Result MountContentImpl(FileSystemClient fs, U8Span mountName, U8Span path, TitleId titleId, FileSystemProxyType type) + { + FsPath.FromSpan(out FsPath fsPath, path); + + IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject(); + + Result rc = fsProxy.OpenFileSystemWithId(out IFileSystem fileSystem, ref fsPath, titleId, type); + if (rc.IsFailure()) return rc; + + return fs.Register(mountName, fileSystem); + } + + private static FileSystemProxyType ConvertToFileSystemProxyType(ContentType type) => type switch + { + ContentType.Meta => FileSystemProxyType.ContentMeta, + ContentType.Control => FileSystemProxyType.ContentControl, + ContentType.Manual => FileSystemProxyType.ContentManual, + ContentType.Data => FileSystemProxyType.ContentData, + _ => throw new ArgumentOutOfRangeException(nameof(type), type, null), + }; + } +} diff --git a/src/LibHac/FsService/FileSystemProxy.cs b/src/LibHac/FsService/FileSystemProxy.cs index ba3f747b..a5c958ed 100644 --- a/src/LibHac/FsService/FileSystemProxy.cs +++ b/src/LibHac/FsService/FileSystemProxy.cs @@ -38,12 +38,12 @@ namespace LibHac.FsService AutoCreateSaveData = true; } - public Result OpenFileSystemWithId(out IFileSystem fileSystem, ref FsPath path, TitleId titleId, FileSystemType type) + public Result OpenFileSystemWithId(out IFileSystem fileSystem, ref FsPath path, TitleId titleId, FileSystemProxyType type) { throw new NotImplementedException(); } - public Result OpenFileSystemWithPatch(out IFileSystem fileSystem, TitleId titleId, FileSystemType type) + public Result OpenFileSystemWithPatch(out IFileSystem fileSystem, TitleId titleId, FileSystemProxyType type) { throw new NotImplementedException(); } diff --git a/src/LibHac/FsService/IFileSystemProxy.cs b/src/LibHac/FsService/IFileSystemProxy.cs index 525b1f33..4a9b0b57 100644 --- a/src/LibHac/FsService/IFileSystemProxy.cs +++ b/src/LibHac/FsService/IFileSystemProxy.cs @@ -11,8 +11,8 @@ namespace LibHac.FsService { Result SetCurrentProcess(long processId); Result OpenDataFileSystemByCurrentProcess(out IFileSystem fileSystem); - Result OpenFileSystemWithPatch(out IFileSystem fileSystem, TitleId titleId, FileSystemType type); - Result OpenFileSystemWithId(out IFileSystem fileSystem, ref FsPath path, TitleId titleId, FileSystemType type); + Result OpenFileSystemWithPatch(out IFileSystem fileSystem, TitleId titleId, FileSystemProxyType type); + Result OpenFileSystemWithId(out IFileSystem fileSystem, ref FsPath path, TitleId titleId, FileSystemProxyType type); Result OpenDataFileSystemByProgramId(out IFileSystem fileSystem, TitleId titleId); Result OpenBisFileSystem(out IFileSystem fileSystem, ref FsPath rootPath, BisPartitionId partitionId); Result OpenBisStorage(out IStorage storage, BisPartitionId partitionId); diff --git a/src/LibHac/SwitchFs.cs b/src/LibHac/SwitchFs.cs index f39f369c..49f508b7 100644 --- a/src/LibHac/SwitchFs.cs +++ b/src/LibHac/SwitchFs.cs @@ -162,11 +162,11 @@ namespace LibHac switch (content.Type) { - case ContentType.Program: - case ContentType.Data: + case Ncm.ContentType.Program: + case Ncm.ContentType.Data: title.MainNca = contentNca; break; - case ContentType.Control: + case Ncm.ContentType.Control: title.ControlNca = contentNca; break; }