From 115d7989053299f16870f6a80330c862e95319af Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Fri, 20 Sep 2019 00:40:14 -0500 Subject: [PATCH] Add more methods to IFileSystemProxy --- src/LibHac/Fs/FsEnums.cs | 12 +++++++ src/LibHac/Fs/FsPath.cs | 4 +++ src/LibHac/FsService/IDeviceOperator.cs | 7 ++++ src/LibHac/FsService/IFileSystemProxy.cs | 41 +++++++++++++++++++++--- src/LibHac/Ncm/StorageId.cs | 6 +--- src/LibHac/Spl/AccessKey.cs | 20 ++++++++++++ 6 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 src/LibHac/FsService/IDeviceOperator.cs create mode 100644 src/LibHac/Spl/AccessKey.cs diff --git a/src/LibHac/Fs/FsEnums.cs b/src/LibHac/Fs/FsEnums.cs index f3613492..223f36fb 100644 --- a/src/LibHac/Fs/FsEnums.cs +++ b/src/LibHac/Fs/FsEnums.cs @@ -80,4 +80,16 @@ Thumbnail = 1, ExtensionInfo = 2 } + + public enum ImageDirectoryId + { + Nand = 0, + SdCard = 1 + } + + public enum CloudBackupWorkStorageId + { + Nand = 0, + SdCard = 1 + } } diff --git a/src/LibHac/Fs/FsPath.cs b/src/LibHac/Fs/FsPath.cs index 7db2b8f0..4f10eb67 100644 --- a/src/LibHac/Fs/FsPath.cs +++ b/src/LibHac/Fs/FsPath.cs @@ -1,9 +1,11 @@ using System; +using System.Diagnostics; using System.Runtime.InteropServices; using LibHac.Common; namespace LibHac.Fs { + [DebuggerDisplay("{ToString()}")] [StructLayout(LayoutKind.Explicit, Size = MaxLength + 1)] public struct FsPath { @@ -12,5 +14,7 @@ namespace LibHac.Fs [FieldOffset(0)] private byte _str; public Span Str => SpanHelpers.CreateSpan(ref _str, MaxLength + 1); + + public override string ToString() => StringUtils.Utf8ZToString(Str); } } diff --git a/src/LibHac/FsService/IDeviceOperator.cs b/src/LibHac/FsService/IDeviceOperator.cs new file mode 100644 index 00000000..943b71fe --- /dev/null +++ b/src/LibHac/FsService/IDeviceOperator.cs @@ -0,0 +1,7 @@ +namespace LibHac.FsService +{ + public interface IDeviceOperator + { + + } +} \ No newline at end of file diff --git a/src/LibHac/FsService/IFileSystemProxy.cs b/src/LibHac/FsService/IFileSystemProxy.cs index 146219ba..ffc4d3fb 100644 --- a/src/LibHac/FsService/IFileSystemProxy.cs +++ b/src/LibHac/FsService/IFileSystemProxy.cs @@ -2,6 +2,7 @@ using LibHac.Common; using LibHac.Fs; using LibHac.Ncm; +using LibHac.Spl; namespace LibHac.FsService { @@ -10,12 +11,12 @@ 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, U8Span path, TitleId titleId, FileSystemType type); + Result OpenFileSystemWithId(out IFileSystem fileSystem, ref FsPath path, TitleId titleId, FileSystemType type); Result OpenDataFileSystemByProgramId(out IFileSystem fileSystem, TitleId titleId); - Result OpenBisFileSystem(out IFileSystem fileSystem, U8Span rootPath, BisPartitionId partitionId); + Result OpenBisFileSystem(out IFileSystem fileSystem, ref FsPath rootPath, BisPartitionId partitionId); Result OpenBisStorage(out IStorage storage, BisPartitionId partitionId); Result InvalidateBisCache(); - Result OpenHostFileSystem(out IFileSystem fileSystem, U8Span subPath); + Result OpenHostFileSystem(out IFileSystem fileSystem, ref FsPath subPath); Result OpenSdCardFileSystem(out IFileSystem fileSystem); Result FormatSdCardFileSystem(); Result DeleteSaveDataFileSystem(ulong saveDataId); @@ -50,20 +51,52 @@ namespace LibHac.FsService Result WriteSaveDataFileSystemExtraDataBySaveDataAttribute(ref SaveDataAttribute2 attribute, SaveDataSpaceId spaceId, ReadOnlySpan extraDataBuffer, ReadOnlySpan maskBuffer); Result OpenSaveDataMetaFile(out IFile file, SaveDataSpaceId spaceId, ref SaveDataAttribute2 attribute, SaveMetaType type); + Result ListAccessibleSaveDataOwnerId(out int readCount, Span idBuffer, TitleId programId, int startIndex, int bufferIdCount); + Result OpenImageDirectoryFileSystem(out IFileSystem fileSystem, ImageDirectoryId dirId); Result OpenContentStorageFileSystem(out IFileSystem fileSystem, ContentStorageId storageId); + Result OpenCloudBackupWorkStorageFileSystem(out IFileSystem fileSystem, CloudBackupWorkStorageId storageId); Result OpenCustomStorageFileSystem(out IFileSystem fileSystem, CustomStorageId storageId); Result OpenDataStorageByCurrentProcess(out IStorage storage); Result OpenDataStorageByProgramId(out IStorage storage, TitleId programId); Result OpenDataStorageByDataId(out IStorage storage, TitleId dataId, StorageId storageId); + Result OpenPatchDataStorageByCurrentProcess(out IStorage storage); + Result OpenDataFileSystemWithProgramIndex(out IFileSystem fileSystem, byte programIndex); + Result OpenDataStorageWithProgramIndex(out IStorage storage, byte programIndex); + Result OpenDeviceOperator(out IDeviceOperator deviceOperator); + Result QuerySaveDataTotalSize(out long totalSize, long dataSize, long journalSize); + Result VerifySaveDataFileSystem(ulong saveDataId, Span readBuffer); + Result CorruptSaveDataFileSystem(ulong saveDataId); + Result CreatePaddingFile(long size); + Result DeleteAllPaddingFiles(); + Result GetRightsId(out RightsId rightsId, TitleId programId, StorageId storageId); + Result RegisterExternalKey(ref RightsId rightsId, ref AccessKey externalKey); + Result UnregisterAllExternalKey(); + Result GetRightsIdByPath(out RightsId rightsId, ref FsPath path); + Result GetRightsIdAndKeyGenerationByPath(out RightsId rightsId, out byte keyGeneration, ref FsPath path); + Result SetCurrentPosixTimeWithTimeDifference(long time, int difference); + Result GetFreeSpaceSizeForSaveData(out long freeSpaceSize, SaveDataSpaceId spaceId); + Result VerifySaveDataFileSystemBySaveDataSpaceId(SaveDataSpaceId spaceId, ulong saveDataId, Span readBuffer); + Result CorruptSaveDataFileSystemBySaveDataSpaceId(SaveDataSpaceId spaceId, ulong saveDataId); + Result QuerySaveDataInternalStorageTotalSize(out long size, SaveDataSpaceId spaceId, ulong saveDataId); + Result GetSaveDataCommitId(out long commitId, SaveDataSpaceId spaceId, ulong saveDataId); + Result UnregisterExternalKey(ref RightsId rightsId); Result SetSdCardEncryptionSeed(ReadOnlySpan seed); + Result SetSdCardAccessibility(bool isAccessible); + Result IsSdCardAccessible(out bool isAccessible); + + Result SetBisRootForHost(BisPartitionId partitionId, ref FsPath path); Result SetSaveDataSize(long saveDataSize, long saveDataJournalSize); - Result SetSaveDataRootPath(U8Span path); + Result SetSaveDataRootPath(ref FsPath path); Result DisableAutoSaveDataCreation(); Result SetGlobalAccessLogMode(int mode); Result GetGlobalAccessLogMode(out int mode); Result OutputAccessLogToSdCard(U8Span logString); Result RegisterUpdatePartition(); Result OpenRegisteredUpdatePartition(out IFileSystem fileSystem); + + Result GetProgramIndexForAccessLog(out int programIndex, out int programCount); + Result OverrideSaveDataTransferTokenSignVerificationKey(ReadOnlySpan key); + Result CorruptSaveDataFileSystemByOffset(SaveDataSpaceId spaceId, ulong saveDataId, long offset); } } \ No newline at end of file diff --git a/src/LibHac/Ncm/StorageId.cs b/src/LibHac/Ncm/StorageId.cs index a19d8493..1fd4339a 100644 --- a/src/LibHac/Ncm/StorageId.cs +++ b/src/LibHac/Ncm/StorageId.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace LibHac.Ncm +namespace LibHac.Ncm { public enum StorageId : byte { diff --git a/src/LibHac/Spl/AccessKey.cs b/src/LibHac/Spl/AccessKey.cs new file mode 100644 index 00000000..987a55b8 --- /dev/null +++ b/src/LibHac/Spl/AccessKey.cs @@ -0,0 +1,20 @@ +using System; +using System.Diagnostics; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using LibHac.Common; + +namespace LibHac.Spl +{ + [DebuggerDisplay("{ToString()}")] + [StructLayout(LayoutKind.Sequential, Size = 0x10)] + public struct AccessKey + { + private long _dummy1; + private long _dummy2; + + public Span Key => SpanHelpers.CreateSpan(ref Unsafe.As(ref _dummy1), 0x10); + + public override string ToString() => Key.ToHexString(); + } +}