Use ref readonly for many incoming SharedRef parameters

This commit is contained in:
Alex Barney 2024-05-05 23:08:53 -07:00
parent e19ea92b90
commit 6a5d03e1f3
66 changed files with 206 additions and 209 deletions

View File

@ -8,9 +8,9 @@ internal class BcatServiceObject : IServiceObject
{ {
private SharedRef<IServiceCreator> _serviceCreator; private SharedRef<IServiceCreator> _serviceCreator;
public BcatServiceObject(ref SharedRef<IServiceCreator> serviceCreator) public BcatServiceObject(ref readonly SharedRef<IServiceCreator> serviceCreator)
{ {
_serviceCreator = SharedRef<IServiceCreator>.CreateMove(ref serviceCreator); _serviceCreator = SharedRef<IServiceCreator>.CreateCopy(in serviceCreator);
} }
public void Dispose() public void Dispose()
@ -18,9 +18,9 @@ internal class BcatServiceObject : IServiceObject
_serviceCreator.Destroy(); _serviceCreator.Destroy();
} }
public Result GetServiceObject(ref SharedRef<IDisposable> serviceObject) public Result GetServiceObject(ref SharedRef<IDisposable> outServiceObject)
{ {
serviceObject.SetByCopy(in _serviceCreator); outServiceObject.SetByCopy(in _serviceCreator);
return Result.Success; return Result.Success;
} }
} }

View File

@ -25,28 +25,28 @@ internal class DeliveryCacheStorageService : IDeliveryCacheStorageService
Access = accessControl; Access = accessControl;
} }
public Result CreateFileService(ref SharedRef<IDeliveryCacheFileService> service) public Result CreateFileService(ref SharedRef<IDeliveryCacheFileService> outService)
{ {
lock (Locker) lock (Locker)
{ {
if (FileServiceOpenCount >= MaxOpenCount) if (FileServiceOpenCount >= MaxOpenCount)
return ResultBcat.ServiceOpenLimitReached.Log(); return ResultBcat.ServiceOpenLimitReached.Log();
service.Reset(new DeliveryCacheFileService(Server, this, ApplicationId, Access)); outService.Reset(new DeliveryCacheFileService(Server, this, ApplicationId, Access));
FileServiceOpenCount++; FileServiceOpenCount++;
return Result.Success; return Result.Success;
} }
} }
public Result CreateDirectoryService(ref SharedRef<IDeliveryCacheDirectoryService> service) public Result CreateDirectoryService(ref SharedRef<IDeliveryCacheDirectoryService> outService)
{ {
lock (Locker) lock (Locker)
{ {
if (DirectoryServiceOpenCount >= MaxOpenCount) if (DirectoryServiceOpenCount >= MaxOpenCount)
return ResultBcat.ServiceOpenLimitReached.Log(); return ResultBcat.ServiceOpenLimitReached.Log();
service.Reset(new DeliveryCacheDirectoryService(Server, this, ApplicationId, Access)); outService.Reset(new DeliveryCacheDirectoryService(Server, this, ApplicationId, Access));
DirectoryServiceOpenCount++; DirectoryServiceOpenCount++;
return Result.Success; return Result.Success;

View File

@ -31,10 +31,10 @@ public class FileStorage : IStorage
_fileSize = InvalidSize; _fileSize = InvalidSize;
} }
public FileStorage(ref SharedRef<IFile> baseFile) public FileStorage(ref readonly SharedRef<IFile> baseFile)
{ {
_baseFile = baseFile.Get; _baseFile = baseFile.Get;
_baseFileShared = SharedRef<IFile>.CreateMove(ref baseFile); _baseFileShared = SharedRef<IFile>.CreateCopy(in baseFile);
_fileSize = InvalidSize; _fileSize = InvalidSize;
} }

View File

@ -661,7 +661,7 @@ public static class UserFileSystem
if (!fileSystem.HasValue) if (!fileSystem.HasValue)
return ResultFs.UnsupportedCommitTarget.Log(); return ResultFs.UnsupportedCommitTarget.Log();
res = commitManager.Get.Add(ref fileSystem.Ref); res = commitManager.Get.Add(fileSystem.Ref);
if (res.IsFailure()) return res.Miss(); if (res.IsFailure()) return res.Miss();
} }

View File

@ -16,14 +16,14 @@ internal class StorageServiceObjectAdapter : IStorage
{ {
private SharedRef<IStorageSf> _baseStorage; private SharedRef<IStorageSf> _baseStorage;
public StorageServiceObjectAdapter(ref SharedRef<IStorageSf> baseStorage) public StorageServiceObjectAdapter(ref readonly SharedRef<IStorageSf> baseStorage)
{ {
_baseStorage = SharedRef<IStorageSf>.CreateMove(ref baseStorage); _baseStorage = SharedRef<IStorageSf>.CreateCopy(in baseStorage);
} }
public StorageServiceObjectAdapter(ref SharedRef<IStorageDevice> baseStorage) public StorageServiceObjectAdapter(ref readonly SharedRef<IStorageDevice> baseStorage)
{ {
_baseStorage = SharedRef<IStorageSf>.CreateMove(ref baseStorage); _baseStorage = SharedRef<IStorageSf>.CreateCopy(in baseStorage);
} }
public override void Dispose() public override void Dispose()

View File

@ -28,7 +28,7 @@ public static class BaseFileSystem
ref SharedRef<IFileSystemSf> fileSystem) ref SharedRef<IFileSystemSf> fileSystem)
{ {
using var fileSystemAdapter = using var fileSystemAdapter =
new UniqueRef<IFileSystem>(new FileSystemServiceObjectAdapter(ref fileSystem.Ref)); new UniqueRef<IFileSystem>(new FileSystemServiceObjectAdapter(in fileSystem));
Result res = fs.Register(mountName, ref fileSystemAdapter.Ref); Result res = fs.Register(mountName, ref fileSystemAdapter.Ref);
if (res.IsFailure()) return res.Miss(); if (res.IsFailure()) return res.Miss();

View File

@ -140,8 +140,8 @@ public static class FileSystemProxyServiceObject
/// <param name="fs">The <see cref="FileSystemClient"/> to use.</param> /// <param name="fs">The <see cref="FileSystemClient"/> to use.</param>
/// <param name="serviceObject">The service object this <see cref="FileSystemClient"/> will use.</param> /// <param name="serviceObject">The service object this <see cref="FileSystemClient"/> will use.</param>
public static void InitializeDfcFileSystemProxyServiceObject(this FileSystemClientImpl fs, public static void InitializeDfcFileSystemProxyServiceObject(this FileSystemClientImpl fs,
ref SharedRef<IFileSystemProxy> serviceObject) ref readonly SharedRef<IFileSystemProxy> serviceObject)
{ {
fs.Globals.FileSystemProxyServiceObject.DfcFileSystemProxyServiceObject.SetByMove(ref serviceObject); fs.Globals.FileSystemProxyServiceObject.DfcFileSystemProxyServiceObject.SetByCopy(in serviceObject);
} }
} }

View File

@ -25,9 +25,9 @@ internal class FileServiceObjectAdapter : IFile
{ {
private SharedRef<IFileSf> _baseFile; private SharedRef<IFileSf> _baseFile;
public FileServiceObjectAdapter(ref SharedRef<IFileSf> baseFile) public FileServiceObjectAdapter(ref readonly SharedRef<IFileSf> baseFile)
{ {
_baseFile = SharedRef<IFileSf>.CreateMove(ref baseFile); _baseFile = SharedRef<IFileSf>.CreateCopy(in baseFile);
} }
public override void Dispose() public override void Dispose()
@ -91,9 +91,9 @@ internal class DirectoryServiceObjectAdapter : IDirectory
{ {
private SharedRef<IDirectorySf> _baseDirectory; private SharedRef<IDirectorySf> _baseDirectory;
public DirectoryServiceObjectAdapter(ref SharedRef<IDirectorySf> baseDirectory) public DirectoryServiceObjectAdapter(ref readonly SharedRef<IDirectorySf> baseDirectory)
{ {
_baseDirectory = SharedRef<IDirectorySf>.CreateMove(ref baseDirectory); _baseDirectory = SharedRef<IDirectorySf>.CreateCopy(in baseDirectory);
} }
public override void Dispose() public override void Dispose()
@ -136,9 +136,9 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget
return Result.Success; return Result.Success;
} }
public FileSystemServiceObjectAdapter(ref SharedRef<IFileSystemSf> baseFileSystem) public FileSystemServiceObjectAdapter(ref readonly SharedRef<IFileSystemSf> baseFileSystem)
{ {
_baseFs = SharedRef<IFileSystemSf>.CreateMove(ref baseFileSystem); _baseFs = SharedRef<IFileSystemSf>.CreateCopy(in baseFileSystem);
} }
public override void Dispose() public override void Dispose()

View File

@ -26,9 +26,9 @@ namespace LibHac.Fs
private readonly FileSystemClient _fsClient; private readonly FileSystemClient _fsClient;
private SharedRef<ISaveDataInfoReader> _reader; private SharedRef<ISaveDataInfoReader> _reader;
internal SaveDataIterator(FileSystemClient fsClient, ref SharedRef<ISaveDataInfoReader> reader) internal SaveDataIterator(FileSystemClient fsClient, ref readonly SharedRef<ISaveDataInfoReader> reader)
{ {
_reader = SharedRef<ISaveDataInfoReader>.CreateMove(ref reader); _reader = SharedRef<ISaveDataInfoReader>.CreateCopy(in reader);
_fsClient = fsClient; _fsClient = fsClient;
} }

View File

@ -20,9 +20,9 @@ public class SaveDataChunkIterator : ISaveDataChunkIterator
// LibHac addition // LibHac addition
private FileSystemClient _fsClient; private FileSystemClient _fsClient;
public SaveDataChunkIterator(FileSystemClient fs, ref SharedRef<FsSrv.Sf.ISaveDataChunkIterator> baseInterface) public SaveDataChunkIterator(FileSystemClient fs, ref readonly SharedRef<FsSrv.Sf.ISaveDataChunkIterator> baseInterface)
{ {
_baseInterface = SharedRef<FsSrv.Sf.ISaveDataChunkIterator>.CreateMove(ref baseInterface); _baseInterface = SharedRef<FsSrv.Sf.ISaveDataChunkIterator>.CreateCopy(in baseInterface);
_fsClient = fs; _fsClient = fs;
} }
@ -69,9 +69,9 @@ public class SaveDataChunkExporter : ISaveDataChunkExporter
// LibHac addition // LibHac addition
private FileSystemClient _fsClient; private FileSystemClient _fsClient;
public SaveDataChunkExporter(FileSystemClient fs, ref SharedRef<FsSrv.Sf.ISaveDataChunkExporter> baseInterface) public SaveDataChunkExporter(FileSystemClient fs, ref readonly SharedRef<FsSrv.Sf.ISaveDataChunkExporter> baseInterface)
{ {
_baseInterface = SharedRef<FsSrv.Sf.ISaveDataChunkExporter>.CreateMove(ref baseInterface); _baseInterface = SharedRef<FsSrv.Sf.ISaveDataChunkExporter>.CreateCopy(in baseInterface);
_fsClient = fs; _fsClient = fs;
} }
@ -116,9 +116,9 @@ public class SaveDataChunkImporter : ISaveDataChunkImporter
// LibHac addition // LibHac addition
private FileSystemClient _fsClient; private FileSystemClient _fsClient;
public SaveDataChunkImporter(FileSystemClient fs, ref SharedRef<FsSrv.Sf.ISaveDataChunkImporter> baseInterface) public SaveDataChunkImporter(FileSystemClient fs, ref readonly SharedRef<FsSrv.Sf.ISaveDataChunkImporter> baseInterface)
{ {
_baseInterface = SharedRef<FsSrv.Sf.ISaveDataChunkImporter>.CreateMove(ref baseInterface); _baseInterface = SharedRef<FsSrv.Sf.ISaveDataChunkImporter>.CreateCopy(in baseInterface);
_fsClient = fs; _fsClient = fs;
} }
@ -150,9 +150,9 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter
private FileSystemClient _fsClient; private FileSystemClient _fsClient;
public SaveDataExporterVersion2(FileSystemClient fs, public SaveDataExporterVersion2(FileSystemClient fs,
ref SharedRef<FsSrv.Sf.ISaveDataDivisionExporter> baseInterface) ref readonly SharedRef<FsSrv.Sf.ISaveDataDivisionExporter> baseInterface)
{ {
_baseInterface = SharedRef<FsSrv.Sf.ISaveDataDivisionExporter>.CreateMove(ref baseInterface); _baseInterface = SharedRef<FsSrv.Sf.ISaveDataDivisionExporter>.CreateCopy(in baseInterface);
_fsClient = fs; _fsClient = fs;
} }
@ -329,9 +329,9 @@ public class SaveDataImporterVersion2 : ISaveDataDivisionImporter
private FileSystemClient _fsClient; private FileSystemClient _fsClient;
public SaveDataImporterVersion2(FileSystemClient fs, public SaveDataImporterVersion2(FileSystemClient fs,
ref SharedRef<FsSrv.Sf.ISaveDataDivisionImporter> baseInterface) ref readonly SharedRef<FsSrv.Sf.ISaveDataDivisionImporter> baseInterface)
{ {
_baseInterface = SharedRef<FsSrv.Sf.ISaveDataDivisionImporter>.CreateMove(ref baseInterface); _baseInterface = SharedRef<FsSrv.Sf.ISaveDataDivisionImporter>.CreateCopy(in baseInterface);
_fsClient = fs; _fsClient = fs;
} }

View File

@ -266,9 +266,9 @@ namespace LibHac.Fs
{ {
private SharedRef<ISaveDataTransferProhibiter> _prohibiter; private SharedRef<ISaveDataTransferProhibiter> _prohibiter;
public SaveDataTransferProhibiterForCloudBackUp(ref SharedRef<ISaveDataTransferProhibiter> prohibiter) public SaveDataTransferProhibiterForCloudBackUp(ref readonly SharedRef<ISaveDataTransferProhibiter> prohibiter)
{ {
_prohibiter = SharedRef<ISaveDataTransferProhibiter>.CreateMove(ref prohibiter); _prohibiter = SharedRef<ISaveDataTransferProhibiter>.CreateCopy(in prohibiter);
} }
public void Dispose() public void Dispose()

View File

@ -54,10 +54,10 @@ public static class SdCard
} }
private static Result RegisterFileSystem(FileSystemClient fs, U8Span mountName, private static Result RegisterFileSystem(FileSystemClient fs, U8Span mountName,
ref SharedRef<IFileSystemSf> fileSystem) ref readonly SharedRef<IFileSystemSf> fileSystem)
{ {
using var fileSystemAdapter = using var fileSystemAdapter =
new UniqueRef<IFileSystem>(new FileSystemServiceObjectAdapter(ref fileSystem)); new UniqueRef<IFileSystem>(new FileSystemServiceObjectAdapter(in fileSystem));
if (!fileSystemAdapter.HasValue) if (!fileSystemAdapter.HasValue)
return ResultFs.AllocationMemoryFailedInSdCardA.Log(); return ResultFs.AllocationMemoryFailedInSdCardA.Log();
@ -214,7 +214,7 @@ public static class SdCard
return isInserted; return isInserted;
static Result CheckIfInserted(FileSystemClient fs, ref SharedRef<IDeviceOperator> deviceOperator, static Result CheckIfInserted(FileSystemClient fs, ref readonly SharedRef<IDeviceOperator> deviceOperator,
out bool isInserted) out bool isInserted)
{ {
UnsafeHelpers.SkipParamInit(out isInserted); UnsafeHelpers.SkipParamInit(out isInserted);

View File

@ -262,8 +262,7 @@ public readonly struct BaseFileSystemService
return Result.Success; return Result.Success;
} }
public Result OpenImageDirectoryFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, public Result OpenImageDirectoryFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, ImageDirectoryId directoryId)
ImageDirectoryId directoryId)
{ {
// Caller must have the MountImageAndVideoStorage permission // Caller must have the MountImageAndVideoStorage permission
Result res = GetProgramInfo(out ProgramInfo programInfo); Result res = GetProgramInfo(out ProgramInfo programInfo);

View File

@ -180,13 +180,13 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader
return ncaFsService.OpenFileSystemWithPatch(ref outFileSystem, programId, fsType).Ret(); return ncaFsService.OpenFileSystemWithPatch(ref outFileSystem, programId, fsType).Ret();
} }
public Result OpenCodeFileSystem(ref SharedRef<IFileSystemSf> fileSystem, OutBuffer outVerificationData, public Result OpenCodeFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, OutBuffer outVerificationData,
ref readonly FspPath path, ContentAttributes attributes, ProgramId programId) ref readonly FspPath path, ContentAttributes attributes, ProgramId programId)
{ {
Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService);
if (res.IsFailure()) return res.Miss(); 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) public Result SetCurrentProcess(ulong processId)

View File

@ -210,10 +210,10 @@ public static class FileSystemServerInitializer
_server = server; _server = server;
} }
public Result GetServiceObject(ref SharedRef<IDisposable> serviceObject) public Result GetServiceObject(ref SharedRef<IDisposable> outServiceObject)
{ {
using SharedRef<IFileSystemProxy> derivedObject = _server.Impl.GetFileSystemProxyServiceObject(); using SharedRef<IFileSystemProxy> derivedObject = _server.Impl.GetFileSystemProxyServiceObject();
serviceObject.SetByMove(ref derivedObject.Ref); outServiceObject.SetByMove(ref derivedObject.Ref);
return Result.Success; return Result.Success;
} }
@ -229,10 +229,10 @@ public static class FileSystemServerInitializer
_server = server; _server = server;
} }
public Result GetServiceObject(ref SharedRef<IDisposable> serviceObject) public Result GetServiceObject(ref SharedRef<IDisposable> outServiceObject)
{ {
using SharedRef<IFileSystemProxyForLoader> derivedObject = _server.Impl.GetFileSystemProxyForLoaderServiceObject(); using SharedRef<IFileSystemProxyForLoader> derivedObject = _server.Impl.GetFileSystemProxyForLoaderServiceObject();
serviceObject.SetByMove(ref derivedObject.Ref); outServiceObject.SetByMove(ref derivedObject.Ref);
return Result.Success; return Result.Success;
} }
@ -248,10 +248,10 @@ public static class FileSystemServerInitializer
_server = server; _server = server;
} }
public Result GetServiceObject(ref SharedRef<IDisposable> serviceObject) public Result GetServiceObject(ref SharedRef<IDisposable> outServiceObject)
{ {
using SharedRef<IProgramRegistry> derivedObject = _server.Impl.GetProgramRegistryServiceObject(); using SharedRef<IProgramRegistry> derivedObject = _server.Impl.GetProgramRegistryServiceObject();
serviceObject.SetByMove(ref derivedObject.Ref); outServiceObject.SetByMove(ref derivedObject.Ref);
return Result.Success; return Result.Success;
} }

View File

@ -39,10 +39,10 @@ public class EmulatedBisFileSystemCreator : IBuiltInStorageFileSystemCreator
/// Each partition will be located at their default paths in this IFileSystem. /// Each partition will be located at their default paths in this IFileSystem.
/// </summary> /// </summary>
/// <param name="rootFileSystem">The <see cref="IFileSystem"/> to use as the root file system.</param> /// <param name="rootFileSystem">The <see cref="IFileSystem"/> to use as the root file system.</param>
public EmulatedBisFileSystemCreator(ref SharedRef<IFileSystem> rootFileSystem) public EmulatedBisFileSystemCreator(ref readonly SharedRef<IFileSystem> rootFileSystem)
{ {
Config = new EmulatedBisFileSystemCreatorConfig(); Config = new EmulatedBisFileSystemCreatorConfig();
Config.SetRootFileSystem(ref rootFileSystem).ThrowIfFailure(); Config.SetRootFileSystem(in rootFileSystem).ThrowIfFailure();
} }
/// <summary> /// <summary>

View File

@ -18,12 +18,12 @@ public class EmulatedBisFileSystemCreatorConfig
private SharedRef<IFileSystem>[] PartitionFileSystems { get; } = new SharedRef<IFileSystem>[ValidPartitionCount]; private SharedRef<IFileSystem>[] PartitionFileSystems { get; } = new SharedRef<IFileSystem>[ValidPartitionCount];
private string[] PartitionPaths { get; } = new string[ValidPartitionCount]; private string[] PartitionPaths { get; } = new string[ValidPartitionCount];
public Result SetRootFileSystem(ref SharedRef<IFileSystem> fileSystem) public Result SetRootFileSystem(ref readonly SharedRef<IFileSystem> fileSystem)
{ {
if (!fileSystem.HasValue) return ResultFs.NullptrArgument.Log(); if (!fileSystem.HasValue) return ResultFs.NullptrArgument.Log();
if (_rootFileSystem.HasValue) return ResultFs.PreconditionViolation.Log(); if (_rootFileSystem.HasValue) return ResultFs.PreconditionViolation.Log();
_rootFileSystem.SetByMove(ref fileSystem); _rootFileSystem.SetByCopy(in fileSystem);
return Result.Success; return Result.Success;
} }

View File

@ -17,16 +17,16 @@ public class EmulatedSdCardFileSystemCreator : ISdCardProxyFileSystemCreator, ID
private SharedRef<IFileSystem> _sdCardFileSystem; private SharedRef<IFileSystem> _sdCardFileSystem;
private string _path; private string _path;
public EmulatedSdCardFileSystemCreator(SdmmcApi sdmmc, ref SharedRef<IFileSystem> rootFileSystem) public EmulatedSdCardFileSystemCreator(SdmmcApi sdmmc, ref readonly SharedRef<IFileSystem> rootFileSystem)
{ {
_sdmmc = sdmmc; _sdmmc = sdmmc;
_rootFileSystem = SharedRef<IFileSystem>.CreateMove(ref rootFileSystem); _rootFileSystem = SharedRef<IFileSystem>.CreateCopy(in rootFileSystem);
} }
public EmulatedSdCardFileSystemCreator(SdmmcApi sdmmc, ref SharedRef<IFileSystem> rootFileSystem, string path) public EmulatedSdCardFileSystemCreator(SdmmcApi sdmmc, ref readonly SharedRef<IFileSystem> rootFileSystem, string path)
{ {
_sdmmc = sdmmc; _sdmmc = sdmmc;
_rootFileSystem = SharedRef<IFileSystem>.CreateMove(ref rootFileSystem); _rootFileSystem = SharedRef<IFileSystem>.CreateCopy(in rootFileSystem);
_path = path; _path = path;
} }

View File

@ -31,13 +31,13 @@ public class FatFileSystemCreator : IFatFileSystemCreator
// Missing: Call nn::fat::SetMemoryResource // Missing: Call nn::fat::SetMemoryResource
} }
public Result Create(ref SharedRef<IFileSystem> outFileSystem, ref SharedRef<IStorage> baseStorage, public Result Create(ref SharedRef<IFileSystem> outFileSystem, ref readonly SharedRef<IStorage> baseStorage,
FatAttribute attribute, int driveId, Result invalidFatFormatResult, Result usableSpaceNotEnoughResult) FatAttribute attribute, int driveId, Result invalidFatFormatResult, Result usableSpaceNotEnoughResult)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
public Result Format(ref SharedRef<IStorage> partitionStorage, FatAttribute attribute, FatFormatParam formatParam, public Result Format(ref readonly SharedRef<IStorage> partitionStorage, FatAttribute attribute, FatFormatParam formatParam,
int driveId, Result invalidFatFormatResult, Result usableSpaceNotEnoughResult) int driveId, Result invalidFatFormatResult, Result usableSpaceNotEnoughResult)
{ {
throw new NotImplementedException(); throw new NotImplementedException();

View File

@ -38,12 +38,12 @@ public class GameCardRootPartition : IDisposable
// LibHac addition so we can access fssrv::storage functions // LibHac addition so we can access fssrv::storage functions
private readonly FileSystemServer _fsServer; private readonly FileSystemServer _fsServer;
public GameCardRootPartition(GameCardHandle handle, ref SharedRef<IStorage> rootStorage, public GameCardRootPartition(GameCardHandle handle, ref readonly SharedRef<IStorage> rootStorage,
IGameCardStorageCreator storageCreator, ref UniqueRef<Sha256PartitionFileSystemMeta> partitionFsMeta, IGameCardStorageCreator storageCreator, ref UniqueRef<Sha256PartitionFileSystemMeta> partitionFsMeta,
FileSystemServer fsServer) FileSystemServer fsServer)
{ {
_partitionFsMeta = new UniqueRef<Sha256PartitionFileSystemMeta>(ref partitionFsMeta); _partitionFsMeta = new UniqueRef<Sha256PartitionFileSystemMeta>(ref partitionFsMeta);
_alignedRootStorage = SharedRef<IStorage>.CreateMove(ref rootStorage); _alignedRootStorage = SharedRef<IStorage>.CreateCopy(in rootStorage);
_gcHandle = handle; _gcHandle = handle;
_gameCardStorageCreator = storageCreator; _gameCardStorageCreator = storageCreator;
_logoPartitionStorage = new SharedRef<IStorage>(); _logoPartitionStorage = new SharedRef<IStorage>();

View File

@ -7,9 +7,9 @@ namespace LibHac.FsSrv.FsCreator;
public interface IFatFileSystemCreator public interface IFatFileSystemCreator
{ {
Result Create(ref SharedRef<IFileSystem> outFileSystem, ref SharedRef<IStorage> baseStorage, Result Create(ref SharedRef<IFileSystem> outFileSystem, ref readonly SharedRef<IStorage> baseStorage,
FatAttribute attribute, int driveId, Result invalidFatFormatResult, Result usableSpaceNotEnoughResult); FatAttribute attribute, int driveId, Result invalidFatFormatResult, Result usableSpaceNotEnoughResult);
Result Format(ref SharedRef<IStorage> partitionStorage, FatAttribute attribute, FatFormatParam formatParam, Result Format(ref readonly SharedRef<IStorage> partitionStorage, FatAttribute attribute, FatFormatParam formatParam,
int driveId, Result invalidFatFormatResult, Result usableSpaceNotEnoughResult); int driveId, Result invalidFatFormatResult, Result usableSpaceNotEnoughResult);
} }

View File

@ -12,7 +12,7 @@ public interface ISaveDataFileSystemCreator : IDisposable
{ {
Result CreateRaw(ref SharedRef<IFile> outFile, ref readonly SharedRef<IFileSystem> fileSystem, ulong saveDataId, OpenMode openMode); Result CreateRaw(ref SharedRef<IFile> outFile, ref readonly SharedRef<IFileSystem> fileSystem, ulong saveDataId, OpenMode openMode);
Result Create(ref SharedRef<ISaveDataFileSystem> outFileSystem, ref SharedRef<IFileSystem> baseFileSystem, Result Create(ref SharedRef<ISaveDataFileSystem> outFileSystem, ref readonly SharedRef<IFileSystem> baseFileSystem,
SaveDataSpaceId spaceId, ulong saveDataId, bool allowDirectorySaveData, bool isDeviceUniqueMac, SaveDataSpaceId spaceId, ulong saveDataId, bool allowDirectorySaveData, bool isDeviceUniqueMac,
bool isJournalingSupported, bool isMultiCommitSupported, bool openReadOnly, bool openShared, bool isJournalingSupported, bool isMultiCommitSupported, bool openReadOnly, bool openShared,
ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible); ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible);

View File

@ -313,7 +313,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator
return Result.Success; return Result.Success;
} }
public Result Create(ref SharedRef<ISaveDataFileSystem> outFileSystem, ref SharedRef<IFileSystem> baseFileSystem, public Result Create(ref SharedRef<ISaveDataFileSystem> outFileSystem, ref readonly SharedRef<IFileSystem> baseFileSystem,
SaveDataSpaceId spaceId, ulong saveDataId, bool allowDirectorySaveData, bool isDeviceUniqueMac, SaveDataSpaceId spaceId, ulong saveDataId, bool allowDirectorySaveData, bool isDeviceUniqueMac,
bool isJournalingSupported, bool isMultiCommitSupported, bool openReadOnly, bool openShared, bool isJournalingSupported, bool isMultiCommitSupported, bool openReadOnly, bool openShared,
ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible) ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible)
@ -345,7 +345,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator
} }
// Get a file system over the save directory // Get a file system over the save directory
using var baseFs = new UniqueRef<SubdirectoryFileSystem>(new SubdirectoryFileSystem(ref baseFileSystem)); using var baseFs = new UniqueRef<SubdirectoryFileSystem>(new SubdirectoryFileSystem(in baseFileSystem));
if (!baseFs.HasValue) if (!baseFs.HasValue)
return ResultFs.AllocationMemoryFailedInSaveDataFileSystemCreatorA.Log(); return ResultFs.AllocationMemoryFailedInSaveDataFileSystemCreatorA.Log();
@ -374,7 +374,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator
Optional<OpenType> openType = Optional<OpenType> openType =
openShared ? new Optional<OpenType>(OpenType.Normal) : new Optional<OpenType>(); openShared ? new Optional<OpenType>(OpenType.Normal) : new Optional<OpenType>();
res = _fsServer.OpenSaveDataStorage(ref fileStorage.Ref, ref baseFileSystem, spaceId, saveDataId, res = _fsServer.OpenSaveDataStorage(ref fileStorage.Ref, in baseFileSystem, spaceId, saveDataId,
OpenMode.ReadWrite, openType); OpenMode.ReadWrite, openType);
if (res.IsFailure()) return res.Miss(); if (res.IsFailure()) return res.Miss();

View File

@ -7,8 +7,8 @@ namespace LibHac.FsSrv.Impl;
public class AsynchronousAccessFileSystem : ForwardingFileSystem public class AsynchronousAccessFileSystem : ForwardingFileSystem
{ {
public AsynchronousAccessFileSystem(ref SharedRef<IFileSystem> baseFileSystem) : base( public AsynchronousAccessFileSystem(ref readonly SharedRef<IFileSystem> baseFileSystem) : base(
ref baseFileSystem) in baseFileSystem)
{ } { }
// ReSharper disable once RedundantOverriddenMember // ReSharper disable once RedundantOverriddenMember

View File

@ -10,17 +10,17 @@ public class DeepRetryFileSystem : ForwardingFileSystem
private WeakRef<DeepRetryFileSystem> _selfReference; private WeakRef<DeepRetryFileSystem> _selfReference;
private SharedRef<IRomFileSystemAccessFailureManager> _accessFailureManager; private SharedRef<IRomFileSystemAccessFailureManager> _accessFailureManager;
protected DeepRetryFileSystem(ref SharedRef<IFileSystem> baseFileSystem, protected DeepRetryFileSystem(ref readonly SharedRef<IFileSystem> baseFileSystem,
ref SharedRef<IRomFileSystemAccessFailureManager> accessFailureManager) : base(ref baseFileSystem) ref readonly SharedRef<IRomFileSystemAccessFailureManager> accessFailureManager) : base(in baseFileSystem)
{ {
_accessFailureManager = SharedRef<IRomFileSystemAccessFailureManager>.CreateMove(ref accessFailureManager); _accessFailureManager = SharedRef<IRomFileSystemAccessFailureManager>.CreateCopy(in accessFailureManager);
} }
public static SharedRef<IFileSystem> CreateShared(ref SharedRef<IFileSystem> baseFileSystem, public static SharedRef<IFileSystem> CreateShared(ref readonly SharedRef<IFileSystem> baseFileSystem,
ref SharedRef<IRomFileSystemAccessFailureManager> accessFailureManager) ref readonly SharedRef<IRomFileSystemAccessFailureManager> accessFailureManager)
{ {
using var retryFileSystem = new SharedRef<DeepRetryFileSystem>( using var retryFileSystem = new SharedRef<DeepRetryFileSystem>(
new DeepRetryFileSystem(ref baseFileSystem, ref accessFailureManager)); new DeepRetryFileSystem(in baseFileSystem, in accessFailureManager));
retryFileSystem.Get._selfReference.Set(in retryFileSystem.Ref); retryFileSystem.Get._selfReference.Set(in retryFileSystem.Ref);

View File

@ -14,9 +14,9 @@ internal class DeviceEventSimulationStorage : IStorage
private SharedRef<IStorage> _baseStorage; private SharedRef<IStorage> _baseStorage;
private IDeviceEventSimulator _deviceEventSimulator; private IDeviceEventSimulator _deviceEventSimulator;
public DeviceEventSimulationStorage(ref SharedRef<IStorage> baseStorage, IDeviceEventSimulator deviceEventSimulator) public DeviceEventSimulationStorage(ref readonly SharedRef<IStorage> baseStorage, IDeviceEventSimulator deviceEventSimulator)
{ {
_baseStorage = SharedRef<IStorage>.CreateMove(ref baseStorage); _baseStorage = SharedRef<IStorage>.CreateCopy(in baseStorage);
_deviceEventSimulator = deviceEventSimulator; _deviceEventSimulator = deviceEventSimulator;
} }

View File

@ -27,9 +27,9 @@ public class FileInterfaceAdapter : IFileSf
private bool _allowAllOperations; private bool _allowAllOperations;
public FileInterfaceAdapter(ref UniqueRef<IFile> baseFile, public FileInterfaceAdapter(ref UniqueRef<IFile> baseFile,
ref SharedRef<FileSystemInterfaceAdapter> parentFileSystem, bool allowAllOperations) ref readonly SharedRef<FileSystemInterfaceAdapter> parentFileSystem, bool allowAllOperations)
{ {
_parentFs = SharedRef<FileSystemInterfaceAdapter>.CreateMove(ref parentFileSystem); _parentFs = SharedRef<FileSystemInterfaceAdapter>.CreateCopy(in parentFileSystem);
_baseFile = new UniqueRef<IFile>(ref baseFile); _baseFile = new UniqueRef<IFile>(ref baseFile);
_allowAllOperations = allowAllOperations; _allowAllOperations = allowAllOperations;
} }
@ -187,9 +187,9 @@ public class DirectoryInterfaceAdapter : IDirectorySf
private UniqueRef<IDirectory> _baseDirectory; private UniqueRef<IDirectory> _baseDirectory;
public DirectoryInterfaceAdapter(ref UniqueRef<IDirectory> baseDirectory, public DirectoryInterfaceAdapter(ref UniqueRef<IDirectory> baseDirectory,
ref SharedRef<FileSystemInterfaceAdapter> parentFileSystem) ref readonly SharedRef<FileSystemInterfaceAdapter> parentFileSystem)
{ {
_parentFs = SharedRef<FileSystemInterfaceAdapter>.CreateMove(ref parentFileSystem); _parentFs = SharedRef<FileSystemInterfaceAdapter>.CreateCopy(in parentFileSystem);
_baseDirectory = new UniqueRef<IDirectory>(ref baseDirectory); _baseDirectory = new UniqueRef<IDirectory>(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. // creating files and directories. We don't have an ISharedObject, so a self-reference is used instead.
private WeakRef<FileSystemInterfaceAdapter> _selfReference; private WeakRef<FileSystemInterfaceAdapter> _selfReference;
private FileSystemInterfaceAdapter(ref SharedRef<IFileSystem> fileSystem, private FileSystemInterfaceAdapter(ref readonly SharedRef<IFileSystem> fileSystem,
bool allowAllOperations) bool allowAllOperations)
{ {
_baseFileSystem = SharedRef<IFileSystem>.CreateMove(ref fileSystem); _baseFileSystem = SharedRef<IFileSystem>.CreateCopy(in fileSystem);
_allowAllOperations = allowAllOperations; _allowAllOperations = allowAllOperations;
} }
private FileSystemInterfaceAdapter(ref SharedRef<IFileSystem> fileSystem, PathFlags flags, private FileSystemInterfaceAdapter(ref readonly SharedRef<IFileSystem> fileSystem, PathFlags flags,
bool allowAllOperations) bool allowAllOperations)
{ {
_baseFileSystem = SharedRef<IFileSystem>.CreateMove(ref fileSystem); _baseFileSystem = SharedRef<IFileSystem>.CreateCopy(in fileSystem);
_pathFlags = flags; _pathFlags = flags;
_allowAllOperations = allowAllOperations; _allowAllOperations = allowAllOperations;
} }
public static SharedRef<IFileSystemSf> CreateShared(ref SharedRef<IFileSystem> baseFileSystem, bool allowAllOperations) public static SharedRef<IFileSystemSf> CreateShared(ref readonly SharedRef<IFileSystem> baseFileSystem, bool allowAllOperations)
{ {
var adapter = new FileSystemInterfaceAdapter(ref baseFileSystem, allowAllOperations); var adapter = new FileSystemInterfaceAdapter(in baseFileSystem, allowAllOperations);
using var sharedAdapter = new SharedRef<FileSystemInterfaceAdapter>(adapter); using var sharedAdapter = new SharedRef<FileSystemInterfaceAdapter>(adapter);
adapter._selfReference.Set(in sharedAdapter); adapter._selfReference.Set(in sharedAdapter);
@ -277,9 +277,9 @@ public class FileSystemInterfaceAdapter : IFileSystemSf
} }
public static SharedRef<IFileSystemSf> CreateShared( public static SharedRef<IFileSystemSf> CreateShared(
ref SharedRef<IFileSystem> baseFileSystem, PathFlags flags, bool allowAllOperations) ref readonly SharedRef<IFileSystem> 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<FileSystemInterfaceAdapter>(adapter); using var sharedAdapter = new SharedRef<FileSystemInterfaceAdapter>(adapter);
adapter._selfReference.Set(in sharedAdapter); adapter._selfReference.Set(in sharedAdapter);
@ -605,9 +605,9 @@ public class FileSystemInterfaceAdapter : IFileSystemSf
return Result.Success; return Result.Success;
} }
public Result GetImpl(ref SharedRef<IFileSystem> fileSystem) public Result GetImpl(ref SharedRef<IFileSystem> outFileSystem)
{ {
fileSystem.SetByCopy(in _baseFileSystem); outFileSystem.SetByCopy(in _baseFileSystem);
return Result.Success; return Result.Success;
} }
} }

View File

@ -47,7 +47,7 @@ public static class FileSystemProxyServiceObject
return ResultFs.PortAcceptableCountLimited.Log(); return ResultFs.PortAcceptableCountLimited.Log();
} }
public Result OpenCodeFileSystem(ref SharedRef<IFileSystem> fileSystem, OutBuffer outVerificationData, public Result OpenCodeFileSystem(ref SharedRef<IFileSystem> outFileSystem, OutBuffer outVerificationData,
ref readonly FspPath path, ContentAttributes attributes, ProgramId programId) ref readonly FspPath path, ContentAttributes attributes, ProgramId programId)
{ {
return ResultFs.PortAcceptableCountLimited.Log(); return ResultFs.PortAcceptableCountLimited.Log();

View File

@ -66,20 +66,20 @@ internal class MultiCommitManager : IMultiCommitManager
private readonly FileSystemServer _fsServer; private readonly FileSystemServer _fsServer;
private ref MultiCommitManagerGlobals Globals => ref _fsServer.Globals.MultiCommitManager; private ref MultiCommitManagerGlobals Globals => ref _fsServer.Globals.MultiCommitManager;
public MultiCommitManager(FileSystemServer fsServer, ref SharedRef<ISaveDataMultiCommitCoreInterface> multiCommitInterface) public MultiCommitManager(FileSystemServer fsServer, ref readonly SharedRef<ISaveDataMultiCommitCoreInterface> multiCommitInterface)
{ {
_fsServer = fsServer; _fsServer = fsServer;
_multiCommitInterface = SharedRef<ISaveDataMultiCommitCoreInterface>.CreateMove(ref multiCommitInterface); _multiCommitInterface = SharedRef<ISaveDataMultiCommitCoreInterface>.CreateCopy(in multiCommitInterface);
_fileSystems = new SharedRef<IFileSystem>[MaxFileSystemCount]; _fileSystems = new SharedRef<IFileSystem>[MaxFileSystemCount];
_fileSystemCount = 0; _fileSystemCount = 0;
_counter = 0; _counter = 0;
} }
public static SharedRef<IMultiCommitManager> CreateShared(FileSystemServer fsServer, public static SharedRef<IMultiCommitManager> CreateShared(FileSystemServer fsServer,
ref SharedRef<ISaveDataMultiCommitCoreInterface> multiCommitInterface) ref readonly SharedRef<ISaveDataMultiCommitCoreInterface> multiCommitInterface)
{ {
return new SharedRef<IMultiCommitManager>(new MultiCommitManager(fsServer, ref multiCommitInterface)); return new SharedRef<IMultiCommitManager>(new MultiCommitManager(fsServer, in multiCommitInterface));
} }
public void Dispose() public void Dispose()
@ -121,7 +121,7 @@ internal class MultiCommitManager : IMultiCommitManager
/// <see cref="ResultFs.MultiCommitFileSystemLimit"/>: The maximum number of file systems have been added. /// <see cref="ResultFs.MultiCommitFileSystemLimit"/>: The maximum number of file systems have been added.
/// <see cref="MaxFileSystemCount"/> file systems may be added to a single multi-commit.<br/> /// <see cref="MaxFileSystemCount"/> file systems may be added to a single multi-commit.<br/>
/// <see cref="ResultFs.MultiCommitFileSystemDuplicated"/>: The provided file system has already been added.</returns> /// <see cref="ResultFs.MultiCommitFileSystemDuplicated"/>: The provided file system has already been added.</returns>
public Result Add(ref SharedRef<IFileSystemSf> fileSystem) public Result Add(ref readonly SharedRef<IFileSystemSf> fileSystem)
{ {
if (_fileSystemCount >= MaxFileSystemCount) if (_fileSystemCount >= MaxFileSystemCount)
return ResultFs.MultiCommitFileSystemLimit.Log(); return ResultFs.MultiCommitFileSystemLimit.Log();

View File

@ -10,37 +10,35 @@ internal class OpenCountFileSystem : ForwardingFileSystem
private SharedRef<IEntryOpenCountSemaphoreManager> _entryCountSemaphore; private SharedRef<IEntryOpenCountSemaphoreManager> _entryCountSemaphore;
private UniqueRef<IUniqueLock> _mountCountSemaphore; private UniqueRef<IUniqueLock> _mountCountSemaphore;
public OpenCountFileSystem(ref SharedRef<IFileSystem> baseFileSystem, public OpenCountFileSystem(ref readonly SharedRef<IFileSystem> baseFileSystem,
ref SharedRef<IEntryOpenCountSemaphoreManager> entryCountSemaphore) : base(ref baseFileSystem) ref readonly SharedRef<IEntryOpenCountSemaphoreManager> entryCountSemaphore) : base(in baseFileSystem)
{ {
_entryCountSemaphore = SharedRef<IEntryOpenCountSemaphoreManager>.CreateMove(ref entryCountSemaphore); _entryCountSemaphore = SharedRef<IEntryOpenCountSemaphoreManager>.CreateCopy(in entryCountSemaphore);
} }
public OpenCountFileSystem(ref SharedRef<IFileSystem> baseFileSystem, public OpenCountFileSystem(ref readonly SharedRef<IFileSystem> baseFileSystem,
ref SharedRef<IEntryOpenCountSemaphoreManager> entryCountSemaphore, ref readonly SharedRef<IEntryOpenCountSemaphoreManager> entryCountSemaphore,
ref UniqueRef<IUniqueLock> mountCountSemaphore) : base(ref baseFileSystem) ref UniqueRef<IUniqueLock> mountCountSemaphore) : base(in baseFileSystem)
{ {
_entryCountSemaphore = SharedRef<IEntryOpenCountSemaphoreManager>.CreateMove(ref entryCountSemaphore); _entryCountSemaphore = SharedRef<IEntryOpenCountSemaphoreManager>.CreateCopy(in entryCountSemaphore);
_mountCountSemaphore = new UniqueRef<IUniqueLock>(ref mountCountSemaphore); _mountCountSemaphore = new UniqueRef<IUniqueLock>(ref mountCountSemaphore);
} }
public static SharedRef<IFileSystem> CreateShared( public static SharedRef<IFileSystem> CreateShared(
ref SharedRef<IFileSystem> baseFileSystem, ref readonly SharedRef<IFileSystem> baseFileSystem,
ref SharedRef<IEntryOpenCountSemaphoreManager> entryCountSemaphore, ref readonly SharedRef<IEntryOpenCountSemaphoreManager> entryCountSemaphore,
ref UniqueRef<IUniqueLock> mountCountSemaphore) ref UniqueRef<IUniqueLock> mountCountSemaphore)
{ {
var filesystem = var filesystem = new OpenCountFileSystem(in baseFileSystem, in entryCountSemaphore, ref mountCountSemaphore);
new OpenCountFileSystem(ref baseFileSystem, ref entryCountSemaphore, ref mountCountSemaphore);
return new SharedRef<IFileSystem>(filesystem); return new SharedRef<IFileSystem>(filesystem);
} }
public static SharedRef<IFileSystem> CreateShared( public static SharedRef<IFileSystem> CreateShared(
ref SharedRef<IFileSystem> baseFileSystem, ref readonly SharedRef<IFileSystem> baseFileSystem,
ref SharedRef<IEntryOpenCountSemaphoreManager> entryCountSemaphore) ref readonly SharedRef<IEntryOpenCountSemaphoreManager> entryCountSemaphore)
{ {
var filesystem = var filesystem = new OpenCountFileSystem(in baseFileSystem, in entryCountSemaphore);
new OpenCountFileSystem(ref baseFileSystem, ref entryCountSemaphore);
return new SharedRef<IFileSystem>(filesystem); return new SharedRef<IFileSystem>(filesystem);
} }

View File

@ -36,9 +36,9 @@ public class SaveDataFileSystemCacheManager : IDisposable
return SharedRef<ISaveDataFileSystem>.CreateMove(ref _fileSystem); return SharedRef<ISaveDataFileSystem>.CreateMove(ref _fileSystem);
} }
public void Register(ref SharedRef<ISaveDataFileSystem> fileSystem, SaveDataSpaceId spaceId, ulong saveDataId) public void Register(ref readonly SharedRef<ISaveDataFileSystem> fileSystem, SaveDataSpaceId spaceId, ulong saveDataId)
{ {
_fileSystem.SetByMove(ref fileSystem); _fileSystem.SetByCopy(in fileSystem);
_spaceId = spaceId; _spaceId = spaceId;
_saveDataId = saveDataId; _saveDataId = saveDataId;
} }

View File

@ -17,10 +17,10 @@ public class SaveDataFileSystemCacheRegister : IFileSystem
private SaveDataSpaceId _spaceId; private SaveDataSpaceId _spaceId;
private ulong _saveDataId; private ulong _saveDataId;
public SaveDataFileSystemCacheRegister(ref SharedRef<ISaveDataFileSystem> baseFileSystem, public SaveDataFileSystemCacheRegister(ref readonly SharedRef<ISaveDataFileSystem> baseFileSystem,
SaveDataFileSystemCacheManager cacheManager, SaveDataSpaceId spaceId, ulong saveDataId) SaveDataFileSystemCacheManager cacheManager, SaveDataSpaceId spaceId, ulong saveDataId)
{ {
_baseFileSystem = SharedRef<ISaveDataFileSystem>.CreateMove(ref baseFileSystem); _baseFileSystem = SharedRef<ISaveDataFileSystem>.CreateCopy(in baseFileSystem);
_cacheManager = cacheManager; _cacheManager = cacheManager;
_spaceId = spaceId; _spaceId = spaceId;
_saveDataId = saveDataId; _saveDataId = saveDataId;

View File

@ -16,9 +16,9 @@ public class StorageInterfaceAdapter : IStorageSf
{ {
private SharedRef<IStorage> _baseStorage; private SharedRef<IStorage> _baseStorage;
public StorageInterfaceAdapter(ref SharedRef<IStorage> baseStorage) public StorageInterfaceAdapter(ref readonly SharedRef<IStorage> baseStorage)
{ {
_baseStorage = SharedRef<IStorage>.CreateMove(ref baseStorage); _baseStorage = SharedRef<IStorage>.CreateCopy(in baseStorage);
} }
public void Dispose() public void Dispose()

View File

@ -16,11 +16,11 @@ internal static class Utility
} }
public static Result CreateSubDirectoryFileSystem(ref SharedRef<IFileSystem> outSubDirFileSystem, public static Result CreateSubDirectoryFileSystem(ref SharedRef<IFileSystem> outSubDirFileSystem,
ref SharedRef<IFileSystem> baseFileSystem, ref readonly Path rootPath) ref readonly SharedRef<IFileSystem> baseFileSystem, ref readonly Path rootPath)
{ {
if (rootPath.IsEmpty()) if (rootPath.IsEmpty())
{ {
outSubDirFileSystem.SetByMove(ref baseFileSystem); outSubDirFileSystem.SetByCopy(in baseFileSystem);
return Result.Success; return Result.Success;
} }
@ -31,7 +31,7 @@ internal static class Utility
dir.Reset(); dir.Reset();
using var fs = new SharedRef<SubdirectoryFileSystem>(new SubdirectoryFileSystem(ref baseFileSystem)); using var fs = new SharedRef<SubdirectoryFileSystem>(new SubdirectoryFileSystem(in baseFileSystem));
if (!fs.HasValue) if (!fs.HasValue)
return ResultFs.AllocationMemoryFailedInSubDirectoryFileSystemCreatorA.Log(); return ResultFs.AllocationMemoryFailedInSubDirectoryFileSystemCreatorA.Log();
@ -44,7 +44,7 @@ internal static class Utility
} }
public static Result WrapSubDirectory(ref SharedRef<IFileSystem> outFileSystem, public static Result WrapSubDirectory(ref SharedRef<IFileSystem> outFileSystem,
ref SharedRef<IFileSystem> baseFileSystem, ref readonly Path rootPath, bool createIfMissing) ref readonly SharedRef<IFileSystem> baseFileSystem, ref readonly Path rootPath, bool createIfMissing)
{ {
// The path must already exist if we're not automatically creating it // The path must already exist if we're not automatically creating it
if (!createIfMissing) if (!createIfMissing)
@ -57,7 +57,7 @@ internal static class Utility
Result res = FsSystem.Utility.EnsureDirectory(baseFileSystem.Get, in rootPath); Result res = FsSystem.Utility.EnsureDirectory(baseFileSystem.Get, in rootPath);
if (res.IsFailure()) return res.Miss(); 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) public static long ConvertZeroCommitId(in SaveDataExtraData extraData)

View File

@ -1825,16 +1825,16 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave
openReadOnly).Ret(); openReadOnly).Ret();
} }
public Result OpenSaveDataFileSystem(ref SharedRef<IFileSystemSf> fileSystem, SaveDataSpaceId spaceId, public Result OpenSaveDataFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, SaveDataSpaceId spaceId,
in SaveDataAttribute attribute) 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<IFileSystemSf> fileSystem, SaveDataSpaceId spaceId, public Result OpenReadOnlySaveDataFileSystem(ref SharedRef<IFileSystemSf> outGileSystem, SaveDataSpaceId spaceId,
in SaveDataAttribute attribute) 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<IFileSystemSf> outFileSystem, public Result OpenSaveDataFileSystemBySystemSaveDataId(ref SharedRef<IFileSystemSf> outFileSystem,

View File

@ -299,7 +299,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
bool openShared = SaveDataProperties.IsSharedOpenNeeded(type); bool openShared = SaveDataProperties.IsSharedOpenNeeded(type);
bool isReconstructible = SaveDataProperties.IsReconstructible(type, spaceId); 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, isEmulatedOnHost, isDeviceUniqueMac, isJournalingSupported, isMultiCommitSupported,
openReadOnly, openShared, _timeStampGetter, isReconstructible); openReadOnly, openShared, _timeStampGetter, isReconstructible);
if (res.IsFailure()) return res.Miss(); if (res.IsFailure()) return res.Miss();

View File

@ -116,9 +116,9 @@ internal class SaveDataInfoFilterReader : SaveDataInfoReaderImpl
private SharedRef<SaveDataInfoReaderImpl> _reader; private SharedRef<SaveDataInfoReaderImpl> _reader;
private SaveDataInfoFilter _infoFilter; private SaveDataInfoFilter _infoFilter;
public SaveDataInfoFilterReader(ref SharedRef<SaveDataInfoReaderImpl> reader, in SaveDataInfoFilter infoFilter) public SaveDataInfoFilterReader(ref readonly SharedRef<SaveDataInfoReaderImpl> reader, in SaveDataInfoFilter infoFilter)
{ {
_reader = SharedRef<SaveDataInfoReaderImpl>.CreateMove(ref reader); _reader = SharedRef<SaveDataInfoReaderImpl>.CreateCopy(in reader);
_infoFilter = infoFilter; _infoFilter = infoFilter;
} }

View File

@ -168,10 +168,10 @@ public class SaveDataSharedFileStorage : IStorage
private SharedRef<SaveDataOpenTypeSetFileStorage> _baseStorage; private SharedRef<SaveDataOpenTypeSetFileStorage> _baseStorage;
private SaveDataOpenTypeSetFileStorage.OpenType _type; private SaveDataOpenTypeSetFileStorage.OpenType _type;
public SaveDataSharedFileStorage(ref SharedRef<SaveDataOpenTypeSetFileStorage> baseStorage, public SaveDataSharedFileStorage(ref readonly SharedRef<SaveDataOpenTypeSetFileStorage> baseStorage,
SaveDataOpenTypeSetFileStorage.OpenType type) SaveDataOpenTypeSetFileStorage.OpenType type)
{ {
_baseStorage = SharedRef<SaveDataOpenTypeSetFileStorage>.CreateMove(ref baseStorage); _baseStorage = SharedRef<SaveDataOpenTypeSetFileStorage>.CreateCopy(in baseStorage);
_type = type; _type = type;
} }
@ -278,10 +278,10 @@ public class SaveDataFileStorageHolder
private SaveDataSpaceId _spaceId; private SaveDataSpaceId _spaceId;
private ulong _saveDataId; private ulong _saveDataId;
public Entry(ref SharedRef<SaveDataOpenTypeSetFileStorage> storage, SaveDataSpaceId spaceId, public Entry(ref readonly SharedRef<SaveDataOpenTypeSetFileStorage> storage, SaveDataSpaceId spaceId,
ulong saveDataId) ulong saveDataId)
{ {
_storage = SharedRef<SaveDataOpenTypeSetFileStorage>.CreateMove(ref storage); _storage = SharedRef<SaveDataOpenTypeSetFileStorage>.CreateCopy(in storage);
_spaceId = spaceId; _spaceId = spaceId;
_saveDataId = saveDataId; _saveDataId = saveDataId;
} }

View File

@ -10,7 +10,7 @@ namespace LibHac.FsSrv.Sf;
public interface IFileSystem : IDisposable public interface IFileSystem : IDisposable
{ {
Result GetImpl(ref SharedRef<Fs.Fsa.IFileSystem> fileSystem); Result GetImpl(ref SharedRef<Fs.Fsa.IFileSystem> outFileSystem);
Result CreateFile(ref readonly Path path, long size, int option); Result CreateFile(ref readonly Path path, long size, int option);
Result DeleteFile(ref readonly Path path); Result DeleteFile(ref readonly Path path);
Result CreateDirectory(ref readonly Path path); Result CreateDirectory(ref readonly Path path);

View File

@ -9,7 +9,7 @@ namespace LibHac.FsSrv.Sf;
public interface IFileSystemProxyForLoader : IDisposable public interface IFileSystemProxyForLoader : IDisposable
{ {
Result OpenCodeFileSystem(ref SharedRef<IFileSystemSf> fileSystem, OutBuffer outVerificationData, Result OpenCodeFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, OutBuffer outVerificationData,
ref readonly FspPath path, ContentAttributes attributes, ProgramId programId); ref readonly FspPath path, ContentAttributes attributes, ProgramId programId);
Result IsArchivedProgram(out bool isArchived, ulong processId); Result IsArchivedProgram(out bool isArchived, ulong processId);

View File

@ -6,6 +6,6 @@ namespace LibHac.FsSrv.Sf;
public interface IMultiCommitManager : IDisposable public interface IMultiCommitManager : IDisposable
{ {
Result Add(ref SharedRef<IFileSystemSf> fileSystem); Result Add(ref readonly SharedRef<IFileSystemSf> fileSystem);
Result Commit(); Result Commit();
} }

View File

@ -9,9 +9,9 @@ public class SpeedEmulationStorage : IStorage
{ {
private SharedRef<IStorage> _baseStorage; private SharedRef<IStorage> _baseStorage;
public SpeedEmulationStorage(ref SharedRef<IStorage> baseStorage, FileSystemServer fsServer) public SpeedEmulationStorage(ref readonly SharedRef<IStorage> baseStorage, FileSystemServer fsServer)
{ {
_baseStorage = SharedRef<IStorage>.CreateMove(ref baseStorage); _baseStorage = SharedRef<IStorage>.CreateCopy(in baseStorage);
} }
public override void Dispose() public override void Dispose()

View File

@ -57,10 +57,10 @@ public class AesXtsStorage : IStorage
iv.CopyTo(_iv); iv.CopyTo(_iv);
} }
public AesXtsStorage(ref SharedRef<IStorage> baseStorage, ReadOnlySpan<byte> key1, ReadOnlySpan<byte> key2, public AesXtsStorage(ref readonly SharedRef<IStorage> baseStorage, ReadOnlySpan<byte> key1, ReadOnlySpan<byte> key2,
ReadOnlySpan<byte> iv, int blockSize) ReadOnlySpan<byte> iv, int blockSize)
{ {
_baseStorageShared = SharedRef<IStorage>.CreateMove(ref baseStorage); _baseStorageShared = SharedRef<IStorage>.CreateCopy(in baseStorage);
_baseStorage = _baseStorageShared.Get; _baseStorage = _baseStorageShared.Get;
_blockSize = blockSize; _blockSize = blockSize;
_mutex = new SdkMutexType(); _mutex = new SdkMutexType();

View File

@ -105,7 +105,7 @@ public class AlignmentMatchingFile : ForwardingFile
public class AlignmentMatchableFileSystem : ForwardingFileSystem public class AlignmentMatchableFileSystem : ForwardingFileSystem
{ {
public AlignmentMatchableFileSystem(ref SharedRef<IFileSystem> baseFileSystem) : base(ref baseFileSystem) { } public AlignmentMatchableFileSystem(ref readonly SharedRef<IFileSystem> baseFileSystem) : base(in baseFileSystem) { }
protected override Result DoOpenFile(ref UniqueRef<IFile> outFile, ref readonly Path path, OpenMode mode) protected override Result DoOpenFile(ref UniqueRef<IFile> outFile, ref readonly Path path, OpenMode mode)
{ {

View File

@ -59,13 +59,13 @@ public class AlignmentMatchingStorage<TDataAlignment, TBufferAlignment> : IStora
private bool _isBaseStorageSizeDirty; private bool _isBaseStorageSizeDirty;
private SharedRef<IStorage> _sharedBaseStorage; private SharedRef<IStorage> _sharedBaseStorage;
public AlignmentMatchingStorage(ref SharedRef<IStorage> baseStorage) public AlignmentMatchingStorage(ref readonly SharedRef<IStorage> baseStorage)
{ {
VerifyTypeParameters(); VerifyTypeParameters();
_baseStorage = baseStorage.Get; _baseStorage = baseStorage.Get;
_isBaseStorageSizeDirty = true; _isBaseStorageSizeDirty = true;
_sharedBaseStorage = SharedRef<IStorage>.CreateMove(ref baseStorage); _sharedBaseStorage = SharedRef<IStorage>.CreateCopy(in baseStorage);
} }
public AlignmentMatchingStorage(IStorage baseStorage) public AlignmentMatchingStorage(IStorage baseStorage)

View File

@ -78,9 +78,9 @@ public class ForwardingFileSystem : IFileSystem
{ {
protected SharedRef<IFileSystem> BaseFileSystem; protected SharedRef<IFileSystem> BaseFileSystem;
protected ForwardingFileSystem(ref SharedRef<IFileSystem> baseFileSystem) protected ForwardingFileSystem(ref readonly SharedRef<IFileSystem> baseFileSystem)
{ {
BaseFileSystem = SharedRef<IFileSystem>.CreateMove(ref baseFileSystem); BaseFileSystem = SharedRef<IFileSystem>.CreateCopy(in baseFileSystem);
} }
public override void Dispose() public override void Dispose()

View File

@ -106,9 +106,9 @@ public abstract class IResultConvertFileSystem<T> : ISaveDataFileSystem where T
{ {
private SharedRef<T> _baseFileSystem; private SharedRef<T> _baseFileSystem;
protected IResultConvertFileSystem(ref SharedRef<T> baseFileSystem) protected IResultConvertFileSystem(ref readonly SharedRef<T> baseFileSystem)
{ {
_baseFileSystem = SharedRef<T>.CreateMove(ref baseFileSystem); _baseFileSystem = SharedRef<T>.CreateCopy(in baseFileSystem);
} }
public override void Dispose() public override void Dispose()

View File

@ -11,10 +11,10 @@ public class UniqueLockWithPin<T> : IUniqueLock where T : class, IDisposable
private UniqueLock<SemaphoreAdapter> _semaphore; private UniqueLock<SemaphoreAdapter> _semaphore;
private SharedRef<T> _pinnedObject; private SharedRef<T> _pinnedObject;
public UniqueLockWithPin(ref UniqueLock<SemaphoreAdapter> semaphore, ref SharedRef<T> pinnedObject) public UniqueLockWithPin(ref UniqueLock<SemaphoreAdapter> semaphore, ref readonly SharedRef<T> pinnedObject)
{ {
_semaphore = new UniqueLock<SemaphoreAdapter>(ref semaphore); _semaphore = new UniqueLock<SemaphoreAdapter>(ref semaphore);
_pinnedObject = SharedRef<T>.CreateMove(ref pinnedObject); _pinnedObject = SharedRef<T>.CreateCopy(in pinnedObject);
} }
public void Dispose() public void Dispose()

View File

@ -16,10 +16,10 @@ public class MemoryResourceBufferHoldStorage : IStorage
private MemoryResource _memoryResource; private MemoryResource _memoryResource;
private Mem.Buffer _buffer; private Mem.Buffer _buffer;
public MemoryResourceBufferHoldStorage(ref SharedRef<IStorage> baseStorage, MemoryResource memoryResource, public MemoryResourceBufferHoldStorage(ref readonly SharedRef<IStorage> baseStorage, MemoryResource memoryResource,
int bufferSize) int bufferSize)
{ {
_storage = SharedRef<IStorage>.CreateMove(ref baseStorage); _storage = SharedRef<IStorage>.CreateCopy(in baseStorage);
_memoryResource = memoryResource; _memoryResource = memoryResource;
_buffer = memoryResource.Allocate(bufferSize); _buffer = memoryResource.Allocate(bufferSize);
} }

View File

@ -233,7 +233,7 @@ public class NcaFileSystemDriver : IDisposable
throw new NotImplementedException(); throw new NotImplementedException();
} }
private Result CreateAesXtsStorage(ref SharedRef<IStorage> outStorage, ref SharedRef<IStorage> baseStorage, private Result CreateAesXtsStorage(ref SharedRef<IStorage> outStorage, ref readonly SharedRef<IStorage> baseStorage,
long offset) long offset)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@ -269,7 +269,7 @@ public class NcaFileSystemDriver : IDisposable
} }
private Result CreateSparseStorageWithVerification(ref SharedRef<IStorage> outStorage, out long outFsDataOffset, private Result CreateSparseStorageWithVerification(ref SharedRef<IStorage> outStorage, out long outFsDataOffset,
out SharedRef<SparseStorage> outSparseStorage, ref SharedRef<IStorage> outSparseStorageMetaStorage, ref SharedRef<SparseStorage> outSparseStorage, ref SharedRef<IStorage> outSparseStorageMetaStorage,
ref SharedRef<IStorage> outLayerInfoStorage, int index, NcaFsHeader.EncryptionType encryptionType, ref SharedRef<IStorage> outLayerInfoStorage, int index, NcaFsHeader.EncryptionType encryptionType,
in NcaAesCtrUpperIv upperIv, in NcaSparseInfo sparseInfo, in NcaMetaDataHashDataInfo metaDataHashDataInfo, in NcaAesCtrUpperIv upperIv, in NcaSparseInfo sparseInfo, in NcaMetaDataHashDataInfo metaDataHashDataInfo,
NcaFsHeader.MetaDataHashType metaDataHashType) NcaFsHeader.MetaDataHashType metaDataHashType)

View File

@ -23,10 +23,10 @@ public class ReadOnlyBlockCacheStorage : IStorage
private SharedRef<IStorage> _baseStorage; private SharedRef<IStorage> _baseStorage;
private int _blockSize; private int _blockSize;
public ReadOnlyBlockCacheStorage(ref SharedRef<IStorage> baseStorage, int blockSize, Memory<byte> buffer, public ReadOnlyBlockCacheStorage(ref readonly SharedRef<IStorage> baseStorage, int blockSize, Memory<byte> buffer,
int cacheBlockCount) int cacheBlockCount)
{ {
_baseStorage = SharedRef<IStorage>.CreateMove(ref baseStorage); _baseStorage = SharedRef<IStorage>.CreateCopy(in baseStorage);
_blockSize = blockSize; _blockSize = blockSize;
_blockCache = new BlockCache(); _blockCache = new BlockCache();
_mutex = new SdkMutexType(); _mutex = new SdkMutexType();

View File

@ -55,8 +55,8 @@ public class SaveDataResultConvertFileSystem : IResultConvertFileSystem<ISaveDat
{ {
private bool _isReconstructible; private bool _isReconstructible;
public SaveDataResultConvertFileSystem(ref SharedRef<ISaveDataFileSystem> baseFileSystem, bool isReconstructible) : public SaveDataResultConvertFileSystem(ref readonly SharedRef<ISaveDataFileSystem> baseFileSystem, bool isReconstructible) :
base(ref baseFileSystem) base(in baseFileSystem)
{ {
_isReconstructible = isReconstructible; _isReconstructible = isReconstructible;
} }

View File

@ -128,10 +128,10 @@ internal class StorageLayoutTypeSetFile : IFile
Assert.SdkAssert(StorageLayoutTypeFunctions.IsStorageFlagValid(storageFlag)); Assert.SdkAssert(StorageLayoutTypeFunctions.IsStorageFlagValid(storageFlag));
} }
public StorageLayoutTypeSetFile(ref SharedRef<IFile> baseFile, StorageLayoutType storageFlag) public StorageLayoutTypeSetFile(ref readonly SharedRef<IFile> baseFile, StorageLayoutType storageFlag)
{ {
_baseFile = baseFile.Get; _baseFile = baseFile.Get;
_baseFileShared = SharedRef<IFile>.CreateMove(ref baseFile); _baseFileShared = SharedRef<IFile>.CreateCopy(in baseFile);
_storageFlag = storageFlag; _storageFlag = storageFlag;
Assert.SdkAssert(StorageLayoutTypeFunctions.IsStorageFlagValid(storageFlag)); Assert.SdkAssert(StorageLayoutTypeFunctions.IsStorageFlagValid(storageFlag));
@ -235,9 +235,9 @@ internal class StorageLayoutTypeSetFileSystem : IFileSystem
private SharedRef<IFileSystem> _baseFileSystem; private SharedRef<IFileSystem> _baseFileSystem;
private StorageLayoutType _storageFlag; private StorageLayoutType _storageFlag;
public StorageLayoutTypeSetFileSystem(ref SharedRef<IFileSystem> baseFileSystem, StorageLayoutType storageFlag) public StorageLayoutTypeSetFileSystem(ref readonly SharedRef<IFileSystem> baseFileSystem, StorageLayoutType storageFlag)
{ {
_baseFileSystem = SharedRef<IFileSystem>.CreateMove(ref baseFileSystem); _baseFileSystem = SharedRef<IFileSystem>.CreateCopy(in baseFileSystem);
_storageFlag = storageFlag; _storageFlag = storageFlag;
Assert.SdkAssert(StorageLayoutTypeFunctions.IsStorageFlagValid(storageFlag)); Assert.SdkAssert(StorageLayoutTypeFunctions.IsStorageFlagValid(storageFlag));

View File

@ -488,13 +488,13 @@ internal static class Utility
} }
public static Result MakeUniqueLockWithPin<T>(ref UniqueRef<IUniqueLock> outUniqueLock, public static Result MakeUniqueLockWithPin<T>(ref UniqueRef<IUniqueLock> outUniqueLock,
SemaphoreAdapter semaphore, ref SharedRef<T> objectToPin) where T : class, IDisposable SemaphoreAdapter semaphore, ref readonly SharedRef<T> objectToPin) where T : class, IDisposable
{ {
using var semaphoreAdapter = new UniqueLock<SemaphoreAdapter>(); using var semaphoreAdapter = new UniqueLock<SemaphoreAdapter>();
Result res = TryAcquireCountSemaphore(ref semaphoreAdapter.Ref(), semaphore); Result res = TryAcquireCountSemaphore(ref semaphoreAdapter.Ref(), semaphore);
if (res.IsFailure()) return res.Miss(); if (res.IsFailure()) return res.Miss();
var lockWithPin = new UniqueLockWithPin<T>(ref semaphoreAdapter.Ref(), ref objectToPin); var lockWithPin = new UniqueLockWithPin<T>(ref semaphoreAdapter.Ref(), in objectToPin);
using var uniqueLock = new UniqueRef<IUniqueLock>(lockWithPin); using var uniqueLock = new UniqueRef<IUniqueLock>(lockWithPin);
outUniqueLock.Set(ref uniqueLock.Ref); outUniqueLock.Set(ref uniqueLock.Ref);

View File

@ -22,9 +22,9 @@ internal class ReadOnlyGameCardStorage : IStorage
// LibHac additions // LibHac additions
private readonly IGcApi _gc; private readonly IGcApi _gc;
public ReadOnlyGameCardStorage(ref SharedRef<IGameCardManager> deviceManger, IGcApi gc) public ReadOnlyGameCardStorage(ref readonly SharedRef<IGameCardManager> deviceManger, IGcApi gc)
{ {
_deviceManager = SharedRef<IGameCardManager>.CreateMove(ref deviceManger); _deviceManager = SharedRef<IGameCardManager>.CreateCopy(in deviceManger);
_gc = gc; _gc = gc;
} }
@ -105,9 +105,9 @@ internal class WriteOnlyGameCardStorage : IStorage
// LibHac additions // LibHac additions
private readonly IGcApi _gc; private readonly IGcApi _gc;
public WriteOnlyGameCardStorage(ref SharedRef<IGameCardManager> deviceManger, IGcApi gc) public WriteOnlyGameCardStorage(ref readonly SharedRef<IGameCardManager> deviceManger, IGcApi gc)
{ {
_deviceManager = SharedRef<IGameCardManager>.CreateMove(ref deviceManger); _deviceManager = SharedRef<IGameCardManager>.CreateCopy(in deviceManger);
_gc = gc; _gc = gc;
} }

View File

@ -26,17 +26,17 @@ internal class GameCardStorageDevice : GameCardStorageInterfaceAdapter, IStorage
private WeakRef<GameCardStorageDevice> _selfReference; private WeakRef<GameCardStorageDevice> _selfReference;
private readonly IGcApi _gc; private readonly IGcApi _gc;
private GameCardStorageDevice(IGcApi gc, ref SharedRef<IGameCardManager> manager, private GameCardStorageDevice(IGcApi gc, ref readonly SharedRef<IGameCardManager> manager,
ref readonly SharedRef<IStorage> baseStorage, GameCardHandle handle) : base(in baseStorage) ref readonly SharedRef<IStorage> baseStorage, GameCardHandle handle) : base(in baseStorage)
{ {
_manager = SharedRef<IGameCardManager>.CreateMove(ref manager); _manager = SharedRef<IGameCardManager>.CreateCopy(in manager);
_handle = handle; _handle = handle;
_isSecure = false; _isSecure = false;
_gc = gc; _gc = gc;
} }
private GameCardStorageDevice(IGcApi gc, ref SharedRef<IGameCardManager> manager, private GameCardStorageDevice(IGcApi gc, ref readonly SharedRef<IGameCardManager> manager,
ref readonly SharedRef<IStorage> baseStorage, GameCardHandle handle, bool isSecure, ref readonly SharedRef<IStorage> baseStorage, GameCardHandle handle, bool isSecure,
ReadOnlySpan<byte> cardDeviceId, ReadOnlySpan<byte> cardImageHash) ReadOnlySpan<byte> cardDeviceId, ReadOnlySpan<byte> cardImageHash)
: base(in baseStorage) : base(in baseStorage)
@ -44,7 +44,7 @@ internal class GameCardStorageDevice : GameCardStorageInterfaceAdapter, IStorage
Assert.SdkRequiresEqual(cardDeviceId.Length, Values.GcCardDeviceIdSize); Assert.SdkRequiresEqual(cardDeviceId.Length, Values.GcCardDeviceIdSize);
Assert.SdkRequiresEqual(cardImageHash.Length, Values.GcCardImageHashSize); Assert.SdkRequiresEqual(cardImageHash.Length, Values.GcCardImageHashSize);
_manager = SharedRef<IGameCardManager>.CreateMove(ref manager); _manager = SharedRef<IGameCardManager>.CreateCopy(in manager);
_handle = handle; _handle = handle;
_isSecure = isSecure; _isSecure = isSecure;
@ -54,10 +54,10 @@ internal class GameCardStorageDevice : GameCardStorageInterfaceAdapter, IStorage
_gc = gc; _gc = gc;
} }
public static SharedRef<GameCardStorageDevice> CreateShared(IGcApi gc, ref SharedRef<IGameCardManager> manager, public static SharedRef<GameCardStorageDevice> CreateShared(IGcApi gc, ref readonly SharedRef<IGameCardManager> manager,
ref readonly SharedRef<IStorage> baseStorage, GameCardHandle handle) ref readonly SharedRef<IStorage> 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<GameCardStorageDevice>(storageDevice); using var sharedStorageDevice = new SharedRef<GameCardStorageDevice>(storageDevice);
storageDevice._selfReference.Set(in sharedStorageDevice); storageDevice._selfReference.Set(in sharedStorageDevice);
@ -65,11 +65,11 @@ internal class GameCardStorageDevice : GameCardStorageInterfaceAdapter, IStorage
return SharedRef<GameCardStorageDevice>.CreateMove(ref sharedStorageDevice.Ref); return SharedRef<GameCardStorageDevice>.CreateMove(ref sharedStorageDevice.Ref);
} }
public static SharedRef<GameCardStorageDevice> CreateShared(IGcApi gc, ref SharedRef<IGameCardManager> manager, public static SharedRef<GameCardStorageDevice> CreateShared(IGcApi gc, ref readonly SharedRef<IGameCardManager> manager,
ref readonly SharedRef<IStorage> baseStorage, GameCardHandle handle, bool isSecure, ref readonly SharedRef<IStorage> baseStorage, GameCardHandle handle, bool isSecure,
ReadOnlySpan<byte> cardDeviceId, ReadOnlySpan<byte> cardImageHash) ReadOnlySpan<byte> cardDeviceId, ReadOnlySpan<byte> 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); cardImageHash);
using var sharedStorageDevice = new SharedRef<GameCardStorageDevice>(storageDevice); using var sharedStorageDevice = new SharedRef<GameCardStorageDevice>(storageDevice);

View File

@ -9,9 +9,9 @@ public class AddOnContentLocationResolver : IDisposable
{ {
private SharedRef<IAddOnContentLocationResolver> _interface; private SharedRef<IAddOnContentLocationResolver> _interface;
public AddOnContentLocationResolver(ref SharedRef<IAddOnContentLocationResolver> baseInterface) public AddOnContentLocationResolver(ref readonly SharedRef<IAddOnContentLocationResolver> baseInterface)
{ {
_interface = SharedRef<IAddOnContentLocationResolver>.CreateMove(ref baseInterface); _interface = SharedRef<IAddOnContentLocationResolver>.CreateCopy(in baseInterface);
} }
public void Dispose() public void Dispose()

View File

@ -9,9 +9,9 @@ public class LocationResolver : IDisposable
{ {
private SharedRef<ILocationResolver> _interface; private SharedRef<ILocationResolver> _interface;
public LocationResolver(ref SharedRef<ILocationResolver> baseInterface) public LocationResolver(ref readonly SharedRef<ILocationResolver> baseInterface)
{ {
_interface = SharedRef<ILocationResolver>.CreateMove(ref baseInterface); _interface = SharedRef<ILocationResolver>.CreateCopy(in baseInterface);
} }
public void Dispose() public void Dispose()

View File

@ -8,9 +8,9 @@ public class RegisteredLocationResolver : IDisposable
{ {
private SharedRef<IRegisteredLocationResolver> _interface; private SharedRef<IRegisteredLocationResolver> _interface;
public RegisteredLocationResolver(ref SharedRef<IRegisteredLocationResolver> baseInterface) public RegisteredLocationResolver(ref readonly SharedRef<IRegisteredLocationResolver> baseInterface)
{ {
_interface = SharedRef<IRegisteredLocationResolver>.CreateMove(ref baseInterface); _interface = SharedRef<IRegisteredLocationResolver>.CreateCopy(in baseInterface);
} }
public void Dispose() public void Dispose()

View File

@ -24,9 +24,9 @@ internal class MmcDeviceOperator : IStorageDeviceOperator
// LibHac additions // LibHac additions
private readonly SdmmcApi _sdmmc; private readonly SdmmcApi _sdmmc;
public MmcDeviceOperator(ref SharedRef<MmcPartitionStorageDevice> storageDevice, SdmmcApi sdmmc) public MmcDeviceOperator(ref readonly SharedRef<MmcPartitionStorageDevice> storageDevice, SdmmcApi sdmmc)
{ {
_storageDevice = SharedRef<MmcPartitionStorageDevice>.CreateMove(ref storageDevice); _storageDevice = SharedRef<MmcPartitionStorageDevice>.CreateCopy(in storageDevice);
_sdmmc = sdmmc; _sdmmc = sdmmc;
} }

View File

@ -26,11 +26,11 @@ internal abstract class MmcPartitionStorageDevice : IDisposable
protected WeakRef<MmcPartitionStorageDevice> SelfReference; protected WeakRef<MmcPartitionStorageDevice> SelfReference;
protected readonly SdmmcApi Sdmmc; protected readonly SdmmcApi Sdmmc;
protected MmcPartitionStorageDevice(MmcPartition partition, ref SharedRef<ISdmmcDeviceManager> manager, protected MmcPartitionStorageDevice(MmcPartition partition, ref readonly SharedRef<ISdmmcDeviceManager> manager,
SdmmcHandle handle, SdmmcApi sdmmc) SdmmcHandle handle, SdmmcApi sdmmc)
{ {
_partition = partition; _partition = partition;
_manager = SharedRef<ISdmmcDeviceManager>.CreateMove(ref manager); _manager = SharedRef<ISdmmcDeviceManager>.CreateCopy(in manager);
_handle = handle; _handle = handle;
Sdmmc = sdmmc; Sdmmc = sdmmc;
} }
@ -101,8 +101,8 @@ internal abstract class MmcPartitionStorageDeviceInterfaceAdapter : MmcPartition
private readonly IStorage _baseStorage; private readonly IStorage _baseStorage;
protected MmcPartitionStorageDeviceInterfaceAdapter(IStorage baseStorage, MmcPartition partition, protected MmcPartitionStorageDeviceInterfaceAdapter(IStorage baseStorage, MmcPartition partition,
ref SharedRef<ISdmmcDeviceManager> manager, SdmmcHandle handle, SdmmcApi sdmmc) ref readonly SharedRef<ISdmmcDeviceManager> manager, SdmmcHandle handle, SdmmcApi sdmmc)
: base(partition, ref manager, handle, sdmmc) : base(partition, in manager, handle, sdmmc)
{ {
_baseStorage = baseStorage; _baseStorage = baseStorage;
} }
@ -148,14 +148,14 @@ internal abstract class MmcPartitionStorageDeviceInterfaceAdapter : MmcPartition
/// <remarks>Based on nnSdk 16.2.0 (FS 16.0.0)</remarks> /// <remarks>Based on nnSdk 16.2.0 (FS 16.0.0)</remarks>
internal class MmcUserDataPartitionStorageDevice : MmcPartitionStorageDeviceInterfaceAdapter internal class MmcUserDataPartitionStorageDevice : MmcPartitionStorageDeviceInterfaceAdapter
{ {
private MmcUserDataPartitionStorageDevice(ref SharedRef<ISdmmcDeviceManager> manager, SdmmcHandle handle, private MmcUserDataPartitionStorageDevice(ref readonly SharedRef<ISdmmcDeviceManager> manager, SdmmcHandle handle,
SdmmcApi sdmmc) 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<MmcUserDataPartitionStorageDevice> CreateShared(ref SharedRef<ISdmmcDeviceManager> manager, public static SharedRef<MmcUserDataPartitionStorageDevice> CreateShared(ref readonly SharedRef<ISdmmcDeviceManager> manager,
SdmmcHandle handle, SdmmcApi sdmmc) 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<MmcUserDataPartitionStorageDevice>(storageDevice); using var sharedStorageDevice = new SharedRef<MmcUserDataPartitionStorageDevice>(storageDevice);
storageDevice.SelfReference.Set(in sharedStorageDevice); storageDevice.SelfReference.Set(in sharedStorageDevice);
@ -212,14 +212,14 @@ internal class MmcUserDataPartitionStorageDevice : MmcPartitionStorageDeviceInte
/// <remarks>Based on nnSdk 16.2.0 (FS 16.0.0)</remarks> /// <remarks>Based on nnSdk 16.2.0 (FS 16.0.0)</remarks>
internal class MmcBootPartitionStorageDevice : MmcPartitionStorageDeviceInterfaceAdapter internal class MmcBootPartitionStorageDevice : MmcPartitionStorageDeviceInterfaceAdapter
{ {
private MmcBootPartitionStorageDevice(Fs.MmcPartition partition, ref SharedRef<ISdmmcDeviceManager> manager, private MmcBootPartitionStorageDevice(Fs.MmcPartition partition, ref readonly SharedRef<ISdmmcDeviceManager> manager,
SdmmcHandle handle, SdmmcApi sdmmc) 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<MmcBootPartitionStorageDevice> CreateShared(Fs.MmcPartition partition, public static SharedRef<MmcBootPartitionStorageDevice> CreateShared(Fs.MmcPartition partition,
ref SharedRef<ISdmmcDeviceManager> manager, SdmmcHandle handle, SdmmcApi sdmmc) ref readonly SharedRef<ISdmmcDeviceManager> 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<MmcBootPartitionStorageDevice>(storageDevice); using var sharedStorageDevice = new SharedRef<MmcBootPartitionStorageDevice>(storageDevice);
storageDevice.SelfReference.Set(in sharedStorageDevice); storageDevice.SelfReference.Set(in sharedStorageDevice);

View File

@ -21,9 +21,9 @@ internal class SdCardDeviceOperator : IStorageDeviceOperator
// LibHac additions // LibHac additions
private readonly SdmmcApi _sdmmc; private readonly SdmmcApi _sdmmc;
public SdCardDeviceOperator(ref SharedRef<SdCardStorageDevice> storageDevice, SdmmcApi sdmmc) public SdCardDeviceOperator(ref readonly SharedRef<SdCardStorageDevice> storageDevice, SdmmcApi sdmmc)
{ {
_storageDevice = SharedRef<SdCardStorageDevice>.CreateMove(ref storageDevice); _storageDevice = SharedRef<SdCardStorageDevice>.CreateCopy(in storageDevice);
_sdmmc = sdmmc; _sdmmc = sdmmc;
} }

View File

@ -20,18 +20,18 @@ internal class SdCardStorageDevice : SdmmcStorageInterfaceAdapter, IStorageDevic
private WeakRef<SdCardStorageDevice> _selfReference; private WeakRef<SdCardStorageDevice> _selfReference;
private readonly SdmmcApi _sdmmc; private readonly SdmmcApi _sdmmc;
private SdCardStorageDevice(ref SharedRef<ISdmmcDeviceManager> manager, SdmmcHandle handle, SdmmcApi sdmmc) private SdCardStorageDevice(ref readonly SharedRef<ISdmmcDeviceManager> manager, SdmmcHandle handle, SdmmcApi sdmmc)
: base(manager.Get.GetStorage()) : base(manager.Get.GetStorage())
{ {
_manager = SharedRef<ISdmmcDeviceManager>.CreateMove(ref manager); _manager = SharedRef<ISdmmcDeviceManager>.CreateCopy(in manager);
_handle = handle; _handle = handle;
_sdmmc = sdmmc; _sdmmc = sdmmc;
} }
public static SharedRef<SdCardStorageDevice> CreateShared(ref SharedRef<ISdmmcDeviceManager> manager, public static SharedRef<SdCardStorageDevice> CreateShared(ref readonly SharedRef<ISdmmcDeviceManager> manager,
SdmmcHandle handle, SdmmcApi sdmmc) 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<SdCardStorageDevice>(device); using var sharedDevice = new SharedRef<SdCardStorageDevice>(device);
device._selfReference.Set(in sharedDevice); device._selfReference.Set(in sharedDevice);

View File

@ -7,5 +7,5 @@ namespace LibHac.Sm;
// have at least some sort of service system for now // have at least some sort of service system for now
public interface IServiceObject : IDisposable public interface IServiceObject : IDisposable
{ {
Result GetServiceObject(ref SharedRef<IDisposable> serviceObject); Result GetServiceObject(ref SharedRef<IDisposable> outServiceObject);
} }

View File

@ -12,14 +12,14 @@ public class ServiceManagerClient
Server = server; Server = server;
} }
public Result GetService<T>(ref SharedRef<T> serviceObject, ReadOnlySpan<char> name) where T : class, IDisposable public Result GetService<T>(ref SharedRef<T> outServiceObject, ReadOnlySpan<char> name) where T : class, IDisposable
{ {
using var service = new SharedRef<IDisposable>(); using var service = new SharedRef<IDisposable>();
Result res = Server.GetService(ref service.Ref, ServiceName.Encode(name)); Result res = Server.GetService(ref service.Ref, ServiceName.Encode(name));
if (res.IsFailure()) return res.Miss(); if (res.IsFailure()) return res.Miss();
if (serviceObject.TryCastSet(ref service.Ref)) if (outServiceObject.TryCastSet(ref service.Ref))
{ {
return Result.Success; return Result.Success;
} }

View File

@ -33,11 +33,11 @@ public class SaveDataFileSystem : IFileSystem
private KeySet KeySet { get; } private KeySet KeySet { get; }
public SaveDataFileSystem(KeySet keySet, ref SharedRef<IStorage> storage, public SaveDataFileSystem(KeySet keySet, ref readonly SharedRef<IStorage> storage,
IntegrityCheckLevel integrityCheckLevel, bool leaveOpen) IntegrityCheckLevel integrityCheckLevel, bool leaveOpen)
: this(keySet, storage.Get, integrityCheckLevel, true) : this(keySet, storage.Get, integrityCheckLevel, true)
{ {
_baseStorageShared = SharedRef<IStorage>.CreateMove(ref storage); _baseStorageShared = SharedRef<IStorage>.CreateCopy(in storage);
} }
public SaveDataFileSystem(KeySet keySet, IStorage storage, IntegrityCheckLevel integrityCheckLevel, bool leaveOpen) public SaveDataFileSystem(KeySet keySet, IStorage storage, IntegrityCheckLevel integrityCheckLevel, bool leaveOpen)