Reorganize SaveDataFileSystemService

This commit is contained in:
Alex Barney 2024-01-26 15:49:50 -07:00
parent 49edb744c5
commit beca253086
12 changed files with 705 additions and 636 deletions

View file

@ -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.
/// Contents are undefined if the function does not return <see cref="Result.Success"/>.
/// </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.
/// Contents are undefined if the function does not return <see cref="Result.Success"/>
/// 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/>
/// <see cref="ResultFs.InvalidCharacter"/>: The path contains an invalid character.<br/>
/// <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)
{
UnsafeHelpers.SkipParamInit(out isNormalized, out length);
UnsafeHelpers.SkipParamInit(out isNormalized, out outNormalizedLength);
var state = PathState.Initial;
int pathLength = 0;
@ -311,7 +311,7 @@ public static class PathNormalizer
break;
}
length = pathLength;
outNormalizedLength = pathLength;
return Result.Success;
}

View file

@ -47,13 +47,13 @@ public static class FileSystemServerInitializer
InitializeFileSystemProxyServer(client, server);
var saveService = new SaveDataFileSystemService(fspConfig.SaveDataFileSystemService, processId);
using SharedRef<SaveDataFileSystemService> saveService = SaveDataFileSystemService.CreateShared(fspConfig.SaveDataFileSystemService, processId);
saveService.CleanUpTemporaryStorage().IgnoreResult();
saveService.CleanUpSaveData().IgnoreResult();
saveService.CompleteSaveDataExtension().IgnoreResult();
saveService.FixSaveData().IgnoreResult();
saveService.RecoverMultiCommit().IgnoreResult();
saveService.Get.CleanUpTemporaryStorage().IgnoreResult();
saveService.Get.CleanUpSaveData().IgnoreResult();
saveService.Get.CompleteSaveDataExtension().IgnoreResult();
saveService.Get.FixSaveData().IgnoreResult();
saveService.Get.RecoverMultiCommit().IgnoreResult();
config.StorageDeviceManagerFactory.SetReady(StorageDevicePortId.SdCard, null);
config.StorageDeviceManagerFactory.SetReady(StorageDevicePortId.GameCard, null);

View file

@ -204,7 +204,7 @@ public class DirectoryInterfaceAdapter : IDirectorySf
const int maxTryCount = 2;
UnsafeHelpers.SkipParamInit(out entriesRead);
Span<DirectoryEntry> entries = MemoryMarshal.Cast<byte, DirectoryEntry>(entryBuffer.Buffer);
Span<DirectoryEntry> entries = entryBuffer.AsSpan<DirectoryEntry>();
Result res = Result.Success;
long numRead = 0;

View file

@ -10,5 +10,5 @@ public interface ISaveDataMultiCommitCoreInterface : IDisposable
Result RecoverMultiCommit();
Result IsProvisionallyCommittedSaveData(out bool isProvisionallyCommitted, in SaveDataInfo saveInfo);
Result RecoverProvisionallyCommittedSaveData(in SaveDataInfo saveInfo, bool doRollback);
Result OpenMultiCommitContext(ref SharedRef<IFileSystem> contextFileSystem);
Result OpenMultiCommitContext(ref SharedRef<IFileSystem> outContextFileSystem);
}

View file

@ -20,7 +20,7 @@ public interface ISaveDataTransferCoreInterface : IDisposable
Result CancelSaveDataCreation(ulong saveDataId, SaveDataSpaceId spaceId);
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 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 ExtendSaveDataFileSystem(SaveDataSpaceId spaceId, ulong saveDataId, long dataSize, long journalSize);
Result DeleteSaveDataFileSystemBySaveDataSpaceId(SaveDataSpaceId spaceId, ulong saveDataId);

View file

@ -59,8 +59,7 @@ internal readonly struct ProgramIndexRegistryService
return Result.Success;
// Verify that the provided buffer is large enough to hold "programCount" entries
ReadOnlySpan<ProgramIndexMapInfo>
mapInfo = MemoryMarshal.Cast<byte, ProgramIndexMapInfo>(programIndexMapInfo.Buffer);
ReadOnlySpan<ProgramIndexMapInfo> mapInfo = programIndexMapInfo.AsSpan<ProgramIndexMapInfo>();
if (mapInfo.Length < programCount)
return ResultFs.InvalidSize.Log();

File diff suppressed because it is too large Load diff

View file

@ -121,7 +121,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
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();
// Get the path of the save data
@ -160,7 +160,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
{
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();
bool isEmulatedOnHost = IsAllowedDirectorySaveData(spaceId, in saveDataRootPath);
@ -413,8 +413,8 @@ public class SaveDataFileSystemServiceImpl : IDisposable
using var fileSystem = new SharedRef<IFileSystem>();
Result res = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref, creationInfo.SpaceId, in saveDataRootPath,
allowEmulatedSave: false);
Result res = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref, creationInfo.SpaceId, saveDataId,
in saveDataRootPath, allowEmulatedSave: false);
if (res.IsFailure()) return res.Miss();
using scoped var saveImageName = new Path();
@ -486,7 +486,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable
_saveFileSystemCacheManager.Unregister(spaceId, saveDataId);
// 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();
using scoped var saveImageName = new Path();
@ -642,15 +642,15 @@ public class SaveDataFileSystemServiceImpl : IDisposable
}
public Result OpenSaveDataDirectoryFileSystem(ref SharedRef<IFileSystem> outFileSystem,
SaveDataSpaceId spaceId)
SaveDataSpaceId spaceId, ulong saveDataId)
{
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,
SaveDataSpaceId spaceId, ref readonly Path saveDataRootPath, bool allowEmulatedSave)
SaveDataSpaceId spaceId, ulong saveDataId, ref readonly Path saveDataRootPath, bool allowEmulatedSave)
{
Result res;

View file

@ -156,7 +156,7 @@ public class SaveDataIndexer : ISaveDataIndexer
if (_handle != _indexer.GetHandle())
return ResultFs.InvalidHandle.Log();
Span<SaveDataInfo> outInfos = MemoryMarshal.Cast<byte, SaveDataInfo>(saveDataInfoBuffer.Buffer);
Span<SaveDataInfo> outInfos = saveDataInfoBuffer.AsSpan<SaveDataInfo>();
int count;
for (count = 0; !_iterator.IsEnd() && count < outInfos.Length; count++)

View file

@ -53,7 +53,7 @@ internal class SaveDataIndexerLiteInfoReader : SaveDataInfoReaderImpl
if (saveDataInfoBuffer.Size < Unsafe.SizeOf<SaveDataInfo>())
return ResultFs.InvalidSize.Log();
Unsafe.As<byte, SaveDataInfo>(ref MemoryMarshal.GetReference(saveDataInfoBuffer.Buffer)) = _info;
saveDataInfoBuffer.As<SaveDataInfo>() = _info;
readCount = 1;
_finishedIterating = true;

View file

@ -132,7 +132,7 @@ internal class SaveDataInfoFilterReader : SaveDataInfoReaderImpl
{
UnsafeHelpers.SkipParamInit(out readCount);
Span<SaveDataInfo> outInfo = MemoryMarshal.Cast<byte, SaveDataInfo>(saveDataInfoBuffer.Buffer);
Span<SaveDataInfo> outInfo = saveDataInfoBuffer.AsSpan<SaveDataInfo>();
int count = 0;
while (count < outInfo.Length)

View file

@ -22,6 +22,11 @@ public readonly ref struct InBuffer
return ref SpanHelpers.AsReadOnlyStruct<T>(_buffer);
}
public ReadOnlySpan<T> AsSpan<T>() where T : unmanaged
{
return MemoryMarshal.Cast<byte, T>(_buffer);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
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);
}
public Span<T> AsSpan<T>() where T : unmanaged
{
return MemoryMarshal.Cast<byte, T>(_buffer);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static OutBuffer FromSpan<T>(Span<T> buffer) where T : unmanaged
{