From 6a5d03e1f32fa1721a822e66eab4b75e68d12a1f Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sun, 5 May 2024 23:08:53 -0700 Subject: [PATCH] Use `ref readonly` for many incoming `SharedRef` parameters --- src/LibHac/Bcat/Impl/Ipc/BcatServiceObject.cs | 8 +++--- .../Service/DeliveryCacheStorageService.cs | 8 +++--- src/LibHac/Fs/Common/FileStorage.cs | 4 +-- src/LibHac/Fs/Fsa/UserFileSystem.cs | 2 +- .../Fs/Impl/StorageServiceObjectAdapter.cs | 8 +++--- src/LibHac/Fs/Shim/BaseFileSystem.cs | 2 +- .../Fs/Shim/FileSystemProxyServiceObject.cs | 4 +-- .../Fs/Shim/FileSystemServiceObjectAdapter.cs | 12 ++++---- src/LibHac/Fs/Shim/SaveDataManagement.cs | 4 +-- src/LibHac/Fs/Shim/SaveDataTransferAdapter.cs | 20 ++++++------- .../Fs/Shim/SaveDataTransferVersion2.cs | 4 +-- src/LibHac/Fs/Shim/SdCard.cs | 6 ++-- src/LibHac/FsSrv/BaseFileSystemService.cs | 3 +- src/LibHac/FsSrv/FileSystemProxyImpl.cs | 4 +-- .../FsSrv/FileSystemServerInitializer.cs | 12 ++++---- .../FsCreator/EmulatedBisFileSystemCreator.cs | 4 +-- .../EmulatedBisFileSystemCreatorConfig.cs | 4 +-- .../EmulatedSdCardFileSystemCreator.cs | 8 +++--- .../FsSrv/FsCreator/FatFileSystemCreator.cs | 4 +-- .../FsCreator/GameCardFileSystemCreator.cs | 4 +-- .../FsSrv/FsCreator/IFatFileSystemCreator.cs | 4 +-- .../FsCreator/ISaveDataFileSystemCreator.cs | 2 +- .../FsCreator/SaveDataFileSystemCreator.cs | 6 ++-- .../Impl/AsynchronousAccessFileSystem.cs | 4 +-- src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs | 12 ++++---- .../Impl/DeviceEventSimulationStorage.cs | 4 +-- .../FsSrv/Impl/FileSystemInterfaceAdapter.cs | 28 +++++++++---------- .../Impl/FileSystemProxyServiceObject.cs | 2 +- src/LibHac/FsSrv/Impl/MultiCommitManager.cs | 10 +++---- src/LibHac/FsSrv/Impl/OpenCountFileSystem.cs | 28 +++++++++---------- .../Impl/SaveDataFileSystemCacheManager.cs | 4 +-- .../Impl/SaveDataFileSystemCacheRegister.cs | 4 +-- .../FsSrv/Impl/StorageInterfaceAdapter.cs | 4 +-- src/LibHac/FsSrv/Impl/Utility.cs | 10 +++---- src/LibHac/FsSrv/SaveDataFileSystemService.cs | 8 +++--- .../FsSrv/SaveDataFileSystemServiceImpl.cs | 2 +- src/LibHac/FsSrv/SaveDataInfoFilter.cs | 4 +-- src/LibHac/FsSrv/SaveDataSharedFileStorage.cs | 8 +++--- src/LibHac/FsSrv/Sf/IFileSystem.cs | 2 +- .../FsSrv/Sf/IFileSystemProxyForLoader.cs | 2 +- src/LibHac/FsSrv/Sf/IMultiCommitManager.cs | 2 +- src/LibHac/FsSrv/SpeedEmulationStorage.cs | 4 +-- src/LibHac/FsSystem/AesXtsStorage.cs | 4 +-- .../FsSystem/AlignmentMatchableFileSystem.cs | 2 +- .../FsSystem/AlignmentMatchingStorage.cs | 4 +-- src/LibHac/FsSystem/ForwardingFileSystem.cs | 4 +-- .../FsSystem/IResultConvertFileSystem.cs | 4 +-- src/LibHac/FsSystem/IUniqueLock.cs | 4 +-- .../MemoryResourceBufferHoldStorage.cs | 4 +-- src/LibHac/FsSystem/NcaFileSystemDriver.cs | 4 +-- .../FsSystem/ReadOnlyBlockCacheStorage.cs | 4 +-- .../SaveDataResultConvertFileSystem.cs | 4 +-- .../FsSystem/StorageLayoutTypeSetter.cs | 8 +++--- src/LibHac/FsSystem/Utility.cs | 4 +-- src/LibHac/GcSrv/GameCardStorage.cs | 8 +++--- src/LibHac/GcSrv/GameCardStorageDevice.cs | 16 +++++------ src/LibHac/Lr/AddOnContentLocationResolver.cs | 4 +-- src/LibHac/Lr/LocationResolver.cs | 4 +-- src/LibHac/Lr/RegisteredLocationResolver.cs | 4 +-- src/LibHac/SdmmcSrv/MmcDeviceOperator.cs | 4 +-- .../SdmmcSrv/MmcPartitionStorageDevice.cs | 24 ++++++++-------- src/LibHac/SdmmcSrv/SdCardDeviceOperator.cs | 4 +-- src/LibHac/SdmmcSrv/SdCardStorageDevice.cs | 8 +++--- src/LibHac/Sm/IServiceObject.cs | 2 +- src/LibHac/Sm/ServiceManagerClient.cs | 4 +-- .../Tools/FsSystem/Save/SaveDataFileSystem.cs | 4 +-- 66 files changed, 206 insertions(+), 209 deletions(-) diff --git a/src/LibHac/Bcat/Impl/Ipc/BcatServiceObject.cs b/src/LibHac/Bcat/Impl/Ipc/BcatServiceObject.cs index 5780fdc9..016f5527 100644 --- a/src/LibHac/Bcat/Impl/Ipc/BcatServiceObject.cs +++ b/src/LibHac/Bcat/Impl/Ipc/BcatServiceObject.cs @@ -8,9 +8,9 @@ internal class BcatServiceObject : IServiceObject { private SharedRef _serviceCreator; - public BcatServiceObject(ref SharedRef serviceCreator) + public BcatServiceObject(ref readonly SharedRef serviceCreator) { - _serviceCreator = SharedRef.CreateMove(ref serviceCreator); + _serviceCreator = SharedRef.CreateCopy(in serviceCreator); } public void Dispose() @@ -18,9 +18,9 @@ internal class BcatServiceObject : IServiceObject _serviceCreator.Destroy(); } - public Result GetServiceObject(ref SharedRef serviceObject) + public Result GetServiceObject(ref SharedRef outServiceObject) { - serviceObject.SetByCopy(in _serviceCreator); + outServiceObject.SetByCopy(in _serviceCreator); return Result.Success; } } \ No newline at end of file diff --git a/src/LibHac/Bcat/Impl/Service/DeliveryCacheStorageService.cs b/src/LibHac/Bcat/Impl/Service/DeliveryCacheStorageService.cs index 29679812..54f1faf1 100644 --- a/src/LibHac/Bcat/Impl/Service/DeliveryCacheStorageService.cs +++ b/src/LibHac/Bcat/Impl/Service/DeliveryCacheStorageService.cs @@ -25,28 +25,28 @@ internal class DeliveryCacheStorageService : IDeliveryCacheStorageService Access = accessControl; } - public Result CreateFileService(ref SharedRef service) + public Result CreateFileService(ref SharedRef outService) { lock (Locker) { if (FileServiceOpenCount >= MaxOpenCount) return ResultBcat.ServiceOpenLimitReached.Log(); - service.Reset(new DeliveryCacheFileService(Server, this, ApplicationId, Access)); + outService.Reset(new DeliveryCacheFileService(Server, this, ApplicationId, Access)); FileServiceOpenCount++; return Result.Success; } } - public Result CreateDirectoryService(ref SharedRef service) + public Result CreateDirectoryService(ref SharedRef outService) { lock (Locker) { if (DirectoryServiceOpenCount >= MaxOpenCount) return ResultBcat.ServiceOpenLimitReached.Log(); - service.Reset(new DeliveryCacheDirectoryService(Server, this, ApplicationId, Access)); + outService.Reset(new DeliveryCacheDirectoryService(Server, this, ApplicationId, Access)); DirectoryServiceOpenCount++; return Result.Success; diff --git a/src/LibHac/Fs/Common/FileStorage.cs b/src/LibHac/Fs/Common/FileStorage.cs index c2397679..6de88392 100644 --- a/src/LibHac/Fs/Common/FileStorage.cs +++ b/src/LibHac/Fs/Common/FileStorage.cs @@ -31,10 +31,10 @@ public class FileStorage : IStorage _fileSize = InvalidSize; } - public FileStorage(ref SharedRef baseFile) + public FileStorage(ref readonly SharedRef baseFile) { _baseFile = baseFile.Get; - _baseFileShared = SharedRef.CreateMove(ref baseFile); + _baseFileShared = SharedRef.CreateCopy(in baseFile); _fileSize = InvalidSize; } diff --git a/src/LibHac/Fs/Fsa/UserFileSystem.cs b/src/LibHac/Fs/Fsa/UserFileSystem.cs index 14f9e97b..14097827 100644 --- a/src/LibHac/Fs/Fsa/UserFileSystem.cs +++ b/src/LibHac/Fs/Fsa/UserFileSystem.cs @@ -661,7 +661,7 @@ public static class UserFileSystem if (!fileSystem.HasValue) return ResultFs.UnsupportedCommitTarget.Log(); - res = commitManager.Get.Add(ref fileSystem.Ref); + res = commitManager.Get.Add(fileSystem.Ref); if (res.IsFailure()) return res.Miss(); } diff --git a/src/LibHac/Fs/Impl/StorageServiceObjectAdapter.cs b/src/LibHac/Fs/Impl/StorageServiceObjectAdapter.cs index d2a7bd29..a3a9a111 100644 --- a/src/LibHac/Fs/Impl/StorageServiceObjectAdapter.cs +++ b/src/LibHac/Fs/Impl/StorageServiceObjectAdapter.cs @@ -16,14 +16,14 @@ internal class StorageServiceObjectAdapter : IStorage { private SharedRef _baseStorage; - public StorageServiceObjectAdapter(ref SharedRef baseStorage) + public StorageServiceObjectAdapter(ref readonly SharedRef baseStorage) { - _baseStorage = SharedRef.CreateMove(ref baseStorage); + _baseStorage = SharedRef.CreateCopy(in baseStorage); } - public StorageServiceObjectAdapter(ref SharedRef baseStorage) + public StorageServiceObjectAdapter(ref readonly SharedRef baseStorage) { - _baseStorage = SharedRef.CreateMove(ref baseStorage); + _baseStorage = SharedRef.CreateCopy(in baseStorage); } public override void Dispose() diff --git a/src/LibHac/Fs/Shim/BaseFileSystem.cs b/src/LibHac/Fs/Shim/BaseFileSystem.cs index 5e725d1d..9366cc62 100644 --- a/src/LibHac/Fs/Shim/BaseFileSystem.cs +++ b/src/LibHac/Fs/Shim/BaseFileSystem.cs @@ -28,7 +28,7 @@ public static class BaseFileSystem ref SharedRef fileSystem) { using var fileSystemAdapter = - new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref)); + new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); Result res = fs.Register(mountName, ref fileSystemAdapter.Ref); if (res.IsFailure()) return res.Miss(); diff --git a/src/LibHac/Fs/Shim/FileSystemProxyServiceObject.cs b/src/LibHac/Fs/Shim/FileSystemProxyServiceObject.cs index 01ded94d..09e36059 100644 --- a/src/LibHac/Fs/Shim/FileSystemProxyServiceObject.cs +++ b/src/LibHac/Fs/Shim/FileSystemProxyServiceObject.cs @@ -140,8 +140,8 @@ public static class FileSystemProxyServiceObject /// The to use. /// The service object this will use. public static void InitializeDfcFileSystemProxyServiceObject(this FileSystemClientImpl fs, - ref SharedRef serviceObject) + ref readonly SharedRef serviceObject) { - fs.Globals.FileSystemProxyServiceObject.DfcFileSystemProxyServiceObject.SetByMove(ref serviceObject); + fs.Globals.FileSystemProxyServiceObject.DfcFileSystemProxyServiceObject.SetByCopy(in serviceObject); } } \ No newline at end of file diff --git a/src/LibHac/Fs/Shim/FileSystemServiceObjectAdapter.cs b/src/LibHac/Fs/Shim/FileSystemServiceObjectAdapter.cs index 4e890930..e40d32a9 100644 --- a/src/LibHac/Fs/Shim/FileSystemServiceObjectAdapter.cs +++ b/src/LibHac/Fs/Shim/FileSystemServiceObjectAdapter.cs @@ -25,9 +25,9 @@ internal class FileServiceObjectAdapter : IFile { private SharedRef _baseFile; - public FileServiceObjectAdapter(ref SharedRef baseFile) + public FileServiceObjectAdapter(ref readonly SharedRef baseFile) { - _baseFile = SharedRef.CreateMove(ref baseFile); + _baseFile = SharedRef.CreateCopy(in baseFile); } public override void Dispose() @@ -91,9 +91,9 @@ internal class DirectoryServiceObjectAdapter : IDirectory { private SharedRef _baseDirectory; - public DirectoryServiceObjectAdapter(ref SharedRef baseDirectory) + public DirectoryServiceObjectAdapter(ref readonly SharedRef baseDirectory) { - _baseDirectory = SharedRef.CreateMove(ref baseDirectory); + _baseDirectory = SharedRef.CreateCopy(in baseDirectory); } public override void Dispose() @@ -136,9 +136,9 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget return Result.Success; } - public FileSystemServiceObjectAdapter(ref SharedRef baseFileSystem) + public FileSystemServiceObjectAdapter(ref readonly SharedRef baseFileSystem) { - _baseFs = SharedRef.CreateMove(ref baseFileSystem); + _baseFs = SharedRef.CreateCopy(in baseFileSystem); } public override void Dispose() diff --git a/src/LibHac/Fs/Shim/SaveDataManagement.cs b/src/LibHac/Fs/Shim/SaveDataManagement.cs index 439ab99c..a043f16d 100644 --- a/src/LibHac/Fs/Shim/SaveDataManagement.cs +++ b/src/LibHac/Fs/Shim/SaveDataManagement.cs @@ -26,9 +26,9 @@ namespace LibHac.Fs private readonly FileSystemClient _fsClient; private SharedRef _reader; - internal SaveDataIterator(FileSystemClient fsClient, ref SharedRef reader) + internal SaveDataIterator(FileSystemClient fsClient, ref readonly SharedRef reader) { - _reader = SharedRef.CreateMove(ref reader); + _reader = SharedRef.CreateCopy(in reader); _fsClient = fsClient; } diff --git a/src/LibHac/Fs/Shim/SaveDataTransferAdapter.cs b/src/LibHac/Fs/Shim/SaveDataTransferAdapter.cs index 65a55b8f..972958cc 100644 --- a/src/LibHac/Fs/Shim/SaveDataTransferAdapter.cs +++ b/src/LibHac/Fs/Shim/SaveDataTransferAdapter.cs @@ -20,9 +20,9 @@ public class SaveDataChunkIterator : ISaveDataChunkIterator // LibHac addition private FileSystemClient _fsClient; - public SaveDataChunkIterator(FileSystemClient fs, ref SharedRef baseInterface) + public SaveDataChunkIterator(FileSystemClient fs, ref readonly SharedRef baseInterface) { - _baseInterface = SharedRef.CreateMove(ref baseInterface); + _baseInterface = SharedRef.CreateCopy(in baseInterface); _fsClient = fs; } @@ -69,9 +69,9 @@ public class SaveDataChunkExporter : ISaveDataChunkExporter // LibHac addition private FileSystemClient _fsClient; - public SaveDataChunkExporter(FileSystemClient fs, ref SharedRef baseInterface) + public SaveDataChunkExporter(FileSystemClient fs, ref readonly SharedRef baseInterface) { - _baseInterface = SharedRef.CreateMove(ref baseInterface); + _baseInterface = SharedRef.CreateCopy(in baseInterface); _fsClient = fs; } @@ -116,9 +116,9 @@ public class SaveDataChunkImporter : ISaveDataChunkImporter // LibHac addition private FileSystemClient _fsClient; - public SaveDataChunkImporter(FileSystemClient fs, ref SharedRef baseInterface) + public SaveDataChunkImporter(FileSystemClient fs, ref readonly SharedRef baseInterface) { - _baseInterface = SharedRef.CreateMove(ref baseInterface); + _baseInterface = SharedRef.CreateCopy(in baseInterface); _fsClient = fs; } @@ -150,9 +150,9 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter private FileSystemClient _fsClient; public SaveDataExporterVersion2(FileSystemClient fs, - ref SharedRef baseInterface) + ref readonly SharedRef baseInterface) { - _baseInterface = SharedRef.CreateMove(ref baseInterface); + _baseInterface = SharedRef.CreateCopy(in baseInterface); _fsClient = fs; } @@ -329,9 +329,9 @@ public class SaveDataImporterVersion2 : ISaveDataDivisionImporter private FileSystemClient _fsClient; public SaveDataImporterVersion2(FileSystemClient fs, - ref SharedRef baseInterface) + ref readonly SharedRef baseInterface) { - _baseInterface = SharedRef.CreateMove(ref baseInterface); + _baseInterface = SharedRef.CreateCopy(in baseInterface); _fsClient = fs; } diff --git a/src/LibHac/Fs/Shim/SaveDataTransferVersion2.cs b/src/LibHac/Fs/Shim/SaveDataTransferVersion2.cs index b0584834..72900803 100644 --- a/src/LibHac/Fs/Shim/SaveDataTransferVersion2.cs +++ b/src/LibHac/Fs/Shim/SaveDataTransferVersion2.cs @@ -266,9 +266,9 @@ namespace LibHac.Fs { private SharedRef _prohibiter; - public SaveDataTransferProhibiterForCloudBackUp(ref SharedRef prohibiter) + public SaveDataTransferProhibiterForCloudBackUp(ref readonly SharedRef prohibiter) { - _prohibiter = SharedRef.CreateMove(ref prohibiter); + _prohibiter = SharedRef.CreateCopy(in prohibiter); } public void Dispose() diff --git a/src/LibHac/Fs/Shim/SdCard.cs b/src/LibHac/Fs/Shim/SdCard.cs index 9d4e6312..03f780c4 100644 --- a/src/LibHac/Fs/Shim/SdCard.cs +++ b/src/LibHac/Fs/Shim/SdCard.cs @@ -54,10 +54,10 @@ public static class SdCard } private static Result RegisterFileSystem(FileSystemClient fs, U8Span mountName, - ref SharedRef fileSystem) + ref readonly SharedRef fileSystem) { using var fileSystemAdapter = - new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem)); + new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInSdCardA.Log(); @@ -214,7 +214,7 @@ public static class SdCard return isInserted; - static Result CheckIfInserted(FileSystemClient fs, ref SharedRef deviceOperator, + static Result CheckIfInserted(FileSystemClient fs, ref readonly SharedRef deviceOperator, out bool isInserted) { UnsafeHelpers.SkipParamInit(out isInserted); diff --git a/src/LibHac/FsSrv/BaseFileSystemService.cs b/src/LibHac/FsSrv/BaseFileSystemService.cs index 7116fa00..b4923254 100644 --- a/src/LibHac/FsSrv/BaseFileSystemService.cs +++ b/src/LibHac/FsSrv/BaseFileSystemService.cs @@ -262,8 +262,7 @@ public readonly struct BaseFileSystemService return Result.Success; } - public Result OpenImageDirectoryFileSystem(ref SharedRef outFileSystem, - ImageDirectoryId directoryId) + public Result OpenImageDirectoryFileSystem(ref SharedRef outFileSystem, ImageDirectoryId directoryId) { // Caller must have the MountImageAndVideoStorage permission Result res = GetProgramInfo(out ProgramInfo programInfo); diff --git a/src/LibHac/FsSrv/FileSystemProxyImpl.cs b/src/LibHac/FsSrv/FileSystemProxyImpl.cs index 6738035d..62297d41 100644 --- a/src/LibHac/FsSrv/FileSystemProxyImpl.cs +++ b/src/LibHac/FsSrv/FileSystemProxyImpl.cs @@ -180,13 +180,13 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader return ncaFsService.OpenFileSystemWithPatch(ref outFileSystem, programId, fsType).Ret(); } - public Result OpenCodeFileSystem(ref SharedRef fileSystem, OutBuffer outVerificationData, + public Result OpenCodeFileSystem(ref SharedRef outFileSystem, OutBuffer outVerificationData, ref readonly FspPath path, ContentAttributes attributes, ProgramId programId) { Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); if (res.IsFailure()) return res.Miss(); - return ncaFsService.OpenCodeFileSystem(ref fileSystem, outVerificationData, in path, attributes, programId).Ret(); + return ncaFsService.OpenCodeFileSystem(ref outFileSystem, outVerificationData, in path, attributes, programId).Ret(); } public Result SetCurrentProcess(ulong processId) diff --git a/src/LibHac/FsSrv/FileSystemServerInitializer.cs b/src/LibHac/FsSrv/FileSystemServerInitializer.cs index 4834828f..6a3a3436 100644 --- a/src/LibHac/FsSrv/FileSystemServerInitializer.cs +++ b/src/LibHac/FsSrv/FileSystemServerInitializer.cs @@ -210,10 +210,10 @@ public static class FileSystemServerInitializer _server = server; } - public Result GetServiceObject(ref SharedRef serviceObject) + public Result GetServiceObject(ref SharedRef outServiceObject) { using SharedRef derivedObject = _server.Impl.GetFileSystemProxyServiceObject(); - serviceObject.SetByMove(ref derivedObject.Ref); + outServiceObject.SetByMove(ref derivedObject.Ref); return Result.Success; } @@ -229,10 +229,10 @@ public static class FileSystemServerInitializer _server = server; } - public Result GetServiceObject(ref SharedRef serviceObject) + public Result GetServiceObject(ref SharedRef outServiceObject) { using SharedRef derivedObject = _server.Impl.GetFileSystemProxyForLoaderServiceObject(); - serviceObject.SetByMove(ref derivedObject.Ref); + outServiceObject.SetByMove(ref derivedObject.Ref); return Result.Success; } @@ -248,10 +248,10 @@ public static class FileSystemServerInitializer _server = server; } - public Result GetServiceObject(ref SharedRef serviceObject) + public Result GetServiceObject(ref SharedRef outServiceObject) { using SharedRef derivedObject = _server.Impl.GetProgramRegistryServiceObject(); - serviceObject.SetByMove(ref derivedObject.Ref); + outServiceObject.SetByMove(ref derivedObject.Ref); return Result.Success; } diff --git a/src/LibHac/FsSrv/FsCreator/EmulatedBisFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/EmulatedBisFileSystemCreator.cs index dc825810..371e9084 100644 --- a/src/LibHac/FsSrv/FsCreator/EmulatedBisFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/EmulatedBisFileSystemCreator.cs @@ -39,10 +39,10 @@ public class EmulatedBisFileSystemCreator : IBuiltInStorageFileSystemCreator /// Each partition will be located at their default paths in this IFileSystem. /// /// The to use as the root file system. - public EmulatedBisFileSystemCreator(ref SharedRef rootFileSystem) + public EmulatedBisFileSystemCreator(ref readonly SharedRef rootFileSystem) { Config = new EmulatedBisFileSystemCreatorConfig(); - Config.SetRootFileSystem(ref rootFileSystem).ThrowIfFailure(); + Config.SetRootFileSystem(in rootFileSystem).ThrowIfFailure(); } /// diff --git a/src/LibHac/FsSrv/FsCreator/EmulatedBisFileSystemCreatorConfig.cs b/src/LibHac/FsSrv/FsCreator/EmulatedBisFileSystemCreatorConfig.cs index 319108ec..3a77da36 100644 --- a/src/LibHac/FsSrv/FsCreator/EmulatedBisFileSystemCreatorConfig.cs +++ b/src/LibHac/FsSrv/FsCreator/EmulatedBisFileSystemCreatorConfig.cs @@ -18,12 +18,12 @@ public class EmulatedBisFileSystemCreatorConfig private SharedRef[] PartitionFileSystems { get; } = new SharedRef[ValidPartitionCount]; private string[] PartitionPaths { get; } = new string[ValidPartitionCount]; - public Result SetRootFileSystem(ref SharedRef fileSystem) + public Result SetRootFileSystem(ref readonly SharedRef fileSystem) { if (!fileSystem.HasValue) return ResultFs.NullptrArgument.Log(); if (_rootFileSystem.HasValue) return ResultFs.PreconditionViolation.Log(); - _rootFileSystem.SetByMove(ref fileSystem); + _rootFileSystem.SetByCopy(in fileSystem); return Result.Success; } diff --git a/src/LibHac/FsSrv/FsCreator/EmulatedSdCardFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/EmulatedSdCardFileSystemCreator.cs index 84aeb46c..4c144474 100644 --- a/src/LibHac/FsSrv/FsCreator/EmulatedSdCardFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/EmulatedSdCardFileSystemCreator.cs @@ -17,16 +17,16 @@ public class EmulatedSdCardFileSystemCreator : ISdCardProxyFileSystemCreator, ID private SharedRef _sdCardFileSystem; private string _path; - public EmulatedSdCardFileSystemCreator(SdmmcApi sdmmc, ref SharedRef rootFileSystem) + public EmulatedSdCardFileSystemCreator(SdmmcApi sdmmc, ref readonly SharedRef rootFileSystem) { _sdmmc = sdmmc; - _rootFileSystem = SharedRef.CreateMove(ref rootFileSystem); + _rootFileSystem = SharedRef.CreateCopy(in rootFileSystem); } - public EmulatedSdCardFileSystemCreator(SdmmcApi sdmmc, ref SharedRef rootFileSystem, string path) + public EmulatedSdCardFileSystemCreator(SdmmcApi sdmmc, ref readonly SharedRef rootFileSystem, string path) { _sdmmc = sdmmc; - _rootFileSystem = SharedRef.CreateMove(ref rootFileSystem); + _rootFileSystem = SharedRef.CreateCopy(in rootFileSystem); _path = path; } diff --git a/src/LibHac/FsSrv/FsCreator/FatFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/FatFileSystemCreator.cs index e4ea1d5e..ed9756a9 100644 --- a/src/LibHac/FsSrv/FsCreator/FatFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/FatFileSystemCreator.cs @@ -31,13 +31,13 @@ public class FatFileSystemCreator : IFatFileSystemCreator // Missing: Call nn::fat::SetMemoryResource } - public Result Create(ref SharedRef outFileSystem, ref SharedRef baseStorage, + public Result Create(ref SharedRef outFileSystem, ref readonly SharedRef baseStorage, FatAttribute attribute, int driveId, Result invalidFatFormatResult, Result usableSpaceNotEnoughResult) { throw new NotImplementedException(); } - public Result Format(ref SharedRef partitionStorage, FatAttribute attribute, FatFormatParam formatParam, + public Result Format(ref readonly SharedRef partitionStorage, FatAttribute attribute, FatFormatParam formatParam, int driveId, Result invalidFatFormatResult, Result usableSpaceNotEnoughResult) { throw new NotImplementedException(); diff --git a/src/LibHac/FsSrv/FsCreator/GameCardFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/GameCardFileSystemCreator.cs index fe67525a..9c65bd98 100644 --- a/src/LibHac/FsSrv/FsCreator/GameCardFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/GameCardFileSystemCreator.cs @@ -38,12 +38,12 @@ public class GameCardRootPartition : IDisposable // LibHac addition so we can access fssrv::storage functions private readonly FileSystemServer _fsServer; - public GameCardRootPartition(GameCardHandle handle, ref SharedRef rootStorage, + public GameCardRootPartition(GameCardHandle handle, ref readonly SharedRef rootStorage, IGameCardStorageCreator storageCreator, ref UniqueRef partitionFsMeta, FileSystemServer fsServer) { _partitionFsMeta = new UniqueRef(ref partitionFsMeta); - _alignedRootStorage = SharedRef.CreateMove(ref rootStorage); + _alignedRootStorage = SharedRef.CreateCopy(in rootStorage); _gcHandle = handle; _gameCardStorageCreator = storageCreator; _logoPartitionStorage = new SharedRef(); diff --git a/src/LibHac/FsSrv/FsCreator/IFatFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/IFatFileSystemCreator.cs index 16f9f335..f54faf5a 100644 --- a/src/LibHac/FsSrv/FsCreator/IFatFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/IFatFileSystemCreator.cs @@ -7,9 +7,9 @@ namespace LibHac.FsSrv.FsCreator; public interface IFatFileSystemCreator { - Result Create(ref SharedRef outFileSystem, ref SharedRef baseStorage, + Result Create(ref SharedRef outFileSystem, ref readonly SharedRef baseStorage, FatAttribute attribute, int driveId, Result invalidFatFormatResult, Result usableSpaceNotEnoughResult); - Result Format(ref SharedRef partitionStorage, FatAttribute attribute, FatFormatParam formatParam, + Result Format(ref readonly SharedRef partitionStorage, FatAttribute attribute, FatFormatParam formatParam, int driveId, Result invalidFatFormatResult, Result usableSpaceNotEnoughResult); } \ No newline at end of file diff --git a/src/LibHac/FsSrv/FsCreator/ISaveDataFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/ISaveDataFileSystemCreator.cs index 7ab3bcb6..77b15f5e 100644 --- a/src/LibHac/FsSrv/FsCreator/ISaveDataFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/ISaveDataFileSystemCreator.cs @@ -12,7 +12,7 @@ public interface ISaveDataFileSystemCreator : IDisposable { Result CreateRaw(ref SharedRef outFile, ref readonly SharedRef fileSystem, ulong saveDataId, OpenMode openMode); - Result Create(ref SharedRef outFileSystem, ref SharedRef baseFileSystem, + Result Create(ref SharedRef outFileSystem, ref readonly SharedRef baseFileSystem, SaveDataSpaceId spaceId, ulong saveDataId, bool allowDirectorySaveData, bool isDeviceUniqueMac, bool isJournalingSupported, bool isMultiCommitSupported, bool openReadOnly, bool openShared, ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible); diff --git a/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs index 3b129880..edafae9c 100644 --- a/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs @@ -313,7 +313,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator return Result.Success; } - public Result Create(ref SharedRef outFileSystem, ref SharedRef baseFileSystem, + public Result Create(ref SharedRef outFileSystem, ref readonly SharedRef baseFileSystem, SaveDataSpaceId spaceId, ulong saveDataId, bool allowDirectorySaveData, bool isDeviceUniqueMac, bool isJournalingSupported, bool isMultiCommitSupported, bool openReadOnly, bool openShared, ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible) @@ -345,7 +345,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator } // Get a file system over the save directory - using var baseFs = new UniqueRef(new SubdirectoryFileSystem(ref baseFileSystem)); + using var baseFs = new UniqueRef(new SubdirectoryFileSystem(in baseFileSystem)); if (!baseFs.HasValue) return ResultFs.AllocationMemoryFailedInSaveDataFileSystemCreatorA.Log(); @@ -374,7 +374,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator Optional openType = openShared ? new Optional(OpenType.Normal) : new Optional(); - res = _fsServer.OpenSaveDataStorage(ref fileStorage.Ref, ref baseFileSystem, spaceId, saveDataId, + res = _fsServer.OpenSaveDataStorage(ref fileStorage.Ref, in baseFileSystem, spaceId, saveDataId, OpenMode.ReadWrite, openType); if (res.IsFailure()) return res.Miss(); diff --git a/src/LibHac/FsSrv/Impl/AsynchronousAccessFileSystem.cs b/src/LibHac/FsSrv/Impl/AsynchronousAccessFileSystem.cs index e9ed2397..e12761d8 100644 --- a/src/LibHac/FsSrv/Impl/AsynchronousAccessFileSystem.cs +++ b/src/LibHac/FsSrv/Impl/AsynchronousAccessFileSystem.cs @@ -7,8 +7,8 @@ namespace LibHac.FsSrv.Impl; public class AsynchronousAccessFileSystem : ForwardingFileSystem { - public AsynchronousAccessFileSystem(ref SharedRef baseFileSystem) : base( - ref baseFileSystem) + public AsynchronousAccessFileSystem(ref readonly SharedRef baseFileSystem) : base( + in baseFileSystem) { } // ReSharper disable once RedundantOverriddenMember diff --git a/src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs b/src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs index cb6435b0..fbd86788 100644 --- a/src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs +++ b/src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs @@ -10,17 +10,17 @@ public class DeepRetryFileSystem : ForwardingFileSystem private WeakRef _selfReference; private SharedRef _accessFailureManager; - protected DeepRetryFileSystem(ref SharedRef baseFileSystem, - ref SharedRef accessFailureManager) : base(ref baseFileSystem) + protected DeepRetryFileSystem(ref readonly SharedRef baseFileSystem, + ref readonly SharedRef accessFailureManager) : base(in baseFileSystem) { - _accessFailureManager = SharedRef.CreateMove(ref accessFailureManager); + _accessFailureManager = SharedRef.CreateCopy(in accessFailureManager); } - public static SharedRef CreateShared(ref SharedRef baseFileSystem, - ref SharedRef accessFailureManager) + public static SharedRef CreateShared(ref readonly SharedRef baseFileSystem, + ref readonly SharedRef accessFailureManager) { using var retryFileSystem = new SharedRef( - new DeepRetryFileSystem(ref baseFileSystem, ref accessFailureManager)); + new DeepRetryFileSystem(in baseFileSystem, in accessFailureManager)); retryFileSystem.Get._selfReference.Set(in retryFileSystem.Ref); diff --git a/src/LibHac/FsSrv/Impl/DeviceEventSimulationStorage.cs b/src/LibHac/FsSrv/Impl/DeviceEventSimulationStorage.cs index 22d66e97..8965a153 100644 --- a/src/LibHac/FsSrv/Impl/DeviceEventSimulationStorage.cs +++ b/src/LibHac/FsSrv/Impl/DeviceEventSimulationStorage.cs @@ -14,9 +14,9 @@ internal class DeviceEventSimulationStorage : IStorage private SharedRef _baseStorage; private IDeviceEventSimulator _deviceEventSimulator; - public DeviceEventSimulationStorage(ref SharedRef baseStorage, IDeviceEventSimulator deviceEventSimulator) + public DeviceEventSimulationStorage(ref readonly SharedRef baseStorage, IDeviceEventSimulator deviceEventSimulator) { - _baseStorage = SharedRef.CreateMove(ref baseStorage); + _baseStorage = SharedRef.CreateCopy(in baseStorage); _deviceEventSimulator = deviceEventSimulator; } diff --git a/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs b/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs index c0ddfbf4..de0ada66 100644 --- a/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs +++ b/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs @@ -27,9 +27,9 @@ public class FileInterfaceAdapter : IFileSf private bool _allowAllOperations; public FileInterfaceAdapter(ref UniqueRef baseFile, - ref SharedRef parentFileSystem, bool allowAllOperations) + ref readonly SharedRef parentFileSystem, bool allowAllOperations) { - _parentFs = SharedRef.CreateMove(ref parentFileSystem); + _parentFs = SharedRef.CreateCopy(in parentFileSystem); _baseFile = new UniqueRef(ref baseFile); _allowAllOperations = allowAllOperations; } @@ -187,9 +187,9 @@ public class DirectoryInterfaceAdapter : IDirectorySf private UniqueRef _baseDirectory; public DirectoryInterfaceAdapter(ref UniqueRef baseDirectory, - ref SharedRef parentFileSystem) + ref readonly SharedRef parentFileSystem) { - _parentFs = SharedRef.CreateMove(ref parentFileSystem); + _parentFs = SharedRef.CreateCopy(in parentFileSystem); _baseDirectory = new UniqueRef(ref baseDirectory); } @@ -251,24 +251,24 @@ public class FileSystemInterfaceAdapter : IFileSystemSf // creating files and directories. We don't have an ISharedObject, so a self-reference is used instead. private WeakRef _selfReference; - private FileSystemInterfaceAdapter(ref SharedRef fileSystem, + private FileSystemInterfaceAdapter(ref readonly SharedRef fileSystem, bool allowAllOperations) { - _baseFileSystem = SharedRef.CreateMove(ref fileSystem); + _baseFileSystem = SharedRef.CreateCopy(in fileSystem); _allowAllOperations = allowAllOperations; } - private FileSystemInterfaceAdapter(ref SharedRef fileSystem, PathFlags flags, + private FileSystemInterfaceAdapter(ref readonly SharedRef fileSystem, PathFlags flags, bool allowAllOperations) { - _baseFileSystem = SharedRef.CreateMove(ref fileSystem); + _baseFileSystem = SharedRef.CreateCopy(in fileSystem); _pathFlags = flags; _allowAllOperations = allowAllOperations; } - public static SharedRef CreateShared(ref SharedRef baseFileSystem, bool allowAllOperations) + public static SharedRef CreateShared(ref readonly SharedRef baseFileSystem, bool allowAllOperations) { - var adapter = new FileSystemInterfaceAdapter(ref baseFileSystem, allowAllOperations); + var adapter = new FileSystemInterfaceAdapter(in baseFileSystem, allowAllOperations); using var sharedAdapter = new SharedRef(adapter); adapter._selfReference.Set(in sharedAdapter); @@ -277,9 +277,9 @@ public class FileSystemInterfaceAdapter : IFileSystemSf } public static SharedRef CreateShared( - ref SharedRef baseFileSystem, PathFlags flags, bool allowAllOperations) + ref readonly SharedRef baseFileSystem, PathFlags flags, bool allowAllOperations) { - var adapter = new FileSystemInterfaceAdapter(ref baseFileSystem, flags, allowAllOperations); + var adapter = new FileSystemInterfaceAdapter(in baseFileSystem, flags, allowAllOperations); using var sharedAdapter = new SharedRef(adapter); adapter._selfReference.Set(in sharedAdapter); @@ -605,9 +605,9 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return Result.Success; } - public Result GetImpl(ref SharedRef fileSystem) + public Result GetImpl(ref SharedRef outFileSystem) { - fileSystem.SetByCopy(in _baseFileSystem); + outFileSystem.SetByCopy(in _baseFileSystem); return Result.Success; } } \ No newline at end of file diff --git a/src/LibHac/FsSrv/Impl/FileSystemProxyServiceObject.cs b/src/LibHac/FsSrv/Impl/FileSystemProxyServiceObject.cs index dd050fda..ea641220 100644 --- a/src/LibHac/FsSrv/Impl/FileSystemProxyServiceObject.cs +++ b/src/LibHac/FsSrv/Impl/FileSystemProxyServiceObject.cs @@ -47,7 +47,7 @@ public static class FileSystemProxyServiceObject return ResultFs.PortAcceptableCountLimited.Log(); } - public Result OpenCodeFileSystem(ref SharedRef fileSystem, OutBuffer outVerificationData, + public Result OpenCodeFileSystem(ref SharedRef outFileSystem, OutBuffer outVerificationData, ref readonly FspPath path, ContentAttributes attributes, ProgramId programId) { return ResultFs.PortAcceptableCountLimited.Log(); diff --git a/src/LibHac/FsSrv/Impl/MultiCommitManager.cs b/src/LibHac/FsSrv/Impl/MultiCommitManager.cs index 2837c93f..c43a1b78 100644 --- a/src/LibHac/FsSrv/Impl/MultiCommitManager.cs +++ b/src/LibHac/FsSrv/Impl/MultiCommitManager.cs @@ -66,20 +66,20 @@ internal class MultiCommitManager : IMultiCommitManager private readonly FileSystemServer _fsServer; private ref MultiCommitManagerGlobals Globals => ref _fsServer.Globals.MultiCommitManager; - public MultiCommitManager(FileSystemServer fsServer, ref SharedRef multiCommitInterface) + public MultiCommitManager(FileSystemServer fsServer, ref readonly SharedRef multiCommitInterface) { _fsServer = fsServer; - _multiCommitInterface = SharedRef.CreateMove(ref multiCommitInterface); + _multiCommitInterface = SharedRef.CreateCopy(in multiCommitInterface); _fileSystems = new SharedRef[MaxFileSystemCount]; _fileSystemCount = 0; _counter = 0; } public static SharedRef CreateShared(FileSystemServer fsServer, - ref SharedRef multiCommitInterface) + ref readonly SharedRef multiCommitInterface) { - return new SharedRef(new MultiCommitManager(fsServer, ref multiCommitInterface)); + return new SharedRef(new MultiCommitManager(fsServer, in multiCommitInterface)); } public void Dispose() @@ -121,7 +121,7 @@ internal class MultiCommitManager : IMultiCommitManager /// : The maximum number of file systems have been added. /// file systems may be added to a single multi-commit.
/// : The provided file system has already been added. - public Result Add(ref SharedRef fileSystem) + public Result Add(ref readonly SharedRef fileSystem) { if (_fileSystemCount >= MaxFileSystemCount) return ResultFs.MultiCommitFileSystemLimit.Log(); diff --git a/src/LibHac/FsSrv/Impl/OpenCountFileSystem.cs b/src/LibHac/FsSrv/Impl/OpenCountFileSystem.cs index 435f38c1..80bcbafb 100644 --- a/src/LibHac/FsSrv/Impl/OpenCountFileSystem.cs +++ b/src/LibHac/FsSrv/Impl/OpenCountFileSystem.cs @@ -10,37 +10,35 @@ internal class OpenCountFileSystem : ForwardingFileSystem private SharedRef _entryCountSemaphore; private UniqueRef _mountCountSemaphore; - public OpenCountFileSystem(ref SharedRef baseFileSystem, - ref SharedRef entryCountSemaphore) : base(ref baseFileSystem) + public OpenCountFileSystem(ref readonly SharedRef baseFileSystem, + ref readonly SharedRef entryCountSemaphore) : base(in baseFileSystem) { - _entryCountSemaphore = SharedRef.CreateMove(ref entryCountSemaphore); + _entryCountSemaphore = SharedRef.CreateCopy(in entryCountSemaphore); } - public OpenCountFileSystem(ref SharedRef baseFileSystem, - ref SharedRef entryCountSemaphore, - ref UniqueRef mountCountSemaphore) : base(ref baseFileSystem) + public OpenCountFileSystem(ref readonly SharedRef baseFileSystem, + ref readonly SharedRef entryCountSemaphore, + ref UniqueRef mountCountSemaphore) : base(in baseFileSystem) { - _entryCountSemaphore = SharedRef.CreateMove(ref entryCountSemaphore); + _entryCountSemaphore = SharedRef.CreateCopy(in entryCountSemaphore); _mountCountSemaphore = new UniqueRef(ref mountCountSemaphore); } public static SharedRef CreateShared( - ref SharedRef baseFileSystem, - ref SharedRef entryCountSemaphore, + ref readonly SharedRef baseFileSystem, + ref readonly SharedRef entryCountSemaphore, ref UniqueRef mountCountSemaphore) { - var filesystem = - new OpenCountFileSystem(ref baseFileSystem, ref entryCountSemaphore, ref mountCountSemaphore); + var filesystem = new OpenCountFileSystem(in baseFileSystem, in entryCountSemaphore, ref mountCountSemaphore); return new SharedRef(filesystem); } public static SharedRef CreateShared( - ref SharedRef baseFileSystem, - ref SharedRef entryCountSemaphore) + ref readonly SharedRef baseFileSystem, + ref readonly SharedRef entryCountSemaphore) { - var filesystem = - new OpenCountFileSystem(ref baseFileSystem, ref entryCountSemaphore); + var filesystem = new OpenCountFileSystem(in baseFileSystem, in entryCountSemaphore); return new SharedRef(filesystem); } diff --git a/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheManager.cs b/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheManager.cs index 7e15c7df..a6e75ba1 100644 --- a/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheManager.cs +++ b/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheManager.cs @@ -36,9 +36,9 @@ public class SaveDataFileSystemCacheManager : IDisposable return SharedRef.CreateMove(ref _fileSystem); } - public void Register(ref SharedRef fileSystem, SaveDataSpaceId spaceId, ulong saveDataId) + public void Register(ref readonly SharedRef fileSystem, SaveDataSpaceId spaceId, ulong saveDataId) { - _fileSystem.SetByMove(ref fileSystem); + _fileSystem.SetByCopy(in fileSystem); _spaceId = spaceId; _saveDataId = saveDataId; } diff --git a/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheRegister.cs b/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheRegister.cs index 4f9d6122..0ff99f96 100644 --- a/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheRegister.cs +++ b/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheRegister.cs @@ -17,10 +17,10 @@ public class SaveDataFileSystemCacheRegister : IFileSystem private SaveDataSpaceId _spaceId; private ulong _saveDataId; - public SaveDataFileSystemCacheRegister(ref SharedRef baseFileSystem, + public SaveDataFileSystemCacheRegister(ref readonly SharedRef baseFileSystem, SaveDataFileSystemCacheManager cacheManager, SaveDataSpaceId spaceId, ulong saveDataId) { - _baseFileSystem = SharedRef.CreateMove(ref baseFileSystem); + _baseFileSystem = SharedRef.CreateCopy(in baseFileSystem); _cacheManager = cacheManager; _spaceId = spaceId; _saveDataId = saveDataId; diff --git a/src/LibHac/FsSrv/Impl/StorageInterfaceAdapter.cs b/src/LibHac/FsSrv/Impl/StorageInterfaceAdapter.cs index 67a415b1..be9f4c19 100644 --- a/src/LibHac/FsSrv/Impl/StorageInterfaceAdapter.cs +++ b/src/LibHac/FsSrv/Impl/StorageInterfaceAdapter.cs @@ -16,9 +16,9 @@ public class StorageInterfaceAdapter : IStorageSf { private SharedRef _baseStorage; - public StorageInterfaceAdapter(ref SharedRef baseStorage) + public StorageInterfaceAdapter(ref readonly SharedRef baseStorage) { - _baseStorage = SharedRef.CreateMove(ref baseStorage); + _baseStorage = SharedRef.CreateCopy(in baseStorage); } public void Dispose() diff --git a/src/LibHac/FsSrv/Impl/Utility.cs b/src/LibHac/FsSrv/Impl/Utility.cs index 7700a5d4..67cf444a 100644 --- a/src/LibHac/FsSrv/Impl/Utility.cs +++ b/src/LibHac/FsSrv/Impl/Utility.cs @@ -16,11 +16,11 @@ internal static class Utility } public static Result CreateSubDirectoryFileSystem(ref SharedRef outSubDirFileSystem, - ref SharedRef baseFileSystem, ref readonly Path rootPath) + ref readonly SharedRef baseFileSystem, ref readonly Path rootPath) { if (rootPath.IsEmpty()) { - outSubDirFileSystem.SetByMove(ref baseFileSystem); + outSubDirFileSystem.SetByCopy(in baseFileSystem); return Result.Success; } @@ -31,7 +31,7 @@ internal static class Utility dir.Reset(); - using var fs = new SharedRef(new SubdirectoryFileSystem(ref baseFileSystem)); + using var fs = new SharedRef(new SubdirectoryFileSystem(in baseFileSystem)); if (!fs.HasValue) return ResultFs.AllocationMemoryFailedInSubDirectoryFileSystemCreatorA.Log(); @@ -44,7 +44,7 @@ internal static class Utility } public static Result WrapSubDirectory(ref SharedRef outFileSystem, - ref SharedRef baseFileSystem, ref readonly Path rootPath, bool createIfMissing) + ref readonly 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, in rootPath); + return CreateSubDirectoryFileSystem(ref outFileSystem, in baseFileSystem, in rootPath); } public static long ConvertZeroCommitId(in SaveDataExtraData extraData) diff --git a/src/LibHac/FsSrv/SaveDataFileSystemService.cs b/src/LibHac/FsSrv/SaveDataFileSystemService.cs index 50f9695b..51787fe9 100644 --- a/src/LibHac/FsSrv/SaveDataFileSystemService.cs +++ b/src/LibHac/FsSrv/SaveDataFileSystemService.cs @@ -1825,16 +1825,16 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave openReadOnly).Ret(); } - public Result OpenSaveDataFileSystem(ref SharedRef fileSystem, SaveDataSpaceId spaceId, + public Result OpenSaveDataFileSystem(ref SharedRef outFileSystem, SaveDataSpaceId spaceId, in SaveDataAttribute attribute) { - return OpenUserSaveDataFileSystem(ref fileSystem, spaceId, in attribute, openReadOnly: false).Ret(); + return OpenUserSaveDataFileSystem(ref outFileSystem, spaceId, in attribute, openReadOnly: false).Ret(); } - public Result OpenReadOnlySaveDataFileSystem(ref SharedRef fileSystem, SaveDataSpaceId spaceId, + public Result OpenReadOnlySaveDataFileSystem(ref SharedRef outGileSystem, SaveDataSpaceId spaceId, in SaveDataAttribute attribute) { - return OpenUserSaveDataFileSystem(ref fileSystem, spaceId, in attribute, openReadOnly: true).Ret(); + return OpenUserSaveDataFileSystem(ref outGileSystem, spaceId, in attribute, openReadOnly: true).Ret(); } public Result OpenSaveDataFileSystemBySystemSaveDataId(ref SharedRef outFileSystem, diff --git a/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs b/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs index 4c3a716e..199004e8 100644 --- a/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs +++ b/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs @@ -299,7 +299,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable bool openShared = SaveDataProperties.IsSharedOpenNeeded(type); bool isReconstructible = SaveDataProperties.IsReconstructible(type, spaceId); - res = _config.SaveFsCreator.Create(ref saveDataFs.Ref, ref fileSystem.Ref, spaceId, saveDataId, + res = _config.SaveFsCreator.Create(ref saveDataFs.Ref, fileSystem.Ref, spaceId, saveDataId, isEmulatedOnHost, isDeviceUniqueMac, isJournalingSupported, isMultiCommitSupported, openReadOnly, openShared, _timeStampGetter, isReconstructible); if (res.IsFailure()) return res.Miss(); diff --git a/src/LibHac/FsSrv/SaveDataInfoFilter.cs b/src/LibHac/FsSrv/SaveDataInfoFilter.cs index 1e6f2c8e..c8778870 100644 --- a/src/LibHac/FsSrv/SaveDataInfoFilter.cs +++ b/src/LibHac/FsSrv/SaveDataInfoFilter.cs @@ -116,9 +116,9 @@ internal class SaveDataInfoFilterReader : SaveDataInfoReaderImpl private SharedRef _reader; private SaveDataInfoFilter _infoFilter; - public SaveDataInfoFilterReader(ref SharedRef reader, in SaveDataInfoFilter infoFilter) + public SaveDataInfoFilterReader(ref readonly SharedRef reader, in SaveDataInfoFilter infoFilter) { - _reader = SharedRef.CreateMove(ref reader); + _reader = SharedRef.CreateCopy(in reader); _infoFilter = infoFilter; } diff --git a/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs b/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs index c486a2f2..66ed46bd 100644 --- a/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs +++ b/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs @@ -168,10 +168,10 @@ public class SaveDataSharedFileStorage : IStorage private SharedRef _baseStorage; private SaveDataOpenTypeSetFileStorage.OpenType _type; - public SaveDataSharedFileStorage(ref SharedRef baseStorage, + public SaveDataSharedFileStorage(ref readonly SharedRef baseStorage, SaveDataOpenTypeSetFileStorage.OpenType type) { - _baseStorage = SharedRef.CreateMove(ref baseStorage); + _baseStorage = SharedRef.CreateCopy(in baseStorage); _type = type; } @@ -278,10 +278,10 @@ public class SaveDataFileStorageHolder private SaveDataSpaceId _spaceId; private ulong _saveDataId; - public Entry(ref SharedRef storage, SaveDataSpaceId spaceId, + public Entry(ref readonly SharedRef storage, SaveDataSpaceId spaceId, ulong saveDataId) { - _storage = SharedRef.CreateMove(ref storage); + _storage = SharedRef.CreateCopy(in storage); _spaceId = spaceId; _saveDataId = saveDataId; } diff --git a/src/LibHac/FsSrv/Sf/IFileSystem.cs b/src/LibHac/FsSrv/Sf/IFileSystem.cs index 78b39575..74b76def 100644 --- a/src/LibHac/FsSrv/Sf/IFileSystem.cs +++ b/src/LibHac/FsSrv/Sf/IFileSystem.cs @@ -10,7 +10,7 @@ namespace LibHac.FsSrv.Sf; public interface IFileSystem : IDisposable { - Result GetImpl(ref SharedRef fileSystem); + Result GetImpl(ref SharedRef outFileSystem); Result CreateFile(ref readonly Path path, long size, int option); Result DeleteFile(ref readonly Path path); Result CreateDirectory(ref readonly Path path); diff --git a/src/LibHac/FsSrv/Sf/IFileSystemProxyForLoader.cs b/src/LibHac/FsSrv/Sf/IFileSystemProxyForLoader.cs index 3027dccd..9130d7cd 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, OutBuffer outVerificationData, + Result OpenCodeFileSystem(ref SharedRef outFileSystem, OutBuffer outVerificationData, ref readonly FspPath path, ContentAttributes attributes, ProgramId programId); Result IsArchivedProgram(out bool isArchived, ulong processId); diff --git a/src/LibHac/FsSrv/Sf/IMultiCommitManager.cs b/src/LibHac/FsSrv/Sf/IMultiCommitManager.cs index aebbb0ca..09bc6d0d 100644 --- a/src/LibHac/FsSrv/Sf/IMultiCommitManager.cs +++ b/src/LibHac/FsSrv/Sf/IMultiCommitManager.cs @@ -6,6 +6,6 @@ namespace LibHac.FsSrv.Sf; public interface IMultiCommitManager : IDisposable { - Result Add(ref SharedRef fileSystem); + Result Add(ref readonly SharedRef fileSystem); Result Commit(); } \ No newline at end of file diff --git a/src/LibHac/FsSrv/SpeedEmulationStorage.cs b/src/LibHac/FsSrv/SpeedEmulationStorage.cs index 0013eee5..3f89ccbc 100644 --- a/src/LibHac/FsSrv/SpeedEmulationStorage.cs +++ b/src/LibHac/FsSrv/SpeedEmulationStorage.cs @@ -9,9 +9,9 @@ public class SpeedEmulationStorage : IStorage { private SharedRef _baseStorage; - public SpeedEmulationStorage(ref SharedRef baseStorage, FileSystemServer fsServer) + public SpeedEmulationStorage(ref readonly SharedRef baseStorage, FileSystemServer fsServer) { - _baseStorage = SharedRef.CreateMove(ref baseStorage); + _baseStorage = SharedRef.CreateCopy(in baseStorage); } public override void Dispose() diff --git a/src/LibHac/FsSystem/AesXtsStorage.cs b/src/LibHac/FsSystem/AesXtsStorage.cs index 29eec445..e7aca0f7 100644 --- a/src/LibHac/FsSystem/AesXtsStorage.cs +++ b/src/LibHac/FsSystem/AesXtsStorage.cs @@ -57,10 +57,10 @@ public class AesXtsStorage : IStorage iv.CopyTo(_iv); } - public AesXtsStorage(ref SharedRef baseStorage, ReadOnlySpan key1, ReadOnlySpan key2, + public AesXtsStorage(ref readonly SharedRef baseStorage, ReadOnlySpan key1, ReadOnlySpan key2, ReadOnlySpan iv, int blockSize) { - _baseStorageShared = SharedRef.CreateMove(ref baseStorage); + _baseStorageShared = SharedRef.CreateCopy(in baseStorage); _baseStorage = _baseStorageShared.Get; _blockSize = blockSize; _mutex = new SdkMutexType(); diff --git a/src/LibHac/FsSystem/AlignmentMatchableFileSystem.cs b/src/LibHac/FsSystem/AlignmentMatchableFileSystem.cs index 68399b58..422c9fd8 100644 --- a/src/LibHac/FsSystem/AlignmentMatchableFileSystem.cs +++ b/src/LibHac/FsSystem/AlignmentMatchableFileSystem.cs @@ -105,7 +105,7 @@ public class AlignmentMatchingFile : ForwardingFile public class AlignmentMatchableFileSystem : ForwardingFileSystem { - public AlignmentMatchableFileSystem(ref SharedRef baseFileSystem) : base(ref baseFileSystem) { } + public AlignmentMatchableFileSystem(ref readonly SharedRef baseFileSystem) : base(in baseFileSystem) { } protected override Result DoOpenFile(ref UniqueRef outFile, ref readonly Path path, OpenMode mode) { diff --git a/src/LibHac/FsSystem/AlignmentMatchingStorage.cs b/src/LibHac/FsSystem/AlignmentMatchingStorage.cs index 68b0f909..94494801 100644 --- a/src/LibHac/FsSystem/AlignmentMatchingStorage.cs +++ b/src/LibHac/FsSystem/AlignmentMatchingStorage.cs @@ -59,13 +59,13 @@ public class AlignmentMatchingStorage : IStora private bool _isBaseStorageSizeDirty; private SharedRef _sharedBaseStorage; - public AlignmentMatchingStorage(ref SharedRef baseStorage) + public AlignmentMatchingStorage(ref readonly SharedRef baseStorage) { VerifyTypeParameters(); _baseStorage = baseStorage.Get; _isBaseStorageSizeDirty = true; - _sharedBaseStorage = SharedRef.CreateMove(ref baseStorage); + _sharedBaseStorage = SharedRef.CreateCopy(in baseStorage); } public AlignmentMatchingStorage(IStorage baseStorage) diff --git a/src/LibHac/FsSystem/ForwardingFileSystem.cs b/src/LibHac/FsSystem/ForwardingFileSystem.cs index d7111c2e..7c9f7a8c 100644 --- a/src/LibHac/FsSystem/ForwardingFileSystem.cs +++ b/src/LibHac/FsSystem/ForwardingFileSystem.cs @@ -78,9 +78,9 @@ public class ForwardingFileSystem : IFileSystem { protected SharedRef BaseFileSystem; - protected ForwardingFileSystem(ref SharedRef baseFileSystem) + protected ForwardingFileSystem(ref readonly SharedRef baseFileSystem) { - BaseFileSystem = SharedRef.CreateMove(ref baseFileSystem); + BaseFileSystem = SharedRef.CreateCopy(in baseFileSystem); } public override void Dispose() diff --git a/src/LibHac/FsSystem/IResultConvertFileSystem.cs b/src/LibHac/FsSystem/IResultConvertFileSystem.cs index 69c4b3d3..47d5995a 100644 --- a/src/LibHac/FsSystem/IResultConvertFileSystem.cs +++ b/src/LibHac/FsSystem/IResultConvertFileSystem.cs @@ -106,9 +106,9 @@ public abstract class IResultConvertFileSystem : ISaveDataFileSystem where T { private SharedRef _baseFileSystem; - protected IResultConvertFileSystem(ref SharedRef baseFileSystem) + protected IResultConvertFileSystem(ref readonly SharedRef baseFileSystem) { - _baseFileSystem = SharedRef.CreateMove(ref baseFileSystem); + _baseFileSystem = SharedRef.CreateCopy(in baseFileSystem); } public override void Dispose() diff --git a/src/LibHac/FsSystem/IUniqueLock.cs b/src/LibHac/FsSystem/IUniqueLock.cs index c4669ac5..7cab9f44 100644 --- a/src/LibHac/FsSystem/IUniqueLock.cs +++ b/src/LibHac/FsSystem/IUniqueLock.cs @@ -11,10 +11,10 @@ public class UniqueLockWithPin : IUniqueLock where T : class, IDisposable private UniqueLock _semaphore; private SharedRef _pinnedObject; - public UniqueLockWithPin(ref UniqueLock semaphore, ref SharedRef pinnedObject) + public UniqueLockWithPin(ref UniqueLock semaphore, ref readonly SharedRef pinnedObject) { _semaphore = new UniqueLock(ref semaphore); - _pinnedObject = SharedRef.CreateMove(ref pinnedObject); + _pinnedObject = SharedRef.CreateCopy(in pinnedObject); } public void Dispose() diff --git a/src/LibHac/FsSystem/MemoryResourceBufferHoldStorage.cs b/src/LibHac/FsSystem/MemoryResourceBufferHoldStorage.cs index df15b205..a3f8421c 100644 --- a/src/LibHac/FsSystem/MemoryResourceBufferHoldStorage.cs +++ b/src/LibHac/FsSystem/MemoryResourceBufferHoldStorage.cs @@ -16,10 +16,10 @@ public class MemoryResourceBufferHoldStorage : IStorage private MemoryResource _memoryResource; private Mem.Buffer _buffer; - public MemoryResourceBufferHoldStorage(ref SharedRef baseStorage, MemoryResource memoryResource, + public MemoryResourceBufferHoldStorage(ref readonly SharedRef baseStorage, MemoryResource memoryResource, int bufferSize) { - _storage = SharedRef.CreateMove(ref baseStorage); + _storage = SharedRef.CreateCopy(in baseStorage); _memoryResource = memoryResource; _buffer = memoryResource.Allocate(bufferSize); } diff --git a/src/LibHac/FsSystem/NcaFileSystemDriver.cs b/src/LibHac/FsSystem/NcaFileSystemDriver.cs index b0c66abb..c6389d20 100644 --- a/src/LibHac/FsSystem/NcaFileSystemDriver.cs +++ b/src/LibHac/FsSystem/NcaFileSystemDriver.cs @@ -233,7 +233,7 @@ public class NcaFileSystemDriver : IDisposable throw new NotImplementedException(); } - private Result CreateAesXtsStorage(ref SharedRef outStorage, ref SharedRef baseStorage, + private Result CreateAesXtsStorage(ref SharedRef outStorage, ref readonly SharedRef baseStorage, long offset) { throw new NotImplementedException(); @@ -269,7 +269,7 @@ public class NcaFileSystemDriver : IDisposable } private Result CreateSparseStorageWithVerification(ref SharedRef outStorage, out long outFsDataOffset, - out SharedRef outSparseStorage, ref SharedRef outSparseStorageMetaStorage, + ref SharedRef outSparseStorage, ref SharedRef outSparseStorageMetaStorage, ref SharedRef outLayerInfoStorage, int index, NcaFsHeader.EncryptionType encryptionType, in NcaAesCtrUpperIv upperIv, in NcaSparseInfo sparseInfo, in NcaMetaDataHashDataInfo metaDataHashDataInfo, NcaFsHeader.MetaDataHashType metaDataHashType) diff --git a/src/LibHac/FsSystem/ReadOnlyBlockCacheStorage.cs b/src/LibHac/FsSystem/ReadOnlyBlockCacheStorage.cs index 1142b335..e1c854bb 100644 --- a/src/LibHac/FsSystem/ReadOnlyBlockCacheStorage.cs +++ b/src/LibHac/FsSystem/ReadOnlyBlockCacheStorage.cs @@ -23,10 +23,10 @@ public class ReadOnlyBlockCacheStorage : IStorage private SharedRef _baseStorage; private int _blockSize; - public ReadOnlyBlockCacheStorage(ref SharedRef baseStorage, int blockSize, Memory buffer, + public ReadOnlyBlockCacheStorage(ref readonly SharedRef baseStorage, int blockSize, Memory buffer, int cacheBlockCount) { - _baseStorage = SharedRef.CreateMove(ref baseStorage); + _baseStorage = SharedRef.CreateCopy(in baseStorage); _blockSize = blockSize; _blockCache = new BlockCache(); _mutex = new SdkMutexType(); diff --git a/src/LibHac/FsSystem/SaveDataResultConvertFileSystem.cs b/src/LibHac/FsSystem/SaveDataResultConvertFileSystem.cs index 7d4c97d1..9c08ce11 100644 --- a/src/LibHac/FsSystem/SaveDataResultConvertFileSystem.cs +++ b/src/LibHac/FsSystem/SaveDataResultConvertFileSystem.cs @@ -55,8 +55,8 @@ public class SaveDataResultConvertFileSystem : IResultConvertFileSystem baseFileSystem, bool isReconstructible) : - base(ref baseFileSystem) + public SaveDataResultConvertFileSystem(ref readonly SharedRef baseFileSystem, bool isReconstructible) : + base(in baseFileSystem) { _isReconstructible = isReconstructible; } diff --git a/src/LibHac/FsSystem/StorageLayoutTypeSetter.cs b/src/LibHac/FsSystem/StorageLayoutTypeSetter.cs index d8362368..8f74725d 100644 --- a/src/LibHac/FsSystem/StorageLayoutTypeSetter.cs +++ b/src/LibHac/FsSystem/StorageLayoutTypeSetter.cs @@ -128,10 +128,10 @@ internal class StorageLayoutTypeSetFile : IFile Assert.SdkAssert(StorageLayoutTypeFunctions.IsStorageFlagValid(storageFlag)); } - public StorageLayoutTypeSetFile(ref SharedRef baseFile, StorageLayoutType storageFlag) + public StorageLayoutTypeSetFile(ref readonly SharedRef baseFile, StorageLayoutType storageFlag) { _baseFile = baseFile.Get; - _baseFileShared = SharedRef.CreateMove(ref baseFile); + _baseFileShared = SharedRef.CreateCopy(in baseFile); _storageFlag = storageFlag; Assert.SdkAssert(StorageLayoutTypeFunctions.IsStorageFlagValid(storageFlag)); @@ -235,9 +235,9 @@ internal class StorageLayoutTypeSetFileSystem : IFileSystem private SharedRef _baseFileSystem; private StorageLayoutType _storageFlag; - public StorageLayoutTypeSetFileSystem(ref SharedRef baseFileSystem, StorageLayoutType storageFlag) + public StorageLayoutTypeSetFileSystem(ref readonly SharedRef baseFileSystem, StorageLayoutType storageFlag) { - _baseFileSystem = SharedRef.CreateMove(ref baseFileSystem); + _baseFileSystem = SharedRef.CreateCopy(in baseFileSystem); _storageFlag = storageFlag; Assert.SdkAssert(StorageLayoutTypeFunctions.IsStorageFlagValid(storageFlag)); diff --git a/src/LibHac/FsSystem/Utility.cs b/src/LibHac/FsSystem/Utility.cs index 9dbccf5a..85ba34e1 100644 --- a/src/LibHac/FsSystem/Utility.cs +++ b/src/LibHac/FsSystem/Utility.cs @@ -488,13 +488,13 @@ internal static class Utility } public static Result MakeUniqueLockWithPin(ref UniqueRef outUniqueLock, - SemaphoreAdapter semaphore, ref SharedRef objectToPin) where T : class, IDisposable + SemaphoreAdapter semaphore, ref readonly SharedRef objectToPin) where T : class, IDisposable { using var semaphoreAdapter = new UniqueLock(); Result res = TryAcquireCountSemaphore(ref semaphoreAdapter.Ref(), semaphore); if (res.IsFailure()) return res.Miss(); - var lockWithPin = new UniqueLockWithPin(ref semaphoreAdapter.Ref(), ref objectToPin); + var lockWithPin = new UniqueLockWithPin(ref semaphoreAdapter.Ref(), in objectToPin); using var uniqueLock = new UniqueRef(lockWithPin); outUniqueLock.Set(ref uniqueLock.Ref); diff --git a/src/LibHac/GcSrv/GameCardStorage.cs b/src/LibHac/GcSrv/GameCardStorage.cs index 0ac0ffb2..c773fa5b 100644 --- a/src/LibHac/GcSrv/GameCardStorage.cs +++ b/src/LibHac/GcSrv/GameCardStorage.cs @@ -22,9 +22,9 @@ internal class ReadOnlyGameCardStorage : IStorage // LibHac additions private readonly IGcApi _gc; - public ReadOnlyGameCardStorage(ref SharedRef deviceManger, IGcApi gc) + public ReadOnlyGameCardStorage(ref readonly SharedRef deviceManger, IGcApi gc) { - _deviceManager = SharedRef.CreateMove(ref deviceManger); + _deviceManager = SharedRef.CreateCopy(in deviceManger); _gc = gc; } @@ -105,9 +105,9 @@ internal class WriteOnlyGameCardStorage : IStorage // LibHac additions private readonly IGcApi _gc; - public WriteOnlyGameCardStorage(ref SharedRef deviceManger, IGcApi gc) + public WriteOnlyGameCardStorage(ref readonly SharedRef deviceManger, IGcApi gc) { - _deviceManager = SharedRef.CreateMove(ref deviceManger); + _deviceManager = SharedRef.CreateCopy(in deviceManger); _gc = gc; } diff --git a/src/LibHac/GcSrv/GameCardStorageDevice.cs b/src/LibHac/GcSrv/GameCardStorageDevice.cs index 6dcd064a..d15ac7a1 100644 --- a/src/LibHac/GcSrv/GameCardStorageDevice.cs +++ b/src/LibHac/GcSrv/GameCardStorageDevice.cs @@ -26,17 +26,17 @@ internal class GameCardStorageDevice : GameCardStorageInterfaceAdapter, IStorage private WeakRef _selfReference; private readonly IGcApi _gc; - private GameCardStorageDevice(IGcApi gc, ref SharedRef manager, + private GameCardStorageDevice(IGcApi gc, ref readonly SharedRef manager, ref readonly SharedRef baseStorage, GameCardHandle handle) : base(in baseStorage) { - _manager = SharedRef.CreateMove(ref manager); + _manager = SharedRef.CreateCopy(in manager); _handle = handle; _isSecure = false; _gc = gc; } - private GameCardStorageDevice(IGcApi gc, ref SharedRef manager, + private GameCardStorageDevice(IGcApi gc, ref readonly SharedRef manager, ref readonly SharedRef baseStorage, GameCardHandle handle, bool isSecure, ReadOnlySpan cardDeviceId, ReadOnlySpan cardImageHash) : base(in baseStorage) @@ -44,7 +44,7 @@ internal class GameCardStorageDevice : GameCardStorageInterfaceAdapter, IStorage Assert.SdkRequiresEqual(cardDeviceId.Length, Values.GcCardDeviceIdSize); Assert.SdkRequiresEqual(cardImageHash.Length, Values.GcCardImageHashSize); - _manager = SharedRef.CreateMove(ref manager); + _manager = SharedRef.CreateCopy(in manager); _handle = handle; _isSecure = isSecure; @@ -54,10 +54,10 @@ internal class GameCardStorageDevice : GameCardStorageInterfaceAdapter, IStorage _gc = gc; } - public static SharedRef CreateShared(IGcApi gc, ref SharedRef manager, + public static SharedRef CreateShared(IGcApi gc, ref readonly SharedRef manager, ref readonly SharedRef baseStorage, GameCardHandle handle) { - var storageDevice = new GameCardStorageDevice(gc, ref manager, in baseStorage, handle); + var storageDevice = new GameCardStorageDevice(gc, in manager, in baseStorage, handle); using var sharedStorageDevice = new SharedRef(storageDevice); storageDevice._selfReference.Set(in sharedStorageDevice); @@ -65,11 +65,11 @@ internal class GameCardStorageDevice : GameCardStorageInterfaceAdapter, IStorage return SharedRef.CreateMove(ref sharedStorageDevice.Ref); } - public static SharedRef CreateShared(IGcApi gc, ref SharedRef manager, + public static SharedRef CreateShared(IGcApi gc, ref readonly SharedRef manager, ref readonly SharedRef baseStorage, GameCardHandle handle, bool isSecure, ReadOnlySpan cardDeviceId, ReadOnlySpan cardImageHash) { - var storageDevice = new GameCardStorageDevice(gc, ref manager, in baseStorage, handle, isSecure, cardDeviceId, + var storageDevice = new GameCardStorageDevice(gc, in manager, in baseStorage, handle, isSecure, cardDeviceId, cardImageHash); using var sharedStorageDevice = new SharedRef(storageDevice); diff --git a/src/LibHac/Lr/AddOnContentLocationResolver.cs b/src/LibHac/Lr/AddOnContentLocationResolver.cs index 043cb75b..6858c2f3 100644 --- a/src/LibHac/Lr/AddOnContentLocationResolver.cs +++ b/src/LibHac/Lr/AddOnContentLocationResolver.cs @@ -9,9 +9,9 @@ public class AddOnContentLocationResolver : IDisposable { private SharedRef _interface; - public AddOnContentLocationResolver(ref SharedRef baseInterface) + public AddOnContentLocationResolver(ref readonly SharedRef baseInterface) { - _interface = SharedRef.CreateMove(ref baseInterface); + _interface = SharedRef.CreateCopy(in baseInterface); } public void Dispose() diff --git a/src/LibHac/Lr/LocationResolver.cs b/src/LibHac/Lr/LocationResolver.cs index 5e7c7f53..99924478 100644 --- a/src/LibHac/Lr/LocationResolver.cs +++ b/src/LibHac/Lr/LocationResolver.cs @@ -9,9 +9,9 @@ public class LocationResolver : IDisposable { private SharedRef _interface; - public LocationResolver(ref SharedRef baseInterface) + public LocationResolver(ref readonly SharedRef baseInterface) { - _interface = SharedRef.CreateMove(ref baseInterface); + _interface = SharedRef.CreateCopy(in baseInterface); } public void Dispose() diff --git a/src/LibHac/Lr/RegisteredLocationResolver.cs b/src/LibHac/Lr/RegisteredLocationResolver.cs index 0cd4dd4f..c86e45b7 100644 --- a/src/LibHac/Lr/RegisteredLocationResolver.cs +++ b/src/LibHac/Lr/RegisteredLocationResolver.cs @@ -8,9 +8,9 @@ public class RegisteredLocationResolver : IDisposable { private SharedRef _interface; - public RegisteredLocationResolver(ref SharedRef baseInterface) + public RegisteredLocationResolver(ref readonly SharedRef baseInterface) { - _interface = SharedRef.CreateMove(ref baseInterface); + _interface = SharedRef.CreateCopy(in baseInterface); } public void Dispose() diff --git a/src/LibHac/SdmmcSrv/MmcDeviceOperator.cs b/src/LibHac/SdmmcSrv/MmcDeviceOperator.cs index 03e48114..76d13227 100644 --- a/src/LibHac/SdmmcSrv/MmcDeviceOperator.cs +++ b/src/LibHac/SdmmcSrv/MmcDeviceOperator.cs @@ -24,9 +24,9 @@ internal class MmcDeviceOperator : IStorageDeviceOperator // LibHac additions private readonly SdmmcApi _sdmmc; - public MmcDeviceOperator(ref SharedRef storageDevice, SdmmcApi sdmmc) + public MmcDeviceOperator(ref readonly SharedRef storageDevice, SdmmcApi sdmmc) { - _storageDevice = SharedRef.CreateMove(ref storageDevice); + _storageDevice = SharedRef.CreateCopy(in storageDevice); _sdmmc = sdmmc; } diff --git a/src/LibHac/SdmmcSrv/MmcPartitionStorageDevice.cs b/src/LibHac/SdmmcSrv/MmcPartitionStorageDevice.cs index d46383d2..24ec93ab 100644 --- a/src/LibHac/SdmmcSrv/MmcPartitionStorageDevice.cs +++ b/src/LibHac/SdmmcSrv/MmcPartitionStorageDevice.cs @@ -26,11 +26,11 @@ internal abstract class MmcPartitionStorageDevice : IDisposable protected WeakRef SelfReference; protected readonly SdmmcApi Sdmmc; - protected MmcPartitionStorageDevice(MmcPartition partition, ref SharedRef manager, + protected MmcPartitionStorageDevice(MmcPartition partition, ref readonly SharedRef manager, SdmmcHandle handle, SdmmcApi sdmmc) { _partition = partition; - _manager = SharedRef.CreateMove(ref manager); + _manager = SharedRef.CreateCopy(in manager); _handle = handle; Sdmmc = sdmmc; } @@ -101,8 +101,8 @@ internal abstract class MmcPartitionStorageDeviceInterfaceAdapter : MmcPartition private readonly IStorage _baseStorage; protected MmcPartitionStorageDeviceInterfaceAdapter(IStorage baseStorage, MmcPartition partition, - ref SharedRef manager, SdmmcHandle handle, SdmmcApi sdmmc) - : base(partition, ref manager, handle, sdmmc) + ref readonly SharedRef manager, SdmmcHandle handle, SdmmcApi sdmmc) + : base(partition, in manager, handle, sdmmc) { _baseStorage = baseStorage; } @@ -148,14 +148,14 @@ internal abstract class MmcPartitionStorageDeviceInterfaceAdapter : MmcPartition /// Based on nnSdk 16.2.0 (FS 16.0.0) internal class MmcUserDataPartitionStorageDevice : MmcPartitionStorageDeviceInterfaceAdapter { - private MmcUserDataPartitionStorageDevice(ref SharedRef manager, SdmmcHandle handle, + private MmcUserDataPartitionStorageDevice(ref readonly SharedRef manager, SdmmcHandle handle, SdmmcApi sdmmc) - : base(manager.Get.GetStorage(), MmcPartition.UserData, ref manager, handle, sdmmc) { } + : base(manager.Get.GetStorage(), MmcPartition.UserData, in manager, handle, sdmmc) { } - public static SharedRef CreateShared(ref SharedRef manager, + public static SharedRef CreateShared(ref readonly SharedRef manager, SdmmcHandle handle, SdmmcApi sdmmc) { - var storageDevice = new MmcUserDataPartitionStorageDevice(ref manager, handle, sdmmc); + var storageDevice = new MmcUserDataPartitionStorageDevice(in manager, handle, sdmmc); using var sharedStorageDevice = new SharedRef(storageDevice); storageDevice.SelfReference.Set(in sharedStorageDevice); @@ -212,14 +212,14 @@ internal class MmcUserDataPartitionStorageDevice : MmcPartitionStorageDeviceInte /// Based on nnSdk 16.2.0 (FS 16.0.0) internal class MmcBootPartitionStorageDevice : MmcPartitionStorageDeviceInterfaceAdapter { - private MmcBootPartitionStorageDevice(Fs.MmcPartition partition, ref SharedRef manager, + private MmcBootPartitionStorageDevice(Fs.MmcPartition partition, ref readonly SharedRef manager, SdmmcHandle handle, SdmmcApi sdmmc) - : base(manager.Get.GetStorage(), GetPartition(partition), ref manager, handle, sdmmc) { } + : base(manager.Get.GetStorage(), GetPartition(partition), in manager, handle, sdmmc) { } public static SharedRef CreateShared(Fs.MmcPartition partition, - ref SharedRef manager, SdmmcHandle handle, SdmmcApi sdmmc) + ref readonly SharedRef manager, SdmmcHandle handle, SdmmcApi sdmmc) { - var storageDevice = new MmcBootPartitionStorageDevice(partition, ref manager, handle, sdmmc); + var storageDevice = new MmcBootPartitionStorageDevice(partition, in manager, handle, sdmmc); using var sharedStorageDevice = new SharedRef(storageDevice); storageDevice.SelfReference.Set(in sharedStorageDevice); diff --git a/src/LibHac/SdmmcSrv/SdCardDeviceOperator.cs b/src/LibHac/SdmmcSrv/SdCardDeviceOperator.cs index 0f140806..c8791ee7 100644 --- a/src/LibHac/SdmmcSrv/SdCardDeviceOperator.cs +++ b/src/LibHac/SdmmcSrv/SdCardDeviceOperator.cs @@ -21,9 +21,9 @@ internal class SdCardDeviceOperator : IStorageDeviceOperator // LibHac additions private readonly SdmmcApi _sdmmc; - public SdCardDeviceOperator(ref SharedRef storageDevice, SdmmcApi sdmmc) + public SdCardDeviceOperator(ref readonly SharedRef storageDevice, SdmmcApi sdmmc) { - _storageDevice = SharedRef.CreateMove(ref storageDevice); + _storageDevice = SharedRef.CreateCopy(in storageDevice); _sdmmc = sdmmc; } diff --git a/src/LibHac/SdmmcSrv/SdCardStorageDevice.cs b/src/LibHac/SdmmcSrv/SdCardStorageDevice.cs index e13a19e7..35a5d86b 100644 --- a/src/LibHac/SdmmcSrv/SdCardStorageDevice.cs +++ b/src/LibHac/SdmmcSrv/SdCardStorageDevice.cs @@ -20,18 +20,18 @@ internal class SdCardStorageDevice : SdmmcStorageInterfaceAdapter, IStorageDevic private WeakRef _selfReference; private readonly SdmmcApi _sdmmc; - private SdCardStorageDevice(ref SharedRef manager, SdmmcHandle handle, SdmmcApi sdmmc) + private SdCardStorageDevice(ref readonly SharedRef manager, SdmmcHandle handle, SdmmcApi sdmmc) : base(manager.Get.GetStorage()) { - _manager = SharedRef.CreateMove(ref manager); + _manager = SharedRef.CreateCopy(in manager); _handle = handle; _sdmmc = sdmmc; } - public static SharedRef CreateShared(ref SharedRef manager, + public static SharedRef CreateShared(ref readonly SharedRef manager, SdmmcHandle handle, SdmmcApi sdmmc) { - var device = new SdCardStorageDevice(ref manager, handle, sdmmc); + var device = new SdCardStorageDevice(in manager, handle, sdmmc); using var sharedDevice = new SharedRef(device); device._selfReference.Set(in sharedDevice); diff --git a/src/LibHac/Sm/IServiceObject.cs b/src/LibHac/Sm/IServiceObject.cs index eb92de4d..6d73f8b3 100644 --- a/src/LibHac/Sm/IServiceObject.cs +++ b/src/LibHac/Sm/IServiceObject.cs @@ -7,5 +7,5 @@ namespace LibHac.Sm; // have at least some sort of service system for now public interface IServiceObject : IDisposable { - Result GetServiceObject(ref SharedRef serviceObject); + Result GetServiceObject(ref SharedRef outServiceObject); } \ No newline at end of file diff --git a/src/LibHac/Sm/ServiceManagerClient.cs b/src/LibHac/Sm/ServiceManagerClient.cs index f9f13386..4a4718d0 100644 --- a/src/LibHac/Sm/ServiceManagerClient.cs +++ b/src/LibHac/Sm/ServiceManagerClient.cs @@ -12,14 +12,14 @@ public class ServiceManagerClient Server = server; } - public Result GetService(ref SharedRef serviceObject, ReadOnlySpan name) where T : class, IDisposable + public Result GetService(ref SharedRef outServiceObject, ReadOnlySpan name) where T : class, IDisposable { using var service = new SharedRef(); Result res = Server.GetService(ref service.Ref, ServiceName.Encode(name)); if (res.IsFailure()) return res.Miss(); - if (serviceObject.TryCastSet(ref service.Ref)) + if (outServiceObject.TryCastSet(ref service.Ref)) { return Result.Success; } diff --git a/src/LibHac/Tools/FsSystem/Save/SaveDataFileSystem.cs b/src/LibHac/Tools/FsSystem/Save/SaveDataFileSystem.cs index b35dfd72..6d75d0dc 100644 --- a/src/LibHac/Tools/FsSystem/Save/SaveDataFileSystem.cs +++ b/src/LibHac/Tools/FsSystem/Save/SaveDataFileSystem.cs @@ -33,11 +33,11 @@ public class SaveDataFileSystem : IFileSystem private KeySet KeySet { get; } - public SaveDataFileSystem(KeySet keySet, ref SharedRef storage, + public SaveDataFileSystem(KeySet keySet, ref readonly SharedRef storage, IntegrityCheckLevel integrityCheckLevel, bool leaveOpen) : this(keySet, storage.Get, integrityCheckLevel, true) { - _baseStorageShared = SharedRef.CreateMove(ref storage); + _baseStorageShared = SharedRef.CreateCopy(in storage); } public SaveDataFileSystem(KeySet keySet, IStorage storage, IntegrityCheckLevel integrityCheckLevel, bool leaveOpen)