From 53809023763135e2fe45082d0e7f2a46674a296a Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Wed, 29 Dec 2021 10:13:42 -0700 Subject: [PATCH] Rename some save enum/struct fields --- .../Fs/ApplicationSaveDataManagement.cs | 8 +-- src/LibHac/Fs/FsEnums.cs | 6 +-- src/LibHac/Fs/SaveDataStructs.cs | 6 +-- src/LibHac/FsSrv/SaveDataFileSystemService.cs | 12 ++--- .../FsSrv/SaveDataFileSystemServiceImpl.cs | 54 +++++++++---------- src/LibHac/FsSrv/SaveDataIndexerManager.cs | 6 +-- .../ApplicationSaveDataManagementTests.cs | 4 +- .../ShimTests/SaveData.cs | 6 +-- .../ShimTests/SaveDataManagement.cs | 8 +-- 9 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/LibHac/Fs/ApplicationSaveDataManagement.cs b/src/LibHac/Fs/ApplicationSaveDataManagement.cs index 549e3e08..84c67d03 100644 --- a/src/LibHac/Fs/ApplicationSaveDataManagement.cs +++ b/src/LibHac/Fs/ApplicationSaveDataManagement.cs @@ -253,7 +253,7 @@ public static class ApplicationSaveDataManagement } else if (targetMedia == CacheStorageTargetMedia.SdCard) { - rc = TryCreateCacheStorage(fs, out requiredSizeLocal, SaveDataSpaceId.SdCache, applicationId, + rc = TryCreateCacheStorage(fs, out requiredSizeLocal, SaveDataSpaceId.SdUser, applicationId, saveDataOwnerId, index, dataSize, journalSize, allowExisting); if (rc.IsFailure()) return rc; } @@ -265,7 +265,7 @@ public static class ApplicationSaveDataManagement { target = CacheStorageTargetMedia.SdCard; - Result CreateFuncSdCard() => fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, + Result CreateFuncSdCard() => fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdUser, saveDataOwnerId, index, dataSize, journalSize, SaveDataFlags.None); rc = CreateSaveData(fs, CreateFuncSdCard, ref requiredSizeLocal, 0x4000, dataSize, journalSize); @@ -420,7 +420,7 @@ public static class ApplicationSaveDataManagement if (fs.IsSdCardAccessible()) { - Result rc = fs.FindSaveDataWithFilter(out _, SaveDataSpaceId.SdCache, in filter); + Result rc = fs.FindSaveDataWithFilter(out _, SaveDataSpaceId.SdUser, in filter); if (rc.IsFailure() && !ResultFs.TargetNotFound.Includes(rc)) return rc; if (rc.IsSuccess()) @@ -471,4 +471,4 @@ public static class ApplicationSaveDataManagement { return new UserId(uid.Id.High, uid.Id.Low); } -} +} \ No newline at end of file diff --git a/src/LibHac/Fs/FsEnums.cs b/src/LibHac/Fs/FsEnums.cs index cac7c8bf..48f82d31 100644 --- a/src/LibHac/Fs/FsEnums.cs +++ b/src/LibHac/Fs/FsEnums.cs @@ -52,7 +52,7 @@ public enum SaveDataSpaceId : byte User = 1, SdSystem = 2, Temporary = 3, - SdCache = 4, + SdUser = 4, ProperSystem = 100, SafeMode = 101, BisAuto = 127 @@ -260,5 +260,5 @@ public enum SdCardSpeedMode Sdr50 = 5, Sdr104 = 6, Ddr50 = 7, - Unknown = 8, -} + Unknown = 8 +} \ No newline at end of file diff --git a/src/LibHac/Fs/SaveDataStructs.cs b/src/LibHac/Fs/SaveDataStructs.cs index 09f39c14..6a691612 100644 --- a/src/LibHac/Fs/SaveDataStructs.cs +++ b/src/LibHac/Fs/SaveDataStructs.cs @@ -118,7 +118,7 @@ public struct SaveDataCreationInfo [FieldOffset(0x18)] public ulong OwnerId; [FieldOffset(0x20)] public SaveDataFlags Flags; [FieldOffset(0x24)] public SaveDataSpaceId SpaceId; - [FieldOffset(0x25)] public bool Field25; + [FieldOffset(0x25)] public bool IsPseudoSaveData; public static Result Make(out SaveDataCreationInfo creationInfo, long size, long journalSize, ulong ownerId, SaveDataFlags flags, SaveDataSpaceId spaceId) @@ -132,7 +132,7 @@ public struct SaveDataCreationInfo tempCreationInfo.OwnerId = ownerId; tempCreationInfo.Flags = flags; tempCreationInfo.SpaceId = spaceId; - tempCreationInfo.Field25 = false; + tempCreationInfo.IsPseudoSaveData = false; if (!SaveDataTypesValidity.IsValid(in tempCreationInfo)) return ResultFs.InvalidArgument.Log(); @@ -331,7 +331,7 @@ internal static class SaveDataTypesValidity public static bool IsValid(in SaveDataSpaceId spaceId) { - return (uint)spaceId <= (uint)SaveDataSpaceId.SdCache || spaceId == SaveDataSpaceId.ProperSystem || + return (uint)spaceId <= (uint)SaveDataSpaceId.SdUser || spaceId == SaveDataSpaceId.ProperSystem || spaceId == SaveDataSpaceId.SafeMode; } diff --git a/src/LibHac/FsSrv/SaveDataFileSystemService.cs b/src/LibHac/FsSrv/SaveDataFileSystemService.cs index 46e0b8e6..bf148599 100644 --- a/src/LibHac/FsSrv/SaveDataFileSystemService.cs +++ b/src/LibHac/FsSrv/SaveDataFileSystemService.cs @@ -102,7 +102,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave break; case SaveDataSpaceId.User: case SaveDataSpaceId.Temporary: - case SaveDataSpaceId.SdCache: + case SaveDataSpaceId.SdUser: if (!programInfo.AccessControl.CanCall(OperationType.OpenSaveDataInfoReader)) return ResultFs.PermissionDenied.Log(); break; @@ -1751,7 +1751,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave Result rc = GetProgramInfo(out ProgramInfo programInfo); if (rc.IsFailure()) return rc; - if (spaceId != SaveDataSpaceId.SdCache && spaceId != SaveDataSpaceId.User) + if (spaceId != SaveDataSpaceId.SdUser && spaceId != SaveDataSpaceId.User) return ResultFs.InvalidSaveDataSpaceId.Log(); using var filterReader = new UniqueRef(); @@ -1810,12 +1810,12 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave // Cache storage on the SD card will always take priority over case storage in NAND if (_serviceImpl.IsSdCardAccessible()) { - rc = SaveExists(out bool existsOnSdCard, SaveDataSpaceId.SdCache); + rc = SaveExists(out bool existsOnSdCard, SaveDataSpaceId.SdUser); if (rc.IsFailure()) return rc; if (existsOnSdCard) { - spaceId = SaveDataSpaceId.SdCache; + spaceId = SaveDataSpaceId.SdUser; return Result.Success; } } @@ -2207,7 +2207,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave return StorageType.Bis | StorageType.SdCard | StorageType.Usb; if (type == SaveDataType.System || - spaceId != SaveDataSpaceId.SdSystem && spaceId != SaveDataSpaceId.SdCache) + spaceId != SaveDataSpaceId.SdSystem && spaceId != SaveDataSpaceId.SdUser) return StorageType.Bis; return StorageType.SdCard | StorageType.Usb; @@ -2257,4 +2257,4 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave _openEntryCountSemaphore.Dispose(); _saveDataMountCountSemaphore.Dispose(); } -} +} \ No newline at end of file diff --git a/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs b/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs index 8db8ea91..5a6811da 100644 --- a/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs +++ b/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs @@ -659,37 +659,37 @@ public class SaveDataFileSystemServiceImpl return Result.Success; case SaveDataSpaceId.SdSystem: - case SaveDataSpaceId.SdCache: - { - rc = _config.BaseFsService.OpenSdCardProxyFileSystem(ref baseFileSystem.Ref(), true); - if (rc.IsFailure()) return rc.Miss(); + case SaveDataSpaceId.SdUser: + { + rc = _config.BaseFsService.OpenSdCardProxyFileSystem(ref baseFileSystem.Ref(), true); + if (rc.IsFailure()) return rc.Miss(); - // Hack around error CS8350. - const int bufferLength = 0x40; - Span buffer = stackalloc byte[bufferLength]; - ref byte bufferRef = ref MemoryMarshal.GetReference(buffer); - Span pathParentBuffer = MemoryMarshal.CreateSpan(ref bufferRef, bufferLength); + // Hack around error CS8350. + const int bufferLength = 0x40; + Span buffer = stackalloc byte[bufferLength]; + ref byte bufferRef = ref MemoryMarshal.GetReference(buffer); + Span pathParentBuffer = MemoryMarshal.CreateSpan(ref bufferRef, bufferLength); - using var pathParent = new Path(); - rc = PathFunctions.SetUpFixedPathSingleEntry(ref pathParent.Ref(), pathParentBuffer, - CommonPaths.SdCardNintendoRootDirectoryName); - if (rc.IsFailure()) return rc.Miss(); + using var pathParent = new Path(); + rc = PathFunctions.SetUpFixedPathSingleEntry(ref pathParent.Ref(), pathParentBuffer, + CommonPaths.SdCardNintendoRootDirectoryName); + if (rc.IsFailure()) return rc.Miss(); - using var pathSdRoot = new Path(); - rc = pathSdRoot.Combine(in pathParent, in basePath); - if (rc.IsFailure()) return rc.Miss(); + using var pathSdRoot = new Path(); + rc = pathSdRoot.Combine(in pathParent, in basePath); + if (rc.IsFailure()) return rc.Miss(); - using SharedRef tempFileSystem = - SharedRef.CreateMove(ref baseFileSystem.Ref()); - rc = Utility.WrapSubDirectory(ref baseFileSystem.Ref(), ref tempFileSystem.Ref(), in pathSdRoot, createIfMissing); - if (rc.IsFailure()) return rc.Miss(); + using SharedRef tempFileSystem = + SharedRef.CreateMove(ref baseFileSystem.Ref()); + rc = Utility.WrapSubDirectory(ref baseFileSystem.Ref(), ref tempFileSystem.Ref(), in pathSdRoot, createIfMissing); + if (rc.IsFailure()) return rc.Miss(); - rc = _config.EncryptedFsCreator.Create(ref outFileSystem, ref baseFileSystem.Ref(), - IEncryptedFileSystemCreator.KeyId.Save, in _encryptionSeed); - if (rc.IsFailure()) return rc.Miss(); + rc = _config.EncryptedFsCreator.Create(ref outFileSystem, ref baseFileSystem.Ref(), + IEncryptedFileSystemCreator.KeyId.Save, in _encryptionSeed); + if (rc.IsFailure()) return rc.Miss(); - return Result.Success; - } + return Result.Success; + } case SaveDataSpaceId.ProperSystem: rc = _config.BaseFsService.OpenBisFileSystem(ref baseFileSystem.Ref(), @@ -721,7 +721,7 @@ public class SaveDataFileSystemServiceImpl _config.SaveFsCreator.SetSdCardEncryptionSeed(seed.Value); _config.SaveIndexerManager.InvalidateIndexer(SaveDataSpaceId.SdSystem); - _config.SaveIndexerManager.InvalidateIndexer(SaveDataSpaceId.SdCache); + _config.SaveIndexerManager.InvalidateIndexer(SaveDataSpaceId.SdUser); return Result.Success; } @@ -817,4 +817,4 @@ public class SaveDataFileSystemServiceImpl { _config.SaveIndexerManager.ResetIndexer(SaveDataSpaceId.Temporary); } -} +} \ No newline at end of file diff --git a/src/LibHac/FsSrv/SaveDataIndexerManager.cs b/src/LibHac/FsSrv/SaveDataIndexerManager.cs index 45fd089c..3803fae8 100644 --- a/src/LibHac/FsSrv/SaveDataIndexerManager.cs +++ b/src/LibHac/FsSrv/SaveDataIndexerManager.cs @@ -85,7 +85,7 @@ internal class SaveDataIndexerManager : ISaveDataIndexerManager indexer = _bisIndexer.Indexer; break; case SaveDataSpaceId.SdSystem: - case SaveDataSpaceId.SdCache: + case SaveDataSpaceId.SdUser: // ReSharper doesn't realize that UniqueLock locks the indexer's lock object // ReSharper disable InconsistentlySynchronizedField indexerLock = new UniqueLock(_sdCardIndexer.Locker); @@ -176,7 +176,7 @@ internal class SaveDataIndexerManager : ISaveDataIndexerManager // Note: Nintendo doesn't lock when doing this operation lock (_sdCardIndexer.Locker) { - if (spaceId != SaveDataSpaceId.SdCache && spaceId != SaveDataSpaceId.SdSystem) + if (spaceId != SaveDataSpaceId.SdUser && spaceId != SaveDataSpaceId.SdSystem) { Abort.UnexpectedDefault(); } @@ -252,4 +252,4 @@ public class SaveDataIndexerAccessor : IDisposable { _locker.Dispose(); } -} +} \ No newline at end of file diff --git a/tests/LibHac.Tests/Fs/FileSystemClientTests/ApplicationSaveDataManagementTests.cs b/tests/LibHac.Tests/Fs/FileSystemClientTests/ApplicationSaveDataManagementTests.cs index 37eca4fb..560d8dae 100644 --- a/tests/LibHac.Tests/Fs/FileSystemClientTests/ApplicationSaveDataManagementTests.cs +++ b/tests/LibHac.Tests/Fs/FileSystemClientTests/ApplicationSaveDataManagementTests.cs @@ -140,7 +140,7 @@ public class ApplicationSaveDataManagementTests Assert.Equal(CacheStorageTargetMedia.SdCard, target); using var iterator = new UniqueRef(); - fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.SdCache); + fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.SdUser); var info = new SaveDataInfo[2]; Assert.Success(iterator.Get.ReadSaveDataInfo(out long entriesRead, info)); @@ -208,4 +208,4 @@ public class ApplicationSaveDataManagementTests Assert.Success(fs.GetCacheStorageTargetMedia(out CacheStorageTargetMedia target, new Ncm.ApplicationId(11))); Assert.Equal(CacheStorageTargetMedia.None, target); } -} +} \ No newline at end of file diff --git a/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/SaveData.cs b/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/SaveData.cs index 01709c9f..a54043f9 100644 --- a/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/SaveData.cs +++ b/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/SaveData.cs @@ -25,7 +25,7 @@ public class SaveData var applicationId = new Ncm.ApplicationId(1); FileSystemClient fs = FileSystemServerFactory.CreateClient(true); - fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId.Value, 0, 0, SaveDataFlags.None); + fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdUser, applicationId.Value, 0, 0, SaveDataFlags.None); fs.MountCacheStorage("cache".ToU8Span(), applicationId); fs.CreateFile("cache:/file".ToU8Span(), 0); @@ -43,7 +43,7 @@ public class SaveData var applicationId = new Ncm.ApplicationId(1); FileSystemClient fs = FileSystemServerFactory.CreateClient(true); - Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId.Value, 0, 0, SaveDataFlags.None)); + Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdUser, applicationId.Value, 0, 0, SaveDataFlags.None)); Assert.Success(fs.MountCacheStorage("cache".ToU8Span(), applicationId)); fs.CreateFile("cache:/sd".ToU8Span(), 0); fs.Commit("cache".ToU8Span()); @@ -64,4 +64,4 @@ public class SaveData Assert.Success(fs.GetEntryType(out _, "cache:/sd".ToU8Span())); Assert.Failure(fs.GetEntryType(out _, "cache:/bis".ToU8Span())); } -} +} \ No newline at end of file diff --git a/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/SaveDataManagement.cs b/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/SaveDataManagement.cs index 4ab80cfb..5bf97d8c 100644 --- a/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/SaveDataManagement.cs +++ b/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/SaveDataManagement.cs @@ -36,10 +36,10 @@ public class SaveDataManagement var applicationId = new Ncm.ApplicationId(1); FileSystemClient fs = FileSystemServerFactory.CreateClient(true); - Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId.Value, 0, 0, SaveDataFlags.None)); + Assert.Success(fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdUser, applicationId.Value, 0, 0, SaveDataFlags.None)); using var iterator = new UniqueRef(); - fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.SdCache); + fs.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.SdUser); var info = new SaveDataInfo[2]; iterator.Get.ReadSaveDataInfo(out long entriesRead, info); @@ -54,7 +54,7 @@ public class SaveDataManagement var applicationId = new Ncm.ApplicationId(1); FileSystemClient fs = FileSystemServerFactory.CreateClient(false); - Assert.Result(ResultFs.PortSdCardNoDevice, fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdCache, applicationId.Value, 0, 0, SaveDataFlags.None)); + Assert.Result(ResultFs.PortSdCardNoDevice, fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdUser, applicationId.Value, 0, 0, SaveDataFlags.None)); } [Fact] @@ -602,4 +602,4 @@ public class SaveDataManagement return Result.Success; } -} +} \ No newline at end of file