mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Reorganize SaveDataFileSystemService
This commit is contained in:
parent
49edb744c5
commit
beca253086
12 changed files with 705 additions and 636 deletions
|
@ -207,7 +207,7 @@ public static class PathNormalizer
|
||||||
/// contains <see langword="true"/> if the path is normalized or <see langword="false"/> if it is not.
|
/// contains <see langword="true"/> if the path is normalized or <see langword="false"/> if it is not.
|
||||||
/// Contents are undefined if the function does not return <see cref="Result.Success"/>.
|
/// Contents are undefined if the function does not return <see cref="Result.Success"/>.
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="length">When this function returns <see cref="Result.Success"/> and
|
/// <param name="outNormalizedLength">When this function returns <see cref="Result.Success"/> and
|
||||||
/// <paramref name="isNormalized"/> is <see langword="true"/>, contains the length of the normalized path.
|
/// <paramref name="isNormalized"/> is <see langword="true"/>, contains the length of the normalized path.
|
||||||
/// Contents are undefined if the function does not return <see cref="Result.Success"/>
|
/// Contents are undefined if the function does not return <see cref="Result.Success"/>
|
||||||
/// or <paramref name="isNormalized"/> is <see langword="false"/>.
|
/// or <paramref name="isNormalized"/> is <see langword="false"/>.
|
||||||
|
@ -216,15 +216,15 @@ public static class PathNormalizer
|
||||||
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/>
|
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/>
|
||||||
/// <see cref="ResultFs.InvalidCharacter"/>: The path contains an invalid character.<br/>
|
/// <see cref="ResultFs.InvalidCharacter"/>: The path contains an invalid character.<br/>
|
||||||
/// <see cref="ResultFs.InvalidPathFormat"/>: The path is not in a valid format.</returns>
|
/// <see cref="ResultFs.InvalidPathFormat"/>: The path is not in a valid format.</returns>
|
||||||
public static Result IsNormalized(out bool isNormalized, out int length, ReadOnlySpan<byte> path)
|
public static Result IsNormalized(out bool isNormalized, out int outNormalizedLength, ReadOnlySpan<byte> path)
|
||||||
{
|
{
|
||||||
return IsNormalized(out isNormalized, out length, path, false);
|
return IsNormalized(out isNormalized, out outNormalizedLength, path, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result IsNormalized(out bool isNormalized, out int length, ReadOnlySpan<byte> path,
|
public static Result IsNormalized(out bool isNormalized, out int outNormalizedLength, ReadOnlySpan<byte> path,
|
||||||
bool allowAllCharacters)
|
bool allowAllCharacters)
|
||||||
{
|
{
|
||||||
UnsafeHelpers.SkipParamInit(out isNormalized, out length);
|
UnsafeHelpers.SkipParamInit(out isNormalized, out outNormalizedLength);
|
||||||
|
|
||||||
var state = PathState.Initial;
|
var state = PathState.Initial;
|
||||||
int pathLength = 0;
|
int pathLength = 0;
|
||||||
|
@ -311,7 +311,7 @@ public static class PathNormalizer
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
length = pathLength;
|
outNormalizedLength = pathLength;
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,13 +47,13 @@ public static class FileSystemServerInitializer
|
||||||
|
|
||||||
InitializeFileSystemProxyServer(client, server);
|
InitializeFileSystemProxyServer(client, server);
|
||||||
|
|
||||||
var saveService = new SaveDataFileSystemService(fspConfig.SaveDataFileSystemService, processId);
|
using SharedRef<SaveDataFileSystemService> saveService = SaveDataFileSystemService.CreateShared(fspConfig.SaveDataFileSystemService, processId);
|
||||||
|
|
||||||
saveService.CleanUpTemporaryStorage().IgnoreResult();
|
saveService.Get.CleanUpTemporaryStorage().IgnoreResult();
|
||||||
saveService.CleanUpSaveData().IgnoreResult();
|
saveService.Get.CleanUpSaveData().IgnoreResult();
|
||||||
saveService.CompleteSaveDataExtension().IgnoreResult();
|
saveService.Get.CompleteSaveDataExtension().IgnoreResult();
|
||||||
saveService.FixSaveData().IgnoreResult();
|
saveService.Get.FixSaveData().IgnoreResult();
|
||||||
saveService.RecoverMultiCommit().IgnoreResult();
|
saveService.Get.RecoverMultiCommit().IgnoreResult();
|
||||||
|
|
||||||
config.StorageDeviceManagerFactory.SetReady(StorageDevicePortId.SdCard, null);
|
config.StorageDeviceManagerFactory.SetReady(StorageDevicePortId.SdCard, null);
|
||||||
config.StorageDeviceManagerFactory.SetReady(StorageDevicePortId.GameCard, null);
|
config.StorageDeviceManagerFactory.SetReady(StorageDevicePortId.GameCard, null);
|
||||||
|
|
|
@ -204,7 +204,7 @@ public class DirectoryInterfaceAdapter : IDirectorySf
|
||||||
const int maxTryCount = 2;
|
const int maxTryCount = 2;
|
||||||
UnsafeHelpers.SkipParamInit(out entriesRead);
|
UnsafeHelpers.SkipParamInit(out entriesRead);
|
||||||
|
|
||||||
Span<DirectoryEntry> entries = MemoryMarshal.Cast<byte, DirectoryEntry>(entryBuffer.Buffer);
|
Span<DirectoryEntry> entries = entryBuffer.AsSpan<DirectoryEntry>();
|
||||||
|
|
||||||
Result res = Result.Success;
|
Result res = Result.Success;
|
||||||
long numRead = 0;
|
long numRead = 0;
|
||||||
|
|
|
@ -10,5 +10,5 @@ public interface ISaveDataMultiCommitCoreInterface : IDisposable
|
||||||
Result RecoverMultiCommit();
|
Result RecoverMultiCommit();
|
||||||
Result IsProvisionallyCommittedSaveData(out bool isProvisionallyCommitted, in SaveDataInfo saveInfo);
|
Result IsProvisionallyCommittedSaveData(out bool isProvisionallyCommitted, in SaveDataInfo saveInfo);
|
||||||
Result RecoverProvisionallyCommittedSaveData(in SaveDataInfo saveInfo, bool doRollback);
|
Result RecoverProvisionallyCommittedSaveData(in SaveDataInfo saveInfo, bool doRollback);
|
||||||
Result OpenMultiCommitContext(ref SharedRef<IFileSystem> contextFileSystem);
|
Result OpenMultiCommitContext(ref SharedRef<IFileSystem> outContextFileSystem);
|
||||||
}
|
}
|
|
@ -20,7 +20,7 @@ public interface ISaveDataTransferCoreInterface : IDisposable
|
||||||
Result CancelSaveDataCreation(ulong saveDataId, SaveDataSpaceId spaceId);
|
Result CancelSaveDataCreation(ulong saveDataId, SaveDataSpaceId spaceId);
|
||||||
Result OpenSaveDataFile(ref SharedRef<IFile> oufFile, SaveDataSpaceId spaceId, ulong saveDataId, OpenMode mode);
|
Result OpenSaveDataFile(ref SharedRef<IFile> oufFile, SaveDataSpaceId spaceId, ulong saveDataId, OpenMode mode);
|
||||||
Result OpenSaveDataMetaFileRaw(ref SharedRef<IFile> outFile, SaveDataSpaceId spaceId, ulong saveDataId, SaveDataMetaType metaType, OpenMode mode);
|
Result OpenSaveDataMetaFileRaw(ref SharedRef<IFile> outFile, SaveDataSpaceId spaceId, ulong saveDataId, SaveDataMetaType metaType, OpenMode mode);
|
||||||
Result OpenSaveDataInternalStorageFileSystemCore(ref SharedRef<IFileSystem> fileSystem, SaveDataSpaceId spaceId, ulong saveDataId, bool useSecondMacKey);
|
Result OpenSaveDataInternalStorageFileSystemCore(ref SharedRef<IFileSystem> outFileSystem, SaveDataSpaceId spaceId, ulong saveDataId, bool isTemporaryTransferSave);
|
||||||
Result OpenSaveDataFileSystemCore(ref SharedRef<IFileSystem> outFileSystem, out ulong outSaveDataId, SaveDataSpaceId spaceId, in SaveDataAttribute attribute, bool openReadOnly, bool cacheExtraData);
|
Result OpenSaveDataFileSystemCore(ref SharedRef<IFileSystem> outFileSystem, out ulong outSaveDataId, SaveDataSpaceId spaceId, in SaveDataAttribute attribute, bool openReadOnly, bool cacheExtraData);
|
||||||
Result ExtendSaveDataFileSystem(SaveDataSpaceId spaceId, ulong saveDataId, long dataSize, long journalSize);
|
Result ExtendSaveDataFileSystem(SaveDataSpaceId spaceId, ulong saveDataId, long dataSize, long journalSize);
|
||||||
Result DeleteSaveDataFileSystemBySaveDataSpaceId(SaveDataSpaceId spaceId, ulong saveDataId);
|
Result DeleteSaveDataFileSystemBySaveDataSpaceId(SaveDataSpaceId spaceId, ulong saveDataId);
|
||||||
|
|
|
@ -59,8 +59,7 @@ internal readonly struct ProgramIndexRegistryService
|
||||||
return Result.Success;
|
return Result.Success;
|
||||||
|
|
||||||
// Verify that the provided buffer is large enough to hold "programCount" entries
|
// Verify that the provided buffer is large enough to hold "programCount" entries
|
||||||
ReadOnlySpan<ProgramIndexMapInfo>
|
ReadOnlySpan<ProgramIndexMapInfo> mapInfo = programIndexMapInfo.AsSpan<ProgramIndexMapInfo>();
|
||||||
mapInfo = MemoryMarshal.Cast<byte, ProgramIndexMapInfo>(programIndexMapInfo.Buffer);
|
|
||||||
|
|
||||||
if (mapInfo.Length < programCount)
|
if (mapInfo.Length < programCount)
|
||||||
return ResultFs.InvalidSize.Log();
|
return ResultFs.InvalidSize.Log();
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -121,7 +121,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
|
||||||
|
|
||||||
using var fileSystem = new SharedRef<IFileSystem>();
|
using var fileSystem = new SharedRef<IFileSystem>();
|
||||||
|
|
||||||
Result res = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref, spaceId);
|
Result res = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref, spaceId, saveDataId);
|
||||||
if (res.IsFailure()) return res.Miss();
|
if (res.IsFailure()) return res.Miss();
|
||||||
|
|
||||||
// Get the path of the save data
|
// Get the path of the save data
|
||||||
|
@ -160,7 +160,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
|
||||||
{
|
{
|
||||||
using var fileSystem = new SharedRef<IFileSystem>();
|
using var fileSystem = new SharedRef<IFileSystem>();
|
||||||
|
|
||||||
Result res = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref, spaceId, in saveDataRootPath, true);
|
Result res = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref, spaceId, saveDataId, in saveDataRootPath, true);
|
||||||
if (res.IsFailure()) return res.Miss();
|
if (res.IsFailure()) return res.Miss();
|
||||||
|
|
||||||
bool isEmulatedOnHost = IsAllowedDirectorySaveData(spaceId, in saveDataRootPath);
|
bool isEmulatedOnHost = IsAllowedDirectorySaveData(spaceId, in saveDataRootPath);
|
||||||
|
@ -413,8 +413,8 @@ public class SaveDataFileSystemServiceImpl : IDisposable
|
||||||
|
|
||||||
using var fileSystem = new SharedRef<IFileSystem>();
|
using var fileSystem = new SharedRef<IFileSystem>();
|
||||||
|
|
||||||
Result res = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref, creationInfo.SpaceId, in saveDataRootPath,
|
Result res = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref, creationInfo.SpaceId, saveDataId,
|
||||||
allowEmulatedSave: false);
|
in saveDataRootPath, allowEmulatedSave: false);
|
||||||
if (res.IsFailure()) return res.Miss();
|
if (res.IsFailure()) return res.Miss();
|
||||||
|
|
||||||
using scoped var saveImageName = new Path();
|
using scoped var saveImageName = new Path();
|
||||||
|
@ -486,7 +486,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
|
||||||
_saveFileSystemCacheManager.Unregister(spaceId, saveDataId);
|
_saveFileSystemCacheManager.Unregister(spaceId, saveDataId);
|
||||||
|
|
||||||
// Open the directory containing the save data
|
// Open the directory containing the save data
|
||||||
Result res = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref, spaceId, in saveDataRootPath, false);
|
Result res = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref, spaceId, saveDataId, in saveDataRootPath, false);
|
||||||
if (res.IsFailure()) return res.Miss();
|
if (res.IsFailure()) return res.Miss();
|
||||||
|
|
||||||
using scoped var saveImageName = new Path();
|
using scoped var saveImageName = new Path();
|
||||||
|
@ -642,15 +642,15 @@ public class SaveDataFileSystemServiceImpl : IDisposable
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result OpenSaveDataDirectoryFileSystem(ref SharedRef<IFileSystem> outFileSystem,
|
public Result OpenSaveDataDirectoryFileSystem(ref SharedRef<IFileSystem> outFileSystem,
|
||||||
SaveDataSpaceId spaceId)
|
SaveDataSpaceId spaceId, ulong saveDataId)
|
||||||
{
|
{
|
||||||
using scoped var rootPath = new Path();
|
using scoped var rootPath = new Path();
|
||||||
|
|
||||||
return OpenSaveDataDirectoryFileSystem(ref outFileSystem, spaceId, in rootPath, allowEmulatedSave: true);
|
return OpenSaveDataDirectoryFileSystem(ref outFileSystem, spaceId, saveDataId, in rootPath, allowEmulatedSave: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result OpenSaveDataDirectoryFileSystem(ref SharedRef<IFileSystem> outFileSystem,
|
public Result OpenSaveDataDirectoryFileSystem(ref SharedRef<IFileSystem> outFileSystem,
|
||||||
SaveDataSpaceId spaceId, ref readonly Path saveDataRootPath, bool allowEmulatedSave)
|
SaveDataSpaceId spaceId, ulong saveDataId, ref readonly Path saveDataRootPath, bool allowEmulatedSave)
|
||||||
{
|
{
|
||||||
Result res;
|
Result res;
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,7 @@ public class SaveDataIndexer : ISaveDataIndexer
|
||||||
if (_handle != _indexer.GetHandle())
|
if (_handle != _indexer.GetHandle())
|
||||||
return ResultFs.InvalidHandle.Log();
|
return ResultFs.InvalidHandle.Log();
|
||||||
|
|
||||||
Span<SaveDataInfo> outInfos = MemoryMarshal.Cast<byte, SaveDataInfo>(saveDataInfoBuffer.Buffer);
|
Span<SaveDataInfo> outInfos = saveDataInfoBuffer.AsSpan<SaveDataInfo>();
|
||||||
|
|
||||||
int count;
|
int count;
|
||||||
for (count = 0; !_iterator.IsEnd() && count < outInfos.Length; count++)
|
for (count = 0; !_iterator.IsEnd() && count < outInfos.Length; count++)
|
||||||
|
|
|
@ -53,7 +53,7 @@ internal class SaveDataIndexerLiteInfoReader : SaveDataInfoReaderImpl
|
||||||
if (saveDataInfoBuffer.Size < Unsafe.SizeOf<SaveDataInfo>())
|
if (saveDataInfoBuffer.Size < Unsafe.SizeOf<SaveDataInfo>())
|
||||||
return ResultFs.InvalidSize.Log();
|
return ResultFs.InvalidSize.Log();
|
||||||
|
|
||||||
Unsafe.As<byte, SaveDataInfo>(ref MemoryMarshal.GetReference(saveDataInfoBuffer.Buffer)) = _info;
|
saveDataInfoBuffer.As<SaveDataInfo>() = _info;
|
||||||
readCount = 1;
|
readCount = 1;
|
||||||
_finishedIterating = true;
|
_finishedIterating = true;
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,7 @@ internal class SaveDataInfoFilterReader : SaveDataInfoReaderImpl
|
||||||
{
|
{
|
||||||
UnsafeHelpers.SkipParamInit(out readCount);
|
UnsafeHelpers.SkipParamInit(out readCount);
|
||||||
|
|
||||||
Span<SaveDataInfo> outInfo = MemoryMarshal.Cast<byte, SaveDataInfo>(saveDataInfoBuffer.Buffer);
|
Span<SaveDataInfo> outInfo = saveDataInfoBuffer.AsSpan<SaveDataInfo>();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
while (count < outInfo.Length)
|
while (count < outInfo.Length)
|
||||||
|
|
|
@ -22,6 +22,11 @@ public readonly ref struct InBuffer
|
||||||
return ref SpanHelpers.AsReadOnlyStruct<T>(_buffer);
|
return ref SpanHelpers.AsReadOnlyStruct<T>(_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ReadOnlySpan<T> AsSpan<T>() where T : unmanaged
|
||||||
|
{
|
||||||
|
return MemoryMarshal.Cast<byte, T>(_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static InBuffer FromSpan<T>(ReadOnlySpan<T> buffer) where T : unmanaged
|
public static InBuffer FromSpan<T>(ReadOnlySpan<T> buffer) where T : unmanaged
|
||||||
{
|
{
|
||||||
|
@ -52,6 +57,11 @@ public readonly ref struct OutBuffer
|
||||||
return ref SpanHelpers.AsStruct<T>(_buffer);
|
return ref SpanHelpers.AsStruct<T>(_buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Span<T> AsSpan<T>() where T : unmanaged
|
||||||
|
{
|
||||||
|
return MemoryMarshal.Cast<byte, T>(_buffer);
|
||||||
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static OutBuffer FromSpan<T>(Span<T> buffer) where T : unmanaged
|
public static OutBuffer FromSpan<T>(Span<T> buffer) where T : unmanaged
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue