From e19ea92b908701e5bd2685c5e2aa9f522f4d9674 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sat, 4 May 2024 22:43:40 -0700 Subject: [PATCH] Use `ref readonly` instead of `in` for SharedRef parameters --- src/LibHac/FsSrv/DefaultFsServerObjects.cs | 6 +++--- .../FsCreator/ISaveDataFileSystemCreator.cs | 20 ++++++++++--------- .../FsCreator/SaveDataFileSystemCreator.cs | 19 ++++++++++-------- src/LibHac/FsSrv/Impl/SaveDataMover.cs | 5 +++-- src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs | 2 +- .../FsSrv/SaveDataFileSystemServiceImpl.cs | 3 ++- src/LibHac/FsSystem/NcaFileSystemDriver.cs | 2 +- src/LibHac/FsSystem/NcaReader.cs | 6 +++--- 8 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/LibHac/FsSrv/DefaultFsServerObjects.cs b/src/LibHac/FsSrv/DefaultFsServerObjects.cs index 37779e09..e34502ab 100644 --- a/src/LibHac/FsSrv/DefaultFsServerObjects.cs +++ b/src/LibHac/FsSrv/DefaultFsServerObjects.cs @@ -62,9 +62,9 @@ public class DefaultFsServerObjects }; } - public static Result InitializeNcaReader(ref SharedRef outReader, in SharedRef baseStorage, - in NcaCompressionConfiguration compressionConfig, IHash256GeneratorFactorySelector hashGeneratorFactorySelector, - ContentAttributes contentAttributes) + public static Result InitializeNcaReader(ref SharedRef outReader, + ref readonly SharedRef baseStorage, in NcaCompressionConfiguration compressionConfig, + IHash256GeneratorFactorySelector hashGeneratorFactorySelector, ContentAttributes contentAttributes) { throw new NotImplementedException(); } diff --git a/src/LibHac/FsSrv/FsCreator/ISaveDataFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/ISaveDataFileSystemCreator.cs index 01e4204b..7ab3bcb6 100644 --- a/src/LibHac/FsSrv/FsCreator/ISaveDataFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/ISaveDataFileSystemCreator.cs @@ -10,7 +10,7 @@ namespace LibHac.FsSrv.FsCreator; public interface ISaveDataFileSystemCreator : IDisposable { - Result CreateRaw(ref SharedRef outFile, in SharedRef fileSystem, ulong saveDataId, OpenMode openMode); + Result CreateRaw(ref SharedRef outFile, ref readonly SharedRef fileSystem, ulong saveDataId, OpenMode openMode); Result Create(ref SharedRef outFileSystem, ref SharedRef baseFileSystem, SaveDataSpaceId spaceId, ulong saveDataId, bool allowDirectorySaveData, bool isDeviceUniqueMac, @@ -18,16 +18,18 @@ public interface ISaveDataFileSystemCreator : IDisposable ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible); Result CreateExtraDataAccessor(ref SharedRef outExtraDataAccessor, - in SharedRef baseStorage, bool isDeviceUniqueMac, bool isIntegritySaveData, bool isReconstructible); + ref readonly SharedRef baseStorage, bool isDeviceUniqueMac, bool isIntegritySaveData, + bool isReconstructible); - Result CreateInternalStorage(ref SharedRef outFileSystem, in SharedRef baseFileSystem, - SaveDataSpaceId spaceId, ulong saveDataId, bool isDeviceUniqueMac, bool useUniqueKey1, - ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible); + Result CreateInternalStorage(ref SharedRef outFileSystem, + ref readonly SharedRef baseFileSystem, SaveDataSpaceId spaceId, ulong saveDataId, + bool isDeviceUniqueMac, bool useUniqueKey1, ISaveDataCommitTimeStampGetter timeStampGetter, + bool isReconstructible); - Result RecoverMasterHeader(in SharedRef baseFileSystem, ulong saveDataId, IBufferManager bufferManager, - bool isDeviceUniqueMac, bool isReconstructible); + Result RecoverMasterHeader(ref readonly SharedRef baseFileSystem, ulong saveDataId, + IBufferManager bufferManager, bool isDeviceUniqueMac, bool isReconstructible); - Result UpdateMac(in SharedRef baseFileSystem, ulong saveDataId, bool isDeviceUniqueMac, + Result UpdateMac(ref readonly SharedRef baseFileSystem, ulong saveDataId, bool isDeviceUniqueMac, bool isReconstructible); Result Format(in ValueSubStorage saveImageStorage, long blockSize, int countExpandMax, uint blockCount, @@ -47,7 +49,7 @@ public interface ISaveDataFileSystemCreator : IDisposable void SetMacGenerationSeed(ReadOnlySpan seed); Result IsProvisionallyCommittedSaveData(out bool outIsProvisionallyCommitted, - in SharedRef baseFileSystem, in SaveDataInfo info, bool isDeviceUniqueMac, + ref readonly SharedRef baseFileSystem, in SaveDataInfo info, bool isDeviceUniqueMac, ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible); IMacGenerator GetMacGenerator(bool isDeviceUniqueMac, bool isTemporaryTransferSave); diff --git a/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs index ecc6a188..3b129880 100644 --- a/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs @@ -281,7 +281,8 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator seed.CopyTo(_macGenerationSeed.Value); } - public Result CreateRaw(ref SharedRef outFile, in SharedRef fileSystem, ulong saveDataId, OpenMode openMode) + public Result CreateRaw(ref SharedRef outFile, ref readonly SharedRef fileSystem, + ulong saveDataId, OpenMode openMode) { Unsafe.SkipInit(out Array18 saveImageNameBuffer); @@ -419,7 +420,8 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator } public Result CreateExtraDataAccessor(ref SharedRef outExtraDataAccessor, - in SharedRef baseStorage, bool isDeviceUniqueMac, bool isIntegritySaveData, bool isReconstructible) + ref readonly SharedRef baseStorage, bool isDeviceUniqueMac, bool isIntegritySaveData, + bool isReconstructible) { using var saveDataFs = new SharedRef(); @@ -455,8 +457,9 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator } public Result CreateInternalStorage(ref SharedRef outFileSystem, - in SharedRef baseFileSystem, SaveDataSpaceId spaceId, ulong saveDataId, bool isDeviceUniqueMac, - bool useUniqueKey1, ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible) + ref readonly SharedRef baseFileSystem, SaveDataSpaceId spaceId, ulong saveDataId, + bool isDeviceUniqueMac, bool useUniqueKey1, ISaveDataCommitTimeStampGetter timeStampGetter, + bool isReconstructible) { Result res; Unsafe.SkipInit(out Array18 saveImageNameBuffer); @@ -510,7 +513,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator return Result.Success; } - public Result RecoverMasterHeader(in SharedRef baseFileSystem, ulong saveDataId, + public Result RecoverMasterHeader(ref readonly SharedRef baseFileSystem, ulong saveDataId, IBufferManager bufferManager, bool isDeviceUniqueMac, bool isReconstructible) { Unsafe.SkipInit(out Array18 saveImageNameBuffer); @@ -554,8 +557,8 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator return Result.Success; } - public Result UpdateMac(in SharedRef baseFileSystem, ulong saveDataId, bool isDeviceUniqueMac, - bool isReconstructible) + public Result UpdateMac(ref readonly SharedRef baseFileSystem, ulong saveDataId, + bool isDeviceUniqueMac, bool isReconstructible) { Unsafe.SkipInit(out Array18 saveImageNameBuffer); @@ -599,7 +602,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator } public Result IsProvisionallyCommittedSaveData(out bool outIsProvisionallyCommitted, - in SharedRef baseFileSystem, in SaveDataInfo info, bool isDeviceUniqueMac, + ref readonly SharedRef baseFileSystem, in SaveDataInfo info, bool isDeviceUniqueMac, ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible) { UnsafeHelpers.SkipParamInit(out outIsProvisionallyCommitted); diff --git a/src/LibHac/FsSrv/Impl/SaveDataMover.cs b/src/LibHac/FsSrv/Impl/SaveDataMover.cs index 9e43730f..dcdd47d6 100644 --- a/src/LibHac/FsSrv/Impl/SaveDataMover.cs +++ b/src/LibHac/FsSrv/Impl/SaveDataMover.cs @@ -38,8 +38,9 @@ public class SaveDataMover : ISaveDataMover private State _state; private SdkMutex _mutex; - public SaveDataMover(in SharedRef transferInterface, SaveDataSpaceId sourceSpaceId, - SaveDataSpaceId destinationSpaceId, NativeHandle transferMemoryHandle, ulong transferMemorySize) + public SaveDataMover(ref readonly SharedRef transferInterface, + SaveDataSpaceId sourceSpaceId, SaveDataSpaceId destinationSpaceId, NativeHandle transferMemoryHandle, + ulong transferMemorySize) { throw new NotImplementedException(); } diff --git a/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs b/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs index 2b92af54..fbe09b43 100644 --- a/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs +++ b/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs @@ -150,7 +150,7 @@ file static class Anonymous return Result.Success; - static Result ReadData(in UniqueRef file, ref CodeVerificationData outData) + static Result ReadData(ref readonly UniqueRef file, ref CodeVerificationData outData) { Result res = file.Get.GetSize(out long verificationDataSize); if (res.IsFailure()) return res.Miss(); diff --git a/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs b/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs index 79358735..4c3a716e 100644 --- a/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs +++ b/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs @@ -551,7 +551,8 @@ public class SaveDataFileSystemServiceImpl : IDisposable using (var extraDataAccessor = new SharedRef()) { res = _config.SaveFsCreator.CreateExtraDataAccessor(ref extraDataAccessor.Ref, in saveDataStorage, - IsDeviceUniqueMac(spaceId), isIntegritySaveData: true, SaveDataProperties.IsReconstructible(type, spaceId)); + IsDeviceUniqueMac(spaceId), isIntegritySaveData: true, + isReconstructible: SaveDataProperties.IsReconstructible(type, spaceId)); if (res.IsFailure()) return res.Miss(); res = extraDataAccessor.Get.ReadExtraData(out SaveDataExtraData extraData); diff --git a/src/LibHac/FsSystem/NcaFileSystemDriver.cs b/src/LibHac/FsSystem/NcaFileSystemDriver.cs index 5e4eac52..b0c66abb 100644 --- a/src/LibHac/FsSystem/NcaFileSystemDriver.cs +++ b/src/LibHac/FsSystem/NcaFileSystemDriver.cs @@ -87,7 +87,7 @@ file class SharedNcaBodyStorage : IStorage private SharedRef _storage; private SharedRef _ncaReader; - public SharedNcaBodyStorage(in SharedRef baseStorage, in SharedRef ncaReader) + public SharedNcaBodyStorage(ref readonly SharedRef baseStorage, ref readonly SharedRef ncaReader) { _storage = SharedRef.CreateCopy(in baseStorage); _ncaReader = SharedRef.CreateCopy(in ncaReader); diff --git a/src/LibHac/FsSystem/NcaReader.cs b/src/LibHac/FsSystem/NcaReader.cs index 26b1c73b..de6dbe6f 100644 --- a/src/LibHac/FsSystem/NcaReader.cs +++ b/src/LibHac/FsSystem/NcaReader.cs @@ -8,9 +8,9 @@ using LibHac.Spl; namespace LibHac.FsSystem; -public delegate Result NcaReaderInitializer(ref SharedRef outReader, in SharedRef baseStorage, - in NcaCompressionConfiguration compressionConfig, IHash256GeneratorFactorySelector hashGeneratorFactorySelector, - ContentAttributes contentAttributes); +public delegate Result NcaReaderInitializer(ref SharedRef outReader, + ref readonly SharedRef baseStorage, in NcaCompressionConfiguration compressionConfig, + IHash256GeneratorFactorySelector hashGeneratorFactorySelector, ContentAttributes contentAttributes); /// /// Handles reading information from an NCA's header.