mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2025-02-09 13:14:46 +01:00
Use "in" instead of "ref" where appropriate in SharedRef<T>
This commit is contained in:
parent
770cd222f1
commit
f9f31056ef
@ -59,7 +59,7 @@ namespace LibHac.Bcat
|
|||||||
{
|
{
|
||||||
Debug.Assert((uint)type < ServiceTypeCount);
|
Debug.Assert((uint)type < ServiceTypeCount);
|
||||||
|
|
||||||
return SharedRef<IServiceCreator>.CreateCopy(ref _serviceCreators[(int)type]);
|
return SharedRef<IServiceCreator>.CreateCopy(in _serviceCreators[(int)type]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ namespace LibHac.Bcat.Impl.Ipc
|
|||||||
|
|
||||||
public Result GetServiceObject(ref SharedRef<IDisposable> serviceObject)
|
public Result GetServiceObject(ref SharedRef<IDisposable> serviceObject)
|
||||||
{
|
{
|
||||||
serviceObject.SetByCopy(ref _serviceCreator);
|
serviceObject.SetByCopy(in _serviceCreator);
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,7 +81,10 @@ namespace LibHac.Boot
|
|||||||
private const int ModernStage1Size = 0x7000;
|
private const int ModernStage1Size = 0x7000;
|
||||||
private const int MarikoWarmBootPlainTextSectionSize = 0x330;
|
private const int MarikoWarmBootPlainTextSectionSize = 0x330;
|
||||||
|
|
||||||
private IStorage BaseStorage { get; set; }
|
private SharedRef<IStorage> _baseStorage;
|
||||||
|
private SubStorage _pk11Storage;
|
||||||
|
private SubStorage _bodyStorage;
|
||||||
|
|
||||||
private KeySet KeySet { get; set; }
|
private KeySet KeySet { get; set; }
|
||||||
|
|
||||||
public bool IsModern { get; private set; }
|
public bool IsModern { get; private set; }
|
||||||
@ -94,8 +97,6 @@ namespace LibHac.Boot
|
|||||||
public byte KeyRevision { get; private set; }
|
public byte KeyRevision { get; private set; }
|
||||||
|
|
||||||
public int Pk11Size { get; private set; }
|
public int Pk11Size { get; private set; }
|
||||||
private IStorage Pk11Storage { get; set; }
|
|
||||||
private IStorage BodyStorage { get; set; }
|
|
||||||
|
|
||||||
private Package1MarikoOemHeader _marikoOemHeader;
|
private Package1MarikoOemHeader _marikoOemHeader;
|
||||||
private Package1MetaData _metaData;
|
private Package1MetaData _metaData;
|
||||||
@ -109,13 +110,13 @@ namespace LibHac.Boot
|
|||||||
public ref readonly Package1Pk11Header Pk11Header => ref _pk11Header;
|
public ref readonly Package1Pk11Header Pk11Header => ref _pk11Header;
|
||||||
public ref readonly Buffer16 Pk11Mac => ref _pk11Mac;
|
public ref readonly Buffer16 Pk11Mac => ref _pk11Mac;
|
||||||
|
|
||||||
public Result Initialize(KeySet keySet, IStorage storage)
|
public Result Initialize(KeySet keySet, in SharedRef<IStorage> storage)
|
||||||
{
|
{
|
||||||
KeySet = keySet;
|
KeySet = keySet;
|
||||||
BaseStorage = storage;
|
_baseStorage.SetByCopy(in storage);
|
||||||
|
|
||||||
// Read what might be a mariko header and check if it actually is a mariko header
|
// Read what might be a mariko header and check if it actually is a mariko header
|
||||||
Result rc = BaseStorage.Read(0, SpanHelpers.AsByteSpan(ref _marikoOemHeader));
|
Result rc = _baseStorage.Get.Read(0, SpanHelpers.AsByteSpan(ref _marikoOemHeader));
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
IsMariko = IsMarikoImpl();
|
IsMariko = IsMarikoImpl();
|
||||||
@ -127,8 +128,11 @@ namespace LibHac.Boot
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BodyStorage = BaseStorage;
|
rc = _baseStorage.Get.GetSize(out long baseStorageSize);
|
||||||
rc = BodyStorage.Read(0, SpanHelpers.AsByteSpan(ref _metaData));
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
|
|
||||||
|
_bodyStorage = new SubStorage(in _baseStorage, 0, baseStorageSize);
|
||||||
|
rc = _bodyStorage.Read(0, SpanHelpers.AsByteSpan(ref _metaData));
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +173,7 @@ namespace LibHac.Boot
|
|||||||
return ResultLibHac.InvalidPackage1MarikoBodySize.Log();
|
return ResultLibHac.InvalidPackage1MarikoBodySize.Log();
|
||||||
|
|
||||||
// Verify the body storage size is not smaller than the size in the header
|
// Verify the body storage size is not smaller than the size in the header
|
||||||
Result rc = BaseStorage.GetSize(out long totalSize);
|
Result rc = _baseStorage.Get.GetSize(out long totalSize);
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
long bodySize = totalSize - Unsafe.SizeOf<Package1MarikoOemHeader>();
|
long bodySize = totalSize - Unsafe.SizeOf<Package1MarikoOemHeader>();
|
||||||
@ -177,7 +181,7 @@ namespace LibHac.Boot
|
|||||||
return ResultLibHac.InvalidPackage1MarikoBodySize.Log();
|
return ResultLibHac.InvalidPackage1MarikoBodySize.Log();
|
||||||
|
|
||||||
// Create body SubStorage and metadata buffers
|
// Create body SubStorage and metadata buffers
|
||||||
var bodySubStorage = new SubStorage(BaseStorage, Unsafe.SizeOf<Package1MarikoOemHeader>(), bodySize);
|
var bodySubStorage = new SubStorage(in _baseStorage, Unsafe.SizeOf<Package1MarikoOemHeader>(), bodySize);
|
||||||
|
|
||||||
Span<Package1MetaData> metaData = stackalloc Package1MetaData[2];
|
Span<Package1MetaData> metaData = stackalloc Package1MetaData[2];
|
||||||
Span<byte> metaData1 = SpanHelpers.AsByteSpan(ref metaData[0]);
|
Span<byte> metaData1 = SpanHelpers.AsByteSpan(ref metaData[0]);
|
||||||
@ -189,7 +193,7 @@ namespace LibHac.Boot
|
|||||||
|
|
||||||
// Set the body storage and decrypted metadata
|
// Set the body storage and decrypted metadata
|
||||||
_metaData = metaData[0];
|
_metaData = metaData[0];
|
||||||
BodyStorage = bodySubStorage;
|
_bodyStorage = bodySubStorage;
|
||||||
|
|
||||||
// The plaintext metadata is followed by an encrypted copy
|
// The plaintext metadata is followed by an encrypted copy
|
||||||
// If these two match then the body is already decrypted
|
// If these two match then the body is already decrypted
|
||||||
@ -208,7 +212,8 @@ namespace LibHac.Boot
|
|||||||
if (IsDecrypted)
|
if (IsDecrypted)
|
||||||
{
|
{
|
||||||
var decStorage = new AesCbcStorage(bodySubStorage, KeySet.MarikoBek, _metaData.Iv, true);
|
var decStorage = new AesCbcStorage(bodySubStorage, KeySet.MarikoBek, _metaData.Iv, true);
|
||||||
BodyStorage = new CachedStorage(decStorage, 0x4000, 1, true);
|
var cachedStorage = new CachedStorage(decStorage, 0x4000, 1, true);
|
||||||
|
_bodyStorage = new SubStorage(cachedStorage, 0, bodySize);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
@ -236,7 +241,7 @@ namespace LibHac.Boot
|
|||||||
// Read the package1ldr footer
|
// Read the package1ldr footer
|
||||||
int footerOffset = stage1Size - Unsafe.SizeOf<Package1Stage1Footer>();
|
int footerOffset = stage1Size - Unsafe.SizeOf<Package1Stage1Footer>();
|
||||||
|
|
||||||
Result rc = BodyStorage.Read(footerOffset, SpanHelpers.AsByteSpan(ref _stage1Footer));
|
Result rc = _bodyStorage.Read(footerOffset, SpanHelpers.AsByteSpan(ref _stage1Footer));
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
// Get the PK11 size from the field in the unencrypted stage 1 footer
|
// Get the PK11 size from the field in the unencrypted stage 1 footer
|
||||||
@ -249,12 +254,12 @@ namespace LibHac.Boot
|
|||||||
{
|
{
|
||||||
int pk11Offset = IsModern ? ModernStage1Size : LegacyStage1Size;
|
int pk11Offset = IsModern ? ModernStage1Size : LegacyStage1Size;
|
||||||
|
|
||||||
return BodyStorage.Read(pk11Offset, SpanHelpers.AsByteSpan(ref _pk11Header));
|
return _bodyStorage.Read(pk11Offset, SpanHelpers.AsByteSpan(ref _pk11Header));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Result ReadModernEristaMac()
|
private Result ReadModernEristaMac()
|
||||||
{
|
{
|
||||||
return BaseStorage.Read(ModernStage1Size + Pk11Size, _pk11Mac.Bytes);
|
return _baseStorage.Get.Read(ModernStage1Size + Pk11Size, _pk11Mac.Bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Result SetPk11Storage()
|
private Result SetPk11Storage()
|
||||||
@ -262,7 +267,7 @@ namespace LibHac.Boot
|
|||||||
// Read the PK11 header from the body storage
|
// Read the PK11 header from the body storage
|
||||||
int pk11Offset = IsModern ? ModernStage1Size : LegacyStage1Size;
|
int pk11Offset = IsModern ? ModernStage1Size : LegacyStage1Size;
|
||||||
|
|
||||||
Result rc = BodyStorage.Read(pk11Offset, SpanHelpers.AsByteSpan(ref _pk11Header));
|
Result rc = _bodyStorage.Read(pk11Offset, SpanHelpers.AsByteSpan(ref _pk11Header));
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
// Check if PK11 is already decrypted, creating the PK11 storage if it is
|
// Check if PK11 is already decrypted, creating the PK11 storage if it is
|
||||||
@ -270,11 +275,11 @@ namespace LibHac.Boot
|
|||||||
|
|
||||||
if (IsDecrypted)
|
if (IsDecrypted)
|
||||||
{
|
{
|
||||||
Pk11Storage = new SubStorage(BodyStorage, pk11Offset, Pk11Size);
|
_pk11Storage = new SubStorage(_bodyStorage, pk11Offset, Pk11Size);
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
var encPk11Storage = new SubStorage(BodyStorage, pk11Offset, Pk11Size);
|
var encPk11Storage = new SubStorage(_bodyStorage, pk11Offset, Pk11Size);
|
||||||
|
|
||||||
// See if we have an Erista package1 key that can decrypt this PK11
|
// See if we have an Erista package1 key that can decrypt this PK11
|
||||||
if (!IsMariko && TryFindEristaKeyRevision())
|
if (!IsMariko && TryFindEristaKeyRevision())
|
||||||
@ -293,13 +298,13 @@ namespace LibHac.Boot
|
|||||||
KeySet.Package1Keys[KeyRevision].DataRo.ToArray(), _stage1Footer.Iv.ToArray(), true);
|
KeySet.Package1Keys[KeyRevision].DataRo.ToArray(), _stage1Footer.Iv.ToArray(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Pk11Storage = new CachedStorage(decPk11Storage, 0x4000, 1, true);
|
_pk11Storage = new SubStorage(new CachedStorage(decPk11Storage, 0x4000, 1, true), 0, Pk11Size);
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We can't decrypt the PK11. Set Pk11Storage to the encrypted PK11 storage
|
// We can't decrypt the PK11. Set Pk11Storage to the encrypted PK11 storage
|
||||||
Pk11Storage = encPk11Storage;
|
_pk11Storage = encPk11Storage;
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,15 +380,15 @@ namespace LibHac.Boot
|
|||||||
|
|
||||||
// The metadata at the start of the body is unencrypted, so don't take its data from the decrypted
|
// The metadata at the start of the body is unencrypted, so don't take its data from the decrypted
|
||||||
// body storage
|
// body storage
|
||||||
storages.Add(new SubStorage(BaseStorage, 0, Unsafe.SizeOf<Package1MarikoOemHeader>() + metaSize));
|
storages.Add(new SubStorage(in _baseStorage, 0, Unsafe.SizeOf<Package1MarikoOemHeader>() + metaSize));
|
||||||
storages.Add(new SubStorage(BodyStorage, metaSize, _marikoOemHeader.Size - metaSize));
|
storages.Add(new SubStorage(_bodyStorage, metaSize, _marikoOemHeader.Size - metaSize));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int stage1Size = IsModern ? ModernStage1Size : LegacyStage1Size;
|
int stage1Size = IsModern ? ModernStage1Size : LegacyStage1Size;
|
||||||
|
|
||||||
storages.Add(new SubStorage(BaseStorage, 0, stage1Size));
|
storages.Add(new SubStorage(in _baseStorage, 0, stage1Size));
|
||||||
storages.Add(Pk11Storage);
|
storages.Add(_pk11Storage);
|
||||||
|
|
||||||
if (IsModern)
|
if (IsModern)
|
||||||
{
|
{
|
||||||
@ -429,7 +434,7 @@ namespace LibHac.Boot
|
|||||||
int offset = Unsafe.SizeOf<Package1Pk11Header>() + GetSectionOffset(sectionType);
|
int offset = Unsafe.SizeOf<Package1Pk11Header>() + GetSectionOffset(sectionType);
|
||||||
int size = GetSectionSize(sectionType);
|
int size = GetSectionSize(sectionType);
|
||||||
|
|
||||||
return new SubStorage(Pk11Storage, offset, size);
|
return new SubStorage(_pk11Storage, offset, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -156,11 +156,11 @@ namespace LibHac.Common
|
|||||||
return sharedRef;
|
return sharedRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SharedRef<T> CreateCopy<TFrom>(ref SharedRef<TFrom> other) where TFrom : class, T
|
public static SharedRef<T> CreateCopy<TFrom>(in SharedRef<TFrom> other) where TFrom : class, T
|
||||||
{
|
{
|
||||||
var sharedRef = new SharedRef<T>();
|
var sharedRef = new SharedRef<T>();
|
||||||
|
|
||||||
sharedRef._value = Unsafe.As<TFrom, T>(ref other._value);
|
sharedRef._value = Unsafe.As<TFrom, T>(ref other.Ref()._value);
|
||||||
sharedRef._refCount = other._refCount;
|
sharedRef._refCount = other._refCount;
|
||||||
|
|
||||||
sharedRef._refCount?.Increment();
|
sharedRef._refCount?.Increment();
|
||||||
@ -168,9 +168,9 @@ namespace LibHac.Common
|
|||||||
return sharedRef;
|
return sharedRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SharedRef<T> Create<TFrom>(ref WeakRef<TFrom> other) where TFrom : class, T
|
public static SharedRef<T> Create<TFrom>(in WeakRef<TFrom> other) where TFrom : class, T
|
||||||
{
|
{
|
||||||
ref SharedRef<TFrom> otherShared = ref Unsafe.As<WeakRef<TFrom>, SharedRef<TFrom>>(ref other);
|
ref SharedRef<TFrom> otherShared = ref Unsafe.As<WeakRef<TFrom>, SharedRef<TFrom>>(ref other.Ref());
|
||||||
|
|
||||||
var sharedRef = new SharedRef<T>();
|
var sharedRef = new SharedRef<T>();
|
||||||
|
|
||||||
@ -244,14 +244,14 @@ namespace LibHac.Common
|
|||||||
oldRefCount?.Decrement();
|
oldRefCount?.Decrement();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetByCopy<TFrom>(ref SharedRef<TFrom> other) where TFrom : class, T
|
public void SetByCopy<TFrom>(in SharedRef<TFrom> other) where TFrom : class, T
|
||||||
{
|
{
|
||||||
RefCount oldRefCount = _refCount;
|
RefCount oldRefCount = _refCount;
|
||||||
RefCount otherRef = other._refCount;
|
RefCount otherRef = other._refCount;
|
||||||
|
|
||||||
otherRef?.Increment();
|
otherRef?.Increment();
|
||||||
|
|
||||||
_value = Unsafe.As<TFrom, T>(ref other._value);
|
_value = Unsafe.As<TFrom, T>(ref other.Ref()._value);
|
||||||
_refCount = otherRef;
|
_refCount = otherRef;
|
||||||
|
|
||||||
oldRefCount?.Decrement();
|
oldRefCount?.Decrement();
|
||||||
@ -309,9 +309,9 @@ namespace LibHac.Common
|
|||||||
private T _value;
|
private T _value;
|
||||||
private RefCount _refCount;
|
private RefCount _refCount;
|
||||||
|
|
||||||
public WeakRef(ref SharedRef<T> other)
|
public WeakRef(in SharedRef<T> other)
|
||||||
{
|
{
|
||||||
this = Create(ref other);
|
this = Create(in other);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Obsolete("This method should never be manually called. Use the Destroy method instead.", true)]
|
[Obsolete("This method should never be manually called. Use the Destroy method instead.", true)]
|
||||||
@ -350,7 +350,7 @@ namespace LibHac.Common
|
|||||||
return weakRef;
|
return weakRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WeakRef<T> CreateCopy<TFrom>(ref WeakRef<TFrom> other) where TFrom : class, T
|
public static WeakRef<T> CreateCopy<TFrom>(in WeakRef<TFrom> other) where TFrom : class, T
|
||||||
{
|
{
|
||||||
var weakRef = new WeakRef<T>();
|
var weakRef = new WeakRef<T>();
|
||||||
|
|
||||||
@ -361,7 +361,7 @@ namespace LibHac.Common
|
|||||||
|
|
||||||
if (weakRef._refCount.IncrementIfNotZero())
|
if (weakRef._refCount.IncrementIfNotZero())
|
||||||
{
|
{
|
||||||
weakRef._value = Unsafe.As<TFrom, T>(ref other._value);
|
weakRef._value = Unsafe.As<TFrom, T>(ref other.Ref()._value);
|
||||||
weakRef._refCount.Decrement();
|
weakRef._refCount.Decrement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -369,9 +369,9 @@ namespace LibHac.Common
|
|||||||
return weakRef;
|
return weakRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static WeakRef<T> Create<TFrom>(ref SharedRef<TFrom> other) where TFrom : class, T
|
public static WeakRef<T> Create<TFrom>(in SharedRef<TFrom> other) where TFrom : class, T
|
||||||
{
|
{
|
||||||
ref WeakRef<TFrom> otherWeak = ref Unsafe.As<SharedRef<TFrom>, WeakRef<TFrom>>(ref other);
|
ref WeakRef<TFrom> otherWeak = ref Unsafe.As<SharedRef<TFrom>, WeakRef<TFrom>>(ref other.Ref());
|
||||||
|
|
||||||
var weakRef = new WeakRef<T>();
|
var weakRef = new WeakRef<T>();
|
||||||
|
|
||||||
@ -411,16 +411,16 @@ namespace LibHac.Common
|
|||||||
temp.DisposeInternal();
|
temp.DisposeInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCopy<TFrom>(ref WeakRef<TFrom> other) where TFrom : class, T
|
public void SetCopy<TFrom>(in WeakRef<TFrom> other) where TFrom : class, T
|
||||||
{
|
{
|
||||||
WeakRef<T> temp = CreateCopy(ref other);
|
WeakRef<T> temp = CreateCopy(in other);
|
||||||
Swap(ref temp);
|
Swap(ref temp);
|
||||||
temp.DisposeInternal();
|
temp.DisposeInternal();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Set<TFrom>(ref SharedRef<TFrom> other) where TFrom : class, T
|
public void Set<TFrom>(in SharedRef<TFrom> other) where TFrom : class, T
|
||||||
{
|
{
|
||||||
WeakRef<T> temp = Create(ref other);
|
WeakRef<T> temp = Create(in other);
|
||||||
Swap(ref temp);
|
Swap(ref temp);
|
||||||
temp.DisposeInternal();
|
temp.DisposeInternal();
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ using LibHac.FsSrv.Sf;
|
|||||||
|
|
||||||
namespace LibHac.Fs.Shim
|
namespace LibHac.Fs.Shim
|
||||||
{
|
{
|
||||||
|
[NonCopyable]
|
||||||
internal struct FileSystemProxyServiceObjectGlobals : IDisposable
|
internal struct FileSystemProxyServiceObjectGlobals : IDisposable
|
||||||
{
|
{
|
||||||
public nint FileSystemProxyServiceObjectInitGuard;
|
public nint FileSystemProxyServiceObjectInitGuard;
|
||||||
@ -46,7 +47,7 @@ namespace LibHac.Fs.Shim
|
|||||||
g.FileSystemProxyServiceObject.SetByMove(ref createdObject.Ref());
|
g.FileSystemProxyServiceObject.SetByMove(ref createdObject.Ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
return SharedRef<IFileSystemProxy>.CreateCopy(ref g.FileSystemProxyServiceObject);
|
return SharedRef<IFileSystemProxy>.CreateCopy(in g.FileSystemProxyServiceObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SharedRef<IFileSystemProxy> GetFileSystemProxyServiceObjectImpl(FileSystemClientImpl fs)
|
private static SharedRef<IFileSystemProxy> GetFileSystemProxyServiceObjectImpl(FileSystemClientImpl fs)
|
||||||
@ -56,7 +57,7 @@ namespace LibHac.Fs.Shim
|
|||||||
|
|
||||||
if (dfcServiceObject.HasValue)
|
if (dfcServiceObject.HasValue)
|
||||||
{
|
{
|
||||||
return SharedRef<IFileSystemProxy>.CreateCopy(ref dfcServiceObject);
|
return SharedRef<IFileSystemProxy>.CreateCopy(in dfcServiceObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
using var fileSystemProxy = new SharedRef<IFileSystemProxy>();
|
using var fileSystemProxy = new SharedRef<IFileSystemProxy>();
|
||||||
@ -84,7 +85,7 @@ namespace LibHac.Fs.Shim
|
|||||||
g.FileSystemProxyForLoaderServiceObject.SetByMove(ref createdObject.Ref());
|
g.FileSystemProxyForLoaderServiceObject.SetByMove(ref createdObject.Ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
return SharedRef<IFileSystemProxyForLoader>.CreateCopy(ref g.FileSystemProxyForLoaderServiceObject);
|
return SharedRef<IFileSystemProxyForLoader>.CreateCopy(in g.FileSystemProxyForLoaderServiceObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SharedRef<IFileSystemProxyForLoader> GetFileSystemProxyForLoaderServiceObjectImpl(
|
private static SharedRef<IFileSystemProxyForLoader> GetFileSystemProxyForLoaderServiceObjectImpl(
|
||||||
@ -114,7 +115,7 @@ namespace LibHac.Fs.Shim
|
|||||||
g.ProgramRegistryServiceObject.SetByMove(ref createdObject.Ref());
|
g.ProgramRegistryServiceObject.SetByMove(ref createdObject.Ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
return SharedRef<IProgramRegistry>.CreateCopy(ref g.ProgramRegistryServiceObject);
|
return SharedRef<IProgramRegistry>.CreateCopy(in g.ProgramRegistryServiceObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SharedRef<IProgramRegistry> GetProgramRegistryServiceObjectImpl(FileSystemClientImpl fs)
|
private static SharedRef<IProgramRegistry> GetProgramRegistryServiceObjectImpl(FileSystemClientImpl fs)
|
||||||
|
@ -305,7 +305,7 @@ namespace LibHac.Fs.Impl
|
|||||||
|
|
||||||
public SharedRef<IFileSystemSf> GetFileSystem()
|
public SharedRef<IFileSystemSf> GetFileSystem()
|
||||||
{
|
{
|
||||||
return SharedRef<IFileSystemSf>.CreateCopy(ref _baseFs);
|
return SharedRef<IFileSystemSf>.CreateCopy(in _baseFs);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SharedRef<IFileSystemSf> GetMultiCommitTarget()
|
public SharedRef<IFileSystemSf> GetMultiCommitTarget()
|
||||||
|
@ -49,7 +49,7 @@ namespace LibHac.Fs
|
|||||||
_offset = other._offset;
|
_offset = other._offset;
|
||||||
_size = other._size;
|
_size = other._size;
|
||||||
_isResizable = other._isResizable;
|
_isResizable = other._isResizable;
|
||||||
_sharedBaseStorage = SharedRef<IStorage>.CreateCopy(ref other._sharedBaseStorage);
|
_sharedBaseStorage = SharedRef<IStorage>.CreateCopy(in other._sharedBaseStorage);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -90,7 +90,7 @@ namespace LibHac.Fs
|
|||||||
_offset = other._offset + offset;
|
_offset = other._offset + offset;
|
||||||
_size = size;
|
_size = size;
|
||||||
_isResizable = false;
|
_isResizable = false;
|
||||||
_sharedBaseStorage = SharedRef<IStorage>.CreateCopy(ref other._sharedBaseStorage);
|
_sharedBaseStorage = SharedRef<IStorage>.CreateCopy(in other._sharedBaseStorage);
|
||||||
|
|
||||||
Assert.SdkRequiresLessEqual(0, offset);
|
Assert.SdkRequiresLessEqual(0, offset);
|
||||||
Assert.SdkRequiresLessEqual(0, size);
|
Assert.SdkRequiresLessEqual(0, size);
|
||||||
@ -105,13 +105,13 @@ namespace LibHac.Fs
|
|||||||
/// <param name="baseStorage">The base <see cref="IStorage"/>.</param>
|
/// <param name="baseStorage">The base <see cref="IStorage"/>.</param>
|
||||||
/// <param name="offset">The offset in the base storage at which to begin the created SubStorage.</param>
|
/// <param name="offset">The offset in the base storage at which to begin the created SubStorage.</param>
|
||||||
/// <param name="size">The size of the created SubStorage.</param>
|
/// <param name="size">The size of the created SubStorage.</param>
|
||||||
public SubStorage(ref SharedRef<IStorage> baseStorage, long offset, long size)
|
public SubStorage(in SharedRef<IStorage> baseStorage, long offset, long size)
|
||||||
{
|
{
|
||||||
BaseStorage = baseStorage.Get;
|
BaseStorage = baseStorage.Get;
|
||||||
_offset = offset;
|
_offset = offset;
|
||||||
_size = size;
|
_size = size;
|
||||||
_isResizable = false;
|
_isResizable = false;
|
||||||
_sharedBaseStorage = SharedRef<IStorage>.CreateCopy(ref baseStorage);
|
_sharedBaseStorage = SharedRef<IStorage>.CreateCopy(in baseStorage);
|
||||||
|
|
||||||
Assert.SdkRequiresNotNull(baseStorage.Get);
|
Assert.SdkRequiresNotNull(baseStorage.Get);
|
||||||
Assert.SdkRequiresLessEqual(0, _offset);
|
Assert.SdkRequiresLessEqual(0, _offset);
|
||||||
@ -137,7 +137,7 @@ namespace LibHac.Fs
|
|||||||
_offset = other._offset;
|
_offset = other._offset;
|
||||||
_size = other._size;
|
_size = other._size;
|
||||||
_isResizable = other._isResizable;
|
_isResizable = other._isResizable;
|
||||||
_sharedBaseStorage.SetByCopy(ref other._sharedBaseStorage);
|
_sharedBaseStorage.SetByCopy(in other._sharedBaseStorage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ namespace LibHac.FsSrv
|
|||||||
internal Result OpenDeviceOperator(ref SharedRef<IDeviceOperator> outDeviceOperator,
|
internal Result OpenDeviceOperator(ref SharedRef<IDeviceOperator> outDeviceOperator,
|
||||||
AccessControl accessControl)
|
AccessControl accessControl)
|
||||||
{
|
{
|
||||||
outDeviceOperator.SetByCopy(ref _deviceOperator);
|
outDeviceOperator.SetByCopy(in _deviceOperator);
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ namespace LibHac.FsSrv
|
|||||||
|
|
||||||
using var sharedRootFileSystem = new SharedRef<IFileSystem>(rootFileSystem);
|
using var sharedRootFileSystem = new SharedRef<IFileSystem>(rootFileSystem);
|
||||||
using SharedRef<IFileSystem> sharedRootFileSystemCopy =
|
using SharedRef<IFileSystem> sharedRootFileSystemCopy =
|
||||||
SharedRef<IFileSystem>.CreateCopy(ref sharedRootFileSystem.Ref());
|
SharedRef<IFileSystem>.CreateCopy(in sharedRootFileSystem);
|
||||||
|
|
||||||
creators.RomFileSystemCreator = new RomFileSystemCreator();
|
creators.RomFileSystemCreator = new RomFileSystemCreator();
|
||||||
creators.PartitionFileSystemCreator = new PartitionFileSystemCreator();
|
creators.PartitionFileSystemCreator = new PartitionFileSystemCreator();
|
||||||
|
@ -50,7 +50,7 @@ namespace LibHac.FsSrv.FsCreator
|
|||||||
|
|
||||||
public bool TryGetRootFileSystem(ref SharedRef<IFileSystem> outFileSystem)
|
public bool TryGetRootFileSystem(ref SharedRef<IFileSystem> outFileSystem)
|
||||||
{
|
{
|
||||||
outFileSystem.SetByCopy(ref _rootFileSystem);
|
outFileSystem.SetByCopy(in _rootFileSystem);
|
||||||
|
|
||||||
return outFileSystem.HasValue;
|
return outFileSystem.HasValue;
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ namespace LibHac.FsSrv.FsCreator
|
|||||||
if (!IsValidPartitionId(partitionId))
|
if (!IsValidPartitionId(partitionId))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
outFileSystem.SetByCopy(ref PartitionFileSystems[GetArrayIndex(partitionId)]);
|
outFileSystem.SetByCopy(in PartitionFileSystems[GetArrayIndex(partitionId)]);
|
||||||
|
|
||||||
return outFileSystem.HasValue;
|
return outFileSystem.HasValue;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ namespace LibHac.FsSrv.FsCreator
|
|||||||
Result rc = GameCard.GetCardInfo(out GameCardInfo cardInfo, handle);
|
Result rc = GameCard.GetCardInfo(out GameCardInfo cardInfo, handle);
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
outStorage.Reset(new SubStorage(ref baseStorage.Ref(), 0, cardInfo.SecureAreaOffset));
|
outStorage.Reset(new SubStorage(in baseStorage, 0, cardInfo.SecureAreaOffset));
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ namespace LibHac.FsSrv.FsCreator
|
|||||||
rc = GameCard.GetCardInfo(out GameCardInfo cardInfo, handle);
|
rc = GameCard.GetCardInfo(out GameCardInfo cardInfo, handle);
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
outStorage.Reset(new SubStorage(ref baseStorage.Ref(), cardInfo.SecureAreaOffset, cardInfo.SecureAreaSize));
|
outStorage.Reset(new SubStorage(in baseStorage, cardInfo.SecureAreaOffset, cardInfo.SecureAreaSize));
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ namespace LibHac.FsSrv.FsCreator
|
|||||||
|
|
||||||
if (_sdCardFileSystem.HasValue)
|
if (_sdCardFileSystem.HasValue)
|
||||||
{
|
{
|
||||||
outFileSystem.SetByCopy(ref _sdCardFileSystem);
|
outFileSystem.SetByCopy(in _sdCardFileSystem);
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
@ -67,11 +67,11 @@ namespace LibHac.FsSrv.FsCreator
|
|||||||
|
|
||||||
// Todo: Add ProxyFileSystem?
|
// Todo: Add ProxyFileSystem?
|
||||||
|
|
||||||
using SharedRef<IFileSystem> fileSystem = SharedRef<IFileSystem>.CreateCopy(ref _rootFileSystem);
|
using SharedRef<IFileSystem> fileSystem = SharedRef<IFileSystem>.CreateCopy(in _rootFileSystem);
|
||||||
rc = Utility.WrapSubDirectory(ref _sdCardFileSystem, ref fileSystem.Ref(), in sdCardPath, true);
|
rc = Utility.WrapSubDirectory(ref _sdCardFileSystem, ref fileSystem.Ref(), in sdCardPath, true);
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
outFileSystem.SetByCopy(ref _sdCardFileSystem);
|
outFileSystem.SetByCopy(in _sdCardFileSystem);
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
@ -83,8 +83,8 @@ namespace LibHac.FsSrv.FsCreator
|
|||||||
isMultiCommitSupported, !openReadOnly);
|
isMultiCommitSupported, !openReadOnly);
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
outFileSystem.SetByCopy(ref saveDirFs.Ref());
|
outFileSystem.SetByCopy(in saveDirFs);
|
||||||
outExtraDataAccessor.SetByCopy(ref saveDirFs.Ref());
|
outExtraDataAccessor.SetByCopy(in saveDirFs);
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ namespace LibHac.FsSrv.Impl
|
|||||||
using var retryFileSystem = new SharedRef<DeepRetryFileSystem>(
|
using var retryFileSystem = new SharedRef<DeepRetryFileSystem>(
|
||||||
new DeepRetryFileSystem(ref baseFileSystem, ref accessFailureManager));
|
new DeepRetryFileSystem(ref baseFileSystem, ref accessFailureManager));
|
||||||
|
|
||||||
retryFileSystem.Get._selfReference = new WeakRef<DeepRetryFileSystem>(ref retryFileSystem.Ref());
|
retryFileSystem.Get._selfReference.Set(in retryFileSystem.Ref());
|
||||||
|
|
||||||
return SharedRef<IFileSystem>.CreateMove(ref retryFileSystem.Ref());
|
return SharedRef<IFileSystem>.CreateMove(ref retryFileSystem.Ref());
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ namespace LibHac.FsSrv.Impl
|
|||||||
var adapter = new FileSystemInterfaceAdapter(ref baseFileSystem, allowAllOperations);
|
var adapter = new FileSystemInterfaceAdapter(ref baseFileSystem, allowAllOperations);
|
||||||
using var sharedAdapter = new SharedRef<FileSystemInterfaceAdapter>(adapter);
|
using var sharedAdapter = new SharedRef<FileSystemInterfaceAdapter>(adapter);
|
||||||
|
|
||||||
adapter._selfReference.Set(ref sharedAdapter.Ref());
|
adapter._selfReference.Set(in sharedAdapter);
|
||||||
|
|
||||||
return SharedRef<IFileSystemSf>.CreateMove(ref sharedAdapter.Ref());
|
return SharedRef<IFileSystemSf>.CreateMove(ref sharedAdapter.Ref());
|
||||||
}
|
}
|
||||||
@ -279,7 +279,7 @@ namespace LibHac.FsSrv.Impl
|
|||||||
var adapter = new FileSystemInterfaceAdapter(ref baseFileSystem, flags, allowAllOperations);
|
var adapter = new FileSystemInterfaceAdapter(ref baseFileSystem, flags, allowAllOperations);
|
||||||
using var sharedAdapter = new SharedRef<FileSystemInterfaceAdapter>(adapter);
|
using var sharedAdapter = new SharedRef<FileSystemInterfaceAdapter>(adapter);
|
||||||
|
|
||||||
adapter._selfReference.Set(ref sharedAdapter.Ref());
|
adapter._selfReference.Set(in sharedAdapter);
|
||||||
|
|
||||||
return SharedRef<IFileSystemSf>.CreateMove(ref sharedAdapter.Ref());
|
return SharedRef<IFileSystemSf>.CreateMove(ref sharedAdapter.Ref());
|
||||||
}
|
}
|
||||||
@ -498,7 +498,7 @@ namespace LibHac.FsSrv.Impl
|
|||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
using SharedRef<FileSystemInterfaceAdapter> selfReference =
|
using SharedRef<FileSystemInterfaceAdapter> selfReference =
|
||||||
SharedRef<FileSystemInterfaceAdapter>.Create(ref _selfReference);
|
SharedRef<FileSystemInterfaceAdapter>.Create(in _selfReference);
|
||||||
|
|
||||||
var adapter = new FileInterfaceAdapter(ref file.Ref(), ref selfReference.Ref(), _allowAllOperations);
|
var adapter = new FileInterfaceAdapter(ref file.Ref(), ref selfReference.Ref(), _allowAllOperations);
|
||||||
outFile.Reset(adapter);
|
outFile.Reset(adapter);
|
||||||
@ -529,7 +529,7 @@ namespace LibHac.FsSrv.Impl
|
|||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
using SharedRef<FileSystemInterfaceAdapter> selfReference =
|
using SharedRef<FileSystemInterfaceAdapter> selfReference =
|
||||||
SharedRef<FileSystemInterfaceAdapter>.Create(ref _selfReference);
|
SharedRef<FileSystemInterfaceAdapter>.Create(in _selfReference);
|
||||||
|
|
||||||
var adapter = new DirectoryInterfaceAdapter(ref directory.Ref(), ref selfReference.Ref());
|
var adapter = new DirectoryInterfaceAdapter(ref directory.Ref(), ref selfReference.Ref());
|
||||||
outDirectory.Reset(adapter);
|
outDirectory.Reset(adapter);
|
||||||
@ -590,7 +590,7 @@ namespace LibHac.FsSrv.Impl
|
|||||||
|
|
||||||
public Result GetImpl(ref SharedRef<IFileSystem> fileSystem)
|
public Result GetImpl(ref SharedRef<IFileSystem> fileSystem)
|
||||||
{
|
{
|
||||||
fileSystem.SetByCopy(ref _baseFileSystem);
|
fileSystem.SetByCopy(in _baseFileSystem);
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,16 +12,17 @@ namespace LibHac.FsSrv.Impl
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SaveDataExtraDataAccessorCacheManager : ISaveDataExtraDataAccessorCacheObserver
|
public class SaveDataExtraDataAccessorCacheManager : ISaveDataExtraDataAccessorCacheObserver
|
||||||
{
|
{
|
||||||
|
[NonCopyable]
|
||||||
private struct Cache : IDisposable
|
private struct Cache : IDisposable
|
||||||
{
|
{
|
||||||
private WeakRef<ISaveDataExtraDataAccessor> _accessor;
|
private WeakRef<ISaveDataExtraDataAccessor> _accessor;
|
||||||
private readonly SaveDataSpaceId _spaceId;
|
private readonly SaveDataSpaceId _spaceId;
|
||||||
private readonly ulong _saveDataId;
|
private readonly ulong _saveDataId;
|
||||||
|
|
||||||
public Cache(ref SharedRef<ISaveDataExtraDataAccessor> accessor, SaveDataSpaceId spaceId,
|
public Cache(in SharedRef<ISaveDataExtraDataAccessor> accessor, SaveDataSpaceId spaceId,
|
||||||
ulong saveDataId)
|
ulong saveDataId)
|
||||||
{
|
{
|
||||||
_accessor = new WeakRef<ISaveDataExtraDataAccessor>(ref accessor);
|
_accessor = new WeakRef<ISaveDataExtraDataAccessor>(in accessor);
|
||||||
_spaceId = spaceId;
|
_spaceId = spaceId;
|
||||||
_saveDataId = saveDataId;
|
_saveDataId = saveDataId;
|
||||||
}
|
}
|
||||||
@ -69,10 +70,10 @@ namespace LibHac.FsSrv.Impl
|
|||||||
_accessorList.Clear();
|
_accessorList.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result Register(ref SharedRef<ISaveDataExtraDataAccessor> accessor, SaveDataSpaceId spaceId,
|
public Result Register(in SharedRef<ISaveDataExtraDataAccessor> accessor, SaveDataSpaceId spaceId,
|
||||||
ulong saveDataId)
|
ulong saveDataId)
|
||||||
{
|
{
|
||||||
var node = new LinkedListNode<Cache>(new Cache(ref accessor, spaceId, saveDataId));
|
var node = new LinkedListNode<Cache>(new Cache(in accessor, spaceId, saveDataId));
|
||||||
|
|
||||||
using (ScopedLock.Lock(ref _mutex))
|
using (ScopedLock.Lock(ref _mutex))
|
||||||
{
|
{
|
||||||
|
@ -43,7 +43,7 @@ namespace LibHac.FsSrv
|
|||||||
|
|
||||||
// Wrap the service in a ref-counter and give the service a weak self-reference
|
// Wrap the service in a ref-counter and give the service a weak self-reference
|
||||||
using var sharedService = new SharedRef<NcaFileSystemService>(ncaService);
|
using var sharedService = new SharedRef<NcaFileSystemService>(ncaService);
|
||||||
ncaService._selfReference = new WeakRef<NcaFileSystemService>(ref sharedService.Ref());
|
ncaService._selfReference.Set(in sharedService);
|
||||||
|
|
||||||
return SharedRef<NcaFileSystemService>.CreateMove(ref sharedService.Ref());
|
return SharedRef<NcaFileSystemService>.CreateMove(ref sharedService.Ref());
|
||||||
}
|
}
|
||||||
@ -154,7 +154,7 @@ namespace LibHac.FsSrv
|
|||||||
new SharedRef<IFileSystem>(new AsynchronousAccessFileSystem(ref typeSetFileSystem.Ref()));
|
new SharedRef<IFileSystem>(new AsynchronousAccessFileSystem(ref typeSetFileSystem.Ref()));
|
||||||
|
|
||||||
using SharedRef<IRomFileSystemAccessFailureManager> accessFailureManager =
|
using SharedRef<IRomFileSystemAccessFailureManager> accessFailureManager =
|
||||||
SharedRef<IRomFileSystemAccessFailureManager>.Create(ref _selfReference);
|
SharedRef<IRomFileSystemAccessFailureManager>.Create(in _selfReference);
|
||||||
|
|
||||||
using SharedRef<IFileSystem> retryFileSystem =
|
using SharedRef<IFileSystem> retryFileSystem =
|
||||||
DeepRetryFileSystem.CreateShared(ref asyncFileSystem.Ref(), ref accessFailureManager.Ref());
|
DeepRetryFileSystem.CreateShared(ref asyncFileSystem.Ref(), ref accessFailureManager.Ref());
|
||||||
|
@ -145,7 +145,7 @@ namespace LibHac.FsSrv
|
|||||||
}
|
}
|
||||||
|
|
||||||
using var nspFileSystem = new SharedRef<IFileSystem>();
|
using var nspFileSystem = new SharedRef<IFileSystem>();
|
||||||
using SharedRef<IFileSystem> tempFileSystem = SharedRef<IFileSystem>.CreateCopy(ref baseFileSystem.Ref());
|
using SharedRef<IFileSystem> tempFileSystem = SharedRef<IFileSystem>.CreateCopy(in baseFileSystem);
|
||||||
rc = ParseNsp(ref currentPath, ref nspFileSystem.Ref(), ref baseFileSystem.Ref());
|
rc = ParseNsp(ref currentPath, ref nspFileSystem.Ref(), ref baseFileSystem.Ref());
|
||||||
|
|
||||||
if (rc.IsSuccess())
|
if (rc.IsSuccess())
|
||||||
|
@ -44,10 +44,10 @@ namespace LibHac.FsSrv
|
|||||||
private HorizonClient Hos => _serviceImpl.Hos;
|
private HorizonClient Hos => _serviceImpl.Hos;
|
||||||
|
|
||||||
private SharedRef<SaveDataFileSystemService> GetSharedFromThis() =>
|
private SharedRef<SaveDataFileSystemService> GetSharedFromThis() =>
|
||||||
SharedRef<SaveDataFileSystemService>.Create(ref _selfReference);
|
SharedRef<SaveDataFileSystemService>.Create(in _selfReference);
|
||||||
|
|
||||||
private SharedRef<ISaveDataMultiCommitCoreInterface> GetSharedMultiCommitInterfaceFromThis() =>
|
private SharedRef<ISaveDataMultiCommitCoreInterface> GetSharedMultiCommitInterfaceFromThis() =>
|
||||||
SharedRef<ISaveDataMultiCommitCoreInterface>.Create(ref _selfReference);
|
SharedRef<ISaveDataMultiCommitCoreInterface>.Create(in _selfReference);
|
||||||
|
|
||||||
public SaveDataFileSystemService(SaveDataFileSystemServiceImpl serviceImpl, ulong processId)
|
public SaveDataFileSystemService(SaveDataFileSystemServiceImpl serviceImpl, ulong processId)
|
||||||
{
|
{
|
||||||
@ -64,7 +64,7 @@ namespace LibHac.FsSrv
|
|||||||
|
|
||||||
// Wrap the service in a ref-counter and give the service a weak self-reference
|
// Wrap the service in a ref-counter and give the service a weak self-reference
|
||||||
using var sharedService = new SharedRef<SaveDataFileSystemService>(saveService);
|
using var sharedService = new SharedRef<SaveDataFileSystemService>(saveService);
|
||||||
saveService._selfReference = WeakRef<SaveDataFileSystemService>.Create(ref sharedService.Ref());
|
saveService._selfReference.Set(in sharedService);
|
||||||
|
|
||||||
return SharedRef<SaveDataFileSystemService>.CreateMove(ref sharedService.Ref());
|
return SharedRef<SaveDataFileSystemService>.CreateMove(ref sharedService.Ref());
|
||||||
}
|
}
|
||||||
@ -1088,7 +1088,7 @@ namespace LibHac.FsSrv
|
|||||||
Result rc = TryAcquireSaveDataMountCountSemaphore(ref mountCountSemaphore.Ref());
|
Result rc = TryAcquireSaveDataMountCountSemaphore(ref mountCountSemaphore.Ref());
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
Path saveDataRootPath = _saveDataRootPath.DangerousGetPath();
|
using Path saveDataRootPath = _saveDataRootPath.DangerousGetPath();
|
||||||
bool useAsyncFileSystem = !_serviceImpl.IsAllowedDirectorySaveData(spaceId, in saveDataRootPath);
|
bool useAsyncFileSystem = !_serviceImpl.IsAllowedDirectorySaveData(spaceId, in saveDataRootPath);
|
||||||
|
|
||||||
using var fileSystem = new SharedRef<IFileSystem>();
|
using var fileSystem = new SharedRef<IFileSystem>();
|
||||||
@ -1103,7 +1103,7 @@ namespace LibHac.FsSrv
|
|||||||
|
|
||||||
Result ReadExtraData(out SaveDataExtraData data)
|
Result ReadExtraData(out SaveDataExtraData data)
|
||||||
{
|
{
|
||||||
Path savePath = _saveDataRootPath.DangerousGetPath();
|
using Path savePath = _saveDataRootPath.DangerousGetPath();
|
||||||
return _serviceImpl.ReadSaveDataFileSystemExtraData(out data, spaceId, saveDataId, type,
|
return _serviceImpl.ReadSaveDataFileSystemExtraData(out data, spaceId, saveDataId, type,
|
||||||
in savePath);
|
in savePath);
|
||||||
}
|
}
|
||||||
@ -1278,7 +1278,7 @@ namespace LibHac.FsSrv
|
|||||||
rc = accessor.Get.Indexer.GetKey(out SaveDataAttribute key, saveDataId);
|
rc = accessor.Get.Indexer.GetKey(out SaveDataAttribute key, saveDataId);
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
Path saveDataRootPath = _saveDataRootPath.DangerousGetPath();
|
using Path saveDataRootPath = _saveDataRootPath.DangerousGetPath();
|
||||||
return _serviceImpl.ReadSaveDataFileSystemExtraData(out extraData, spaceId, saveDataId, key.Type,
|
return _serviceImpl.ReadSaveDataFileSystemExtraData(out extraData, spaceId, saveDataId, key.Type,
|
||||||
in saveDataRootPath);
|
in saveDataRootPath);
|
||||||
}
|
}
|
||||||
@ -1444,7 +1444,7 @@ namespace LibHac.FsSrv
|
|||||||
{
|
{
|
||||||
using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageType.NonGameCard);
|
using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageType.NonGameCard);
|
||||||
|
|
||||||
Path saveDataRootPath = _saveDataRootPath.DangerousGetPath();
|
using Path saveDataRootPath = _saveDataRootPath.DangerousGetPath();
|
||||||
return _serviceImpl.WriteSaveDataFileSystemExtraData(spaceId, saveDataId, in extraData, in saveDataRootPath,
|
return _serviceImpl.WriteSaveDataFileSystemExtraData(spaceId, saveDataId, in extraData, in saveDataRootPath,
|
||||||
saveType, updateTimeStamp);
|
saveType, updateTimeStamp);
|
||||||
}
|
}
|
||||||
@ -1472,7 +1472,7 @@ namespace LibHac.FsSrv
|
|||||||
ReadExtraData);
|
ReadExtraData);
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
Path saveDataRootPath = _saveDataRootPath.DangerousGetPath();
|
using Path saveDataRootPath = _saveDataRootPath.DangerousGetPath();
|
||||||
rc = _serviceImpl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraDataModify, spaceId,
|
rc = _serviceImpl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraDataModify, spaceId,
|
||||||
saveDataId, key.Type, in saveDataRootPath);
|
saveDataId, key.Type, in saveDataRootPath);
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
@ -1893,7 +1893,7 @@ namespace LibHac.FsSrv
|
|||||||
Result rc = FindCacheStorage(out SaveDataInfo saveInfo, out SaveDataSpaceId spaceId, index);
|
Result rc = FindCacheStorage(out SaveDataInfo saveInfo, out SaveDataSpaceId spaceId, index);
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
Path saveDataRootPath = _saveDataRootPath.DangerousGetPath();
|
using Path saveDataRootPath = _saveDataRootPath.DangerousGetPath();
|
||||||
rc = _serviceImpl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId,
|
rc = _serviceImpl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId,
|
||||||
saveInfo.SaveDataId, saveInfo.Type, in saveDataRootPath);
|
saveInfo.SaveDataId, saveInfo.Type, in saveDataRootPath);
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
@ -175,7 +175,7 @@ namespace LibHac.FsSrv
|
|||||||
{
|
{
|
||||||
extraDataAccessor.Get.RegisterCacheObserver(_extraDataCacheManager, spaceId, saveDataId);
|
extraDataAccessor.Get.RegisterCacheObserver(_extraDataCacheManager, spaceId, saveDataId);
|
||||||
|
|
||||||
rc = _extraDataCacheManager.Register(ref extraDataAccessor.Ref(), spaceId, saveDataId);
|
rc = _extraDataCacheManager.Register(in extraDataAccessor, spaceId, saveDataId);
|
||||||
if (rc.IsFailure()) return rc.Miss();
|
if (rc.IsFailure()) return rc.Miss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -521,7 +521,7 @@ namespace LibHac.FsSrv
|
|||||||
rc = RegisterReader(ref reader.Ref());
|
rc = RegisterReader(ref reader.Ref());
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
outInfoReader.SetByCopy(ref reader.Ref());
|
outInfoReader.SetByCopy(in reader.Ref());
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -785,7 +785,7 @@ namespace LibHac.FsSrv
|
|||||||
|
|
||||||
public ReaderAccessor(ref SharedRef<Reader> reader)
|
public ReaderAccessor(ref SharedRef<Reader> reader)
|
||||||
{
|
{
|
||||||
_reader = new WeakRef<Reader>(ref reader);
|
_reader = new WeakRef<Reader>(in reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose() => _reader.Destroy();
|
public void Dispose() => _reader.Destroy();
|
||||||
|
@ -271,6 +271,7 @@ namespace LibHac.FsSrv
|
|||||||
/// <remarks>Based on FS 12.1.0 (nnSdk 12.3.1).</remarks>
|
/// <remarks>Based on FS 12.1.0 (nnSdk 12.3.1).</remarks>
|
||||||
public class SaveDataFileStorageHolder
|
public class SaveDataFileStorageHolder
|
||||||
{
|
{
|
||||||
|
[NonCopyable]
|
||||||
private struct Entry
|
private struct Entry
|
||||||
{
|
{
|
||||||
private SharedRef<SaveDataOpenTypeSetFileStorage> _storage;
|
private SharedRef<SaveDataOpenTypeSetFileStorage> _storage;
|
||||||
@ -297,7 +298,7 @@ namespace LibHac.FsSrv
|
|||||||
|
|
||||||
public SharedRef<SaveDataOpenTypeSetFileStorage> GetStorage()
|
public SharedRef<SaveDataOpenTypeSetFileStorage> GetStorage()
|
||||||
{
|
{
|
||||||
return SharedRef<SaveDataOpenTypeSetFileStorage>.CreateCopy(ref _storage);
|
return SharedRef<SaveDataOpenTypeSetFileStorage>.CreateCopy(in _storage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -370,7 +371,7 @@ namespace LibHac.FsSrv
|
|||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
using SharedRef<SaveDataOpenTypeSetFileStorage> baseFileStorageCopy =
|
using SharedRef<SaveDataOpenTypeSetFileStorage> baseFileStorageCopy =
|
||||||
SharedRef<SaveDataOpenTypeSetFileStorage>.CreateCopy(ref baseFileStorage.Ref());
|
SharedRef<SaveDataOpenTypeSetFileStorage>.CreateCopy(in baseFileStorage);
|
||||||
|
|
||||||
rc = Register(ref baseFileStorageCopy.Ref(), spaceId, saveDataId);
|
rc = Register(ref baseFileStorageCopy.Ref(), spaceId, saveDataId);
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
@ -7,6 +7,7 @@ namespace LibHac.FsSystem
|
|||||||
{
|
{
|
||||||
public class SaveDataFileSystemCacheManager : ISaveDataFileSystemCacheManager
|
public class SaveDataFileSystemCacheManager : ISaveDataFileSystemCacheManager
|
||||||
{
|
{
|
||||||
|
[NonCopyable]
|
||||||
private struct Cache
|
private struct Cache
|
||||||
{
|
{
|
||||||
// Note: Nintendo only supports caching SaveDataFileSystem. We support DirectorySaveDataFileSystem too,
|
// Note: Nintendo only supports caching SaveDataFileSystem. We support DirectorySaveDataFileSystem too,
|
||||||
|
@ -62,7 +62,7 @@ namespace LibHac.FsSystem
|
|||||||
|
|
||||||
using (var sharedStorage = new SharedRef<IStorage>(storage))
|
using (var sharedStorage = new SharedRef<IStorage>(storage))
|
||||||
{
|
{
|
||||||
return new SubStorage(ref sharedStorage.Ref(), start, length);
|
return new SubStorage(in sharedStorage, start, length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,10 +15,10 @@ namespace hactoolnet
|
|||||||
{
|
{
|
||||||
public static void ProcessPk11(Context ctx)
|
public static void ProcessPk11(Context ctx)
|
||||||
{
|
{
|
||||||
using (var file = new LocalStorage(ctx.Options.InFile, FileAccess.Read))
|
using (var file = new SharedRef<IStorage>(new LocalStorage(ctx.Options.InFile, FileAccess.Read)))
|
||||||
{
|
{
|
||||||
var package1 = new LibHac.Boot.Package1();
|
var package1 = new LibHac.Boot.Package1();
|
||||||
package1.Initialize(ctx.KeySet, file).ThrowIfFailure();
|
package1.Initialize(ctx.KeySet, in file).ThrowIfFailure();
|
||||||
|
|
||||||
ctx.Logger.LogMessage(package1.Print());
|
ctx.Logger.LogMessage(package1.Print());
|
||||||
|
|
||||||
|
@ -443,11 +443,8 @@ namespace LibHac.Tests.Fs
|
|||||||
rc = fileSystem.OpenFile(ref file.Ref(), path, OpenMode.ReadWrite);
|
rc = fileSystem.OpenFile(ref file.Ref(), path, OpenMode.ReadWrite);
|
||||||
if (rc.IsFailure()) return rc;
|
if (rc.IsFailure()) return rc;
|
||||||
|
|
||||||
using (file)
|
rc = file.Get.Write(0, SpanHelpers.AsByteSpan(ref extraData), WriteOption.Flush);
|
||||||
{
|
if (rc.IsFailure()) return rc;
|
||||||
rc = file.Get.Write(0, SpanHelpers.AsByteSpan(ref extraData), WriteOption.Flush);
|
|
||||||
if (rc.IsFailure()) return rc;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user