From 7e2dd220792523fb40a603219c751bf2888f04c2 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Wed, 18 Sep 2019 16:29:27 -0500 Subject: [PATCH] Add more methods to IFileSystemProxy --- src/LibHac/Fs/FsEnums.cs | 5 +- src/LibHac/Fs/SaveDataAttribute2.cs | 16 ----- src/LibHac/Fs/SaveDataStructs.cs | 70 +++++++++++++++++++++ src/LibHac/FsService/IFileSystemProxy.cs | 37 +++++++++-- src/LibHac/FsService/ISaveDataInfoReader.cs | 9 +++ 5 files changed, 115 insertions(+), 22 deletions(-) delete mode 100644 src/LibHac/Fs/SaveDataAttribute2.cs create mode 100644 src/LibHac/Fs/SaveDataStructs.cs create mode 100644 src/LibHac/FsService/ISaveDataInfoReader.cs diff --git a/src/LibHac/Fs/FsEnums.cs b/src/LibHac/Fs/FsEnums.cs index cb187dc8..f3613492 100644 --- a/src/LibHac/Fs/FsEnums.cs +++ b/src/LibHac/Fs/FsEnums.cs @@ -43,7 +43,7 @@ Writable = 2 } - public enum SaveDataSpaceId + public enum SaveDataSpaceId : byte { System = 0, User = 1, @@ -51,7 +51,8 @@ TemporaryStorage = 3, SdCache = 4, ProperSystem = 100, - Safe = 101 + Safe = 101, + BisAuto = 127 } public enum CustomStorageId diff --git a/src/LibHac/Fs/SaveDataAttribute2.cs b/src/LibHac/Fs/SaveDataAttribute2.cs deleted file mode 100644 index 0dd628a7..00000000 --- a/src/LibHac/Fs/SaveDataAttribute2.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Runtime.InteropServices; -using LibHac.Fs.Save; - -namespace LibHac.Fs -{ - [StructLayout(LayoutKind.Explicit, Size = 0x40)] - public struct SaveDataAttribute2 - { - [FieldOffset(0x00)] public ulong TitleId; - [FieldOffset(0x08)] public UserId UserId; - [FieldOffset(0x18)] public ulong SaveDataId; - [FieldOffset(0x20)] public SaveDataType Type; - [FieldOffset(0x21)] public byte Rank; - [FieldOffset(0x22)] public short Index; - } -} diff --git a/src/LibHac/Fs/SaveDataStructs.cs b/src/LibHac/Fs/SaveDataStructs.cs new file mode 100644 index 00000000..b4435b97 --- /dev/null +++ b/src/LibHac/Fs/SaveDataStructs.cs @@ -0,0 +1,70 @@ +using System; +using System.Runtime.InteropServices; +using LibHac.Common; +using LibHac.Fs.Save; +using LibHac.Ncm; + +namespace LibHac.Fs +{ + [StructLayout(LayoutKind.Explicit, Size = 0x40)] + public struct SaveDataAttribute2 + { + [FieldOffset(0x00)] public ulong TitleId; + [FieldOffset(0x08)] public UserId UserId; + [FieldOffset(0x18)] public ulong SaveDataId; + [FieldOffset(0x20)] public SaveDataType Type; + [FieldOffset(0x21)] public byte Rank; + [FieldOffset(0x22)] public short Index; + } + + [StructLayout(LayoutKind.Explicit, Size = 0x48)] + public struct SaveDataFilter + { + [FieldOffset(0x00)] public bool FilterByTitleId; + [FieldOffset(0x01)] public bool FilterBySaveDataType; + [FieldOffset(0x02)] public bool FilterByUserId; + [FieldOffset(0x03)] public bool FilterBySaveDataId; + [FieldOffset(0x04)] public bool FilterByIndex; + [FieldOffset(0x05)] public byte Rank; + + [FieldOffset(0x08)] public TitleId TitleID; + [FieldOffset(0x10)] public UserId UserId; + [FieldOffset(0x20)] public ulong SaveDataId; + [FieldOffset(0x28)] public SaveDataType SaveDataType; + [FieldOffset(0x2A)] public short Index; + } + + [StructLayout(LayoutKind.Explicit, Size = 0x50)] + public struct SaveDataFilterInternal + { + [FieldOffset(0x00)] public bool FilterBySaveDataSpaceId; + [FieldOffset(0x01)] public SaveDataSpaceId SpaceId; + + [FieldOffset(0x08)] public bool FilterByTitleId; + [FieldOffset(0x10)] public TitleId TitleID; + + [FieldOffset(0x18)] public bool FilterBySaveDataType; + [FieldOffset(0x19)] public SaveDataType SaveDataType; + + [FieldOffset(0x20)] public bool FilterByUserId; + [FieldOffset(0x28)] public UserId UserId; + + [FieldOffset(0x38)] public bool FilterBySaveDataId; + [FieldOffset(0x40)] public ulong SaveDataId; + + [FieldOffset(0x48)] public bool FilterByIndex; + [FieldOffset(0x4A)] public short Index; + + [FieldOffset(0x4C)] public int Rank; + } + + [StructLayout(LayoutKind.Explicit, Size = HashLength)] + public struct HashSalt + { + private const int HashLength = 0x20; + + [FieldOffset(0x00)] private byte _hashStart; + + public Span Hash => SpanHelpers.CreateSpan(ref _hashStart, HashLength); + } +} diff --git a/src/LibHac/FsService/IFileSystemProxy.cs b/src/LibHac/FsService/IFileSystemProxy.cs index 61b7a1b7..0498556d 100644 --- a/src/LibHac/FsService/IFileSystemProxy.cs +++ b/src/LibHac/FsService/IFileSystemProxy.cs @@ -18,19 +18,48 @@ namespace LibHac.FsService Result OpenHostFileSystem(out IFileSystem fileSystem, U8Span subPath); Result OpenSdCardFileSystem(out IFileSystem fileSystem); Result FormatSdCardFileSystem(); - Result DeleteSaveDataFileSystem(long saveDataId); + Result DeleteSaveDataFileSystem(ulong saveDataId); Result CreateSaveDataFileSystem(ref SaveDataAttribute2 attribute, ref SaveDataCreateInfo createInfo, ref SaveMetaCreateInfo metaCreateInfo); Result CreateSaveDataFileSystemBySystemSaveDataId(ref SaveDataAttribute2 attribute, ref SaveDataCreateInfo createInfo); Result RegisterSaveDataFileSystemAtomicDeletion(ReadOnlySpan saveDataIds); - + Result DeleteSaveDataFileSystemBySaveDataSpaceId(SaveDataSpaceId spaceId, ulong saveDataId); + Result FormatSdCardDryRun(); + Result IsExFatSupported(out bool isSupported); + Result DeleteSaveDataFileSystemBySaveDataAttribute(SaveDataSpaceId spaceId, ref SaveDataAttribute2 attribute); Result OpenGameCardStorage(out IStorage storage, GameCardHandle handle, GameCardPartitionRaw partitionId); - Result OpenSaveDataFileSystem(out IFileSystem fileSystem, SaveDataSpaceId spaceId, SaveDataAttribute attribute); - Result OpenSaveDataFileSystemBySystemSaveDataId(out IFileSystem fileSystem, SaveDataSpaceId spaceId, SaveDataAttribute attribute); + Result OpenGameCardFileSystem(out IFileSystem fileSystem, GameCardHandle handle, GameCardPartition partitionId); + Result ExtendSaveDataFileSystem(SaveDataSpaceId spaceId, ulong saveDataId, long dataSize, long journalSize); + Result DeleteCacheStorage(short index); + Result GetCacheStorageSize(out long dataSize, out long journalSize, short index); + Result CreateSaveDataFileSystemWithHashSalt(ref SaveDataAttribute2 attribute, ref SaveDataCreateInfo createInfo, ref SaveMetaCreateInfo metaCreateInfo, ref HashSalt hashSalt); + Result OpenSaveDataFileSystem(out IFileSystem fileSystem, SaveDataSpaceId spaceId, ref SaveDataAttribute attribute); + Result OpenSaveDataFileSystemBySystemSaveDataId(out IFileSystem fileSystem, SaveDataSpaceId spaceId, ref SaveDataAttribute attribute); + Result OpenReadOnlySaveDataFileSystem(out IFileSystem fileSystem, SaveDataSpaceId spaceId, ref SaveDataAttribute attribute); + Result ReadSaveDataFileSystemExtraDataBySaveDataSpaceId(Span extraDataBuffer, SaveDataSpaceId spaceId, ulong saveDataId); + Result ReadSaveDataFileSystemExtraData(Span extraDataBuffer, ulong saveDataId); + Result WriteSaveDataFileSystemExtraData(ulong saveDataId, SaveDataSpaceId spaceId, ReadOnlySpan extraDataBuffer); + Result OpenSaveDataInfoReader(out ISaveDataInfoReader infoReader); + Result OpenSaveDataInfoReaderBySaveDataSpaceId(out ISaveDataInfoReader infoReader, SaveDataSpaceId spaceId); + Result OpenSaveDataInfoReaderOnlyCacheStorage(out ISaveDataInfoReader infoReader); + Result OpenSaveDataInternalStorageFileSystem(out IFileSystem fileSystem, SaveDataSpaceId spaceId, ulong saveDataId); + Result UpdateSaveDataMacForDebug(SaveDataSpaceId spaceId, ulong saveDataId); + Result WriteSaveDataFileSystemExtraDataWithMask(ulong saveDataId, SaveDataSpaceId spaceId, ReadOnlySpan extraDataBuffer, ReadOnlySpan maskBuffer); + Result FindSaveDataWithFilter(out long count, Span saveDataInfoBuffer, SaveDataSpaceId spaceId, ref SaveDataFilter filter); + Result OpenSaveDataInfoReaderWithFilter(out ISaveDataInfoReader infoReader, SaveDataSpaceId spaceId, ref SaveDataFilter filter); + Result ReadSaveDataFileSystemExtraDataBySaveDataAttribute(Span extraDataBuffer, SaveDataSpaceId spaceId, ref SaveDataAttribute2 attribute); + Result WriteSaveDataFileSystemExtraDataBySaveDataAttribute(ref SaveDataAttribute2 attribute, SaveDataSpaceId spaceId, ReadOnlySpan extraDataBuffer, ReadOnlySpan maskBuffer); + Result OpenSaveDataMetaFile(out IFile file, SaveDataSpaceId spaceId, ref SaveDataAttribute2 attribute, SaveMetaType type); + Result OpenContentStorageFileSystem(out IFileSystem fileSystem, ContentStorageId storageId); Result OpenCustomStorageFileSystem(out IFileSystem fileSystem, CustomStorageId storageId); Result SetSdCardEncryptionSeed(ReadOnlySpan seed); Result SetSaveDataSize(long saveDataSize, long saveDataJournalSize); Result SetSaveDataRootPath(U8Span path); Result DisableAutoSaveDataCreation(); + Result SetGlobalAccessLogMode(int mode); + Result GetGlobalAccessLogMode(out int mode); + Result OutputAccessLogToSdCard(U8Span logString); + Result RegisterUpdatePartition(); + Result OpenRegisteredUpdatePartition(out IFileSystem fileSystem); } } \ No newline at end of file diff --git a/src/LibHac/FsService/ISaveDataInfoReader.cs b/src/LibHac/FsService/ISaveDataInfoReader.cs new file mode 100644 index 00000000..d0ece142 --- /dev/null +++ b/src/LibHac/FsService/ISaveDataInfoReader.cs @@ -0,0 +1,9 @@ +using System; + +namespace LibHac.FsService +{ + public interface ISaveDataInfoReader + { + Result ReadSaveDataInfo(out long readCount, Span saveDataInfoBuffer); + } +} \ No newline at end of file