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;
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()
@ -18,9 +18,9 @@ internal class BcatServiceObject : IServiceObject
_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;
}
}

View file

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

View file

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

View file

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

View file

@ -16,14 +16,14 @@ internal class StorageServiceObjectAdapter : IStorage
{
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()

View file

@ -28,7 +28,7 @@ public static class BaseFileSystem
ref SharedRef<IFileSystemSf> fileSystem)
{
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);
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="serviceObject">The service object this <see cref="FileSystemClient"/> will use.</param>
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;
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()
@ -91,9 +91,9 @@ internal class DirectoryServiceObjectAdapter : IDirectory
{
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()
@ -136,9 +136,9 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget
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()

View file

@ -26,9 +26,9 @@ namespace LibHac.Fs
private readonly FileSystemClient _fsClient;
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;
}

View file

@ -20,9 +20,9 @@ public class SaveDataChunkIterator : ISaveDataChunkIterator
// LibHac addition
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;
}
@ -69,9 +69,9 @@ public class SaveDataChunkExporter : ISaveDataChunkExporter
// LibHac addition
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;
}
@ -116,9 +116,9 @@ public class SaveDataChunkImporter : ISaveDataChunkImporter
// LibHac addition
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;
}
@ -150,9 +150,9 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter
private FileSystemClient _fsClient;
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;
}
@ -329,9 +329,9 @@ public class SaveDataImporterVersion2 : ISaveDataDivisionImporter
private FileSystemClient _fsClient;
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;
}

View file

@ -266,9 +266,9 @@ namespace LibHac.Fs
{
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()

View file

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

View file

@ -262,8 +262,7 @@ public readonly struct BaseFileSystemService
return Result.Success;
}
public Result OpenImageDirectoryFileSystem(ref SharedRef<IFileSystemSf> outFileSystem,
ImageDirectoryId directoryId)
public Result OpenImageDirectoryFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, ImageDirectoryId directoryId)
{
// Caller must have the MountImageAndVideoStorage permission
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();
}
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)
{
Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService);
if (res.IsFailure()) return res.Miss();
return ncaFsService.OpenCodeFileSystem(ref fileSystem, outVerificationData, in path, attributes, programId).Ret();
return ncaFsService.OpenCodeFileSystem(ref outFileSystem, outVerificationData, in path, attributes, programId).Ret();
}
public Result SetCurrentProcess(ulong processId)

View file

@ -210,10 +210,10 @@ public static class FileSystemServerInitializer
_server = server;
}
public Result GetServiceObject(ref SharedRef<IDisposable> serviceObject)
public Result GetServiceObject(ref SharedRef<IDisposable> outServiceObject)
{
using SharedRef<IFileSystemProxy> derivedObject = _server.Impl.GetFileSystemProxyServiceObject();
serviceObject.SetByMove(ref derivedObject.Ref);
outServiceObject.SetByMove(ref derivedObject.Ref);
return Result.Success;
}
@ -229,10 +229,10 @@ public static class FileSystemServerInitializer
_server = server;
}
public Result GetServiceObject(ref SharedRef<IDisposable> serviceObject)
public Result GetServiceObject(ref SharedRef<IDisposable> outServiceObject)
{
using SharedRef<IFileSystemProxyForLoader> derivedObject = _server.Impl.GetFileSystemProxyForLoaderServiceObject();
serviceObject.SetByMove(ref derivedObject.Ref);
outServiceObject.SetByMove(ref derivedObject.Ref);
return Result.Success;
}
@ -248,10 +248,10 @@ public static class FileSystemServerInitializer
_server = server;
}
public Result GetServiceObject(ref SharedRef<IDisposable> serviceObject)
public Result GetServiceObject(ref SharedRef<IDisposable> outServiceObject)
{
using SharedRef<IProgramRegistry> derivedObject = _server.Impl.GetProgramRegistryServiceObject();
serviceObject.SetByMove(ref derivedObject.Ref);
outServiceObject.SetByMove(ref derivedObject.Ref);
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.
/// </summary>
/// <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.SetRootFileSystem(ref rootFileSystem).ThrowIfFailure();
Config.SetRootFileSystem(in rootFileSystem).ThrowIfFailure();
}
/// <summary>

View file

@ -18,12 +18,12 @@ public class EmulatedBisFileSystemCreatorConfig
private SharedRef<IFileSystem>[] PartitionFileSystems { get; } = new SharedRef<IFileSystem>[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 (_rootFileSystem.HasValue) return ResultFs.PreconditionViolation.Log();
_rootFileSystem.SetByMove(ref fileSystem);
_rootFileSystem.SetByCopy(in fileSystem);
return Result.Success;
}

View file

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

View file

@ -31,13 +31,13 @@ public class FatFileSystemCreator : IFatFileSystemCreator
// 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)
{
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)
{
throw new NotImplementedException();

View file

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

View file

@ -7,9 +7,9 @@ namespace LibHac.FsSrv.FsCreator;
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);
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);
}

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 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,
bool isJournalingSupported, bool isMultiCommitSupported, bool openReadOnly, bool openShared,
ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible);

View file

@ -313,7 +313,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator
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,
bool isJournalingSupported, bool isMultiCommitSupported, bool openReadOnly, bool openShared,
ISaveDataCommitTimeStampGetter timeStampGetter, bool isReconstructible)
@ -345,7 +345,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator
}
// Get a file system over the save directory
using var baseFs = new UniqueRef<SubdirectoryFileSystem>(new SubdirectoryFileSystem(ref baseFileSystem));
using var baseFs = new UniqueRef<SubdirectoryFileSystem>(new SubdirectoryFileSystem(in baseFileSystem));
if (!baseFs.HasValue)
return ResultFs.AllocationMemoryFailedInSaveDataFileSystemCreatorA.Log();
@ -374,7 +374,7 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator
Optional<OpenType> 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);
if (res.IsFailure()) return res.Miss();

View file

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

View file

@ -10,17 +10,17 @@ public class DeepRetryFileSystem : ForwardingFileSystem
private WeakRef<DeepRetryFileSystem> _selfReference;
private SharedRef<IRomFileSystemAccessFailureManager> _accessFailureManager;
protected DeepRetryFileSystem(ref SharedRef<IFileSystem> baseFileSystem,
ref SharedRef<IRomFileSystemAccessFailureManager> accessFailureManager) : base(ref baseFileSystem)
protected DeepRetryFileSystem(ref readonly SharedRef<IFileSystem> 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,
ref SharedRef<IRomFileSystemAccessFailureManager> accessFailureManager)
public static SharedRef<IFileSystem> CreateShared(ref readonly SharedRef<IFileSystem> baseFileSystem,
ref readonly SharedRef<IRomFileSystemAccessFailureManager> accessFailureManager)
{
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);

View file

@ -14,9 +14,9 @@ internal class DeviceEventSimulationStorage : IStorage
private SharedRef<IStorage> _baseStorage;
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;
}

View file

@ -27,9 +27,9 @@ public class FileInterfaceAdapter : IFileSf
private bool _allowAllOperations;
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);
_allowAllOperations = allowAllOperations;
}
@ -187,9 +187,9 @@ public class DirectoryInterfaceAdapter : IDirectorySf
private 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);
}
@ -251,24 +251,24 @@ public class FileSystemInterfaceAdapter : IFileSystemSf
// creating files and directories. We don't have an ISharedObject, so a self-reference is used instead.
private WeakRef<FileSystemInterfaceAdapter> _selfReference;
private FileSystemInterfaceAdapter(ref SharedRef<IFileSystem> fileSystem,
private FileSystemInterfaceAdapter(ref readonly SharedRef<IFileSystem> fileSystem,
bool allowAllOperations)
{
_baseFileSystem = SharedRef<IFileSystem>.CreateMove(ref fileSystem);
_baseFileSystem = SharedRef<IFileSystem>.CreateCopy(in fileSystem);
_allowAllOperations = allowAllOperations;
}
private FileSystemInterfaceAdapter(ref SharedRef<IFileSystem> fileSystem, PathFlags flags,
private FileSystemInterfaceAdapter(ref readonly SharedRef<IFileSystem> fileSystem, PathFlags flags,
bool allowAllOperations)
{
_baseFileSystem = SharedRef<IFileSystem>.CreateMove(ref fileSystem);
_baseFileSystem = SharedRef<IFileSystem>.CreateCopy(in fileSystem);
_pathFlags = flags;
_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);
adapter._selfReference.Set(in sharedAdapter);
@ -277,9 +277,9 @@ public class FileSystemInterfaceAdapter : IFileSystemSf
}
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);
adapter._selfReference.Set(in sharedAdapter);
@ -605,9 +605,9 @@ public class FileSystemInterfaceAdapter : IFileSystemSf
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;
}
}

View file

@ -47,7 +47,7 @@ public static class FileSystemProxyServiceObject
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)
{
return ResultFs.PortAcceptableCountLimited.Log();

View file

@ -66,20 +66,20 @@ internal class MultiCommitManager : IMultiCommitManager
private readonly FileSystemServer _fsServer;
private ref MultiCommitManagerGlobals Globals => ref _fsServer.Globals.MultiCommitManager;
public MultiCommitManager(FileSystemServer fsServer, ref SharedRef<ISaveDataMultiCommitCoreInterface> multiCommitInterface)
public MultiCommitManager(FileSystemServer fsServer, ref readonly SharedRef<ISaveDataMultiCommitCoreInterface> multiCommitInterface)
{
_fsServer = fsServer;
_multiCommitInterface = SharedRef<ISaveDataMultiCommitCoreInterface>.CreateMove(ref multiCommitInterface);
_multiCommitInterface = SharedRef<ISaveDataMultiCommitCoreInterface>.CreateCopy(in multiCommitInterface);
_fileSystems = new SharedRef<IFileSystem>[MaxFileSystemCount];
_fileSystemCount = 0;
_counter = 0;
}
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()
@ -121,7 +121,7 @@ internal class MultiCommitManager : IMultiCommitManager
/// <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="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)
return ResultFs.MultiCommitFileSystemLimit.Log();

View file

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

View file

@ -36,9 +36,9 @@ public class SaveDataFileSystemCacheManager : IDisposable
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;
_saveDataId = saveDataId;
}

View file

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

View file

@ -16,9 +16,9 @@ public class StorageInterfaceAdapter : IStorageSf
{
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()

View file

@ -16,11 +16,11 @@ internal static class Utility
}
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())
{
outSubDirFileSystem.SetByMove(ref baseFileSystem);
outSubDirFileSystem.SetByCopy(in baseFileSystem);
return Result.Success;
}
@ -31,7 +31,7 @@ internal static class Utility
dir.Reset();
using var fs = new SharedRef<SubdirectoryFileSystem>(new SubdirectoryFileSystem(ref baseFileSystem));
using var fs = new SharedRef<SubdirectoryFileSystem>(new SubdirectoryFileSystem(in baseFileSystem));
if (!fs.HasValue)
return ResultFs.AllocationMemoryFailedInSubDirectoryFileSystemCreatorA.Log();
@ -44,7 +44,7 @@ internal static class Utility
}
public static Result WrapSubDirectory(ref SharedRef<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
if (!createIfMissing)
@ -57,7 +57,7 @@ internal static class Utility
Result res = FsSystem.Utility.EnsureDirectory(baseFileSystem.Get, in rootPath);
if (res.IsFailure()) return res.Miss();
return CreateSubDirectoryFileSystem(ref outFileSystem, ref baseFileSystem, in rootPath);
return CreateSubDirectoryFileSystem(ref outFileSystem, in baseFileSystem, in rootPath);
}
public static long ConvertZeroCommitId(in SaveDataExtraData extraData)

View file

@ -1825,16 +1825,16 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave
openReadOnly).Ret();
}
public Result OpenSaveDataFileSystem(ref SharedRef<IFileSystemSf> fileSystem, SaveDataSpaceId spaceId,
public Result OpenSaveDataFileSystem(ref SharedRef<IFileSystemSf> outFileSystem, SaveDataSpaceId spaceId,
in SaveDataAttribute attribute)
{
return OpenUserSaveDataFileSystem(ref fileSystem, spaceId, in attribute, openReadOnly: false).Ret();
return OpenUserSaveDataFileSystem(ref outFileSystem, spaceId, in attribute, openReadOnly: false).Ret();
}
public Result OpenReadOnlySaveDataFileSystem(ref SharedRef<IFileSystemSf> fileSystem, SaveDataSpaceId spaceId,
public Result OpenReadOnlySaveDataFileSystem(ref SharedRef<IFileSystemSf> outGileSystem, SaveDataSpaceId spaceId,
in SaveDataAttribute attribute)
{
return OpenUserSaveDataFileSystem(ref fileSystem, spaceId, in attribute, openReadOnly: true).Ret();
return OpenUserSaveDataFileSystem(ref outGileSystem, spaceId, in attribute, openReadOnly: true).Ret();
}
public Result OpenSaveDataFileSystemBySystemSaveDataId(ref SharedRef<IFileSystemSf> outFileSystem,

View file

@ -299,7 +299,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
bool openShared = SaveDataProperties.IsSharedOpenNeeded(type);
bool isReconstructible = SaveDataProperties.IsReconstructible(type, spaceId);
res = _config.SaveFsCreator.Create(ref saveDataFs.Ref, ref fileSystem.Ref, spaceId, saveDataId,
res = _config.SaveFsCreator.Create(ref saveDataFs.Ref, fileSystem.Ref, spaceId, saveDataId,
isEmulatedOnHost, isDeviceUniqueMac, isJournalingSupported, isMultiCommitSupported,
openReadOnly, openShared, _timeStampGetter, isReconstructible);
if (res.IsFailure()) return res.Miss();

View file

@ -116,9 +116,9 @@ internal class SaveDataInfoFilterReader : SaveDataInfoReaderImpl
private SharedRef<SaveDataInfoReaderImpl> _reader;
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;
}

View file

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

View file

@ -10,7 +10,7 @@ namespace LibHac.FsSrv.Sf;
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 DeleteFile(ref readonly Path path);
Result CreateDirectory(ref readonly Path path);

View file

@ -9,7 +9,7 @@ namespace LibHac.FsSrv.Sf;
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);
Result IsArchivedProgram(out bool isArchived, ulong processId);

View file

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

View file

@ -9,9 +9,9 @@ public class SpeedEmulationStorage : IStorage
{
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()

View file

@ -57,10 +57,10 @@ public class AesXtsStorage : IStorage
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)
{
_baseStorageShared = SharedRef<IStorage>.CreateMove(ref baseStorage);
_baseStorageShared = SharedRef<IStorage>.CreateCopy(in baseStorage);
_baseStorage = _baseStorageShared.Get;
_blockSize = blockSize;
_mutex = new SdkMutexType();

View file

@ -105,7 +105,7 @@ public class AlignmentMatchingFile : ForwardingFile
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)
{

View file

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

View file

@ -78,9 +78,9 @@ public class ForwardingFileSystem : IFileSystem
{
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()

View file

@ -106,9 +106,9 @@ public abstract class IResultConvertFileSystem<T> : ISaveDataFileSystem where T
{
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()

View file

@ -11,10 +11,10 @@ public class UniqueLockWithPin<T> : IUniqueLock where T : class, IDisposable
private UniqueLock<SemaphoreAdapter> _semaphore;
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);
_pinnedObject = SharedRef<T>.CreateMove(ref pinnedObject);
_pinnedObject = SharedRef<T>.CreateCopy(in pinnedObject);
}
public void Dispose()

View file

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

View file

@ -233,7 +233,7 @@ public class NcaFileSystemDriver : IDisposable
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)
{
throw new NotImplementedException();
@ -269,7 +269,7 @@ public class NcaFileSystemDriver : IDisposable
}
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,
in NcaAesCtrUpperIv upperIv, in NcaSparseInfo sparseInfo, in NcaMetaDataHashDataInfo metaDataHashDataInfo,
NcaFsHeader.MetaDataHashType metaDataHashType)

View file

@ -23,10 +23,10 @@ public class ReadOnlyBlockCacheStorage : IStorage
private SharedRef<IStorage> _baseStorage;
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)
{
_baseStorage = SharedRef<IStorage>.CreateMove(ref baseStorage);
_baseStorage = SharedRef<IStorage>.CreateCopy(in baseStorage);
_blockSize = blockSize;
_blockCache = new BlockCache();
_mutex = new SdkMutexType();

View file

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

View file

@ -128,10 +128,10 @@ internal class StorageLayoutTypeSetFile : IFile
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;
_baseFileShared = SharedRef<IFile>.CreateMove(ref baseFile);
_baseFileShared = SharedRef<IFile>.CreateCopy(in baseFile);
_storageFlag = storageFlag;
Assert.SdkAssert(StorageLayoutTypeFunctions.IsStorageFlagValid(storageFlag));
@ -235,9 +235,9 @@ internal class StorageLayoutTypeSetFileSystem : IFileSystem
private SharedRef<IFileSystem> _baseFileSystem;
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;
Assert.SdkAssert(StorageLayoutTypeFunctions.IsStorageFlagValid(storageFlag));

View file

@ -488,13 +488,13 @@ internal static class Utility
}
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>();
Result res = TryAcquireCountSemaphore(ref semaphoreAdapter.Ref(), semaphore);
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);
outUniqueLock.Set(ref uniqueLock.Ref);

View file

@ -22,9 +22,9 @@ internal class ReadOnlyGameCardStorage : IStorage
// LibHac additions
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;
}
@ -105,9 +105,9 @@ internal class WriteOnlyGameCardStorage : IStorage
// LibHac additions
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;
}

View file

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

View file

@ -9,9 +9,9 @@ public class AddOnContentLocationResolver : IDisposable
{
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()

View file

@ -9,9 +9,9 @@ public class LocationResolver : IDisposable
{
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()

View file

@ -8,9 +8,9 @@ public class RegisteredLocationResolver : IDisposable
{
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()

View file

@ -24,9 +24,9 @@ internal class MmcDeviceOperator : IStorageDeviceOperator
// LibHac additions
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;
}

View file

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

View file

@ -21,9 +21,9 @@ internal class SdCardDeviceOperator : IStorageDeviceOperator
// LibHac additions
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;
}

View file

@ -20,18 +20,18 @@ internal class SdCardStorageDevice : SdmmcStorageInterfaceAdapter, IStorageDevic
private WeakRef<SdCardStorageDevice> _selfReference;
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())
{
_manager = SharedRef<ISdmmcDeviceManager>.CreateMove(ref manager);
_manager = SharedRef<ISdmmcDeviceManager>.CreateCopy(in manager);
_handle = handle;
_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)
{
var device = new SdCardStorageDevice(ref manager, handle, sdmmc);
var device = new SdCardStorageDevice(in manager, handle, sdmmc);
using var sharedDevice = new SharedRef<SdCardStorageDevice>(device);
device._selfReference.Set(in sharedDevice);

View file

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

View file

@ -12,14 +12,14 @@ public class ServiceManagerClient
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>();
Result res = Server.GetService(ref service.Ref, ServiceName.Encode(name));
if (res.IsFailure()) return res.Miss();
if (serviceObject.TryCastSet(ref service.Ref))
if (outServiceObject.TryCastSet(ref service.Ref))
{
return Result.Success;
}

View file

@ -33,11 +33,11 @@ public class SaveDataFileSystem : IFileSystem
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)
: 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)