diff --git a/build/RepackNuget.cs b/build/RepackNuget.cs index 46f4aa9a..6ad54c56 100644 --- a/build/RepackNuget.cs +++ b/build/RepackNuget.cs @@ -9,7 +9,6 @@ using System.Xml.Linq; using ICSharpCode.SharpZipLib.Zip; using Nuke.Common.IO; using Nuke.Common.Tools.NuGet; -using static Nuke.Common.IO.FileSystemTasks; namespace LibHacBuild; diff --git a/src/LibHac/Bcat/BcatServer.cs b/src/LibHac/Bcat/BcatServer.cs index 837611f4..c4352219 100644 --- a/src/LibHac/Bcat/BcatServer.cs +++ b/src/LibHac/Bcat/BcatServer.cs @@ -36,7 +36,7 @@ public class BcatServer using SharedRef service = GetServiceCreator(type); - Result res = Hos.Sm.RegisterService(new BcatServiceObject(ref service.Ref), name); + Result res = Hos.Sm.RegisterService(new BcatServiceObject(in service), name); if (res.IsFailure()) { throw new HorizonResultException(res, "Abort"); diff --git a/src/LibHac/Fs/Fsa/UserFileSystem.cs b/src/LibHac/Fs/Fsa/UserFileSystem.cs index 14097827..c17d2013 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(fileSystem.Ref); + res = commitManager.Get.Add(in fileSystem); if (res.IsFailure()) return res.Miss(); } diff --git a/src/LibHac/Fs/ResultHandlingUtility.cs b/src/LibHac/Fs/ResultHandlingUtility.cs index 3b593e58..5bb317b3 100644 --- a/src/LibHac/Fs/ResultHandlingUtility.cs +++ b/src/LibHac/Fs/ResultHandlingUtility.cs @@ -1,5 +1,4 @@ -using System; -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; using LibHac.Diag; using LibHac.Htc; using LibHac.HtcFs; diff --git a/src/LibHac/Fs/Shim/Application.cs b/src/LibHac/Fs/Shim/Application.cs index a6c469be..b9878d35 100644 --- a/src/LibHac/Fs/Shim/Application.cs +++ b/src/LibHac/Fs/Shim/Application.cs @@ -64,8 +64,7 @@ public static class Application Ncm.ProgramId.InvalidId.Value, FileSystemProxyType.Package); if (res.IsFailure()) return res.Miss(); - using var fileSystemAdapter = - new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref)); + using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInApplicationA.Log(); diff --git a/src/LibHac/Fs/Shim/BaseFileSystem.cs b/src/LibHac/Fs/Shim/BaseFileSystem.cs index 9366cc62..e05a59a1 100644 --- a/src/LibHac/Fs/Shim/BaseFileSystem.cs +++ b/src/LibHac/Fs/Shim/BaseFileSystem.cs @@ -25,7 +25,7 @@ public static class BaseFileSystem } private static Result RegisterFileSystem(FileSystemClient fs, U8Span mountName, - ref SharedRef fileSystem) + ref readonly SharedRef fileSystem) { using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); @@ -47,7 +47,7 @@ public static class BaseFileSystem fs.Impl.AbortIfNeeded(res); if (res.IsFailure()) return res.Miss(); - res = RegisterFileSystem(fs, mountName, ref fileSystem.Ref); + res = RegisterFileSystem(fs, mountName, in fileSystem); fs.Impl.AbortIfNeeded(res); if (res.IsFailure()) return res.Miss(); diff --git a/src/LibHac/Fs/Shim/BcatSaveData.cs b/src/LibHac/Fs/Shim/BcatSaveData.cs index 2fa8138e..0f1e1733 100644 --- a/src/LibHac/Fs/Shim/BcatSaveData.cs +++ b/src/LibHac/Fs/Shim/BcatSaveData.cs @@ -67,8 +67,7 @@ public static class BcatSaveData res = fileSystemProxy.Get.OpenSaveDataFileSystem(ref fileSystem.Ref, SaveDataSpaceId.User, in attribute); if (res.IsFailure()) return res.Miss(); - using var fileSystemAdapter = - new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref)); + using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInBcatSaveDataA.Log(); diff --git a/src/LibHac/Fs/Shim/Bis.cs b/src/LibHac/Fs/Shim/Bis.cs index 46951d2b..0d19f6f2 100644 --- a/src/LibHac/Fs/Shim/Bis.cs +++ b/src/LibHac/Fs/Shim/Bis.cs @@ -107,8 +107,7 @@ public static class Bis if (!mountNameGenerator.HasValue) return ResultFs.AllocationMemoryFailedInBisA.Log(); - using var fileSystemAdapter = - new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref)); + using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInBisB.Log(); @@ -174,7 +173,7 @@ public static class Bis fs.Impl.AbortIfNeeded(res); if (res.IsFailure()) return res.Miss(); - using var storageAdapter = new UniqueRef(new StorageServiceObjectAdapter(ref storage.Ref)); + using var storageAdapter = new UniqueRef(new StorageServiceObjectAdapter(in storage)); if (!storageAdapter.HasValue) { diff --git a/src/LibHac/Fs/Shim/Code.cs b/src/LibHac/Fs/Shim/Code.cs index da850ace..652b4913 100644 --- a/src/LibHac/Fs/Shim/Code.cs +++ b/src/LibHac/Fs/Shim/Code.cs @@ -76,8 +76,7 @@ public static class Code in sfPath, attributes, programId); if (res.IsFailure()) return res.Miss(); - using var fileSystemAdapter = - new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref)); + using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInCodeA.Log(); diff --git a/src/LibHac/Fs/Shim/Content.cs b/src/LibHac/Fs/Shim/Content.cs index afa3cee9..e235929c 100644 --- a/src/LibHac/Fs/Shim/Content.cs +++ b/src/LibHac/Fs/Shim/Content.cs @@ -51,8 +51,7 @@ public static class Content res = fileSystemProxy.Get.OpenFileSystemWithId(ref fileSystem.Ref, in sfPath, attributes, id, fsType); if (res.IsFailure()) return res.Miss(); - using var fileSystemAdapter = - new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref)); + using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInContentA.Log(); @@ -253,8 +252,7 @@ public static class Content res = fileSystemProxy.Get.OpenFileSystemWithPatch(ref fileSystem.Ref, programId, fsType); if (res.IsFailure()) return res.Miss(); - using var fileSystemAdapter = - new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref)); + using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInContentA.Log(); diff --git a/src/LibHac/Fs/Shim/ContentStorage.cs b/src/LibHac/Fs/Shim/ContentStorage.cs index 2f3c926c..cee2af5b 100644 --- a/src/LibHac/Fs/Shim/ContentStorage.cs +++ b/src/LibHac/Fs/Shim/ContentStorage.cs @@ -117,8 +117,7 @@ public static class ContentStorage fs.Hos.Os.SleepThread(TimeSpan.FromMilliSeconds(retryInterval)); } - using var fileSystemAdapter = - new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref)); + using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInContentStorageA.Log(); diff --git a/src/LibHac/Fs/Shim/CustomStorage.cs b/src/LibHac/Fs/Shim/CustomStorage.cs index 6404c257..4bacaa21 100644 --- a/src/LibHac/Fs/Shim/CustomStorage.cs +++ b/src/LibHac/Fs/Shim/CustomStorage.cs @@ -50,8 +50,7 @@ public static class CustomStorage res = fileSystemProxy.Get.OpenCustomStorageFileSystem(ref fileSystem.Ref, storageId); if (res.IsFailure()) return res.Miss(); - using var fileSystemAdapter = - new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref)); + using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); res = fs.Register(mountName, ref fileSystemAdapter.Ref); if (res.IsFailure()) return res.Miss(); diff --git a/src/LibHac/Fs/Shim/DeviceSaveData.cs b/src/LibHac/Fs/Shim/DeviceSaveData.cs index c6c58d31..9db60c30 100644 --- a/src/LibHac/Fs/Shim/DeviceSaveData.cs +++ b/src/LibHac/Fs/Shim/DeviceSaveData.cs @@ -50,7 +50,7 @@ public static class DeviceSaveData res = fileSystemProxy.Get.OpenSaveDataFileSystem(ref fileSystem.Ref, DeviceSaveDataSpaceId, in attribute); if (res.IsFailure()) return res.Miss(); - var fileSystemAdapterRaw = new FileSystemServiceObjectAdapter(ref fileSystem.Ref); + var fileSystemAdapterRaw = new FileSystemServiceObjectAdapter(in fileSystem); using var fileSystemAdapter = new UniqueRef(fileSystemAdapterRaw); if (!fileSystemAdapter.HasValue) diff --git a/src/LibHac/Fs/Shim/FileSystemServiceObjectAdapter.cs b/src/LibHac/Fs/Shim/FileSystemServiceObjectAdapter.cs index e40d32a9..bc840fdd 100644 --- a/src/LibHac/Fs/Shim/FileSystemServiceObjectAdapter.cs +++ b/src/LibHac/Fs/Shim/FileSystemServiceObjectAdapter.cs @@ -274,7 +274,7 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget res = _baseFs.Get.OpenDirectory(ref directoryServiceObject.Ref, in sfPath, (uint)mode); if (res.IsFailure()) return res.Miss(); - outDirectory.Reset(new DirectoryServiceObjectAdapter(ref directoryServiceObject.Ref)); + outDirectory.Reset(new DirectoryServiceObjectAdapter(in directoryServiceObject)); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/GameCard.cs b/src/LibHac/Fs/Shim/GameCard.cs index 4d912ea6..d8e838c9 100644 --- a/src/LibHac/Fs/Shim/GameCard.cs +++ b/src/LibHac/Fs/Shim/GameCard.cs @@ -139,8 +139,7 @@ public static class GameCard res = fileSystemProxy.Get.OpenGameCardFileSystem(ref fileSystem.Ref, handle, partitionId); if (res.IsFailure()) return res.Miss(); - using var fileSystemAdapter = - new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref)); + using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInGameCardC.Log(); @@ -181,7 +180,7 @@ public static class GameCard fs.Impl.AbortIfNeeded(res); if (res.IsFailure()) return res.Miss(); - using var storageAdapter = new UniqueRef(new StorageServiceObjectAdapter(ref storage.Ref)); + using var storageAdapter = new UniqueRef(new StorageServiceObjectAdapter(in storage)); if (!storageAdapter.HasValue) return ResultFs.AllocationMemoryFailedInGameCardB.Log(); diff --git a/src/LibHac/Fs/Shim/Host.cs b/src/LibHac/Fs/Shim/Host.cs index 8b853434..7518c206 100644 --- a/src/LibHac/Fs/Shim/Host.cs +++ b/src/LibHac/Fs/Shim/Host.cs @@ -54,7 +54,7 @@ public static class Host } using var fileSystemAdapter = - new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref)); + new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInHostA.Log(); diff --git a/src/LibHac/Fs/Shim/ImageDirectory.cs b/src/LibHac/Fs/Shim/ImageDirectory.cs index 5fb15219..8c02ae78 100644 --- a/src/LibHac/Fs/Shim/ImageDirectory.cs +++ b/src/LibHac/Fs/Shim/ImageDirectory.cs @@ -59,8 +59,7 @@ public static class ImageDirectory res = fileSystemProxy.Get.OpenImageDirectoryFileSystem(ref fileSystem.Ref, directoryId); if (res.IsFailure()) return res.Miss(); - using var fileSystemAdapter = - new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref)); + using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInImageDirectoryA.Log(); diff --git a/src/LibHac/Fs/Shim/Logo.cs b/src/LibHac/Fs/Shim/Logo.cs index 8a903014..fe4d4785 100644 --- a/src/LibHac/Fs/Shim/Logo.cs +++ b/src/LibHac/Fs/Shim/Logo.cs @@ -65,8 +65,7 @@ public static class Logo FileSystemProxyType.Logo); if (res.IsFailure()) return res.Miss(); - using var fileSystemAdapter = - new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref)); + using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInLogoA.Log(); diff --git a/src/LibHac/Fs/Shim/SaveData.cs b/src/LibHac/Fs/Shim/SaveData.cs index bbbf6cbb..c91bb6f9 100644 --- a/src/LibHac/Fs/Shim/SaveData.cs +++ b/src/LibHac/Fs/Shim/SaveData.cs @@ -34,8 +34,7 @@ public static class SaveData saveDataId); if (res.IsFailure()) return res.Miss(); - using var fileSystemAdapter = - new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref)); + using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); outFileSystem.Set(ref fileSystemAdapter.Ref); @@ -102,7 +101,7 @@ public static class SaveData // Note: Nintendo does pass in the same object both as a unique_ptr and as a raw pointer. // Both of these are tied to the lifetime of the created FileSystemServiceObjectAdapter so it shouldn't be an issue. - var fileSystemAdapterRaw = new FileSystemServiceObjectAdapter(ref fileSystem.Ref); + var fileSystemAdapterRaw = new FileSystemServiceObjectAdapter(in fileSystem); using var fileSystemAdapter = new UniqueRef(fileSystemAdapterRaw); if (!fileSystemAdapter.HasValue) diff --git a/src/LibHac/Fs/Shim/SaveDataManagement.cs b/src/LibHac/Fs/Shim/SaveDataManagement.cs index a043f16d..9d908839 100644 --- a/src/LibHac/Fs/Shim/SaveDataManagement.cs +++ b/src/LibHac/Fs/Shim/SaveDataManagement.cs @@ -560,7 +560,7 @@ namespace LibHac.Fs.Shim Result res = fileSystemProxy.Get.OpenSaveDataInfoReaderBySaveDataSpaceId(ref reader.Ref, spaceId); if (res.IsFailure()) return res.Miss(); - using var iterator = new UniqueRef(new SaveDataIterator(fs.Fs, ref reader.Ref)); + using var iterator = new UniqueRef(new SaveDataIterator(fs.Fs, in reader)); if (!iterator.HasValue) return ResultFs.AllocationMemoryFailedInSaveDataManagementA.Log(); @@ -579,7 +579,7 @@ namespace LibHac.Fs.Shim Result res = fileSystemProxy.Get.OpenSaveDataInfoReaderWithFilter(ref reader.Ref, spaceId, in filter); if (res.IsFailure()) return res.Miss(); - using var iterator = new UniqueRef(new SaveDataIterator(fs.Fs, ref reader.Ref)); + using var iterator = new UniqueRef(new SaveDataIterator(fs.Fs, in reader)); if (!iterator.HasValue) return ResultFs.AllocationMemoryFailedInSaveDataManagementA.Log(); diff --git a/src/LibHac/Fs/Shim/SaveDataTransferAdapter.cs b/src/LibHac/Fs/Shim/SaveDataTransferAdapter.cs index 972958cc..ae51889f 100644 --- a/src/LibHac/Fs/Shim/SaveDataTransferAdapter.cs +++ b/src/LibHac/Fs/Shim/SaveDataTransferAdapter.cs @@ -178,7 +178,7 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter _fsClient.Impl.AbortIfNeeded(res); if (res.IsFailure()) return res.Miss(); - outIterator.Reset(new SaveDataChunkIterator(_fsClient, ref iteratorObject.Ref)); + outIterator.Reset(new SaveDataChunkIterator(_fsClient, in iteratorObject)); return Result.Success; } @@ -190,7 +190,7 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter _fsClient.Impl.AbortIfNeeded(res); if (res.IsFailure()) return res.Miss(); - outExporter.Reset(new SaveDataChunkExporter(_fsClient, ref exporterObject.Ref)); + outExporter.Reset(new SaveDataChunkExporter(_fsClient, in exporterObject)); return Result.Success; } @@ -404,7 +404,7 @@ public class SaveDataImporterVersion2 : ISaveDataDivisionImporter _fsClient.Impl.AbortIfNeeded(res); if (res.IsFailure()) return res.Miss(); - outIterator.Reset(new SaveDataChunkIterator(_fsClient, ref iteratorObject.Ref)); + outIterator.Reset(new SaveDataChunkIterator(_fsClient, in iteratorObject)); return Result.Success; } @@ -416,7 +416,7 @@ public class SaveDataImporterVersion2 : ISaveDataDivisionImporter _fsClient.Impl.AbortIfNeeded(res); if (res.IsFailure()) return res.Miss(); - outImporter.Reset(new SaveDataChunkImporter(_fsClient, ref importerObject.Ref)); + outImporter.Reset(new SaveDataChunkImporter(_fsClient, in importerObject)); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/SaveDataTransferVersion2.cs b/src/LibHac/Fs/Shim/SaveDataTransferVersion2.cs index 72900803..035c160f 100644 --- a/src/LibHac/Fs/Shim/SaveDataTransferVersion2.cs +++ b/src/LibHac/Fs/Shim/SaveDataTransferVersion2.cs @@ -85,7 +85,7 @@ namespace LibHac.Fs _fsClient.Impl.LogResultErrorMessage(res); if (res.IsFailure()) return res.Miss(); - outExporter.Reset(new SaveDataExporterVersion2(_fsClient, ref exporterInterface.Ref)); + outExporter.Reset(new SaveDataExporterVersion2(_fsClient, in exporterInterface)); return Result.Success; } @@ -100,7 +100,7 @@ namespace LibHac.Fs _fsClient.Impl.LogResultErrorMessage(res); if (res.IsFailure()) return res.Miss(); - outExporter.Reset(new SaveDataExporterVersion2(_fsClient, ref exporterInterface.Ref)); + outExporter.Reset(new SaveDataExporterVersion2(_fsClient, in exporterInterface)); return Result.Success; } @@ -115,7 +115,7 @@ namespace LibHac.Fs _fsClient.Impl.LogResultErrorMessage(res); if (res.IsFailure()) return res.Miss(); - outExporter.Reset(new SaveDataExporterVersion2(_fsClient, ref exporterInterface.Ref)); + outExporter.Reset(new SaveDataExporterVersion2(_fsClient, in exporterInterface)); return Result.Success; } @@ -130,7 +130,7 @@ namespace LibHac.Fs _fsClient.Impl.LogResultErrorMessage(res); if (res.IsFailure()) return res.Miss(); - outImporter.Reset(new SaveDataImporterVersion2(_fsClient, ref importerInterface.Ref)); + outImporter.Reset(new SaveDataImporterVersion2(_fsClient, in importerInterface)); return Result.Success; } @@ -145,7 +145,7 @@ namespace LibHac.Fs _fsClient.Impl.LogResultErrorMessage(res); if (res.IsFailure()) return res.Miss(); - outImporter.Reset(new SaveDataImporterVersion2(_fsClient, ref importerInterface.Ref)); + outImporter.Reset(new SaveDataImporterVersion2(_fsClient, in importerInterface)); return Result.Success; } @@ -160,7 +160,7 @@ namespace LibHac.Fs _fsClient.Impl.LogResultErrorMessage(res); if (res.IsFailure()) return res.Miss(); - outImporter.Reset(new SaveDataImporterVersion2(_fsClient, ref importerInterface.Ref)); + outImporter.Reset(new SaveDataImporterVersion2(_fsClient, in importerInterface)); return Result.Success; } @@ -175,7 +175,7 @@ namespace LibHac.Fs _fsClient.Impl.LogResultErrorMessage(res); if (res.IsFailure()) return res.Miss(); - outImporter.Reset(new SaveDataImporterVersion2(_fsClient, ref importerInterface.Ref)); + outImporter.Reset(new SaveDataImporterVersion2(_fsClient, in importerInterface)); return Result.Success; } @@ -196,7 +196,7 @@ namespace LibHac.Fs _fsClient.Impl.LogResultErrorMessage(res); if (res.IsFailure()) return res.Miss(); - outImporter.Reset(new SaveDataImporterVersion2(_fsClient, ref importerInterface.Ref)); + outImporter.Reset(new SaveDataImporterVersion2(_fsClient, in importerInterface)); return Result.Success; } @@ -296,7 +296,7 @@ namespace LibHac.Fs.Shim // Result res = fileSystemProxy.Get.OpenSaveDataTransferProhibiter(ref prohibiter.Ref, applicationId); // if (res.IsFailure()) return res.Miss(); - outProhibiter.Reset(new SaveDataTransferProhibiterForCloudBackUp(ref prohibiter.Ref)); + outProhibiter.Reset(new SaveDataTransferProhibiterForCloudBackUp(in prohibiter)); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/SdCard.cs b/src/LibHac/Fs/Shim/SdCard.cs index 03f780c4..60f64d1e 100644 --- a/src/LibHac/Fs/Shim/SdCard.cs +++ b/src/LibHac/Fs/Shim/SdCard.cs @@ -56,8 +56,7 @@ public static class SdCard private static Result RegisterFileSystem(FileSystemClient fs, U8Span mountName, ref readonly SharedRef fileSystem) { - using var fileSystemAdapter = - new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); + using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(in fileSystem)); if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInSdCardA.Log(); @@ -113,14 +112,14 @@ public static class SdCard if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - res = RegisterFileSystem(fs, mountName, ref fileSystem.Ref); + res = RegisterFileSystem(fs, mountName, in fileSystem); Tick end = fs.Hos.Os.GetSystemTick(); fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - res = RegisterFileSystem(fs, mountName, ref fileSystem.Ref); + res = RegisterFileSystem(fs, mountName, in fileSystem); } fs.Impl.AbortIfNeeded(res); @@ -180,14 +179,14 @@ public static class SdCard if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - res = RegisterFileSystem(fs, mountName, ref fileSystem.Ref); + res = RegisterFileSystem(fs, mountName, in fileSystem); Tick end = fs.Hos.Os.GetSystemTick(); fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - res = RegisterFileSystem(fs, mountName, ref fileSystem.Ref); + res = RegisterFileSystem(fs, mountName, in fileSystem); } fs.Impl.AbortIfNeeded(res); @@ -208,7 +207,7 @@ public static class SdCard fs.Impl.LogResultErrorMessage(res); Abort.DoAbortUnless(res.IsSuccess()); - res = CheckIfInserted(fs, ref deviceOperator.Ref, out bool isInserted); + res = CheckIfInserted(fs, in deviceOperator, out bool isInserted); fs.Impl.LogResultErrorMessage(res); Abort.DoAbortUnless(res.IsSuccess()); diff --git a/src/LibHac/Fs/Shim/SystemSaveData.cs b/src/LibHac/Fs/Shim/SystemSaveData.cs index 2dea5f48..2ea5a333 100644 --- a/src/LibHac/Fs/Shim/SystemSaveData.cs +++ b/src/LibHac/Fs/Shim/SystemSaveData.cs @@ -87,7 +87,7 @@ public static class SystemSaveData res = fileSystemProxy.Get.OpenSaveDataFileSystemBySystemSaveDataId(ref fileSystem.Ref, spaceId, in attribute); if (res.IsFailure()) return res.Miss(); - var fileSystemAdapterRaw = new FileSystemServiceObjectAdapter(ref fileSystem.Ref); + var fileSystemAdapterRaw = new FileSystemServiceObjectAdapter(in fileSystem); using var fileSystemAdapter = new UniqueRef(fileSystemAdapterRaw); if (!fileSystemAdapter.HasValue) diff --git a/src/LibHac/FsSrv/BaseFileSystemService.cs b/src/LibHac/FsSrv/BaseFileSystemService.cs index b4923254..18673b1a 100644 --- a/src/LibHac/FsSrv/BaseFileSystemService.cs +++ b/src/LibHac/FsSrv/BaseFileSystemService.cs @@ -1,5 +1,4 @@ -using System; -using LibHac.Common; +using LibHac.Common; using LibHac.Fs; using LibHac.FsSrv.Impl; using LibHac.FsSrv.Sf; @@ -69,8 +68,7 @@ public readonly struct BaseFileSystemService if (res.IsFailure()) return res.Miss(); // Create an SF adapter for the file system - using SharedRef fileSystemAdapter = - FileSystemInterfaceAdapter.CreateShared(ref fileSystem.Ref, false); + using SharedRef fileSystemAdapter = FileSystemInterfaceAdapter.CreateShared(in fileSystem, false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); @@ -131,19 +129,13 @@ public readonly struct BaseFileSystemService if (res.IsFailure()) return res.Miss(); using var subDirFileSystem = new SharedRef(); - res = Utility.CreateSubDirectoryFileSystem(ref subDirFileSystem.Ref, ref fileSystem.Ref, - in pathNormalized); + res = Utility.CreateSubDirectoryFileSystem(ref subDirFileSystem.Ref, in fileSystem, in pathNormalized); if (res.IsFailure()) return res.Miss(); // Add all the file system wrappers - using var typeSetFileSystem = - new SharedRef(new StorageLayoutTypeSetFileSystem(ref subDirFileSystem.Ref, storageFlag)); - - using var asyncFileSystem = - new SharedRef(new AsynchronousAccessFileSystem(ref typeSetFileSystem.Ref)); - - using SharedRef fileSystemAdapter = - FileSystemInterfaceAdapter.CreateShared(ref asyncFileSystem.Ref, false); + using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(in subDirFileSystem, storageFlag)); + using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(in typeSetFileSystem)); + using SharedRef fileSystemAdapter = FileSystemInterfaceAdapter.CreateShared(in asyncFileSystem, allowAllOperations: false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); @@ -193,10 +185,10 @@ public readonly struct BaseFileSystemService if (res.IsFailure()) return res.Miss(); using var asyncFileSystem = - new SharedRef(new AsynchronousAccessFileSystem(ref fileSystem.Ref)); + new SharedRef(new AsynchronousAccessFileSystem(in fileSystem)); using SharedRef fileSystemAdapter = - FileSystemInterfaceAdapter.CreateShared(ref asyncFileSystem.Ref, false); + FileSystemInterfaceAdapter.CreateShared(in asyncFileSystem, false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); @@ -221,14 +213,9 @@ public readonly struct BaseFileSystemService if (res.IsFailure()) return res.Miss(); // Add all the file system wrappers - using var typeSetFileSystem = - new SharedRef(new StorageLayoutTypeSetFileSystem(ref fileSystem.Ref, storageFlag)); - - using var asyncFileSystem = - new SharedRef(new AsynchronousAccessFileSystem(ref typeSetFileSystem.Ref)); - - using SharedRef fileSystemAdapter = - FileSystemInterfaceAdapter.CreateShared(ref asyncFileSystem.Ref, false); + using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(in fileSystem, storageFlag)); + using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(in typeSetFileSystem)); + using SharedRef fileSystemAdapter = FileSystemInterfaceAdapter.CreateShared(in asyncFileSystem, allowAllOperations: false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); @@ -293,7 +280,7 @@ public readonly struct BaseFileSystemService if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemAdapter = - FileSystemInterfaceAdapter.CreateShared(ref baseFileSystem.Ref, false); + FileSystemInterfaceAdapter.CreateShared(in baseFileSystem, false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); diff --git a/src/LibHac/FsSrv/BaseStorageService.cs b/src/LibHac/FsSrv/BaseStorageService.cs index bc030150..359e97b3 100644 --- a/src/LibHac/FsSrv/BaseStorageService.cs +++ b/src/LibHac/FsSrv/BaseStorageService.cs @@ -79,13 +79,9 @@ public readonly struct BaseStorageService res = _serviceImpl.OpenBisStorage(ref storage.Ref, id); if (res.IsFailure()) return res.Miss(); - using var typeSetStorage = - new SharedRef(new StorageLayoutTypeSetStorage(ref storage.Ref, storageFlag)); - + using var typeSetStorage = new SharedRef(new StorageLayoutTypeSetStorage(in storage, storageFlag)); // Todo: Async storage - - using var storageAdapter = - new SharedRef(new StorageInterfaceAdapter(ref typeSetStorage.Ref)); + using var storageAdapter = new SharedRef(new StorageInterfaceAdapter(in typeSetStorage)); outStorage.SetByMove(ref storageAdapter.Ref); @@ -122,9 +118,7 @@ public readonly struct BaseStorageService if (res.IsFailure()) return res.Miss(); // Todo: Async storage - - using var storageAdapter = - new SharedRef(new StorageInterfaceAdapter(ref storage.Ref)); + using var storageAdapter = new SharedRef(new StorageInterfaceAdapter(in storage)); outStorage.SetByMove(ref storageAdapter.Ref); diff --git a/src/LibHac/FsSrv/DefaultFsServerObjects.cs b/src/LibHac/FsSrv/DefaultFsServerObjects.cs index e34502ab..91e14596 100644 --- a/src/LibHac/FsSrv/DefaultFsServerObjects.cs +++ b/src/LibHac/FsSrv/DefaultFsServerObjects.cs @@ -31,8 +31,6 @@ public class DefaultFsServerObjects var gcStorageCreator = new GameCardStorageCreator(fsServer); using var sharedRootFileSystem = new SharedRef(rootFileSystem); - using SharedRef sharedRootFileSystemCopy = - SharedRef.CreateCopy(in sharedRootFileSystem); var memoryResource = new ArrayPoolMemoryResource(); IBufferManager bufferManager = null; @@ -47,8 +45,8 @@ public class DefaultFsServerObjects creators.GameCardStorageCreator = gcStorageCreator; creators.GameCardFileSystemCreator = new GameCardFileSystemCreator(memoryResource, gcStorageCreator, fsServer); creators.EncryptedFileSystemCreator = new EncryptedFileSystemCreator(keySet); - creators.BuiltInStorageFileSystemCreator = new EmulatedBisFileSystemCreator(ref sharedRootFileSystem.Ref); - creators.SdCardFileSystemCreator = new EmulatedSdCardFileSystemCreator(sdmmcNew, ref sharedRootFileSystemCopy.Ref); + creators.BuiltInStorageFileSystemCreator = new EmulatedBisFileSystemCreator(in sharedRootFileSystem); + creators.SdCardFileSystemCreator = new EmulatedSdCardFileSystemCreator(sdmmcNew, in sharedRootFileSystem); var storageDeviceManagerFactory = new EmulatedStorageDeviceManagerFactory(fsServer, sdmmcNew, gameCardNew, hasGameCard: true); diff --git a/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs b/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs index 22dc09b4..1347724b 100644 --- a/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs +++ b/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs @@ -46,7 +46,7 @@ public class FileSystemProxyCoreImpl if (res.IsFailure()) return res.Miss(); using SharedRef tempFs = SharedRef.CreateMove(ref fileSystem.Ref); - res = Utility.WrapSubDirectory(ref fileSystem.Ref, ref tempFs.Ref, in path, createIfMissing: true); + res = Utility.WrapSubDirectory(ref fileSystem.Ref, in tempFs, in path, createIfMissing: true); if (res.IsFailure()) return res.Miss(); } else if (storageId == CustomStorageId.SdCard) @@ -61,7 +61,7 @@ public class FileSystemProxyCoreImpl if (res.IsFailure()) return res.Miss(); using SharedRef tempFs = SharedRef.CreateMove(ref fileSystem.Ref); - res = Utility.WrapSubDirectory(ref fileSystem.Ref, ref tempFs.Ref, in path, createIfMissing: true); + res = Utility.WrapSubDirectory(ref fileSystem.Ref, in tempFs, in path, createIfMissing: true); if (res.IsFailure()) return res.Miss(); tempFs.SetByMove(ref fileSystem.Ref); diff --git a/src/LibHac/FsSrv/FileSystemProxyImpl.cs b/src/LibHac/FsSrv/FileSystemProxyImpl.cs index 62297d41..fbad74a4 100644 --- a/src/LibHac/FsSrv/FileSystemProxyImpl.cs +++ b/src/LibHac/FsSrv/FileSystemProxyImpl.cs @@ -848,14 +848,9 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader if (res.IsFailure()) return res.Miss(); // Add all the file system wrappers - using var typeSetFileSystem = - new SharedRef(new StorageLayoutTypeSetFileSystem(ref fileSystem.Ref, storageFlag)); - - using var asyncFileSystem = - new SharedRef(new AsynchronousAccessFileSystem(ref typeSetFileSystem.Ref)); - - using SharedRef fileSystemAdapter = - FileSystemInterfaceAdapter.CreateShared(ref asyncFileSystem.Ref, allowAllOperations: false); + using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(in fileSystem, storageFlag)); + using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(in typeSetFileSystem)); + using SharedRef fileSystemAdapter = FileSystemInterfaceAdapter.CreateShared(in asyncFileSystem, allowAllOperations: false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); diff --git a/src/LibHac/FsSrv/FileSystemServerInitializer.cs b/src/LibHac/FsSrv/FileSystemServerInitializer.cs index 6a3a3436..7c401007 100644 --- a/src/LibHac/FsSrv/FileSystemServerInitializer.cs +++ b/src/LibHac/FsSrv/FileSystemServerInitializer.cs @@ -45,7 +45,7 @@ public static class FileSystemServerInitializer ulong processId = client.Os.GetCurrentProcessId().Value; fileSystemProxy.Get.SetCurrentProcess(processId).IgnoreResult(); - client.Fs.Impl.InitializeDfcFileSystemProxyServiceObject(ref fileSystemProxy.Ref); + client.Fs.Impl.InitializeDfcFileSystemProxyServiceObject(in fileSystemProxy); InitializeFileSystemProxyServer(client, server); diff --git a/src/LibHac/FsSrv/FsCreator/EmulatedBisFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/EmulatedBisFileSystemCreator.cs index 371e9084..c2e56d90 100644 --- a/src/LibHac/FsSrv/FsCreator/EmulatedBisFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/EmulatedBisFileSystemCreator.cs @@ -83,7 +83,7 @@ public class EmulatedBisFileSystemCreator : IBuiltInStorageFileSystemCreator if (res.IsFailure()) return res.Miss(); using var partitionFileSystem = new SharedRef(); - res = Utility.WrapSubDirectory(ref partitionFileSystem.Ref, ref rootFileSystem.Ref, in bisRootPath, true); + res = Utility.WrapSubDirectory(ref partitionFileSystem.Ref, in rootFileSystem, in bisRootPath, true); if (res.IsFailure()) return res.Miss(); outFileSystem.SetByMove(ref partitionFileSystem.Ref); diff --git a/src/LibHac/FsSrv/FsCreator/EmulatedSdCardFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/EmulatedSdCardFileSystemCreator.cs index 4c144474..65dd7b11 100644 --- a/src/LibHac/FsSrv/FsCreator/EmulatedSdCardFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/EmulatedSdCardFileSystemCreator.cs @@ -69,7 +69,7 @@ public class EmulatedSdCardFileSystemCreator : ISdCardProxyFileSystemCreator, ID // Todo: Add ProxyFileSystem? using SharedRef fileSystem = SharedRef.CreateCopy(in _rootFileSystem); - res = Utility.WrapSubDirectory(ref _sdCardFileSystem, ref fileSystem.Ref, in sdCardPath, true); + res = Utility.WrapSubDirectory(ref _sdCardFileSystem, in fileSystem, in sdCardPath, true); if (res.IsFailure()) return res.Miss(); outFileSystem.SetByCopy(in _sdCardFileSystem); diff --git a/src/LibHac/FsSrv/FsCreator/GameCardFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/GameCardFileSystemCreator.cs index 9c65bd98..8bcc7f5a 100644 --- a/src/LibHac/FsSrv/FsCreator/GameCardFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/GameCardFileSystemCreator.cs @@ -280,7 +280,7 @@ public class GameCardFileSystemCreator : IGameCardFileSystemCreator res = rootPartitionFsMeta.Get.Initialize(rootFsStorage.Get, _allocator, status.PartitionFsHeaderHash, salt); if (res.IsFailure()) return res.Miss(); - _rootPartition.Reset(new GameCardRootPartition(handle, ref rootFsStorage.Ref, _gameCardStorageCreator, + _rootPartition.Reset(new GameCardRootPartition(handle, in rootFsStorage, _gameCardStorageCreator, ref rootPartitionFsMeta.Ref, _fsServer)); if (!_rootPartition.HasValue) diff --git a/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs index edafae9c..d334dafb 100644 --- a/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs @@ -413,7 +413,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator // Wrap the save FS in a result convert FS and set it as the output FS using var resultConvertFs = new SharedRef( - new SaveDataResultConvertFileSystem(ref saveDataFs.Ref, isReconstructible)); + new SaveDataResultConvertFileSystem(in saveDataFs, isReconstructible)); outFileSystem.SetByMove(ref resultConvertFs.Ref); return Result.Success; @@ -450,7 +450,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator } using var resultConvertFs = new SharedRef( - new SaveDataResultConvertFileSystem(ref saveDataFs.Ref, isReconstructible)); + new SaveDataResultConvertFileSystem(in saveDataFs, isReconstructible)); outExtraDataAccessor.SetByMove(ref resultConvertFs.Ref); return Result.Success; @@ -507,7 +507,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator using SharedRef tempSaveFs = SharedRef.CreateMove(ref saveFs.Ref); using var resultConvertFs = new SharedRef( - new SaveDataResultConvertFileSystem(ref tempSaveFs.Ref, isReconstructible)); + new SaveDataResultConvertFileSystem(in tempSaveFs, isReconstructible)); outFileSystem.SetByMove(ref resultConvertFs.Ref); return Result.Success; diff --git a/src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs b/src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs index fbd86788..759fdf34 100644 --- a/src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs +++ b/src/LibHac/FsSrv/Impl/DeepRetryFileSystem.cs @@ -22,7 +22,7 @@ public class DeepRetryFileSystem : ForwardingFileSystem using var retryFileSystem = new SharedRef( new DeepRetryFileSystem(in baseFileSystem, in accessFailureManager)); - retryFileSystem.Get._selfReference.Set(in retryFileSystem.Ref); + retryFileSystem.Get._selfReference.Set(in retryFileSystem); return SharedRef.CreateMove(ref retryFileSystem.Ref); } diff --git a/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs b/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs index de0ada66..803fc11d 100644 --- a/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs +++ b/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs @@ -1,6 +1,5 @@ using System; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using LibHac.Common; using LibHac.Fs; using LibHac.Fs.Fsa; @@ -251,8 +250,7 @@ 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 readonly SharedRef fileSystem, - bool allowAllOperations) + private FileSystemInterfaceAdapter(ref readonly SharedRef fileSystem, bool allowAllOperations) { _baseFileSystem = SharedRef.CreateCopy(in fileSystem); _allowAllOperations = allowAllOperations; @@ -506,7 +504,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf using SharedRef selfReference = SharedRef.Create(in _selfReference); - var adapter = new FileInterfaceAdapter(ref file.Ref, ref selfReference.Ref, _allowAllOperations); + var adapter = new FileInterfaceAdapter(ref file.Ref, in selfReference, _allowAllOperations); outFile.Reset(adapter); return Result.Success; @@ -537,7 +535,7 @@ public class FileSystemInterfaceAdapter : IFileSystemSf using SharedRef selfReference = SharedRef.Create(in _selfReference); - var adapter = new DirectoryInterfaceAdapter(ref directory.Ref, ref selfReference.Ref); + var adapter = new DirectoryInterfaceAdapter(ref directory.Ref, in selfReference); outDirectory.Reset(adapter); return Result.Success; diff --git a/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheManager.cs b/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheManager.cs index a6e75ba1..22ce5a8c 100644 --- a/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheManager.cs +++ b/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheManager.cs @@ -142,7 +142,7 @@ public class SaveDataFileSystemCacheManager : IDisposable { using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - _cachedFileSystems[_nextCacheIndex].Register(ref fileSystem, spaceId, saveDataId); + _cachedFileSystems[_nextCacheIndex].Register(in fileSystem, spaceId, saveDataId); _nextCacheIndex = (_nextCacheIndex + 1) % _maxCachedFileSystemCount; } } diff --git a/src/LibHac/FsSrv/NcaFileSystemService.cs b/src/LibHac/FsSrv/NcaFileSystemService.cs index 668126f0..c96b4d3f 100644 --- a/src/LibHac/FsSrv/NcaFileSystemService.cs +++ b/src/LibHac/FsSrv/NcaFileSystemService.cs @@ -170,11 +170,12 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager } // Add all the file system wrappers - using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(ref fileSystem.Ref, storageFlag)); - using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(ref typeSetFileSystem.Ref)); + using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(in fileSystem, storageFlag)); + using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(in typeSetFileSystem)); + using SharedRef accessFailureManager = SharedRef.Create(in _selfReference); - using SharedRef retryFileSystem = DeepRetryFileSystem.CreateShared(ref asyncFileSystem.Ref, ref accessFailureManager.Ref); - using SharedRef fileSystemAdapter = FileSystemInterfaceAdapter.CreateShared(ref retryFileSystem.Ref, false); + using SharedRef retryFileSystem = DeepRetryFileSystem.CreateShared(in asyncFileSystem, in accessFailureManager); + using SharedRef fileSystemAdapter = FileSystemInterfaceAdapter.CreateShared(in retryFileSystem, false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); @@ -211,9 +212,9 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager if (res.IsFailure()) return res.Miss(); // Add all the file system wrappers - using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(ref fileSystem.Ref, storageFlag)); - using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(ref typeSetFileSystem.Ref)); - using SharedRef fileSystemAdapter = FileSystemInterfaceAdapter.CreateShared(ref asyncFileSystem.Ref, allowAllOperations: false); + using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(in fileSystem, storageFlag)); + using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(in typeSetFileSystem)); + using SharedRef fileSystemAdapter = FileSystemInterfaceAdapter.CreateShared(in asyncFileSystem, allowAllOperations: false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); @@ -237,11 +238,11 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager } else { - asyncFileSystem.Reset(new AsynchronousAccessFileSystem(ref fileSystem.Ref)); + asyncFileSystem.Reset(new AsynchronousAccessFileSystem(in fileSystem)); } using SharedRef fileSystemAdapter = - FileSystemInterfaceAdapter.CreateShared(ref asyncFileSystem.Ref, allowAllOperations: false); + FileSystemInterfaceAdapter.CreateShared(in asyncFileSystem, allowAllOperations: false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); @@ -415,8 +416,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager in accessFailureManager, ref romDivisionSizeUnitCountSemaphore.Ref, in digest, programInfo.ProgramIdValue, storageId, _serviceImpl.FsServer)); - using var typeSetStorage = new SharedRef(new StorageLayoutTypeSetStorage(ref retryStorage.Ref, storageFlag)); - using var storageAdapter = new SharedRef(new StorageInterfaceAdapter(ref typeSetStorage.Ref)); + using var typeSetStorage = new SharedRef(new StorageLayoutTypeSetStorage(in retryStorage, storageFlag)); + using var storageAdapter = new SharedRef(new StorageInterfaceAdapter(in typeSetStorage)); outStorage.SetByMove(ref storageAdapter.Ref); @@ -467,8 +468,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager in accessFailureManager, ref romDivisionSizeUnitCountSemaphore.Ref, in digest, ProgramId.InvalidId.Value, StorageId.None, _serviceImpl.FsServer)); - using var typeSetStorage = new SharedRef(new StorageLayoutTypeSetStorage(ref retryStorage.Ref, storageFlag)); - using var storageAdapter = new SharedRef(new StorageInterfaceAdapter(ref typeSetStorage.Ref)); + using var typeSetStorage = new SharedRef(new StorageLayoutTypeSetStorage(in retryStorage, storageFlag)); + using var storageAdapter = new SharedRef(new StorageInterfaceAdapter(in typeSetStorage)); outStorage.SetByMove(ref storageAdapter.Ref); @@ -511,8 +512,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager in accessFailureManager, ref romDivisionSizeUnitCountSemaphore.Ref, in digest, programId.Value, programInfo.StorageId, _serviceImpl.FsServer)); - using var typeSetStorage = new SharedRef(new StorageLayoutTypeSetStorage(ref retryStorage.Ref, storageFlag)); - using var storageAdapter = new SharedRef(new StorageInterfaceAdapter(ref typeSetStorage.Ref)); + using var typeSetStorage = new SharedRef(new StorageLayoutTypeSetStorage(in retryStorage, storageFlag)); + using var storageAdapter = new SharedRef(new StorageInterfaceAdapter(in typeSetStorage)); outStorage.SetByMove(ref storageAdapter.Ref); @@ -589,14 +590,9 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager if (res.IsFailure()) return res.Miss(); // Add all the wrappers for the file system - using var typeSetFileSystem = - new SharedRef(new StorageLayoutTypeSetFileSystem(ref fileSystem.Ref, storageFlag)); - - using var asyncFileSystem = - new SharedRef(new AsynchronousAccessFileSystem(ref fileSystem.Ref)); - - using SharedRef fileSystemAdapter = - FileSystemInterfaceAdapter.CreateShared(ref asyncFileSystem.Ref, allowAllOperations: false); + using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(in fileSystem, storageFlag)); + using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(in typeSetFileSystem)); + using SharedRef fileSystemAdapter = FileSystemInterfaceAdapter.CreateShared(in asyncFileSystem, allowAllOperations: false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); @@ -618,10 +614,10 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager if (!properProgramInfo.AccessControl.HasContentOwnerId(programId.Value)) return ResultFs.PermissionDenied.Log(); - using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(ref fileSystem.Ref)); + using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(in fileSystem)); using SharedRef fileSystemAdapter = - FileSystemInterfaceAdapter.CreateShared(ref asyncFileSystem.Ref, allowAllOperations: false); + FileSystemInterfaceAdapter.CreateShared(in asyncFileSystem, allowAllOperations: false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); @@ -694,8 +690,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager using var retryStorage = new SharedRef(new DeepRetryStorage(in storage, in storageAccessSplitter, in accessFailureManager, ref mountCountSemaphore.Ref, deepRetryEnabled: isAoc, _serviceImpl.FsServer)); - using var typeSetStorage = new SharedRef(new StorageLayoutTypeSetStorage(ref retryStorage.Ref, storageFlag)); - using var storageAdapter = new SharedRef(new StorageInterfaceAdapter(ref typeSetStorage.Ref)); + using var typeSetStorage = new SharedRef(new StorageLayoutTypeSetStorage(in retryStorage, storageFlag)); + using var storageAdapter = new SharedRef(new StorageInterfaceAdapter(in typeSetStorage)); outStorage.SetByMove(ref storageAdapter.Ref); @@ -742,8 +738,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager return res.Miss(); } - using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(ref fileSystem.Ref, storageFlag)); - using SharedRef fileSystemAdapter = FileSystemInterfaceAdapter.CreateShared(ref typeSetFileSystem.Ref, allowAllOperations: false); + using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(in fileSystem, storageFlag)); + using SharedRef fileSystemAdapter = FileSystemInterfaceAdapter.CreateShared(in typeSetFileSystem, allowAllOperations: false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); @@ -777,8 +773,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager } // Add all the file system wrappers - using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(ref fileSystem.Ref)); - using SharedRef fileSystemAdapter = FileSystemInterfaceAdapter.CreateShared(ref asyncFileSystem.Ref, allowAllOperations: false); + using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(in fileSystem)); + using SharedRef fileSystemAdapter = FileSystemInterfaceAdapter.CreateShared(in asyncFileSystem, allowAllOperations: false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); @@ -822,8 +818,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager in accessFailureManager, ref romDivisionSizeUnitCountSemaphore.Ref, in digest, targetProgramId.Value, programInfo.StorageId, _serviceImpl.FsServer)); - using var typeSetStorage = new SharedRef(new StorageLayoutTypeSetStorage(ref retryStorage.Ref, storageFlag)); - using var storageAdapter = new SharedRef(new StorageInterfaceAdapter(ref typeSetStorage.Ref)); + using var typeSetStorage = new SharedRef(new StorageLayoutTypeSetStorage(in retryStorage, storageFlag)); + using var storageAdapter = new SharedRef(new StorageInterfaceAdapter(in typeSetStorage)); outStorage.SetByMove(ref storageAdapter.Ref); @@ -949,7 +945,7 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager if (res.IsFailure()) return res.Miss(); // Add all the file system wrappers - using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(ref fileSystem.Ref, storageFlag)); + using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(in fileSystem, storageFlag)); outFileSystem.SetByMove(ref typeSetFileSystem.Ref); @@ -975,10 +971,10 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager if (res.IsFailure()) return res.Miss(); // Add all the file system wrappers - using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(ref fileSystem.Ref, storageFlag)); - using var alignmentMatchableFileSystem = new SharedRef(new AlignmentMatchableFileSystem(ref fileSystem.Ref)); - using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(ref alignmentMatchableFileSystem.Ref)); - using SharedRef fileSystemAdapter = FileSystemInterfaceAdapter.CreateShared(ref asyncFileSystem.Ref, allowAllOperations: false); + using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(in fileSystem, storageFlag)); + using var alignmentMatchableFileSystem = new SharedRef(new AlignmentMatchableFileSystem(in typeSetFileSystem)); + using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(in alignmentMatchableFileSystem)); + using SharedRef fileSystemAdapter = FileSystemInterfaceAdapter.CreateShared(in asyncFileSystem, allowAllOperations: false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); @@ -1054,14 +1050,9 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager if (res.IsFailure()) return res.Miss(); // Add all the file system wrappers - using var typeSetFileSystem = - new SharedRef(new StorageLayoutTypeSetFileSystem(ref fileSystem.Ref, storageFlag)); - - using var asyncFileSystem = - new SharedRef(new AsynchronousAccessFileSystem(ref typeSetFileSystem.Ref)); - - using SharedRef fileSystemAdapter = - FileSystemInterfaceAdapter.CreateShared(ref asyncFileSystem.Ref, allowAllOperations: false); + using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(in fileSystem, storageFlag)); + using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(in typeSetFileSystem)); + using SharedRef fileSystemAdapter = FileSystemInterfaceAdapter.CreateShared(in asyncFileSystem, allowAllOperations: false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); @@ -1131,7 +1122,7 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager pathFlags.AllowWindowsPath(); using SharedRef fileSystemAdapter = - FileSystemInterfaceAdapter.CreateShared(ref fileSystem.Ref, pathFlags, allowAllOperations: false); + FileSystemInterfaceAdapter.CreateShared(in fileSystem, pathFlags, allowAllOperations: false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); diff --git a/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs b/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs index fbe09b43..c9eca081 100644 --- a/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs +++ b/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs @@ -382,7 +382,7 @@ public class NcaFileSystemServiceImpl : IDisposable using var ncaReader = new SharedRef(); ulong openProgramId = mountInfo.IsHostOrLocalFs() ? ulong.MaxValue : id; - res = ParseNca(ref ncaReader.Ref, ref baseFileSystem.Ref, currentPath, attributes, openProgramId); + res = ParseNca(ref ncaReader.Ref, in baseFileSystem, currentPath, attributes, openProgramId); if (res.IsFailure()) return res.Miss(); using var storage = new SharedRef(); diff --git a/src/LibHac/FsSrv/SaveDataFileSystemService.cs b/src/LibHac/FsSrv/SaveDataFileSystemService.cs index 51787fe9..8de8106d 100644 --- a/src/LibHac/FsSrv/SaveDataFileSystemService.cs +++ b/src/LibHac/FsSrv/SaveDataFileSystemService.cs @@ -42,9 +42,9 @@ file class SaveDataOpenCountAdapter : IEntryOpenCountSemaphoreManager { private SharedRef _saveService; - public SaveDataOpenCountAdapter(ref SharedRef saveService) + public SaveDataOpenCountAdapter(ref readonly SharedRef saveService) { - _saveService = SharedRef.CreateMove(ref saveService); + _saveService = SharedRef.CreateCopy(in saveService); } public void Dispose() @@ -1752,14 +1752,12 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave if (res.IsFailure()) return res.Miss(); // Add all the wrappers for the file system - using var typeSetFileSystem = - new SharedRef(new StorageLayoutTypeSetFileSystem(ref fileSystem.Ref, storageFlag)); - + using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(in fileSystem, storageFlag)); using var asyncFileSystem = new SharedRef(); if (useAsyncFileSystem) { - asyncFileSystem.Reset(new AsynchronousAccessFileSystem(ref typeSetFileSystem.Ref)); + asyncFileSystem.Reset(new AsynchronousAccessFileSystem(in typeSetFileSystem)); } else { @@ -1768,17 +1766,17 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using SharedRef saveService = GetSharedFromThis(); using var openEntryCountAdapter = - new SharedRef(new SaveDataOpenCountAdapter(ref saveService.Ref)); + new SharedRef(new SaveDataOpenCountAdapter(in saveService)); - using var openCountFileSystem = new SharedRef(new OpenCountFileSystem(ref asyncFileSystem.Ref, - ref openEntryCountAdapter.Ref, ref mountCountSemaphore.Ref)); + using var openCountFileSystem = new SharedRef(new OpenCountFileSystem(in asyncFileSystem, + in openEntryCountAdapter, ref mountCountSemaphore.Ref)); PathFlags pathFlags = FileSystemInterfaceAdapter.GetDefaultPathFlags(); pathFlags.AllowBackslash(); pathFlags.AllowInvalidCharacter(); using SharedRef fileSystemAdapter = - FileSystemInterfaceAdapter.CreateShared(ref openCountFileSystem.Ref, pathFlags, false); + FileSystemInterfaceAdapter.CreateShared(in openCountFileSystem, pathFlags, allowAllOperations: false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); return Result.Success; @@ -1879,14 +1877,12 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave if (res.IsFailure()) return res.Miss(); // Add all the wrappers for the file system - using var typeSetFileSystem = - new SharedRef(new StorageLayoutTypeSetFileSystem(ref fileSystem.Ref, storageFlag)); - + using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(in fileSystem, storageFlag)); using var asyncFileSystem = new SharedRef(); if (useAsyncFileSystem) { - asyncFileSystem.Reset(new AsynchronousAccessFileSystem(ref typeSetFileSystem.Ref)); + asyncFileSystem.Reset(new AsynchronousAccessFileSystem(in typeSetFileSystem)); } else { @@ -1895,17 +1891,17 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using SharedRef saveService = GetSharedFromThis(); using var openEntryCountAdapter = - new SharedRef(new SaveDataOpenCountAdapter(ref saveService.Ref)); + new SharedRef(new SaveDataOpenCountAdapter(in saveService)); using var openCountFileSystem = new SharedRef( - new OpenCountFileSystem(ref asyncFileSystem.Ref, ref openEntryCountAdapter.Ref)); + new OpenCountFileSystem(in asyncFileSystem, in openEntryCountAdapter)); PathFlags pathFlags = FileSystemInterfaceAdapter.GetDefaultPathFlags(); pathFlags.AllowBackslash(); pathFlags.AllowInvalidCharacter(); using SharedRef fileSystemAdapter = - FileSystemInterfaceAdapter.CreateShared(ref openCountFileSystem.Ref, pathFlags, allowAllOperations: false); + FileSystemInterfaceAdapter.CreateShared(in openCountFileSystem, pathFlags, allowAllOperations: false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); return Result.Success; @@ -2257,14 +2253,13 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave if (res.IsFailure()) return res.Miss(); using var reader = new SharedRef(); - res = accessor.Get.GetInterface().OpenSaveDataInfoReader(ref reader.Ref); if (res.IsFailure()) return res.Miss(); var filter = new SaveDataInfoFilter(ConvertToRealSpaceId(spaceId), programId: default, saveDataType: default, userId: default, saveDataId: default, index: default, (int)SaveDataRank.Primary); - filterReader.Reset(new SaveDataInfoFilterReader(ref reader.Ref, in filter)); + filterReader.Reset(new SaveDataInfoFilterReader(in reader, in filter)); } outInfoReader.Set(ref filterReader.Ref); @@ -2300,7 +2295,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave var infoFilter = new SaveDataInfoFilter(ConvertToRealSpaceId(spaceId), in filter); - filterReader.Reset(new SaveDataInfoFilterReader(ref reader.Ref, in infoFilter)); + filterReader.Reset(new SaveDataInfoFilterReader(in reader, in infoFilter)); } outInfoReader.Set(ref filterReader.Ref); @@ -2323,7 +2318,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave if (res.IsFailure()) return res.Miss(); using var filterReader = - new UniqueRef(new SaveDataInfoFilterReader(ref reader.Ref, in infoFilter)); + new UniqueRef(new SaveDataInfoFilterReader(in reader, in infoFilter)); return filterReader.Get.Read(out count, new OutBuffer(SpanHelpers.AsByteSpan(ref info))).Ret(); } @@ -2427,9 +2422,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave in saveDataRootPath, isTemporaryTransferSave, isReconstructible); if (res.IsFailure()) return res.Miss(); - using var typeSetFileSystem = - new SharedRef(new StorageLayoutTypeSetFileSystem(ref fileSystem.Ref, storageFlag)); - + using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(in fileSystem, storageFlag)); outFileSystem.SetByMove(ref typeSetFileSystem.Ref); return Result.Success; } @@ -2476,17 +2469,17 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave if (res.IsFailure()) return res.Miss(); // Add all the wrappers for the file system - using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(ref fileSystem.Ref)); + using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(in fileSystem)); using SharedRef saveService = GetSharedFromThis(); using var openEntryCountAdapter = - new SharedRef(new SaveDataOpenCountAdapter(ref saveService.Ref)); + new SharedRef(new SaveDataOpenCountAdapter(in saveService)); - using var openCountFileSystem = new SharedRef(new OpenCountFileSystem(ref asyncFileSystem.Ref, - ref openEntryCountAdapter.Ref, ref mountCountSemaphore.Ref)); + using var openCountFileSystem = new SharedRef(new OpenCountFileSystem(in asyncFileSystem, + in openEntryCountAdapter, ref mountCountSemaphore.Ref)); using SharedRef fileSystemAdapter = - FileSystemInterfaceAdapter.CreateShared(ref openCountFileSystem.Ref, allowAllOperations: false); + FileSystemInterfaceAdapter.CreateShared(in openCountFileSystem, allowAllOperations: false); outFileSystem.SetByMove(ref fileSystemAdapter.Ref); return Result.Success; @@ -2599,7 +2592,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave var filter = new SaveDataInfoFilter(ConvertToRealSpaceId(spaceId), resolvedProgramId, SaveDataType.Cache, userId: default, saveDataId: default, index: default, (int)SaveDataRank.Primary); - filterReader.Reset(new SaveDataInfoFilterReader(ref reader.Ref, in filter)); + filterReader.Reset(new SaveDataInfoFilterReader(in reader, in filter)); } outInfoReader.Set(ref filterReader.Ref); @@ -2617,8 +2610,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave Result res = _serviceImpl.OpenSaveDataMetaDirectoryFileSystem(ref fileSystem.Ref, spaceId, saveDataId); if (res.IsFailure()) return res.Miss(); - using var typeSetFileSystem = - new SharedRef(new StorageLayoutTypeSetFileSystem(ref fileSystem.Ref, storageFlag)); + using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(in fileSystem, storageFlag)); Unsafe.SkipInit(out Array15 pathMetaBuffer); @@ -2681,13 +2673,9 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave res = _serviceImpl.OpenSaveDataMetaDirectoryFileSystem(ref tmpFileSystem.Ref, spaceId, targetSaveDataId); if (res.IsFailure()) return res.Miss(); - using var typeSetFileSystem = - new SharedRef(new StorageLayoutTypeSetFileSystem(ref tmpFileSystem.Ref, storageFlag)); - - using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(ref typeSetFileSystem.Ref)); - - using SharedRef fileSystem = - FileSystemInterfaceAdapter.CreateShared(ref asyncFileSystem.Ref, allowAllOperations: false); + using var typeSetFileSystem = new SharedRef(new StorageLayoutTypeSetFileSystem(in tmpFileSystem, storageFlag)); + using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(in typeSetFileSystem)); + using SharedRef fileSystem = FileSystemInterfaceAdapter.CreateShared(in asyncFileSystem, allowAllOperations: false); Unsafe.SkipInit(out Sf.Path sfPath); var sb = new U8StringBuilder(SpanHelpers.AsByteSpan(ref sfPath)); @@ -2847,8 +2835,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using SharedRef transferInterface = GetSaveDataTransferCoreInterfaceFromThis(); using var manager = new SharedRef( - new SaveDataTransferManager(_serviceImpl.GetSaveDataTransferCryptoConfiguration(), - in transferInterface.Ref)); + new SaveDataTransferManager(_serviceImpl.GetSaveDataTransferCryptoConfiguration(), in transferInterface)); if (!manager.HasValue) return ResultFs.AllocationMemoryFailedInFileSystemProxyImplA.Log(); @@ -2896,7 +2883,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using SharedRef transferInterface = GetSaveDataTransferCoreInterfaceFromThis(); using var manager = new SharedRef( new SaveDataTransferManagerForSaveDataRepair( - _serviceImpl.GetSaveDataTransferCryptoConfiguration(), in transferInterface.Ref, + _serviceImpl.GetSaveDataTransferCryptoConfiguration(), in transferInterface, _serviceImpl.GetSaveDataPorterManager(), isOpenPorterWithKeyEnabled)); if (!manager.HasValue) @@ -2919,7 +2906,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using SharedRef transferInterface = GetSaveDataTransferCoreInterfaceFromThis(); using var manager = new SharedRef( new Impl.SaveDataTransferManagerForRepair(_serviceImpl.GetSaveDataTransferCryptoConfiguration(), - in transferInterface.Ref, _serviceImpl.GetSaveDataPorterManager())); + in transferInterface, _serviceImpl.GetSaveDataPorterManager())); if (!manager.HasValue) return ResultFs.AllocationMemoryFailedInFileSystemProxyImplA.Log(); @@ -3318,7 +3305,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { using SharedRef commitInterface = GetSharedMultiCommitInterfaceFromThis(); - outCommitManager.Reset(new MultiCommitManager(_serviceImpl.FsServer, ref commitInterface.Ref)); + outCommitManager.Reset(new MultiCommitManager(_serviceImpl.FsServer, in commitInterface)); return Result.Success; } diff --git a/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs b/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs index 199004e8..42541ef7 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, fileSystem.Ref, spaceId, saveDataId, + res = _config.SaveFsCreator.Create(ref saveDataFs.Ref, in fileSystem, spaceId, saveDataId, isEmulatedOnHost, isDeviceUniqueMac, isJournalingSupported, isMultiCommitSupported, openReadOnly, openShared, _timeStampGetter, isReconstructible); if (res.IsFailure()) return res.Miss(); @@ -316,7 +316,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable } using var registerFs = new SharedRef( - new SaveDataFileSystemCacheRegister(ref saveDataFs.Ref, _saveFileSystemCacheManager, spaceId, saveDataId)); + new SaveDataFileSystemCacheRegister(in saveDataFs, _saveFileSystemCacheManager, spaceId, saveDataId)); if (openReadOnly) { @@ -1148,7 +1148,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable caseSensitive: true); if (res.IsFailure()) return res.Miss(); - res = Utility.WrapSubDirectory(ref outFileSystem, ref baseFileSystem.Ref, in directoryPath, + res = Utility.WrapSubDirectory(ref outFileSystem, in baseFileSystem, in directoryPath, createIfMissing); if (res.IsFailure()) return res.Miss(); @@ -1162,8 +1162,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable caseSensitive: true); if (res.IsFailure()) return res.Miss(); - res = Utility.WrapSubDirectory(ref outFileSystem, ref baseFileSystem.Ref, in directoryPath, - createIfMissing); + res = Utility.WrapSubDirectory(ref outFileSystem, in baseFileSystem, in directoryPath, createIfMissing); if (res.IsFailure()) return res.Miss(); break; @@ -1189,7 +1188,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable using SharedRef tempFileSystem = SharedRef.CreateMove(ref baseFileSystem.Ref); - res = Utility.WrapSubDirectory(ref baseFileSystem.Ref, ref tempFileSystem.Ref, in pathSdRoot, createIfMissing); + res = Utility.WrapSubDirectory(ref baseFileSystem.Ref, in tempFileSystem, in pathSdRoot, createIfMissing); if (res.IsFailure()) return res.Miss(); res = _config.EncryptedFsCreator.Create(ref outFileSystem, in baseFileSystem, @@ -1205,8 +1204,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable BisPartitionId.SystemProperPartition, caseSensitive: true); if (res.IsFailure()) return res.Miss(); - res = Utility.WrapSubDirectory(ref outFileSystem, ref baseFileSystem.Ref, in directoryPath, - createIfMissing); + res = Utility.WrapSubDirectory(ref outFileSystem, in baseFileSystem, in directoryPath, createIfMissing); if (res.IsFailure()) return res.Miss(); break; @@ -1218,8 +1216,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable caseSensitive: true); if (res.IsFailure()) return res.Miss(); - res = Utility.WrapSubDirectory(ref outFileSystem, ref baseFileSystem.Ref, in directoryPath, - createIfMissing); + res = Utility.WrapSubDirectory(ref outFileSystem, in baseFileSystem, in directoryPath, createIfMissing); if (res.IsFailure()) return res.Miss(); break; diff --git a/src/LibHac/FsSrv/SaveDataIndexer.cs b/src/LibHac/FsSrv/SaveDataIndexer.cs index 68dd8aa1..77422013 100644 --- a/src/LibHac/FsSrv/SaveDataIndexer.cs +++ b/src/LibHac/FsSrv/SaveDataIndexer.cs @@ -1,7 +1,6 @@ using System; using System.Buffers.Binary; using System.Collections.Generic; -using System.Runtime.InteropServices; using LibHac.Common; using LibHac.Common.FixedArrays; using LibHac.Diag; diff --git a/src/LibHac/FsSrv/SaveDataIndexerLite.cs b/src/LibHac/FsSrv/SaveDataIndexerLite.cs index 81e646cf..9c1ca231 100644 --- a/src/LibHac/FsSrv/SaveDataIndexerLite.cs +++ b/src/LibHac/FsSrv/SaveDataIndexerLite.cs @@ -1,5 +1,4 @@ using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using LibHac.Common; using LibHac.Fs; using LibHac.Os; diff --git a/src/LibHac/FsSrv/SaveDataInfoFilter.cs b/src/LibHac/FsSrv/SaveDataInfoFilter.cs index c8778870..36b1e416 100644 --- a/src/LibHac/FsSrv/SaveDataInfoFilter.cs +++ b/src/LibHac/FsSrv/SaveDataInfoFilter.cs @@ -1,6 +1,5 @@ using System; using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; using LibHac.Common; using LibHac.Fs; using LibHac.Ncm; diff --git a/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs b/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs index 66ed46bd..8d75395b 100644 --- a/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs +++ b/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs @@ -366,24 +366,21 @@ public class SaveDataFileStorageHolder res = baseFileStorage.Get.Initialize(in baseFileSystem, in saveImageName, mode, type.ValueRo); if (res.IsFailure()) return res.Miss(); - using SharedRef baseFileStorageCopy = - SharedRef.CreateCopy(in baseFileStorage); - - res = Register(ref baseFileStorageCopy.Ref, spaceId, saveDataId); + res = Register(in baseFileStorage, spaceId, saveDataId); if (res.IsFailure()) return res.Miss(); } - outSaveDataStorage.Reset(new SaveDataSharedFileStorage(ref baseFileStorage.Ref, type.ValueRo)); + outSaveDataStorage.Reset(new SaveDataSharedFileStorage(in baseFileStorage, type.ValueRo)); return Result.Success; } - public Result Register(ref SharedRef storage, SaveDataSpaceId spaceId, + public Result Register(ref readonly SharedRef storage, SaveDataSpaceId spaceId, ulong saveDataId) { Assert.SdkRequires(Globals.Mutex.IsLockedByCurrentThread()); - _entryList.AddLast(new Entry(ref storage, spaceId, saveDataId)); + _entryList.AddLast(new Entry(in storage, spaceId, saveDataId)); return Result.Success; } diff --git a/src/LibHac/FsSrv/Storage/GameCardService.cs b/src/LibHac/FsSrv/Storage/GameCardService.cs index 7173eaf9..700c0c13 100644 --- a/src/LibHac/FsSrv/Storage/GameCardService.cs +++ b/src/LibHac/FsSrv/Storage/GameCardService.cs @@ -137,7 +137,7 @@ internal static class GameCardService using var storage = new SharedRef(new StorageServiceObjectAdapter(ref gameCardStorageDevice.Ref)); using var deviceEventSimulationStorage = new SharedRef( - new DeviceEventSimulationStorage(ref storage.Ref, service.FsSrv.Impl.GetGameCardEventSimulator())); + new DeviceEventSimulationStorage(in storage, service.FsSrv.Impl.GetGameCardEventSimulator())); outStorage.SetByMove(ref deviceEventSimulationStorage.Ref); diff --git a/src/LibHac/FsSrv/Storage/MmcService.cs b/src/LibHac/FsSrv/Storage/MmcService.cs index e51c8408..c1bb4b83 100644 --- a/src/LibHac/FsSrv/Storage/MmcService.cs +++ b/src/LibHac/FsSrv/Storage/MmcService.cs @@ -105,12 +105,12 @@ internal static class MmcService res = storageDeviceManager.Get.OpenStorage(ref mmcStorage.Ref, attribute); if (res.IsFailure()) return res.Miss(); - using var storage = new SharedRef(new StorageServiceObjectAdapter(ref mmcStorage.Ref)); + using var storage = new SharedRef(new StorageServiceObjectAdapter(in mmcStorage)); if (IsSpeedEmulationNeeded(partition)) { using var emulationStorage = - new SharedRef(new SpeedEmulationStorage(ref storage.Ref, service.FsSrv)); + new SharedRef(new SpeedEmulationStorage(in storage, service.FsSrv)); outStorage.SetByMove(ref emulationStorage.Ref); return Result.Success; diff --git a/src/LibHac/FsSrv/Storage/SdCardService.cs b/src/LibHac/FsSrv/Storage/SdCardService.cs index bb0019d5..c2c7563d 100644 --- a/src/LibHac/FsSrv/Storage/SdCardService.cs +++ b/src/LibHac/FsSrv/Storage/SdCardService.cs @@ -62,14 +62,14 @@ internal static class SdCardService res = storageDeviceManager.Get.OpenStorage(ref sdCardStorage.Ref, 0); if (res.IsFailure()) return res.Miss(); - using var storage = new SharedRef(new StorageServiceObjectAdapter(ref sdCardStorage.Ref)); + using var storage = new SharedRef(new StorageServiceObjectAdapter(in sdCardStorage)); SdCardEventSimulator eventSimulator = service.FsSrv.Impl.GetSdCardEventSimulator(); using var deviceEventSimulationStorage = - new SharedRef(new DeviceEventSimulationStorage(ref storage.Ref, eventSimulator)); + new SharedRef(new DeviceEventSimulationStorage(in storage, eventSimulator)); using var emulationStorage = new SharedRef( - new SpeedEmulationStorage(ref deviceEventSimulationStorage.Ref, service.FsSrv)); + new SpeedEmulationStorage(in deviceEventSimulationStorage, service.FsSrv)); outStorage.SetByMove(ref emulationStorage.Ref); return Result.Success; diff --git a/src/LibHac/FsSystem/IAesCtrDecryptor.cs b/src/LibHac/FsSystem/IAesCtrDecryptor.cs index b1a1709a..26e44210 100644 --- a/src/LibHac/FsSystem/IAesCtrDecryptor.cs +++ b/src/LibHac/FsSystem/IAesCtrDecryptor.cs @@ -1,6 +1,5 @@ using System; using LibHac.Fs; -using LibHac.Spl; namespace LibHac.FsSystem; diff --git a/src/LibHac/FsSystem/StorageLayoutTypeSetter.cs b/src/LibHac/FsSystem/StorageLayoutTypeSetter.cs index 8f74725d..cfa22b77 100644 --- a/src/LibHac/FsSystem/StorageLayoutTypeSetter.cs +++ b/src/LibHac/FsSystem/StorageLayoutTypeSetter.cs @@ -51,9 +51,9 @@ internal class StorageLayoutTypeSetStorage : IStorage private SharedRef _baseStorage; private StorageLayoutType _storageFlag; - public StorageLayoutTypeSetStorage(ref SharedRef baseStorage, StorageLayoutType storageFlag) + public StorageLayoutTypeSetStorage(ref readonly SharedRef baseStorage, StorageLayoutType storageFlag) { - _baseStorage = SharedRef.CreateMove(ref baseStorage); + _baseStorage = SharedRef.CreateCopy(in baseStorage); _storageFlag = storageFlag; Assert.SdkAssert(StorageLayoutTypeFunctions.IsStorageFlagValid(storageFlag)); diff --git a/src/LibHac/GcSrv/GameCardDeviceOperator.cs b/src/LibHac/GcSrv/GameCardDeviceOperator.cs index 05489649..594a8a80 100644 --- a/src/LibHac/GcSrv/GameCardDeviceOperator.cs +++ b/src/LibHac/GcSrv/GameCardDeviceOperator.cs @@ -27,9 +27,9 @@ internal class GameCardDeviceOperator : IStorageDeviceOperator return (uint)((ulong)byteCount / GcPageSize); } - public GameCardDeviceOperator(ref SharedRef storageDevice, IGcApi gc) + public GameCardDeviceOperator(ref readonly SharedRef storageDevice, IGcApi gc) { - _storageDevice = SharedRef.CreateMove(ref storageDevice); + _storageDevice = SharedRef.CreateCopy(in storageDevice); _gc = gc; } diff --git a/src/LibHac/GcSrv/GameCardManager.cs b/src/LibHac/GcSrv/GameCardManager.cs index 909c6e5c..94698aa9 100644 --- a/src/LibHac/GcSrv/GameCardManager.cs +++ b/src/LibHac/GcSrv/GameCardManager.cs @@ -559,14 +559,14 @@ public class GameCardManager : IStorageDeviceManager, IStorageDeviceOperator, IG { using SharedRef manager = SharedRef.Create(in _selfReference); - return new ReadOnlyGameCardStorage(ref manager.Ref, _gc); + return new ReadOnlyGameCardStorage(in manager, _gc); } private WriteOnlyGameCardStorage MakeWriteOnlyGameCardStorage() { using SharedRef manager = SharedRef.Create(in _selfReference); - return new WriteOnlyGameCardStorage(ref manager.Ref, _gc); + return new WriteOnlyGameCardStorage(in manager, _gc); } private SharedRef CreateStorageDeviceNonSecure(ref readonly SharedRef baseStorage, @@ -575,7 +575,7 @@ public class GameCardManager : IStorageDeviceManager, IStorageDeviceOperator, IG using SharedRef manager = SharedRef.Create(in _selfReference); using SharedRef storageDevice = - GameCardStorageDevice.CreateShared(_gc, ref manager.Ref, in baseStorage, handle); + GameCardStorageDevice.CreateShared(_gc, in manager, in baseStorage, handle); return SharedRef.CreateMove(ref storageDevice.Ref); } @@ -586,7 +586,7 @@ public class GameCardManager : IStorageDeviceManager, IStorageDeviceOperator, IG using SharedRef manager = SharedRef.Create(in _selfReference); using SharedRef storageDevice = GameCardStorageDevice.CreateShared( - _gc, ref manager.Ref, in baseStorage, handle, isSecure: true, cardDeviceId, cardImageHash); + _gc, in manager, in baseStorage, handle, isSecure: true, cardDeviceId, cardImageHash); return SharedRef.CreateMove(ref storageDevice.Ref); } diff --git a/src/LibHac/GcSrv/GameCardStorageDevice.cs b/src/LibHac/GcSrv/GameCardStorageDevice.cs index d15ac7a1..db5f7147 100644 --- a/src/LibHac/GcSrv/GameCardStorageDevice.cs +++ b/src/LibHac/GcSrv/GameCardStorageDevice.cs @@ -145,7 +145,7 @@ internal class GameCardStorageDevice : GameCardStorageInterfaceAdapter, IStorage SharedRef.Create(in _selfReference); using var deviceOperator = - new SharedRef(new GameCardDeviceOperator(ref storageDevice.Ref, _gc)); + new SharedRef(new GameCardDeviceOperator(in storageDevice, _gc)); if (!deviceOperator.HasValue) return ResultFs.AllocationMemoryFailedInGameCardManagerG.Log(); diff --git a/src/LibHac/SdmmcSrv/MmcManager.cs b/src/LibHac/SdmmcSrv/MmcManager.cs index 12c1f0d6..77d6ecfe 100644 --- a/src/LibHac/SdmmcSrv/MmcManager.cs +++ b/src/LibHac/SdmmcSrv/MmcManager.cs @@ -211,7 +211,7 @@ internal class MmcManager : IStorageDeviceManager, IStorageDeviceOperator, ISdmm using SharedRef manager = SharedRef.Create(in _selfReference); using SharedRef storageDevice = - MmcUserDataPartitionStorageDevice.CreateShared(ref manager.Ref, MmcHandle, _sdmmc); + MmcUserDataPartitionStorageDevice.CreateShared(in manager, MmcHandle, _sdmmc); outStorageDevice.SetByMove(ref storageDevice.Ref); } @@ -221,7 +221,7 @@ internal class MmcManager : IStorageDeviceManager, IStorageDeviceOperator, ISdmm using SharedRef manager = SharedRef.Create(in _selfReference); using SharedRef storageDevice = - MmcBootPartitionStorageDevice.CreateShared(partition, ref manager.Ref, MmcHandle, _sdmmc); + MmcBootPartitionStorageDevice.CreateShared(partition, in manager, MmcHandle, _sdmmc); outStorageDevice.SetByMove(ref storageDevice.Ref); } diff --git a/src/LibHac/SdmmcSrv/MmcPartitionStorageDevice.cs b/src/LibHac/SdmmcSrv/MmcPartitionStorageDevice.cs index 24ec93ab..c24ebbf4 100644 --- a/src/LibHac/SdmmcSrv/MmcPartitionStorageDevice.cs +++ b/src/LibHac/SdmmcSrv/MmcPartitionStorageDevice.cs @@ -60,8 +60,7 @@ internal abstract class MmcPartitionStorageDevice : IDisposable using SharedRef storageDevice = SharedRef.Create(in SelfReference); - using var deviceOperator = - new SharedRef(new MmcDeviceOperator(ref storageDevice.Ref, Sdmmc)); + using var deviceOperator = new SharedRef(new MmcDeviceOperator(in storageDevice, Sdmmc)); if (!deviceOperator.HasValue) return ResultFs.AllocationMemoryFailedInSdmmcStorageServiceA.Log(); diff --git a/src/LibHac/SdmmcSrv/SdCardManager.cs b/src/LibHac/SdmmcSrv/SdCardManager.cs index 5013a2e4..fd2ff3eb 100644 --- a/src/LibHac/SdmmcSrv/SdCardManager.cs +++ b/src/LibHac/SdmmcSrv/SdCardManager.cs @@ -183,9 +183,7 @@ public class SdCardManager : IStorageDeviceManager, IStorageDeviceOperator, ISdm if (res.IsFailure()) return res.Miss(); using SharedRef manager = SharedRef.Create(in _selfReference); - - using SharedRef - storageDevice = SdCardStorageDevice.CreateShared(ref manager.Ref, handle, _sdmmc); + using SharedRef storageDevice = SdCardStorageDevice.CreateShared(in manager, handle, _sdmmc); if (!storageDevice.HasValue) return ResultFs.AllocationMemoryFailedInSdmmcStorageServiceA.Log(); diff --git a/src/LibHac/SdmmcSrv/SdCardStorageDevice.cs b/src/LibHac/SdmmcSrv/SdCardStorageDevice.cs index 35a5d86b..eee03816 100644 --- a/src/LibHac/SdmmcSrv/SdCardStorageDevice.cs +++ b/src/LibHac/SdmmcSrv/SdCardStorageDevice.cs @@ -73,7 +73,7 @@ internal class SdCardStorageDevice : SdmmcStorageInterfaceAdapter, IStorageDevic using SharedRef storageDevice = SharedRef.Create(in _selfReference); using var deviceOperator = - new SharedRef(new SdCardDeviceOperator(ref storageDevice.Ref, _sdmmc)); + new SharedRef(new SdCardDeviceOperator(in storageDevice, _sdmmc)); if (!deviceOperator.HasValue) return ResultFs.AllocationMemoryFailedInSdmmcStorageServiceA.Log(); diff --git a/tests/LibHac.Tests/Fs/StorageTester.cs b/tests/LibHac.Tests/Fs/StorageTester.cs index 5bee09bd..29c21652 100644 --- a/tests/LibHac.Tests/Fs/StorageTester.cs +++ b/tests/LibHac.Tests/Fs/StorageTester.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.IO; using System.Linq; using LibHac.Fs; diff --git a/tests/LibHac.Tests/FsSystem/ReadOnlyBlockCacheStorageTests.cs b/tests/LibHac.Tests/FsSystem/ReadOnlyBlockCacheStorageTests.cs index 5522e90d..31c91d6c 100644 --- a/tests/LibHac.Tests/FsSystem/ReadOnlyBlockCacheStorageTests.cs +++ b/tests/LibHac.Tests/FsSystem/ReadOnlyBlockCacheStorageTests.cs @@ -38,7 +38,7 @@ public class ReadOnlyBlockCacheStorageTests } using var baseStorage = new SharedRef(new MemoryStorage(BaseData)); - CacheStorage = new ReadOnlyBlockCacheStorage(ref baseStorage.Ref, _blockSize, CacheBuffer, _cacheBlockCount); + CacheStorage = new ReadOnlyBlockCacheStorage(in baseStorage, _blockSize, CacheBuffer, _cacheBlockCount); } public Span GetBaseDataBlock(int index) => BaseData.AsSpan(_blockSize * index, _blockSize);