From 3e64f9ef0322a02852640db82cbb5e0871d89209 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Mon, 7 Mar 2022 14:08:05 -0700 Subject: [PATCH] Skeleton NcaFileSystemDriver --- src/LibHac/FsSystem/CompressedStorage.cs | 6 +- src/LibHac/FsSystem/NcaFileSystemDriver.cs | 194 ++++++++++++++++++++- 2 files changed, 195 insertions(+), 5 deletions(-) diff --git a/src/LibHac/FsSystem/CompressedStorage.cs b/src/LibHac/FsSystem/CompressedStorage.cs index ec0b819b..e8e16bd8 100644 --- a/src/LibHac/FsSystem/CompressedStorage.cs +++ b/src/LibHac/FsSystem/CompressedStorage.cs @@ -1,4 +1,5 @@ -using System; +// ReSharper disable UnusedMember.Local NotAccessedField.Local +using System; using System.Runtime.CompilerServices; using LibHac.Diag; using LibHac.Fs; @@ -12,9 +13,6 @@ namespace LibHac.FsSystem; public class CompressedStorage : IStorage, IAsynchronousAccessSplitter { - public delegate Result DecompressorFunction(Span destination, ReadOnlySpan source); - public delegate DecompressorFunction GetDecompressorFunction(CompressionType type); - public class CompressedStorageCore : IDisposable { private long _blockSizeMax; diff --git a/src/LibHac/FsSystem/NcaFileSystemDriver.cs b/src/LibHac/FsSystem/NcaFileSystemDriver.cs index adda8dae..0f651f37 100644 --- a/src/LibHac/FsSystem/NcaFileSystemDriver.cs +++ b/src/LibHac/FsSystem/NcaFileSystemDriver.cs @@ -1,5 +1,10 @@ -using LibHac.Common.FixedArrays; +// ReSharper disable UnusedMember.Local +using System; +using LibHac.Common; +using LibHac.Common.FixedArrays; using LibHac.Crypto; +using LibHac.Fs; +using LibHac.FsSrv; namespace LibHac.FsSystem; @@ -60,4 +65,191 @@ public enum KeyType SaveDataDeviceUniqueMac = 0x62, SaveDataSeedUniqueMac = 0x63, SaveDataTransferMac = 0x64 +} + +public class NcaFileSystemDriver : IDisposable +{ + public struct StorageContext : IDisposable + { + public bool OpenRawStorage; + public SharedRef BodySubStorage; + public SharedRef CurrentSparseStorage; + public SharedRef SparseStorageMetaStorage; + public SharedRef OriginalSparseStorage; + // Todo: externalCurrentSparseStorage, externalOriginalSparseStorage + public SharedRef AesCtrExStorageMetaStorage; + public SharedRef AesCtrExStorageDataStorage; + public SharedRef AesCtrExStorage; + public SharedRef IndirectStorageMetaStorage; + public SharedRef IndirectStorage; + public SharedRef FsDataStorage; + public SharedRef CompressedStorageMetaStorage; + public SharedRef CompressedStorage; + + public void Dispose() + { + BodySubStorage.Destroy(); + CurrentSparseStorage.Destroy(); + SparseStorageMetaStorage.Destroy(); + OriginalSparseStorage.Destroy(); + AesCtrExStorageMetaStorage.Destroy(); + AesCtrExStorageDataStorage.Destroy(); + AesCtrExStorage.Destroy(); + IndirectStorageMetaStorage.Destroy(); + IndirectStorage.Destroy(); + FsDataStorage.Destroy(); + CompressedStorageMetaStorage.Destroy(); + CompressedStorage.Destroy(); + } + } + + private enum AlignmentStorageRequirement + { + CacheBlockSize = 0, + None = 1 + } + + public NcaFileSystemDriver(ref SharedRef ncaReader, MemoryResource allocator, + IBufferManager bufferManager, IHash256GeneratorFactorySelector hashGeneratorFactorySelector) + { + throw new NotImplementedException(); + } + + public NcaFileSystemDriver(ref SharedRef originalNcaReader, ref SharedRef currentNcaReader, + MemoryResource allocator, IBufferManager bufferManager, + IHash256GeneratorFactorySelector hashGeneratorFactorySelector) + { + throw new NotImplementedException(); + } + + public void Dispose() + { + throw new NotImplementedException(); + } + + private bool IsUsingHwAesCtrForSpeedEmulation(FileSystemServer fs) + { + throw new NotImplementedException(); + } + + private long GetFsOffset(NcaReader reader, int index) + { + return (long)reader.GetFsOffset(index); + } + + private long GetFsEndOffset(NcaReader reader, int index) + { + return (long)reader.GetFsEndOffset(index); + } + + public Result OpenStorage(ref SharedRef outStorage, + ref SharedRef outStorageAccessSplitter, out NcaFsHeaderReader outHeaderReader, + int fsIndex) + { + throw new NotImplementedException(); + } + + private Result OpenStorageImpl(ref SharedRef outStorage, out NcaFsHeaderReader outHeaderReader, + int fsIndex, ref StorageContext storageContext) + { + throw new NotImplementedException(); + } + + private Result OpenIndirectableStorageAsOriginal(ref SharedRef outStorage, + in NcaFsHeaderReader headerReader, ref StorageContext storageContext) + { + throw new NotImplementedException(); + } + + private Result CreateBodySubStorage(ref SharedRef outStorage, long offset, long size) + { + throw new NotImplementedException(); + } + + private Result CreateAesCtrStorage(ref SharedRef outStorage, ref SharedRef baseStorage, + long offset, in NcaAesCtrUpperIv upperIv, AlignmentStorageRequirement alignmentRequirement) + { + throw new NotImplementedException(); + } + + private Result CreateAesXtsStorage(ref SharedRef outStorage, ref SharedRef baseStorage, + long offset) + { + throw new NotImplementedException(); + } + + private Result CreateSparseStorageMetaStorage(ref SharedRef outStorage, + ref SharedRef baseStorage, long offset, in NcaAesCtrUpperIv upperIv, in NcaSparseInfo sparseInfo) + { + throw new NotImplementedException(); + } + + private Result CreateSparseStorageCore(ref SharedRef outStorage, ref SharedRef baseStorage, + long baseStorageSize, ref SharedRef sparseStorageMetaStorage, in NcaSparseInfo sparseInfo, + bool hasExternalInfo) + { + throw new NotImplementedException(); + } + + private Result CreateSparseStorage(ref SharedRef outStorage, out long outFsDataOffset, + ref SharedRef outSparseStorage, ref SharedRef outSparseStorageMetaStorage, int index, + in NcaAesCtrUpperIv upperIv, in NcaSparseInfo sparseInfo) + { + throw new NotImplementedException(); + } + + private Result CreateAesCtrExStorageMetaStorage(ref SharedRef outStorage, + ref SharedRef baseStorage, long offset, in NcaAesCtrUpperIv upperIv, in NcaPatchInfo patchInfo) + { + throw new NotImplementedException(); + } + + private Result CreateAesCtrExStorage(ref SharedRef outStorage, + ref SharedRef outAesCtrExStorage, ref SharedRef baseStorage, + ref SharedRef aesCtrExMetaStorage, long counterOffset, in NcaAesCtrUpperIv upperIv, + in NcaPatchInfo patchInfo) + { + throw new NotImplementedException(); + } + + private Result CreateIndirectStorageMetaStorage(ref SharedRef outStorage, + ref SharedRef baseStorage, in NcaPatchInfo patchInfo) + { + throw new NotImplementedException(); + } + + private Result CreateIndirectStorage(ref SharedRef outStorage, + ref SharedRef outIndirectStorage, ref SharedRef baseStorage, + ref SharedRef originalDataStorage, ref SharedRef indirectStorageMetaStorage, + in NcaPatchInfo patchInfo) + { + throw new NotImplementedException(); + } + + private Result CreateSha256Storage(ref SharedRef outStorage, ref SharedRef baseStorage, + in NcaFsHeader.HashData.HierarchicalSha256Data sha256Data) + { + throw new NotImplementedException(); + } + + private Result HierarchicalSha256Data(ref SharedRef outStorage, ref SharedRef baseStorage, + in NcaFsHeader.HashData.IntegrityMetaInfo metaInfo) + { + throw new NotImplementedException(); + } + + public static Result CreateCompressedStorage(ref SharedRef outStorage, + ref SharedRef outCompressedStorage, ref SharedRef outMetaStorage, + ref SharedRef baseStorage, in NcaCompressionInfo compressionInfo, + GetDecompressorFunction getDecompressor, MemoryResource allocator, IBufferManager bufferManager) + { + throw new NotImplementedException(); + } + + public Result CreateCompressedStorage(ref SharedRef outStorage, + ref SharedRef outCompressedStorage, ref SharedRef outMetaStorage, + ref SharedRef baseStorage, in NcaCompressionInfo compressionInfo) + { + throw new NotImplementedException(); + } } \ No newline at end of file