Add StorageOnNcaCreator

This commit is contained in:
Alex Barney 2024-03-17 09:32:59 -07:00
parent b88d283fbc
commit ea49386b48
7 changed files with 466 additions and 62 deletions

View file

@ -0,0 +1,7 @@
namespace LibHac.Fs;
public enum ContentAttributes : byte
{
None = 0,
All = 0xF
}

View file

@ -1,14 +1,26 @@
using LibHac.Common; using LibHac.Common;
using LibHac.Fs; using LibHac.Fs;
using LibHac.Fs.Fsa; using LibHac.FsSystem;
using LibHac.Tools.FsSystem.NcaUtils;
namespace LibHac.FsSrv.FsCreator; namespace LibHac.FsSrv.FsCreator;
public interface IStorageOnNcaCreator public interface IStorageOnNcaCreator
{ {
Result Create(ref SharedRef<IStorage> outStorage, out NcaFsHeader fsHeader, Nca nca, int fsIndex, bool isCodeFs); Result Create(ref SharedRef<IStorage> outStorage, out LibHac.Tools.FsSystem.NcaUtils.NcaFsHeader fsHeader, LibHac.Tools.FsSystem.NcaUtils.Nca nca, int fsIndex, bool isCodeFs);
Result CreateWithPatch(ref SharedRef<IStorage> outStorage, out NcaFsHeader fsHeader, Nca baseNca, Nca patchNca, int fsIndex, bool isCodeFs); Result OpenNca(out LibHac.Tools.FsSystem.NcaUtils.Nca nca, IStorage ncaStorage);
Result OpenNca(out Nca nca, IStorage ncaStorage); }
Result VerifyAcidSignature(IFileSystem codeFileSystem, Nca nca);
public interface IStorageOnNcaCreator17
{
Result Create(ref SharedRef<IStorage> outStorage,
ref SharedRef<IAsynchronousAccessSplitter> outStorageAccessSplitter, out NcaFsHeaderReader17 outHeaderReader,
ref readonly SharedRef<NcaReader17> ncaReader, int fsIndex);
Result CreateWithPatch(ref SharedRef<IStorage> outStorage,
ref SharedRef<IAsynchronousAccessSplitter> outStorageAccessSplitter, out NcaFsHeaderReader17 outHeaderReader,
ref readonly SharedRef<NcaReader17> originalNcaReader, ref readonly SharedRef<NcaReader17> currentNcaReader,
int fsIndex);
Result CreateNcaReader(ref SharedRef<NcaReader17> outReader, ref readonly SharedRef<IStorage> baseStorage,
ContentAttributes contentAttributes);
} }

View file

@ -0,0 +1,57 @@
using System;
using LibHac.Common;
using LibHac.Fs;
namespace LibHac.FsSrv.FsCreator;
/// <summary>
/// Converts internal RomFS <see cref="Result"/>s returned by an <see cref="IStorage"/> to external <see cref="Result"/>s.
/// </summary>
/// <remarks>Based on nnSdk 17.5.0 (FS 17.0.0)</remarks>
public class RomResultConvertStorage : IStorage
{
private SharedRef<IStorage> _baseStorage;
public RomResultConvertStorage(ref readonly SharedRef<IStorage> baseStorage)
{
_baseStorage = SharedRef<IStorage>.CreateCopy(in baseStorage);
}
public override void Dispose()
{
_baseStorage.Destroy();
base.Dispose();
}
public override Result Read(long offset, Span<byte> destination)
{
return RomResultConverter.ConvertRomResult(_baseStorage.Get.Read(offset, destination)).Ret();
}
public override Result Write(long offset, ReadOnlySpan<byte> source)
{
return RomResultConverter.ConvertRomResult(_baseStorage.Get.Write(offset, source)).Ret();
}
public override Result Flush()
{
return RomResultConverter.ConvertRomResult(_baseStorage.Get.Flush()).Ret();
}
public override Result SetSize(long size)
{
return RomResultConverter.ConvertRomResult(_baseStorage.Get.SetSize(size)).Ret();
}
public override Result GetSize(out long size)
{
return RomResultConverter.ConvertRomResult(_baseStorage.Get.GetSize(out size)).Ret();
}
public override Result OperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
ReadOnlySpan<byte> inBuffer)
{
return RomResultConverter
.ConvertRomResult(_baseStorage.Get.OperateRange(outBuffer, operationId, offset, size, inBuffer)).Ret();
}
}

View file

@ -0,0 +1,183 @@
using LibHac.Diag;
using LibHac.Fs;
namespace LibHac.FsSrv.FsCreator;
/// <summary>
/// Converts internal RomFS <see cref="Result"/> values to external <see cref="Result"/>s.
/// </summary>
/// <remarks>Based on nnSdk 17.5.0 (FS 17.0.0)</remarks>
public static class RomResultConverter
{
private static Result ConvertCorruptedResult(Result result)
{
if (ResultFs.NcaCorrupted.Includes(result))
{
if (ResultFs.InvalidNcaFileSystemType.Includes(result))
return ResultFs.InvalidRomNcaFileSystemType.LogConverted(result);
if (ResultFs.InvalidNcaSignature.Includes(result))
return ResultFs.InvalidRomNcaSignature.LogConverted(result);
if (ResultFs.NcaHeaderSignature1VerificationFailed.Includes(result))
return ResultFs.RomNcaHeaderSignature1VerificationFailed.LogConverted(result);
if (ResultFs.NcaFsHeaderHashVerificationFailed.Includes(result))
return ResultFs.RomNcaFsHeaderHashVerificationFailed.LogConverted(result);
if (ResultFs.InvalidNcaKeyIndex.Includes(result))
return ResultFs.InvalidRomNcaKeyIndex.LogConverted(result);
if (ResultFs.InvalidNcaFsHeaderHashType.Includes(result))
return ResultFs.InvalidRomNcaFsHeaderHashType.LogConverted(result);
if (ResultFs.InvalidNcaFsHeaderEncryptionType.Includes(result))
return ResultFs.InvalidRomNcaFsHeaderEncryptionType.LogConverted(result);
if (ResultFs.InvalidNcaPatchInfoIndirectSize.Includes(result))
return ResultFs.InvalidRomNcaPatchInfoIndirectSize.LogConverted(result);
if (ResultFs.InvalidNcaPatchInfoAesCtrExSize.Includes(result))
return ResultFs.InvalidRomNcaPatchInfoAesCtrExSize.LogConverted(result);
if (ResultFs.InvalidNcaPatchInfoAesCtrExOffset.Includes(result))
return ResultFs.InvalidRomNcaPatchInfoAesCtrExOffset.LogConverted(result);
if (ResultFs.InvalidNcaId.Includes(result))
return ResultFs.InvalidRomNcaId.LogConverted(result);
if (ResultFs.InvalidNcaHeader.Includes(result))
return ResultFs.InvalidRomNcaHeader.LogConverted(result);
if (ResultFs.InvalidNcaFsHeader.Includes(result))
return ResultFs.InvalidRomNcaFsHeader.LogConverted(result);
if (ResultFs.InvalidNcaPatchInfoIndirectOffset.Includes(result))
return ResultFs.InvalidRomNcaPatchInfoIndirectOffset.LogConverted(result);
if (ResultFs.InvalidHierarchicalSha256BlockSize.Includes(result))
return ResultFs.InvalidRomHierarchicalSha256BlockSize.LogConverted(result);
if (ResultFs.InvalidHierarchicalSha256LayerCount.Includes(result))
return ResultFs.InvalidRomHierarchicalSha256LayerCount.LogConverted(result);
if (ResultFs.HierarchicalSha256BaseStorageTooLarge.Includes(result))
return ResultFs.RomHierarchicalSha256BaseStorageTooLarge.LogConverted(result);
if (ResultFs.HierarchicalSha256HashVerificationFailed.Includes(result))
return ResultFs.RomHierarchicalSha256HashVerificationFailed.LogConverted(result);
if (ResultFs.InvalidHierarchicalIntegrityVerificationLayerCount.Includes(result))
return ResultFs.InvalidRomHierarchicalIntegrityVerificationLayerCount.LogConverted(result);
if (ResultFs.NcaIndirectStorageOutOfRange.Includes(result))
return ResultFs.RomNcaIndirectStorageOutOfRange.LogConverted(result);
if (ResultFs.NcaInvalidCompressionInfo.Includes(result))
return ResultFs.RomNcaInvalidCompressionInfo.LogConverted(result);
Assert.SdkAssert(ResultFs.InvalidNcaHeader1SignatureKeyGeneration.Includes(result), $"Unknown Result 0x{result.Value:X8}");
return result.Rethrow();
}
if (ResultFs.IntegrityVerificationStorageCorrupted.Includes(result))
{
if (ResultFs.IncorrectIntegrityVerificationMagicCode.Includes(result))
return ResultFs.IncorrectRomIntegrityVerificationMagicCode.LogConverted(result);
if (ResultFs.InvalidZeroHash.Includes(result))
return ResultFs.InvalidRomZeroSignature.LogConverted(result);
if (ResultFs.NonRealDataVerificationFailed.Includes(result))
return ResultFs.RomNonRealDataVerificationFailed.LogConverted(result);
if (ResultFs.ClearedRealDataVerificationFailed.Includes(result))
return ResultFs.ClearedRomRealDataVerificationFailed.LogConverted(result);
if (ResultFs.UnclearedRealDataVerificationFailed.Includes(result))
return ResultFs.UnclearedRomRealDataVerificationFailed.LogConverted(result);
Assert.SdkAssert(false, $"Unknown Result 0x{result.Value:X8}");
return result.Rethrow();
}
if (ResultFs.PartitionFileSystemCorrupted.Includes(result))
{
if (ResultFs.InvalidSha256PartitionHashTarget.Includes(result))
return ResultFs.InvalidRomSha256PartitionHashTarget.LogConverted(result);
if (ResultFs.Sha256PartitionHashVerificationFailed.Includes(result))
return ResultFs.RomSha256PartitionHashVerificationFailed.LogConverted(result);
if (ResultFs.PartitionSignatureVerificationFailed.Includes(result))
return ResultFs.RomPartitionSignatureVerificationFailed.LogConverted(result);
if (ResultFs.Sha256PartitionSignatureVerificationFailed.Includes(result))
return ResultFs.RomSha256PartitionSignatureVerificationFailed.LogConverted(result);
if (ResultFs.InvalidPartitionEntryOffset.Includes(result))
return ResultFs.InvalidRomPartitionEntryOffset.LogConverted(result);
if (ResultFs.InvalidSha256PartitionMetaDataSize.Includes(result))
return ResultFs.InvalidRomSha256PartitionMetaDataSize.LogConverted(result);
Assert.SdkAssert(false, $"Unknown Result 0x{result.Value:X8}");
return result.Rethrow();
}
if (ResultFs.HostFileSystemCorrupted.Includes(result))
{
if (ResultFs.HostEntryCorrupted.Includes(result))
return ResultFs.RomHostEntryCorrupted.LogConverted(result);
if (ResultFs.HostFileDataCorrupted.Includes(result))
return ResultFs.RomHostFileDataCorrupted.LogConverted(result);
if (ResultFs.HostFileCorrupted.Includes(result))
return ResultFs.RomHostFileCorrupted.LogConverted(result);
if (ResultFs.InvalidHostHandle.Includes(result))
return ResultFs.InvalidRomHostHandle.LogConverted(result);
Assert.SdkAssert(false, $"Unknown Result 0x{result.Value:X8}");
return result.Rethrow();
}
if (result.IsSuccess())
return Result.Success;
return result.Miss();
}
public static Result ConvertRomResult(Result result)
{
if (result.IsSuccess())
return Result.Success;
if (ResultFs.UnsupportedVersion.Includes(result))
return ResultFs.UnsupportedRomVersion.LogConverted(result);
if (ResultFs.NcaCorrupted.Includes(result) ||
ResultFs.IntegrityVerificationStorageCorrupted.Includes(result) ||
ResultFs.BuiltInStorageCorrupted.Includes(result) ||
ResultFs.PartitionFileSystemCorrupted.Includes(result) ||
ResultFs.HostFileSystemCorrupted.Includes(result))
{
return ConvertCorruptedResult(result);
}
if (ResultFs.FatFileSystemCorrupted.Includes(result))
return result.Miss();
if (ResultFs.NotFound.Includes(result))
return ResultFs.PathNotFound.LogConverted(result);
if (ResultFs.FileNotFound.Includes(result) ||
ResultFs.IncompatiblePath.Includes(result))
{
return ResultFs.PathNotFound.LogConverted(result);
}
return result;
}
}

View file

@ -0,0 +1,84 @@
using LibHac.Common;
using LibHac.Fs;
using LibHac.FsSystem;
namespace LibHac.FsSrv.FsCreator;
/// <summary>
/// Opens the partitions in NCAs as <see cref="IStorage"/>s.
/// </summary>
/// <remarks>Based on nnSdk 17.5.0 (FS 17.0.0)</remarks>
public class StorageOnNcaCreator17 : IStorageOnNcaCreator17
{
private MemoryResource _memoryResource;
private NcaCompressionConfiguration _compressionConfig;
private IBufferManager _bufferManager;
private NcaReaderInitializer _ncaReaderInitializer;
private IHash256GeneratorFactorySelector _hashGeneratorFactorySelector;
public StorageOnNcaCreator17(MemoryResource memoryResource, IBufferManager bufferManager,
NcaReaderInitializer ncaReaderInitializer, in NcaCompressionConfiguration compressionConfig,
IHash256GeneratorFactorySelector hashGeneratorFactorySelector)
{
_memoryResource = memoryResource;
_compressionConfig = compressionConfig;
_bufferManager = bufferManager;
_ncaReaderInitializer = ncaReaderInitializer;
_hashGeneratorFactorySelector = hashGeneratorFactorySelector;
}
public Result Create(ref SharedRef<IStorage> outStorage,
ref SharedRef<IAsynchronousAccessSplitter> outStorageAccessSplitter, out NcaFsHeaderReader17 outHeaderReader,
ref readonly SharedRef<NcaReader17> ncaReader, int fsIndex)
{
var ncaFsDriver = new NcaFileSystemDriver(in ncaReader, _memoryResource, _bufferManager, _hashGeneratorFactorySelector);
using var storage = new SharedRef<IStorage>();
using var storageAccessSplitter = new SharedRef<IAsynchronousAccessSplitter>();
Result res = RomResultConverter.ConvertRomResult(ncaFsDriver.OpenStorage(ref storage.Ref,
ref storageAccessSplitter.Ref, out outHeaderReader, fsIndex));
if (res.IsFailure()) return res.Miss();
using var resultConvertStorage = new SharedRef<RomResultConvertStorage>(new RomResultConvertStorage(in storage));
outStorage.SetByMove(ref resultConvertStorage.Ref);
outStorageAccessSplitter.SetByMove(ref storageAccessSplitter.Ref);
return Result.Success;
}
public Result CreateWithPatch(ref SharedRef<IStorage> outStorage,
ref SharedRef<IAsynchronousAccessSplitter> outStorageAccessSplitter, out NcaFsHeaderReader17 outHeaderReader,
ref readonly SharedRef<NcaReader17> originalNcaReader, ref readonly SharedRef<NcaReader17> currentNcaReader,
int fsIndex)
{
var ncaFsDriver = new NcaFileSystemDriver(in originalNcaReader, in currentNcaReader, _memoryResource,
_bufferManager, _hashGeneratorFactorySelector);
using var storage = new SharedRef<IStorage>();
using var storageAccessSplitter = new SharedRef<IAsynchronousAccessSplitter>();
Result res = RomResultConverter.ConvertRomResult(ncaFsDriver.OpenStorage(ref storage.Ref,
ref storageAccessSplitter.Ref, out outHeaderReader, fsIndex));
if (res.IsFailure()) return res.Miss();
using var resultConvertStorage = new SharedRef<RomResultConvertStorage>(new RomResultConvertStorage(in storage));
outStorage.SetByMove(ref resultConvertStorage.Ref);
outStorageAccessSplitter.SetByMove(ref storageAccessSplitter.Ref);
return Result.Success;
}
public Result CreateNcaReader(ref SharedRef<NcaReader17> outReader, ref readonly SharedRef<IStorage> baseStorage,
ContentAttributes contentAttributes)
{
using var ncaReader = new SharedRef<NcaReader17>();
Result res = RomResultConverter.ConvertRomResult(_ncaReaderInitializer(ref ncaReader.Ref, in baseStorage,
in _compressionConfig, _hashGeneratorFactorySelector, contentAttributes));
if (res.IsFailure()) return res.Miss();
outReader.SetByMove(ref ncaReader.Ref);
return Result.Success;
}
}

View file

@ -3,6 +3,7 @@ using System;
using LibHac.Common; using LibHac.Common;
using LibHac.Common.FixedArrays; using LibHac.Common.FixedArrays;
using LibHac.Crypto; using LibHac.Crypto;
using LibHac.Diag;
using LibHac.Fs; using LibHac.Fs;
using LibHac.FsSrv; using LibHac.FsSrv;
@ -85,6 +86,75 @@ public enum KeyType
SaveDataTransferMac = NcaCryptoConfiguration.KeyAreaEncryptionKeyCount + 5 SaveDataTransferMac = NcaCryptoConfiguration.KeyAreaEncryptionKeyCount + 5
} }
file static class Anonymous
{
public static long GetFsOffset(NcaReader17 reader, int index)
{
return (long)reader.GetFsOffset(index);
}
public static long GetFsEndOffset(NcaReader17 reader, int index)
{
return (long)reader.GetFsEndOffset(index);
}
}
file class SharedNcaBodyStorage : IStorage
{
private SharedRef<IStorage> _storage;
private SharedRef<NcaReader17> _ncaReader;
public SharedNcaBodyStorage(in SharedRef<IStorage> baseStorage, in SharedRef<NcaReader17> ncaReader)
{
_storage = SharedRef<IStorage>.CreateCopy(in baseStorage);
_ncaReader = SharedRef<NcaReader17>.CreateCopy(in ncaReader);
}
public override void Dispose()
{
_storage.Destroy();
_ncaReader.Destroy();
base.Dispose();
}
public override Result Read(long offset, Span<byte> destination)
{
Assert.SdkRequiresNotNull(in _storage);
return _storage.Get.Read(offset, destination).Ret();
}
public override Result Write(long offset, ReadOnlySpan<byte> source)
{
Assert.SdkRequiresNotNull(in _storage);
return _storage.Get.Write(offset, source).Ret();
}
public override Result Flush()
{
Assert.SdkRequiresNotNull(in _storage);
return _storage.Get.Flush().Ret();
}
public override Result SetSize(long size)
{
Assert.SdkRequiresNotNull(in _storage);
return _storage.Get.SetSize(size).Ret();
}
public override Result GetSize(out long size)
{
Assert.SdkRequiresNotNull(in _storage);
return _storage.Get.GetSize(out size).Ret();
}
public override Result OperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
ReadOnlySpan<byte> inBuffer)
{
Assert.SdkRequiresNotNull(in _storage);
return _storage.Get.OperateRange(outBuffer, operationId, offset, size, inBuffer).Ret();
}
}
public class NcaFileSystemDriver : IDisposable public class NcaFileSystemDriver : IDisposable
{ {
[NonCopyableDisposable] [NonCopyableDisposable]
@ -132,14 +202,14 @@ public class NcaFileSystemDriver : IDisposable
None = 1 None = 1
} }
public NcaFileSystemDriver(ref SharedRef<NcaReader> ncaReader, MemoryResource allocator, public NcaFileSystemDriver(ref readonly SharedRef<NcaReader17> ncaReader, MemoryResource allocator,
IBufferManager bufferManager, IHash256GeneratorFactorySelector hashGeneratorFactorySelector) IBufferManager bufferManager, IHash256GeneratorFactorySelector hashGeneratorFactorySelector)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public NcaFileSystemDriver(ref SharedRef<NcaReader> originalNcaReader, ref SharedRef<NcaReader> currentNcaReader, public NcaFileSystemDriver(ref readonly SharedRef<NcaReader17> originalNcaReader,
MemoryResource allocator, IBufferManager bufferManager, ref readonly SharedRef<NcaReader17> currentNcaReader, MemoryResource allocator, IBufferManager bufferManager,
IHash256GeneratorFactorySelector hashGeneratorFactorySelector) IHash256GeneratorFactorySelector hashGeneratorFactorySelector)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@ -150,36 +220,21 @@ public class NcaFileSystemDriver : IDisposable
throw new NotImplementedException(); 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<IStorage> outStorage, public Result OpenStorage(ref SharedRef<IStorage> outStorage,
ref SharedRef<IAsynchronousAccessSplitter> outStorageAccessSplitter, out NcaFsHeaderReader outHeaderReader, ref SharedRef<IAsynchronousAccessSplitter> outStorageAccessSplitter, out NcaFsHeaderReader17 outHeaderReader,
int fsIndex) int fsIndex)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private Result OpenStorageImpl(ref SharedRef<IStorage> outStorage, out NcaFsHeaderReader outHeaderReader, private Result OpenStorageImpl(ref SharedRef<IStorage> outStorage, out NcaFsHeaderReader17 outHeaderReader,
int fsIndex, ref StorageContext storageContext) int fsIndex, ref StorageContext storageContext)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private Result OpenIndirectableStorageAsOriginal(ref SharedRef<IStorage> outStorage, private Result OpenIndirectableStorageAsOriginal(ref SharedRef<IStorage> outStorage,
in NcaFsHeaderReader headerReader, ref StorageContext storageContext) in NcaFsHeaderReader17 headerReader, ref StorageContext storageContext)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -189,7 +244,7 @@ public class NcaFileSystemDriver : IDisposable
throw new NotImplementedException(); throw new NotImplementedException();
} }
private Result CreateAesCtrStorage(ref SharedRef<IStorage> outStorage, ref SharedRef<IStorage> baseStorage, private Result CreateAesCtrStorage(ref SharedRef<IStorage> outStorage, ref readonly SharedRef<IStorage> baseStorage,
long offset, in NcaAesCtrUpperIv upperIv, AlignmentStorageRequirement alignmentRequirement) long offset, in NcaAesCtrUpperIv upperIv, AlignmentStorageRequirement alignmentRequirement)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@ -202,22 +257,23 @@ public class NcaFileSystemDriver : IDisposable
} }
private Result CreateSparseStorageMetaStorage(ref SharedRef<IStorage> outStorage, private Result CreateSparseStorageMetaStorage(ref SharedRef<IStorage> outStorage,
ref SharedRef<IStorage> baseStorage, long offset, in NcaAesCtrUpperIv upperIv, in NcaSparseInfo sparseInfo) ref readonly SharedRef<IStorage> baseStorage, long offset, in NcaAesCtrUpperIv upperIv,
in NcaSparseInfo sparseInfo)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private Result CreateSparseStorageMetaStorageWithVerification(ref SharedRef<IStorage> outStorage, private Result CreateSparseStorageMetaStorageWithVerification(ref SharedRef<IStorage> outStorage,
ref SharedRef<IStorage> outLayerInfoStorage, ref SharedRef<IStorage> baseStorage, long offset, ref SharedRef<IStorage> outLayerInfoStorage, ref readonly SharedRef<IStorage> baseStorage, long offset,
in NcaAesCtrUpperIv upperIv, in NcaSparseInfo sparseInfo, in NcaMetaDataHashDataInfo metaDataHashDataInfo, NcaFsHeader.EncryptionType encryptionType, in NcaAesCtrUpperIv upperIv, in NcaSparseInfo sparseInfo,
IHash256GeneratorFactory hashGeneratorFactory) in NcaMetaDataHashDataInfo metaDataHashDataInfo, IHash256GeneratorFactory hashGeneratorFactory)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private Result CreateSparseStorageCore(ref SharedRef<SparseStorage> outStorage, ref SharedRef<IStorage> baseStorage, private Result CreateSparseStorageCore(ref SharedRef<SparseStorage> outStorage,
long baseStorageSize, ref SharedRef<IStorage> sparseStorageMetaStorage, in NcaSparseInfo sparseInfo, ref readonly SharedRef<IStorage> baseStorage, long baseStorageSize,
bool hasExternalInfo) ref readonly SharedRef<IStorage> sparseStorageMetaStorage, in NcaSparseInfo sparseInfo, bool hasExternalInfo)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -231,8 +287,8 @@ public class NcaFileSystemDriver : IDisposable
private Result CreateSparseStorageWithVerification(ref SharedRef<IStorage> outStorage, out long outFsDataOffset, private Result CreateSparseStorageWithVerification(ref SharedRef<IStorage> outStorage, out long outFsDataOffset,
out SharedRef<SparseStorage> outSparseStorage, ref SharedRef<IStorage> outSparseStorageMetaStorage, out SharedRef<SparseStorage> outSparseStorage, ref SharedRef<IStorage> outSparseStorageMetaStorage,
ref SharedRef<IStorage> outLayerInfoStorage, int index, in NcaAesCtrUpperIv upperIv, ref SharedRef<IStorage> outLayerInfoStorage, int index, NcaFsHeader.EncryptionType encryptionType,
in NcaSparseInfo sparseInfo, in NcaMetaDataHashDataInfo metaDataHashDataInfo, in NcaAesCtrUpperIv upperIv, in NcaSparseInfo sparseInfo, in NcaMetaDataHashDataInfo metaDataHashDataInfo,
NcaFsHeader.MetaDataHashType metaDataHashType) NcaFsHeader.MetaDataHashType metaDataHashType)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@ -240,86 +296,87 @@ public class NcaFileSystemDriver : IDisposable
private Result CreatePatchMetaStorage(ref SharedRef<IStorage> outAesCtrExMetaStorage, private Result CreatePatchMetaStorage(ref SharedRef<IStorage> outAesCtrExMetaStorage,
ref SharedRef<IStorage> outIndirectMetaStorage, ref SharedRef<IStorage> outLayerInfoStorage, ref SharedRef<IStorage> outIndirectMetaStorage, ref SharedRef<IStorage> outLayerInfoStorage,
ref SharedRef<IStorage> baseStorage, long offset, in NcaAesCtrUpperIv upperIv, in NcaPatchInfo patchInfo, ref readonly SharedRef<IStorage> baseStorage, long offset, NcaFsHeader.EncryptionType encryptionType,
in NcaMetaDataHashDataInfo metaDataHashDataInfo, IHash256GeneratorFactory hashGeneratorFactory) in NcaAesCtrUpperIv upperIv, in NcaPatchInfo patchInfo, in NcaMetaDataHashDataInfo metaDataHashDataInfo,
IHash256GeneratorFactory hashGeneratorFactory)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private Result CreateAesCtrExStorageMetaStorage(ref SharedRef<IStorage> outStorage, private Result CreateAesCtrExStorageMetaStorage(ref SharedRef<IStorage> outStorage,
ref SharedRef<IStorage> baseStorage, long offset, NcaFsHeader.EncryptionType encryptionType, ref readonly SharedRef<IStorage> baseStorage, long offset, NcaFsHeader.EncryptionType encryptionType,
in NcaAesCtrUpperIv upperIv, in NcaPatchInfo patchInfo) in NcaAesCtrUpperIv upperIv, in NcaPatchInfo patchInfo)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private Result CreateAesCtrExStorage(ref SharedRef<IStorage> outStorage, private Result CreateAesCtrExStorage(ref SharedRef<IStorage> outStorage,
ref SharedRef<AesCtrCounterExtendedStorage> outAesCtrExStorage, ref SharedRef<IStorage> baseStorage, ref SharedRef<AesCtrCounterExtendedStorage> outAesCtrExStorage, ref readonly SharedRef<IStorage> baseStorage,
ref SharedRef<IStorage> aesCtrExMetaStorage, long counterOffset, in NcaAesCtrUpperIv upperIv, ref readonly SharedRef<IStorage> aesCtrExMetaStorage, long counterOffset, in NcaAesCtrUpperIv upperIv,
in NcaPatchInfo patchInfo) in NcaPatchInfo patchInfo)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private Result CreateIndirectStorageMetaStorage(ref SharedRef<IStorage> outStorage, private Result CreateIndirectStorageMetaStorage(ref SharedRef<IStorage> outStorage,
ref SharedRef<IStorage> baseStorage, in NcaPatchInfo patchInfo) ref readonly SharedRef<IStorage> baseStorage, in NcaPatchInfo patchInfo)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private Result CreateIndirectStorage(ref SharedRef<IStorage> outStorage, private Result CreateIndirectStorage(ref SharedRef<IStorage> outStorage,
ref SharedRef<IndirectStorage> outIndirectStorage, ref SharedRef<IStorage> baseStorage, ref SharedRef<IndirectStorage> outIndirectStorage, ref readonly SharedRef<IStorage> baseStorage,
ref SharedRef<IStorage> originalDataStorage, ref SharedRef<IStorage> indirectStorageMetaStorage, ref readonly SharedRef<IStorage> originalDataStorage,
in NcaPatchInfo patchInfo) ref readonly SharedRef<IStorage> indirectStorageMetaStorage, in NcaPatchInfo patchInfo)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private Result CreateSha256Storage(ref SharedRef<IStorage> outStorage, ref SharedRef<IStorage> baseStorage, private Result CreateSha256Storage(ref SharedRef<IStorage> outStorage, ref readonly SharedRef<IStorage> baseStorage,
in NcaFsHeader.HashData.HierarchicalSha256Data sha256Data, IHash256GeneratorFactory hashGeneratorFactory) in NcaFsHeader.HashData.HierarchicalSha256Data sha256Data, IHash256GeneratorFactory hashGeneratorFactory)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private Result CreateIntegrityVerificationStorage(ref SharedRef<IStorage> outStorage, private Result CreateIntegrityVerificationStorage(ref SharedRef<IStorage> outStorage,
ref SharedRef<IStorage> baseStorage, in NcaFsHeader.HashData.IntegrityMetaInfo metaInfo, ref readonly SharedRef<IStorage> baseStorage, in NcaFsHeader.HashData.IntegrityMetaInfo metaInfo,
IHash256GeneratorFactory hashGeneratorFactory)
{
throw new NotImplementedException();
}
private Result CreateIntegrityVerificationStorageImpl(ref SharedRef<IStorage> outStorage,
ref SharedRef<IStorage> baseStorage, in NcaFsHeader.HashData.IntegrityMetaInfo metaInfo, long layerInfoOffset,
int maxDataCacheEntries, int maxHashCacheEntries, sbyte bufferLevel,
IHash256GeneratorFactory hashGeneratorFactory) IHash256GeneratorFactory hashGeneratorFactory)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private Result CreateIntegrityVerificationStorageForMeta(ref SharedRef<IStorage> outStorage, private Result CreateIntegrityVerificationStorageForMeta(ref SharedRef<IStorage> outStorage,
ref SharedRef<IStorage> outLayerInfoStorage, ref SharedRef<IStorage> baseStorage, long offset, ref SharedRef<IStorage> outLayerInfoStorage, ref readonly SharedRef<IStorage> baseStorage, long offset,
in NcaMetaDataHashDataInfo metaDataHashDataInfo, IHash256GeneratorFactory hashGeneratorFactory) in NcaMetaDataHashDataInfo metaDataHashDataInfo, IHash256GeneratorFactory hashGeneratorFactory)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private Result CreateIntegrityVerificationStorageImpl(ref SharedRef<IStorage> outStorage,
ref readonly SharedRef<IStorage> baseStorage, in NcaFsHeader.HashData.IntegrityMetaInfo metaInfo,
long layerInfoOffset, int maxDataCacheEntries, int maxHashCacheEntries, sbyte bufferLevel,
IHash256GeneratorFactory hashGeneratorFactory)
{
throw new NotImplementedException();
}
public static Result CreateCompressedStorage(ref SharedRef<IStorage> outStorage, public static Result CreateCompressedStorage(ref SharedRef<IStorage> outStorage,
ref SharedRef<CompressedStorage> outCompressedStorage, ref SharedRef<IStorage> outMetaStorage, ref SharedRef<CompressedStorage> outCompressedStorage, ref SharedRef<IStorage> outMetaStorage,
ref SharedRef<IStorage> baseStorage, in NcaCompressionInfo compressionInfo, ref readonly SharedRef<IStorage> baseStorage, in NcaCompressionInfo compressionInfo,
GetDecompressorFunction getDecompressor, MemoryResource allocator, IBufferManager bufferManager) GetDecompressorFunction getDecompressor, MemoryResource allocator, IBufferManager bufferManager)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Result CreateCompressedStorage(ref SharedRef<IStorage> outStorage, private Result CreateCompressedStorage(ref SharedRef<IStorage> outStorage,
ref SharedRef<CompressedStorage> outCompressedStorage, ref SharedRef<IStorage> outMetaStorage, ref SharedRef<CompressedStorage> outCompressedStorage, ref SharedRef<IStorage> outMetaStorage,
ref SharedRef<IStorage> baseStorage, in NcaCompressionInfo compressionInfo) ref readonly SharedRef<IStorage> baseStorage, in NcaCompressionInfo compressionInfo)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Result CreateRegionSwitchStorage(ref SharedRef<IStorage> outStorage, NcaFsHeaderReader headerReader, private Result CreateRegionSwitchStorage(ref SharedRef<IStorage> outStorage, in NcaFsHeaderReader17 headerReader,
ref SharedRef<IStorage> insideRegionStorage, ref SharedRef<IStorage> outsideRegionStorage) ref readonly SharedRef<IStorage> insideRegionStorage, ref readonly SharedRef<IStorage> outsideRegionStorage)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View file

@ -8,6 +8,10 @@ using LibHac.Spl;
namespace LibHac.FsSystem; namespace LibHac.FsSystem;
public delegate Result NcaReaderInitializer(ref SharedRef<NcaReader17> outReader, in SharedRef<IStorage> baseStorage,
in NcaCompressionConfiguration compressionConfig, IHash256GeneratorFactorySelector hashGeneratorFactorySelector,
ContentAttributes contentAttributes);
/// <summary> /// <summary>
/// Handles reading information from an NCA's header. /// Handles reading information from an NCA's header.
/// </summary> /// </summary>