From 32dff54ccebe2c77af29f87bdec16317e43a9d9b Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sat, 9 Dec 2023 23:30:19 -0700 Subject: [PATCH] Use ref readonly --- .../Bcat/DeliveryCacheDirectoryEntry.cs | 2 +- .../Ipc/IDeliveryCacheDirectoryService.cs | 2 +- .../Impl/Ipc/IDeliveryCacheFileService.cs | 2 +- .../Core/DeliveryCacheFileMetaAccessor.cs | 6 +- .../Core/DeliveryCacheStorageManager.cs | 8 +- .../Service/DeliveryCacheDirectoryService.cs | 6 +- .../Impl/Service/DeliveryCacheFileService.cs | 8 +- src/LibHac/Boot/Package1.cs | 2 +- src/LibHac/Boot/Package2StorageReader.cs | 10 +-- src/LibHac/Common/Keys/KeySet.cs | 4 +- src/LibHac/Common/Ref.cs | 2 +- src/LibHac/Common/SharedRef.cs | 16 ++-- src/LibHac/Common/SpanHelpers.cs | 8 +- src/LibHac/Diag/Abort.cs | 2 +- src/LibHac/Diag/Assert.cs | 14 ++-- src/LibHac/Diag/Impl/ObserverManager.cs | 8 +- src/LibHac/Diag/Log.cs | 4 +- src/LibHac/Diag/LogObserver.cs | 10 ++- src/LibHac/Fs/AccessLog.cs | 2 +- src/LibHac/Fs/Common/FileStorage.cs | 2 +- src/LibHac/Fs/Common/Path.cs | 22 +++--- src/LibHac/Fs/Common/PathUtility.cs | 2 +- src/LibHac/Fs/Common/SaveDataTypes.cs | 4 +- src/LibHac/Fs/Fsa/IAttributeFileSystem.cs | 16 ++-- src/LibHac/Fs/Fsa/IFileSystem.cs | 64 ++++++++-------- src/LibHac/Fs/Fsa/Registrar.cs | 30 ++++---- src/LibHac/Fs/Fsa/UserFileSystem.cs | 2 +- src/LibHac/Fs/ReadOnlyFileSystem.cs | 26 +++---- .../Fs/Shim/FileSystemServiceObjectAdapter.cs | 32 ++++---- src/LibHac/Fs/Shim/Host.cs | 2 +- src/LibHac/Fs/Shim/PathBasedFileDataCache.cs | 4 +- src/LibHac/Fs/Shim/SaveDataManagement.cs | 14 ++-- src/LibHac/Fs/Shim/SdCard.cs | 14 ++-- src/LibHac/Fs/SubStorage.cs | 2 +- src/LibHac/Fs/ValueSubStorage.cs | 8 +- src/LibHac/FsSrv/BaseFileSystemService.cs | 4 +- src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs | 8 +- src/LibHac/FsSrv/FileSystemProxyImpl.cs | 21 +++--- .../FsCreator/ILocalFileSystemCreator.cs | 2 +- .../ISubDirectoryFileSystemCreator.cs | 2 +- .../ITargetManagerFileSystemCreator.cs | 2 +- .../SaveDataResultConvertFileSystem.cs | 4 +- .../SubDirectoryFileSystemCreator.cs | 2 +- .../TargetManagerFileSystemCreator.cs | 2 +- .../Impl/AsynchronousAccessFileSystem.cs | 4 +- src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs | 4 +- .../FsSrv/Impl/FileSystemInterfaceAdapter.cs | 32 ++++---- .../Impl/FileSystemProxyServiceObject.cs | 2 +- .../Impl/ISaveDataTransferCoreInterface.cs | 2 +- src/LibHac/FsSrv/Impl/LocationResolverSet.cs | 2 +- src/LibHac/FsSrv/Impl/OpenCountFileSystem.cs | 8 +- .../SaveDataExtraDataAccessorCacheManager.cs | 4 +- .../Impl/SaveDataFileSystemCacheRegister.cs | 26 +++---- src/LibHac/FsSrv/Impl/Utility.cs | 8 +- src/LibHac/FsSrv/NcaFileSystemService.cs | 8 +- src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs | 35 +++++---- src/LibHac/FsSrv/SaveDataFileSystemService.cs | 21 +++--- .../FsSrv/SaveDataFileSystemServiceImpl.cs | 49 ++++++------ src/LibHac/FsSrv/SaveDataIndexer.cs | 4 +- src/LibHac/FsSrv/SaveDataSharedFileStorage.cs | 2 +- src/LibHac/FsSrv/Sf/IFileSystem.cs | 30 ++++---- src/LibHac/FsSrv/Sf/IFileSystemProxy.cs | 18 ++--- .../FsSrv/Sf/IFileSystemProxyForLoader.cs | 2 +- ...aveDataTransferManagerForSaveDataRepair.cs | 6 +- .../FsSystem/AesCtrCounterExtendedStorage.cs | 6 +- src/LibHac/FsSystem/AesCtrStorage.cs | 2 +- src/LibHac/FsSystem/AesXtsStorageExternal.cs | 2 +- .../FsSystem/AlignmentMatchingStorage.cs | 4 +- .../FsSystem/AlignmentMatchingStorageImpl.cs | 4 +- .../ApplicationTemporaryFileSystem.cs | 22 +++--- src/LibHac/FsSystem/BucketTree.cs | 8 +- src/LibHac/FsSystem/BucketTreeBuilder.cs | 6 +- src/LibHac/FsSystem/BufferedStorage.cs | 5 +- src/LibHac/FsSystem/CompressedStorage.cs | 14 ++-- .../FsSystem/ConcatenationFileSystem.cs | 74 +++++++++---------- .../FsSystem/DirectorySaveDataFileSystem.cs | 40 +++++----- src/LibHac/FsSystem/ForwardingFileSystem.cs | 30 ++++---- ...ierarchicalIntegrityVerificationStorage.cs | 22 +++--- .../FsSystem/IResultConvertFileSystem.cs | 26 +++---- src/LibHac/FsSystem/IndirectStorage.cs | 12 +-- .../FsSystem/IntegrityVerificationStorage.cs | 20 ++--- src/LibHac/FsSystem/LocalFileSystem.cs | 44 +++++------ src/LibHac/FsSystem/NcaReader.cs | 2 +- src/LibHac/FsSystem/PartitionFileSystem.cs | 30 ++++---- .../FsSystem/PartitionFileSystemMeta.cs | 2 +- src/LibHac/FsSystem/SparseStorage.cs | 2 +- .../FsSystem/StorageLayoutTypeSetter.cs | 56 +++++++------- src/LibHac/FsSystem/SubdirectoryFileSystem.cs | 34 ++++----- src/LibHac/FsSystem/SwitchStorage.cs | 6 +- src/LibHac/FsSystem/UnionStorage.cs | 5 +- src/LibHac/FsSystem/Utility.cs | 47 ++++++------ src/LibHac/Gc/GameCardEmulated.cs | 2 +- src/LibHac/Gc/IGcApi.cs | 2 +- src/LibHac/GcSrv/GameCardManager.cs | 4 +- src/LibHac/GcSrv/GameCardStorage.cs | 2 +- src/LibHac/GcSrv/GameCardStorageDevice.cs | 12 +-- .../Kernel/InitialProcessBinaryReader.cs | 8 +- src/LibHac/Kernel/KipReader.cs | 2 +- src/LibHac/Lr/ILocationResolver.cs | 14 ++-- src/LibHac/Lr/IRegisteredLocationResolver.cs | 8 +- src/LibHac/Lr/LocationResolver.cs | 14 ++-- src/LibHac/Lr/RegisteredLocationResolver.cs | 8 +- src/LibHac/Os/ReaderWriterLock.cs | 6 +- src/LibHac/Os/UniqueLock.cs | 2 +- src/LibHac/Sf/Buffers.cs | 2 +- src/LibHac/Tools/Fs/InMemoryFileSystem.cs | 30 ++++---- src/LibHac/Tools/FsSystem/AesXtsFileHeader.cs | 4 +- src/LibHac/Tools/FsSystem/AesXtsFileSystem.cs | 66 ++++++++--------- .../Tools/FsSystem/CompressedStorage.cs | 4 +- .../Tools/FsSystem/FileSystemExtensions.cs | 20 ++--- .../Tools/FsSystem/LayeredFileSystem.cs | 42 +++++------ .../Tools/FsSystem/RomFs/RomFsFileSystem.cs | 26 +++---- .../Tools/FsSystem/Save/SaveDataFileSystem.cs | 26 +++---- .../FsSystem/Save/SaveDataFileSystemCore.cs | 28 +++---- src/LibHac/Tools/FsSystem/Save/SaveFsList.cs | 4 +- src/hactoolnet/ProcessKip.cs | 4 +- src/hactoolnet/Program.cs | 2 +- tests/LibHac.Tests/BufferStructTests.cs | 2 +- tests/LibHac.Tests/Common/Layout.cs | 2 +- tests/LibHac.Tests/LibHacTestFramework.cs | 2 +- 120 files changed, 779 insertions(+), 768 deletions(-) diff --git a/src/LibHac/Bcat/DeliveryCacheDirectoryEntry.cs b/src/LibHac/Bcat/DeliveryCacheDirectoryEntry.cs index 2b18afbd..2fb05bae 100644 --- a/src/LibHac/Bcat/DeliveryCacheDirectoryEntry.cs +++ b/src/LibHac/Bcat/DeliveryCacheDirectoryEntry.cs @@ -6,7 +6,7 @@ public struct DeliveryCacheDirectoryEntry public long Size; public Digest Digest; - public DeliveryCacheDirectoryEntry(in FileName name, long size, in Digest digest) + public DeliveryCacheDirectoryEntry(ref readonly FileName name, long size, ref readonly Digest digest) { Name = name; Size = size; diff --git a/src/LibHac/Bcat/Impl/Ipc/IDeliveryCacheDirectoryService.cs b/src/LibHac/Bcat/Impl/Ipc/IDeliveryCacheDirectoryService.cs index a4cbaf3e..c9ab616b 100644 --- a/src/LibHac/Bcat/Impl/Ipc/IDeliveryCacheDirectoryService.cs +++ b/src/LibHac/Bcat/Impl/Ipc/IDeliveryCacheDirectoryService.cs @@ -4,7 +4,7 @@ namespace LibHac.Bcat.Impl.Ipc; public interface IDeliveryCacheDirectoryService : IDisposable { - Result Open(ref DirectoryName name); + Result Open(ref readonly DirectoryName name); Result Read(out int entriesRead, Span entryBuffer); Result GetCount(out int count); } \ No newline at end of file diff --git a/src/LibHac/Bcat/Impl/Ipc/IDeliveryCacheFileService.cs b/src/LibHac/Bcat/Impl/Ipc/IDeliveryCacheFileService.cs index 6903caca..9f268020 100644 --- a/src/LibHac/Bcat/Impl/Ipc/IDeliveryCacheFileService.cs +++ b/src/LibHac/Bcat/Impl/Ipc/IDeliveryCacheFileService.cs @@ -4,7 +4,7 @@ namespace LibHac.Bcat.Impl.Ipc; public interface IDeliveryCacheFileService : IDisposable { - Result Open(ref DirectoryName directoryName, ref FileName fileName); + Result Open(ref readonly DirectoryName directoryName, ref readonly FileName fileName); Result Read(out long bytesRead, long offset, Span destination); Result GetSize(out long size); Result GetDigest(out Digest digest); diff --git a/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheFileMetaAccessor.cs b/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheFileMetaAccessor.cs index 20d03288..a88bc285 100644 --- a/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheFileMetaAccessor.cs +++ b/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheFileMetaAccessor.cs @@ -23,11 +23,11 @@ internal class DeliveryCacheFileMetaAccessor Server = server; } - public Result ReadApplicationFileMeta(ulong applicationId, ref DirectoryName directoryName, + public Result ReadApplicationFileMeta(ulong applicationId, ref readonly DirectoryName directoryName, bool allowMissingMetaFile) { Span metaPath = stackalloc byte[0x50]; - Server.GetStorageManager().GetFilesMetaPath(metaPath, applicationId, ref directoryName); + Server.GetStorageManager().GetFilesMetaPath(metaPath, applicationId, in directoryName); return Read(new U8Span(metaPath), allowMissingMetaFile); } @@ -48,7 +48,7 @@ internal class DeliveryCacheFileMetaAccessor } } - public Result FindEntry(out DeliveryCacheFileMetaEntry entry, ref FileName fileName) + public Result FindEntry(out DeliveryCacheFileMetaEntry entry, ref readonly FileName fileName) { UnsafeHelpers.SkipParamInit(out entry); diff --git a/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheStorageManager.cs b/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheStorageManager.cs index 7eb45ba6..308801fd 100644 --- a/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheStorageManager.cs +++ b/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheStorageManager.cs @@ -212,8 +212,8 @@ internal class DeliveryCacheStorageManager } } - public void GetFilePath(Span pathBuffer, ulong applicationId, ref DirectoryName directoryName, - ref FileName fileName) + public void GetFilePath(Span pathBuffer, ulong applicationId, ref readonly DirectoryName directoryName, + ref readonly FileName fileName) { // returns "mount:/directories/%s/files/%s", directoryName, fileName lock (_locker) @@ -228,7 +228,7 @@ internal class DeliveryCacheStorageManager } } - public void GetFilesMetaPath(Span pathBuffer, ulong applicationId, ref DirectoryName directoryName) + public void GetFilesMetaPath(Span pathBuffer, ulong applicationId, ref readonly DirectoryName directoryName) { // returns "mount:/directories/%s/files.meta", directoryName lock (_locker) @@ -253,7 +253,7 @@ internal class DeliveryCacheStorageManager } } - public void GetDirectoryPath(Span pathBuffer, ulong applicationId, ref DirectoryName directoryName) + public void GetDirectoryPath(Span pathBuffer, ulong applicationId, ref readonly DirectoryName directoryName) { // returns "mount:/directories/%s", directoryName lock (_locker) diff --git a/src/LibHac/Bcat/Impl/Service/DeliveryCacheDirectoryService.cs b/src/LibHac/Bcat/Impl/Service/DeliveryCacheDirectoryService.cs index ff1397c9..b53eed71 100644 --- a/src/LibHac/Bcat/Impl/Service/DeliveryCacheDirectoryService.cs +++ b/src/LibHac/Bcat/Impl/Service/DeliveryCacheDirectoryService.cs @@ -27,7 +27,7 @@ internal class DeliveryCacheDirectoryService : IDeliveryCacheDirectoryService Access = accessControl; } - public Result Open(ref DirectoryName name) + public Result Open(ref readonly DirectoryName name) { if (!name.IsValid()) return ResultBcat.InvalidArgument.Log(); @@ -38,7 +38,7 @@ internal class DeliveryCacheDirectoryService : IDeliveryCacheDirectoryService return ResultBcat.AlreadyOpen.Log(); var metaReader = new DeliveryCacheFileMetaAccessor(Server); - Result res = metaReader.ReadApplicationFileMeta(ApplicationId, ref name, false); + Result res = metaReader.ReadApplicationFileMeta(ApplicationId, in name, false); if (res.IsFailure()) return res.Miss(); Count = metaReader.Count; @@ -59,7 +59,7 @@ internal class DeliveryCacheDirectoryService : IDeliveryCacheDirectoryService return ResultBcat.NotOpen.Log(); var metaReader = new DeliveryCacheFileMetaAccessor(Server); - Result res = metaReader.ReadApplicationFileMeta(ApplicationId, ref _name, true); + Result res = metaReader.ReadApplicationFileMeta(ApplicationId, in _name, true); if (res.IsFailure()) return res.Miss(); int i; diff --git a/src/LibHac/Bcat/Impl/Service/DeliveryCacheFileService.cs b/src/LibHac/Bcat/Impl/Service/DeliveryCacheFileService.cs index a221b1f7..541f25df 100644 --- a/src/LibHac/Bcat/Impl/Service/DeliveryCacheFileService.cs +++ b/src/LibHac/Bcat/Impl/Service/DeliveryCacheFileService.cs @@ -29,7 +29,7 @@ internal class DeliveryCacheFileService : IDeliveryCacheFileService Access = accessControl; } - public Result Open(ref DirectoryName directoryName, ref FileName fileName) + public Result Open(ref readonly DirectoryName directoryName, ref readonly FileName fileName) { if (!directoryName.IsValid()) return ResultBcat.InvalidArgument.Log(); @@ -43,14 +43,14 @@ internal class DeliveryCacheFileService : IDeliveryCacheFileService return ResultBcat.AlreadyOpen.Log(); var metaReader = new DeliveryCacheFileMetaAccessor(Server); - Result res = metaReader.ReadApplicationFileMeta(ApplicationId, ref directoryName, true); + Result res = metaReader.ReadApplicationFileMeta(ApplicationId, in directoryName, true); if (res.IsFailure()) return res.Miss(); - res = metaReader.FindEntry(out DeliveryCacheFileMetaEntry entry, ref fileName); + res = metaReader.FindEntry(out DeliveryCacheFileMetaEntry entry, in fileName); if (res.IsFailure()) return res.Miss(); Span filePath = stackalloc byte[0x80]; - Server.GetStorageManager().GetFilePath(filePath, ApplicationId, ref directoryName, ref fileName); + Server.GetStorageManager().GetFilePath(filePath, ApplicationId, in directoryName, in fileName); res = Server.GetFsClient().OpenFile(out _handle, new U8Span(filePath), OpenMode.Read); if (res.IsFailure()) return res.Miss(); diff --git a/src/LibHac/Boot/Package1.cs b/src/LibHac/Boot/Package1.cs index 3565950e..b4663ee7 100644 --- a/src/LibHac/Boot/Package1.cs +++ b/src/LibHac/Boot/Package1.cs @@ -105,7 +105,7 @@ public class Package1 public ref readonly Package1Pk11Header Pk11Header => ref _pk11Header; public ref readonly Array16 Pk11Mac => ref _pk11Mac; - public Result Initialize(KeySet keySet, in SharedRef storage) + public Result Initialize(KeySet keySet, ref readonly SharedRef storage) { KeySet = keySet; _baseStorage.SetByCopy(in storage); diff --git a/src/LibHac/Boot/Package2StorageReader.cs b/src/LibHac/Boot/Package2StorageReader.cs index 9b4c0f0d..8daedc61 100644 --- a/src/LibHac/Boot/Package2StorageReader.cs +++ b/src/LibHac/Boot/Package2StorageReader.cs @@ -37,7 +37,7 @@ public class Package2StorageReader : IDisposable /// The keyset to use for decrypting the package. /// An of the encrypted package2. /// The of the operation. - public Result Initialize(KeySet keySet, in SharedRef storage) + public Result Initialize(KeySet keySet, ref readonly SharedRef storage) { Result res = storage.Get.Read(0, SpanHelpers.AsByteSpan(ref _header)); if (res.IsFailure()) return res.Miss(); @@ -65,7 +65,7 @@ public class Package2StorageReader : IDisposable int offset = _header.Meta.GetPayloadFileOffset(index); int size = (int)_header.Meta.PayloadSizes[index]; - var payloadSubStorage = new SubStorage(_storage, offset, size); + var payloadSubStorage = new SubStorage(in _storage, offset, size); if (size == 0) { @@ -178,7 +178,7 @@ public class Package2StorageReader : IDisposable int offset = _header.Meta.GetPayloadFileOffset(i); int size = (int)_header.Meta.PayloadSizes[i]; - var payloadSubStorage = new SubStorage(_storage, offset, size); + var payloadSubStorage = new SubStorage(in _storage, offset, size); offset = 0; sha.Initialize(); @@ -224,10 +224,10 @@ public class Package2StorageReader : IDisposable int encryptedHeaderSize = Unsafe.SizeOf() - unencryptedHeaderSize; // Get signature and IV - storages.Add(new SubStorage(_storage, 0, unencryptedHeaderSize)); + storages.Add(new SubStorage(in _storage, 0, unencryptedHeaderSize)); // Open decrypted meta - var encMetaStorage = new SubStorage(_storage, unencryptedHeaderSize, encryptedHeaderSize); + var encMetaStorage = new SubStorage(in _storage, unencryptedHeaderSize, encryptedHeaderSize); // The counter starts counting at the beginning of the meta struct, but the first block in // the struct isn't encrypted. Increase the counter by one to skip that block. diff --git a/src/LibHac/Common/Keys/KeySet.cs b/src/LibHac/Common/Keys/KeySet.cs index e995c1f8..4f552a13 100644 --- a/src/LibHac/Common/Keys/KeySet.cs +++ b/src/LibHac/Common/Keys/KeySet.cs @@ -257,7 +257,7 @@ public class KeySet public void DeriveSdCardKeys() => KeyDerivation.DeriveSdCardKeys(this); - private static RSAParameters CreateRsaParameters(in RsaKey key) + private static RSAParameters CreateRsaParameters(ref readonly RsaKey key) { return new RSAParameters { @@ -266,7 +266,7 @@ public class KeySet }; } - private static RSAParameters CreateRsaParameters(in RsaFullKey key) + private static RSAParameters CreateRsaParameters(ref readonly RsaFullKey key) { return new RSAParameters { diff --git a/src/LibHac/Common/Ref.cs b/src/LibHac/Common/Ref.cs index 2fc6368c..e03ad041 100644 --- a/src/LibHac/Common/Ref.cs +++ b/src/LibHac/Common/Ref.cs @@ -72,7 +72,7 @@ public readonly ref struct ReadOnlyRef /// /// The reference to the target value. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public ReadOnlyRef(in T value) + public ReadOnlyRef(ref readonly T value) { _ref = ref value; } diff --git a/src/LibHac/Common/SharedRef.cs b/src/LibHac/Common/SharedRef.cs index d5fd426c..3c516820 100644 --- a/src/LibHac/Common/SharedRef.cs +++ b/src/LibHac/Common/SharedRef.cs @@ -141,7 +141,7 @@ public struct SharedRef : IDisposable where T : class, IDisposable return sharedRef; } - public static SharedRef CreateCopy(in SharedRef other) where TFrom : class, T + public static SharedRef CreateCopy(ref readonly SharedRef other) where TFrom : class, T { var sharedRef = new SharedRef(); @@ -153,7 +153,7 @@ public struct SharedRef : IDisposable where T : class, IDisposable return sharedRef; } - public static SharedRef Create(in WeakRef other) where TFrom : class, T + public static SharedRef Create(ref readonly WeakRef other) where TFrom : class, T { ref SharedRef otherShared = ref Unsafe.As, SharedRef>(ref Unsafe.AsRef(in other)); @@ -228,7 +228,7 @@ public struct SharedRef : IDisposable where T : class, IDisposable oldRefCount?.Decrement(); } - public void SetByCopy(in SharedRef other) where TFrom : class, T + public void SetByCopy(ref readonly SharedRef other) where TFrom : class, T { RefCount oldRefCount = _refCount; RefCount otherRef = other._refCount; @@ -293,7 +293,7 @@ public struct WeakRef : IDisposable where T : class, IDisposable private T _value; private RefCount _refCount; - public WeakRef(in SharedRef other) + public WeakRef(ref readonly SharedRef other) { this = Create(in other); } @@ -337,7 +337,7 @@ public struct WeakRef : IDisposable where T : class, IDisposable return weakRef; } - public static WeakRef CreateCopy(in WeakRef other) where TFrom : class, T + public static WeakRef CreateCopy(ref readonly WeakRef other) where TFrom : class, T { var weakRef = new WeakRef(); @@ -356,7 +356,7 @@ public struct WeakRef : IDisposable where T : class, IDisposable return weakRef; } - public static WeakRef Create(in SharedRef other) where TFrom : class, T + public static WeakRef Create(ref readonly SharedRef other) where TFrom : class, T { ref readonly WeakRef otherWeak = ref Unsafe.As, WeakRef>(ref Unsafe.AsRef(in other)); @@ -398,14 +398,14 @@ public struct WeakRef : IDisposable where T : class, IDisposable temp.DisposeInternal(); } - public void SetCopy(in WeakRef other) where TFrom : class, T + public void SetCopy(ref readonly WeakRef other) where TFrom : class, T { WeakRef temp = CreateCopy(in other); Swap(ref temp); temp.DisposeInternal(); } - public void Set(in SharedRef other) where TFrom : class, T + public void Set(ref readonly SharedRef other) where TFrom : class, T { WeakRef temp = Create(in other); Swap(ref temp); diff --git a/src/LibHac/Common/SpanHelpers.cs b/src/LibHac/Common/SpanHelpers.cs index 79d5a516..46631143 100644 --- a/src/LibHac/Common/SpanHelpers.cs +++ b/src/LibHac/Common/SpanHelpers.cs @@ -60,19 +60,19 @@ public static class SpanHelpers } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlySpan CreateReadOnlySpan(in T reference, int length) + public static ReadOnlySpan CreateReadOnlySpan(ref readonly T reference, int length) { return MemoryMarshal.CreateReadOnlySpan(ref Unsafe.AsRef(in reference), length); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlySpan AsReadOnlySpan(in T reference) where T : unmanaged + public static ReadOnlySpan AsReadOnlySpan(ref readonly T reference) where T : unmanaged { return new ReadOnlySpan(in reference); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlySpan AsReadOnlySpan(in TStruct reference) + public static ReadOnlySpan AsReadOnlySpan(ref readonly TStruct reference) where TStruct : unmanaged where TSpan : unmanaged { return CreateReadOnlySpan(in Unsafe.As(ref Unsafe.AsRef(in reference)), @@ -80,7 +80,7 @@ public static class SpanHelpers } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ReadOnlySpan AsReadOnlyByteSpan(in T reference) where T : unmanaged + public static ReadOnlySpan AsReadOnlyByteSpan(ref readonly T reference) where T : unmanaged { return CreateReadOnlySpan(in Unsafe.As(ref Unsafe.AsRef(in reference)), Unsafe.SizeOf()); } diff --git a/src/LibHac/Diag/Abort.cs b/src/LibHac/Diag/Abort.cs index 47215081..5516e455 100644 --- a/src/LibHac/Diag/Abort.cs +++ b/src/LibHac/Diag/Abort.cs @@ -25,7 +25,7 @@ public enum AbortReason public static class Abort { - internal static void InvokeAbortObserver(in AbortInfo abortInfo) + internal static void InvokeAbortObserver(ref readonly AbortInfo abortInfo) { // Todo } diff --git a/src/LibHac/Diag/Assert.cs b/src/LibHac/Diag/Assert.cs index ed0e81ff..121efa2d 100644 --- a/src/LibHac/Diag/Assert.cs +++ b/src/LibHac/Diag/Assert.cs @@ -32,7 +32,7 @@ public enum AssertionFailureOperation Continue } -public delegate AssertionFailureOperation AssertionFailureHandler(in AssertionInfo assertionInfo); +public delegate AssertionFailureOperation AssertionFailureHandler(ref readonly AssertionInfo assertionInfo); public static class Assert { @@ -52,13 +52,13 @@ public static class Assert } } - private static AssertionFailureOperation DefaultAssertionFailureHandler(in AssertionInfo assertionInfo) + private static AssertionFailureOperation DefaultAssertionFailureHandler(ref readonly AssertionInfo assertionInfo) { return AssertionFailureOperation.Abort; } private static void ExecuteAssertionFailureOperation(AssertionFailureOperation operation, - in AssertionInfo assertionInfo) + ref readonly AssertionInfo assertionInfo) { switch (operation) { @@ -84,7 +84,7 @@ public static class Assert } } - private static void InvokeAssertionFailureHandler(in AssertionInfo assertionInfo) + private static void InvokeAssertionFailureHandler(ref readonly AssertionInfo assertionInfo) { AssertionFailureOperation operation = _assertionFailureHandler(in assertionInfo); ExecuteAssertionFailureOperation(operation, in assertionInfo); @@ -440,7 +440,7 @@ public static class Assert // Not null SharedRef // --------------------------------------------------------------------- - private static void NotNullImpl(AssertionType assertionType, in SharedRef value, + private static void NotNullImpl(AssertionType assertionType, ref readonly SharedRef value, string valueText, string functionName, string fileName, int lineNumber) where T : class, IDisposable { if (AssertImpl.NotNull(in value)) @@ -575,7 +575,7 @@ public static class Assert // Null UniqueRef // --------------------------------------------------------------------- - private static void NullImpl(AssertionType assertionType, in UniqueRef value, + private static void NullImpl(AssertionType assertionType, ref readonly UniqueRef value, string valueText, string functionName, string fileName, int lineNumber) where T : class, IDisposable { if (AssertImpl.Null(in value)) @@ -621,7 +621,7 @@ public static class Assert // Null SharedRef // --------------------------------------------------------------------- - private static void NullImpl(AssertionType assertionType, in SharedRef value, + private static void NullImpl(AssertionType assertionType, ref readonly SharedRef value, string valueText, string functionName, string fileName, int lineNumber) where T : class, IDisposable { if (AssertImpl.Null(in value)) diff --git a/src/LibHac/Diag/Impl/ObserverManager.cs b/src/LibHac/Diag/Impl/ObserverManager.cs index f619be69..083bb3dd 100644 --- a/src/LibHac/Diag/Impl/ObserverManager.cs +++ b/src/LibHac/Diag/Impl/ObserverManager.cs @@ -13,7 +13,7 @@ internal class ObserverManager where TObserver : IObserverHold private LinkedList _observers; private ReaderWriterLock _rwLock; - public delegate void Function(ref TObserver observer, in TItem item); + public delegate void Function(ref TObserver observer, ref readonly TItem item); public ObserverManager(HorizonClient hos) { @@ -61,7 +61,7 @@ internal class ObserverManager where TObserver : IObserverHold _observers.Clear(); } - public void InvokeAllObserver(in TItem item, Function function) + public void InvokeAllObserver(ref readonly TItem item, Function function) { using ScopedLock lk = ScopedLock.Lock(ref _rwLock); @@ -81,7 +81,7 @@ internal class LogObserverManager private readonly LinkedList _observers; private ReaderWriterLock _rwLock; - public delegate void Function(ref LogObserverHolder observer, in LogObserverContext item); + public delegate void Function(ref LogObserverHolder observer, ref readonly LogObserverContext item); public LogObserverManager(HorizonClient hos) { @@ -129,7 +129,7 @@ internal class LogObserverManager _observers.Clear(); } - public void InvokeAllObserver(in LogObserverContext item, Function function) + public void InvokeAllObserver(ref readonly LogObserverContext item, Function function) { using ScopedLock lk = ScopedLock.Lock(ref _rwLock); diff --git a/src/LibHac/Diag/Log.cs b/src/LibHac/Diag/Log.cs index 1fffe3f4..de2e5a23 100644 --- a/src/LibHac/Diag/Log.cs +++ b/src/LibHac/Diag/Log.cs @@ -7,12 +7,12 @@ namespace LibHac.Diag; public static class Log { // Todo: Should we split large logs into smaller chunks like Horizon does? - public static void LogImpl(this DiagClientImpl diag, in LogMetaData metaData, ReadOnlySpan message) + public static void LogImpl(this DiagClientImpl diag, ref readonly LogMetaData metaData, ReadOnlySpan message) { diag.PutImpl(in metaData, message); } - public static void PutImpl(this DiagClientImpl diag, in LogMetaData metaData, ReadOnlySpan message) + public static void PutImpl(this DiagClientImpl diag, ref readonly LogMetaData metaData, ReadOnlySpan message) { var logBody = new LogBody { diff --git a/src/LibHac/Diag/LogObserver.cs b/src/LibHac/Diag/LogObserver.cs index b9c8a86e..9d8bb456 100644 --- a/src/LibHac/Diag/LogObserver.cs +++ b/src/LibHac/Diag/LogObserver.cs @@ -3,7 +3,7 @@ using LibHac.Diag.Impl; namespace LibHac.Diag { - public delegate void LogObserver(in LogMetaData metaData, in LogBody body, object arguments); + public delegate void LogObserver(ref readonly LogMetaData metaData, ref readonly LogBody body, object arguments); internal struct LogObserverGlobals { @@ -40,7 +40,8 @@ namespace LibHac.Diag diag.Impl.GetLogObserverManager().UnregisterObserver(observerHolder); } - private static void TentativeDefaultLogObserver(in LogMetaData metaData, in LogBody body, object arguments) + private static void TentativeDefaultLogObserver(ref readonly LogMetaData metaData, ref readonly LogBody body, + object arguments) { } @@ -61,7 +62,8 @@ namespace LibHac.Diag return g.Manager; } - internal static void CallAllLogObserver(this DiagClientImpl diag, in LogMetaData metaData, in LogBody body) + internal static void CallAllLogObserver(this DiagClientImpl diag, ref readonly LogMetaData metaData, + ref readonly LogBody body) { var context = new LogObserverContext { @@ -73,7 +75,7 @@ namespace LibHac.Diag manager.InvokeAllObserver(in context, InvokeFunction); - static void InvokeFunction(ref LogObserverHolder holder, in LogObserverContext item) + static void InvokeFunction(ref LogObserverHolder holder, ref readonly LogObserverContext item) { holder.Observer(in item.MetaData, in item.Body, holder.Arguments); } diff --git a/src/LibHac/Fs/AccessLog.cs b/src/LibHac/Fs/AccessLog.cs index 89f4a728..038ea900 100644 --- a/src/LibHac/Fs/AccessLog.cs +++ b/src/LibHac/Fs/AccessLog.cs @@ -401,7 +401,7 @@ namespace LibHac.Fs.Impl public static class AccessLogImpl { - internal static T DereferenceOutValue(in T value, Result result) where T : unmanaged + internal static T DereferenceOutValue(ref readonly T value, Result result) where T : unmanaged { return result.IsSuccess() ? value : default; } diff --git a/src/LibHac/Fs/Common/FileStorage.cs b/src/LibHac/Fs/Common/FileStorage.cs index 175385ce..0b26e54d 100644 --- a/src/LibHac/Fs/Common/FileStorage.cs +++ b/src/LibHac/Fs/Common/FileStorage.cs @@ -179,7 +179,7 @@ public class FileStorageBasedFileSystem : FileStorage /// : The specified path does not exist or is a directory.
/// : When opening as , /// the file is already opened as . - public Result Initialize(ref SharedRef baseFileSystem, in Path path, OpenMode mode) + public Result Initialize(ref SharedRef baseFileSystem, ref readonly Path path, OpenMode mode) { using var baseFile = new UniqueRef(); diff --git a/src/LibHac/Fs/Common/Path.cs b/src/LibHac/Fs/Common/Path.cs index 9b6c9af4..bb3b9c40 100644 --- a/src/LibHac/Fs/Common/Path.cs +++ b/src/LibHac/Fs/Common/Path.cs @@ -46,7 +46,7 @@ public static class PathExtensions /// A reference to the given . #pragma warning disable LH0001 // DoNotCopyValue #pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type - public static unsafe ref Path Ref(this scoped in Path path) + public static unsafe ref Path Ref(this scoped ref readonly Path path) { fixed (Path* p = &path) { @@ -61,7 +61,7 @@ public static class PathExtensions return ref *p; } - public static unsafe bool IsNullRef(in Path path) + public static unsafe bool IsNullRef(ref readonly Path path) { fixed (Path* p = &path) { @@ -69,7 +69,7 @@ public static class PathExtensions } } - public static unsafe bool IsNullRef(in int path) + public static unsafe bool IsNullRef(ref readonly int path) { fixed (int* p = &path) { @@ -131,7 +131,7 @@ public ref struct Path /// : The operation was successful.
/// : The IsNormalized flag of /// is not .
- public Result Initialize(scoped in Path path) + public Result Initialize(scoped ref readonly Path path) { if (!path._isNormalized) return ResultFs.NotNormalized.Log(); @@ -406,7 +406,7 @@ public ref struct Path /// : The operation was successful.
/// : The IsNormalized flag of /// is not .
- public Result Initialize(scoped in Path other) + public Result Initialize(scoped ref readonly Path other) { if (!other._isNormalized) return ResultFs.NotNormalized.Log(); @@ -433,7 +433,7 @@ public ref struct Path /// because paths are always normalized upon initialization. /// The path used to initialize this . /// : The operation was successful. - public Result Initialize(scoped in Stored other) + public Result Initialize(scoped ref readonly Stored other) { int otherLength = other.GetLength(); @@ -840,7 +840,7 @@ public ref struct Path /// The to insert. /// : The operation was successful.
/// : The path provided in is a Windows path.
- public Result InsertParent(scoped in Path parent) + public Result InsertParent(scoped ref readonly Path parent) { return InsertParent(parent.GetString()); } @@ -933,7 +933,7 @@ public ref struct Path /// path is not normalized yet the IsNormalized flag is still . /// The child to append to the current path. /// : The operation was successful. - public Result AppendChild(scoped in Path child) + public Result AppendChild(scoped ref readonly Path child) { return AppendChild(child.GetString()); } @@ -949,7 +949,7 @@ public ref struct Path /// : The operation was successful.
/// : The IsNormalized flag of either /// or is not .
- public Result Combine(scoped in Path path1, scoped in Path path2) + public Result Combine(scoped ref readonly Path path1, scoped ref readonly Path path2) { int path1Length = path1.GetLength(); int path2Length = path2.GetLength(); @@ -985,7 +985,7 @@ public ref struct Path /// : The operation was successful.
/// : The IsNormalized flag of /// is not .
- public Result Combine(scoped in Path path1, scoped ReadOnlySpan path2) + public Result Combine(scoped ref readonly Path path1, scoped ReadOnlySpan path2) { int path1Length = path1.GetLength(); int path2Length = StringUtils.GetLength(path2); @@ -1010,7 +1010,7 @@ public ref struct Path /// The first path to combine. /// The second path to combine. /// : The operation was successful. - public Result Combine(scoped ReadOnlySpan path1, scoped in Path path2) + public Result Combine(scoped ReadOnlySpan path1, scoped ref readonly Path path2) { int path1Length = StringUtils.GetLength(path1); int path2Length = path2.GetLength(); diff --git a/src/LibHac/Fs/Common/PathUtility.cs b/src/LibHac/Fs/Common/PathUtility.cs index 7b363caa..7b6921ca 100644 --- a/src/LibHac/Fs/Common/PathUtility.cs +++ b/src/LibHac/Fs/Common/PathUtility.cs @@ -88,7 +88,7 @@ public static class PathUtility return path[length - 1] == DirectorySeparator || path[length - 1] == AltDirectorySeparator; } - public static bool IsDirectoryPath(in FspPath path) + public static bool IsDirectoryPath(ref readonly FspPath path) { return IsDirectoryPath(SpanHelpers.AsReadOnlyByteSpan(in path)); } diff --git a/src/LibHac/Fs/Common/SaveDataTypes.cs b/src/LibHac/Fs/Common/SaveDataTypes.cs index f0f8ee0c..23631140 100644 --- a/src/LibHac/Fs/Common/SaveDataTypes.cs +++ b/src/LibHac/Fs/Common/SaveDataTypes.cs @@ -265,8 +265,8 @@ public struct SaveDataCreationInfo2 public int MetaSize; public Array356 Reserved4; - public static Result Make(out SaveDataCreationInfo2 creationInfo, in SaveDataAttribute attribute, long size, - long journalSize, long blockSize, ulong ownerId, SaveDataFlags flags, SaveDataSpaceId spaceId, + public static Result Make(out SaveDataCreationInfo2 creationInfo, in SaveDataAttribute attribute, + long size, long journalSize, long blockSize, ulong ownerId, SaveDataFlags flags, SaveDataSpaceId spaceId, SaveDataFormatType formatType) { UnsafeHelpers.SkipParamInit(out creationInfo); diff --git a/src/LibHac/Fs/Fsa/IAttributeFileSystem.cs b/src/LibHac/Fs/Fsa/IAttributeFileSystem.cs index 5401f7a6..6fc24bdd 100644 --- a/src/LibHac/Fs/Fsa/IAttributeFileSystem.cs +++ b/src/LibHac/Fs/Fsa/IAttributeFileSystem.cs @@ -3,28 +3,28 @@ // ReSharper disable once InconsistentNaming public abstract class IAttributeFileSystem : IFileSystem { - public Result CreateDirectory(in Path path, NxFileAttributes archiveAttribute) + public Result CreateDirectory(ref readonly Path path, NxFileAttributes archiveAttribute) { return DoCreateDirectory(in path, archiveAttribute); } - public Result GetFileAttributes(out NxFileAttributes attributes, in Path path) + public Result GetFileAttributes(out NxFileAttributes attributes, ref readonly Path path) { return DoGetFileAttributes(out attributes, in path); } - public Result SetFileAttributes(in Path path, NxFileAttributes attributes) + public Result SetFileAttributes(ref readonly Path path, NxFileAttributes attributes) { return DoSetFileAttributes(in path, attributes); } - public Result GetFileSize(out long fileSize, in Path path) + public Result GetFileSize(out long fileSize, ref readonly Path path) { return DoGetFileSize(out fileSize, in path); } - protected abstract Result DoCreateDirectory(in Path path, NxFileAttributes archiveAttribute); - protected abstract Result DoGetFileAttributes(out NxFileAttributes attributes, in Path path); - protected abstract Result DoSetFileAttributes(in Path path, NxFileAttributes attributes); - protected abstract Result DoGetFileSize(out long fileSize, in Path path); + protected abstract Result DoCreateDirectory(ref readonly Path path, NxFileAttributes archiveAttribute); + protected abstract Result DoGetFileAttributes(out NxFileAttributes attributes, ref readonly Path path); + protected abstract Result DoSetFileAttributes(ref readonly Path path, NxFileAttributes attributes); + protected abstract Result DoGetFileSize(out long fileSize, ref readonly Path path); } \ No newline at end of file diff --git a/src/LibHac/Fs/Fsa/IFileSystem.cs b/src/LibHac/Fs/Fsa/IFileSystem.cs index 9310b916..ba28aa67 100644 --- a/src/LibHac/Fs/Fsa/IFileSystem.cs +++ b/src/LibHac/Fs/Fsa/IFileSystem.cs @@ -26,7 +26,7 @@ public abstract class IFileSystem : IDisposable /// : The parent directory of the specified path does not exist.
/// : Specified path already exists as either a file or directory.
/// : Insufficient free space to create the file. - public Result CreateFile(in Path path, long size, CreateFileOptions option) + public Result CreateFile(ref readonly Path path, long size, CreateFileOptions option) { if (size < 0) return ResultFs.OutOfRange.Log(); @@ -44,7 +44,7 @@ public abstract class IFileSystem : IDisposable /// : The parent directory of the specified path does not exist.
/// : Specified path already exists as either a file or directory.
/// : Insufficient free space to create the file. - public Result CreateFile(in Path path, long size) + public Result CreateFile(ref readonly Path path, long size) { return CreateFile(in path, size, CreateFileOptions.None); } @@ -55,7 +55,7 @@ public abstract class IFileSystem : IDisposable /// The full path of the file to delete. /// : The operation was successful.
/// : The specified path does not exist or is a directory.
- public Result DeleteFile(in Path path) + public Result DeleteFile(ref readonly Path path) { return DoDeleteFile(in path); } @@ -68,7 +68,7 @@ public abstract class IFileSystem : IDisposable /// : The parent directory of the specified path does not exist.
/// : Specified path already exists as either a file or directory.
/// : Insufficient free space to create the directory. - public Result CreateDirectory(in Path path) + public Result CreateDirectory(ref readonly Path path) { return DoCreateDirectory(in path); } @@ -80,7 +80,7 @@ public abstract class IFileSystem : IDisposable /// : The operation was successful.
/// : The specified path does not exist or is a file.
/// : The specified directory is not empty.
- public Result DeleteDirectory(in Path path) + public Result DeleteDirectory(ref readonly Path path) { return DoDeleteDirectory(in path); } @@ -91,7 +91,7 @@ public abstract class IFileSystem : IDisposable /// The full path of the directory to delete. /// : The operation was successful.
/// : The specified path does not exist or is a file.
- public Result DeleteDirectoryRecursively(in Path path) + public Result DeleteDirectoryRecursively(ref readonly Path path) { return DoDeleteDirectoryRecursively(in path); } @@ -102,7 +102,7 @@ public abstract class IFileSystem : IDisposable /// The full path of the directory to clean. /// : The operation was successful.
/// : The specified path does not exist or is a file.
- public Result CleanDirectoryRecursively(in Path path) + public Result CleanDirectoryRecursively(ref readonly Path path) { return DoCleanDirectoryRecursively(in path); } @@ -119,7 +119,7 @@ public abstract class IFileSystem : IDisposable /// /// If and are the same, this function does nothing and returns successfully. /// - public Result RenameFile(in Path currentPath, in Path newPath) + public Result RenameFile(ref readonly Path currentPath, ref readonly Path newPath) { return DoRenameFile(in currentPath, in newPath); } @@ -137,7 +137,7 @@ public abstract class IFileSystem : IDisposable /// /// If and are the same, this function does nothing and returns . /// - public Result RenameDirectory(in Path currentPath, in Path newPath) + public Result RenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) { return DoRenameDirectory(in currentPath, in newPath); } @@ -149,7 +149,7 @@ public abstract class IFileSystem : IDisposable /// The full path to check. /// : The operation was successful.
/// : The specified path does not exist.
- public Result GetEntryType(out DirectoryEntryType entryType, in Path path) + public Result GetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { return DoGetEntryType(out entryType, in path); } @@ -186,7 +186,7 @@ public abstract class IFileSystem : IDisposable /// : The specified path does not exist or is a directory.
/// : When opening as , /// the file is already opened as . - public Result OpenFile(ref UniqueRef file, in Path path, OpenMode mode) + public Result OpenFile(ref UniqueRef file, ref readonly Path path, OpenMode mode) { if ((mode & OpenMode.ReadWrite) == 0 || (mode & ~OpenMode.All) != 0) return ResultFs.InvalidModeForFileOpen.Log(); @@ -225,7 +225,7 @@ public abstract class IFileSystem : IDisposable /// Specifies which sub-entries should be enumerated. /// : The operation was successful.
/// : The specified path does not exist or is a file.
- public Result OpenDirectory(ref UniqueRef outDirectory, in Path path, OpenDirectoryMode mode) + public Result OpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { if ((mode & OpenDirectoryMode.All) == 0 || (mode & ~(OpenDirectoryMode.All | OpenDirectoryMode.NoFileSize)) != 0) @@ -253,7 +253,7 @@ public abstract class IFileSystem : IDisposable /// If the operation returns successfully, the amount of free space available on the drive, in bytes. /// The path of the drive to query. Unused in almost all cases. /// The of the requested operation. - public Result GetFreeSpaceSize(out long freeSpace, in Path path) + public Result GetFreeSpaceSize(out long freeSpace, ref readonly Path path) { return DoGetFreeSpaceSize(out freeSpace, in path); } @@ -264,7 +264,7 @@ public abstract class IFileSystem : IDisposable /// If the operation returns successfully, the total size of the drive, in bytes. /// The path of the drive to query. Unused in almost all cases. /// The of the requested operation. - public Result GetTotalSpaceSize(out long totalSpace, in Path path) + public Result GetTotalSpaceSize(out long totalSpace, ref readonly Path path) { return DoGetTotalSpaceSize(out totalSpace, in path); } @@ -277,7 +277,7 @@ public abstract class IFileSystem : IDisposable /// The path of the file or directory. /// : The operation was successful.
/// : The specified path does not exist.
- public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) + public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, ref readonly Path path) { return DoGetFileTimeStampRaw(out timeStamp, in path); } @@ -294,9 +294,9 @@ public abstract class IFileSystem : IDisposable /// The type of query to perform. /// The full path of the file to query. /// The of the requested operation. - public Result QueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, in Path path) + public Result QueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, ref readonly Path path) { - return DoQueryEntry(outBuffer, inBuffer, queryId, path); + return DoQueryEntry(outBuffer, inBuffer, queryId, in path); } /// @@ -309,44 +309,44 @@ public abstract class IFileSystem : IDisposable return DoGetFileSystemAttribute(out outAttribute); } - protected abstract Result DoCreateFile(in Path path, long size, CreateFileOptions option); - protected abstract Result DoDeleteFile(in Path path); - protected abstract Result DoCreateDirectory(in Path path); - protected abstract Result DoDeleteDirectory(in Path path); - protected abstract Result DoDeleteDirectoryRecursively(in Path path); - protected abstract Result DoCleanDirectoryRecursively(in Path path); - protected abstract Result DoRenameFile(in Path currentPath, in Path newPath); - protected abstract Result DoRenameDirectory(in Path currentPath, in Path newPath); - protected abstract Result DoGetEntryType(out DirectoryEntryType entryType, in Path path); + protected abstract Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option); + protected abstract Result DoDeleteFile(ref readonly Path path); + protected abstract Result DoCreateDirectory(ref readonly Path path); + protected abstract Result DoDeleteDirectory(ref readonly Path path); + protected abstract Result DoDeleteDirectoryRecursively(ref readonly Path path); + protected abstract Result DoCleanDirectoryRecursively(ref readonly Path path); + protected abstract Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath); + protected abstract Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath); + protected abstract Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path); - protected virtual Result DoGetFreeSpaceSize(out long freeSpace, in Path path) + protected virtual Result DoGetFreeSpaceSize(out long freeSpace, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out freeSpace); return ResultFs.NotImplemented.Log(); } - protected virtual Result DoGetTotalSpaceSize(out long totalSpace, in Path path) + protected virtual Result DoGetTotalSpaceSize(out long totalSpace, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out totalSpace); return ResultFs.NotImplemented.Log(); } - protected abstract Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode); - protected abstract Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, OpenDirectoryMode mode); + protected abstract Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode); + protected abstract Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode); protected abstract Result DoCommit(); protected virtual Result DoCommitProvisionally(long counter) => ResultFs.NotImplemented.Log(); protected virtual Result DoRollback() => ResultFs.NotImplemented.Log(); protected virtual Result DoFlush() => ResultFs.NotImplemented.Log(); - protected virtual Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) + protected virtual Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out timeStamp); return ResultFs.NotImplemented.Log(); } protected virtual Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - in Path path) => ResultFs.NotImplemented.Log(); + ref readonly Path path) => ResultFs.NotImplemented.Log(); protected virtual Result DoGetFileSystemAttribute(out FileSystemAttribute outAttribute) { diff --git a/src/LibHac/Fs/Fsa/Registrar.cs b/src/LibHac/Fs/Fsa/Registrar.cs index 7a21d30d..7bc8f1e5 100644 --- a/src/LibHac/Fs/Fsa/Registrar.cs +++ b/src/LibHac/Fs/Fsa/Registrar.cs @@ -49,43 +49,43 @@ public static class Registrar base.Dispose(); } - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) => + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) => _fileSystem.Get.CreateFile(in path, size, option); - protected override Result DoDeleteFile(in Path path) => _fileSystem.Get.DeleteFile(in path); + protected override Result DoDeleteFile(ref readonly Path path) => _fileSystem.Get.DeleteFile(in path); - protected override Result DoCreateDirectory(in Path path) => _fileSystem.Get.CreateDirectory(in path); + protected override Result DoCreateDirectory(ref readonly Path path) => _fileSystem.Get.CreateDirectory(in path); - protected override Result DoDeleteDirectory(in Path path) => _fileSystem.Get.DeleteDirectory(in path); + protected override Result DoDeleteDirectory(ref readonly Path path) => _fileSystem.Get.DeleteDirectory(in path); - protected override Result DoDeleteDirectoryRecursively(in Path path) => + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) => _fileSystem.Get.DeleteDirectoryRecursively(in path); - protected override Result DoCleanDirectoryRecursively(in Path path) => + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) => _fileSystem.Get.CleanDirectoryRecursively(in path); - protected override Result DoRenameFile(in Path currentPath, in Path newPath) => + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) => _fileSystem.Get.RenameFile(in currentPath, in newPath); - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) => + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) => _fileSystem.Get.RenameDirectory(in currentPath, in newPath); - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) => + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) => _fileSystem.Get.GetEntryType(out entryType, in path); - protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) => + protected override Result DoGetFreeSpaceSize(out long freeSpace, ref readonly Path path) => _fileSystem.Get.GetFreeSpaceSize(out freeSpace, in path); protected override Result DoGetFileSystemAttribute(out FileSystemAttribute outAttribute) => _fileSystem.Get.GetFileSystemAttribute(out outAttribute); - protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) => + protected override Result DoGetTotalSpaceSize(out long totalSpace, ref readonly Path path) => _fileSystem.Get.GetTotalSpaceSize(out totalSpace, in path); - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) => + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) => _fileSystem.Get.OpenFile(ref outFile, in path, mode); - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) => _fileSystem.Get.OpenDirectory(ref outDirectory, in path, mode); @@ -98,11 +98,11 @@ public static class Registrar protected override Result DoFlush() => _fileSystem.Get.Flush(); - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) => + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, ref readonly Path path) => _fileSystem.Get.GetFileTimeStampRaw(out timeStamp, in path); protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - in Path path) => _fileSystem.Get.QueryEntry(outBuffer, inBuffer, queryId, in path); + ref readonly Path path) => _fileSystem.Get.QueryEntry(outBuffer, inBuffer, queryId, in path); } public static Result Register(this FileSystemClient fs, U8Span name, ref UniqueRef fileSystem) diff --git a/src/LibHac/Fs/Fsa/UserFileSystem.cs b/src/LibHac/Fs/Fsa/UserFileSystem.cs index c5281a5f..14f9e97b 100644 --- a/src/LibHac/Fs/Fsa/UserFileSystem.cs +++ b/src/LibHac/Fs/Fsa/UserFileSystem.cs @@ -738,7 +738,7 @@ public static class UserFileSystem ? SaveDataFlags.Restore : SaveDataFlags.None; - return fs.Impl.WriteSaveDataFileSystemExtraData(SaveDataSpaceId.User, in attribute, in extraData, + return fs.Impl.WriteSaveDataFileSystemExtraData(SaveDataSpaceId.User, attribute, in extraData, in extraDataMask); } } diff --git a/src/LibHac/Fs/ReadOnlyFileSystem.cs b/src/LibHac/Fs/ReadOnlyFileSystem.cs index 54458dd7..60469a1b 100644 --- a/src/LibHac/Fs/ReadOnlyFileSystem.cs +++ b/src/LibHac/Fs/ReadOnlyFileSystem.cs @@ -90,7 +90,7 @@ public class ReadOnlyFileSystem : IFileSystem base.Dispose(); } - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { // The Read flag must be the only flag set if ((mode & OpenMode.All) != OpenMode.Read) @@ -104,40 +104,40 @@ public class ReadOnlyFileSystem : IFileSystem return Result.Success; } - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { // An IDirectory is already read-only so we don't need a wrapper ReadOnlyDictionary class return _baseFileSystem.Get.OpenDirectory(ref outDirectory, in path, mode); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { return _baseFileSystem.Get.GetEntryType(out entryType, in path); } - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) => + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); - protected override Result DoDeleteFile(in Path path) => + protected override Result DoDeleteFile(ref readonly Path path) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); - protected override Result DoCreateDirectory(in Path path) => + protected override Result DoCreateDirectory(ref readonly Path path) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); - protected override Result DoDeleteDirectory(in Path path) => + protected override Result DoDeleteDirectory(ref readonly Path path) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); - protected override Result DoDeleteDirectoryRecursively(in Path path) => + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); - protected override Result DoCleanDirectoryRecursively(in Path path) => + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); - protected override Result DoRenameFile(in Path currentPath, in Path newPath) => + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) => + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) => ResultFs.UnsupportedWriteForReadOnlyFileSystem.Log(); protected override Result DoCommit() => @@ -146,12 +146,12 @@ public class ReadOnlyFileSystem : IFileSystem protected override Result DoCommitProvisionally(long counter) => ResultFs.UnsupportedCommitProvisionallyForReadOnlyFileSystem.Log(); - protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, ref readonly Path path) { return _baseFileSystem.Get.GetFreeSpaceSize(out freeSpace, in path); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, ref readonly Path path) { Unsafe.SkipInit(out totalSpace); return ResultFs.UnsupportedGetTotalSpaceSizeForReadOnlyFileSystem.Log(); diff --git a/src/LibHac/Fs/Shim/FileSystemServiceObjectAdapter.cs b/src/LibHac/Fs/Shim/FileSystemServiceObjectAdapter.cs index fa3233c5..4e890930 100644 --- a/src/LibHac/Fs/Shim/FileSystemServiceObjectAdapter.cs +++ b/src/LibHac/Fs/Shim/FileSystemServiceObjectAdapter.cs @@ -123,7 +123,7 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget { private SharedRef _baseFs; - private static Result GetPathForServiceObject(out PathSf sfPath, in Path path) + private static Result GetPathForServiceObject(out PathSf sfPath, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out sfPath); @@ -147,7 +147,7 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget base.Dispose(); } - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) { Result res = GetPathForServiceObject(out PathSf sfPath, in path); if (res.IsFailure()) return res.Miss(); @@ -155,7 +155,7 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget return _baseFs.Get.CreateFile(in sfPath, size, (int)option); } - protected override Result DoDeleteFile(in Path path) + protected override Result DoDeleteFile(ref readonly Path path) { Result res = GetPathForServiceObject(out PathSf sfPath, in path); if (res.IsFailure()) return res.Miss(); @@ -163,7 +163,7 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget return _baseFs.Get.DeleteFile(in sfPath); } - protected override Result DoCreateDirectory(in Path path) + protected override Result DoCreateDirectory(ref readonly Path path) { Result res = GetPathForServiceObject(out PathSf sfPath, in path); if (res.IsFailure()) return res.Miss(); @@ -171,7 +171,7 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget return _baseFs.Get.CreateDirectory(in sfPath); } - protected override Result DoDeleteDirectory(in Path path) + protected override Result DoDeleteDirectory(ref readonly Path path) { Result res = GetPathForServiceObject(out PathSf sfPath, in path); if (res.IsFailure()) return res.Miss(); @@ -179,7 +179,7 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget return _baseFs.Get.DeleteDirectory(in sfPath); } - protected override Result DoDeleteDirectoryRecursively(in Path path) + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) { Result res = GetPathForServiceObject(out PathSf sfPath, in path); if (res.IsFailure()) return res.Miss(); @@ -187,7 +187,7 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget return _baseFs.Get.DeleteDirectoryRecursively(in sfPath); } - protected override Result DoCleanDirectoryRecursively(in Path path) + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) { Result res = GetPathForServiceObject(out PathSf sfPath, in path); if (res.IsFailure()) return res.Miss(); @@ -195,7 +195,7 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget return _baseFs.Get.CleanDirectoryRecursively(in sfPath); } - protected override Result DoRenameFile(in Path currentPath, in Path newPath) + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) { Result res = GetPathForServiceObject(out PathSf currentSfPath, in currentPath); if (res.IsFailure()) return res.Miss(); @@ -206,7 +206,7 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget return _baseFs.Get.RenameFile(in currentSfPath, in newSfPath); } - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) { Result res = GetPathForServiceObject(out PathSf currentSfPath, in currentPath); if (res.IsFailure()) return res.Miss(); @@ -217,7 +217,7 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget return _baseFs.Get.RenameDirectory(in currentSfPath, in newSfPath); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out entryType); @@ -229,7 +229,7 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget return _baseFs.Get.GetEntryType(out sfEntryType, in sfPath); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out freeSpace); @@ -239,7 +239,7 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget return _baseFs.Get.GetFreeSpaceSize(out freeSpace, in sfPath); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out totalSpace); @@ -249,7 +249,7 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget return _baseFs.Get.GetTotalSpaceSize(out totalSpace, in sfPath); } - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { Result res = GetPathForServiceObject(out PathSf sfPath, in path); if (res.IsFailure()) return res.Miss(); @@ -263,7 +263,7 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget return Result.Success; } - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { Result res = GetPathForServiceObject(out PathSf sfPath, in path); @@ -283,7 +283,7 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget return _baseFs.Get.Commit(); } - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out timeStamp); @@ -299,7 +299,7 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget } protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - in Path path) + ref readonly Path path) { Result res = GetPathForServiceObject(out PathSf sfPath, in path); if (res.IsFailure()) return res.Miss(); diff --git a/src/LibHac/Fs/Shim/Host.cs b/src/LibHac/Fs/Shim/Host.cs index b6c7241a..8b853434 100644 --- a/src/LibHac/Fs/Shim/Host.cs +++ b/src/LibHac/Fs/Shim/Host.cs @@ -37,7 +37,7 @@ public static class Host /// Options for opening the host file system. /// The of the operation. private static Result OpenHostFileSystemImpl(FileSystemClient fs, ref UniqueRef outFileSystem, - in FspPath path, MountHostOption option) + ref readonly FspPath path, MountHostOption option) { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var fileSystem = new SharedRef(); diff --git a/src/LibHac/Fs/Shim/PathBasedFileDataCache.cs b/src/LibHac/Fs/Shim/PathBasedFileDataCache.cs index 30499df5..4956a8c7 100644 --- a/src/LibHac/Fs/Shim/PathBasedFileDataCache.cs +++ b/src/LibHac/Fs/Shim/PathBasedFileDataCache.cs @@ -19,7 +19,7 @@ public static class PathBasedFileDataCacheShim } internal static void InvalidatePathBasedFileDataCacheEntry(this FileSystemClientImpl fs, - FileSystemAccessor fsAccessor, in Path path) + FileSystemAccessor fsAccessor, ref readonly Path path) { throw new NotImplementedException(); } @@ -31,7 +31,7 @@ public static class PathBasedFileDataCacheShim } internal static bool FindPathBasedFileDataCacheEntry(this FileSystemClientImpl fs, out FilePathHash outHash, - out int outHashIndex, FileSystemAccessor fsAccessor, in Path path) + out int outHashIndex, FileSystemAccessor fsAccessor, ref readonly Path path) { throw new NotImplementedException(); } diff --git a/src/LibHac/Fs/Shim/SaveDataManagement.cs b/src/LibHac/Fs/Shim/SaveDataManagement.cs index 0895d360..439ab99c 100644 --- a/src/LibHac/Fs/Shim/SaveDataManagement.cs +++ b/src/LibHac/Fs/Shim/SaveDataManagement.cs @@ -157,7 +157,7 @@ namespace LibHac.Fs.Shim } public static Result ReadSaveDataFileSystemExtraData(this FileSystemClientImpl fs, - out SaveDataExtraData extraData, SaveDataSpaceId spaceId, in SaveDataAttribute attribute) + out SaveDataExtraData extraData, SaveDataSpaceId spaceId, SaveDataAttribute attribute) { UnsafeHelpers.SkipParamInit(out extraData); @@ -171,7 +171,7 @@ namespace LibHac.Fs.Shim } public static Result ReadSaveDataFileSystemExtraData(this FileSystemClientImpl fs, - out SaveDataExtraData extraData, SaveDataSpaceId spaceId, in SaveDataAttribute attribute, + out SaveDataExtraData extraData, SaveDataSpaceId spaceId, SaveDataAttribute attribute, in SaveDataExtraData extraDataMask) { UnsafeHelpers.SkipParamInit(out extraData); @@ -262,7 +262,7 @@ namespace LibHac.Fs.Shim /// to write to, nothing will be written and will be returned. /// public static Result WriteSaveDataFileSystemExtraData(this FileSystemClientImpl fs, SaveDataSpaceId spaceId, - in SaveDataAttribute attribute, in SaveDataExtraData extraData, in SaveDataExtraData extraDataMask) + SaveDataAttribute attribute, in SaveDataExtraData extraData, in SaveDataExtraData extraDataMask) { using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); @@ -1359,7 +1359,7 @@ namespace LibHac.Fs.Shim SaveDataType.System, userId, saveDataId); if (res.IsFailure()) return res.Miss(); - res = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, in attribute); + res = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, attribute); if (res.IsFailure()) return res.Miss(); flags = extraData.Flags; @@ -1456,7 +1456,7 @@ namespace LibHac.Fs.Shim SaveDataType.System, userId, saveDataId); if (res.IsFailure()) return res.Miss(); - return fs.Impl.WriteSaveDataFileSystemExtraData(spaceId, in attribute, in extraData, in extraDataMask); + return fs.Impl.WriteSaveDataFileSystemExtraData(spaceId, attribute, in extraData, in extraDataMask); } } @@ -2253,7 +2253,7 @@ namespace LibHac.Fs.Shim extraDataMask.Flags = SaveDataFlags.Restore; res = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, SaveDataSpaceId.User, - in attribute, in extraDataMask); + attribute, in extraDataMask); if (res.IsFailure()) return res.Miss(); isRestoreFlagSet = extraData.Flags.HasFlag(SaveDataFlags.Restore); @@ -2303,7 +2303,7 @@ namespace LibHac.Fs.Shim if (res.IsFailure()) return res.Miss(); res = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, SaveDataSpaceId.User, - in attribute, in extraDataMask); + attribute, in extraDataMask); if (res.IsFailure()) return res.Miss(); saveSize = extraData.DataSize; diff --git a/src/LibHac/Fs/Shim/SdCard.cs b/src/LibHac/Fs/Shim/SdCard.cs index fd4b4b57..9d4e6312 100644 --- a/src/LibHac/Fs/Shim/SdCard.cs +++ b/src/LibHac/Fs/Shim/SdCard.cs @@ -26,7 +26,7 @@ public static class SdCard return OpenFileSystem(fs, in fileSystemProxy, ref outFileSystem); - static Result OpenFileSystem(FileSystemClient fs, in SharedRef fileSystemProxy, + static Result OpenFileSystem(FileSystemClient fs, ref readonly SharedRef fileSystemProxy, ref SharedRef outFileSystem) { // Retry a few times if the storage device isn't ready yet @@ -261,7 +261,7 @@ public static class SdCard outMode = (SdCardSpeedMode)speedMode; return Result.Success; - static Result GetSpeedMode(FileSystemClient fs, in SharedRef deviceOperator, + static Result GetSpeedMode(FileSystemClient fs, ref readonly SharedRef deviceOperator, out long outSpeedMode) { outSpeedMode = 0; @@ -305,7 +305,7 @@ public static class SdCard return Result.Success; - static Result GetCid(FileSystemClient fs, in SharedRef deviceOperator, Span outCidBuffer) + static Result GetCid(FileSystemClient fs, ref readonly SharedRef deviceOperator, Span outCidBuffer) { // Retry a few times if the storage device isn't ready yet const int maxRetries = 10; @@ -348,7 +348,7 @@ public static class SdCard return Result.Success; - static Result GetUserAreaSize(FileSystemClient fs, in SharedRef deviceOperator, + static Result GetUserAreaSize(FileSystemClient fs, ref readonly SharedRef deviceOperator, out long outSize) { outSize = 0; @@ -394,7 +394,7 @@ public static class SdCard return Result.Success; - static Result GetProtectedAreaSize(FileSystemClient fs, in SharedRef deviceOperator, + static Result GetProtectedAreaSize(FileSystemClient fs, ref readonly SharedRef deviceOperator, out long outSize) { outSize = 0; @@ -442,7 +442,7 @@ public static class SdCard outLogSize = logSize; return Result.Success; - static Result GetErrorInfo(FileSystemClient fs, in SharedRef deviceOperator, + static Result GetErrorInfo(FileSystemClient fs, ref readonly SharedRef deviceOperator, out StorageErrorInfo outErrorInfo, out long outLogSize, Span logBuffer) { UnsafeHelpers.SkipParamInit(out outErrorInfo, out outLogSize); @@ -482,7 +482,7 @@ public static class SdCard return Result.Success; - static Result Format(FileSystemClient fs, in SharedRef fileSystemProxy) + static Result Format(FileSystemClient fs, ref readonly SharedRef fileSystemProxy) { // Retry a few times if the storage device isn't ready yet const int maxRetries = 10; diff --git a/src/LibHac/Fs/SubStorage.cs b/src/LibHac/Fs/SubStorage.cs index 998524e7..c5f53a45 100644 --- a/src/LibHac/Fs/SubStorage.cs +++ b/src/LibHac/Fs/SubStorage.cs @@ -106,7 +106,7 @@ public class SubStorage : IStorage /// The base . /// The offset in the base storage at which to begin the created SubStorage. /// The size of the created SubStorage. - public SubStorage(in SharedRef baseStorage, long offset, long size) + public SubStorage(ref readonly SharedRef baseStorage, long offset, long size) { BaseStorage = baseStorage.Get; _offset = offset; diff --git a/src/LibHac/Fs/ValueSubStorage.cs b/src/LibHac/Fs/ValueSubStorage.cs index 440dad33..6151d0f8 100644 --- a/src/LibHac/Fs/ValueSubStorage.cs +++ b/src/LibHac/Fs/ValueSubStorage.cs @@ -23,7 +23,7 @@ public struct ValueSubStorage : IDisposable _sharedBaseStorage = new SharedRef(); } - public ValueSubStorage(in ValueSubStorage other) + public ValueSubStorage(ref readonly ValueSubStorage other) { _baseStorage = other._baseStorage; _offset = other._offset; @@ -45,7 +45,7 @@ public struct ValueSubStorage : IDisposable Assert.SdkRequiresLessEqual(0, size); } - public ValueSubStorage(in ValueSubStorage subStorage, long offset, long size) + public ValueSubStorage(ref readonly ValueSubStorage subStorage, long offset, long size) { _baseStorage = subStorage._baseStorage; _offset = subStorage._offset + offset; @@ -59,7 +59,7 @@ public struct ValueSubStorage : IDisposable Assert.SdkRequiresGreaterEqual(subStorage._size, offset + size); } - public ValueSubStorage(in SharedRef baseStorage, long offset, long size) + public ValueSubStorage(ref readonly SharedRef baseStorage, long offset, long size) { _baseStorage = baseStorage.Get; _offset = offset; @@ -88,7 +88,7 @@ public struct ValueSubStorage : IDisposable return new SubStorage(_baseStorage, _offset, _size); } - public void Set(in ValueSubStorage other) + public void Set(ref readonly ValueSubStorage other) { if (!Unsafe.AreSame(ref Unsafe.AsRef(in this), ref Unsafe.AsRef(in other))) { diff --git a/src/LibHac/FsSrv/BaseFileSystemService.cs b/src/LibHac/FsSrv/BaseFileSystemService.cs index 639d6603..f9950bd9 100644 --- a/src/LibHac/FsSrv/BaseFileSystemService.cs +++ b/src/LibHac/FsSrv/BaseFileSystemService.cs @@ -85,7 +85,7 @@ public readonly struct BaseFileSystemService return _serviceImpl.FormatBaseFileSystem(fileSystemId); } - public Result OpenBisFileSystem(ref SharedRef outFileSystem, in FspPath rootPath, + public Result OpenBisFileSystem(ref SharedRef outFileSystem, ref readonly FspPath rootPath, BisPartitionId partitionId) { Result res = GetProgramInfo(out ProgramInfo programInfo); @@ -150,7 +150,7 @@ public readonly struct BaseFileSystemService return Result.Success; } - public Result SetBisRootForHost(BisPartitionId partitionId, in FspPath path) + public Result SetBisRootForHost(BisPartitionId partitionId, ref readonly FspPath path) { throw new NotImplementedException(); } diff --git a/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs b/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs index bf6187bd..7bcf0ed1 100644 --- a/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs +++ b/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs @@ -78,7 +78,7 @@ public class FileSystemProxyCoreImpl return Result.Success; } - private Result OpenHostFileSystem(ref SharedRef outFileSystem, in Path path) + private Result OpenHostFileSystem(ref SharedRef outFileSystem, ref readonly Path path) { using var pathHost = new Path(); Result res = pathHost.Initialize(in path); @@ -88,13 +88,13 @@ public class FileSystemProxyCoreImpl if (res.IsFailure()) return res.Miss(); res = _fsCreators.TargetManagerFileSystemCreator.Create(ref outFileSystem, in pathHost, isSupported, - ensureRootPathExists: false, Result.Success); + ensureRootPathExists: false, pathNotFoundResult: Result.Success); if (res.IsFailure()) return res.Miss(); return Result.Success; } - public Result OpenHostFileSystem(ref SharedRef outFileSystem, in Path path, + public Result OpenHostFileSystem(ref SharedRef outFileSystem, ref readonly Path path, bool openCaseSensitive) { if (!path.IsEmpty() && openCaseSensitive) @@ -105,7 +105,7 @@ public class FileSystemProxyCoreImpl else { Result res = _fsCreators.TargetManagerFileSystemCreator.Create(ref outFileSystem, in path, - openCaseSensitive, ensureRootPathExists: false, Result.Success); + openCaseSensitive, ensureRootPathExists: false, pathNotFoundResult: Result.Success); if (res.IsFailure()) return res.Miss(); } diff --git a/src/LibHac/FsSrv/FileSystemProxyImpl.cs b/src/LibHac/FsSrv/FileSystemProxyImpl.cs index b8c75da2..4b3b1d5f 100644 --- a/src/LibHac/FsSrv/FileSystemProxyImpl.cs +++ b/src/LibHac/FsSrv/FileSystemProxyImpl.cs @@ -153,7 +153,7 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader return new DebugConfigurationService(_fsServer, Globals.DebugConfigurationServiceImpl, _currentProcess); } - public Result OpenFileSystemWithId(ref SharedRef outFileSystem, in FspPath path, + public Result OpenFileSystemWithId(ref SharedRef outFileSystem, ref readonly FspPath path, ulong id, FileSystemProxyType fsType) { Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); @@ -172,7 +172,7 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader } public Result OpenCodeFileSystem(ref SharedRef fileSystem, - out CodeVerificationData verificationData, in FspPath path, ProgramId programId) + out CodeVerificationData verificationData, ref readonly FspPath path, ProgramId programId) { UnsafeHelpers.SkipParamInit(out verificationData); @@ -251,7 +251,7 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader return ncaFsService.OpenDataStorageByDataId(ref outStorage, dataId, storageId); } - public Result OpenDataStorageByPath(ref SharedRef outFileSystem, in FspPath path, + public Result OpenDataStorageByPath(ref SharedRef outFileSystem, ref readonly FspPath path, FileSystemProxyType fsType) { Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); @@ -478,7 +478,7 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader return GetBaseFileSystemService().FormatBaseFileSystem(fileSystemId); } - public Result OpenBisFileSystem(ref SharedRef outFileSystem, in FspPath rootPath, + public Result OpenBisFileSystem(ref SharedRef outFileSystem, ref readonly FspPath rootPath, BisPartitionId partitionId) { return GetBaseFileSystemService().OpenBisFileSystem(ref outFileSystem, in rootPath, partitionId); @@ -494,13 +494,13 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader return GetBaseStorageService().InvalidateBisCache(); } - public Result OpenHostFileSystem(ref SharedRef outFileSystem, in FspPath path) + public Result OpenHostFileSystem(ref SharedRef outFileSystem, ref readonly FspPath path) { return OpenHostFileSystemWithOption(ref outFileSystem, in path, MountHostOption.None); } public Result OpenHostFileSystemWithOption(ref SharedRef outFileSystem, - in FspPath path, MountHostOption option) + ref readonly FspPath path, MountHostOption option) { Result res = GetProgramInfo(out ProgramInfo programInfo); if (res.IsFailure()) return res.Miss(); @@ -783,7 +783,7 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader return Result.Success; } - public Result SetSaveDataRootPath(in FspPath path) + public Result SetSaveDataRootPath(ref readonly FspPath path) { Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); if (res.IsFailure()) return res.Miss(); @@ -919,12 +919,13 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader return ncaFsService.GetRightsId(out rightsId, programId, storageId); } - public Result GetRightsIdByPath(out RightsId rightsId, in FspPath path) + public Result GetRightsIdByPath(out RightsId rightsId, ref readonly FspPath path) { return GetRightsIdAndKeyGenerationByPath(out rightsId, out _, in path); } - public Result GetRightsIdAndKeyGenerationByPath(out RightsId rightsId, out byte keyGeneration, in FspPath path) + public Result GetRightsIdAndKeyGenerationByPath(out RightsId rightsId, out byte keyGeneration, + ref readonly FspPath path) { UnsafeHelpers.SkipParamInit(out rightsId, out keyGeneration); @@ -992,7 +993,7 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader .RegisterProgramIndexMapInfo(programIndexMapInfoBuffer, programCount); } - public Result SetBisRootForHost(BisPartitionId partitionId, in FspPath path) + public Result SetBisRootForHost(BisPartitionId partitionId, ref readonly FspPath path) { return GetBaseFileSystemService().SetBisRootForHost(partitionId, in path); } diff --git a/src/LibHac/FsSrv/FsCreator/ILocalFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/ILocalFileSystemCreator.cs index b8737308..ef019306 100644 --- a/src/LibHac/FsSrv/FsCreator/ILocalFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/ILocalFileSystemCreator.cs @@ -6,5 +6,5 @@ namespace LibHac.FsSrv.FsCreator; public interface ILocalFileSystemCreator { - Result Create(ref SharedRef outFileSystem, in Path rootPath, bool openCaseSensitive, bool ensureRootPathExists, Result pathNotFoundResult); + Result Create(ref SharedRef outFileSystem, ref readonly Path rootPath, bool openCaseSensitive, bool ensureRootPathExists, Result pathNotFoundResult); } \ No newline at end of file diff --git a/src/LibHac/FsSrv/FsCreator/ISubDirectoryFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/ISubDirectoryFileSystemCreator.cs index 72c4ac07..e910d5c8 100644 --- a/src/LibHac/FsSrv/FsCreator/ISubDirectoryFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/ISubDirectoryFileSystemCreator.cs @@ -6,5 +6,5 @@ namespace LibHac.FsSrv.FsCreator; public interface ISubDirectoryFileSystemCreator { - Result Create(ref SharedRef outSubDirFileSystem, ref SharedRef baseFileSystem, in Path path); + Result Create(ref SharedRef outSubDirFileSystem, ref SharedRef baseFileSystem, ref readonly Path path); } \ No newline at end of file diff --git a/src/LibHac/FsSrv/FsCreator/ITargetManagerFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/ITargetManagerFileSystemCreator.cs index c1b92611..56113d8d 100644 --- a/src/LibHac/FsSrv/FsCreator/ITargetManagerFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/ITargetManagerFileSystemCreator.cs @@ -6,6 +6,6 @@ namespace LibHac.FsSrv.FsCreator; public interface ITargetManagerFileSystemCreator { - Result Create(ref SharedRef outFileSystem, in Path rootPath, bool openCaseSensitive, bool ensureRootPathExists, Result pathNotFoundResult); + Result Create(ref SharedRef outFileSystem, ref readonly Path rootPath, bool openCaseSensitive, bool ensureRootPathExists, Result pathNotFoundResult); Result NormalizeCaseOfPath(out bool isSupported, ref Path path); } \ No newline at end of file diff --git a/src/LibHac/FsSrv/FsCreator/SaveDataResultConvertFileSystem.cs b/src/LibHac/FsSrv/FsCreator/SaveDataResultConvertFileSystem.cs index 732c067c..2c853ae2 100644 --- a/src/LibHac/FsSrv/FsCreator/SaveDataResultConvertFileSystem.cs +++ b/src/LibHac/FsSrv/FsCreator/SaveDataResultConvertFileSystem.cs @@ -82,7 +82,7 @@ public class SaveDataResultConvertFileSystem : IResultConvertFileSystem outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { using var file = new UniqueRef(); Result res = ConvertResult(GetFileSystem().OpenFile(ref file.Ref, in path, mode)); @@ -95,7 +95,7 @@ public class SaveDataResultConvertFileSystem : IResultConvertFileSystem outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { using var directory = new UniqueRef(); diff --git a/src/LibHac/FsSrv/FsCreator/SubDirectoryFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/SubDirectoryFileSystemCreator.cs index 0ad03f84..a3aa90d8 100644 --- a/src/LibHac/FsSrv/FsCreator/SubDirectoryFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/SubDirectoryFileSystemCreator.cs @@ -8,7 +8,7 @@ namespace LibHac.FsSrv.FsCreator; public class SubDirectoryFileSystemCreator : ISubDirectoryFileSystemCreator { public Result Create(ref SharedRef outSubDirFileSystem, ref SharedRef baseFileSystem, - in Path path) + ref readonly Path path) { using var directory = new UniqueRef(); diff --git a/src/LibHac/FsSrv/FsCreator/TargetManagerFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/TargetManagerFileSystemCreator.cs index 581d1e9f..f84078dd 100644 --- a/src/LibHac/FsSrv/FsCreator/TargetManagerFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/TargetManagerFileSystemCreator.cs @@ -7,7 +7,7 @@ namespace LibHac.FsSrv.FsCreator; public class TargetManagerFileSystemCreator : ITargetManagerFileSystemCreator { - public Result Create(ref SharedRef outFileSystem, in Path rootPath, bool openCaseSensitive, + public Result Create(ref SharedRef outFileSystem, ref readonly Path rootPath, bool openCaseSensitive, bool ensureRootPathExists, Result pathNotFoundResult) { throw new NotImplementedException(); diff --git a/src/LibHac/FsSrv/Impl/AsynchronousAccessFileSystem.cs b/src/LibHac/FsSrv/Impl/AsynchronousAccessFileSystem.cs index 4b50c4c6..e9ed2397 100644 --- a/src/LibHac/FsSrv/Impl/AsynchronousAccessFileSystem.cs +++ b/src/LibHac/FsSrv/Impl/AsynchronousAccessFileSystem.cs @@ -12,9 +12,9 @@ public class AsynchronousAccessFileSystem : ForwardingFileSystem { } // ReSharper disable once RedundantOverriddenMember - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { // Todo: Implement - return base.DoOpenFile(ref outFile, path, mode); + return base.DoOpenFile(ref outFile, in path, mode); } } \ No newline at end of file diff --git a/src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs b/src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs index 1179a4e6..cb6435b0 100644 --- a/src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs +++ b/src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs @@ -36,9 +36,9 @@ public class DeepRetryFileSystem : ForwardingFileSystem } // ReSharper disable once RedundantOverriddenMember - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { // Todo: Implement - return base.DoOpenFile(ref outFile, path, mode); + return base.DoOpenFile(ref outFile, in path, mode); } } \ No newline at end of file diff --git a/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs b/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs index 36a63b1f..43a157e1 100644 --- a/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs +++ b/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs @@ -295,7 +295,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf private static ReadOnlySpan RootDir => "/"u8; - private Result SetUpPath(ref Path fsPath, in PathSf sfPath) + private Result SetUpPath(ref Path fsPath, ref readonly PathSf sfPath) { Result res; @@ -316,7 +316,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return Result.Success; } - public Result CreateFile(in PathSf path, long size, int option) + public Result CreateFile(ref readonly PathSf path, long size, int option) { if (size < 0) return ResultFs.InvalidSize.Log(); @@ -331,7 +331,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return Result.Success; } - public Result DeleteFile(in PathSf path) + public Result DeleteFile(ref readonly PathSf path) { using var pathNormalized = new Path(); Result res = SetUpPath(ref pathNormalized.Ref(), in path); @@ -343,7 +343,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return Result.Success; } - public Result CreateDirectory(in PathSf path) + public Result CreateDirectory(ref readonly PathSf path) { using var pathNormalized = new Path(); Result res = SetUpPath(ref pathNormalized.Ref(), in path); @@ -358,7 +358,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return Result.Success; } - public Result DeleteDirectory(in PathSf path) + public Result DeleteDirectory(ref readonly PathSf path) { using var pathNormalized = new Path(); Result res = SetUpPath(ref pathNormalized.Ref(), in path); @@ -373,7 +373,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return Result.Success; } - public Result DeleteDirectoryRecursively(in PathSf path) + public Result DeleteDirectoryRecursively(ref readonly PathSf path) { using var pathNormalized = new Path(); Result res = SetUpPath(ref pathNormalized.Ref(), in path); @@ -388,7 +388,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return Result.Success; } - public Result CleanDirectoryRecursively(in PathSf path) + public Result CleanDirectoryRecursively(ref readonly PathSf path) { using var pathNormalized = new Path(); Result res = SetUpPath(ref pathNormalized.Ref(), in path); @@ -400,7 +400,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return Result.Success; } - public Result RenameFile(in PathSf currentPath, in PathSf newPath) + public Result RenameFile(ref readonly PathSf currentPath, ref readonly PathSf newPath) { using var currentPathNormalized = new Path(); Result res = SetUpPath(ref currentPathNormalized.Ref(), in currentPath); @@ -416,7 +416,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return Result.Success; } - public Result RenameDirectory(in PathSf currentPath, in PathSf newPath) + public Result RenameDirectory(ref readonly PathSf currentPath, ref readonly PathSf newPath) { using var currentPathNormalized = new Path(); Result res = SetUpPath(ref currentPathNormalized.Ref(), in currentPath); @@ -435,7 +435,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return Result.Success; } - public Result GetEntryType(out uint entryType, in PathSf path) + public Result GetEntryType(out uint entryType, ref readonly PathSf path) { UnsafeHelpers.SkipParamInit(out entryType); @@ -450,7 +450,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return Result.Success; } - public Result GetFreeSpaceSize(out long freeSpace, in PathSf path) + public Result GetFreeSpaceSize(out long freeSpace, ref readonly PathSf path) { UnsafeHelpers.SkipParamInit(out freeSpace); @@ -465,7 +465,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return Result.Success; } - public Result GetTotalSpaceSize(out long totalSpace, in PathSf path) + public Result GetTotalSpaceSize(out long totalSpace, ref readonly PathSf path) { UnsafeHelpers.SkipParamInit(out totalSpace); @@ -480,7 +480,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return Result.Success; } - public Result OpenFile(ref SharedRef outFile, in PathSf path, uint mode) + public Result OpenFile(ref SharedRef outFile, ref readonly PathSf path, uint mode) { const int maxTryCount = 2; @@ -510,7 +510,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return Result.Success; } - public Result OpenDirectory(ref SharedRef outDirectory, in PathSf path, uint mode) + public Result OpenDirectory(ref SharedRef outDirectory, ref readonly PathSf path, uint mode) { const int maxTryCount = 2; @@ -546,7 +546,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return _baseFileSystem.Get.Commit(); } - public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in PathSf path) + public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, ref readonly PathSf path) { UnsafeHelpers.SkipParamInit(out timeStamp); @@ -561,7 +561,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return Result.Success; } - public Result QueryEntry(OutBuffer outBuffer, InBuffer inBuffer, int queryId, in PathSf path) + public Result QueryEntry(OutBuffer outBuffer, InBuffer inBuffer, int queryId, ref readonly PathSf path) { static Result PermissionCheck(QueryId queryId, FileSystemInterfaceAdapter fsAdapter) { diff --git a/src/LibHac/FsSrv/Impl/FileSystemProxyServiceObject.cs b/src/LibHac/FsSrv/Impl/FileSystemProxyServiceObject.cs index 595cd5f7..0f09a232 100644 --- a/src/LibHac/FsSrv/Impl/FileSystemProxyServiceObject.cs +++ b/src/LibHac/FsSrv/Impl/FileSystemProxyServiceObject.cs @@ -48,7 +48,7 @@ public static class FileSystemProxyServiceObject } public Result OpenCodeFileSystem(ref SharedRef fileSystem, - out CodeVerificationData verificationData, in FspPath path, ProgramId programId) + out CodeVerificationData verificationData, ref readonly FspPath path, ProgramId programId) { UnsafeHelpers.SkipParamInit(out verificationData); diff --git a/src/LibHac/FsSrv/Impl/ISaveDataTransferCoreInterface.cs b/src/LibHac/FsSrv/Impl/ISaveDataTransferCoreInterface.cs index 6b73228e..d1d98aed 100644 --- a/src/LibHac/FsSrv/Impl/ISaveDataTransferCoreInterface.cs +++ b/src/LibHac/FsSrv/Impl/ISaveDataTransferCoreInterface.cs @@ -13,7 +13,7 @@ public interface ISaveDataTransferCoreInterface : IDisposable Result QuerySaveDataTotalSize(out long outTotalSize, long dataSize, long journalSize); Result CheckSaveDataFile(long saveDataId, SaveDataSpaceId spaceId); Result CreateSaveDataFileSystemCore(in SaveDataAttribute attribute, in SaveDataCreationInfo creationInfo, in SaveDataMetaInfo metaInfo, in Optional hashSalt, bool leaveUnfinalized); - Result GetSaveDataInfo(out SaveDataInfo saveInfo, SaveDataSpaceId spaceId, in SaveDataAttribute attribute); + Result GetSaveDataInfo(out SaveDataInfo saveInfo, SaveDataSpaceId spaceId, SaveDataAttribute attribute); Result ReadSaveDataFileSystemExtraDataCore(out SaveDataExtraData extraData, SaveDataSpaceId spaceId, ulong saveDataId, bool isTemporarySaveData); Result WriteSaveDataFileSystemExtraDataCore(SaveDataSpaceId spaceId, ulong saveDataId, in SaveDataExtraData extraData, SaveDataType type, bool updateTimeStamp); Result FinalizeSaveDataCreation(ulong saveDataId, SaveDataSpaceId spaceId); diff --git a/src/LibHac/FsSrv/Impl/LocationResolverSet.cs b/src/LibHac/FsSrv/Impl/LocationResolverSet.cs index f837a064..200950e6 100644 --- a/src/LibHac/FsSrv/Impl/LocationResolverSet.cs +++ b/src/LibHac/FsSrv/Impl/LocationResolverSet.cs @@ -74,7 +74,7 @@ internal class LocationResolverSet : IDisposable } } - private static Result SetUpFsPath(ref Fs.Path outPath, in Lr.Path lrPath) + private static Result SetUpFsPath(ref Fs.Path outPath, ref readonly Lr.Path lrPath) { var pathFlags = new PathFlags(); pathFlags.AllowMountName(); diff --git a/src/LibHac/FsSrv/Impl/OpenCountFileSystem.cs b/src/LibHac/FsSrv/Impl/OpenCountFileSystem.cs index caf4e877..435f38c1 100644 --- a/src/LibHac/FsSrv/Impl/OpenCountFileSystem.cs +++ b/src/LibHac/FsSrv/Impl/OpenCountFileSystem.cs @@ -46,18 +46,18 @@ internal class OpenCountFileSystem : ForwardingFileSystem } // ReSharper disable once RedundantOverriddenMember - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { // Todo: Implement - return base.DoOpenFile(ref outFile, path, mode); + return base.DoOpenFile(ref outFile, in path, mode); } // ReSharper disable once RedundantOverriddenMember - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { // Todo: Implement - return base.DoOpenDirectory(ref outDirectory, path, mode); + return base.DoOpenDirectory(ref outDirectory, in path, mode); } public override void Dispose() diff --git a/src/LibHac/FsSrv/Impl/SaveDataExtraDataAccessorCacheManager.cs b/src/LibHac/FsSrv/Impl/SaveDataExtraDataAccessorCacheManager.cs index d1cb9268..5e16e00c 100644 --- a/src/LibHac/FsSrv/Impl/SaveDataExtraDataAccessorCacheManager.cs +++ b/src/LibHac/FsSrv/Impl/SaveDataExtraDataAccessorCacheManager.cs @@ -24,7 +24,7 @@ public class SaveDataExtraDataAccessorCacheManager : ISaveDataExtraDataAccessorO private readonly SaveDataSpaceId _spaceId; private readonly ulong _saveDataId; - public Cache(in SharedRef accessor, SaveDataSpaceId spaceId, ulong saveDataId) + public Cache(ref readonly SharedRef accessor, SaveDataSpaceId spaceId, ulong saveDataId) { _accessor = new WeakRef(in accessor); _spaceId = spaceId; @@ -74,7 +74,7 @@ public class SaveDataExtraDataAccessorCacheManager : ISaveDataExtraDataAccessorO _accessorList.Clear(); } - public Result Register(in SharedRef accessor, SaveDataSpaceId spaceId, + public Result Register(ref readonly SharedRef accessor, SaveDataSpaceId spaceId, ulong saveDataId) { accessor.Get.RegisterExtraDataAccessorObserver(this, spaceId, saveDataId); diff --git a/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheRegister.cs b/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheRegister.cs index a09c8a59..c6b2993b 100644 --- a/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheRegister.cs +++ b/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheRegister.cs @@ -34,58 +34,58 @@ public class SaveDataFileSystemCacheRegister : IFileSystem base.Dispose(); } - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { return _baseFileSystem.Get.OpenFile(ref outFile, in path, mode); } - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { return _baseFileSystem.Get.OpenDirectory(ref outDirectory, in path, mode); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { return _baseFileSystem.Get.GetEntryType(out entryType, in path); } - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) { return _baseFileSystem.Get.CreateFile(in path, size, option); } - protected override Result DoDeleteFile(in Path path) + protected override Result DoDeleteFile(ref readonly Path path) { return _baseFileSystem.Get.DeleteFile(in path); } - protected override Result DoCreateDirectory(in Path path) + protected override Result DoCreateDirectory(ref readonly Path path) { return _baseFileSystem.Get.CreateDirectory(in path); } - protected override Result DoDeleteDirectory(in Path path) + protected override Result DoDeleteDirectory(ref readonly Path path) { return _baseFileSystem.Get.DeleteDirectory(in path); } - protected override Result DoDeleteDirectoryRecursively(in Path path) + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) { return _baseFileSystem.Get.DeleteDirectoryRecursively(in path); } - protected override Result DoCleanDirectoryRecursively(in Path path) + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) { return _baseFileSystem.Get.CleanDirectoryRecursively(in path); } - protected override Result DoRenameFile(in Path currentPath, in Path newPath) + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) { return _baseFileSystem.Get.RenameFile(in currentPath, in newPath); } - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) { return _baseFileSystem.Get.RenameDirectory(in currentPath, in newPath); } @@ -105,12 +105,12 @@ public class SaveDataFileSystemCacheRegister : IFileSystem return _baseFileSystem.Get.Rollback(); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, ref readonly Path path) { return _baseFileSystem.Get.GetFreeSpaceSize(out freeSpace, in path); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, ref readonly Path path) { return _baseFileSystem.Get.GetTotalSpaceSize(out totalSpace, in path); } diff --git a/src/LibHac/FsSrv/Impl/Utility.cs b/src/LibHac/FsSrv/Impl/Utility.cs index 32bd6fe6..c8df560d 100644 --- a/src/LibHac/FsSrv/Impl/Utility.cs +++ b/src/LibHac/FsSrv/Impl/Utility.cs @@ -16,7 +16,7 @@ internal static class Utility } public static Result CreateSubDirectoryFileSystem(ref SharedRef outSubDirFileSystem, - ref SharedRef baseFileSystem, in Path rootPath) + ref SharedRef baseFileSystem, ref readonly Path rootPath) { if (rootPath.IsEmpty()) { @@ -26,7 +26,7 @@ internal static class Utility // Check if the directory exists using var dir = new UniqueRef(); - Result res = baseFileSystem.Get.OpenDirectory(ref dir.Ref, rootPath, OpenDirectoryMode.Directory); + Result res = baseFileSystem.Get.OpenDirectory(ref dir.Ref, in rootPath, OpenDirectoryMode.Directory); if (res.IsFailure()) return res.Miss(); dir.Reset(); @@ -44,7 +44,7 @@ internal static class Utility } public static Result WrapSubDirectory(ref SharedRef outFileSystem, - ref SharedRef baseFileSystem, in Path rootPath, bool createIfMissing) + ref SharedRef baseFileSystem, ref readonly Path rootPath, bool createIfMissing) { // The path must already exist if we're not automatically creating it if (!createIfMissing) @@ -57,7 +57,7 @@ internal static class Utility Result res = FsSystem.Utility.EnsureDirectory(baseFileSystem.Get, in rootPath); if (res.IsFailure()) return res.Miss(); - return CreateSubDirectoryFileSystem(ref outFileSystem, ref baseFileSystem, rootPath); + return CreateSubDirectoryFileSystem(ref outFileSystem, ref baseFileSystem, in rootPath); } public static long ConvertZeroCommitId(in SaveDataExtraData extraData) diff --git a/src/LibHac/FsSrv/NcaFileSystemService.cs b/src/LibHac/FsSrv/NcaFileSystemService.cs index 383a8355..4ae94b87 100644 --- a/src/LibHac/FsSrv/NcaFileSystemService.cs +++ b/src/LibHac/FsSrv/NcaFileSystemService.cs @@ -168,7 +168,7 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager } public Result OpenCodeFileSystem(ref SharedRef outFileSystem, - out CodeVerificationData verificationData, in FspPath path, ProgramId programId) + out CodeVerificationData verificationData, ref readonly FspPath path, ProgramId programId) { throw new NotImplementedException(); } @@ -178,7 +178,7 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager throw new NotImplementedException(); } - public Result OpenDataStorageByPath(ref SharedRef outFileSystem, in FspPath path, + public Result OpenDataStorageByPath(ref SharedRef outFileSystem, ref readonly FspPath path, FileSystemProxyType fsType) { throw new NotImplementedException(); @@ -225,7 +225,7 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager throw new NotImplementedException(); } - public Result OpenFileSystemWithId(ref SharedRef outFileSystem, in FspPath path, + public Result OpenFileSystemWithId(ref SharedRef outFileSystem, ref readonly FspPath path, ulong id, FileSystemProxyType fsType) { const StorageLayoutType storageFlag = StorageLayoutType.All; @@ -384,7 +384,7 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager return Result.Success; } - public Result GetRightsIdAndKeyGenerationByPath(out RightsId outRightsId, out byte outKeyGeneration, in FspPath path) + public Result GetRightsIdAndKeyGenerationByPath(out RightsId outRightsId, out byte outKeyGeneration, ref readonly FspPath path) { const ulong checkThroughProgramId = ulong.MaxValue; UnsafeHelpers.SkipParamInit(out outRightsId, out outKeyGeneration); diff --git a/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs b/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs index b90cee60..fe6dece2 100644 --- a/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs +++ b/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs @@ -67,23 +67,22 @@ public class NcaFileSystemServiceImpl public bool CanMountNca; } - public Result OpenFileSystem(ref SharedRef outFileSystem, in Path path, FileSystemProxyType type, - ulong id, bool isDirectory) + public Result OpenFileSystem(ref SharedRef outFileSystem, ref readonly Path path, + FileSystemProxyType type, ulong id, bool isDirectory) { - return OpenFileSystem(ref outFileSystem, out Unsafe.NullRef(), in path, type, false, - id, isDirectory); + return OpenFileSystem(ref outFileSystem, out Unsafe.NullRef(), in path, type, false, id, + isDirectory); } - public Result OpenFileSystem(ref SharedRef outFileSystem, in Path path, FileSystemProxyType type, - bool canMountSystemDataPrivate, ulong id, bool isDirectory) + public Result OpenFileSystem(ref SharedRef outFileSystem, ref readonly Path path, + FileSystemProxyType type, bool canMountSystemDataPrivate, ulong id, bool isDirectory) { return OpenFileSystem(ref outFileSystem, out Unsafe.NullRef(), in path, type, canMountSystemDataPrivate, id, isDirectory); } - public Result OpenFileSystem(ref SharedRef outFileSystem, - out CodeVerificationData verificationData, in Path path, FileSystemProxyType type, - bool canMountSystemDataPrivate, ulong id, bool isDirectory) + public Result OpenFileSystem(ref SharedRef outFileSystem, out CodeVerificationData verificationData, + ref readonly Path path, FileSystemProxyType type, bool canMountSystemDataPrivate, ulong id, bool isDirectory) { UnsafeHelpers.SkipParamInit(out verificationData); @@ -192,20 +191,20 @@ public class NcaFileSystemServiceImpl } } - public Result OpenDataFileSystem(ref SharedRef outFileSystem, in Path path, + public Result OpenDataFileSystem(ref SharedRef outFileSystem, ref readonly Path path, FileSystemProxyType fsType, ulong programId, bool isDirectory) { throw new NotImplementedException(); } public Result OpenStorageWithPatch(ref SharedRef outStorage, out Hash ncaHeaderDigest, - in Path originalNcaPath, in Path currentNcaPath, FileSystemProxyType fsType, ulong id) + ref readonly Path originalNcaPath, ref readonly Path currentNcaPath, FileSystemProxyType fsType, ulong id) { throw new NotImplementedException(); } - public Result OpenFileSystemWithPatch(ref SharedRef outFileSystem, - in Path originalNcaPath, in Path currentNcaPath, FileSystemProxyType fsType, ulong id) + public Result OpenFileSystemWithPatch(ref SharedRef outFileSystem, ref readonly Path originalNcaPath, + ref readonly Path currentNcaPath, FileSystemProxyType fsType, ulong id) { using var romFsStorage = new SharedRef(); Result res = OpenStorageWithPatch(ref romFsStorage.Ref, out Unsafe.NullRef(), in originalNcaPath, @@ -281,7 +280,7 @@ public class NcaFileSystemServiceImpl return Result.Success; } - public Result GetRightsId(out RightsId rightsId, out byte keyGeneration, in Path path, ProgramId programId) + public Result GetRightsId(out RightsId rightsId, out byte keyGeneration, ref readonly Path path, ProgramId programId) { throw new NotImplementedException(); } @@ -305,7 +304,7 @@ public class NcaFileSystemServiceImpl return Result.Success; } - public Result RegisterUpdatePartition(ulong programId, in Path path) + public Result RegisterUpdatePartition(ulong programId, ref readonly Path path) { throw new NotImplementedException(); } @@ -511,7 +510,7 @@ public class NcaFileSystemServiceImpl return ResultFs.PathNotFound.Log(); } - private Result ParseDir(in Path path, ref SharedRef outContentFileSystem, + private Result ParseDir(ref readonly Path path, ref SharedRef outContentFileSystem, ref SharedRef baseFileSystem, FileSystemProxyType fsType, bool preserveUnc) { using var fileSystem = new SharedRef(); @@ -522,7 +521,7 @@ public class NcaFileSystemServiceImpl } private Result ParseDirWithPathCaseNormalizationOnCaseSensitiveHostFs(ref SharedRef outFileSystem, - in Path path) + ref readonly Path path) { using var pathRoot = new Path(); using var pathData = new Path(); @@ -858,7 +857,7 @@ public class NcaFileSystemServiceImpl _romFsRecoveredByInvalidateCacheCount = 0; } - public Result OpenHostFileSystem(ref SharedRef outFileSystem, in Path rootPath, bool openCaseSensitive) + public Result OpenHostFileSystem(ref SharedRef outFileSystem, ref readonly Path rootPath, bool openCaseSensitive) { return _config.TargetManagerFsCreator.Create(ref outFileSystem, in rootPath, openCaseSensitive, false, Result.Success); diff --git a/src/LibHac/FsSrv/SaveDataFileSystemService.cs b/src/LibHac/FsSrv/SaveDataFileSystemService.cs index 24daa321..8e18d5cd 100644 --- a/src/LibHac/FsSrv/SaveDataFileSystemService.cs +++ b/src/LibHac/FsSrv/SaveDataFileSystemService.cs @@ -739,7 +739,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.NonGameCard); - Result res = GetSaveDataInfo(out SaveDataInfo info, spaceId, in attribute); + Result res = GetSaveDataInfo(out SaveDataInfo info, spaceId, attribute); if (res.IsFailure()) return res; return DeleteSaveDataFileSystemBySaveDataSpaceIdCore(spaceId, info.SaveDataId).Ret(); @@ -776,9 +776,12 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave res = accessor.Get.GetInterface().GetKey(out SaveDataAttribute key, saveDataId); if (res.IsFailure()) return res.Miss(); - Result GetExtraData(out SaveDataExtraData data) => - _serviceImpl.ReadSaveDataFileSystemExtraData(out data, targetSpaceId, saveDataId, key.Type, - _saveDataRootPath.DangerousGetPath()); + + Result GetExtraData(out SaveDataExtraData data) + { + var path = _saveDataRootPath.DangerousGetPath(); + return _serviceImpl.ReadSaveDataFileSystemExtraData(out data, targetSpaceId, saveDataId, key.Type, in path); + } res = SaveDataAccessibilityChecker.CheckDelete(in key, programInfo, GetExtraData); if (res.IsFailure()) return res.Miss(); @@ -842,7 +845,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave throw new NotImplementedException(); } - public Result SetSaveDataRootPath(in FspPath path) + public Result SetSaveDataRootPath(ref readonly FspPath path) { Result res = GetProgramInfo(out ProgramInfo programInfo); if (res.IsFailure()) return res.Miss(); @@ -1165,7 +1168,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave return Result.Success; } - public Result GetSaveDataInfo(out SaveDataInfo info, SaveDataSpaceId spaceId, in SaveDataAttribute attribute) + public Result GetSaveDataInfo(out SaveDataInfo info, SaveDataSpaceId spaceId, SaveDataAttribute attribute) { UnsafeHelpers.SkipParamInit(out info); @@ -1849,7 +1852,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave tempAttribute.ProgramId = ResolveDefaultSaveDataReferenceProgramId(programInfo.ProgramId); } - res = GetSaveDataInfo(out SaveDataInfo info, spaceId, in tempAttribute); + res = GetSaveDataInfo(out SaveDataInfo info, spaceId, tempAttribute); if (res.IsFailure()) return res.Miss(); // Make a mask for reading the entire extra data @@ -1898,7 +1901,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave tempAttribute.ProgramId = ResolveDefaultSaveDataReferenceProgramId(programInfo.ProgramId); } - res = GetSaveDataInfo(out SaveDataInfo info, spaceId, in tempAttribute); + res = GetSaveDataInfo(out SaveDataInfo info, spaceId, tempAttribute); if (res.IsFailure()) return res.Miss(); return ReadSaveDataFileSystemExtraDataCore(out extraDataRef, spaceId, info.SaveDataId, in maskRef).Ret(); @@ -1978,7 +1981,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave tempAttribute.ProgramId = ResolveDefaultSaveDataReferenceProgramId(programInfo.ProgramId); } - res = GetSaveDataInfo(out SaveDataInfo info, spaceId, in tempAttribute); + res = GetSaveDataInfo(out SaveDataInfo info, spaceId, tempAttribute); if (res.IsFailure()) return res.Miss(); return WriteSaveDataFileSystemExtraDataWithMask(info.SaveDataId, spaceId, extraData, extraDataMask).Ret(); diff --git a/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs b/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs index 8938823b..63dca759 100644 --- a/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs +++ b/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs @@ -82,12 +82,12 @@ public class SaveDataFileSystemServiceImpl : IDisposable spaceId == SaveDataSpaceId.SafeMode; } - private static Result WipeData(IFileSystem fileSystem, in Path filePath, RandomDataGenerator random) + private static Result WipeData(IFileSystem fileSystem, ref readonly Path filePath, RandomDataGenerator random) { throw new NotImplementedException(); } - private static Result WipeMasterHeader(IFileSystem fileSystem, in Path filePath, RandomDataGenerator random) + private static Result WipeMasterHeader(IFileSystem fileSystem, ref readonly Path filePath, RandomDataGenerator random) { throw new NotImplementedException(); } @@ -156,7 +156,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable } public Result OpenSaveDataFileSystem(ref SharedRef outFileSystem, SaveDataSpaceId spaceId, - ulong saveDataId, in Path saveDataRootPath, bool openReadOnly, SaveDataType type, bool cacheExtraData) + ulong saveDataId, ref readonly Path saveDataRootPath, bool openReadOnly, SaveDataType type, bool cacheExtraData) { using var fileSystem = new SharedRef(); @@ -241,33 +241,33 @@ public class SaveDataFileSystemServiceImpl : IDisposable } public Result OpenSaveDataInternalStorageFileSystem(ref SharedRef outFileSystem, - SaveDataSpaceId spaceId, ulong saveDataId, in Path saveDataRootPath, bool useSecondMacKey, + SaveDataSpaceId spaceId, ulong saveDataId, ref readonly Path saveDataRootPath, bool useSecondMacKey, bool isReconstructible) { throw new NotImplementedException(); } private Result OpenSaveDataImageFile(ref UniqueRef outFile, SaveDataSpaceId spaceId, ulong saveDataId, - in Path saveDataRootPath) + ref readonly Path saveDataRootPath) { throw new NotImplementedException(); } public Result ExtendSaveDataFileSystemCore(out long extendedTotalSize, ulong saveDataId, SaveDataSpaceId spaceId, - SaveDataType type, long dataSize, long journalSize, in Path saveDataRootPath, bool isExtensionStart) + SaveDataType type, long dataSize, long journalSize, ref readonly Path saveDataRootPath, bool isExtensionStart) { throw new NotImplementedException(); } public Result StartExtendSaveDataFileSystem(out long extendedTotalSize, ulong saveDataId, SaveDataSpaceId spaceId, - SaveDataType type, long dataSize, long journalSize, in Path saveDataRootPath) + SaveDataType type, long dataSize, long journalSize, ref readonly Path saveDataRootPath) { return ExtendSaveDataFileSystemCore(out extendedTotalSize, saveDataId, spaceId, type, dataSize, journalSize, in saveDataRootPath, isExtensionStart: true); } public Result ResumeExtendSaveDataFileSystem(out long extendedTotalSize, ulong saveDataId, SaveDataSpaceId spaceId, - SaveDataType type, in Path saveDataRootPath) + SaveDataType type, ref readonly Path saveDataRootPath) { return ExtendSaveDataFileSystemCore(out extendedTotalSize, saveDataId, spaceId, type, dataSize: 0, journalSize: 0, in saveDataRootPath, isExtensionStart: false); @@ -283,7 +283,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable } public void RevertExtendSaveDataFileSystem(ulong saveDataId, SaveDataSpaceId spaceId, long originalSize, - in Path saveDataRootPath) + ref readonly Path saveDataRootPath) { using var saveDataFile = new UniqueRef(); Result res = OpenSaveDataImageFile(ref saveDataFile.Ref, spaceId, saveDataId, in saveDataRootPath); @@ -401,7 +401,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable } public Result CreateSaveDataFileSystem(ulong saveDataId, in SaveDataCreationInfo2 creationInfo, - in Path saveDataRootPath, bool skipFormat) + ref readonly Path saveDataRootPath, bool skipFormat) { Unsafe.SkipInit(out Array18 saveImageNameBuffer); @@ -477,7 +477,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable } public Result DeleteSaveDataFileSystem(SaveDataSpaceId spaceId, ulong saveDataId, bool wipeSaveFile, - in Path saveDataRootPath) + ref readonly Path saveDataRootPath) { Unsafe.SkipInit(out Array18 saveImageNameBuffer); @@ -538,7 +538,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable } public Result ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, SaveDataSpaceId spaceId, - ulong saveDataId, SaveDataType type, in Path saveDataRootPath) + ulong saveDataId, SaveDataType type, ref readonly Path saveDataRootPath) { UnsafeHelpers.SkipParamInit(out extraData); @@ -564,7 +564,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable // We won't actually use the returned save data FS. // Opening the FS should cache an extra data accessor for it. - res = OpenSaveDataFileSystem(ref unusedSaveDataFs.Ref, spaceId, saveDataId, saveDataRootPath, + res = OpenSaveDataFileSystem(ref unusedSaveDataFs.Ref, spaceId, saveDataId, in saveDataRootPath, openReadOnly: true, type, cacheExtraData: true); if (res.IsFailure()) return res.Miss(); @@ -581,7 +581,8 @@ public class SaveDataFileSystemServiceImpl : IDisposable } public Result WriteSaveDataFileSystemExtraData(SaveDataSpaceId spaceId, ulong saveDataId, - in SaveDataExtraData extraData, in Path saveDataRootPath, SaveDataType type, bool updateTimeStamp) + in SaveDataExtraData extraData, ref readonly Path saveDataRootPath, SaveDataType type, + bool updateTimeStamp) { // Emulated save data on a host device doesn't have extra data. if (IsAllowedDirectorySaveData(spaceId, in saveDataRootPath)) @@ -604,7 +605,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable // We won't actually use the returned save data FS. // Opening the FS should cache an extra data accessor for it. - res = OpenSaveDataFileSystem(ref unusedSaveDataFs.Ref, spaceId, saveDataId, saveDataRootPath, + res = OpenSaveDataFileSystem(ref unusedSaveDataFs.Ref, spaceId, saveDataId, in saveDataRootPath, openReadOnly: false, type, cacheExtraData: true); if (res.IsFailure()) return res.Miss(); @@ -625,7 +626,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable } public Result CorruptSaveDataFileSystem(SaveDataSpaceId spaceId, ulong saveDataId, long offset, - in Path saveDataRootPath) + ref readonly Path saveDataRootPath) { throw new NotImplementedException(); } @@ -635,7 +636,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable return _config.TimeService.GetCurrentPosixTime(out timeStamp); } - private bool IsSaveEmulated(in Path saveDataRootPath) + private bool IsSaveEmulated(ref readonly Path saveDataRootPath) { return !saveDataRootPath.IsEmpty(); } @@ -649,7 +650,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable } public Result OpenSaveDataDirectoryFileSystem(ref SharedRef outFileSystem, - SaveDataSpaceId spaceId, in Path saveDataRootPath, bool allowEmulatedSave) + SaveDataSpaceId spaceId, ref readonly Path saveDataRootPath, bool allowEmulatedSave) { Result res; @@ -662,7 +663,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable // Ensure the target save data directory exists res = _config.TargetManagerFsCreator.Create(ref tmFileSystem.Ref, in saveDataRootPath, openCaseSensitive: false, ensureRootPathExists: true, - ResultFs.SaveDataRootPathUnavailable.Value); + pathNotFoundResult: ResultFs.SaveDataRootPathUnavailable.Value); if (res.IsFailure()) return res.Miss(); } @@ -674,13 +675,13 @@ public class SaveDataFileSystemServiceImpl : IDisposable if (res.IsFailure()) return res.Miss(); res = _config.TargetManagerFsCreator.Create(ref outFileSystem, in path, isTargetFsCaseSensitive, - ensureRootPathExists: false, ResultFs.SaveDataRootPathUnavailable.Value); + ensureRootPathExists: false, pathNotFoundResult: ResultFs.SaveDataRootPathUnavailable.Value); if (res.IsFailure()) return res.Miss(); } else { res = _config.LocalFsCreator.Create(ref outFileSystem, in saveDataRootPath, openCaseSensitive: true, - ensureRootPathExists: true, ResultFs.SaveDataRootPathUnavailable.Value); + ensureRootPathExists: true, pathNotFoundResult: ResultFs.SaveDataRootPathUnavailable.Value); if (res.IsFailure()) return res.Miss(); } @@ -709,13 +710,13 @@ public class SaveDataFileSystemServiceImpl : IDisposable } public Result OpenSaveDataDirectoryFileSystemImpl(ref SharedRef outFileSystem, - SaveDataSpaceId spaceId, in Path directoryPath) + SaveDataSpaceId spaceId, ref readonly Path directoryPath) { return OpenSaveDataDirectoryFileSystemImpl(ref outFileSystem, spaceId, in directoryPath, createIfMissing: true); } public Result OpenSaveDataDirectoryFileSystemImpl(ref SharedRef outFileSystem, - SaveDataSpaceId spaceId, in Path directoryPath, bool createIfMissing) + SaveDataSpaceId spaceId, ref readonly Path directoryPath, bool createIfMissing) { using var baseFileSystem = new SharedRef(); @@ -819,7 +820,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable /// /// Checks if a save is to be stored on a host device. /// - public bool IsAllowedDirectorySaveData(SaveDataSpaceId spaceId, in Path saveDataRootPath) + public bool IsAllowedDirectorySaveData(SaveDataSpaceId spaceId, ref readonly Path saveDataRootPath) { return spaceId == SaveDataSpaceId.User && IsSaveEmulated(in saveDataRootPath); } diff --git a/src/LibHac/FsSrv/SaveDataIndexer.cs b/src/LibHac/FsSrv/SaveDataIndexer.cs index 2d35ee32..b0563f92 100644 --- a/src/LibHac/FsSrv/SaveDataIndexer.cs +++ b/src/LibHac/FsSrv/SaveDataIndexer.cs @@ -184,7 +184,7 @@ public class SaveDataIndexer : ISaveDataIndexer { private WeakRef _reader; - public ReaderAccessor(in SharedRef reader) + public ReaderAccessor(ref readonly SharedRef reader) { _reader = new WeakRef(in reader); } @@ -748,7 +748,7 @@ public class SaveDataIndexer : ISaveDataIndexer /// /// The reader to add. /// The of the operation. - private Result RegisterReader(in SharedRef reader) + private Result RegisterReader(ref readonly SharedRef reader) { Assert.SdkRequires(_mutex.IsLockedByCurrentThread()); diff --git a/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs b/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs index 0b0b0381..cdebe6c9 100644 --- a/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs +++ b/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs @@ -74,7 +74,7 @@ public class SaveDataOpenTypeSetFileStorage : FileStorageBasedFileSystem _mutex = new SdkMutexType(); } - public Result Initialize(ref SharedRef baseFileSystem, in Path path, OpenMode mode, OpenType type) + public Result Initialize(ref SharedRef baseFileSystem, ref readonly Path path, OpenMode mode, OpenType type) { Result res = Initialize(ref baseFileSystem, in path, mode); if (res.IsFailure()) return res.Miss(); diff --git a/src/LibHac/FsSrv/Sf/IFileSystem.cs b/src/LibHac/FsSrv/Sf/IFileSystem.cs index 6ac7b877..78b39575 100644 --- a/src/LibHac/FsSrv/Sf/IFileSystem.cs +++ b/src/LibHac/FsSrv/Sf/IFileSystem.cs @@ -11,21 +11,21 @@ namespace LibHac.FsSrv.Sf; public interface IFileSystem : IDisposable { Result GetImpl(ref SharedRef fileSystem); - Result CreateFile(in Path path, long size, int option); - Result DeleteFile(in Path path); - Result CreateDirectory(in Path path); - Result DeleteDirectory(in Path path); - Result DeleteDirectoryRecursively(in Path path); - Result RenameFile(in Path currentPath, in Path newPath); - Result RenameDirectory(in Path currentPath, in Path newPath); - Result GetEntryType(out uint entryType, in Path path); - Result OpenFile(ref SharedRef outFile, in Path path, uint mode); - Result OpenDirectory(ref SharedRef outDirectory, in Path path, uint mode); + Result CreateFile(ref readonly Path path, long size, int option); + Result DeleteFile(ref readonly Path path); + Result CreateDirectory(ref readonly Path path); + Result DeleteDirectory(ref readonly Path path); + Result DeleteDirectoryRecursively(ref readonly Path path); + Result RenameFile(ref readonly Path currentPath, ref readonly Path newPath); + Result RenameDirectory(ref readonly Path currentPath, ref readonly Path newPath); + Result GetEntryType(out uint entryType, ref readonly Path path); + Result OpenFile(ref SharedRef outFile, ref readonly Path path, uint mode); + Result OpenDirectory(ref SharedRef outDirectory, ref readonly Path path, uint mode); Result Commit(); - Result GetFreeSpaceSize(out long freeSpace, in Path path); - Result GetTotalSpaceSize(out long totalSpace, in Path path); - Result CleanDirectoryRecursively(in Path path); - Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path); - Result QueryEntry(OutBuffer outBuffer, InBuffer inBuffer, int queryId, in Path path); + Result GetFreeSpaceSize(out long freeSpace, ref readonly Path path); + Result GetTotalSpaceSize(out long totalSpace, ref readonly Path path); + Result CleanDirectoryRecursively(ref readonly Path path); + Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, ref readonly Path path); + Result QueryEntry(OutBuffer outBuffer, InBuffer inBuffer, int queryId, ref readonly Path path); Result GetFileSystemAttribute(out FileSystemAttribute outAttribute); } \ No newline at end of file diff --git a/src/LibHac/FsSrv/Sf/IFileSystemProxy.cs b/src/LibHac/FsSrv/Sf/IFileSystemProxy.cs index 51cb3c4c..59c346ee 100644 --- a/src/LibHac/FsSrv/Sf/IFileSystemProxy.cs +++ b/src/LibHac/FsSrv/Sf/IFileSystemProxy.cs @@ -19,12 +19,12 @@ public interface IFileSystemProxy : IDisposable Result SetCurrentProcess(ulong processId); Result OpenDataFileSystemByCurrentProcess(ref SharedRef outFileSystem); Result OpenFileSystemWithPatch(ref SharedRef outFileSystem, ProgramId programId, FileSystemProxyType fsType); - Result OpenFileSystemWithId(ref SharedRef outFileSystem, in FspPath path, ulong id, FileSystemProxyType fsType); + Result OpenFileSystemWithId(ref SharedRef outFileSystem, ref readonly FspPath path, ulong id, FileSystemProxyType fsType); Result OpenDataFileSystemByProgramId(ref SharedRef outFileSystem, ProgramId programId); - Result OpenBisFileSystem(ref SharedRef outFileSystem, in FspPath rootPath, BisPartitionId partitionId); + Result OpenBisFileSystem(ref SharedRef outFileSystem, ref readonly FspPath rootPath, BisPartitionId partitionId); Result OpenBisStorage(ref SharedRef outStorage, BisPartitionId partitionId); Result InvalidateBisCache(); - Result OpenHostFileSystem(ref SharedRef outFileSystem, in FspPath path); + Result OpenHostFileSystem(ref SharedRef outFileSystem, ref readonly FspPath path); Result OpenSdCardFileSystem(ref SharedRef outFileSystem); Result FormatSdCardFileSystem(); Result DeleteSaveDataFileSystem(ulong saveDataId); @@ -41,7 +41,7 @@ public interface IFileSystemProxy : IDisposable Result DeleteCacheStorage(ushort index); Result GetCacheStorageSize(out long dataSize, out long journalSize, ushort index); Result CreateSaveDataFileSystemWithHashSalt(in SaveDataAttribute attribute, in SaveDataCreationInfo creationInfo, in SaveDataMetaInfo metaInfo, in HashSalt hashSalt); - Result OpenHostFileSystemWithOption(ref SharedRef outFileSystem, in FspPath path, MountHostOption option); + Result OpenHostFileSystemWithOption(ref SharedRef outFileSystem, ref readonly FspPath path, MountHostOption option); Result CreateSaveDataFileSystemWithCreationInfo2(in SaveDataCreationInfo2 creationInfo); Result OpenSaveDataFileSystem(ref SharedRef outFileSystem, SaveDataSpaceId spaceId, in SaveDataAttribute attribute); Result OpenSaveDataFileSystemBySystemSaveDataId(ref SharedRef outFileSystem, SaveDataSpaceId spaceId, in SaveDataAttribute attribute); @@ -79,7 +79,7 @@ public interface IFileSystemProxy : IDisposable Result OpenDataStorageByDataId(ref SharedRef outStorage, DataId dataId, StorageId storageId); Result OpenPatchDataStorageByCurrentProcess(ref SharedRef outStorage); Result OpenDataFileSystemWithProgramIndex(ref SharedRef outFileSystem, byte programIndex); - Result OpenDataStorageByPath(ref SharedRef outFileSystem, in FspPath path, FileSystemProxyType fsType); + Result OpenDataStorageByPath(ref SharedRef outFileSystem, ref readonly FspPath path, FileSystemProxyType fsType); Result OpenDataStorageWithProgramIndex(ref SharedRef outStorage, byte programIndex); Result OpenDeviceOperator(ref SharedRef outDeviceOperator); Result OpenSdCardDetectionEventNotifier(ref SharedRef outEventNotifier); @@ -95,8 +95,8 @@ public interface IFileSystemProxy : IDisposable Result GetRightsId(out RightsId rightsId, ProgramId programId, StorageId storageId); Result RegisterExternalKey(in RightsId rightsId, in AccessKey externalKey); Result UnregisterAllExternalKey(); - Result GetRightsIdByPath(out RightsId rightsId, in FspPath path); - Result GetRightsIdAndKeyGenerationByPath(out RightsId rightsId, out byte keyGeneration, in FspPath path); + Result GetRightsIdByPath(out RightsId rightsId, ref readonly FspPath path); + Result GetRightsIdAndKeyGenerationByPath(out RightsId rightsId, out byte keyGeneration, ref readonly FspPath path); Result SetCurrentPosixTimeWithTimeDifference(long currentTime, int timeDifference); Result GetFreeSpaceSizeForSaveData(out long freeSpaceSize, SaveDataSpaceId spaceId); Result VerifySaveDataFileSystemBySaveDataSpaceId(SaveDataSpaceId spaceId, ulong saveDataId, OutBuffer readBuffer); @@ -114,9 +114,9 @@ public interface IFileSystemProxy : IDisposable Result AbandonAccessFailure(ulong processId); Result GetAndClearErrorInfo(out FileSystemProxyErrorInfo errorInfo); Result RegisterProgramIndexMapInfo(InBuffer programIndexMapInfoBuffer, int programCount); - Result SetBisRootForHost(BisPartitionId partitionId, in FspPath path); + Result SetBisRootForHost(BisPartitionId partitionId, ref readonly FspPath path); Result SetSaveDataSize(long saveDataSize, long saveDataJournalSize); - Result SetSaveDataRootPath(in FspPath path); + Result SetSaveDataRootPath(ref readonly FspPath path); Result DisableAutoSaveDataCreation(); Result SetGlobalAccessLogMode(GlobalAccessLogMode mode); Result GetGlobalAccessLogMode(out GlobalAccessLogMode mode); diff --git a/src/LibHac/FsSrv/Sf/IFileSystemProxyForLoader.cs b/src/LibHac/FsSrv/Sf/IFileSystemProxyForLoader.cs index d160d7e9..58e6f54e 100644 --- a/src/LibHac/FsSrv/Sf/IFileSystemProxyForLoader.cs +++ b/src/LibHac/FsSrv/Sf/IFileSystemProxyForLoader.cs @@ -9,7 +9,7 @@ namespace LibHac.FsSrv.Sf; public interface IFileSystemProxyForLoader : IDisposable { Result OpenCodeFileSystem(ref SharedRef fileSystem, - out CodeVerificationData verificationData, in FspPath path, ProgramId programId); + out CodeVerificationData verificationData, ref readonly FspPath path, ProgramId programId); Result IsArchivedProgram(out bool isArchived, ulong processId); Result SetCurrentProcess(ulong processId); diff --git a/src/LibHac/FsSrv/Sf/ISaveDataTransferManagerForSaveDataRepair.cs b/src/LibHac/FsSrv/Sf/ISaveDataTransferManagerForSaveDataRepair.cs index 5d05bfb1..0565b01e 100644 --- a/src/LibHac/FsSrv/Sf/ISaveDataTransferManagerForSaveDataRepair.cs +++ b/src/LibHac/FsSrv/Sf/ISaveDataTransferManagerForSaveDataRepair.cs @@ -11,8 +11,8 @@ public interface ISaveDataTransferManagerForSaveDataRepair : IDisposable public Result SetKeyPackage(InBuffer keyPackage); public Result OpenSaveDataExporterAndGetEncryptedKey(ref SharedRef outExporter, out RsaEncryptedKey key, SaveDataSpaceId spaceId, ulong saveDataId); public Result PrepareOpenSaveDataImporter(out RsaEncryptedKey key); - public Result OpenSaveDataImporterForSaveDataAfterRepair(ref SharedRef outImporter, InBuffer initialDataBeforeRepair, InBuffer initialDataAfterRepair, UserId userId, SaveDataSpaceId spaceId); - public Result OpenSaveDataImporterForSaveDataBeforeRepair(ref SharedRef outImporter, InBuffer initialData, UserId userId, SaveDataSpaceId spaceId); + public Result OpenSaveDataImporterForSaveDataAfterRepair(ref SharedRef outImporter, InBuffer initialDataBeforeRepair, InBuffer initialDataAfterRepair, in UserId userId, SaveDataSpaceId spaceId); + public Result OpenSaveDataImporterForSaveDataBeforeRepair(ref SharedRef outImporter, InBuffer initialData, in UserId userId, SaveDataSpaceId spaceId); public Result OpenSaveDataExporterWithKey(ref SharedRef outExporter, in AesKey key, SaveDataSpaceId spaceId, ulong saveDataId); - public Result OpenSaveDataImporterWithKey(ref SharedRef outImporter, in AesKey key, InBuffer initialData, UserId userId, ulong saveDataSpaceId); + public Result OpenSaveDataImporterWithKey(ref SharedRef outImporter, in AesKey key, InBuffer initialData, in UserId userId, ulong saveDataSpaceId); } \ No newline at end of file diff --git a/src/LibHac/FsSystem/AesCtrCounterExtendedStorage.cs b/src/LibHac/FsSystem/AesCtrCounterExtendedStorage.cs index 9fb925c8..45d0cddc 100644 --- a/src/LibHac/FsSystem/AesCtrCounterExtendedStorage.cs +++ b/src/LibHac/FsSystem/AesCtrCounterExtendedStorage.cs @@ -126,7 +126,7 @@ public class AesCtrCounterExtendedStorage : IStorage // ReSharper disable once UnusedMember.Local private Result Initialize(MemoryResource allocator, ReadOnlySpan key, uint secureValue, - in ValueSubStorage dataStorage, in ValueSubStorage tableStorage) + ref readonly ValueSubStorage dataStorage, ref readonly ValueSubStorage tableStorage) { Unsafe.SkipInit(out BucketTree.Header header); @@ -159,8 +159,8 @@ public class AesCtrCounterExtendedStorage : IStorage } public Result Initialize(MemoryResource allocator, ReadOnlySpan key, uint secureValue, long counterOffset, - in ValueSubStorage dataStorage, in ValueSubStorage nodeStorage, in ValueSubStorage entryStorage, int entryCount, - ref UniqueRef decryptor) + ref readonly ValueSubStorage dataStorage, ref readonly ValueSubStorage nodeStorage, + ref readonly ValueSubStorage entryStorage, int entryCount, ref UniqueRef decryptor) { Assert.SdkRequiresEqual(key.Length, KeySize); Assert.SdkRequiresGreaterEqual(counterOffset, 0); diff --git a/src/LibHac/FsSystem/AesCtrStorage.cs b/src/LibHac/FsSystem/AesCtrStorage.cs index dc742eb3..5fed0307 100644 --- a/src/LibHac/FsSystem/AesCtrStorage.cs +++ b/src/LibHac/FsSystem/AesCtrStorage.cs @@ -50,7 +50,7 @@ public class AesCtrStorage : IStorage iv.CopyTo(_iv); } - public AesCtrStorage(in SharedRef baseStorage, ReadOnlySpan key, ReadOnlySpan iv) + public AesCtrStorage(ref readonly SharedRef baseStorage, ReadOnlySpan key, ReadOnlySpan iv) { Assert.SdkRequiresNotNull(in baseStorage); Assert.SdkRequiresEqual(key.Length, KeySize); diff --git a/src/LibHac/FsSystem/AesXtsStorageExternal.cs b/src/LibHac/FsSystem/AesXtsStorageExternal.cs index 8595ca77..106ce249 100644 --- a/src/LibHac/FsSystem/AesXtsStorageExternal.cs +++ b/src/LibHac/FsSystem/AesXtsStorageExternal.cs @@ -53,7 +53,7 @@ public class AesXtsStorageExternal : IStorage iv.CopyTo(_iv); } - public AesXtsStorageExternal(in SharedRef baseStorage, ReadOnlySpan key1, ReadOnlySpan key2, + public AesXtsStorageExternal(ref readonly SharedRef baseStorage, ReadOnlySpan key1, ReadOnlySpan key2, ReadOnlySpan iv, uint blockSize, CryptAesXtsFunction encryptFunction, CryptAesXtsFunction decryptFunction) : this(baseStorage.Get, key1, key2, iv, blockSize, encryptFunction, decryptFunction) { diff --git a/src/LibHac/FsSystem/AlignmentMatchingStorage.cs b/src/LibHac/FsSystem/AlignmentMatchingStorage.cs index 40bba64f..68b0f909 100644 --- a/src/LibHac/FsSystem/AlignmentMatchingStorage.cs +++ b/src/LibHac/FsSystem/AlignmentMatchingStorage.cs @@ -205,7 +205,7 @@ public class AlignmentMatchingStoragePooledBuffer : IStorage Assert.SdkRequires(BitUtil.IsPowerOfTwo(dataAlign), "DataAlign must be a power of 2."); } - public AlignmentMatchingStoragePooledBuffer(in SharedRef baseStorage, int dataAlign) + public AlignmentMatchingStoragePooledBuffer(ref readonly SharedRef baseStorage, int dataAlign) { Abort.DoAbortUnless(BitUtil.IsPowerOfTwo(BufferAlign)); @@ -345,7 +345,7 @@ public class AlignmentMatchingStorageInBulkRead : IStorage Assert.SdkRequires(BitUtil.IsPowerOfTwo(dataAlignment)); } - public AlignmentMatchingStorageInBulkRead(in SharedRef baseStorage, int dataAlignment) + public AlignmentMatchingStorageInBulkRead(ref readonly SharedRef baseStorage, int dataAlignment) { Abort.DoAbortUnless(BitUtil.IsPowerOfTwo(BufferAlign)); diff --git a/src/LibHac/FsSystem/AlignmentMatchingStorageImpl.cs b/src/LibHac/FsSystem/AlignmentMatchingStorageImpl.cs index 5c9968b7..c16eb0fa 100644 --- a/src/LibHac/FsSystem/AlignmentMatchingStorageImpl.cs +++ b/src/LibHac/FsSystem/AlignmentMatchingStorageImpl.cs @@ -33,13 +33,13 @@ public static class AlignmentMatchingStorageImpl return (uint)(Alignment.AlignUp(value, alignment) - value); } - public static Result Read(in SharedRef storage, Span workBuffer, uint dataAlignment, + public static Result Read(ref readonly SharedRef storage, Span workBuffer, uint dataAlignment, uint bufferAlignment, long offset, Span destination) { return Read(storage.Get, workBuffer, dataAlignment, bufferAlignment, offset, destination); } - public static Result Write(in SharedRef storage, Span subBuffer, uint dataAlignment, + public static Result Write(ref readonly SharedRef storage, Span subBuffer, uint dataAlignment, uint bufferAlignment, long offset, ReadOnlySpan source) { return Write(storage.Get, subBuffer, dataAlignment, bufferAlignment, offset, source); diff --git a/src/LibHac/FsSystem/ApplicationTemporaryFileSystem.cs b/src/LibHac/FsSystem/ApplicationTemporaryFileSystem.cs index 87de79d4..4f484185 100644 --- a/src/LibHac/FsSystem/ApplicationTemporaryFileSystem.cs +++ b/src/LibHac/FsSystem/ApplicationTemporaryFileSystem.cs @@ -7,57 +7,57 @@ namespace LibHac.FsSystem; public class ApplicationTemporaryFileSystem : IFileSystem, ISaveDataExtraDataAccessor { - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) { throw new NotImplementedException(); } - protected override Result DoDeleteFile(in Path path) + protected override Result DoDeleteFile(ref readonly Path path) { throw new NotImplementedException(); } - protected override Result DoCreateDirectory(in Path path) + protected override Result DoCreateDirectory(ref readonly Path path) { throw new NotImplementedException(); } - protected override Result DoDeleteDirectory(in Path path) + protected override Result DoDeleteDirectory(ref readonly Path path) { throw new NotImplementedException(); } - protected override Result DoDeleteDirectoryRecursively(in Path path) + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) { throw new NotImplementedException(); } - protected override Result DoCleanDirectoryRecursively(in Path path) + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) { throw new NotImplementedException(); } - protected override Result DoRenameFile(in Path currentPath, in Path newPath) + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) { throw new NotImplementedException(); } - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) { throw new NotImplementedException(); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { throw new NotImplementedException(); } - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { throw new NotImplementedException(); } - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { throw new NotImplementedException(); diff --git a/src/LibHac/FsSystem/BucketTree.cs b/src/LibHac/FsSystem/BucketTree.cs index a5d99783..f18e619a 100644 --- a/src/LibHac/FsSystem/BucketTree.cs +++ b/src/LibHac/FsSystem/BucketTree.cs @@ -62,7 +62,7 @@ file struct StorageNode _index = (int)(pos - _start) - 1; } - public Result Find(in ValueSubStorage storage, long virtualAddress) + public Result Find(ref readonly ValueSubStorage storage, long virtualAddress) { int end = _count; Offset pos = _start; @@ -489,8 +489,8 @@ public partial class BucketTree : IDisposable return Result.Success; } - public Result Initialize(MemoryResource allocator, in ValueSubStorage nodeStorage, in ValueSubStorage entryStorage, - int nodeSize, int entrySize, int entryCount) + public Result Initialize(MemoryResource allocator, ref readonly ValueSubStorage nodeStorage, + ref readonly ValueSubStorage entryStorage, int nodeSize, int entrySize, int entryCount) { Assert.SdkRequiresNotNull(allocator); Assert.SdkRequiresLessEqual(sizeof(long), entrySize); @@ -683,7 +683,7 @@ public partial class BucketTree : IDisposable } private Result ScanContinuousReading(out ContinuousReadingInfo info, - in ContinuousReadingParam param) where TEntry : unmanaged, IContinuousReadingEntry + ref readonly ContinuousReadingParam param) where TEntry : unmanaged, IContinuousReadingEntry { Assert.SdkRequires(IsInitialized()); Assert.Equal(Unsafe.SizeOf(), _entrySize); diff --git a/src/LibHac/FsSystem/BucketTreeBuilder.cs b/src/LibHac/FsSystem/BucketTreeBuilder.cs index 0b92254e..a3f18311 100644 --- a/src/LibHac/FsSystem/BucketTreeBuilder.cs +++ b/src/LibHac/FsSystem/BucketTreeBuilder.cs @@ -45,9 +45,9 @@ public partial class BucketTree /// The size of each entry that will be stored in the bucket tree. /// The exact number of entries that will be added to the bucket tree. /// The of the operation. - public Result Initialize(MemoryResource allocator, in ValueSubStorage headerStorage, - in ValueSubStorage nodeStorage, in ValueSubStorage entryStorage, int nodeSize, int entrySize, - int entryCount) + public Result Initialize(MemoryResource allocator, ref readonly ValueSubStorage headerStorage, + ref readonly ValueSubStorage nodeStorage, ref readonly ValueSubStorage entryStorage, int nodeSize, + int entrySize, int entryCount) { Assert.NotNull(allocator); Assert.SdkRequiresLessEqual(sizeof(long), entrySize); diff --git a/src/LibHac/FsSystem/BufferedStorage.cs b/src/LibHac/FsSystem/BufferedStorage.cs index f4e4f969..6fc54029 100644 --- a/src/LibHac/FsSystem/BufferedStorage.cs +++ b/src/LibHac/FsSystem/BufferedStorage.cs @@ -891,7 +891,7 @@ public class BufferedStorage : IStorage /// The to gain exclusive access to. /// The of the operation, and if exclusive /// access to the was gained; if not. - public (Result Result, bool wasUpgradeSuccessful) Upgrade(in SharedCache sharedCache) + public (Result Result, bool wasUpgradeSuccessful) Upgrade(ref readonly SharedCache sharedCache) { Assert.SdkRequires(_bufferedStorage == sharedCache.BufferedStorage); Assert.SdkRequires(!sharedCache.Cache.IsNull); @@ -989,7 +989,8 @@ public class BufferedStorage : IStorage /// The size of each cached block. Must be a power of 2. /// The maximum number of blocks that can be cached at one time. /// - public Result Initialize(in ValueSubStorage baseStorage, IBufferManager bufferManager, int blockSize, int bufferCount) + public Result Initialize(ref readonly ValueSubStorage baseStorage, IBufferManager bufferManager, int blockSize, + int bufferCount) { Assert.SdkRequiresNotNull(bufferManager); Assert.SdkRequiresLess(0, blockSize); diff --git a/src/LibHac/FsSystem/CompressedStorage.cs b/src/LibHac/FsSystem/CompressedStorage.cs index 5fee1e67..bd47c61d 100644 --- a/src/LibHac/FsSystem/CompressedStorage.cs +++ b/src/LibHac/FsSystem/CompressedStorage.cs @@ -64,9 +64,10 @@ public class CompressedStorage : IStorage, IAsynchronousAccessSplitter throw new NotImplementedException(); } - public Result Initialize(MemoryResource allocatorForBucketTree, in ValueSubStorage dataStorage, - in ValueSubStorage nodeStorage, in ValueSubStorage entryStorage, int bucketTreeEntryCount, - long blockSizeMax, long continuousReadingSizeMax, GetDecompressorFunction getDecompressorFunc) + public Result Initialize(MemoryResource allocatorForBucketTree, ref readonly ValueSubStorage dataStorage, + ref readonly ValueSubStorage nodeStorage, ref readonly ValueSubStorage entryStorage, + int bucketTreeEntryCount, long blockSizeMax, long continuousReadingSizeMax, + GetDecompressorFunction getDecompressorFunc) { Assert.SdkRequiresNotNull(allocatorForBucketTree); Assert.SdkRequiresLess(0, blockSizeMax); @@ -296,9 +297,10 @@ public class CompressedStorage : IStorage, IAsynchronousAccessSplitter } public Result Initialize(MemoryResource allocatorForBucketTree, IBufferManager allocatorForCacheManager, - in ValueSubStorage dataStorage, in ValueSubStorage nodeStorage, in ValueSubStorage entryStorage, - int bucketTreeEntryCount, long blockSizeMax, long continuousReadingSizeMax, - GetDecompressorFunction getDecompressorFunc, long cacheSize0, long cacheSize1, int maxCacheEntries) + ref readonly ValueSubStorage dataStorage, ref readonly ValueSubStorage nodeStorage, + ref readonly ValueSubStorage entryStorage, int bucketTreeEntryCount, long blockSizeMax, + long continuousReadingSizeMax, GetDecompressorFunction getDecompressorFunc, long cacheSize0, long cacheSize1, + int maxCacheEntries) { Result res = _core.Initialize(allocatorForBucketTree, in dataStorage, in nodeStorage, in entryStorage, bucketTreeEntryCount, blockSizeMax, continuousReadingSizeMax, getDecompressorFunc); diff --git a/src/LibHac/FsSystem/ConcatenationFileSystem.cs b/src/LibHac/FsSystem/ConcatenationFileSystem.cs index 931eccb8..6502271a 100644 --- a/src/LibHac/FsSystem/ConcatenationFileSystem.cs +++ b/src/LibHac/FsSystem/ConcatenationFileSystem.cs @@ -63,7 +63,7 @@ public class ConcatenationFileSystem : IFileSystem base.Dispose(); } - public Result Initialize(in Path path) + public Result Initialize(ref readonly Path path) { return _path.Initialize(in path).Ret(); } @@ -401,7 +401,7 @@ public class ConcatenationFileSystem : IFileSystem base.Dispose(); } - public Result Initialize(in Path path) + public Result Initialize(ref readonly Path path) { return _path.Initialize(in path).Ret(); } @@ -481,7 +481,7 @@ public class ConcatenationFileSystem : IFileSystem return Result.Success; } - private bool IsReadTarget(in DirectoryEntry entry) + private bool IsReadTarget(ref readonly DirectoryEntry entry) { bool hasConcatAttribute = IsConcatenationFileAttribute(entry.Attributes); @@ -540,7 +540,7 @@ public class ConcatenationFileSystem : IFileSystem return path.AppendChild(buffer).Ret(); } - private static Result GenerateInternalFilePath(ref Path outPath, int index, in Path basePath) + private static Result GenerateInternalFilePath(ref Path outPath, int index, ref readonly Path basePath) { Result res = outPath.Initialize(in basePath); if (res.IsFailure()) return res.Miss(); @@ -548,7 +548,7 @@ public class ConcatenationFileSystem : IFileSystem return AppendInternalFilePath(ref outPath, index).Ret(); } - private static Result GenerateParentPath(ref Path outParentPath, in Path path) + private static Result GenerateParentPath(ref Path outParentPath, ref readonly Path path) { if (path == RootPath) return ResultFs.PathNotFound.Log(); @@ -564,7 +564,7 @@ public class ConcatenationFileSystem : IFileSystem return attribute.HasFlag(NxFileAttributes.Directory | NxFileAttributes.Archive); } - private bool IsConcatenationFile(in Path path) + private bool IsConcatenationFile(ref readonly Path path) { Result res = _baseFileSystem.Get.GetFileAttributes(out NxFileAttributes attribute, in path); if (res.IsFailure()) @@ -573,7 +573,7 @@ public class ConcatenationFileSystem : IFileSystem return IsConcatenationFileAttribute(attribute); } - private Result GetInternalFileCount(out int count, in Path path) + private Result GetInternalFileCount(out int count, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out count); @@ -608,7 +608,7 @@ public class ConcatenationFileSystem : IFileSystem } } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { using var scopedLock = new ScopedLock(ref _mutex); @@ -618,28 +618,28 @@ public class ConcatenationFileSystem : IFileSystem return Result.Success; } - return _baseFileSystem.Get.GetEntryType(out entryType, path).Ret(); + return _baseFileSystem.Get.GetEntryType(out entryType, in path).Ret(); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, ref readonly Path path) { using var scopedLock = new ScopedLock(ref _mutex); - return _baseFileSystem.Get.GetFreeSpaceSize(out freeSpace, path).Ret(); + return _baseFileSystem.Get.GetFreeSpaceSize(out freeSpace, in path).Ret(); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, ref readonly Path path) { using var scopedLock = new ScopedLock(ref _mutex); - return _baseFileSystem.Get.GetTotalSpaceSize(out totalSpace, path).Ret(); + return _baseFileSystem.Get.GetTotalSpaceSize(out totalSpace, in path).Ret(); } - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, ref readonly Path path) { using var scopedLock = new ScopedLock(ref _mutex); - return _baseFileSystem.Get.GetFileTimeStampRaw(out timeStamp, path).Ret(); + return _baseFileSystem.Get.GetFileTimeStampRaw(out timeStamp, in path).Ret(); } protected override Result DoFlush() @@ -649,7 +649,7 @@ public class ConcatenationFileSystem : IFileSystem return _baseFileSystem.Get.Flush().Ret(); } - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { using var scopedLock = new ScopedLock(ref _mutex); @@ -708,18 +708,18 @@ public class ConcatenationFileSystem : IFileSystem } } - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { using var scopedLock = new ScopedLock(ref _mutex); - if (IsConcatenationFile(path)) + if (IsConcatenationFile(in path)) { return ResultFs.PathNotFound.Log(); } using var baseDirectory = new UniqueRef(); - Result res = _baseFileSystem.Get.OpenDirectory(ref baseDirectory.Ref, path, OpenDirectoryMode.All); + Result res = _baseFileSystem.Get.OpenDirectory(ref baseDirectory.Ref, in path, OpenDirectoryMode.All); if (res.IsFailure()) return res.Miss(); using var concatDirectory = new UniqueRef( @@ -731,7 +731,7 @@ public class ConcatenationFileSystem : IFileSystem return Result.Success; } - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) { using var scopedLock = new ScopedLock(ref _mutex); @@ -740,7 +740,7 @@ public class ConcatenationFileSystem : IFileSystem // Create a normal file if the concatenation file flag isn't set if (!option.HasFlag(CreateFileOptions.CreateConcatenationFile)) { - return _baseFileSystem.Get.CreateFile(path, size, newOption).Ret(); + return _baseFileSystem.Get.CreateFile(in path, size, newOption).Ret(); } using var parentPath = new Path(); @@ -815,7 +815,7 @@ public class ConcatenationFileSystem : IFileSystem return Result.Success; } - protected override Result DoDeleteFile(in Path path) + protected override Result DoDeleteFile(ref readonly Path path) { using var scopedLock = new ScopedLock(ref _mutex); @@ -824,7 +824,7 @@ public class ConcatenationFileSystem : IFileSystem return _baseFileSystem.Get.DeleteFile(in path).Ret(); } - Result res = GetInternalFileCount(out int count, path); + Result res = GetInternalFileCount(out int count, in path); if (res.IsFailure()) return res.Miss(); using var filePath = new Path(); @@ -849,7 +849,7 @@ public class ConcatenationFileSystem : IFileSystem return Result.Success; } - protected override Result DoCreateDirectory(in Path path) + protected override Result DoCreateDirectory(ref readonly Path path) { using var scopedLock = new ScopedLock(ref _mutex); @@ -864,26 +864,26 @@ public class ConcatenationFileSystem : IFileSystem return _baseFileSystem.Get.CreateDirectory(in path).Ret(); } - protected override Result DoDeleteDirectory(in Path path) + protected override Result DoDeleteDirectory(ref readonly Path path) { using var scopedLock = new ScopedLock(ref _mutex); // Make sure the directory isn't a concatenation file. - if (IsConcatenationFile(path)) + if (IsConcatenationFile(in path)) return ResultFs.PathNotFound.Log(); - return _baseFileSystem.Get.DeleteDirectory(path).Ret(); + return _baseFileSystem.Get.DeleteDirectory(in path).Ret(); } - private Result CleanDirectoryRecursivelyImpl(in Path path) + private Result CleanDirectoryRecursivelyImpl(ref readonly Path path) { - static Result OnEnterDir(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) => + static Result OnEnterDir(ref readonly Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) => Result.Success; - static Result OnExitDir(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) => + static Result OnExitDir(ref readonly Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) => closure.SourceFileSystem.DeleteDirectory(in path).Ret(); - static Result OnFile(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) => + static Result OnFile(ref readonly Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) => closure.SourceFileSystem.DeleteFile(in path).Ret(); var closure = new FsIterationTaskClosure(); @@ -894,7 +894,7 @@ public class ConcatenationFileSystem : IFileSystem ref closure).Ret(); } - protected override Result DoDeleteDirectoryRecursively(in Path path) + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) { bool isConcatenationFile; using (new ScopedLock(ref _mutex)) @@ -911,7 +911,7 @@ public class ConcatenationFileSystem : IFileSystem return _baseFileSystem.Get.DeleteDirectory(in path).Ret(); } - protected override Result DoCleanDirectoryRecursively(in Path path) + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) { bool isConcatenationFile; using (new ScopedLock(ref _mutex)) @@ -925,7 +925,7 @@ public class ConcatenationFileSystem : IFileSystem return CleanDirectoryRecursivelyImpl(in path).Ret(); } - protected override Result DoRenameFile(in Path currentPath, in Path newPath) + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) { using var scopedLock = new ScopedLock(ref _mutex); @@ -935,7 +935,7 @@ public class ConcatenationFileSystem : IFileSystem return _baseFileSystem.Get.RenameFile(in currentPath, in newPath).Ret(); } - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) { using var scopedLock = new ScopedLock(ref _mutex); @@ -945,7 +945,7 @@ public class ConcatenationFileSystem : IFileSystem return _baseFileSystem.Get.RenameDirectory(in currentPath, in newPath).Ret(); } - public Result GetFileSize(out long size, in Path path) + public Result GetFileSize(out long size, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out size); @@ -987,7 +987,7 @@ public class ConcatenationFileSystem : IFileSystem } protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - in Path path) + ref readonly Path path) { using var scopedLock = new ScopedLock(ref _mutex); diff --git a/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs b/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs index 37255424..89d173e8 100644 --- a/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs +++ b/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs @@ -331,7 +331,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return Result.Success; } - private Result ResolvePath(ref Path outFullPath, in Path path) + private Result ResolvePath(ref Path outFullPath, ref readonly Path path) { using var pathDirectoryName = new Path(); @@ -349,7 +349,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return Result.Success; } - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) { using var fullPath = new Path(); Result res = ResolvePath(ref fullPath.Ref(), in path); @@ -363,7 +363,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return Result.Success; } - protected override Result DoDeleteFile(in Path path) + protected override Result DoDeleteFile(ref readonly Path path) { using var fullPath = new Path(); Result res = ResolvePath(ref fullPath.Ref(), in path); @@ -377,7 +377,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return Result.Success; } - protected override Result DoCreateDirectory(in Path path) + protected override Result DoCreateDirectory(ref readonly Path path) { using var fullPath = new Path(); Result res = ResolvePath(ref fullPath.Ref(), in path); @@ -391,7 +391,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return Result.Success; } - protected override Result DoDeleteDirectory(in Path path) + protected override Result DoDeleteDirectory(ref readonly Path path) { using var fullPath = new Path(); Result res = ResolvePath(ref fullPath.Ref(), in path); @@ -405,7 +405,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return Result.Success; } - protected override Result DoDeleteDirectoryRecursively(in Path path) + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) { using var fullPath = new Path(); Result res = ResolvePath(ref fullPath.Ref(), in path); @@ -419,7 +419,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return Result.Success; } - protected override Result DoCleanDirectoryRecursively(in Path path) + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) { using var fullPath = new Path(); Result res = ResolvePath(ref fullPath.Ref(), in path); @@ -433,7 +433,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return Result.Success; } - protected override Result DoRenameFile(in Path currentPath, in Path newPath) + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) { using var currentFullPath = new Path(); using var newFullPath = new Path(); @@ -452,7 +452,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return Result.Success; } - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) { using var currentFullPath = new Path(); using var newFullPath = new Path(); @@ -471,7 +471,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return Result.Success; } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out entryType); @@ -487,7 +487,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return Result.Success; } - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { using var fullPath = new Path(); Result res = ResolvePath(ref fullPath.Ref(), in path); @@ -510,7 +510,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return Result.Success; } - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { using var fullPath = new Path(); @@ -531,10 +531,10 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem /// The path of the destination directory. /// The path of the source directory. /// The of the operation. - private Result SynchronizeDirectory(in Path destPath, in Path sourcePath) + private Result SynchronizeDirectory(ref readonly Path destPath, ref readonly Path sourcePath) { // Delete destination dir and recreate it. - Result res = _baseFs.DeleteDirectoryRecursively(destPath); + Result res = _baseFs.DeleteDirectoryRecursively(in destPath); // Changed: Nintendo returns all errors unconditionally because SynchronizeDirectory is always called // in situations where a PathNotFound error would mean the save directory was in an invalid state. @@ -542,7 +542,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem // put the save directory in an invalid state. if (res.IsFailure() && !ResultFs.PathNotFound.Includes(res)) return res; - res = _baseFs.CreateDirectory(destPath); + res = _baseFs.CreateDirectory(in destPath); if (res.IsFailure()) return res.Miss(); var directoryEntry = new DirectoryEntry(); @@ -650,7 +650,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return Result.Success; } - protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out freeSpace); @@ -666,7 +666,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return Result.Success; } - protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out totalSpace); @@ -895,7 +895,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return PathFunctions.SetUpFixedPath(ref path, extraDataName); } - private Result EnsureExtraDataSize(in Path path) + private Result EnsureExtraDataSize(ref readonly Path path) { using var file = new UniqueRef(); Result res = _baseFs.OpenFile(ref file.Ref, in path, OpenMode.ReadWrite); @@ -910,7 +910,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return file.Get.SetSize(Unsafe.SizeOf()); } - private Result SynchronizeExtraData(in Path destPath, in Path sourcePath) + private Result SynchronizeExtraData(ref readonly Path destPath, ref readonly Path sourcePath) { Span workBuffer = stackalloc byte[Unsafe.SizeOf()]; @@ -961,7 +961,7 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return WriteExtraDataImpl(in extraData); } - private Result WriteExtraDataImpl(in SaveDataExtraData extraData) + private Result WriteExtraDataImpl(ref readonly SaveDataExtraData extraData) { Assert.SdkRequires(_mutex.IsLockedByCurrentThread()); diff --git a/src/LibHac/FsSystem/ForwardingFileSystem.cs b/src/LibHac/FsSystem/ForwardingFileSystem.cs index 39bda625..d7111c2e 100644 --- a/src/LibHac/FsSystem/ForwardingFileSystem.cs +++ b/src/LibHac/FsSystem/ForwardingFileSystem.cs @@ -90,40 +90,40 @@ public class ForwardingFileSystem : IFileSystem base.Dispose(); } - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) => + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) => BaseFileSystem.Get.CreateFile(in path, size, option); - protected override Result DoDeleteFile(in Path path) => BaseFileSystem.Get.DeleteFile(in path); + protected override Result DoDeleteFile(ref readonly Path path) => BaseFileSystem.Get.DeleteFile(in path); - protected override Result DoCreateDirectory(in Path path) => BaseFileSystem.Get.CreateDirectory(in path); + protected override Result DoCreateDirectory(ref readonly Path path) => BaseFileSystem.Get.CreateDirectory(in path); - protected override Result DoDeleteDirectory(in Path path) => BaseFileSystem.Get.DeleteDirectory(in path); + protected override Result DoDeleteDirectory(ref readonly Path path) => BaseFileSystem.Get.DeleteDirectory(in path); - protected override Result DoDeleteDirectoryRecursively(in Path path) => + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) => BaseFileSystem.Get.DeleteDirectoryRecursively(in path); - protected override Result DoCleanDirectoryRecursively(in Path path) => + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) => BaseFileSystem.Get.CleanDirectoryRecursively(in path); - protected override Result DoRenameFile(in Path currentPath, in Path newPath) => + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) => BaseFileSystem.Get.RenameFile(in currentPath, in newPath); - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) => + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) => BaseFileSystem.Get.RenameDirectory(in currentPath, in newPath); - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) => + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) => BaseFileSystem.Get.GetEntryType(out entryType, in path); - protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) => + protected override Result DoGetFreeSpaceSize(out long freeSpace, ref readonly Path path) => BaseFileSystem.Get.GetFreeSpaceSize(out freeSpace, in path); - protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) => + protected override Result DoGetTotalSpaceSize(out long totalSpace, ref readonly Path path) => BaseFileSystem.Get.GetTotalSpaceSize(out totalSpace, in path); - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) => + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) => BaseFileSystem.Get.OpenFile(ref outFile, in path, mode); - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) => BaseFileSystem.Get.OpenDirectory(ref outDirectory, in path, mode); @@ -136,12 +136,12 @@ public class ForwardingFileSystem : IFileSystem protected override Result DoFlush() => BaseFileSystem.Get.Flush(); - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) => + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, ref readonly Path path) => BaseFileSystem.Get.GetFileTimeStampRaw(out timeStamp, in path); protected override Result DoGetFileSystemAttribute(out FileSystemAttribute outAttribute) => BaseFileSystem.Get.GetFileSystemAttribute(out outAttribute); protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - in Path path) => BaseFileSystem.Get.QueryEntry(outBuffer, inBuffer, queryId, in path); + ref readonly Path path) => BaseFileSystem.Get.QueryEntry(outBuffer, inBuffer, queryId, in path); } \ No newline at end of file diff --git a/src/LibHac/FsSystem/HierarchicalIntegrityVerificationStorage.cs b/src/LibHac/FsSystem/HierarchicalIntegrityVerificationStorage.cs index 0bc9f34f..41f20e67 100644 --- a/src/LibHac/FsSystem/HierarchicalIntegrityVerificationStorage.cs +++ b/src/LibHac/FsSystem/HierarchicalIntegrityVerificationStorage.cs @@ -162,7 +162,7 @@ public class HierarchicalIntegrityVerificationStorageControlArea : IDisposable } } - public static Result Format(in ValueSubStorage metaStorage, + public static Result Format(ref readonly ValueSubStorage metaStorage, in HierarchicalIntegrityVerificationMetaInformation metaInfo) { // Ensure the storage is large enough to hold the meta info. @@ -189,7 +189,7 @@ public class HierarchicalIntegrityVerificationStorageControlArea : IDisposable return Result.Success; } - public static Result Expand(in ValueSubStorage metaStorage, + public static Result Expand(ref readonly ValueSubStorage metaStorage, in HierarchicalIntegrityVerificationMetaInformation newMeta) { // Ensure the storage is large enough to hold the meta info. @@ -230,7 +230,7 @@ public class HierarchicalIntegrityVerificationStorageControlArea : IDisposable outInfo = _meta.LevelHashInfo; } - public Result Initialize(in ValueSubStorage metaStorage) + public Result Initialize(ref readonly ValueSubStorage metaStorage) { // Ensure the storage is large enough to hold the meta info. Result res = metaStorage.GetSize(out long metaSize); @@ -279,7 +279,7 @@ public class HierarchicalIntegrityVerificationStorage : IStorage private ValueSubStorage[] _storages; - public HierarchicalStorageInformation(in HierarchicalStorageInformation other) + public HierarchicalStorageInformation(ref readonly HierarchicalStorageInformation other) { _storages = new ValueSubStorage[(int)Storage.DataStorage + 1]; @@ -311,13 +311,13 @@ public class HierarchicalIntegrityVerificationStorage : IStorage } } - public void SetMasterHashStorage(in ValueSubStorage storage) => _storages[(int)Storage.MasterStorage].Set(in storage); - public void SetLayer1HashStorage(in ValueSubStorage storage) => _storages[(int)Storage.Layer1Storage].Set(in storage); - public void SetLayer2HashStorage(in ValueSubStorage storage) => _storages[(int)Storage.Layer2Storage].Set(in storage); - public void SetLayer3HashStorage(in ValueSubStorage storage) => _storages[(int)Storage.Layer3Storage].Set(in storage); - public void SetLayer4HashStorage(in ValueSubStorage storage) => _storages[(int)Storage.Layer4Storage].Set(in storage); - public void SetLayer5HashStorage(in ValueSubStorage storage) => _storages[(int)Storage.Layer5Storage].Set(in storage); - public void SetDataStorage(in ValueSubStorage storage) => _storages[(int)Storage.DataStorage].Set(in storage); + public void SetMasterHashStorage(ref readonly ValueSubStorage storage) => _storages[(int)Storage.MasterStorage].Set(in storage); + public void SetLayer1HashStorage(ref readonly ValueSubStorage storage) => _storages[(int)Storage.Layer1Storage].Set(in storage); + public void SetLayer2HashStorage(ref readonly ValueSubStorage storage) => _storages[(int)Storage.Layer2Storage].Set(in storage); + public void SetLayer3HashStorage(ref readonly ValueSubStorage storage) => _storages[(int)Storage.Layer3Storage].Set(in storage); + public void SetLayer4HashStorage(ref readonly ValueSubStorage storage) => _storages[(int)Storage.Layer4Storage].Set(in storage); + public void SetLayer5HashStorage(ref readonly ValueSubStorage storage) => _storages[(int)Storage.Layer5Storage].Set(in storage); + public void SetDataStorage(ref readonly ValueSubStorage storage) => _storages[(int)Storage.DataStorage].Set(in storage); } internal const uint IntegrityVerificationStorageMagic = 0x43465649; // IVFC diff --git a/src/LibHac/FsSystem/IResultConvertFileSystem.cs b/src/LibHac/FsSystem/IResultConvertFileSystem.cs index f27ae852..a8a4c6b5 100644 --- a/src/LibHac/FsSystem/IResultConvertFileSystem.cs +++ b/src/LibHac/FsSystem/IResultConvertFileSystem.cs @@ -122,47 +122,47 @@ public abstract class IResultConvertFileSystem : ISaveDataFileSystem where T protected abstract Result ConvertResult(Result result); - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) { return ConvertResult(_baseFileSystem.Get.CreateFile(in path, size)).Ret(); } - protected override Result DoDeleteFile(in Path path) + protected override Result DoDeleteFile(ref readonly Path path) { return ConvertResult(_baseFileSystem.Get.DeleteFile(in path)).Ret(); } - protected override Result DoCreateDirectory(in Path path) + protected override Result DoCreateDirectory(ref readonly Path path) { return ConvertResult(_baseFileSystem.Get.CreateDirectory(in path)).Ret(); } - protected override Result DoDeleteDirectory(in Path path) + protected override Result DoDeleteDirectory(ref readonly Path path) { return ConvertResult(_baseFileSystem.Get.DeleteDirectory(in path)).Ret(); } - protected override Result DoDeleteDirectoryRecursively(in Path path) + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) { return ConvertResult(_baseFileSystem.Get.DeleteDirectoryRecursively(in path)).Ret(); } - protected override Result DoCleanDirectoryRecursively(in Path path) + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) { return ConvertResult(_baseFileSystem.Get.CleanDirectoryRecursively(in path)).Ret(); } - protected override Result DoRenameFile(in Path currentPath, in Path newPath) + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) { return ConvertResult(_baseFileSystem.Get.RenameFile(in currentPath, in newPath)).Ret(); } - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) { return ConvertResult(_baseFileSystem.Get.RenameDirectory(in currentPath, in newPath)).Ret(); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { return ConvertResult(_baseFileSystem.Get.GetEntryType(out entryType, in path)).Ret(); } @@ -187,23 +187,23 @@ public abstract class IResultConvertFileSystem : ISaveDataFileSystem where T return ConvertResult(_baseFileSystem.Get.Flush()).Ret(); } - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, ref readonly Path path) { return ConvertResult(_baseFileSystem.Get.GetFileTimeStampRaw(out timeStamp, in path)).Ret(); } protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - in Path path) + ref readonly Path path) { return ConvertResult(_baseFileSystem.Get.QueryEntry(outBuffer, inBuffer, queryId, in path)).Ret(); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, ref readonly Path path) { return ConvertResult(_baseFileSystem.Get.GetFreeSpaceSize(out freeSpace, in path)).Ret(); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, ref readonly Path path) { return ConvertResult(_baseFileSystem.Get.GetTotalSpaceSize(out totalSpace, in path)).Ret(); } diff --git a/src/LibHac/FsSystem/IndirectStorage.cs b/src/LibHac/FsSystem/IndirectStorage.cs index bfe6d952..68ba8631 100644 --- a/src/LibHac/FsSystem/IndirectStorage.cs +++ b/src/LibHac/FsSystem/IndirectStorage.cs @@ -90,7 +90,7 @@ public class IndirectStorage : IStorage public static long QueryEntryStorageSize(int entryCount) => BucketTree.QueryEntryStorageSize(NodeSize, Unsafe.SizeOf(), entryCount); - public void SetStorage(int index, in ValueSubStorage storage) + public void SetStorage(int index, ref readonly ValueSubStorage storage) { Assert.SdkRequiresInRange(index, 0, StorageCount); _dataStorage[index].Set(in storage); @@ -120,7 +120,7 @@ public class IndirectStorage : IStorage return _table.IsInitialized(); } - public Result Initialize(MemoryResource allocator, in ValueSubStorage tableStorage) + public Result Initialize(MemoryResource allocator, ref readonly ValueSubStorage tableStorage) { Unsafe.SkipInit(out BucketTree.Header header); @@ -141,14 +141,14 @@ public class IndirectStorage : IStorage if (storageSize < entryStorageOffset + entryStorageSize) return ResultFs.InvalidIndirectStorageBucketTreeSize.Log(); - using var nodeStorage = new ValueSubStorage(tableStorage, nodeStorageOffset, nodeStorageSize); - using var entryStorage = new ValueSubStorage(tableStorage, entryStorageOffset, entryStorageSize); + using var nodeStorage = new ValueSubStorage(in tableStorage, nodeStorageOffset, nodeStorageSize); + using var entryStorage = new ValueSubStorage(in tableStorage, entryStorageOffset, entryStorageSize); return Initialize(allocator, in nodeStorage, in entryStorage, header.EntryCount); } - public Result Initialize(MemoryResource allocator, in ValueSubStorage nodeStorage, in ValueSubStorage entryStorage, - int entryCount) + public Result Initialize(MemoryResource allocator, ref readonly ValueSubStorage nodeStorage, + ref readonly ValueSubStorage entryStorage, int entryCount) { return _table.Initialize(allocator, in nodeStorage, in entryStorage, NodeSize, Unsafe.SizeOf(), entryCount); diff --git a/src/LibHac/FsSystem/IntegrityVerificationStorage.cs b/src/LibHac/FsSystem/IntegrityVerificationStorage.cs index 6efe3d75..1f0503b7 100644 --- a/src/LibHac/FsSystem/IntegrityVerificationStorage.cs +++ b/src/LibHac/FsSystem/IntegrityVerificationStorage.cs @@ -90,8 +90,8 @@ public class IntegrityVerificationStorage : IStorage return _verificationBlockSize; } - public void Initialize(in ValueSubStorage hashStorage, in ValueSubStorage dataStorage, int sizeVerificationBlock, - int sizeUpperLayerVerificationBlock, IBufferManager bufferManager, + public void Initialize(ref readonly ValueSubStorage hashStorage, ref readonly ValueSubStorage dataStorage, + int sizeVerificationBlock, int sizeUpperLayerVerificationBlock, IBufferManager bufferManager, IHash256GeneratorFactory hashGeneratorFactory, in Optional hashSalt, bool isRealData, bool isWritable, bool allowClearedBlocks) { @@ -226,7 +226,7 @@ public class IntegrityVerificationStorage : IStorage { int verifiedSize = (verifiedCount + i) << _verificationBlockOrder; ref BlockHash blockHash = ref signatureBuffer.GetBuffer()[i]; - currentResult = VerifyHash(destination.Slice(verifiedCount), ref blockHash, in hashGenerator); + currentResult = VerifyHash(destination.Slice(verifiedCount), ref blockHash, ref hashGenerator.Ref); if (ResultFs.IntegrityVerificationStorageCorrupted.Includes(currentResult)) { @@ -319,7 +319,7 @@ public class IntegrityVerificationStorage : IStorage { int updatedSize = (updatedSignatureCount + i) << _verificationBlockOrder; CalcBlockHash(out signatureBuffer.GetBuffer()[i], source.Slice(updatedSize), - in hashGenerator); + ref hashGenerator.Ref); } } @@ -523,18 +523,18 @@ public class IntegrityVerificationStorage : IStorage Result res = _hashGeneratorFactory.Create(ref hashGenerator.Ref); if (res.IsFailure()) return res.Miss(); - CalcBlockHash(out outHash, buffer, verificationBlockSize, in hashGenerator); + CalcBlockHash(out outHash, buffer, verificationBlockSize, ref hashGenerator.Ref); return Result.Success; } private void CalcBlockHash(out BlockHash outHash, ReadOnlySpan buffer, - in UniqueRef hashGenerator) + ref UniqueRef hashGenerator) { - CalcBlockHash(out outHash, buffer, _verificationBlockSize, in hashGenerator); + CalcBlockHash(out outHash, buffer, _verificationBlockSize, ref hashGenerator); } private void CalcBlockHash(out BlockHash outHash, ReadOnlySpan buffer, int verificationBlockSize, - in UniqueRef hashGenerator) + ref UniqueRef hashGenerator) { UnsafeHelpers.SkipParamInit(out outHash); @@ -568,7 +568,7 @@ public class IntegrityVerificationStorage : IStorage } private Result VerifyHash(ReadOnlySpan buffer, ref BlockHash hash, - in UniqueRef hashGenerator) + ref UniqueRef hashGenerator) { Assert.SdkRequiresGreaterEqual(buffer.Length, HashSize); @@ -582,7 +582,7 @@ public class IntegrityVerificationStorage : IStorage return ResultFs.ClearedRealDataVerificationFailed.Log(); } - CalcBlockHash(out BlockHash actualHash, buffer, hashGenerator); + CalcBlockHash(out BlockHash actualHash, buffer, ref hashGenerator); if (!CryptoUtil.IsSameBytes(SpanHelpers.AsReadOnlyByteSpan(in hash), SpanHelpers.AsReadOnlyByteSpan(in actualHash), Unsafe.SizeOf())) diff --git a/src/LibHac/FsSystem/LocalFileSystem.cs b/src/LibHac/FsSystem/LocalFileSystem.cs index fab7476c..596c5eb2 100644 --- a/src/LibHac/FsSystem/LocalFileSystem.cs +++ b/src/LibHac/FsSystem/LocalFileSystem.cs @@ -158,7 +158,7 @@ public class LocalFileSystem : IAttributeFileSystem return Result.Success; } - private Result ResolveFullPath(out string outFullPath, in Path path, bool checkCaseSensitivity) + private Result ResolveFullPath(out string outFullPath, ref readonly Path path, bool checkCaseSensitivity) { UnsafeHelpers.SkipParamInit(out outFullPath); @@ -194,7 +194,7 @@ public class LocalFileSystem : IAttributeFileSystem return Result.Success; } - protected override Result DoGetFileAttributes(out NxFileAttributes attributes, in Path path) + protected override Result DoGetFileAttributes(out NxFileAttributes attributes, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out attributes); @@ -213,7 +213,7 @@ public class LocalFileSystem : IAttributeFileSystem return Result.Success; } - protected override Result DoSetFileAttributes(in Path path, NxFileAttributes attributes) + protected override Result DoSetFileAttributes(ref readonly Path path, NxFileAttributes attributes) { Result res = ResolveFullPath(out string fullPath, in path, true); if (res.IsFailure()) return res.Miss(); @@ -241,7 +241,7 @@ public class LocalFileSystem : IAttributeFileSystem return Result.Success; } - protected override Result DoGetFileSize(out long fileSize, in Path path) + protected override Result DoGetFileSize(out long fileSize, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out fileSize); @@ -254,12 +254,12 @@ public class LocalFileSystem : IAttributeFileSystem return GetSizeInternal(out fileSize, info); } - protected override Result DoCreateDirectory(in Path path) + protected override Result DoCreateDirectory(ref readonly Path path) { - return DoCreateDirectory(path, NxFileAttributes.None); + return DoCreateDirectory(in path, NxFileAttributes.None); } - protected override Result DoCreateDirectory(in Path path, NxFileAttributes archiveAttribute) + protected override Result DoCreateDirectory(ref readonly Path path, NxFileAttributes archiveAttribute) { Result res = ResolveFullPath(out string fullPath, in path, false); if (res.IsFailure()) return res.Miss(); @@ -280,7 +280,7 @@ public class LocalFileSystem : IAttributeFileSystem return CreateDirInternal(dir, archiveAttribute); } - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) { Result res = ResolveFullPath(out string fullPath, in path, false); if (res.IsFailure()) return res.Miss(); @@ -308,7 +308,7 @@ public class LocalFileSystem : IAttributeFileSystem } } - protected override Result DoDeleteDirectory(in Path path) + protected override Result DoDeleteDirectory(ref readonly Path path) { Result res = ResolveFullPath(out string fullPath, in path, true); if (res.IsFailure()) return res.Miss(); @@ -320,7 +320,7 @@ public class LocalFileSystem : IAttributeFileSystem () => DeleteDirectoryInternal(dir, false), _fsClient); } - protected override Result DoDeleteDirectoryRecursively(in Path path) + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) { Result res = ResolveFullPath(out string fullPath, in path, true); if (res.IsFailure()) return res.Miss(); @@ -332,7 +332,7 @@ public class LocalFileSystem : IAttributeFileSystem () => DeleteDirectoryInternal(dir, true), _fsClient); } - protected override Result DoCleanDirectoryRecursively(in Path path) + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) { Result res = ResolveFullPath(out string fullPath, in path, true); if (res.IsFailure()) return res.Miss(); @@ -343,7 +343,7 @@ public class LocalFileSystem : IAttributeFileSystem return CleanDirectoryInternal(dir, _fsClient); } - protected override Result DoDeleteFile(in Path path) + protected override Result DoDeleteFile(ref readonly Path path) { Result res = ResolveFullPath(out string fullPath, in path, true); if (res.IsFailure()) return res.Miss(); @@ -355,7 +355,7 @@ public class LocalFileSystem : IAttributeFileSystem () => DeleteFileInternal(file), _fsClient); } - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { Result res = ResolveFullPath(out string fullPath, in path, true); @@ -378,12 +378,12 @@ public class LocalFileSystem : IAttributeFileSystem return Result.Success; } - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { Result res = ResolveFullPath(out string fullPath, in path, true); if (res.IsFailure()) return res.Miss(); - res = GetEntryType(out DirectoryEntryType entryType, path); + res = GetEntryType(out DirectoryEntryType entryType, in path); if (res.IsFailure()) return res.Miss(); if (entryType == DirectoryEntryType.Directory) @@ -401,7 +401,7 @@ public class LocalFileSystem : IAttributeFileSystem return Result.Success; } - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) { Result res = ResolveFullPath(out string fullCurrentPath, in currentPath, true); if (res.IsFailure()) return res.Miss(); @@ -422,7 +422,7 @@ public class LocalFileSystem : IAttributeFileSystem () => RenameDirInternal(currentDirInfo, newDirInfo), _fsClient); } - protected override Result DoRenameFile(in Path currentPath, in Path newPath) + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) { Result res = ResolveFullPath(out string fullCurrentPath, in currentPath, true); if (res.IsFailure()) return res.Miss(); @@ -443,7 +443,7 @@ public class LocalFileSystem : IAttributeFileSystem () => RenameFileInternal(currentFileInfo, newFileInfo), _fsClient); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out entryType); @@ -471,7 +471,7 @@ public class LocalFileSystem : IAttributeFileSystem return ResultFs.PathNotFound.Log(); } - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out timeStamp); @@ -501,7 +501,7 @@ public class LocalFileSystem : IAttributeFileSystem return Result.Success; } - protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out freeSpace); @@ -512,7 +512,7 @@ public class LocalFileSystem : IAttributeFileSystem return Result.Success; } - protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out totalSpace); @@ -567,7 +567,7 @@ public class LocalFileSystem : IAttributeFileSystem } protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - in Path path) + ref readonly Path path) { return ResultFs.UnsupportedOperation.Log(); } diff --git a/src/LibHac/FsSystem/NcaReader.cs b/src/LibHac/FsSystem/NcaReader.cs index 81838ffe..077df87d 100644 --- a/src/LibHac/FsSystem/NcaReader.cs +++ b/src/LibHac/FsSystem/NcaReader.cs @@ -449,7 +449,7 @@ public class NcaReader : IDisposable Assert.SdkRequires(_bodyStorage.HasValue); Assert.SdkRequiresLessEqual(Unsafe.SizeOf(), outBuffer.Length); - SpanHelpers.AsReadOnlyByteSpan(_header).CopyTo(outBuffer); + SpanHelpers.AsReadOnlyByteSpan(in _header).CopyTo(outBuffer); } public DecryptAesCtrFunction GetExternalDecryptAesCtrFunction() diff --git a/src/LibHac/FsSystem/PartitionFileSystem.cs b/src/LibHac/FsSystem/PartitionFileSystem.cs index e60c39ae..1ea3f034 100644 --- a/src/LibHac/FsSystem/PartitionFileSystem.cs +++ b/src/LibHac/FsSystem/PartitionFileSystem.cs @@ -406,14 +406,14 @@ public class PartitionFileSystemCore : IFil base.Dispose(); } - public Result Initialize(in SharedRef baseStorage) + public Result Initialize(ref readonly SharedRef baseStorage) { _sharedStorage.SetByCopy(in baseStorage); return Initialize(_sharedStorage.Get).Ret(); } - public Result Initialize(in SharedRef baseStorage, MemoryResource allocator) + public Result Initialize(ref readonly SharedRef baseStorage, MemoryResource allocator) { _sharedStorage.SetByCopy(in baseStorage); @@ -445,14 +445,14 @@ public class PartitionFileSystemCore : IFil return Result.Success; } - public Result Initialize(ref UniqueRef metaData, in SharedRef baseStorage) + public Result Initialize(ref UniqueRef metaData, ref readonly SharedRef baseStorage) { _uniqueMetaData.Set(ref metaData); return Initialize(_uniqueMetaData.Get, in baseStorage).Ret(); } - public Result Initialize(TMetaData metaData, in SharedRef baseStorage) + public Result Initialize(TMetaData metaData, ref readonly SharedRef baseStorage) { if (_isInitialized) return ResultFs.PreconditionViolation.Log(); @@ -484,7 +484,7 @@ public class PartitionFileSystemCore : IFil return Result.Success; } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { Unsafe.SkipInit(out entryType); @@ -510,7 +510,7 @@ public class PartitionFileSystemCore : IFil return ResultFs.PathNotFound.Log(); } - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { if (!_isInitialized) return ResultFs.PreconditionViolation.Log(); @@ -531,7 +531,7 @@ public class PartitionFileSystemCore : IFil return Result.Success; } - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, OpenDirectoryMode mode) + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { if (!_isInitialized) return ResultFs.PreconditionViolation.Log(); @@ -547,14 +547,14 @@ public class PartitionFileSystemCore : IFil return Result.Success; } - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoDeleteFile(in Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoCreateDirectory(in Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoDeleteDirectory(in Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoDeleteDirectoryRecursively(in Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoCleanDirectoryRecursively(in Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoRenameFile(in Path currentPath, in Path newPath) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoDeleteFile(ref readonly Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoCreateDirectory(ref readonly Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoDeleteDirectory(ref readonly Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) => ResultFs.UnsupportedWriteForPartitionFileSystem.Log(); protected override Result DoCommit() { diff --git a/src/LibHac/FsSystem/PartitionFileSystemMeta.cs b/src/LibHac/FsSystem/PartitionFileSystemMeta.cs index 038f59e0..5e706e97 100644 --- a/src/LibHac/FsSystem/PartitionFileSystemMeta.cs +++ b/src/LibHac/FsSystem/PartitionFileSystemMeta.cs @@ -208,7 +208,7 @@ namespace LibHac.FsSystem { UnsafeHelpers.SkipParamInit(out outSize); - if (!CryptoUtil.IsSameBytes(SpanHelpers.AsReadOnlyByteSpan(header), TFormat.VersionSignature, + if (!CryptoUtil.IsSameBytes(SpanHelpers.AsReadOnlyByteSpan(in header), TFormat.VersionSignature, TFormat.VersionSignature.Length)) { return TFormat.ResultSignatureVerificationFailed.Log(); diff --git a/src/LibHac/FsSystem/SparseStorage.cs b/src/LibHac/FsSystem/SparseStorage.cs index 8e5b8ae8..764a278d 100644 --- a/src/LibHac/FsSystem/SparseStorage.cs +++ b/src/LibHac/FsSystem/SparseStorage.cs @@ -73,7 +73,7 @@ public class SparseStorage : IndirectStorage SetZeroStorage(); } - public void SetDataStorage(in ValueSubStorage storage) + public void SetDataStorage(ref readonly ValueSubStorage storage) { Assert.SdkRequires(IsInitialized()); diff --git a/src/LibHac/FsSystem/StorageLayoutTypeSetter.cs b/src/LibHac/FsSystem/StorageLayoutTypeSetter.cs index c0c1f69a..d8362368 100644 --- a/src/LibHac/FsSystem/StorageLayoutTypeSetter.cs +++ b/src/LibHac/FsSystem/StorageLayoutTypeSetter.cs @@ -253,73 +253,73 @@ internal class StorageLayoutTypeSetFileSystem : IFileSystem base.Dispose(); } - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) { using var scopedContext = new ScopedStorageLayoutTypeSetter(_storageFlag); - return _baseFileSystem.Get.CreateFile(path, size, option); + return _baseFileSystem.Get.CreateFile(in path, size, option); } - protected override Result DoDeleteFile(in Path path) + protected override Result DoDeleteFile(ref readonly Path path) { using var scopedContext = new ScopedStorageLayoutTypeSetter(_storageFlag); - return _baseFileSystem.Get.DeleteFile(path); + return _baseFileSystem.Get.DeleteFile(in path); } - protected override Result DoCreateDirectory(in Path path) + protected override Result DoCreateDirectory(ref readonly Path path) { using var scopedContext = new ScopedStorageLayoutTypeSetter(_storageFlag); - return _baseFileSystem.Get.CreateDirectory(path); + return _baseFileSystem.Get.CreateDirectory(in path); } - protected override Result DoDeleteDirectory(in Path path) + protected override Result DoDeleteDirectory(ref readonly Path path) { using var scopedContext = new ScopedStorageLayoutTypeSetter(_storageFlag); - return _baseFileSystem.Get.DeleteDirectory(path); + return _baseFileSystem.Get.DeleteDirectory(in path); } - protected override Result DoDeleteDirectoryRecursively(in Path path) + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) { using var scopedContext = new ScopedStorageLayoutTypeSetter(_storageFlag); - return _baseFileSystem.Get.DeleteDirectoryRecursively(path); + return _baseFileSystem.Get.DeleteDirectoryRecursively(in path); } - protected override Result DoCleanDirectoryRecursively(in Path path) + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) { using var scopedContext = new ScopedStorageLayoutTypeSetter(_storageFlag); - return _baseFileSystem.Get.CleanDirectoryRecursively(path); + return _baseFileSystem.Get.CleanDirectoryRecursively(in path); } - protected override Result DoRenameFile(in Path currentPath, in Path newPath) + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) { using var scopedContext = new ScopedStorageLayoutTypeSetter(_storageFlag); - return _baseFileSystem.Get.RenameFile(currentPath, newPath); + return _baseFileSystem.Get.RenameFile(in currentPath, in newPath); } - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) { using var scopedContext = new ScopedStorageLayoutTypeSetter(_storageFlag); - return _baseFileSystem.Get.RenameDirectory(currentPath, newPath); + return _baseFileSystem.Get.RenameDirectory(in currentPath, in newPath); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { using var scopedContext = new ScopedStorageLayoutTypeSetter(_storageFlag); - return _baseFileSystem.Get.GetEntryType(out entryType, path); + return _baseFileSystem.Get.GetEntryType(out entryType, in path); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, ref readonly Path path) { using var scopedContext = new ScopedStorageLayoutTypeSetter(_storageFlag); - return _baseFileSystem.Get.GetFreeSpaceSize(out freeSpace, path); + return _baseFileSystem.Get.GetFreeSpaceSize(out freeSpace, in path); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, ref readonly Path path) { using var scopedContext = new ScopedStorageLayoutTypeSetter(_storageFlag); - return _baseFileSystem.Get.GetTotalSpaceSize(out totalSpace, path); + return _baseFileSystem.Get.GetTotalSpaceSize(out totalSpace, in path); } - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { using var scopedContext = new ScopedStorageLayoutTypeSetter(_storageFlag); using var baseFile = new UniqueRef(); @@ -331,7 +331,7 @@ internal class StorageLayoutTypeSetFileSystem : IFileSystem return Result.Success; } - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { using var scopedContext = new ScopedStorageLayoutTypeSetter(_storageFlag); @@ -368,10 +368,10 @@ internal class StorageLayoutTypeSetFileSystem : IFileSystem return _baseFileSystem.Get.Flush(); } - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, ref readonly Path path) { using var scopedContext = new ScopedStorageLayoutTypeSetter(_storageFlag); - return _baseFileSystem.Get.GetFileTimeStampRaw(out timeStamp, path); + return _baseFileSystem.Get.GetFileTimeStampRaw(out timeStamp, in path); } protected override Result DoGetFileSystemAttribute(out FileSystemAttribute outAttribute) @@ -381,9 +381,9 @@ internal class StorageLayoutTypeSetFileSystem : IFileSystem } protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - in Path path) + ref readonly Path path) { using var scopedContext = new ScopedStorageLayoutTypeSetter(_storageFlag); - return _baseFileSystem.Get.QueryEntry(outBuffer, inBuffer, queryId, path); + return _baseFileSystem.Get.QueryEntry(outBuffer, inBuffer, queryId, in path); } } \ No newline at end of file diff --git a/src/LibHac/FsSystem/SubdirectoryFileSystem.cs b/src/LibHac/FsSystem/SubdirectoryFileSystem.cs index 4681577b..dd65e375 100644 --- a/src/LibHac/FsSystem/SubdirectoryFileSystem.cs +++ b/src/LibHac/FsSystem/SubdirectoryFileSystem.cs @@ -32,18 +32,18 @@ public class SubdirectoryFileSystem : IFileSystem base.Dispose(); } - public Result Initialize(in Path rootPath) + public Result Initialize(ref readonly Path rootPath) { return _rootPath.Initialize(in rootPath); } - private Result ResolveFullPath(ref Path outPath, in Path relativePath) + private Result ResolveFullPath(ref Path outPath, ref readonly Path relativePath) { using Path rootPath = _rootPath.DangerousGetPath(); return outPath.Combine(in rootPath, in relativePath); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out entryType); @@ -57,7 +57,7 @@ public class SubdirectoryFileSystem : IFileSystem return Result.Success; } - protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out freeSpace); @@ -71,7 +71,7 @@ public class SubdirectoryFileSystem : IFileSystem return Result.Success; } - protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out totalSpace); @@ -85,7 +85,7 @@ public class SubdirectoryFileSystem : IFileSystem return Result.Success; } - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out timeStamp); @@ -99,7 +99,7 @@ public class SubdirectoryFileSystem : IFileSystem return Result.Success; } - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { using var fullPath = new Path(); Result res = ResolveFullPath(ref fullPath.Ref(), in path); @@ -111,7 +111,7 @@ public class SubdirectoryFileSystem : IFileSystem return Result.Success; } - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { using var fullPath = new Path(); @@ -124,7 +124,7 @@ public class SubdirectoryFileSystem : IFileSystem return Result.Success; } - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) { using var fullPath = new Path(); Result res = ResolveFullPath(ref fullPath.Ref(), in path); @@ -136,7 +136,7 @@ public class SubdirectoryFileSystem : IFileSystem return Result.Success; } - protected override Result DoDeleteFile(in Path path) + protected override Result DoDeleteFile(ref readonly Path path) { using var fullPath = new Path(); Result res = ResolveFullPath(ref fullPath.Ref(), in path); @@ -148,7 +148,7 @@ public class SubdirectoryFileSystem : IFileSystem return Result.Success; } - protected override Result DoCreateDirectory(in Path path) + protected override Result DoCreateDirectory(ref readonly Path path) { using var fullPath = new Path(); Result res = ResolveFullPath(ref fullPath.Ref(), in path); @@ -160,7 +160,7 @@ public class SubdirectoryFileSystem : IFileSystem return Result.Success; } - protected override Result DoDeleteDirectory(in Path path) + protected override Result DoDeleteDirectory(ref readonly Path path) { using var fullPath = new Path(); Result res = ResolveFullPath(ref fullPath.Ref(), in path); @@ -172,7 +172,7 @@ public class SubdirectoryFileSystem : IFileSystem return Result.Success; } - protected override Result DoDeleteDirectoryRecursively(in Path path) + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) { using var fullPath = new Path(); Result res = ResolveFullPath(ref fullPath.Ref(), in path); @@ -184,7 +184,7 @@ public class SubdirectoryFileSystem : IFileSystem return Result.Success; } - protected override Result DoCleanDirectoryRecursively(in Path path) + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) { using var fullPath = new Path(); Result res = ResolveFullPath(ref fullPath.Ref(), in path); @@ -196,7 +196,7 @@ public class SubdirectoryFileSystem : IFileSystem return Result.Success; } - protected override Result DoRenameFile(in Path currentPath, in Path newPath) + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) { using var currentFullPath = new Path(); Result res = ResolveFullPath(ref currentFullPath.Ref(), in currentPath); @@ -212,7 +212,7 @@ public class SubdirectoryFileSystem : IFileSystem return Result.Success; } - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) { using var currentFullPath = new Path(); Result res = ResolveFullPath(ref currentFullPath.Ref(), in currentPath); @@ -229,7 +229,7 @@ public class SubdirectoryFileSystem : IFileSystem } protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - in Path path) + ref readonly Path path) { using var fullPath = new Path(); Result res = ResolveFullPath(ref fullPath.Ref(), in path); diff --git a/src/LibHac/FsSystem/SwitchStorage.cs b/src/LibHac/FsSystem/SwitchStorage.cs index 81f57cf7..5561f4a4 100644 --- a/src/LibHac/FsSystem/SwitchStorage.cs +++ b/src/LibHac/FsSystem/SwitchStorage.cs @@ -17,7 +17,7 @@ public class SwitchStorage : IStorage private SharedRef _falseStorage; private Func _storageSelectionFunction; - public SwitchStorage(in SharedRef trueStorage, in SharedRef falseStorage, + public SwitchStorage(ref readonly SharedRef trueStorage, ref readonly SharedRef falseStorage, Func storageSelectionFunction) { _trueStorage = SharedRef.CreateCopy(in trueStorage); @@ -125,8 +125,8 @@ public class RegionSwitchStorage : IStorage private SharedRef _outsideRegionStorage; private Region _region; - public RegionSwitchStorage(in SharedRef insideRegionStorage, - in SharedRef outsideRegionStorage, Region region) + public RegionSwitchStorage(ref readonly SharedRef insideRegionStorage, + ref readonly SharedRef outsideRegionStorage, Region region) { _insideRegionStorage = SharedRef.CreateCopy(in insideRegionStorage); _outsideRegionStorage = SharedRef.CreateCopy(in outsideRegionStorage); diff --git a/src/LibHac/FsSystem/UnionStorage.cs b/src/LibHac/FsSystem/UnionStorage.cs index 4e5f8c42..485dd2b5 100644 --- a/src/LibHac/FsSystem/UnionStorage.cs +++ b/src/LibHac/FsSystem/UnionStorage.cs @@ -68,7 +68,7 @@ public class UnionStorage : IStorage return GetLogSize(blockSize) * blockCount + LogHeaderSize; } - public static Result Format(in ValueSubStorage storage, long blockSize) + public static Result Format(ref readonly ValueSubStorage storage, long blockSize) { Assert.SdkRequiresGreater(blockSize, 1); Assert.SdkRequires(BitUtil.IsPowerOfTwo(blockSize)); @@ -80,7 +80,8 @@ public class UnionStorage : IStorage return storage.Write(0, SpanHelpers.AsReadOnlyByteSpan(in header)); } - public Result Initialize(in ValueSubStorage baseStorage, in ValueSubStorage logStorage, long blockSize) + public Result Initialize(ref readonly ValueSubStorage baseStorage, ref readonly ValueSubStorage logStorage, + long blockSize) { Assert.SdkRequiresNull(_buffer); diff --git a/src/LibHac/FsSystem/Utility.cs b/src/LibHac/FsSystem/Utility.cs index 450446f1..9e972a60 100644 --- a/src/LibHac/FsSystem/Utility.cs +++ b/src/LibHac/FsSystem/Utility.cs @@ -30,7 +30,7 @@ public class DummyEventNotifier : IEventNotifier /// Based on nnSdk 13.4.0 (FS 13.1.0) internal static class Utility { - public delegate Result FsIterationTask(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure); + public delegate Result FsIterationTask(ref readonly Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure); /// /// Used to pass various ref structs to an . @@ -145,8 +145,8 @@ internal static class Utility return Result.Success; } - public static Result IterateDirectoryRecursively(IFileSystem fs, in Path rootPath, ref DirectoryEntry dirEntry, - FsIterationTask onEnterDir, FsIterationTask onExitDir, FsIterationTask onFile, + public static Result IterateDirectoryRecursively(IFileSystem fs, ref readonly Path rootPath, + ref DirectoryEntry dirEntry, FsIterationTask onEnterDir, FsIterationTask onExitDir, FsIterationTask onFile, ref FsIterationTaskClosure closure) { using var pathBuffer = new Path(); @@ -160,8 +160,8 @@ internal static class Utility return Result.Success; } - public static Result CleanupDirectoryRecursively(IFileSystem fs, in Path rootPath, ref DirectoryEntry dirEntry, - FsIterationTask onEnterDir, FsIterationTask onExitDir, FsIterationTask onFile, + public static Result CleanupDirectoryRecursively(IFileSystem fs, ref readonly Path rootPath, + ref DirectoryEntry dirEntry, FsIterationTask onEnterDir, FsIterationTask onExitDir, FsIterationTask onFile, ref FsIterationTaskClosure closure) { using var pathBuffer = new Path(); @@ -172,12 +172,12 @@ internal static class Utility ref closure); } - public static Result CopyFile(IFileSystem destFileSystem, IFileSystem sourceFileSystem, in Path destPath, - in Path sourcePath, Span workBuffer) + public static Result CopyFile(IFileSystem destFileSystem, IFileSystem sourceFileSystem, ref readonly Path destPath, + ref readonly Path sourcePath, Span workBuffer) { // Open source file. using var sourceFile = new UniqueRef(); - Result res = sourceFileSystem.OpenFile(ref sourceFile.Ref, sourcePath, OpenMode.Read); + Result res = sourceFileSystem.OpenFile(ref sourceFile.Ref, in sourcePath, OpenMode.Read); if (res.IsFailure()) return res.Miss(); res = sourceFile.Get.GetSize(out long fileSize); @@ -210,9 +210,10 @@ internal static class Utility } public static Result CopyDirectoryRecursively(IFileSystem destinationFileSystem, IFileSystem sourceFileSystem, - in Path destinationPath, in Path sourcePath, ref DirectoryEntry dirEntry, Span workBuffer) + ref readonly Path destinationPath, ref readonly Path sourcePath, ref DirectoryEntry dirEntry, + Span workBuffer) { - static Result OnEnterDir(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) + static Result OnEnterDir(ref readonly Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) { Result res = closure.DestinationPathBuffer.AppendChild(entry.Name); if (res.IsFailure()) return res.Miss(); @@ -220,12 +221,12 @@ internal static class Utility return closure.SourceFileSystem.CreateDirectory(in closure.DestinationPathBuffer); } - static Result OnExitDir(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) + static Result OnExitDir(ref readonly Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) { return closure.DestinationPathBuffer.RemoveChild(); } - static Result OnFile(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) + static Result OnFile(ref readonly Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) { Result res = closure.DestinationPathBuffer.AppendChild(entry.Name); if (res.IsFailure()) return res.Miss(); @@ -242,7 +243,7 @@ internal static class Utility closure.SourceFileSystem = sourceFileSystem; closure.DestFileSystem = destinationFileSystem; - Result res = closure.DestinationPathBuffer.Initialize(destinationPath); + Result res = closure.DestinationPathBuffer.Initialize(in destinationPath); if (res.IsFailure()) return res.Miss(); res = IterateDirectoryRecursively(sourceFileSystem, in sourcePath, ref dirEntry, OnEnterDir, OnExitDir, @@ -252,17 +253,17 @@ internal static class Utility return res; } - public static Result CopyDirectoryRecursively(IFileSystem fileSystem, in Path destinationPath, - in Path sourcePath, ref DirectoryEntry dirEntry, Span workBuffer) + public static Result CopyDirectoryRecursively(IFileSystem fileSystem, ref readonly Path destinationPath, + ref readonly Path sourcePath, ref DirectoryEntry dirEntry, Span workBuffer) { var closure = new FsIterationTaskClosure(); closure.Buffer = workBuffer; closure.SourceFileSystem = fileSystem; - Result res = closure.DestinationPathBuffer.Initialize(destinationPath); + Result res = closure.DestinationPathBuffer.Initialize(in destinationPath); if (res.IsFailure()) return res.Miss(); - static Result OnEnterDir(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) + static Result OnEnterDir(ref readonly Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) { Result res = closure.DestinationPathBuffer.AppendChild(entry.Name); if (res.IsFailure()) return res.Miss(); @@ -270,12 +271,12 @@ internal static class Utility return closure.SourceFileSystem.CreateDirectory(in closure.DestinationPathBuffer); } - static Result OnExitDir(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) + static Result OnExitDir(ref readonly Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) { return closure.DestinationPathBuffer.RemoveChild(); } - static Result OnFile(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) + static Result OnFile(ref readonly Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) { Result res = closure.DestinationPathBuffer.AppendChild(entry.Name); if (res.IsFailure()) return res.Miss(); @@ -296,10 +297,10 @@ internal static class Utility public static Result VerifyDirectoryRecursively(IFileSystem fileSystem, Span workBuffer) { - static Result OnEnterAndExitDir(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) => + static Result OnEnterAndExitDir(ref readonly Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) => Result.Success; - static Result OnFile(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) + static Result OnFile(ref readonly Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) { using var file = new UniqueRef(); @@ -336,7 +337,7 @@ internal static class Utility OnEnterAndExitDir, OnFile, ref closure); } - private static Result EnsureDirectoryImpl(IFileSystem fileSystem, in Path path) + private static Result EnsureDirectoryImpl(IFileSystem fileSystem, ref readonly Path path) { using var pathCopy = new Path(); bool isFinished; @@ -378,7 +379,7 @@ internal static class Utility return Result.Success; } - public static Result EnsureDirectory(IFileSystem fileSystem, in Path path) + public static Result EnsureDirectory(IFileSystem fileSystem, ref readonly Path path) { Result res = fileSystem.GetEntryType(out _, in path); diff --git a/src/LibHac/Gc/GameCardEmulated.cs b/src/LibHac/Gc/GameCardEmulated.cs index 47e503ad..08cd34ca 100644 --- a/src/LibHac/Gc/GameCardEmulated.cs +++ b/src/LibHac/Gc/GameCardEmulated.cs @@ -68,7 +68,7 @@ public sealed class GameCardEmulated : IGcApi }; } - public void InsertGameCard(in SharedRef storage) + public void InsertGameCard(ref readonly SharedRef storage) { _attached = false; _activated = false; diff --git a/src/LibHac/Gc/IGcApi.cs b/src/LibHac/Gc/IGcApi.cs index 29c7d474..4cc92862 100644 --- a/src/LibHac/Gc/IGcApi.cs +++ b/src/LibHac/Gc/IGcApi.cs @@ -8,7 +8,7 @@ namespace LibHac.Gc; public interface IGcApi { IGcWriterApi Writer { get; } - void InsertGameCard(in SharedRef storage); + void InsertGameCard(ref readonly SharedRef storage); void RemoveGameCard(); void PresetInternalKeys(ReadOnlySpan gameCardKey, ReadOnlySpan gameCardCertificate); void Initialize(Memory workBuffer, ulong deviceBufferAddress); diff --git a/src/LibHac/GcSrv/GameCardManager.cs b/src/LibHac/GcSrv/GameCardManager.cs index 7be31806..909c6e5c 100644 --- a/src/LibHac/GcSrv/GameCardManager.cs +++ b/src/LibHac/GcSrv/GameCardManager.cs @@ -569,7 +569,7 @@ public class GameCardManager : IStorageDeviceManager, IStorageDeviceOperator, IG return new WriteOnlyGameCardStorage(ref manager.Ref, _gc); } - private SharedRef CreateStorageDeviceNonSecure(in SharedRef baseStorage, + private SharedRef CreateStorageDeviceNonSecure(ref readonly SharedRef baseStorage, GameCardHandle handle) { using SharedRef manager = SharedRef.Create(in _selfReference); @@ -580,7 +580,7 @@ public class GameCardManager : IStorageDeviceManager, IStorageDeviceOperator, IG return SharedRef.CreateMove(ref storageDevice.Ref); } - private SharedRef CreateStorageDeviceSecure(in SharedRef baseStorage, + private SharedRef CreateStorageDeviceSecure(ref readonly SharedRef baseStorage, GameCardHandle handle, ReadOnlySpan cardDeviceId, ReadOnlySpan cardImageHash) { using SharedRef manager = SharedRef.Create(in _selfReference); diff --git a/src/LibHac/GcSrv/GameCardStorage.cs b/src/LibHac/GcSrv/GameCardStorage.cs index c2fa6e39..0ac0ffb2 100644 --- a/src/LibHac/GcSrv/GameCardStorage.cs +++ b/src/LibHac/GcSrv/GameCardStorage.cs @@ -173,7 +173,7 @@ internal abstract class GameCardStorageInterfaceAdapter : IStorageSf { private SharedRef _baseStorage; - protected GameCardStorageInterfaceAdapter(in SharedRef baseStorage) + protected GameCardStorageInterfaceAdapter(ref readonly SharedRef baseStorage) { _baseStorage = SharedRef.CreateCopy(in baseStorage); } diff --git a/src/LibHac/GcSrv/GameCardStorageDevice.cs b/src/LibHac/GcSrv/GameCardStorageDevice.cs index d872c47d..6dcd064a 100644 --- a/src/LibHac/GcSrv/GameCardStorageDevice.cs +++ b/src/LibHac/GcSrv/GameCardStorageDevice.cs @@ -27,7 +27,7 @@ internal class GameCardStorageDevice : GameCardStorageInterfaceAdapter, IStorage private readonly IGcApi _gc; private GameCardStorageDevice(IGcApi gc, ref SharedRef manager, - in SharedRef baseStorage, GameCardHandle handle) : base(in baseStorage) + ref readonly SharedRef baseStorage, GameCardHandle handle) : base(in baseStorage) { _manager = SharedRef.CreateMove(ref manager); _handle = handle; @@ -37,8 +37,8 @@ internal class GameCardStorageDevice : GameCardStorageInterfaceAdapter, IStorage } private GameCardStorageDevice(IGcApi gc, ref SharedRef manager, - in SharedRef baseStorage, GameCardHandle handle, bool isSecure, ReadOnlySpan cardDeviceId, - ReadOnlySpan cardImageHash) + ref readonly SharedRef baseStorage, GameCardHandle handle, bool isSecure, + ReadOnlySpan cardDeviceId, ReadOnlySpan cardImageHash) : base(in baseStorage) { Assert.SdkRequiresEqual(cardDeviceId.Length, Values.GcCardDeviceIdSize); @@ -55,7 +55,7 @@ internal class GameCardStorageDevice : GameCardStorageInterfaceAdapter, IStorage } public static SharedRef CreateShared(IGcApi gc, ref SharedRef manager, - in SharedRef baseStorage, GameCardHandle handle) + ref readonly SharedRef baseStorage, GameCardHandle handle) { var storageDevice = new GameCardStorageDevice(gc, ref manager, in baseStorage, handle); @@ -66,8 +66,8 @@ internal class GameCardStorageDevice : GameCardStorageInterfaceAdapter, IStorage } public static SharedRef CreateShared(IGcApi gc, ref SharedRef manager, - in SharedRef baseStorage, GameCardHandle handle, bool isSecure, ReadOnlySpan cardDeviceId, - ReadOnlySpan cardImageHash) + ref readonly SharedRef baseStorage, GameCardHandle handle, bool isSecure, + ReadOnlySpan cardDeviceId, ReadOnlySpan cardImageHash) { var storageDevice = new GameCardStorageDevice(gc, ref manager, in baseStorage, handle, isSecure, cardDeviceId, cardImageHash); diff --git a/src/LibHac/Kernel/InitialProcessBinaryReader.cs b/src/LibHac/Kernel/InitialProcessBinaryReader.cs index 16900abd..cbbdb053 100644 --- a/src/LibHac/Kernel/InitialProcessBinaryReader.cs +++ b/src/LibHac/Kernel/InitialProcessBinaryReader.cs @@ -23,7 +23,7 @@ public class InitialProcessBinaryReader : IDisposable _storage.Destroy(); } - public Result Initialize(in SharedRef binaryStorage) + public Result Initialize(ref readonly SharedRef binaryStorage) { if (!binaryStorage.HasValue) return ResultLibHac.NullArgument.Log(); @@ -47,7 +47,7 @@ public class InitialProcessBinaryReader : IDisposable // There's no metadata with the offsets of each KIP; they're all stored sequentially in the file. // Read the size of each KIP to get their offsets. - res = GetKipOffsets(out _offsets, binaryStorage, _header.ProcessCount); + res = GetKipOffsets(out _offsets, in binaryStorage, _header.ProcessCount); if (res.IsFailure()) return res.Miss(); _storage.SetByCopy(in binaryStorage); @@ -64,8 +64,8 @@ public class InitialProcessBinaryReader : IDisposable return Result.Success; } - private static Result GetKipOffsets(out (int offset, int size)[] kipOffsets, in SharedRef iniStorage, - int processCount) + private static Result GetKipOffsets(out (int offset, int size)[] kipOffsets, + ref readonly SharedRef iniStorage, int processCount) { Assert.SdkRequiresLessEqual(processCount, MaxProcessCount); diff --git a/src/LibHac/Kernel/KipReader.cs b/src/LibHac/Kernel/KipReader.cs index 8d42bc16..f330a7ec 100644 --- a/src/LibHac/Kernel/KipReader.cs +++ b/src/LibHac/Kernel/KipReader.cs @@ -39,7 +39,7 @@ public class KipReader : IDisposable _kipStorage.Destroy(); } - public Result Initialize(in SharedRef kipData) + public Result Initialize(ref readonly SharedRef kipData) { if (!kipData.HasValue) return ResultLibHac.NullArgument.Log(); diff --git a/src/LibHac/Lr/ILocationResolver.cs b/src/LibHac/Lr/ILocationResolver.cs index ddbf955c..8b5b25d6 100644 --- a/src/LibHac/Lr/ILocationResolver.cs +++ b/src/LibHac/Lr/ILocationResolver.cs @@ -7,23 +7,23 @@ namespace LibHac.Lr; public interface ILocationResolver : IDisposable { Result ResolveProgramPath(out Path path, ProgramId id); - Result RedirectProgramPath(in Path path, ProgramId id); + Result RedirectProgramPath(ref readonly Path path, ProgramId id); Result ResolveApplicationControlPath(out Path path, ProgramId id); Result ResolveApplicationHtmlDocumentPath(out Path path, ProgramId id); Result ResolveDataPath(out Path path, DataId id); - Result RedirectApplicationControlPath(in Path path, ProgramId id, ProgramId ownerId); - Result RedirectApplicationHtmlDocumentPath(in Path path, ProgramId id, ProgramId ownerId); + Result RedirectApplicationControlPath(ref readonly Path path, ProgramId id, ProgramId ownerId); + Result RedirectApplicationHtmlDocumentPath(ref readonly Path path, ProgramId id, ProgramId ownerId); Result ResolveApplicationLegalInformationPath(out Path path, ProgramId id); - Result RedirectApplicationLegalInformationPath(in Path path, ProgramId id, ProgramId ownerId); + Result RedirectApplicationLegalInformationPath(ref readonly Path path, ProgramId id, ProgramId ownerId); Result Refresh(); - Result RedirectApplicationProgramPath(in Path path, ProgramId id, ProgramId ownerId); + Result RedirectApplicationProgramPath(ref readonly Path path, ProgramId id, ProgramId ownerId); Result ClearApplicationRedirection(InArray excludingIds); Result EraseProgramRedirection(ProgramId id); Result EraseApplicationControlRedirection(ProgramId id); Result EraseApplicationHtmlDocumentRedirection(ProgramId id); Result EraseApplicationLegalInformationRedirection(ProgramId id); Result ResolveProgramPathForDebug(out Path path, ProgramId id); - Result RedirectProgramPathForDebug(in Path path, ProgramId id); - Result RedirectApplicationProgramPathForDebug(in Path path, ProgramId id, ProgramId ownerId); + Result RedirectProgramPathForDebug(ref readonly Path path, ProgramId id); + Result RedirectApplicationProgramPathForDebug(ref readonly Path path, ProgramId id, ProgramId ownerId); Result EraseProgramRedirectionForDebug(ProgramId id); } \ No newline at end of file diff --git a/src/LibHac/Lr/IRegisteredLocationResolver.cs b/src/LibHac/Lr/IRegisteredLocationResolver.cs index 95c2665f..4c121075 100644 --- a/src/LibHac/Lr/IRegisteredLocationResolver.cs +++ b/src/LibHac/Lr/IRegisteredLocationResolver.cs @@ -6,13 +6,13 @@ namespace LibHac.Lr; public interface IRegisteredLocationResolver : IDisposable { Result ResolveProgramPath(out Path path, ProgramId id); - Result RegisterProgramPath(in Path path, ProgramId id, ProgramId ownerId); + Result RegisterProgramPath(ref readonly Path path, ProgramId id, ProgramId ownerId); Result UnregisterProgramPath(ProgramId id); - Result RedirectProgramPath(in Path path, ProgramId id, ProgramId ownerId); + Result RedirectProgramPath(ref readonly Path path, ProgramId id, ProgramId ownerId); Result ResolveHtmlDocumentPath(out Path path, ProgramId id); - Result RegisterHtmlDocumentPath(in Path path, ProgramId id, ProgramId ownerId); + Result RegisterHtmlDocumentPath(ref readonly Path path, ProgramId id, ProgramId ownerId); Result UnregisterHtmlDocumentPath(ProgramId id); - Result RedirectHtmlDocumentPath(in Path path, ProgramId id); + Result RedirectHtmlDocumentPath(ref readonly Path path, ProgramId id); Result Refresh(); Result RefreshExcluding(ReadOnlySpan ids); } \ No newline at end of file diff --git a/src/LibHac/Lr/LocationResolver.cs b/src/LibHac/Lr/LocationResolver.cs index 7f88c6c8..5e7c7f53 100644 --- a/src/LibHac/Lr/LocationResolver.cs +++ b/src/LibHac/Lr/LocationResolver.cs @@ -22,7 +22,7 @@ public class LocationResolver : IDisposable public Result ResolveProgramPath(out Path path, ProgramId id) => _interface.Get.ResolveProgramPath(out path, id); - public Result RedirectProgramPath(in Path path, ProgramId id) => + public Result RedirectProgramPath(ref readonly Path path, ProgramId id) => _interface.Get.RedirectProgramPath(in path, id); public Result ResolveApplicationControlPath(out Path path, ProgramId id) => @@ -34,22 +34,22 @@ public class LocationResolver : IDisposable public Result ResolveDataPath(out Path path, DataId id) => _interface.Get.ResolveDataPath(out path, id); - public Result RedirectApplicationControlPath(in Path path, ProgramId id, ProgramId ownerId) => + public Result RedirectApplicationControlPath(ref readonly Path path, ProgramId id, ProgramId ownerId) => _interface.Get.RedirectApplicationControlPath(in path, id, ownerId); - public Result RedirectApplicationHtmlDocumentPath(in Path path, ProgramId id, ProgramId ownerId) => + public Result RedirectApplicationHtmlDocumentPath(ref readonly Path path, ProgramId id, ProgramId ownerId) => _interface.Get.RedirectApplicationHtmlDocumentPath(in path, id, ownerId); public Result ResolveApplicationLegalInformationPath(out Path path, ProgramId id) => _interface.Get.ResolveApplicationLegalInformationPath(out path, id); - public Result RedirectApplicationLegalInformationPath(in Path path, ProgramId id, ProgramId ownerId) => + public Result RedirectApplicationLegalInformationPath(ref readonly Path path, ProgramId id, ProgramId ownerId) => _interface.Get.RedirectApplicationLegalInformationPath(in path, id, ownerId); public Result Refresh() => _interface.Get.Refresh(); - public Result RedirectApplicationProgramPath(in Path path, ProgramId id, ProgramId ownerId) => + public Result RedirectApplicationProgramPath(ref readonly Path path, ProgramId id, ProgramId ownerId) => _interface.Get.RedirectApplicationProgramPath(in path, id, ownerId); public Result ClearApplicationRedirection(InArray excludingIds) => @@ -70,10 +70,10 @@ public class LocationResolver : IDisposable public Result ResolveProgramPathForDebug(out Path path, ProgramId id) => _interface.Get.ResolveProgramPathForDebug(out path, id); - public Result RedirectProgramPathForDebug(in Path path, ProgramId id) => + public Result RedirectProgramPathForDebug(ref readonly Path path, ProgramId id) => _interface.Get.RedirectProgramPathForDebug(in path, id); - public Result RedirectApplicationProgramPathForDebug(in Path path, ProgramId id, ProgramId ownerId) => + public Result RedirectApplicationProgramPathForDebug(ref readonly Path path, ProgramId id, ProgramId ownerId) => _interface.Get.RedirectApplicationProgramPathForDebug(in path, id, ownerId); public Result EraseProgramRedirectionForDebug(ProgramId id) => diff --git a/src/LibHac/Lr/RegisteredLocationResolver.cs b/src/LibHac/Lr/RegisteredLocationResolver.cs index 1e2b7c1d..0cd4dd4f 100644 --- a/src/LibHac/Lr/RegisteredLocationResolver.cs +++ b/src/LibHac/Lr/RegisteredLocationResolver.cs @@ -21,25 +21,25 @@ public class RegisteredLocationResolver : IDisposable public Result ResolveProgramPath(out Path path, ProgramId id) => _interface.Get.ResolveProgramPath(out path, id); - public Result RegisterProgramPath(in Path path, ProgramId id, ProgramId ownerId) => + public Result RegisterProgramPath(ref readonly Path path, ProgramId id, ProgramId ownerId) => _interface.Get.RegisterProgramPath(in path, id, ownerId); public Result UnregisterProgramPath(ProgramId id) => _interface.Get.UnregisterProgramPath(id); - public Result RedirectProgramPath(in Path path, ProgramId id, ProgramId ownerId) => + public Result RedirectProgramPath(ref readonly Path path, ProgramId id, ProgramId ownerId) => _interface.Get.RedirectProgramPath(in path, id, ownerId); public Result ResolveHtmlDocumentPath(out Path path, ProgramId id) => _interface.Get.ResolveHtmlDocumentPath(out path, id); - public Result RegisterHtmlDocumentPath(in Path path, ProgramId id, ProgramId ownerId) => + public Result RegisterHtmlDocumentPath(ref readonly Path path, ProgramId id, ProgramId ownerId) => _interface.Get.RegisterHtmlDocumentPath(in path, id, ownerId); public Result UnregisterHtmlDocumentPath(ProgramId id) => _interface.Get.UnregisterHtmlDocumentPath(id); - public Result RedirectHtmlDocumentPath(in Path path, ProgramId id) => + public Result RedirectHtmlDocumentPath(ref readonly Path path, ProgramId id) => _interface.Get.RedirectHtmlDocumentPath(in path, id); public Result Refresh() => diff --git a/src/LibHac/Os/ReaderWriterLock.cs b/src/LibHac/Os/ReaderWriterLock.cs index 5261d9a0..f63e98c0 100644 --- a/src/LibHac/Os/ReaderWriterLock.cs +++ b/src/LibHac/Os/ReaderWriterLock.cs @@ -76,21 +76,21 @@ public static class ReaderWriterLockApi os.Impl.ReleaseWriteLockImpl(ref rwLock); } - public static bool IsReadLockHeld(this OsState os, in ReaderWriterLockType rwLock) + public static bool IsReadLockHeld(this OsState os, ref readonly ReaderWriterLockType rwLock) { Assert.SdkRequires(rwLock.LockState == ReaderWriterLockType.State.Initialized); return ReaderWriterLockImpl.GetReadLockCount(in ReaderWriterLockImpl.GetLockCountRo(in rwLock)) != 0; } // Todo: Use Horizon thread APIs - public static bool IsWriteLockHeldByCurrentThread(this OsState os, in ReaderWriterLockType rwLock) + public static bool IsWriteLockHeldByCurrentThread(this OsState os, ref readonly ReaderWriterLockType rwLock) { Assert.SdkRequires(rwLock.LockState == ReaderWriterLockType.State.Initialized); return rwLock.OwnerThread == Environment.CurrentManagedThreadId && ReaderWriterLockImpl.GetWriteLockCount(in rwLock) != 0; } - public static bool IsReaderWriterLockOwnerThread(this OsState os, in ReaderWriterLockType rwLock) + public static bool IsReaderWriterLockOwnerThread(this OsState os, ref readonly ReaderWriterLockType rwLock) { Assert.SdkRequires(rwLock.LockState == ReaderWriterLockType.State.Initialized); return rwLock.OwnerThread == Environment.CurrentManagedThreadId; diff --git a/src/LibHac/Os/UniqueLock.cs b/src/LibHac/Os/UniqueLock.cs index 0e38690c..337d33f1 100644 --- a/src/LibHac/Os/UniqueLock.cs +++ b/src/LibHac/Os/UniqueLock.cs @@ -26,7 +26,7 @@ public static class UniqueLock } #pragma warning disable CS8500 // This takes the address of, gets the size of, or declares a pointer to a managed type - public static unsafe ref UniqueLockRef Ref(this scoped in UniqueLockRef value) where T : struct, ILockable + public static unsafe ref UniqueLockRef Ref(this in UniqueLockRef value) where T : struct, ILockable { fixed (UniqueLockRef* p = &value) { diff --git a/src/LibHac/Sf/Buffers.cs b/src/LibHac/Sf/Buffers.cs index 78095c73..9a9d6a3b 100644 --- a/src/LibHac/Sf/Buffers.cs +++ b/src/LibHac/Sf/Buffers.cs @@ -29,7 +29,7 @@ public readonly ref struct InBuffer } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static InBuffer FromStruct(in T value) where T : unmanaged + public static InBuffer FromStruct(ref readonly T value) where T : unmanaged { return new InBuffer(SpanHelpers.AsReadOnlyByteSpan(in value)); } diff --git a/src/LibHac/Tools/Fs/InMemoryFileSystem.cs b/src/LibHac/Tools/Fs/InMemoryFileSystem.cs index f1a9b36c..053a4927 100644 --- a/src/LibHac/Tools/Fs/InMemoryFileSystem.cs +++ b/src/LibHac/Tools/Fs/InMemoryFileSystem.cs @@ -22,12 +22,12 @@ public class InMemoryFileSystem : IAttributeFileSystem FsTable = new FileTable(); } - protected override Result DoCreateDirectory(in Path path) + protected override Result DoCreateDirectory(ref readonly Path path) { return FsTable.AddDirectory(new U8Span(path.GetString())); } - protected override Result DoCreateDirectory(in Path path, NxFileAttributes archiveAttribute) + protected override Result DoCreateDirectory(ref readonly Path path, NxFileAttributes archiveAttribute) { Result res = FsTable.AddDirectory(new U8Span(path.GetString())); if (res.IsFailure()) return res.Miss(); @@ -39,7 +39,7 @@ public class InMemoryFileSystem : IAttributeFileSystem return Result.Success; } - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) { Result res = FsTable.AddFile(new U8Span(path.GetString())); if (res.IsFailure()) return res.Miss(); @@ -50,27 +50,27 @@ public class InMemoryFileSystem : IAttributeFileSystem return file.File.SetSize(size); } - protected override Result DoDeleteDirectory(in Path path) + protected override Result DoDeleteDirectory(ref readonly Path path) { return FsTable.DeleteDirectory(new U8Span(path.GetString()), false); } - protected override Result DoDeleteDirectoryRecursively(in Path path) + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) { return FsTable.DeleteDirectory(new U8Span(path.GetString()), true); } - protected override Result DoCleanDirectoryRecursively(in Path path) + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) { return FsTable.CleanDirectory(new U8Span(path.GetString())); } - protected override Result DoDeleteFile(in Path path) + protected override Result DoDeleteFile(ref readonly Path path) { return FsTable.DeleteFile(new U8Span(path.GetString())); } - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { Result res = FsTable.GetDirectory(new U8Span(path.GetString()), out DirectoryNode dirNode); @@ -80,7 +80,7 @@ public class InMemoryFileSystem : IAttributeFileSystem return Result.Success; } - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { Result res = FsTable.GetFile(new U8Span(path.GetString()), out FileNode fileNode); if (res.IsFailure()) return res.Miss(); @@ -90,17 +90,17 @@ public class InMemoryFileSystem : IAttributeFileSystem return Result.Success; } - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) { return FsTable.RenameDirectory(new U8Span(currentPath.GetString()), new U8Span(newPath.GetString())); } - protected override Result DoRenameFile(in Path currentPath, in Path newPath) + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) { return FsTable.RenameFile(new U8Span(currentPath.GetString()), new U8Span(newPath.GetString())); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out entryType); @@ -124,7 +124,7 @@ public class InMemoryFileSystem : IAttributeFileSystem return Result.Success; } - protected override Result DoGetFileAttributes(out NxFileAttributes attributes, in Path path) + protected override Result DoGetFileAttributes(out NxFileAttributes attributes, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out attributes); @@ -143,7 +143,7 @@ public class InMemoryFileSystem : IAttributeFileSystem return ResultFs.PathNotFound.Log(); } - protected override Result DoSetFileAttributes(in Path path, NxFileAttributes attributes) + protected override Result DoSetFileAttributes(ref readonly Path path, NxFileAttributes attributes) { if (FsTable.GetFile(new U8Span(path.GetString()), out FileNode file).IsSuccess()) { @@ -160,7 +160,7 @@ public class InMemoryFileSystem : IAttributeFileSystem return ResultFs.PathNotFound.Log(); } - protected override Result DoGetFileSize(out long fileSize, in Path path) + protected override Result DoGetFileSize(out long fileSize, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out fileSize); diff --git a/src/LibHac/Tools/FsSystem/AesXtsFileHeader.cs b/src/LibHac/Tools/FsSystem/AesXtsFileHeader.cs index 6904d1a6..77854c69 100644 --- a/src/LibHac/Tools/FsSystem/AesXtsFileHeader.cs +++ b/src/LibHac/Tools/FsSystem/AesXtsFileHeader.cs @@ -115,12 +115,12 @@ public class AesXtsFileHeader byte[] data = new byte[0x80]; Array.Copy(Signature, data, 0x20); - MemoryMarshal.Write(data.AsSpan(0x20), ref magic); + MemoryMarshal.Write(data.AsSpan(0x20), in magic); Array.Copy(key1, 0, data, 0x28, 0x10); Array.Copy(key2, 0, data, 0x38, 0x10); - MemoryMarshal.Write(data.AsSpan(0x48), ref size); + MemoryMarshal.Write(data.AsSpan(0x48), in size); return data; } diff --git a/src/LibHac/Tools/FsSystem/AesXtsFileSystem.cs b/src/LibHac/Tools/FsSystem/AesXtsFileSystem.cs index d538a8ac..5a4ee0ea 100644 --- a/src/LibHac/Tools/FsSystem/AesXtsFileSystem.cs +++ b/src/LibHac/Tools/FsSystem/AesXtsFileSystem.cs @@ -40,14 +40,14 @@ public class AesXtsFileSystem : IFileSystem base.Dispose(); } - protected override Result DoCreateDirectory(in Path path) + protected override Result DoCreateDirectory(ref readonly Path path) { - return _baseFileSystem.CreateDirectory(path); + return _baseFileSystem.CreateDirectory(in path); } - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) { - return CreateFile(path, size, option, new byte[0x20]); + return CreateFile(in path, size, option, new byte[0x20]); } /// @@ -58,7 +58,7 @@ public class AesXtsFileSystem : IFileSystem /// Flags to control how the file is created. /// Should usually be /// The 256-bit key containing a 128-bit data key followed by a 128-bit tweak key. - public Result CreateFile(in Path path, long size, CreateFileOptions options, byte[] key) + public Result CreateFile(ref readonly Path path, long size, CreateFileOptions options, byte[] key) { long containerSize = AesXtsFile.HeaderLength + Alignment.AlignUp(size, 0x10); @@ -77,41 +77,41 @@ public class AesXtsFileSystem : IFileSystem return Result.Success; } - protected override Result DoDeleteDirectory(in Path path) + protected override Result DoDeleteDirectory(ref readonly Path path) { - return _baseFileSystem.DeleteDirectory(path); + return _baseFileSystem.DeleteDirectory(in path); } - protected override Result DoDeleteDirectoryRecursively(in Path path) + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) { - return _baseFileSystem.DeleteDirectoryRecursively(path); + return _baseFileSystem.DeleteDirectoryRecursively(in path); } - protected override Result DoCleanDirectoryRecursively(in Path path) + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) { - return _baseFileSystem.CleanDirectoryRecursively(path); + return _baseFileSystem.CleanDirectoryRecursively(in path); } - protected override Result DoDeleteFile(in Path path) + protected override Result DoDeleteFile(ref readonly Path path) { - return _baseFileSystem.DeleteFile(path); + return _baseFileSystem.DeleteFile(in path); } - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { using var baseDir = new UniqueRef(); - Result res = _baseFileSystem.OpenDirectory(ref baseDir.Ref, path, mode); + Result res = _baseFileSystem.OpenDirectory(ref baseDir.Ref, in path, mode); if (res.IsFailure()) return res.Miss(); outDirectory.Reset(new AesXtsDirectory(_baseFileSystem, ref baseDir.Ref, new U8String(path.GetString().ToArray()), mode)); return Result.Success; } - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { using var baseFile = new UniqueRef(); - Result res = _baseFileSystem.OpenFile(ref baseFile.Ref, path, mode | OpenMode.Read); + Result res = _baseFileSystem.OpenFile(ref baseFile.Ref, in path, mode | OpenMode.Read); if (res.IsFailure()) return res.Miss(); var xtsFile = new AesXtsFile(mode, ref baseFile.Ref, new U8String(path.GetString().ToArray()), _kekSource, @@ -121,7 +121,7 @@ public class AesXtsFileSystem : IFileSystem return Result.Success; } - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) { // todo: Return proper result codes @@ -133,7 +133,7 @@ public class AesXtsFileSystem : IFileSystem // Reencrypt any modified file headers with the old path // Rename directory to the old path - Result res = _baseFileSystem.RenameDirectory(currentPath, newPath); + Result res = _baseFileSystem.RenameDirectory(in currentPath, in newPath); if (res.IsFailure()) return res.Miss(); try @@ -143,7 +143,7 @@ public class AesXtsFileSystem : IFileSystem catch (Exception) { RenameDirectoryImpl(currentPath.ToString(), newPath.ToString(), true); - _baseFileSystem.RenameDirectory(currentPath, newPath); + _baseFileSystem.RenameDirectory(in currentPath, in newPath); throw; } @@ -181,13 +181,13 @@ public class AesXtsFileSystem : IFileSystem } } - protected override Result DoRenameFile(in Path currentPath, in Path newPath) + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) { // todo: Return proper result codes AesXtsFileHeader header = ReadXtsHeader(currentPath.ToString(), currentPath.ToString()); - Result res = _baseFileSystem.RenameFile(currentPath, newPath); + Result res = _baseFileSystem.RenameFile(in currentPath, in newPath); if (res.IsFailure()) return res.Miss(); try @@ -196,7 +196,7 @@ public class AesXtsFileSystem : IFileSystem } catch (Exception) { - _baseFileSystem.RenameFile(newPath, currentPath); + _baseFileSystem.RenameFile(in newPath, in currentPath); WriteXtsHeader(header, currentPath.ToString(), currentPath.ToString()); throw; @@ -205,24 +205,24 @@ public class AesXtsFileSystem : IFileSystem return Result.Success; } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { - return _baseFileSystem.GetEntryType(out entryType, path); + return _baseFileSystem.GetEntryType(out entryType, in path); } - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, ref readonly Path path) { - return _baseFileSystem.GetFileTimeStampRaw(out timeStamp, path); + return _baseFileSystem.GetFileTimeStampRaw(out timeStamp, in path); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, ref readonly Path path) { - return _baseFileSystem.GetFreeSpaceSize(out freeSpace, path); + return _baseFileSystem.GetFreeSpaceSize(out freeSpace, in path); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, ref readonly Path path) { - return _baseFileSystem.GetTotalSpaceSize(out totalSpace, path); + return _baseFileSystem.GetTotalSpaceSize(out totalSpace, in path); } protected override Result DoCommit() @@ -241,9 +241,9 @@ public class AesXtsFileSystem : IFileSystem } protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - in Path path) + ref readonly Path path) { - return _baseFileSystem.QueryEntry(outBuffer, inBuffer, queryId, path); + return _baseFileSystem.QueryEntry(outBuffer, inBuffer, queryId, in path); } private AesXtsFileHeader ReadXtsHeader(string filePath, string keyPath) diff --git a/src/LibHac/Tools/FsSystem/CompressedStorage.cs b/src/LibHac/Tools/FsSystem/CompressedStorage.cs index b97e7f6b..78877345 100644 --- a/src/LibHac/Tools/FsSystem/CompressedStorage.cs +++ b/src/LibHac/Tools/FsSystem/CompressedStorage.cs @@ -43,8 +43,8 @@ internal class CompressedStorage : IStorage _dataStorage = new ValueSubStorage(); } - public Result Initialize(MemoryResource allocatorForBucketTree, in ValueSubStorage dataStorage, - in ValueSubStorage nodeStorage, in ValueSubStorage entryStorage, int bucketTreeEntryCount) + public Result Initialize(MemoryResource allocatorForBucketTree, ref readonly ValueSubStorage dataStorage, + ref readonly ValueSubStorage nodeStorage, ref readonly ValueSubStorage entryStorage, int bucketTreeEntryCount) { Result res = _bucketTree.Initialize(allocatorForBucketTree, in nodeStorage, in entryStorage, NodeSize, Unsafe.SizeOf(), bucketTreeEntryCount); diff --git a/src/LibHac/Tools/FsSystem/FileSystemExtensions.cs b/src/LibHac/Tools/FsSystem/FileSystemExtensions.cs index 3f1943c0..2baa736c 100644 --- a/src/LibHac/Tools/FsSystem/FileSystemExtensions.cs +++ b/src/LibHac/Tools/FsSystem/FileSystemExtensions.cs @@ -45,10 +45,10 @@ public static class FileSystemExtensions } public static Result CopyDirectoryRecursively(IFileSystem destinationFileSystem, IFileSystem sourceFileSystem, - in Path destinationPath, in Path sourcePath, ref DirectoryEntry dirEntry, Span workBuffer, - IProgressReport logger = null, CreateFileOptions option = CreateFileOptions.None) + ref readonly Path destinationPath, ref readonly Path sourcePath, ref DirectoryEntry dirEntry, + Span workBuffer, IProgressReport logger = null, CreateFileOptions option = CreateFileOptions.None) { - static Result OnEnterDir(in Path path, in DirectoryEntry entry, + static Result OnEnterDir(ref readonly Path path, in DirectoryEntry entry, ref Utility.FsIterationTaskClosure closure) { Result res = closure.DestinationPathBuffer.AppendChild(entry.Name); @@ -60,12 +60,12 @@ public static class FileSystemExtensions return Result.Success; } - static Result OnExitDir(in Path path, in DirectoryEntry entry, ref Utility.FsIterationTaskClosure closure) + static Result OnExitDir(ref readonly Path path, in DirectoryEntry entry, ref Utility.FsIterationTaskClosure closure) { return closure.DestinationPathBuffer.RemoveChild(); } - Result OnFile(in Path path, in DirectoryEntry entry, ref Utility.FsIterationTaskClosure closure) + Result OnFile(ref readonly Path path, in DirectoryEntry entry, ref Utility.FsIterationTaskClosure closure) { logger?.LogMessage(path.ToString()); @@ -84,7 +84,7 @@ public static class FileSystemExtensions taskClosure.SourceFileSystem = sourceFileSystem; taskClosure.DestFileSystem = destinationFileSystem; - Result res = taskClosure.DestinationPathBuffer.Initialize(destinationPath); + Result res = taskClosure.DestinationPathBuffer.Initialize(in destinationPath); if (res.IsFailure()) return res.Miss(); res = Utility.IterateDirectoryRecursively(sourceFileSystem, in sourcePath, ref dirEntry, OnEnterDir, @@ -94,13 +94,13 @@ public static class FileSystemExtensions return res; } - public static Result CopyFile(IFileSystem destFileSystem, IFileSystem sourceFileSystem, in Path destPath, - in Path sourcePath, Span workBuffer, IProgressReport logger = null, + public static Result CopyFile(IFileSystem destFileSystem, IFileSystem sourceFileSystem, ref readonly Path destPath, + ref readonly Path sourcePath, Span workBuffer, IProgressReport logger = null, CreateFileOptions option = CreateFileOptions.None) { // Open source file. using var sourceFile = new UniqueRef(); - Result res = sourceFileSystem.OpenFile(ref sourceFile.Ref, sourcePath, OpenMode.Read); + Result res = sourceFileSystem.OpenFile(ref sourceFile.Ref, in sourcePath, OpenMode.Read); if (res.IsFailure()) return res.Miss(); res = sourceFile.Get.GetSize(out long fileSize); @@ -352,7 +352,7 @@ public static class FileSystemExtensions return Utility.EnsureDirectory(fs, in pathNormalized); } - public static Result CreateOrOverwriteFile(IFileSystem fileSystem, in Path path, long size, + public static Result CreateOrOverwriteFile(IFileSystem fileSystem, ref readonly Path path, long size, CreateFileOptions option = CreateFileOptions.None) { Result res = fileSystem.CreateFile(in path, size, option); diff --git a/src/LibHac/Tools/FsSystem/LayeredFileSystem.cs b/src/LibHac/Tools/FsSystem/LayeredFileSystem.cs index 0744ecff..1b3ad576 100644 --- a/src/LibHac/Tools/FsSystem/LayeredFileSystem.cs +++ b/src/LibHac/Tools/FsSystem/LayeredFileSystem.cs @@ -37,7 +37,7 @@ public class LayeredFileSystem : IFileSystem Sources.AddRange(sourceFileSystems); } - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { // Open directories from all layers so they can be merged @@ -108,17 +108,17 @@ public class LayeredFileSystem : IFileSystem return ResultFs.PathNotFound.Log(); } - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { foreach (IFileSystem fs in Sources) { - Result res = fs.GetEntryType(out DirectoryEntryType type, path); + Result res = fs.GetEntryType(out DirectoryEntryType type, in path); if (res.IsSuccess()) { if (type == DirectoryEntryType.File) { - return fs.OpenFile(ref outFile, path, mode); + return fs.OpenFile(ref outFile, in path, mode); } if (type == DirectoryEntryType.Directory) @@ -135,13 +135,13 @@ public class LayeredFileSystem : IFileSystem return ResultFs.PathNotFound.Log(); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out entryType); foreach (IFileSystem fs in Sources) { - Result getEntryResult = fs.GetEntryType(out DirectoryEntryType type, path); + Result getEntryResult = fs.GetEntryType(out DirectoryEntryType type, in path); if (getEntryResult.IsSuccess()) { @@ -153,17 +153,17 @@ public class LayeredFileSystem : IFileSystem return ResultFs.PathNotFound.Log(); } - protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, in Path path) + protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out timeStamp); foreach (IFileSystem fs in Sources) { - Result getEntryResult = fs.GetEntryType(out _, path); + Result getEntryResult = fs.GetEntryType(out _, in path); if (getEntryResult.IsSuccess()) { - return fs.GetFileTimeStampRaw(out timeStamp, path); + return fs.GetFileTimeStampRaw(out timeStamp, in path); } } @@ -171,15 +171,15 @@ public class LayeredFileSystem : IFileSystem } protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, - in Path path) + ref readonly Path path) { foreach (IFileSystem fs in Sources) { - Result getEntryResult = fs.GetEntryType(out _, path); + Result getEntryResult = fs.GetEntryType(out _, in path); if (getEntryResult.IsSuccess()) { - return fs.QueryEntry(outBuffer, inBuffer, queryId, path); + return fs.QueryEntry(outBuffer, inBuffer, queryId, in path); } } @@ -191,14 +191,14 @@ public class LayeredFileSystem : IFileSystem return Result.Success; } - protected override Result DoCreateDirectory(in Path path) => ResultFs.UnsupportedOperation.Log(); - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) => ResultFs.UnsupportedOperation.Log(); - protected override Result DoDeleteDirectory(in Path path) => ResultFs.UnsupportedOperation.Log(); - protected override Result DoDeleteDirectoryRecursively(in Path path) => ResultFs.UnsupportedOperation.Log(); - protected override Result DoCleanDirectoryRecursively(in Path path) => ResultFs.UnsupportedOperation.Log(); - protected override Result DoDeleteFile(in Path path) => ResultFs.UnsupportedOperation.Log(); - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) => ResultFs.UnsupportedOperation.Log(); - protected override Result DoRenameFile(in Path currentPath, in Path newPath) => ResultFs.UnsupportedOperation.Log(); + protected override Result DoCreateDirectory(ref readonly Path path) => ResultFs.UnsupportedOperation.Log(); + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) => ResultFs.UnsupportedOperation.Log(); + protected override Result DoDeleteDirectory(ref readonly Path path) => ResultFs.UnsupportedOperation.Log(); + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) => ResultFs.UnsupportedOperation.Log(); + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) => ResultFs.UnsupportedOperation.Log(); + protected override Result DoDeleteFile(ref readonly Path path) => ResultFs.UnsupportedOperation.Log(); + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) => ResultFs.UnsupportedOperation.Log(); + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) => ResultFs.UnsupportedOperation.Log(); private class MergedDirectory : IDirectory { @@ -218,7 +218,7 @@ public class LayeredFileSystem : IFileSystem Mode = mode; } - public Result Initialize(in Path path) + public Result Initialize(ref readonly Path path) { Result res = _path.Initialize(in path); if (res.IsFailure()) return res.Miss(); diff --git a/src/LibHac/Tools/FsSystem/RomFs/RomFsFileSystem.cs b/src/LibHac/Tools/FsSystem/RomFs/RomFsFileSystem.cs index 269b1b37..f6d8c279 100644 --- a/src/LibHac/Tools/FsSystem/RomFs/RomFsFileSystem.cs +++ b/src/LibHac/Tools/FsSystem/RomFs/RomFsFileSystem.cs @@ -37,7 +37,7 @@ public class RomFsFileSystem : IFileSystem base.Dispose(); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out entryType); @@ -61,7 +61,7 @@ public class RomFsFileSystem : IFileSystem return Result.Success; } - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { if (!FileTable.TryOpenDirectory(path.ToString(), out FindPosition position)) @@ -73,7 +73,7 @@ public class RomFsFileSystem : IFileSystem return Result.Success; } - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { if (!FileTable.TryOpenFile(path.ToString(), out RomFileInfo info)) { @@ -95,23 +95,23 @@ public class RomFsFileSystem : IFileSystem return BaseStorage; } - protected override Result DoCreateDirectory(in Path path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); - protected override Result DoDeleteDirectory(in Path path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); - protected override Result DoDeleteDirectoryRecursively(in Path path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); - protected override Result DoCleanDirectoryRecursively(in Path path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); - protected override Result DoDeleteFile(in Path path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); - protected override Result DoRenameFile(in Path currentPath, in Path newPath) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); + protected override Result DoCreateDirectory(ref readonly Path path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); + protected override Result DoDeleteDirectory(ref readonly Path path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); + protected override Result DoDeleteFile(ref readonly Path path) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) => ResultFs.UnsupportedWriteForRomFsFileSystem.Log(); protected override Result DoCommitProvisionally(long counter) => ResultFs.UnsupportedCommitProvisionallyForRomFsFileSystem.Log(); - protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, ref readonly Path path) { freeSpace = 0; return Result.Success; } - protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out totalSpace); return ResultFs.UnsupportedGetTotalSpaceSizeForRomFsFileSystem.Log(); diff --git a/src/LibHac/Tools/FsSystem/Save/SaveDataFileSystem.cs b/src/LibHac/Tools/FsSystem/Save/SaveDataFileSystem.cs index 47859b67..b35dfd72 100644 --- a/src/LibHac/Tools/FsSystem/Save/SaveDataFileSystem.cs +++ b/src/LibHac/Tools/FsSystem/Save/SaveDataFileSystem.cs @@ -155,49 +155,49 @@ public class SaveDataFileSystem : IFileSystem IntegrityStorageType.Save, integrityCheckLevel, LeaveOpen); } - protected override Result DoCreateDirectory(in Path path) + protected override Result DoCreateDirectory(ref readonly Path path) { Result result = SaveDataFileSystemCore.CreateDirectory(in path); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) { Result result = SaveDataFileSystemCore.CreateFile(in path, size, option); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoDeleteDirectory(in Path path) + protected override Result DoDeleteDirectory(ref readonly Path path) { Result result = SaveDataFileSystemCore.DeleteDirectory(in path); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoDeleteDirectoryRecursively(in Path path) + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) { Result result = SaveDataFileSystemCore.DeleteDirectoryRecursively(in path); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoCleanDirectoryRecursively(in Path path) + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) { Result result = SaveDataFileSystemCore.CleanDirectoryRecursively(in path); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoDeleteFile(in Path path) + protected override Result DoDeleteFile(ref readonly Path path) { Result result = SaveDataFileSystemCore.DeleteFile(in path); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { Result result = SaveDataFileSystemCore.OpenDirectory(ref outDirectory, in path, mode); @@ -205,42 +205,42 @@ public class SaveDataFileSystem : IFileSystem return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { Result result = SaveDataFileSystemCore.OpenFile(ref outFile, in path, mode); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) { Result result = SaveDataFileSystemCore.RenameDirectory(in currentPath, in newPath); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoRenameFile(in Path currentPath, in Path newPath) + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) { Result result = SaveDataFileSystemCore.RenameFile(in currentPath, in newPath); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { Result result = SaveDataFileSystemCore.GetEntryType(out entryType, in path); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, ref readonly Path path) { Result result = SaveDataFileSystemCore.GetFreeSpaceSize(out freeSpace, in path); return SaveResults.ConvertToExternalResult(result).LogConverted(result); } - protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, ref readonly Path path) { Result result = SaveDataFileSystemCore.GetTotalSpaceSize(out totalSpace, in path); diff --git a/src/LibHac/Tools/FsSystem/Save/SaveDataFileSystemCore.cs b/src/LibHac/Tools/FsSystem/Save/SaveDataFileSystemCore.cs index f974c83d..f502f8a6 100644 --- a/src/LibHac/Tools/FsSystem/Save/SaveDataFileSystemCore.cs +++ b/src/LibHac/Tools/FsSystem/Save/SaveDataFileSystemCore.cs @@ -32,7 +32,7 @@ public class SaveDataFileSystemCore : IFileSystem FileTable = new HierarchicalSaveFileTable(dirTableStorage, fileTableStorage); } - private Result CheckIfNormalized(in Path path) + private Result CheckIfNormalized(ref readonly Path path) { Result res = PathNormalizer.IsNormalized(out bool isNormalized, out _, path.GetString()); if (res.IsFailure()) return res.Miss(); @@ -43,7 +43,7 @@ public class SaveDataFileSystemCore : IFileSystem return Result.Success; } - protected override Result DoCreateDirectory(in Path path) + protected override Result DoCreateDirectory(ref readonly Path path) { Result res = CheckIfNormalized(in path); if (res.IsFailure()) return res.Miss(); @@ -53,7 +53,7 @@ public class SaveDataFileSystemCore : IFileSystem return Result.Success; } - protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) + protected override Result DoCreateFile(ref readonly Path path, long size, CreateFileOptions option) { Result res = CheckIfNormalized(in path); if (res.IsFailure()) return res.Miss(); @@ -81,7 +81,7 @@ public class SaveDataFileSystemCore : IFileSystem return Result.Success; } - protected override Result DoDeleteDirectory(in Path path) + protected override Result DoDeleteDirectory(ref readonly Path path) { Result res = CheckIfNormalized(in path); if (res.IsFailure()) return res.Miss(); @@ -91,7 +91,7 @@ public class SaveDataFileSystemCore : IFileSystem return Result.Success; } - protected override Result DoDeleteDirectoryRecursively(in Path path) + protected override Result DoDeleteDirectoryRecursively(ref readonly Path path) { Result res = CheckIfNormalized(in path); if (res.IsFailure()) return res.Miss(); @@ -105,7 +105,7 @@ public class SaveDataFileSystemCore : IFileSystem return Result.Success; } - protected override Result DoCleanDirectoryRecursively(in Path path) + protected override Result DoCleanDirectoryRecursively(ref readonly Path path) { Result res = CheckIfNormalized(in path); if (res.IsFailure()) return res.Miss(); @@ -115,7 +115,7 @@ public class SaveDataFileSystemCore : IFileSystem return Result.Success; } - protected override Result DoDeleteFile(in Path path) + protected override Result DoDeleteFile(ref readonly Path path) { Result res = CheckIfNormalized(in path); if (res.IsFailure()) return res.Miss(); @@ -135,7 +135,7 @@ public class SaveDataFileSystemCore : IFileSystem return Result.Success; } - protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, + protected override Result DoOpenDirectory(ref UniqueRef outDirectory, ref readonly Path path, OpenDirectoryMode mode) { Result res = CheckIfNormalized(in path); @@ -151,7 +151,7 @@ public class SaveDataFileSystemCore : IFileSystem return Result.Success; } - protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) + protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { Result res = CheckIfNormalized(in path); if (res.IsFailure()) return res.Miss(); @@ -168,7 +168,7 @@ public class SaveDataFileSystemCore : IFileSystem return Result.Success; } - protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) + protected override Result DoRenameDirectory(ref readonly Path currentPath, ref readonly Path newPath) { Result res = CheckIfNormalized(in currentPath); if (res.IsFailure()) return res.Miss(); @@ -179,7 +179,7 @@ public class SaveDataFileSystemCore : IFileSystem return FileTable.RenameDirectory(new U8Span(currentPath.GetString()), new U8Span(newPath.GetString())); } - protected override Result DoRenameFile(in Path currentPath, in Path newPath) + protected override Result DoRenameFile(ref readonly Path currentPath, ref readonly Path newPath) { Result res = CheckIfNormalized(in currentPath); if (res.IsFailure()) return res.Miss(); @@ -192,7 +192,7 @@ public class SaveDataFileSystemCore : IFileSystem return Result.Success; } - protected override Result DoGetEntryType(out DirectoryEntryType entryType, in Path path) + protected override Result DoGetEntryType(out DirectoryEntryType entryType, ref readonly Path path) { UnsafeHelpers.SkipParamInit(out entryType); @@ -214,7 +214,7 @@ public class SaveDataFileSystemCore : IFileSystem return ResultFs.PathNotFound.Log(); } - protected override Result DoGetFreeSpaceSize(out long freeSpace, in Path path) + protected override Result DoGetFreeSpaceSize(out long freeSpace, ref readonly Path path) { int freeBlockCount = AllocationTable.GetFreeListLength(); freeSpace = Header.BlockSize * freeBlockCount; @@ -222,7 +222,7 @@ public class SaveDataFileSystemCore : IFileSystem return Result.Success; } - protected override Result DoGetTotalSpaceSize(out long totalSpace, in Path path) + protected override Result DoGetTotalSpaceSize(out long totalSpace, ref readonly Path path) { totalSpace = Header.BlockSize * Header.BlockCount; diff --git a/src/LibHac/Tools/FsSystem/Save/SaveFsList.cs b/src/LibHac/Tools/FsSystem/Save/SaveFsList.cs index 2654a90c..72ddcc85 100644 --- a/src/LibHac/Tools/FsSystem/Save/SaveFsList.cs +++ b/src/LibHac/Tools/FsSystem/Save/SaveFsList.cs @@ -295,7 +295,7 @@ internal class SaveFsList where T : struct private void SetListCapacity(int capacity) { Span buf = stackalloc byte[sizeof(int)]; - MemoryMarshal.Write(buf, ref capacity); + MemoryMarshal.Write(buf, in capacity); Storage.Write(4, buf).ThrowIfFailure(); } @@ -303,7 +303,7 @@ internal class SaveFsList where T : struct private void SetListLength(int length) { Span buf = stackalloc byte[sizeof(int)]; - MemoryMarshal.Write(buf, ref length); + MemoryMarshal.Write(buf, in length); Storage.Write(0, buf).ThrowIfFailure(); } diff --git a/src/hactoolnet/ProcessKip.cs b/src/hactoolnet/ProcessKip.cs index f95daa3f..931b892f 100644 --- a/src/hactoolnet/ProcessKip.cs +++ b/src/hactoolnet/ProcessKip.cs @@ -38,10 +38,10 @@ internal static class ProcessKip } } - public static void ExtractIni1(in SharedRef iniStorage, string outDir) + public static void ExtractIni1(ref readonly SharedRef iniStorage, string outDir) { using var ini1 = new InitialProcessBinaryReader(); - ini1.Initialize(iniStorage).ThrowIfFailure(); + ini1.Initialize(in iniStorage).ThrowIfFailure(); Directory.CreateDirectory(outDir); using var kipReader = new KipReader(); diff --git a/src/hactoolnet/Program.cs b/src/hactoolnet/Program.cs index e4e49369..5cb60778 100644 --- a/src/hactoolnet/Program.cs +++ b/src/hactoolnet/Program.cs @@ -84,7 +84,7 @@ public static class Program // ReSharper disable once AccessToDisposedClosure // References to logWriter should be gone by the time it's disposed ctx.Horizon.Diag.InitializeLogObserverHolder(ref logObserver, - (in LogMetaData data, in LogBody body, object arguments) => + (ref readonly LogMetaData data, ref readonly LogBody body, object arguments) => logWriter.Write(body.Message.ToString()), null); ctx.Horizon.Diag.RegisterLogObserver(logObserver); diff --git a/tests/LibHac.Tests/BufferStructTests.cs b/tests/LibHac.Tests/BufferStructTests.cs index be07aa3d..eebbd7ab 100644 --- a/tests/LibHac.Tests/BufferStructTests.cs +++ b/tests/LibHac.Tests/BufferStructTests.cs @@ -50,7 +50,7 @@ public class BufferStructTests ReadOnlySpan byteSpan = buffer; Assert.Equal(16, byteSpan.Length); - Assert.True(Unsafe.AreSame(ref Unsafe.As(ref buffer), ref Unsafe.AsRef(byteSpan[0]))); + Assert.True(Unsafe.AreSame(ref Unsafe.As(ref buffer), ref Unsafe.AsRef(in byteSpan[0]))); } [Fact] diff --git a/tests/LibHac.Tests/Common/Layout.cs b/tests/LibHac.Tests/Common/Layout.cs index dc1842ac..61876159 100644 --- a/tests/LibHac.Tests/Common/Layout.cs +++ b/tests/LibHac.Tests/Common/Layout.cs @@ -5,7 +5,7 @@ namespace LibHac.Tests.Common; public class Layout { - public static int GetOffset(in TStruct structRef, in TField fieldRef) + public static int GetOffset(ref readonly TStruct structRef, ref readonly TField fieldRef) { ref TField structOffset = ref Unsafe.As(ref Unsafe.AsRef(in structRef)); ref TField fieldOffset = ref Unsafe.AsRef(in fieldRef); diff --git a/tests/LibHac.Tests/LibHacTestFramework.cs b/tests/LibHac.Tests/LibHacTestFramework.cs index 8d8aa148..5a5a985a 100644 --- a/tests/LibHac.Tests/LibHacTestFramework.cs +++ b/tests/LibHac.Tests/LibHacTestFramework.cs @@ -23,7 +23,7 @@ public class LibHacTestFramework : XunitTestFramework private static void SetDebugHandler() { - AssertionFailureHandler handler = (in AssertionInfo info) => + AssertionFailureHandler handler = (ref readonly AssertionInfo info) => { if (SkipAbortFunctions.Contains(info.FunctionName)) {