diff --git a/src/LibHac/Arp/ArpClient.cs b/src/LibHac/Arp/ArpClient.cs index 0cbca8c8..f01bd2bd 100644 --- a/src/LibHac/Arp/ArpClient.cs +++ b/src/LibHac/Arp/ArpClient.cs @@ -61,11 +61,11 @@ public class ArpClient : IDisposable return; using var reader = new SharedRef(); - Result rc = _hosClient.Sm.GetService(ref reader.Ref(), "arp:r"); + Result res = _hosClient.Sm.GetService(ref reader.Ref(), "arp:r"); - if (rc.IsFailure()) + if (res.IsFailure()) { - throw new HorizonResultException(rc, "Failed to initialize arp reader."); + throw new HorizonResultException(res, "Failed to initialize arp reader."); } _reader.SetByMove(ref reader.Ref()); diff --git a/src/LibHac/Bcat/BcatServer.cs b/src/LibHac/Bcat/BcatServer.cs index 0d898c4d..624a7c4e 100644 --- a/src/LibHac/Bcat/BcatServer.cs +++ b/src/LibHac/Bcat/BcatServer.cs @@ -36,10 +36,10 @@ public class BcatServer using SharedRef service = GetServiceCreator(type); - Result rc = Hos.Sm.RegisterService(new BcatServiceObject(ref service.Ref()), name); - if (rc.IsFailure()) + Result res = Hos.Sm.RegisterService(new BcatServiceObject(ref service.Ref()), name); + if (res.IsFailure()) { - throw new HorizonResultException(rc, "Abort"); + throw new HorizonResultException(res, "Abort"); } } diff --git a/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheDirectoryMetaAccessor.cs b/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheDirectoryMetaAccessor.cs index 2fd7a329..c8f5ac73 100644 --- a/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheDirectoryMetaAccessor.cs +++ b/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheDirectoryMetaAccessor.cs @@ -52,11 +52,11 @@ internal class DeliveryCacheDirectoryMetaAccessor { FileSystemClient fs = Server.GetFsClient(); - Result rc = fs.OpenFile(out FileHandle handle, path, OpenMode.Read); + Result res = fs.OpenFile(out FileHandle handle, path, OpenMode.Read); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (ResultFs.PathNotFound.Includes(rc)) + if (ResultFs.PathNotFound.Includes(res)) { if (allowMissingMetaFile) { @@ -64,10 +64,10 @@ internal class DeliveryCacheDirectoryMetaAccessor return Result.Success; } - return ResultBcat.NotFound.LogConverted(rc); + return ResultBcat.NotFound.LogConverted(res); } - return rc; + return res; } try @@ -76,16 +76,16 @@ internal class DeliveryCacheDirectoryMetaAccessor int header = 0; // Verify the header value - rc = fs.ReadFile(out long bytesRead, handle, 0, SpanHelpers.AsByteSpan(ref header)); - if (rc.IsFailure()) return rc; + res = fs.ReadFile(out long bytesRead, handle, 0, SpanHelpers.AsByteSpan(ref header)); + if (res.IsFailure()) return res.Miss(); if (bytesRead != sizeof(int) || header != MetaFileHeaderValue) return ResultBcat.InvalidDeliveryCacheStorageFile.Log(); // Read all the directory entries Span buffer = MemoryMarshal.Cast(Entries); - rc = fs.ReadFile(out bytesRead, handle, 4, buffer); - if (rc.IsFailure()) return rc; + res = fs.ReadFile(out bytesRead, handle, 4, buffer); + if (res.IsFailure()) return res.Miss(); Count = (int)((uint)bytesRead / Unsafe.SizeOf()); diff --git a/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheFileMetaAccessor.cs b/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheFileMetaAccessor.cs index 14520c29..20d03288 100644 --- a/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheFileMetaAccessor.cs +++ b/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheFileMetaAccessor.cs @@ -73,11 +73,11 @@ internal class DeliveryCacheFileMetaAccessor { FileSystemClient fs = Server.GetFsClient(); - Result rc = fs.OpenFile(out FileHandle handle, path, OpenMode.Read); + Result res = fs.OpenFile(out FileHandle handle, path, OpenMode.Read); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (ResultFs.PathNotFound.Includes(rc)) + if (ResultFs.PathNotFound.Includes(res)) { if (allowMissingMetaFile) { @@ -85,10 +85,10 @@ internal class DeliveryCacheFileMetaAccessor return Result.Success; } - return ResultBcat.NotFound.LogConverted(rc); + return ResultBcat.NotFound.LogConverted(res); } - return rc; + return res; } try @@ -97,16 +97,16 @@ internal class DeliveryCacheFileMetaAccessor int header = 0; // Verify the header value - rc = fs.ReadFile(out long bytesRead, handle, 0, SpanHelpers.AsByteSpan(ref header)); - if (rc.IsFailure()) return rc; + res = fs.ReadFile(out long bytesRead, handle, 0, SpanHelpers.AsByteSpan(ref header)); + if (res.IsFailure()) return res.Miss(); if (bytesRead != sizeof(int) || header != MetaFileHeaderValue) return ResultBcat.InvalidDeliveryCacheStorageFile.Log(); // Read all the file entries Span buffer = MemoryMarshal.Cast(Entries); - rc = fs.ReadFile(out bytesRead, handle, 4, buffer); - if (rc.IsFailure()) return rc; + res = fs.ReadFile(out bytesRead, handle, 4, buffer); + if (res.IsFailure()) return res.Miss(); Count = (int)((uint)bytesRead / Unsafe.SizeOf()); diff --git a/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheStorageManager.cs b/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheStorageManager.cs index c10712b3..c6252748 100644 --- a/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheStorageManager.cs +++ b/src/LibHac/Bcat/Impl/Service/Core/DeliveryCacheStorageManager.cs @@ -35,8 +35,8 @@ internal class DeliveryCacheStorageManager lock (_locker) { // Find an existing storage entry for this application ID or get an empty one - Result rc = FindOrGetUnusedEntry(out int index, applicationId); - if (rc.IsFailure()) return rc; + Result res = FindOrGetUnusedEntry(out int index, applicationId); + if (res.IsFailure()) return res.Miss(); ref Entry entry = ref Entries[index]; @@ -55,15 +55,15 @@ internal class DeliveryCacheStorageManager // Mount the save if enabled if (!DisableStorage) { - rc = Server.GetFsClient() + res = Server.GetFsClient() .MountBcatSaveData(new U8Span(mountName.Name), new Ncm.ApplicationId(applicationId)); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (ResultFs.TargetNotFound.Includes(rc)) - return ResultBcat.SaveDataNotFound.LogConverted(rc); + if (ResultFs.TargetNotFound.Includes(res)) + return ResultBcat.SaveDataNotFound.LogConverted(res); - return rc; + return res; } } @@ -121,11 +121,11 @@ internal class DeliveryCacheStorageManager if (!DisableStorage) { - Result rc = Server.GetFsClient().Commit(new U8Span(mountName.Name)); + Result res = Server.GetFsClient().Commit(new U8Span(mountName.Name)); - if (rc.IsFailure()) + if (res.IsFailure()) { - throw new HorizonResultException(rc, "Abort"); + throw new HorizonResultException(res, "Abort"); } } } @@ -141,19 +141,19 @@ internal class DeliveryCacheStorageManager AppendMountName(ref sb, applicationId); sb.Append(RootPath); - Result rc; + Result res; if (DisableStorage) { size = 0x4400000; - rc = Result.Success; + res = Result.Success; } else { - rc = Server.GetFsClient().GetFreeSpaceSize(out size, new U8Span(path)); + res = Server.GetFsClient().GetFreeSpaceSize(out size, new U8Span(path)); } - return rc; + return res; } } diff --git a/src/LibHac/Bcat/Impl/Service/DeliveryCacheDirectoryService.cs b/src/LibHac/Bcat/Impl/Service/DeliveryCacheDirectoryService.cs index 586905a8..ff1397c9 100644 --- a/src/LibHac/Bcat/Impl/Service/DeliveryCacheDirectoryService.cs +++ b/src/LibHac/Bcat/Impl/Service/DeliveryCacheDirectoryService.cs @@ -38,8 +38,8 @@ internal class DeliveryCacheDirectoryService : IDeliveryCacheDirectoryService return ResultBcat.AlreadyOpen.Log(); var metaReader = new DeliveryCacheFileMetaAccessor(Server); - Result rc = metaReader.ReadApplicationFileMeta(ApplicationId, ref name, false); - if (rc.IsFailure()) return rc; + Result res = metaReader.ReadApplicationFileMeta(ApplicationId, ref name, false); + if (res.IsFailure()) return res.Miss(); Count = metaReader.Count; _name = name; @@ -59,18 +59,18 @@ internal class DeliveryCacheDirectoryService : IDeliveryCacheDirectoryService return ResultBcat.NotOpen.Log(); var metaReader = new DeliveryCacheFileMetaAccessor(Server); - Result rc = metaReader.ReadApplicationFileMeta(ApplicationId, ref _name, true); - if (rc.IsFailure()) return rc; + Result res = metaReader.ReadApplicationFileMeta(ApplicationId, ref _name, true); + if (res.IsFailure()) return res.Miss(); int i; for (i = 0; i < entryBuffer.Length; i++) { - rc = metaReader.GetEntry(out DeliveryCacheFileMetaEntry entry, i); + res = metaReader.GetEntry(out DeliveryCacheFileMetaEntry entry, i); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (!ResultBcat.NotFound.Includes(rc)) - return rc; + if (!ResultBcat.NotFound.Includes(res)) + return res; break; } diff --git a/src/LibHac/Bcat/Impl/Service/DeliveryCacheFileService.cs b/src/LibHac/Bcat/Impl/Service/DeliveryCacheFileService.cs index 9954de1e..f6920fa3 100644 --- a/src/LibHac/Bcat/Impl/Service/DeliveryCacheFileService.cs +++ b/src/LibHac/Bcat/Impl/Service/DeliveryCacheFileService.cs @@ -43,17 +43,17 @@ internal class DeliveryCacheFileService : IDeliveryCacheFileService return ResultBcat.AlreadyOpen.Log(); var metaReader = new DeliveryCacheFileMetaAccessor(Server); - Result rc = metaReader.ReadApplicationFileMeta(ApplicationId, ref directoryName, true); - if (rc.IsFailure()) return rc; + Result res = metaReader.ReadApplicationFileMeta(ApplicationId, ref directoryName, true); + if (res.IsFailure()) return res.Miss(); - rc = metaReader.FindEntry(out DeliveryCacheFileMetaEntry entry, ref fileName); - if (rc.IsFailure()) return rc; + res = metaReader.FindEntry(out DeliveryCacheFileMetaEntry entry, ref fileName); + if (res.IsFailure()) return res.Miss(); Span filePath = stackalloc byte[0x80]; Server.GetStorageManager().GetFilePath(filePath, ApplicationId, ref directoryName, ref fileName); - rc = Server.GetFsClient().OpenFile(out _handle, new U8Span(filePath), OpenMode.Read); - if (rc.IsFailure()) return rc; + res = Server.GetFsClient().OpenFile(out _handle, new U8Span(filePath), OpenMode.Read); + if (res.IsFailure()) return res.Miss(); _metaEntry = entry; IsFileOpen = true; @@ -71,8 +71,8 @@ internal class DeliveryCacheFileService : IDeliveryCacheFileService if (!IsFileOpen) return ResultBcat.NotOpen.Log(); - Result rc = Server.GetFsClient().ReadFile(out long read, _handle, offset, destination); - if (rc.IsFailure()) return rc; + Result res = Server.GetFsClient().ReadFile(out long read, _handle, offset, destination); + if (res.IsFailure()) return res.Miss(); bytesRead = read; return Result.Success; diff --git a/src/LibHac/Bcat/Impl/Service/DeliveryCacheStorageService.cs b/src/LibHac/Bcat/Impl/Service/DeliveryCacheStorageService.cs index bfd95f59..9cd5bfec 100644 --- a/src/LibHac/Bcat/Impl/Service/DeliveryCacheStorageService.cs +++ b/src/LibHac/Bcat/Impl/Service/DeliveryCacheStorageService.cs @@ -60,18 +60,18 @@ internal class DeliveryCacheStorageService : IDeliveryCacheStorageService lock (Locker) { var metaReader = new DeliveryCacheDirectoryMetaAccessor(Server); - Result rc = metaReader.ReadApplicationDirectoryMeta(ApplicationId, true); - if (rc.IsFailure()) return rc; + Result res = metaReader.ReadApplicationDirectoryMeta(ApplicationId, true); + if (res.IsFailure()) return res.Miss(); int i; for (i = 0; i < nameBuffer.Length; i++) { - rc = metaReader.GetEntry(out DeliveryCacheDirectoryMetaEntry entry, i); + res = metaReader.GetEntry(out DeliveryCacheDirectoryMetaEntry entry, i); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (!ResultBcat.NotFound.Includes(rc)) - return rc; + if (!ResultBcat.NotFound.Includes(res)) + return res; break; } diff --git a/src/LibHac/Bcat/Impl/Service/ServiceCreator.cs b/src/LibHac/Bcat/Impl/Service/ServiceCreator.cs index f4cd1e9e..3fa2a452 100644 --- a/src/LibHac/Bcat/Impl/Service/ServiceCreator.cs +++ b/src/LibHac/Bcat/Impl/Service/ServiceCreator.cs @@ -25,11 +25,11 @@ internal class ServiceCreator : IServiceCreator public Result CreateDeliveryCacheStorageService(ref SharedRef outService, ulong processId) { - Result rc = Server.Hos.Arp.GetApplicationLaunchProperty(out ApplicationLaunchProperty launchProperty, + Result res = Server.Hos.Arp.GetApplicationLaunchProperty(out ApplicationLaunchProperty launchProperty, processId); - if (rc.IsFailure()) - return ResultBcat.NotFound.LogConverted(rc); + if (res.IsFailure()) + return ResultBcat.NotFound.LogConverted(res); return CreateDeliveryCacheStorageServiceImpl(ref outService, launchProperty.ApplicationId); } @@ -46,8 +46,8 @@ internal class ServiceCreator : IServiceCreator private Result CreateDeliveryCacheStorageServiceImpl(ref SharedRef outService, ApplicationId applicationId) { - Result rc = Server.GetStorageManager().Open(applicationId.Value); - if (rc.IsFailure()) return rc; + Result res = Server.GetStorageManager().Open(applicationId.Value); + if (res.IsFailure()) return res.Miss(); // todo: Check if network account required diff --git a/src/LibHac/Boot/Package1.cs b/src/LibHac/Boot/Package1.cs index eae84d17..4f954a99 100644 --- a/src/LibHac/Boot/Package1.cs +++ b/src/LibHac/Boot/Package1.cs @@ -108,40 +108,40 @@ public class Package1 _baseStorage.SetByCopy(in storage); // Read what might be a mariko header and check if it actually is a mariko header - Result rc = _baseStorage.Get.Read(0, SpanHelpers.AsByteSpan(ref _marikoOemHeader)); - if (rc.IsFailure()) return rc; + Result res = _baseStorage.Get.Read(0, SpanHelpers.AsByteSpan(ref _marikoOemHeader)); + if (res.IsFailure()) return res.Miss(); IsMariko = IsMarikoImpl(); if (IsMariko) { - rc = InitMarikoBodyStorage(); - if (rc.IsFailure()) return rc; + res = InitMarikoBodyStorage(); + if (res.IsFailure()) return res.Miss(); } else { - rc = _baseStorage.Get.GetSize(out long baseStorageSize); - if (rc.IsFailure()) return rc.Miss(); + res = _baseStorage.Get.GetSize(out long baseStorageSize); + if (res.IsFailure()) return res.Miss(); _bodyStorage = new SubStorage(in _baseStorage, 0, baseStorageSize); - rc = _bodyStorage.Read(0, SpanHelpers.AsByteSpan(ref _metaData)); - if (rc.IsFailure()) return rc; + res = _bodyStorage.Read(0, SpanHelpers.AsByteSpan(ref _metaData)); + if (res.IsFailure()) return res.Miss(); } - rc = ParseStage1(); - if (rc.IsFailure()) return rc; + res = ParseStage1(); + if (res.IsFailure()) return res.Miss(); - rc = ReadPk11Header(); - if (rc.IsFailure()) return rc; + res = ReadPk11Header(); + if (res.IsFailure()) return res.Miss(); if (!IsMariko && IsModern) { - rc = ReadModernEristaMac(); - if (rc.IsFailure()) return rc; + res = ReadModernEristaMac(); + if (res.IsFailure()) return res.Miss(); } - rc = SetPk11Storage(); - if (rc.IsFailure()) return rc; + res = SetPk11Storage(); + if (res.IsFailure()) return res.Miss(); // Make sure the PK11 section sizes add up to the expected size if (IsDecrypted && !VerifyPk11Sizes()) @@ -165,8 +165,8 @@ public class Package1 return ResultLibHac.InvalidPackage1MarikoBodySize.Log(); // Verify the body storage size is not smaller than the size in the header - Result rc = _baseStorage.Get.GetSize(out long totalSize); - if (rc.IsFailure()) return rc; + Result res = _baseStorage.Get.GetSize(out long totalSize); + if (res.IsFailure()) return res.Miss(); long bodySize = totalSize - Unsafe.SizeOf(); if (bodySize < MarikoOemHeader.Size) @@ -180,8 +180,8 @@ public class Package1 Span metaData2 = SpanHelpers.AsByteSpan(ref metaData[1]); // Read both the plaintext metadata and encrypted metadata - rc = bodySubStorage.Read(0, MemoryMarshal.Cast(metaData)); - if (rc.IsFailure()) return rc; + res = bodySubStorage.Read(0, MemoryMarshal.Cast(metaData)); + if (res.IsFailure()) return res.Miss(); // Set the body storage and decrypted metadata _metaData = metaData[0]; @@ -233,8 +233,8 @@ public class Package1 // Read the package1ldr footer int footerOffset = stage1Size - Unsafe.SizeOf(); - Result rc = _bodyStorage.Read(footerOffset, SpanHelpers.AsByteSpan(ref _stage1Footer)); - if (rc.IsFailure()) return rc; + Result res = _bodyStorage.Read(footerOffset, SpanHelpers.AsByteSpan(ref _stage1Footer)); + if (res.IsFailure()) return res.Miss(); // Get the PK11 size from the field in the unencrypted stage 1 footer Pk11Size = _stage1Footer.Pk11Size; @@ -259,8 +259,8 @@ public class Package1 // Read the PK11 header from the body storage int pk11Offset = IsModern ? ModernStage1Size : LegacyStage1Size; - Result rc = _bodyStorage.Read(pk11Offset, SpanHelpers.AsByteSpan(ref _pk11Header)); - if (rc.IsFailure()) return rc; + Result res = _bodyStorage.Read(pk11Offset, SpanHelpers.AsByteSpan(ref _pk11Header)); + if (res.IsFailure()) return res.Miss(); // Check if PK11 is already decrypted, creating the PK11 storage if it is IsDecrypted = _pk11Header.Magic == Package1Pk11Header.ExpectedMagic; diff --git a/src/LibHac/Boot/Package2StorageReader.cs b/src/LibHac/Boot/Package2StorageReader.cs index 66258236..df3468cb 100644 --- a/src/LibHac/Boot/Package2StorageReader.cs +++ b/src/LibHac/Boot/Package2StorageReader.cs @@ -39,8 +39,8 @@ public class Package2StorageReader : IDisposable /// The of the operation. public Result Initialize(KeySet keySet, in SharedRef storage) { - Result rc = storage.Get.Read(0, SpanHelpers.AsByteSpan(ref _header)); - if (rc.IsFailure()) return rc; + Result res = storage.Get.Read(0, SpanHelpers.AsByteSpan(ref _header)); + if (res.IsFailure()) return res.Miss(); _key = keySet.Package2Keys[_header.Meta.GetKeyGeneration()]; DecryptHeader(_key, ref _header.Meta, ref _header.Meta); @@ -105,8 +105,8 @@ public class Package2StorageReader : IDisposable // Ini is embedded in the kernel using var kernelStorage = new UniqueRef(); - Result rc = OpenKernel(ref kernelStorage.Ref()); - if (rc.IsFailure()) return rc; + Result res = OpenKernel(ref kernelStorage.Ref()); + if (res.IsFailure()) return res.Miss(); if (!IniExtract.TryGetIni1Offset(out int offset, out int size, kernelStorage.Get)) { @@ -124,11 +124,11 @@ public class Package2StorageReader : IDisposable /// The of the operation. public Result Verify() { - Result rc = VerifySignature(); - if (rc.IsFailure()) return rc; + Result res = VerifySignature(); + if (res.IsFailure()) return res.Miss(); - rc = VerifyMeta(); - if (rc.IsFailure()) return rc; + res = VerifyMeta(); + if (res.IsFailure()) return res.Miss(); return VerifyPayloads(); } @@ -143,8 +143,8 @@ public class Package2StorageReader : IDisposable Unsafe.SkipInit(out Package2Meta meta); Span metaBytes = SpanHelpers.AsByteSpan(ref meta); - Result rc = _storage.Get.Read(Package2Header.SignatureSize, metaBytes); - if (rc.IsFailure()) return rc; + Result res = _storage.Get.Read(Package2Header.SignatureSize, metaBytes); + if (res.IsFailure()) return res.Miss(); return _header.VerifySignature(_keySet.Package2SigningKeyParams.Modulus, metaBytes); } @@ -188,8 +188,8 @@ public class Package2StorageReader : IDisposable int toRead = Math.Min(array.Length, size); Span span = array.AsSpan(0, toRead); - Result rc = payloadSubStorage.Read(offset, span); - if (rc.IsFailure()) return rc; + Result res = payloadSubStorage.Read(offset, span); + if (res.IsFailure()) return res.Miss(); sha.Update(span); @@ -243,8 +243,8 @@ public class Package2StorageReader : IDisposable continue; using var payloadStorage = new UniqueRef(); - Result rc = OpenPayload(ref payloadStorage.Ref(), i); - if (rc.IsFailure()) return rc.Miss(); + Result res = OpenPayload(ref payloadStorage.Ref(), i); + if (res.IsFailure()) return res.Miss(); storages.Add(payloadStorage.Release()); } diff --git a/src/LibHac/Fs/AccessLog.cs b/src/LibHac/Fs/AccessLog.cs index 5039acf4..1fdba473 100644 --- a/src/LibHac/Fs/AccessLog.cs +++ b/src/LibHac/Fs/AccessLog.cs @@ -66,9 +66,9 @@ namespace LibHac.Fs using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.GetGlobalAccessLogMode(out mode); - fs.Impl.AbortIfNeeded(rc); - return rc; + Result res = fileSystemProxy.Get.GetGlobalAccessLogMode(out mode); + fs.Impl.AbortIfNeeded(res); + return res; } public static Result SetGlobalAccessLogMode(this FileSystemClient fs, GlobalAccessLogMode mode) @@ -82,9 +82,9 @@ namespace LibHac.Fs using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.SetGlobalAccessLogMode(mode); - fs.Impl.AbortIfNeeded(rc); - return rc; + Result res = fileSystemProxy.Get.SetGlobalAccessLogMode(mode); + fs.Impl.AbortIfNeeded(res); + return res; } public static void SetLocalAccessLog(this FileSystemClient fs, bool enabled) @@ -503,8 +503,8 @@ namespace LibHac.Fs.Impl private static void GetProgramIndexForAccessLog(FileSystemClientImpl fs, out int index, out int count) { using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.GetProgramIndexForAccessLog(out index, out count); - Abort.DoAbortUnless(rc.IsSuccess()); + Result res = fileSystemProxy.Get.GetProgramIndexForAccessLog(out index, out count); + Abort.DoAbortUnless(res.IsSuccess()); } private static void OutputAccessLogStart(FileSystemClientImpl fs) @@ -713,9 +713,9 @@ namespace LibHac.Fs.Impl } else { - Result rc = fs.Fs.GetGlobalAccessLogMode(out g.GlobalAccessLogMode); - fs.LogResultErrorMessage(rc); - if (rc.IsFailure()) Abort.DoAbort(rc); + Result res = fs.Fs.GetGlobalAccessLogMode(out g.GlobalAccessLogMode); + fs.LogResultErrorMessage(res); + if (res.IsFailure()) Abort.DoAbort(res); if (g.GlobalAccessLogMode != GlobalAccessLogMode.None) { @@ -771,9 +771,9 @@ namespace LibHac.Fs.Impl internal static bool IsEnabledFileSystemAccessorAccessLog(this FileSystemClientImpl fs, U8Span mountName) { - Result rc = fs.Find(out FileSystemAccessor accessor, mountName); + Result res = fs.Find(out FileSystemAccessor accessor, mountName); - if (rc.IsFailure()) + if (res.IsFailure()) return true; return accessor.IsEnabledAccessLog(); @@ -781,9 +781,9 @@ namespace LibHac.Fs.Impl public static void EnableFileSystemAccessorAccessLog(this FileSystemClientImpl fs, U8Span mountName) { - Result rc = fs.Find(out FileSystemAccessor fileSystem, mountName); - fs.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + Result res = fs.Find(out FileSystemAccessor fileSystem, mountName); + fs.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); fileSystem.SetAccessLog(true); } diff --git a/src/LibHac/Fs/ApplicationSaveDataManagement.cs b/src/LibHac/Fs/ApplicationSaveDataManagement.cs index bb0dcb2d..82a23a55 100644 --- a/src/LibHac/Fs/ApplicationSaveDataManagement.cs +++ b/src/LibHac/Fs/ApplicationSaveDataManagement.cs @@ -38,11 +38,11 @@ public static class ApplicationSaveDataManagement // ReSharper disable HeuristicUnreachableCode // Get the current save data size - Result rc = fs.Impl.GetSaveDataAvailableSize(out long availableSize, spaceId, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + Result res = fs.Impl.GetSaveDataAvailableSize(out long availableSize, spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); - rc = fs.Impl.GetSaveDataJournalSize(out long journalSize, spaceId, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Impl.GetSaveDataJournalSize(out long journalSize, spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); // Check if the save data needs to be extended if (availableSize < saveDataSize || journalSize < saveDataJournalSize) @@ -57,18 +57,18 @@ public static class ApplicationSaveDataManagement long newSaveDataSize = Math.Max(saveDataSize, availableSize); long newSaveDataJournalSize = Math.Max(saveDataJournalSize, journalSize); - rc = fs.Impl.ExtendSaveData(spaceId, saveDataId, newSaveDataSize, newSaveDataJournalSize); + res = fs.Impl.ExtendSaveData(spaceId, saveDataId, newSaveDataSize, newSaveDataJournalSize); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (ResultFs.UsableSpaceNotEnough.Includes(rc)) + if (ResultFs.UsableSpaceNotEnough.Includes(res)) { // Calculate how much space we need to extend the save data - rc = fs.QuerySaveDataTotalSize(out long currentSaveDataTotalSize, availableSize, journalSize); - if (rc.IsFailure()) return rc.Miss(); + res = fs.QuerySaveDataTotalSize(out long currentSaveDataTotalSize, availableSize, journalSize); + if (res.IsFailure()) return res.Miss(); - rc = fs.QuerySaveDataTotalSize(out long newSaveDataTotalSize, newSaveDataSize, newSaveDataJournalSize); - if (rc.IsFailure()) return rc.Miss(); + res = fs.QuerySaveDataTotalSize(out long newSaveDataTotalSize, newSaveDataSize, newSaveDataJournalSize); + if (res.IsFailure()) return res.Miss(); long newSaveDataSizeDifference = RoundUpOccupationSize(newSaveDataTotalSize) - RoundUpOccupationSize(currentSaveDataTotalSize); @@ -80,7 +80,7 @@ public static class ApplicationSaveDataManagement return ResultFs.UsableSpaceNotEnough.Log(); } - return rc.Miss(); + return res.Miss(); } } @@ -92,21 +92,21 @@ public static class ApplicationSaveDataManagement private static Result CreateSaveData(FileSystemClient fs, ref long inOutRequiredSize, Func createFunc, long saveDataSize, long saveDataJournalSize, long saveDataBaseSize) { - Result rc = createFunc(); + Result res = createFunc(); - if (rc.IsSuccess()) + if (res.IsSuccess()) return Result.Success; - if (ResultFs.UsableSpaceNotEnough.Includes(rc)) + if (ResultFs.UsableSpaceNotEnough.Includes(res)) { - rc = fs.QuerySaveDataTotalSize(out long saveDataTotalSize, saveDataSize, saveDataJournalSize); - if (rc.IsFailure()) return rc; + res = fs.QuerySaveDataTotalSize(out long saveDataTotalSize, saveDataSize, saveDataJournalSize); + if (res.IsFailure()) return res.Miss(); inOutRequiredSize += RoundUpOccupationSize(saveDataTotalSize) + saveDataBaseSize; } - else if (!ResultFs.PathAlreadyExists.Includes(rc)) + else if (!ResultFs.PathAlreadyExists.Includes(res)) { - return rc.Miss(); + return res.Miss(); } return Result.Success; @@ -116,30 +116,30 @@ public static class ApplicationSaveDataManagement in SaveDataFilter filter, Func createFunc, long saveDataSize, long saveDataJournalSize, long saveDataBaseSize) { - Result rc = fs.FindSaveDataWithFilter(out SaveDataInfo info, SaveDataSpaceId.User, in filter); + Result res = fs.FindSaveDataWithFilter(out SaveDataInfo info, SaveDataSpaceId.User, in filter); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (ResultFs.TargetNotFound.Includes(rc)) + if (ResultFs.TargetNotFound.Includes(res)) { - rc = CreateSaveData(fs, ref inOutRequiredSize, createFunc, saveDataSize, saveDataJournalSize, + res = CreateSaveData(fs, ref inOutRequiredSize, createFunc, saveDataSize, saveDataJournalSize, saveDataBaseSize); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } - return rc.Miss(); + return res.Miss(); } long requiredSize = 0; - rc = ExtendSaveDataIfNeeded(fs, ref requiredSize, SaveDataSpaceId.User, info.SaveDataId, saveDataSize, + res = ExtendSaveDataIfNeeded(fs, ref requiredSize, SaveDataSpaceId.User, info.SaveDataId, saveDataSize, saveDataJournalSize); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (!ResultFs.UsableSpaceNotEnough.Includes(rc)) - return rc.Miss(); + if (!ResultFs.UsableSpaceNotEnough.Includes(res)) + return res.Miss(); inOutRequiredSize += requiredSize; } @@ -210,15 +210,15 @@ public static class ApplicationSaveDataManagement if (bcatDeliveryCacheStorageSize > 0) { - Result rc = SaveDataFilter.Make(out SaveDataFilter filter, programId: default, SaveDataType.Bcat, + Result res = SaveDataFilter.Make(out SaveDataFilter filter, programId: default, SaveDataType.Bcat, userId: default, saveDataId: default, index: default); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); Result CreateBcatStorageFunc() => fs.CreateBcatSaveData(applicationId, bcatDeliveryCacheStorageSize); - rc = EnsureAndExtendSaveData(fs, ref requiredSize, in filter, CreateBcatStorageFunc, + res = EnsureAndExtendSaveData(fs, ref requiredSize, in filter, CreateBcatStorageFunc, bcatDeliveryCacheStorageSize, bcatDeliveryCacheJournalSize, 0x4000); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } if (requiredSize == 0) @@ -235,12 +235,12 @@ public static class ApplicationSaveDataManagement Ncm.ApplicationId applicationId) { UnsafeHelpers.SkipParamInit(out targetMedia); - Result rc; + Result res; if (fs.IsSdCardAccessible()) { - rc = DoesCacheStorageExist(out bool existsOnSd, SaveDataSpaceId.SdUser, fs, applicationId); - if (rc.IsFailure()) return rc.Miss(); + res = DoesCacheStorageExist(out bool existsOnSd, SaveDataSpaceId.SdUser, fs, applicationId); + if (res.IsFailure()) return res.Miss(); if (existsOnSd) { @@ -249,8 +249,8 @@ public static class ApplicationSaveDataManagement } } - rc = DoesCacheStorageExist(out bool existsOnNand, SaveDataSpaceId.User, fs, applicationId); - if (rc.IsFailure()) return rc.Miss(); + res = DoesCacheStorageExist(out bool existsOnNand, SaveDataSpaceId.User, fs, applicationId); + if (res.IsFailure()) return res.Miss(); targetMedia = existsOnNand ? CacheStorageTargetMedia.Nand : CacheStorageTargetMedia.None; return Result.Success; @@ -262,16 +262,16 @@ public static class ApplicationSaveDataManagement bool doesStorageExist = true; - Result rc = SaveDataFilter.Make(out SaveDataFilter filter, applicationId.Value, SaveDataType.Cache, + Result res = SaveDataFilter.Make(out SaveDataFilter filter, applicationId.Value, SaveDataType.Cache, userId: default, saveDataId: default, index: default); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); - rc = fs.Impl.FindSaveDataWithFilter(out SaveDataInfo _, spaceId, in filter); + res = fs.Impl.FindSaveDataWithFilter(out SaveDataInfo _, spaceId, in filter); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (!ResultFs.TargetNotFound.Includes(rc)) - return rc.Miss(); + if (!ResultFs.TargetNotFound.Includes(res)) + return res.Miss(); doesStorageExist = false; } @@ -287,26 +287,26 @@ public static class ApplicationSaveDataManagement { long requiredSize = 0; - Result rc = SaveDataFilter.Make(out SaveDataFilter filter, applicationId.Value, SaveDataType.Cache, + Result res = SaveDataFilter.Make(out SaveDataFilter filter, applicationId.Value, SaveDataType.Cache, userId: default, saveDataId: default, index); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); // Check if the cache storage already exists or not. bool doesStorageExist = true; - rc = fs.Impl.FindSaveDataWithFilter(out SaveDataInfo info, spaceId, in filter); + res = fs.Impl.FindSaveDataWithFilter(out SaveDataInfo info, spaceId, in filter); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (ResultFs.TargetNotFound.Includes(rc)) + if (ResultFs.TargetNotFound.Includes(res)) { doesStorageExist = false; } else { - fs.Impl.AbortIfNeeded(rc); - return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + return res.Miss(); } } @@ -315,32 +315,32 @@ public static class ApplicationSaveDataManagement // The cache storage already exists. Ensure it's large enough. if (!allowExisting) { - rc = ResultFs.AlreadyExists.Value; - fs.Impl.AbortIfNeeded(rc); - return rc.Miss(); + res = ResultFs.AlreadyExists.Value; + fs.Impl.AbortIfNeeded(res); + return res.Miss(); } - rc = ExtendSaveDataIfNeeded(fs, ref requiredSize, spaceId, info.SaveDataId, cacheStorageSize, + res = ExtendSaveDataIfNeeded(fs, ref requiredSize, spaceId, info.SaveDataId, cacheStorageSize, cacheStorageJournalSize); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (ResultFs.UsableSpaceNotEnough.Includes(rc)) + if (ResultFs.UsableSpaceNotEnough.Includes(res)) { // Don't return this error. If there's not enough space we return Success along with // The amount of space required to create the cache storage. } - else if (ResultFs.SaveDataExtending.Includes(rc)) + else if (ResultFs.SaveDataExtending.Includes(res)) { - rc = ResultFs.SaveDataCorrupted.LogConverted(rc); - fs.Impl.AbortIfNeeded(rc); - return rc.Miss(); + res = ResultFs.SaveDataCorrupted.LogConverted(res); + fs.Impl.AbortIfNeeded(res); + return res.Miss(); } else { - rc.Miss(); - fs.Impl.AbortIfNeeded(rc); - return rc; + res.Miss(); + fs.Impl.AbortIfNeeded(res); + return res; } } } @@ -350,11 +350,11 @@ public static class ApplicationSaveDataManagement Result CreateCacheFunc() => fs.CreateCacheStorage(applicationId, spaceId, saveDataOwnerId, index, cacheStorageSize, cacheStorageJournalSize, SaveDataFlags.None); - rc = CreateSaveData(fs, ref requiredSize, CreateCacheFunc, cacheStorageSize, cacheStorageJournalSize, + res = CreateSaveData(fs, ref requiredSize, CreateCacheFunc, cacheStorageSize, cacheStorageJournalSize, 0x4000); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); } outRequiredSize = requiredSize; @@ -369,26 +369,26 @@ public static class ApplicationSaveDataManagement long requiredSize = 0; // Check if the cache storage already exists - Result rc = GetCacheStorageTargetMediaImpl(fs, out CacheStorageTargetMedia media, applicationId); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetCacheStorageTargetMediaImpl(fs, out CacheStorageTargetMedia media, applicationId); + if (res.IsFailure()) return res.Miss(); if (media == CacheStorageTargetMedia.SdCard) { // If it exists on the SD card, ensure it's large enough. targetMedia = CacheStorageTargetMedia.SdCard; - rc = TryCreateCacheStorage(fs, ref requiredSize, SaveDataSpaceId.SdUser, applicationId, saveDataOwnerId, + res = TryCreateCacheStorage(fs, ref requiredSize, SaveDataSpaceId.SdUser, applicationId, saveDataOwnerId, index, cacheStorageSize, cacheStorageJournalSize, allowExisting); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } else if (media == CacheStorageTargetMedia.Nand) { // If it exists on the BIS, ensure it's large enough. targetMedia = CacheStorageTargetMedia.Nand; - rc = TryCreateCacheStorage(fs, ref requiredSize, SaveDataSpaceId.User, applicationId, saveDataOwnerId, + res = TryCreateCacheStorage(fs, ref requiredSize, SaveDataSpaceId.User, applicationId, saveDataOwnerId, index, cacheStorageSize, cacheStorageJournalSize, allowExisting); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } else { @@ -401,9 +401,9 @@ public static class ApplicationSaveDataManagement Result CreateStorageOnSdCard() => fs.CreateCacheStorage(applicationId, SaveDataSpaceId.SdUser, saveDataOwnerId, index, cacheStorageSize, cacheStorageJournalSize, SaveDataFlags.None); - rc = CreateSaveData(fs, ref requiredSize, CreateStorageOnSdCard, cacheStorageSize, cacheStorageJournalSize, + res = CreateSaveData(fs, ref requiredSize, CreateStorageOnSdCard, cacheStorageSize, cacheStorageJournalSize, 0x4000); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); // Don't use the SD card if it doesn't have enough space. if (requiredSize != 0) @@ -419,9 +419,9 @@ public static class ApplicationSaveDataManagement Result CreateStorageOnNand() => fs.CreateCacheStorage(applicationId, SaveDataSpaceId.User, saveDataOwnerId, index, cacheStorageSize, cacheStorageSize, SaveDataFlags.None); - rc = CreateSaveData(fs, ref requiredSize, CreateStorageOnNand, cacheStorageSize, cacheStorageJournalSize, + res = CreateSaveData(fs, ref requiredSize, CreateStorageOnNand, cacheStorageSize, cacheStorageJournalSize, 0x4000); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); if (requiredSize != 0) targetMedia = CacheStorageTargetMedia.None; @@ -443,18 +443,18 @@ public static class ApplicationSaveDataManagement long requiredSize = 0; - Result rc = SaveDataFilter.Make(out SaveDataFilter filter, applicationId.Value, SaveDataType.Device, + Result res = SaveDataFilter.Make(out SaveDataFilter filter, applicationId.Value, SaveDataType.Device, userId: default, saveDataId: default, index: default); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); const SaveDataFlags flags = SaveDataFlags.None; Result CreateSave() => fs.CreateDeviceSaveData(applicationId, applicationId.Value, saveDataSize, saveDataJournalSize, flags); - rc = EnsureAndExtendSaveData(fs.Fs, ref requiredSize, in filter, CreateSave, saveDataSize, saveDataJournalSize, + res = EnsureAndExtendSaveData(fs.Fs, ref requiredSize, in filter, CreateSave, saveDataSize, saveDataJournalSize, 0x4000); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); outRequiredSize = requiredSize; return Result.Success; @@ -463,9 +463,9 @@ public static class ApplicationSaveDataManagement public static Result GetCacheStorageTargetMedia(this FileSystemClient fs, out CacheStorageTargetMedia targetMedia, Ncm.ApplicationId applicationId) { - Result rc = GetCacheStorageTargetMediaImpl(fs, out targetMedia, applicationId); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetCacheStorageTargetMediaImpl(fs, out targetMedia, applicationId); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -476,11 +476,11 @@ public static class ApplicationSaveDataManagement { outRequiredSize = 0; - Result rc = EnsureApplicationCacheStorageImpl(fs, ref outRequiredSize, out targetMedia, applicationId, + Result res = EnsureApplicationCacheStorageImpl(fs, ref outRequiredSize, out targetMedia, applicationId, saveDataOwnerId, index, cacheStorageSize, cacheStorageJournalSize, allowExisting); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -490,12 +490,12 @@ public static class ApplicationSaveDataManagement { outRequiredSize = 0; - Result rc = EnsureApplicationCacheStorageImpl(fs, ref outRequiredSize, out _, applicationId, + Result res = EnsureApplicationCacheStorageImpl(fs, ref outRequiredSize, out _, applicationId, controlProperty.SaveDataOwnerId, index: 0, controlProperty.CacheStorageSize, controlProperty.CacheStorageJournalSize, true); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -509,12 +509,12 @@ public static class ApplicationSaveDataManagement if (controlProperty.CacheStorageSize > 0) { - Result rc = EnsureApplicationCacheStorageImpl(fs, ref outRequiredSize, out targetMedia, applicationId, + Result res = EnsureApplicationCacheStorageImpl(fs, ref outRequiredSize, out targetMedia, applicationId, controlProperty.SaveDataOwnerId, index: 0, controlProperty.CacheStorageSize, controlProperty.CacheStorageJournalSize, true); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -527,27 +527,27 @@ public static class ApplicationSaveDataManagement { UnsafeHelpers.SkipParamInit(out outRequiredSize, out targetMedia); - Result rc; + Result res; if (index > controlProperty.CacheStorageIndexMax) { - rc = ResultFs.CacheStorageIndexTooLarge.Value; - fs.Impl.AbortIfNeeded(rc); - return rc.Miss(); + res = ResultFs.CacheStorageIndexTooLarge.Value; + fs.Impl.AbortIfNeeded(res); + return res.Miss(); } if (cacheStorageSize + cacheStorageJournalSize > controlProperty.CacheStorageDataAndJournalSizeMax) { - rc = ResultFs.CacheStorageSizeTooLarge.Value; - fs.Impl.AbortIfNeeded(rc); - return rc.Miss(); + res = ResultFs.CacheStorageSizeTooLarge.Value; + fs.Impl.AbortIfNeeded(res); + return res.Miss(); } - rc = EnsureApplicationCacheStorageImpl(fs, ref outRequiredSize, out targetMedia, applicationId, + res = EnsureApplicationCacheStorageImpl(fs, ref outRequiredSize, out targetMedia, applicationId, controlProperty.SaveDataOwnerId, index, cacheStorageSize, cacheStorageJournalSize, false); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -556,31 +556,31 @@ public static class ApplicationSaveDataManagement { while (true) { - Result rc = SaveDataFilter.Make(out SaveDataFilter filter, programId: default, SaveDataType.Temporary, + Result res = SaveDataFilter.Make(out SaveDataFilter filter, programId: default, SaveDataType.Temporary, userId: default, saveDataId: default, index: default); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); // Try to find any temporary save data. - rc = fs.Impl.FindSaveDataWithFilter(out SaveDataInfo info, SaveDataSpaceId.Temporary, in filter); + res = fs.Impl.FindSaveDataWithFilter(out SaveDataInfo info, SaveDataSpaceId.Temporary, in filter); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (ResultFs.TargetNotFound.Includes(rc)) + if (ResultFs.TargetNotFound.Includes(res)) { // No more save data found. We're done cleaning. return Result.Success; } - fs.Impl.AbortIfNeeded(rc); - return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + return res.Miss(); } // Delete the found save data. - rc = fs.Impl.DeleteSaveData(SaveDataSpaceId.Temporary, info.SaveDataId); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Impl.DeleteSaveData(SaveDataSpaceId.Temporary, info.SaveDataId); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); } } @@ -589,11 +589,11 @@ public static class ApplicationSaveDataManagement { outRequiredSize = 0; - Result rc = EnsureApplicationBcatDeliveryCacheStorageImpl(fs, ref outRequiredSize, applicationId, + Result res = EnsureApplicationBcatDeliveryCacheStorageImpl(fs, ref outRequiredSize, applicationId, in controlProperty); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -604,9 +604,9 @@ public static class ApplicationSaveDataManagement UnsafeHelpers.SkipParamInit(out outRequiredSize); using var prohibiter = new UniqueRef(); - Result rc = fs.Impl.OpenSaveDataTransferProhibiterForCloudBackUp(ref prohibiter.Ref(), applicationId); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fs.Impl.OpenSaveDataTransferProhibiterForCloudBackUp(ref prohibiter.Ref(), applicationId); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); long requiredSize = 0; @@ -629,20 +629,20 @@ public static class ApplicationSaveDataManagement } UserId userId = Unsafe.As(ref Unsafe.AsRef(in user)); - rc = SaveDataFilter.Make(out SaveDataFilter filter, applicationId.Value, SaveDataType.Account, userId, + res = SaveDataFilter.Make(out SaveDataFilter filter, applicationId.Value, SaveDataType.Account, userId, saveDataId: default, index: default); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); long baseSize = RoundUpOccupationSize(new SaveDataMetaPolicy(SaveDataType.Account).GetSaveDataMetaSize()) + 0x8000; - rc = EnsureAndExtendSaveData(fs, ref requiredSize, in filter, CreateAccountSaveFunc, accountSaveDataSize, + res = EnsureAndExtendSaveData(fs, ref requiredSize, in filter, CreateAccountSaveFunc, accountSaveDataSize, accountSaveJournalSize, baseSize); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); } // Ensure the device save exists @@ -651,35 +651,35 @@ public static class ApplicationSaveDataManagement Result CreateDeviceSaveFunc() => fs.Impl.CreateDeviceSaveData(applicationId, saveDataOwnerId, deviceSaveDataSize, deviceSaveJournalSize, SaveDataFlags.None); - rc = SaveDataFilter.Make(out SaveDataFilter filter, applicationId.Value, SaveDataType.Device, + res = SaveDataFilter.Make(out SaveDataFilter filter, applicationId.Value, SaveDataType.Device, userId: default, saveDataId: default, index: default); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); long baseSize = RoundUpOccupationSize(new SaveDataMetaPolicy(SaveDataType.Device).GetSaveDataMetaSize()) + 0x8000; long requiredSizeForDeviceSaveData = 0; - rc = EnsureAndExtendSaveData(fs, ref requiredSizeForDeviceSaveData, in filter, CreateDeviceSaveFunc, + res = EnsureAndExtendSaveData(fs, ref requiredSizeForDeviceSaveData, in filter, CreateDeviceSaveFunc, deviceSaveDataSize, deviceSaveJournalSize, baseSize); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (requiredSizeForDeviceSaveData == 0) { - rc = fs.Impl.CreateDeviceSaveData(applicationId, saveDataOwnerId, deviceSaveDataSize, + res = fs.Impl.CreateDeviceSaveData(applicationId, saveDataOwnerId, deviceSaveDataSize, deviceSaveJournalSize, SaveDataFlags.None); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (ResultFs.PathAlreadyExists.Includes(rc)) + if (ResultFs.PathAlreadyExists.Includes(res)) { // Nothing to do if the save already exists. - rc.Catch().Handle(); + res.Catch().Handle(); } - else if (ResultFs.UsableSpaceNotEnough.Includes(rc)) + else if (ResultFs.UsableSpaceNotEnough.Includes(res)) { requiredSizeForDeviceSaveData += RoundUpOccupationSize(new SaveDataMetaPolicy(SaveDataType.Device).GetSaveDataMetaSize()) + @@ -687,8 +687,8 @@ public static class ApplicationSaveDataManagement } else { - fs.Impl.AbortIfNeeded(rc); - return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + return res.Miss(); } } } @@ -697,19 +697,19 @@ public static class ApplicationSaveDataManagement } long requiredSizeForBcat = 0; - rc = EnsureApplicationBcatDeliveryCacheStorageImpl(fs, ref requiredSizeForBcat, applicationId, + res = EnsureApplicationBcatDeliveryCacheStorageImpl(fs, ref requiredSizeForBcat, applicationId, in controlProperty); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (ResultFs.UsableSpaceNotEnough.Includes(rc)) + if (ResultFs.UsableSpaceNotEnough.Includes(res)) { requiredSize += requiredSizeForBcat; } else { - fs.Impl.AbortIfNeeded(rc); - return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + return res.Miss(); } } @@ -720,9 +720,9 @@ public static class ApplicationSaveDataManagement { UnsafeHelpers.SkipParamInit(out requiredSize); - Result rc = fs.Impl.QuerySaveDataTotalSize(out long saveDataTotalSize, + Result res = fs.Impl.QuerySaveDataTotalSize(out long saveDataTotalSize, controlProperty.TemporaryStorageSize, saveDataJournalSize: 0); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); requiredSize = RoundUpOccupationSize(saveDataTotalSize) + 0x4000; return Result.Success; @@ -730,30 +730,30 @@ public static class ApplicationSaveDataManagement if (requiredSize == 0) { - rc = fs.Impl.CreateTemporaryStorage(applicationId, saveDataOwnerId, + res = fs.Impl.CreateTemporaryStorage(applicationId, saveDataOwnerId, controlProperty.TemporaryStorageSize, SaveDataFlags.None); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (ResultFs.UsableSpaceNotEnough.Includes(rc)) + if (ResultFs.UsableSpaceNotEnough.Includes(res)) { - rc = CalculateRequiredSizeForTemporaryStorage(fs, out long temporaryStorageSize, + res = CalculateRequiredSizeForTemporaryStorage(fs, out long temporaryStorageSize, in controlProperty); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); requiredSize += temporaryStorageSize; } - else if (ResultFs.PathAlreadyExists.Includes(rc)) + else if (ResultFs.PathAlreadyExists.Includes(res)) { // Nothing to do if the save already exists. - rc.Catch().Handle(); + res.Catch().Handle(); } else { - fs.Impl.AbortIfNeeded(rc); - return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + return res.Miss(); } } } @@ -761,32 +761,32 @@ public static class ApplicationSaveDataManagement { // If there was already insufficient space to create the previous saves, check if the temp // save already exists instead of trying to create a new one. - rc = SaveDataFilter.Make(out SaveDataFilter filter, applicationId.Value, SaveDataType.Temporary, + res = SaveDataFilter.Make(out SaveDataFilter filter, applicationId.Value, SaveDataType.Temporary, userId: default, saveDataId: default, index: default); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); // Check if the temporary save exists - rc = fs.Impl.FindSaveDataWithFilter(out SaveDataInfo _, SaveDataSpaceId.Temporary, in filter); + res = fs.Impl.FindSaveDataWithFilter(out SaveDataInfo _, SaveDataSpaceId.Temporary, in filter); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (ResultFs.TargetNotFound.Includes(rc)) + if (ResultFs.TargetNotFound.Includes(res)) { // If it doesn't exist, calculate the size required to create it - rc = CalculateRequiredSizeForTemporaryStorage(fs, out long temporaryStorageSize, + res = CalculateRequiredSizeForTemporaryStorage(fs, out long temporaryStorageSize, in controlProperty); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); requiredSize += temporaryStorageSize; } else { - fs.Impl.AbortIfNeeded(rc); - return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + return res.Miss(); } } } @@ -800,9 +800,9 @@ public static class ApplicationSaveDataManagement outRequiredSize = requiredSize; - rc = ResultFs.UsableSpaceNotEnough.Log(); - fs.Impl.AbortIfNeeded(rc); - return rc; + res = ResultFs.UsableSpaceNotEnough.Log(); + fs.Impl.AbortIfNeeded(res); + return res; } public static Result ExtendApplicationSaveData(this FileSystemClient fs, out long outRequiredSize, @@ -811,40 +811,40 @@ public static class ApplicationSaveDataManagement { UnsafeHelpers.SkipParamInit(out outRequiredSize); - Result rc = CheckSaveDataType(type, in user); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckSaveDataType(type, in user); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); UserId userId = Unsafe.As(ref Unsafe.AsRef(in user)); - rc = SaveDataFilter.Make(out SaveDataFilter filter, applicationId.Value, type, userId, saveDataId: default, + res = SaveDataFilter.Make(out SaveDataFilter filter, applicationId.Value, type, userId, saveDataId: default, index: default); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = fs.Impl.FindSaveDataWithFilter(out SaveDataInfo info, SaveDataSpaceId.User, in filter); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Impl.FindSaveDataWithFilter(out SaveDataInfo info, SaveDataSpaceId.User, in filter); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = CheckExtensionSizeUnderMax(type, in controlProperty, saveDataSize, saveDataJournalSize); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = CheckExtensionSizeUnderMax(type, in controlProperty, saveDataSize, saveDataJournalSize); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); long requiredSize = 0; - rc = ExtendSaveDataIfNeeded(fs, ref requiredSize, SaveDataSpaceId.User, info.SaveDataId, saveDataSize, + res = ExtendSaveDataIfNeeded(fs, ref requiredSize, SaveDataSpaceId.User, info.SaveDataId, saveDataSize, saveDataJournalSize); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (ResultFs.UsableSpaceNotEnough.Includes(rc)) + if (ResultFs.UsableSpaceNotEnough.Includes(res)) { outRequiredSize = requiredSize; - fs.Impl.AbortIfNeeded(rc); - return rc.Rethrow(); + fs.Impl.AbortIfNeeded(res); + return res.Rethrow(); } - fs.Impl.AbortIfNeeded(rc); - return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + return res.Miss(); } return Result.Success; @@ -855,27 +855,27 @@ public static class ApplicationSaveDataManagement { UnsafeHelpers.SkipParamInit(out outSaveDataSize, out outSaveDataJournalSize); - Result rc = CheckSaveDataType(type, in user); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckSaveDataType(type, in user); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); UserId userId = Unsafe.As(ref Unsafe.AsRef(in user)); - rc = SaveDataFilter.Make(out SaveDataFilter filter, applicationId.Value, type, userId, saveDataId: default, + res = SaveDataFilter.Make(out SaveDataFilter filter, applicationId.Value, type, userId, saveDataId: default, index: default); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = fs.Impl.FindSaveDataWithFilter(out SaveDataInfo info, SaveDataSpaceId.User, in filter); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Impl.FindSaveDataWithFilter(out SaveDataInfo info, SaveDataSpaceId.User, in filter); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = fs.Impl.GetSaveDataAvailableSize(out long saveDataSize, info.SaveDataId); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Impl.GetSaveDataAvailableSize(out long saveDataSize, info.SaveDataId); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = fs.Impl.GetSaveDataJournalSize(out long saveDataJournalSize, info.SaveDataId); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Impl.GetSaveDataJournalSize(out long saveDataJournalSize, info.SaveDataId); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outSaveDataSize = saveDataSize; outSaveDataJournalSize = saveDataJournalSize; diff --git a/src/LibHac/Fs/Common/DirectoryPathParser.cs b/src/LibHac/Fs/Common/DirectoryPathParser.cs index 8db7ebe4..9eedc20f 100644 --- a/src/LibHac/Fs/Common/DirectoryPathParser.cs +++ b/src/LibHac/Fs/Common/DirectoryPathParser.cs @@ -49,8 +49,8 @@ public ref struct DirectoryPathParser if (windowsSkipLength != 0) { - Result rc = CurrentPath.InitializeWithNormalization(pathBuffer, windowsSkipLength + 1); - if (rc.IsFailure()) return rc; + Result res = CurrentPath.InitializeWithNormalization(pathBuffer, windowsSkipLength + 1); + if (res.IsFailure()) return res.Miss(); _buffer = _buffer.Slice(1); } @@ -60,8 +60,8 @@ public ref struct DirectoryPathParser if (!initialPath.IsEmpty) { - Result rc = CurrentPath.InitializeWithNormalization(initialPath); - if (rc.IsFailure()) return rc; + Result res = CurrentPath.InitializeWithNormalization(initialPath); + if (res.IsFailure()) return res.Miss(); } } diff --git a/src/LibHac/Fs/Common/FileStorage.cs b/src/LibHac/Fs/Common/FileStorage.cs index bdd06d76..601f976f 100644 --- a/src/LibHac/Fs/Common/FileStorage.cs +++ b/src/LibHac/Fs/Common/FileStorage.cs @@ -57,11 +57,11 @@ public class FileStorage : IStorage if (destination.Length == 0) return Result.Success; - Result rc = UpdateSize(); - if (rc.IsFailure()) return rc.Miss(); + Result res = UpdateSize(); + if (res.IsFailure()) return res.Miss(); - rc = CheckAccessRange(offset, destination.Length, _fileSize); - if (rc.IsFailure()) return rc.Miss(); + res = CheckAccessRange(offset, destination.Length, _fileSize); + if (res.IsFailure()) return res.Miss(); return _baseFile.Read(out _, offset, destination, ReadOption.None); } @@ -71,11 +71,11 @@ public class FileStorage : IStorage if (source.Length == 0) return Result.Success; - Result rc = UpdateSize(); - if (rc.IsFailure()) return rc.Miss(); + Result res = UpdateSize(); + if (res.IsFailure()) return res.Miss(); - rc = CheckAccessRange(offset, source.Length, _fileSize); - if (rc.IsFailure()) return rc.Miss(); + res = CheckAccessRange(offset, source.Length, _fileSize); + if (res.IsFailure()) return res.Miss(); return _baseFile.Write(offset, source, WriteOption.None); } @@ -89,8 +89,8 @@ public class FileStorage : IStorage { UnsafeHelpers.SkipParamInit(out size); - Result rc = UpdateSize(); - if (rc.IsFailure()) return rc.Miss(); + Result res = UpdateSize(); + if (res.IsFailure()) return res.Miss(); size = _fileSize; return Result.Success; @@ -108,8 +108,8 @@ public class FileStorage : IStorage { case OperationId.InvalidateCache: { - Result rc = _baseFile.OperateRange(OperationId.InvalidateCache, offset, size); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseFile.OperateRange(OperationId.InvalidateCache, offset, size); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -124,11 +124,11 @@ public class FileStorage : IStorage return Result.Success; } - Result rc = UpdateSize(); - if (rc.IsFailure()) return rc.Miss(); + Result res = UpdateSize(); + if (res.IsFailure()) return res.Miss(); - rc = CheckOffsetAndSize(offset, size); - if (rc.IsFailure()) return rc.Miss(); + res = CheckOffsetAndSize(offset, size); + if (res.IsFailure()) return res.Miss(); return _baseFile.OperateRange(outBuffer, operationId, offset, size, inBuffer); } @@ -142,8 +142,8 @@ public class FileStorage : IStorage if (_fileSize != InvalidSize) return Result.Success; - Result rc = _baseFile.GetSize(out long size); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseFile.GetSize(out long size); + if (res.IsFailure()) return res.Miss(); _fileSize = size; return Result.Success; @@ -183,8 +183,8 @@ public class FileStorageBasedFileSystem : FileStorage { using var baseFile = new UniqueRef(); - Result rc = baseFileSystem.Get.OpenFile(ref baseFile.Ref(), in path, mode); - if (rc.IsFailure()) return rc.Miss(); + Result res = baseFileSystem.Get.OpenFile(ref baseFile.Ref(), in path, mode); + if (res.IsFailure()) return res.Miss(); SetFile(baseFile.Get); _baseFileSystem.SetByMove(ref baseFileSystem); @@ -254,11 +254,11 @@ public class FileHandleStorage : IStorage if (destination.Length == 0) return Result.Success; - Result rc = UpdateSize(); - if (rc.IsFailure()) return rc.Miss(); + Result res = UpdateSize(); + if (res.IsFailure()) return res.Miss(); - rc = CheckAccessRange(offset, destination.Length, _size); - if (rc.IsFailure()) return rc.Miss(); + res = CheckAccessRange(offset, destination.Length, _size); + if (res.IsFailure()) return res.Miss(); return _fsClient.ReadFile(_handle, offset, destination, ReadOption.None); } @@ -270,11 +270,11 @@ public class FileHandleStorage : IStorage if (source.Length == 0) return Result.Success; - Result rc = UpdateSize(); - if (rc.IsFailure()) return rc.Miss(); + Result res = UpdateSize(); + if (res.IsFailure()) return res.Miss(); - rc = CheckAccessRange(offset, source.Length, _size); - if (rc.IsFailure()) return rc.Miss(); + res = CheckAccessRange(offset, source.Length, _size); + if (res.IsFailure()) return res.Miss(); return _fsClient.WriteFile(_handle, offset, source, WriteOption.None); } @@ -288,8 +288,8 @@ public class FileHandleStorage : IStorage { UnsafeHelpers.SkipParamInit(out size); - Result rc = UpdateSize(); - if (rc.IsFailure()) return rc.Miss(); + Result res = UpdateSize(); + if (res.IsFailure()) return res.Miss(); size = _size; return Result.Success; @@ -309,8 +309,8 @@ public class FileHandleStorage : IStorage if (outBuffer.Length != Unsafe.SizeOf()) return ResultFs.InvalidSize.Log(); - Result rc = _fsClient.QueryRange(out SpanHelpers.AsStruct(outBuffer), _handle, offset, size); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsClient.QueryRange(out SpanHelpers.AsStruct(outBuffer), _handle, offset, size); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -320,8 +320,8 @@ public class FileHandleStorage : IStorage if (_size != InvalidSize) return Result.Success; - Result rc = _fsClient.GetFileSize(out long size, _handle); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsClient.GetFileSize(out long size, _handle); + if (res.IsFailure()) return res.Miss(); _size = size; return Result.Success; diff --git a/src/LibHac/Fs/Common/Path.cs b/src/LibHac/Fs/Common/Path.cs index c34b368c..f705d6e4 100644 --- a/src/LibHac/Fs/Common/Path.cs +++ b/src/LibHac/Fs/Common/Path.cs @@ -129,8 +129,8 @@ public ref struct Path _length = path.GetLength(); - Result rc = Preallocate(_length + NullTerminatorLength); - if (rc.IsFailure()) return rc; + Result res = Preallocate(_length + NullTerminatorLength); + if (res.IsFailure()) return res.Miss(); int bytesCopied = StringUtils.Copy(_buffer, path._string, _length + NullTerminatorLength); @@ -404,8 +404,8 @@ public ref struct Path int otherLength = other.GetLength(); - Result rc = Preallocate(otherLength + NullTerminatorLength); - if (rc.IsFailure()) return rc; + Result res = Preallocate(otherLength + NullTerminatorLength); + if (res.IsFailure()) return res.Miss(); int bytesCopied = StringUtils.Copy(_writeBuffer, other.GetString(), otherLength + NullTerminatorLength); @@ -428,8 +428,8 @@ public ref struct Path { int otherLength = other.GetLength(); - Result rc = Preallocate(otherLength + NullTerminatorLength); - if (rc.IsFailure()) return rc; + Result res = Preallocate(otherLength + NullTerminatorLength); + if (res.IsFailure()) return res.Miss(); int bytesCopied = StringUtils.Copy(_writeBuffer, other.GetString(), otherLength + NullTerminatorLength); @@ -457,8 +457,8 @@ public ref struct Path return Result.Success; } - Result rc = Preallocate(length + NullTerminatorLength); - if (rc.IsFailure()) return rc; + Result res = Preallocate(length + NullTerminatorLength); + if (res.IsFailure()) return res.Miss(); int bytesCopied = StringUtils.Copy(GetWriteBuffer(), path, length + NullTerminatorLength); @@ -478,8 +478,8 @@ public ref struct Path /// : The operation was successful. public Result Initialize(ReadOnlySpan path) { - Result rc = InitializeImpl(path, StringUtils.GetLength(path)); - if (rc.IsFailure()) return rc; + Result res = InitializeImpl(path, StringUtils.GetLength(path)); + if (res.IsFailure()) return res.Miss(); _isNormalized = false; return Result.Success; @@ -500,8 +500,8 @@ public ref struct Path /// : The path is not in a valid format. public Result InitializeWithNormalization(ReadOnlySpan path) { - Result rc = Initialize(path); - if (rc.IsFailure()) return rc; + Result res = Initialize(path); + if (res.IsFailure()) return res.Miss(); if (_string.At(0) != NullTerminator && !WindowsPath.IsWindowsPath(_string, false) && _string.At(0) != DirectorySeparator) @@ -509,21 +509,21 @@ public ref struct Path var flags = new PathFlags(); flags.AllowRelativePath(); - rc = Normalize(flags); - if (rc.IsFailure()) return rc; + res = Normalize(flags); + if (res.IsFailure()) return res.Miss(); } else if (WindowsPath.IsWindowsPath(_string, true)) { var flags = new PathFlags(); flags.AllowWindowsPath(); - rc = Normalize(flags); - if (rc.IsFailure()) return rc; + res = Normalize(flags); + if (res.IsFailure()) return res.Miss(); } else { - rc = PathNormalizer.IsNormalized(out _isNormalized, out _, _string); - if (rc.IsFailure()) return rc; + res = PathNormalizer.IsNormalized(out _isNormalized, out _, _string); + if (res.IsFailure()) return res.Miss(); } // Note: I have no idea why Nintendo checks if the path is normalized @@ -544,8 +544,8 @@ public ref struct Path /// : The operation was successful. public Result Initialize(ReadOnlySpan path, int length) { - Result rc = InitializeImpl(path, length); - if (rc.IsFailure()) return rc; + Result res = InitializeImpl(path, length); + if (res.IsFailure()) return res.Miss(); _isNormalized = false; return Result.Success; @@ -567,8 +567,8 @@ public ref struct Path /// : The path is not in a valid format. public Result InitializeWithNormalization(ReadOnlySpan path, int length) { - Result rc = Initialize(path, length); - if (rc.IsFailure()) return rc; + Result res = Initialize(path, length); + if (res.IsFailure()) return res.Miss(); if (_string.At(0) != NullTerminator && !WindowsPath.IsWindowsPath(_string, false) && _string.At(0) != DirectorySeparator) @@ -576,21 +576,21 @@ public ref struct Path var flags = new PathFlags(); flags.AllowRelativePath(); - rc = Normalize(flags); - if (rc.IsFailure()) return rc; + res = Normalize(flags); + if (res.IsFailure()) return res.Miss(); } else if (WindowsPath.IsWindowsPath(_string, true)) { var flags = new PathFlags(); flags.AllowWindowsPath(); - rc = Normalize(flags); - if (rc.IsFailure()) return rc; + res = Normalize(flags); + if (res.IsFailure()) return res.Miss(); } else { - rc = PathNormalizer.IsNormalized(out _isNormalized, out _, _string); - if (rc.IsFailure()) return rc; + res = PathNormalizer.IsNormalized(out _isNormalized, out _, _string); + if (res.IsFailure()) return res.Miss(); } // Note: I have no idea why Nintendo checks if the path is normalized @@ -610,8 +610,8 @@ public ref struct Path /// : The operation was successful. public Result InitializeWithReplaceBackslash(ReadOnlySpan path) { - Result rc = InitializeImpl(path, StringUtils.GetLength(path)); - if (rc.IsFailure()) return rc; + Result res = InitializeImpl(path, StringUtils.GetLength(path)); + if (res.IsFailure()) return res.Miss(); if (_writeBufferLength > 1) { @@ -632,8 +632,8 @@ public ref struct Path /// : The operation was successful. public Result InitializeWithReplaceForwardSlashes(ReadOnlySpan path) { - Result rc = InitializeImpl(path, StringUtils.GetLength(path)); - if (rc.IsFailure()) return rc; + Result res = InitializeImpl(path, StringUtils.GetLength(path)); + if (res.IsFailure()) return res.Miss(); if (_writeBufferLength > 1) { @@ -663,8 +663,8 @@ public ref struct Path /// : The operation was successful. public Result InitializeWithReplaceUnc(ReadOnlySpan path) { - Result rc = InitializeImpl(path, StringUtils.GetLength(path)); - if (rc.IsFailure()) return rc; + Result res = InitializeImpl(path, StringUtils.GetLength(path)); + if (res.IsFailure()) return res.Miss(); _isNormalized = false; @@ -763,8 +763,8 @@ public ref struct Path } // Give our Path a buffer that can hold the combined string. - Result rc = Preallocate(parentLength + DirectorySeparator + childLength + NullTerminatorLength); - if (rc.IsFailure()) return rc; + Result res = Preallocate(parentLength + DirectorySeparator + childLength + NullTerminatorLength); + if (res.IsFailure()) return res.Miss(); Span destBuffer = GetWriteBuffer(); @@ -887,8 +887,8 @@ public ref struct Path ClearBuffer(); } - Result rc = Preallocate(parentLength + SeparatorLength + childLength + NullTerminatorLength); - if (rc.IsFailure()) return rc; + Result res = Preallocate(parentLength + SeparatorLength + childLength + NullTerminatorLength); + if (res.IsFailure()) return res.Miss(); Span destBuffer = GetWriteBuffer(); @@ -946,21 +946,21 @@ public ref struct Path int path1Length = path1.GetLength(); int path2Length = path2.GetLength(); - Result rc = Preallocate(path1Length + SeparatorLength + path2Length + NullTerminatorLength); - if (rc.IsFailure()) return rc; + Result res = Preallocate(path1Length + SeparatorLength + path2Length + NullTerminatorLength); + if (res.IsFailure()) return res.Miss(); - rc = Initialize(in path1); - if (rc.IsFailure()) return rc; + res = Initialize(in path1); + if (res.IsFailure()) return res.Miss(); if (IsEmpty()) { - rc = Initialize(in path2); - if (rc.IsFailure()) return rc; + res = Initialize(in path2); + if (res.IsFailure()) return res.Miss(); } else { - rc = AppendChild(in path2); - if (rc.IsFailure()) return rc; + res = AppendChild(in path2); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -982,14 +982,14 @@ public ref struct Path int path1Length = path1.GetLength(); int path2Length = StringUtils.GetLength(path2); - Result rc = Preallocate(path1Length + SeparatorLength + path2Length + NullTerminatorLength); - if (rc.IsFailure()) return rc; + Result res = Preallocate(path1Length + SeparatorLength + path2Length + NullTerminatorLength); + if (res.IsFailure()) return res.Miss(); - rc = Initialize(in path1); - if (rc.IsFailure()) return rc; + res = Initialize(in path1); + if (res.IsFailure()) return res.Miss(); - rc = AppendChild(path2); - if (rc.IsFailure()) return rc; + res = AppendChild(path2); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -1007,14 +1007,14 @@ public ref struct Path int path1Length = StringUtils.GetLength(path1); int path2Length = path2.GetLength(); - Result rc = Preallocate(path1Length + SeparatorLength + path2Length + NullTerminatorLength); - if (rc.IsFailure()) return rc; + Result res = Preallocate(path1Length + SeparatorLength + path2Length + NullTerminatorLength); + if (res.IsFailure()) return res.Miss(); - rc = Initialize(path1); - if (rc.IsFailure()) return rc; + res = Initialize(path1); + if (res.IsFailure()) return res.Miss(); - rc = AppendChild(in path2); - if (rc.IsFailure()) return rc; + res = AppendChild(in path2); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -1036,8 +1036,8 @@ public ref struct Path if (oldLength > 0) { ReadOnlySpan oldString = _string; - Result rc = Preallocate(oldLength); - if (rc.IsFailure()) return rc; + Result res = Preallocate(oldLength); + if (res.IsFailure()) return res.Miss(); StringUtils.Copy(_writeBuffer, oldString, oldLength + NullTerminatorLength); } @@ -1109,8 +1109,8 @@ public ref struct Path if (_isNormalized) return Result.Success; - Result rc = PathFormatter.IsNormalized(out bool isNormalized, out _, _string, flags); - if (rc.IsFailure()) return rc; + Result res = PathFormatter.IsNormalized(out bool isNormalized, out _, _string, flags); + if (res.IsFailure()) return res.Miss(); if (isNormalized) { @@ -1133,8 +1133,8 @@ public ref struct Path { rentedArray = ArrayPool.Shared.Rent(alignedBufferLength); - rc = PathFormatter.Normalize(rentedArray, GetWriteBuffer(), flags); - if (rc.IsFailure()) return rc; + res = PathFormatter.Normalize(rentedArray, GetWriteBuffer(), flags); + if (res.IsFailure()) return res.Miss(); SetModifiableBuffer(Shared.Move(ref rentedArray), alignedBufferLength); _isNormalized = true; @@ -1169,14 +1169,14 @@ public static class PathFunctions /// : The path is in an invalid format or is not normalized. public static Result SetUpFixedPath(ref Path path, ReadOnlySpan pathBuffer) { - Result rc = PathNormalizer.IsNormalized(out bool isNormalized, out _, pathBuffer); - if (rc.IsFailure()) return rc; + Result res = PathNormalizer.IsNormalized(out bool isNormalized, out _, pathBuffer); + if (res.IsFailure()) return res.Miss(); if (!isNormalized) return ResultFs.InvalidPathFormat.Log(); - rc = path.SetShallowBuffer(pathBuffer); - if (rc.IsFailure()) return rc; + res = path.SetShallowBuffer(pathBuffer); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Common/PathFormatter.cs b/src/LibHac/Fs/Common/PathFormatter.cs index ef95288e..6f5a8c72 100644 --- a/src/LibHac/Fs/Common/PathFormatter.cs +++ b/src/LibHac/Fs/Common/PathFormatter.cs @@ -238,7 +238,7 @@ public static class PathFormatter if (WindowsPath.IsUncPath(currentPath, false, true)) { - Result rc; + Result res; ReadOnlySpan finalPath = currentPath; @@ -253,9 +253,9 @@ public static class PathFormatter { if (currentComponentOffset != 0) { - rc = CheckSharedName( + res = CheckSharedName( currentPath.Slice(currentComponentOffset, pos - currentComponentOffset)); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); finalPath = currentPath.Slice(pos); break; @@ -264,8 +264,8 @@ public static class PathFormatter if (currentPath.At(pos + 1) == DirectorySeparator || currentPath.At(pos + 1) == AltDirectorySeparator) return ResultFs.InvalidPathFormat.Log(); - rc = CheckHostName(currentPath.Slice(2, pos - 2)); - if (rc.IsFailure()) return rc; + res = CheckHostName(currentPath.Slice(2, pos - 2)); + if (res.IsFailure()) return res.Miss(); currentComponentOffset = pos + 1; } @@ -276,8 +276,8 @@ public static class PathFormatter if (currentComponentOffset != 0 && finalPath == currentPath) { - rc = CheckSharedName(currentPath.Slice(currentComponentOffset, pos - currentComponentOffset)); - if (rc.IsFailure()) return rc; + res = CheckSharedName(currentPath.Slice(currentComponentOffset, pos - currentComponentOffset)); + if (res.IsFailure()) return res.Miss(); finalPath = currentPath.Slice(pos); } @@ -326,16 +326,16 @@ public static class PathFormatter { isNormalized = true; - Result rc = ParseWindowsPathImpl(out newPath, out windowsPathLength, Span.Empty, path, hasMountName); - if (!rc.IsSuccess()) + Result res = ParseWindowsPathImpl(out newPath, out windowsPathLength, Span.Empty, path, hasMountName); + if (!res.IsSuccess()) { - if (ResultFs.NotNormalized.Includes(rc)) + if (ResultFs.NotNormalized.Includes(res)) { isNormalized = false; } else { - return rc; + return res; } } @@ -396,8 +396,8 @@ public static class PathFormatter { UnsafeHelpers.SkipParamInit(out isNormalized, out normalizedLength); - Result rc = PathUtility.CheckUtf8(path); - if (rc.IsFailure()) return rc; + Result res = PathUtility.CheckUtf8(path); + if (res.IsFailure()) return res.Miss(); ReadOnlySpan buffer = path; int totalLength = 0; @@ -425,8 +425,8 @@ public static class PathFormatter bool hasMountName = false; - rc = SkipMountName(out buffer, out int mountNameLength, buffer); - if (rc.IsFailure()) return rc; + res = SkipMountName(out buffer, out int mountNameLength, buffer); + if (res.IsFailure()) return res.Miss(); if (mountNameLength != 0) { @@ -449,8 +449,8 @@ public static class PathFormatter bool isRelativePath = false; - rc = SkipRelativeDotPath(out buffer, out int relativePathLength, buffer); - if (rc.IsFailure()) return rc; + res = SkipRelativeDotPath(out buffer, out int relativePathLength, buffer); + if (res.IsFailure()) return res.Miss(); if (relativePathLength != 0) { @@ -469,8 +469,8 @@ public static class PathFormatter isRelativePath = true; } - rc = SkipWindowsPath(out buffer, out int windowsPathLength, out bool isNormalizedWin, buffer, hasMountName); - if (rc.IsFailure()) return rc; + res = SkipWindowsPath(out buffer, out int windowsPathLength, out bool isNormalizedWin, buffer, hasMountName); + if (res.IsFailure()) return res.Miss(); if (!isNormalizedWin) { @@ -513,9 +513,9 @@ public static class PathFormatter return Result.Success; } - rc = PathUtility.CheckInvalidBackslash(out bool isBackslashContained, buffer, + res = PathUtility.CheckInvalidBackslash(out bool isBackslashContained, buffer, flags.IsWindowsPathAllowed() || flags.IsBackslashAllowed()); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); if (isBackslashContained && !flags.IsBackslashAllowed()) { @@ -523,8 +523,8 @@ public static class PathFormatter return Result.Success; } - rc = PathNormalizer.IsNormalized(out isNormalized, out int length, buffer, flags.AreAllCharactersAllowed()); - if (rc.IsFailure()) return rc; + res = PathNormalizer.IsNormalized(out isNormalized, out int length, buffer, flags.AreAllCharactersAllowed()); + if (res.IsFailure()) return res.Miss(); totalLength += length; normalizedLength = totalLength; @@ -533,7 +533,7 @@ public static class PathFormatter public static Result Normalize(Span outputBuffer, ReadOnlySpan path, PathFlags flags) { - Result rc; + Result res; ReadOnlySpan src = path; int currentPos = 0; @@ -554,8 +554,8 @@ public static class PathFormatter if (flags.IsMountNameAllowed()) { - rc = ParseMountName(out src, out int mountNameLength, outputBuffer.Slice(currentPos), src); - if (rc.IsFailure()) return rc; + res = ParseMountName(out src, out int mountNameLength, outputBuffer.Slice(currentPos), src); + if (res.IsFailure()) return res.Miss(); currentPos += mountNameLength; hasMountName = mountNameLength != 0; @@ -578,8 +578,8 @@ public static class PathFormatter if (currentPos >= outputBuffer.Length) return ResultFs.TooLongPath.Log(); - rc = ParseRelativeDotPath(out src, out int relativePathLength, outputBuffer.Slice(currentPos), src); - if (rc.IsFailure()) return rc; + res = ParseRelativeDotPath(out src, out int relativePathLength, outputBuffer.Slice(currentPos), src); + if (res.IsFailure()) return res.Miss(); currentPos += relativePathLength; @@ -600,9 +600,9 @@ public static class PathFormatter if (currentPos >= outputBuffer.Length) return ResultFs.TooLongPath.Log(); - rc = ParseWindowsPath(out src, out int windowsPathLength, outputBuffer.Slice(currentPos), src, + res = ParseWindowsPath(out src, out int windowsPathLength, outputBuffer.Slice(currentPos), src, hasMountName); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); currentPos += windowsPathLength; @@ -624,9 +624,9 @@ public static class PathFormatter isWindowsPath = true; } - rc = PathUtility.CheckInvalidBackslash(out bool isBackslashContained, src, + res = PathUtility.CheckInvalidBackslash(out bool isBackslashContained, src, flags.IsWindowsPathAllowed() || flags.IsBackslashAllowed()); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); byte[] srcBufferSlashReplaced = null; try @@ -644,9 +644,9 @@ public static class PathFormatter src = srcBufferSlashReplaced.AsSpan(srcOffset); } - rc = PathNormalizer.Normalize(outputBuffer.Slice(currentPos), out _, src, isWindowsPath, isDriveRelative, + res = PathNormalizer.Normalize(outputBuffer.Slice(currentPos), out _, src, isWindowsPath, isDriveRelative, flags.AreAllCharactersAllowed()); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Common/PathNormalizer.cs b/src/LibHac/Fs/Common/PathNormalizer.cs index 4d49f715..f9bd509e 100644 --- a/src/LibHac/Fs/Common/PathNormalizer.cs +++ b/src/LibHac/Fs/Common/PathNormalizer.cs @@ -49,7 +49,7 @@ public static class PathNormalizer var convertedPath = new RentedArray(); try { - Result rc; + Result res; // Check if parent directory path replacement is needed. if (IsParentDirectoryPathReplacementNeeded(currentPath)) { @@ -100,8 +100,8 @@ public static class PathNormalizer { if (!allowAllCharacters) { - rc = CheckInvalidCharacter(currentPath[i + dirLen]); - if (rc.IsFailure()) return rc.Miss(); + res = CheckInvalidCharacter(currentPath[i + dirLen]); + if (res.IsFailure()) return res.Miss(); } dirLen++; @@ -185,8 +185,8 @@ public static class PathNormalizer outputBuffer[totalLength] = NullTerminator; - rc = IsNormalized(out bool isNormalized, out _, outputBuffer, allowAllCharacters); - if (rc.IsFailure()) return rc; + res = IsNormalized(out bool isNormalized, out _, outputBuffer, allowAllCharacters); + if (res.IsFailure()) return res.Miss(); Assert.SdkAssert(isNormalized); @@ -238,8 +238,8 @@ public static class PathNormalizer if (!allowAllCharacters && state != PathState.Initial) { - Result rc = CheckInvalidCharacter(c); - if (rc.IsFailure()) return rc; + Result res = CheckInvalidCharacter(c); + if (res.IsFailure()) return res.Miss(); } switch (state) diff --git a/src/LibHac/Fs/Common/PathUtility.cs b/src/LibHac/Fs/Common/PathUtility.cs index e62032af..70981d0e 100644 --- a/src/LibHac/Fs/Common/PathUtility.cs +++ b/src/LibHac/Fs/Common/PathUtility.cs @@ -56,9 +56,9 @@ public static class PathUtility if (length >= PathTool.EntryNameLengthMax + 1) return ResultFs.TooLongPath.Log(); - Result rc = PathFormatter.SkipMountName(out ReadOnlySpan pathWithoutMountName, out int skipLength, + Result res = PathFormatter.SkipMountName(out ReadOnlySpan pathWithoutMountName, out int skipLength, new U8Span(path)); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); if (!WindowsPath.IsWindowsPath(pathWithoutMountName, true)) { diff --git a/src/LibHac/Fs/Fsa/FileAccessor.cs b/src/LibHac/Fs/Fsa/FileAccessor.cs index 33694d73..6de95034 100644 --- a/src/LibHac/Fs/Fsa/FileAccessor.cs +++ b/src/LibHac/Fs/Fsa/FileAccessor.cs @@ -93,7 +93,7 @@ internal class FileAccessor : IDisposable { UnsafeHelpers.SkipParamInit(out bytesRead); - Result rc; + Result res; Span logBuffer = stackalloc byte[0x50]; var handle = new FileHandle(this); @@ -102,15 +102,15 @@ internal class FileAccessor : IDisposable if (Hos.Fs.Impl.IsEnabledAccessLog() && Hos.Fs.Impl.IsEnabledHandleAccessLog(handle)) { Tick start = Hos.Os.GetSystemTick(); - rc = _lastResult; + res = _lastResult; Tick end = Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogOffset).AppendFormat(offset) .Append(LogSize).AppendFormat(destination.Length) - .Append(LogReadSize).AppendFormat(AccessLogImpl.DereferenceOutValue(in bytesRead, rc)); + .Append(LogReadSize).AppendFormat(AccessLogImpl.DereferenceOutValue(in bytesRead, res)); - Hos.Fs.Impl.OutputAccessLog(rc, start, end, handle, new U8Span(logBuffer), + Hos.Fs.Impl.OutputAccessLog(res, start, end, handle, new U8Span(logBuffer), nameof(UserFile.ReadFile)); } @@ -130,23 +130,23 @@ internal class FileAccessor : IDisposable if (Hos.Fs.Impl.IsEnabledAccessLog() && Hos.Fs.Impl.IsEnabledHandleAccessLog(handle)) { Tick start = Hos.Os.GetSystemTick(); - rc = ReadWithoutCacheAccessLog(out bytesRead, offset, destination, in option); + res = ReadWithoutCacheAccessLog(out bytesRead, offset, destination, in option); Tick end = Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogOffset).AppendFormat(offset) .Append(LogSize).AppendFormat(destination.Length) - .Append(LogReadSize).AppendFormat(AccessLogImpl.DereferenceOutValue(in bytesRead, rc)); + .Append(LogReadSize).AppendFormat(AccessLogImpl.DereferenceOutValue(in bytesRead, res)); - Hos.Fs.Impl.OutputAccessLog(rc, start, end, handle, new U8Span(logBuffer), + Hos.Fs.Impl.OutputAccessLog(res, start, end, handle, new U8Span(logBuffer), nameof(UserFile.ReadFile)); } else { - rc = ReadWithoutCacheAccessLog(out bytesRead, offset, destination, in option); + res = ReadWithoutCacheAccessLog(out bytesRead, offset, destination, in option); } - return rc; + return res; } public Result Write(long offset, ReadOnlySpan source, in WriteOption option) @@ -159,14 +159,14 @@ internal class FileAccessor : IDisposable if (_filePathHash is not null) { - Result rc = UpdateLastResult(Hos.Fs.Impl.WriteViaPathBasedFileDataCache(_file.Get, (int)GetOpenMode(), + Result res = UpdateLastResult(Hos.Fs.Impl.WriteViaPathBasedFileDataCache(_file.Get, (int)GetOpenMode(), _parentFileSystem, in _filePathHash.Value, _pathHashIndex, offset, source, in option)); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } else { - Result rc = UpdateLastResult(_file.Get.Write(offset, source, in option)); - if (rc.IsFailure()) return rc; + Result res = UpdateLastResult(_file.Get.Write(offset, source, in option)); + if (res.IsFailure()) return res.Miss(); } setter.Set(option.HasFlushFlag() ? WriteState.None : WriteState.NeedsFlush); @@ -181,8 +181,8 @@ internal class FileAccessor : IDisposable using ScopedSetter setter = ScopedSetter.MakeScopedSetter(ref _writeState, WriteState.Failed); - Result rc = UpdateLastResult(_file.Get.Flush()); - if (rc.IsFailure()) return rc; + Result res = UpdateLastResult(_file.Get.Flush()); + if (res.IsFailure()) return res.Miss(); setter.Set(WriteState.None); return Result.Success; @@ -201,16 +201,16 @@ internal class FileAccessor : IDisposable { using UniqueLock lk = Hos.Fs.Impl.LockPathBasedFileDataCacheEntries(); - Result rc = UpdateLastResult(_file.Get.SetSize(size)); - if (rc.IsFailure()) return rc.Miss(); + Result res = UpdateLastResult(_file.Get.SetSize(size)); + if (res.IsFailure()) return res.Miss(); Hos.Fs.Impl.InvalidatePathBasedFileDataCacheEntry(_parentFileSystem, in _filePathHash.Value, _pathHashIndex); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } else { - Result rc = UpdateLastResult(_file.Get.SetSize(size)); - if (rc.IsFailure()) return rc; + Result res = UpdateLastResult(_file.Get.SetSize(size)); + if (res.IsFailure()) return res.Miss(); } setter.Set(originalWriteState); diff --git a/src/LibHac/Fs/Fsa/FileSystemAccessor.cs b/src/LibHac/Fs/Fsa/FileSystemAccessor.cs index 4d5bec42..8177e537 100644 --- a/src/LibHac/Fs/Fsa/FileSystemAccessor.cs +++ b/src/LibHac/Fs/Fsa/FileSystemAccessor.cs @@ -146,9 +146,9 @@ internal class FileSystemAccessor : IDisposable private Result SetUpPath(ref Path path, U8Span pathBuffer) { - Result rc = PathFormatter.IsNormalized(out bool isNormalized, out _, pathBuffer, _pathFlags); + Result res = PathFormatter.IsNormalized(out bool isNormalized, out _, pathBuffer, _pathFlags); - if (rc.IsSuccess() && isNormalized) + if (res.IsSuccess() && isNormalized) { path.SetShallowBuffer(pathBuffer); } @@ -156,17 +156,17 @@ internal class FileSystemAccessor : IDisposable { if (_pathFlags.IsWindowsPathAllowed()) { - rc = path.InitializeWithReplaceForwardSlashes(pathBuffer); - if (rc.IsFailure()) return rc; + res = path.InitializeWithReplaceForwardSlashes(pathBuffer); + if (res.IsFailure()) return res.Miss(); } else { - rc = path.InitializeWithReplaceBackslash(pathBuffer); - if (rc.IsFailure()) return rc; + res = path.InitializeWithReplaceBackslash(pathBuffer); + if (res.IsFailure()) return res.Miss(); } - rc = path.Normalize(_pathFlags); - if (rc.IsFailure()) return rc; + res = path.Normalize(_pathFlags); + if (res.IsFailure()) return res.Miss(); } if (path.GetLength() > PathTool.EntryNameLengthMax) @@ -178,22 +178,22 @@ internal class FileSystemAccessor : IDisposable public Result CreateFile(U8Span path, long size, CreateFileOptions option) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); if (_isPathCacheAttached) { using UniqueLock lk = Hos.Fs.Impl.LockPathBasedFileDataCacheEntries(); - rc = _fileSystem.Get.CreateFile(in pathNormalized, size, option); - if (rc.IsFailure()) return rc.Miss(); + res = _fileSystem.Get.CreateFile(in pathNormalized, size, option); + if (res.IsFailure()) return res.Miss(); Hos.Fs.Impl.InvalidatePathBasedFileDataCacheEntry(this, in pathNormalized); } else { - rc = _fileSystem.Get.CreateFile(in pathNormalized, size, option); - if (rc.IsFailure()) return rc; + res = _fileSystem.Get.CreateFile(in pathNormalized, size, option); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -202,11 +202,11 @@ internal class FileSystemAccessor : IDisposable public Result DeleteFile(U8Span path) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); - rc = _fileSystem.Get.DeleteFile(in pathNormalized); - if (rc.IsFailure()) return rc; + res = _fileSystem.Get.DeleteFile(in pathNormalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -214,11 +214,11 @@ internal class FileSystemAccessor : IDisposable public Result CreateDirectory(U8Span path) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); - rc = _fileSystem.Get.CreateDirectory(in pathNormalized); - if (rc.IsFailure()) return rc; + res = _fileSystem.Get.CreateDirectory(in pathNormalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -226,11 +226,11 @@ internal class FileSystemAccessor : IDisposable public Result DeleteDirectory(U8Span path) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); - rc = _fileSystem.Get.CreateDirectory(in pathNormalized); - if (rc.IsFailure()) return rc; + res = _fileSystem.Get.CreateDirectory(in pathNormalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -238,11 +238,11 @@ internal class FileSystemAccessor : IDisposable public Result DeleteDirectoryRecursively(U8Span path) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); - rc = _fileSystem.Get.DeleteDirectoryRecursively(in pathNormalized); - if (rc.IsFailure()) return rc; + res = _fileSystem.Get.DeleteDirectoryRecursively(in pathNormalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -250,11 +250,11 @@ internal class FileSystemAccessor : IDisposable public Result CleanDirectoryRecursively(U8Span path) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); - rc = _fileSystem.Get.CleanDirectoryRecursively(in pathNormalized); - if (rc.IsFailure()) return rc; + res = _fileSystem.Get.CleanDirectoryRecursively(in pathNormalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -262,26 +262,26 @@ internal class FileSystemAccessor : IDisposable public Result RenameFile(U8Span currentPath, U8Span newPath) { using var currentPathNormalized = new Path(); - Result rc = SetUpPath(ref currentPathNormalized.Ref(), currentPath); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref currentPathNormalized.Ref(), currentPath); + if (res.IsFailure()) return res.Miss(); using var newPathNormalized = new Path(); - rc = SetUpPath(ref newPathNormalized.Ref(), newPath); - if (rc.IsFailure()) return rc; + res = SetUpPath(ref newPathNormalized.Ref(), newPath); + if (res.IsFailure()) return res.Miss(); if (_isPathCacheAttached) { using UniqueLock lk = Hos.Fs.Impl.LockPathBasedFileDataCacheEntries(); - rc = _fileSystem.Get.RenameFile(in currentPathNormalized, in newPathNormalized); - if (rc.IsFailure()) return rc.Miss(); + res = _fileSystem.Get.RenameFile(in currentPathNormalized, in newPathNormalized); + if (res.IsFailure()) return res.Miss(); Hos.Fs.Impl.InvalidatePathBasedFileDataCacheEntry(this, in newPathNormalized); } else { - rc = _fileSystem.Get.RenameFile(in currentPathNormalized, in newPathNormalized); - if (rc.IsFailure()) return rc; + res = _fileSystem.Get.RenameFile(in currentPathNormalized, in newPathNormalized); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -290,26 +290,26 @@ internal class FileSystemAccessor : IDisposable public Result RenameDirectory(U8Span currentPath, U8Span newPath) { using var currentPathNormalized = new Path(); - Result rc = SetUpPath(ref currentPathNormalized.Ref(), currentPath); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref currentPathNormalized.Ref(), currentPath); + if (res.IsFailure()) return res.Miss(); using var newPathNormalized = new Path(); - rc = SetUpPath(ref newPathNormalized.Ref(), newPath); - if (rc.IsFailure()) return rc; + res = SetUpPath(ref newPathNormalized.Ref(), newPath); + if (res.IsFailure()) return res.Miss(); if (_isPathCacheAttached) { using UniqueLock lk = Hos.Fs.Impl.LockPathBasedFileDataCacheEntries(); - rc = _fileSystem.Get.RenameDirectory(in currentPathNormalized, in newPathNormalized); - if (rc.IsFailure()) return rc.Miss(); + res = _fileSystem.Get.RenameDirectory(in currentPathNormalized, in newPathNormalized); + if (res.IsFailure()) return res.Miss(); Hos.Fs.Impl.InvalidatePathBasedFileDataCacheEntries(this); } else { - rc = _fileSystem.Get.RenameDirectory(in currentPathNormalized, in newPathNormalized); - if (rc.IsFailure()) return rc; + res = _fileSystem.Get.RenameDirectory(in currentPathNormalized, in newPathNormalized); + if (res.IsFailure()) return res.Miss(); } return Result.Success; } @@ -319,11 +319,11 @@ internal class FileSystemAccessor : IDisposable UnsafeHelpers.SkipParamInit(out entryType); using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); - rc = _fileSystem.Get.GetEntryType(out entryType, in pathNormalized); - if (rc.IsFailure()) return rc; + res = _fileSystem.Get.GetEntryType(out entryType, in pathNormalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -333,11 +333,11 @@ internal class FileSystemAccessor : IDisposable UnsafeHelpers.SkipParamInit(out freeSpace); using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); - rc = _fileSystem.Get.GetFreeSpaceSize(out freeSpace, in pathNormalized); - if (rc.IsFailure()) return rc; + res = _fileSystem.Get.GetFreeSpaceSize(out freeSpace, in pathNormalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -347,11 +347,11 @@ internal class FileSystemAccessor : IDisposable UnsafeHelpers.SkipParamInit(out totalSpace); using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); - rc = _fileSystem.Get.GetTotalSpaceSize(out totalSpace, in pathNormalized); - if (rc.IsFailure()) return rc; + res = _fileSystem.Get.GetTotalSpaceSize(out totalSpace, in pathNormalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -359,12 +359,12 @@ internal class FileSystemAccessor : IDisposable public Result OpenFile(ref UniqueRef outFile, U8Span path, OpenMode mode) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); using var file = new UniqueRef(); - rc = _fileSystem.Get.OpenFile(ref file.Ref(), in pathNormalized, mode); - if (rc.IsFailure()) return rc; + res = _fileSystem.Get.OpenFile(ref file.Ref(), in pathNormalized, mode); + if (res.IsFailure()) return res.Miss(); var accessor = new FileAccessor(Hos, ref file.Ref(), this, mode); @@ -398,12 +398,12 @@ internal class FileSystemAccessor : IDisposable public Result OpenDirectory(ref UniqueRef outDirectory, U8Span path, OpenDirectoryMode mode) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); using var directory = new UniqueRef(); - rc = _fileSystem.Get.OpenDirectory(ref directory.Ref(), in pathNormalized, mode); - if (rc.IsFailure()) return rc; + res = _fileSystem.Get.OpenDirectory(ref directory.Ref(), in pathNormalized, mode); + if (res.IsFailure()) return res.Miss(); var accessor = new DirectoryAccessor(ref directory.Ref(), this); @@ -447,11 +447,11 @@ internal class FileSystemAccessor : IDisposable UnsafeHelpers.SkipParamInit(out timeStamp); using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); - rc = _fileSystem.Get.GetFileTimeStampRaw(out timeStamp, in pathNormalized); - if (rc.IsFailure()) return rc; + res = _fileSystem.Get.GetFileTimeStampRaw(out timeStamp, in pathNormalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -459,11 +459,11 @@ internal class FileSystemAccessor : IDisposable public Result QueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, U8Span path) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); - rc = _fileSystem.Get.QueryEntry(outBuffer, inBuffer, queryId, in pathNormalized); - if (rc.IsFailure()) return rc; + res = _fileSystem.Get.QueryEntry(outBuffer, inBuffer, queryId, in pathNormalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -495,8 +495,8 @@ internal class FileSystemAccessor : IDisposable if (!_saveDataAttributeGetter.HasValue) return ResultFs.PreconditionViolation.Log(); - Result rc = _saveDataAttributeGetter.Get.GetSaveDataAttribute(out attribute); - if (rc.IsFailure()) return rc; + Result res = _saveDataAttributeGetter.Get.GetSaveDataAttribute(out attribute); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -669,8 +669,8 @@ internal class FileSystemAccessor : IDisposable if ((openMode & fileOpenModeMask) == 0) continue; - Result rc = file.Value.GetSize(out long fileSize); - if (rc.IsFailure()) + Result res = file.Value.GetSize(out long fileSize); + if (res.IsFailure()) fileSize = -1; var openModeString = new U8StringBuilder(openModeStringBuffer); diff --git a/src/LibHac/Fs/Fsa/IFile.cs b/src/LibHac/Fs/Fsa/IFile.cs index c519787a..e3ad83d7 100644 --- a/src/LibHac/Fs/Fsa/IFile.cs +++ b/src/LibHac/Fs/Fsa/IFile.cs @@ -83,8 +83,8 @@ public abstract class IFile : IDisposable { if (option.HasFlushFlag()) { - Result rc = Flush(); - if (rc.IsFailure()) return rc; + Result res = Flush(); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -167,8 +167,8 @@ public abstract class IFile : IDisposable return ResultFs.ReadUnpermitted.Log(); // Get the file size, and validate our offset. - Result rc = GetSize(out long fileSize); - if (rc.IsFailure()) return rc; + Result res = GetSize(out long fileSize); + if (res.IsFailure()) return res.Miss(); if (offset > fileSize) return ResultFs.OutOfRange.Log(); @@ -187,8 +187,8 @@ public abstract class IFile : IDisposable return ResultFs.WriteUnpermitted.Log(); // Get the file size. - Result rc = GetSize(out long fileSize); - if (rc.IsFailure()) return rc; + Result res = GetSize(out long fileSize); + if (res.IsFailure()) return res.Miss(); needsAppend = false; diff --git a/src/LibHac/Fs/Fsa/IFileSystem.cs b/src/LibHac/Fs/Fsa/IFileSystem.cs index b480546e..d00ab461 100644 --- a/src/LibHac/Fs/Fsa/IFileSystem.cs +++ b/src/LibHac/Fs/Fsa/IFileSystem.cs @@ -167,8 +167,8 @@ public abstract class IFileSystem : IDisposable return ResultFs.NullptrArgument.Log(); using var pathNormalized = new Path(); - Result rs = pathNormalized.InitializeWithNormalization(path); - if (rs.IsFailure()) return rs; + Result res = pathNormalized.InitializeWithNormalization(path); + if (res.IsFailure()) return res; return DoGetEntryType(out entryType, in pathNormalized); } @@ -209,8 +209,8 @@ public abstract class IFileSystem : IDisposable return ResultFs.NullptrArgument.Log(); using var pathNormalized = new Path(); - Result rs = pathNormalized.InitializeWithNormalization(path); - if (rs.IsFailure()) return rs; + Result res = pathNormalized.InitializeWithNormalization(path); + if (res.IsFailure()) return res; return DoOpenFile(ref file, in pathNormalized, mode); } diff --git a/src/LibHac/Fs/Fsa/MountUtility.cs b/src/LibHac/Fs/Fsa/MountUtility.cs index 56188f8e..df863e0e 100644 --- a/src/LibHac/Fs/Fsa/MountUtility.cs +++ b/src/LibHac/Fs/Fsa/MountUtility.cs @@ -124,8 +124,8 @@ public static class MountUtility return ResultFs.NotMounted.Log(); } - Result rc = GetMountNameAndSubPath(out MountName mountName, out subPath, path); - if (rc.IsFailure()) return rc; + Result res = GetMountNameAndSubPath(out MountName mountName, out subPath, path); + if (res.IsFailure()) return res.Miss(); return fs.Find(out fileSystem, new U8Span(mountName.Name)); } @@ -157,8 +157,8 @@ public static class MountUtility public static Result Unmount(this FileSystemClientImpl fs, U8Span mountName) { - Result rc = fs.Find(out FileSystemAccessor fileSystem, mountName); - if (rc.IsFailure()) return rc; + Result res = fs.Find(out FileSystemAccessor fileSystem, mountName); + if (res.IsFailure()) return res.Miss(); if (fileSystem.IsFileDataCacheAttachable()) { @@ -178,11 +178,11 @@ public static class MountUtility { UnsafeHelpers.SkipParamInit(out isMounted); - Result rc = fs.Find(out _, mountName); - if (rc.IsFailure()) + Result res = fs.Find(out _, mountName); + if (res.IsFailure()) { - if (!ResultFs.NotMounted.Includes(rc)) - return rc; + if (!ResultFs.NotMounted.Includes(res)) + return res; isMounted = false; } @@ -196,52 +196,52 @@ public static class MountUtility public static void Unmount(this FileSystemClient fs, U8Span mountName) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x30]; if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledFileSystemAccessorAccessLog(mountName)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.Unmount(mountName); + res = fs.Impl.Unmount(mountName); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogName).Append(mountName).Append((byte)'"'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.Unmount(mountName); + res = fs.Impl.Unmount(mountName); } - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); } public static bool IsMounted(this FileSystemClient fs, U8Span mountName) { - Result rc; + Result res; bool isMounted; Span logBuffer = stackalloc byte[0x30]; if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledFileSystemAccessorAccessLog(mountName)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.IsMounted(out isMounted, mountName); + res = fs.Impl.IsMounted(out isMounted, mountName); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); ReadOnlySpan boolString = AccessLogImpl.ConvertFromBoolToAccessLogBooleanValue(isMounted); sb.Append(LogName).Append(mountName).Append(LogIsMounted).Append(boolString).Append((byte)'"'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.IsMounted(out isMounted, mountName); + res = fs.Impl.IsMounted(out isMounted, mountName); } - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); return isMounted; } @@ -249,33 +249,33 @@ public static class MountUtility public static Result ConvertToFsCommonPath(this FileSystemClient fs, U8SpanMutable commonPathBuffer, U8Span path) { - Result rc; + Result res; if (commonPathBuffer.IsNull()) { - rc = ResultFs.NullptrArgument.Value; - fs.Impl.AbortIfNeeded(rc); - return rc; + res = ResultFs.NullptrArgument.Value; + fs.Impl.AbortIfNeeded(res); + return res; } if (path.IsNull()) { - rc = ResultFs.NullptrArgument.Value; - fs.Impl.AbortIfNeeded(rc); - return rc; + res = ResultFs.NullptrArgument.Value; + fs.Impl.AbortIfNeeded(res); + return res; } - rc = GetMountNameAndSubPath(out MountName mountName, out U8Span subPath, path); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + res = GetMountNameAndSubPath(out MountName mountName, out U8Span subPath, path); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = fs.Impl.Find(out FileSystemAccessor fileSystem, new U8Span(mountName.Name)); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + res = fs.Impl.Find(out FileSystemAccessor fileSystem, new U8Span(mountName.Name)); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = fileSystem.GetCommonMountName(commonPathBuffer.Value); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + res = fileSystem.GetCommonMountName(commonPathBuffer.Value); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); int mountNameLength = StringUtils.GetLength(commonPathBuffer); int commonPathLength = StringUtils.GetLength(subPath); diff --git a/src/LibHac/Fs/Fsa/Registrar.cs b/src/LibHac/Fs/Fsa/Registrar.cs index 70b934d9..010d8b9e 100644 --- a/src/LibHac/Fs/Fsa/Registrar.cs +++ b/src/LibHac/Fs/Fsa/Registrar.cs @@ -110,8 +110,8 @@ public static class Registrar using var accessor = new UniqueRef(new FileSystemAccessor(fs.Hos, name, null, ref fileSystem, ref mountNameGenerator.Ref(), ref attributeGetter.Ref())); - Result rc = fs.Impl.Register(ref accessor.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = fs.Impl.Register(ref accessor.Ref()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -124,8 +124,8 @@ public static class Registrar using var accessor = new UniqueRef(new FileSystemAccessor(fs.Hos, name, null, ref fileSystem, ref mountNameGenerator, ref attributeGetter.Ref())); - Result rc = fs.Impl.Register(ref accessor.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = fs.Impl.Register(ref accessor.Ref()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -137,10 +137,10 @@ public static class Registrar using var unmountHookInvoker = new UniqueRef(); using var attributeGetter = new UniqueRef(); - Result rc = Register(fs, name, multiCommitTarget, ref fileSystem, ref mountNameGenerator, + Result res = Register(fs, name, multiCommitTarget, ref fileSystem, ref mountNameGenerator, ref attributeGetter.Ref(), useDataCache, storageForPurgeFileDataCache, usePathCache, ref unmountHookInvoker.Ref()); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -152,9 +152,9 @@ public static class Registrar { using var attributeGetter = new UniqueRef(); - Result rc = Register(fs, name, multiCommitTarget, ref fileSystem, ref mountNameGenerator, + Result res = Register(fs, name, multiCommitTarget, ref fileSystem, ref mountNameGenerator, ref attributeGetter.Ref(), useDataCache, storageForPurgeFileDataCache, usePathCache, ref unmountHook); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -166,10 +166,10 @@ public static class Registrar { using var unmountHookInvoker = new UniqueRef(); - Result rc = Register(fs, name, multiCommitTarget, ref fileSystem, ref mountNameGenerator, + Result res = Register(fs, name, multiCommitTarget, ref fileSystem, ref mountNameGenerator, ref saveAttributeGetter, useDataCache, storageForPurgeFileDataCache, usePathCache, ref unmountHookInvoker.Ref()); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -200,8 +200,8 @@ public static class Registrar accessor.Get.SetFileDataCacheAttachable(useDataCache, storageForPurgeFileDataCache); accessor.Get.SetPathBasedFileDataCacheAttachable(usePathCache); - Result rc = fs.Impl.Register(ref accessor.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = fs.Impl.Register(ref accessor.Ref()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Fsa/UserDirectory.cs b/src/LibHac/Fs/Fsa/UserDirectory.cs index 8b8b0989..8c44bce2 100644 --- a/src/LibHac/Fs/Fsa/UserDirectory.cs +++ b/src/LibHac/Fs/Fsa/UserDirectory.cs @@ -22,12 +22,12 @@ public static class UserDirectory public static Result ReadDirectory(this FileSystemClient fs, out long entriesRead, Span entryBuffer, DirectoryHandle handle) { - Result rc; + Result res; if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledHandleAccessLog(handle)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Get(handle).Read(out entriesRead, entryBuffer); + res = Get(handle).Read(out entriesRead, entryBuffer); Tick end = fs.Hos.Os.GetSystemTick(); Span buffer = stackalloc byte[0x50]; @@ -35,40 +35,40 @@ public static class UserDirectory sb.Append(LogEntryBufferCount).AppendFormat(entryBuffer.Length) .Append(LogEntryCount).AppendFormat(entriesRead); - fs.Impl.OutputAccessLog(rc, start, end, handle, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, handle, new U8Span(sb.Buffer)); } else { - rc = Get(handle).Read(out entriesRead, entryBuffer); + res = Get(handle).Read(out entriesRead, entryBuffer); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result GetDirectoryEntryCount(this FileSystemClient fs, out long count, DirectoryHandle handle) { - Result rc; + Result res; if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledHandleAccessLog(handle)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Get(handle).GetEntryCount(out count); + res = Get(handle).GetEntryCount(out count); Tick end = fs.Hos.Os.GetSystemTick(); Span buffer = stackalloc byte[0x50]; var sb = new U8StringBuilder(buffer, true); sb.Append(LogEntryCount).AppendFormat(count); - fs.Impl.OutputAccessLog(rc, start, end, handle, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, handle, new U8Span(sb.Buffer)); } else { - rc = Get(handle).GetEntryCount(out count); + res = Get(handle).GetEntryCount(out count); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static void CloseDirectory(this FileSystemClient fs, DirectoryHandle handle) diff --git a/src/LibHac/Fs/Fsa/UserFile.cs b/src/LibHac/Fs/Fsa/UserFile.cs index a25e9aff..21841d5e 100644 --- a/src/LibHac/Fs/Fsa/UserFile.cs +++ b/src/LibHac/Fs/Fsa/UserFile.cs @@ -28,57 +28,57 @@ public static class UserFile public static Result ReadFile(this FileSystemClient fs, FileHandle handle, long offset, Span destination, in ReadOption option) { - Result rc = ReadFileImpl(fs, out long bytesRead, handle, offset, destination, in option); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + Result res = ReadFileImpl(fs, out long bytesRead, handle, offset, destination, in option); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (bytesRead == destination.Length) return Result.Success; - rc = ResultFs.OutOfRange.Log(); - fs.Impl.AbortIfNeeded(rc); - return rc; + res = ResultFs.OutOfRange.Log(); + fs.Impl.AbortIfNeeded(res); + return res; } public static Result ReadFile(this FileSystemClient fs, FileHandle handle, long offset, Span destination) { - Result rc = ReadFileImpl(fs, out long bytesRead, handle, offset, destination, ReadOption.None); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + Result res = ReadFileImpl(fs, out long bytesRead, handle, offset, destination, ReadOption.None); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (bytesRead == destination.Length) return Result.Success; - rc = ResultFs.OutOfRange.Log(); - fs.Impl.AbortIfNeeded(rc); - return rc; + res = ResultFs.OutOfRange.Log(); + fs.Impl.AbortIfNeeded(res); + return res; } public static Result ReadFile(this FileSystemClient fs, out long bytesRead, FileHandle handle, long offset, Span destination, in ReadOption option) { - Result rc = ReadFileImpl(fs, out bytesRead, handle, offset, destination, in option); - fs.Impl.AbortIfNeeded(rc); - return rc; + Result res = ReadFileImpl(fs, out bytesRead, handle, offset, destination, in option); + fs.Impl.AbortIfNeeded(res); + return res; } public static Result ReadFile(this FileSystemClient fs, out long bytesRead, FileHandle handle, long offset, Span destination) { - Result rc = ReadFileImpl(fs, out bytesRead, handle, offset, destination, ReadOption.None); - fs.Impl.AbortIfNeeded(rc); - return rc; + Result res = ReadFileImpl(fs, out bytesRead, handle, offset, destination, ReadOption.None); + fs.Impl.AbortIfNeeded(res); + return res; } public static Result WriteFile(this FileSystemClient fs, FileHandle handle, long offset, ReadOnlySpan source, in WriteOption option) { - Result rc; + Result res; if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledHandleAccessLog(handle)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Get(handle).Write(offset, source, in option); + res = Get(handle).Write(offset, source, in option); Tick end = fs.Hos.Os.GetSystemTick(); Span buffer = stackalloc byte[0x60]; @@ -89,87 +89,87 @@ public static class UserFile if (option.HasFlushFlag()) sb.Append(LogWriteOptionFlush); - fs.Impl.OutputAccessLog(rc, start, end, handle, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, handle, new U8Span(sb.Buffer)); sb.Dispose(); } else { - rc = Get(handle).Write(offset, source, in option); + res = Get(handle).Write(offset, source, in option); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result FlushFile(this FileSystemClient fs, FileHandle handle) { - Result rc; + Result res; if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledHandleAccessLog(handle)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Get(handle).Flush(); + res = Get(handle).Flush(); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, handle, U8Span.Empty); + fs.Impl.OutputAccessLog(res, start, end, handle, U8Span.Empty); } else { - rc = Get(handle).Flush(); + res = Get(handle).Flush(); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result SetFileSize(this FileSystemClient fs, FileHandle handle, long size) { - Result rc; + Result res; if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledHandleAccessLog(handle)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Get(handle).SetSize(size); + res = Get(handle).SetSize(size); Tick end = fs.Hos.Os.GetSystemTick(); Span buffer = stackalloc byte[0x20]; var sb = new U8StringBuilder(buffer, true); sb.Append(LogSize).AppendFormat(size); - fs.Impl.OutputAccessLog(rc, start, end, handle, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, handle, new U8Span(sb.Buffer)); } else { - rc = Get(handle).SetSize(size); + res = Get(handle).SetSize(size); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result GetFileSize(this FileSystemClient fs, out long size, FileHandle handle) { - Result rc; + Result res; if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledHandleAccessLog(handle)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Get(handle).GetSize(out size); + res = Get(handle).GetSize(out size); Tick end = fs.Hos.Os.GetSystemTick(); Span buffer = stackalloc byte[0x20]; var sb = new U8StringBuilder(buffer, true); - sb.Append(LogSize).AppendFormat(AccessLogImpl.DereferenceOutValue(in size, rc)); - fs.Impl.OutputAccessLog(rc, start, end, handle, new U8Span(sb.Buffer)); + sb.Append(LogSize).AppendFormat(AccessLogImpl.DereferenceOutValue(in size, res)); + fs.Impl.OutputAccessLog(res, start, end, handle, new U8Span(sb.Buffer)); } else { - rc = Get(handle).GetSize(out size); + res = Get(handle).GetSize(out size); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static OpenMode GetFileOpenMode(this FileSystemClient fs, FileHandle handle) @@ -212,20 +212,20 @@ public static class UserFile { UnsafeHelpers.SkipParamInit(out rangeInfo); - Result rc = Get(handle).OperateRange(SpanHelpers.AsByteSpan(ref rangeInfo), OperationId.QueryRange, offset, + Result res = Get(handle).OperateRange(SpanHelpers.AsByteSpan(ref rangeInfo), OperationId.QueryRange, offset, size, ReadOnlySpan.Empty); - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result InvalidateCache(this FileSystemClient fs, FileHandle handle) { - Result rc = Get(handle).OperateRange(Span.Empty, OperationId.InvalidateCache, 0, long.MaxValue, + Result res = Get(handle).OperateRange(Span.Empty, OperationId.InvalidateCache, 0, long.MaxValue, ReadOnlySpan.Empty); - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result QueryUnpreparedRange(this FileSystemClient fs, out Range unpreparedRange, FileHandle handle) @@ -233,11 +233,11 @@ public static class UserFile UnsafeHelpers.SkipParamInit(out unpreparedRange); Unsafe.SkipInit(out UnpreparedRangeInfo info); - Result rc = Get(handle).OperateRange(SpanHelpers.AsByteSpan(ref info), OperationId.QueryUnpreparedRange, 0, 0, + Result res = Get(handle).OperateRange(SpanHelpers.AsByteSpan(ref info), OperationId.QueryUnpreparedRange, 0, 0, ReadOnlySpan.Empty); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); unpreparedRange = info.Range; return Result.Success; @@ -249,11 +249,11 @@ public static class UserFile UnsafeHelpers.SkipParamInit(out unpreparedRangeInfo); Unsafe.SkipInit(out UnpreparedRangeInfo info); - Result rc = Get(handle).OperateRange(SpanHelpers.AsByteSpan(ref info), OperationId.QueryUnpreparedRange, 0, 0, + Result res = Get(handle).OperateRange(SpanHelpers.AsByteSpan(ref info), OperationId.QueryUnpreparedRange, 0, 0, ReadOnlySpan.Empty); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); unpreparedRangeInfo = info; return Result.Success; @@ -267,11 +267,11 @@ public static class UserFile Unsafe.SkipInit(out UnpreparedRangeInfo info); var args = new LazyLoadArguments { GuideIndex = guideIndex }; - Result rc = Get(handle).OperateRange(SpanHelpers.AsByteSpan(ref info), OperationId.QueryLazyLoadCompletionRate, + Result res = Get(handle).OperateRange(SpanHelpers.AsByteSpan(ref info), OperationId.QueryLazyLoadCompletionRate, 0, 0, SpanHelpers.AsReadOnlyByteSpan(in args)); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); completionRate = info.CompletionRate; return Result.Success; @@ -282,11 +282,11 @@ public static class UserFile { Unsafe.SkipInit(out UnpreparedRangeInfo info); - Result rc = Get(handle).OperateRange(SpanHelpers.AsByteSpan(ref info), OperationId.ReadyLazyLoadFile, + Result res = Get(handle).OperateRange(SpanHelpers.AsByteSpan(ref info), OperationId.ReadyLazyLoadFile, offset, size, ReadOnlySpan.Empty); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Fsa/UserFileSystem.cs b/src/LibHac/Fs/Fsa/UserFileSystem.cs index 97472a9a..771bb9fe 100644 --- a/src/LibHac/Fs/Fsa/UserFileSystem.cs +++ b/src/LibHac/Fs/Fsa/UserFileSystem.cs @@ -25,7 +25,7 @@ public static class UserFileSystem public static Result DeleteFile(this FileSystemClient fs, U8Span path) { - Result rc; + Result res; U8Span subPath; FileSystemAccessor fileSystem; Span logBuffer = stackalloc byte[0x300]; @@ -33,41 +33,41 @@ public static class UserFileSystem if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(path).Append((byte)'"'); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog() && fileSystem.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fileSystem.DeleteFile(subPath); + res = fileSystem.DeleteFile(subPath); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fileSystem.DeleteFile(subPath); + res = fileSystem.DeleteFile(subPath); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result CreateDirectory(this FileSystemClient fs, U8Span path) { - Result rc; + Result res; U8Span subPath; FileSystemAccessor fileSystem; Span logBuffer = stackalloc byte[0x300]; @@ -75,41 +75,41 @@ public static class UserFileSystem if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(path).Append((byte)'"'); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog() && fileSystem.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fileSystem.CreateDirectory(subPath); + res = fileSystem.CreateDirectory(subPath); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fileSystem.CreateDirectory(subPath); + res = fileSystem.CreateDirectory(subPath); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result DeleteDirectory(this FileSystemClient fs, U8Span path) { - Result rc; + Result res; U8Span subPath; FileSystemAccessor fileSystem; Span logBuffer = stackalloc byte[0x300]; @@ -117,41 +117,41 @@ public static class UserFileSystem if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(path).Append((byte)'"'); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog() && fileSystem.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fileSystem.DeleteDirectory(subPath); + res = fileSystem.DeleteDirectory(subPath); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fileSystem.DeleteDirectory(subPath); + res = fileSystem.DeleteDirectory(subPath); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result DeleteDirectoryRecursively(this FileSystemClient fs, U8Span path) { - Result rc; + Result res; U8Span subPath; FileSystemAccessor fileSystem; Span logBuffer = stackalloc byte[0x300]; @@ -159,41 +159,41 @@ public static class UserFileSystem if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(path).Append((byte)'"'); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog() && fileSystem.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fileSystem.DeleteDirectoryRecursively(subPath); + res = fileSystem.DeleteDirectoryRecursively(subPath); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fileSystem.DeleteDirectoryRecursively(subPath); + res = fileSystem.DeleteDirectoryRecursively(subPath); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result CleanDirectoryRecursively(this FileSystemClient fs, U8Span path) { - Result rc; + Result res; U8Span subPath; FileSystemAccessor fileSystem; Span logBuffer = stackalloc byte[0x300]; @@ -201,41 +201,41 @@ public static class UserFileSystem if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(path).Append((byte)'"'); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog() && fileSystem.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fileSystem.CleanDirectoryRecursively(subPath); + res = fileSystem.CleanDirectoryRecursively(subPath); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fileSystem.CleanDirectoryRecursively(subPath); + res = fileSystem.CleanDirectoryRecursively(subPath); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result RenameFile(this FileSystemClient fs, U8Span currentPath, U8Span newPath) { - Result rc; + Result res; U8Span currentSubPath, newSubPath; FileSystemAccessor currentFileSystem, newFileSystem; Span logBuffer = stackalloc byte[0x300]; @@ -244,64 +244,64 @@ public static class UserFileSystem if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.FindFileSystem(out currentFileSystem, out currentSubPath, currentPath); + res = fs.Impl.FindFileSystem(out currentFileSystem, out currentSubPath, currentPath); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(currentPath).Append(LogNewPath).Append(newPath).Append((byte)'"'); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fs.Impl.FindFileSystem(out currentFileSystem, out currentSubPath, currentPath); + res = fs.Impl.FindFileSystem(out currentFileSystem, out currentSubPath, currentPath); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); // Get the file system accessor for the new path if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.FindFileSystem(out newFileSystem, out newSubPath, newPath); + res = fs.Impl.FindFileSystem(out newFileSystem, out newSubPath, newPath); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fs.Impl.FindFileSystem(out newFileSystem, out newSubPath, newPath); + res = fs.Impl.FindFileSystem(out newFileSystem, out newSubPath, newPath); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); // Rename the file if (fs.Impl.IsEnabledAccessLog() && currentFileSystem.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = currentFileSystem != newFileSystem + res = currentFileSystem != newFileSystem ? ResultFs.RenameToOtherFileSystem.Log() : currentFileSystem.RenameFile(currentSubPath, newSubPath); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = currentFileSystem != newFileSystem + res = currentFileSystem != newFileSystem ? ResultFs.RenameToOtherFileSystem.Log() : currentFileSystem.RenameFile(currentSubPath, newSubPath); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result RenameDirectory(this FileSystemClient fs, U8Span currentPath, U8Span newPath) { - Result rc; + Result res; U8Span currentSubPath, newSubPath; FileSystemAccessor currentFileSystem, newFileSystem; Span logBuffer = stackalloc byte[0x300]; @@ -310,66 +310,66 @@ public static class UserFileSystem if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.FindFileSystem(out currentFileSystem, out currentSubPath, currentPath); + res = fs.Impl.FindFileSystem(out currentFileSystem, out currentSubPath, currentPath); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(currentPath).Append(LogNewPath).Append(newPath).Append((byte)'"'); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fs.Impl.FindFileSystem(out currentFileSystem, out currentSubPath, currentPath); + res = fs.Impl.FindFileSystem(out currentFileSystem, out currentSubPath, currentPath); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); // Get the file system accessor for the new path if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.FindFileSystem(out newFileSystem, out newSubPath, newPath); + res = fs.Impl.FindFileSystem(out newFileSystem, out newSubPath, newPath); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fs.Impl.FindFileSystem(out newFileSystem, out newSubPath, newPath); + res = fs.Impl.FindFileSystem(out newFileSystem, out newSubPath, newPath); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); // Rename the directory if (fs.Impl.IsEnabledAccessLog() && currentFileSystem.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = currentFileSystem != newFileSystem + res = currentFileSystem != newFileSystem ? ResultFs.RenameToOtherFileSystem.Log() : currentFileSystem.RenameDirectory(currentSubPath, newSubPath); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = currentFileSystem != newFileSystem + res = currentFileSystem != newFileSystem ? ResultFs.RenameToOtherFileSystem.Log() : currentFileSystem.RenameDirectory(currentSubPath, newSubPath); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result GetEntryType(this FileSystemClient fs, out DirectoryEntryType type, U8Span path) { UnsafeHelpers.SkipParamInit(out type); - Result rc; + Result res; U8Span subPath; FileSystemAccessor fileSystem; Span logBuffer = stackalloc byte[0x300]; @@ -377,51 +377,51 @@ public static class UserFileSystem if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(path).Append(LogEntryType) - .Append(idString.ToString(AccessLogImpl.DereferenceOutValue(in type, rc))); + .Append(idString.ToString(AccessLogImpl.DereferenceOutValue(in type, res))); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog() && fileSystem.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fileSystem.GetEntryType(out type, subPath); + res = fileSystem.GetEntryType(out type, subPath); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(path).Append(LogEntryType) - .Append(idString.ToString(AccessLogImpl.DereferenceOutValue(in type, rc))); + .Append(idString.ToString(AccessLogImpl.DereferenceOutValue(in type, res))); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fileSystem.GetEntryType(out type, subPath); + res = fileSystem.GetEntryType(out type, subPath); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result GetFreeSpaceSize(this FileSystemClient fs, out long freeSpace, U8Span path) { UnsafeHelpers.SkipParamInit(out freeSpace); - Result rc; + Result res; var subPath = U8Span.Empty; FileSystemAccessor fileSystem; Span logBuffer = stackalloc byte[0x300]; @@ -437,22 +437,22 @@ public static class UserFileSystem if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = FindImpl(fs, path, out fileSystem, ref subPath); + res = FindImpl(fs, path, out fileSystem, ref subPath); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(path).Append((byte)'"').Append(LogSize) - .AppendFormat(AccessLogImpl.DereferenceOutValue(in freeSpace, rc)); + .AppendFormat(AccessLogImpl.DereferenceOutValue(in freeSpace, res)); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = FindImpl(fs, path, out fileSystem, ref subPath); + res = FindImpl(fs, path, out fileSystem, ref subPath); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); static Result GetImpl(out long freeSpace, FileSystemAccessor fileSystem, U8Span subPath) { @@ -467,29 +467,29 @@ public static class UserFileSystem if (fs.Impl.IsEnabledAccessLog() && fileSystem.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = GetImpl(out freeSpace, fileSystem, subPath); + res = GetImpl(out freeSpace, fileSystem, subPath); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(path).Append((byte)'"').Append(LogSize) - .AppendFormat(AccessLogImpl.DereferenceOutValue(in freeSpace, rc)); + .AppendFormat(AccessLogImpl.DereferenceOutValue(in freeSpace, res)); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = GetImpl(out freeSpace, fileSystem, subPath); + res = GetImpl(out freeSpace, fileSystem, subPath); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result OpenFile(this FileSystemClient fs, out FileHandle handle, U8Span path, OpenMode mode) { UnsafeHelpers.SkipParamInit(out handle); - Result rc; + Result res; U8Span subPath; FileSystemAccessor fileSystem; Span logBuffer = stackalloc byte[0x300]; @@ -497,37 +497,37 @@ public static class UserFileSystem if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(path).Append((byte)'"').Append(LogOpenMode).AppendFormat((int)mode, 'X'); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); using var file = new UniqueRef(); if (fs.Impl.IsEnabledAccessLog() && fileSystem.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fileSystem.OpenFile(ref file.Ref(), subPath, mode); + res = fileSystem.OpenFile(ref file.Ref(), subPath, mode); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, file.Get, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, file.Get, new U8Span(logBuffer)); } else { - rc = fileSystem.OpenFile(ref file.Ref(), subPath, mode); + res = fileSystem.OpenFile(ref file.Ref(), subPath, mode); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); handle = new FileHandle(file.Release()); return Result.Success; @@ -546,7 +546,7 @@ public static class UserFileSystem { UnsafeHelpers.SkipParamInit(out handle); - Result rc; + Result res; U8Span subPath; FileSystemAccessor fileSystem; Span logBuffer = stackalloc byte[0x300]; @@ -554,38 +554,38 @@ public static class UserFileSystem if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(path).Append((byte)'"').Append(LogOpenMode).AppendFormat((int)mode, 'X'); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); using var accessor = new UniqueRef(); if (fs.Impl.IsEnabledAccessLog() && fileSystem.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fileSystem.OpenDirectory(ref accessor.Ref(), subPath, mode); + res = fileSystem.OpenDirectory(ref accessor.Ref(), subPath, mode); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, accessor.Get, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, accessor.Get, new U8Span(logBuffer)); } else { - rc = fileSystem.OpenDirectory(ref accessor.Ref(), subPath, mode); + res = fileSystem.OpenDirectory(ref accessor.Ref(), subPath, mode); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); handle = new DirectoryHandle(accessor.Release()); return Result.Success; @@ -594,43 +594,43 @@ public static class UserFileSystem private static Result CommitImpl(FileSystemClient fs, U8Span mountName, [CallerMemberName] string functionName = "") { - Result rc; + Result res; FileSystemAccessor fileSystem; Span logBuffer = stackalloc byte[0x30]; if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.Find(out fileSystem, mountName); + res = fs.Impl.Find(out fileSystem, mountName); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogName).Append(mountName).Append((byte)'"'); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer), functionName); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer), functionName); } else { - rc = fs.Impl.Find(out fileSystem, mountName); + res = fs.Impl.Find(out fileSystem, mountName); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog() && fileSystem.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fileSystem.Commit(); + res = fileSystem.Commit(); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer), functionName); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer), functionName); } else { - rc = fileSystem.Commit(); + res = fileSystem.Commit(); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result Commit(this FileSystemClient fs, ReadOnlySpan mountNames) @@ -649,67 +649,67 @@ public static class UserFileSystem using var commitManager = new SharedRef(); using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.OpenMultiCommitManager(ref commitManager.Ref()); - if (rc.IsFailure()) return rc; + Result res = fileSystemProxy.Get.OpenMultiCommitManager(ref commitManager.Ref()); + if (res.IsFailure()) return res.Miss(); for (int i = 0; i < mountNames.Length; i++) { - rc = fs.Impl.Find(out FileSystemAccessor accessor, mountNames[i]); - if (rc.IsFailure()) return rc; + res = fs.Impl.Find(out FileSystemAccessor accessor, mountNames[i]); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystem = accessor.GetMultiCommitTarget(); if (!fileSystem.HasValue) return ResultFs.UnsupportedCommitTarget.Log(); - rc = commitManager.Get.Add(ref fileSystem.Ref()); - if (rc.IsFailure()) return rc; + res = commitManager.Get.Add(ref fileSystem.Ref()); + if (res.IsFailure()) return res.Miss(); } - rc = commitManager.Get.Commit(); - if (rc.IsFailure()) return rc; + res = commitManager.Get.Commit(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public static Result Commit(this FileSystemClient fs, U8Span mountName, CommitOption option) { - Result rc; + Result res; FileSystemAccessor fileSystem; Span logBuffer = stackalloc byte[0x40]; if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.Find(out fileSystem, mountName); + res = fs.Impl.Find(out fileSystem, mountName); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogName).Append(mountName).Append(LogCommitOption).AppendFormat((int)option.Flags, 'X'); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fs.Impl.Find(out fileSystem, mountName); + res = fs.Impl.Find(out fileSystem, mountName); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog() && fileSystem.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = RunCommit(fs, option, fileSystem); + res = RunCommit(fs, option, fileSystem); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = RunCommit(fs, option, fileSystem); + res = RunCommit(fs, option, fileSystem); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result RunCommit(FileSystemClient fs, CommitOption option, FileSystemAccessor fileSystem) { @@ -724,8 +724,8 @@ public static class UserFileSystem return ResultFs.InvalidCommitOption.Log(); } - Result rc = fileSystem.GetSaveDataAttribute(out SaveDataAttribute attribute); - if (rc.IsFailure()) return rc; + Result res = fileSystem.GetSaveDataAttribute(out SaveDataAttribute attribute); + if (res.IsFailure()) return res.Miss(); if (attribute.ProgramId == SaveData.InvalidProgramId) attribute.ProgramId = SaveData.AutoResolveCallerProgramId; diff --git a/src/LibHac/Fs/Fsa/UserFileSystemForDebug.cs b/src/LibHac/Fs/Fsa/UserFileSystemForDebug.cs index 375bbd80..f51b50a5 100644 --- a/src/LibHac/Fs/Fsa/UserFileSystemForDebug.cs +++ b/src/LibHac/Fs/Fsa/UserFileSystemForDebug.cs @@ -14,8 +14,8 @@ public static class UserFileSystemForDebug { UnsafeHelpers.SkipParamInit(out timeStamp); - Result rc = fs.FindFileSystem(out FileSystemAccessor fileSystem, out U8Span subPath, path); - if (rc.IsFailure()) return rc.Miss(); + Result res = fs.FindFileSystem(out FileSystemAccessor fileSystem, out U8Span subPath, path); + if (res.IsFailure()) return res.Miss(); return fileSystem.GetFileTimeStampRaw(out timeStamp, subPath); } @@ -23,8 +23,8 @@ public static class UserFileSystemForDebug public static Result GetFileTimeStampRawForDebug(this FileSystemClient fs, out FileTimeStampRaw timeStamp, U8Span path) { - Result rc = fs.Impl.GetFileTimeStampRawForDebug(out timeStamp, path); - fs.Impl.AbortIfNeeded(rc); - return rc; + Result res = fs.Impl.GetFileTimeStampRawForDebug(out timeStamp, path); + fs.Impl.AbortIfNeeded(res); + return res; } } \ No newline at end of file diff --git a/src/LibHac/Fs/Fsa/UserFileSystemPrivate.cs b/src/LibHac/Fs/Fsa/UserFileSystemPrivate.cs index 974df1f3..d216d515 100644 --- a/src/LibHac/Fs/Fsa/UserFileSystemPrivate.cs +++ b/src/LibHac/Fs/Fsa/UserFileSystemPrivate.cs @@ -14,7 +14,7 @@ public static class UserFileSystemPrivate { public static Result CreateFile(this FileSystemClient fs, U8Span path, long size, CreateFileOptions option) { - Result rc; + Result res; U8Span subPath; FileSystemAccessor fileSystem; Span logBuffer = stackalloc byte[0x300]; @@ -22,65 +22,65 @@ public static class UserFileSystemPrivate if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(path).Append((byte)'"'); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); + res = fs.Impl.FindFileSystem(out fileSystem, out subPath, path); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog() && fileSystem.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fileSystem.CreateFile(subPath, size, option); + res = fileSystem.CreateFile(subPath, size, option); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(path).Append((byte)'"').Append(LogSize).AppendFormat(size); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fileSystem.CreateFile(subPath, size, option); + res = fileSystem.CreateFile(subPath, size, option); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result GetTotalSpaceSize(this FileSystemClient fs, out long totalSpace, U8Span path) { UnsafeHelpers.SkipParamInit(out totalSpace); - Result rc = fs.Impl.FindFileSystem(out FileSystemAccessor fileSystem, out U8Span subPath, path); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + Result res = fs.Impl.FindFileSystem(out FileSystemAccessor fileSystem, out U8Span subPath, path); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = fileSystem.GetTotalSpaceSize(out totalSpace, subPath); - fs.Impl.AbortIfNeeded(rc); - return rc; + res = fileSystem.GetTotalSpaceSize(out totalSpace, subPath); + fs.Impl.AbortIfNeeded(res); + return res; } public static Result SetConcatenationFileAttribute(this FileSystemClient fs, U8Span path) { - Result rc = fs.Impl.FindFileSystem(out FileSystemAccessor fileSystem, out U8Span subPath, path); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + Result res = fs.Impl.FindFileSystem(out FileSystemAccessor fileSystem, out U8Span subPath, path); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = fileSystem.QueryEntry(Span.Empty, ReadOnlySpan.Empty, QueryId.SetConcatenationFileAttribute, + res = fileSystem.QueryEntry(Span.Empty, ReadOnlySpan.Empty, QueryId.SetConcatenationFileAttribute, subPath); - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result QueryUnpreparedFileInformation(this FileSystemClient fs, out UnpreparedFileInformation info, @@ -88,13 +88,13 @@ public static class UserFileSystemPrivate { UnsafeHelpers.SkipParamInit(out info); - Result rc = fs.Impl.FindFileSystem(out FileSystemAccessor fileSystem, out _, path); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + Result res = fs.Impl.FindFileSystem(out FileSystemAccessor fileSystem, out _, path); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = fileSystem.QueryEntry(SpanHelpers.AsByteSpan(ref info), ReadOnlySpan.Empty, + res = fileSystem.QueryEntry(SpanHelpers.AsByteSpan(ref info), ReadOnlySpan.Empty, QueryId.QueryUnpreparedFileInformation, new U8Span(new[] { (byte)'/' })); - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } } \ No newline at end of file diff --git a/src/LibHac/Fs/IStorage.cs b/src/LibHac/Fs/IStorage.cs index 357f378b..56c4cd00 100644 --- a/src/LibHac/Fs/IStorage.cs +++ b/src/LibHac/Fs/IStorage.cs @@ -93,8 +93,8 @@ public abstract class IStorage : IDisposable public static Result CheckAccessRange(long offset, ulong size, long totalSize) { - Result rc = CheckAccessRange(offset, unchecked((long)size), totalSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckAccessRange(offset, unchecked((long)size), totalSize); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -115,17 +115,17 @@ public abstract class IStorage : IDisposable public static Result CheckOffsetAndSize(long offset, ulong size) { - Result rc = CheckOffsetAndSize(offset, unchecked((long)size)); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckOffsetAndSize(offset, unchecked((long)size)); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public static Result CheckOffsetAndSizeWithResult(long offset, long size, Result resultOnFailure) { - Result rc = CheckOffsetAndSize(offset, size); + Result res = CheckOffsetAndSize(offset, size); - if (rc.IsFailure()) + if (res.IsFailure()) return resultOnFailure.Log(); return Result.Success; @@ -133,9 +133,9 @@ public abstract class IStorage : IDisposable public static Result CheckOffsetAndSizeWithResult(long offset, ulong size, Result resultOnFailure) { - Result rc = CheckOffsetAndSize(offset, size); + Result res = CheckOffsetAndSize(offset, size); - if (rc.IsFailure()) + if (res.IsFailure()) return resultOnFailure.Log(); return Result.Success; diff --git a/src/LibHac/Fs/MemoryStorage.cs b/src/LibHac/Fs/MemoryStorage.cs index 76c7b0c1..60c2e7f9 100644 --- a/src/LibHac/Fs/MemoryStorage.cs +++ b/src/LibHac/Fs/MemoryStorage.cs @@ -22,8 +22,8 @@ public class MemoryStorage : IStorage if (destination.Length == 0) return Result.Success; - Result rc = CheckAccessRange(offset, destination.Length, _storageBuffer.Length); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckAccessRange(offset, destination.Length, _storageBuffer.Length); + if (res.IsFailure()) return res.Miss(); _storageBuffer.AsSpan((int)offset, destination.Length).CopyTo(destination); @@ -35,8 +35,8 @@ public class MemoryStorage : IStorage if (source.Length == 0) return Result.Success; - Result rc = CheckAccessRange(offset, source.Length, _storageBuffer.Length); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckAccessRange(offset, source.Length, _storageBuffer.Length); + if (res.IsFailure()) return res.Miss(); source.CopyTo(_storageBuffer.AsSpan((int)offset)); diff --git a/src/LibHac/Fs/ReadOnlyFileSystem.cs b/src/LibHac/Fs/ReadOnlyFileSystem.cs index ce2e6e46..6866b636 100644 --- a/src/LibHac/Fs/ReadOnlyFileSystem.cs +++ b/src/LibHac/Fs/ReadOnlyFileSystem.cs @@ -97,8 +97,8 @@ public class ReadOnlyFileSystem : IFileSystem return ResultFs.InvalidModeForFileOpen.Log(); using var baseFile = new UniqueRef(); - Result rc = _baseFileSystem.Get.OpenFile(ref baseFile.Ref(), in path, mode); - if (rc.IsFailure()) return rc; + Result res = _baseFileSystem.Get.OpenFile(ref baseFile.Ref(), in path, mode); + if (res.IsFailure()) return res.Miss(); outFile.Reset(new ReadOnlyFile(ref baseFile.Ref())); return Result.Success; diff --git a/src/LibHac/Fs/Shim/Application.cs b/src/LibHac/Fs/Shim/Application.cs index b1116531..addbe125 100644 --- a/src/LibHac/Fs/Shim/Application.cs +++ b/src/LibHac/Fs/Shim/Application.cs @@ -20,12 +20,12 @@ public static class Application { public static Result MountApplicationPackage(this FileSystemClient fs, U8Span mountName, U8Span path) { - Result rc; + Result res; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Mount(fs, mountName, path); + res = Mount(fs, mountName, path); Tick end = fs.Hos.Os.GetSystemTick(); Span logBuffer = stackalloc byte[0x300]; @@ -34,15 +34,15 @@ public static class Application sb.Append(LogName).Append(mountName).Append(LogQuote) .Append(LogPath).Append(path).Append(LogQuote); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = Mount(fs, mountName, path); + res = Mount(fs, mountName, path); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -51,18 +51,18 @@ public static class Application static Result Mount(FileSystemClient fs, U8Span mountName, U8Span path) { - Result rc = fs.Impl.CheckMountName(mountName); - if (rc.IsFailure()) return rc; + Result res = fs.Impl.CheckMountName(mountName); + if (res.IsFailure()) return res.Miss(); - rc = PathUtility.ConvertToFspPath(out FspPath sfPath, path); - if (rc.IsFailure()) return rc; + res = PathUtility.ConvertToFspPath(out FspPath sfPath, path); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var fileSystem = new SharedRef(); - rc = fileSystemProxy.Get.OpenFileSystemWithId(ref fileSystem.Ref(), in sfPath, + res = fileSystemProxy.Get.OpenFileSystemWithId(ref fileSystem.Ref(), in sfPath, Ncm.ProgramId.InvalidId.Value, FileSystemProxyType.Package); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref())); @@ -70,8 +70,8 @@ public static class Application if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInApplicationA.Log(); - rc = fs.Register(mountName, ref fileSystemAdapter.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Register(mountName, ref fileSystemAdapter.Ref()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/BaseFileSystem.cs b/src/LibHac/Fs/Shim/BaseFileSystem.cs index a5563819..f73401c8 100644 --- a/src/LibHac/Fs/Shim/BaseFileSystem.cs +++ b/src/LibHac/Fs/Shim/BaseFileSystem.cs @@ -19,8 +19,8 @@ public static class BaseFileSystem { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.OpenBaseFileSystem(ref outFileSystem, fileSystemId); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenBaseFileSystem(ref outFileSystem, fileSystemId); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -31,26 +31,26 @@ public static class BaseFileSystem using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref())); - Result rc = fs.Register(mountName, ref fileSystemAdapter.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = fs.Register(mountName, ref fileSystemAdapter.Ref()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public static Result MountBaseFileSystem(this FileSystemClient fs, U8Span mountName, BaseFileSystemId fileSystemId) { - Result rc = fs.Impl.CheckMountName(mountName); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fs.Impl.CheckMountName(mountName); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); using var fileSystem = new SharedRef(); - rc = OpenBaseFileSystem(fs, ref fileSystem.Ref(), fileSystemId); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = OpenBaseFileSystem(fs, ref fileSystem.Ref(), fileSystemId); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = RegisterFileSystem(fs, mountName, ref fileSystem.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = RegisterFileSystem(fs, mountName, ref fileSystem.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -59,9 +59,9 @@ public static class BaseFileSystem { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.FormatBaseFileSystem(fileSystemId); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.FormatBaseFileSystem(fileSystemId); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/BcatSaveData.cs b/src/LibHac/Fs/Shim/BcatSaveData.cs index 3c515a6a..acab83c4 100644 --- a/src/LibHac/Fs/Shim/BcatSaveData.cs +++ b/src/LibHac/Fs/Shim/BcatSaveData.cs @@ -23,12 +23,12 @@ public static class BcatSaveData public static Result MountBcatSaveData(this FileSystemClient fs, U8Span mountName, Ncm.ApplicationId applicationId) { - Result rc; + Result res; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Mount(fs, mountName, applicationId); + res = Mount(fs, mountName, applicationId); Tick end = fs.Hos.Os.GetSystemTick(); Span logBuffer = stackalloc byte[0x50]; @@ -37,15 +37,15 @@ public static class BcatSaveData sb.Append(LogName).Append(mountName).Append(LogQuote) .Append(LogApplicationId).AppendFormat(applicationId.Value, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = Mount(fs, mountName, applicationId); + res = Mount(fs, mountName, applicationId); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -54,19 +54,19 @@ public static class BcatSaveData static Result Mount(FileSystemClient fs, U8Span mountName, Ncm.ApplicationId applicationId) { - Result rc = fs.Impl.CheckMountName(mountName); - if (rc.IsFailure()) return rc; + Result res = fs.Impl.CheckMountName(mountName); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Bcat, + res = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Bcat, InvalidUserId, InvalidSystemSaveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); using var fileSystem = new SharedRef(); - rc = fileSystemProxy.Get.OpenSaveDataFileSystem(ref fileSystem.Ref(), SaveDataSpaceId.User, in attribute); - if (rc.IsFailure()) return rc; + res = fileSystemProxy.Get.OpenSaveDataFileSystem(ref fileSystem.Ref(), SaveDataSpaceId.User, in attribute); + if (res.IsFailure()) return res.Miss(); using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref())); @@ -74,8 +74,8 @@ public static class BcatSaveData if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInBcatSaveDataA.Log(); - rc = fs.Register(mountName, ref fileSystemAdapter.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Register(mountName, ref fileSystemAdapter.Ref()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/Bis.cs b/src/LibHac/Fs/Shim/Bis.cs index 9298649c..6b5086f8 100644 --- a/src/LibHac/Fs/Shim/Bis.cs +++ b/src/LibHac/Fs/Shim/Bis.cs @@ -55,12 +55,12 @@ public static class Bis private static Result MountBis(this FileSystemClientImpl fs, U8Span mountName, BisPartitionId partitionId, U8Span rootPath) { - Result rc; + Result res; if (fs.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Mount(fs, mountName, partitionId); + res = Mount(fs, mountName, partitionId); Tick end = fs.Hos.Os.GetSystemTick(); Span logBuffer = stackalloc byte[0x300]; @@ -71,15 +71,15 @@ public static class Bis .Append(LogBisPartitionId).Append(idString.ToString(partitionId)) .Append(LogPath).Append(rootPath).Append(LogQuote); - fs.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = Mount(fs, mountName, partitionId); + res = Mount(fs, mountName, partitionId); } - fs.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.IsEnabledAccessLog(AccessLogTarget.System)) fs.EnableFileSystemAccessorAccessLog(mountName); @@ -88,8 +88,8 @@ public static class Bis static Result Mount(FileSystemClientImpl fs, U8Span mountName, BisPartitionId partitionId) { - Result rc = fs.CheckMountNameAcceptingReservedMountName(mountName); - if (rc.IsFailure()) return rc.Miss(); + Result res = fs.CheckMountNameAcceptingReservedMountName(mountName); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); @@ -98,8 +98,8 @@ public static class Bis using var fileSystem = new SharedRef(); - rc = fileSystemProxy.Get.OpenBisFileSystem(ref fileSystem.Ref(), in sfPath, partitionId); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystemProxy.Get.OpenBisFileSystem(ref fileSystem.Ref(), in sfPath, partitionId); + if (res.IsFailure()) return res.Miss(); using var mountNameGenerator = new UniqueRef(new BisCommonMountNameGenerator(partitionId)); @@ -113,8 +113,8 @@ public static class Bis if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInBisB.Log(); - rc = fs.Fs.Register(mountName, ref fileSystemAdapter.Ref(), ref mountNameGenerator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Fs.Register(mountName, ref fileSystemAdapter.Ref(), ref mountNameGenerator.Ref()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -170,17 +170,17 @@ public static class Bis using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var storage = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenBisStorage(ref storage.Ref(), partitionId); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenBisStorage(ref storage.Ref(), partitionId); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); using var storageAdapter = new UniqueRef(new StorageServiceObjectAdapter(ref storage.Ref())); if (!storageAdapter.HasValue) { - rc = ResultFs.AllocationMemoryFailedInBisC.Value; - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Log(); + res = ResultFs.AllocationMemoryFailedInBisC.Value; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Log(); } outPartitionStorage.Set(ref storageAdapter.Ref()); @@ -191,9 +191,9 @@ public static class Bis { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.InvalidateBisCache(); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.InvalidateBisCache(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/Code.cs b/src/LibHac/Fs/Shim/Code.cs index d5df1784..683f672c 100644 --- a/src/LibHac/Fs/Shim/Code.cs +++ b/src/LibHac/Fs/Shim/Code.cs @@ -22,11 +22,11 @@ public static class Code public static Result MountCode(this FileSystemClient fs, out CodeVerificationData verificationData, U8Span mountName, U8Span path, ProgramId programId) { - Result rc; + Result res; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Mount(fs, out verificationData, mountName, path, programId); + res = Mount(fs, out verificationData, mountName, path, programId); Tick end = fs.Hos.Os.GetSystemTick(); Span logBuffer = stackalloc byte[0x300]; @@ -36,15 +36,15 @@ public static class Code .Append(LogPath).Append(path).Append(LogQuote) .Append(LogProgramId).AppendFormat(programId.Value, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = Mount(fs, out verificationData, mountName, path, programId); + res = Mount(fs, out verificationData, mountName, path, programId); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -56,24 +56,24 @@ public static class Code { UnsafeHelpers.SkipParamInit(out verificationData); - Result rc = fs.Impl.CheckMountName(mountName); - if (rc.IsFailure()) return rc; + Result res = fs.Impl.CheckMountName(mountName); + if (res.IsFailure()) return res.Miss(); - rc = PathUtility.ConvertToFspPath(out FspPath sfPath, path); - if (rc.IsFailure()) return rc; + res = PathUtility.ConvertToFspPath(out FspPath sfPath, path); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyForLoaderServiceObject(); // Todo: IPC code should automatically set process ID - rc = fileSystemProxy.Get.SetCurrentProcess(fs.Hos.Os.GetCurrentProcessId().Value); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystemProxy.Get.SetCurrentProcess(fs.Hos.Os.GetCurrentProcessId().Value); + if (res.IsFailure()) return res.Miss(); using var fileSystem = new SharedRef(); - rc = fileSystemProxy.Get.OpenCodeFileSystem(ref fileSystem.Ref(), out verificationData, in sfPath, + res = fileSystemProxy.Get.OpenCodeFileSystem(ref fileSystem.Ref(), out verificationData, in sfPath, programId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref())); @@ -81,8 +81,8 @@ public static class Code if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInCodeA.Log(); - rc = fs.Register(mountName, ref fileSystemAdapter.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Register(mountName, ref fileSystemAdapter.Ref()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/Content.cs b/src/LibHac/Fs/Shim/Content.cs index a067ff26..f65bcc0d 100644 --- a/src/LibHac/Fs/Shim/Content.cs +++ b/src/LibHac/Fs/Shim/Content.cs @@ -37,19 +37,19 @@ public static class Content private static Result MountContentImpl(FileSystemClient fs, U8Span mountName, U8Span path, ulong id, ContentType contentType) { - Result rc = fs.Impl.CheckMountNameAcceptingReservedMountName(mountName); - if (rc.IsFailure()) return rc; + Result res = fs.Impl.CheckMountNameAcceptingReservedMountName(mountName); + if (res.IsFailure()) return res.Miss(); FileSystemProxyType fsType = ConvertToFileSystemProxyType(contentType); - rc = PathUtility.ConvertToFspPath(out FspPath sfPath, path); - if (rc.IsFailure()) return rc; + res = PathUtility.ConvertToFspPath(out FspPath sfPath, path); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var fileSystem = new SharedRef(); - rc = fileSystemProxy.Get.OpenFileSystemWithId(ref fileSystem.Ref(), in sfPath, id, fsType); - if (rc.IsFailure()) return rc; + res = fileSystemProxy.Get.OpenFileSystemWithId(ref fileSystem.Ref(), in sfPath, id, fsType); + if (res.IsFailure()) return res.Miss(); using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref())); @@ -57,21 +57,21 @@ public static class Content if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInContentA.Log(); - rc = fs.Register(mountName, ref fileSystemAdapter.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Register(mountName, ref fileSystemAdapter.Ref()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public static Result MountContent(this FileSystemClient fs, U8Span mountName, U8Span path, ContentType contentType) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x300]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = PreMount(contentType); + res = PreMount(contentType); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -81,22 +81,22 @@ public static class Content .Append(LogPath).Append(path).Append(LogQuote) .Append(LogContentType).Append(idString.ToString(contentType)); - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = PreMount(contentType); + res = PreMount(contentType); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); ProgramId programId = default; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = MountContentImpl(fs, mountName, path, programId.Value, contentType); + res = MountContentImpl(fs, mountName, path, programId.Value, contentType); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -107,15 +107,15 @@ public static class Content .Append(LogProgramId).AppendFormat(programId.Value, 'X') .Append(LogContentType).Append(idString.ToString(contentType)); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = MountContentImpl(fs, mountName, path, programId.Value, contentType); + res = MountContentImpl(fs, mountName, path, programId.Value, contentType); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -134,13 +134,13 @@ public static class Content public static Result MountContent(this FileSystemClient fs, U8Span mountName, U8Span path, ProgramId programId, ContentType contentType) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x300]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = MountContentImpl(fs, mountName, path, programId.Value, contentType); + res = MountContentImpl(fs, mountName, path, programId.Value, contentType); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -153,15 +153,15 @@ public static class Content logBuffer = sb.Buffer; - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = MountContentImpl(fs, mountName, path, programId.Value, contentType); + res = MountContentImpl(fs, mountName, path, programId.Value, contentType); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -172,13 +172,13 @@ public static class Content public static Result MountContent(this FileSystemClient fs, U8Span mountName, U8Span path, DataId dataId, ContentType contentType) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x300]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = MountContentImpl(fs, mountName, path, dataId.Value, contentType); + res = MountContentImpl(fs, mountName, path, dataId.Value, contentType); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -189,15 +189,15 @@ public static class Content .Append(LogDataId).AppendFormat(dataId.Value, 'X') .Append(LogContentType).Append(idString.ToString(contentType)); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = MountContentImpl(fs, mountName, path, dataId.Value, contentType); + res = MountContentImpl(fs, mountName, path, dataId.Value, contentType); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -208,13 +208,13 @@ public static class Content public static Result MountContent(this FileSystemClient fs, U8Span mountName, ProgramId programId, ContentType contentType) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x300]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Mount(fs, mountName, programId, contentType); + res = Mount(fs, mountName, programId, contentType); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -224,15 +224,15 @@ public static class Content .Append(LogProgramId).AppendFormat(programId.Value, 'X') .Append(LogContentType).Append(idString.ToString(contentType)); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = Mount(fs, mountName, programId, contentType); + res = Mount(fs, mountName, programId, contentType); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -241,16 +241,16 @@ public static class Content static Result Mount(FileSystemClient fs, U8Span mountName, ProgramId programId, ContentType contentType) { - Result rc = fs.Impl.CheckMountNameAcceptingReservedMountName(mountName); - if (rc.IsFailure()) return rc; + Result res = fs.Impl.CheckMountNameAcceptingReservedMountName(mountName); + if (res.IsFailure()) return res.Miss(); FileSystemProxyType fsType = ConvertToFileSystemProxyType(contentType); using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var fileSystem = new SharedRef(); - rc = fileSystemProxy.Get.OpenFileSystemWithPatch(ref fileSystem.Ref(), programId, fsType); - if (rc.IsFailure()) return rc; + res = fileSystemProxy.Get.OpenFileSystemWithPatch(ref fileSystem.Ref(), programId, fsType); + if (res.IsFailure()) return res.Miss(); using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref())); @@ -258,8 +258,8 @@ public static class Content if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInContentA.Log(); - rc = fs.Register(mountName, ref fileSystemAdapter.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Register(mountName, ref fileSystemAdapter.Ref()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/ContentStorage.cs b/src/LibHac/Fs/Shim/ContentStorage.cs index 590839ef..580378a2 100644 --- a/src/LibHac/Fs/Shim/ContentStorage.cs +++ b/src/LibHac/Fs/Shim/ContentStorage.cs @@ -56,13 +56,13 @@ public static class ContentStorage public static Result MountContentStorage(this FileSystemClient fs, U8Span mountName, ContentStorageId storageId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x40]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Mount(fs, mountName, storageId); + res = Mount(fs, mountName, storageId); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -71,15 +71,15 @@ public static class ContentStorage sb.Append(LogName).Append(mountName).Append(LogQuote) .Append(LogContentStorageId).Append(idString.ToString(storageId)); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = Mount(fs, mountName, storageId); + res = Mount(fs, mountName, storageId); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -93,26 +93,26 @@ public static class ContentStorage const int maxRetries = 10; const int retryInterval = 1000; - Result rc = fs.Impl.CheckMountNameAcceptingReservedMountName(mountName); - if (rc.IsFailure()) return rc; + Result res = fs.Impl.CheckMountNameAcceptingReservedMountName(mountName); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var fileSystem = new SharedRef(); for (int i = 0; i < maxRetries; i++) { - rc = fileSystemProxy.Get.OpenContentStorageFileSystem(ref fileSystem.Ref(), storageId); + res = fileSystemProxy.Get.OpenContentStorageFileSystem(ref fileSystem.Ref(), storageId); - if (rc.IsSuccess()) + if (res.IsSuccess()) break; - if (!ResultFs.SystemPartitionNotReady.Includes(rc)) - return rc; + if (!ResultFs.SystemPartitionNotReady.Includes(res)) + return res; // Note: Nintendo has an off-by-one error where they check if // "i == maxRetries" instead of "i == maxRetries - 1" if (i == maxRetries - 1) - return rc; + return res; fs.Hos.Os.SleepThread(TimeSpan.FromMilliSeconds(retryInterval)); } @@ -129,8 +129,8 @@ public static class ContentStorage if (!mountNameGenerator.HasValue) return ResultFs.AllocationMemoryFailedInContentStorageB.Log(); - rc = fs.Register(mountName, ref fileSystemAdapter.Ref(), ref mountNameGenerator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Register(mountName, ref fileSystemAdapter.Ref(), ref mountNameGenerator.Ref()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/CustomStorage.cs b/src/LibHac/Fs/Shim/CustomStorage.cs index 27545b29..12d898b3 100644 --- a/src/LibHac/Fs/Shim/CustomStorage.cs +++ b/src/LibHac/Fs/Shim/CustomStorage.cs @@ -32,29 +32,29 @@ public static class CustomStorage public static Result MountCustomStorage(this FileSystemClient fs, U8Span mountName, CustomStorageId storageId) { - Result rc = Mount(fs, mountName, storageId); + Result res = Mount(fs, mountName, storageId); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; static Result Mount(FileSystemClient fs, U8Span mountName, CustomStorageId storageId) { - Result rc = fs.Impl.CheckMountName(mountName); - if (rc.IsFailure()) return rc.Miss(); + Result res = fs.Impl.CheckMountName(mountName); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var fileSystem = new SharedRef(); - rc = fileSystemProxy.Get.OpenCustomStorageFileSystem(ref fileSystem.Ref(), storageId); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystemProxy.Get.OpenCustomStorageFileSystem(ref fileSystem.Ref(), storageId); + if (res.IsFailure()) return res.Miss(); using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref())); - rc = fs.Register(mountName, ref fileSystemAdapter.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Register(mountName, ref fileSystemAdapter.Ref()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/Debug.cs b/src/LibHac/Fs/Shim/Debug.cs index 65b4557b..e4d69dc1 100644 --- a/src/LibHac/Fs/Shim/Debug.cs +++ b/src/LibHac/Fs/Shim/Debug.cs @@ -24,9 +24,9 @@ public static class DebugShim { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.CreatePaddingFile(size); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.CreatePaddingFile(size); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -35,9 +35,9 @@ public static class DebugShim { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.DeleteAllPaddingFiles(); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.DeleteAllPaddingFiles(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -47,9 +47,9 @@ public static class DebugShim { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.OverrideSaveDataTransferTokenSignVerificationKey(new InBuffer(keyBuffer)); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OverrideSaveDataTransferTokenSignVerificationKey(new InBuffer(keyBuffer)); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -58,9 +58,9 @@ public static class DebugShim { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.RegisterDebugConfiguration((uint)key, value); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.RegisterDebugConfiguration((uint)key, value); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -69,9 +69,9 @@ public static class DebugShim { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.UnregisterDebugConfiguration((uint)key); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.UnregisterDebugConfiguration((uint)key); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/DeviceSaveData.cs b/src/LibHac/Fs/Shim/DeviceSaveData.cs index ab759bdd..3f698387 100644 --- a/src/LibHac/Fs/Shim/DeviceSaveData.cs +++ b/src/LibHac/Fs/Shim/DeviceSaveData.cs @@ -29,9 +29,9 @@ public static class DeviceSaveData public Result GetSaveDataAttribute(out SaveDataAttribute attribute) { - Result rc = SaveDataAttribute.Make(out attribute, _programId, SaveDataType.Device, InvalidUserId, + Result res = SaveDataAttribute.Make(out attribute, _programId, SaveDataType.Device, InvalidUserId, InvalidSystemSaveDataId); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -42,14 +42,14 @@ public static class DeviceSaveData private static Result MountDeviceSaveDataImpl(this FileSystemClientImpl fs, U8Span mountName, in SaveDataAttribute attribute) { - Result rc = fs.CheckMountName(mountName); - if (rc.IsFailure()) return rc; + Result res = fs.CheckMountName(mountName); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); using var fileSystem = new SharedRef(); - rc = fileSystemProxy.Get.OpenSaveDataFileSystem(ref fileSystem.Ref(), DeviceSaveDataSpaceId, in attribute); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystemProxy.Get.OpenSaveDataFileSystem(ref fileSystem.Ref(), DeviceSaveDataSpaceId, in attribute); + if (res.IsFailure()) return res.Miss(); var fileSystemAdapterRaw = new FileSystemServiceObjectAdapter(ref fileSystem.Ref()); using var fileSystemAdapter = new UniqueRef(fileSystemAdapterRaw); @@ -62,10 +62,10 @@ public static class DeviceSaveData using var mountNameGenerator = new UniqueRef(); - rc = fs.Fs.Register(mountName, fileSystemAdapterRaw, ref fileSystemAdapter.Ref(), ref mountNameGenerator.Ref(), + res = fs.Fs.Register(mountName, fileSystemAdapterRaw, ref fileSystemAdapter.Ref(), ref mountNameGenerator.Ref(), ref saveDataAttributeGetter.Ref(), useDataCache: false, storageForPurgeFileDataCache: null, usePathCache: true); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -74,30 +74,30 @@ public static class DeviceSaveData { Span logBuffer = stackalloc byte[0x30]; - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, InvalidProgramId, SaveDataType.Device, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, InvalidProgramId, SaveDataType.Device, InvalidUserId, InvalidSystemSaveDataId); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = MountDeviceSaveDataImpl(fs.Impl, mountName, in attribute); + res = MountDeviceSaveDataImpl(fs.Impl, mountName, in attribute); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogName).Append(mountName).Append(LogQuote); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = MountDeviceSaveDataImpl(fs.Impl, mountName, in attribute); + res = MountDeviceSaveDataImpl(fs.Impl, mountName, in attribute); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -110,31 +110,31 @@ public static class DeviceSaveData { Span logBuffer = stackalloc byte[0x50]; - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Device, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Device, InvalidUserId, InvalidSystemSaveDataId); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = MountDeviceSaveDataImpl(fs.Impl, mountName, in attribute); + res = MountDeviceSaveDataImpl(fs.Impl, mountName, in attribute); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogName).Append(mountName).Append(LogQuote) .Append(LogApplicationId).AppendFormat(applicationId.Value, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = MountDeviceSaveDataImpl(fs.Impl, mountName, in attribute); + res = MountDeviceSaveDataImpl(fs.Impl, mountName, in attribute); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -149,7 +149,7 @@ public static class DeviceSaveData public static bool IsDeviceSaveDataExisting(this FileSystemClient fs, ApplicationId applicationId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x30]; bool exists; @@ -158,21 +158,21 @@ public static class DeviceSaveData if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.IsSaveDataExisting(out exists, appId, SaveDataType.Device, InvalidUserId); + res = fs.Impl.IsSaveDataExisting(out exists, appId, SaveDataType.Device, InvalidUserId); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogApplicationId).AppendFormat(applicationId.Value, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.IsSaveDataExisting(out exists, appId, SaveDataType.Device, InvalidUserId); + res = fs.Impl.IsSaveDataExisting(out exists, appId, SaveDataType.Device, InvalidUserId); } - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); return exists; } diff --git a/src/LibHac/Fs/Shim/ErrorInfo.cs b/src/LibHac/Fs/Shim/ErrorInfo.cs index 7a951e54..e7c1f396 100644 --- a/src/LibHac/Fs/Shim/ErrorInfo.cs +++ b/src/LibHac/Fs/Shim/ErrorInfo.cs @@ -14,9 +14,9 @@ public static class ErrorInfo { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.GetAndClearErrorInfo(out outErrorInfo); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.GetAndClearErrorInfo(out outErrorInfo); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/FileSystemProxyServiceObject.cs b/src/LibHac/Fs/Shim/FileSystemProxyServiceObject.cs index 6f8c019b..21def861 100644 --- a/src/LibHac/Fs/Shim/FileSystemProxyServiceObject.cs +++ b/src/LibHac/Fs/Shim/FileSystemProxyServiceObject.cs @@ -61,11 +61,11 @@ public static class FileSystemProxyServiceObject } using var fileSystemProxy = new SharedRef(); - Result rc = fs.Hos.Sm.GetService(ref fileSystemProxy.Ref(), "fsp-srv"); + Result res = fs.Hos.Sm.GetService(ref fileSystemProxy.Ref(), "fsp-srv"); - if (rc.IsFailure()) + if (res.IsFailure()) { - throw new HorizonResultException(rc, "Failed to get file system proxy service object."); + throw new HorizonResultException(res, "Failed to get file system proxy service object."); } fileSystemProxy.Get.SetCurrentProcess(fs.Hos.Os.GetCurrentProcessId().Value).IgnoreResult(); @@ -92,11 +92,11 @@ public static class FileSystemProxyServiceObject FileSystemClientImpl fs) { using var fileSystemProxy = new SharedRef(); - Result rc = fs.Hos.Sm.GetService(ref fileSystemProxy.Ref(), "fsp-ldr"); + Result res = fs.Hos.Sm.GetService(ref fileSystemProxy.Ref(), "fsp-ldr"); - if (rc.IsFailure()) + if (res.IsFailure()) { - throw new HorizonResultException(rc, "Failed to get file system proxy service object."); + throw new HorizonResultException(res, "Failed to get file system proxy service object."); } fileSystemProxy.Get.SetCurrentProcess(fs.Hos.Os.GetCurrentProcessId().Value).IgnoreResult(); @@ -121,11 +121,11 @@ public static class FileSystemProxyServiceObject private static SharedRef GetProgramRegistryServiceObjectImpl(FileSystemClientImpl fs) { using var registry = new SharedRef(); - Result rc = fs.Hos.Sm.GetService(ref registry.Ref(), "fsp-pr"); + Result res = fs.Hos.Sm.GetService(ref registry.Ref(), "fsp-pr"); - if (rc.IsFailure()) + if (res.IsFailure()) { - throw new HorizonResultException(rc, "Failed to get registry service object."); + throw new HorizonResultException(res, "Failed to get registry service object."); } registry.Get.SetCurrentProcess(fs.Hos.Os.GetCurrentProcessId().Value).IgnoreResult(); diff --git a/src/LibHac/Fs/Shim/FileSystemServiceObjectAdapter.cs b/src/LibHac/Fs/Shim/FileSystemServiceObjectAdapter.cs index 20e88640..58ce2bc4 100644 --- a/src/LibHac/Fs/Shim/FileSystemServiceObjectAdapter.cs +++ b/src/LibHac/Fs/Shim/FileSystemServiceObjectAdapter.cs @@ -150,70 +150,70 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { - Result rc = GetPathForServiceObject(out PathSf sfPath, in path); - if (rc.IsFailure()) return rc; + Result res = GetPathForServiceObject(out PathSf sfPath, in path); + if (res.IsFailure()) return res.Miss(); return _baseFs.Get.CreateFile(in sfPath, size, (int)option); } protected override Result DoDeleteFile(in Path path) { - Result rc = GetPathForServiceObject(out PathSf sfPath, in path); - if (rc.IsFailure()) return rc; + Result res = GetPathForServiceObject(out PathSf sfPath, in path); + if (res.IsFailure()) return res.Miss(); return _baseFs.Get.DeleteFile(in sfPath); } protected override Result DoCreateDirectory(in Path path) { - Result rc = GetPathForServiceObject(out PathSf sfPath, in path); - if (rc.IsFailure()) return rc; + Result res = GetPathForServiceObject(out PathSf sfPath, in path); + if (res.IsFailure()) return res.Miss(); return _baseFs.Get.CreateDirectory(in sfPath); } protected override Result DoDeleteDirectory(in Path path) { - Result rc = GetPathForServiceObject(out PathSf sfPath, in path); - if (rc.IsFailure()) return rc; + Result res = GetPathForServiceObject(out PathSf sfPath, in path); + if (res.IsFailure()) return res.Miss(); return _baseFs.Get.DeleteDirectory(in sfPath); } protected override Result DoDeleteDirectoryRecursively(in Path path) { - Result rc = GetPathForServiceObject(out PathSf sfPath, in path); - if (rc.IsFailure()) return rc; + Result res = GetPathForServiceObject(out PathSf sfPath, in path); + if (res.IsFailure()) return res.Miss(); return _baseFs.Get.DeleteDirectoryRecursively(in sfPath); } protected override Result DoCleanDirectoryRecursively(in Path path) { - Result rc = GetPathForServiceObject(out PathSf sfPath, in path); - if (rc.IsFailure()) return rc; + Result res = GetPathForServiceObject(out PathSf sfPath, in path); + if (res.IsFailure()) return res.Miss(); return _baseFs.Get.CleanDirectoryRecursively(in sfPath); } protected override Result DoRenameFile(in Path currentPath, in Path newPath) { - Result rc = GetPathForServiceObject(out PathSf currentSfPath, in currentPath); - if (rc.IsFailure()) return rc; + Result res = GetPathForServiceObject(out PathSf currentSfPath, in currentPath); + if (res.IsFailure()) return res.Miss(); - rc = GetPathForServiceObject(out PathSf newSfPath, in newPath); - if (rc.IsFailure()) return rc; + res = GetPathForServiceObject(out PathSf newSfPath, in newPath); + if (res.IsFailure()) return res.Miss(); return _baseFs.Get.RenameFile(in currentSfPath, in newSfPath); } protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) { - Result rc = GetPathForServiceObject(out PathSf currentSfPath, in currentPath); - if (rc.IsFailure()) return rc; + Result res = GetPathForServiceObject(out PathSf currentSfPath, in currentPath); + if (res.IsFailure()) return res.Miss(); - rc = GetPathForServiceObject(out PathSf newSfPath, in newPath); - if (rc.IsFailure()) return rc; + res = GetPathForServiceObject(out PathSf newSfPath, in newPath); + if (res.IsFailure()) return res.Miss(); return _baseFs.Get.RenameDirectory(in currentSfPath, in newSfPath); } @@ -222,8 +222,8 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget { UnsafeHelpers.SkipParamInit(out entryType); - Result rc = GetPathForServiceObject(out PathSf sfPath, in path); - if (rc.IsFailure()) return rc; + Result res = GetPathForServiceObject(out PathSf sfPath, in path); + if (res.IsFailure()) return res.Miss(); ref uint sfEntryType = ref Unsafe.As(ref entryType); @@ -234,8 +234,8 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget { UnsafeHelpers.SkipParamInit(out freeSpace); - Result rc = GetPathForServiceObject(out PathSf sfPath, in path); - if (rc.IsFailure()) return rc; + Result res = GetPathForServiceObject(out PathSf sfPath, in path); + if (res.IsFailure()) return res.Miss(); return _baseFs.Get.GetFreeSpaceSize(out freeSpace, in sfPath); } @@ -244,21 +244,21 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget { UnsafeHelpers.SkipParamInit(out totalSpace); - Result rc = GetPathForServiceObject(out PathSf sfPath, in path); - if (rc.IsFailure()) return rc; + Result res = GetPathForServiceObject(out PathSf sfPath, in path); + if (res.IsFailure()) return res.Miss(); return _baseFs.Get.GetTotalSpaceSize(out totalSpace, in sfPath); } protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) { - Result rc = GetPathForServiceObject(out PathSf sfPath, in path); - if (rc.IsFailure()) return rc; + Result res = GetPathForServiceObject(out PathSf sfPath, in path); + if (res.IsFailure()) return res.Miss(); using var fileServiceObject = new SharedRef(); - rc = _baseFs.Get.OpenFile(ref fileServiceObject.Ref(), in sfPath, (uint)mode); - if (rc.IsFailure()) return rc; + res = _baseFs.Get.OpenFile(ref fileServiceObject.Ref(), in sfPath, (uint)mode); + if (res.IsFailure()) return res.Miss(); outFile.Reset(new FileServiceObjectAdapter(ref fileServiceObject.Ref())); return Result.Success; @@ -267,13 +267,13 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, OpenDirectoryMode mode) { - Result rc = GetPathForServiceObject(out PathSf sfPath, in path); - if (rc.IsFailure()) return rc; + Result res = GetPathForServiceObject(out PathSf sfPath, in path); + if (res.IsFailure()) return res.Miss(); using var directoryServiceObject = new SharedRef(); - rc = _baseFs.Get.OpenDirectory(ref directoryServiceObject.Ref(), in sfPath, (uint)mode); - if (rc.IsFailure()) return rc; + res = _baseFs.Get.OpenDirectory(ref directoryServiceObject.Ref(), in sfPath, (uint)mode); + if (res.IsFailure()) return res.Miss(); outDirectory.Reset(new DirectoryServiceObjectAdapter(ref directoryServiceObject.Ref())); return Result.Success; @@ -288,8 +288,8 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget { UnsafeHelpers.SkipParamInit(out timeStamp); - Result rc = GetPathForServiceObject(out PathSf sfPath, in path); - if (rc.IsFailure()) return rc; + Result res = GetPathForServiceObject(out PathSf sfPath, in path); + if (res.IsFailure()) return res.Miss(); return _baseFs.Get.GetFileTimeStampRaw(out timeStamp, in sfPath); } @@ -297,8 +297,8 @@ internal class FileSystemServiceObjectAdapter : IFileSystem, IMultiCommitTarget protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, in Path path) { - Result rc = GetPathForServiceObject(out PathSf sfPath, in path); - if (rc.IsFailure()) return rc; + Result res = GetPathForServiceObject(out PathSf sfPath, in path); + if (res.IsFailure()) return res.Miss(); return _baseFs.Get.QueryEntry(new OutBuffer(outBuffer), new InBuffer(inBuffer), (int)queryId, in sfPath); } diff --git a/src/LibHac/Fs/Shim/GameCard.cs b/src/LibHac/Fs/Shim/GameCard.cs index db78c8b7..6219d103 100644 --- a/src/LibHac/Fs/Shim/GameCard.cs +++ b/src/LibHac/Fs/Shim/GameCard.cs @@ -84,13 +84,13 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.GetGameCardHandle(out GameCardHandle handle); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetGameCardHandle(out GameCardHandle handle); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outHandle = handle; return Result.Success; @@ -99,13 +99,13 @@ public static class GameCard public static Result MountGameCardPartition(this FileSystemClient fs, U8Span mountName, GameCardHandle handle, GameCardPartition partitionId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x60]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Mount(fs, mountName, handle, partitionId); + res = Mount(fs, mountName, handle, partitionId); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -115,15 +115,15 @@ public static class GameCard .Append(LogGameCardHandle).AppendFormat(handle, 'X') .Append(LogGameCardPartition).Append(idString.ToString(partitionId)); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = Mount(fs, mountName, handle, partitionId); + res = Mount(fs, mountName, handle, partitionId); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -132,14 +132,14 @@ public static class GameCard static Result Mount(FileSystemClient fs, U8Span mountName, GameCardHandle handle, GameCardPartition partitionId) { - Result rc = fs.Impl.CheckMountNameAcceptingReservedMountName(mountName); - if (rc.IsFailure()) return rc.Miss(); + Result res = fs.Impl.CheckMountNameAcceptingReservedMountName(mountName); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var fileSystem = new SharedRef(); - rc = fileSystemProxy.Get.OpenGameCardFileSystem(ref fileSystem.Ref(), handle, partitionId); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystemProxy.Get.OpenGameCardFileSystem(ref fileSystem.Ref(), handle, partitionId); + if (res.IsFailure()) return res.Miss(); using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref())); @@ -162,13 +162,13 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); - rc = deviceOperator.Get.IsGameCardInserted(out bool isInserted); - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + res = deviceOperator.Get.IsGameCardInserted(out bool isInserted); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); return isInserted; } @@ -179,9 +179,9 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var storage = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenGameCardStorage(ref storage.Ref(), handle, partitionType); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenGameCardStorage(ref storage.Ref(), handle, partitionType); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); using var storageAdapter = new UniqueRef(new StorageServiceObjectAdapter(ref storage.Ref())); @@ -197,13 +197,13 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.EraseGameCard((uint)cardSize, romAreaStartPageAddress); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.EraseGameCard((uint)cardSize, romAreaStartPageAddress); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -216,13 +216,13 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.GetGameCardUpdatePartitionInfo(out uint cupVersion, out ulong cupId, handle); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetGameCardUpdatePartitionInfo(out uint cupVersion, out ulong cupId, handle); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outPartitionInfo.CupVersion = cupVersion; outPartitionInfo.CupId = cupId; @@ -235,13 +235,13 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); - rc = deviceOperator.Get.FinalizeGameCardDriver(); - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + res = deviceOperator.Get.FinalizeGameCardDriver(); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); } public static Result GetGameCardAttribute(this FileSystemClient fs, out GameCardAttribute outAttribute, @@ -252,13 +252,13 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.GetGameCardAttribute(out byte gameCardAttribute, handle); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetGameCardAttribute(out byte gameCardAttribute, handle); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outAttribute = (GameCardAttribute)gameCardAttribute; @@ -273,13 +273,13 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.GetGameCardCompatibilityType(out byte gameCardCompatibilityType, handle); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetGameCardCompatibilityType(out byte gameCardCompatibilityType, handle); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outCompatibilityType = (GameCardCompatibilityType)gameCardCompatibilityType; @@ -292,13 +292,13 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.GetGameCardDeviceCertificate(new OutBuffer(outBuffer), outBuffer.Length, handle); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetGameCardDeviceCertificate(new OutBuffer(outBuffer), outBuffer.Length, handle); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -309,14 +309,14 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.ChallengeCardExistence(new OutBuffer(responseBuffer), new InBuffer(challengeSeedBuffer), + res = deviceOperator.Get.ChallengeCardExistence(new OutBuffer(responseBuffer), new InBuffer(challengeSeedBuffer), new InBuffer(challengeValueBuffer), handle); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -329,16 +329,16 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); Unsafe.SkipInit(out RmaInformation rmaInformation); - rc = deviceOperator.Get.GetGameCardAsicInfo(OutBuffer.FromStruct(ref rmaInformation), + res = deviceOperator.Get.GetGameCardAsicInfo(OutBuffer.FromStruct(ref rmaInformation), Unsafe.SizeOf(), new InBuffer(asicFirmwareBuffer), asicFirmwareBuffer.Length); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outRmaInfo = rmaInformation; @@ -352,15 +352,15 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); Unsafe.SkipInit(out GameCardIdSet gcIdSet); - rc = deviceOperator.Get.GetGameCardIdSet(OutBuffer.FromStruct(ref gcIdSet), Unsafe.SizeOf()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetGameCardIdSet(OutBuffer.FromStruct(ref gcIdSet), Unsafe.SizeOf()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outGcIdSet = gcIdSet; @@ -369,27 +369,27 @@ public static class GameCard public static Result GetGameCardCid(this FileSystemClient fs, Span outCidBuffer) { - Result rc; + Result res; if (outCidBuffer.Length < Unsafe.SizeOf()) { - rc = ResultFs.InvalidSize.Value; - fs.Impl.AbortIfNeeded(rc); - return rc.Log(); + res = ResultFs.InvalidSize.Value; + fs.Impl.AbortIfNeeded(res); + return res.Log(); } using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); Unsafe.SkipInit(out GameCardIdSet gcIdSet); - rc = deviceOperator.Get.GetGameCardIdSet(OutBuffer.FromStruct(ref gcIdSet), Unsafe.SizeOf()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetGameCardIdSet(OutBuffer.FromStruct(ref gcIdSet), Unsafe.SizeOf()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); SpanHelpers.AsByteSpan(ref gcIdSet).CopyTo(outCidBuffer); @@ -401,13 +401,13 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.WriteToGameCardDirectly(offset, new OutBuffer(buffer), buffer.Length); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.WriteToGameCardDirectly(offset, new OutBuffer(buffer), buffer.Length); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -417,13 +417,13 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.SetVerifyWriteEnableFlag(isEnabled); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.SetVerifyWriteEnableFlag(isEnabled); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -433,13 +433,13 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.GetGameCardImageHash(new OutBuffer(outBuffer), outBuffer.Length, handle); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetGameCardImageHash(new OutBuffer(outBuffer), outBuffer.Length, handle); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -450,14 +450,14 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.GetGameCardDeviceIdForProdCard(new OutBuffer(outIdBuffer), outIdBuffer.Length, + res = deviceOperator.Get.GetGameCardDeviceIdForProdCard(new OutBuffer(outIdBuffer), outIdBuffer.Length, new InBuffer(devHeaderBuffer), devHeaderBuffer.Length); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -467,13 +467,13 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.EraseAndWriteParamDirectly(new InBuffer(devParamBuffer), devParamBuffer.Length); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.EraseAndWriteParamDirectly(new InBuffer(devParamBuffer), devParamBuffer.Length); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -483,13 +483,13 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.ReadParamDirectly(new OutBuffer(outBuffer), outBuffer.Length); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.ReadParamDirectly(new OutBuffer(outBuffer), outBuffer.Length); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -499,13 +499,13 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.ForceEraseGameCard(); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.ForceEraseGameCard(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -517,13 +517,13 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.GetGameCardErrorInfo(out GameCardErrorInfo gameCardErrorInfo); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetGameCardErrorInfo(out GameCardErrorInfo gameCardErrorInfo); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outErrorInfo = gameCardErrorInfo; @@ -537,13 +537,13 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.GetGameCardErrorReportInfo(out GameCardErrorReportInfo gameCardErrorReportInfo); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetGameCardErrorReportInfo(out GameCardErrorReportInfo gameCardErrorReportInfo); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outErrorInfo = gameCardErrorReportInfo; @@ -556,37 +556,37 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var fileSystem = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenGameCardFileSystem(ref fileSystem.Ref(), handle, partitionId); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenGameCardFileSystem(ref fileSystem.Ref(), handle, partitionId); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public static Result GetGameCardDeviceId(this FileSystemClient fs, Span outBuffer) { - Result rc; + Result res; // Note: Nintendo checks for length 8 here rather than GcCardDeviceIdSize (0x10) if (outBuffer.Length < GcCardDeviceIdSize) { - rc = ResultFs.InvalidSize.Value; - fs.Impl.AbortIfNeeded(rc); - return rc.Log(); + res = ResultFs.InvalidSize.Value; + fs.Impl.AbortIfNeeded(res); + return res.Log(); } using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); Span buffer = stackalloc byte[GcCardDeviceIdSize]; - rc = deviceOperator.Get.GetGameCardDeviceId(new OutBuffer(buffer), GcCardDeviceIdSize); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetGameCardDeviceId(new OutBuffer(buffer), GcCardDeviceIdSize); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); buffer.CopyTo(outBuffer); @@ -600,12 +600,12 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.SetDeviceSimulationEvent((uint)SdmmcPort.GcAsic, (uint)simulatedOperationType, + res = deviceOperator.Get.SetDeviceSimulationEvent((uint)SdmmcPort.GcAsic, (uint)simulatedOperationType, (uint)simulatedFailureType, failureResult.Value, autoClearEvent); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -615,9 +615,9 @@ public static class GameCard { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.SimulateDeviceDetectionEvent(SdmmcPort.GcAsic, mode, signalEvent); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.SimulateDeviceDetectionEvent(SdmmcPort.GcAsic, mode, signalEvent); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -626,10 +626,10 @@ public static class GameCard SimulatingDeviceTargetOperation simulatedOperationType, SimulatingDeviceAccessFailureEventType simulatedFailureType) { - Result rc = SetGameCardSimulationEventImpl(fs, simulatedOperationType, simulatedFailureType, Result.Success, + Result res = SetGameCardSimulationEventImpl(fs, simulatedOperationType, simulatedFailureType, Result.Success, autoClearEvent: false); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -638,10 +638,10 @@ public static class GameCard SimulatingDeviceTargetOperation simulatedOperationType, SimulatingDeviceAccessFailureEventType simulatedFailureType, bool autoClearEvent) { - Result rc = SetGameCardSimulationEventImpl(fs, simulatedOperationType, simulatedFailureType, Result.Success, + Result res = SetGameCardSimulationEventImpl(fs, simulatedOperationType, simulatedFailureType, Result.Success, autoClearEvent); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -649,10 +649,10 @@ public static class GameCard public static Result SetGameCardSimulationEvent(this FileSystemClient fs, SimulatingDeviceTargetOperation simulatedOperationType, Result failureResult, bool autoClearEvent) { - Result rc = SetGameCardSimulationEventImpl(fs, simulatedOperationType, + Result res = SetGameCardSimulationEventImpl(fs, simulatedOperationType, SimulatingDeviceAccessFailureEventType.AccessFailure, failureResult, autoClearEvent); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -662,13 +662,13 @@ public static class GameCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.ClearDeviceSimulationEvent((uint)SdmmcPort.GcAsic); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.ClearDeviceSimulationEvent((uint)SdmmcPort.GcAsic); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/Host.cs b/src/LibHac/Fs/Shim/Host.cs index dc804d67..97d79627 100644 --- a/src/LibHac/Fs/Shim/Host.cs +++ b/src/LibHac/Fs/Shim/Host.cs @@ -45,13 +45,13 @@ public static class Host if (option.Flags != MountHostOptionFlag.None) { - Result rc = fileSystemProxy.Get.OpenHostFileSystemWithOption(ref fileSystem.Ref(), in path, option); - if (rc.IsFailure()) return rc; + Result res = fileSystemProxy.Get.OpenHostFileSystemWithOption(ref fileSystem.Ref(), in path, option); + if (res.IsFailure()) return res.Miss(); } else { - Result rc = fileSystemProxy.Get.OpenHostFileSystem(ref fileSystem.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = fileSystemProxy.Get.OpenHostFileSystem(ref fileSystem.Ref(), in path); + if (res.IsFailure()) return res.Miss(); } using var fileSystemAdapter = @@ -129,8 +129,8 @@ public static class Host if (fs.Impl.IsUsedReservedMountName(mountName)) return ResultFs.InvalidMountName.Log(); - Result rc = PathUtility.ConvertToFspPath(out FspPath sfPath, path); - if (rc.IsFailure()) return rc.Miss(); + Result res = PathUtility.ConvertToFspPath(out FspPath sfPath, path); + if (res.IsFailure()) return res.Miss(); if (sfPath.Str[0] == NullTerminator) { @@ -140,8 +140,8 @@ public static class Host using var fileSystem = new UniqueRef(); - rc = OpenHostFileSystemImpl(fs, ref fileSystem.Ref(), in sfPath, option); - if (rc.IsFailure()) return rc.Miss(); + res = OpenHostFileSystemImpl(fs, ref fileSystem.Ref(), in sfPath, option); + if (res.IsFailure()) return res.Miss(); outFileSystem.Set(ref fileSystem.Ref()); return Result.Success; @@ -159,8 +159,8 @@ public static class Host private static Result PreMountHost(FileSystemClient fs, ref UniqueRef outMountNameGenerator, U8Span mountName, U8Span path) { - Result rc = fs.Impl.CheckMountName(mountName); - if (rc.IsFailure()) return rc; + Result res = fs.Impl.CheckMountName(mountName); + if (res.IsFailure()) return res.Miss(); outMountNameGenerator.Reset(new HostCommonMountNameGenerator(path)); @@ -179,7 +179,7 @@ public static class Host /// The of the operation. public static Result MountHost(this FileSystemClient fs, U8Span mountName, U8Span path) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x300]; using var mountNameGenerator = new UniqueRef(); @@ -187,7 +187,7 @@ public static class Host if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = PreMountHost(fs, ref mountNameGenerator.Ref(), mountName, path); + res = PreMountHost(fs, ref mountNameGenerator.Ref(), mountName, path); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); @@ -196,49 +196,49 @@ public static class Host logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = PreMountHost(fs, ref mountNameGenerator.Ref(), mountName, path); + res = PreMountHost(fs, ref mountNameGenerator.Ref(), mountName, path); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); using var fileSystem = new UniqueRef(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = OpenHostFileSystem(fs, ref fileSystem.Ref(), mountName, path, MountHostOption.None); + res = OpenHostFileSystem(fs, ref fileSystem.Ref(), mountName, path, MountHostOption.None); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = OpenHostFileSystem(fs, ref fileSystem.Ref(), mountName, path, MountHostOption.None); + res = OpenHostFileSystem(fs, ref fileSystem.Ref(), mountName, path, MountHostOption.None); } // No AbortIfNeeded here - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = PostMount(fs, mountName, ref fileSystem.Ref(), ref mountNameGenerator.Ref()); + res = PostMount(fs, mountName, ref fileSystem.Ref(), ref mountNameGenerator.Ref()); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = PostMount(fs, mountName, ref fileSystem.Ref(), ref mountNameGenerator.Ref()); + res = PostMount(fs, mountName, ref fileSystem.Ref(), ref mountNameGenerator.Ref()); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -251,8 +251,8 @@ public static class Host using UniqueRef baseMountNameGenerator = UniqueRef.Create(ref mountNameGenerator); - Result rc = fs.Register(mountName, ref fileSystem, ref baseMountNameGenerator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = fs.Register(mountName, ref fileSystem, ref baseMountNameGenerator.Ref()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -268,7 +268,7 @@ public static class Host /// The of the operation. public static Result MountHost(this FileSystemClient fs, U8Span mountName, U8Span path, MountHostOption option) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x300]; using var mountNameGenerator = new UniqueRef(); @@ -276,7 +276,7 @@ public static class Host if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = PreMountHost(fs, ref mountNameGenerator.Ref(), mountName, path); + res = PreMountHost(fs, ref mountNameGenerator.Ref(), mountName, path); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -288,49 +288,49 @@ public static class Host logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = PreMountHost(fs, ref mountNameGenerator.Ref(), mountName, path); + res = PreMountHost(fs, ref mountNameGenerator.Ref(), mountName, path); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); using var fileSystem = new UniqueRef(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = OpenHostFileSystem(fs, ref fileSystem.Ref(), mountName, path, option); + res = OpenHostFileSystem(fs, ref fileSystem.Ref(), mountName, path, option); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = OpenHostFileSystem(fs, ref fileSystem.Ref(), mountName, path, option); + res = OpenHostFileSystem(fs, ref fileSystem.Ref(), mountName, path, option); } // No AbortIfNeeded here - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = PostMount(fs, mountName, ref fileSystem.Ref(), ref mountNameGenerator.Ref()); + res = PostMount(fs, mountName, ref fileSystem.Ref(), ref mountNameGenerator.Ref()); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = PostMount(fs, mountName, ref fileSystem.Ref(), ref mountNameGenerator.Ref()); + res = PostMount(fs, mountName, ref fileSystem.Ref(), ref mountNameGenerator.Ref()); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -343,8 +343,8 @@ public static class Host using UniqueRef baseMountNameGenerator = UniqueRef.Create(ref mountNameGenerator); - Result rc = fs.Register(mountName, ref fileSystem, ref baseMountNameGenerator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = fs.Register(mountName, ref fileSystem, ref baseMountNameGenerator.Ref()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -357,7 +357,7 @@ public static class Host /// The of the operation. public static Result MountHostRoot(this FileSystemClient fs) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x30]; using var fileSystem = new UniqueRef(); @@ -366,38 +366,38 @@ public static class Host if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = OpenHostFileSystemImpl(fs, ref fileSystem.Ref(), in sfPath, MountHostOption.None); + res = OpenHostFileSystemImpl(fs, ref fileSystem.Ref(), in sfPath, MountHostOption.None); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogName).Append(HostRootFileSystemMountName).Append(LogQuote); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = OpenHostFileSystemImpl(fs, ref fileSystem.Ref(), in sfPath, MountHostOption.None); + res = OpenHostFileSystemImpl(fs, ref fileSystem.Ref(), in sfPath, MountHostOption.None); } // No AbortIfNeeded here - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = PostMount(fs, ref fileSystem.Ref()); + res = PostMount(fs, ref fileSystem.Ref()); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = PostMount(fs, ref fileSystem.Ref()); + res = PostMount(fs, ref fileSystem.Ref()); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) fs.Impl.EnableFileSystemAccessorAccessLog(new U8Span(HostRootFileSystemMountName)); @@ -412,9 +412,9 @@ public static class Host if (!mountNameGenerator.HasValue) return ResultFs.AllocationMemoryFailedInHostC.Log(); - Result rc = fs.Register(new U8Span(HostRootFileSystemMountName), ref fileSystem, + Result res = fs.Register(new U8Span(HostRootFileSystemMountName), ref fileSystem, ref mountNameGenerator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -428,7 +428,7 @@ public static class Host /// The of the operation. public static Result MountHostRoot(this FileSystemClient fs, MountHostOption option) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x60]; using var fileSystem = new UniqueRef(); @@ -437,7 +437,7 @@ public static class Host if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = OpenHostFileSystemImpl(fs, ref fileSystem.Ref(), in sfPath, option); + res = OpenHostFileSystemImpl(fs, ref fileSystem.Ref(), in sfPath, option); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -448,31 +448,31 @@ public static class Host logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = OpenHostFileSystemImpl(fs, ref fileSystem.Ref(), in sfPath, option); + res = OpenHostFileSystemImpl(fs, ref fileSystem.Ref(), in sfPath, option); } // No AbortIfNeeded here - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = PostMount(fs, ref fileSystem.Ref()); + res = PostMount(fs, ref fileSystem.Ref()); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = PostMount(fs, ref fileSystem.Ref()); + res = PostMount(fs, ref fileSystem.Ref()); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) fs.Impl.EnableFileSystemAccessorAccessLog(new U8Span(HostRootFileSystemMountName)); @@ -487,9 +487,9 @@ public static class Host if (!mountNameGenerator.HasValue) return ResultFs.AllocationMemoryFailedInHostC.Log(); - Result rc = fs.Register(new U8Span(HostRootFileSystemMountName), ref fileSystem, + Result res = fs.Register(new U8Span(HostRootFileSystemMountName), ref fileSystem, ref mountNameGenerator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -501,7 +501,7 @@ public static class Host /// The to use. public static void UnmountHostRoot(this FileSystemClient fs) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x30]; var mountName = new U8Span(HostRootFileSystemMountName); @@ -509,20 +509,20 @@ public static class Host if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledFileSystemAccessorAccessLog(mountName)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.Unmount(mountName); + res = fs.Impl.Unmount(mountName); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogName).Append(mountName).Append((byte)'"'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.Unmount(mountName); + res = fs.Impl.Unmount(mountName); } - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); } } \ No newline at end of file diff --git a/src/LibHac/Fs/Shim/ImageDirectory.cs b/src/LibHac/Fs/Shim/ImageDirectory.cs index 213d357e..73f2f55b 100644 --- a/src/LibHac/Fs/Shim/ImageDirectory.cs +++ b/src/LibHac/Fs/Shim/ImageDirectory.cs @@ -19,13 +19,13 @@ public static class ImageDirectory { public static Result MountImageDirectory(this FileSystemClient fs, U8Span mountName, ImageDirectoryId directoryId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x50]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Mount(fs, mountName, directoryId); + res = Mount(fs, mountName, directoryId); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -34,15 +34,15 @@ public static class ImageDirectory sb.Append(LogName).Append(mountName).Append(LogQuote) .Append(LogImageDirectoryId).Append(idString.ToString(directoryId)); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = Mount(fs, mountName, directoryId); + res = Mount(fs, mountName, directoryId); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -51,14 +51,14 @@ public static class ImageDirectory static Result Mount(FileSystemClient fs, U8Span mountName, ImageDirectoryId directoryId) { - Result rc = fs.Impl.CheckMountName(mountName); - if (rc.IsFailure()) return rc.Miss(); + Result res = fs.Impl.CheckMountName(mountName); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var fileSystem = new SharedRef(); - rc = fileSystemProxy.Get.OpenImageDirectoryFileSystem(ref fileSystem.Ref(), directoryId); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystemProxy.Get.OpenImageDirectoryFileSystem(ref fileSystem.Ref(), directoryId); + if (res.IsFailure()) return res.Miss(); using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref())); @@ -66,8 +66,8 @@ public static class ImageDirectory if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInImageDirectoryA.Log(); - rc = fs.Impl.Fs.Register(mountName, ref fileSystemAdapter.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Impl.Fs.Register(mountName, ref fileSystemAdapter.Ref()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/LoaderApi.cs b/src/LibHac/Fs/Shim/LoaderApi.cs index 94fbfa09..62f61750 100644 --- a/src/LibHac/Fs/Shim/LoaderApi.cs +++ b/src/LibHac/Fs/Shim/LoaderApi.cs @@ -15,9 +15,9 @@ public static class LoaderApi using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyForLoaderServiceObject(); - Result rc = fileSystemProxy.Get.IsArchivedProgram(out isArchived, processId.Value); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.IsArchivedProgram(out isArchived, processId.Value); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/Logo.cs b/src/LibHac/Fs/Shim/Logo.cs index 03659567..4b358dd1 100644 --- a/src/LibHac/Fs/Shim/Logo.cs +++ b/src/LibHac/Fs/Shim/Logo.cs @@ -20,13 +20,13 @@ public static class Logo { public static Result MountLogo(this FileSystemClient fs, U8Span mountName, U8Span path, ProgramId programId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x300]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Mount(fs, mountName, path, programId); + res = Mount(fs, mountName, path, programId); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); @@ -35,15 +35,15 @@ public static class Logo .Append(LogPath).Append(path).Append(LogQuote) .Append(LogProgramId).AppendFormat(programId.Value, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = Mount(fs, mountName, path, programId); + res = Mount(fs, mountName, path, programId); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -52,18 +52,18 @@ public static class Logo static Result Mount(FileSystemClient fs, U8Span mountName, U8Span path, ProgramId programId) { - Result rc = fs.Impl.CheckMountName(mountName); - if (rc.IsFailure()) return rc.Miss(); + Result res = fs.Impl.CheckMountName(mountName); + if (res.IsFailure()) return res.Miss(); - rc = PathUtility.ConvertToFspPath(out FspPath sfPath, path); - if (rc.IsFailure()) return rc; + res = PathUtility.ConvertToFspPath(out FspPath sfPath, path); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var fileSystem = new SharedRef(); - rc = fileSystemProxy.Get.OpenFileSystemWithId(ref fileSystem.Ref(), in sfPath, programId.Value, + res = fileSystemProxy.Get.OpenFileSystemWithId(ref fileSystem.Ref(), in sfPath, programId.Value, FileSystemProxyType.Logo); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref())); @@ -71,8 +71,8 @@ public static class Logo if (!fileSystemAdapter.HasValue) return ResultFs.AllocationMemoryFailedInLogoA.Log(); - rc = fs.Impl.Fs.Register(mountName, ref fileSystemAdapter.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Impl.Fs.Register(mountName, ref fileSystemAdapter.Ref()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/MemoryReportInfo.cs b/src/LibHac/Fs/Shim/MemoryReportInfo.cs index 8aa6fcb1..c18972d0 100644 --- a/src/LibHac/Fs/Shim/MemoryReportInfo.cs +++ b/src/LibHac/Fs/Shim/MemoryReportInfo.cs @@ -13,9 +13,9 @@ public static class MemoryReportInfoShim { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.GetAndClearMemoryReportInfo(out reportInfo); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.GetAndClearMemoryReportInfo(out reportInfo); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/Mmc.cs b/src/LibHac/Fs/Shim/Mmc.cs index b3ff1a6f..a560cfbd 100644 --- a/src/LibHac/Fs/Shim/Mmc.cs +++ b/src/LibHac/Fs/Shim/Mmc.cs @@ -18,13 +18,13 @@ public static class Mmc using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.GetMmcSpeedMode(out long speedMode); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetMmcSpeedMode(out long speedMode); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outSpeedMode = (MmcSpeedMode)speedMode; return Result.Success; @@ -35,13 +35,13 @@ public static class Mmc using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.GetMmcCid(new OutBuffer(outCidBuffer), outCidBuffer.Length); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetMmcCid(new OutBuffer(outCidBuffer), outCidBuffer.Length); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -51,13 +51,13 @@ public static class Mmc using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.EraseMmc((uint)partition); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.EraseMmc((uint)partition); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -70,13 +70,13 @@ public static class Mmc using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.GetMmcPartitionSize(out outPartitionSize, (uint)partition); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetMmcPartitionSize(out outPartitionSize, (uint)partition); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -88,13 +88,13 @@ public static class Mmc using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.GetMmcPatrolCount(out outPatrolCount); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetMmcPatrolCount(out outPatrolCount); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -107,14 +107,14 @@ public static class Mmc using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.GetAndClearMmcErrorInfo(out outErrorInfo, out long logSize, new OutBuffer(logBuffer), + res = deviceOperator.Get.GetAndClearMmcErrorInfo(out outErrorInfo, out long logSize, new OutBuffer(logBuffer), logBuffer.Length); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outLogSize = logSize; @@ -126,13 +126,13 @@ public static class Mmc using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.GetMmcExtendedCsd(new OutBuffer(outBuffer), outBuffer.Length); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetMmcExtendedCsd(new OutBuffer(outBuffer), outBuffer.Length); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -142,13 +142,13 @@ public static class Mmc using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.SuspendMmcPatrol(); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.SuspendMmcPatrol(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -158,13 +158,13 @@ public static class Mmc using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.ResumeMmcPatrol(); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.ResumeMmcPatrol(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/PosixTime.cs b/src/LibHac/Fs/Shim/PosixTime.cs index 9d32bc04..7169602c 100644 --- a/src/LibHac/Fs/Shim/PosixTime.cs +++ b/src/LibHac/Fs/Shim/PosixTime.cs @@ -14,9 +14,9 @@ public static class PosixTimeShim { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.SetCurrentPosixTimeWithTimeDifference(currentPosixTime.Value, + Result res = fileSystemProxy.Get.SetCurrentPosixTimeWithTimeDifference(currentPosixTime.Value, timeDifferenceSeconds); - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } } \ No newline at end of file diff --git a/src/LibHac/Fs/Shim/ProgramIndexMapInfo.cs b/src/LibHac/Fs/Shim/ProgramIndexMapInfo.cs index 2d59563a..842b3890 100644 --- a/src/LibHac/Fs/Shim/ProgramIndexMapInfo.cs +++ b/src/LibHac/Fs/Shim/ProgramIndexMapInfo.cs @@ -27,9 +27,9 @@ public static class ProgramIndexMapInfoShim using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.RegisterProgramIndexMapInfo(InBuffer.FromSpan(mapInfo), mapInfo.Length); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.RegisterProgramIndexMapInfo(InBuffer.FromSpan(mapInfo), mapInfo.Length); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/ProgramRegistry.cs b/src/LibHac/Fs/Shim/ProgramRegistry.cs index f33e7de9..afe04bb4 100644 --- a/src/LibHac/Fs/Shim/ProgramRegistry.cs +++ b/src/LibHac/Fs/Shim/ProgramRegistry.cs @@ -21,15 +21,15 @@ public static class ProgramRegistry { using SharedRef programRegistry = fs.Impl.GetProgramRegistryServiceObject(); - Result rc = programRegistry.Get.SetCurrentProcess(fs.Hos.Os.GetCurrentProcessId().Value); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = programRegistry.Get.SetCurrentProcess(fs.Hos.Os.GetCurrentProcessId().Value); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = programRegistry.Get.RegisterProgram(processId, programId, storageId, new InBuffer(accessControlData), + res = programRegistry.Get.RegisterProgram(processId, programId, storageId, new InBuffer(accessControlData), accessControlData.Length, new InBuffer(accessControlDescriptor), accessControlDescriptor.Length); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/RightsId.cs b/src/LibHac/Fs/Shim/RightsId.cs index 12306e86..675edf2b 100644 --- a/src/LibHac/Fs/Shim/RightsId.cs +++ b/src/LibHac/Fs/Shim/RightsId.cs @@ -16,9 +16,9 @@ public static class RightsIdShim { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.GetRightsId(out rightsId, programId, storageId); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.GetRightsId(out rightsId, programId, storageId); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -27,15 +27,15 @@ public static class RightsIdShim { UnsafeHelpers.SkipParamInit(out rightsId); - Result rc = PathUtility.ConvertToFspPath(out FspPath sfPath, path); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = PathUtility.ConvertToFspPath(out FspPath sfPath, path); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - rc = fileSystemProxy.Get.GetRightsIdByPath(out rightsId, in sfPath); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystemProxy.Get.GetRightsIdByPath(out rightsId, in sfPath); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -44,15 +44,15 @@ public static class RightsIdShim { UnsafeHelpers.SkipParamInit(out rightsId, out keyGeneration); - Result rc = PathUtility.ConvertToFspPath(out FspPath sfPath, path); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = PathUtility.ConvertToFspPath(out FspPath sfPath, path); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - rc = fileSystemProxy.Get.GetRightsIdAndKeyGenerationByPath(out rightsId, out keyGeneration, in sfPath); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystemProxy.Get.GetRightsIdAndKeyGenerationByPath(out rightsId, out keyGeneration, in sfPath); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -61,9 +61,9 @@ public static class RightsIdShim { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.RegisterExternalKey(in rightsId, in key); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.RegisterExternalKey(in rightsId, in key); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -72,9 +72,9 @@ public static class RightsIdShim { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.UnregisterExternalKey(in rightsId); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.UnregisterExternalKey(in rightsId); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -83,9 +83,9 @@ public static class RightsIdShim { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.UnregisterAllExternalKey(); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.UnregisterAllExternalKey(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/SaveData.cs b/src/LibHac/Fs/Shim/SaveData.cs index 0dc83873..834fea32 100644 --- a/src/LibHac/Fs/Shim/SaveData.cs +++ b/src/LibHac/Fs/Shim/SaveData.cs @@ -30,9 +30,9 @@ public static class SaveData using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var fileSystem = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenSaveDataInternalStorageFileSystem(ref fileSystem.Ref(), spaceId, + Result res = fileSystemProxy.Get.OpenSaveDataInternalStorageFileSystem(ref fileSystem.Ref(), spaceId, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); using var fileSystemAdapter = new UniqueRef(new FileSystemServiceObjectAdapter(ref fileSystem.Ref())); @@ -46,30 +46,30 @@ public static class SaveData long saveDataJournalSize) { // Find the save data for the current program. - Result rc = SaveDataFilter.Make(out SaveDataFilter filter, InvalidProgramId.Value, SaveDataType.Account, userId, + Result res = SaveDataFilter.Make(out SaveDataFilter filter, InvalidProgramId.Value, SaveDataType.Account, userId, InvalidSystemSaveDataId, index: 0, SaveDataRank.Primary); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); - rc = fs.Impl.FindSaveDataWithFilter(out SaveDataInfo info, SaveDataSpaceId.User, in filter); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Impl.FindSaveDataWithFilter(out SaveDataInfo info, SaveDataSpaceId.User, in filter); + if (res.IsFailure()) return res.Miss(); SaveDataSpaceId spaceId = info.SpaceId; ulong saveDataId = info.SaveDataId; // Get the current save data's sizes. - rc = fs.Impl.GetSaveDataAvailableSize(out long availableSize, spaceId, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Impl.GetSaveDataAvailableSize(out long availableSize, spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); - rc = fs.Impl.GetSaveDataJournalSize(out long journalSize, spaceId, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Impl.GetSaveDataJournalSize(out long journalSize, spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); // Extend the save data if it's not large enough. if (availableSize < saveDataSize || journalSize < saveDataJournalSize) { long newSaveDataSize = Math.Max(saveDataSize, availableSize); long newJournalSize = Math.Max(saveDataJournalSize, journalSize); - rc = fs.Impl.ExtendSaveData(spaceId, saveDataId, newSaveDataSize, newJournalSize); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Impl.ExtendSaveData(spaceId, saveDataId, newSaveDataSize, newJournalSize); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -78,26 +78,26 @@ public static class SaveData private static Result MountSaveDataImpl(this FileSystemClientImpl fs, U8Span mountName, SaveDataSpaceId spaceId, ProgramId programId, UserId userId, SaveDataType type, bool openReadOnly, ushort index) { - Result rc = fs.CheckMountName(mountName); - if (rc.IsFailure()) return rc; + Result res = fs.CheckMountName(mountName); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, programId, type, userId, InvalidSystemSaveDataId, + res = SaveDataAttribute.Make(out SaveDataAttribute attribute, programId, type, userId, InvalidSystemSaveDataId, index); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); using var fileSystem = new SharedRef(); if (openReadOnly) { - rc = fileSystemProxy.Get.OpenReadOnlySaveDataFileSystem(ref fileSystem.Ref(), spaceId, in attribute); - if (rc.IsFailure()) return rc; + res = fileSystemProxy.Get.OpenReadOnlySaveDataFileSystem(ref fileSystem.Ref(), spaceId, in attribute); + if (res.IsFailure()) return res.Miss(); } else { - rc = fileSystemProxy.Get.OpenSaveDataFileSystem(ref fileSystem.Ref(), spaceId, in attribute); - if (rc.IsFailure()) return rc; + res = fileSystemProxy.Get.OpenSaveDataFileSystem(ref fileSystem.Ref(), spaceId, in attribute); + if (res.IsFailure()) return res.Miss(); } // Note: Nintendo does pass in the same object both as a unique_ptr and as a raw pointer. @@ -110,9 +110,9 @@ public static class SaveData using var mountNameGenerator = new UniqueRef(); - rc = fs.Fs.Register(mountName, fileSystemAdapterRaw, ref fileSystemAdapter.Ref(), ref mountNameGenerator.Ref(), + res = fs.Fs.Register(mountName, fileSystemAdapterRaw, ref fileSystemAdapter.Ref(), ref mountNameGenerator.Ref(), false, null, true); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -131,13 +131,13 @@ public static class SaveData using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, InvalidProgramId, SaveDataType.Account, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, InvalidProgramId, SaveDataType.Account, userId, InvalidSystemSaveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = SaveDataCreationInfo.Make(out SaveDataCreationInfo creationInfo, saveDataSize, saveDataJournalSize, + res = SaveDataCreationInfo.Make(out SaveDataCreationInfo creationInfo, saveDataSize, saveDataJournalSize, ownerId: 0, SaveDataFlags.None, SaveDataSpaceId.User); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); var metaInfo = new SaveDataMetaInfo { @@ -145,22 +145,22 @@ public static class SaveData Size = 0 }; - rc = fileSystemProxy.Get.CreateSaveDataFileSystem(in attribute, in creationInfo, in metaInfo); + res = fileSystemProxy.Get.CreateSaveDataFileSystem(in attribute, in creationInfo, in metaInfo); - if (rc.IsFailure()) + if (res.IsFailure()) { // Ensure the save is large enough if it already exists - if (ResultFs.PathAlreadyExists.Includes(rc)) + if (ResultFs.PathAlreadyExists.Includes(res)) { if (extendIfNeeded) { - rc = ExtendSaveDataIfNeeded(fs.Fs, userId, saveDataSize, saveDataJournalSize); - if (rc.IsFailure()) return rc.Miss(); + res = ExtendSaveDataIfNeeded(fs.Fs, userId, saveDataSize, saveDataJournalSize); + if (res.IsFailure()) return res.Miss(); } } else { - return rc.Miss(); + return res.Miss(); } } @@ -175,28 +175,28 @@ public static class SaveData public static Result MountSaveData(this FileSystemClient fs, U8Span mountName, UserId userId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x60]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = MountSaveDataImpl(fs.Impl, mountName, InvalidUserId); + res = MountSaveDataImpl(fs.Impl, mountName, InvalidUserId); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogName).Append(mountName).Append(LogQuote) .Append(LogUserId).AppendFormat(userId.Id.High, 'X', 16).AppendFormat(userId.Id.Low, 'X', 16); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = MountSaveDataImpl(fs.Impl, mountName, InvalidUserId); + res = MountSaveDataImpl(fs.Impl, mountName, InvalidUserId); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -207,13 +207,13 @@ public static class SaveData public static Result MountSaveData(this FileSystemClient fs, U8Span mountName, Ncm.ApplicationId applicationId, UserId userId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x90]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, applicationId, userId, + res = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, applicationId, userId, SaveDataType.Account, openReadOnly: false, index: 0); Tick end = fs.Hos.Os.GetSystemTick(); @@ -222,16 +222,16 @@ public static class SaveData .Append(LogApplicationId).AppendFormat(applicationId.Value, 'X') .Append(LogUserId).AppendFormat(userId.Id.High, 'X', 16).AppendFormat(userId.Id.Low, 'X', 16); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, applicationId, userId, + res = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, applicationId, userId, SaveDataType.Account, openReadOnly: false, index: 0); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -242,13 +242,13 @@ public static class SaveData public static Result MountSaveDataReadOnly(this FileSystemClient fs, U8Span mountName, Ncm.ApplicationId applicationId, UserId userId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x90]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, applicationId, userId, + res = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, applicationId, userId, SaveDataType.Account, openReadOnly: true, index: 0); Tick end = fs.Hos.Os.GetSystemTick(); @@ -257,16 +257,16 @@ public static class SaveData .Append(LogApplicationId).AppendFormat(applicationId.Value, 'X') .Append(LogUserId).AppendFormat(userId.Id.High, 'X', 16).AppendFormat(userId.Id.Low, 'X', 16); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, applicationId, userId, + res = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, applicationId, userId, SaveDataType.Account, openReadOnly: true, index: 0); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -292,53 +292,53 @@ public static class SaveData using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, type, userId, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, type, userId, InvalidSystemSaveDataId); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); using var fileSystem = new SharedRef(); - rc = fileSystemProxy.Get.OpenSaveDataFileSystem(ref fileSystem.Ref(), SaveDataSpaceId.User, in attribute); + res = fileSystemProxy.Get.OpenSaveDataFileSystem(ref fileSystem.Ref(), SaveDataSpaceId.User, in attribute); - if (rc.IsSuccess() || ResultFs.TargetLocked.Includes(rc) || ResultFs.SaveDataExtending.Includes(rc)) + if (res.IsSuccess() || ResultFs.TargetLocked.Includes(res) || ResultFs.SaveDataExtending.Includes(res)) { exists = true; return Result.Success; } - if (ResultFs.TargetNotFound.Includes(rc)) + if (ResultFs.TargetNotFound.Includes(res)) { exists = false; return Result.Success; } - return rc.Miss(); + return res.Miss(); } public static Result MountTemporaryStorage(this FileSystemClient fs, U8Span mountName) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x30]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.Temporary, InvalidProgramId, InvalidUserId, + res = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.Temporary, InvalidProgramId, InvalidUserId, SaveDataType.Temporary, openReadOnly: false, index: 0); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogName).Append(mountName).Append(LogQuote); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.Temporary, InvalidProgramId, InvalidUserId, + res = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.Temporary, InvalidProgramId, InvalidUserId, SaveDataType.Temporary, openReadOnly: false, index: 0); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -348,29 +348,29 @@ public static class SaveData public static Result MountCacheStorage(this FileSystemClient fs, U8Span mountName) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x30]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, InvalidProgramId, + res = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, InvalidProgramId, InvalidUserId, SaveDataType.Cache, openReadOnly: false, index: 0); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogName).Append(mountName).Append(LogQuote); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, InvalidProgramId, + res = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, InvalidProgramId, InvalidUserId, SaveDataType.Cache, openReadOnly: false, index: 0); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -380,14 +380,14 @@ public static class SaveData public static Result MountCacheStorage(this FileSystemClient fs, U8Span mountName, int index) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x40]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, InvalidProgramId, + res = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, InvalidProgramId, InvalidUserId, SaveDataType.Cache, openReadOnly: false, (ushort)index); Tick end = fs.Hos.Os.GetSystemTick(); @@ -395,16 +395,16 @@ public static class SaveData sb.Append(LogName).Append(mountName).Append(LogQuote) .Append(LogIndex).AppendFormat(index); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, InvalidProgramId, + res = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, InvalidProgramId, InvalidUserId, SaveDataType.Cache, openReadOnly: false, (ushort)index); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -414,13 +414,13 @@ public static class SaveData public static Result MountCacheStorage(this FileSystemClient fs, U8Span mountName, Ncm.ApplicationId applicationId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x50]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, applicationId, + res = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, applicationId, InvalidUserId, SaveDataType.Cache, openReadOnly: false, index: 0); Tick end = fs.Hos.Os.GetSystemTick(); @@ -428,16 +428,16 @@ public static class SaveData sb.Append(LogName).Append(mountName).Append(LogQuote) .Append(LogApplicationId).AppendFormat(applicationId.Value, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, applicationId, + res = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, applicationId, InvalidUserId, SaveDataType.Cache, openReadOnly: false, index: 0); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -448,13 +448,13 @@ public static class SaveData public static Result MountCacheStorage(this FileSystemClient fs, U8Span mountName, Ncm.ApplicationId applicationId, int index) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x60]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, applicationId, + res = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, applicationId, InvalidUserId, SaveDataType.Cache, openReadOnly: false, (ushort)index); Tick end = fs.Hos.Os.GetSystemTick(); @@ -463,16 +463,16 @@ public static class SaveData .Append(LogApplicationId).AppendFormat(applicationId.Value, 'X') .Append(LogIndex).AppendFormat(index); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, applicationId, + res = MountSaveDataImpl(fs.Impl, mountName, SaveDataSpaceId.User, applicationId, InvalidUserId, SaveDataType.Cache, openReadOnly: false, (ushort)index); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -483,9 +483,9 @@ public static class SaveData public static Result OpenSaveDataInternalStorageFileSystem(this FileSystemClient fs, ref UniqueRef outFileSystem, SaveDataSpaceId spaceId, ulong saveDataId) { - Result rc = OpenSaveDataInternalStorageFileSystemImpl(fs, ref outFileSystem, spaceId, saveDataId); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = OpenSaveDataInternalStorageFileSystemImpl(fs, ref outFileSystem, spaceId, saveDataId); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -493,21 +493,21 @@ public static class SaveData public static Result MountSaveDataInternalStorage(this FileSystemClient fs, U8Span mountName, SaveDataSpaceId spaceId, ulong saveDataId) { - Result rc = Operate(fs, mountName, spaceId, saveDataId); + Result res = Operate(fs, mountName, spaceId, saveDataId); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; static Result Operate(FileSystemClient fs, U8Span mountName, SaveDataSpaceId spaceId, ulong saveDataId) { - Result rc = fs.Impl.CheckMountName(mountName); - if (rc.IsFailure()) return rc.Miss(); + Result res = fs.Impl.CheckMountName(mountName); + if (res.IsFailure()) return res.Miss(); using var fileSystem = new UniqueRef(); - rc = OpenSaveDataInternalStorageFileSystemImpl(fs, ref fileSystem.Ref(), spaceId, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataInternalStorageFileSystemImpl(fs, ref fileSystem.Ref(), spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); return fs.Register(mountName, ref fileSystem.Ref()); } diff --git a/src/LibHac/Fs/Shim/SaveDataForDebug.cs b/src/LibHac/Fs/Shim/SaveDataForDebug.cs index 88353f83..24e775b1 100644 --- a/src/LibHac/Fs/Shim/SaveDataForDebug.cs +++ b/src/LibHac/Fs/Shim/SaveDataForDebug.cs @@ -23,36 +23,36 @@ public static class SaveDataForDebug public static void SetSaveDataRootPath(this FileSystemClient fs, U8Span path) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x300]; if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = SetRootPath(fs, path); + res = SetRootPath(fs, path); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogPath).Append(path).Append(LogQuote); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = SetRootPath(fs, path); + res = SetRootPath(fs, path); } - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnlessSuccess(rc); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnlessSuccess(res); static Result SetRootPath(FileSystemClient fs, U8Span path) { - Result rc = PathUtility.ConvertToFspPath(out FspPath sfPath, path); - if (rc.IsFailure()) return rc.Miss(); + Result res = PathUtility.ConvertToFspPath(out FspPath sfPath, path); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - rc = fileSystemProxy.Get.SetSaveDataRootPath(in sfPath); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystemProxy.Get.SetSaveDataRootPath(in sfPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -60,25 +60,25 @@ public static class SaveDataForDebug public static void UnsetSaveDataRootPath(this FileSystemClient fs) { - Result rc; + Result res; if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - rc = fileSystemProxy.Get.UnsetSaveDataRootPath(); + res = fileSystemProxy.Get.UnsetSaveDataRootPath(); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, null, U8Span.Empty); + fs.Impl.OutputAccessLog(res, start, end, null, U8Span.Empty); } else { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - rc = fileSystemProxy.Get.UnsetSaveDataRootPath(); + res = fileSystemProxy.Get.UnsetSaveDataRootPath(); } - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnlessSuccess(rc); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnlessSuccess(res); } /// @@ -96,27 +96,27 @@ public static class SaveDataForDebug /// : Insufficient permissions. public static Result EnsureSaveDataForDebug(this FileSystemClient fs, long saveDataSize, long saveDataJournalSize) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x60]; if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Ensure(fs, saveDataSize, saveDataJournalSize); + res = Ensure(fs, saveDataSize, saveDataJournalSize); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogSaveDataSize).AppendFormat(saveDataSize, 'd') .Append(LogSaveDataJournalSize).AppendFormat(saveDataJournalSize, 'd'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = Ensure(fs, saveDataSize, saveDataJournalSize); + res = Ensure(fs, saveDataSize, saveDataJournalSize); } - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; @@ -124,9 +124,9 @@ public static class SaveDataForDebug { UserId userIdForDebug = InvalidUserId; - Result rc = fs.Impl.EnsureSaveDataImpl(userIdForDebug, saveDataSize, saveDataJournalSize, + Result res = fs.Impl.EnsureSaveDataImpl(userIdForDebug, saveDataSize, saveDataJournalSize, extendIfNeeded: true); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -146,26 +146,26 @@ public static class SaveDataForDebug /// : Insufficient permissions. public static Result MountSaveDataForDebug(this FileSystemClient fs, U8Span mountName) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x30]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Mount(fs, mountName); + res = Mount(fs, mountName); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogName).Append(mountName).Append(LogQuote); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = Mount(fs, mountName); + res = Mount(fs, mountName); } - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -176,12 +176,12 @@ public static class SaveDataForDebug { UserId userIdForDebug = InvalidUserId; - Result rc = fs.Impl.EnsureSaveDataImpl(userIdForDebug, SaveDataSizeForDebug, SaveDataJournalSizeForDebug, + Result res = fs.Impl.EnsureSaveDataImpl(userIdForDebug, SaveDataSizeForDebug, SaveDataJournalSizeForDebug, extendIfNeeded: false); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); - rc = fs.Impl.MountSaveDataImpl(mountName, userIdForDebug); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Impl.MountSaveDataImpl(mountName, userIdForDebug); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/SaveDataManagement.cs b/src/LibHac/Fs/Shim/SaveDataManagement.cs index 84f77f32..9335570a 100644 --- a/src/LibHac/Fs/Shim/SaveDataManagement.cs +++ b/src/LibHac/Fs/Shim/SaveDataManagement.cs @@ -40,36 +40,36 @@ namespace LibHac.Fs private Result ReadSaveDataInfoImpl(out long readCount, Span buffer) { - Result rc = _reader.Get.Read(out readCount, OutBuffer.FromSpan(buffer)); - if (rc.IsFailure()) return rc.Miss(); + Result res = _reader.Get.Read(out readCount, OutBuffer.FromSpan(buffer)); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public Result ReadSaveDataInfo(out long readCount, Span buffer) { - Result rc; + Result res; FileSystemClient fs = _fsClient; Span logBuffer = stackalloc byte[0x50]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = ReadSaveDataInfoImpl(out readCount, buffer); + res = ReadSaveDataInfoImpl(out readCount, buffer); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogSize).AppendFormat(buffer.Length, 'd'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = ReadSaveDataInfoImpl(out readCount, buffer); + res = ReadSaveDataInfoImpl(out readCount, buffer); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -137,8 +137,8 @@ namespace LibHac.Fs.Shim using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.ReadSaveDataFileSystemExtraData(OutBuffer.FromStruct(ref extraData), saveDataId); - if (rc.IsFailure()) return rc; + Result res = fileSystemProxy.Get.ReadSaveDataFileSystemExtraData(OutBuffer.FromStruct(ref extraData), saveDataId); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -150,9 +150,9 @@ namespace LibHac.Fs.Shim using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.ReadSaveDataFileSystemExtraDataBySaveDataSpaceId( + Result res = fileSystemProxy.Get.ReadSaveDataFileSystemExtraDataBySaveDataSpaceId( OutBuffer.FromStruct(ref extraData), spaceId, saveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -164,9 +164,9 @@ namespace LibHac.Fs.Shim using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.ReadSaveDataFileSystemExtraDataBySaveDataAttribute( + Result res = fileSystemProxy.Get.ReadSaveDataFileSystemExtraDataBySaveDataAttribute( OutBuffer.FromStruct(ref extraData), spaceId, in attribute); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -179,9 +179,9 @@ namespace LibHac.Fs.Shim using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute( + Result res = fileSystemProxy.Get.ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute( OutBuffer.FromStruct(ref extraData), spaceId, in attribute, InBuffer.FromStruct(in extraDataMask)); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -202,10 +202,10 @@ namespace LibHac.Fs.Shim { using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.WriteSaveDataFileSystemExtraData(saveDataId, spaceId, + Result res = fileSystemProxy.Get.WriteSaveDataFileSystemExtraData(saveDataId, spaceId, InBuffer.FromStruct(in extraData)); - fs.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -233,10 +233,10 @@ namespace LibHac.Fs.Shim { using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.WriteSaveDataFileSystemExtraDataWithMask(saveDataId, spaceId, + Result res = fileSystemProxy.Get.WriteSaveDataFileSystemExtraDataWithMask(saveDataId, spaceId, InBuffer.FromStruct(in extraData), InBuffer.FromStruct(in extraDataMask)); - fs.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -267,10 +267,10 @@ namespace LibHac.Fs.Shim { using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.WriteSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(in attribute, + Result res = fileSystemProxy.Get.WriteSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(in attribute, spaceId, InBuffer.FromStruct(in extraData), InBuffer.FromStruct(in extraDataMask)); - fs.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -285,8 +285,8 @@ namespace LibHac.Fs.Shim Unsafe.SkipInit(out SaveDataInfo tempInfo); OutBuffer saveInfoBuffer = OutBuffer.FromStruct(ref tempInfo); - Result rc = fileSystemProxy.Get.FindSaveDataWithFilter(out long count, saveInfoBuffer, spaceId, in filter); - if (rc.IsFailure()) return rc; + Result res = fileSystemProxy.Get.FindSaveDataWithFilter(out long count, saveInfoBuffer, spaceId, in filter); + if (res.IsFailure()) return res.Miss(); if (count == 0) return ResultFs.TargetNotFound.Log(); @@ -300,19 +300,19 @@ namespace LibHac.Fs.Shim { using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Account, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Account, userId, InvalidSystemSaveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = SaveDataCreationInfo.Make(out SaveDataCreationInfo creationInfo, size, journalSize, ownerId, flags, + res = SaveDataCreationInfo.Make(out SaveDataCreationInfo creationInfo, size, journalSize, ownerId, flags, SaveDataSpaceId.User); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); var metaPolicy = new SaveDataMetaPolicy(SaveDataType.Account); metaPolicy.GenerateMetaInfo(out SaveDataMetaInfo metaInfo); - rc = fileSystemProxy.Get.CreateSaveDataFileSystem(in attribute, in creationInfo, in metaInfo); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystemProxy.Get.CreateSaveDataFileSystem(in attribute, in creationInfo, in metaInfo); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -322,14 +322,14 @@ namespace LibHac.Fs.Shim { using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Bcat, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Bcat, InvalidUserId, InvalidSystemSaveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = SaveDataCreationInfo.Make(out SaveDataCreationInfo creationInfo, size, + res = SaveDataCreationInfo.Make(out SaveDataCreationInfo creationInfo, size, SaveDataProperties.BcatSaveDataJournalSize, SystemProgramId.Bcat.Value, SaveDataFlags.None, SaveDataSpaceId.User); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); var metaInfo = new SaveDataMetaInfo { @@ -337,8 +337,8 @@ namespace LibHac.Fs.Shim Size = 0 }; - rc = fileSystemProxy.Get.CreateSaveDataFileSystem(in attribute, in creationInfo, in metaInfo); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystemProxy.Get.CreateSaveDataFileSystem(in attribute, in creationInfo, in metaInfo); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -348,19 +348,19 @@ namespace LibHac.Fs.Shim { using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Device, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Device, InvalidUserId, InvalidSystemSaveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = SaveDataCreationInfo.Make(out SaveDataCreationInfo creationInfo, size, journalSize, ownerId, flags, + res = SaveDataCreationInfo.Make(out SaveDataCreationInfo creationInfo, size, journalSize, ownerId, flags, SaveDataSpaceId.User); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); var metaPolicy = new SaveDataMetaPolicy(SaveDataType.Device); metaPolicy.GenerateMetaInfo(out SaveDataMetaInfo metaInfo); - rc = fileSystemProxy.Get.CreateSaveDataFileSystem(in attribute, in creationInfo, in metaInfo); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystemProxy.Get.CreateSaveDataFileSystem(in attribute, in creationInfo, in metaInfo); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -370,13 +370,13 @@ namespace LibHac.Fs.Shim { using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Cache, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Cache, InvalidUserId, InvalidSystemSaveDataId, index); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = SaveDataCreationInfo.Make(out SaveDataCreationInfo creationInfo, size, journalSize, ownerId, flags, + res = SaveDataCreationInfo.Make(out SaveDataCreationInfo creationInfo, size, journalSize, ownerId, flags, spaceId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); var metaInfo = new SaveDataMetaInfo { @@ -384,8 +384,8 @@ namespace LibHac.Fs.Shim Size = 0 }; - rc = fileSystemProxy.Get.CreateSaveDataFileSystem(in attribute, in creationInfo, in metaInfo); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystemProxy.Get.CreateSaveDataFileSystem(in attribute, in creationInfo, in metaInfo); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -412,38 +412,38 @@ namespace LibHac.Fs.Shim public static Result DeleteSaveData(this FileSystemClient fs, ulong saveDataId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x30]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.DeleteSaveData(saveDataId); + res = fs.Impl.DeleteSaveData(saveDataId); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogSaveDataId).AppendFormat(saveDataId, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.DeleteSaveData(saveDataId); + res = fs.Impl.DeleteSaveData(saveDataId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result DeleteSaveData(this FileSystemClient fs, SaveDataSpaceId spaceId, ulong saveDataId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x50]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.DeleteSaveData(spaceId, saveDataId); + res = fs.Impl.DeleteSaveData(spaceId, saveDataId); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -452,27 +452,27 @@ namespace LibHac.Fs.Shim sb.Append(LogSaveDataSpaceId).Append(idString.ToString(spaceId)) .Append(LogSaveDataId).AppendFormat(saveDataId, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.DeleteSaveData(spaceId, saveDataId); + res = fs.Impl.DeleteSaveData(spaceId, saveDataId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result DeleteSystemSaveData(this FileSystemClient fs, SaveDataSpaceId spaceId, ulong saveDataId, UserId userId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x80]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Delete(fs, spaceId, saveDataId, userId); + res = Delete(fs, spaceId, saveDataId, userId); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -482,23 +482,23 @@ namespace LibHac.Fs.Shim .Append(LogSaveDataId).AppendFormat(saveDataId, 'X') .Append(LogUserId).AppendFormat(userId.Id.High, 'X', 16).AppendFormat(userId.Id.Low, 'X', 16); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = Delete(fs, spaceId, saveDataId, userId); + res = Delete(fs, spaceId, saveDataId, userId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result Delete(FileSystemClient fs, SaveDataSpaceId spaceId, ulong saveDataId, UserId userId) { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, InvalidProgramId, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, InvalidProgramId, SaveDataType.System, userId, saveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return fileSystemProxy.Get.DeleteSaveDataFileSystemBySaveDataAttribute(spaceId, in attribute); } @@ -506,35 +506,35 @@ namespace LibHac.Fs.Shim public static Result DeleteDeviceSaveData(this FileSystemClient fs, ApplicationId applicationId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x30]; if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Delete(fs, applicationId); + res = Delete(fs, applicationId); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogApplicationId).AppendFormat(applicationId.Value, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = Delete(fs, applicationId); + res = Delete(fs, applicationId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result Delete(FileSystemClient fs, ApplicationId applicationId) { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, new ProgramId(applicationId.Value), + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, new ProgramId(applicationId.Value), SaveDataType.Device, InvalidUserId, InvalidSystemSaveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return fileSystemProxy.Get.DeleteSaveDataFileSystemBySaveDataAttribute(SaveDataSpaceId.User, in attribute); } @@ -545,9 +545,9 @@ namespace LibHac.Fs.Shim { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.RegisterSaveDataFileSystemAtomicDeletion(InBuffer.FromSpan(saveDataIdList)); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.RegisterSaveDataFileSystemAtomicDeletion(InBuffer.FromSpan(saveDataIdList)); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -558,8 +558,8 @@ namespace LibHac.Fs.Shim using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); using var reader = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenSaveDataInfoReaderBySaveDataSpaceId(ref reader.Ref(), spaceId); - if (rc.IsFailure()) return rc; + Result res = fileSystemProxy.Get.OpenSaveDataInfoReaderBySaveDataSpaceId(ref reader.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); using var iterator = new UniqueRef(new SaveDataIterator(fs.Fs, ref reader.Ref())); @@ -577,8 +577,8 @@ namespace LibHac.Fs.Shim using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); using var reader = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenSaveDataInfoReaderWithFilter(ref reader.Ref(), spaceId, in filter); - if (rc.IsFailure()) return rc; + Result res = fileSystemProxy.Get.OpenSaveDataInfoReaderWithFilter(ref reader.Ref(), spaceId, in filter); + if (res.IsFailure()) return res.Miss(); using var iterator = new UniqueRef(new SaveDataIterator(fs.Fs, ref reader.Ref())); @@ -593,8 +593,8 @@ namespace LibHac.Fs.Shim public static Result ReadSaveDataIteratorSaveDataInfo(this FileSystemClientImpl fs, out long readCount, Span buffer, ref SaveDataIterator iterator) { - Result rc = iterator.ReadSaveDataInfo(out readCount, buffer); - if (rc.IsFailure()) return rc.Miss(); + Result res = iterator.ReadSaveDataInfo(out readCount, buffer); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -602,94 +602,94 @@ namespace LibHac.Fs.Shim public static Result OpenSaveDataIterator(this FileSystemClient fs, ref UniqueRef outIterator, SaveDataSpaceId spaceId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x50]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.OpenSaveDataIterator(ref outIterator, spaceId); + res = fs.Impl.OpenSaveDataIterator(ref outIterator, spaceId); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogSaveDataSpaceId).Append(idString.ToString(spaceId)); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.OpenSaveDataIterator(ref outIterator, spaceId); + res = fs.Impl.OpenSaveDataIterator(ref outIterator, spaceId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result OpenSaveDataIterator(this FileSystemClient fs, ref UniqueRef outIterator, SaveDataSpaceId spaceId, in SaveDataFilter filter) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x50]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.OpenSaveDataIterator(ref outIterator, spaceId, in filter); + res = fs.Impl.OpenSaveDataIterator(ref outIterator, spaceId, in filter); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogSaveDataSpaceId).Append(idString.ToString(spaceId)); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.OpenSaveDataIterator(ref outIterator, spaceId, in filter); + res = fs.Impl.OpenSaveDataIterator(ref outIterator, spaceId, in filter); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result FindSaveDataWithFilter(this FileSystemClient fs, out SaveDataInfo info, SaveDataSpaceId spaceId, in SaveDataFilter filter) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x50]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.FindSaveDataWithFilter(out info, spaceId, in filter); + res = fs.Impl.FindSaveDataWithFilter(out info, spaceId, in filter); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogSaveDataSpaceId).Append(idString.ToString(spaceId)); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.FindSaveDataWithFilter(out info, spaceId, in filter); + res = fs.Impl.FindSaveDataWithFilter(out info, spaceId, in filter); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result CreateSaveData(this FileSystemClient fs, Ncm.ApplicationId applicationId, UserId userId, ulong ownerId, long size, long journalSize, SaveDataFlags flags) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x100]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.CreateSaveData(applicationId, userId, ownerId, size, journalSize, flags); + res = fs.Impl.CreateSaveData(applicationId, userId, ownerId, size, journalSize, flags); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); @@ -700,27 +700,27 @@ namespace LibHac.Fs.Shim .Append(LogSaveDataJournalSize).AppendFormat(journalSize, 'd') .Append(LogSaveDataFlags).AppendFormat((int)flags, 'X', 8); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.CreateSaveData(applicationId, userId, ownerId, size, journalSize, flags); + res = fs.Impl.CreateSaveData(applicationId, userId, ownerId, size, journalSize, flags); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result CreateSaveData(this FileSystemClient fs, Ncm.ApplicationId applicationId, UserId userId, ulong ownerId, long size, long journalSize, in HashSalt hashSalt, SaveDataFlags flags) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x100]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = CreateSave(fs, applicationId, userId, ownerId, size, journalSize, in hashSalt, flags); + res = CreateSave(fs, applicationId, userId, ownerId, size, journalSize, in hashSalt, flags); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); @@ -731,28 +731,28 @@ namespace LibHac.Fs.Shim .Append(LogSaveDataJournalSize).AppendFormat(journalSize, 'd') .Append(LogSaveDataFlags).AppendFormat((int)flags, 'X', 8); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = CreateSave(fs, applicationId, userId, ownerId, size, journalSize, in hashSalt, flags); + res = CreateSave(fs, applicationId, userId, ownerId, size, journalSize, in hashSalt, flags); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result CreateSave(FileSystemClient fs, Ncm.ApplicationId applicationId, UserId userId, ulong ownerId, long size, long journalSize, in HashSalt hashSalt, SaveDataFlags flags) { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Account, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Account, userId, InvalidSystemSaveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = SaveDataCreationInfo.Make(out SaveDataCreationInfo creationInfo, size, journalSize, ownerId, flags, + res = SaveDataCreationInfo.Make(out SaveDataCreationInfo creationInfo, size, journalSize, ownerId, flags, SaveDataSpaceId.User); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); var metaPolicy = new SaveDataMetaPolicy(SaveDataType.Account); metaPolicy.GenerateMetaInfo(out SaveDataMetaInfo metaInfo); @@ -764,40 +764,40 @@ namespace LibHac.Fs.Shim public static Result CreateBcatSaveData(this FileSystemClient fs, Ncm.ApplicationId applicationId, long size) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x50]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.CreateBcatSaveData(applicationId, size); + res = fs.Impl.CreateBcatSaveData(applicationId, size); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogApplicationId).AppendFormat(applicationId.Value, 'X') .Append(LogSaveDataSize).AppendFormat(size, 'd'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.CreateBcatSaveData(applicationId, size); + res = fs.Impl.CreateBcatSaveData(applicationId, size); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result CreateDeviceSaveData(this FileSystemClient fs, Ncm.ApplicationId applicationId, ulong ownerId, long size, long journalSize, SaveDataFlags flags) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x100]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.CreateDeviceSaveData(applicationId, ownerId, size, journalSize, flags); + res = fs.Impl.CreateDeviceSaveData(applicationId, ownerId, size, journalSize, flags); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); @@ -807,15 +807,15 @@ namespace LibHac.Fs.Shim .Append(LogSaveDataJournalSize).AppendFormat(journalSize, 'd') .Append(LogSaveDataFlags).AppendFormat((int)flags, 'X', 8); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.CreateDeviceSaveData(applicationId, ownerId, size, journalSize, flags); + res = fs.Impl.CreateDeviceSaveData(applicationId, ownerId, size, journalSize, flags); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result CreateTemporaryStorage(this FileSystemClientImpl fs, Ncm.ApplicationId applicationId, @@ -823,13 +823,13 @@ namespace LibHac.Fs.Shim { using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Temporary, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Temporary, InvalidUserId, InvalidSystemSaveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = SaveDataCreationInfo.Make(out SaveDataCreationInfo creationInfo, size, journalSize: 0, ownerId, flags, + res = SaveDataCreationInfo.Make(out SaveDataCreationInfo creationInfo, size, journalSize: 0, ownerId, flags, SaveDataSpaceId.Temporary); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); var metaInfo = new SaveDataMetaInfo { @@ -843,13 +843,13 @@ namespace LibHac.Fs.Shim public static Result CreateTemporaryStorage(this FileSystemClient fs, Ncm.ApplicationId applicationId, ulong ownerId, long size, SaveDataFlags flags) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x100]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.CreateTemporaryStorage(applicationId, ownerId, size, flags); + res = fs.Impl.CreateTemporaryStorage(applicationId, ownerId, size, flags); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); @@ -858,27 +858,27 @@ namespace LibHac.Fs.Shim .Append(LogSaveDataSize).AppendFormat(size, 'd') .Append(LogSaveDataFlags).AppendFormat((int)flags, 'X', 8); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.CreateTemporaryStorage(applicationId, ownerId, size, flags); + res = fs.Impl.CreateTemporaryStorage(applicationId, ownerId, size, flags); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result CreateCacheStorage(this FileSystemClient fs, Ncm.ApplicationId applicationId, SaveDataSpaceId spaceId, ulong ownerId, ushort index, long size, long journalSize, SaveDataFlags flags) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x100]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.CreateCacheStorage(applicationId, spaceId, ownerId, index, size, journalSize, flags); + res = fs.Impl.CreateCacheStorage(applicationId, spaceId, ownerId, index, size, journalSize, flags); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -890,15 +890,15 @@ namespace LibHac.Fs.Shim .Append(LogSaveDataJournalSize).AppendFormat(journalSize, 'd') .Append(LogSaveDataFlags).AppendFormat((int)flags, 'X', 8); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.CreateCacheStorage(applicationId, spaceId, ownerId, index, size, journalSize, flags); + res = fs.Impl.CreateCacheStorage(applicationId, spaceId, ownerId, index, size, journalSize, flags); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result CreateCacheStorage(this FileSystemClient fs, Ncm.ApplicationId applicationId, @@ -916,13 +916,13 @@ namespace LibHac.Fs.Shim public static Result CreateSystemSaveData(this FileSystemClient fs, SaveDataSpaceId spaceId, ulong saveDataId, UserId userId, ulong ownerId, long size, long journalSize, SaveDataFlags flags) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x100]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = CreateSave(fs, spaceId, saveDataId, userId, ownerId, size, journalSize, flags); + res = CreateSave(fs, spaceId, saveDataId, userId, ownerId, size, journalSize, flags); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -935,28 +935,28 @@ namespace LibHac.Fs.Shim .Append(LogSaveDataJournalSize).AppendFormat(journalSize, 'd') .Append(LogSaveDataFlags).AppendFormat((int)flags, 'X', 8); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = CreateSave(fs, spaceId, saveDataId, userId, ownerId, size, journalSize, flags); + res = CreateSave(fs, spaceId, saveDataId, userId, ownerId, size, journalSize, flags); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result CreateSave(FileSystemClient fs, SaveDataSpaceId spaceId, ulong saveDataId, UserId userId, ulong ownerId, long size, long journalSize, SaveDataFlags flags) { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, InvalidProgramId, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, InvalidProgramId, SaveDataType.System, userId, saveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = SaveDataCreationInfo.Make(out SaveDataCreationInfo creationInfo, size, journalSize, ownerId, flags, + res = SaveDataCreationInfo.Make(out SaveDataCreationInfo creationInfo, size, journalSize, ownerId, flags, spaceId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return fileSystemProxy.Get.CreateSaveDataFileSystemBySystemSaveDataId(in attribute, in creationInfo); } @@ -1001,13 +1001,13 @@ namespace LibHac.Fs.Shim using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, InvalidProgramId, SaveDataType.System, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, InvalidProgramId, SaveDataType.System, userId, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); - rc = SaveDataCreationInfo2.Make(out SaveDataCreationInfo2 creationInfo, in attribute, size, journalSize, + res = SaveDataCreationInfo2.Make(out SaveDataCreationInfo2 creationInfo, in attribute, size, journalSize, SaveDataBlockSize, ownerId, flags, spaceId, formatType); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); creationInfo.MetaType = SaveDataMetaType.None; creationInfo.MetaSize = 0; @@ -1018,13 +1018,13 @@ namespace LibHac.Fs.Shim public static Result CreateSystemSaveData(this FileSystemClient fs, SaveDataSpaceId spaceId, ulong saveDataId, ulong ownerId, long size, long journalSize, SaveDataFlags flags, SaveDataFormatType formatType) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x180]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = CreateSystemSaveData(fs.Impl, spaceId, saveDataId, InvalidUserId, ownerId, size, journalSize, + res = CreateSystemSaveData(fs.Impl, spaceId, saveDataId, InvalidUserId, ownerId, size, journalSize, flags, formatType); Tick end = fs.Hos.Os.GetSystemTick(); @@ -1039,16 +1039,16 @@ namespace LibHac.Fs.Shim .Append(LogSaveDataFlags).AppendFormat((int)flags, 'X', 8) .Append(LogSaveDataFormatType).Append(idString.ToString(formatType)); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = CreateSystemSaveData(fs.Impl, spaceId, saveDataId, InvalidUserId, ownerId, size, journalSize, + res = CreateSystemSaveData(fs.Impl, spaceId, saveDataId, InvalidUserId, ownerId, size, journalSize, flags, formatType); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result ExtendSaveData(this FileSystemClientImpl fs, SaveDataSpaceId spaceId, ulong saveDataId, @@ -1062,7 +1062,7 @@ namespace LibHac.Fs.Shim public static Result ExtendSaveData(this FileSystemClient fs, ulong saveDataId, long saveDataSize, long journalSize) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x90]; var spaceId = SaveDataSpaceId.System; @@ -1070,7 +1070,7 @@ namespace LibHac.Fs.Shim if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.ExtendSaveData(spaceId, saveDataId, saveDataSize, journalSize); + res = fs.Impl.ExtendSaveData(spaceId, saveDataId, saveDataSize, journalSize); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -1081,27 +1081,27 @@ namespace LibHac.Fs.Shim .Append(LogSaveDataSize).AppendFormat(saveDataSize, 'd') .Append(LogSaveDataJournalSize).AppendFormat(journalSize, 'd'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.ExtendSaveData(spaceId, saveDataId, saveDataSize, journalSize); + res = fs.Impl.ExtendSaveData(spaceId, saveDataId, saveDataSize, journalSize); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result ExtendSaveData(this FileSystemClient fs, SaveDataSpaceId spaceId, ulong saveDataId, long saveDataSize, long journalSize) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x90]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.ExtendSaveData(spaceId, saveDataId, saveDataSize, journalSize); + res = fs.Impl.ExtendSaveData(spaceId, saveDataId, saveDataSize, journalSize); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -1112,15 +1112,15 @@ namespace LibHac.Fs.Shim .Append(LogSaveDataSize).AppendFormat(saveDataSize, 'd') .Append(LogSaveDataJournalSize).AppendFormat(journalSize, 'd'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.ExtendSaveData(spaceId, saveDataId, saveDataSize, journalSize); + res = fs.Impl.ExtendSaveData(spaceId, saveDataId, saveDataSize, journalSize); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result QuerySaveDataTotalSize(this FileSystemClientImpl fs, out long totalSize, long saveDataSize, @@ -1130,9 +1130,9 @@ namespace LibHac.Fs.Shim using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.QuerySaveDataTotalSize(out long tempTotalSize, saveDataSize, + Result res = fileSystemProxy.Get.QuerySaveDataTotalSize(out long tempTotalSize, saveDataSize, saveDataJournalSize); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); totalSize = tempTotalSize; return Result.Success; @@ -1141,39 +1141,39 @@ namespace LibHac.Fs.Shim public static Result QuerySaveDataTotalSize(this FileSystemClient fs, out long totalSize, long saveDataSize, long saveDataJournalSize) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x50]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.QuerySaveDataTotalSize(out totalSize, saveDataSize, saveDataJournalSize); + res = fs.Impl.QuerySaveDataTotalSize(out totalSize, saveDataSize, saveDataJournalSize); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogSaveDataSize).AppendFormat(saveDataSize, 'd') .Append(LogSaveDataJournalSize).AppendFormat(saveDataJournalSize, 'd'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.QuerySaveDataTotalSize(out totalSize, saveDataSize, saveDataJournalSize); + res = fs.Impl.QuerySaveDataTotalSize(out totalSize, saveDataSize, saveDataJournalSize); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result GetSaveDataOwnerId(this FileSystemClient fs, out ulong ownerId, ulong saveDataId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x40]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = GetOwnerId(fs, out ownerId, saveDataId); + res = GetOwnerId(fs, out ownerId, saveDataId); Tick end = fs.Hos.Os.GetSystemTick(); // Note: Nintendo accidentally uses ", save_data_size: %ld" instead of ", savedataid: 0x%lX" @@ -1181,22 +1181,22 @@ namespace LibHac.Fs.Shim var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogSaveDataId).AppendFormat(saveDataId, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = GetOwnerId(fs, out ownerId, saveDataId); + res = GetOwnerId(fs, out ownerId, saveDataId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result GetOwnerId(FileSystemClient fs, out ulong ownerId, ulong saveDataId) { UnsafeHelpers.SkipParamInit(out ownerId); - Result rc = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, saveDataId); - if (rc.IsFailure()) return rc; + Result res = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, saveDataId); + if (res.IsFailure()) return res.Miss(); ownerId = extraData.OwnerId; return Result.Success; @@ -1206,13 +1206,13 @@ namespace LibHac.Fs.Shim public static Result GetSaveDataOwnerId(this FileSystemClient fs, out ulong ownerId, SaveDataSpaceId spaceId, ulong saveDataId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x50]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = GetOwnerId(fs, out ownerId, spaceId, saveDataId); + res = GetOwnerId(fs, out ownerId, spaceId, saveDataId); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -1221,23 +1221,23 @@ namespace LibHac.Fs.Shim sb.Append(LogSaveDataSpaceId).Append(idString.ToString(spaceId)) .Append(LogSaveDataId).AppendFormat(saveDataId, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = GetOwnerId(fs, out ownerId, spaceId, saveDataId); + res = GetOwnerId(fs, out ownerId, spaceId, saveDataId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result GetOwnerId(FileSystemClient fs, out ulong ownerId, SaveDataSpaceId spaceId, ulong saveDataId) { UnsafeHelpers.SkipParamInit(out ownerId); - Result rc = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, + Result res = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, saveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); ownerId = extraData.OwnerId; return Result.Success; @@ -1246,34 +1246,34 @@ namespace LibHac.Fs.Shim public static Result GetSaveDataFlags(this FileSystemClient fs, out SaveDataFlags flags, ulong saveDataId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x40]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = GetFlags(fs, out flags, saveDataId); + res = GetFlags(fs, out flags, saveDataId); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogSaveDataId).AppendFormat(saveDataId, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = GetFlags(fs, out flags, saveDataId); + res = GetFlags(fs, out flags, saveDataId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result GetFlags(FileSystemClient fs, out SaveDataFlags flags, ulong saveDataId) { UnsafeHelpers.SkipParamInit(out flags); - Result rc = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, saveDataId); - if (rc.IsFailure()) return rc; + Result res = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, saveDataId); + if (res.IsFailure()) return res.Miss(); flags = extraData.Flags; return Result.Success; @@ -1283,13 +1283,13 @@ namespace LibHac.Fs.Shim public static Result GetSaveDataFlags(this FileSystemClient fs, out SaveDataFlags flags, SaveDataSpaceId spaceId, ulong saveDataId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x50]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = GetFlags(fs, out flags, spaceId, saveDataId); + res = GetFlags(fs, out flags, spaceId, saveDataId); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -1298,24 +1298,24 @@ namespace LibHac.Fs.Shim sb.Append(LogSaveDataSpaceId).Append(idString.ToString(spaceId)) .Append(LogSaveDataId).AppendFormat(saveDataId, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = GetFlags(fs, out flags, spaceId, saveDataId); + res = GetFlags(fs, out flags, spaceId, saveDataId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result GetFlags(FileSystemClient fs, out SaveDataFlags flags, SaveDataSpaceId spaceId, ulong saveDataId) { UnsafeHelpers.SkipParamInit(out flags); - Result rc = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, + Result res = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, saveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); flags = extraData.Flags; return Result.Success; @@ -1325,13 +1325,13 @@ namespace LibHac.Fs.Shim public static Result GetSystemSaveDataFlags(this FileSystemClient fs, out SaveDataFlags flags, SaveDataSpaceId spaceId, ulong saveDataId, UserId userId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x80]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = GetFlags(fs, out flags, spaceId, saveDataId, userId); + res = GetFlags(fs, out flags, spaceId, saveDataId, userId); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -1341,27 +1341,27 @@ namespace LibHac.Fs.Shim .Append(LogSaveDataId).AppendFormat(saveDataId, 'X') .Append(LogUserId).AppendFormat(userId.Id.High, 'X', 16).AppendFormat(userId.Id.Low, 'X', 16); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = GetFlags(fs, out flags, spaceId, saveDataId, userId); + res = GetFlags(fs, out flags, spaceId, saveDataId, userId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result GetFlags(FileSystemClient fs, out SaveDataFlags flags, SaveDataSpaceId spaceId, ulong saveDataId, UserId userId) { UnsafeHelpers.SkipParamInit(out flags); - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, InvalidProgramId, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, InvalidProgramId, SaveDataType.System, userId, saveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, in attribute); - if (rc.IsFailure()) return rc; + res = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, in attribute); + if (res.IsFailure()) return res.Miss(); flags = extraData.Flags; return Result.Success; @@ -1376,13 +1376,13 @@ namespace LibHac.Fs.Shim public static Result SetSaveDataFlags(this FileSystemClient fs, ulong saveDataId, SaveDataSpaceId spaceId, SaveDataFlags flags) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x70]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = SetFlags(fs, saveDataId, spaceId, flags); + res = SetFlags(fs, saveDataId, spaceId, flags); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -1392,21 +1392,21 @@ namespace LibHac.Fs.Shim .Append(LogSaveDataSpaceId).Append(idString.ToString(spaceId)) .Append(LogSaveDataFlags).AppendFormat((int)flags, 'X', 8); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = SetFlags(fs, saveDataId, spaceId, flags); + res = SetFlags(fs, saveDataId, spaceId, flags); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result SetFlags(FileSystemClient fs, ulong saveDataId, SaveDataSpaceId spaceId, SaveDataFlags flags) { - Result rc = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, + Result res = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, saveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); extraData.Flags = flags; @@ -1417,13 +1417,13 @@ namespace LibHac.Fs.Shim public static Result SetSystemSaveDataFlags(this FileSystemClient fs, SaveDataSpaceId spaceId, ulong saveDataId, UserId userId, SaveDataFlags flags) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0xA0]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = SetFlags(fs, spaceId, saveDataId, userId, flags); + res = SetFlags(fs, spaceId, saveDataId, userId, flags); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -1434,15 +1434,15 @@ namespace LibHac.Fs.Shim .Append(LogSaveDataSpaceId).Append(idString.ToString(spaceId)) .Append(LogSaveDataFlags).AppendFormat((int)flags, 'X', 8); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = SetFlags(fs, spaceId, saveDataId, userId, flags); + res = SetFlags(fs, spaceId, saveDataId, userId, flags); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result SetFlags(FileSystemClient fs, SaveDataSpaceId spaceId, ulong saveDataId, UserId userId, SaveDataFlags flags) @@ -1453,9 +1453,9 @@ namespace LibHac.Fs.Shim SaveDataExtraData extraData = default; extraData.Flags = flags; - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, InvalidProgramId, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, InvalidProgramId, SaveDataType.System, userId, saveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return fs.Impl.WriteSaveDataFileSystemExtraData(spaceId, in attribute, in extraData, in extraDataMask); } @@ -1463,34 +1463,34 @@ namespace LibHac.Fs.Shim public static Result GetSaveDataTimeStamp(this FileSystemClient fs, out PosixTime timeStamp, ulong saveDataId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x30]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = GetTimeStamp(fs, out timeStamp, saveDataId); + res = GetTimeStamp(fs, out timeStamp, saveDataId); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogSaveDataId).AppendFormat(saveDataId, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = GetTimeStamp(fs, out timeStamp, saveDataId); + res = GetTimeStamp(fs, out timeStamp, saveDataId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result GetTimeStamp(FileSystemClient fs, out PosixTime timeStamp, ulong saveDataId) { UnsafeHelpers.SkipParamInit(out timeStamp); - Result rc = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, saveDataId); - if (rc.IsFailure()) return rc; + Result res = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, saveDataId); + if (res.IsFailure()) return res.Miss(); timeStamp = new PosixTime(extraData.TimeStamp); return Result.Success; @@ -1500,13 +1500,13 @@ namespace LibHac.Fs.Shim public static Result SetSaveDataTimeStamp(this FileSystemClient fs, SaveDataSpaceId spaceId, ulong saveDataId, PosixTime timeStamp) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x80]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = SetTimeStamp(fs, spaceId, saveDataId, timeStamp); + res = SetTimeStamp(fs, spaceId, saveDataId, timeStamp); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -1516,15 +1516,15 @@ namespace LibHac.Fs.Shim .Append(LogSaveDataSpaceId).Append(idString.ToString(spaceId)) .Append(LogSaveDataTimeStamp).AppendFormat(timeStamp.Value, 'd'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = SetTimeStamp(fs, spaceId, saveDataId, timeStamp); + res = SetTimeStamp(fs, spaceId, saveDataId, timeStamp); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result SetTimeStamp(FileSystemClient fs, SaveDataSpaceId spaceId, ulong saveDataId, PosixTime timeStamp) @@ -1542,13 +1542,13 @@ namespace LibHac.Fs.Shim public static Result GetSaveDataTimeStamp(this FileSystemClient fs, out PosixTime timeStamp, SaveDataSpaceId spaceId, ulong saveDataId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x50]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = GetTimeStamp(fs, out timeStamp, spaceId, saveDataId); + res = GetTimeStamp(fs, out timeStamp, spaceId, saveDataId); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -1557,24 +1557,24 @@ namespace LibHac.Fs.Shim sb.Append(LogSaveDataSpaceId).Append(idString.ToString(spaceId)) .Append(LogSaveDataId).AppendFormat(saveDataId, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = GetTimeStamp(fs, out timeStamp, spaceId, saveDataId); + res = GetTimeStamp(fs, out timeStamp, spaceId, saveDataId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result GetTimeStamp(FileSystemClient fs, out PosixTime timeStamp, SaveDataSpaceId spaceId, ulong saveDataId) { UnsafeHelpers.SkipParamInit(out timeStamp); - Result rc = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, + Result res = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, saveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); timeStamp = new PosixTime(extraData.TimeStamp); return Result.Success; @@ -1586,8 +1586,8 @@ namespace LibHac.Fs.Shim { UnsafeHelpers.SkipParamInit(out availableSize); - Result rc = fs.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, saveDataId); - if (rc.IsFailure()) return rc; + Result res = fs.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, saveDataId); + if (res.IsFailure()) return res.Miss(); availableSize = extraData.DataSize; return Result.Success; @@ -1598,8 +1598,8 @@ namespace LibHac.Fs.Shim { UnsafeHelpers.SkipParamInit(out availableSize); - Result rc = fs.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, saveDataId); - if (rc.IsFailure()) return rc; + Result res = fs.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); availableSize = extraData.DataSize; return Result.Success; @@ -1608,39 +1608,39 @@ namespace LibHac.Fs.Shim public static Result GetSaveDataAvailableSize(this FileSystemClient fs, out long availableSize, ulong saveDataId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x40]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.GetSaveDataAvailableSize(out availableSize, saveDataId); + res = fs.Impl.GetSaveDataAvailableSize(out availableSize, saveDataId); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogSaveDataId).AppendFormat(saveDataId, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.GetSaveDataAvailableSize(out availableSize, saveDataId); + res = fs.Impl.GetSaveDataAvailableSize(out availableSize, saveDataId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result GetSaveDataAvailableSize(this FileSystemClient fs, out long availableSize, SaveDataSpaceId spaceId, ulong saveDataId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x50]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.GetSaveDataAvailableSize(out availableSize, spaceId, saveDataId); + res = fs.Impl.GetSaveDataAvailableSize(out availableSize, spaceId, saveDataId); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -1649,15 +1649,15 @@ namespace LibHac.Fs.Shim sb.Append(LogSaveDataSpaceId).Append(idString.ToString(spaceId)) .Append(LogSaveDataId).AppendFormat(saveDataId, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.GetSaveDataAvailableSize(out availableSize, spaceId, saveDataId); + res = fs.Impl.GetSaveDataAvailableSize(out availableSize, spaceId, saveDataId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result GetSaveDataJournalSize(this FileSystemClientImpl fs, out long journalSize, @@ -1665,8 +1665,8 @@ namespace LibHac.Fs.Shim { UnsafeHelpers.SkipParamInit(out journalSize); - Result rc = fs.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, saveDataId); - if (rc.IsFailure()) return rc; + Result res = fs.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, saveDataId); + if (res.IsFailure()) return res.Miss(); journalSize = extraData.JournalSize; return Result.Success; @@ -1677,8 +1677,8 @@ namespace LibHac.Fs.Shim { UnsafeHelpers.SkipParamInit(out journalSize); - Result rc = fs.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, saveDataId); - if (rc.IsFailure()) return rc; + Result res = fs.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); journalSize = extraData.JournalSize; return Result.Success; @@ -1686,39 +1686,39 @@ namespace LibHac.Fs.Shim public static Result GetSaveDataJournalSize(this FileSystemClient fs, out long journalSize, ulong saveDataId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x40]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.GetSaveDataJournalSize(out journalSize, saveDataId); + res = fs.Impl.GetSaveDataJournalSize(out journalSize, saveDataId); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogSaveDataId).AppendFormat(saveDataId, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.GetSaveDataJournalSize(out journalSize, saveDataId); + res = fs.Impl.GetSaveDataJournalSize(out journalSize, saveDataId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result GetSaveDataJournalSize(this FileSystemClient fs, out long journalSize, SaveDataSpaceId spaceId, ulong saveDataId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x50]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.GetSaveDataJournalSize(out journalSize, spaceId, saveDataId); + res = fs.Impl.GetSaveDataJournalSize(out journalSize, spaceId, saveDataId); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -1727,27 +1727,27 @@ namespace LibHac.Fs.Shim sb.Append(LogSaveDataSpaceId).Append(idString.ToString(spaceId)) .Append(LogSaveDataId).AppendFormat(saveDataId, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.GetSaveDataJournalSize(out journalSize, spaceId, saveDataId); + res = fs.Impl.GetSaveDataJournalSize(out journalSize, spaceId, saveDataId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result GetSaveDataCommitId(this FileSystemClient fs, out long commitId, SaveDataSpaceId spaceId, ulong saveDataId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x50]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = GetCommitId(fs, out commitId, spaceId, saveDataId); + res = GetCommitId(fs, out commitId, spaceId, saveDataId); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -1756,15 +1756,15 @@ namespace LibHac.Fs.Shim sb.Append(LogSaveDataSpaceId).Append(idString.ToString(spaceId)) .Append(LogSaveDataId).AppendFormat(saveDataId, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = GetCommitId(fs, out commitId, spaceId, saveDataId); + res = GetCommitId(fs, out commitId, spaceId, saveDataId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result GetCommitId(FileSystemClient fs, out long commitId, SaveDataSpaceId spaceId, ulong saveDataId) { @@ -1779,13 +1779,13 @@ namespace LibHac.Fs.Shim public static Result SetSaveDataCommitId(this FileSystemClient fs, SaveDataSpaceId spaceId, ulong saveDataId, long commitId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x80]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = SetCommitId(fs, spaceId, saveDataId, commitId); + res = SetCommitId(fs, spaceId, saveDataId, commitId); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -1795,15 +1795,15 @@ namespace LibHac.Fs.Shim .Append(LogSaveDataSpaceId).Append(idString.ToString(spaceId)) .Append(LogSaveDataCommitId).AppendFormat(commitId, 'X', 16); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = SetCommitId(fs, spaceId, saveDataId, commitId); + res = SetCommitId(fs, spaceId, saveDataId, commitId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result SetCommitId(FileSystemClient fs, SaveDataSpaceId spaceId, ulong saveDataId, long commitId) { @@ -1830,13 +1830,13 @@ namespace LibHac.Fs.Shim public static Result QuerySaveDataInternalStorageTotalSize(this FileSystemClient fs, out long size, SaveDataSpaceId spaceId, ulong saveDataId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x50]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System) && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.QuerySaveDataInternalStorageTotalSize(out size, spaceId, saveDataId); + res = fs.Impl.QuerySaveDataInternalStorageTotalSize(out size, spaceId, saveDataId); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -1845,15 +1845,15 @@ namespace LibHac.Fs.Shim sb.Append(LogSaveDataSpaceId).Append(idString.ToString(spaceId)) .Append(LogSaveDataId).AppendFormat(saveDataId, 'X'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.QuerySaveDataInternalStorageTotalSize(out size, spaceId, saveDataId); + res = fs.Impl.QuerySaveDataInternalStorageTotalSize(out size, spaceId, saveDataId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result VerifySaveData(this FileSystemClient fs, out bool isValid, ulong saveDataId, @@ -1869,24 +1869,24 @@ namespace LibHac.Fs.Shim using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.VerifySaveDataFileSystemBySaveDataSpaceId(spaceId, saveDataId, + Result res = fileSystemProxy.Get.VerifySaveDataFileSystemBySaveDataSpaceId(spaceId, saveDataId, new OutBuffer(workBuffer)); - if (ResultFs.DataCorrupted.Includes(rc)) + if (ResultFs.DataCorrupted.Includes(res)) { isValid = false; return Result.Success; } - fs.Impl.AbortIfNeeded(rc); + fs.Impl.AbortIfNeeded(res); - if (rc.IsSuccess()) + if (res.IsSuccess()) { isValid = true; return Result.Success; } - return rc; + return res; } public static Result CorruptSaveDataForDebug(this FileSystemClient fs, ulong saveDataId) @@ -1899,10 +1899,10 @@ namespace LibHac.Fs.Shim { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.CorruptSaveDataFileSystemBySaveDataSpaceId(spaceId, saveDataId); + Result res = fileSystemProxy.Get.CorruptSaveDataFileSystemBySaveDataSpaceId(spaceId, saveDataId); - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result CorruptSaveDataForDebug(this FileSystemClient fs, SaveDataSpaceId spaceId, @@ -1910,45 +1910,45 @@ namespace LibHac.Fs.Shim { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.CorruptSaveDataFileSystemByOffset(spaceId, saveDataId, offset); + Result res = fileSystemProxy.Get.CorruptSaveDataFileSystemByOffset(spaceId, saveDataId, offset); - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static void DisableAutoSaveDataCreation(this FileSystemClient fs) { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.DisableAutoSaveDataCreation(); + Result res = fileSystemProxy.Get.DisableAutoSaveDataCreation(); - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); } public static Result DeleteCacheStorage(this FileSystemClient fs, int index) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x20]; if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Delete(fs, index); + res = Delete(fs, index); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogIndex).AppendFormat(index, 'd'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = Delete(fs, index); + res = Delete(fs, index); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result Delete(FileSystemClient fs, int index) { @@ -1964,30 +1964,30 @@ namespace LibHac.Fs.Shim public static Result GetCacheStorageSize(this FileSystemClient fs, out long saveSize, out long journalSize, int index) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x60]; if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = GetSize(fs, out saveSize, out journalSize, index); + res = GetSize(fs, out saveSize, out journalSize, index); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogIndex).AppendFormat(index, 'd') - .Append(LogSaveDataSize).AppendFormat(AccessLogImpl.DereferenceOutValue(in saveSize, rc), 'd') + .Append(LogSaveDataSize).AppendFormat(AccessLogImpl.DereferenceOutValue(in saveSize, res), 'd') .Append(LogSaveDataJournalSize) - .AppendFormat(AccessLogImpl.DereferenceOutValue(in journalSize, rc), 'd'); + .AppendFormat(AccessLogImpl.DereferenceOutValue(in journalSize, res), 'd'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = GetSize(fs, out saveSize, out journalSize, index); + res = GetSize(fs, out saveSize, out journalSize, index); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result GetSize(FileSystemClient fs, out long saveSize, out long journalSize, int index) { @@ -2007,7 +2007,7 @@ namespace LibHac.Fs.Shim { UnsafeHelpers.SkipParamInit(out handle); - Result rc; + Result res; Span logBuffer = stackalloc byte[0x40]; CacheStorageListCache listCache; @@ -2015,21 +2015,21 @@ namespace LibHac.Fs.Shim if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Open(fs, out listCache); + res = Open(fs, out listCache); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogCacheStorageListHandle).AppendFormat(listCache.GetHashCode(), 'x'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = Open(fs, out listCache); + res = Open(fs, out listCache); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); handle = new CacheStorageListHandle(listCache); return Result.Success; @@ -2039,7 +2039,7 @@ namespace LibHac.Fs.Shim UnsafeHelpers.SkipParamInit(out listCache); CacheStorageListCache tempListCache = null; - Result rc = Utility.DoContinuouslyUntilSaveDataListFetched(fs.Hos, () => + Result res = Utility.DoContinuouslyUntilSaveDataListFetched(fs.Hos, () => { // Note: Nintendo uses the same CacheStorageListCache for every attempt to fetch the save data list // without clearing it between runs. This means that if it has to retry fetching the list, the @@ -2070,7 +2070,7 @@ namespace LibHac.Fs.Shim return Result.Success; }); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); Assert.SdkRequiresNotNull(tempListCache); @@ -2084,29 +2084,29 @@ namespace LibHac.Fs.Shim { UnsafeHelpers.SkipParamInit(out storageInfoReadCount); - Result rc; + Result res; Span logBuffer = stackalloc byte[0x70]; if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Read(out storageInfoReadCount, storageInfoBuffer, handle); + res = Read(out storageInfoReadCount, storageInfoBuffer, handle); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogCacheStorageListHandle).AppendFormat(handle.Cache.GetHashCode(), 'x') .Append(LogInfoBufferCount).AppendFormat(storageInfoBuffer.Length, 'X') - .Append(LogCacheStorageCount).AppendFormat(AccessLogImpl.DereferenceOutValue(in storageInfoReadCount, rc), 'd'); + .Append(LogCacheStorageCount).AppendFormat(AccessLogImpl.DereferenceOutValue(in storageInfoReadCount, res), 'd'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = Read(out storageInfoReadCount, storageInfoBuffer, handle); + res = Read(out storageInfoReadCount, storageInfoBuffer, handle); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; @@ -2159,9 +2159,9 @@ namespace LibHac.Fs.Shim { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.UpdateSaveDataMacForDebug(spaceId, saveDataId); - fs.Impl.AbortIfNeeded(rc); - return rc; + Result res = fileSystemProxy.Get.UpdateSaveDataMacForDebug(spaceId, saveDataId); + fs.Impl.AbortIfNeeded(res); + return res; } public static Result ListApplicationAccessibleSaveDataOwnerId(this FileSystemClient fs, out int readCount, @@ -2178,10 +2178,10 @@ namespace LibHac.Fs.Shim var programId = new ProgramId(applicationId.Value + (uint)programIndex); OutBuffer idOutBuffer = OutBuffer.FromSpan(idBuffer); - Result rc = fileSystemProxy.Get.ListAccessibleSaveDataOwnerId(out readCount, idOutBuffer, programId, startIndex, + Result res = fileSystemProxy.Get.ListAccessibleSaveDataOwnerId(out readCount, idOutBuffer, programId, startIndex, idBuffer.Length); - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; } public static Result GetSaveDataRestoreFlag(this FileSystemClient fs, out bool isRestoreFlagSet, @@ -2189,52 +2189,52 @@ namespace LibHac.Fs.Shim { UnsafeHelpers.SkipParamInit(out isRestoreFlagSet); - Result rc; + Result res; FileSystemAccessor fileSystem; Span logBuffer = stackalloc byte[0x40]; if (fs.Impl.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.Find(out fileSystem, mountName); + res = fs.Impl.Find(out fileSystem, mountName); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogName).Append(mountName).Append(LogQuote); - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = fs.Impl.Find(out fileSystem, mountName); + res = fs.Impl.Find(out fileSystem, mountName); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc; + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog() && fileSystem.IsEnabledAccessLog()) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = GetRestoreFlagValue(fs, out isRestoreFlagSet, fileSystem); + res = GetRestoreFlagValue(fs, out isRestoreFlagSet, fileSystem); Tick end = fs.Hos.Os.GetSystemTick(); ReadOnlySpan isSetString = AccessLogImpl.ConvertFromBoolToAccessLogBooleanValue( - AccessLogImpl.DereferenceOutValue(in isRestoreFlagSet, rc)); + AccessLogImpl.DereferenceOutValue(in isRestoreFlagSet, res)); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogName).Append(mountName).Append(LogQuote) .Append(LogRestoreFlag).Append(isSetString); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = GetRestoreFlagValue(fs, out isRestoreFlagSet, fileSystem); + res = GetRestoreFlagValue(fs, out isRestoreFlagSet, fileSystem); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result GetRestoreFlagValue(FileSystemClient fs, out bool isRestoreFlagSet, FileSystemAccessor fileSystem) @@ -2244,8 +2244,8 @@ namespace LibHac.Fs.Shim if (fileSystem is null) return ResultFs.NullptrArgument.Log(); - Result rc = fileSystem.GetSaveDataAttribute(out SaveDataAttribute attribute); - if (rc.IsFailure()) return rc; + Result res = fileSystem.GetSaveDataAttribute(out SaveDataAttribute attribute); + if (res.IsFailure()) return res.Miss(); if (attribute.ProgramId == InvalidProgramId) attribute.ProgramId = AutoResolveCallerProgramId; @@ -2253,9 +2253,9 @@ namespace LibHac.Fs.Shim SaveDataExtraData extraDataMask = default; extraDataMask.Flags = SaveDataFlags.Restore; - rc = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, SaveDataSpaceId.User, + res = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, SaveDataSpaceId.User, in attribute, in extraDataMask); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); isRestoreFlagSet = extraData.Flags.HasFlag(SaveDataFlags.Restore); return Result.Success; @@ -2265,30 +2265,30 @@ namespace LibHac.Fs.Shim public static Result GetDeviceSaveDataSize(this FileSystemClient fs, out long saveSize, out long journalSize, ApplicationId applicationId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x70]; if (fs.Impl.IsEnabledAccessLog() && fs.Impl.IsEnabledHandleAccessLog(null)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = GetSize(fs, out saveSize, out journalSize, applicationId); + res = GetSize(fs, out saveSize, out journalSize, applicationId); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogApplicationId).AppendFormat(applicationId.Value, 'X') - .Append(LogSaveDataSize).AppendFormat(AccessLogImpl.DereferenceOutValue(in saveSize, rc), 'd') + .Append(LogSaveDataSize).AppendFormat(AccessLogImpl.DereferenceOutValue(in saveSize, res), 'd') .Append(LogSaveDataJournalSize) - .AppendFormat(AccessLogImpl.DereferenceOutValue(in journalSize, rc), 'd'); + .AppendFormat(AccessLogImpl.DereferenceOutValue(in journalSize, res), 'd'); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = GetSize(fs, out saveSize, out journalSize, applicationId); + res = GetSize(fs, out saveSize, out journalSize, applicationId); } - fs.Impl.AbortIfNeeded(rc); - return rc; + fs.Impl.AbortIfNeeded(res); + return res; static Result GetSize(FileSystemClient fs, out long saveSize, out long journalSize, ApplicationId applicationId) @@ -2299,13 +2299,13 @@ namespace LibHac.Fs.Shim extraDataMask.DataSize = unchecked((long)0xFFFFFFFFFFFFFFFF); extraDataMask.JournalSize = unchecked((long)0xFFFFFFFFFFFFFFFF); - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, new ProgramId(applicationId.Value), + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, new ProgramId(applicationId.Value), SaveDataType.Device, InvalidUserId, InvalidSystemSaveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, SaveDataSpaceId.User, + res = fs.Impl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, SaveDataSpaceId.User, in attribute, in extraDataMask); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); saveSize = extraData.DataSize; journalSize = extraData.JournalSize; diff --git a/src/LibHac/Fs/Shim/SaveDataTransferAdapter.cs b/src/LibHac/Fs/Shim/SaveDataTransferAdapter.cs index 2dd57606..5c12022d 100644 --- a/src/LibHac/Fs/Shim/SaveDataTransferAdapter.cs +++ b/src/LibHac/Fs/Shim/SaveDataTransferAdapter.cs @@ -33,25 +33,25 @@ public class SaveDataChunkIterator : ISaveDataChunkIterator public ushort GetId() { - Result rc = _baseInterface.Get.GetId(out uint id); - _fsClient.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + Result res = _baseInterface.Get.GetId(out uint id); + _fsClient.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); return (ushort)id; } public void Next() { - Result rc = _baseInterface.Get.Next(); - _fsClient.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + Result res = _baseInterface.Get.Next(); + _fsClient.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); } public bool IsEnd() { - Result rc = _baseInterface.Get.IsEnd(out bool isEnd); - _fsClient.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + Result res = _baseInterface.Get.IsEnd(out bool isEnd); + _fsClient.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); return isEnd; } @@ -84,11 +84,11 @@ public class SaveDataChunkExporter : ISaveDataChunkExporter { UnsafeHelpers.SkipParamInit(out outPulledSize); - Result rc = _baseInterface.Get.Pull(out ulong pulledSize, new OutBuffer(destination), + Result res = _baseInterface.Get.Pull(out ulong pulledSize, new OutBuffer(destination), (ulong)destination.Length); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outPulledSize = pulledSize; return Result.Success; @@ -96,9 +96,9 @@ public class SaveDataChunkExporter : ISaveDataChunkExporter public long GetRestRawDataSize() { - Result rc = _baseInterface.Get.GetRestRawDataSize(out long restSize); - _fsClient.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + Result res = _baseInterface.Get.GetRestRawDataSize(out long restSize); + _fsClient.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); return restSize; } @@ -129,9 +129,9 @@ public class SaveDataChunkImporter : ISaveDataChunkImporter public Result Push(ReadOnlySpan source) { - Result rc = _baseInterface.Get.Push(new InBuffer(source), (ulong)source.Length); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.Push(new InBuffer(source), (ulong)source.Length); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -163,9 +163,9 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter public Result SetDivisionCount(int divisionCount) { - Result rc = _baseInterface.Get.SetDivisionCount(divisionCount); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.SetDivisionCount(divisionCount); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -174,9 +174,9 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter { using var iteratorObject = new SharedRef(); - Result rc = _baseInterface.Get.OpenSaveDataDiffChunkIterator(ref iteratorObject.Ref()); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.OpenSaveDataDiffChunkIterator(ref iteratorObject.Ref()); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outIterator.Reset(new SaveDataChunkIterator(_fsClient, ref iteratorObject.Ref())); return Result.Success; @@ -186,9 +186,9 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter { using var exporterObject = new SharedRef(); - Result rc = _baseInterface.Get.OpenSaveDataChunkExporter(ref exporterObject.Ref(), chunkId); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.OpenSaveDataChunkExporter(ref exporterObject.Ref(), chunkId); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outExporter.Reset(new SaveDataChunkExporter(_fsClient, ref exporterObject.Ref())); return Result.Success; @@ -198,9 +198,9 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter { UnsafeHelpers.SkipParamInit(out outKeySeed); - Result rc = _baseInterface.Get.GetKeySeed(out KeySeed keySeed); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.GetKeySeed(out KeySeed keySeed); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outKeySeed = keySeed; return Result.Success; @@ -210,9 +210,9 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter { UnsafeHelpers.SkipParamInit(out outInitialDataMac); - Result rc = _baseInterface.Get.GetInitialDataMac(out InitialDataMac initialDataMac); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.GetInitialDataMac(out InitialDataMac initialDataMac); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outInitialDataMac = initialDataMac; return Result.Success; @@ -222,9 +222,9 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter { UnsafeHelpers.SkipParamInit(out outKeyGeneration); - Result rc = _baseInterface.Get.GetInitialDataMacKeyGeneration(out int initialDataMacKeyGeneration); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.GetInitialDataMacKeyGeneration(out int initialDataMacKeyGeneration); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outKeyGeneration = initialDataMacKeyGeneration; return Result.Success; @@ -232,18 +232,18 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter public Result FinalizeExport() { - Result rc = _baseInterface.Get.FinalizeExport(); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.FinalizeExport(); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public Result CancelExport() { - Result rc = _baseInterface.Get.CancelExport(); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.CancelExport(); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -252,9 +252,9 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter { UnsafeHelpers.SkipParamInit(out outContext); - Result rc = _baseInterface.Get.SuspendExport(OutBuffer.FromStruct(ref outContext)); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.SuspendExport(OutBuffer.FromStruct(ref outContext)); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -263,9 +263,9 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter { UnsafeHelpers.SkipParamInit(out outInitialDataAad); - Result rc = _baseInterface.Get.GetImportInitialDataAad(out InitialDataAad initialDataAad); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.GetImportInitialDataAad(out InitialDataAad initialDataAad); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outInitialDataAad = initialDataAad; return Result.Success; @@ -273,9 +273,9 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter public Result SetExportInitialDataAad(in InitialDataAad initialDataAad) { - Result rc = _baseInterface.Get.SetExportInitialDataAad(in initialDataAad); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.SetExportInitialDataAad(in initialDataAad); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -285,9 +285,9 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter UnsafeHelpers.SkipParamInit(out outCommitId); Unsafe.SkipInit(out SaveDataExtraData extraData); - Result rc = _baseInterface.Get.ReadSaveDataExtraData(OutBuffer.FromStruct(ref extraData)); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.ReadSaveDataExtraData(OutBuffer.FromStruct(ref extraData)); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outCommitId = extraData.CommitId; return Result.Success; @@ -298,9 +298,9 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter UnsafeHelpers.SkipParamInit(out outTimeStamp); Unsafe.SkipInit(out SaveDataExtraData extraData); - Result rc = _baseInterface.Get.ReadSaveDataExtraData(OutBuffer.FromStruct(ref extraData)); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.ReadSaveDataExtraData(OutBuffer.FromStruct(ref extraData)); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outTimeStamp = new PosixTime(extraData.TimeStamp); return Result.Success; @@ -308,9 +308,9 @@ public class SaveDataExporterVersion2 : ISaveDataDivisionExporter public Result GetReportInfo(out ExportReportInfo outReportInfo) { - Result rc = _baseInterface.Get.GetReportInfo(out outReportInfo); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.GetReportInfo(out outReportInfo); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -342,36 +342,36 @@ public class SaveDataImporterVersion2 : ISaveDataDivisionImporter public Result InitializeImport(out long remaining, long sizeToProcess) { - Result rc = _baseInterface.Get.InitializeImport(out remaining, sizeToProcess); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.InitializeImport(out remaining, sizeToProcess); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public Result FinalizeImport() { - Result rc = _baseInterface.Get.FinalizeImport(); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.FinalizeImport(); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public Result FinalizeImportWithoutSwap() { - Result rc = _baseInterface.Get.FinalizeImportWithoutSwap(); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.FinalizeImportWithoutSwap(); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public Result CancelImport() { - Result rc = _baseInterface.Get.CancelImport(); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.CancelImport(); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -380,18 +380,18 @@ public class SaveDataImporterVersion2 : ISaveDataDivisionImporter { UnsafeHelpers.SkipParamInit(out outContext); - Result rc = _baseInterface.Get.GetImportContext(OutBuffer.FromStruct(ref outContext)); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.GetImportContext(OutBuffer.FromStruct(ref outContext)); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public Result SuspendImport() { - Result rc = _baseInterface.Get.SuspendImport(); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.SuspendImport(); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -400,9 +400,9 @@ public class SaveDataImporterVersion2 : ISaveDataDivisionImporter { using var iteratorObject = new SharedRef(); - Result rc = _baseInterface.Get.OpenSaveDataDiffChunkIterator(ref iteratorObject.Ref()); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.OpenSaveDataDiffChunkIterator(ref iteratorObject.Ref()); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outIterator.Reset(new SaveDataChunkIterator(_fsClient, ref iteratorObject.Ref())); return Result.Success; @@ -412,9 +412,9 @@ public class SaveDataImporterVersion2 : ISaveDataDivisionImporter { using var importerObject = new SharedRef(); - Result rc = _baseInterface.Get.OpenSaveDataChunkImporter(ref importerObject.Ref(), chunkId); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.OpenSaveDataChunkImporter(ref importerObject.Ref(), chunkId); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outImporter.Reset(new SaveDataChunkImporter(_fsClient, ref importerObject.Ref())); return Result.Success; @@ -424,9 +424,9 @@ public class SaveDataImporterVersion2 : ISaveDataDivisionImporter { UnsafeHelpers.SkipParamInit(out outInitialDataAad); - Result rc = _baseInterface.Get.GetImportInitialDataAad(out InitialDataAad initialDataAad); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.GetImportInitialDataAad(out InitialDataAad initialDataAad); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outInitialDataAad = initialDataAad; return Result.Success; @@ -437,9 +437,9 @@ public class SaveDataImporterVersion2 : ISaveDataDivisionImporter UnsafeHelpers.SkipParamInit(out outCommitId); Unsafe.SkipInit(out SaveDataExtraData extraData); - Result rc = _baseInterface.Get.ReadSaveDataExtraData(OutBuffer.FromStruct(ref extraData)); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.ReadSaveDataExtraData(OutBuffer.FromStruct(ref extraData)); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outCommitId = extraData.CommitId; return Result.Success; @@ -450,9 +450,9 @@ public class SaveDataImporterVersion2 : ISaveDataDivisionImporter UnsafeHelpers.SkipParamInit(out outTimeStamp); Unsafe.SkipInit(out SaveDataExtraData extraData); - Result rc = _baseInterface.Get.ReadSaveDataExtraData(OutBuffer.FromStruct(ref extraData)); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.ReadSaveDataExtraData(OutBuffer.FromStruct(ref extraData)); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outTimeStamp = new PosixTime(extraData.TimeStamp); return Result.Success; @@ -460,9 +460,9 @@ public class SaveDataImporterVersion2 : ISaveDataDivisionImporter public Result GetReportInfo(out ImportReportInfo outReportInfo) { - Result rc = _baseInterface.Get.GetReportInfo(out outReportInfo); - _fsClient.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.GetReportInfo(out outReportInfo); + _fsClient.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/SaveDataTransferVersion2.cs b/src/LibHac/Fs/Shim/SaveDataTransferVersion2.cs index 03d004eb..812fec30 100644 --- a/src/LibHac/Fs/Shim/SaveDataTransferVersion2.cs +++ b/src/LibHac/Fs/Shim/SaveDataTransferVersion2.cs @@ -45,9 +45,9 @@ namespace LibHac.Fs { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.OpenSaveDataTransferManagerVersion2(ref _baseInterface); - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + Result res = fileSystemProxy.Get.OpenSaveDataTransferManagerVersion2(ref _baseInterface); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); _fsClient = fs; } @@ -61,18 +61,18 @@ namespace LibHac.Fs { UnsafeHelpers.SkipParamInit(out outChallenge); - Result rc = _baseInterface.Get.GetChallenge(OutBuffer.FromStruct(ref outChallenge)); - _fsClient.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.GetChallenge(OutBuffer.FromStruct(ref outChallenge)); + _fsClient.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public Result SetKeySeedPackage(in KeySeedPackage keySeedPackage) { - Result rc = _baseInterface.Get.SetKeySeedPackage(InBuffer.FromStruct(in keySeedPackage)); - _fsClient.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.SetKeySeedPackage(InBuffer.FromStruct(in keySeedPackage)); + _fsClient.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -82,9 +82,9 @@ namespace LibHac.Fs { using var exporterInterface = new SharedRef(); - Result rc = _baseInterface.Get.OpenSaveDataExporter(ref exporterInterface.Ref(), spaceId, saveDataId); - _fsClient.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseInterface.Get.OpenSaveDataExporter(ref exporterInterface.Ref(), spaceId, saveDataId); + _fsClient.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); outExporter.Reset(new SaveDataExporterVersion2(_fsClient, ref exporterInterface.Ref())); return Result.Success; @@ -95,11 +95,11 @@ namespace LibHac.Fs { using var exporterInterface = new SharedRef(); - Result rc = _baseInterface.Get.OpenSaveDataExporterForDiffExport(ref exporterInterface.Ref(), + Result res = _baseInterface.Get.OpenSaveDataExporterForDiffExport(ref exporterInterface.Ref(), InBuffer.FromStruct(in initialData), spaceId, saveDataId); - _fsClient.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + _fsClient.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); outExporter.Reset(new SaveDataExporterVersion2(_fsClient, ref exporterInterface.Ref())); return Result.Success; @@ -110,11 +110,11 @@ namespace LibHac.Fs { using var exporterInterface = new SharedRef(); - Result rc = _baseInterface.Get.OpenSaveDataExporterByContext(ref exporterInterface.Ref(), + Result res = _baseInterface.Get.OpenSaveDataExporterByContext(ref exporterInterface.Ref(), InBuffer.FromStruct(in exportContext)); - _fsClient.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + _fsClient.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); outExporter.Reset(new SaveDataExporterVersion2(_fsClient, ref exporterInterface.Ref())); return Result.Success; @@ -125,11 +125,11 @@ namespace LibHac.Fs { using var importerInterface = new SharedRef(); - Result rc = _baseInterface.Get.OpenSaveDataImporterDeprecated(ref importerInterface.Ref(), + Result res = _baseInterface.Get.OpenSaveDataImporterDeprecated(ref importerInterface.Ref(), InBuffer.FromStruct(in initialData), in userId, spaceId); - _fsClient.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + _fsClient.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); outImporter.Reset(new SaveDataImporterVersion2(_fsClient, ref importerInterface.Ref())); return Result.Success; @@ -140,11 +140,11 @@ namespace LibHac.Fs { using var importerInterface = new SharedRef(); - Result rc = _baseInterface.Get.OpenSaveDataImporterForDiffImport(ref importerInterface.Ref(), + Result res = _baseInterface.Get.OpenSaveDataImporterForDiffImport(ref importerInterface.Ref(), InBuffer.FromStruct(in initialData), spaceId, saveDataId); - _fsClient.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + _fsClient.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); outImporter.Reset(new SaveDataImporterVersion2(_fsClient, ref importerInterface.Ref())); return Result.Success; @@ -155,11 +155,11 @@ namespace LibHac.Fs { using var importerInterface = new SharedRef(); - Result rc = _baseInterface.Get.OpenSaveDataImporterForDuplicateDiffImport(ref importerInterface.Ref(), + Result res = _baseInterface.Get.OpenSaveDataImporterForDuplicateDiffImport(ref importerInterface.Ref(), InBuffer.FromStruct(in initialData), spaceId, saveDataId); - _fsClient.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + _fsClient.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); outImporter.Reset(new SaveDataImporterVersion2(_fsClient, ref importerInterface.Ref())); return Result.Success; @@ -170,11 +170,11 @@ namespace LibHac.Fs { using var importerInterface = new SharedRef(); - Result rc = _baseInterface.Get.OpenSaveDataImporter(ref importerInterface.Ref(), + Result res = _baseInterface.Get.OpenSaveDataImporter(ref importerInterface.Ref(), InBuffer.FromStruct(in initialData), in userId, spaceId, useSwap); - _fsClient.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + _fsClient.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); outImporter.Reset(new SaveDataImporterVersion2(_fsClient, ref importerInterface.Ref())); return Result.Success; @@ -191,11 +191,11 @@ namespace LibHac.Fs { using var importerInterface = new SharedRef(); - Result rc = _baseInterface.Get.OpenSaveDataImporterByContext(ref importerInterface.Ref(), + Result res = _baseInterface.Get.OpenSaveDataImporterByContext(ref importerInterface.Ref(), InBuffer.FromStruct(in importContext)); - _fsClient.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + _fsClient.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); outImporter.Reset(new SaveDataImporterVersion2(_fsClient, ref importerInterface.Ref())); return Result.Success; @@ -203,18 +203,18 @@ namespace LibHac.Fs public static SaveDataTag MakeUserAccountSaveDataTag(Ncm.ApplicationId applicationId, in UserId userId) { - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Account, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Account, userId, InvalidSystemSaveDataId, index: 0, SaveDataRank.Primary); - Abort.DoAbortUnless(rc.IsSuccess()); + Abort.DoAbortUnless(res.IsSuccess()); return Unsafe.As(ref attribute); } public static SaveDataTag MakeDeviceSaveDataTag(Ncm.ApplicationId applicationId) { - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Device, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, applicationId, SaveDataType.Device, InvalidUserId, InvalidSystemSaveDataId, index: 0, SaveDataRank.Primary); - Abort.DoAbortUnless(rc.IsSuccess()); + Abort.DoAbortUnless(res.IsSuccess()); return Unsafe.As(ref attribute); } @@ -224,20 +224,20 @@ namespace LibHac.Fs ref readonly SaveDataAttribute attribute = ref Unsafe.As(ref Unsafe.AsRef(in tag)); - Result rc = _baseInterface.Get.CancelSuspendingImportByAttribute(in attribute); + Result res = _baseInterface.Get.CancelSuspendingImportByAttribute(in attribute); - _fsClient.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + _fsClient.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public Result CancelSuspendingImport(Ncm.ApplicationId applicationId, in UserId userId) { - Result rc = _baseInterface.Get.CancelSuspendingImport(applicationId, in userId); + Result res = _baseInterface.Get.CancelSuspendingImport(applicationId, in userId); - _fsClient.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + _fsClient.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -249,10 +249,10 @@ namespace LibHac.Fs ref readonly SaveDataAttribute attribute = ref Unsafe.As(ref Unsafe.AsRef(in tag)); - Result rc = _baseInterface.Get.SwapSecondary(in attribute, doSwap, commitId); + Result res = _baseInterface.Get.SwapSecondary(in attribute, doSwap, commitId); - _fsClient.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + _fsClient.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -294,8 +294,8 @@ namespace LibHac.Fs.Shim using var prohibiter = new SharedRef(); // Todo: Uncomment once opening transfer prohibiters is implemented - // Result rc = fileSystemProxy.Get.OpenSaveDataTransferProhibiter(ref prohibiter.Ref(), applicationId); - // if (rc.IsFailure()) return rc.Miss(); + // Result res = fileSystemProxy.Get.OpenSaveDataTransferProhibiter(ref prohibiter.Ref(), applicationId); + // if (res.IsFailure()) return res.Miss(); outProhibiter.Reset(new SaveDataTransferProhibiterForCloudBackUp(ref prohibiter.Ref())); @@ -305,9 +305,9 @@ namespace LibHac.Fs.Shim public static Result OpenSaveDataTransferProhibiterForCloudBackUp(this FileSystemClient fs, ref UniqueRef outProhibiter, Ncm.ApplicationId applicationId) { - Result rc = fs.Impl.OpenSaveDataTransferProhibiterForCloudBackUp(ref outProhibiter, applicationId); - fs.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fs.Impl.OpenSaveDataTransferProhibiterForCloudBackUp(ref outProhibiter, applicationId); + fs.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -318,11 +318,11 @@ namespace LibHac.Fs.Shim { for (int i = 0; i < applicationIds.Length; i++) { - Result rc = fs.Impl.OpenSaveDataTransferProhibiterForCloudBackUp(ref outProhibiters[i], + Result res = fs.Impl.OpenSaveDataTransferProhibiterForCloudBackUp(ref outProhibiters[i], applicationIds[i]); - fs.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -335,11 +335,11 @@ namespace LibHac.Fs.Shim ulong tempAppId = 0; var programId = new Ncm.ProgramId(applicationId.Value + (uint)programIndex); - Result rc = fileSystemProxy.Get.ListAccessibleSaveDataOwnerId(out outCount, + Result res = fileSystemProxy.Get.ListAccessibleSaveDataOwnerId(out outCount, OutBuffer.FromStruct(ref tempAppId), programId, startIndex: 0, bufferIdCount: 0); - fs.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -351,15 +351,15 @@ namespace LibHac.Fs.Shim using var iterator = new UniqueRef(); // We want to iterate every save with a Secondary rank - Result rc = SaveDataFilter.Make(out SaveDataFilter filter, programId: default, saveType: default, + Result res = SaveDataFilter.Make(out SaveDataFilter filter, programId: default, saveType: default, userId: default, saveDataId: default, index: default, SaveDataRank.Secondary); - fs.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); - rc = fs.Impl.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.User, in filter); - fs.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + res = fs.Impl.OpenSaveDataIterator(ref iterator.Ref(), SaveDataSpaceId.User, in filter); + fs.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); long workSize = 0; @@ -367,11 +367,11 @@ namespace LibHac.Fs.Shim { Unsafe.SkipInit(out SaveDataInfo info); - rc = fs.Impl.ReadSaveDataIteratorSaveDataInfo(out long count, SpanHelpers.AsSpan(ref info), + res = fs.Impl.ReadSaveDataIteratorSaveDataInfo(out long count, SpanHelpers.AsSpan(ref info), ref iterator.Get); - fs.Impl.LogResultErrorMessage(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.LogResultErrorMessage(res); + if (res.IsFailure()) return res.Miss(); // Break once we've iterated all saves if (count == 0) diff --git a/src/LibHac/Fs/Shim/SdCard.cs b/src/LibHac/Fs/Shim/SdCard.cs index 91af5574..d85eaa55 100644 --- a/src/LibHac/Fs/Shim/SdCard.cs +++ b/src/LibHac/Fs/Shim/SdCard.cs @@ -35,16 +35,16 @@ public static class SdCard for (int i = 0; i < maxRetries; i++) { - Result rc = fileSystemProxy.Get.OpenSdCardFileSystem(ref outFileSystem); + Result res = fileSystemProxy.Get.OpenSdCardFileSystem(ref outFileSystem); - if (rc.IsSuccess()) + if (res.IsSuccess()) break; - if (!ResultFs.StorageDeviceNotReady.Includes(rc)) - return rc; + if (!ResultFs.StorageDeviceNotReady.Includes(res)) + return res; if (i == maxRetries - 1) - return rc; + return res; fs.Hos.Os.SleepThread(TimeSpan.FromMilliSeconds(retryInterval)); } @@ -67,29 +67,29 @@ public static class SdCard public static Result MountSdCard(this FileSystemClient fs, U8Span mountName) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x30]; // Check if the mount name is valid if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.CheckMountName(mountName); + res = fs.Impl.CheckMountName(mountName); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogName).Append(mountName); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fs.Impl.CheckMountName(mountName); + res = fs.Impl.CheckMountName(mountName); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); // Open the SD card file system using var fileSystem = new SharedRef(); @@ -97,34 +97,34 @@ public static class SdCard if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = OpenSdCardFileSystem(fs, ref fileSystem.Ref()); + res = OpenSdCardFileSystem(fs, ref fileSystem.Ref()); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = OpenSdCardFileSystem(fs, ref fileSystem.Ref()); + res = OpenSdCardFileSystem(fs, ref fileSystem.Ref()); } - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); // Mount the file system if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = RegisterFileSystem(fs, mountName, ref fileSystem.Ref()); + res = RegisterFileSystem(fs, mountName, ref fileSystem.Ref()); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = RegisterFileSystem(fs, mountName, ref fileSystem.Ref()); + res = RegisterFileSystem(fs, mountName, ref fileSystem.Ref()); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -134,29 +134,29 @@ public static class SdCard public static Result MountSdCardForDebug(this FileSystemClient fs, U8Span mountName) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x30]; // Check if the mount name is valid if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = fs.Impl.CheckMountName(mountName); + res = fs.Impl.CheckMountName(mountName); Tick end = fs.Hos.Os.GetSystemTick(); var sb = new U8StringBuilder(logBuffer, true); sb.Append(LogName).Append(mountName); logBuffer = sb.Buffer; - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = fs.Impl.CheckMountName(mountName); + res = fs.Impl.CheckMountName(mountName); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); // Open the SD card file system using var fileSystem = new SharedRef(); @@ -164,34 +164,34 @@ public static class SdCard if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = OpenSdCardFileSystem(fs, ref fileSystem.Ref()); + res = OpenSdCardFileSystem(fs, ref fileSystem.Ref()); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLogUnlessResultSuccess(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLogUnlessResultSuccess(res, start, end, null, new U8Span(logBuffer)); } else { - rc = OpenSdCardFileSystem(fs, ref fileSystem.Ref()); + res = OpenSdCardFileSystem(fs, ref fileSystem.Ref()); } - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); // Mount the file system if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = RegisterFileSystem(fs, mountName, ref fileSystem.Ref()); + res = RegisterFileSystem(fs, mountName, ref fileSystem.Ref()); Tick end = fs.Hos.Os.GetSystemTick(); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(logBuffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(logBuffer)); } else { - rc = RegisterFileSystem(fs, mountName, ref fileSystem.Ref()); + res = RegisterFileSystem(fs, mountName, ref fileSystem.Ref()); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.Application)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); @@ -204,13 +204,13 @@ public static class SdCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); - rc = CheckIfInserted(fs, ref deviceOperator.Ref(), out bool isInserted); - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + res = CheckIfInserted(fs, ref deviceOperator.Ref(), out bool isInserted); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); return isInserted; @@ -225,16 +225,16 @@ public static class SdCard for (int i = 0; i < maxRetries; i++) { - Result rc = deviceOperator.Get.IsSdCardInserted(out isInserted); + Result res = deviceOperator.Get.IsSdCardInserted(out isInserted); - if (rc.IsSuccess()) + if (res.IsSuccess()) break; - if (!ResultFs.StorageDeviceNotReady.Includes(rc)) - return rc; + if (!ResultFs.StorageDeviceNotReady.Includes(res)) + return res; if (i == maxRetries - 1) - return rc; + return res; fs.Hos.Os.SleepThread(TimeSpan.FromMilliSeconds(retryInterval)); } @@ -250,13 +250,13 @@ public static class SdCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = GetSpeedMode(fs, in deviceOperator, out long speedMode); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = GetSpeedMode(fs, in deviceOperator, out long speedMode); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outMode = (SdCardSpeedMode)speedMode; return Result.Success; @@ -272,16 +272,16 @@ public static class SdCard for (int i = 0; i < maxRetries; i++) { - Result rc = deviceOperator.Get.GetSdCardSpeedMode(out outSpeedMode); + Result res = deviceOperator.Get.GetSdCardSpeedMode(out outSpeedMode); - if (rc.IsSuccess()) + if (res.IsSuccess()) break; - if (!ResultFs.StorageDeviceNotReady.Includes(rc)) - return rc; + if (!ResultFs.StorageDeviceNotReady.Includes(res)) + return res; if (i == maxRetries - 1) - return rc; + return res; fs.Hos.Os.SleepThread(TimeSpan.FromMilliSeconds(retryInterval)); } @@ -295,13 +295,13 @@ public static class SdCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = GetCid(fs, in deviceOperator, outCidBuffer); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = GetCid(fs, in deviceOperator, outCidBuffer); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; @@ -313,16 +313,16 @@ public static class SdCard for (int i = 0; i < maxRetries; i++) { - Result rc = deviceOperator.Get.GetSdCardCid(new OutBuffer(outCidBuffer), outCidBuffer.Length); + Result res = deviceOperator.Get.GetSdCardCid(new OutBuffer(outCidBuffer), outCidBuffer.Length); - if (rc.IsSuccess()) + if (res.IsSuccess()) break; - if (!ResultFs.StorageDeviceNotReady.Includes(rc)) - return rc; + if (!ResultFs.StorageDeviceNotReady.Includes(res)) + return res; if (i == maxRetries - 1) - return rc; + return res; fs.Hos.Os.SleepThread(TimeSpan.FromMilliSeconds(retryInterval)); } @@ -338,13 +338,13 @@ public static class SdCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = GetUserAreaSize(fs, in deviceOperator, out outSize); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = GetUserAreaSize(fs, in deviceOperator, out outSize); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; @@ -359,16 +359,16 @@ public static class SdCard for (int i = 0; i < maxRetries; i++) { - Result rc = deviceOperator.Get.GetSdCardUserAreaSize(out outSize); + Result res = deviceOperator.Get.GetSdCardUserAreaSize(out outSize); - if (rc.IsSuccess()) + if (res.IsSuccess()) break; - if (!ResultFs.StorageDeviceNotReady.Includes(rc)) - return rc; + if (!ResultFs.StorageDeviceNotReady.Includes(res)) + return res; if (i == maxRetries - 1) - return rc; + return res; fs.Hos.Os.SleepThread(TimeSpan.FromMilliSeconds(retryInterval)); } @@ -384,13 +384,13 @@ public static class SdCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = GetProtectedAreaSize(fs, in deviceOperator, out outSize); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = GetProtectedAreaSize(fs, in deviceOperator, out outSize); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; @@ -405,16 +405,16 @@ public static class SdCard for (int i = 0; i < maxRetries; i++) { - Result rc = deviceOperator.Get.GetSdCardProtectedAreaSize(out outSize); + Result res = deviceOperator.Get.GetSdCardProtectedAreaSize(out outSize); - if (rc.IsSuccess()) + if (res.IsSuccess()) break; - if (!ResultFs.StorageDeviceNotReady.Includes(rc)) - return rc; + if (!ResultFs.StorageDeviceNotReady.Includes(res)) + return res; if (i == maxRetries - 1) - return rc; + return res; fs.Hos.Os.SleepThread(TimeSpan.FromMilliSeconds(retryInterval)); } @@ -431,13 +431,13 @@ public static class SdCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = GetErrorInfo(fs, in deviceOperator, out outErrorInfo, out long logSize, logBuffer); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = GetErrorInfo(fs, in deviceOperator, out outErrorInfo, out long logSize, logBuffer); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outLogSize = logSize; return Result.Success; @@ -453,17 +453,17 @@ public static class SdCard for (int i = 0; i < maxRetries; i++) { - Result rc = deviceOperator.Get.GetAndClearSdCardErrorInfo(out outErrorInfo, out outLogSize, + Result res = deviceOperator.Get.GetAndClearSdCardErrorInfo(out outErrorInfo, out outLogSize, new OutBuffer(logBuffer), logBuffer.Length); - if (rc.IsSuccess()) + if (res.IsSuccess()) break; - if (!ResultFs.StorageDeviceNotReady.Includes(rc)) - return rc; + if (!ResultFs.StorageDeviceNotReady.Includes(res)) + return res; if (i == maxRetries - 1) - return rc; + return res; fs.Hos.Os.SleepThread(TimeSpan.FromMilliSeconds(retryInterval)); } @@ -476,9 +476,9 @@ public static class SdCard { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = Format(fs, in fileSystemProxy); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = Format(fs, in fileSystemProxy); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; @@ -490,16 +490,16 @@ public static class SdCard for (int i = 0; i < maxRetries; i++) { - Result rc = fileSystemProxy.Get.FormatSdCardFileSystem(); + Result res = fileSystemProxy.Get.FormatSdCardFileSystem(); - if (rc.IsSuccess()) + if (res.IsSuccess()) break; - if (!ResultFs.StorageDeviceNotReady.Includes(rc)) - return rc; + if (!ResultFs.StorageDeviceNotReady.Includes(res)) + return res; if (i == maxRetries - 1) - return rc; + return res; fs.Hos.Os.SleepThread(TimeSpan.FromMilliSeconds(retryInterval)); } @@ -512,9 +512,9 @@ public static class SdCard { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.FormatSdCardDryRun(); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.FormatSdCardDryRun(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -523,9 +523,9 @@ public static class SdCard { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.IsExFatSupported(out bool isSupported); - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + Result res = fileSystemProxy.Get.IsExFatSupported(out bool isSupported); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); return isSupported; } @@ -534,25 +534,25 @@ public static class SdCard { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.SetSdCardEncryptionSeed(in seed); - fs.Impl.AbortIfNeeded(rc); - return rc; + Result res = fileSystemProxy.Get.SetSdCardEncryptionSeed(in seed); + fs.Impl.AbortIfNeeded(res); + return res; } public static void SetSdCardAccessibility(this FileSystemClient fs, bool isAccessible) { - Result rc = fs.Impl.SetSdCardAccessibility(isAccessible); - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + Result res = fs.Impl.SetSdCardAccessibility(isAccessible); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); } public static bool IsSdCardAccessible(this FileSystemClient fs) { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.IsSdCardAccessible(out bool isAccessible); - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnless(rc.IsSuccess()); + Result res = fileSystemProxy.Get.IsSdCardAccessible(out bool isAccessible); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnless(res.IsSuccess()); return isAccessible; } @@ -569,9 +569,9 @@ public static class SdCard { using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.SimulateDeviceDetectionEvent(SdmmcPort.SdCard, mode, signalEvent); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.SimulateDeviceDetectionEvent(SdmmcPort.SdCard, mode, signalEvent); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -580,10 +580,10 @@ public static class SdCard SimulatingDeviceTargetOperation simulatedOperationType, SimulatingDeviceAccessFailureEventType simulatedFailureType) { - Result rc = SetSdCardSimulationEvent(fs, simulatedOperationType, simulatedFailureType, Result.Success, + Result res = SetSdCardSimulationEvent(fs, simulatedOperationType, simulatedFailureType, Result.Success, autoClearEvent: false); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -592,10 +592,10 @@ public static class SdCard SimulatingDeviceTargetOperation simulatedOperationType, SimulatingDeviceAccessFailureEventType simulatedFailureType, bool autoClearEvent) { - Result rc = SetSdCardSimulationEvent(fs, simulatedOperationType, simulatedFailureType, Result.Success, + Result res = SetSdCardSimulationEvent(fs, simulatedOperationType, simulatedFailureType, Result.Success, autoClearEvent); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -603,10 +603,10 @@ public static class SdCard public static Result SetSdCardSimulationEvent(this FileSystemClient fs, SimulatingDeviceTargetOperation simulatedOperationType, Result failureResult, bool autoClearEvent) { - Result rc = SetSdCardSimulationEvent(fs, simulatedOperationType, + Result res = SetSdCardSimulationEvent(fs, simulatedOperationType, SimulatingDeviceAccessFailureEventType.AccessFailure, failureResult, autoClearEvent); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -616,13 +616,13 @@ public static class SdCard using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.ClearDeviceSimulationEvent((uint)SdmmcPort.SdCard); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.ClearDeviceSimulationEvent((uint)SdmmcPort.SdCard); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -631,8 +631,8 @@ public static class SdCard { using SharedRef fileSystemProxy = fs.GetFileSystemProxyServiceObject(); - Result rc = fileSystemProxy.Get.SetSdCardAccessibility(isAccessible); - fs.AbortIfNeeded(rc); - return rc; + Result res = fileSystemProxy.Get.SetSdCardAccessibility(isAccessible); + fs.AbortIfNeeded(res); + return res; } } \ No newline at end of file diff --git a/src/LibHac/Fs/Shim/SdmmcControl.cs b/src/LibHac/Fs/Shim/SdmmcControl.cs index e92a4b3e..93dc1789 100644 --- a/src/LibHac/Fs/Shim/SdmmcControl.cs +++ b/src/LibHac/Fs/Shim/SdmmcControl.cs @@ -17,12 +17,12 @@ public static class SdmmcControl using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.GetSdmmcConnectionStatus(out int speedMode, out int busWidth, (int)port); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetSdmmcConnectionStatus(out int speedMode, out int busWidth, (int)port); + if (res.IsFailure()) return res.Miss(); outSpeedMode = (SdmmcSpeedMode)speedMode; outBusWidth = (SdmmcBusWidth)busWidth; @@ -35,13 +35,13 @@ public static class SdmmcControl using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.SuspendSdmmcControl(); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.SuspendSdmmcControl(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -51,13 +51,13 @@ public static class SdmmcControl using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.ResumeSdmmcControl(); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.ResumeSdmmcControl(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Fs/Shim/SignedSystemPartition.cs b/src/LibHac/Fs/Shim/SignedSystemPartition.cs index 13a8981e..f39a69ce 100644 --- a/src/LibHac/Fs/Shim/SignedSystemPartition.cs +++ b/src/LibHac/Fs/Shim/SignedSystemPartition.cs @@ -14,35 +14,35 @@ public static class SignedSystemPartition { public static bool IsValidSignedSystemPartitionOnSdCard(this FileSystemClient fs, U8Span path) { - Result rc = fs.Impl.FindFileSystem(out FileSystemAccessor fileSystem, out U8Span _, path); - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnlessSuccess(rc); + Result res = fs.Impl.FindFileSystem(out FileSystemAccessor fileSystem, out U8Span _, path); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnlessSuccess(res); bool isValid = false; - rc = Operate(ref isValid, fileSystem); - fs.Impl.LogResultErrorMessage(rc); - Abort.DoAbortUnlessSuccess(rc); + res = Operate(ref isValid, fileSystem); + fs.Impl.LogResultErrorMessage(res); + Abort.DoAbortUnlessSuccess(res); return isValid; static Result Operate(ref bool isValid, FileSystemAccessor fileSystem) { - Result rc = fileSystem.QueryEntry(SpanHelpers.AsByteSpan(ref isValid), ReadOnlySpan.Empty, + Result res = fileSystem.QueryEntry(SpanHelpers.AsByteSpan(ref isValid), ReadOnlySpan.Empty, QueryId.IsSignedSystemPartition, new U8Span(new[] { (byte)'/' })); - if (rc.IsFailure()) + if (res.IsFailure()) { // Any IFileSystems other than a signed system partition IFileSystem should // return an "UnsupportedOperation" result - if (ResultFs.UnsupportedOperation.Includes(rc)) + if (ResultFs.UnsupportedOperation.Includes(res)) { - rc.Catch(); + res.Catch(); isValid = false; } else { - return rc.Miss(); + return res.Miss(); } } diff --git a/src/LibHac/Fs/Shim/SpeedEmulation.cs b/src/LibHac/Fs/Shim/SpeedEmulation.cs index f0908414..8ddf8244 100644 --- a/src/LibHac/Fs/Shim/SpeedEmulation.cs +++ b/src/LibHac/Fs/Shim/SpeedEmulation.cs @@ -21,13 +21,13 @@ namespace LibHac.Fs.Shim using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.SetSpeedEmulationMode((int)mode); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.SetSpeedEmulationMode((int)mode); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -39,13 +39,13 @@ namespace LibHac.Fs.Shim using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); using var deviceOperator = new SharedRef(); - Result rc = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + Result res = fileSystemProxy.Get.OpenDeviceOperator(ref deviceOperator.Ref()); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); - rc = deviceOperator.Get.GetSpeedEmulationMode(out int mode); - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + res = deviceOperator.Get.GetSpeedEmulationMode(out int mode); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); outMode = (SpeedEmulationMode)mode; diff --git a/src/LibHac/Fs/Shim/SystemSaveData.cs b/src/LibHac/Fs/Shim/SystemSaveData.cs index 753cd229..6f7e5dc8 100644 --- a/src/LibHac/Fs/Shim/SystemSaveData.cs +++ b/src/LibHac/Fs/Shim/SystemSaveData.cs @@ -40,13 +40,13 @@ public static class SystemSaveData public static Result MountSystemSaveData(this FileSystemClient fs, U8Span mountName, SaveDataSpaceId spaceId, ulong saveDataId, UserId userId) { - Result rc; + Result res; Span logBuffer = stackalloc byte[0x90]; if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) { Tick start = fs.Hos.Os.GetSystemTick(); - rc = Mount(fs, mountName, spaceId, saveDataId, userId); + res = Mount(fs, mountName, spaceId, saveDataId, userId); Tick end = fs.Hos.Os.GetSystemTick(); var idString = new IdString(); @@ -56,37 +56,37 @@ public static class SystemSaveData .Append(LogSaveDataId).AppendFormat(saveDataId, 'X') .Append(LogUserId).AppendFormat(userId.Id.High, 'X', 16).AppendFormat(userId.Id.Low, 'X', 16); - fs.Impl.OutputAccessLog(rc, start, end, null, new U8Span(sb.Buffer)); + fs.Impl.OutputAccessLog(res, start, end, null, new U8Span(sb.Buffer)); } else { - rc = Mount(fs, mountName, spaceId, saveDataId, userId); + res = Mount(fs, mountName, spaceId, saveDataId, userId); } - fs.Impl.AbortIfNeeded(rc); - if (rc.IsFailure()) return rc.Miss(); + fs.Impl.AbortIfNeeded(res); + if (res.IsFailure()) return res.Miss(); if (fs.Impl.IsEnabledAccessLog(AccessLogTarget.System)) fs.Impl.EnableFileSystemAccessorAccessLog(mountName); - return rc; + return res; static Result Mount(FileSystemClient fs, U8Span mountName, SaveDataSpaceId spaceId, ulong saveDataId, UserId userId) { - Result rc = fs.Impl.CheckMountName(mountName); - if (rc.IsFailure()) return rc; + Result res = fs.Impl.CheckMountName(mountName); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemProxy = fs.Impl.GetFileSystemProxyServiceObject(); - rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, InvalidProgramId, + res = SaveDataAttribute.Make(out SaveDataAttribute attribute, InvalidProgramId, SaveDataType.System, userId, saveDataId); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); using var fileSystem = new SharedRef(); - rc = fileSystemProxy.Get.OpenSaveDataFileSystemBySystemSaveDataId(ref fileSystem.Ref(), spaceId, in attribute); - if (rc.IsFailure()) return rc; + res = fileSystemProxy.Get.OpenSaveDataFileSystemBySystemSaveDataId(ref fileSystem.Ref(), spaceId, in attribute); + if (res.IsFailure()) return res.Miss(); var fileSystemAdapterRaw = new FileSystemServiceObjectAdapter(ref fileSystem.Ref()); using var fileSystemAdapter = new UniqueRef(fileSystemAdapterRaw); diff --git a/src/LibHac/Fs/SubStorage.cs b/src/LibHac/Fs/SubStorage.cs index bdbb93d3..998524e7 100644 --- a/src/LibHac/Fs/SubStorage.cs +++ b/src/LibHac/Fs/SubStorage.cs @@ -159,11 +159,11 @@ public class SubStorage : IStorage if (!IsValid()) return ResultFs.NotInitialized.Log(); if (destination.Length == 0) return Result.Success; - Result rc = CheckAccessRange(offset, destination.Length, _size); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckAccessRange(offset, destination.Length, _size); + if (res.IsFailure()) return res.Miss(); - rc = BaseStorage.Read(_offset + offset, destination); - if (rc.IsFailure()) return rc.Miss(); + res = BaseStorage.Read(_offset + offset, destination); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -173,11 +173,11 @@ public class SubStorage : IStorage if (!IsValid()) return ResultFs.NotInitialized.Log(); if (source.Length == 0) return Result.Success; - Result rc = CheckAccessRange(offset, source.Length, _size); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckAccessRange(offset, source.Length, _size); + if (res.IsFailure()) return res.Miss(); - rc = BaseStorage.Write(_offset + offset, source); - if (rc.IsFailure()) return rc.Miss(); + res = BaseStorage.Write(_offset + offset, source); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -186,8 +186,8 @@ public class SubStorage : IStorage { if (!IsValid()) return ResultFs.NotInitialized.Log(); - Result rc = BaseStorage.Flush(); - if (rc.IsFailure()) return rc.Miss(); + Result res = BaseStorage.Flush(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -197,11 +197,11 @@ public class SubStorage : IStorage if (!IsValid()) return ResultFs.NotInitialized.Log(); if (!_isResizable) return ResultFs.UnsupportedSetSizeForNotResizableSubStorage.Log(); - Result rc = CheckOffsetAndSize(_offset, size); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckOffsetAndSize(_offset, size); + if (res.IsFailure()) return res.Miss(); - rc = BaseStorage.GetSize(out long currentSize); - if (rc.IsFailure()) return rc; + res = BaseStorage.GetSize(out long currentSize); + if (res.IsFailure()) return res.Miss(); if (currentSize != _offset + _size) { @@ -209,8 +209,8 @@ public class SubStorage : IStorage return ResultFs.UnsupportedSetSizeForResizableSubStorage.Log(); } - rc = BaseStorage.SetSize(_offset + size); - if (rc.IsFailure()) return rc; + res = BaseStorage.SetSize(_offset + size); + if (res.IsFailure()) return res.Miss(); _size = size; @@ -235,8 +235,8 @@ public class SubStorage : IStorage { if (size == 0) return Result.Success; - Result rc = CheckOffsetAndSize(_offset, size); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckOffsetAndSize(_offset, size); + if (res.IsFailure()) return res.Miss(); } return BaseStorage.OperateRange(outBuffer, operationId, _offset + offset, size, inBuffer); diff --git a/src/LibHac/Fs/Utility.cs b/src/LibHac/Fs/Utility.cs index 955c983f..6e6aac09 100644 --- a/src/LibHac/Fs/Utility.cs +++ b/src/LibHac/Fs/Utility.cs @@ -31,16 +31,16 @@ public static class Utility for (int i = 0; i < maxTryCount; i++) { - Result rc = listGetter(); + Result res = listGetter(); - if (rc.IsSuccess()) - return rc; + if (res.IsSuccess()) + return res; // Try again if any save data were added or removed while getting the list - if (!ResultFs.InvalidHandle.Includes(rc)) - return rc.Miss(); + if (!ResultFs.InvalidHandle.Includes(res)) + return res.Miss(); - lastResult = rc; + lastResult = res; hos.Os.SleepThread(TimeSpan.FromMilliSeconds(sleepTime)); sleepTime *= sleepTimeMultiplier; } diff --git a/src/LibHac/Fs/ValueSubStorage.cs b/src/LibHac/Fs/ValueSubStorage.cs index 7cabaf9c..440dad33 100644 --- a/src/LibHac/Fs/ValueSubStorage.cs +++ b/src/LibHac/Fs/ValueSubStorage.cs @@ -112,11 +112,11 @@ public struct ValueSubStorage : IDisposable if (!IsValid()) return ResultFs.NotInitialized.Log(); if (destination.Length == 0) return Result.Success; - Result rc = IStorage.CheckAccessRange(offset, destination.Length, _size); - if (rc.IsFailure()) return rc.Miss(); + Result res = IStorage.CheckAccessRange(offset, destination.Length, _size); + if (res.IsFailure()) return res.Miss(); - rc = _baseStorage.Read(_offset + offset, destination); - if (rc.IsFailure()) return rc.Miss(); + res = _baseStorage.Read(_offset + offset, destination); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -126,11 +126,11 @@ public struct ValueSubStorage : IDisposable if (!IsValid()) return ResultFs.NotInitialized.Log(); if (source.Length == 0) return Result.Success; - Result rc = IStorage.CheckAccessRange(offset, source.Length, _size); - if (rc.IsFailure()) return rc.Miss(); + Result res = IStorage.CheckAccessRange(offset, source.Length, _size); + if (res.IsFailure()) return res.Miss(); - rc = _baseStorage.Write(_offset + offset, source); - if (rc.IsFailure()) return rc.Miss(); + res = _baseStorage.Write(_offset + offset, source); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -139,8 +139,8 @@ public struct ValueSubStorage : IDisposable { if (!IsValid()) return ResultFs.NotInitialized.Log(); - Result rc = _baseStorage.Flush(); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseStorage.Flush(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -150,11 +150,11 @@ public struct ValueSubStorage : IDisposable if (!IsValid()) return ResultFs.NotInitialized.Log(); if (!_isResizable) return ResultFs.UnsupportedSetSizeForNotResizableSubStorage.Log(); - Result rc = IStorage.CheckOffsetAndSize(_offset, size); - if (rc.IsFailure()) return rc; + Result res = IStorage.CheckOffsetAndSize(_offset, size); + if (res.IsFailure()) return res.Miss(); - rc = _baseStorage.GetSize(out long currentSize); - if (rc.IsFailure()) return rc; + res = _baseStorage.GetSize(out long currentSize); + if (res.IsFailure()) return res.Miss(); if (currentSize != _offset + _size) { @@ -162,8 +162,8 @@ public struct ValueSubStorage : IDisposable return ResultFs.UnsupportedSetSizeForResizableSubStorage.Log(); } - rc = _baseStorage.SetSize(_offset + size); - if (rc.IsFailure()) return rc; + res = _baseStorage.SetSize(_offset + size); + if (res.IsFailure()) return res.Miss(); _size = size; @@ -193,8 +193,8 @@ public struct ValueSubStorage : IDisposable { if (size == 0) return Result.Success; - Result rc = IStorage.CheckOffsetAndSize(_offset, size); - if (rc.IsFailure()) return rc.Miss(); + Result res = IStorage.CheckOffsetAndSize(_offset, size); + if (res.IsFailure()) return res.Miss(); } return _baseStorage.OperateRange(outBuffer, operationId, _offset + offset, size, inBuffer); diff --git a/src/LibHac/FsSrv/AccessFailureManagementService.cs b/src/LibHac/FsSrv/AccessFailureManagementService.cs index 3940cc54..1ab17106 100644 --- a/src/LibHac/FsSrv/AccessFailureManagementService.cs +++ b/src/LibHac/FsSrv/AccessFailureManagementService.cs @@ -25,16 +25,16 @@ public readonly struct AccessFailureManagementService public Result OpenAccessFailureDetectionEventNotifier(ref SharedRef outNotifier, ulong processId, bool notifyOnDeepRetry) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.OpenAccessFailureDetectionEventNotifier)) return ResultFs.PermissionDenied.Log(); using var notifier = new UniqueRef(); - rc = _serviceImpl.CreateNotifier(ref notifier.Ref(), processId, notifyOnDeepRetry); - if (rc.IsFailure()) return rc; + res = _serviceImpl.CreateNotifier(ref notifier.Ref(), processId, notifyOnDeepRetry); + if (res.IsFailure()) return res.Miss(); outNotifier.Set(ref notifier.Ref()); return Result.Success; @@ -44,8 +44,8 @@ public readonly struct AccessFailureManagementService { UnsafeHelpers.SkipParamInit(out eventHandle); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.GetAccessFailureDetectionEvent)) return ResultFs.PermissionDenied.Log(); @@ -60,8 +60,8 @@ public readonly struct AccessFailureManagementService { UnsafeHelpers.SkipParamInit(out isDetected); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.IsAccessFailureDetected)) return ResultFs.PermissionDenied.Log(); @@ -72,8 +72,8 @@ public readonly struct AccessFailureManagementService public Result ResolveAccessFailure(ulong processId) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.ResolveAccessFailure)) return ResultFs.PermissionDenied.Log(); @@ -87,8 +87,8 @@ public readonly struct AccessFailureManagementService public Result AbandonAccessFailure(ulong processId) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.AbandonAccessFailure)) return ResultFs.PermissionDenied.Log(); diff --git a/src/LibHac/FsSrv/AccessLogService.cs b/src/LibHac/FsSrv/AccessLogService.cs index 4808ab15..0bc825f9 100644 --- a/src/LibHac/FsSrv/AccessLogService.cs +++ b/src/LibHac/FsSrv/AccessLogService.cs @@ -18,8 +18,8 @@ internal readonly struct AccessLogService public Result SetAccessLogMode(GlobalAccessLogMode mode) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.SetGlobalAccessLogMode)) return ResultFs.PermissionDenied.Log(); @@ -36,8 +36,8 @@ internal readonly struct AccessLogService public Result OutputAccessLogToSdCard(InBuffer textBuffer) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); return _serviceImpl.OutputAccessLogToSdCard(textBuffer.Buffer, programInfo.ProgramIdValue, _processId); } diff --git a/src/LibHac/FsSrv/BaseFileSystemService.cs b/src/LibHac/FsSrv/BaseFileSystemService.cs index 7d322c23..b73fa3a9 100644 --- a/src/LibHac/FsSrv/BaseFileSystemService.cs +++ b/src/LibHac/FsSrv/BaseFileSystemService.cs @@ -35,8 +35,8 @@ public readonly struct BaseFileSystemService private Result CheckCapabilityById(BaseFileSystemId id, ulong processId) { - Result rc = GetProgramInfo(out ProgramInfo programInfo, processId); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo, processId); + if (res.IsFailure()) return res.Miss(); if (id == BaseFileSystemId.TemporaryDirectory) { @@ -60,13 +60,13 @@ public readonly struct BaseFileSystemService public Result OpenBaseFileSystem(ref SharedRef outFileSystem, BaseFileSystemId fileSystemId) { - Result rc = CheckCapabilityById(fileSystemId, _processId); - if (rc.IsFailure()) return rc; + Result res = CheckCapabilityById(fileSystemId, _processId); + if (res.IsFailure()) return res.Miss(); // Open the file system using var fileSystem = new SharedRef(); - rc = _serviceImpl.OpenBaseFileSystem(ref fileSystem.Ref(), fileSystemId); - if (rc.IsFailure()) return rc; + res = _serviceImpl.OpenBaseFileSystem(ref fileSystem.Ref(), fileSystemId); + if (res.IsFailure()) return res.Miss(); // Create an SF adapter for the file system using SharedRef fileSystemAdapter = @@ -79,8 +79,8 @@ public readonly struct BaseFileSystemService public Result FormatBaseFileSystem(BaseFileSystemId fileSystemId) { - Result rc = CheckCapabilityById(fileSystemId, _processId); - if (rc.IsFailure()) return rc; + Result res = CheckCapabilityById(fileSystemId, _processId); + if (res.IsFailure()) return res.Miss(); return _serviceImpl.FormatBaseFileSystem(fileSystemId); } @@ -88,8 +88,8 @@ public readonly struct BaseFileSystemService public Result OpenBisFileSystem(ref SharedRef outFileSystem, in FspPath rootPath, BisPartitionId partitionId) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); // Get the permissions the caller needs AccessibilityType requiredAccess = partitionId switch @@ -117,23 +117,23 @@ public readonly struct BaseFileSystemService // Normalize the path using var pathNormalized = new Path(); - rc = pathNormalized.Initialize(rootPath.Str); - if (rc.IsFailure()) return rc; + res = pathNormalized.Initialize(rootPath.Str); + if (res.IsFailure()) return res.Miss(); var pathFlags = new PathFlags(); pathFlags.AllowEmptyPath(); - rc = pathNormalized.Normalize(pathFlags); - if (rc.IsFailure()) return rc; + res = pathNormalized.Normalize(pathFlags); + if (res.IsFailure()) return res.Miss(); // Open the file system using var fileSystem = new SharedRef(); - rc = _serviceImpl.OpenBisFileSystem(ref fileSystem.Ref(), partitionId, false); - if (rc.IsFailure()) return rc; + res = _serviceImpl.OpenBisFileSystem(ref fileSystem.Ref(), partitionId, false); + if (res.IsFailure()) return res.Miss(); using var subDirFileSystem = new SharedRef(); - rc = Utility.CreateSubDirectoryFileSystem(ref subDirFileSystem.Ref(), ref fileSystem.Ref(), + res = Utility.CreateSubDirectoryFileSystem(ref subDirFileSystem.Ref(), ref fileSystem.Ref(), in pathNormalized); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); // Add all the file system wrappers using var typeSetFileSystem = @@ -162,8 +162,8 @@ public readonly struct BaseFileSystemService return ResultFs.InvalidSize.Log(); // Caller must have the FillBis permission - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.FillBis)) return ResultFs.PermissionDenied.Log(); @@ -174,8 +174,8 @@ public readonly struct BaseFileSystemService public Result DeleteAllPaddingFiles() { // Caller must have the FillBis permission - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.FillBis)) return ResultFs.PermissionDenied.Log(); @@ -186,16 +186,16 @@ public readonly struct BaseFileSystemService public Result OpenGameCardFileSystem(ref SharedRef outFileSystem, GameCardHandle handle, GameCardPartition partitionId) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.GetAccessibilityFor(AccessibilityType.MountGameCard).CanRead) return ResultFs.PermissionDenied.Log(); using var fileSystem = new SharedRef(); - rc = _serviceImpl.OpenGameCardFileSystem(ref fileSystem.Ref(), handle, partitionId); - if (rc.IsFailure()) return rc; + res = _serviceImpl.OpenGameCardFileSystem(ref fileSystem.Ref(), handle, partitionId); + if (res.IsFailure()) return res.Miss(); using var asyncFileSystem = new SharedRef(new AsynchronousAccessFileSystem(ref fileSystem.Ref())); @@ -210,8 +210,8 @@ public readonly struct BaseFileSystemService public Result OpenSdCardFileSystem(ref SharedRef outFileSystem) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); Accessibility accessibility = programInfo.AccessControl.GetAccessibilityFor(AccessibilityType.MountSdCard); @@ -222,8 +222,8 @@ public readonly struct BaseFileSystemService using var scopedContext = new ScopedStorageLayoutTypeSetter(storageFlag); using var fileSystem = new SharedRef(); - rc = _serviceImpl.OpenSdCardProxyFileSystem(ref fileSystem.Ref()); - if (rc.IsFailure()) return rc; + res = _serviceImpl.OpenSdCardProxyFileSystem(ref fileSystem.Ref()); + if (res.IsFailure()) return res.Miss(); // Add all the file system wrappers using var typeSetFileSystem = @@ -243,8 +243,8 @@ public readonly struct BaseFileSystemService public Result FormatSdCardFileSystem() { // Caller must have the FormatSdCard permission - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.FormatSdCard)) return ResultFs.PermissionDenied.Log(); @@ -271,8 +271,8 @@ public readonly struct BaseFileSystemService ImageDirectoryId directoryId) { // Caller must have the MountImageAndVideoStorage permission - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); Accessibility accessibility = programInfo.AccessControl.GetAccessibilityFor(AccessibilityType.MountImageAndVideoStorage); @@ -295,8 +295,8 @@ public readonly struct BaseFileSystemService } using var baseFileSystem = new SharedRef(); - rc = _serviceImpl.OpenBaseFileSystem(ref baseFileSystem.Ref(), fileSystemId); - if (rc.IsFailure()) return rc; + res = _serviceImpl.OpenBaseFileSystem(ref baseFileSystem.Ref(), fileSystemId); + if (res.IsFailure()) return res.Miss(); using SharedRef fileSystemAdapter = FileSystemInterfaceAdapter.CreateShared(ref baseFileSystem.Ref(), false); @@ -310,15 +310,15 @@ public readonly struct BaseFileSystemService ulong transferMemorySize) { // Caller must have the OpenBisWiper permission - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.OpenBisWiper)) return ResultFs.PermissionDenied.Log(); using var bisWiper = new UniqueRef(); - rc = _serviceImpl.OpenBisWiper(ref bisWiper.Ref(), transferMemoryHandle, transferMemorySize); - if (rc.IsFailure()) return rc; + res = _serviceImpl.OpenBisWiper(ref bisWiper.Ref(), transferMemoryHandle, transferMemorySize); + if (res.IsFailure()) return res.Miss(); outBisWiper.Set(ref bisWiper.Ref()); diff --git a/src/LibHac/FsSrv/BaseFileSystemServiceImpl.cs b/src/LibHac/FsSrv/BaseFileSystemServiceImpl.cs index df8a43d7..00c2b71a 100644 --- a/src/LibHac/FsSrv/BaseFileSystemServiceImpl.cs +++ b/src/LibHac/FsSrv/BaseFileSystemServiceImpl.cs @@ -53,8 +53,8 @@ public class BaseFileSystemServiceImpl public Result OpenBisFileSystem(ref SharedRef outFileSystem, BisPartitionId partitionId, bool caseSensitive) { - Result rc = _config.BisFileSystemCreator.Create(ref outFileSystem, partitionId, caseSensitive); - if (rc.IsFailure()) return rc.Miss(); + Result res = _config.BisFileSystemCreator.Create(ref outFileSystem, partitionId, caseSensitive); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -73,17 +73,17 @@ public class BaseFileSystemServiceImpl GameCardPartition partitionId) { const int maxTries = 2; - Result rc = Result.Success; + Result res = Result.Success; for (int i = 0; i < maxTries; i++) { - rc = _config.GameCardFileSystemCreator.Create(ref outFileSystem, handle, partitionId); + res = _config.GameCardFileSystemCreator.Create(ref outFileSystem, handle, partitionId); - if (!ResultFs.DataCorrupted.Includes(rc)) + if (!ResultFs.DataCorrupted.Includes(res)) break; } - return rc; + return res; } public Result OpenSdCardProxyFileSystem(ref SharedRef outFileSystem) diff --git a/src/LibHac/FsSrv/BaseStorageService.cs b/src/LibHac/FsSrv/BaseStorageService.cs index 8f34721b..b3253a51 100644 --- a/src/LibHac/FsSrv/BaseStorageService.cs +++ b/src/LibHac/FsSrv/BaseStorageService.cs @@ -64,11 +64,11 @@ public readonly struct BaseStorageService var storageFlag = StorageLayoutType.Bis; using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(storageFlag); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); - rc = GetAccessibilityForOpenBisPartition(out Accessibility accessibility, programInfo, id); - if (rc.IsFailure()) return rc; + res = GetAccessibilityForOpenBisPartition(out Accessibility accessibility, programInfo, id); + if (res.IsFailure()) return res.Miss(); bool canAccess = accessibility.CanRead && accessibility.CanWrite; @@ -76,8 +76,8 @@ public readonly struct BaseStorageService return ResultFs.PermissionDenied.Log(); using var storage = new SharedRef(); - rc = _serviceImpl.OpenBisStorage(ref storage.Ref(), id); - if (rc.IsFailure()) return rc; + res = _serviceImpl.OpenBisStorage(ref storage.Ref(), id); + if (res.IsFailure()) return res.Miss(); using var typeSetStorage = new SharedRef(new StorageLayoutTypeSetStorage(ref storage.Ref(), storageFlag)); @@ -94,8 +94,8 @@ public readonly struct BaseStorageService public Result InvalidateBisCache() { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.InvalidateBisCache)) return ResultFs.PermissionDenied.Log(); @@ -106,8 +106,8 @@ public readonly struct BaseStorageService public Result OpenGameCardStorage(ref SharedRef outStorage, GameCardHandle handle, GameCardPartitionRaw partitionId) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); Accessibility accessibility = programInfo.AccessControl.GetAccessibilityFor(AccessibilityType.OpenGameCardStorage); @@ -118,8 +118,8 @@ public readonly struct BaseStorageService return ResultFs.PermissionDenied.Log(); using var storage = new SharedRef(); - rc = _serviceImpl.OpenGameCardPartition(ref storage.Ref(), handle, partitionId); - if (rc.IsFailure()) return rc; + res = _serviceImpl.OpenGameCardPartition(ref storage.Ref(), handle, partitionId); + if (res.IsFailure()) return res.Miss(); // Todo: Async storage @@ -133,19 +133,19 @@ public readonly struct BaseStorageService public Result OpenDeviceOperator(ref SharedRef outDeviceOperator) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); - rc = _serviceImpl.OpenDeviceOperator(ref outDeviceOperator, programInfo.AccessControl); - if (rc.IsFailure()) return rc.Miss(); + res = _serviceImpl.OpenDeviceOperator(ref outDeviceOperator, programInfo.AccessControl); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public Result OpenSdCardDetectionEventNotifier(ref SharedRef outEventNotifier) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.OpenSdCardDetectionEventNotifier)) return ResultFs.PermissionDenied.Log(); @@ -155,8 +155,8 @@ public readonly struct BaseStorageService public Result OpenGameCardDetectionEventNotifier(ref SharedRef outEventNotifier) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.OpenGameCardDetectionEventNotifier)) return ResultFs.PermissionDenied.Log(); @@ -166,8 +166,8 @@ public readonly struct BaseStorageService public Result SimulateDeviceDetectionEvent(SdmmcPort port, SimulatingDeviceDetectionMode mode, bool signalEvent) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.SimulateDevice)) return ResultFs.PermissionDenied.Log(); diff --git a/src/LibHac/FsSrv/DebugConfigurationService.cs b/src/LibHac/FsSrv/DebugConfigurationService.cs index 9d10b64f..e86442fd 100644 --- a/src/LibHac/FsSrv/DebugConfigurationService.cs +++ b/src/LibHac/FsSrv/DebugConfigurationService.cs @@ -37,8 +37,8 @@ public struct DebugConfigurationService public Result Register(uint key, long value) { - Result rc = GetProgramInfo(out ProgramInfo programInfo, _processId); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo, _processId); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.SetDebugConfiguration)) return ResultFs.PermissionDenied.Log(); @@ -49,8 +49,8 @@ public struct DebugConfigurationService public Result Unregister(uint key) { - Result rc = GetProgramInfo(out ProgramInfo programInfo, _processId); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo, _processId); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.SetDebugConfiguration)) return ResultFs.PermissionDenied.Log(); diff --git a/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs b/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs index 46872992..cff1f5c4 100644 --- a/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs +++ b/src/LibHac/FsSrv/FileSystemProxyCoreImpl.cs @@ -37,37 +37,37 @@ public class FileSystemProxyCoreImpl if (storageId == CustomStorageId.System) { - Result rc = _baseFileSystemService.OpenBisFileSystem(ref fileSystem.Ref(), BisPartitionId.User); - if (rc.IsFailure()) return rc; + Result res = _baseFileSystemService.OpenBisFileSystem(ref fileSystem.Ref(), BisPartitionId.User); + if (res.IsFailure()) return res.Miss(); using var path = new Path(); - rc = PathFunctions.SetUpFixedPathSingleEntry(ref path.Ref(), pathBuffer.Items, + res = PathFunctions.SetUpFixedPathSingleEntry(ref path.Ref(), pathBuffer.Items, CustomStorage.GetCustomStorageDirectoryName(CustomStorageId.System)); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); using SharedRef tempFs = SharedRef.CreateMove(ref fileSystem.Ref()); - rc = Utility.WrapSubDirectory(ref fileSystem.Ref(), ref tempFs.Ref(), in path, createIfMissing: true); - if (rc.IsFailure()) return rc; + res = Utility.WrapSubDirectory(ref fileSystem.Ref(), ref tempFs.Ref(), in path, createIfMissing: true); + if (res.IsFailure()) return res.Miss(); } else if (storageId == CustomStorageId.SdCard) { - Result rc = _baseFileSystemService.OpenSdCardProxyFileSystem(ref fileSystem.Ref()); - if (rc.IsFailure()) return rc; + Result res = _baseFileSystemService.OpenSdCardProxyFileSystem(ref fileSystem.Ref()); + if (res.IsFailure()) return res.Miss(); using var path = new Path(); - rc = PathFunctions.SetUpFixedPathDoubleEntry(ref path.Ref(), pathBuffer.Items, + res = PathFunctions.SetUpFixedPathDoubleEntry(ref path.Ref(), pathBuffer.Items, CommonPaths.SdCardNintendoRootDirectoryName, CustomStorage.GetCustomStorageDirectoryName(CustomStorageId.System)); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); using SharedRef tempFs = SharedRef.CreateMove(ref fileSystem.Ref()); - rc = Utility.WrapSubDirectory(ref fileSystem.Ref(), ref tempFs.Ref(), in path, createIfMissing: true); - if (rc.IsFailure()) return rc; + res = Utility.WrapSubDirectory(ref fileSystem.Ref(), ref tempFs.Ref(), in path, createIfMissing: true); + if (res.IsFailure()) return res.Miss(); tempFs.SetByMove(ref fileSystem.Ref()); - rc = _fsCreators.EncryptedFileSystemCreator.Create(ref fileSystem.Ref(), ref tempFs.Ref(), + res = _fsCreators.EncryptedFileSystemCreator.Create(ref fileSystem.Ref(), ref tempFs.Ref(), IEncryptedFileSystemCreator.KeyId.CustomStorage, in _sdEncryptionSeed); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); } else { @@ -81,15 +81,15 @@ public class FileSystemProxyCoreImpl private Result OpenHostFileSystem(ref SharedRef outFileSystem, in Path path) { using var pathHost = new Path(); - Result rc = pathHost.Initialize(in path); - if (rc.IsFailure()) return rc; + Result res = pathHost.Initialize(in path); + if (res.IsFailure()) return res.Miss(); - rc = _fsCreators.TargetManagerFileSystemCreator.NormalizeCaseOfPath(out bool isSupported, ref pathHost.Ref()); - if (rc.IsFailure()) return rc; + res = _fsCreators.TargetManagerFileSystemCreator.NormalizeCaseOfPath(out bool isSupported, ref pathHost.Ref()); + if (res.IsFailure()) return res.Miss(); - rc = _fsCreators.TargetManagerFileSystemCreator.Create(ref outFileSystem, in pathHost, isSupported, + res = _fsCreators.TargetManagerFileSystemCreator.Create(ref outFileSystem, in pathHost, isSupported, ensureRootPathExists: false, Result.Success); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -99,14 +99,14 @@ public class FileSystemProxyCoreImpl { if (!path.IsEmpty() && openCaseSensitive) { - Result rc = OpenHostFileSystem(ref outFileSystem, in path); - if (rc.IsFailure()) return rc; + Result res = OpenHostFileSystem(ref outFileSystem, in path); + if (res.IsFailure()) return res.Miss(); } else { - Result rc = _fsCreators.TargetManagerFileSystemCreator.Create(ref outFileSystem, in path, + Result res = _fsCreators.TargetManagerFileSystemCreator.Create(ref outFileSystem, in path, openCaseSensitive, ensureRootPathExists: false, Result.Success); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); } return Result.Success; diff --git a/src/LibHac/FsSrv/FileSystemProxyImpl.cs b/src/LibHac/FsSrv/FileSystemProxyImpl.cs index 51c96bec..ac621710 100644 --- a/src/LibHac/FsSrv/FileSystemProxyImpl.cs +++ b/src/LibHac/FsSrv/FileSystemProxyImpl.cs @@ -156,8 +156,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenFileSystemWithId(ref SharedRef outFileSystem, in FspPath path, ulong id, FileSystemProxyType fsType) { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.OpenFileSystemWithId(ref outFileSystem, in path, id, fsType); } @@ -165,8 +165,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenFileSystemWithPatch(ref SharedRef outFileSystem, ProgramId programId, FileSystemProxyType fsType) { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.OpenFileSystemWithPatch(ref outFileSystem, programId, fsType); } @@ -176,8 +176,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader { UnsafeHelpers.SkipParamInit(out verificationData); - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.OpenCodeFileSystem(ref fileSystem, out verificationData, in path, programId); } @@ -202,16 +202,16 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader { UnsafeHelpers.SkipParamInit(out freeSpaceSize); - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.GetFreeSpaceSizeForSaveData(out freeSpaceSize, spaceId); } public Result OpenDataFileSystemByCurrentProcess(ref SharedRef outFileSystem) { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.OpenDataFileSystemByCurrentProcess(ref outFileSystem); } @@ -219,16 +219,16 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenDataFileSystemByProgramId(ref SharedRef outFileSystem, ProgramId programId) { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.OpenDataFileSystemByProgramId(ref outFileSystem, programId); } public Result OpenDataStorageByCurrentProcess(ref SharedRef outStorage) { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.OpenDataStorageByCurrentProcess(ref outStorage); } @@ -236,8 +236,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenDataStorageByProgramId(ref SharedRef outStorage, ProgramId programId) { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.OpenDataStorageByProgramId(ref outStorage, programId); } @@ -245,8 +245,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenDataStorageByDataId(ref SharedRef outStorage, DataId dataId, StorageId storageId) { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.OpenDataStorageByDataId(ref outStorage, dataId, storageId); } @@ -254,8 +254,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenDataStorageByPath(ref SharedRef outFileSystem, in FspPath path, FileSystemProxyType fsType) { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.OpenDataStorageByPath(ref outFileSystem, in path, fsType); } @@ -268,8 +268,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenDataFileSystemWithProgramIndex(ref SharedRef outFileSystem, byte programIndex) { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.OpenDataFileSystemWithProgramIndex(ref outFileSystem, programIndex); } @@ -277,32 +277,32 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenDataStorageWithProgramIndex(ref SharedRef outStorage, byte programIndex) { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.OpenDataStorageWithProgramIndex(ref outStorage, programIndex); } public Result RegisterSaveDataFileSystemAtomicDeletion(InBuffer saveDataIds) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.RegisterSaveDataFileSystemAtomicDeletion(saveDataIds); } public Result DeleteSaveDataFileSystem(ulong saveDataId) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.DeleteSaveDataFileSystem(saveDataId); } public Result DeleteSaveDataFileSystemBySaveDataSpaceId(SaveDataSpaceId spaceId, ulong saveDataId) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.DeleteSaveDataFileSystemBySaveDataSpaceId(spaceId, saveDataId); } @@ -310,16 +310,16 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result DeleteSaveDataFileSystemBySaveDataAttribute(SaveDataSpaceId spaceId, in SaveDataAttribute attribute) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.DeleteSaveDataFileSystemBySaveDataAttribute(spaceId, in attribute); } public Result UpdateSaveDataMacForDebug(SaveDataSpaceId spaceId, ulong saveDataId) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.UpdateSaveDataMacForDebug(spaceId, saveDataId); } @@ -327,8 +327,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result CreateSaveDataFileSystem(in SaveDataAttribute attribute, in SaveDataCreationInfo creationInfo, in SaveDataMetaInfo metaInfo) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.CreateSaveDataFileSystem(in attribute, in creationInfo, in metaInfo); } @@ -336,8 +336,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result CreateSaveDataFileSystemWithHashSalt(in SaveDataAttribute attribute, in SaveDataCreationInfo creationInfo, in SaveDataMetaInfo metaInfo, in HashSalt hashSalt) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.CreateSaveDataFileSystemWithHashSalt(in attribute, in creationInfo, in metaInfo, in hashSalt); @@ -346,16 +346,16 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result CreateSaveDataFileSystemBySystemSaveDataId(in SaveDataAttribute attribute, in SaveDataCreationInfo creationInfo) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.CreateSaveDataFileSystemBySystemSaveDataId(in attribute, in creationInfo); } public Result CreateSaveDataFileSystemWithCreationInfo2(in SaveDataCreationInfo2 creationInfo) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.CreateSaveDataFileSystemWithCreationInfo2(in creationInfo); } @@ -363,8 +363,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result ExtendSaveDataFileSystem(SaveDataSpaceId spaceId, ulong saveDataId, long dataSize, long journalSize) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.ExtendSaveDataFileSystem(spaceId, saveDataId, dataSize, journalSize); } @@ -372,8 +372,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenSaveDataFileSystem(ref SharedRef outFileSystem, SaveDataSpaceId spaceId, in SaveDataAttribute attribute) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.OpenSaveDataFileSystem(ref outFileSystem, spaceId, in attribute); } @@ -381,8 +381,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenReadOnlySaveDataFileSystem(ref SharedRef outFileSystem, SaveDataSpaceId spaceId, in SaveDataAttribute attribute) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.OpenReadOnlySaveDataFileSystem(ref outFileSystem, spaceId, in attribute); } @@ -390,16 +390,16 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenSaveDataFileSystemBySystemSaveDataId(ref SharedRef outFileSystem, SaveDataSpaceId spaceId, in SaveDataAttribute attribute) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.OpenSaveDataFileSystemBySystemSaveDataId(ref outFileSystem, spaceId, in attribute); } public Result ReadSaveDataFileSystemExtraData(OutBuffer extraDataBuffer, ulong saveDataId) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.ReadSaveDataFileSystemExtraData(extraDataBuffer, saveDataId); } @@ -407,8 +407,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result ReadSaveDataFileSystemExtraDataBySaveDataAttribute(OutBuffer extraDataBuffer, SaveDataSpaceId spaceId, in SaveDataAttribute attribute) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.ReadSaveDataFileSystemExtraDataBySaveDataAttribute(extraDataBuffer, spaceId, in attribute); @@ -417,8 +417,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(OutBuffer extraDataBuffer, SaveDataSpaceId spaceId, in SaveDataAttribute attribute, InBuffer maskBuffer) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(extraDataBuffer, spaceId, in attribute, maskBuffer); @@ -427,8 +427,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result ReadSaveDataFileSystemExtraDataBySaveDataSpaceId(OutBuffer extraDataBuffer, SaveDataSpaceId spaceId, ulong saveDataId) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.ReadSaveDataFileSystemExtraDataBySaveDataSpaceId(extraDataBuffer, spaceId, saveDataId); } @@ -436,8 +436,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result WriteSaveDataFileSystemExtraData(ulong saveDataId, SaveDataSpaceId spaceId, InBuffer extraDataBuffer) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.WriteSaveDataFileSystemExtraData(saveDataId, spaceId, extraDataBuffer); } @@ -445,8 +445,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result WriteSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(in SaveDataAttribute attribute, SaveDataSpaceId spaceId, InBuffer extraDataBuffer, InBuffer maskBuffer) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.WriteSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(in attribute, spaceId, extraDataBuffer, maskBuffer); @@ -455,8 +455,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result WriteSaveDataFileSystemExtraDataWithMask(ulong saveDataId, SaveDataSpaceId spaceId, InBuffer extraDataBuffer, InBuffer maskBuffer) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.WriteSaveDataFileSystemExtraDataWithMask(saveDataId, spaceId, extraDataBuffer, maskBuffer); @@ -502,8 +502,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenHostFileSystemWithOption(ref SharedRef outFileSystem, in FspPath path, MountHostOption option) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); Accessibility accessibility = programInfo.AccessControl.GetAccessibilityFor(AccessibilityType.MountHost); @@ -515,13 +515,13 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader if (path.Str.At(0) == DirectorySeparator && path.Str.At(1) != DirectorySeparator) { - rc = pathNormalized.Initialize(path.Str.Slice(1)); - if (rc.IsFailure()) return rc; + res = pathNormalized.Initialize(path.Str.Slice(1)); + if (res.IsFailure()) return res.Miss(); } else { - rc = pathNormalized.InitializeWithReplaceUnc(path.Str); - if (rc.IsFailure()) return rc; + res = pathNormalized.InitializeWithReplaceUnc(path.Str); + if (res.IsFailure()) return res.Miss(); } var flags = new PathFlags(); @@ -529,13 +529,13 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader flags.AllowRelativePath(); flags.AllowEmptyPath(); - rc = pathNormalized.Normalize(flags); - if (rc.IsFailure()) return rc; + res = pathNormalized.Normalize(flags); + if (res.IsFailure()) return res.Miss(); bool isCaseSensitive = option.Flags.HasFlag(MountHostOptionFlag.PseudoCaseSensitive); - rc = _fsProxyCore.OpenHostFileSystem(ref hostFileSystem.Ref(), in pathNormalized, isCaseSensitive); - if (rc.IsFailure()) return rc; + res = _fsProxyCore.OpenHostFileSystem(ref hostFileSystem.Ref(), in pathNormalized, isCaseSensitive); + if (res.IsFailure()) return res.Miss(); var adapterFlags = new PathFlags(); if (path.Str.At(0) == NullTerminator) @@ -597,24 +597,24 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenSystemDataUpdateEventNotifier(ref SharedRef outEventNotifier) { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.OpenSystemDataUpdateEventNotifier(ref outEventNotifier); } public Result NotifySystemDataUpdateEvent() { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.NotifySystemDataUpdateEvent(); } public Result OpenSaveDataInfoReader(ref SharedRef outInfoReader) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.OpenSaveDataInfoReader(ref outInfoReader); } @@ -622,8 +622,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenSaveDataInfoReaderBySaveDataSpaceId( ref SharedRef outInfoReader, SaveDataSpaceId spaceId) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.OpenSaveDataInfoReaderBySaveDataSpaceId(ref outInfoReader, spaceId); } @@ -631,8 +631,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenSaveDataInfoReaderWithFilter(ref SharedRef outInfoReader, SaveDataSpaceId spaceId, in SaveDataFilter filter) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.OpenSaveDataInfoReaderWithFilter(ref outInfoReader, spaceId, in filter); } @@ -642,8 +642,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader { UnsafeHelpers.SkipParamInit(out count); - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.FindSaveDataWithFilter(out count, saveDataInfoBuffer, spaceId, in filter); } @@ -651,8 +651,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenSaveDataInternalStorageFileSystem(ref SharedRef outFileSystem, SaveDataSpaceId spaceId, ulong saveDataId) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.OpenSaveDataInternalStorageFileSystem(ref outFileSystem, spaceId, saveDataId); } @@ -661,8 +661,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader { UnsafeHelpers.SkipParamInit(out size); - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.QuerySaveDataInternalStorageTotalSize(out size, spaceId, saveDataId); } @@ -671,16 +671,16 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader { UnsafeHelpers.SkipParamInit(out commitId); - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.GetSaveDataCommitId(out commitId, spaceId, saveDataId); } public Result OpenSaveDataInfoReaderOnlyCacheStorage(ref SharedRef outInfoReader) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.OpenSaveDataInfoReaderOnlyCacheStorage(ref outInfoReader); } @@ -688,16 +688,16 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenSaveDataMetaFile(ref SharedRef outFile, SaveDataSpaceId spaceId, in SaveDataAttribute attribute, SaveDataMetaType type) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.OpenSaveDataMetaFile(ref outFile, spaceId, in attribute, type); } public Result DeleteCacheStorage(ushort index) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.DeleteCacheStorage(index); } @@ -706,16 +706,16 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader { UnsafeHelpers.SkipParamInit(out dataSize, out journalSize); - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.GetCacheStorageSize(out dataSize, out journalSize, index); } public Result OpenSaveDataTransferManager(ref SharedRef outTransferManager) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.OpenSaveDataTransferManager(ref outTransferManager); } @@ -723,8 +723,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenSaveDataTransferManagerVersion2( ref SharedRef outTransferManager) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.OpenSaveDataTransferManagerVersion2(ref outTransferManager); } @@ -732,8 +732,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenSaveDataTransferManagerForSaveDataRepair( ref SharedRef outTransferManager) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.OpenSaveDataTransferManagerForSaveDataRepair(ref outTransferManager); } @@ -741,8 +741,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenSaveDataTransferManagerForRepair( ref SharedRef outTransferManager) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.OpenSaveDataTransferManagerForRepair(ref outTransferManager); } @@ -750,8 +750,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenSaveDataTransferProhibiter(ref SharedRef outProhibiter, Ncm.ApplicationId applicationId) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.OpenSaveDataTransferProhibiter(ref outProhibiter, applicationId); } @@ -761,8 +761,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader { UnsafeHelpers.SkipParamInit(out readCount); - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.ListAccessibleSaveDataOwnerId(out readCount, idBuffer, programId, startIndex, bufferIdCount); @@ -771,8 +771,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenSaveDataMover(ref SharedRef outSaveDataMover, SaveDataSpaceId sourceSpaceId, SaveDataSpaceId destinationSpaceId, NativeHandle workBufferHandle, ulong workBufferSize) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.OpenSaveDataMover(ref outSaveDataMover, sourceSpaceId, destinationSpaceId, workBufferHandle, workBufferSize); @@ -785,16 +785,16 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result SetSaveDataRootPath(in FspPath path) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.SetSaveDataRootPath(in path); } public Result UnsetSaveDataRootPath() { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.UnsetSaveDataRootPath(); } @@ -802,8 +802,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenContentStorageFileSystem(ref SharedRef outFileSystem, ContentStorageId storageId) { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.OpenContentStorageFileSystem(ref outFileSystem, storageId); } @@ -814,8 +814,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader var storageFlag = StorageLayoutType.NonGameCard; using var scopedContext = new ScopedStorageLayoutTypeSetter(storageFlag); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); Accessibility accessibility = programInfo.AccessControl.GetAccessibilityFor(AccessibilityType.MountCloudBackupWorkStorage); @@ -824,8 +824,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader return ResultFs.PermissionDenied.Log(); using var fileSystem = new SharedRef(); - rc = _fsProxyCore.OpenCloudBackupWorkStorageFileSystem(ref fileSystem.Ref(), storageId); - if (rc.IsFailure()) return rc; + res = _fsProxyCore.OpenCloudBackupWorkStorageFileSystem(ref fileSystem.Ref(), storageId); + if (res.IsFailure()) return res.Miss(); // Add all the wrappers for the file system using var typeSetFileSystem = @@ -847,8 +847,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader var storageFlag = StorageLayoutType.NonGameCard; using var scopedContext = new ScopedStorageLayoutTypeSetter(storageFlag); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); AccessibilityType accessType = storageId > CustomStorageId.SdCard ? AccessibilityType.NotMount @@ -860,8 +860,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader return ResultFs.PermissionDenied.Log(); using var fileSystem = new SharedRef(); - rc = _fsProxyCore.OpenCustomStorageFileSystem(ref fileSystem.Ref(), storageId); - if (rc.IsFailure()) return rc; + res = _fsProxyCore.OpenCustomStorageFileSystem(ref fileSystem.Ref(), storageId); + if (res.IsFailure()) return res.Miss(); // Add all the file system wrappers using var typeSetFileSystem = @@ -888,8 +888,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader { UnsafeHelpers.SkipParamInit(out isArchived); - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.IsArchivedProgram(out isArchived, processId); } @@ -898,8 +898,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader { UnsafeHelpers.SkipParamInit(out totalSize); - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.QuerySaveDataTotalSize(out totalSize, dataSize, journalSize); } @@ -913,8 +913,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader { UnsafeHelpers.SkipParamInit(out rightsId); - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.GetRightsId(out rightsId, programId, storageId); } @@ -928,55 +928,55 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader { UnsafeHelpers.SkipParamInit(out rightsId, out keyGeneration); - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.GetRightsIdAndKeyGenerationByPath(out rightsId, out keyGeneration, in path); } public Result RegisterExternalKey(in RightsId rightsId, in AccessKey externalKey) { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.RegisterExternalKey(in rightsId, in externalKey); } public Result UnregisterExternalKey(in RightsId rightsId) { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.UnregisterExternalKey(in rightsId); } public Result UnregisterAllExternalKey() { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.UnregisterAllExternalKey(); } public Result SetSdCardEncryptionSeed(in EncryptionSeed seed) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.SetEncryptionSeed)) return ResultFs.PermissionDenied.Log(); - rc = _fsProxyCore.SetSdCardEncryptionSeed(in seed); - if (rc.IsFailure()) return rc; + res = _fsProxyCore.SetSdCardEncryptionSeed(in seed); + if (res.IsFailure()) return res.Miss(); - rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); - rc = saveFsService.SetSdCardEncryptionSeed(in seed); - if (rc.IsFailure()) return rc; + res = saveFsService.SetSdCardEncryptionSeed(in seed); + if (res.IsFailure()) return res.Miss(); - rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.SetSdCardEncryptionSeed(in seed); } @@ -1000,8 +1000,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result VerifySaveDataFileSystemBySaveDataSpaceId(SaveDataSpaceId spaceId, ulong saveDataId, OutBuffer readBuffer) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.VerifySaveDataFileSystemBySaveDataSpaceId(spaceId, saveDataId, readBuffer); } @@ -1013,8 +1013,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result CorruptSaveDataFileSystemByOffset(SaveDataSpaceId spaceId, ulong saveDataId, long offset) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.CorruptSaveDataFileSystemByOffset(spaceId, saveDataId, offset); } @@ -1022,8 +1022,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result CorruptSaveDataFileSystemBySaveDataSpaceId(SaveDataSpaceId spaceId, ulong saveDataId) { // Corrupt both of the save data headers - Result rc = CorruptSaveDataFileSystemByOffset(spaceId, saveDataId, 0); - if (rc.IsFailure()) return rc; + Result res = CorruptSaveDataFileSystemByOffset(spaceId, saveDataId, 0); + if (res.IsFailure()) return res.Miss(); return CorruptSaveDataFileSystemByOffset(spaceId, saveDataId, 0x4000); } @@ -1085,16 +1085,16 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result RegisterUpdatePartition() { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.RegisterUpdatePartition(); } public Result OpenRegisteredUpdatePartition(ref SharedRef outFileSystem) { - Result rc = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); - if (rc.IsFailure()) return rc; + Result res = GetNcaFileSystemService(out NcaFileSystemService ncaFsService); + if (res.IsFailure()) return res.Miss(); return ncaFsService.OpenRegisteredUpdatePartition(ref outFileSystem); } @@ -1111,16 +1111,16 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OverrideSaveDataTransferTokenSignVerificationKey(InBuffer key) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.OverrideSaveDataTransferTokenSignVerificationKey(key); } public Result SetSdCardAccessibility(bool isAccessible) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.SetSdCardAccessibility(isAccessible); } @@ -1129,8 +1129,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader { UnsafeHelpers.SkipParamInit(out isAccessible); - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.IsSdCardAccessible(out isAccessible); } @@ -1164,8 +1164,8 @@ public class FileSystemProxyImpl : IFileSystemProxy, IFileSystemProxyForLoader public Result OpenMultiCommitManager(ref SharedRef outCommitManager) { - Result rc = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); - if (rc.IsFailure()) return rc; + Result res = GetSaveDataFileSystemService(out SaveDataFileSystemService saveFsService); + if (res.IsFailure()) return res.Miss(); return saveFsService.OpenMultiCommitManager(ref outCommitManager); } diff --git a/src/LibHac/FsSrv/FsCreator/EmulatedBisFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/EmulatedBisFileSystemCreator.cs index 368d66ff..43c5bf34 100644 --- a/src/LibHac/FsSrv/FsCreator/EmulatedBisFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/EmulatedBisFileSystemCreator.cs @@ -75,17 +75,17 @@ public class EmulatedBisFileSystemCreator : IBuiltInStorageFileSystemCreator } using var bisRootPath = new Path(); - Result rc = bisRootPath.Initialize(GetPartitionPath(partitionId).ToU8String()); - if (rc.IsFailure()) return rc; + Result res = bisRootPath.Initialize(GetPartitionPath(partitionId).ToU8String()); + if (res.IsFailure()) return res.Miss(); var pathFlags = new PathFlags(); pathFlags.AllowEmptyPath(); - rc = bisRootPath.Normalize(pathFlags); - if (rc.IsFailure()) return rc; + res = bisRootPath.Normalize(pathFlags); + if (res.IsFailure()) return res.Miss(); using var partitionFileSystem = new SharedRef(); - rc = Utility.WrapSubDirectory(ref partitionFileSystem.Ref(), ref rootFileSystem.Ref(), in bisRootPath, true); - if (rc.IsFailure()) return rc; + res = Utility.WrapSubDirectory(ref partitionFileSystem.Ref(), ref rootFileSystem.Ref(), in bisRootPath, true); + if (res.IsFailure()) return res.Miss(); outFileSystem.SetByMove(ref partitionFileSystem.Ref()); return Result.Success; diff --git a/src/LibHac/FsSrv/FsCreator/EmulatedGameCardFsCreator.cs b/src/LibHac/FsSrv/FsCreator/EmulatedGameCardFsCreator.cs index 550105c7..f5200e97 100644 --- a/src/LibHac/FsSrv/FsCreator/EmulatedGameCardFsCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/EmulatedGameCardFsCreator.cs @@ -22,8 +22,8 @@ public class EmulatedGameCardFsCreator : IGameCardFileSystemCreator { // Use the old xci code temporarily - Result rc = _gameCard.GetXci(out Xci xci, handle); - if (rc.IsFailure()) return rc; + Result res = _gameCard.GetXci(out Xci xci, handle); + if (res.IsFailure()) return res.Miss(); if (!xci.HasPartition((XciPartitionType)partitionType)) { diff --git a/src/LibHac/FsSrv/FsCreator/EmulatedGameCardStorageCreator.cs b/src/LibHac/FsSrv/FsCreator/EmulatedGameCardStorageCreator.cs index df9c37b8..51ce7036 100644 --- a/src/LibHac/FsSrv/FsCreator/EmulatedGameCardStorageCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/EmulatedGameCardStorageCreator.cs @@ -22,8 +22,8 @@ public class EmulatedGameCardStorageCreator : IGameCardStorageCreator using var baseStorage = new SharedRef(new ReadOnlyGameCardStorage(GameCard, handle)); - Result rc = GameCard.GetCardInfo(out GameCardInfo cardInfo, handle); - if (rc.IsFailure()) return rc; + Result res = GameCard.GetCardInfo(out GameCardInfo cardInfo, handle); + if (res.IsFailure()) return res.Miss(); outStorage.Reset(new SubStorage(in baseStorage, 0, cardInfo.SecureAreaOffset)); return Result.Success; @@ -39,17 +39,17 @@ public class EmulatedGameCardStorageCreator : IGameCardStorageCreator Span deviceId = stackalloc byte[0x10]; Span imageHash = stackalloc byte[0x20]; - Result rc = GameCard.GetGameCardDeviceId(deviceId); - if (rc.IsFailure()) return rc; + Result res = GameCard.GetGameCardDeviceId(deviceId); + if (res.IsFailure()) return res.Miss(); - rc = GameCard.GetGameCardImageHash(imageHash); - if (rc.IsFailure()) return rc; + res = GameCard.GetGameCardImageHash(imageHash); + if (res.IsFailure()) return res.Miss(); using var baseStorage = new SharedRef(new ReadOnlyGameCardStorage(GameCard, handle, deviceId, imageHash)); - rc = GameCard.GetCardInfo(out GameCardInfo cardInfo, handle); - if (rc.IsFailure()) return rc; + res = GameCard.GetCardInfo(out GameCardInfo cardInfo, handle); + if (res.IsFailure()) return res.Miss(); outStorage.Reset(new SubStorage(in baseStorage, cardInfo.SecureAreaOffset, cardInfo.SecureAreaSize)); return Result.Success; @@ -113,8 +113,8 @@ public class EmulatedGameCardStorageCreator : IGameCardStorageCreator { UnsafeHelpers.SkipParamInit(out size); - Result rc = GameCard.GetCardInfo(out GameCardInfo info, Handle); - if (rc.IsFailure()) return rc; + Result res = GameCard.GetCardInfo(out GameCardInfo info, Handle); + if (res.IsFailure()) return res.Miss(); size = info.Size; return Result.Success; diff --git a/src/LibHac/FsSrv/FsCreator/EmulatedSdCardFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/EmulatedSdCardFileSystemCreator.cs index b7359146..cac3a50b 100644 --- a/src/LibHac/FsSrv/FsCreator/EmulatedSdCardFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/EmulatedSdCardFileSystemCreator.cs @@ -58,19 +58,19 @@ public class EmulatedSdCardFileSystemCreator : ISdCardProxyFileSystemCreator, ID string path = _path ?? DefaultPath; using var sdCardPath = new Path(); - Result rc = sdCardPath.Initialize(StringUtils.StringToUtf8(path)); - if (rc.IsFailure()) return rc; + Result res = sdCardPath.Initialize(StringUtils.StringToUtf8(path)); + if (res.IsFailure()) return res.Miss(); var pathFlags = new PathFlags(); pathFlags.AllowEmptyPath(); - rc = sdCardPath.Normalize(pathFlags); - if (rc.IsFailure()) return rc; + res = sdCardPath.Normalize(pathFlags); + if (res.IsFailure()) return res.Miss(); // Todo: Add ProxyFileSystem? using SharedRef fileSystem = SharedRef.CreateCopy(in _rootFileSystem); - rc = Utility.WrapSubDirectory(ref _sdCardFileSystem, ref fileSystem.Ref(), in sdCardPath, true); - if (rc.IsFailure()) return rc; + res = Utility.WrapSubDirectory(ref _sdCardFileSystem, ref fileSystem.Ref(), in sdCardPath, true); + if (res.IsFailure()) return res.Miss(); outFileSystem.SetByCopy(in _sdCardFileSystem); diff --git a/src/LibHac/FsSrv/FsCreator/PartitionFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/PartitionFileSystemCreator.cs index a5d4bcac..fde875b0 100644 --- a/src/LibHac/FsSrv/FsCreator/PartitionFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/PartitionFileSystemCreator.cs @@ -13,8 +13,8 @@ public class PartitionFileSystemCreator : IPartitionFileSystemCreator using var partitionFs = new SharedRef>(new PartitionFileSystemCore()); - Result rc = partitionFs.Get.Initialize(ref baseStorage); - if (rc.IsFailure()) return rc.Miss(); + Result res = partitionFs.Get.Initialize(ref baseStorage); + if (res.IsFailure()) return res.Miss(); outFileSystem.SetByMove(ref partitionFs.Ref()); return Result.Success; diff --git a/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs index 577feb51..07a05c21 100644 --- a/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/SaveDataFileSystemCreator.cs @@ -48,14 +48,14 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator Unsafe.SkipInit(out Array18 saveImageNameBuffer); using var saveImageName = new Path(); - Result rc = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + Result res = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId); + if (res.IsFailure()) return res.Miss(); - rc = baseFileSystem.Get.GetEntryType(out DirectoryEntryType type, in saveImageName); + res = baseFileSystem.Get.GetEntryType(out DirectoryEntryType type, in saveImageName); - if (rc.IsFailure()) + if (res.IsFailure()) { - return ResultFs.PathNotFound.Includes(rc) ? ResultFs.TargetNotFound.LogConverted(rc) : rc.Miss(); + return ResultFs.PathNotFound.Includes(res) ? ResultFs.TargetNotFound.LogConverted(res) : res.Miss(); } using var saveDataFs = new SharedRef(); @@ -74,8 +74,8 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator if (!baseFs.HasValue) return ResultFs.AllocationMemoryFailedInSaveDataFileSystemCreatorA.Log(); - rc = baseFs.Get.Initialize(in saveImageName); - if (rc.IsFailure()) return rc.Miss(); + res = baseFs.Get.Initialize(in saveImageName); + if (res.IsFailure()) return res.Miss(); // Create and initialize the directory save data FS using UniqueRef tempFs = UniqueRef.Create(ref baseFs.Ref()); @@ -85,9 +85,9 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator if (!saveDirFs.HasValue) return ResultFs.AllocationMemoryFailedInSaveDataFileSystemCreatorB.Log(); - rc = saveDirFs.Get.Initialize(isJournalingSupported, isMultiCommitSupported, !openReadOnly, + res = saveDirFs.Get.Initialize(isJournalingSupported, isMultiCommitSupported, !openReadOnly, timeStampGetter, _randomGenerator); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); saveDataFs.SetByMove(ref saveDirFs.Ref()); } @@ -98,9 +98,9 @@ public class SaveDataFileSystemCreator : ISaveDataFileSystemCreator Optional openType = openShared ? new Optional(OpenType.Normal) : new Optional(); - rc = _fsServer.OpenSaveDataStorage(ref fileStorage.Ref(), ref baseFileSystem, spaceId, saveDataId, + res = _fsServer.OpenSaveDataStorage(ref fileStorage.Ref(), ref baseFileSystem, spaceId, saveDataId, OpenMode.ReadWrite, openType); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); throw new NotImplementedException(); } diff --git a/src/LibHac/FsSrv/FsCreator/SaveDataResultConvertFileSystem.cs b/src/LibHac/FsSrv/FsCreator/SaveDataResultConvertFileSystem.cs index 60813646..34b72d1a 100644 --- a/src/LibHac/FsSrv/FsCreator/SaveDataResultConvertFileSystem.cs +++ b/src/LibHac/FsSrv/FsCreator/SaveDataResultConvertFileSystem.cs @@ -85,8 +85,8 @@ public class SaveDataResultConvertFileSystem : IResultConvertFileSystem outFile, in Path path, OpenMode mode) { using var file = new UniqueRef(); - Result rc = ConvertResult(GetFileSystem().OpenFile(ref file.Ref(), in path, mode)); - if (rc.IsFailure()) return rc.Miss(); + Result res = ConvertResult(GetFileSystem().OpenFile(ref file.Ref(), in path, mode)); + if (res.IsFailure()) return res.Miss(); using UniqueRef resultConvertFile = new(new SaveDataResultConvertFile(ref file.Ref(), _isReconstructible)); @@ -99,8 +99,8 @@ public class SaveDataResultConvertFileSystem : IResultConvertFileSystem(); - Result rc = ConvertResult(GetFileSystem().OpenDirectory(ref directory.Ref(), in path, mode)); - if (rc.IsFailure()) return rc.Miss(); + Result res = ConvertResult(GetFileSystem().OpenDirectory(ref directory.Ref(), in path, mode)); + if (res.IsFailure()) return res.Miss(); using UniqueRef resultConvertDirectory = new(new SaveDataResultConvertDirectory(ref directory.Ref(), _isReconstructible)); diff --git a/src/LibHac/FsSrv/FsCreator/StorageOnNcaCreator.cs b/src/LibHac/FsSrv/FsCreator/StorageOnNcaCreator.cs index 31f1eeb1..dcf9a54f 100644 --- a/src/LibHac/FsSrv/FsCreator/StorageOnNcaCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/StorageOnNcaCreator.cs @@ -28,18 +28,18 @@ public class StorageOnNcaCreator : IStorageOnNcaCreator { UnsafeHelpers.SkipParamInit(out fsHeader); - Result rc = OpenStorage(out IStorage storageTemp, nca, fsIndex); - if (rc.IsFailure()) return rc; + Result res = OpenStorage(out IStorage storageTemp, nca, fsIndex); + if (res.IsFailure()) return res.Miss(); if (isCodeFs) { using (var codeFs = new PartitionFileSystemCore()) { - rc = codeFs.Initialize(storageTemp); - if (rc.IsFailure()) return rc; + res = codeFs.Initialize(storageTemp); + if (res.IsFailure()) return res.Miss(); - rc = VerifyAcidSignature(codeFs, nca); - if (rc.IsFailure()) return rc; + res = VerifyAcidSignature(codeFs, nca); + if (res.IsFailure()) return res.Miss(); } } diff --git a/src/LibHac/FsSrv/FsCreator/SubDirectoryFileSystemCreator.cs b/src/LibHac/FsSrv/FsCreator/SubDirectoryFileSystemCreator.cs index a0dd0206..db484754 100644 --- a/src/LibHac/FsSrv/FsCreator/SubDirectoryFileSystemCreator.cs +++ b/src/LibHac/FsSrv/FsCreator/SubDirectoryFileSystemCreator.cs @@ -12,8 +12,8 @@ public class SubDirectoryFileSystemCreator : ISubDirectoryFileSystemCreator { using var directory = new UniqueRef(); - Result rc = baseFileSystem.Get.OpenDirectory(ref directory.Ref(), in path, OpenDirectoryMode.Directory); - if (rc.IsFailure()) return rc; + Result res = baseFileSystem.Get.OpenDirectory(ref directory.Ref(), in path, OpenDirectoryMode.Directory); + if (res.IsFailure()) return res.Miss(); directory.Reset(); @@ -22,8 +22,8 @@ public class SubDirectoryFileSystemCreator : ISubDirectoryFileSystemCreator if (!subFs.HasValue) return ResultFs.AllocationMemoryFailedInSubDirectoryFileSystemCreatorA.Log(); - rc = subFs.Get.Initialize(in path); - if (rc.IsFailure()) return rc; + res = subFs.Get.Initialize(in path); + if (res.IsFailure()) return res.Miss(); outSubDirFileSystem.SetByMove(ref subFs.Ref()); return Result.Success; diff --git a/src/LibHac/FsSrv/Impl/DeviceEventSimulationStorage.cs b/src/LibHac/FsSrv/Impl/DeviceEventSimulationStorage.cs index 53a70155..22d66e97 100644 --- a/src/LibHac/FsSrv/Impl/DeviceEventSimulationStorage.cs +++ b/src/LibHac/FsSrv/Impl/DeviceEventSimulationStorage.cs @@ -30,8 +30,8 @@ internal class DeviceEventSimulationStorage : IStorage { Assert.SdkNotNull(_deviceEventSimulator); - Result rc = _deviceEventSimulator.CheckSimulatedAccessFailureEvent(SimulatingDeviceTargetOperation.Read); - if (rc.IsFailure()) return rc; + Result res = _deviceEventSimulator.CheckSimulatedAccessFailureEvent(SimulatingDeviceTargetOperation.Read); + if (res.IsFailure()) return res.Miss(); return _baseStorage.Get.Read(offset, destination); } @@ -40,8 +40,8 @@ internal class DeviceEventSimulationStorage : IStorage { Assert.SdkNotNull(_deviceEventSimulator); - Result rc = _deviceEventSimulator.CheckSimulatedAccessFailureEvent(SimulatingDeviceTargetOperation.Write); - if (rc.IsFailure()) return rc; + Result res = _deviceEventSimulator.CheckSimulatedAccessFailureEvent(SimulatingDeviceTargetOperation.Write); + if (res.IsFailure()) return res.Miss(); return _baseStorage.Get.Write(offset, source); } diff --git a/src/LibHac/FsSrv/Impl/DeviceOperator.cs b/src/LibHac/FsSrv/Impl/DeviceOperator.cs index ab9d1718..4c79e93e 100644 --- a/src/LibHac/FsSrv/Impl/DeviceOperator.cs +++ b/src/LibHac/FsSrv/Impl/DeviceOperator.cs @@ -68,8 +68,8 @@ public class DeviceOperator : IDeviceOperator { UnsafeHelpers.SkipParamInit(out outSpeedMode); - Result rc = _fsServer.Storage.GetSdCardSpeedMode(out SdCardSpeedMode speedMode); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsServer.Storage.GetSdCardSpeedMode(out SdCardSpeedMode speedMode); + if (res.IsFailure()) return res.Miss(); outSpeedMode = (long)speedMode; return Result.Success; @@ -79,8 +79,8 @@ public class DeviceOperator : IDeviceOperator { UnsafeHelpers.SkipParamInit(out outSize); - Result rc = _fsServer.Storage.GetSdCardUserAreaSize(out long size); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsServer.Storage.GetSdCardUserAreaSize(out long size); + if (res.IsFailure()) return res.Miss(); outSize = size; return Result.Success; @@ -90,8 +90,8 @@ public class DeviceOperator : IDeviceOperator { UnsafeHelpers.SkipParamInit(out outSize); - Result rc = _fsServer.Storage.GetSdCardProtectedAreaSize(out long size); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsServer.Storage.GetSdCardProtectedAreaSize(out long size); + if (res.IsFailure()) return res.Miss(); outSize = size; return Result.Success; @@ -105,9 +105,9 @@ public class DeviceOperator : IDeviceOperator if (logBuffer.Size < logBufferSize) return ResultFs.InvalidSize.Log(); - Result rc = _fsServer.Storage.GetAndClearSdCardErrorInfo(out StorageErrorInfo storageErrorInfo, + Result res = _fsServer.Storage.GetAndClearSdCardErrorInfo(out StorageErrorInfo storageErrorInfo, out long logSize, GetSpan(logBuffer, logBufferSize)); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); outStorageErrorInfo = storageErrorInfo; outLogSize = logSize; @@ -126,8 +126,8 @@ public class DeviceOperator : IDeviceOperator { UnsafeHelpers.SkipParamInit(out outSpeedMode); - Result rc = _fsServer.Storage.GetMmcSpeedMode(out MmcSpeedMode speedMode); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsServer.Storage.GetMmcSpeedMode(out MmcSpeedMode speedMode); + if (res.IsFailure()) return res.Miss(); outSpeedMode = (long)speedMode; return Result.Success; @@ -145,8 +145,8 @@ public class DeviceOperator : IDeviceOperator { UnsafeHelpers.SkipParamInit(out outSize); - Result rc = _fsServer.Storage.GetMmcPartitionSize(out long mmcPartitionSize, (MmcPartition)partitionId); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsServer.Storage.GetMmcPartitionSize(out long mmcPartitionSize, (MmcPartition)partitionId); + if (res.IsFailure()) return res.Miss(); outSize = mmcPartitionSize; return Result.Success; @@ -156,8 +156,8 @@ public class DeviceOperator : IDeviceOperator { UnsafeHelpers.SkipParamInit(out outCount); - Result rc = _fsServer.Storage.GetMmcPatrolCount(out uint mmcPatrolCount); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsServer.Storage.GetMmcPatrolCount(out uint mmcPatrolCount); + if (res.IsFailure()) return res.Miss(); outCount = mmcPatrolCount; return Result.Success; @@ -171,9 +171,9 @@ public class DeviceOperator : IDeviceOperator if (logBuffer.Size < logBufferSize) return ResultFs.InvalidSize.Log(); - Result rc = _fsServer.Storage.GetAndClearMmcErrorInfo(out StorageErrorInfo storageErrorInfo, out long logSize, + Result res = _fsServer.Storage.GetAndClearMmcErrorInfo(out StorageErrorInfo storageErrorInfo, out long logSize, GetSpan(logBuffer, logBufferSize)); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); outStorageErrorInfo = storageErrorInfo; outLogSize = logSize; @@ -208,8 +208,8 @@ public class DeviceOperator : IDeviceOperator { UnsafeHelpers.SkipParamInit(out outIsInserted); - Result rc = _fsServer.Storage.IsGameCardInserted(out bool isInserted); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsServer.Storage.IsGameCardInserted(out bool isInserted); + if (res.IsFailure()) return res.Miss(); outIsInserted = isInserted; return Result.Success; @@ -229,15 +229,15 @@ public class DeviceOperator : IDeviceOperator { UnsafeHelpers.SkipParamInit(out outHandle); - Result rc = _fsServer.Storage.GetInitializationResult(); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsServer.Storage.GetInitializationResult(); + if (res.IsFailure()) return res.Miss(); _fsServer.Storage.IsGameCardInserted(out bool isInserted).IgnoreResult(); if (!isInserted) return ResultFs.GameCardFsGetHandleFailure.Log(); - rc = _fsServer.Storage.GetGameCardHandle(out GameCardHandle handle); - if (rc.IsFailure()) return rc.Miss(); + res = _fsServer.Storage.GetGameCardHandle(out GameCardHandle handle); + if (res.IsFailure()) return res.Miss(); outHandle = handle; return Result.Success; @@ -247,8 +247,8 @@ public class DeviceOperator : IDeviceOperator { UnsafeHelpers.SkipParamInit(out outCupVersion, out outCupId); - Result rc = _fsServer.Storage.GetGameCardStatus(out GameCardStatus gameCardStatus, handle); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsServer.Storage.GetGameCardStatus(out GameCardStatus gameCardStatus, handle); + if (res.IsFailure()) return res.Miss(); outCupVersion = gameCardStatus.UpdatePartitionVersion; outCupId = gameCardStatus.UpdatePartitionId; @@ -269,8 +269,8 @@ public class DeviceOperator : IDeviceOperator { UnsafeHelpers.SkipParamInit(out outAttribute); - Result rc = _fsServer.Storage.GetGameCardStatus(out GameCardStatus gameCardStatus, handle); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsServer.Storage.GetGameCardStatus(out GameCardStatus gameCardStatus, handle); + if (res.IsFailure()) return res.Miss(); outAttribute = gameCardStatus.GameCardAttribute; return Result.Success; @@ -280,8 +280,8 @@ public class DeviceOperator : IDeviceOperator { UnsafeHelpers.SkipParamInit(out outCompatibilityType); - Result rc = _fsServer.Storage.GetGameCardStatus(out GameCardStatus gameCardStatus, handle); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsServer.Storage.GetGameCardStatus(out GameCardStatus gameCardStatus, handle); + if (res.IsFailure()) return res.Miss(); outCompatibilityType = gameCardStatus.CompatibilityType; return Result.Success; @@ -323,9 +323,9 @@ public class DeviceOperator : IDeviceOperator if (rmaInfoBufferSize != Unsafe.SizeOf()) return ResultFs.InvalidArgument.Log(); - Result rc = _fsServer.Storage.GetGameCardAsicInfo(out RmaInformation rmaInfo, + Result res = _fsServer.Storage.GetGameCardAsicInfo(out RmaInformation rmaInfo, GetSpan(asicFirmwareBuffer, asicFirmwareBufferSize)); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); SpanHelpers.AsReadOnlyByteSpan(in rmaInfo).CopyTo(outRmaInfoBuffer.Buffer); return Result.Success; @@ -339,8 +339,8 @@ public class DeviceOperator : IDeviceOperator if (outBufferSize != Unsafe.SizeOf()) return ResultFs.InvalidArgument.Log(); - Result rc = _fsServer.Storage.GetGameCardIdSet(out GameCardIdSet gcIdSet); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsServer.Storage.GetGameCardIdSet(out GameCardIdSet gcIdSet); + if (res.IsFailure()) return res.Miss(); SpanHelpers.AsReadOnlyByteSpan(in gcIdSet).CopyTo(outBuffer.Buffer); return Result.Success; @@ -436,8 +436,8 @@ public class DeviceOperator : IDeviceOperator { UnsafeHelpers.SkipParamInit(out outErrorInfo); - Result rc = _fsServer.Storage.GetGameCardErrorInfo(out GameCardErrorInfo gameCardErrorInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsServer.Storage.GetGameCardErrorInfo(out GameCardErrorInfo gameCardErrorInfo); + if (res.IsFailure()) return res.Miss(); outErrorInfo = gameCardErrorInfo; return Result.Success; @@ -447,8 +447,8 @@ public class DeviceOperator : IDeviceOperator { UnsafeHelpers.SkipParamInit(out outErrorInfo); - Result rc = _fsServer.Storage.GetGameCardErrorReportInfo(out GameCardErrorReportInfo gameCardErrorReportInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsServer.Storage.GetGameCardErrorReportInfo(out GameCardErrorReportInfo gameCardErrorReportInfo); + if (res.IsFailure()) return res.Miss(); outErrorInfo = gameCardErrorReportInfo; return Result.Success; @@ -479,13 +479,13 @@ public class DeviceOperator : IDeviceOperator public Result SuspendSdmmcControl() { - Result rc = _fsServer.Storage.SuspendSdCardControl(); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsServer.Storage.SuspendSdCardControl(); + if (res.IsFailure()) return res.Miss(); // Missing: Detach SD card device buffer - rc = _fsServer.Storage.SuspendMmcControl(); - if (rc.IsFailure()) return rc.Miss(); + res = _fsServer.Storage.SuspendMmcControl(); + if (res.IsFailure()) return res.Miss(); // Missing: Detach MMC device buffer @@ -496,13 +496,13 @@ public class DeviceOperator : IDeviceOperator { // Missing: Attach MMC device buffer - Result rc = _fsServer.Storage.ResumeMmcControl(); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fsServer.Storage.ResumeMmcControl(); + if (res.IsFailure()) return res.Miss(); // Missing: Attach SD card device buffer - rc = _fsServer.Storage.ResumeSdCardControl(); - if (rc.IsFailure()) return rc.Miss(); + res = _fsServer.Storage.ResumeSdCardControl(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -514,8 +514,8 @@ public class DeviceOperator : IDeviceOperator if ((uint)port > (uint)Port.GcAsic0) return ResultFs.InvalidArgument.Log(); - Result rc = SdmmcSrv.Common.CheckConnection(out SpeedMode speedMode, out BusWidth busWidth, (Port)port); - if (rc.IsFailure()) return rc.Miss(); + Result res = SdmmcSrv.Common.CheckConnection(out SpeedMode speedMode, out BusWidth busWidth, (Port)port); + if (res.IsFailure()) return res.Miss(); SdmmcSpeedMode sdmmcSpeedMode = speedMode switch { diff --git a/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs b/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs index 66c7b466..d686f14c 100644 --- a/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs +++ b/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs @@ -55,19 +55,19 @@ public class FileInterfaceAdapter : IFileSf if (destination.Size < (int)size) return ResultFs.InvalidSize.Log(); - Result rc = Result.Success; + Result res = Result.Success; long readSize = 0; for (int tryNum = 0; tryNum < maxTryCount; tryNum++) { - rc = _baseFile.Get.Read(out readSize, offset, destination.Buffer.Slice(0, (int)size), option); + res = _baseFile.Get.Read(out readSize, offset, destination.Buffer.Slice(0, (int)size), option); // Retry on ResultDataCorrupted - if (!ResultFs.DataCorrupted.Includes(rc)) + if (!ResultFs.DataCorrupted.Includes(res)) break; } - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); bytesRead = readSize; return Result.Success; @@ -108,19 +108,19 @@ public class FileInterfaceAdapter : IFileSf const int maxTryCount = 2; UnsafeHelpers.SkipParamInit(out size); - Result rc = Result.Success; + Result res = Result.Success; long tmpSize = 0; for (int tryNum = 0; tryNum < maxTryCount; tryNum++) { - rc = _baseFile.Get.GetSize(out tmpSize); + res = _baseFile.Get.GetSize(out tmpSize); // Retry on ResultDataCorrupted - if (!ResultFs.DataCorrupted.Includes(rc)) + if (!ResultFs.DataCorrupted.Includes(res)) break; } - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); size = tmpSize; return Result.Success; @@ -135,17 +135,17 @@ public class FileInterfaceAdapter : IFileSf { Unsafe.SkipInit(out QueryRangeInfo info); - Result rc = _baseFile.Get.OperateRange(SpanHelpers.AsByteSpan(ref info), OperationId.QueryRange, offset, + Result res = _baseFile.Get.OperateRange(SpanHelpers.AsByteSpan(ref info), OperationId.QueryRange, offset, size, ReadOnlySpan.Empty); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); rangeInfo.Merge(in info); } else if (operationId == (int)OperationId.InvalidateCache) { - Result rc = _baseFile.Get.OperateRange(Span.Empty, OperationId.InvalidateCache, offset, size, + Result res = _baseFile.Get.OperateRange(Span.Empty, OperationId.InvalidateCache, offset, size, ReadOnlySpan.Empty); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -168,11 +168,11 @@ public class FileInterfaceAdapter : IFileSf return Result.Success; } - Result rc = PermissionCheck((OperationId)operationId, this); - if (rc.IsFailure()) return rc; + Result res = PermissionCheck((OperationId)operationId, this); + if (res.IsFailure()) return res.Miss(); - rc = _baseFile.Get.OperateRange(outBuffer.Buffer, (OperationId)operationId, offset, size, inBuffer.Buffer); - if (rc.IsFailure()) return rc; + res = _baseFile.Get.OperateRange(outBuffer.Buffer, (OperationId)operationId, offset, size, inBuffer.Buffer); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -207,19 +207,19 @@ public class DirectoryInterfaceAdapter : IDirectorySf Span entries = MemoryMarshal.Cast(entryBuffer.Buffer); - Result rc = Result.Success; + Result res = Result.Success; long numRead = 0; for (int tryNum = 0; tryNum < maxTryCount; tryNum++) { - rc = _baseDirectory.Get.Read(out numRead, entries); + res = _baseDirectory.Get.Read(out numRead, entries); // Retry on ResultDataCorrupted - if (!ResultFs.DataCorrupted.Includes(rc)) + if (!ResultFs.DataCorrupted.Includes(res)) break; } - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); entriesRead = numRead; return Result.Success; @@ -229,8 +229,8 @@ public class DirectoryInterfaceAdapter : IDirectorySf { UnsafeHelpers.SkipParamInit(out entryCount); - Result rc = _baseDirectory.Get.GetEntryCount(out long count); - if (rc.IsFailure()) return rc; + Result res = _baseDirectory.Get.GetEntryCount(out long count); + if (res.IsFailure()) return res.Miss(); entryCount = count; return Result.Success; @@ -297,21 +297,21 @@ public class FileSystemInterfaceAdapter : IFileSystemSf private Result SetUpPath(ref Path fsPath, in PathSf sfPath) { - Result rc; + Result res; if (_pathFlags.IsWindowsPathAllowed()) { - rc = fsPath.InitializeWithReplaceUnc(sfPath.Str); - if (rc.IsFailure()) return rc; + res = fsPath.InitializeWithReplaceUnc(sfPath.Str); + if (res.IsFailure()) return res.Miss(); } else { - rc = fsPath.Initialize(sfPath.Str); - if (rc.IsFailure()) return rc; + res = fsPath.Initialize(sfPath.Str); + if (res.IsFailure()) return res.Miss(); } - rc = fsPath.Normalize(_pathFlags); - if (rc.IsFailure()) return rc; + res = fsPath.Normalize(_pathFlags); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -322,11 +322,11 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return ResultFs.InvalidSize.Log(); using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.Get.CreateFile(in pathNormalized, size, (CreateFileOptions)option); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.Get.CreateFile(in pathNormalized, size, (CreateFileOptions)option); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -334,11 +334,11 @@ public class FileSystemInterfaceAdapter : IFileSystemSf public Result DeleteFile(in PathSf path) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.Get.DeleteFile(in pathNormalized); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.Get.DeleteFile(in pathNormalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -346,14 +346,14 @@ public class FileSystemInterfaceAdapter : IFileSystemSf public Result CreateDirectory(in PathSf path) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), in path); + if (res.IsFailure()) return res.Miss(); if (pathNormalized == RootDir) return ResultFs.PathAlreadyExists.Log(); - rc = _baseFileSystem.Get.CreateDirectory(in pathNormalized); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.Get.CreateDirectory(in pathNormalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -361,14 +361,14 @@ public class FileSystemInterfaceAdapter : IFileSystemSf public Result DeleteDirectory(in PathSf path) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), in path); + if (res.IsFailure()) return res.Miss(); if (pathNormalized == RootDir) return ResultFs.DirectoryUndeletable.Log(); - rc = _baseFileSystem.Get.DeleteDirectory(in pathNormalized); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.Get.DeleteDirectory(in pathNormalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -376,14 +376,14 @@ public class FileSystemInterfaceAdapter : IFileSystemSf public Result DeleteDirectoryRecursively(in PathSf path) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), in path); + if (res.IsFailure()) return res.Miss(); if (pathNormalized == RootDir) return ResultFs.DirectoryUndeletable.Log(); - rc = _baseFileSystem.Get.DeleteDirectoryRecursively(in pathNormalized); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.Get.DeleteDirectoryRecursively(in pathNormalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -391,11 +391,11 @@ public class FileSystemInterfaceAdapter : IFileSystemSf public Result CleanDirectoryRecursively(in PathSf path) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.Get.CleanDirectoryRecursively(in pathNormalized); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.Get.CleanDirectoryRecursively(in pathNormalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -403,15 +403,15 @@ public class FileSystemInterfaceAdapter : IFileSystemSf public Result RenameFile(in PathSf currentPath, in PathSf newPath) { using var currentPathNormalized = new Path(); - Result rc = SetUpPath(ref currentPathNormalized.Ref(), in currentPath); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref currentPathNormalized.Ref(), in currentPath); + if (res.IsFailure()) return res.Miss(); using var newPathNormalized = new Path(); - rc = SetUpPath(ref newPathNormalized.Ref(), in newPath); - if (rc.IsFailure()) return rc; + res = SetUpPath(ref newPathNormalized.Ref(), in newPath); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.Get.RenameFile(in currentPathNormalized, in newPathNormalized); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.Get.RenameFile(in currentPathNormalized, in newPathNormalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -419,18 +419,18 @@ public class FileSystemInterfaceAdapter : IFileSystemSf public Result RenameDirectory(in PathSf currentPath, in PathSf newPath) { using var currentPathNormalized = new Path(); - Result rc = SetUpPath(ref currentPathNormalized.Ref(), in currentPath); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref currentPathNormalized.Ref(), in currentPath); + if (res.IsFailure()) return res.Miss(); using var newPathNormalized = new Path(); - rc = SetUpPath(ref newPathNormalized.Ref(), in newPath); - if (rc.IsFailure()) return rc; + res = SetUpPath(ref newPathNormalized.Ref(), in newPath); + if (res.IsFailure()) return res.Miss(); if (PathUtility.IsSubPath(currentPathNormalized.GetString(), newPathNormalized.GetString())) return ResultFs.DirectoryUnrenamable.Log(); - rc = _baseFileSystem.Get.RenameDirectory(in currentPathNormalized, in newPathNormalized); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.Get.RenameDirectory(in currentPathNormalized, in newPathNormalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -440,11 +440,11 @@ public class FileSystemInterfaceAdapter : IFileSystemSf UnsafeHelpers.SkipParamInit(out entryType); using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.Get.GetEntryType(out DirectoryEntryType type, in pathNormalized); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.Get.GetEntryType(out DirectoryEntryType type, in pathNormalized); + if (res.IsFailure()) return res.Miss(); entryType = (uint)type; return Result.Success; @@ -455,11 +455,11 @@ public class FileSystemInterfaceAdapter : IFileSystemSf UnsafeHelpers.SkipParamInit(out freeSpace); using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.Get.GetFreeSpaceSize(out long space, in pathNormalized); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.Get.GetFreeSpaceSize(out long space, in pathNormalized); + if (res.IsFailure()) return res.Miss(); freeSpace = space; return Result.Success; @@ -470,11 +470,11 @@ public class FileSystemInterfaceAdapter : IFileSystemSf UnsafeHelpers.SkipParamInit(out totalSpace); using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.Get.GetTotalSpaceSize(out long space, in pathNormalized); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.Get.GetTotalSpaceSize(out long space, in pathNormalized); + if (res.IsFailure()) return res.Miss(); totalSpace = space; return Result.Success; @@ -485,21 +485,21 @@ public class FileSystemInterfaceAdapter : IFileSystemSf const int maxTryCount = 2; using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), in path); + if (res.IsFailure()) return res.Miss(); using var file = new UniqueRef(); for (int tryNum = 0; tryNum < maxTryCount; tryNum++) { - rc = _baseFileSystem.Get.OpenFile(ref file.Ref(), in pathNormalized, (OpenMode)mode); + res = _baseFileSystem.Get.OpenFile(ref file.Ref(), in pathNormalized, (OpenMode)mode); // Retry on ResultDataCorrupted - if (!ResultFs.DataCorrupted.Includes(rc)) + if (!ResultFs.DataCorrupted.Includes(res)) break; } - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); using SharedRef selfReference = SharedRef.Create(in _selfReference); @@ -515,22 +515,22 @@ public class FileSystemInterfaceAdapter : IFileSystemSf const int maxTryCount = 2; using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), in path); + if (res.IsFailure()) return res.Miss(); using var directory = new UniqueRef(); for (int tryNum = 0; tryNum < maxTryCount; tryNum++) { - rc = _baseFileSystem.Get.OpenDirectory(ref directory.Ref(), in pathNormalized, + res = _baseFileSystem.Get.OpenDirectory(ref directory.Ref(), in pathNormalized, (OpenDirectoryMode)mode); // Retry on ResultDataCorrupted - if (!ResultFs.DataCorrupted.Includes(rc)) + if (!ResultFs.DataCorrupted.Includes(res)) break; } - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); using SharedRef selfReference = SharedRef.Create(in _selfReference); @@ -551,11 +551,11 @@ public class FileSystemInterfaceAdapter : IFileSystemSf UnsafeHelpers.SkipParamInit(out timeStamp); using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.Get.GetFileTimeStampRaw(out FileTimeStampRaw tempTimeStamp, in pathNormalized); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.Get.GetFileTimeStampRaw(out FileTimeStampRaw tempTimeStamp, in pathNormalized); + if (res.IsFailure()) return res.Miss(); timeStamp = tempTimeStamp; return Result.Success; @@ -578,16 +578,16 @@ public class FileSystemInterfaceAdapter : IFileSystemSf return Result.Success; } - Result rc = PermissionCheck((QueryId)queryId, this); - if (rc.IsFailure()) return rc; + Result res = PermissionCheck((QueryId)queryId, this); + if (res.IsFailure()) return res.Miss(); using var pathNormalized = new Path(); - rc = SetUpPath(ref pathNormalized.Ref(), in path); - if (rc.IsFailure()) return rc; + res = SetUpPath(ref pathNormalized.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.Get.QueryEntry(outBuffer.Buffer, inBuffer.Buffer, (QueryId)queryId, + res = _baseFileSystem.Get.QueryEntry(outBuffer.Buffer, inBuffer.Buffer, (QueryId)queryId, in pathNormalized); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/FsSrv/Impl/LocationResolverSet.cs b/src/LibHac/FsSrv/Impl/LocationResolverSet.cs index 17705c28..52408dca 100644 --- a/src/LibHac/FsSrv/Impl/LocationResolverSet.cs +++ b/src/LibHac/FsSrv/Impl/LocationResolverSet.cs @@ -82,11 +82,11 @@ internal class LocationResolverSet : IDisposable if (Utility.IsHostFsMountName(lrPath.Value)) pathFlags.AllowWindowsPath(); - Result rc = outPath.InitializeWithReplaceUnc(lrPath.Value); - if (rc.IsFailure()) return rc; + Result res = outPath.InitializeWithReplaceUnc(lrPath.Value); + if (res.IsFailure()) return res.Miss(); - rc = outPath.Normalize(pathFlags); - if (rc.IsFailure()) return rc; + res = outPath.Normalize(pathFlags); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -107,9 +107,9 @@ internal class LocationResolverSet : IDisposable if (!_resolvers[index].HasValue) { _resolvers[index].Set(null); - Result rc = Hos.Lr.OpenLocationResolver(out _resolvers[index].Value, storageId); + Result res = Hos.Lr.OpenLocationResolver(out _resolvers[index].Value, storageId); - if (rc.IsFailure()) + if (res.IsFailure()) { _resolvers[index].Clear(); return ResultLr.ApplicationNotFound.Log(); @@ -137,8 +137,8 @@ internal class LocationResolverSet : IDisposable if (!_aocResolver.HasValue) { - Result rc = Hos.Lr.OpenAddOnContentLocationResolver(out AddOnContentLocationResolver lr); - if (rc.IsFailure()) return rc.Miss(); + Result res = Hos.Lr.OpenAddOnContentLocationResolver(out AddOnContentLocationResolver lr); + if (res.IsFailure()) return res.Miss(); _aocResolver.Set(in lr); } @@ -149,11 +149,11 @@ internal class LocationResolverSet : IDisposable public Result ResolveApplicationControlPath(ref Fs.Path outPath, Ncm.ApplicationId applicationId, StorageId storageId) { - Result rc = GetLocationResolver(out LocationResolver resolver, storageId); - if (rc.IsFailure()) return rc; + Result res = GetLocationResolver(out LocationResolver resolver, storageId); + if (res.IsFailure()) return res.Miss(); - rc = resolver.ResolveApplicationControlPath(out Lr.Path path, applicationId); - if (rc.IsFailure()) return rc; + res = resolver.ResolveApplicationControlPath(out Lr.Path path, applicationId); + if (res.IsFailure()) return res.Miss(); return SetUpFsPath(ref outPath, in path); } @@ -162,11 +162,11 @@ internal class LocationResolverSet : IDisposable { UnsafeHelpers.SkipParamInit(out isDirectory); - Result rc = GetLocationResolver(out LocationResolver resolver, storageId); - if (rc.IsFailure()) return rc; + Result res = GetLocationResolver(out LocationResolver resolver, storageId); + if (res.IsFailure()) return res.Miss(); - rc = resolver.ResolveApplicationHtmlDocumentPath(out Lr.Path path, applicationId); - if (rc.IsFailure()) return rc; + res = resolver.ResolveApplicationHtmlDocumentPath(out Lr.Path path, applicationId); + if (res.IsFailure()) return res.Miss(); isDirectory = PathUtility.IsDirectoryPath(path.Value); @@ -177,11 +177,11 @@ internal class LocationResolverSet : IDisposable { UnsafeHelpers.SkipParamInit(out isDirectory); - Result rc = GetLocationResolver(out LocationResolver resolver, storageId); - if (rc.IsFailure()) return rc; + Result res = GetLocationResolver(out LocationResolver resolver, storageId); + if (res.IsFailure()) return res.Miss(); - rc = resolver.ResolveProgramPath(out Lr.Path path, programId); - if (rc.IsFailure()) return rc; + res = resolver.ResolveProgramPath(out Lr.Path path, programId); + if (res.IsFailure()) return res.Miss(); isDirectory = PathUtility.IsDirectoryPath(path.Value); @@ -192,11 +192,11 @@ internal class LocationResolverSet : IDisposable { UnsafeHelpers.SkipParamInit(out isDirectory); - Result rc = GetLocationResolver(out LocationResolver resolver, storageId); - if (rc.IsFailure()) return rc; + Result res = GetLocationResolver(out LocationResolver resolver, storageId); + if (res.IsFailure()) return res.Miss(); - rc = resolver.ResolveProgramPathForDebug(out Lr.Path path, programId); - if (rc.IsFailure()) return rc; + res = resolver.ResolveProgramPathForDebug(out Lr.Path path, programId); + if (res.IsFailure()) return res.Miss(); isDirectory = PathUtility.IsDirectoryPath(path.Value); @@ -205,11 +205,11 @@ internal class LocationResolverSet : IDisposable public Result ResolveAddOnContentPath(ref Fs.Path outPath, DataId dataId) { - Result rc = GetAddOnContentLocationResolver(out AddOnContentLocationResolver resolver); - if (rc.IsFailure()) return rc; + Result res = GetAddOnContentLocationResolver(out AddOnContentLocationResolver resolver); + if (res.IsFailure()) return res.Miss(); - rc = resolver.ResolveAddOnContentPath(out Lr.Path path, dataId); - if (rc.IsFailure()) return rc; + res = resolver.ResolveAddOnContentPath(out Lr.Path path, dataId); + if (res.IsFailure()) return res.Miss(); return SetUpFsPath(ref outPath, in path); } @@ -219,11 +219,11 @@ internal class LocationResolverSet : IDisposable if (storageId == StorageId.None) return ResultFs.InvalidAlignment.Log(); - Result rc = GetLocationResolver(out LocationResolver resolver, storageId); - if (rc.IsFailure()) return rc; + Result res = GetLocationResolver(out LocationResolver resolver, storageId); + if (res.IsFailure()) return res.Miss(); - rc = resolver.ResolveDataPath(out Lr.Path path, dataId); - if (rc.IsFailure()) return rc; + res = resolver.ResolveDataPath(out Lr.Path path, dataId); + if (res.IsFailure()) return res.Miss(); return SetUpFsPath(ref outPath, in path); } @@ -233,11 +233,11 @@ internal class LocationResolverSet : IDisposable RegisteredLocationResolver resolver = null; try { - Result rc = GetRegisteredLocationResolver(out resolver); - if (rc.IsFailure()) return rc; + Result res = GetRegisteredLocationResolver(out resolver); + if (res.IsFailure()) return res.Miss(); - rc = resolver.ResolveProgramPath(out Lr.Path path, new ProgramId(id)); - if (rc.IsFailure()) return rc; + res = resolver.ResolveProgramPath(out Lr.Path path, new ProgramId(id)); + if (res.IsFailure()) return res.Miss(); return SetUpFsPath(ref outPath, in path); } @@ -252,11 +252,11 @@ internal class LocationResolverSet : IDisposable RegisteredLocationResolver resolver = null; try { - Result rc = GetRegisteredLocationResolver(out resolver); - if (rc.IsFailure()) return rc; + Result res = GetRegisteredLocationResolver(out resolver); + if (res.IsFailure()) return res.Miss(); - rc = resolver.ResolveHtmlDocumentPath(out Lr.Path path, new ProgramId(id)); - if (rc.IsFailure()) return rc; + res = resolver.ResolveHtmlDocumentPath(out Lr.Path path, new ProgramId(id)); + if (res.IsFailure()) return res.Miss(); return SetUpFsPath(ref outPath, in path); } diff --git a/src/LibHac/FsSrv/Impl/MultiCommitManager.cs b/src/LibHac/FsSrv/Impl/MultiCommitManager.cs index 3f83ac21..6b63e195 100644 --- a/src/LibHac/FsSrv/Impl/MultiCommitManager.cs +++ b/src/LibHac/FsSrv/Impl/MultiCommitManager.cs @@ -100,15 +100,15 @@ internal class MultiCommitManager : IMultiCommitManager private Result EnsureSaveDataForContext() { using var contextFileSystem = new SharedRef(); - Result rc = _multiCommitInterface.Get.OpenMultiCommitContext(ref contextFileSystem.Ref()); + Result res = _multiCommitInterface.Get.OpenMultiCommitContext(ref contextFileSystem.Ref()); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (!ResultFs.TargetNotFound.Includes(rc)) - return rc; + if (!ResultFs.TargetNotFound.Includes(res)) + return res; - rc = _fsServer.Hos.Fs.CreateSystemSaveData(SaveDataId, SaveDataSize, SaveJournalSize, SaveDataFlags.None); - if (rc.IsFailure()) return rc; + res = _fsServer.Hos.Fs.CreateSystemSaveData(SaveDataId, SaveDataSize, SaveJournalSize, SaveDataFlags.None); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -128,8 +128,8 @@ internal class MultiCommitManager : IMultiCommitManager return ResultFs.MultiCommitFileSystemLimit.Log(); using var fsaFileSystem = new SharedRef(); - Result rc = fileSystem.Get.GetImpl(ref fsaFileSystem.Ref()); - if (rc.IsFailure()) return rc; + Result res = fileSystem.Get.GetImpl(ref fsaFileSystem.Ref()); + if (res.IsFailure()) return res.Miss(); // Check that the file system hasn't already been added for (int i = 0; i < _fileSystemCount; i++) @@ -155,20 +155,20 @@ internal class MultiCommitManager : IMultiCommitManager _counter = 1; using var contextUpdater = new ContextUpdater(contextFileSystem); - Result rc = contextUpdater.Create(_counter, _fileSystemCount); - if (rc.IsFailure()) return rc; + Result res = contextUpdater.Create(_counter, _fileSystemCount); + if (res.IsFailure()) return res.Miss(); - rc = CommitProvisionallyFileSystem(_counter); - if (rc.IsFailure()) return rc; + res = CommitProvisionallyFileSystem(_counter); + if (res.IsFailure()) return res.Miss(); - rc = contextUpdater.CommitProvisionallyDone(); - if (rc.IsFailure()) return rc; + res = contextUpdater.CommitProvisionallyDone(); + if (res.IsFailure()) return res.Miss(); - rc = CommitFileSystem(); - if (rc.IsFailure()) return rc; + res = CommitFileSystem(); + if (res.IsFailure()) return res.Miss(); - rc = contextUpdater.CommitDone(); - if (rc.IsFailure()) return rc; + res = contextUpdater.CommitDone(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -182,11 +182,11 @@ internal class MultiCommitManager : IMultiCommitManager using ScopedLock scopedLock = ScopedLock.Lock(ref Globals.MultiCommitMutex); using var contextFileSystem = new SharedRef(); - Result rc = EnsureSaveDataForContext(); - if (rc.IsFailure()) return rc; + Result res = EnsureSaveDataForContext(); + if (res.IsFailure()) return res.Miss(); - rc = _multiCommitInterface.Get.OpenMultiCommitContext(ref contextFileSystem.Ref()); - if (rc.IsFailure()) return rc; + res = _multiCommitInterface.Get.OpenMultiCommitContext(ref contextFileSystem.Ref()); + if (res.IsFailure()) return res.Miss(); return Commit(contextFileSystem.Get); } @@ -198,20 +198,20 @@ internal class MultiCommitManager : IMultiCommitManager /// The of the operation. private Result CommitProvisionallyFileSystem(long counter) { - Result rc = Result.Success; + Result res = Result.Success; int i; for (i = 0; i < _fileSystemCount; i++) { Assert.SdkNotNull(_fileSystems[i].Get); - rc = _fileSystems[i].Get.CommitProvisionally(counter); + res = _fileSystems[i].Get.CommitProvisionally(counter); - if (rc.IsFailure()) + if (res.IsFailure()) break; } - if (rc.IsFailure()) + if (res.IsFailure()) { // Rollback all provisional commits including the failed commit for (int j = 0; j <= i; j++) @@ -222,7 +222,7 @@ internal class MultiCommitManager : IMultiCommitManager } } - return rc; + return res; } /// @@ -269,17 +269,17 @@ internal class MultiCommitManager : IMultiCommitManager IFileSystem contextFs, SaveDataFileSystemServiceImpl saveService) { using var contextFilePath = new Fs.Path(); - Result rc = PathFunctions.SetUpFixedPath(ref contextFilePath.Ref(), CommitContextFileName); - if (rc.IsFailure()) return rc; + Result res = PathFunctions.SetUpFixedPath(ref contextFilePath.Ref(), CommitContextFileName); + if (res.IsFailure()) return res.Miss(); // Read the multi-commit context using var contextFile = new UniqueRef(); - rc = contextFs.OpenFile(ref contextFile.Ref(), in contextFilePath, OpenMode.ReadWrite); - if (rc.IsFailure()) return rc; + res = contextFs.OpenFile(ref contextFile.Ref(), in contextFilePath, OpenMode.ReadWrite); + if (res.IsFailure()) return res.Miss(); Unsafe.SkipInit(out Context context); - rc = contextFile.Get.Read(out _, 0, SpanHelpers.AsByteSpan(ref context), ReadOption.None); - if (rc.IsFailure()) return rc; + res = contextFile.Get.Read(out _, 0, SpanHelpers.AsByteSpan(ref context), ReadOption.None); + if (res.IsFailure()) return res.Miss(); // Note: Nintendo doesn't check if the proper amount of bytes were read, but it // doesn't really matter since the context is validated. @@ -301,32 +301,32 @@ internal class MultiCommitManager : IMultiCommitManager using var reader = new SharedRef(); using var accessor = new UniqueRef(); - rc = saveService.OpenSaveDataIndexerAccessor(ref accessor.Ref(), out _, SaveDataSpaceId.User); - if (rc.IsFailure()) return rc; + res = saveService.OpenSaveDataIndexerAccessor(ref accessor.Ref(), out _, SaveDataSpaceId.User); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().OpenSaveDataInfoReader(ref reader.Ref()); - if (rc.IsFailure()) return rc; + res = accessor.Get.GetInterface().OpenSaveDataInfoReader(ref reader.Ref()); + if (res.IsFailure()) return res.Miss(); // Iterate through all the saves to find any provisionally committed save data while (true) { Unsafe.SkipInit(out SaveDataInfo info); - rc = reader.Get.Read(out long readCount, OutBuffer.FromStruct(ref info)); - if (rc.IsFailure()) return rc; + res = reader.Get.Read(out long readCount, OutBuffer.FromStruct(ref info)); + if (res.IsFailure()) return res.Miss(); // Break once we're done iterating all save data if (readCount == 0) break; - rc = multiCommitInterface.IsProvisionallyCommittedSaveData(out bool isProvisionallyCommitted, + res = multiCommitInterface.IsProvisionallyCommittedSaveData(out bool isProvisionallyCommitted, in info); // Note: Multi-commits are only recovered at boot time, so some saves could be missed if there // are more than MaxFileSystemCount provisionally committed saves. // In theory this shouldn't happen because a multi-commit should only be interrupted if the // entire OS is brought down. - if (rc.IsSuccess() && isProvisionallyCommitted && saveCount < MaxFileSystemCount) + if (res.IsSuccess() && isProvisionallyCommitted && saveCount < MaxFileSystemCount) { savesToRecover[saveCount] = info; saveCount++; @@ -339,11 +339,11 @@ internal class MultiCommitManager : IMultiCommitManager // If any commits fail, the result from the first failed recovery will be returned. for (int i = 0; i < saveCount; i++) { - rc = multiCommitInterface.RecoverProvisionallyCommittedSaveData(in savesToRecover[i], false); + res = multiCommitInterface.RecoverProvisionallyCommittedSaveData(in savesToRecover[i], false); - if (rc.IsFailure() && !recoveryResult.IsFailure()) + if (res.IsFailure() && !recoveryResult.IsFailure()) { - recoveryResult = rc; + recoveryResult = res; } } @@ -369,9 +369,9 @@ internal class MultiCommitManager : IMultiCommitManager // Keep track of the first error that occurs during the recovery Result recoveryResult = Result.Success; - Result rc = RecoverCommit(multiCommitInterface, contextFs, saveService); + Result res = RecoverCommit(multiCommitInterface, contextFs, saveService); - if (rc.IsFailure()) + if (res.IsFailure()) { // Note: Yes, the next ~50 lines are exactly the same as the code in RecoverCommit except // for a single bool value. No, Nintendo doesn't split it out into its own function. @@ -382,32 +382,32 @@ internal class MultiCommitManager : IMultiCommitManager using var reader = new SharedRef(); using var accessor = new UniqueRef(); - rc = saveService.OpenSaveDataIndexerAccessor(ref accessor.Ref(), out _, SaveDataSpaceId.User); - if (rc.IsFailure()) return rc; + res = saveService.OpenSaveDataIndexerAccessor(ref accessor.Ref(), out _, SaveDataSpaceId.User); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().OpenSaveDataInfoReader(ref reader.Ref()); - if (rc.IsFailure()) return rc; + res = accessor.Get.GetInterface().OpenSaveDataInfoReader(ref reader.Ref()); + if (res.IsFailure()) return res.Miss(); // Iterate through all the saves to find any provisionally committed save data while (true) { Unsafe.SkipInit(out SaveDataInfo info); - rc = reader.Get.Read(out long readCount, OutBuffer.FromStruct(ref info)); - if (rc.IsFailure()) return rc; + res = reader.Get.Read(out long readCount, OutBuffer.FromStruct(ref info)); + if (res.IsFailure()) return res.Miss(); // Break once we're done iterating all save data if (readCount == 0) break; - rc = multiCommitInterface.IsProvisionallyCommittedSaveData(out bool isProvisionallyCommitted, + res = multiCommitInterface.IsProvisionallyCommittedSaveData(out bool isProvisionallyCommitted, in info); // Note: Multi-commits are only recovered at boot time, so some saves could be missed if there // are more than MaxFileSystemCount provisionally committed saves. // In theory this shouldn't happen because a multi-commit should only be interrupted if the // entire OS is brought down. - if (rc.IsSuccess() && isProvisionallyCommitted && saveCount < MaxFileSystemCount) + if (res.IsSuccess() && isProvisionallyCommitted && saveCount < MaxFileSystemCount) { savesToRecover[saveCount] = info; saveCount++; @@ -420,25 +420,25 @@ internal class MultiCommitManager : IMultiCommitManager // If any commits fail, the result from the first failed recovery will be returned. for (int i = 0; i < saveCount; i++) { - rc = multiCommitInterface.RecoverProvisionallyCommittedSaveData(in savesToRecover[i], true); + res = multiCommitInterface.RecoverProvisionallyCommittedSaveData(in savesToRecover[i], true); - if (rc.IsFailure() && !recoveryResult.IsFailure()) + if (res.IsFailure() && !recoveryResult.IsFailure()) { - recoveryResult = rc; + recoveryResult = res; } } } using var contextFilePath = new Fs.Path(); - rc = PathFunctions.SetUpFixedPath(ref contextFilePath.Ref(), CommitContextFileName); - if (rc.IsFailure()) return rc; + res = PathFunctions.SetUpFixedPath(ref contextFilePath.Ref(), CommitContextFileName); + if (res.IsFailure()) return res.Miss(); // Delete the commit context file - rc = contextFs.DeleteFile(in contextFilePath); - if (rc.IsFailure()) return rc; + res = contextFs.DeleteFile(in contextFilePath); + if (res.IsFailure()) return res.Miss(); - rc = contextFs.Commit(); - if (rc.IsFailure()) return rc; + res = contextFs.Commit(); + if (res.IsFailure()) return res.Miss(); return recoveryResult; } @@ -462,12 +462,12 @@ internal class MultiCommitManager : IMultiCommitManager using var fileSystem = new SharedRef(); // Check if a multi-commit was interrupted by checking if there's a commit context file. - Result rc = multiCommitInterface.OpenMultiCommitContext(ref fileSystem.Ref()); + Result res = multiCommitInterface.OpenMultiCommitContext(ref fileSystem.Ref()); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (!ResultFs.PathNotFound.Includes(rc) && !ResultFs.TargetNotFound.Includes(rc)) - return rc; + if (!ResultFs.PathNotFound.Includes(res) && !ResultFs.TargetNotFound.Includes(res)) + return res; // Unable to open the multi-commit context file system, so there's nothing to recover needsRecovery = false; @@ -476,16 +476,16 @@ internal class MultiCommitManager : IMultiCommitManager if (needsRecovery) { using var contextFilePath = new Fs.Path(); - rc = PathFunctions.SetUpFixedPath(ref contextFilePath.Ref(), CommitContextFileName); - if (rc.IsFailure()) return rc; + res = PathFunctions.SetUpFixedPath(ref contextFilePath.Ref(), CommitContextFileName); + if (res.IsFailure()) return res.Miss(); using var file = new UniqueRef(); - rc = fileSystem.Get.OpenFile(ref file.Ref(), in contextFilePath, OpenMode.Read); + res = fileSystem.Get.OpenFile(ref file.Ref(), in contextFilePath, OpenMode.Read); - if (rc.IsFailure()) + if (res.IsFailure()) { // Unable to open the context file. No multi-commit to recover. - if (ResultFs.PathNotFound.Includes(rc)) + if (ResultFs.PathNotFound.Includes(res)) needsRecovery = false; } } @@ -547,31 +547,31 @@ internal class MultiCommitManager : IMultiCommitManager public Result Create(long counter, int fileSystemCount) { using var contextFilePath = new Fs.Path(); - Result rc = PathFunctions.SetUpFixedPath(ref contextFilePath.Ref(), CommitContextFileName); - if (rc.IsFailure()) return rc; + Result res = PathFunctions.SetUpFixedPath(ref contextFilePath.Ref(), CommitContextFileName); + if (res.IsFailure()) return res.Miss(); // Open context file and create if it doesn't exist using (var contextFile = new UniqueRef()) { - rc = _fileSystem.OpenFile(ref contextFile.Ref(), in contextFilePath, OpenMode.Read); + res = _fileSystem.OpenFile(ref contextFile.Ref(), in contextFilePath, OpenMode.Read); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (!ResultFs.PathNotFound.Includes(rc)) - return rc; + if (!ResultFs.PathNotFound.Includes(res)) + return res; - rc = _fileSystem.CreateFile(in contextFilePath, CommitContextFileSize); - if (rc.IsFailure()) return rc; + res = _fileSystem.CreateFile(in contextFilePath, CommitContextFileSize); + if (res.IsFailure()) return res.Miss(); - rc = _fileSystem.OpenFile(ref contextFile.Ref(), in contextFilePath, OpenMode.Read); - if (rc.IsFailure()) return rc; + res = _fileSystem.OpenFile(ref contextFile.Ref(), in contextFilePath, OpenMode.Read); + if (res.IsFailure()) return res.Miss(); } } using (var contextFile = new UniqueRef()) { - rc = _fileSystem.OpenFile(ref contextFile.Ref(), in contextFilePath, OpenMode.ReadWrite); - if (rc.IsFailure()) return rc; + res = _fileSystem.OpenFile(ref contextFile.Ref(), in contextFilePath, OpenMode.ReadWrite); + if (res.IsFailure()) return res.Miss(); _context.Version = CurrentCommitContextVersion; _context.State = CommitState.NotCommitted; @@ -579,15 +579,15 @@ internal class MultiCommitManager : IMultiCommitManager _context.Counter = counter; // Write the initial context to the file - rc = contextFile.Get.Write(0, SpanHelpers.AsByteSpan(ref _context), WriteOption.None); - if (rc.IsFailure()) return rc; + res = contextFile.Get.Write(0, SpanHelpers.AsByteSpan(ref _context), WriteOption.None); + if (res.IsFailure()) return res.Miss(); - rc = contextFile.Get.Flush(); - if (rc.IsFailure()) return rc; + res = contextFile.Get.Flush(); + if (res.IsFailure()) return res.Miss(); } - rc = _fileSystem.Commit(); - if (rc.IsFailure()) return rc; + res = _fileSystem.Commit(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -601,20 +601,20 @@ internal class MultiCommitManager : IMultiCommitManager { using (var contextFilePath = new Fs.Path()) { - Result rc = PathFunctions.SetUpFixedPath(ref contextFilePath.Ref(), CommitContextFileName); - if (rc.IsFailure()) return rc; + Result res = PathFunctions.SetUpFixedPath(ref contextFilePath.Ref(), CommitContextFileName); + if (res.IsFailure()) return res.Miss(); using var contextFile = new UniqueRef(); - rc = _fileSystem.OpenFile(ref contextFile.Ref(), in contextFilePath, OpenMode.ReadWrite); - if (rc.IsFailure()) return rc; + res = _fileSystem.OpenFile(ref contextFile.Ref(), in contextFilePath, OpenMode.ReadWrite); + if (res.IsFailure()) return res.Miss(); _context.State = CommitState.ProvisionallyCommitted; - rc = contextFile.Get.Write(0, SpanHelpers.AsByteSpan(ref _context), WriteOption.None); - if (rc.IsFailure()) return rc; + res = contextFile.Get.Write(0, SpanHelpers.AsByteSpan(ref _context), WriteOption.None); + if (res.IsFailure()) return res.Miss(); - rc = contextFile.Get.Flush(); - if (rc.IsFailure()) return rc; + res = contextFile.Get.Flush(); + if (res.IsFailure()) return res.Miss(); } return _fileSystem.Commit(); @@ -627,14 +627,14 @@ internal class MultiCommitManager : IMultiCommitManager public Result CommitDone() { using var contextFilePath = new Fs.Path(); - Result rc = PathFunctions.SetUpFixedPath(ref contextFilePath.Ref(), CommitContextFileName); - if (rc.IsFailure()) return rc; + Result res = PathFunctions.SetUpFixedPath(ref contextFilePath.Ref(), CommitContextFileName); + if (res.IsFailure()) return res.Miss(); - rc = _fileSystem.DeleteFile(in contextFilePath); - if (rc.IsFailure()) return rc; + res = _fileSystem.DeleteFile(in contextFilePath); + if (res.IsFailure()) return res.Miss(); - rc = _fileSystem.Commit(); - if (rc.IsFailure()) return rc; + res = _fileSystem.Commit(); + if (res.IsFailure()) return res.Miss(); _fileSystem = null; return Result.Success; diff --git a/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheManager.cs b/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheManager.cs index bafc9d90..ebe64091 100644 --- a/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheManager.cs +++ b/src/LibHac/FsSrv/Impl/SaveDataFileSystemCacheManager.cs @@ -137,8 +137,8 @@ public class SaveDataFileSystemCacheManager : IDisposable } else { - Result rc = fileSystem.Get.RollbackOnlyModified(); - if (rc.IsSuccess()) + Result res = fileSystem.Get.RollbackOnlyModified(); + if (res.IsSuccess()) { using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); diff --git a/src/LibHac/FsSrv/Impl/StorageInterfaceAdapter.cs b/src/LibHac/FsSrv/Impl/StorageInterfaceAdapter.cs index 37589d86..67a415b1 100644 --- a/src/LibHac/FsSrv/Impl/StorageInterfaceAdapter.cs +++ b/src/LibHac/FsSrv/Impl/StorageInterfaceAdapter.cs @@ -39,18 +39,18 @@ public class StorageInterfaceAdapter : IStorageSf if (destination.Size < size) return ResultFs.InvalidSize.Log(); - Result rc = Result.Success; + Result res = Result.Success; for (int tryNum = 0; tryNum < maxTryCount; tryNum++) { - rc = _baseStorage.Get.Read(offset, destination.Buffer.Slice(0, (int)size)); + res = _baseStorage.Get.Read(offset, destination.Buffer.Slice(0, (int)size)); // Retry on ResultDataCorrupted - if (!ResultFs.DataCorrupted.Includes(rc)) + if (!ResultFs.DataCorrupted.Includes(res)) break; } - return rc; + return res; } public Result Write(long offset, InBuffer source, long size) @@ -94,17 +94,17 @@ public class StorageInterfaceAdapter : IStorageSf { Unsafe.SkipInit(out QueryRangeInfo info); - Result rc = _baseStorage.Get.OperateRange(SpanHelpers.AsByteSpan(ref info), OperationId.QueryRange, + Result res = _baseStorage.Get.OperateRange(SpanHelpers.AsByteSpan(ref info), OperationId.QueryRange, offset, size, ReadOnlySpan.Empty); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); rangeInfo.Merge(in info); } else if (operationId == (int)OperationId.InvalidateCache) { - Result rc = _baseStorage.Get.OperateRange(Span.Empty, OperationId.InvalidateCache, offset, size, + Result res = _baseStorage.Get.OperateRange(Span.Empty, OperationId.InvalidateCache, offset, size, ReadOnlySpan.Empty); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); } return Result.Success; diff --git a/src/LibHac/FsSrv/Impl/Utility.cs b/src/LibHac/FsSrv/Impl/Utility.cs index 75894983..576872a0 100644 --- a/src/LibHac/FsSrv/Impl/Utility.cs +++ b/src/LibHac/FsSrv/Impl/Utility.cs @@ -26,8 +26,8 @@ internal static class Utility // Check if the directory exists using var dir = new UniqueRef(); - Result rc = baseFileSystem.Get.OpenDirectory(ref dir.Ref(), rootPath, OpenDirectoryMode.Directory); - if (rc.IsFailure()) return rc; + Result res = baseFileSystem.Get.OpenDirectory(ref dir.Ref(), rootPath, OpenDirectoryMode.Directory); + if (res.IsFailure()) return res.Miss(); dir.Reset(); @@ -35,8 +35,8 @@ internal static class Utility if (!fs.HasValue) return ResultFs.AllocationMemoryFailedInSubDirectoryFileSystemCreatorA.Log(); - rc = fs.Get.Initialize(in rootPath); - if (rc.IsFailure()) return rc; + res = fs.Get.Initialize(in rootPath); + if (res.IsFailure()) return res.Miss(); outSubDirFileSystem.SetByMove(ref fs.Ref()); @@ -54,8 +54,8 @@ internal static class Utility } // Ensure the path exists or check if it's a directory - Result rc = FsSystem.Utility.EnsureDirectory(baseFileSystem.Get, in rootPath); - if (rc.IsFailure()) return rc; + Result res = FsSystem.Utility.EnsureDirectory(baseFileSystem.Get, in rootPath); + if (res.IsFailure()) return res.Miss(); return CreateSubDirectoryFileSystem(ref outFileSystem, ref baseFileSystem, rootPath); } diff --git a/src/LibHac/FsSrv/NcaFileSystemService.cs b/src/LibHac/FsSrv/NcaFileSystemService.cs index 152cba2f..e3c232e4 100644 --- a/src/LibHac/FsSrv/NcaFileSystemService.cs +++ b/src/LibHac/FsSrv/NcaFileSystemService.cs @@ -77,8 +77,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager using var scopedContext = new ScopedStorageLayoutTypeSetter(storageFlag); // Get the program info for the caller and verify permissions - Result rc = GetProgramInfo(out ProgramInfo callerProgramInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo callerProgramInfo); + if (res.IsFailure()) return res.Miss(); if (fsType != FileSystemProxyType.Manual) { @@ -102,8 +102,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager return ResultFs.PermissionDenied.Log(); // Get the program info for the owner of the file system being opened - rc = GetProgramInfoByProgramId(out ProgramInfo ownerProgramInfo, programId.Value); - if (rc.IsFailure()) return rc; + res = GetProgramInfoByProgramId(out ProgramInfo ownerProgramInfo, programId.Value); + if (res.IsFailure()) return res.Miss(); // Try to find the path to the original version of the file system using var originalPath = new Path(); @@ -127,9 +127,9 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager return originalResult; // There is an original version and no patch version. Open the original directly - rc = _serviceImpl.OpenFileSystem(ref fileSystem.Ref(), in originalPath, fsType, programId.Value, + res = _serviceImpl.OpenFileSystem(ref fileSystem.Ref(), in originalPath, fsType, programId.Value, isDirectory); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); } else { @@ -141,9 +141,9 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager : ref PathExtensions.GetNullRef(); // Open the file system using both the original and patch versions - rc = _serviceImpl.OpenFileSystemWithPatch(ref fileSystem.Ref(), in originalNcaPath, in patchPath, + res = _serviceImpl.OpenFileSystemWithPatch(ref fileSystem.Ref(), in originalNcaPath, in patchPath, fsType, programId.Value); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); } // Add all the file system wrappers @@ -231,8 +231,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager const StorageLayoutType storageFlag = StorageLayoutType.All; using var scopedContext = new ScopedStorageLayoutTypeSetter(storageFlag); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); AccessControl ac = programInfo.AccessControl; @@ -278,21 +278,21 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager bool canMountSystemDataPrivate = ac.GetAccessibilityFor(AccessibilityType.MountSystemDataPrivate).CanRead; using var pathNormalized = new Path(); - rc = pathNormalized.InitializeWithReplaceUnc(path.Str); - if (rc.IsFailure()) return rc; + res = pathNormalized.InitializeWithReplaceUnc(path.Str); + if (res.IsFailure()) return res.Miss(); var pathFlags = new PathFlags(); pathFlags.AllowWindowsPath(); pathFlags.AllowMountName(); - rc = pathNormalized.Normalize(pathFlags); - if (rc.IsFailure()) return rc; + res = pathNormalized.Normalize(pathFlags); + if (res.IsFailure()) return res.Miss(); bool isDirectory = PathUtility.IsDirectoryPath(in path); using var fileSystem = new SharedRef(); - rc = _serviceImpl.OpenFileSystem(ref fileSystem.Ref(), in pathNormalized, fsType, canMountSystemDataPrivate, + res = _serviceImpl.OpenFileSystem(ref fileSystem.Ref(), in pathNormalized, fsType, canMountSystemDataPrivate, id, isDirectory); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); // Add all the wrappers for the file system using var typeSetFileSystem = @@ -321,17 +321,17 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager public Result OpenDataFileSystemWithProgramIndex(ref SharedRef outFileSystem, byte programIndex) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); // Get the program ID of the program with the specified index if in a multi-program application - rc = _serviceImpl.ResolveRomReferenceProgramId(out ProgramId targetProgramId, programInfo.ProgramId, + res = _serviceImpl.ResolveRomReferenceProgramId(out ProgramId targetProgramId, programInfo.ProgramId, programIndex); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); using var fileSystem = new SharedRef(); - rc = OpenDataFileSystemCore(ref fileSystem.Ref(), out _, targetProgramId.Value, programInfo.StorageId); - if (rc.IsFailure()) return rc; + res = OpenDataFileSystemCore(ref fileSystem.Ref(), out _, targetProgramId.Value, programInfo.StorageId); + if (res.IsFailure()) return res.Miss(); // Verify the caller has access to the file system if (targetProgramId != programInfo.ProgramId && @@ -363,21 +363,21 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.All); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.GetRightsId)) return ResultFs.PermissionDenied.Log(); using var programPath = new Path(); - rc = _serviceImpl.ResolveProgramPath(out bool isDirectory, ref programPath.Ref(), programId, storageId); - if (rc.IsFailure()) return rc; + res = _serviceImpl.ResolveProgramPath(out bool isDirectory, ref programPath.Ref(), programId, storageId); + if (res.IsFailure()) return res.Miss(); if (isDirectory) return ResultFs.TargetNotFound.Log(); - rc = _serviceImpl.GetRightsId(out RightsId rightsId, out _, in programPath, programId); - if (rc.IsFailure()) return rc; + res = _serviceImpl.GetRightsId(out RightsId rightsId, out _, in programPath, programId); + if (res.IsFailure()) return res.Miss(); outRightsId = rightsId; @@ -391,28 +391,28 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.All); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.GetRightsId)) return ResultFs.PermissionDenied.Log(); using var pathNormalized = new Path(); - rc = pathNormalized.Initialize(path.Str); - if (rc.IsFailure()) return rc; + res = pathNormalized.Initialize(path.Str); + if (res.IsFailure()) return res.Miss(); var pathFlags = new PathFlags(); pathFlags.AllowWindowsPath(); pathFlags.AllowMountName(); - rc = pathNormalized.Normalize(pathFlags); - if (rc.IsFailure()) return rc; + res = pathNormalized.Normalize(pathFlags); + if (res.IsFailure()) return res.Miss(); if (PathUtility.IsDirectoryPath(in path)) return ResultFs.TargetNotFound.Log(); - rc = _serviceImpl.GetRightsId(out RightsId rightsId, out byte keyGeneration, in pathNormalized, + res = _serviceImpl.GetRightsId(out RightsId rightsId, out byte keyGeneration, in pathNormalized, new ProgramId(checkThroughProgramId)); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); outRightsId = rightsId; outKeyGeneration = keyGeneration; @@ -430,15 +430,15 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager using var scopedContext = new ScopedStorageLayoutTypeSetter(storageFlag); using var programPath = new Path(); - Result rc = _serviceImpl.ResolveRomPath(out bool isDirectory, ref programPath.Ref(), programId, storageId); - if (rc.IsFailure()) return rc; + Result res = _serviceImpl.ResolveRomPath(out bool isDirectory, ref programPath.Ref(), programId, storageId); + if (res.IsFailure()) return res.Miss(); isHostFs = Utility.IsHostFsMountName(programPath.GetString()); using var fileSystem = new SharedRef(); - rc = _serviceImpl.OpenDataFileSystem(ref fileSystem.Ref(), in programPath, FileSystemProxyType.Rom, + res = _serviceImpl.OpenDataFileSystem(ref fileSystem.Ref(), in programPath, FileSystemProxyType.Rom, programId, isDirectory); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); // Add all the file system wrappers using var typeSetFileSystem = @@ -455,8 +455,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager StorageLayoutType storageFlag = contentStorageId == ContentStorageId.System ? StorageLayoutType.Bis : StorageLayoutType.All; using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(storageFlag); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); Accessibility accessibility = programInfo.AccessControl.GetAccessibilityFor(AccessibilityType.MountContentStorage); @@ -465,8 +465,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager return ResultFs.PermissionDenied.Log(); using var fileSystem = new SharedRef(); - rc = _serviceImpl.OpenContentStorageFileSystem(ref fileSystem.Ref(), contentStorageId); - if (rc.IsFailure()) return rc; + res = _serviceImpl.OpenContentStorageFileSystem(ref fileSystem.Ref(), contentStorageId); + if (res.IsFailure()) return res.Miss(); // Add all the file system wrappers using var typeSetFileSystem = @@ -485,8 +485,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager public Result RegisterExternalKey(in RightsId rightsId, in AccessKey accessKey) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.RegisterExternalKey)) return ResultFs.PermissionDenied.Log(); @@ -496,8 +496,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager public Result UnregisterExternalKey(in RightsId rightsId) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.RegisterExternalKey)) return ResultFs.PermissionDenied.Log(); @@ -507,8 +507,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager public Result UnregisterAllExternalKey() { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.RegisterExternalKey)) return ResultFs.PermissionDenied.Log(); @@ -518,8 +518,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager public Result RegisterUpdatePartition() { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.RegisterUpdatePartition)) return ResultFs.PermissionDenied.Log(); @@ -527,8 +527,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager ulong targetProgramId = programInfo.ProgramIdValue; using var programPath = new Path(); - rc = _serviceImpl.ResolveRomPath(out _, ref programPath.Ref(), targetProgramId, programInfo.StorageId); - if (rc.IsFailure()) return rc; + res = _serviceImpl.ResolveRomPath(out _, ref programPath.Ref(), targetProgramId, programInfo.StorageId); + if (res.IsFailure()) return res.Miss(); return _serviceImpl.RegisterUpdatePartition(targetProgramId, in programPath); } @@ -538,8 +538,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager var storageFlag = StorageLayoutType.All; using var scopedLayoutType = new ScopedStorageLayoutTypeSetter(storageFlag); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); Accessibility accessibility = programInfo.AccessControl.GetAccessibilityFor(AccessibilityType.MountRegisteredUpdatePartition); @@ -547,8 +547,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager return ResultFs.PermissionDenied.Log(); using var fileSystem = new SharedRef(); - rc = _serviceImpl.OpenRegisteredUpdatePartition(ref fileSystem.Ref()); - if (rc.IsFailure()) return rc; + res = _serviceImpl.OpenRegisteredUpdatePartition(ref fileSystem.Ref()); + if (res.IsFailure()) return res.Miss(); // Add all the file system wrappers using var typeSetFileSystem = @@ -572,8 +572,8 @@ internal class NcaFileSystemService : IRomFileSystemAccessFailureManager public Result SetSdCardEncryptionSeed(in EncryptionSeed encryptionSeed) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.SetEncryptionSeed)) return ResultFs.PermissionDenied.Log(); diff --git a/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs b/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs index 478bbb87..9c5d95de 100644 --- a/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs +++ b/src/LibHac/FsSrv/NcaFileSystemServiceImpl.cs @@ -94,9 +94,9 @@ public class NcaFileSystemServiceImpl // Open the root filesystem based on the path's mount name using var baseFileSystem = new SharedRef(); - Result rc = ParseMountName(ref currentPath, ref baseFileSystem.Ref(), out bool shouldContinue, + Result res = ParseMountName(ref currentPath, ref baseFileSystem.Ref(), out bool shouldContinue, out MountInfo mountNameInfo); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); // Don't continue if the rest of the path is empty if (!shouldContinue) @@ -104,18 +104,18 @@ public class NcaFileSystemServiceImpl if (type == FileSystemProxyType.Logo && mountNameInfo.IsGameCard) { - rc = _config.BaseFsService.OpenGameCardFileSystem(ref outFileSystem, (uint)mountNameInfo.GcHandle, + res = _config.BaseFsService.OpenGameCardFileSystem(ref outFileSystem, (uint)mountNameInfo.GcHandle, GameCardPartition.Logo); - if (rc.IsSuccess()) + if (res.IsSuccess()) return Result.Success; - if (!ResultFs.PartitionNotFound.Includes(rc)) - return rc; + if (!ResultFs.PartitionNotFound.Includes(res)) + return res; } - rc = CheckDirOrNcaOrNsp(ref currentPath, out isDirectory); - if (rc.IsFailure()) return rc; + res = CheckDirOrNcaOrNsp(ref currentPath, out isDirectory); + if (res.IsFailure()) return res.Miss(); if (isDirectory) { @@ -123,17 +123,17 @@ public class NcaFileSystemServiceImpl return ResultFs.PermissionDenied.Log(); using var directoryPath = new Path(); - rc = directoryPath.InitializeWithNormalization(currentPath.Value); - if (rc.IsFailure()) return rc; + res = directoryPath.InitializeWithNormalization(currentPath.Value); + if (res.IsFailure()) return res.Miss(); if (type == FileSystemProxyType.Manual) { using var hostFileSystem = new SharedRef(); using var readOnlyFileSystem = new SharedRef(); - rc = ParseDirWithPathCaseNormalizationOnCaseSensitiveHostFs(ref hostFileSystem.Ref(), + res = ParseDirWithPathCaseNormalizationOnCaseSensitiveHostFs(ref hostFileSystem.Ref(), in directoryPath); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); readOnlyFileSystem.Reset(new ReadOnlyFileSystem(ref hostFileSystem.Ref())); outFileSystem.SetByMove(ref readOnlyFileSystem.Ref()); @@ -146,9 +146,9 @@ public class NcaFileSystemServiceImpl using var nspFileSystem = new SharedRef(); using SharedRef tempFileSystem = SharedRef.CreateCopy(in baseFileSystem); - rc = ParseNsp(ref currentPath, ref nspFileSystem.Ref(), ref baseFileSystem.Ref()); + res = ParseNsp(ref currentPath, ref nspFileSystem.Ref(), ref baseFileSystem.Ref()); - if (rc.IsSuccess()) + if (res.IsSuccess()) { // Must be the end of the path to open Application Package FS type if (currentPath.Value.At(0) == 0) @@ -172,13 +172,13 @@ public class NcaFileSystemServiceImpl ulong openProgramId = mountNameInfo.IsHostFs ? ulong.MaxValue : id; - rc = ParseNca(ref currentPath, out Nca nca, ref baseFileSystem.Ref(), openProgramId); - if (rc.IsFailure()) return rc; + res = ParseNca(ref currentPath, out Nca nca, ref baseFileSystem.Ref(), openProgramId); + if (res.IsFailure()) return res.Miss(); using var ncaSectionStorage = new SharedRef(); - rc = OpenStorageByContentType(ref ncaSectionStorage.Ref(), nca, out NcaFormatType fsType, type, + res = OpenStorageByContentType(ref ncaSectionStorage.Ref(), nca, out NcaFormatType fsType, type, mountNameInfo.IsGameCard, canMountSystemDataPrivate); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); switch (fsType) { @@ -207,9 +207,9 @@ public class NcaFileSystemServiceImpl in Path originalNcaPath, in Path currentNcaPath, FileSystemProxyType fsType, ulong id) { using var romFsStorage = new SharedRef(); - Result rc = OpenStorageWithPatch(ref romFsStorage.Ref(), out Unsafe.NullRef(), in originalNcaPath, + Result res = OpenStorageWithPatch(ref romFsStorage.Ref(), out Unsafe.NullRef(), in originalNcaPath, in currentNcaPath, fsType, id); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return _config.RomFsCreator.Create(ref outFileSystem, ref romFsStorage.Ref()); } @@ -218,22 +218,22 @@ public class NcaFileSystemServiceImpl ContentStorageId contentStorageId) { using var fileSystem = new SharedRef(); - Result rc; + Result res; // Open the appropriate base file system for the content storage ID switch (contentStorageId) { case ContentStorageId.System: - rc = _config.BaseFsService.OpenBisFileSystem(ref fileSystem.Ref(), BisPartitionId.System); - if (rc.IsFailure()) return rc; + res = _config.BaseFsService.OpenBisFileSystem(ref fileSystem.Ref(), BisPartitionId.System); + if (res.IsFailure()) return res.Miss(); break; case ContentStorageId.User: - rc = _config.BaseFsService.OpenBisFileSystem(ref fileSystem.Ref(), BisPartitionId.User); - if (rc.IsFailure()) return rc; + res = _config.BaseFsService.OpenBisFileSystem(ref fileSystem.Ref(), BisPartitionId.User); + if (res.IsFailure()) return res.Miss(); break; case ContentStorageId.SdCard: - rc = _config.BaseFsService.OpenSdCardProxyFileSystem(ref fileSystem.Ref()); - if (rc.IsFailure()) return rc; + res = _config.BaseFsService.OpenSdCardProxyFileSystem(ref fileSystem.Ref()); + if (res.IsFailure()) return res.Miss(); break; default: return ResultFs.InvalidArgument.Log(); @@ -255,24 +255,24 @@ public class NcaFileSystemServiceImpl } using var contentStoragePath = new Path(); - rc = PathFunctions.SetUpFixedPath(ref contentStoragePath.Ref(), contentStoragePathBuffer); - if (rc.IsFailure()) return rc; + res = PathFunctions.SetUpFixedPath(ref contentStoragePath.Ref(), contentStoragePathBuffer); + if (res.IsFailure()) return res.Miss(); // Make sure the content storage path exists - rc = Utility.EnsureDirectory(fileSystem.Get, in contentStoragePath); - if (rc.IsFailure()) return rc; + res = Utility.EnsureDirectory(fileSystem.Get, in contentStoragePath); + if (res.IsFailure()) return res.Miss(); using var subDirFs = new SharedRef(); - rc = _config.SubDirectoryFsCreator.Create(ref subDirFs.Ref(), ref fileSystem.Ref(), in contentStoragePath); - if (rc.IsFailure()) return rc; + res = _config.SubDirectoryFsCreator.Create(ref subDirFs.Ref(), ref fileSystem.Ref(), in contentStoragePath); + if (res.IsFailure()) return res.Miss(); // Only content on the SD card is encrypted if (contentStorageId == ContentStorageId.SdCard) { using SharedRef tempFileSystem = SharedRef.CreateMove(ref subDirFs.Ref()); - rc = _config.EncryptedFsCreator.Create(ref subDirFs.Ref(), ref tempFileSystem.Ref(), + res = _config.EncryptedFsCreator.Create(ref subDirFs.Ref(), ref tempFileSystem.Ref(), IEncryptedFileSystemCreator.KeyId.Content, in _encryptionSeed); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); } outFileSystem.SetByMove(ref subDirFs.Ref()); @@ -351,8 +351,8 @@ public class NcaFileSystemServiceImpl path = path.Slice(8); - Result rc = _config.BaseFsService.OpenGameCardFileSystem(ref outFileSystem, (uint)handle, partition); - if (rc.IsFailure()) return rc; + Result res = _config.BaseFsService.OpenGameCardFileSystem(ref outFileSystem, (uint)handle, partition); + if (res.IsFailure()) return res.Miss(); info.GcHandle = handle; info.IsGameCard = true; @@ -364,8 +364,8 @@ public class NcaFileSystemServiceImpl { path = path.Slice(CommonPaths.ContentStorageSystemMountName.Length); - Result rc = OpenContentStorageFileSystem(ref outFileSystem, ContentStorageId.System); - if (rc.IsFailure()) return rc; + Result res = OpenContentStorageFileSystem(ref outFileSystem, ContentStorageId.System); + if (res.IsFailure()) return res.Miss(); info.CanMountNca = true; } @@ -375,8 +375,8 @@ public class NcaFileSystemServiceImpl { path = path.Slice(CommonPaths.ContentStorageUserMountName.Length); - Result rc = OpenContentStorageFileSystem(ref outFileSystem, ContentStorageId.User); - if (rc.IsFailure()) return rc; + Result res = OpenContentStorageFileSystem(ref outFileSystem, ContentStorageId.User); + if (res.IsFailure()) return res.Miss(); info.CanMountNca = true; } @@ -386,8 +386,8 @@ public class NcaFileSystemServiceImpl { path = path.Slice(CommonPaths.ContentStorageSdCardMountName.Length); - Result rc = OpenContentStorageFileSystem(ref outFileSystem, ContentStorageId.SdCard); - if (rc.IsFailure()) return rc; + Result res = OpenContentStorageFileSystem(ref outFileSystem, ContentStorageId.SdCard); + if (res.IsFailure()) return res.Miss(); info.CanMountNca = true; } @@ -397,8 +397,8 @@ public class NcaFileSystemServiceImpl { path = path.Slice(CommonPaths.BisCalibrationFilePartitionMountName.Length); - Result rc = _config.BaseFsService.OpenBisFileSystem(ref outFileSystem, BisPartitionId.CalibrationFile); - if (rc.IsFailure()) return rc; + Result res = _config.BaseFsService.OpenBisFileSystem(ref outFileSystem, BisPartitionId.CalibrationFile); + if (res.IsFailure()) return res.Miss(); } else if (StringUtils.Compare(path, CommonPaths.BisSafeModePartitionMountName, @@ -406,8 +406,8 @@ public class NcaFileSystemServiceImpl { path = path.Slice(CommonPaths.BisSafeModePartitionMountName.Length); - Result rc = _config.BaseFsService.OpenBisFileSystem(ref outFileSystem, BisPartitionId.SafeMode); - if (rc.IsFailure()) return rc; + Result res = _config.BaseFsService.OpenBisFileSystem(ref outFileSystem, BisPartitionId.SafeMode); + if (res.IsFailure()) return res.Miss(); } else if (StringUtils.Compare(path, CommonPaths.BisUserPartitionMountName, @@ -415,8 +415,8 @@ public class NcaFileSystemServiceImpl { path = path.Slice(CommonPaths.BisUserPartitionMountName.Length); - Result rc = _config.BaseFsService.OpenBisFileSystem(ref outFileSystem, BisPartitionId.User); - if (rc.IsFailure()) return rc; + Result res = _config.BaseFsService.OpenBisFileSystem(ref outFileSystem, BisPartitionId.User); + if (res.IsFailure()) return res.Miss(); } else if (StringUtils.Compare(path, CommonPaths.BisSystemPartitionMountName, @@ -424,8 +424,8 @@ public class NcaFileSystemServiceImpl { path = path.Slice(CommonPaths.BisSystemPartitionMountName.Length); - Result rc = _config.BaseFsService.OpenBisFileSystem(ref outFileSystem, BisPartitionId.System); - if (rc.IsFailure()) return rc; + Result res = _config.BaseFsService.OpenBisFileSystem(ref outFileSystem, BisPartitionId.System); + if (res.IsFailure()) return res.Miss(); } else if (StringUtils.Compare(path, CommonPaths.SdCardFileSystemMountName, @@ -433,8 +433,8 @@ public class NcaFileSystemServiceImpl { path = path.Slice(CommonPaths.SdCardFileSystemMountName.Length); - Result rc = _config.BaseFsService.OpenSdCardProxyFileSystem(ref outFileSystem); - if (rc.IsFailure()) return rc; + Result res = _config.BaseFsService.OpenSdCardProxyFileSystem(ref outFileSystem); + if (res.IsFailure()) return res.Miss(); } else if (StringUtils.Compare(path, CommonPaths.HostRootFileSystemMountName, @@ -443,14 +443,14 @@ public class NcaFileSystemServiceImpl path = path.Slice(CommonPaths.HostRootFileSystemMountName.Length); using var rootPathEmpty = new Path(); - Result rc = rootPathEmpty.InitializeAsEmpty(); - if (rc.IsFailure()) return rc; + Result res = rootPathEmpty.InitializeAsEmpty(); + if (res.IsFailure()) return res.Miss(); info.IsHostFs = true; info.CanMountNca = true; - rc = OpenHostFileSystem(ref outFileSystem, in rootPathEmpty, openCaseSensitive: false); - if (rc.IsFailure()) return rc; + res = OpenHostFileSystem(ref outFileSystem, in rootPathEmpty, openCaseSensitive: false); + if (res.IsFailure()) return res.Miss(); } else if (StringUtils.Compare(path, CommonPaths.RegisteredUpdatePartitionMountName, @@ -519,8 +519,8 @@ public class NcaFileSystemServiceImpl ref SharedRef baseFileSystem, FileSystemProxyType fsType, bool preserveUnc) { using var fileSystem = new SharedRef(); - Result rc = _config.SubDirectoryFsCreator.Create(ref fileSystem.Ref(), ref baseFileSystem, in path); - if (rc.IsFailure()) return rc; + Result res = _config.SubDirectoryFsCreator.Create(ref fileSystem.Ref(), ref baseFileSystem, in path); + if (res.IsFailure()) return res.Miss(); return ParseContentTypeForDirectory(ref outContentFileSystem, ref fileSystem.Ref(), fsType); } @@ -531,19 +531,19 @@ public class NcaFileSystemServiceImpl using var pathRoot = new Path(); using var pathData = new Path(); - Result rc = PathFunctions.SetUpFixedPath(ref pathData.Ref(), + Result res = PathFunctions.SetUpFixedPath(ref pathData.Ref(), new[] { (byte)'/', (byte)'d', (byte)'a', (byte)'t', (byte)'a' }); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = pathRoot.Combine(in path, in pathData); - if (rc.IsFailure()) return rc; + res = pathRoot.Combine(in path, in pathData); + if (res.IsFailure()) return res.Miss(); - rc = _config.TargetManagerFsCreator.NormalizeCaseOfPath(out bool isSupported, ref pathRoot.Ref()); - if (rc.IsFailure()) return rc; + res = _config.TargetManagerFsCreator.NormalizeCaseOfPath(out bool isSupported, ref pathRoot.Ref()); + if (res.IsFailure()) return res.Miss(); - rc = _config.TargetManagerFsCreator.Create(ref outFileSystem, in pathRoot, isSupported, false, + res = _config.TargetManagerFsCreator.Create(ref outFileSystem, in pathRoot, isSupported, false, Result.Success); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -584,23 +584,23 @@ public class NcaFileSystemServiceImpl nspPathLen += 4; using var pathNsp = new Path(); - Result rc = pathNsp.InitializeWithNormalization(path, nspPathLen); - if (rc.IsFailure()) return rc; + Result res = pathNsp.InitializeWithNormalization(path, nspPathLen); + if (res.IsFailure()) return res.Miss(); using var nspFileStorage = new SharedRef(new FileStorageBasedFileSystem()); - rc = nspFileStorage.Get.Initialize(ref baseFileSystem, in pathNsp, OpenMode.Read); - if (rc.IsFailure()) return rc; + res = nspFileStorage.Get.Initialize(ref baseFileSystem, in pathNsp, OpenMode.Read); + if (res.IsFailure()) return res.Miss(); using SharedRef tempStorage = SharedRef.CreateMove(ref nspFileStorage.Ref()); - rc = _config.PartitionFsCreator.Create(ref outFileSystem, ref tempStorage.Ref()); + res = _config.PartitionFsCreator.Create(ref outFileSystem, ref tempStorage.Ref()); - if (rc.IsSuccess()) + if (res.IsSuccess()) { path = path.Slice(nspPathLen); } - return rc; + return res; } private Result ParseNca(ref U8Span path, out Nca nca, ref SharedRef baseFileSystem, ulong ncaId) @@ -611,14 +611,14 @@ public class NcaFileSystemServiceImpl var ncaFileStorage = new FileStorageBasedFileSystem(); using var pathNca = new Path(); - Result rc = pathNca.InitializeWithNormalization(path); - if (rc.IsFailure()) return rc; + Result res = pathNca.InitializeWithNormalization(path); + if (res.IsFailure()) return res.Miss(); - rc = ncaFileStorage.Initialize(ref baseFileSystem, in pathNca, OpenMode.Read); - if (rc.IsFailure()) return rc; + res = ncaFileStorage.Initialize(ref baseFileSystem, in pathNca, OpenMode.Read); + if (res.IsFailure()) return res.Miss(); - rc = _config.StorageOnNcaCreator.OpenNca(out Nca ncaTemp, ncaFileStorage); - if (rc.IsFailure()) return rc; + res = _config.StorageOnNcaCreator.OpenNca(out Nca ncaTemp, ncaFileStorage); + if (res.IsFailure()) return res.Miss(); if (ncaId == ulong.MaxValue) { @@ -668,15 +668,15 @@ public class NcaFileSystemServiceImpl using var subDirFs = new SharedRef(); using var directoryPath = new Path(); - Result rc = PathFunctions.SetUpFixedPath(ref directoryPath.Ref(), dirName); - if (rc.IsFailure()) return rc; + Result res = PathFunctions.SetUpFixedPath(ref directoryPath.Ref(), dirName); + if (res.IsFailure()) return res.Miss(); if (directoryPath.IsEmpty()) return ResultFs.InvalidArgument.Log(); // Open the subdirectory filesystem - rc = _config.SubDirectoryFsCreator.Create(ref subDirFs.Ref(), ref baseFileSystem, in directoryPath); - if (rc.IsFailure()) return rc; + res = _config.SubDirectoryFsCreator.Create(ref subDirFs.Ref(), ref baseFileSystem, in directoryPath); + if (res.IsFailure()) return res.Miss(); outFileSystem.SetByMove(ref subDirFs.Ref()); return Result.Success; @@ -691,8 +691,8 @@ public class NcaFileSystemServiceImpl return Result.Success; // ReSharper disable once UnusedVariable - Result rc = _externalKeyManager.Get(rightsId, out AccessKey accessKey); - if (rc.IsFailure()) return rc; + Result res = _externalKeyManager.Get(rightsId, out AccessKey accessKey); + if (res.IsFailure()) return res.Miss(); // todo: Set key in nca reader @@ -747,15 +747,15 @@ public class NcaFileSystemServiceImpl if (nca.Header.DistributionType == DistributionType.GameCard && !isGameCard) return ResultFs.PermissionDenied.Log(); - Result rc = SetExternalKeyForRightsId(nca); - if (rc.IsFailure()) return rc; + Result res = SetExternalKeyForRightsId(nca); + if (res.IsFailure()) return res.Miss(); - rc = GetPartitionIndex(out int sectionIndex, fsProxyType); - if (rc.IsFailure()) return rc; + res = GetPartitionIndex(out int sectionIndex, fsProxyType); + if (res.IsFailure()) return res.Miss(); - rc = _config.StorageOnNcaCreator.Create(ref outNcaStorage, out NcaFsHeader fsHeader, nca, + res = _config.StorageOnNcaCreator.Create(ref outNcaStorage, out NcaFsHeader fsHeader, nca, sectionIndex, fsProxyType == FileSystemProxyType.Code); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); fsType = fsHeader.FormatType; return Result.Success; @@ -783,14 +783,14 @@ public class NcaFileSystemServiceImpl public Result ResolveProgramPath(out bool isDirectory, ref Path path, ProgramId programId, StorageId storageId) { - Result rc = _locationResolverSet.ResolveProgramPath(out isDirectory, ref path, programId, storageId); - if (rc.IsSuccess()) + Result res = _locationResolverSet.ResolveProgramPath(out isDirectory, ref path, programId, storageId); + if (res.IsSuccess()) return Result.Success; isDirectory = false; - rc = _locationResolverSet.ResolveDataPath(ref path, new DataId(programId.Value), storageId); - if (rc.IsSuccess()) + res = _locationResolverSet.ResolveDataPath(ref path, new DataId(programId.Value), storageId); + if (res.IsSuccess()) return Result.Success; return ResultFs.TargetNotFound.Log(); diff --git a/src/LibHac/FsSrv/ProgramRegistryService.cs b/src/LibHac/FsSrv/ProgramRegistryService.cs index ba2643c4..4ddec122 100644 --- a/src/LibHac/FsSrv/ProgramRegistryService.cs +++ b/src/LibHac/FsSrv/ProgramRegistryService.cs @@ -46,8 +46,8 @@ internal readonly struct ProgramIndexRegistryService // Verify the caller's permissions using (var programRegistry = new ProgramRegistryImpl(_fsServer)) { - Result rc = programRegistry.GetProgramInfo(out ProgramInfo programInfo, _processId); - if (rc.IsFailure()) return rc; + Result res = programRegistry.GetProgramInfo(out ProgramInfo programInfo, _processId); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.RegisterProgramIndexMapInfo)) return ResultFs.PermissionDenied.Log(); @@ -85,8 +85,8 @@ internal readonly struct ProgramIndexRegistryService UnsafeHelpers.SkipParamInit(out programIndex, out programCount); // No permissions are needed to call this method - Result rc = GetProgramInfo(out ProgramInfo programInfo, _processId); - if (rc.IsFailure()) return rc; + Result res = GetProgramInfo(out ProgramInfo programInfo, _processId); + if (res.IsFailure()) return res.Miss(); // Try to get map info for this process Optional mapInfo = _serviceImpl.GetProgramIndexMapInfo(programInfo.ProgramId); diff --git a/src/LibHac/FsSrv/SaveDataFileSystemService.cs b/src/LibHac/FsSrv/SaveDataFileSystemService.cs index c246fe1b..be0ba656 100644 --- a/src/LibHac/FsSrv/SaveDataFileSystemService.cs +++ b/src/LibHac/FsSrv/SaveDataFileSystemService.cs @@ -157,8 +157,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave } else { - Result rc = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, ownerId); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, ownerId); + if (res.IsFailure()) return res.Miss(); // If none of the above conditions apply, the program needs write access to the owner's save data. // The program also needs either permission to create any save data, or it must be creating its own @@ -210,8 +210,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { AccessControl accessControl = programInfo.AccessControl; - Result rc = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, extraDataGetter); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, extraDataGetter); + if (res.IsFailure()) return res.Miss(); // Note: This is correct. Even if a program only has read accessibility to a save data, // Nintendo allows opening it with read/write accessibility as of FS 14.0.0 @@ -254,8 +254,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave } // Otherwise the program needs the DeleteOwnSaveData permission and write access to the save - Result rc = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, extraDataGetter); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, extraDataGetter); + if (res.IsFailure()) return res.Miss(); if (accessControl.CanCall(OperationType.DeleteOwnSaveData) && accessibility.CanWrite) { @@ -277,9 +277,9 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave case SaveDataSpaceId.ProperSystem: case SaveDataSpaceId.SafeMode: { - Result rc = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, + Result res = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, extraDataGetter); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); // The program needs the ExtendSystemSaveData permission and either one of // read/write access to the save or the ExtendOthersSystemSaveData permission @@ -297,9 +297,9 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { bool canAccess = accessControl.CanCall(OperationType.ExtendSaveData); - Result rc = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, + Result res = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, extraDataGetter); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); if (attribute.ProgramId == programInfo.ProgramId || accessibility.CanRead) { @@ -331,8 +331,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave bool canAccess = accessControl.CanCall(OperationType.ReadSaveDataFileSystemExtraData); - Result rc = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, extraDataGetter); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, extraDataGetter); + if (res.IsFailure()) return res.Miss(); SaveDataExtraData emptyMask = default; SaveDataExtraData maskWithoutRestoreFlag = mask; @@ -378,18 +378,18 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave if (SaveDataProperties.IsSystemSaveData(attribute.Type)) { - Result rc = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, + Result res = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, extraDataGetter); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); canAccess |= accessibility.CanWrite; } if ((mask.Flags & ~SaveDataFlags.Restore) == 0) { - Result rc = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, + Result res = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, extraDataGetter); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); canAccess |= accessibility.CanWrite; } @@ -463,8 +463,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave public static Result CheckOpenProhibiter(ProgramId programId, ProgramInfo programInfo) { - Result rc = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, programId.Value); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetAccessibilityForSaveData(out Accessibility accessibility, programInfo, programId.Value); + if (res.IsFailure()) return res.Miss(); bool canAccess = programInfo.AccessControl.CanCall(OperationType.OpenSaveDataTransferProhibiter); @@ -500,16 +500,16 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { UnsafeHelpers.SkipParamInit(out accessibility); - Result rc = extraDataGetter(out SaveDataExtraData extraData); - if (rc.IsFailure()) + Result res = extraDataGetter(out SaveDataExtraData extraData); + if (res.IsFailure()) { - if (ResultFs.TargetNotFound.Includes(rc)) + if (ResultFs.TargetNotFound.Includes(res)) { accessibility = new Accessibility(false, false); return Result.Success; } - return rc; + return res; } // Allow access when opening a directory save FS on a dev console @@ -619,15 +619,15 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.NonGameCard); using var fileSystem = new SharedRef(); - Result rc = _serviceImpl.OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + Result res = _serviceImpl.OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); using var pathRoot = new Path(); - rc = PathFunctions.SetUpFixedPath(ref pathRoot.Ref(), new[] { (byte)'/' }); - if (rc.IsFailure()) return rc.Miss(); + res = PathFunctions.SetUpFixedPath(ref pathRoot.Ref(), new[] { (byte)'/' }); + if (res.IsFailure()) return res.Miss(); fileSystem.Get.GetFreeSpaceSize(out long freeSpaceSize, in pathRoot); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); outFreeSpaceSize = freeSpaceSize; return Result.Success; @@ -637,8 +637,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.Bis); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); // This function only operates on the system save data space, so the caller // must have permissions to delete system save data @@ -653,8 +653,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave bool success = false; using var accessor = new UniqueRef(); - rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), SaveDataSpaceId.System); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), SaveDataSpaceId.System); + if (res.IsFailure()) return res.Miss(); ReadOnlySpan ids = MemoryMarshal.Cast(saveDataIds.Buffer); @@ -663,12 +663,12 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave // Try to set the state of all the save IDs as being marked for deletion. for (int i = 0; i < ids.Length; i++) { - rc = accessor.Get.GetInterface().SetState(ids[i], SaveDataState.MarkedForDeletion); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().SetState(ids[i], SaveDataState.MarkedForDeletion); + if (res.IsFailure()) return res.Miss(); } - rc = accessor.Get.GetInterface().Commit(); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().Commit(); + if (res.IsFailure()) return res.Miss(); success = true; return Result.Success; @@ -678,8 +678,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave // Rollback the operation if something goes wrong. if (!success) { - rc = accessor.Get.GetInterface().Rollback(); - if (rc.IsFailure()) + res = accessor.Get.GetInterface().Rollback(); + if (res.IsFailure()) { Hos.Diag.Impl.LogImpl(Log.EmptyModuleName, LogSeverity.Info, "[fs] Error: Failed to rollback save data indexer.\n".ToU8Span()); @@ -698,15 +698,15 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave private Result DeleteSaveDataFileSystemCore(SaveDataSpaceId spaceId, ulong saveDataId, bool wipeSaveFile) { // Delete the save data's meta files - Result rc = _serviceImpl.DeleteAllSaveDataMetas(saveDataId, spaceId); - if (rc.IsFailure() && !ResultFs.PathNotFound.Includes(rc)) - return rc.Miss(); + Result res = _serviceImpl.DeleteAllSaveDataMetas(saveDataId, spaceId); + if (res.IsFailure() && !ResultFs.PathNotFound.Includes(res)) + return res.Miss(); // Delete the actual save data. using Path saveDataRootPath = _saveDataRootPath.DangerousGetPath(); - rc = _serviceImpl.DeleteSaveDataFileSystem(spaceId, saveDataId, wipeSaveFile, in saveDataRootPath); - if (rc.IsFailure() && !ResultFs.PathNotFound.Includes(rc)) - return rc.Miss(); + res = _serviceImpl.DeleteSaveDataFileSystem(spaceId, saveDataId, wipeSaveFile, in saveDataRootPath); + if (res.IsFailure() && !ResultFs.PathNotFound.Includes(res)) + return res.Miss(); return Result.Success; } @@ -723,11 +723,11 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave if (saveDataId != SaveIndexerId) { using var accessor = new UniqueRef(); - Result rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + Result res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().GetValue(out SaveDataIndexerValue value, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().GetValue(out SaveDataIndexerValue value, saveDataId); + if (res.IsFailure()) return res.Miss(); if (value.SpaceId != ConvertToRealSpaceId(spaceId)) return ResultFs.TargetNotFound.Log(); @@ -741,16 +741,16 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.NonGameCard); - Result rs = GetSaveDataInfo(out SaveDataInfo info, spaceId, in attribute); - if (rs.IsFailure()) return rs; + Result res = GetSaveDataInfo(out SaveDataInfo info, spaceId, in attribute); + if (res.IsFailure()) return res; return DeleteSaveDataFileSystemBySaveDataSpaceIdCore(spaceId, info.SaveDataId).Ret(); } private Result DeleteSaveDataFileSystemCommon(SaveDataSpaceId spaceId, ulong saveDataId) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); using var accessor = new UniqueRef(); @@ -758,8 +758,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave if (saveDataId != SaveIndexerId) { - rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); // Get the actual space ID of this save. if (spaceId == SaveDataSpaceId.ProperSystem || spaceId == SaveDataSpaceId.SafeMode) @@ -768,29 +768,29 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave } else { - rc = accessor.Get.GetInterface().GetValue(out SaveDataIndexerValue value, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().GetValue(out SaveDataIndexerValue value, saveDataId); + if (res.IsFailure()) return res.Miss(); targetSpaceId = value.SpaceId; } // Check if the caller has permission to delete this save. - rc = accessor.Get.GetInterface().GetKey(out SaveDataAttribute key, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().GetKey(out SaveDataAttribute key, saveDataId); + if (res.IsFailure()) return res.Miss(); Result GetExtraData(out SaveDataExtraData data) => _serviceImpl.ReadSaveDataFileSystemExtraData(out data, targetSpaceId, saveDataId, key.Type, _saveDataRootPath.DangerousGetPath()); - rc = SaveDataAccessibilityChecker.CheckDelete(in key, programInfo, GetExtraData); - if (rc.IsFailure()) return rc.Miss(); + res = SaveDataAccessibilityChecker.CheckDelete(in key, programInfo, GetExtraData); + if (res.IsFailure()) return res.Miss(); // Pre-delete checks successful. Put the save in the Processing state until deletion is finished. - rc = accessor.Get.GetInterface().SetState(saveDataId, SaveDataState.Processing); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().SetState(saveDataId, SaveDataState.Processing); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().Commit(); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().Commit(); + if (res.IsFailure()) return res.Miss(); } else { @@ -802,18 +802,18 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave } // Do the actual deletion. - rc = DeleteSaveDataFileSystemCore(targetSpaceId, saveDataId, wipeSaveFile: false); - if (rc.IsFailure()) return rc.Miss(); + res = DeleteSaveDataFileSystemCore(targetSpaceId, saveDataId, wipeSaveFile: false); + if (res.IsFailure()) return res.Miss(); // Remove the save data from the indexer. // The indexer doesn't track itself, so skip if deleting its save data. if (saveDataId != SaveIndexerId) { - rc = accessor.Get.GetInterface().Delete(saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().Delete(saveDataId); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().Commit(); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().Commit(); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -846,8 +846,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave public Result SetSaveDataRootPath(in FspPath path) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.DebugSaveData)) return ResultFs.PermissionDenied.Log(); @@ -856,13 +856,13 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave if (path.Str[0] == NullTerminator) { - rc = saveDataRootPath.Initialize(new[] { (byte)'.' }); - if (rc.IsFailure()) return rc.Miss(); + res = saveDataRootPath.Initialize(new[] { (byte)'.' }); + if (res.IsFailure()) return res.Miss(); } else { - rc = saveDataRootPath.InitializeWithReplaceUnc(path.Str); - if (rc.IsFailure()) return rc.Miss(); + res = saveDataRootPath.InitializeWithReplaceUnc(path.Str); + if (res.IsFailure()) return res.Miss(); } var pathFlags = new PathFlags(); @@ -870,8 +870,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave pathFlags.AllowRelativePath(); pathFlags.AllowEmptyPath(); - rc = saveDataRootPath.Normalize(pathFlags); - if (rc.IsFailure()) return rc.Miss(); + res = saveDataRootPath.Normalize(pathFlags); + if (res.IsFailure()) return res.Miss(); _saveDataRootPath.Initialize(in saveDataRootPath); @@ -880,15 +880,15 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave public Result UnsetSaveDataRootPath() { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.DebugSaveData)) return ResultFs.PermissionDenied.Log(); using var saveDataRootPath = new Path(); - rc = saveDataRootPath.InitializeAsEmpty(); - if (rc.IsFailure()) return rc.Miss(); + res = saveDataRootPath.InitializeAsEmpty(); + if (res.IsFailure()) return res.Miss(); _saveDataRootPath.Initialize(in saveDataRootPath); @@ -911,8 +911,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using var scopedContext = new ScopedStorageLayoutTypeSetter(storageFlag); using var file = new SharedRef(); - Result rc = _serviceImpl.OpenSaveDataFile(ref file.Ref(), spaceId, saveDataId, openMode); - if (rc.IsFailure()) return rc.Miss(); + Result res = _serviceImpl.OpenSaveDataFile(ref file.Ref(), spaceId, saveDataId, openMode); + if (res.IsFailure()) return res.Miss(); using var typeSetFile = new SharedRef(new StorageLayoutTypeSetFile(ref file.Ref(), storageFlag)); @@ -930,7 +930,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave ulong saveDataId = 0; bool creating = false; bool accessorInitialized = false; - Result rc; + Result res; StorageLayoutType storageFlag = DecidePossibleStorageFlag(creationInfo.Attribute.Type, creationInfo.SpaceId); using var scopedContext = new ScopedStorageLayoutTypeSetter(storageFlag); @@ -944,9 +944,9 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { // The save indexer doesn't index itself saveDataId = SaveIndexerId; - rc = _serviceImpl.DoesSaveDataEntityExist(out bool saveExists, creationInfo.SpaceId, saveDataId); + res = _serviceImpl.DoesSaveDataEntityExist(out bool saveExists, creationInfo.SpaceId, saveDataId); - if (rc.IsSuccess() && saveExists) + if (res.IsSuccess() && saveExists) { return ResultFs.PathAlreadyExists.Log(); } @@ -955,8 +955,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave } else { - rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), creationInfo.SpaceId); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), creationInfo.SpaceId); + if (res.IsFailure()) return res.Miss(); accessorInitialized = true; @@ -968,7 +968,7 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave // If a static save data ID is specified that ID is always used saveDataId = creationInfo.Attribute.StaticSaveDataId; - rc = accessor.Get.GetInterface().PutStaticSaveDataIdIndex(in indexerKey); + res = accessor.Get.GetInterface().PutStaticSaveDataIdIndex(in indexerKey); } else { @@ -984,102 +984,102 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave } // If a static save data ID is no specified we're assigned a new save ID - rc = accessor.Get.GetInterface().Publish(out saveDataId, in indexerKey); + res = accessor.Get.GetInterface().Publish(out saveDataId, in indexerKey); } - if (rc.IsSuccess()) + if (res.IsSuccess()) { creating = true; // Set the state, space ID and size on the new save indexer entry. - rc = accessor.Get.GetInterface().SetState(saveDataId, SaveDataState.Processing); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().SetState(saveDataId, SaveDataState.Processing); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().SetSpaceId(saveDataId, ConvertToRealSpaceId(creationInfo.SpaceId)); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().SetSpaceId(saveDataId, ConvertToRealSpaceId(creationInfo.SpaceId)); + if (res.IsFailure()) return res.Miss(); - rc = QuerySaveDataTotalSize(out long saveDataSize, creationInfo.Size, creationInfo.JournalSize); - if (rc.IsFailure()) return rc.Miss(); + res = QuerySaveDataTotalSize(out long saveDataSize, creationInfo.Size, creationInfo.JournalSize); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().SetSize(saveDataId, saveDataSize); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().SetSize(saveDataId, saveDataSize); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().Commit(); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().Commit(); + if (res.IsFailure()) return res.Miss(); } else { - if (ResultFs.AlreadyExists.Includes(rc)) + if (ResultFs.AlreadyExists.Includes(res)) { // The save already exists. Ensure the thumbnail meta file exists if needed. if (creationInfo.MetaType == SaveDataMetaType.Thumbnail) { - Result rcMeta = accessor.Get.GetInterface().Get(out SaveDataIndexerValue value, in indexerKey); - if (rcMeta.IsFailure()) return rcMeta.Miss(); + Result resultMeta = accessor.Get.GetInterface().Get(out SaveDataIndexerValue value, in indexerKey); + if (resultMeta.IsFailure()) return resultMeta.Miss(); - rcMeta = CreateEmptyThumbnailFile(creationInfo.SpaceId, value.SaveDataId); + resultMeta = CreateEmptyThumbnailFile(creationInfo.SpaceId, value.SaveDataId); // Allow the thumbnail file to already exist - if (rcMeta.IsFailure() && !ResultFs.PathAlreadyExists.Includes(rcMeta)) - return rcMeta.Miss(); + if (resultMeta.IsFailure() && !ResultFs.PathAlreadyExists.Includes(resultMeta)) + return resultMeta.Miss(); } - return ResultFs.PathAlreadyExists.LogConverted(rc); + return ResultFs.PathAlreadyExists.LogConverted(res); } - return rc.Miss(); + return res.Miss(); } - if (rc.IsFailure()) + if (res.IsFailure()) { - if (ResultFs.AlreadyExists.Includes(rc)) + if (ResultFs.AlreadyExists.Includes(res)) { - return ResultFs.PathAlreadyExists.LogConverted(rc); + return ResultFs.PathAlreadyExists.LogConverted(res); } - return rc; + return res; } } // After the new save is added to the save indexer, create the save data file or directory. using Path saveDataRootPath = _saveDataRootPath.DangerousGetPath(); - rc = _serviceImpl.CreateSaveDataFileSystem(saveDataId, in creationInfo, in saveDataRootPath, skipFormat: false); + res = _serviceImpl.CreateSaveDataFileSystem(saveDataId, in creationInfo, in saveDataRootPath, skipFormat: false); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (!ResultFs.PathAlreadyExists.Includes(rc)) - return rc.Miss(); + if (!ResultFs.PathAlreadyExists.Includes(res)) + return res.Miss(); // The save exists on the file system but not in the save indexer. // Delete the save data and try creating it again. - rc = DeleteSaveDataFileSystemCore(creationInfo.SpaceId, saveDataId, false); - if (rc.IsFailure()) return rc.Miss(); + res = DeleteSaveDataFileSystemCore(creationInfo.SpaceId, saveDataId, false); + if (res.IsFailure()) return res.Miss(); - rc = _serviceImpl.CreateSaveDataFileSystem(saveDataId, in creationInfo, in saveDataRootPath, + res = _serviceImpl.CreateSaveDataFileSystem(saveDataId, in creationInfo, in saveDataRootPath, skipFormat: false); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } if (creationInfo.MetaType != SaveDataMetaType.None) { // Create the requested save data meta file. - rc = _serviceImpl.CreateSaveDataMeta(saveDataId, creationInfo.SpaceId, creationInfo.MetaType, + res = _serviceImpl.CreateSaveDataMeta(saveDataId, creationInfo.SpaceId, creationInfo.MetaType, creationInfo.MetaSize); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); if (creationInfo.MetaType == SaveDataMetaType.Thumbnail) { using var metaFile = new UniqueRef(); - rc = _serviceImpl.OpenSaveDataMeta(ref metaFile.Ref(), saveDataId, creationInfo.SpaceId, + res = _serviceImpl.OpenSaveDataMeta(ref metaFile.Ref(), saveDataId, creationInfo.SpaceId, creationInfo.MetaType); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); // The first 0x20 bytes of thumbnail meta files is an SHA-256 hash. // Zero the hash to indicate that it's currently unused. ReadOnlySpan metaFileHash = stackalloc byte[0x20]; - rc = metaFile.Get.Write(0, metaFileHash, WriteOption.Flush); - if (rc.IsFailure()) return rc.Miss(); + res = metaFile.Get.Write(0, metaFileHash, WriteOption.Flush); + if (res.IsFailure()) return res.Miss(); } } @@ -1093,11 +1093,11 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave if (creationInfo.Attribute.StaticSaveDataId != SaveIndexerId) { // Mark the save data as being successfully created - rc = accessor.Get.GetInterface().SetState(saveDataId, SaveDataState.Normal); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().SetState(saveDataId, SaveDataState.Normal); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().Commit(); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().Commit(); + if (res.IsFailure()) return res.Miss(); } creating = false; @@ -1108,28 +1108,28 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave // Revert changes if an error happened in the middle of creation if (creating) { - rc = DeleteSaveDataFileSystemCore(creationInfo.SpaceId, saveDataId, false); - if (rc.IsFailure()) + res = DeleteSaveDataFileSystemCore(creationInfo.SpaceId, saveDataId, false); + if (res.IsFailure()) { - Hos.Diag.Impl.LogImpl(Log.EmptyModuleName, LogSeverity.Info, GetRollbackErrorMessage(rc)); + Hos.Diag.Impl.LogImpl(Log.EmptyModuleName, LogSeverity.Info, GetRollbackErrorMessage(res)); } if (accessorInitialized && saveDataId != SaveIndexerId) { - rc = accessor.Get.GetInterface().GetValue(out SaveDataIndexerValue value, saveDataId); + res = accessor.Get.GetInterface().GetValue(out SaveDataIndexerValue value, saveDataId); - if (rc.IsSuccess() && value.SpaceId == creationInfo.SpaceId) + if (res.IsSuccess() && value.SpaceId == creationInfo.SpaceId) { accessor.Get.GetInterface().Delete(saveDataId); - if (rc.IsFailure() && !ResultFs.TargetNotFound.Includes(rc)) + if (res.IsFailure() && !ResultFs.TargetNotFound.Includes(res)) { - Hos.Diag.Impl.LogImpl(Log.EmptyModuleName, LogSeverity.Info, GetRollbackErrorMessage(rc)); + Hos.Diag.Impl.LogImpl(Log.EmptyModuleName, LogSeverity.Info, GetRollbackErrorMessage(res)); } accessor.Get.GetInterface().Commit(); - if (rc.IsFailure()) + if (res.IsFailure()) { - Hos.Diag.Impl.LogImpl(Log.EmptyModuleName, LogSeverity.Info, GetRollbackErrorMessage(rc)); + Hos.Diag.Impl.LogImpl(Log.EmptyModuleName, LogSeverity.Info, GetRollbackErrorMessage(res)); } } } @@ -1147,10 +1147,10 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave in SaveDataMetaInfo metaInfo, in Optional hashSalt, bool leaveUnfinalized) { // Changed: The original allocates a SaveDataCreationInfo2 on the heap for some reason - Result rc = SaveDataCreationInfo2.Make(out SaveDataCreationInfo2 newCreationInfo, in attribute, + Result res = SaveDataCreationInfo2.Make(out SaveDataCreationInfo2 newCreationInfo, in attribute, creationInfo.Size, creationInfo.JournalSize, creationInfo.BlockSize, creationInfo.OwnerId, creationInfo.Flags, creationInfo.SpaceId, GetSaveDataFormatType(in attribute)); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); newCreationInfo.IsHashSaltEnabled = hashSalt.HasValue; if (hashSalt.HasValue) @@ -1161,8 +1161,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave newCreationInfo.MetaType = metaInfo.Type; newCreationInfo.MetaSize = metaInfo.Size; - rc = CreateSaveDataFileSystemCore(in newCreationInfo, leaveUnfinalized); - if (rc.IsFailure()) return rc.Miss(); + res = CreateSaveDataFileSystemCore(in newCreationInfo, leaveUnfinalized); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -1174,11 +1174,11 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.NonGameCard); using var accessor = new UniqueRef(); - Result rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + Result res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().Get(out SaveDataIndexerValue value, in attribute); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().Get(out SaveDataIndexerValue value, in attribute); + if (res.IsFailure()) return res.Miss(); SaveDataIndexer.GenerateSaveDataInfo(out info, in attribute, in value); return Result.Success; @@ -1191,8 +1191,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave if (dataSize < 0 || journalSize < 0) return ResultFs.InvalidSize.Log(); - Result rc = _serviceImpl.QuerySaveDataTotalSize(out long totalSize, SaveDataBlockSize, dataSize, journalSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = _serviceImpl.QuerySaveDataTotalSize(out long totalSize, SaveDataBlockSize, dataSize, journalSize); + if (res.IsFailure()) return res.Miss(); outTotalSize = totalSize; return Result.Success; @@ -1202,17 +1202,17 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave in SaveDataMetaInfo metaInfo) { // Changed: The original allocates a SaveDataCreationInfo2 on the heap for some reason - Result rc = SaveDataCreationInfo2.Make(out SaveDataCreationInfo2 newCreationInfo, in attribute, + Result res = SaveDataCreationInfo2.Make(out SaveDataCreationInfo2 newCreationInfo, in attribute, creationInfo.Size, creationInfo.JournalSize, creationInfo.BlockSize, creationInfo.OwnerId, creationInfo.Flags, creationInfo.SpaceId, GetSaveDataFormatType(in attribute)); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); newCreationInfo.IsHashSaltEnabled = false; newCreationInfo.MetaType = metaInfo.Type; newCreationInfo.MetaSize = metaInfo.Size; - rc = CreateSaveDataFileSystemWithCreationInfo2(in newCreationInfo); - if (rc.IsFailure()) return rc.Miss(); + res = CreateSaveDataFileSystemWithCreationInfo2(in newCreationInfo); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -1221,18 +1221,18 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave in SaveDataCreationInfo creationInfo, in SaveDataMetaInfo metaInfo, in HashSalt hashSalt) { // Changed: The original allocates a SaveDataCreationInfo2 on the heap for some reason - Result rc = SaveDataCreationInfo2.Make(out SaveDataCreationInfo2 newCreationInfo, in attribute, + Result res = SaveDataCreationInfo2.Make(out SaveDataCreationInfo2 newCreationInfo, in attribute, creationInfo.Size, creationInfo.JournalSize, creationInfo.BlockSize, creationInfo.OwnerId, creationInfo.Flags, creationInfo.SpaceId, GetSaveDataFormatType(in attribute)); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); newCreationInfo.IsHashSaltEnabled = true; newCreationInfo.HashSalt = hashSalt; newCreationInfo.MetaType = metaInfo.Type; newCreationInfo.MetaSize = metaInfo.Size; - rc = CreateSaveDataFileSystemWithCreationInfo2(in newCreationInfo); - if (rc.IsFailure()) return rc.Miss(); + res = CreateSaveDataFileSystemWithCreationInfo2(in newCreationInfo); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -1242,8 +1242,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave StorageLayoutType storageFlag = DecidePossibleStorageFlag(creationInfo.Attribute.Type, creationInfo.SpaceId); using var scopedContext = new ScopedStorageLayoutTypeSetter(storageFlag); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (creationInfo.IsHashSaltEnabled && !programInfo.AccessControl.CanCall(OperationType.CreateSaveDataWithHashSalt)) @@ -1252,9 +1252,9 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave } ProgramId resolvedProgramId = ResolveDefaultSaveDataReferenceProgramId(programInfo.ProgramId); - rc = SaveDataAccessibilityChecker.CheckCreate(in creationInfo.Attribute, creationInfo.OwnerId, programInfo, + res = SaveDataAccessibilityChecker.CheckCreate(in creationInfo.Attribute, creationInfo.OwnerId, programInfo, resolvedProgramId); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); if (creationInfo.Attribute.Type == SaveDataType.Account && creationInfo.Attribute.UserId == InvalidUserId) { @@ -1271,13 +1271,13 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave newCreationInfo.OwnerId = ResolveDefaultSaveDataReferenceProgramId(programInfo.ProgramId).Value; } - rc = CreateSaveDataFileSystemCore(in newCreationInfo, leaveUnfinalized: false); - if (rc.IsFailure()) return rc.Miss(); + res = CreateSaveDataFileSystemCore(in newCreationInfo, leaveUnfinalized: false); + if (res.IsFailure()) return res.Miss(); } else { - rc = CreateSaveDataFileSystemCore(in creationInfo, leaveUnfinalized: false); - if (rc.IsFailure()) return rc.Miss(); + res = CreateSaveDataFileSystemCore(in creationInfo, leaveUnfinalized: false); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -1289,22 +1289,22 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave StorageLayoutType storageFlag = DecidePossibleStorageFlag(attribute.Type, creationInfo.SpaceId); using var scopedContext = new ScopedStorageLayoutTypeSetter(storageFlag); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!IsStaticSaveDataIdValueRange(attribute.StaticSaveDataId)) return ResultFs.InvalidArgument.Log(); ulong ownerId = creationInfo.OwnerId == 0 ? programInfo.ProgramIdValue : creationInfo.OwnerId; - rc = SaveDataAccessibilityChecker.CheckCreate(in attribute, ownerId, programInfo, programInfo.ProgramId); - if (rc.IsFailure()) return rc.Miss(); + res = SaveDataAccessibilityChecker.CheckCreate(in attribute, ownerId, programInfo, programInfo.ProgramId); + if (res.IsFailure()) return res.Miss(); // Changed: The original allocates a SaveDataCreationInfo2 on the heap for some reason - rc = SaveDataCreationInfo2.Make(out SaveDataCreationInfo2 newCreationInfo, in attribute, creationInfo.Size, + res = SaveDataCreationInfo2.Make(out SaveDataCreationInfo2 newCreationInfo, in attribute, creationInfo.Size, creationInfo.JournalSize, creationInfo.BlockSize, ownerId, creationInfo.Flags, creationInfo.SpaceId, GetSaveDataFormatType(in attribute)); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); newCreationInfo.IsHashSaltEnabled = false; @@ -1312,8 +1312,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave newCreationInfo.MetaType = SaveDataMetaType.None; newCreationInfo.MetaSize = 0; - rc = CreateSaveDataFileSystemCore(in newCreationInfo, leaveUnfinalized: false); - if (rc.IsFailure()) return rc.Miss(); + res = CreateSaveDataFileSystemCore(in newCreationInfo, leaveUnfinalized: false); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -1322,16 +1322,16 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { SaveDataAttribute key; - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); using (var accessor = new UniqueRef()) { - rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().GetKey(out key, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().GetKey(out key, saveDataId); + if (res.IsFailure()) return res.Miss(); Result ReadExtraData(out SaveDataExtraData data) { @@ -1340,12 +1340,12 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave } // Check if we have permissions to extend this save data. - rc = SaveDataAccessibilityChecker.CheckExtend(spaceId, in key, programInfo, ReadExtraData); - if (rc.IsFailure()) return rc.Miss(); + res = SaveDataAccessibilityChecker.CheckExtend(spaceId, in key, programInfo, ReadExtraData); + if (res.IsFailure()) return res.Miss(); // Check that the save data is in a state that we can start extending it. - rc = accessor.Get.GetInterface().GetValue(out SaveDataIndexerValue value, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().GetValue(out SaveDataIndexerValue value, saveDataId); + if (res.IsFailure()) return res.Miss(); switch (value.State) { @@ -1362,21 +1362,21 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave } // Mark the save data as being extended. - rc = accessor.Get.GetInterface().SetState(saveDataId, SaveDataState.Extending); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().SetState(saveDataId, SaveDataState.Extending); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().Commit(); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().Commit(); + if (res.IsFailure()) return res.Miss(); } // Get the indexer key for the save data. using (var accessor = new UniqueRef()) { - rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().GetKey(out key, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().GetKey(out key, saveDataId); + if (res.IsFailure()) return res.Miss(); } // Start the extension. @@ -1388,17 +1388,17 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { // Try to return the save data to its original state if something went wrong. using var accessor = new UniqueRef(); - rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().GetValue(out SaveDataIndexerValue value, saveDataId); - if (rc.IsSuccess()) + res = accessor.Get.GetInterface().GetValue(out SaveDataIndexerValue value, saveDataId); + if (res.IsSuccess()) { _serviceImpl.RevertExtendSaveDataFileSystem(saveDataId, spaceId, value.Size, in saveDataRootPath); } - rc = accessor.Get.GetInterface().SetState(saveDataId, SaveDataState.Normal); - if (rc.IsSuccess()) + res = accessor.Get.GetInterface().SetState(saveDataId, SaveDataState.Normal); + if (res.IsSuccess()) { accessor.Get.GetInterface().Commit().IgnoreResult(); } @@ -1409,30 +1409,30 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave // Update the save data's size in the indexer. using (var accessor = new UniqueRef()) { - rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); accessor.Get.GetInterface().SetSize(saveDataId, extendedTotalSize).IgnoreResult(); - rc = accessor.Get.GetInterface().Commit(); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().Commit(); + if (res.IsFailure()) return res.Miss(); } // Finish the extension. - rc = _serviceImpl.FinishExtendSaveDataFileSystem(saveDataId, spaceId); - if (rc.IsFailure()) return rc.Miss(); + res = _serviceImpl.FinishExtendSaveDataFileSystem(saveDataId, spaceId); + if (res.IsFailure()) return res.Miss(); // Set the save data's state back to normal. using (var accessor = new UniqueRef()) { - rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().SetState(saveDataId, SaveDataState.Normal); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().SetState(saveDataId, SaveDataState.Normal); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().Commit(); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().Commit(); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -1468,11 +1468,11 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave } else { - Result rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + Result res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().Get(out SaveDataIndexerValue indexerValue, in attribute); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().Get(out SaveDataIndexerValue indexerValue, in attribute); + if (res.IsFailure()) return res.Miss(); if (indexerValue.SpaceId != ConvertToRealSpaceId(spaceId)) return ResultFs.TargetNotFound.Log(); @@ -1500,16 +1500,16 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave // Remove the save from the indexer if the save is missing from the disk. if (ResultFs.PathNotFound.Includes(saveFsResult)) { - Result rc = RemoveSaveIndexerEntry(); - if (rc.IsFailure()) return rc.Miss(); + Result res = RemoveSaveIndexerEntry(); + if (res.IsFailure()) return res.Miss(); return ResultFs.TargetNotFound.LogConverted(saveFsResult); } if (ResultFs.TargetNotFound.Includes(saveFsResult)) { - Result rc = RemoveSaveIndexerEntry(); - if (rc.IsFailure()) return rc.Miss(); + Result res = RemoveSaveIndexerEntry(); + if (res.IsFailure()) return res.Miss(); } return saveFsResult; @@ -1522,12 +1522,12 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave if (isStaticSaveDataId) { // The accessor won't be open yet if the save has a static ID - Result rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + Result res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); // Check the space ID of the save data - rc = accessor.Get.GetInterface().Get(out SaveDataIndexerValue value, in key); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().Get(out SaveDataIndexerValue value, in key); + if (res.IsFailure()) return res.Miss(); if (value.SpaceId != ConvertToRealSpaceId(spaceId)) return ResultFs.TargetNotFound.Log(); @@ -1549,8 +1549,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave // Try grabbing the mount count semaphore using var mountCountSemaphore = new UniqueRef(); - Result rc = TryAcquireSaveDataMountCountSemaphore(ref mountCountSemaphore.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = TryAcquireSaveDataMountCountSemaphore(ref mountCountSemaphore.Ref()); + if (res.IsFailure()) return res.Miss(); using Path saveDataRootPath = _saveDataRootPath.DangerousGetPath(); bool useAsyncFileSystem = !_serviceImpl.IsAllowedDirectorySaveData(spaceId, in saveDataRootPath); @@ -1558,9 +1558,9 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using var fileSystem = new SharedRef(); // Open the file system - rc = OpenSaveDataFileSystemCore(ref fileSystem.Ref(), out ulong saveDataId, spaceId, in attribute, + res = OpenSaveDataFileSystemCore(ref fileSystem.Ref(), out ulong saveDataId, spaceId, in attribute, openReadOnly, cacheExtraData: true); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); // Can't use attribute in a closure, so copy the needed field SaveDataType type = attribute.Type; @@ -1572,8 +1572,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave } // Check if we have permissions to open this save data - rc = SaveDataAccessibilityChecker.CheckOpen(in attribute, programInfo, ReadExtraData); - if (rc.IsFailure()) return rc.Miss(); + res = SaveDataAccessibilityChecker.CheckOpen(in attribute, programInfo, ReadExtraData); + if (res.IsFailure()) return res.Miss(); // Add all the wrappers for the file system using var typeSetFileSystem = @@ -1612,11 +1612,11 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave private Result OpenUserSaveDataFileSystem(ref SharedRef outFileSystem, SaveDataSpaceId spaceId, in SaveDataAttribute attribute, bool openReadOnly) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); - rc = SaveDataAccessibilityChecker.CheckOpenPre(in attribute, programInfo); - if (rc.IsFailure()) return rc.Miss(); + res = SaveDataAccessibilityChecker.CheckOpenPre(in attribute, programInfo); + if (res.IsFailure()) return res.Miss(); SaveDataAttribute tempAttribute; @@ -1624,9 +1624,9 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { ProgramId resolvedProgramId = ResolveDefaultSaveDataReferenceProgramId(programInfo.ProgramId); - rc = SaveDataAttribute.Make(out tempAttribute, resolvedProgramId, attribute.Type, attribute.UserId, + res = SaveDataAttribute.Make(out tempAttribute, resolvedProgramId, attribute.Type, attribute.UserId, attribute.StaticSaveDataId, attribute.Index); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } else { @@ -1638,8 +1638,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave if (tempAttribute.Type == SaveDataType.Cache) { // Check whether the save is on the SD card or the BIS - rc = GetCacheStorageSpaceId(out targetSpaceId, tempAttribute.ProgramId.Value); - if (rc.IsFailure()) return rc.Miss(); + res = GetCacheStorageSpaceId(out targetSpaceId, tempAttribute.ProgramId.Value); + if (res.IsFailure()) return res.Miss(); } else { @@ -1656,8 +1656,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave if (!IsStaticSaveDataIdValueRange(attribute.StaticSaveDataId)) return ResultFs.InvalidArgument.Log(); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); StorageLayoutType storageFlag = DecidePossibleStorageFlag(attribute.Type, spaceId); using var scopedContext = new ScopedStorageLayoutTypeSetter(storageFlag); @@ -1674,9 +1674,9 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using var fileSystem = new SharedRef(); // Open the file system - rc = OpenSaveDataFileSystemCore(ref fileSystem.Ref(), out ulong saveDataId, spaceId, in attribute, + res = OpenSaveDataFileSystemCore(ref fileSystem.Ref(), out ulong saveDataId, spaceId, in attribute, openReadOnly: false, cacheExtraData: true); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); // Can't use attribute in a closure, so copy the needed field SaveDataType type = attribute.Type; @@ -1688,8 +1688,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave } // Check if we have permissions to open this save data - rc = SaveDataAccessibilityChecker.CheckOpen(in attribute, programInfo, ReadExtraData); - if (rc.IsFailure()) return rc.Miss(); + res = SaveDataAccessibilityChecker.CheckOpen(in attribute, programInfo, ReadExtraData); + if (res.IsFailure()) return res.Miss(); // Add all the wrappers for the file system using var typeSetFileSystem = @@ -1736,11 +1736,11 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.NonGameCard); using var accessor = new UniqueRef(); - Result rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + Result res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().GetKey(out SaveDataAttribute key, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().GetKey(out SaveDataAttribute key, saveDataId); + if (res.IsFailure()) return res.Miss(); using Path saveDataRootPath = _saveDataRootPath.DangerousGetPath(); return _serviceImpl.ReadSaveDataFileSystemExtraData(out extraData, spaceId, saveDataId, key.Type, @@ -1754,8 +1754,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.NonGameCard); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); SaveDataSpaceId resolvedSpaceId; SaveDataAttribute key; @@ -1766,37 +1766,37 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave if (IsStaticSaveDataIdValueRange(saveDataId)) { - rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), SaveDataSpaceId.System); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), SaveDataSpaceId.System); + if (res.IsFailure()) return res.Miss(); } else { - rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), SaveDataSpaceId.User); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), SaveDataSpaceId.User); + if (res.IsFailure()) return res.Miss(); } - rc = accessor.Get.GetInterface().GetValue(out SaveDataIndexerValue value, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().GetValue(out SaveDataIndexerValue value, saveDataId); + if (res.IsFailure()) return res.Miss(); resolvedSpaceId = value.SpaceId; - rc = accessor.Get.GetInterface().GetKey(out key, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().GetKey(out key, saveDataId); + if (res.IsFailure()) return res.Miss(); } else { using var accessor = new UniqueRef(); - rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId.ValueRo); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId.ValueRo); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().GetValue(out SaveDataIndexerValue _, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().GetValue(out SaveDataIndexerValue _, saveDataId); + if (res.IsFailure()) return res.Miss(); resolvedSpaceId = spaceId.ValueRo; - rc = accessor.Get.GetInterface().GetKey(out key, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().GetKey(out key, saveDataId); + if (res.IsFailure()) return res.Miss(); } Result ReadExtraData(out SaveDataExtraData data) @@ -1806,13 +1806,13 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave in savePath); } - rc = SaveDataAccessibilityChecker.CheckReadExtraData(in key, in extraDataMask, programInfo, ReadExtraData); - if (rc.IsFailure()) return rc.Miss(); + res = SaveDataAccessibilityChecker.CheckReadExtraData(in key, in extraDataMask, programInfo, ReadExtraData); + if (res.IsFailure()) return res.Miss(); using Path saveDataRootPath = _saveDataRootPath.DangerousGetPath(); - rc = _serviceImpl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData tempExtraData, resolvedSpaceId, + res = _serviceImpl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData tempExtraData, resolvedSpaceId, saveDataId, key.Type, in saveDataRootPath); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); MaskExtraData(ref tempExtraData, in extraDataMask); extraData = tempExtraData; @@ -1841,8 +1841,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave ref SaveDataExtraData extraDataRef = ref SpanHelpers.AsStruct(extraData.Buffer); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); SaveDataAttribute tempAttribute = attribute; @@ -1851,8 +1851,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave tempAttribute.ProgramId = ResolveDefaultSaveDataReferenceProgramId(programInfo.ProgramId); } - rc = GetSaveDataInfo(out SaveDataInfo info, spaceId, in tempAttribute); - if (rc.IsFailure()) return rc.Miss(); + res = GetSaveDataInfo(out SaveDataInfo info, spaceId, in tempAttribute); + if (res.IsFailure()) return res.Miss(); // Make a mask for reading the entire extra data Unsafe.SkipInit(out SaveDataExtraData extraDataMask); @@ -1890,8 +1890,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave ref SaveDataExtraData extraDataRef = ref SpanHelpers.AsStruct(extraData.Buffer); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); SaveDataAttribute tempAttribute = attribute; @@ -1900,8 +1900,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave tempAttribute.ProgramId = ResolveDefaultSaveDataReferenceProgramId(programInfo.ProgramId); } - rc = GetSaveDataInfo(out SaveDataInfo info, spaceId, in tempAttribute); - if (rc.IsFailure()) return rc.Miss(); + res = GetSaveDataInfo(out SaveDataInfo info, spaceId, in tempAttribute); + if (res.IsFailure()) return res.Miss(); return ReadSaveDataFileSystemExtraDataCore(out extraDataRef, spaceId, info.SaveDataId, in maskRef).Ret(); } @@ -1921,16 +1921,16 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.NonGameCard); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); using var accessor = new UniqueRef(); - rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().GetKey(out SaveDataAttribute key, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().GetKey(out SaveDataAttribute key, saveDataId); + if (res.IsFailure()) return res.Miss(); Result ReadExtraData(out SaveDataExtraData data) { @@ -1939,13 +1939,13 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave in saveDataRootPath); } - rc = SaveDataAccessibilityChecker.CheckWriteExtraData(in key, in extraDataMask, programInfo, ReadExtraData); - if (rc.IsFailure()) return rc.Miss(); + res = SaveDataAccessibilityChecker.CheckWriteExtraData(in key, in extraDataMask, programInfo, ReadExtraData); + if (res.IsFailure()) return res.Miss(); using Path saveDataRootPath = _saveDataRootPath.DangerousGetPath(); - rc = _serviceImpl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraDataModify, spaceId, saveDataId, + res = _serviceImpl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraDataModify, spaceId, saveDataId, key.Type, in saveDataRootPath); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); ModifySaveDataExtraData(ref extraDataModify, in extraData, in extraDataMask); @@ -1970,8 +1970,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave public Result WriteSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(in SaveDataAttribute attribute, SaveDataSpaceId spaceId, InBuffer extraData, InBuffer extraDataMask) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); SaveDataAttribute tempAttribute = attribute; @@ -1980,8 +1980,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave tempAttribute.ProgramId = ResolveDefaultSaveDataReferenceProgramId(programInfo.ProgramId); } - rc = GetSaveDataInfo(out SaveDataInfo info, spaceId, in tempAttribute); - if (rc.IsFailure()) return rc.Miss(); + res = GetSaveDataInfo(out SaveDataInfo info, spaceId, in tempAttribute); + if (res.IsFailure()) return res.Miss(); return WriteSaveDataFileSystemExtraDataWithMask(info.SaveDataId, spaceId, extraData, extraDataMask).Ret(); } @@ -2008,8 +2008,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.Bis); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.OpenSaveDataInfoReader)) return ResultFs.PermissionDenied.Log(); @@ -2021,11 +2021,11 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using (var accessor = new UniqueRef()) { - rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), SaveDataSpaceId.System); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), SaveDataSpaceId.System); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().OpenSaveDataInfoReader(ref reader.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().OpenSaveDataInfoReader(ref reader.Ref()); + if (res.IsFailure()) return res.Miss(); } outInfoReader.SetByMove(ref reader.Ref()); @@ -2038,23 +2038,23 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.NonGameCard); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); - rc = CheckOpenSaveDataInfoReaderAccessControl(programInfo, spaceId); - if (rc.IsFailure()) return rc.Miss(); + res = CheckOpenSaveDataInfoReaderAccessControl(programInfo, spaceId); + if (res.IsFailure()) return res.Miss(); using var filterReader = new UniqueRef(); using (var accessor = new UniqueRef()) { - rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); using var reader = new SharedRef(); - rc = accessor.Get.GetInterface().OpenSaveDataInfoReader(ref reader.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().OpenSaveDataInfoReader(ref reader.Ref()); + if (res.IsFailure()) return res.Miss(); var filter = new SaveDataInfoFilter(ConvertToRealSpaceId(spaceId), programId: default, saveDataType: default, userId: default, saveDataId: default, index: default, (int)SaveDataRank.Primary); @@ -2072,26 +2072,26 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.NonGameCard); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.OpenSaveDataInfoReaderForInternal)) return ResultFs.PermissionDenied.Log(); - rc = CheckOpenSaveDataInfoReaderAccessControl(programInfo, spaceId); - if (rc.IsFailure()) return rc.Miss(); + res = CheckOpenSaveDataInfoReaderAccessControl(programInfo, spaceId); + if (res.IsFailure()) return res.Miss(); using var filterReader = new UniqueRef(); using (var accessor = new UniqueRef()) { - rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); using var reader = new SharedRef(); - rc = accessor.Get.GetInterface().OpenSaveDataInfoReader(ref reader.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().OpenSaveDataInfoReader(ref reader.Ref()); + if (res.IsFailure()) return res.Miss(); var infoFilter = new SaveDataInfoFilter(ConvertToRealSpaceId(spaceId), in filter); @@ -2111,11 +2111,11 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using var reader = new SharedRef(); using var accessor = new UniqueRef(); - Result rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + Result res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().OpenSaveDataInfoReader(ref reader.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().OpenSaveDataInfoReader(ref reader.Ref()); + if (res.IsFailure()) return res.Miss(); using var filterReader = new UniqueRef(new SaveDataInfoFilterReader(ref reader.Ref(), in infoFilter)); @@ -2133,19 +2133,19 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.NonGameCard); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); - rc = CheckOpenSaveDataInfoReaderAccessControl(programInfo, spaceId); + res = CheckOpenSaveDataInfoReaderAccessControl(programInfo, spaceId); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (!ResultFs.PermissionDenied.Includes(rc)) - return rc; + if (!ResultFs.PermissionDenied.Includes(res)) + return res; // Don't have full info reader permissions. Check if we have find permissions. - rc = SaveDataAccessibilityChecker.CheckFind(in filter, programInfo); - if (rc.IsFailure()) return rc.Miss(); + res = SaveDataAccessibilityChecker.CheckFind(in filter, programInfo); + if (res.IsFailure()) return res.Miss(); } SaveDataFilter tempFilter = filter; @@ -2162,17 +2162,17 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave private Result CreateEmptyThumbnailFile(SaveDataSpaceId spaceId, ulong saveDataId) { - Result rc = _serviceImpl.CreateSaveDataMeta(saveDataId, spaceId, SaveDataMetaType.Thumbnail, + Result res = _serviceImpl.CreateSaveDataMeta(saveDataId, spaceId, SaveDataMetaType.Thumbnail, SaveDataMetaPolicy.ThumbnailFileSize); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); using var file = new UniqueRef(); - rc = _serviceImpl.OpenSaveDataMeta(ref file.Ref(), saveDataId, spaceId, SaveDataMetaType.Thumbnail); - if (rc.IsFailure()) return rc.Miss(); + res = _serviceImpl.OpenSaveDataMeta(ref file.Ref(), saveDataId, spaceId, SaveDataMetaType.Thumbnail); + if (res.IsFailure()) return res.Miss(); Hash hash = default; - rc = file.Get.Write(0, hash.Value, WriteOption.Flush); - if (rc.IsFailure()) return rc.Miss(); + res = file.Get.Write(0, hash.Value, WriteOption.Flush); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -2198,15 +2198,15 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { UnsafeHelpers.SkipParamInit(out commitId); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.GetSaveDataCommitId)) return ResultFs.PermissionDenied.Log(); Unsafe.SkipInit(out SaveDataExtraData extraData); - rc = ReadSaveDataFileSystemExtraDataBySaveDataSpaceId(OutBuffer.FromStruct(ref extraData), spaceId, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = ReadSaveDataFileSystemExtraDataBySaveDataSpaceId(OutBuffer.FromStruct(ref extraData), spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); commitId = Impl.Utility.ConvertZeroCommitId(in extraData); return Result.Success; @@ -2217,14 +2217,14 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.NonGameCard); // Find where the current program's cache storage is located - Result rc = GetCacheStorageSpaceId(out SaveDataSpaceId spaceId); + Result res = GetCacheStorageSpaceId(out SaveDataSpaceId spaceId); - if (rc.IsFailure()) + if (res.IsFailure()) { spaceId = SaveDataSpaceId.User; - if (!ResultFs.TargetNotFound.Includes(rc)) - return rc; + if (!ResultFs.TargetNotFound.Includes(res)) + return res; } return OpenSaveDataInfoReaderOnlyCacheStorage(ref outInfoReader, spaceId).Ret(); @@ -2235,8 +2235,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.NonGameCard); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (spaceId != SaveDataSpaceId.SdUser && spaceId != SaveDataSpaceId.User) return ResultFs.InvalidSaveDataSpaceId.Log(); @@ -2246,11 +2246,11 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using (var reader = new SharedRef()) using (var accessor = new UniqueRef()) { - rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().OpenSaveDataInfoReader(ref reader.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().OpenSaveDataInfoReader(ref reader.Ref()); + if (res.IsFailure()) return res.Miss(); ProgramId resolvedProgramId = ResolveDefaultSaveDataReferenceProgramId(programInfo.ProgramId); @@ -2281,8 +2281,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { UnsafeHelpers.SkipParamInit(out spaceId); - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); ulong resolvedProgramId = ResolveDefaultSaveDataReferenceProgramId(programInfo.ProgramId).Value; return GetCacheStorageSpaceId(out spaceId, resolvedProgramId); @@ -2291,13 +2291,13 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave private Result GetCacheStorageSpaceId(out SaveDataSpaceId spaceId, ulong programId) { UnsafeHelpers.SkipParamInit(out spaceId); - Result rc; + Result res; // Cache storage on the SD card will always take priority over case storage in NAND if (_serviceImpl.IsSdCardAccessible()) { - rc = DoesCacheStorageExist(out bool existsOnSdCard, SaveDataSpaceId.SdUser); - if (rc.IsFailure()) return rc.Miss(); + res = DoesCacheStorageExist(out bool existsOnSdCard, SaveDataSpaceId.SdUser); + if (res.IsFailure()) return res.Miss(); if (existsOnSdCard) { @@ -2306,8 +2306,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave } } - rc = DoesCacheStorageExist(out bool existsOnNand, SaveDataSpaceId.User); - if (rc.IsFailure()) return rc.Miss(); + res = DoesCacheStorageExist(out bool existsOnNand, SaveDataSpaceId.User); + if (res.IsFailure()) return res.Miss(); if (existsOnNand) { @@ -2336,19 +2336,19 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { UnsafeHelpers.SkipParamInit(out saveInfo); - Result rc = GetCacheStorageSpaceId(out spaceId); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetCacheStorageSpaceId(out spaceId); + if (res.IsFailure()) return res.Miss(); - rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); ProgramId resolvedProgramId = ResolveDefaultSaveDataReferenceProgramId(programInfo.ProgramId); var filter = new SaveDataInfoFilter(ConvertToRealSpaceId(spaceId), resolvedProgramId, SaveDataType.Cache, userId: default, saveDataId: default, index, (int)SaveDataRank.Primary); - rc = FindSaveDataWithFilterImpl(out long count, out SaveDataInfo info, spaceId, in filter); - if (rc.IsFailure()) return rc.Miss(); + res = FindSaveDataWithFilterImpl(out long count, out SaveDataInfo info, spaceId, in filter); + if (res.IsFailure()) return res.Miss(); if (count == 0) return ResultFs.TargetNotFound.Log(); @@ -2361,11 +2361,11 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.NonGameCard); - Result rc = FindCacheStorage(out SaveDataInfo saveInfo, out SaveDataSpaceId spaceId, index); - if (rc.IsFailure()) return rc.Miss(); + Result res = FindCacheStorage(out SaveDataInfo saveInfo, out SaveDataSpaceId spaceId, index); + if (res.IsFailure()) return res.Miss(); - rc = Hos.Fs.DeleteSaveData(spaceId, saveInfo.SaveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = Hos.Fs.DeleteSaveData(spaceId, saveInfo.SaveDataId); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -2376,13 +2376,13 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.NonGameCard); - Result rc = FindCacheStorage(out SaveDataInfo saveInfo, out SaveDataSpaceId spaceId, index); - if (rc.IsFailure()) return rc.Miss(); + Result res = FindCacheStorage(out SaveDataInfo saveInfo, out SaveDataSpaceId spaceId, index); + if (res.IsFailure()) return res.Miss(); using Path saveDataRootPath = _saveDataRootPath.DangerousGetPath(); - rc = _serviceImpl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, saveInfo.SaveDataId, + res = _serviceImpl.ReadSaveDataFileSystemExtraData(out SaveDataExtraData extraData, spaceId, saveInfo.SaveDataId, saveInfo.Type, in saveDataRootPath); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); usableDataSize = extraData.DataSize; journalSize = extraData.JournalSize; @@ -2420,13 +2420,13 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave public Result OpenSaveDataTransferProhibiter(ref SharedRef prohibiter, Ncm.ApplicationId applicationId) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); Assert.SdkNotNull(_serviceImpl.GetSaveDataTransferCryptoConfiguration()); - rc = SaveDataAccessibilityChecker.CheckOpenProhibiter(applicationId, programInfo); - if (rc.IsFailure()) return rc.Miss(); + res = SaveDataAccessibilityChecker.CheckOpenProhibiter(applicationId, programInfo); + if (res.IsFailure()) return res.Miss(); return OpenSaveDataTransferProhibiterCore(ref prohibiter, applicationId).Ret(); } @@ -2465,14 +2465,14 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave return ResultFs.InvalidSize.Log(); } - Result rc = GetProgramInfo(out ProgramInfo callerProgramInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo callerProgramInfo); + if (res.IsFailure()) return res.Miss(); if (!callerProgramInfo.AccessControl.CanCall(OperationType.ListAccessibleSaveDataOwnerId)) return ResultFs.PermissionDenied.Log(); - rc = GetProgramInfoByProgramId(out ProgramInfo targetProgramInfo, programId.Value); - if (rc.IsFailure()) return rc.Miss(); + res = GetProgramInfoByProgramId(out ProgramInfo targetProgramInfo, programId.Value); + if (res.IsFailure()) return res.Miss(); targetProgramInfo.AccessControl.ListSaveDataOwnedId(out readCount, ids.Slice(0, bufferIdCount), startIndex); return Result.Success; @@ -2487,8 +2487,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave OutBuffer workBuffer) { // The caller needs the VerifySaveData permission. - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.VerifySaveData)) return ResultFs.PermissionDenied.Log(); @@ -2503,14 +2503,14 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using (var accessor = new UniqueRef()) { - rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().GetValue(out value, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().GetValue(out value, saveDataId); + if (res.IsFailure()) return res.Miss(); - rc = accessor.Get.GetInterface().GetKey(out SaveDataAttribute key, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = accessor.Get.GetInterface().GetKey(out SaveDataAttribute key, saveDataId); + if (res.IsFailure()) return res.Miss(); saveDataType = key.Type; } @@ -2519,14 +2519,14 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using var fileSystem = new SharedRef(); using Path saveDataRootPath = _saveDataRootPath.DangerousGetPath(); - rc = _serviceImpl.OpenSaveDataFileSystem(ref fileSystem.Ref(), value.SpaceId, saveDataId, + res = _serviceImpl.OpenSaveDataFileSystem(ref fileSystem.Ref(), value.SpaceId, saveDataId, in saveDataRootPath, openReadOnly: false, saveDataType, cacheExtraData: true); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); // Verify the file system. - rc = Utility.VerifyDirectoryRecursively(fileSystem.Get, workBuffer.Buffer); - if (rc.IsFailure()) return rc.Miss(); + res = Utility.VerifyDirectoryRecursively(fileSystem.Get, workBuffer.Buffer); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -2547,8 +2547,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.Bis); using var accessor = new UniqueRef(); - Result rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), SaveDataSpaceId.System); - if (rc.IsFailure()) return rc.Miss(); + Result res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), SaveDataSpaceId.System); + if (res.IsFailure()) return res.Miss(); return CleanUpSaveData(accessor.Get).Ret(); } @@ -2564,8 +2564,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.Bis); using var accessor = new UniqueRef(); - Result rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), SaveDataSpaceId.System); - if (rc.IsFailure()) return rc.Miss(); + Result res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), SaveDataSpaceId.System); + if (res.IsFailure()) return res.Miss(); return CompleteSaveDataExtension(accessor.Get).Ret(); } @@ -2581,15 +2581,15 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave using var scopedContext = new ScopedStorageLayoutTypeSetter(StorageLayoutType.Bis); using var fileSystem = new SharedRef(); - Result rc = _serviceImpl.OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref(), SaveDataSpaceId.Temporary); - if (rc.IsFailure()) return rc.Miss(); + Result res = _serviceImpl.OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref(), SaveDataSpaceId.Temporary); + if (res.IsFailure()) return res.Miss(); using var pathRoot = new Path(); - rc = PathFunctions.SetUpFixedPath(ref pathRoot.Ref(), new[] { (byte)'/' }); - if (rc.IsFailure()) return rc.Miss(); + res = PathFunctions.SetUpFixedPath(ref pathRoot.Ref(), new[] { (byte)'/' }); + if (res.IsFailure()) return res.Miss(); - rc = fileSystem.Get.CleanDirectoryRecursively(in pathRoot); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystem.Get.CleanDirectoryRecursively(in pathRoot); + if (res.IsFailure()) return res.Miss(); _serviceImpl.ResetTemporaryStorageIndexer(); return Result.Success; @@ -2612,15 +2612,15 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave public Result OpenMultiCommitContext(ref SharedRef contextFileSystem) { - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, new ProgramId(MultiCommitManager.ProgramId), + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, new ProgramId(MultiCommitManager.ProgramId), SaveDataType.System, InvalidUserId, MultiCommitManager.SaveDataId, index: 0); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); using var fileSystem = new SharedRef(); - rc = OpenSaveDataFileSystemCore(ref fileSystem.Ref(), out _, SaveDataSpaceId.System, in attribute, + res = OpenSaveDataFileSystemCore(ref fileSystem.Ref(), out _, SaveDataSpaceId.System, in attribute, openReadOnly: false, cacheExtraData: true); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); contextFileSystem.SetByMove(ref fileSystem.Ref()); return Result.Success; @@ -2638,25 +2638,25 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave public Result RecoverProvisionallyCommittedSaveData(in SaveDataInfo saveInfo, bool doRollback) { - Result rc = SaveDataAttribute.Make(out SaveDataAttribute attribute, saveInfo.ProgramId, saveInfo.Type, + Result res = SaveDataAttribute.Make(out SaveDataAttribute attribute, saveInfo.ProgramId, saveInfo.Type, saveInfo.UserId, saveInfo.SaveDataId, saveInfo.Index); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); using var fileSystem = new SharedRef(); - rc = OpenSaveDataFileSystemCore(ref fileSystem.Ref(), out _, saveInfo.SpaceId, in attribute, + res = OpenSaveDataFileSystemCore(ref fileSystem.Ref(), out _, saveInfo.SpaceId, in attribute, openReadOnly: false, cacheExtraData: false); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); if (!doRollback) { - rc = fileSystem.Get.Commit(); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystem.Get.Commit(); + if (res.IsFailure()) return res.Miss(); } else { - rc = fileSystem.Get.Rollback(); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystem.Get.Rollback(); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -2666,9 +2666,9 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { using SharedRef saveService = GetSharedFromThis(); - Result rc = Utility.MakeUniqueLockWithPin(ref outSemaphoreLock, _openEntryCountSemaphore, + Result res = Utility.MakeUniqueLockWithPin(ref outSemaphoreLock, _openEntryCountSemaphore, ref saveService.Ref()); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -2677,9 +2677,9 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave { using SharedRef saveService = GetSharedFromThis(); - Result rc = Utility.MakeUniqueLockWithPin(ref outSemaphoreLock, _saveDataMountCountSemaphore, + Result res = Utility.MakeUniqueLockWithPin(ref outSemaphoreLock, _saveDataMountCountSemaphore, ref saveService.Ref()); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -2691,8 +2691,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave public Result SetSdCardAccessibility(bool isAccessible) { - Result rc = GetProgramInfo(out ProgramInfo programInfo); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetProgramInfo(out ProgramInfo programInfo); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.SetSdCardAccessibility)) return ResultFs.PermissionDenied.Log(); @@ -2711,8 +2711,8 @@ internal class SaveDataFileSystemService : ISaveDataTransferCoreInterface, ISave SaveDataSpaceId spaceId) { using var accessor = new UniqueRef(); - Result rc = _serviceImpl.OpenSaveDataIndexerAccessor(ref accessor.Ref(), out bool isInitialOpen, spaceId); - if (rc.IsFailure()) return rc.Miss(); + Result res = _serviceImpl.OpenSaveDataIndexerAccessor(ref accessor.Ref(), out bool isInitialOpen, spaceId); + if (res.IsFailure()) return res.Miss(); if (isInitialOpen) { diff --git a/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs b/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs index c71a3173..002416aa 100644 --- a/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs +++ b/src/LibHac/FsSrv/SaveDataFileSystemServiceImpl.cs @@ -100,8 +100,8 @@ public class SaveDataFileSystemServiceImpl : IDisposable _timeStampGetter = new TimeStampGetter(this); - Result rc = _saveFileSystemCacheManager.Initialize(_config.SaveDataFileSystemCacheCount); - Abort.DoAbortUnless(rc.IsSuccess()); + Result res = _saveFileSystemCacheManager.Initialize(_config.SaveDataFileSystemCacheCount); + Abort.DoAbortUnless(res.IsSuccess()); } public void Dispose() @@ -121,31 +121,31 @@ public class SaveDataFileSystemServiceImpl : IDisposable using var fileSystem = new SharedRef(); - Result rc = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref(), spaceId); - if (rc.IsFailure()) return rc.Miss(); + Result res = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref(), spaceId); + if (res.IsFailure()) return res.Miss(); // Get the path of the save data Unsafe.SkipInit(out Array18 saveImageNameBuffer); using var saveImageName = new Path(); - rc = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId); + if (res.IsFailure()) return res.Miss(); - rc = fileSystem.Get.GetEntryType(out _, in saveImageName); + res = fileSystem.Get.GetEntryType(out _, in saveImageName); - if (rc.IsSuccess()) + if (res.IsSuccess()) { exists = true; return Result.Success; } - else if (ResultFs.PathNotFound.Includes(rc)) + else if (ResultFs.PathNotFound.Includes(res)) { exists = false; return Result.Success; } else { - return rc.Miss(); + return res.Miss(); } } @@ -160,8 +160,8 @@ public class SaveDataFileSystemServiceImpl : IDisposable { using var fileSystem = new SharedRef(); - Result rc = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref(), spaceId, in saveDataRootPath, true); - if (rc.IsFailure()) return rc.Miss(); + Result res = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref(), spaceId, in saveDataRootPath, true); + if (res.IsFailure()) return res.Miss(); bool isEmulatedOnHost = IsAllowedDirectorySaveData(spaceId, in saveDataRootPath); @@ -170,11 +170,11 @@ public class SaveDataFileSystemServiceImpl : IDisposable // Create the save data directory on the host if needed. Unsafe.SkipInit(out Array18 saveDirectoryNameBuffer); using var saveDirectoryName = new Path(); - rc = PathFunctions.SetUpFixedPathSaveId(ref saveDirectoryName.Ref(), saveDirectoryNameBuffer.Items, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = PathFunctions.SetUpFixedPathSaveId(ref saveDirectoryName.Ref(), saveDirectoryNameBuffer.Items, saveDataId); + if (res.IsFailure()) return res.Miss(); - rc = FsSystem.Utility.EnsureDirectory(fileSystem.Get, in saveDirectoryName); - if (rc.IsFailure()) return rc.Miss(); + res = FsSystem.Utility.EnsureDirectory(fileSystem.Get, in saveDirectoryName); + if (res.IsFailure()) return res.Miss(); } using var saveDataFs = new SharedRef(); @@ -190,10 +190,10 @@ public class SaveDataFileSystemServiceImpl : IDisposable bool openShared = SaveDataProperties.IsSharedOpenNeeded(type); bool isReconstructible = SaveDataProperties.IsReconstructible(type, spaceId); - rc = _config.SaveFsCreator.Create(ref saveDataFs.Ref(), ref fileSystem.Ref(), spaceId, saveDataId, + res = _config.SaveFsCreator.Create(ref saveDataFs.Ref(), ref fileSystem.Ref(), spaceId, saveDataId, isEmulatedOnHost, isDeviceUniqueMac, isJournalingSupported, isMultiCommitSupported, openReadOnly, openShared, _timeStampGetter, isReconstructible); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } if (!isEmulatedOnHost && cacheExtraData) @@ -201,8 +201,8 @@ public class SaveDataFileSystemServiceImpl : IDisposable using SharedRef extraDataAccessor = SharedRef.CreateCopy(in saveDataFs); - rc = _saveExtraDataCacheManager.Register(in extraDataAccessor, spaceId, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = _saveExtraDataCacheManager.Register(in extraDataAccessor, spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); } } @@ -233,9 +233,9 @@ public class SaveDataFileSystemServiceImpl : IDisposable Unsafe.SkipInit(out Array27 saveDataMetaIdDirectoryNameBuffer); using var saveDataMetaIdDirectoryName = new Path(); - Result rc = PathFunctions.SetUpFixedPathSaveMetaDir(ref saveDataMetaIdDirectoryName.Ref(), + Result res = PathFunctions.SetUpFixedPathSaveMetaDir(ref saveDataMetaIdDirectoryName.Ref(), saveDataMetaIdDirectoryNameBuffer.Items, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return OpenSaveDataDirectoryFileSystemImpl(ref outFileSystem, spaceId, in saveDataMetaIdDirectoryName).Ret(); } @@ -275,9 +275,9 @@ public class SaveDataFileSystemServiceImpl : IDisposable public Result FinishExtendSaveDataFileSystem(ulong saveDataId, SaveDataSpaceId spaceId) { - Result rc = DeleteSaveDataMeta(saveDataId, spaceId, SaveDataMetaType.ExtensionContext); - if (rc.IsFailure() && !ResultFs.PathNotFound.Includes(rc)) - return rc.Miss(); + Result res = DeleteSaveDataMeta(saveDataId, spaceId, SaveDataMetaType.ExtensionContext); + if (res.IsFailure() && !ResultFs.PathNotFound.Includes(res)) + return res.Miss(); return Result.Success; } @@ -286,9 +286,9 @@ public class SaveDataFileSystemServiceImpl : IDisposable in Path saveDataRootPath) { using var saveDataFile = new UniqueRef(); - Result rc = OpenSaveDataImageFile(ref saveDataFile.Ref(), spaceId, saveDataId, in saveDataRootPath); + Result res = OpenSaveDataImageFile(ref saveDataFile.Ref(), spaceId, saveDataId, in saveDataRootPath); - if (rc.IsSuccess()) + if (res.IsSuccess()) { saveDataFile.Get.SetSize(originalSize).IgnoreResult(); } @@ -308,18 +308,18 @@ public class SaveDataFileSystemServiceImpl : IDisposable { using var fileSystem = new SharedRef(); - Result rc = OpenSaveDataMetaDirectoryFileSystem(ref fileSystem.Ref(), spaceId, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + Result res = OpenSaveDataMetaDirectoryFileSystem(ref fileSystem.Ref(), spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); Unsafe.SkipInit(out Array15 saveDataMetaNameBuffer); using var saveDataMetaName = new Path(); - rc = PathFunctions.SetUpFixedPathSaveMetaName(ref saveDataMetaName.Ref(), saveDataMetaNameBuffer.Items, + res = PathFunctions.SetUpFixedPathSaveMetaName(ref saveDataMetaName.Ref(), saveDataMetaNameBuffer.Items, (uint)metaType); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); - rc = fileSystem.Get.CreateFile(in saveDataMetaName, metaFileSize); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystem.Get.CreateFile(in saveDataMetaName, metaFileSize); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -328,18 +328,18 @@ public class SaveDataFileSystemServiceImpl : IDisposable { using var fileSystem = new SharedRef(); - Result rc = OpenSaveDataMetaDirectoryFileSystem(ref fileSystem.Ref(), spaceId, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + Result res = OpenSaveDataMetaDirectoryFileSystem(ref fileSystem.Ref(), spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); Unsafe.SkipInit(out Array15 saveDataMetaNameBuffer); using var saveDataMetaName = new Path(); - rc = PathFunctions.SetUpFixedPathSaveMetaName(ref saveDataMetaName.Ref(), saveDataMetaNameBuffer.Items, + res = PathFunctions.SetUpFixedPathSaveMetaName(ref saveDataMetaName.Ref(), saveDataMetaNameBuffer.Items, (uint)metaType); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); - rc = fileSystem.Get.DeleteFile(in saveDataMetaName); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystem.Get.DeleteFile(in saveDataMetaName); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -358,27 +358,27 @@ public class SaveDataFileSystemServiceImpl : IDisposable using var fileSystem = new SharedRef(); using var saveDataMetaDirectoryName = new Path(); - Result rc = PathFunctions.SetUpFixedPath(ref saveDataMetaDirectoryName.Ref(), metaDirName); - if (rc.IsFailure()) return rc.Miss(); + Result res = PathFunctions.SetUpFixedPath(ref saveDataMetaDirectoryName.Ref(), metaDirName); + if (res.IsFailure()) return res.Miss(); - rc = OpenSaveDataDirectoryFileSystemImpl(ref fileSystem.Ref(), spaceId, in saveDataMetaDirectoryName, + res = OpenSaveDataDirectoryFileSystemImpl(ref fileSystem.Ref(), spaceId, in saveDataMetaDirectoryName, createIfMissing: false); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); using var saveDataIdDirectoryName = new Path(); PathFunctions.SetUpFixedPathSaveId(ref saveDataIdDirectoryName.Ref(), saveDataIdDirectoryNameBuffer.Items, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); // Delete the save data's meta directory, ignoring the error if the directory is already gone - rc = fileSystem.Get.DeleteDirectoryRecursively(in saveDataIdDirectoryName); + res = fileSystem.Get.DeleteDirectoryRecursively(in saveDataIdDirectoryName); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (ResultFs.PathNotFound.Includes(rc)) + if (ResultFs.PathNotFound.Includes(res)) return Result.Success; - return rc.Miss(); + return res.Miss(); } return Result.Success; @@ -389,18 +389,18 @@ public class SaveDataFileSystemServiceImpl : IDisposable { using var fileSystem = new SharedRef(); - Result rc = OpenSaveDataMetaDirectoryFileSystem(ref fileSystem.Ref(), spaceId, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + Result res = OpenSaveDataMetaDirectoryFileSystem(ref fileSystem.Ref(), spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); Unsafe.SkipInit(out Array15 saveDataMetaNameBuffer); using var saveDataMetaName = new Path(); - rc = PathFunctions.SetUpFixedPathSaveMetaName(ref saveDataMetaName.Ref(), saveDataMetaNameBuffer.Items, + res = PathFunctions.SetUpFixedPathSaveMetaName(ref saveDataMetaName.Ref(), saveDataMetaNameBuffer.Items, (uint)metaType); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); - rc = fileSystem.Get.OpenFile(ref outMetaFile, in saveDataMetaName, OpenMode.ReadWrite); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystem.Get.OpenFile(ref outMetaFile, in saveDataMetaName, OpenMode.ReadWrite); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -418,13 +418,13 @@ public class SaveDataFileSystemServiceImpl : IDisposable using var fileSystem = new SharedRef(); - Result rc = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref(), creationInfo.SpaceId, in saveDataRootPath, + Result res = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref(), creationInfo.SpaceId, in saveDataRootPath, allowEmulatedSave: false); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); using var saveImageName = new Path(); - rc = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId); + if (res.IsFailure()) return res.Miss(); bool isPseudoSaveFs = _config.IsPseudoSaveData(); bool isCreationSuccessful = false; @@ -433,8 +433,8 @@ public class SaveDataFileSystemServiceImpl : IDisposable { if (isPseudoSaveFs) { - rc = FsSystem.Utility.EnsureDirectory(fileSystem.Get, in saveImageName); - if (rc.IsFailure()) return rc.Miss(); + res = FsSystem.Utility.EnsureDirectory(fileSystem.Get, in saveImageName); + if (res.IsFailure()) return res.Miss(); } else { @@ -445,8 +445,8 @@ public class SaveDataFileSystemServiceImpl : IDisposable extraData.Attribute = creationInfo.Attribute; extraData.OwnerId = ownerId; - rc = GetSaveDataCommitTimeStamp(out extraData.TimeStamp); - if (rc.IsFailure()) + res = GetSaveDataCommitTimeStamp(out extraData.TimeStamp); + if (res.IsFailure()) extraData.TimeStamp = 0; extraData.CommitId = 0; @@ -457,9 +457,9 @@ public class SaveDataFileSystemServiceImpl : IDisposable extraData.JournalSize = journalSize; extraData.FormatType = creationInfo.FormatType; - rc = WriteSaveDataFileSystemExtraData(spaceId, saveDataId, in extraData, in saveDataRootPath, + res = WriteSaveDataFileSystemExtraData(spaceId, saveDataId, in extraData, in saveDataRootPath, creationInfo.Attribute.Type, updateTimeStamp: true); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); isCreationSuccessful = true; return Result.Success; @@ -491,22 +491,22 @@ public class SaveDataFileSystemServiceImpl : IDisposable _saveFileSystemCacheManager.Unregister(spaceId, saveDataId); // Open the directory containing the save data - Result rc = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref(), spaceId, in saveDataRootPath, false); - if (rc.IsFailure()) return rc.Miss(); + Result res = OpenSaveDataDirectoryFileSystem(ref fileSystem.Ref(), spaceId, in saveDataRootPath, false); + if (res.IsFailure()) return res.Miss(); using var saveImageName = new Path(); - rc = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId); + if (res.IsFailure()) return res.Miss(); // Check if the save data is a file or a directory - rc = fileSystem.Get.GetEntryType(out DirectoryEntryType entryType, in saveImageName); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystem.Get.GetEntryType(out DirectoryEntryType entryType, in saveImageName); + if (res.IsFailure()) return res.Miss(); // Delete the save data, wiping the file if needed if (entryType == DirectoryEntryType.Directory) { - rc = fileSystem.Get.DeleteDirectoryRecursively(in saveImageName); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystem.Get.DeleteDirectoryRecursively(in saveImageName); + if (res.IsFailure()) return res.Miss(); } else { @@ -518,10 +518,10 @@ public class SaveDataFileSystemServiceImpl : IDisposable if (GetDebugConfigurationService().Get(DebugOptionKey.SaveDataEncryption, 0) != 0) { using SharedRef tempFileSystem = SharedRef.CreateCopy(in fileSystem); - rc = _config.SaveFsCreator.IsDataEncrypted(out isDataEncrypted, ref tempFileSystem.Ref(), + res = _config.SaveFsCreator.IsDataEncrypted(out isDataEncrypted, ref tempFileSystem.Ref(), saveDataId, _config.BufferManager, IsDeviceUniqueMac(spaceId), isReconstructible: false); - if (rc.IsFailure()) + if (res.IsFailure()) isDataEncrypted = false; } @@ -535,8 +535,8 @@ public class SaveDataFileSystemServiceImpl : IDisposable } } - rc = fileSystem.Get.DeleteFile(in saveImageName); - if (rc.IsFailure()) return rc.Miss(); + res = fileSystem.Get.DeleteFile(in saveImageName); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -561,26 +561,26 @@ public class SaveDataFileSystemServiceImpl : IDisposable using var extraDataAccessor = new SharedRef(); // Try to grab an extra data accessor for the requested save from the cache. - Result rc = _saveExtraDataCacheManager.GetCache(ref extraDataAccessor.Ref(), spaceId, saveDataId); + Result res = _saveExtraDataCacheManager.GetCache(ref extraDataAccessor.Ref(), spaceId, saveDataId); - if (rc.IsFailure()) + if (res.IsFailure()) { // Try to open the extra data accessor if it's not in the cache. // We won't actually use the returned save data FS. // Opening the FS should cache an extra data accessor for it. - rc = OpenSaveDataFileSystem(ref unusedSaveDataFs.Ref(), spaceId, saveDataId, saveDataRootPath, + res = OpenSaveDataFileSystem(ref unusedSaveDataFs.Ref(), spaceId, saveDataId, saveDataRootPath, openReadOnly: true, type, cacheExtraData: true); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); // Try to grab an accessor from the cache again. - rc = _saveExtraDataCacheManager.GetCache(ref extraDataAccessor.Ref(), spaceId, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = _saveExtraDataCacheManager.GetCache(ref extraDataAccessor.Ref(), spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); } // We successfully got an extra data accessor. Read the extra data from it. - rc = extraDataAccessor.Get.ReadExtraData(out extraData); - if (rc.IsFailure()) return rc.Miss(); + res = extraDataAccessor.Get.ReadExtraData(out extraData); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -601,30 +601,30 @@ public class SaveDataFileSystemServiceImpl : IDisposable using var extraDataAccessor = new SharedRef(); // Try to grab an extra data accessor for the requested save from the cache. - Result rc = _saveExtraDataCacheManager.GetCache(ref extraDataAccessor.Ref(), spaceId, saveDataId); + Result res = _saveExtraDataCacheManager.GetCache(ref extraDataAccessor.Ref(), spaceId, saveDataId); - if (rc.IsFailure()) + if (res.IsFailure()) { // No accessor was found in the cache. Try to open one. // We won't actually use the returned save data FS. // Opening the FS should cache an extra data accessor for it. - rc = OpenSaveDataFileSystem(ref unusedSaveDataFs.Ref(), spaceId, saveDataId, saveDataRootPath, + res = OpenSaveDataFileSystem(ref unusedSaveDataFs.Ref(), spaceId, saveDataId, saveDataRootPath, openReadOnly: false, type, cacheExtraData: true); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); // Try to grab an accessor from the cache again. - rc = _saveExtraDataCacheManager.GetCache(ref extraDataAccessor.Ref(), spaceId, saveDataId); - if (rc.IsFailure()) return rc.Miss(); + res = _saveExtraDataCacheManager.GetCache(ref extraDataAccessor.Ref(), spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); } // We should have a valid accessor if we've reached this point. // Write and commit the extra data. - rc = extraDataAccessor.Get.WriteExtraData(in extraData); - if (rc.IsFailure()) return rc.Miss(); + res = extraDataAccessor.Get.WriteExtraData(in extraData); + if (res.IsFailure()) return res.Miss(); - rc = extraDataAccessor.Get.CommitExtraData(updateTimeStamp); - if (rc.IsFailure()) return rc.Miss(); + res = extraDataAccessor.Get.CommitExtraData(updateTimeStamp); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -656,7 +656,7 @@ public class SaveDataFileSystemServiceImpl : IDisposable public Result OpenSaveDataDirectoryFileSystem(ref SharedRef outFileSystem, SaveDataSpaceId spaceId, in Path saveDataRootPath, bool allowEmulatedSave) { - Result rc; + Result res; if (allowEmulatedSave && IsAllowedDirectorySaveData(spaceId, in saveDataRootPath)) { @@ -665,28 +665,28 @@ public class SaveDataFileSystemServiceImpl : IDisposable using (var tmFileSystem = new SharedRef()) { // Ensure the target save data directory exists - rc = _config.TargetManagerFsCreator.Create(ref tmFileSystem.Ref(), in saveDataRootPath, + res = _config.TargetManagerFsCreator.Create(ref tmFileSystem.Ref(), in saveDataRootPath, openCaseSensitive: false, ensureRootPathExists: true, ResultFs.SaveDataRootPathUnavailable.Value); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } using var path = new Path(); - rc = path.Initialize(in saveDataRootPath); - if (rc.IsFailure()) return rc.Miss(); + res = path.Initialize(in saveDataRootPath); + if (res.IsFailure()) return res.Miss(); - rc = _config.TargetManagerFsCreator.NormalizeCaseOfPath(out bool isTargetFsCaseSensitive, ref path.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = _config.TargetManagerFsCreator.NormalizeCaseOfPath(out bool isTargetFsCaseSensitive, ref path.Ref()); + if (res.IsFailure()) return res.Miss(); - rc = _config.TargetManagerFsCreator.Create(ref outFileSystem, in path, isTargetFsCaseSensitive, + res = _config.TargetManagerFsCreator.Create(ref outFileSystem, in path, isTargetFsCaseSensitive, ensureRootPathExists: false, ResultFs.SaveDataRootPathUnavailable.Value); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } else { - rc = _config.LocalFsCreator.Create(ref outFileSystem, in saveDataRootPath, openCaseSensitive: true, + res = _config.LocalFsCreator.Create(ref outFileSystem, in saveDataRootPath, openCaseSensitive: true, ensureRootPathExists: true, ResultFs.SaveDataRootPathUnavailable.Value); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -704,11 +704,11 @@ public class SaveDataFileSystemServiceImpl : IDisposable saveDirName = new[] { (byte)'/', (byte)'s', (byte)'a', (byte)'v', (byte)'e' }; // /save } - rc = PathFunctions.SetUpFixedPath(ref saveDataAreaDirectoryName.Ref(), saveDirName); - if (rc.IsFailure()) return rc.Miss(); + res = PathFunctions.SetUpFixedPath(ref saveDataAreaDirectoryName.Ref(), saveDirName); + if (res.IsFailure()) return res.Miss(); - rc = OpenSaveDataDirectoryFileSystemImpl(ref outFileSystem, spaceId, in saveDataAreaDirectoryName); - if (rc.IsFailure()) return rc.Miss(); + res = OpenSaveDataDirectoryFileSystemImpl(ref outFileSystem, spaceId, in saveDataAreaDirectoryName); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -728,13 +728,13 @@ public class SaveDataFileSystemServiceImpl : IDisposable { case SaveDataSpaceId.System: { - Result rc = _config.BaseFsService.OpenBisFileSystem(ref baseFileSystem.Ref(), BisPartitionId.System, + Result res = _config.BaseFsService.OpenBisFileSystem(ref baseFileSystem.Ref(), BisPartitionId.System, caseSensitive: true); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); - rc = Utility.WrapSubDirectory(ref outFileSystem, ref baseFileSystem.Ref(), in directoryPath, + res = Utility.WrapSubDirectory(ref outFileSystem, ref baseFileSystem.Ref(), in directoryPath, createIfMissing); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); break; } @@ -742,13 +742,13 @@ public class SaveDataFileSystemServiceImpl : IDisposable case SaveDataSpaceId.User: case SaveDataSpaceId.Temporary: { - Result rc = _config.BaseFsService.OpenBisFileSystem(ref baseFileSystem.Ref(), BisPartitionId.User, + Result res = _config.BaseFsService.OpenBisFileSystem(ref baseFileSystem.Ref(), BisPartitionId.User, caseSensitive: true); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); - rc = Utility.WrapSubDirectory(ref outFileSystem, ref baseFileSystem.Ref(), in directoryPath, + res = Utility.WrapSubDirectory(ref outFileSystem, ref baseFileSystem.Ref(), in directoryPath, createIfMissing); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); break; } @@ -756,55 +756,55 @@ public class SaveDataFileSystemServiceImpl : IDisposable case SaveDataSpaceId.SdSystem: case SaveDataSpaceId.SdUser: { - Result rc = _config.BaseFsService.OpenSdCardProxyFileSystem(ref baseFileSystem.Ref(), + Result res = _config.BaseFsService.OpenSdCardProxyFileSystem(ref baseFileSystem.Ref(), openCaseSensitive: true); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); Unsafe.SkipInit(out Array64 pathParentBuffer); using var pathParent = new Path(); - rc = PathFunctions.SetUpFixedPathSingleEntry(ref pathParent.Ref(), pathParentBuffer.Items, + res = PathFunctions.SetUpFixedPathSingleEntry(ref pathParent.Ref(), pathParentBuffer.Items, CommonPaths.SdCardNintendoRootDirectoryName); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); using var pathSdRoot = new Path(); - rc = pathSdRoot.Combine(in pathParent, in directoryPath); - if (rc.IsFailure()) return rc.Miss(); + res = pathSdRoot.Combine(in pathParent, in directoryPath); + if (res.IsFailure()) return res.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(); + res = Utility.WrapSubDirectory(ref baseFileSystem.Ref(), ref tempFileSystem.Ref(), in pathSdRoot, createIfMissing); + if (res.IsFailure()) return res.Miss(); - rc = _config.EncryptedFsCreator.Create(ref outFileSystem, ref baseFileSystem.Ref(), + res = _config.EncryptedFsCreator.Create(ref outFileSystem, ref baseFileSystem.Ref(), IEncryptedFileSystemCreator.KeyId.Save, in _encryptionSeed); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); break; } case SaveDataSpaceId.ProperSystem: { - Result rc = _config.BaseFsService.OpenBisFileSystem(ref baseFileSystem.Ref(), + Result res = _config.BaseFsService.OpenBisFileSystem(ref baseFileSystem.Ref(), BisPartitionId.SystemProperPartition, caseSensitive: true); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); - rc = Utility.WrapSubDirectory(ref outFileSystem, ref baseFileSystem.Ref(), in directoryPath, + res = Utility.WrapSubDirectory(ref outFileSystem, ref baseFileSystem.Ref(), in directoryPath, createIfMissing); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); break; } case SaveDataSpaceId.SafeMode: { - Result rc = _config.BaseFsService.OpenBisFileSystem(ref baseFileSystem.Ref(), BisPartitionId.SafeMode, + Result res = _config.BaseFsService.OpenBisFileSystem(ref baseFileSystem.Ref(), BisPartitionId.SafeMode, caseSensitive: true); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); - rc = Utility.WrapSubDirectory(ref outFileSystem, ref baseFileSystem.Ref(), in directoryPath, + res = Utility.WrapSubDirectory(ref outFileSystem, ref baseFileSystem.Ref(), in directoryPath, createIfMissing); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); break; } @@ -890,8 +890,8 @@ public class SaveDataFileSystemServiceImpl : IDisposable UnsafeHelpers.SkipParamInit(out count); using var accessor = new UniqueRef(); - Result rc = OpenSaveDataIndexerAccessor(ref accessor.Ref(), out bool _, SaveDataSpaceId.User); - if (rc.IsFailure()) return rc.Miss(); + Result res = OpenSaveDataIndexerAccessor(ref accessor.Ref(), out bool _, SaveDataSpaceId.User); + if (res.IsFailure()) return res.Miss(); count = accessor.Get.GetInterface().GetIndexCount(); return Result.Success; diff --git a/src/LibHac/FsSrv/SaveDataIndexer.cs b/src/LibHac/FsSrv/SaveDataIndexer.cs index 6096d78a..7f9ab314 100644 --- a/src/LibHac/FsSrv/SaveDataIndexer.cs +++ b/src/LibHac/FsSrv/SaveDataIndexer.cs @@ -89,40 +89,40 @@ public class SaveDataIndexer : ISaveDataIndexer _fsClient.DisableAutoSaveDataCreation(); - Result rc = _fsClient.MountSystemSaveData(new U8Span(_mountName), spaceId, saveDataId); + Result res = _fsClient.MountSystemSaveData(new U8Span(_mountName), spaceId, saveDataId); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (ResultFs.TargetNotFound.Includes(rc)) + if (ResultFs.TargetNotFound.Includes(res)) { - rc = _fsClient.CreateSystemSaveData(spaceId, saveDataId, 0, SaveDataAvailableSize, + res = _fsClient.CreateSystemSaveData(spaceId, saveDataId, 0, SaveDataAvailableSize, SaveDataJournalSize, 0); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = _fsClient.MountSystemSaveData(new U8Span(_mountName), spaceId, saveDataId); - if (rc.IsFailure()) return rc; + res = _fsClient.MountSystemSaveData(new U8Span(_mountName), spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); } - else if (ResultFs.SignedSystemPartitionDataCorrupted.Includes(rc)) + else if (ResultFs.SignedSystemPartitionDataCorrupted.Includes(res)) { - return rc; + return res; } - else if (ResultFs.DataCorrupted.Includes(rc)) + else if (ResultFs.DataCorrupted.Includes(res)) { if (spaceId == SaveDataSpaceId.SdSystem) - return rc; + return res; - rc = _fsClient.DeleteSaveData(spaceId, saveDataId); - if (rc.IsFailure()) return rc; + res = _fsClient.DeleteSaveData(spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); - rc = _fsClient.CreateSystemSaveData(spaceId, saveDataId, 0, 0xC0000, 0xC0000, 0); - if (rc.IsFailure()) return rc; + res = _fsClient.CreateSystemSaveData(spaceId, saveDataId, 0, 0xC0000, 0xC0000, 0); + if (res.IsFailure()) return res.Miss(); - rc = _fsClient.MountSystemSaveData(new U8Span(_mountName), spaceId, saveDataId); - if (rc.IsFailure()) return rc; + res = _fsClient.MountSystemSaveData(new U8Span(_mountName), spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); } else { - return rc; + return res; } } @@ -308,14 +308,14 @@ public class SaveDataIndexer : ISaveDataIndexer using var scopedMount = new ScopedMount(_fsClient); - Result rc = scopedMount.Mount(_mountName, _spaceId, _indexerSaveDataId); - if (rc.IsFailure()) return rc; + Result res = scopedMount.Mount(_mountName, _spaceId, _indexerSaveDataId); + if (res.IsFailure()) return res.Miss(); Span rootPath = stackalloc byte[MaxPathLength]; MakeRootPath(rootPath, _mountName); - rc = _kvDatabase.Initialize(_fsClient, new U8Span(rootPath), KvDatabaseCapacity, _memoryResource, _bufferMemoryResource); - if (rc.IsFailure()) return rc; + res = _kvDatabase.Initialize(_fsClient, new U8Span(rootPath), KvDatabaseCapacity, _memoryResource, _bufferMemoryResource); + if (res.IsFailure()) return res.Miss(); _isInitialized = true; return Result.Success; @@ -337,11 +337,11 @@ public class SaveDataIndexer : ISaveDataIndexer return Result.Success; using var scopedMount = new ScopedMount(_fsClient); - Result rc = scopedMount.Mount(_mountName, _spaceId, _indexerSaveDataId); - if (rc.IsFailure()) return rc; + Result res = scopedMount.Mount(_mountName, _spaceId, _indexerSaveDataId); + if (res.IsFailure()) return res.Miss(); - rc = _kvDatabase.Load(); - if (rc.IsFailure()) return rc; + res = _kvDatabase.Load(); + if (res.IsFailure()) return res.Miss(); bool createdNewFile = false; @@ -350,18 +350,18 @@ public class SaveDataIndexer : ISaveDataIndexer try { - rc = _fsClient.OpenFile(out FileHandle file, new U8Span(lastPublishedIdPath), OpenMode.Read); + res = _fsClient.OpenFile(out FileHandle file, new U8Span(lastPublishedIdPath), OpenMode.Read); // Create the last published ID file if it doesn't exist. - if (rc.IsFailure()) + if (res.IsFailure()) { - if (!ResultFs.PathNotFound.Includes(rc)) return rc; + if (!ResultFs.PathNotFound.Includes(res)) return res; - rc = _fsClient.CreateFile(new U8Span(lastPublishedIdPath), LastPublishedIdFileSize); - if (rc.IsFailure()) return rc; + res = _fsClient.CreateFile(new U8Span(lastPublishedIdPath), LastPublishedIdFileSize); + if (res.IsFailure()) return res.Miss(); - rc = _fsClient.OpenFile(out file, new U8Span(lastPublishedIdPath), OpenMode.Read); - if (rc.IsFailure()) return rc; + res = _fsClient.OpenFile(out file, new U8Span(lastPublishedIdPath), OpenMode.Read); + if (res.IsFailure()) return res.Miss(); createdNewFile = true; } @@ -371,8 +371,8 @@ public class SaveDataIndexer : ISaveDataIndexer // If we had to create the file earlier, we don't need to load the value again. if (!createdNewFile) { - rc = _fsClient.ReadFile(file, 0, SpanHelpers.AsByteSpan(ref _lastPublishedId)); - if (rc.IsFailure()) return rc; + res = _fsClient.ReadFile(file, 0, SpanHelpers.AsByteSpan(ref _lastPublishedId)); + if (res.IsFailure()) return res.Miss(); } else { @@ -404,19 +404,19 @@ public class SaveDataIndexer : ISaveDataIndexer using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - Result rc = TryInitializeDatabase(); - if (rc.IsFailure()) return rc; + Result res = TryInitializeDatabase(); + if (res.IsFailure()) return res.Miss(); - rc = TryLoadDatabase(forceLoad: false); - if (rc.IsFailure()) return rc; + res = TryLoadDatabase(forceLoad: false); + if (res.IsFailure()) return res.Miss(); Assert.SdkRequires(_isLoaded); // Make sure the key isn't in the database already. SaveDataIndexerValue value = default; - rc = _kvDatabase.Get(out _, in key, SpanHelpers.AsByteSpan(ref value)); + res = _kvDatabase.Get(out _, in key, SpanHelpers.AsByteSpan(ref value)); - if (rc.IsSuccess()) + if (res.IsSuccess()) { return ResultFs.AlreadyExists.Log(); } @@ -426,16 +426,16 @@ public class SaveDataIndexer : ISaveDataIndexer ulong newSaveDataId = _lastPublishedId; value = new SaveDataIndexerValue { SaveDataId = newSaveDataId }; - rc = _kvDatabase.Set(in key, SpanHelpers.AsByteSpan(ref value)); + res = _kvDatabase.Set(in key, SpanHelpers.AsByteSpan(ref value)); - if (rc.IsFailure()) + if (res.IsFailure()) { _lastPublishedId--; - return rc; + return res; } - rc = FixReader(in key); - if (rc.IsFailure()) return rc; + res = FixReader(in key); + if (res.IsFailure()) return res.Miss(); saveDataId = value.SaveDataId; return Result.Success; @@ -445,11 +445,11 @@ public class SaveDataIndexer : ISaveDataIndexer { using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - Result rc = TryInitializeDatabase(); - if (rc.IsFailure()) return rc; + Result res = TryInitializeDatabase(); + if (res.IsFailure()) return res.Miss(); - rc = TryLoadDatabase(forceLoad: false); - if (rc.IsFailure()) return rc; + res = TryLoadDatabase(forceLoad: false); + if (res.IsFailure()) return res.Miss(); Assert.SdkRequires(_isLoaded); Assert.SdkRequires(key.StaticSaveDataId != InvalidSystemSaveDataId); @@ -469,11 +469,11 @@ public class SaveDataIndexer : ISaveDataIndexer var value = new SaveDataIndexerValue { SaveDataId = key.StaticSaveDataId }; - rc = _kvDatabase.Set(in key, SpanHelpers.AsReadOnlyByteSpan(in value)); - if (rc.IsFailure()) return rc; + res = _kvDatabase.Set(in key, SpanHelpers.AsReadOnlyByteSpan(in value)); + if (res.IsFailure()) return res.Miss(); - rc = FixReader(in key); - if (rc.IsFailure()) return rc; + res = FixReader(in key); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -489,11 +489,11 @@ public class SaveDataIndexer : ISaveDataIndexer { using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - Result rc = TryInitializeDatabase(); - if (rc.IsFailure()) return rc; + Result res = TryInitializeDatabase(); + if (res.IsFailure()) return res.Miss(); - rc = TryLoadDatabase(forceLoad: false); - if (rc.IsFailure()) return rc; + res = TryLoadDatabase(forceLoad: false); + if (res.IsFailure()) return res.Miss(); Assert.SdkRequires(_isLoaded); @@ -512,11 +512,11 @@ public class SaveDataIndexer : ISaveDataIndexer SaveDataAttribute key = iterator.Get().Key; - rc = _kvDatabase.Delete(in key); - if (rc.IsFailure()) return rc; + res = _kvDatabase.Delete(in key); + if (res.IsFailure()) return res.Miss(); - rc = FixReader(in key); - if (rc.IsFailure()) return rc; + res = FixReader(in key); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -526,39 +526,39 @@ public class SaveDataIndexer : ISaveDataIndexer using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); // Make sure we've loaded the database - Result rc = TryInitializeDatabase(); - if (rc.IsFailure()) return rc; + Result res = TryInitializeDatabase(); + if (res.IsFailure()) return res.Miss(); - rc = TryLoadDatabase(forceLoad: false); - if (rc.IsFailure()) return rc; + res = TryLoadDatabase(forceLoad: false); + if (res.IsFailure()) return res.Miss(); Assert.SdkRequires(_isLoaded); // Mount the indexer's save data using var scopedMount = new ScopedMount(_fsClient); - rc = scopedMount.Mount(_mountName, _spaceId, _indexerSaveDataId); - if (rc.IsFailure()) return rc; + res = scopedMount.Mount(_mountName, _spaceId, _indexerSaveDataId); + if (res.IsFailure()) return res.Miss(); // Save the actual database - rc = _kvDatabase.Save(); - if (rc.IsFailure()) return rc; + res = _kvDatabase.Save(); + if (res.IsFailure()) return res.Miss(); // Save the last published save data ID Span lastPublishedIdPath = stackalloc byte[MaxPathLength]; MakeLastPublishedIdSaveFilePath(lastPublishedIdPath, _mountName); - rc = _fsClient.OpenFile(out FileHandle file, new U8Span(lastPublishedIdPath), OpenMode.Write); - if (rc.IsFailure()) return rc; + res = _fsClient.OpenFile(out FileHandle file, new U8Span(lastPublishedIdPath), OpenMode.Write); + if (res.IsFailure()) return res.Miss(); bool isFileClosed = false; try { - rc = _fsClient.WriteFile(file, 0, SpanHelpers.AsByteSpan(ref _lastPublishedId), WriteOption.None); - if (rc.IsFailure()) return rc; + res = _fsClient.WriteFile(file, 0, SpanHelpers.AsByteSpan(ref _lastPublishedId), WriteOption.None); + if (res.IsFailure()) return res.Miss(); - rc = _fsClient.FlushFile(file); - if (rc.IsFailure()) return rc; + res = _fsClient.FlushFile(file); + if (res.IsFailure()) return res.Miss(); _fsClient.CloseFile(file); isFileClosed = true; @@ -578,11 +578,11 @@ public class SaveDataIndexer : ISaveDataIndexer { using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - Result rc = TryInitializeDatabase(); - if (rc.IsFailure()) return rc; + Result res = TryInitializeDatabase(); + if (res.IsFailure()) return res.Miss(); - rc = TryLoadDatabase(forceLoad: true); - if (rc.IsFailure()) return rc; + res = TryLoadDatabase(forceLoad: true); + if (res.IsFailure()) return res.Miss(); UpdateHandle(); return Result.Success; @@ -595,14 +595,14 @@ public class SaveDataIndexer : ISaveDataIndexer if (_isLoaded) _isLoaded = false; - Result rc = _fsClient.DeleteSaveData(_indexerSaveDataId); + Result res = _fsClient.DeleteSaveData(_indexerSaveDataId); - if (rc.IsSuccess() || ResultFs.TargetNotFound.Includes(rc)) + if (res.IsSuccess() || ResultFs.TargetNotFound.Includes(res)) { UpdateHandle(); } - return rc; + return res; } public Result Get(out SaveDataIndexerValue value, in SaveDataAttribute key) @@ -611,19 +611,19 @@ public class SaveDataIndexer : ISaveDataIndexer using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - Result rc = TryInitializeDatabase(); - if (rc.IsFailure()) return rc; + Result res = TryInitializeDatabase(); + if (res.IsFailure()) return res.Miss(); - rc = TryLoadDatabase(forceLoad: false); - if (rc.IsFailure()) return rc; + res = TryLoadDatabase(forceLoad: false); + if (res.IsFailure()) return res.Miss(); Assert.SdkRequires(_isLoaded); - rc = _kvDatabase.Get(out _, in key, SpanHelpers.AsByteSpan(ref value)); + res = _kvDatabase.Get(out _, in key, SpanHelpers.AsByteSpan(ref value)); - if (rc.IsFailure()) + if (res.IsFailure()) { - return ResultFs.TargetNotFound.LogConverted(rc); + return ResultFs.TargetNotFound.LogConverted(res); } return Result.Success; @@ -665,11 +665,11 @@ public class SaveDataIndexer : ISaveDataIndexer using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - Result rc = TryInitializeDatabase(); - if (rc.IsFailure()) return rc; + Result res = TryInitializeDatabase(); + if (res.IsFailure()) return res.Miss(); - rc = TryLoadDatabase(forceLoad: false); - if (rc.IsFailure()) return rc; + res = TryLoadDatabase(forceLoad: false); + if (res.IsFailure()) return res.Miss(); Assert.SdkRequires(_isLoaded); @@ -695,11 +695,11 @@ public class SaveDataIndexer : ISaveDataIndexer using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - Result rc = TryInitializeDatabase(); - if (rc.IsFailure()) return rc; + Result res = TryInitializeDatabase(); + if (res.IsFailure()) return res.Miss(); - rc = TryLoadDatabase(forceLoad: false); - if (rc.IsFailure()) return rc; + res = TryLoadDatabase(forceLoad: false); + if (res.IsFailure()) return res.Miss(); Assert.SdkRequires(_isLoaded); @@ -725,11 +725,11 @@ public class SaveDataIndexer : ISaveDataIndexer { using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - Result rc = TryInitializeDatabase(); - if (rc.IsFailure()) return rc; + Result res = TryInitializeDatabase(); + if (res.IsFailure()) return res.Miss(); - rc = TryLoadDatabase(forceLoad: false); - if (rc.IsFailure()) return rc; + res = TryLoadDatabase(forceLoad: false); + if (res.IsFailure()) return res.Miss(); Assert.SdkRequires(_isLoaded); @@ -836,16 +836,16 @@ public class SaveDataIndexer : ISaveDataIndexer { using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - Result rc = TryInitializeDatabase(); - if (rc.IsFailure()) return rc; + Result res = TryInitializeDatabase(); + if (res.IsFailure()) return res.Miss(); - rc = TryLoadDatabase(forceLoad: false); - if (rc.IsFailure()) return rc; + res = TryLoadDatabase(forceLoad: false); + if (res.IsFailure()) return res.Miss(); // Create the reader and register it in the opened-reader list using var reader = new SharedRef(new Reader(this)); - rc = RegisterReader(in reader); - if (rc.IsFailure()) return rc; + res = RegisterReader(in reader); + if (res.IsFailure()) return res.Miss(); outInfoReader.SetByMove(ref reader.Ref()); return Result.Success; @@ -884,11 +884,11 @@ public class SaveDataIndexer : ISaveDataIndexer { using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - Result rc = TryInitializeDatabase(); - if (rc.IsFailure()) return rc; + Result res = TryInitializeDatabase(); + if (res.IsFailure()) return res.Miss(); - rc = TryLoadDatabase(forceLoad: false); - if (rc.IsFailure()) return rc; + res = TryLoadDatabase(forceLoad: false); + if (res.IsFailure()) return res.Miss(); Assert.SdkRequires(_isLoaded); @@ -915,8 +915,8 @@ public class SaveDataIndexer : ISaveDataIndexer // Run the function on the save data's indexer value and update the value in the database func(ref value, data); - rc = _kvDatabase.Set(in iterator.Get().Key, SpanHelpers.AsReadOnlyByteSpan(in value)); - if (rc.IsFailure()) return rc; + res = _kvDatabase.Set(in iterator.Get().Key, SpanHelpers.AsReadOnlyByteSpan(in value)); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/FsSrv/SaveDataIndexerManager.cs b/src/LibHac/FsSrv/SaveDataIndexerManager.cs index a4abcf9b..a2aab577 100644 --- a/src/LibHac/FsSrv/SaveDataIndexerManager.cs +++ b/src/LibHac/FsSrv/SaveDataIndexerManager.cs @@ -104,8 +104,8 @@ internal class SaveDataIndexerManager : ISaveDataIndexerManager, IDisposable { case SaveDataSpaceId.Temporary: // ReSharper disable once RedundantAssignment - Result rc = _tempIndexer.Reset(); - Assert.SdkAssert(rc.IsSuccess()); + Result res = _tempIndexer.Reset(); + Assert.SdkAssert(res.IsSuccess()); break; default: diff --git a/src/LibHac/FsSrv/SaveDataInfoFilter.cs b/src/LibHac/FsSrv/SaveDataInfoFilter.cs index 0bfc509f..71f98f1d 100644 --- a/src/LibHac/FsSrv/SaveDataInfoFilter.cs +++ b/src/LibHac/FsSrv/SaveDataInfoFilter.cs @@ -138,8 +138,8 @@ internal class SaveDataInfoFilterReader : SaveDataInfoReaderImpl while (count < outInfo.Length) { Unsafe.SkipInit(out SaveDataInfo info); - Result rc = _reader.Get.Read(out long baseReadCount, OutBuffer.FromStruct(ref info)); - if (rc.IsFailure()) return rc; + Result res = _reader.Get.Read(out long baseReadCount, OutBuffer.FromStruct(ref info)); + if (res.IsFailure()) return res.Miss(); if (baseReadCount == 0) break; diff --git a/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs b/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs index c85e4508..bb176244 100644 --- a/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs +++ b/src/LibHac/FsSrv/SaveDataSharedFileStorage.cs @@ -76,8 +76,8 @@ public class SaveDataOpenTypeSetFileStorage : FileStorageBasedFileSystem public Result Initialize(ref SharedRef baseFileSystem, in Path path, OpenMode mode, OpenType type) { - Result rc = Initialize(ref baseFileSystem, in path, mode); - if (rc.IsFailure()) return rc; + Result res = Initialize(ref baseFileSystem, in path, mode); + if (res.IsFailure()) return res.Miss(); return SetOpenType(type); } @@ -205,8 +205,8 @@ public class SaveDataSharedFileStorage : IStorage { using UniqueLockRef scopedLock = _baseStorage.Get.GetLock(); - Result rc = AccessCheck(isWriteAccess: false); - if (rc.IsFailure()) return rc; + Result res = AccessCheck(isWriteAccess: false); + if (res.IsFailure()) return res.Miss(); return _baseStorage.Get.Read(offset, destination); } @@ -215,8 +215,8 @@ public class SaveDataSharedFileStorage : IStorage { using UniqueLockRef scopedLock = _baseStorage.Get.GetLock(); - Result rc = AccessCheck(isWriteAccess: true); - if (rc.IsFailure()) return rc; + Result res = AccessCheck(isWriteAccess: true); + if (res.IsFailure()) return res.Miss(); return _baseStorage.Get.Write(offset, source); } @@ -225,8 +225,8 @@ public class SaveDataSharedFileStorage : IStorage { using UniqueLockRef scopedLock = _baseStorage.Get.GetLock(); - Result rc = AccessCheck(isWriteAccess: true); - if (rc.IsFailure()) return rc; + Result res = AccessCheck(isWriteAccess: true); + if (res.IsFailure()) return res.Miss(); return _baseStorage.Get.SetSize(size); } @@ -237,8 +237,8 @@ public class SaveDataSharedFileStorage : IStorage using UniqueLockRef scopedLock = _baseStorage.Get.GetLock(); - Result rc = AccessCheck(isWriteAccess: false); - if (rc.IsFailure()) return rc; + Result res = AccessCheck(isWriteAccess: false); + if (res.IsFailure()) return res.Miss(); return _baseStorage.Get.GetSize(out size); } @@ -247,8 +247,8 @@ public class SaveDataSharedFileStorage : IStorage { using UniqueLockRef scopedLock = _baseStorage.Get.GetLock(); - Result rc = AccessCheck(isWriteAccess: true); - if (rc.IsFailure()) return rc; + Result res = AccessCheck(isWriteAccess: true); + if (res.IsFailure()) return res.Miss(); return _baseStorage.Get.Flush(); } @@ -258,8 +258,8 @@ public class SaveDataSharedFileStorage : IStorage { using UniqueLockRef scopedLock = _baseStorage.Get.GetLock(); - Result rc = AccessCheck(isWriteAccess: true); - if (rc.IsFailure()) return rc; + Result res = AccessCheck(isWriteAccess: true); + if (res.IsFailure()) return res.Miss(); return _baseStorage.Get.OperateRange(outBuffer, operationId, offset, size, inBuffer); } @@ -337,15 +337,15 @@ public class SaveDataFileStorageHolder Unsafe.SkipInit(out Array18 saveImageNameBuffer); using var saveImageName = new Path(); - Result rc = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId); - if (rc.IsFailure()) return rc; + Result res = PathFunctions.SetUpFixedPathSaveId(ref saveImageName.Ref(), saveImageNameBuffer.Items, saveDataId); + if (res.IsFailure()) return res.Miss(); // If an open type isn't specified, open the save without the shared file storage layer if (!type.HasValue) { using var fileStorage = new SharedRef(new FileStorageBasedFileSystem()); - rc = fileStorage.Get.Initialize(ref baseFileSystem, in saveImageName, mode); - if (rc.IsFailure()) return rc; + res = fileStorage.Get.Initialize(ref baseFileSystem, in saveImageName, mode); + if (res.IsFailure()) return res.Miss(); outSaveDataStorage.SetByMove(ref fileStorage.Ref()); return Result.Success; @@ -357,20 +357,20 @@ public class SaveDataFileStorageHolder if (baseFileStorage.HasValue) { - rc = baseFileStorage.Get.SetOpenType(type.ValueRo); - if (rc.IsFailure()) return rc; + res = baseFileStorage.Get.SetOpenType(type.ValueRo); + if (res.IsFailure()) return res.Miss(); } else { baseFileStorage.Reset(new SaveDataOpenTypeSetFileStorage(_fsServer, spaceId, saveDataId)); - rc = baseFileStorage.Get.Initialize(ref baseFileSystem, in saveImageName, mode, type.ValueRo); - if (rc.IsFailure()) return rc; + res = baseFileStorage.Get.Initialize(ref baseFileSystem, in saveImageName, mode, type.ValueRo); + if (res.IsFailure()) return res.Miss(); using SharedRef baseFileStorageCopy = SharedRef.CreateCopy(in baseFileStorage); - rc = Register(ref baseFileStorageCopy.Ref(), spaceId, saveDataId); - if (rc.IsFailure()) return rc; + res = Register(ref baseFileStorageCopy.Ref(), spaceId, saveDataId); + if (res.IsFailure()) return res.Miss(); } outSaveDataStorage.Reset(new SaveDataSharedFileStorage(ref baseFileStorage.Ref(), type.ValueRo)); diff --git a/src/LibHac/FsSrv/StatusReportService.cs b/src/LibHac/FsSrv/StatusReportService.cs index ddc64d26..fcc96117 100644 --- a/src/LibHac/FsSrv/StatusReportService.cs +++ b/src/LibHac/FsSrv/StatusReportService.cs @@ -89,8 +89,8 @@ public class StatusReportServiceImpl Assert.SdkRequiresNotNull(_config.SaveDataFileSystemServiceImpl); - Result rc = _config.SaveDataFileSystemServiceImpl.GetSaveDataIndexCount(out int count); - if (rc.IsFailure()) return rc; + Result res = _config.SaveDataFileSystemServiceImpl.GetSaveDataIndexCount(out int count); + if (res.IsFailure()) return res.Miss(); errorInfo.SaveDataIndexCount = count; return Result.Success; diff --git a/src/LibHac/FsSrv/Storage/GameCardService.cs b/src/LibHac/FsSrv/Storage/GameCardService.cs index 4e303322..5677bafb 100644 --- a/src/LibHac/FsSrv/Storage/GameCardService.cs +++ b/src/LibHac/FsSrv/Storage/GameCardService.cs @@ -52,16 +52,16 @@ internal static class GameCardService ref SharedRef outStorageDevice, OpenGameCardAttribute attribute) { using var storageDeviceManager = new SharedRef(); - Result rc = service.GetGameCardManager(ref storageDeviceManager.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManager(ref storageDeviceManager.Ref()); + if (res.IsFailure()) return res.Miss(); ref GameCardServiceGlobals g = ref service.Globals.GameCardService; using var gameCardStorageDevice = new SharedRef(); using ScopedLock scopedLock = ScopedLock.Lock(ref g.StorageDeviceMutex); - rc = storageDeviceManager.Get.OpenDevice(ref gameCardStorageDevice.Ref(), MakeAttributeId(attribute)); - if (rc.IsFailure()) return rc.Miss(); + res = storageDeviceManager.Get.OpenDevice(ref gameCardStorageDevice.Ref(), MakeAttributeId(attribute)); + if (res.IsFailure()) return res.Miss(); g.CachedStorageDevice.SetByCopy(in gameCardStorageDevice); outStorageDevice.SetByCopy(in gameCardStorageDevice); @@ -73,8 +73,8 @@ internal static class GameCardService ref SharedRef outDeviceOperator) { using var storageDeviceManager = new SharedRef(); - Result rc = service.GetGameCardManager(ref storageDeviceManager.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManager(ref storageDeviceManager.Ref()); + if (res.IsFailure()) return res.Miss(); return storageDeviceManager.Get.OpenOperator(ref outDeviceOperator); } @@ -83,8 +83,8 @@ internal static class GameCardService ref SharedRef outDeviceOperator, OpenGameCardAttribute attribute) { using var storageDevice = new SharedRef(); - Result rc = service.OpenAndCacheGameCardDevice(ref storageDevice.Ref(), attribute); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.OpenAndCacheGameCardDevice(ref storageDevice.Ref(), attribute); + if (res.IsFailure()) return res.Miss(); return storageDevice.Get.OpenOperator(ref outDeviceOperator.Ref()); } @@ -110,12 +110,12 @@ internal static class GameCardService { using var gameCardStorageDevice = new SharedRef(); - Result rc = service.OpenAndCacheGameCardDevice(ref gameCardStorageDevice.Ref(), attribute); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.OpenAndCacheGameCardDevice(ref gameCardStorageDevice.Ref(), attribute); + if (res.IsFailure()) return res.Miss(); // Verify that the game card handle hasn't changed. - rc = service.GetCurrentGameCardHandle(out StorageDeviceHandle newHandle); - if (rc.IsFailure()) return rc.Miss(); + res = service.GetCurrentGameCardHandle(out StorageDeviceHandle newHandle); + if (res.IsFailure()) return res.Miss(); if (newHandle.Value != handle) { @@ -153,8 +153,8 @@ internal static class GameCardService { if (g.CachedStorageDevice.HasValue) { - Result rc = g.CachedStorageDevice.Get.GetHandle(out GameCardHandle handle); - if (rc.IsFailure()) return rc.Miss(); + Result res = g.CachedStorageDevice.Get.GetHandle(out GameCardHandle handle); + if (res.IsFailure()) return res.Miss(); outHandle = new StorageDeviceHandle(handle, StorageDevicePortId.GameCard); return Result.Success; @@ -163,12 +163,12 @@ internal static class GameCardService { using var gameCardStorageDevice = new SharedRef(); - Result rc = service.OpenAndCacheGameCardDevice(ref gameCardStorageDevice.Ref(), + Result res = service.OpenAndCacheGameCardDevice(ref gameCardStorageDevice.Ref(), OpenGameCardAttribute.ReadOnly); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); - rc = gameCardStorageDevice.Get.GetHandle(out GameCardHandle handleValue); - if (rc.IsFailure()) return rc.Miss(); + res = gameCardStorageDevice.Get.GetHandle(out GameCardHandle handleValue); + if (res.IsFailure()) return res.Miss(); outHandle = new StorageDeviceHandle(handleValue, StorageDevicePortId.GameCard); return Result.Success; @@ -181,8 +181,8 @@ internal static class GameCardService UnsafeHelpers.SkipParamInit(out isValid); using var storageDeviceManager = new SharedRef(); - Result rc = service.GetGameCardManager(ref storageDeviceManager.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManager(ref storageDeviceManager.Ref()); + if (res.IsFailure()) return res.Miss(); return storageDeviceManager.Get.IsHandleValid(out isValid, handle.Value); } @@ -192,12 +192,12 @@ internal static class GameCardService UnsafeHelpers.SkipParamInit(out outIsInserted); using var storageDeviceManager = new SharedRef(); - Result rc = service.GetGameCardManager(ref storageDeviceManager.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManager(ref storageDeviceManager.Ref()); + if (res.IsFailure()) return res.Miss(); // Get the actual state of the game card. - rc = storageDeviceManager.Get.IsInserted(out bool isInserted); - if (rc.IsFailure()) return rc.Miss(); + res = storageDeviceManager.Get.IsInserted(out bool isInserted); + if (res.IsFailure()) return res.Miss(); // Get the simulated state of the game card based on the actual state. outIsInserted = service.FsSrv.Impl.GetGameCardEventSimulator().FilterDetectionState(isInserted); @@ -207,8 +207,8 @@ internal static class GameCardService public static Result EraseGameCard(this StorageService service, uint gameCardSize, ulong romAreaStartPageAddress) { using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); InBuffer inBuffer = InBuffer.FromStruct(in romAreaStartPageAddress); int operationId = MakeOperationId(GameCardOperationIdValue.EraseGameCard); @@ -219,8 +219,8 @@ internal static class GameCardService public static Result GetInitializationResult(this StorageService service) { using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardManagerOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManagerOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); int operationId = MakeOperationId(GameCardManagerOperationIdValue.GetInitializationResult); @@ -233,13 +233,13 @@ internal static class GameCardService UnsafeHelpers.SkipParamInit(out outGameCardStatus); using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); // Verify that the game card handle hasn't changed. var deviceHandle = new StorageDeviceHandle(handle, StorageDevicePortId.GameCard); - rc = service.IsGameCardHandleValid(out bool isValidHandle, in deviceHandle); - if (rc.IsFailure()) return rc.Miss(); + res = service.IsGameCardHandleValid(out bool isValidHandle, in deviceHandle); + if (res.IsFailure()) return res.Miss(); if (!isValidHandle) return ResultFs.GameCardFsCheckHandleInGetStatusFailure.Log(); @@ -248,8 +248,8 @@ internal static class GameCardService OutBuffer outCardStatusBuffer = OutBuffer.FromStruct(ref outGameCardStatus); int operationId = MakeOperationId(GameCardOperationIdValue.GetGameCardStatus); - rc = gcOperator.Get.OperateOut(out long bytesWritten, outCardStatusBuffer, operationId); - if (rc.IsFailure()) return rc.Miss(); + res = gcOperator.Get.OperateOut(out long bytesWritten, outCardStatusBuffer, operationId); + if (res.IsFailure()) return res.Miss(); Assert.SdkEqual(Unsafe.SizeOf(), bytesWritten); @@ -259,8 +259,8 @@ internal static class GameCardService public static Result FinalizeGameCardLibrary(this StorageService service) { using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardManagerOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManagerOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); int operationId = MakeOperationId(GameCardManagerOperationIdValue.Finalize); @@ -271,13 +271,13 @@ internal static class GameCardService GameCardHandle handle) { using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); // Verify that the game card handle hasn't changed. var deviceHandle = new StorageDeviceHandle(handle, StorageDevicePortId.GameCard); - rc = service.IsGameCardHandleValid(out bool isValidHandle, in deviceHandle); - if (rc.IsFailure()) return rc.Miss(); + res = service.IsGameCardHandleValid(out bool isValidHandle, in deviceHandle); + if (res.IsFailure()) return res.Miss(); if (!isValidHandle) return ResultFs.GameCardFsCheckHandleInGetDeviceCertFailure.Log(); @@ -286,8 +286,8 @@ internal static class GameCardService var outCertBuffer = new OutBuffer(outBuffer); int operationId = MakeOperationId(GameCardOperationIdValue.GetGameCardDeviceCertificate); - rc = gcOperator.Get.OperateOut(out long bytesWritten, outCertBuffer, operationId); - if (rc.IsFailure()) return rc.Miss(); + res = gcOperator.Get.OperateOut(out long bytesWritten, outCertBuffer, operationId); + if (res.IsFailure()) return res.Miss(); Assert.SdkEqual(GcDeviceCertificateSize, bytesWritten); @@ -298,13 +298,13 @@ internal static class GameCardService ReadOnlySpan challengeSeed, ReadOnlySpan challengeValue, GameCardHandle handle) { using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); // Verify that the game card handle hasn't changed. var deviceHandle = new StorageDeviceHandle(handle, StorageDevicePortId.GameCard); - rc = service.IsGameCardHandleValid(out bool isValidHandle, in deviceHandle); - if (rc.IsFailure()) return rc.Miss(); + res = service.IsGameCardHandleValid(out bool isValidHandle, in deviceHandle); + if (res.IsFailure()) return res.Miss(); if (!isValidHandle) return ResultFs.GameCardFsCheckHandleInChallengeCardExistence.Log(); @@ -315,9 +315,9 @@ internal static class GameCardService var responseBuffer = new OutBuffer(outResponseBuffer); int operationId = MakeOperationId(GameCardOperationIdValue.ChallengeCardExistence); - rc = gcOperator.Get.OperateIn2Out(out long bytesWritten, responseBuffer, valueBuffer, seedBuffer, offset: 0, + res = gcOperator.Get.OperateIn2Out(out long bytesWritten, responseBuffer, valueBuffer, seedBuffer, offset: 0, size: 0, operationId); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); Assert.SdkEqual(GcCardExistenceResponseDataSize, bytesWritten); @@ -329,15 +329,15 @@ internal static class GameCardService UnsafeHelpers.SkipParamInit(out outHandle); using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardManagerOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManagerOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); // Get the current handle. OutBuffer handleOutBuffer = OutBuffer.FromStruct(ref outHandle); int operationId = MakeOperationId(GameCardManagerOperationIdValue.GetHandle); - rc = gcOperator.Get.OperateOut(out long bytesWritten, handleOutBuffer, operationId); - if (rc.IsFailure()) return rc.Miss(); + res = gcOperator.Get.OperateOut(out long bytesWritten, handleOutBuffer, operationId); + if (res.IsFailure()) return res.Miss(); Assert.SdkEqual(Unsafe.SizeOf(), bytesWritten); @@ -348,11 +348,11 @@ internal static class GameCardService if (g.CachedStorageDevice.HasValue) { g.CachedStorageDevice.Get.GetHandle(out GameCardHandle handleValue); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); var currentHandle = new StorageDeviceHandle(handleValue, StorageDevicePortId.GameCard); - rc = service.IsGameCardHandleValid(out bool isHandleValid, in currentHandle); - if (rc.IsFailure()) return rc.Miss(); + res = service.IsGameCardHandleValid(out bool isHandleValid, in currentHandle); + if (res.IsFailure()) return res.Miss(); if (!isHandleValid) g.CachedStorageDevice.Reset(); @@ -367,16 +367,16 @@ internal static class GameCardService UnsafeHelpers.SkipParamInit(out rmaInfo); using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardManagerOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManagerOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); var inFirmwareBuffer = new InBuffer(firmwareBuffer); OutBuffer outRmaInfoBuffer = OutBuffer.FromStruct(ref rmaInfo); int operationId = MakeOperationId(GameCardManagerOperationIdValue.GetGameCardAsicInfo); - rc = gcOperator.Get.OperateInOut(out long bytesWritten, outRmaInfoBuffer, inFirmwareBuffer, offset: 0, + res = gcOperator.Get.OperateInOut(out long bytesWritten, outRmaInfoBuffer, inFirmwareBuffer, offset: 0, size: firmwareBuffer.Length, operationId); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); Assert.SdkEqual(Unsafe.SizeOf(), bytesWritten); @@ -388,14 +388,14 @@ internal static class GameCardService UnsafeHelpers.SkipParamInit(out outIdSet); using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); OutBuffer outIdSetBuffer = OutBuffer.FromStruct(ref outIdSet); int operationId = MakeOperationId(GameCardOperationIdValue.GetGameCardIdSet); - rc = gcOperator.Get.OperateOut(out long bytesWritten, outIdSetBuffer, operationId); - if (rc.IsFailure()) return rc.Miss(); + res = gcOperator.Get.OperateOut(out long bytesWritten, outIdSetBuffer, operationId); + if (res.IsFailure()) return res.Miss(); Assert.SdkEqual(Unsafe.SizeOf(), bytesWritten); @@ -405,8 +405,8 @@ internal static class GameCardService public static Result WriteToGameCardDirectly(this StorageService service, long offset, Span buffer) { using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardManagerOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManagerOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); var outBuffer = new OutBuffer(buffer); var inUnusedBuffer = new InBuffer(); @@ -414,18 +414,18 @@ internal static class GameCardService // Missing: Register device buffer - rc = gcOperator.Get.OperateInOut(out _, outBuffer, inUnusedBuffer, offset, buffer.Length, operationId); + res = gcOperator.Get.OperateInOut(out _, outBuffer, inUnusedBuffer, offset, buffer.Length, operationId); // Missing: Unregister device buffer - return rc; + return res; } public static Result SetVerifyWriteEnableFlag(this StorageService service, bool isEnabled) { using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardManagerOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManagerOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); InBuffer inIsEnabledBuffer = InBuffer.FromStruct(in isEnabled); int operationId = MakeOperationId(GameCardManagerOperationIdValue.SetVerifyEnableFlag); @@ -436,13 +436,13 @@ internal static class GameCardService public static Result GetGameCardImageHash(this StorageService service, Span outBuffer, GameCardHandle handle) { using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); // Verify that the game card handle hasn't changed. var deviceHandle = new StorageDeviceHandle(handle, StorageDevicePortId.GameCard); - rc = service.IsGameCardHandleValid(out bool isValidHandle, in deviceHandle); - if (rc.IsFailure()) return rc.Miss(); + res = service.IsGameCardHandleValid(out bool isValidHandle, in deviceHandle); + if (res.IsFailure()) return res.Miss(); if (!isValidHandle) return ResultFs.GameCardFsCheckHandleInGetCardImageHashFailure.Log(); @@ -451,8 +451,8 @@ internal static class GameCardService var outImageHashBuffer = new OutBuffer(outBuffer); int operationId = MakeOperationId(GameCardOperationIdValue.GetGameCardImageHash); - rc = gcOperator.Get.OperateOut(out long bytesWritten, outImageHashBuffer, operationId); - if (rc.IsFailure()) return rc.Miss(); + res = gcOperator.Get.OperateOut(out long bytesWritten, outImageHashBuffer, operationId); + if (res.IsFailure()) return res.Miss(); Assert.SdkEqual(GcCardImageHashSize, bytesWritten); @@ -463,16 +463,16 @@ internal static class GameCardService ReadOnlySpan devHeaderBuffer) { using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardManagerOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManagerOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); var inDevHeaderBuffer = new InBuffer(devHeaderBuffer); var outDeviceIdBuffer = new OutBuffer(outBuffer); int operationId = MakeOperationId(GameCardManagerOperationIdValue.GetGameCardDeviceIdForProdCard); - rc = gcOperator.Get.OperateInOut(out long bytesWritten, outDeviceIdBuffer, inDevHeaderBuffer, offset: 0, + res = gcOperator.Get.OperateInOut(out long bytesWritten, outDeviceIdBuffer, inDevHeaderBuffer, offset: 0, size: 0, operationId); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); Assert.SdkEqual(GcPageSize, bytesWritten); @@ -482,8 +482,8 @@ internal static class GameCardService public static Result EraseAndWriteParamDirectly(this StorageService service, ReadOnlySpan devParamBuffer) { using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardManagerOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManagerOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); var inDevParamBuffer = new InBuffer(devParamBuffer); int operationId = MakeOperationId(GameCardManagerOperationIdValue.EraseAndWriteParamDirectly); @@ -494,13 +494,13 @@ internal static class GameCardService public static Result ReadParamDirectly(this StorageService service, Span outDevParamBuffer) { using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardManagerOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManagerOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); int operationId = MakeOperationId(GameCardManagerOperationIdValue.ReadParamDirectly); - rc = gcOperator.Get.OperateOut(out long bytesWritten, new OutBuffer(outDevParamBuffer), operationId); - if (rc.IsFailure()) return rc.Miss(); + res = gcOperator.Get.OperateOut(out long bytesWritten, new OutBuffer(outDevParamBuffer), operationId); + if (res.IsFailure()) return res.Miss(); Assert.SdkEqual(GcPageSize, bytesWritten); @@ -510,8 +510,8 @@ internal static class GameCardService public static Result ForceEraseGameCard(this StorageService service) { using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardManagerOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManagerOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); int operationId = MakeOperationId(GameCardManagerOperationIdValue.ForceErase); @@ -523,14 +523,14 @@ internal static class GameCardService UnsafeHelpers.SkipParamInit(out errorInfo); using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardManagerOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManagerOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); OutBuffer outErrorInfoBuffer = OutBuffer.FromStruct(ref errorInfo); int operationId = MakeOperationId(GameCardManagerOperationIdValue.GetGameCardErrorInfo); - rc = gcOperator.Get.OperateOut(out long bytesWritten, outErrorInfoBuffer, operationId); - if (rc.IsFailure()) return rc.Miss(); + res = gcOperator.Get.OperateOut(out long bytesWritten, outErrorInfoBuffer, operationId); + if (res.IsFailure()) return res.Miss(); Assert.SdkEqual(Unsafe.SizeOf(), bytesWritten); @@ -543,14 +543,14 @@ internal static class GameCardService UnsafeHelpers.SkipParamInit(out errorReportInfo); using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardManagerOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManagerOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); OutBuffer outErrorReportInfoBuffer = OutBuffer.FromStruct(ref errorReportInfo); int operationId = MakeOperationId(GameCardManagerOperationIdValue.GetGameCardErrorReportInfo); - rc = gcOperator.Get.OperateOut(out long bytesWritten, outErrorReportInfoBuffer, operationId); - if (rc.IsFailure()) return rc.Miss(); + res = gcOperator.Get.OperateOut(out long bytesWritten, outErrorReportInfoBuffer, operationId); + if (res.IsFailure()) return res.Miss(); Assert.SdkEqual(Unsafe.SizeOf(), bytesWritten); @@ -560,14 +560,14 @@ internal static class GameCardService public static Result GetGameCardDeviceId(this StorageService service, Span outBuffer) { using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); var outDeviceIdBuffer = new OutBuffer(outBuffer); int operationId = MakeOperationId(GameCardOperationIdValue.GetGameCardDeviceId); - rc = gcOperator.Get.OperateOut(out long bytesWritten, outDeviceIdBuffer, operationId); - if (rc.IsFailure()) return rc.Miss(); + res = gcOperator.Get.OperateOut(out long bytesWritten, outDeviceIdBuffer, operationId); + if (res.IsFailure()) return res.Miss(); Assert.SdkEqual(GcCardDeviceIdSize, bytesWritten); @@ -577,17 +577,17 @@ internal static class GameCardService public static bool IsGameCardActivationValid(this StorageService service, GameCardHandle handle) { using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardManagerOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return Result.ConvertResultToReturnType(rc); + Result res = service.GetGameCardManagerOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return Result.ConvertResultToReturnType(res); bool isValid = false; InBuffer inHandleBuffer = InBuffer.FromStruct(in handle); OutBuffer outIsValidBuffer = OutBuffer.FromStruct(ref isValid); int operationId = MakeOperationId(GameCardManagerOperationIdValue.IsGameCardActivationValid); - rc = gcOperator.Get.OperateInOut(out long bytesWritten, outIsValidBuffer, inHandleBuffer, offset: 0, size: 0, + res = gcOperator.Get.OperateInOut(out long bytesWritten, outIsValidBuffer, inHandleBuffer, offset: 0, size: 0, operationId); - if (rc.IsFailure()) return Result.ConvertResultToReturnType(rc); + if (res.IsFailure()) return Result.ConvertResultToReturnType(res); Assert.SdkEqual(Unsafe.SizeOf(), bytesWritten); @@ -598,8 +598,8 @@ internal static class GameCardService ref SharedRef outEventNotifier) { using var storageDeviceManager = new SharedRef(); - Result rc = service.GetGameCardManager(ref storageDeviceManager.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManager(ref storageDeviceManager.Ref()); + if (res.IsFailure()) return res.Miss(); return storageDeviceManager.Get.OpenDetectionEvent(ref outEventNotifier); } @@ -607,8 +607,8 @@ internal static class GameCardService public static Result SimulateGameCardDetectionEventSignaled(this StorageService service) { using var gcOperator = new SharedRef(); - Result rc = service.GetGameCardManagerOperator(ref gcOperator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetGameCardManagerOperator(ref gcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); int operationId = MakeOperationId(GameCardManagerOperationIdValue.SimulateDetectionEventSignaled); diff --git a/src/LibHac/FsSrv/Storage/MmcService.cs b/src/LibHac/FsSrv/Storage/MmcService.cs index 3e3cbdc9..ec3615c8 100644 --- a/src/LibHac/FsSrv/Storage/MmcService.cs +++ b/src/LibHac/FsSrv/Storage/MmcService.cs @@ -42,8 +42,8 @@ internal static class MmcService ref SharedRef outDeviceOperator) { using var storageDeviceManager = new SharedRef(); - Result rc = service.GetMmcManager(ref storageDeviceManager.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetMmcManager(ref storageDeviceManager.Ref()); + if (res.IsFailure()) return res.Miss(); return storageDeviceManager.Get.OpenOperator(ref outDeviceOperator); } @@ -77,15 +77,15 @@ internal static class MmcService ref SharedRef outMmcOperator, MmcPartition partition) { using var storageDeviceManager = new SharedRef(); - Result rc = service.GetMmcManager(ref storageDeviceManager.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetMmcManager(ref storageDeviceManager.Ref()); + if (res.IsFailure()) return res.Miss(); - rc = GetAttribute(out ulong attribute, partition); - if (rc.IsFailure()) return rc; + res = GetAttribute(out ulong attribute, partition); + if (res.IsFailure()) return res.Miss(); using var storageDevice = new SharedRef(); - rc = storageDeviceManager.Get.OpenDevice(ref storageDevice.Ref(), attribute); - if (rc.IsFailure()) return rc; + res = storageDeviceManager.Get.OpenDevice(ref storageDevice.Ref(), attribute); + if (res.IsFailure()) return res.Miss(); return storageDevice.Get.OpenOperator(ref outMmcOperator); } @@ -94,15 +94,15 @@ internal static class MmcService MmcPartition partition) { using var storageDeviceManager = new SharedRef(); - Result rc = service.GetMmcManager(ref storageDeviceManager.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetMmcManager(ref storageDeviceManager.Ref()); + if (res.IsFailure()) return res.Miss(); - rc = GetAttribute(out ulong attribute, partition); - if (rc.IsFailure()) return rc; + res = GetAttribute(out ulong attribute, partition); + if (res.IsFailure()) return res.Miss(); using var mmcStorage = new SharedRef(); - rc = storageDeviceManager.Get.OpenStorage(ref mmcStorage.Ref(), attribute); - if (rc.IsFailure()) return rc; + res = storageDeviceManager.Get.OpenStorage(ref mmcStorage.Ref(), attribute); + if (res.IsFailure()) return res.Miss(); using var storage = new SharedRef(new StorageServiceObjectAdapter(ref mmcStorage.Ref())); @@ -124,15 +124,15 @@ internal static class MmcService UnsafeHelpers.SkipParamInit(out speedMode); using var mmcOperator = new SharedRef(); - Result rc = service.GetMmcOperator(ref mmcOperator.Ref(), MmcPartition.UserData); - if (rc.IsFailure()) return rc; + Result res = service.GetMmcOperator(ref mmcOperator.Ref(), MmcPartition.UserData); + if (res.IsFailure()) return res.Miss(); Unsafe.SkipInit(out SpeedMode sdmmcSpeedMode); OutBuffer outBuffer = OutBuffer.FromStruct(ref sdmmcSpeedMode); int operationId = MakeOperationId(MmcOperationIdValue.GetSpeedMode); - rc = mmcOperator.Get.OperateOut(out _, outBuffer, operationId); - if (rc.IsFailure()) return rc; + res = mmcOperator.Get.OperateOut(out _, outBuffer, operationId); + if (res.IsFailure()) return res.Miss(); speedMode = sdmmcSpeedMode switch { @@ -150,8 +150,8 @@ internal static class MmcService public static Result GetMmcCid(this StorageService service, Span cidBuffer) { using var mmcOperator = new SharedRef(); - Result rc = service.GetMmcOperator(ref mmcOperator.Ref(), MmcPartition.UserData); - if (rc.IsFailure()) return rc; + Result res = service.GetMmcOperator(ref mmcOperator.Ref(), MmcPartition.UserData); + if (res.IsFailure()) return res.Miss(); int operationId = MakeOperationId(MmcOperationIdValue.GetCid); var outBuffer = new OutBuffer(cidBuffer); @@ -162,8 +162,8 @@ internal static class MmcService public static Result EraseMmc(this StorageService service, MmcPartition partition) { using var mmcOperator = new SharedRef(); - Result rc = service.GetMmcOperator(ref mmcOperator.Ref(), partition); - if (rc.IsFailure()) return rc; + Result res = service.GetMmcOperator(ref mmcOperator.Ref(), partition); + if (res.IsFailure()) return res.Miss(); return mmcOperator.Get.Operate(MakeOperationId(MmcOperationIdValue.Erase)); } @@ -173,8 +173,8 @@ internal static class MmcService UnsafeHelpers.SkipParamInit(out size); using var mmcOperator = new SharedRef(); - Result rc = service.GetMmcOperator(ref mmcOperator.Ref(), partition); - if (rc.IsFailure()) return rc; + Result res = service.GetMmcOperator(ref mmcOperator.Ref(), partition); + if (res.IsFailure()) return res.Miss(); int operationId = MakeOperationId(MmcOperationIdValue.GetPartitionSize); OutBuffer outBuffer = OutBuffer.FromStruct(ref size); @@ -187,8 +187,8 @@ internal static class MmcService UnsafeHelpers.SkipParamInit(out count); using var mmcOperator = new SharedRef(); - Result rc = service.GetMmcManagerOperator(ref mmcOperator.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetMmcManagerOperator(ref mmcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); int operationId = MakeOperationId(MmcManagerOperationIdValue.GetPatrolCount); OutBuffer outBuffer = OutBuffer.FromStruct(ref count); @@ -202,8 +202,8 @@ internal static class MmcService UnsafeHelpers.SkipParamInit(out errorInfo, out logSize); using var mmcOperator = new SharedRef(); - Result rc = service.GetMmcManagerOperator(ref mmcOperator.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetMmcManagerOperator(ref mmcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); OutBuffer errorInfoOutBuffer = OutBuffer.FromStruct(ref errorInfo); var logOutBuffer = new OutBuffer(logBuffer); @@ -215,8 +215,8 @@ internal static class MmcService public static Result GetMmcExtendedCsd(this StorageService service, Span buffer) { using var mmcOperator = new SharedRef(); - Result rc = service.GetMmcOperator(ref mmcOperator.Ref(), MmcPartition.UserData); - if (rc.IsFailure()) return rc; + Result res = service.GetMmcOperator(ref mmcOperator.Ref(), MmcPartition.UserData); + if (res.IsFailure()) return res.Miss(); int operationId = MakeOperationId(MmcOperationIdValue.GetExtendedCsd); var outBuffer = new OutBuffer(buffer); @@ -227,8 +227,8 @@ internal static class MmcService public static Result SuspendMmcPatrol(this StorageService service) { using var mmcOperator = new SharedRef(); - Result rc = service.GetMmcManagerOperator(ref mmcOperator.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetMmcManagerOperator(ref mmcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); return mmcOperator.Get.Operate(MakeOperationId(MmcManagerOperationIdValue.SuspendPatrol)); } @@ -236,8 +236,8 @@ internal static class MmcService public static Result ResumeMmcPatrol(this StorageService service) { using var mmcOperator = new SharedRef(); - Result rc = service.GetMmcManagerOperator(ref mmcOperator.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetMmcManagerOperator(ref mmcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); return mmcOperator.Get.Operate(MakeOperationId(MmcManagerOperationIdValue.ResumePatrol)); } @@ -248,8 +248,8 @@ internal static class MmcService UnsafeHelpers.SkipParamInit(out successCount, out failureCount); using var mmcOperator = new SharedRef(); - Result rc = service.GetMmcManagerOperator(ref mmcOperator.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetMmcManagerOperator(ref mmcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); int operationId = MakeOperationId(MmcManagerOperationIdValue.GetAndClearPatrolReadAllocateBufferCount); OutBuffer successCountBuffer = OutBuffer.FromStruct(ref successCount); @@ -261,8 +261,8 @@ internal static class MmcService public static Result SuspendMmcControl(this StorageService service) { using var mmcOperator = new SharedRef(); - Result rc = service.GetMmcManagerOperator(ref mmcOperator.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetMmcManagerOperator(ref mmcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); return mmcOperator.Get.Operate(MakeOperationId(MmcManagerOperationIdValue.SuspendControl)); } @@ -270,8 +270,8 @@ internal static class MmcService public static Result ResumeMmcControl(this StorageService service) { using var mmcOperator = new SharedRef(); - Result rc = service.GetMmcManagerOperator(ref mmcOperator.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetMmcManagerOperator(ref mmcOperator.Ref()); + if (res.IsFailure()) return res.Miss(); return mmcOperator.Get.Operate(MakeOperationId(MmcManagerOperationIdValue.ResumeControl)); } diff --git a/src/LibHac/FsSrv/Storage/SdCardService.cs b/src/LibHac/FsSrv/Storage/SdCardService.cs index e23ac7db..3fe44962 100644 --- a/src/LibHac/FsSrv/Storage/SdCardService.cs +++ b/src/LibHac/FsSrv/Storage/SdCardService.cs @@ -32,8 +32,8 @@ internal static class SdCardService ref SharedRef outDeviceOperator) { using var storageDeviceManager = new SharedRef(); - Result rc = service.GetSdCardManager(ref storageDeviceManager.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetSdCardManager(ref storageDeviceManager.Ref()); + if (res.IsFailure()) return res.Miss(); return storageDeviceManager.Get.OpenOperator(ref outDeviceOperator); } @@ -42,12 +42,12 @@ internal static class SdCardService ref SharedRef outSdCardOperator) { using var storageDeviceManager = new SharedRef(); - Result rc = service.GetSdCardManager(ref storageDeviceManager.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetSdCardManager(ref storageDeviceManager.Ref()); + if (res.IsFailure()) return res.Miss(); using var storageDevice = new SharedRef(); - rc = storageDeviceManager.Get.OpenDevice(ref storageDevice.Ref(), 0); - if (rc.IsFailure()) return rc; + res = storageDeviceManager.Get.OpenDevice(ref storageDevice.Ref(), 0); + if (res.IsFailure()) return res.Miss(); return storageDevice.Get.OpenOperator(ref outSdCardOperator); } @@ -55,12 +55,12 @@ internal static class SdCardService public static Result OpenSdStorage(this StorageService service, ref SharedRef outStorage) { using var storageDeviceManager = new SharedRef(); - Result rc = service.GetSdCardManager(ref storageDeviceManager.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetSdCardManager(ref storageDeviceManager.Ref()); + if (res.IsFailure()) return res.Miss(); using var sdCardStorage = new SharedRef(); - rc = storageDeviceManager.Get.OpenStorage(ref sdCardStorage.Ref(), 0); - if (rc.IsFailure()) return rc; + res = storageDeviceManager.Get.OpenStorage(ref sdCardStorage.Ref(), 0); + if (res.IsFailure()) return res.Miss(); using var storage = new SharedRef(new StorageServiceObjectAdapter(ref sdCardStorage.Ref())); @@ -80,15 +80,15 @@ internal static class SdCardService UnsafeHelpers.SkipParamInit(out handle); using var storageDeviceManager = new SharedRef(); - Result rc = service.GetSdCardManager(ref storageDeviceManager.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetSdCardManager(ref storageDeviceManager.Ref()); + if (res.IsFailure()) return res.Miss(); using var sdCardStorageDevice = new SharedRef(); - rc = storageDeviceManager.Get.OpenDevice(ref sdCardStorageDevice.Ref(), 0); - if (rc.IsFailure()) return rc; + res = storageDeviceManager.Get.OpenDevice(ref sdCardStorageDevice.Ref(), 0); + if (res.IsFailure()) return res.Miss(); - rc = sdCardStorageDevice.Get.GetHandle(out uint handleValue); - if (rc.IsFailure()) return rc; + res = sdCardStorageDevice.Get.GetHandle(out uint handleValue); + if (res.IsFailure()) return res.Miss(); handle = new StorageDeviceHandle(handleValue, StorageDevicePortId.SdCard); return Result.Success; @@ -100,8 +100,8 @@ internal static class SdCardService UnsafeHelpers.SkipParamInit(out isValid); using var storageDeviceManager = new SharedRef(); - Result rc = service.GetSdCardManager(ref storageDeviceManager.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetSdCardManager(ref storageDeviceManager.Ref()); + if (res.IsFailure()) return res.Miss(); // Note: I don't know why the official code doesn't check the handle port return storageDeviceManager.Get.IsHandleValid(out isValid, handle.Value); @@ -110,8 +110,8 @@ internal static class SdCardService public static Result InvalidateSdCard(this StorageService service) { using var storageDeviceManager = new SharedRef(); - Result rc = service.GetSdCardManager(ref storageDeviceManager.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetSdCardManager(ref storageDeviceManager.Ref()); + if (res.IsFailure()) return res.Miss(); return storageDeviceManager.Get.Invalidate(); } @@ -121,11 +121,11 @@ internal static class SdCardService UnsafeHelpers.SkipParamInit(out isInserted); using var storageDeviceManager = new SharedRef(); - Result rc = service.GetSdCardManager(ref storageDeviceManager.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetSdCardManager(ref storageDeviceManager.Ref()); + if (res.IsFailure()) return res.Miss(); - rc = storageDeviceManager.Get.IsInserted(out bool actualState); - if (rc.IsFailure()) return rc.Miss(); + res = storageDeviceManager.Get.IsInserted(out bool actualState); + if (res.IsFailure()) return res.Miss(); isInserted = service.FsSrv.Impl.GetSdCardEventSimulator().FilterDetectionState(actualState); return Result.Success; @@ -136,15 +136,15 @@ internal static class SdCardService UnsafeHelpers.SkipParamInit(out speedMode); using var sdCardOperator = new SharedRef(); - Result rc = service.GetSdCardOperator(ref sdCardOperator.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetSdCardOperator(ref sdCardOperator.Ref()); + if (res.IsFailure()) return res.Miss(); Unsafe.SkipInit(out SpeedMode sdmmcSpeedMode); OutBuffer outBuffer = OutBuffer.FromStruct(ref sdmmcSpeedMode); int operationId = MakeOperationId(SdCardOperationIdValue.GetSpeedMode); - rc = sdCardOperator.Get.OperateOut(out _, outBuffer, operationId); - if (rc.IsFailure()) return rc; + res = sdCardOperator.Get.OperateOut(out _, outBuffer, operationId); + if (res.IsFailure()) return res.Miss(); speedMode = sdmmcSpeedMode switch { @@ -165,8 +165,8 @@ internal static class SdCardService public static Result GetSdCardCid(this StorageService service, Span cidBuffer) { using var sdCardOperator = new SharedRef(); - Result rc = service.GetSdCardOperator(ref sdCardOperator.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetSdCardOperator(ref sdCardOperator.Ref()); + if (res.IsFailure()) return res.Miss(); int operationId = MakeOperationId(SdCardOperationIdValue.GetCid); var outBuffer = new OutBuffer(cidBuffer); @@ -179,8 +179,8 @@ internal static class SdCardService UnsafeHelpers.SkipParamInit(out count); using var sdCardOperator = new SharedRef(); - Result rc = service.GetSdCardOperator(ref sdCardOperator.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetSdCardOperator(ref sdCardOperator.Ref()); + if (res.IsFailure()) return res.Miss(); int operationId = MakeOperationId(SdCardOperationIdValue.GetUserAreaNumSectors); OutBuffer outBuffer = OutBuffer.FromStruct(ref count); @@ -193,8 +193,8 @@ internal static class SdCardService UnsafeHelpers.SkipParamInit(out size); using var sdCardOperator = new SharedRef(); - Result rc = service.GetSdCardOperator(ref sdCardOperator.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetSdCardOperator(ref sdCardOperator.Ref()); + if (res.IsFailure()) return res.Miss(); int operationId = MakeOperationId(SdCardOperationIdValue.GetUserAreaSize); OutBuffer outBuffer = OutBuffer.FromStruct(ref size); @@ -207,8 +207,8 @@ internal static class SdCardService UnsafeHelpers.SkipParamInit(out count); using var sdCardOperator = new SharedRef(); - Result rc = service.GetSdCardOperator(ref sdCardOperator.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetSdCardOperator(ref sdCardOperator.Ref()); + if (res.IsFailure()) return res.Miss(); int operationId = MakeOperationId(SdCardOperationIdValue.GetProtectedAreaNumSectors); OutBuffer outBuffer = OutBuffer.FromStruct(ref count); @@ -221,8 +221,8 @@ internal static class SdCardService UnsafeHelpers.SkipParamInit(out size); using var sdCardOperator = new SharedRef(); - Result rc = service.GetSdCardOperator(ref sdCardOperator.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetSdCardOperator(ref sdCardOperator.Ref()); + if (res.IsFailure()) return res.Miss(); int operationId = MakeOperationId(SdCardOperationIdValue.GetProtectedAreaSize); OutBuffer outBuffer = OutBuffer.FromStruct(ref size); @@ -236,8 +236,8 @@ internal static class SdCardService UnsafeHelpers.SkipParamInit(out errorInfo, out logSize); using var sdCardOperator = new SharedRef(); - Result rc = service.GetSdCardManagerOperator(ref sdCardOperator.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetSdCardManagerOperator(ref sdCardOperator.Ref()); + if (res.IsFailure()) return res.Miss(); OutBuffer errorInfoOutBuffer = OutBuffer.FromStruct(ref errorInfo); var logOutBuffer = new OutBuffer(logBuffer); @@ -250,8 +250,8 @@ internal static class SdCardService ref SharedRef outEventNotifier) { using var storageDeviceManager = new SharedRef(); - Result rc = service.GetSdCardManager(ref storageDeviceManager.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = service.GetSdCardManager(ref storageDeviceManager.Ref()); + if (res.IsFailure()) return res.Miss(); return storageDeviceManager.Get.OpenDetectionEvent(ref outEventNotifier); } @@ -259,8 +259,8 @@ internal static class SdCardService public static Result SimulateSdCardDetectionEventSignaled(this StorageService service) { using var sdCardOperator = new SharedRef(); - Result rc = service.GetSdCardManagerOperator(ref sdCardOperator.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetSdCardManagerOperator(ref sdCardOperator.Ref()); + if (res.IsFailure()) return res.Miss(); return sdCardOperator.Get.Operate( MakeOperationId(SdCardManagerOperationIdValue.SimulateDetectionEventSignaled)); @@ -269,8 +269,8 @@ internal static class SdCardService public static Result SuspendSdCardControl(this StorageService service) { using var sdCardOperator = new SharedRef(); - Result rc = service.GetSdCardManagerOperator(ref sdCardOperator.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetSdCardManagerOperator(ref sdCardOperator.Ref()); + if (res.IsFailure()) return res.Miss(); return sdCardOperator.Get.Operate(MakeOperationId(SdCardManagerOperationIdValue.SuspendControl)); } @@ -278,8 +278,8 @@ internal static class SdCardService public static Result ResumeSdCardControl(this StorageService service) { using var sdCardOperator = new SharedRef(); - Result rc = service.GetSdCardManagerOperator(ref sdCardOperator.Ref()); - if (rc.IsFailure()) return rc; + Result res = service.GetSdCardManagerOperator(ref sdCardOperator.Ref()); + if (res.IsFailure()) return res.Miss(); return sdCardOperator.Get.Operate(MakeOperationId(SdCardManagerOperationIdValue.ResumeControl)); } diff --git a/src/LibHac/FsSrv/TimeService.cs b/src/LibHac/FsSrv/TimeService.cs index 7b6a3c4d..2a729ce1 100644 --- a/src/LibHac/FsSrv/TimeService.cs +++ b/src/LibHac/FsSrv/TimeService.cs @@ -26,8 +26,8 @@ public readonly struct TimeService public Result SetCurrentPosixTimeWithTimeDifference(long currentTime, int timeDifference) { using var programRegistry = new ProgramRegistryImpl(_serviceImpl.FsServer); - Result rc = programRegistry.GetProgramInfo(out ProgramInfo programInfo, _processId); - if (rc.IsFailure()) return rc; + Result res = programRegistry.GetProgramInfo(out ProgramInfo programInfo, _processId); + if (res.IsFailure()) return res.Miss(); if (!programInfo.AccessControl.CanCall(OperationType.SetCurrentPosixTime)) return ResultFs.PermissionDenied.Log(); diff --git a/src/LibHac/FsSystem/AesCtrCounterExtendedStorage.cs b/src/LibHac/FsSystem/AesCtrCounterExtendedStorage.cs index b2971b4e..a7e3c4b1 100644 --- a/src/LibHac/FsSystem/AesCtrCounterExtendedStorage.cs +++ b/src/LibHac/FsSystem/AesCtrCounterExtendedStorage.cs @@ -130,11 +130,11 @@ public class AesCtrCounterExtendedStorage : IStorage { Unsafe.SkipInit(out BucketTree.Header header); - Result rc = tableStorage.Read(0, SpanHelpers.AsByteSpan(ref header)); - if (rc.IsFailure()) return rc.Miss(); + Result res = tableStorage.Read(0, SpanHelpers.AsByteSpan(ref header)); + if (res.IsFailure()) return res.Miss(); - rc = header.Verify(); - if (rc.IsFailure()) return rc.Miss(); + res = header.Verify(); + if (res.IsFailure()) return res.Miss(); long nodeStorageSize = QueryNodeStorageSize(header.EntryCount); long entryStorageSize = QueryEntryStorageSize(header.EntryCount); @@ -142,11 +142,11 @@ public class AesCtrCounterExtendedStorage : IStorage long entryStorageOffset = nodeStorageOffset + nodeStorageSize; using var decryptor = new UniqueRef(); - rc = CreateSoftwareDecryptor(ref decryptor.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = CreateSoftwareDecryptor(ref decryptor.Ref()); + if (res.IsFailure()) return res.Miss(); - rc = tableStorage.GetSize(out long storageSize); - if (rc.IsFailure()) return rc.Miss(); + res = tableStorage.GetSize(out long storageSize); + if (res.IsFailure()) return res.Miss(); if (nodeStorageOffset + nodeStorageSize + entryStorageSize > storageSize) return ResultFs.InvalidAesCtrCounterExtendedMetaStorageSize.Log(); @@ -166,24 +166,24 @@ public class AesCtrCounterExtendedStorage : IStorage Assert.SdkRequiresGreaterEqual(counterOffset, 0); Assert.SdkRequiresNotNull(in decryptor); - Result rc; + Result res; if (entryCount > 0) { - rc = _table.Initialize(allocator, in nodeStorage, in entryStorage, NodeSize, Unsafe.SizeOf(), + res = _table.Initialize(allocator, in nodeStorage, in entryStorage, NodeSize, Unsafe.SizeOf(), entryCount); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } else { _table.Initialize(NodeSize, 0); } - rc = dataStorage.GetSize(out long dataStorageSize); - if (rc.IsFailure()) return rc.Miss(); + res = dataStorage.GetSize(out long dataStorageSize); + if (res.IsFailure()) return res.Miss(); - rc = _table.GetOffsets(out BucketTree.Offsets offsets); - if (rc.IsFailure()) return rc.Miss(); + res = _table.GetOffsets(out BucketTree.Offsets offsets); + if (res.IsFailure()) return res.Miss(); if (offsets.EndOffset > dataStorageSize) return ResultFs.InvalidAesCtrCounterExtendedDataStorageSize.Log(); @@ -224,23 +224,23 @@ public class AesCtrCounterExtendedStorage : IStorage return ResultFs.InvalidSize.Log(); // Ensure the the requested range is within the bounds of the table. - Result rc = _table.GetOffsets(out BucketTree.Offsets offsets); - if (rc.IsFailure()) return rc.Miss(); + Result res = _table.GetOffsets(out BucketTree.Offsets offsets); + if (res.IsFailure()) return res.Miss(); if (!offsets.IsInclude(offset, destination.Length)) return ResultFs.OutOfRange.Log(); // Fill the destination buffer with the encrypted data. - rc = _dataStorage.Read(offset, destination); - if (rc.IsFailure()) return rc.Miss(); + res = _dataStorage.Read(offset, destination); + if (res.IsFailure()) return res.Miss(); // Temporarily increase our thread priority. using var changePriority = new ScopedThreadPriorityChanger(1, ScopedThreadPriorityChanger.Mode.Relative); // Find the entry in the table that contains our current offset. using var visitor = new BucketTree.Visitor(); - rc = _table.Find(ref visitor.Ref, offset); - if (rc.IsFailure()) return rc.Miss(); + res = _table.Find(ref visitor.Ref, offset); + if (res.IsFailure()) return res.Miss(); // Verify that the entry's offset is aligned to an AES block and within the bounds of the table. long entryOffset = visitor.Get().GetOffset(); @@ -270,8 +270,8 @@ public class AesCtrCounterExtendedStorage : IStorage { // Advance to the next entry so we know where our current entry ends. // The current entry's end offset is the next entry's start offset. - rc = visitor.MoveNext(); - if (rc.IsFailure()) return rc.Miss(); + res = visitor.MoveNext(); + if (res.IsFailure()) return res.Miss(); entryEndOffset = visitor.Get().GetOffset(); if (!offsets.IsInclude(entryEndOffset)) @@ -309,8 +309,8 @@ public class AesCtrCounterExtendedStorage : IStorage AesCtrStorage.MakeIv(counter.Items, upperIv.Value, counterOffset); // Decrypt the data from the current entry. - rc = _decryptor.Get.Decrypt(currentData.Slice(0, (int)dataSize), _key, counter); - if (rc.IsFailure()) return rc.Miss(); + res = _decryptor.Get.Decrypt(currentData.Slice(0, (int)dataSize), _key, counter); + if (res.IsFailure()) return res.Miss(); } // Advance the current offsets. @@ -335,8 +335,8 @@ public class AesCtrCounterExtendedStorage : IStorage { UnsafeHelpers.SkipParamInit(out size); - Result rc = _table.GetOffsets(out BucketTree.Offsets offsets); - if (rc.IsFailure()) return rc.Miss(); + Result res = _table.GetOffsets(out BucketTree.Offsets offsets); + if (res.IsFailure()) return res.Miss(); size = offsets.EndOffset; return Result.Success; @@ -357,12 +357,12 @@ public class AesCtrCounterExtendedStorage : IStorage Assert.SdkRequires(IsInitialized()); // Invalidate the table's cache. - Result rc = _table.InvalidateCache(); - if (rc.IsFailure()) return rc.Miss(); + Result res = _table.InvalidateCache(); + if (res.IsFailure()) return res.Miss(); // Invalidate the data storage's cache. - rc = _dataStorage.OperateRange(OperationId.InvalidateCache, offset: 0, size: long.MaxValue); - if (rc.IsFailure()) return rc.Miss(); + res = _dataStorage.OperateRange(OperationId.InvalidateCache, offset: 0, size: long.MaxValue); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -390,15 +390,15 @@ public class AesCtrCounterExtendedStorage : IStorage return ResultFs.InvalidSize.Log(); // Ensure the storage contains the provided offset and size. - Result rc = _table.GetOffsets(out BucketTree.Offsets offsets); - if (rc.IsFailure()) return rc.Miss(); + Result res = _table.GetOffsets(out BucketTree.Offsets offsets); + if (res.IsFailure()) return res.Miss(); if (!offsets.IsInclude(offset, size)) return ResultFs.OutOfRange.Log(); // Get the QueryRangeInfo of the underlying data storage. - rc = _dataStorage.OperateRange(outBuffer, operationId, offset, size, inBuffer); - if (rc.IsFailure()) return rc.Miss(); + res = _dataStorage.OperateRange(outBuffer, operationId, offset, size, inBuffer); + if (res.IsFailure()) return res.Miss(); // Set the key type in the info and merge it with the output info. Unsafe.SkipInit(out QueryRangeInfo info); @@ -456,8 +456,8 @@ public class AesCtrCounterExtendedStorage : IStorage Span dstBuffer = destination.Slice(currentOffset, currentSize); Span workBuffer = pooledBuffer.GetBuffer().Slice(0, currentSize); - Result rc = _decryptFunction(workBuffer, _keyIndex, _keyGeneration, encryptedKey, counter, dstBuffer); - if (rc.IsFailure()) return rc.Miss(); + Result res = _decryptFunction(workBuffer, _keyIndex, _keyGeneration, encryptedKey, counter, dstBuffer); + if (res.IsFailure()) return res.Miss(); workBuffer.CopyTo(dstBuffer); diff --git a/src/LibHac/FsSystem/AesCtrStorage.cs b/src/LibHac/FsSystem/AesCtrStorage.cs index 6be43f3f..595cb0a7 100644 --- a/src/LibHac/FsSystem/AesCtrStorage.cs +++ b/src/LibHac/FsSystem/AesCtrStorage.cs @@ -82,8 +82,8 @@ public class AesCtrStorage : IStorage if (!Alignment.IsAlignedPow2(destination.Length, (uint)BlockSize)) return ResultFs.InvalidArgument.Log(); - Result rc = _baseStorage.Read(offset, destination); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseStorage.Read(offset, destination); + if (res.IsFailure()) return res.Miss(); using var changePriority = new ScopedThreadPriorityChanger(1, ScopedThreadPriorityChanger.Mode.Relative); @@ -144,8 +144,8 @@ public class AesCtrStorage : IStorage } // Write the encrypted data. - Result rc = _baseStorage.Write(offset + currentOffset, writeBuffer); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseStorage.Write(offset + currentOffset, writeBuffer); + if (res.IsFailure()) return res.Miss(); // Advance. currentOffset += writeSize; @@ -210,8 +210,8 @@ public class AesCtrStorage : IStorage ref Unsafe.As(ref MemoryMarshal.GetReference(outBuffer)); // Get the QueryRangeInfo of the underlying base storage. - Result rc = _baseStorage.OperateRange(outBuffer, operationId, offset, size, inBuffer); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseStorage.OperateRange(outBuffer, operationId, offset, size, inBuffer); + if (res.IsFailure()) return res.Miss(); Unsafe.SkipInit(out QueryRangeInfo info); info.Clear(); @@ -223,8 +223,8 @@ public class AesCtrStorage : IStorage } default: { - Result rc = _baseStorage.OperateRange(outBuffer, operationId, offset, size, inBuffer); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseStorage.OperateRange(outBuffer, operationId, offset, size, inBuffer); + if (res.IsFailure()) return res.Miss(); break; } diff --git a/src/LibHac/FsSystem/AesXtsStorageExternal.cs b/src/LibHac/FsSystem/AesXtsStorageExternal.cs index a920a7f6..8d94605f 100644 --- a/src/LibHac/FsSystem/AesXtsStorageExternal.cs +++ b/src/LibHac/FsSystem/AesXtsStorageExternal.cs @@ -85,8 +85,8 @@ public class AesXtsStorageExternal : IStorage return ResultFs.InvalidArgument.Log(); // Read the encrypted data. - Result rc = _baseStorage.Read(offset, destination); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseStorage.Read(offset, destination); + if (res.IsFailure()) return res.Miss(); // Temporarily increase our thread priority while decrypting. using var changePriority = new ScopedThreadPriorityChanger(1, ScopedThreadPriorityChanger.Mode.Relative); @@ -115,8 +115,8 @@ public class AesXtsStorageExternal : IStorage Span decryptionBuffer = tmpBuffer.GetBuffer().Slice(0, (int)_blockSize); // Decrypt and copy the partial block to the output buffer. - rc = _decryptFunction(decryptionBuffer, _key[0], _key[1], counter, decryptionBuffer); - if (rc.IsFailure()) return rc.Miss(); + res = _decryptFunction(decryptionBuffer, _key[0], _key[1], counter, decryptionBuffer); + if (res.IsFailure()) return res.Miss(); tmpBuffer.GetBuffer().Slice(skipSize, dataSize).CopyTo(destination); } @@ -134,8 +134,8 @@ public class AesXtsStorageExternal : IStorage { Span currentBlock = currentOutput.Slice(0, Math.Min((int)_blockSize, remainingSize)); - rc = _decryptFunction(currentBlock, _key[0], _key[1], counter, currentBlock); - if (rc.IsFailure()) return rc.Miss(); + res = _decryptFunction(currentBlock, _key[0], _key[1], counter, currentBlock); + if (res.IsFailure()) return res.Miss(); remainingSize -= currentBlock.Length; currentOutput = currentBlock.Slice(currentBlock.Length); @@ -148,7 +148,7 @@ public class AesXtsStorageExternal : IStorage public override Result Write(long offset, ReadOnlySpan source) { - Result rc; + Result res; // Allow zero-size writes. if (source.Length == 0) @@ -199,11 +199,11 @@ public class AesXtsStorageExternal : IStorage source.Slice(0, dataSize).CopyTo(tmpBuffer.GetBuffer().Slice(skipSize, dataSize)); Span encryptionBuffer = tmpBuffer.GetBuffer().Slice(0, (int)_blockSize); - rc = _encryptFunction(encryptionBuffer, _key[0], _key[1], counter, encryptionBuffer); - if (rc.IsFailure()) return rc.Miss(); + res = _encryptFunction(encryptionBuffer, _key[0], _key[1], counter, encryptionBuffer); + if (res.IsFailure()) return res.Miss(); - rc = _baseStorage.Write(offset, tmpBuffer.GetBuffer().Slice(skipSize, dataSize)); - if (rc.IsFailure()) return rc.Miss(); + res = _baseStorage.Write(offset, tmpBuffer.GetBuffer().Slice(skipSize, dataSize)); + if (res.IsFailure()) return res.Miss(); } Utility.AddCounter(counter, 1); @@ -237,8 +237,8 @@ public class AesXtsStorageExternal : IStorage ? pooledBuffer.GetBuffer().Slice(encryptOffset, currentSize) : MemoryMarshal.CreateSpan(ref MemoryMarshal.GetReference(encryptSource), encryptSource.Length); - rc = _encryptFunction(encryptDest, _key[0], _key[1], counter, encryptSource); - if (rc.IsFailure()) return rc.Miss(); + res = _encryptFunction(encryptDest, _key[0], _key[1], counter, encryptSource); + if (res.IsFailure()) return res.Miss(); Utility.AddCounter(counter, 1); @@ -252,8 +252,8 @@ public class AesXtsStorageExternal : IStorage ? pooledBuffer.GetBuffer().Slice(0, writeSize) : source.Slice(processedSize, writeSize); - rc = _baseStorage.Write(currentOffset, writeBuffer); - if (rc.IsFailure()) return rc.Miss(); + res = _baseStorage.Write(currentOffset, writeBuffer); + if (res.IsFailure()) return res.Miss(); // Advance. currentOffset += writeSize; @@ -296,8 +296,8 @@ public class AesXtsStorageExternal : IStorage return ResultFs.InvalidArgument.Log(); } - Result rc = _baseStorage.OperateRange(outBuffer, operationId, offset, size, inBuffer); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseStorage.OperateRange(outBuffer, operationId, offset, size, inBuffer); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/FsSystem/AlignmentMatchingStorage.cs b/src/LibHac/FsSystem/AlignmentMatchingStorage.cs index 7ec5ff57..cd089fd9 100644 --- a/src/LibHac/FsSystem/AlignmentMatchingStorage.cs +++ b/src/LibHac/FsSystem/AlignmentMatchingStorage.cs @@ -77,11 +77,11 @@ public class AlignmentMatchingStorage : IStora if (destination.Length == 0) return Result.Success; - Result rc = GetSize(out long totalSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetSize(out long totalSize); + if (res.IsFailure()) return res.Miss(); - rc = CheckAccessRange(offset, destination.Length, totalSize); - if (rc.IsFailure()) return rc.Miss(); + res = CheckAccessRange(offset, destination.Length, totalSize); + if (res.IsFailure()) return res.Miss(); return AlignmentMatchingStorageImpl.Read(_baseStorage, workBuffer, DataAlign, BufferAlign, offset, destination); } @@ -93,11 +93,11 @@ public class AlignmentMatchingStorage : IStora if (source.Length == 0) return Result.Success; - Result rc = GetSize(out long totalSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetSize(out long totalSize); + if (res.IsFailure()) return res.Miss(); - rc = CheckAccessRange(offset, source.Length, totalSize); - if (rc.IsFailure()) return rc.Miss(); + res = CheckAccessRange(offset, source.Length, totalSize); + if (res.IsFailure()) return res.Miss(); return AlignmentMatchingStorageImpl.Write(_baseStorage, workBuffer, DataAlign, BufferAlign, offset, source); } @@ -109,10 +109,10 @@ public class AlignmentMatchingStorage : IStora public override Result SetSize(long size) { - Result rc = _baseStorage.SetSize(Alignment.AlignUpPow2(size, DataAlign)); + Result res = _baseStorage.SetSize(Alignment.AlignUpPow2(size, DataAlign)); _isBaseStorageSizeDirty = true; - return rc; + return res; } public override Result GetSize(out long size) @@ -121,8 +121,8 @@ public class AlignmentMatchingStorage : IStora if (_isBaseStorageSizeDirty) { - Result rc = _baseStorage.GetSize(out long baseStorageSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseStorage.GetSize(out long baseStorageSize); + if (res.IsFailure()) return res.Miss(); _baseStorageSize = baseStorageSize; _isBaseStorageSizeDirty = false; @@ -143,11 +143,11 @@ public class AlignmentMatchingStorage : IStora if (size == 0) return Result.Success; - Result rc = GetSize(out long baseStorageSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetSize(out long baseStorageSize); + if (res.IsFailure()) return res.Miss(); - rc = CheckOffsetAndSize(offset, size); - if (rc.IsFailure()) return rc.Miss(); + res = CheckOffsetAndSize(offset, size); + if (res.IsFailure()) return res.Miss(); long validSize = Math.Min(size, baseStorageSize - offset); long alignedOffset = Alignment.AlignDownPow2(offset, DataAlign); @@ -217,11 +217,11 @@ public class AlignmentMatchingStoragePooledBuffer : IStorage if (destination.Length == 0) return Result.Success; - Result rc = GetSize(out long baseStorageSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetSize(out long baseStorageSize); + if (res.IsFailure()) return res.Miss(); - rc = CheckAccessRange(offset, destination.Length, baseStorageSize); - if (rc.IsFailure()) return rc.Miss(); + res = CheckAccessRange(offset, destination.Length, baseStorageSize); + if (res.IsFailure()) return res.Miss(); using var pooledBuffer = new PooledBuffer(); pooledBuffer.AllocateParticularlyLarge((int)_dataAlignment, (int)_dataAlignment); @@ -235,11 +235,11 @@ public class AlignmentMatchingStoragePooledBuffer : IStorage if (source.Length == 0) return Result.Success; - Result rc = GetSize(out long baseStorageSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetSize(out long baseStorageSize); + if (res.IsFailure()) return res.Miss(); - rc = CheckAccessRange(offset, source.Length, baseStorageSize); - if (rc.IsFailure()) return rc.Miss(); + res = CheckAccessRange(offset, source.Length, baseStorageSize); + if (res.IsFailure()) return res.Miss(); using var pooledBuffer = new PooledBuffer(); pooledBuffer.AllocateParticularlyLarge((int)_dataAlignment, (int)_dataAlignment); @@ -255,10 +255,10 @@ public class AlignmentMatchingStoragePooledBuffer : IStorage public override Result SetSize(long size) { - Result rc = _baseStorage.SetSize(Alignment.AlignUpPow2(size, _dataAlignment)); + Result res = _baseStorage.SetSize(Alignment.AlignUpPow2(size, _dataAlignment)); _isBaseStorageSizeDirty = true; - return rc; + return res; } public override Result GetSize(out long size) @@ -267,8 +267,8 @@ public class AlignmentMatchingStoragePooledBuffer : IStorage if (_isBaseStorageSizeDirty) { - Result rc = _baseStorage.GetSize(out long baseStorageSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseStorage.GetSize(out long baseStorageSize); + if (res.IsFailure()) return res.Miss(); _isBaseStorageSizeDirty = false; _baseStorageSize = baseStorageSize; @@ -289,11 +289,11 @@ public class AlignmentMatchingStoragePooledBuffer : IStorage if (size == 0) return Result.Success; - Result rc = GetSize(out long baseStorageSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetSize(out long baseStorageSize); + if (res.IsFailure()) return res.Miss(); - rc = CheckOffsetAndSize(offset, size); - if (rc.IsFailure()) return rc.Miss(); + res = CheckOffsetAndSize(offset, size); + if (res.IsFailure()) return res.Miss(); long validSize = Math.Min(size, baseStorageSize - offset); long alignedOffset = Alignment.AlignDownPow2(offset, _dataAlignment); @@ -359,11 +359,11 @@ public class AlignmentMatchingStorageInBulkRead : IStorage if (destination.Length == 0) return Result.Success; - Result rc = GetSize(out long baseStorageSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetSize(out long baseStorageSize); + if (res.IsFailure()) return res.Miss(); - rc = CheckAccessRange(offset, destination.Length, baseStorageSize); - if (rc.IsFailure()) return rc.Miss(); + res = CheckAccessRange(offset, destination.Length, baseStorageSize); + if (res.IsFailure()) return res.Miss(); // Calculate the aligned offsets of the requested region. long offsetEnd = offset + destination.Length; @@ -385,8 +385,8 @@ public class AlignmentMatchingStorageInBulkRead : IStorage // into the buffer and copy the unaligned portion to the destination buffer. if (alignedSize <= pooledBuffer.GetSize()) { - rc = _baseStorage.Read(alignedOffset, pooledBuffer.GetBuffer().Slice(0, (int)alignedSize)); - if (rc.IsFailure()) return rc.Miss(); + res = _baseStorage.Read(alignedOffset, pooledBuffer.GetBuffer().Slice(0, (int)alignedSize)); + if (res.IsFailure()) return res.Miss(); pooledBuffer.GetBuffer().Slice((int)(offset - alignedOffset), destination.Length) .CopyTo(destination); @@ -415,8 +415,8 @@ public class AlignmentMatchingStorageInBulkRead : IStorage int headSize = (int)(coreOffset - offset); Assert.SdkLess(headSize, destination.Length); - rc = _baseStorage.Read(alignedOffset, pooledBuffer.GetBuffer().Slice(0, (int)_dataAlignment)); - if (rc.IsFailure()) return rc.Miss(); + res = _baseStorage.Read(alignedOffset, pooledBuffer.GetBuffer().Slice(0, (int)_dataAlignment)); + if (res.IsFailure()) return res.Miss(); pooledBuffer.GetBuffer().Slice((int)(offset - alignedOffset), headSize).CopyTo(destination); } @@ -427,8 +427,8 @@ public class AlignmentMatchingStorageInBulkRead : IStorage int coreSize = (int)(coreOffsetEnd - coreOffset); Span coreBuffer = destination.Slice((int)(coreOffset - offset), coreSize); - rc = _baseStorage.Read(coreOffset, coreBuffer); - if (rc.IsFailure()) return rc.Miss(); + res = _baseStorage.Read(coreOffset, coreBuffer); + if (res.IsFailure()) return res.Miss(); } // Handle any data after the aligned portion. @@ -436,8 +436,8 @@ public class AlignmentMatchingStorageInBulkRead : IStorage { int tailSize = (int)(offsetEnd - coreOffsetEnd); - rc = _baseStorage.Read(coreOffsetEnd, pooledBuffer.GetBuffer().Slice(0, (int)_dataAlignment)); - if (rc.IsFailure()) return rc.Miss(); + res = _baseStorage.Read(coreOffsetEnd, pooledBuffer.GetBuffer().Slice(0, (int)_dataAlignment)); + if (res.IsFailure()) return res.Miss(); pooledBuffer.GetBuffer().Slice(0, tailSize).CopyTo(destination.Slice((int)(coreOffsetEnd - offset))); } @@ -450,11 +450,11 @@ public class AlignmentMatchingStorageInBulkRead : IStorage if (source.Length == 0) return Result.Success; - Result rc = GetSize(out long baseStorageSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetSize(out long baseStorageSize); + if (res.IsFailure()) return res.Miss(); - rc = CheckAccessRange(offset, source.Length, baseStorageSize); - if (rc.IsFailure()) return rc.Miss(); + res = CheckAccessRange(offset, source.Length, baseStorageSize); + if (res.IsFailure()) return res.Miss(); using var pooledBuffer = new PooledBuffer((int)_dataAlignment, (int)_dataAlignment); @@ -469,10 +469,10 @@ public class AlignmentMatchingStorageInBulkRead : IStorage public override Result SetSize(long size) { - Result rc = _baseStorage.SetSize(Alignment.AlignUpPow2(size, _dataAlignment)); + Result res = _baseStorage.SetSize(Alignment.AlignUpPow2(size, _dataAlignment)); _baseStorageSize = -1; - return rc; + return res; } public override Result GetSize(out long size) @@ -481,8 +481,8 @@ public class AlignmentMatchingStorageInBulkRead : IStorage if (_baseStorageSize < 0) { - Result rc = _baseStorage.GetSize(out long baseStorageSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseStorage.GetSize(out long baseStorageSize); + if (res.IsFailure()) return res.Miss(); _baseStorageSize = baseStorageSize; } @@ -502,11 +502,11 @@ public class AlignmentMatchingStorageInBulkRead : IStorage if (size == 0) return Result.Success; - Result rc = GetSize(out long baseStorageSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetSize(out long baseStorageSize); + if (res.IsFailure()) return res.Miss(); - rc = CheckOffsetAndSize(offset, size); - if (rc.IsFailure()) return rc.Miss(); + res = CheckOffsetAndSize(offset, size); + if (res.IsFailure()) return res.Miss(); long validSize = Math.Min(size, baseStorageSize - offset); long alignedOffset = Alignment.AlignDownPow2(offset, _dataAlignment); diff --git a/src/LibHac/FsSystem/AlignmentMatchingStorageImpl.cs b/src/LibHac/FsSystem/AlignmentMatchingStorageImpl.cs index 951f8d96..adcbecfe 100644 --- a/src/LibHac/FsSystem/AlignmentMatchingStorageImpl.cs +++ b/src/LibHac/FsSystem/AlignmentMatchingStorageImpl.cs @@ -70,8 +70,8 @@ public static class AlignmentMatchingStorageImpl // Read the core portion that doesn't contain any partial blocks. if (coreSize > 0) { - Result rc = storage.Read(coreOffset, destination.Slice((int)offsetRoundUpDifference, (int)coreSize)); - if (rc.IsFailure()) return rc.Miss(); + Result res = storage.Read(coreOffset, destination.Slice((int)offsetRoundUpDifference, (int)coreSize)); + if (res.IsFailure()) return res.Miss(); } // Read any partial block at the head of the requested range @@ -82,8 +82,8 @@ public static class AlignmentMatchingStorageImpl Assert.SdkAssert(GetRoundDownDifference(offset, dataAlignment) + headSize <= workBuffer.Length); - Result rc = storage.Read(headOffset, workBuffer.Slice(0, (int)dataAlignment)); - if (rc.IsFailure()) return rc.Miss(); + Result res = storage.Read(headOffset, workBuffer.Slice(0, (int)dataAlignment)); + if (res.IsFailure()) return res.Miss(); workBuffer.Slice((int)GetRoundDownDifference(offset, dataAlignment), headSize).CopyTo(destination); } @@ -97,8 +97,8 @@ public static class AlignmentMatchingStorageImpl long alignedTailOffset = Alignment.AlignDownPow2(tailOffset, dataAlignment); long copySize = Math.Min(alignedTailOffset + dataAlignment - tailOffset, remainingTailSize); - Result rc = storage.Read(alignedTailOffset, workBuffer.Slice(0, (int)dataAlignment)); - if (rc.IsFailure()) return rc.Miss(); + Result res = storage.Read(alignedTailOffset, workBuffer.Slice(0, (int)dataAlignment)); + if (res.IsFailure()) return res.Miss(); Assert.SdkAssert(tailOffset - offset + copySize <= destination.Length); Assert.SdkAssert(tailOffset - alignedTailOffset + copySize <= dataAlignment); @@ -137,8 +137,8 @@ public static class AlignmentMatchingStorageImpl // Write the core portion that doesn't contain any partial blocks. if (coreSize > 0) { - Result rc = storage.Write(coreOffset, source.Slice((int)offsetRoundUpDifference, (int)coreSize)); - if (rc.IsFailure()) return rc.Miss(); + Result res = storage.Write(coreOffset, source.Slice((int)offsetRoundUpDifference, (int)coreSize)); + if (res.IsFailure()) return res.Miss(); } // Write any partial block at the head of the specified range @@ -151,13 +151,13 @@ public static class AlignmentMatchingStorageImpl // Read the existing block, copy the partial block to the appropriate portion, // and write the modified block back to the base storage. - Result rc = storage.Read(headOffset, workBuffer.Slice(0, (int)dataAlignment)); - if (rc.IsFailure()) return rc.Miss(); + Result res = storage.Read(headOffset, workBuffer.Slice(0, (int)dataAlignment)); + if (res.IsFailure()) return res.Miss(); source.Slice(0, headSize).CopyTo(workBuffer.Slice((int)(offset - headOffset))); - rc = storage.Write(headOffset, workBuffer.Slice(0, (int)dataAlignment)); - if (rc.IsFailure()) return rc.Miss(); + res = storage.Write(headOffset, workBuffer.Slice(0, (int)dataAlignment)); + if (res.IsFailure()) return res.Miss(); } long tailOffset = coveredOffset + coreSize; @@ -173,14 +173,14 @@ public static class AlignmentMatchingStorageImpl // Read the existing block, copy the partial block to the appropriate portion, // and write the modified block back to the base storage. - Result rc = storage.Read(alignedTailOffset, workBuffer.Slice(0, (int)dataAlignment)); - if (rc.IsFailure()) return rc.Miss(); + Result res = storage.Read(alignedTailOffset, workBuffer.Slice(0, (int)dataAlignment)); + if (res.IsFailure()) return res.Miss(); source.Slice((int)(tailOffset - offset), (int)copySize) .CopyTo(workBuffer.Slice((int)GetRoundDownDifference(tailOffset, dataAlignment))); - rc = storage.Write(alignedTailOffset, workBuffer.Slice(0, (int)dataAlignment)); - if (rc.IsFailure()) return rc.Miss(); + res = storage.Write(alignedTailOffset, workBuffer.Slice(0, (int)dataAlignment)); + if (res.IsFailure()) return res.Miss(); remainingTailSize -= copySize; tailOffset += copySize; diff --git a/src/LibHac/FsSystem/AsynchronousAccess.cs b/src/LibHac/FsSystem/AsynchronousAccess.cs index c833b0a5..c903efa6 100644 --- a/src/LibHac/FsSystem/AsynchronousAccess.cs +++ b/src/LibHac/FsSystem/AsynchronousAccess.cs @@ -36,8 +36,8 @@ public interface IAsynchronousAccessSplitter : IDisposable return Result.Success; } - Result rc = QueryAppropriateOffset(out long offsetAppropriate, startOffset, accessSize, alignmentSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = QueryAppropriateOffset(out long offsetAppropriate, startOffset, accessSize, alignmentSize); + if (res.IsFailure()) return res.Miss(); Assert.SdkNotEqual(startOffset, offsetAppropriate); nextOffset = Math.Min(startOffset, offsetAppropriate); @@ -53,8 +53,8 @@ public interface IAsynchronousAccessSplitter : IDisposable while (currentOffset < endOffset) { - Result rc = QueryNextOffset(out currentOffset, currentOffset, endOffset, accessSize, alignmentSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = QueryNextOffset(out currentOffset, currentOffset, endOffset, accessSize, alignmentSize); + if (res.IsFailure()) return res.Miss(); invocationCount++; } diff --git a/src/LibHac/FsSystem/BlockCacheBufferedStorage.cs b/src/LibHac/FsSystem/BlockCacheBufferedStorage.cs index a572367e..9c5af0ec 100644 --- a/src/LibHac/FsSystem/BlockCacheBufferedStorage.cs +++ b/src/LibHac/FsSystem/BlockCacheBufferedStorage.cs @@ -101,8 +101,8 @@ public class BlockCacheBufferedStorage : IStorage Assert.SdkNull(_storageData); Assert.SdkGreater(maxCacheEntries, 0); - Result rc = _cacheManager.Initialize(bufferManager, maxCacheEntries); - if (rc.IsFailure()) return rc.Miss(); + Result res = _cacheManager.Initialize(bufferManager, maxCacheEntries); + if (res.IsFailure()) return res.Miss(); _mutex = mutex; _storageData = data; diff --git a/src/LibHac/FsSystem/BucketTree.cs b/src/LibHac/FsSystem/BucketTree.cs index bad11457..3ade95a4 100644 --- a/src/LibHac/FsSystem/BucketTree.cs +++ b/src/LibHac/FsSystem/BucketTree.cs @@ -237,8 +237,8 @@ public partial class BucketTree : IDisposable Offset mid = pos + half; long offset = 0; - Result rc = storage.Read(mid.Get(), SpanHelpers.AsByteSpan(ref offset)); - if (rc.IsFailure()) return rc.Miss(); + Result res = storage.Read(mid.Get(), SpanHelpers.AsByteSpan(ref offset)); + if (res.IsFailure()) return res.Miss(); if (offset <= virtualAddress) { @@ -481,8 +481,8 @@ public partial class BucketTree : IDisposable { UnsafeHelpers.SkipParamInit(out offsets); - Result rc = EnsureOffsetCache(); - if (rc.IsFailure()) return rc.Miss(); + Result res = EnsureOffsetCache(); + if (res.IsFailure()) return res.Miss(); offsets = _offsetCache.Offsets; return Result.Success; @@ -510,12 +510,12 @@ public partial class BucketTree : IDisposable try { // Read node. - Result rc = nodeStorage.Read(0, _nodeL1.GetBuffer()); - if (rc.IsFailure()) return rc; + Result res = nodeStorage.Read(0, _nodeL1.GetBuffer()); + if (res.IsFailure()) return res.Miss(); // Verify node. - rc = _nodeL1.GetHeader().Verify(0, nodeSize, sizeof(long)); - if (rc.IsFailure()) return rc; + res = _nodeL1.GetHeader().Verify(0, nodeSize, sizeof(long)); + if (res.IsFailure()) return res.Miss(); // Validate offsets. int offsetCount = GetOffsetCount(nodeSize); @@ -604,22 +604,22 @@ public partial class BucketTree : IDisposable if (IsEmpty()) return ResultFs.OutOfRange.Log(); - Result rc = GetOffsets(out Offsets offsets); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetOffsets(out Offsets offsets); + if (res.IsFailure()) return res.Miss(); - rc = visitor.Initialize(this, in offsets); - if (rc.IsFailure()) return rc.Miss(); + res = visitor.Initialize(this, in offsets); + if (res.IsFailure()) return res.Miss(); return visitor.Find(virtualAddress); } public Result InvalidateCache() { - Result rc = _nodeStorage.OperateRange(OperationId.InvalidateCache, 0, long.MaxValue); - if (rc.IsFailure()) return rc.Miss(); + Result res = _nodeStorage.OperateRange(OperationId.InvalidateCache, 0, long.MaxValue); + if (res.IsFailure()) return res.Miss(); - rc = _entryStorage.OperateRange(OperationId.InvalidateCache, 0, long.MaxValue); - if (rc.IsFailure()) return rc.Miss(); + res = _entryStorage.OperateRange(OperationId.InvalidateCache, 0, long.MaxValue); + if (res.IsFailure()) return res.Miss(); _offsetCache.IsInitialized = false; return Result.Success; @@ -635,11 +635,11 @@ public partial class BucketTree : IDisposable if (_offsetCache.IsInitialized) return Result.Success; - Result rc = _nodeStorage.Read(0, _nodeL1.GetBuffer()); - if (rc.IsFailure()) return rc.Miss(); + Result res = _nodeStorage.Read(0, _nodeL1.GetBuffer()); + if (res.IsFailure()) return res.Miss(); - rc = _nodeL1.GetHeader().Verify(0, _nodeSize, sizeof(long)); - if (rc.IsFailure()) return rc.Miss(); + res = _nodeL1.GetHeader().Verify(0, _nodeSize, sizeof(long)); + if (res.IsFailure()) return res.Miss(); BucketTreeNode node = _nodeL1.GetNode(); @@ -705,8 +705,8 @@ public partial class BucketTree : IDisposable using var pool = new PooledBuffer((int)_nodeSize, 1); var buffer = Span.Empty; - Result rc = _entryStorage.GetSize(out long entryStorageSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = _entryStorage.GetSize(out long entryStorageSize); + if (res.IsFailure()) return res.Miss(); // Read the node. if (_nodeSize <= pool.GetSize()) @@ -717,8 +717,8 @@ public partial class BucketTree : IDisposable if (_nodeSize + ofs > entryStorageSize) return ResultFs.InvalidBucketTreeNodeEntryCount.Log(); - rc = _entryStorage.Read(ofs, buffer.Slice(0, (int)_nodeSize)); - if (rc.IsFailure()) return rc.Miss(); + res = _entryStorage.Read(ofs, buffer.Slice(0, (int)_nodeSize)); + if (res.IsFailure()) return res.Miss(); } // Calculate extents. @@ -758,8 +758,8 @@ public partial class BucketTree : IDisposable if (_entrySize + ofs > entryStorageSize) return ResultFs.InvalidBucketTreeEntryOffset.Log(); - rc = _entryStorage.Read(ofs, SpanHelpers.AsByteSpan(ref nextEntry)); - if (rc.IsFailure()) return rc.Miss(); + res = _entryStorage.Read(ofs, SpanHelpers.AsByteSpan(ref nextEntry)); + if (res.IsFailure()) return res.Miss(); } else { @@ -940,7 +940,7 @@ public partial class BucketTree : IDisposable { Assert.SdkRequiresNotNull(_tree); - Result rc; + Result res; // Get the L1 node. BucketTreeNode nodeL1 = _tree._nodeL1.GetNode(); @@ -983,8 +983,8 @@ public partial class BucketTree : IDisposable if (index >= _tree._offsetCount) return ResultFs.InvalidBucketTreeNodeOffset.Log(); - rc = FindEntrySet(out entrySetIndex, virtualAddress, index); - if (rc.IsFailure()) return rc; + res = FindEntrySet(out entrySetIndex, virtualAddress, index); + if (res.IsFailure()) return res.Miss(); } else { @@ -997,8 +997,8 @@ public partial class BucketTree : IDisposable return ResultFs.InvalidBucketTreeNodeOffset.Log(); // Find the entry. - rc = FindEntry(virtualAddress, entrySetIndex); - if (rc.IsFailure()) return rc; + res = FindEntry(virtualAddress, entrySetIndex); + if (res.IsFailure()) return res.Miss(); // Set count. _entrySetCount = _tree._entrySetCount; @@ -1033,13 +1033,13 @@ public partial class BucketTree : IDisposable ref ValueSubStorage storage = ref _tree._nodeStorage; // Read the node. - Result rc = storage.Read(nodeOffset, buffer.Slice(0, (int)nodeSize)); - if (rc.IsFailure()) return rc; + Result res = storage.Read(nodeOffset, buffer.Slice(0, (int)nodeSize)); + if (res.IsFailure()) return res.Miss(); // Validate the header. NodeHeader header = MemoryMarshal.Cast(buffer)[0]; - rc = header.Verify(nodeIndex, nodeSize, sizeof(long)); - if (rc.IsFailure()) return rc; + res = header.Verify(nodeIndex, nodeSize, sizeof(long)); + if (res.IsFailure()) return res.Miss(); // Create the node and find. var node = new StorageNode(sizeof(long), header.EntryCount); @@ -1064,16 +1064,16 @@ public partial class BucketTree : IDisposable // Read and validate the header. Unsafe.SkipInit(out NodeHeader header); - Result rc = storage.Read(nodeOffset, SpanHelpers.AsByteSpan(ref header)); - if (rc.IsFailure()) return rc.Miss(); + Result res = storage.Read(nodeOffset, SpanHelpers.AsByteSpan(ref header)); + if (res.IsFailure()) return res.Miss(); - rc = header.Verify(nodeIndex, nodeSize, sizeof(long)); - if (rc.IsFailure()) return rc.Miss(); + res = header.Verify(nodeIndex, nodeSize, sizeof(long)); + if (res.IsFailure()) return res.Miss(); // Create the node, and find. var node = new StorageNode(nodeOffset, sizeof(long), header.EntryCount); - rc = node.Find(in storage, virtualAddress); - if (rc.IsFailure()) return rc.Miss(); + res = node.Find(in storage, virtualAddress); + if (res.IsFailure()) return res.Miss(); if (node.GetIndex() < 0) return ResultFs.InvalidBucketTreeVirtualOffset.Log(); @@ -1109,13 +1109,13 @@ public partial class BucketTree : IDisposable ref ValueSubStorage storage = ref _tree._entryStorage; // Read the entry set. - Result rc = storage.Read(entrySetOffset, buffer.Slice(0, (int)entrySetSize)); - if (rc.IsFailure()) return rc; + Result res = storage.Read(entrySetOffset, buffer.Slice(0, (int)entrySetSize)); + if (res.IsFailure()) return res.Miss(); // Validate the entry set. EntrySetHeader entrySet = MemoryMarshal.Cast(buffer)[0]; - rc = entrySet.Header.Verify(entrySetIndex, entrySetSize, entrySize); - if (rc.IsFailure()) return rc; + res = entrySet.Header.Verify(entrySetIndex, entrySetSize, entrySize); + if (res.IsFailure()) return res.Miss(); // Create the node, and find. var node = new StorageNode(entrySize, entrySet.Info.Count); @@ -1146,16 +1146,16 @@ public partial class BucketTree : IDisposable // Read and validate the entry set. Unsafe.SkipInit(out EntrySetHeader entrySet); - Result rc = storage.Read(entrySetOffset, SpanHelpers.AsByteSpan(ref entrySet)); - if (rc.IsFailure()) return rc.Miss(); + Result res = storage.Read(entrySetOffset, SpanHelpers.AsByteSpan(ref entrySet)); + if (res.IsFailure()) return res.Miss(); - rc = entrySet.Header.Verify(entrySetIndex, entrySetSize, entrySize); - if (rc.IsFailure()) return rc.Miss(); + res = entrySet.Header.Verify(entrySetIndex, entrySetSize, entrySize); + if (res.IsFailure()) return res.Miss(); // Create the node, and find. var node = new StorageNode(entrySetOffset, entrySize, entrySet.Info.Count); - rc = node.Find(in storage, virtualAddress); - if (rc.IsFailure()) return rc.Miss(); + res = node.Find(in storage, virtualAddress); + if (res.IsFailure()) return res.Miss(); if (node.GetIndex() < 0) return ResultFs.InvalidBucketTreeVirtualOffset.Log(); @@ -1165,8 +1165,8 @@ public partial class BucketTree : IDisposable int entryIndex = node.GetIndex(); long entryOffset = GetBucketTreeEntryOffset(entrySetOffset, entrySize, entryIndex); - rc = storage.Read(entryOffset, _entry.Span); - if (rc.IsFailure()) return rc.Miss(); + res = storage.Read(entryOffset, _entry.Span); + if (res.IsFailure()) return res.Miss(); // Set our entry set/index. _entrySet = entrySet; @@ -1177,7 +1177,7 @@ public partial class BucketTree : IDisposable public Result MoveNext() { - Result rc; + Result res; if (!IsValid()) return ResultFs.OutOfRange.Log(); @@ -1198,11 +1198,11 @@ public partial class BucketTree : IDisposable long entrySetSize = _tree._nodeSize; long entrySetOffset = entrySetIndex * entrySetSize; - rc = _tree._entryStorage.Read(entrySetOffset, SpanHelpers.AsByteSpan(ref _entrySet)); - if (rc.IsFailure()) return rc; + res = _tree._entryStorage.Read(entrySetOffset, SpanHelpers.AsByteSpan(ref _entrySet)); + if (res.IsFailure()) return res.Miss(); - rc = _entrySet.Header.Verify(entrySetIndex, entrySetSize, _tree._entrySize); - if (rc.IsFailure()) return rc; + res = _entrySet.Header.Verify(entrySetIndex, entrySetSize, _tree._entrySize); + if (res.IsFailure()) return res.Miss(); if (_entrySet.Info.Start != end || _entrySet.Info.Start >= _entrySet.Info.End) return ResultFs.InvalidBucketTreeEntrySetOffset.Log(); @@ -1218,8 +1218,8 @@ public partial class BucketTree : IDisposable long entrySize = _tree._entrySize; long entryOffset = GetBucketTreeEntryOffset(_entrySet.Info.Index, _tree._nodeSize, entrySize, entryIndex); - rc = _tree._entryStorage.Read(entryOffset, _entry.Span); - if (rc.IsFailure()) return rc; + res = _tree._entryStorage.Read(entryOffset, _entry.Span); + if (res.IsFailure()) return res.Miss(); // Note that we changed index. _entryIndex = entryIndex; @@ -1228,7 +1228,7 @@ public partial class BucketTree : IDisposable public Result MovePrevious() { - Result rc; + Result res; if (!IsValid()) return ResultFs.OutOfRange.Log(); @@ -1248,11 +1248,11 @@ public partial class BucketTree : IDisposable int entrySetIndex = _entrySet.Info.Index - 1; long entrySetOffset = entrySetIndex * entrySetSize; - rc = _tree._entryStorage.Read(entrySetOffset, SpanHelpers.AsByteSpan(ref _entrySet)); - if (rc.IsFailure()) return rc; + res = _tree._entryStorage.Read(entrySetOffset, SpanHelpers.AsByteSpan(ref _entrySet)); + if (res.IsFailure()) return res.Miss(); - rc = _entrySet.Header.Verify(entrySetIndex, entrySetSize, _tree._entrySize); - if (rc.IsFailure()) return rc; + res = _entrySet.Header.Verify(entrySetIndex, entrySetSize, _tree._entrySize); + if (res.IsFailure()) return res.Miss(); if (_entrySet.Info.End != start || _entrySet.Info.Start >= _entrySet.Info.End) return ResultFs.InvalidBucketTreeEntrySetOffset.Log(); @@ -1270,8 +1270,8 @@ public partial class BucketTree : IDisposable long entrySize = _tree._entrySize; long entryOffset = GetBucketTreeEntryOffset(_entrySet.Info.Index, _tree._nodeSize, entrySize, entryIndex); - rc = _tree._entryStorage.Read(entryOffset, _entry.Span); - if (rc.IsFailure()) return rc; + res = _tree._entryStorage.Read(entryOffset, _entry.Span); + if (res.IsFailure()) return res.Miss(); // Note that we changed index. _entryIndex = entryIndex; diff --git a/src/LibHac/FsSystem/BucketTreeBuilder.cs b/src/LibHac/FsSystem/BucketTreeBuilder.cs index 84c49e1c..a921e5a7 100644 --- a/src/LibHac/FsSystem/BucketTreeBuilder.cs +++ b/src/LibHac/FsSystem/BucketTreeBuilder.cs @@ -67,8 +67,8 @@ public partial class BucketTree // Create and write the header var header = new Header(); header.Format(entryCount); - Result rc = headerStorage.Write(0, SpanHelpers.AsByteSpan(ref header)); - if (rc.IsFailure()) return rc; + Result res = headerStorage.Write(0, SpanHelpers.AsByteSpan(ref header)); + if (res.IsFailure()) return res.Miss(); // Allocate buffers for the L1 node and entry sets _l1Node.Allocate(allocator, nodeSize); @@ -115,8 +115,8 @@ public partial class BucketTree if (entryOffset <= _currentOffset) return ResultFs.InvalidOffset.Log(); - Result rc = FinalizePreviousEntrySet(entryOffset); - if (rc.IsFailure()) return rc; + Result res = FinalizePreviousEntrySet(entryOffset); + if (res.IsFailure()) return res.Miss(); AddEntryOffset(entryOffset); @@ -153,8 +153,8 @@ public partial class BucketTree // Write the entry set to the entry storage long storageOffset = (long)_nodeSize * prevEntrySetIndex; - Result rc = _entryStorage.Write(storageOffset, _entrySet.GetBuffer()); - if (rc.IsFailure()) return rc; + Result res = _entryStorage.Write(storageOffset, _entrySet.GetBuffer()); + if (res.IsFailure()) return res.Miss(); // Clear the entry set buffer to begin the new entry set _entrySet.FillZero(); @@ -177,8 +177,8 @@ public partial class BucketTree // Write the L2 node to the node storage long nodeOffset = (long)_nodeSize * (prevL2NodeIndex + 1); - rc = _nodeStorage.Write(nodeOffset, _l2Node.GetBuffer()); - if (rc.IsFailure()) return rc; + res = _nodeStorage.Write(nodeOffset, _l2Node.GetBuffer()); + if (res.IsFailure()) return res.Miss(); // Clear the L2 node buffer to begin the new node _l2Node.FillZero(); @@ -253,8 +253,8 @@ public partial class BucketTree if (_currentOffset == -1) return Result.Success; - Result rc = FinalizePreviousEntrySet(endOffset); - if (rc.IsFailure()) return rc; + Result res = FinalizePreviousEntrySet(endOffset); + if (res.IsFailure()) return res.Miss(); int entrySetIndex = _currentEntryIndex / _entriesPerEntrySet; int indexInEntrySet = _currentEntryIndex % _entriesPerEntrySet; @@ -269,8 +269,8 @@ public partial class BucketTree entrySetHeader.OffsetEnd = endOffset; long entryStorageOffset = (long)_nodeSize * entrySetIndex; - rc = _entryStorage.Write(entryStorageOffset, _entrySet.GetBuffer()); - if (rc.IsFailure()) return rc; + res = _entryStorage.Write(entryStorageOffset, _entrySet.GetBuffer()); + if (res.IsFailure()) return res.Miss(); } int l2NodeIndex = BitUtil.DivideUp(_currentL2OffsetIndex, _offsetsPerNode) - 2; @@ -285,8 +285,8 @@ public partial class BucketTree l2NodeHeader.OffsetEnd = endOffset; long l2NodeStorageOffset = _nodeSize * (l2NodeIndex + 1); - rc = _nodeStorage.Write(l2NodeStorageOffset, _l2Node.GetBuffer()); - if (rc.IsFailure()) return rc; + res = _nodeStorage.Write(l2NodeStorageOffset, _l2Node.GetBuffer()); + if (res.IsFailure()) return res.Miss(); } // Finalize the L1 node @@ -304,8 +304,8 @@ public partial class BucketTree l1NodeHeader.EntryCount = l2NodeIndex + 1; } - rc = _nodeStorage.Write(0, _l1Node.GetBuffer()); - if (rc.IsFailure()) return rc; + res = _nodeStorage.Write(0, _l1Node.GetBuffer()); + if (res.IsFailure()) return res.Miss(); _currentOffset = long.MaxValue; return Result.Success; diff --git a/src/LibHac/FsSystem/BufferedStorage.cs b/src/LibHac/FsSystem/BufferedStorage.cs index b2a6c780..fa677f02 100644 --- a/src/LibHac/FsSystem/BufferedStorage.cs +++ b/src/LibHac/FsSystem/BufferedStorage.cs @@ -317,8 +317,8 @@ public class BufferedStorage : IStorage Span cacheBuffer = _memoryRange.Span; Assert.SdkEqual(flushSize, cacheBuffer.Length); - Result rc = baseStorage.Write(_offset, cacheBuffer); - if (rc.IsFailure()) return rc.Miss(); + Result res = baseStorage.Write(_offset, cacheBuffer); + if (res.IsFailure()) return res.Miss(); _isDirty = false; @@ -395,19 +395,19 @@ public class BufferedStorage : IStorage Assert.SdkRequires(!IsValid()); Assert.SdkRequires(!_isDirty); - Result rc; + Result res; // Make sure this Cache has an allocated buffer if (_memoryRange.IsNull) { - rc = AllocateFetchBuffer(); - if (rc.IsFailure()) return rc.Miss(); + res = AllocateFetchBuffer(); + if (res.IsFailure()) return res.Miss(); } CalcFetchParameter(out FetchParameter fetchParam, offset); - rc = _bufferedStorage._baseStorage.Read(fetchParam.Offset, fetchParam.Buffer); - if (rc.IsFailure()) return rc.Miss(); + res = _bufferedStorage._baseStorage.Read(fetchParam.Offset, fetchParam.Buffer); + if (res.IsFailure()) return res.Miss(); _offset = fetchParam.Offset; Assert.SdkAssert(Hits(offset, 1)); @@ -437,8 +437,8 @@ public class BufferedStorage : IStorage // Make sure this Cache has an allocated buffer if (_memoryRange.IsNull) { - Result rc = AllocateFetchBuffer(); - if (rc.IsFailure()) return rc.Miss(); + Result res = AllocateFetchBuffer(); + if (res.IsFailure()) return res.Miss(); } CalcFetchParameter(out FetchParameter fetchParam, offset); @@ -531,15 +531,15 @@ public class BufferedStorage : IStorage IBufferManager bufferManager = _bufferedStorage._bufferManager; Assert.SdkAssert(bufferManager.AcquireCache(_cacheHandle).IsNull); - Result rc = BufferManagerUtility.AllocateBufferUsingBufferManagerContext(out _memoryRange, + Result res = BufferManagerUtility.AllocateBufferUsingBufferManagerContext(out _memoryRange, bufferManager, (int)_bufferedStorage._blockSize, new IBufferManager.BufferAttribute(), static (in Buffer buffer) => !buffer.IsNull); // Clear the current MemoryRange if allocation failed. - if (rc.IsFailure()) + if (res.IsFailure()) { _memoryRange = Buffer.Empty; - return rc.Log(); + return res.Log(); } return Result.Success; @@ -999,8 +999,8 @@ public class BufferedStorage : IStorage Assert.SdkRequiresLess(0, bufferCount); // Get the base storage size. - Result rc = baseStorage.GetSize(out _baseStorageSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = baseStorage.GetSize(out _baseStorageSize); + if (res.IsFailure()) return res.Miss(); // Set members. _baseStorage.Set(in baseStorage); @@ -1104,7 +1104,7 @@ public class BufferedStorage : IStorage { Assert.SdkRequires(IsInitialized()); - Result rc; + Result res; long prevSize = _baseStorageSize; if (prevSize < size) { @@ -1117,8 +1117,8 @@ public class BufferedStorage : IStorage if (cache.AcquireNextOverlappedCache(invalidateOffset, invalidateSize)) { - rc = cache.Flush(); - if (rc.IsFailure()) return rc.Miss(); + res = cache.Flush(); + if (res.IsFailure()) return res.Miss(); cache.Invalidate(); } @@ -1138,8 +1138,8 @@ public class BufferedStorage : IStorage { if (isFragment && cache.Hits(invalidateOffset, 1)) { - rc = cache.Flush(); - if (rc.IsFailure()) return rc.Miss(); + res = cache.Flush(); + if (res.IsFailure()) return res.Miss(); } cache.Invalidate(); @@ -1147,12 +1147,12 @@ public class BufferedStorage : IStorage } // Set the size. - rc = _baseStorage.SetSize(size); - if (rc.IsFailure()) return rc.Miss(); + res = _baseStorage.SetSize(size); + if (res.IsFailure()) return res.Miss(); // Get our new size. - rc = _baseStorage.GetSize(out long newSize); - if (rc.IsFailure()) return rc.Miss(); + res = _baseStorage.GetSize(out long newSize); + if (res.IsFailure()) return res.Miss(); _baseStorageSize = newSize; return Result.Success; @@ -1180,8 +1180,8 @@ public class BufferedStorage : IStorage using var cache = new SharedCache(this); while (cache.AcquireNextDirtyCache()) { - Result rc = cache.Flush(); - if (rc.IsFailure()) return rc.Miss(); + Result res = cache.Flush(); + if (res.IsFailure()) return res.Miss(); } // Flush the base storage. @@ -1219,8 +1219,8 @@ public class BufferedStorage : IStorage if (_bufferManager.GetTotalAllocatableSize() < flushThreshold) { - Result rc = Flush(); - if (rc.IsFailure()) return rc.Miss(); + Result res = Flush(); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -1244,8 +1244,8 @@ public class BufferedStorage : IStorage { if (++dirtyCount > 1) { - Result rc = cache.Flush(); - if (rc.IsFailure()) return rc.Miss(); + Result res = cache.Flush(); + if (res.IsFailure()) return res.Miss(); cache.Invalidate(); } @@ -1302,13 +1302,13 @@ public class BufferedStorage : IStorage if (remainingSize <= bulkReadSizeMax) { // Try to do a bulk read. - Result rc = BulkRead(currentOffset, destination.Slice((int)bufferOffset, (int)remainingSize), + Result res = BulkRead(currentOffset, destination.Slice((int)bufferOffset, (int)remainingSize), headCacheNeeded, tailCacheNeeded); // If the read fails due to insufficient pooled buffer size // then we want to fall back to the normal read path. - if (!ResultFs.AllocationPooledBufferNotEnoughSize.Includes(rc)) - return rc.Miss(); + if (!ResultFs.AllocationPooledBufferNotEnoughSize.Includes(res)) + return res.Miss(); } } @@ -1346,8 +1346,8 @@ public class BufferedStorage : IStorage if (!cache.AcquireNextOverlappedCache(currentOffset, currentSize)) { // The block wasn't in the cache. Read the block from the base storage - Result rc = PrepareAllocation(); - if (rc.IsFailure()) return rc.Miss(); + Result res = PrepareAllocation(); + if (res.IsFailure()) return res.Miss(); // Loop until we can get exclusive access to the cache block while (true) @@ -1364,15 +1364,15 @@ public class BufferedStorage : IStorage // Fetch the data from the base storage into the cache buffer if successful if (upgradeResult.wasUpgradeSuccessful) { - rc = fetchCache.Fetch(currentOffset); - if (rc.IsFailure()) return rc.Miss(); + res = fetchCache.Fetch(currentOffset); + if (res.IsFailure()) return res.Miss(); break; } } - rc = ControlDirtiness(); - if (rc.IsFailure()) return rc.Miss(); + res = ControlDirtiness(); + if (res.IsFailure()) return res.Miss(); } // Copy the data from the cache buffer to the destination buffer @@ -1387,16 +1387,16 @@ public class BufferedStorage : IStorage { while (cache.AcquireNextOverlappedCache(currentOffset, currentSize)) { - Result rc = cache.Flush(); - if (rc.IsFailure()) return rc.Miss(); + Result res = cache.Flush(); + if (res.IsFailure()) return res.Miss(); cache.Invalidate(); } } // Read directly from the base storage to the destination buffer - Result rcRead = _baseStorage.Read(currentOffset, currentDestination); - if (rcRead.IsFailure()) return rcRead.Miss(); + Result resultRead = _baseStorage.Read(currentOffset, currentDestination); + if (resultRead.IsFailure()) return resultRead.Miss(); } remainingSize -= currentSize; @@ -1510,7 +1510,7 @@ public class BufferedStorage : IStorage /// The of the operation. private Result BulkRead(long offset, Span buffer, bool isHeadCacheNeeded, bool isTailCacheNeeded) { - Result rc; + Result res; // Determine aligned extents. long alignedOffset = Alignment.AlignDownPow2(offset, (uint)_blockSize); @@ -1541,16 +1541,16 @@ public class BufferedStorage : IStorage { while (cache.AcquireNextOverlappedCache(alignedOffset, alignedSize)) { - rc = cache.Flush(); - if (rc.IsFailure()) return rc.Miss(); + res = cache.Flush(); + if (res.IsFailure()) return res.Miss(); cache.Invalidate(); } } // Read from the base storage. - rc = _baseStorage.Read(alignedOffset, workBuffer.Slice(0, (int)alignedSize)); - if (rc.IsFailure()) return rc.Miss(); + res = _baseStorage.Read(alignedOffset, workBuffer.Slice(0, (int)alignedSize)); + if (res.IsFailure()) return res.Miss(); if (workBuffer != buffer) { workBuffer.Slice((int)(offset - alignedOffset), buffer.Length).CopyTo(buffer); @@ -1561,8 +1561,8 @@ public class BufferedStorage : IStorage // Cache the head block if needed. if (isHeadCacheNeeded) { - rc = PrepareAllocation(); - if (rc.IsFailure()) return rc.Miss(); + res = PrepareAllocation(); + if (res.IsFailure()) return res.Miss(); using var cache = new SharedCache(this); while (true) @@ -1577,8 +1577,8 @@ public class BufferedStorage : IStorage if (upgradeResult.wasUpgradeSuccessful) { - rc = fetchCache.FetchFromBuffer(alignedOffset, workBuffer.Slice(0, (int)alignedSize)); - if (rc.IsFailure()) return rc.Miss(); + res = fetchCache.FetchFromBuffer(alignedOffset, workBuffer.Slice(0, (int)alignedSize)); + if (res.IsFailure()) return res.Miss(); break; } } @@ -1591,8 +1591,8 @@ public class BufferedStorage : IStorage { if (!cached) { - rc = PrepareAllocation(); - if (rc.IsFailure()) return rc.Miss(); + res = PrepareAllocation(); + if (res.IsFailure()) return res.Miss(); } using var cache = new SharedCache(this); @@ -1611,9 +1611,9 @@ public class BufferedStorage : IStorage long tailCacheOffset = Alignment.AlignDownPow2(offset + buffer.Length, (uint)_blockSize); long tailCacheSize = alignedSize - tailCacheOffset + alignedOffset; - rc = fetchCache.FetchFromBuffer(tailCacheOffset, + res = fetchCache.FetchFromBuffer(tailCacheOffset, workBuffer.Slice((int)(tailCacheOffset - alignedOffset), (int)tailCacheSize)); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); break; } } @@ -1621,8 +1621,8 @@ public class BufferedStorage : IStorage if (cached) { - rc = ControlDirtiness(); - if (rc.IsFailure()) return rc.Miss(); + res = ControlDirtiness(); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -1665,15 +1665,15 @@ public class BufferedStorage : IStorage currentSize = Alignment.AlignDownPow2(remainingSize, (uint)_blockSize); } - Result rc; + Result res; if (currentSize <= _blockSize) { using var cache = new SharedCache(this); if (!cache.AcquireNextOverlappedCache(currentOffset, currentSize)) { - rc = PrepareAllocation(); - if (rc.IsFailure()) return rc.Miss(); + res = PrepareAllocation(); + if (res.IsFailure()) return res.Miss(); while (true) { @@ -1687,8 +1687,8 @@ public class BufferedStorage : IStorage if (upgradeResult.wasUpgradeSuccessful) { - rc = fetchCache.Fetch(currentOffset); - if (rc.IsFailure()) return rc.Miss(); + res = fetchCache.Fetch(currentOffset); + if (res.IsFailure()) return res.Miss(); break; } } @@ -1697,8 +1697,8 @@ public class BufferedStorage : IStorage BufferManagerUtility.EnableBlockingBufferManagerAllocation(); - rc = ControlDirtiness(); - if (rc.IsFailure()) return rc.Miss(); + res = ControlDirtiness(); + if (res.IsFailure()) return res.Miss(); } else { @@ -1706,15 +1706,15 @@ public class BufferedStorage : IStorage { while (cache.AcquireNextOverlappedCache(currentOffset, currentSize)) { - rc = cache.Flush(); - if (rc.IsFailure()) return rc.Miss(); + res = cache.Flush(); + if (res.IsFailure()) return res.Miss(); cache.Invalidate(); } } - rc = _baseStorage.Write(currentOffset, currentSource.Slice(0, currentSize)); - if (rc.IsFailure()) return rc.Miss(); + res = _baseStorage.Write(currentOffset, currentSource.Slice(0, currentSize)); + if (res.IsFailure()) return res.Miss(); BufferManagerUtility.EnableBlockingBufferManagerAllocation(); } diff --git a/src/LibHac/FsSystem/Buffers/BufferManagerUtility.cs b/src/LibHac/FsSystem/Buffers/BufferManagerUtility.cs index fcaf91ee..1491d584 100644 --- a/src/LibHac/FsSystem/Buffers/BufferManagerUtility.cs +++ b/src/LibHac/FsSystem/Buffers/BufferManagerUtility.cs @@ -62,8 +62,8 @@ internal static class BufferManagerUtility // Todo: Log allocation failure } - Result rc = onFailure(); - if (rc.IsFailure()) return rc; + Result res = onFailure(); + if (res.IsFailure()) return res.Miss(); Thread.Sleep(RetryWait); } @@ -126,14 +126,14 @@ internal static class BufferManagerUtility if (!context.IsNeedBlocking()) { // If we don't need to block, just allocate the buffer. - Result rc = AllocateBufferImpl(); - if (rc.IsFailure()) return rc; + Result res = AllocateBufferImpl(); + if (res.IsFailure()) return res.Miss(); } else { // Otherwise, try to allocate repeatedly. - Result rc = DoContinuouslyUntilBufferIsAllocated(AllocateBufferImpl); - if (rc.IsFailure()) return rc; + Result res = DoContinuouslyUntilBufferIsAllocated(AllocateBufferImpl); + if (res.IsFailure()) return res.Miss(); } Assert.SdkAssert(!tempBuffer.IsNull); diff --git a/src/LibHac/FsSystem/Buffers/FileSystemBufferManager.cs b/src/LibHac/FsSystem/Buffers/FileSystemBufferManager.cs index e8ac8f8c..1a015dce 100644 --- a/src/LibHac/FsSystem/Buffers/FileSystemBufferManager.cs +++ b/src/LibHac/FsSystem/Buffers/FileSystemBufferManager.cs @@ -385,11 +385,11 @@ public class FileSystemBufferManager : IBufferManager public Result Initialize(int maxCacheCount, Memory heapBuffer, int blockSize) { - Result rc = _cacheTable.Initialize(maxCacheCount); - if (rc.IsFailure()) return rc; + Result res = _cacheTable.Initialize(maxCacheCount); + if (res.IsFailure()) return res.Miss(); - rc = _buddyHeap.Initialize(heapBuffer, blockSize); - if (rc.IsFailure()) return rc; + res = _buddyHeap.Initialize(heapBuffer, blockSize); + if (res.IsFailure()) return res.Miss(); _totalSize = (int)_buddyHeap.GetTotalFreeSize(); _peakFreeSize = _totalSize; @@ -400,11 +400,11 @@ public class FileSystemBufferManager : IBufferManager public Result Initialize(int maxCacheCount, Memory heapBuffer, int blockSize, int maxOrder) { - Result rc = _cacheTable.Initialize(maxCacheCount); - if (rc.IsFailure()) return rc; + Result res = _cacheTable.Initialize(maxCacheCount); + if (res.IsFailure()) return res.Miss(); - rc = _buddyHeap.Initialize(heapBuffer, blockSize, maxOrder); - if (rc.IsFailure()) return rc; + res = _buddyHeap.Initialize(heapBuffer, blockSize, maxOrder); + if (res.IsFailure()) return res.Miss(); _totalSize = (int)_buddyHeap.GetTotalFreeSize(); _peakFreeSize = _totalSize; @@ -418,11 +418,11 @@ public class FileSystemBufferManager : IBufferManager // Note: We can't use an external buffer for the cache handle table since it contains managed pointers, // so pass the work buffer directly to the buddy heap. - Result rc = _cacheTable.Initialize(maxCacheCount); - if (rc.IsFailure()) return rc; + Result res = _cacheTable.Initialize(maxCacheCount); + if (res.IsFailure()) return res.Miss(); - rc = _buddyHeap.Initialize(heapBuffer, blockSize, workBuffer); - if (rc.IsFailure()) return rc; + res = _buddyHeap.Initialize(heapBuffer, blockSize, workBuffer); + if (res.IsFailure()) return res.Miss(); _totalSize = (int)_buddyHeap.GetTotalFreeSize(); _peakFreeSize = _totalSize; @@ -437,11 +437,11 @@ public class FileSystemBufferManager : IBufferManager // Note: We can't use an external buffer for the cache handle table since it contains managed pointers, // so pass the work buffer directly to the buddy heap. - Result rc = _cacheTable.Initialize(maxCacheCount); - if (rc.IsFailure()) return rc; + Result res = _cacheTable.Initialize(maxCacheCount); + if (res.IsFailure()) return res.Miss(); - rc = _buddyHeap.Initialize(heapBuffer, blockSize, maxOrder, workBuffer); - if (rc.IsFailure()) return rc; + res = _buddyHeap.Initialize(heapBuffer, blockSize, maxOrder, workBuffer); + if (res.IsFailure()) return res.Miss(); _totalSize = (int)_buddyHeap.GetTotalFreeSize(); _peakFreeSize = _totalSize; diff --git a/src/LibHac/FsSystem/CompressedStorage.cs b/src/LibHac/FsSystem/CompressedStorage.cs index 7ea54a39..82ae8df1 100644 --- a/src/LibHac/FsSystem/CompressedStorage.cs +++ b/src/LibHac/FsSystem/CompressedStorage.cs @@ -43,8 +43,8 @@ public class CompressedStorage : IStorage, IAsynchronousAccessSplitter { Assert.SdkRequiresNotNullOut(out size); - Result rc = _bucketTree.GetOffsets(out BucketTree.Offsets offsets); - if (rc.IsFailure()) return rc.Miss(); + Result res = _bucketTree.GetOffsets(out BucketTree.Offsets offsets); + if (res.IsFailure()) return res.Miss(); size = offsets.EndOffset; return Result.Success; @@ -74,9 +74,9 @@ public class CompressedStorage : IStorage, IAsynchronousAccessSplitter Assert.SdkRequiresLessEqual(blockSizeMax, continuousReadingSizeMax); Assert.SdkRequiresNotNull(getDecompressorFunc); - Result rc = _bucketTree.Initialize(allocatorForBucketTree, in nodeStorage, in entryStorage, NodeSize, + Result res = _bucketTree.Initialize(allocatorForBucketTree, in nodeStorage, in entryStorage, NodeSize, Unsafe.SizeOf(), bucketTreeEntryCount); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); _blockSizeMax = blockSizeMax; _continuousReadingSizeMax = continuousReadingSizeMax; @@ -197,8 +197,8 @@ public class CompressedStorage : IStorage, IAsynchronousAccessSplitter public Result Initialize(IBufferManager allocator, long storageSize, long cacheSize0, long cacheSize1, int maxCacheEntries) { - Result rc = _cacheManager.Initialize(allocator, maxCacheEntries); - if (rc.IsFailure()) return rc.Miss(); + Result res = _cacheManager.Initialize(allocator, maxCacheEntries); + if (res.IsFailure()) return res.Miss(); _storageSize = storageSize; _cacheSize0 = cacheSize0; @@ -299,15 +299,15 @@ public class CompressedStorage : IStorage, IAsynchronousAccessSplitter int bucketTreeEntryCount, long blockSizeMax, long continuousReadingSizeMax, GetDecompressorFunction getDecompressorFunc, long cacheSize0, long cacheSize1, int maxCacheEntries) { - Result rc = _core.Initialize(allocatorForBucketTree, in dataStorage, in nodeStorage, in entryStorage, + Result res = _core.Initialize(allocatorForBucketTree, in dataStorage, in nodeStorage, in entryStorage, bucketTreeEntryCount, blockSizeMax, continuousReadingSizeMax, getDecompressorFunc); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); - rc = _core.GetSize(out long size); - if (rc.IsFailure()) return rc.Miss(); + res = _core.GetSize(out long size); + if (res.IsFailure()) return res.Miss(); - rc = _cacheManager.Initialize(allocatorForCacheManager, size, cacheSize0, cacheSize1, maxCacheEntries); - if (rc.IsFailure()) return rc.Miss(); + res = _cacheManager.Initialize(allocatorForCacheManager, size, cacheSize0, cacheSize1, maxCacheEntries); + if (res.IsFailure()) return res.Miss(); return Result.Success; @@ -321,8 +321,8 @@ public class CompressedStorage : IStorage, IAsynchronousAccessSplitter public override Result Read(long offset, Span destination) { - Result rc = _cacheManager.Read(_core, offset, destination); - if (rc.IsFailure()) return rc.Miss(); + Result res = _cacheManager.Read(_core, offset, destination); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -344,8 +344,8 @@ public class CompressedStorage : IStorage, IAsynchronousAccessSplitter public override Result GetSize(out long size) { - Result rc = _core.GetSize(out size); - if (rc.IsFailure()) return rc.Miss(); + Result res = _core.GetSize(out size); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -361,14 +361,14 @@ public class CompressedStorage : IStorage, IAsynchronousAccessSplitter case OperationId.InvalidateCache: { _cacheManager.Invalidate(); - Result rc = _core.Invalidate(); - if (rc.IsFailure()) return rc.Miss(); + Result res = _core.Invalidate(); + if (res.IsFailure()) return res.Miss(); break; } case OperationId.QueryRange: { - Result rc = _core.QueryRange(outBuffer, offset, size); - if (rc.IsFailure()) return rc.Miss(); + Result res = _core.QueryRange(outBuffer, offset, size); + if (res.IsFailure()) return res.Miss(); break; } default: @@ -381,9 +381,9 @@ public class CompressedStorage : IStorage, IAsynchronousAccessSplitter public Result QueryAppropriateOffset(out long offsetAppropriate, long startOffset, long accessSize, long alignmentSize) { - Result rc = _core.QueryAppropriateOffsetForAsynchronousAccess(out offsetAppropriate, startOffset, accessSize, + Result res = _core.QueryAppropriateOffsetForAsynchronousAccess(out offsetAppropriate, startOffset, accessSize, alignmentSize); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/FsSystem/ConcatenationFileSystem.cs b/src/LibHac/FsSystem/ConcatenationFileSystem.cs index d4a9501f..261eaaf6 100644 --- a/src/LibHac/FsSystem/ConcatenationFileSystem.cs +++ b/src/LibHac/FsSystem/ConcatenationFileSystem.cs @@ -100,8 +100,8 @@ public class ConcatenationFileSystem : IFileSystem long fileOffset = offset; - Result rc = DryRead(out long remaining, offset, destination.Length, in option, _mode); - if (rc.IsFailure()) return rc.Miss(); + Result res = DryRead(out long remaining, offset, destination.Length, in option, _mode); + if (res.IsFailure()) return res.Miss(); int bufferOffset = 0; @@ -115,9 +115,9 @@ public class ConcatenationFileSystem : IFileSystem Assert.SdkAssert(fileIndex < _fileArray.Count); - rc = _fileArray[fileIndex].Read(out long internalFileBytesRead, internalFileOffset, + res = _fileArray[fileIndex].Read(out long internalFileBytesRead, internalFileOffset, destination.Slice(bufferOffset, bytesToRead), in option); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); remaining -= internalFileBytesRead; bufferOffset += (int)internalFileBytesRead; @@ -133,13 +133,13 @@ public class ConcatenationFileSystem : IFileSystem protected override Result DoWrite(long offset, ReadOnlySpan source, in WriteOption option) { - Result rc = DryWrite(out bool needsAppend, offset, source.Length, in option, _mode); - if (rc.IsFailure()) return rc.Miss(); + Result res = DryWrite(out bool needsAppend, offset, source.Length, in option, _mode); + if (res.IsFailure()) return res.Miss(); if (source.Length > 0 && needsAppend) { - rc = SetSize(offset + source.Length); - if (rc.IsFailure()) return rc.Miss(); + res = SetSize(offset + source.Length); + if (res.IsFailure()) return res.Miss(); } int remaining = source.Length; @@ -159,9 +159,9 @@ public class ConcatenationFileSystem : IFileSystem Assert.SdkAssert(fileIndex < _fileArray.Count); - rc = _fileArray[fileIndex].Write(internalFileOffset, source.Slice(bufferOffset, bytesToWrite), + res = _fileArray[fileIndex].Write(internalFileOffset, source.Slice(bufferOffset, bytesToWrite), in internalFileOption); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); remaining -= bytesToWrite; bufferOffset += bytesToWrite; @@ -170,8 +170,8 @@ public class ConcatenationFileSystem : IFileSystem if (option.HasFlushFlag()) { - rc = Flush(); - if (rc.IsFailure()) return rc.Miss(); + res = Flush(); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -186,8 +186,8 @@ public class ConcatenationFileSystem : IFileSystem { Assert.SdkNotNull(_fileArray[index]); - Result rc = _fileArray[index].Flush(); - if (rc.IsFailure()) return rc.Miss(); + Result res = _fileArray[index].Flush(); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -195,11 +195,11 @@ public class ConcatenationFileSystem : IFileSystem protected override Result DoSetSize(long size) { - Result rc = DrySetSize(size, _mode); - if (rc.IsFailure()) return rc.Miss(); + Result res = DrySetSize(size, _mode); + if (res.IsFailure()) return res.Miss(); - rc = GetSize(out long currentSize); - if (rc.IsFailure()) return rc.Miss(); + res = GetSize(out long currentSize); + if (res.IsFailure()) return res.Miss(); if (currentSize == size) return Result.Success; @@ -207,33 +207,33 @@ public class ConcatenationFileSystem : IFileSystem int newTailIndex = GetInternalFileCount(size) - 1; using var internalFilePath = new Path(); - rc = internalFilePath.Initialize(in _path); - if (rc.IsFailure()) return rc.Miss(); + res = internalFilePath.Initialize(in _path); + if (res.IsFailure()) return res.Miss(); if (size > currentSize) { Assert.SdkAssert(_fileArray.Count > currentTailIndex); - rc = _fileArray[currentTailIndex].SetSize(GetInternalFileSize(size, currentTailIndex)); - if (rc.IsFailure()) return rc.Miss(); + res = _fileArray[currentTailIndex].SetSize(GetInternalFileSize(size, currentTailIndex)); + if (res.IsFailure()) return res.Miss(); for (int i = currentTailIndex + 1; i <= newTailIndex; i++) { - rc = AppendInternalFilePath(ref internalFilePath.Ref(), i); - if (rc.IsFailure()) return rc.Miss(); + res = AppendInternalFilePath(ref internalFilePath.Ref(), i); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.CreateFile(in internalFilePath, GetInternalFileSize(size, i), + res = _baseFileSystem.CreateFile(in internalFilePath, GetInternalFileSize(size, i), CreateFileOptions.None); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); using var newInternalFile = new UniqueRef(); - rc = _baseFileSystem.OpenFile(ref newInternalFile.Ref(), in internalFilePath, _mode); - if (rc.IsFailure()) return rc.Miss(); + res = _baseFileSystem.OpenFile(ref newInternalFile.Ref(), in internalFilePath, _mode); + if (res.IsFailure()) return res.Miss(); _fileArray.Add(newInternalFile.Release()); - rc = internalFilePath.RemoveChild(); - if (rc.IsFailure()) return rc.Miss(); + res = internalFilePath.RemoveChild(); + if (res.IsFailure()) return res.Miss(); } } else @@ -243,18 +243,18 @@ public class ConcatenationFileSystem : IFileSystem _fileArray[i].Dispose(); _fileArray.RemoveAt(i); - rc = AppendInternalFilePath(ref internalFilePath.Ref(), i); - if (rc.IsFailure()) return rc.Miss(); + res = AppendInternalFilePath(ref internalFilePath.Ref(), i); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.DeleteFile(in internalFilePath); - if (rc.IsFailure()) return rc.Miss(); + res = _baseFileSystem.DeleteFile(in internalFilePath); + if (res.IsFailure()) return res.Miss(); - rc = internalFilePath.RemoveChild(); - if (rc.IsFailure()) return rc.Miss(); + res = internalFilePath.RemoveChild(); + if (res.IsFailure()) return res.Miss(); } - rc = _fileArray[newTailIndex].SetSize(GetInternalFileSize(size, newTailIndex)); - if (rc.IsFailure()) return rc.Miss(); + res = _fileArray[newTailIndex].SetSize(GetInternalFileSize(size, newTailIndex)); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -268,8 +268,8 @@ public class ConcatenationFileSystem : IFileSystem foreach (IFile file in _fileArray) { - Result rc = file.GetSize(out long internalFileSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = file.GetSize(out long internalFileSize); + if (res.IsFailure()) return res.Miss(); totalSize += internalFileSize; } @@ -290,8 +290,8 @@ public class ConcatenationFileSystem : IFileSystem foreach (IFile file in _fileArray) { - Result rc = file.OperateRange(operationId, 0, long.MaxValue); - if (rc.IsFailure()) return rc.Miss(); + Result res = file.OperateRange(operationId, 0, long.MaxValue); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -306,8 +306,8 @@ public class ConcatenationFileSystem : IFileSystem closure.OperationId = operationId; closure.InfoMerged.Clear(); - Result rc = DoOperateRangeImpl(offset, size, QueryRangeImpl, ref closure); - if (rc.IsFailure()) return rc.Miss(); + Result res = DoOperateRangeImpl(offset, size, QueryRangeImpl, ref closure); + if (res.IsFailure()) return res.Miss(); SpanHelpers.AsByteSpan(ref closure.InfoMerged).CopyTo(outBuffer); return Result.Success; @@ -320,9 +320,9 @@ public class ConcatenationFileSystem : IFileSystem { Unsafe.SkipInit(out QueryRangeInfo infoEntry); - Result rc = file.OperateRange(SpanHelpers.AsByteSpan(ref infoEntry), closure.OperationId, offset, size, + Result res = file.OperateRange(SpanHelpers.AsByteSpan(ref infoEntry), closure.OperationId, offset, size, closure.InBuffer); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); closure.InfoMerged.Merge(in infoEntry); return Result.Success; @@ -335,8 +335,8 @@ public class ConcatenationFileSystem : IFileSystem if (offset < 0) return ResultFs.OutOfRange.Log(); - Result rc = GetSize(out long currentSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetSize(out long currentSize); + if (res.IsFailure()) return res.Miss(); if (offset > currentSize) return ResultFs.OutOfRange.Log(); @@ -355,8 +355,8 @@ public class ConcatenationFileSystem : IFileSystem Assert.SdkAssert(fileIndex < _fileArray.Count); - rc = func(_fileArray[fileIndex], internalFileOffset, sizeToOperate, ref closure); - if (rc.IsFailure()) return rc.Miss(); + res = func(_fileArray[fileIndex], internalFileOffset, sizeToOperate, ref closure); + if (res.IsFailure()) return res.Miss(); remaining -= sizeToOperate; currentOffset += sizeToOperate; @@ -415,8 +415,8 @@ public class ConcatenationFileSystem : IFileSystem while (readCountTotal < entryBuffer.Length) { - Result rc = _baseDirectory.Get.Read(out long readCount, SpanHelpers.AsSpan(ref entry)); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseDirectory.Get.Read(out long readCount, SpanHelpers.AsSpan(ref entry)); + if (res.IsFailure()) return res.Miss(); if (readCount == 0) break; @@ -431,14 +431,14 @@ public class ConcatenationFileSystem : IFileSystem if (!_mode.HasFlag(OpenDirectoryMode.NoFileSize)) { using var internalFilePath = new Path(); - rc = internalFilePath.Initialize(in _path); - if (rc.IsFailure()) return rc.Miss(); + res = internalFilePath.Initialize(in _path); + if (res.IsFailure()) return res.Miss(); - rc = internalFilePath.AppendChild(entry.Name); - if (rc.IsFailure()) return rc.Miss(); + res = internalFilePath.AppendChild(entry.Name); + if (res.IsFailure()) return res.Miss(); - rc = _concatenationFileSystem.GetFileSize(out entry.Size, in internalFilePath); - if (rc.IsFailure()) return rc.Miss(); + res = _concatenationFileSystem.GetFileSize(out entry.Size, in internalFilePath); + if (res.IsFailure()) return res.Miss(); } } @@ -459,16 +459,16 @@ public class ConcatenationFileSystem : IFileSystem using Path path = _path.DangerousGetPath(); - Result rc = _baseFileSystem.OpenDirectory(ref directory.Ref(), in path, + Result res = _baseFileSystem.OpenDirectory(ref directory.Ref(), in path, OpenDirectoryMode.All | OpenDirectoryMode.NoFileSize); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); long entryCountTotal = 0; while (true) { directory.Get.Read(out long readCount, SpanHelpers.AsSpan(ref entry)); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); if (readCount == 0) break; @@ -543,8 +543,8 @@ public class ConcatenationFileSystem : IFileSystem private static Result GenerateInternalFilePath(ref Path outPath, int index, in Path basePath) { - Result rc = outPath.Initialize(in basePath); - if (rc.IsFailure()) return rc.Miss(); + Result res = outPath.Initialize(in basePath); + if (res.IsFailure()) return res.Miss(); return AppendInternalFilePath(ref outPath, index).Ret(); } @@ -554,8 +554,8 @@ public class ConcatenationFileSystem : IFileSystem if (path == RootPath) return ResultFs.PathNotFound.Log(); - Result rc = outParentPath.Initialize(in path); - if (rc.IsFailure()) return rc.Miss(); + Result res = outParentPath.Initialize(in path); + if (res.IsFailure()) return res.Miss(); return outParentPath.RemoveChild().Ret(); } @@ -567,8 +567,8 @@ public class ConcatenationFileSystem : IFileSystem private bool IsConcatenationFile(in Path path) { - Result rc = _baseFileSystem.Get.GetFileAttributes(out NxFileAttributes attribute, in path); - if (rc.IsFailure()) + Result res = _baseFileSystem.Get.GetFileAttributes(out NxFileAttributes attribute, in path); + if (res.IsFailure()) return false; return IsConcatenationFileAttribute(attribute); @@ -579,33 +579,33 @@ public class ConcatenationFileSystem : IFileSystem UnsafeHelpers.SkipParamInit(out count); using var internalFilePath = new Path(); - Result rc = internalFilePath.Initialize(in path); - if (rc.IsFailure()) return rc.Miss(); + Result res = internalFilePath.Initialize(in path); + if (res.IsFailure()) return res.Miss(); for (int i = 0; ; i++) { - rc = AppendInternalFilePath(ref internalFilePath.Ref(), i); - if (rc.IsFailure()) return rc.Miss(); + res = AppendInternalFilePath(ref internalFilePath.Ref(), i); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.Get.GetEntryType(out _, in internalFilePath); - if (rc.IsFailure()) + res = _baseFileSystem.Get.GetEntryType(out _, in internalFilePath); + if (res.IsFailure()) { // We've passed the last internal file of the concatenation file // once the next internal file doesn't exist. - if (ResultFs.PathNotFound.Includes(rc)) + if (ResultFs.PathNotFound.Includes(res)) { - rc.Catch(); + res.Catch(); count = i; - rc.Handle(); + res.Handle(); return Result.Success; } - return rc.Miss(); + return res.Miss(); } - rc = internalFilePath.RemoveChild(); - if (rc.IsFailure()) return rc.Miss(); + res = internalFilePath.RemoveChild(); + if (res.IsFailure()) return res.Miss(); } } @@ -659,8 +659,8 @@ public class ConcatenationFileSystem : IFileSystem return _baseFileSystem.Get.OpenFile(ref outFile, in path, mode).Ret(); } - Result rc = GetInternalFileCount(out int fileCount, in path); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetInternalFileCount(out int fileCount, in path); + if (res.IsFailure()) return res.Miss(); if (fileCount <= 0) return ResultFs.ConcatenationFsInvalidInternalFileCount.Log(); @@ -669,30 +669,30 @@ public class ConcatenationFileSystem : IFileSystem using var filePath = new Path(); filePath.Initialize(in path); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); try { for (int i = 0; i < fileCount; i++) { - rc = AppendInternalFilePath(ref filePath.Ref(), i); - if (rc.IsFailure()) return rc.Miss(); + res = AppendInternalFilePath(ref filePath.Ref(), i); + if (res.IsFailure()) return res.Miss(); using var internalFile = new UniqueRef(); - rc = _baseFileSystem.Get.OpenFile(ref internalFile.Ref(), in filePath, mode); - if (rc.IsFailure()) return rc.Miss(); + res = _baseFileSystem.Get.OpenFile(ref internalFile.Ref(), in filePath, mode); + if (res.IsFailure()) return res.Miss(); internalFiles.Add(internalFile.Release()); - rc = filePath.RemoveChild(); - if (rc.IsFailure()) return rc.Miss(); + res = filePath.RemoveChild(); + if (res.IsFailure()) return res.Miss(); } using var concatFile = new UniqueRef( new ConcatenationFile(mode, ref internalFiles, _internalFileSize, _baseFileSystem.Get)); - rc = concatFile.Get.Initialize(in path); - if (rc.IsFailure()) return rc.Miss(); + res = concatFile.Get.Initialize(in path); + if (res.IsFailure()) return res.Miss(); outFile.Set(ref concatFile.Ref()); return Result.Success; @@ -720,13 +720,13 @@ public class ConcatenationFileSystem : IFileSystem } using var baseDirectory = new UniqueRef(); - Result rc = _baseFileSystem.Get.OpenDirectory(ref baseDirectory.Ref(), path, OpenDirectoryMode.All); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseFileSystem.Get.OpenDirectory(ref baseDirectory.Ref(), path, OpenDirectoryMode.All); + if (res.IsFailure()) return res.Miss(); using var concatDirectory = new UniqueRef( new ConcatenationDirectory(mode, ref baseDirectory.Ref(), this, _baseFileSystem.Get)); - rc = concatDirectory.Get.Initialize(in path); - if (rc.IsFailure()) return rc.Miss(); + res = concatDirectory.Get.Initialize(in path); + if (res.IsFailure()) return res.Miss(); outDirectory.Set(ref concatDirectory.Ref()); return Result.Success; @@ -745,8 +745,8 @@ public class ConcatenationFileSystem : IFileSystem } using var parentPath = new Path(); - Result rc = GenerateParentPath(ref parentPath.Ref(), in path); - if (rc.IsFailure()) return rc.Miss(); + Result res = GenerateParentPath(ref parentPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); if (IsConcatenationFile(in parentPath)) { @@ -754,18 +754,18 @@ public class ConcatenationFileSystem : IFileSystem return ResultFs.PathNotFound.Log(); } - rc = _baseFileSystem.Get.CreateDirectory(in path, NxFileAttributes.Archive); - if (rc.IsFailure()) return rc.Miss(); + res = _baseFileSystem.Get.CreateDirectory(in path, NxFileAttributes.Archive); + if (res.IsFailure()) return res.Miss(); // Handle the empty file case by manually creating a single empty internal file if (size == 0) { using var emptyFilePath = new Path(); - rc = GenerateInternalFilePath(ref emptyFilePath.Ref(), 0, in path); - if (rc.IsFailure()) return rc.Miss(); + res = GenerateInternalFilePath(ref emptyFilePath.Ref(), 0, in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.Get.CreateFile(in emptyFilePath, 0, newOption); - if (rc.IsFailure()) return rc.Miss(); + res = _baseFileSystem.Get.CreateFile(in emptyFilePath, 0, newOption); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -773,12 +773,12 @@ public class ConcatenationFileSystem : IFileSystem long remaining = size; using var filePath = new Path(); filePath.Initialize(in path); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); for (int i = 0; remaining > 0; i++) { - rc = AppendInternalFilePath(ref filePath.Ref(), i); - if (rc.IsFailure()) return rc.Miss(); + res = AppendInternalFilePath(ref filePath.Ref(), i); + if (res.IsFailure()) return res.Miss(); long fileSize = Math.Min(remaining, _internalFileSize); Result createInternalFileResult = _baseFileSystem.Get.CreateFile(in filePath, fileSize, newOption); @@ -792,11 +792,11 @@ public class ConcatenationFileSystem : IFileSystem for (int index = i - 1; index >= 0; index--) { - rc = GenerateInternalFilePath(ref filePath.Ref(), index, in path); - if (rc.IsFailure()) + res = GenerateInternalFilePath(ref filePath.Ref(), index, in path); + if (res.IsFailure()) { createInternalFileResult.Handle(); - return rc.Miss(); + return res.Miss(); } if (_baseFileSystem.Get.DeleteFile(in filePath).IsFailure()) @@ -807,8 +807,8 @@ public class ConcatenationFileSystem : IFileSystem return createInternalFileResult.Rethrow(); } - rc = filePath.RemoveChild(); - if (rc.IsFailure()) return rc.Miss(); + res = filePath.RemoveChild(); + if (res.IsFailure()) return res.Miss(); remaining -= fileSize; } @@ -825,27 +825,27 @@ public class ConcatenationFileSystem : IFileSystem return _baseFileSystem.Get.DeleteFile(in path).Ret(); } - Result rc = GetInternalFileCount(out int count, path); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetInternalFileCount(out int count, path); + if (res.IsFailure()) return res.Miss(); using var filePath = new Path(); - rc = filePath.Initialize(in path); - if (rc.IsFailure()) return rc.Miss(); + res = filePath.Initialize(in path); + if (res.IsFailure()) return res.Miss(); for (int i = count - 1; i >= 0; i--) { - rc = AppendInternalFilePath(ref filePath.Ref(), i); - if (rc.IsFailure()) return rc.Miss(); + res = AppendInternalFilePath(ref filePath.Ref(), i); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.Get.DeleteFile(in filePath); - if (rc.IsFailure()) return rc.Miss(); + res = _baseFileSystem.Get.DeleteFile(in filePath); + if (res.IsFailure()) return res.Miss(); - rc = filePath.RemoveChild(); - if (rc.IsFailure()) return rc.Miss(); + res = filePath.RemoveChild(); + if (res.IsFailure()) return res.Miss(); } - rc = _baseFileSystem.Get.DeleteDirectoryRecursively(in path); - if (rc.IsFailure()) return rc.Miss(); + res = _baseFileSystem.Get.DeleteDirectoryRecursively(in path); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -856,8 +856,8 @@ public class ConcatenationFileSystem : IFileSystem // Check if the parent path is a concatenation file because we can't create a directory inside one. using var parentPath = new Path(); - Result rc = GenerateParentPath(ref parentPath.Ref(), in path); - if (rc.IsFailure()) return rc.Miss(); + Result res = GenerateParentPath(ref parentPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); if (IsConcatenationFile(in parentPath)) return ResultFs.PathNotFound.Log(); @@ -906,8 +906,8 @@ public class ConcatenationFileSystem : IFileSystem if (isConcatenationFile) return ResultFs.PathNotFound.Log(); - Result rc = CleanDirectoryRecursivelyImpl(in path); - if (rc.IsFailure()) return rc.Miss(); + Result res = CleanDirectoryRecursivelyImpl(in path); + if (res.IsFailure()) return res.Miss(); return _baseFileSystem.Get.DeleteDirectory(in path).Ret(); } @@ -953,35 +953,35 @@ public class ConcatenationFileSystem : IFileSystem using var scopedLock = new ScopedLock(ref _mutex); using var internalFilePath = new Path(); - Result rc = internalFilePath.Initialize(in path); - if (rc.IsFailure()) return rc.Miss(); + Result res = internalFilePath.Initialize(in path); + if (res.IsFailure()) return res.Miss(); long sizeTotal = 0; for (int i = 0; ; i++) { - rc = AppendInternalFilePath(ref internalFilePath.Ref(), i); - if (rc.IsFailure()) return rc.Miss(); + res = AppendInternalFilePath(ref internalFilePath.Ref(), i); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.Get.GetFileSize(out long internalFileSize, in internalFilePath); - if (rc.IsFailure()) + res = _baseFileSystem.Get.GetFileSize(out long internalFileSize, in internalFilePath); + if (res.IsFailure()) { // We've passed the last internal file of the concatenation file // once the next internal file doesn't exist. - if (ResultFs.PathNotFound.Includes(rc)) + if (ResultFs.PathNotFound.Includes(res)) { - rc.Catch(); + res.Catch(); size = sizeTotal; - rc.Handle(); + res.Handle(); return Result.Success; } - return rc.Miss(); + return res.Miss(); } - rc = internalFilePath.RemoveChild(); - if (rc.IsFailure()) return rc.Miss(); + res = internalFilePath.RemoveChild(); + if (res.IsFailure()) return res.Miss(); sizeTotal += internalFileSize; } diff --git a/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs b/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs index b5afe6b9..91eda922 100644 --- a/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs +++ b/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs @@ -191,16 +191,16 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem while (true) { - Result rc = function(in closure); + Result res = function(in closure); - if (rc.IsSuccess()) - return rc; + if (res.IsSuccess()) + return res; - if (!ResultFs.TargetLocked.Includes(rc)) - return rc; + if (!ResultFs.TargetLocked.Includes(res)) + return res; if (remainingRetries <= 0) - return rc; + return res; remainingRetries--; @@ -225,75 +225,75 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem _randomGenerator = randomGenerator; // Open the lock file - Result rc = AcquireLockFile(); - if (rc.IsFailure()) return rc; + Result res = AcquireLockFile(); + if (res.IsFailure()) return res.Miss(); using var pathModifiedDirectory = new Path(); - rc = PathFunctions.SetUpFixedPath(ref pathModifiedDirectory.Ref(), ModifiedDirectoryName); - if (rc.IsFailure()) return rc; + res = PathFunctions.SetUpFixedPath(ref pathModifiedDirectory.Ref(), ModifiedDirectoryName); + if (res.IsFailure()) return res.Miss(); using var pathCommittedDirectory = new Path(); - rc = PathFunctions.SetUpFixedPath(ref pathCommittedDirectory.Ref(), CommittedDirectoryName); - if (rc.IsFailure()) return rc; + res = PathFunctions.SetUpFixedPath(ref pathCommittedDirectory.Ref(), CommittedDirectoryName); + if (res.IsFailure()) return res.Miss(); using var pathSynchronizingDirectory = new Path(); - rc = PathFunctions.SetUpFixedPath(ref pathSynchronizingDirectory.Ref(), SynchronizingDirectoryName); - if (rc.IsFailure()) return rc; + res = PathFunctions.SetUpFixedPath(ref pathSynchronizingDirectory.Ref(), SynchronizingDirectoryName); + if (res.IsFailure()) return res.Miss(); // Ensure the working directory exists - rc = _baseFs.GetEntryType(out _, in pathModifiedDirectory); + res = _baseFs.GetEntryType(out _, in pathModifiedDirectory); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (!ResultFs.PathNotFound.Includes(rc)) - return rc; + if (!ResultFs.PathNotFound.Includes(res)) + return res; - rc = _baseFs.CreateDirectory(in pathModifiedDirectory); - if (rc.IsFailure()) return rc; + res = _baseFs.CreateDirectory(in pathModifiedDirectory); + if (res.IsFailure()) return res.Miss(); if (_isJournalingSupported) { - rc = _baseFs.CreateDirectory(in pathCommittedDirectory); + res = _baseFs.CreateDirectory(in pathCommittedDirectory); // Changed: Nintendo returns on all failures, but we'll keep going if committed already // exists to avoid confusing people manually creating savedata in emulators - if (rc.IsFailure() && !ResultFs.PathAlreadyExists.Includes(rc)) - return rc; + if (res.IsFailure() && !ResultFs.PathAlreadyExists.Includes(res)) + return res; } } // Only the working directory is needed for non-journaling savedata if (_isJournalingSupported) { - rc = _baseFs.GetEntryType(out _, in pathCommittedDirectory); + res = _baseFs.GetEntryType(out _, in pathCommittedDirectory); - if (rc.IsSuccess()) + if (res.IsSuccess()) { // The previous commit successfully completed. Copy the committed dir to the working dir. if (_isJournalingEnabled) { - rc = SynchronizeDirectory(in pathModifiedDirectory, in pathCommittedDirectory); - if (rc.IsFailure()) return rc; + res = SynchronizeDirectory(in pathModifiedDirectory, in pathCommittedDirectory); + if (res.IsFailure()) return res.Miss(); } } - else if (ResultFs.PathNotFound.Includes(rc)) + else if (ResultFs.PathNotFound.Includes(res)) { // If a previous commit failed, the committed dir may be missing. // Finish that commit by copying the working dir to the committed dir - rc = SynchronizeDirectory(in pathSynchronizingDirectory, in pathModifiedDirectory); - if (rc.IsFailure()) return rc; + res = SynchronizeDirectory(in pathSynchronizingDirectory, in pathModifiedDirectory); + if (res.IsFailure()) return res.Miss(); - rc = _baseFs.RenameDirectory(in pathSynchronizingDirectory, in pathCommittedDirectory); - if (rc.IsFailure()) return rc; + res = _baseFs.RenameDirectory(in pathSynchronizingDirectory, in pathCommittedDirectory); + if (res.IsFailure()) return res.Miss(); } else { - return rc; + return res; } } - rc = InitializeExtraData(); - if (rc.IsFailure()) return rc; + res = InitializeExtraData(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -305,25 +305,25 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem return Result.Success; using var pathLockFile = new Path(); - Result rc = PathFunctions.SetUpFixedPath(ref pathLockFile.Ref(), LockFileName); - if (rc.IsFailure()) return rc; + Result res = PathFunctions.SetUpFixedPath(ref pathLockFile.Ref(), LockFileName); + if (res.IsFailure()) return res.Miss(); using var lockFile = new UniqueRef(); - rc = _baseFs.OpenFile(ref lockFile.Ref(), in pathLockFile, OpenMode.ReadWrite); + res = _baseFs.OpenFile(ref lockFile.Ref(), in pathLockFile, OpenMode.ReadWrite); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (ResultFs.PathNotFound.Includes(rc)) + if (ResultFs.PathNotFound.Includes(res)) { - rc = _baseFs.CreateFile(in pathLockFile, 0); - if (rc.IsFailure()) return rc; + res = _baseFs.CreateFile(in pathLockFile, 0); + if (res.IsFailure()) return res.Miss(); - rc = _baseFs.OpenFile(ref lockFile.Ref(), in pathLockFile, OpenMode.ReadWrite); - if (rc.IsFailure()) return rc; + res = _baseFs.OpenFile(ref lockFile.Ref(), in pathLockFile, OpenMode.ReadWrite); + if (res.IsFailure()) return res.Miss(); } else { - return rc.Miss(); + return res.Miss(); } } @@ -340,11 +340,11 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem ? CommittedDirectoryName : ModifiedDirectoryName; - Result rc = PathFunctions.SetUpFixedPath(ref pathDirectoryName.Ref(), directoryName); - if (rc.IsFailure()) return rc; + Result res = PathFunctions.SetUpFixedPath(ref pathDirectoryName.Ref(), directoryName); + if (res.IsFailure()) return res.Miss(); - rc = outFullPath.Combine(in pathDirectoryName, in path); - if (rc.IsFailure()) return rc; + res = outFullPath.Combine(in pathDirectoryName, in path); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -352,13 +352,13 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { using var fullPath = new Path(); - Result rc = ResolvePath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolvePath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - rc = _baseFs.CreateFile(in fullPath, size, option); - if (rc.IsFailure()) return rc; + res = _baseFs.CreateFile(in fullPath, size, option); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -366,13 +366,13 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem protected override Result DoDeleteFile(in Path path) { using var fullPath = new Path(); - Result rc = ResolvePath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolvePath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - rc = _baseFs.DeleteFile(in fullPath); - if (rc.IsFailure()) return rc; + res = _baseFs.DeleteFile(in fullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -380,13 +380,13 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem protected override Result DoCreateDirectory(in Path path) { using var fullPath = new Path(); - Result rc = ResolvePath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolvePath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - rc = _baseFs.CreateDirectory(in fullPath); - if (rc.IsFailure()) return rc; + res = _baseFs.CreateDirectory(in fullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -394,13 +394,13 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem protected override Result DoDeleteDirectory(in Path path) { using var fullPath = new Path(); - Result rc = ResolvePath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolvePath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - rc = _baseFs.DeleteDirectory(in fullPath); - if (rc.IsFailure()) return rc; + res = _baseFs.DeleteDirectory(in fullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -408,13 +408,13 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem protected override Result DoDeleteDirectoryRecursively(in Path path) { using var fullPath = new Path(); - Result rc = ResolvePath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolvePath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - rc = _baseFs.DeleteDirectoryRecursively(in fullPath); - if (rc.IsFailure()) return rc; + res = _baseFs.DeleteDirectoryRecursively(in fullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -422,13 +422,13 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem protected override Result DoCleanDirectoryRecursively(in Path path) { using var fullPath = new Path(); - Result rc = ResolvePath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolvePath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - rc = _baseFs.CleanDirectoryRecursively(in fullPath); - if (rc.IsFailure()) return rc; + res = _baseFs.CleanDirectoryRecursively(in fullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -438,16 +438,16 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem using var currentFullPath = new Path(); using var newFullPath = new Path(); - Result rc = ResolvePath(ref currentFullPath.Ref(), in currentPath); - if (rc.IsFailure()) return rc; + Result res = ResolvePath(ref currentFullPath.Ref(), in currentPath); + if (res.IsFailure()) return res.Miss(); - rc = ResolvePath(ref newFullPath.Ref(), in newPath); - if (rc.IsFailure()) return rc; + res = ResolvePath(ref newFullPath.Ref(), in newPath); + if (res.IsFailure()) return res.Miss(); using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - rc = _baseFs.RenameFile(in currentFullPath, in newFullPath); - if (rc.IsFailure()) return rc; + res = _baseFs.RenameFile(in currentFullPath, in newFullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -457,16 +457,16 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem using var currentFullPath = new Path(); using var newFullPath = new Path(); - Result rc = ResolvePath(ref currentFullPath.Ref(), in currentPath); - if (rc.IsFailure()) return rc; + Result res = ResolvePath(ref currentFullPath.Ref(), in currentPath); + if (res.IsFailure()) return res.Miss(); - rc = ResolvePath(ref newFullPath.Ref(), in newPath); - if (rc.IsFailure()) return rc; + res = ResolvePath(ref newFullPath.Ref(), in newPath); + if (res.IsFailure()) return res.Miss(); using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - rc = _baseFs.RenameDirectory(in currentFullPath, in newFullPath); - if (rc.IsFailure()) return rc; + res = _baseFs.RenameDirectory(in currentFullPath, in newFullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -476,13 +476,13 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem UnsafeHelpers.SkipParamInit(out entryType); using var fullPath = new Path(); - Result rc = ResolvePath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolvePath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - rc = _baseFs.GetEntryType(out entryType, in fullPath); - if (rc.IsFailure()) return rc; + res = _baseFs.GetEntryType(out entryType, in fullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -490,14 +490,14 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) { using var fullPath = new Path(); - Result rc = ResolvePath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolvePath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); using var baseFile = new UniqueRef(); - rc = _baseFs.OpenFile(ref baseFile.Ref(), in fullPath, mode); - if (rc.IsFailure()) return rc; + res = _baseFs.OpenFile(ref baseFile.Ref(), in fullPath, mode); + if (res.IsFailure()) return res.Miss(); using var file = new UniqueRef(new DirectorySaveDataFile(ref baseFile.Ref(), this, mode)); @@ -514,13 +514,13 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem OpenDirectoryMode mode) { using var fullPath = new Path(); - Result rc = ResolvePath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolvePath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); - rc = _baseFs.OpenDirectory(ref outDirectory, in fullPath, mode); - if (rc.IsFailure()) return rc; + res = _baseFs.OpenDirectory(ref outDirectory, in fullPath, mode); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -534,16 +534,16 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem private Result SynchronizeDirectory(in Path destPath, in Path sourcePath) { // Delete destination dir and recreate it. - Result rc = _baseFs.DeleteDirectoryRecursively(destPath); + Result res = _baseFs.DeleteDirectoryRecursively(destPath); // Changed: Nintendo returns all errors unconditionally because SynchronizeDirectory is always called // in situations where a PathNotFound error would mean the save directory was in an invalid state. // We'll ignore PathNotFound errors to be more user-friendly to users who might accidentally // put the save directory in an invalid state. - if (rc.IsFailure() && !ResultFs.PathNotFound.Includes(rc)) return rc; + if (res.IsFailure() && !ResultFs.PathNotFound.Includes(res)) return res; - rc = _baseFs.CreateDirectory(destPath); - if (rc.IsFailure()) return rc; + res = _baseFs.CreateDirectory(destPath); + if (res.IsFailure()) return res.Miss(); var directoryEntry = new DirectoryEntry(); @@ -578,23 +578,23 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem using var closure = new RetryClosure(this); - Result rc = PathFunctions.SetUpFixedPath(ref closure.ModifiedPath.Ref(), ModifiedDirectoryName); - if (rc.IsFailure()) return rc; + Result res = PathFunctions.SetUpFixedPath(ref closure.ModifiedPath.Ref(), ModifiedDirectoryName); + if (res.IsFailure()) return res.Miss(); - rc = PathFunctions.SetUpFixedPath(ref closure.CommittedPath.Ref(), CommittedDirectoryName); - if (rc.IsFailure()) return rc; + res = PathFunctions.SetUpFixedPath(ref closure.CommittedPath.Ref(), CommittedDirectoryName); + if (res.IsFailure()) return res.Miss(); - rc = PathFunctions.SetUpFixedPath(ref closure.SynchronizingPath.Ref(), SynchronizingDirectoryName); - if (rc.IsFailure()) return rc; + res = PathFunctions.SetUpFixedPath(ref closure.SynchronizingPath.Ref(), SynchronizingDirectoryName); + if (res.IsFailure()) return res.Miss(); // All files must be closed before commiting save data. if (_openWritableFileCount > 0) return ResultFs.WriteModeFileNotClosed.Log(); // Get rid of the previous commit by renaming the folder. - rc = RetryFinitelyForTargetLocked(in closure, + res = RetryFinitelyForTargetLocked(in closure, (in RetryClosure c) => c.This._baseFs.RenameDirectory(in c.CommittedPath, in c.SynchronizingPath)); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); // If something goes wrong beyond this point, the commit of the main data // will be completed the next time the savedata is opened. @@ -603,28 +603,28 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem { Assert.SdkNotNull(_randomGenerator); - rc = UpdateExtraDataTimeStamp(); - if (rc.IsFailure()) return rc.Miss(); + res = UpdateExtraDataTimeStamp(); + if (res.IsFailure()) return res.Miss(); } - rc = CommitExtraDataImpl(); - if (rc.IsFailure()) return rc.Miss(); + res = CommitExtraDataImpl(); + if (res.IsFailure()) return res.Miss(); - rc = RetryFinitelyForTargetLocked(in closure, + res = RetryFinitelyForTargetLocked(in closure, (in RetryClosure c) => c.This.SynchronizeDirectory(in c.SynchronizingPath, in c.ModifiedPath)); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = RetryFinitelyForTargetLocked(in closure, + res = RetryFinitelyForTargetLocked(in closure, (in RetryClosure c) => c.This._baseFs.RenameDirectory(in c.SynchronizingPath, in c.CommittedPath)); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return Result.Success; } protected override Result DoCommit() { - Result rc = DoCommit(updateTimeStamp: true); - if (rc.IsFailure()) return rc.Miss(); + Result res = DoCommit(updateTimeStamp: true); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -642,9 +642,9 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem // No old data is kept for non-journaling save data, so there's nothing to rollback to in that case if (_isJournalingSupported) { - Result rc = Initialize(_isJournalingSupported, _isMultiCommitSupported, _isJournalingEnabled, + Result res = Initialize(_isJournalingSupported, _isMultiCommitSupported, _isJournalingEnabled, _timeStampGetter, _randomGenerator); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -657,11 +657,11 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); using var pathModifiedDirectory = new Path(); - Result rc = PathFunctions.SetUpFixedPath(ref pathModifiedDirectory.Ref(), ModifiedDirectoryName); - if (rc.IsFailure()) return rc; + Result res = PathFunctions.SetUpFixedPath(ref pathModifiedDirectory.Ref(), ModifiedDirectoryName); + if (res.IsFailure()) return res.Miss(); - rc = _baseFs.GetFreeSpaceSize(out freeSpace, in pathModifiedDirectory); - if (rc.IsFailure()) return rc; + res = _baseFs.GetFreeSpaceSize(out freeSpace, in pathModifiedDirectory); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -673,11 +673,11 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem using ScopedLock scopedLock = ScopedLock.Lock(ref _mutex); using var pathModifiedDirectory = new Path(); - Result rc = PathFunctions.SetUpFixedPath(ref pathModifiedDirectory.Ref(), ModifiedDirectoryName); - if (rc.IsFailure()) return rc; + Result res = PathFunctions.SetUpFixedPath(ref pathModifiedDirectory.Ref(), ModifiedDirectoryName); + if (res.IsFailure()) return res.Miss(); - rc = _baseFs.GetTotalSpaceSize(out totalSpace, in pathModifiedDirectory); - if (rc.IsFailure()) return rc; + res = _baseFs.GetTotalSpaceSize(out totalSpace, in pathModifiedDirectory); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -701,8 +701,8 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem public override Result CommitExtraData(bool updateTimeStamp) { - Result rc = DoCommit(updateTimeStamp); - if (rc.IsFailure()) return rc.Miss(); + Result res = DoCommit(updateTimeStamp); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -777,54 +777,54 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem private Result InitializeExtraData() { using var pathModifiedExtraData = new Path(); - Result rc = PathFunctions.SetUpFixedPath(ref pathModifiedExtraData.Ref(), ModifiedExtraDataName); - if (rc.IsFailure()) return rc; + Result res = PathFunctions.SetUpFixedPath(ref pathModifiedExtraData.Ref(), ModifiedExtraDataName); + if (res.IsFailure()) return res.Miss(); using var pathCommittedExtraData = new Path(); - rc = PathFunctions.SetUpFixedPath(ref pathCommittedExtraData.Ref(), CommittedExtraDataName); - if (rc.IsFailure()) return rc; + res = PathFunctions.SetUpFixedPath(ref pathCommittedExtraData.Ref(), CommittedExtraDataName); + if (res.IsFailure()) return res.Miss(); using var pathSynchronizingExtraData = new Path(); - rc = PathFunctions.SetUpFixedPath(ref pathSynchronizingExtraData.Ref(), SynchronizingExtraDataName); - if (rc.IsFailure()) return rc; + res = PathFunctions.SetUpFixedPath(ref pathSynchronizingExtraData.Ref(), SynchronizingExtraDataName); + if (res.IsFailure()) return res.Miss(); // Ensure the extra data files exist. // We don't currently handle the case where some of the extra data paths are directories instead of files. - rc = _baseFs.GetEntryType(out _, in pathModifiedExtraData); + res = _baseFs.GetEntryType(out _, in pathModifiedExtraData); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (!ResultFs.PathNotFound.Includes(rc)) - return rc; + if (!ResultFs.PathNotFound.Includes(res)) + return res; // The Modified file doesn't exist. Create it. - rc = _baseFs.CreateFile(in pathModifiedExtraData, Unsafe.SizeOf()); - if (rc.IsFailure()) return rc; + res = _baseFs.CreateFile(in pathModifiedExtraData, Unsafe.SizeOf()); + if (res.IsFailure()) return res.Miss(); if (_isJournalingSupported) { - rc = _baseFs.GetEntryType(out _, in pathCommittedExtraData); + res = _baseFs.GetEntryType(out _, in pathCommittedExtraData); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (!ResultFs.PathNotFound.Includes(rc)) - return rc; + if (!ResultFs.PathNotFound.Includes(res)) + return res; // Neither the modified or committed files existed. // Check if the synchronizing file exists and use it if it does. - rc = _baseFs.GetEntryType(out _, in pathSynchronizingExtraData); + res = _baseFs.GetEntryType(out _, in pathSynchronizingExtraData); - if (rc.IsSuccess()) + if (res.IsSuccess()) { - rc = _baseFs.RenameFile(in pathSynchronizingExtraData, in pathCommittedExtraData); - if (rc.IsFailure()) return rc; + res = _baseFs.RenameFile(in pathSynchronizingExtraData, in pathCommittedExtraData); + if (res.IsFailure()) return res.Miss(); } else { // The synchronizing file did not exist. Create an empty committed extra data file. - rc = _baseFs.CreateFile(in pathCommittedExtraData, Unsafe.SizeOf()); - if (rc.IsFailure() && !ResultFs.PathAlreadyExists.Includes(rc)) - return rc; + res = _baseFs.CreateFile(in pathCommittedExtraData, Unsafe.SizeOf()); + if (res.IsFailure() && !ResultFs.PathAlreadyExists.Includes(res)) + return res; } } } @@ -832,27 +832,27 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem else { // If the working file exists make sure it's the right size - rc = EnsureExtraDataSize(in pathModifiedExtraData); - if (rc.IsFailure()) return rc; + res = EnsureExtraDataSize(in pathModifiedExtraData); + if (res.IsFailure()) return res.Miss(); } // Only the working extra data is needed for non-journaling savedata if (_isJournalingSupported) { - rc = _baseFs.GetEntryType(out _, in pathCommittedExtraData); + res = _baseFs.GetEntryType(out _, in pathCommittedExtraData); - if (rc.IsSuccess()) + if (res.IsSuccess()) { - rc = EnsureExtraDataSize(in pathCommittedExtraData); - if (rc.IsFailure()) return rc; + res = EnsureExtraDataSize(in pathCommittedExtraData); + if (res.IsFailure()) return res.Miss(); if (_isJournalingEnabled) { - rc = SynchronizeExtraData(in pathModifiedExtraData, in pathCommittedExtraData); - if (rc.IsFailure()) return rc; + res = SynchronizeExtraData(in pathModifiedExtraData, in pathCommittedExtraData); + if (res.IsFailure()) return res.Miss(); } } - else if (ResultFs.PathNotFound.Includes(rc)) + else if (ResultFs.PathNotFound.Includes(res)) { // The committed file doesn't exist. Try to recover from whatever invalid state we're in. @@ -860,29 +860,29 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem // Finish that commit by copying the working extra data to the committed extra data if (_baseFs.GetEntryType(out _, in pathSynchronizingExtraData).IsSuccess()) { - rc = SynchronizeExtraData(in pathSynchronizingExtraData, in pathModifiedExtraData); - if (rc.IsFailure()) return rc; + res = SynchronizeExtraData(in pathSynchronizingExtraData, in pathModifiedExtraData); + if (res.IsFailure()) return res.Miss(); - rc = _baseFs.RenameFile(in pathSynchronizingExtraData, in pathCommittedExtraData); - if (rc.IsFailure()) return rc; + res = _baseFs.RenameFile(in pathSynchronizingExtraData, in pathCommittedExtraData); + if (res.IsFailure()) return res.Miss(); } else { // The only existing file is the modified file. // Copy the working extra data to the committed extra data. - rc = _baseFs.CreateFile(in pathSynchronizingExtraData, Unsafe.SizeOf()); - if (rc.IsFailure()) return rc; + res = _baseFs.CreateFile(in pathSynchronizingExtraData, Unsafe.SizeOf()); + if (res.IsFailure()) return res.Miss(); - rc = SynchronizeExtraData(in pathSynchronizingExtraData, in pathModifiedExtraData); - if (rc.IsFailure()) return rc; + res = SynchronizeExtraData(in pathSynchronizingExtraData, in pathModifiedExtraData); + if (res.IsFailure()) return res.Miss(); - rc = _baseFs.RenameFile(in pathSynchronizingExtraData, in pathCommittedExtraData); - if (rc.IsFailure()) return rc; + res = _baseFs.RenameFile(in pathSynchronizingExtraData, in pathCommittedExtraData); + if (res.IsFailure()) return res.Miss(); } } else { - return rc; + return res; } } @@ -901,11 +901,11 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem private Result EnsureExtraDataSize(in Path path) { using var file = new UniqueRef(); - Result rc = _baseFs.OpenFile(ref file.Ref(), in path, OpenMode.ReadWrite); - if (rc.IsFailure()) return rc; + Result res = _baseFs.OpenFile(ref file.Ref(), in path, OpenMode.ReadWrite); + if (res.IsFailure()) return res.Miss(); - rc = file.Get.GetSize(out long fileSize); - if (rc.IsFailure()) return rc; + res = file.Get.GetSize(out long fileSize); + if (res.IsFailure()) return res.Miss(); if (fileSize == Unsafe.SizeOf()) return Result.Success; @@ -919,22 +919,22 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem using (var sourceFile = new UniqueRef()) { - Result rc = _baseFs.OpenFile(ref sourceFile.Ref(), in sourcePath, OpenMode.Read); - if (rc.IsFailure()) return rc; + Result res = _baseFs.OpenFile(ref sourceFile.Ref(), in sourcePath, OpenMode.Read); + if (res.IsFailure()) return res.Miss(); - rc = sourceFile.Get.Read(out long bytesRead, 0, workBuffer); - if (rc.IsFailure()) return rc; + res = sourceFile.Get.Read(out long bytesRead, 0, workBuffer); + if (res.IsFailure()) return res.Miss(); Assert.SdkEqual(bytesRead, Unsafe.SizeOf()); } using (var destFile = new UniqueRef()) { - Result rc = _baseFs.OpenFile(ref destFile.Ref(), in destPath, OpenMode.Write); - if (rc.IsFailure()) return rc; + Result res = _baseFs.OpenFile(ref destFile.Ref(), in destPath, OpenMode.Write); + if (res.IsFailure()) return res.Miss(); - rc = destFile.Get.Write(0, workBuffer, WriteOption.Flush); - if (rc.IsFailure()) return rc; + res = destFile.Get.Write(0, workBuffer, WriteOption.Flush); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -944,8 +944,8 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem { Assert.SdkRequires(_mutex.IsLockedByCurrentThread()); - Result rc = ReadExtraDataImpl(out SaveDataExtraData extraData); - if (rc.IsFailure()) return rc; + Result res = ReadExtraDataImpl(out SaveDataExtraData extraData); + if (res.IsFailure()) return res.Miss(); if (_timeStampGetter.Get(out long timeStamp).IsSuccess()) { @@ -969,15 +969,15 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem Assert.SdkRequires(_mutex.IsLockedByCurrentThread()); using var pathExtraData = new Path(); - Result rc = GetExtraDataPath(ref pathExtraData.Ref()); - if (rc.IsFailure()) return rc; + Result res = GetExtraDataPath(ref pathExtraData.Ref()); + if (res.IsFailure()) return res.Miss(); using var file = new UniqueRef(); - rc = _baseFs.OpenFile(ref file.Ref(), in pathExtraData, OpenMode.Write); - if (rc.IsFailure()) return rc; + res = _baseFs.OpenFile(ref file.Ref(), in pathExtraData, OpenMode.Write); + if (res.IsFailure()) return res.Miss(); - rc = file.Get.Write(0, SpanHelpers.AsReadOnlyByteSpan(in extraData), WriteOption.Flush); - if (rc.IsFailure()) return rc; + res = file.Get.Write(0, SpanHelpers.AsReadOnlyByteSpan(in extraData), WriteOption.Flush); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -991,30 +991,30 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem using var closure = new RetryClosure(this); - Result rc = PathFunctions.SetUpFixedPath(ref closure.ModifiedPath.Ref(), ModifiedExtraDataName); - if (rc.IsFailure()) return rc; + Result res = PathFunctions.SetUpFixedPath(ref closure.ModifiedPath.Ref(), ModifiedExtraDataName); + if (res.IsFailure()) return res.Miss(); - rc = PathFunctions.SetUpFixedPath(ref closure.CommittedPath.Ref(), CommittedExtraDataName); - if (rc.IsFailure()) return rc; + res = PathFunctions.SetUpFixedPath(ref closure.CommittedPath.Ref(), CommittedExtraDataName); + if (res.IsFailure()) return res.Miss(); - rc = PathFunctions.SetUpFixedPath(ref closure.SynchronizingPath.Ref(), SynchronizingExtraDataName); - if (rc.IsFailure()) return rc; + res = PathFunctions.SetUpFixedPath(ref closure.SynchronizingPath.Ref(), SynchronizingExtraDataName); + if (res.IsFailure()) return res.Miss(); // Get rid of the previous commit by renaming the file. - rc = RetryFinitelyForTargetLocked(in closure, + res = RetryFinitelyForTargetLocked(in closure, (in RetryClosure c) => c.This._baseFs.RenameFile(in c.CommittedPath, in c.SynchronizingPath)); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); // If something goes wrong beyond this point, the commit will be // completed the next time the savedata is opened. - rc = RetryFinitelyForTargetLocked(in closure, + res = RetryFinitelyForTargetLocked(in closure, (in RetryClosure c) => c.This.SynchronizeExtraData(in c.SynchronizingPath, in c.ModifiedPath)); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = RetryFinitelyForTargetLocked(in closure, + res = RetryFinitelyForTargetLocked(in closure, (in RetryClosure c) => c.This._baseFs.RenameFile(in c.SynchronizingPath, in c.CommittedPath)); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -1026,15 +1026,15 @@ public class DirectorySaveDataFileSystem : ISaveDataFileSystem Assert.SdkRequires(_mutex.IsLockedByCurrentThread()); using var pathExtraData = new Path(); - Result rc = GetExtraDataPath(ref pathExtraData.Ref()); - if (rc.IsFailure()) return rc; + Result res = GetExtraDataPath(ref pathExtraData.Ref()); + if (res.IsFailure()) return res.Miss(); using var file = new UniqueRef(); - rc = _baseFs.OpenFile(ref file.Ref(), in pathExtraData, OpenMode.Read); - if (rc.IsFailure()) return rc; + res = _baseFs.OpenFile(ref file.Ref(), in pathExtraData, OpenMode.Read); + if (res.IsFailure()) return res.Miss(); - rc = file.Get.Read(out long bytesRead, 0, SpanHelpers.AsByteSpan(ref extraData)); - if (rc.IsFailure()) return rc; + res = file.Get.Read(out long bytesRead, 0, SpanHelpers.AsByteSpan(ref extraData)); + if (res.IsFailure()) return res.Miss(); Assert.SdkEqual(bytesRead, Unsafe.SizeOf()); diff --git a/src/LibHac/FsSystem/HierarchicalIntegrityVerificationStorage.cs b/src/LibHac/FsSystem/HierarchicalIntegrityVerificationStorage.cs index 67270e15..c591b296 100644 --- a/src/LibHac/FsSystem/HierarchicalIntegrityVerificationStorage.cs +++ b/src/LibHac/FsSystem/HierarchicalIntegrityVerificationStorage.cs @@ -166,8 +166,8 @@ public class HierarchicalIntegrityVerificationStorageControlArea : IDisposable in HierarchicalIntegrityVerificationMetaInformation metaInfo) { // Ensure the storage is large enough to hold the meta info. - Result rc = metaStorage.GetSize(out long metaSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = metaStorage.GetSize(out long metaSize); + if (res.IsFailure()) return res.Miss(); if (metaSize < Unsafe.SizeOf()) return ResultFs.InvalidSize.Log(); @@ -180,11 +180,11 @@ public class HierarchicalIntegrityVerificationStorageControlArea : IDisposable return ResultFs.UnsupportedVersion.Log(); // Write the meta info to the storage. - rc = metaStorage.Write(0, SpanHelpers.AsReadOnlyByteSpan(in metaInfo)); - if (rc.IsFailure()) return rc.Miss(); + res = metaStorage.Write(0, SpanHelpers.AsReadOnlyByteSpan(in metaInfo)); + if (res.IsFailure()) return res.Miss(); - rc = metaStorage.Flush(); - if (rc.IsFailure()) return rc.Miss(); + res = metaStorage.Flush(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -193,16 +193,16 @@ public class HierarchicalIntegrityVerificationStorageControlArea : IDisposable in HierarchicalIntegrityVerificationMetaInformation newMeta) { // Ensure the storage is large enough to hold the meta info. - Result rc = metaStorage.GetSize(out long metaSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = metaStorage.GetSize(out long metaSize); + if (res.IsFailure()) return res.Miss(); if (metaSize < Unsafe.SizeOf()) return ResultFs.InvalidSize.Log(); // Validate both the previous and new metas. HierarchicalIntegrityVerificationMetaInformation previousMeta = default; - rc = metaStorage.Read(0, SpanHelpers.AsByteSpan(ref previousMeta)); - if (rc.IsFailure()) return rc.Miss(); + res = metaStorage.Read(0, SpanHelpers.AsByteSpan(ref previousMeta)); + if (res.IsFailure()) return res.Miss(); if (newMeta.Magic != IntegrityVerificationStorageMagic || newMeta.Magic != previousMeta.Magic) return ResultFs.IncorrectIntegrityVerificationMagicCode.Log(); @@ -211,11 +211,11 @@ public class HierarchicalIntegrityVerificationStorageControlArea : IDisposable return ResultFs.UnsupportedVersion.Log(); // Write the new meta. - rc = metaStorage.Write(0, SpanHelpers.AsReadOnlyByteSpan(in newMeta)); - if (rc.IsFailure()) return rc.Miss(); + res = metaStorage.Write(0, SpanHelpers.AsReadOnlyByteSpan(in newMeta)); + if (res.IsFailure()) return res.Miss(); - rc = metaStorage.Flush(); - if (rc.IsFailure()) return rc.Miss(); + res = metaStorage.Flush(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -233,16 +233,16 @@ public class HierarchicalIntegrityVerificationStorageControlArea : IDisposable public Result Initialize(in ValueSubStorage metaStorage) { // Ensure the storage is large enough to hold the meta info. - Result rc = metaStorage.GetSize(out long metaSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = metaStorage.GetSize(out long metaSize); + if (res.IsFailure()) return res.Miss(); if (metaSize < Unsafe.SizeOf()) return ResultFs.InvalidSize.Log(); // Set the storage and read the meta. _storage.Set(in metaStorage); - rc = _storage.Read(0, SpanHelpers.AsByteSpan(ref _meta)); - if (rc.IsFailure()) return rc.Miss(); + res = _storage.Read(0, SpanHelpers.AsByteSpan(ref _meta)); + if (res.IsFailure()) return res.Miss(); // Validate the meta magic and version. if (_meta.Magic != IntegrityVerificationStorageMagic) @@ -454,11 +454,11 @@ public class HierarchicalIntegrityVerificationStorage : IStorage // Initialize the top level buffer storage. _bufferedStorages[0] = new BlockCacheBufferedStorage(); - Result rc = _bufferedStorages[0].Initialize(_bufferManagers.Buffers[0], _mutex, _integrityStorages[0], + Result res = _bufferedStorages[0].Initialize(_bufferManagers.Buffers[0], _mutex, _integrityStorages[0], info.Layers[0].Size, 1 << info.Layers[0].BlockOrder, maxHashCacheEntries, false, BaseBufferLevel, false, isWritable); - if (!rc.IsFailure()) + if (!res.IsFailure()) { int level; @@ -485,11 +485,11 @@ public class HierarchicalIntegrityVerificationStorage : IStorage // Initialize the buffer storage. _bufferedStorages[level + 1] = new BlockCacheBufferedStorage(); - rc = _bufferedStorages[level + 1].Initialize(_bufferManagers.Buffers[level + 1], _mutex, + res = _bufferedStorages[level + 1].Initialize(_bufferManagers.Buffers[level + 1], _mutex, _integrityStorages[level + 1], info.Layers[level + 1].Size, 1 << info.Layers[level + 1].BlockOrder, maxHashCacheEntries, false, (sbyte)(BaseBufferLevel + (level + 1)), false, isWritable); - if (rc.IsFailure()) + if (res.IsFailure()) { // Cleanup initialized storages if we failed. _integrityStorages[level + 1].FinalizeObject(); @@ -504,7 +504,7 @@ public class HierarchicalIntegrityVerificationStorage : IStorage } } - if (!rc.IsFailure()) + if (!res.IsFailure()) { // Initialize the final level storage. // If hash salt is enabled, generate it. @@ -528,11 +528,11 @@ public class HierarchicalIntegrityVerificationStorage : IStorage // Initialize the buffer storage. _bufferedStorages[level + 1] = new BlockCacheBufferedStorage(); - rc = _bufferedStorages[level + 1].Initialize(_bufferManagers.Buffers[level + 1], _mutex, + res = _bufferedStorages[level + 1].Initialize(_bufferManagers.Buffers[level + 1], _mutex, _integrityStorages[level + 1], info.Layers[level + 1].Size, 1 << info.Layers[level + 1].BlockOrder, maxDataCacheEntries, true, bufferLevel, true, isWritable); - if (!rc.IsFailure()) + if (!res.IsFailure()) { _dataSize = info.Layers[level + 1].Size; return Result.Success; @@ -558,7 +558,7 @@ public class HierarchicalIntegrityVerificationStorage : IStorage _bufferManagers = null; _mutex = null; - return rc; + return res; } public void FinalizeObject() @@ -610,8 +610,8 @@ public class HierarchicalIntegrityVerificationStorage : IStorage { for (int level = _layerCount - 2; level >= 0; level--) { - Result rc = _bufferedStorages[level].Flush(); - if (rc.IsFailure()) return rc.Miss(); + Result res = _bufferedStorages[level].Flush(); + if (res.IsFailure()) return res.Miss(); } g.GlobalReadSemaphore.Acquire(); @@ -619,8 +619,8 @@ public class HierarchicalIntegrityVerificationStorage : IStorage try { - Result rc = _bufferedStorages[_layerCount - 2].Read(offset, destination); - if (rc.IsFailure()) return rc.Miss(); + Result res = _bufferedStorages[_layerCount - 2].Read(offset, destination); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -653,8 +653,8 @@ public class HierarchicalIntegrityVerificationStorage : IStorage { for (int level = _layerCount - 2; level >= 0; level--) { - Result rc = _bufferedStorages[level].Flush(); - if (rc.IsFailure()) return rc.Miss(); + Result res = _bufferedStorages[level].Flush(); + if (res.IsFailure()) return res.Miss(); } g.GlobalWriteSemaphore.Acquire(); @@ -662,8 +662,8 @@ public class HierarchicalIntegrityVerificationStorage : IStorage try { - Result rc = _bufferedStorages[_layerCount - 2].Write(offset, source); - if (rc.IsFailure()) return rc.Miss(); + Result res = _bufferedStorages[_layerCount - 2].Write(offset, source); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -691,18 +691,18 @@ public class HierarchicalIntegrityVerificationStorage : IStorage case OperationId.FillZero: case OperationId.DestroySignature: { - Result rc = _bufferedStorages[_layerCount - 2] + Result res = _bufferedStorages[_layerCount - 2] .OperateRange(outBuffer, operationId, offset, size, inBuffer); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } case OperationId.InvalidateCache: case OperationId.QueryRange: { - Result rc = _bufferedStorages[_layerCount - 2] + Result res = _bufferedStorages[_layerCount - 2] .OperateRange(outBuffer, operationId, offset, size, inBuffer); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -715,8 +715,8 @@ public class HierarchicalIntegrityVerificationStorage : IStorage { for (int level = _layerCount - 2; level >= 0; level--) { - Result rc = _bufferedStorages[level].Commit(); - if (rc.IsFailure()) return rc.Miss(); + Result res = _bufferedStorages[level].Commit(); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -726,8 +726,8 @@ public class HierarchicalIntegrityVerificationStorage : IStorage { for (int level = _layerCount - 2; level >= 0; level--) { - Result rc = _bufferedStorages[level].OnRollback(); - if (rc.IsFailure()) return rc.Miss(); + Result res = _bufferedStorages[level].OnRollback(); + if (res.IsFailure()) return res.Miss(); } return Result.Success; diff --git a/src/LibHac/FsSystem/Impl/TargetLockedAvoidance.cs b/src/LibHac/FsSystem/Impl/TargetLockedAvoidance.cs index 0ba4302d..b0840d54 100644 --- a/src/LibHac/FsSystem/Impl/TargetLockedAvoidance.cs +++ b/src/LibHac/FsSystem/Impl/TargetLockedAvoidance.cs @@ -13,9 +13,9 @@ internal static class TargetLockedAvoidance // Allow usage outside of a Horizon context by using standard .NET APIs public static Result RetryToAvoidTargetLocked(Func func, FileSystemClient? fs = null) { - Result rc = func(); + Result res = func(); - for (int i = 0; i < RetryCount && ResultFs.TargetLocked.Includes(rc); i++) + for (int i = 0; i < RetryCount && ResultFs.TargetLocked.Includes(res); i++) { if (fs is null) { @@ -26,9 +26,9 @@ internal static class TargetLockedAvoidance fs.Hos.Os.SleepThread(TimeSpan.FromMilliSeconds(SleepTimeMs)); } - rc = func(); + res = func(); } - return rc; + return res; } } diff --git a/src/LibHac/FsSystem/IndirectStorage.cs b/src/LibHac/FsSystem/IndirectStorage.cs index 648b1955..03940920 100644 --- a/src/LibHac/FsSystem/IndirectStorage.cs +++ b/src/LibHac/FsSystem/IndirectStorage.cs @@ -124,19 +124,19 @@ public class IndirectStorage : IStorage { Unsafe.SkipInit(out BucketTree.Header header); - Result rc = tableStorage.Read(0, SpanHelpers.AsByteSpan(ref header)); - if (rc.IsFailure()) return rc.Miss(); + Result res = tableStorage.Read(0, SpanHelpers.AsByteSpan(ref header)); + if (res.IsFailure()) return res.Miss(); - rc = header.Verify(); - if (rc.IsFailure()) return rc.Miss(); + res = header.Verify(); + if (res.IsFailure()) return res.Miss(); long nodeStorageSize = QueryNodeStorageSize(header.EntryCount); long entryStorageSize = QueryEntryStorageSize(header.EntryCount); long nodeStorageOffset = QueryHeaderStorageSize(); long entryStorageOffset = nodeStorageSize + nodeStorageOffset; - rc = tableStorage.GetSize(out long storageSize); - if (rc.IsFailure()) return rc.Miss(); + res = tableStorage.GetSize(out long storageSize); + if (res.IsFailure()) return res.Miss(); if (storageSize < entryStorageOffset + entryStorageSize) return ResultFs.InvalidIndirectStorageBucketTreeSize.Log(); @@ -181,17 +181,17 @@ public class IndirectStorage : IStorage var closure = new OperatePerEntryClosure { OutBuffer = destination, Offset = offset }; - Result rc = OperatePerEntry(offset, destination.Length, enableContinuousReading: true, verifyEntryRanges: true, ref closure, + Result res = OperatePerEntry(offset, destination.Length, enableContinuousReading: true, verifyEntryRanges: true, ref closure, static (ref ValueSubStorage storage, long physicalOffset, long virtualOffset, long size, ref OperatePerEntryClosure entryClosure) => { int bufferPosition = (int)(virtualOffset - entryClosure.Offset); - Result rc = storage.Read(physicalOffset, entryClosure.OutBuffer.Slice(bufferPosition, (int)size)); - if (rc.IsFailure()) return rc.Miss(); + Result res = storage.Read(physicalOffset, entryClosure.OutBuffer.Slice(bufferPosition, (int)size)); + if (res.IsFailure()) return res.Miss(); return Result.Success; }); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -210,8 +210,8 @@ public class IndirectStorage : IStorage { UnsafeHelpers.SkipParamInit(out size); - Result rc = _table.GetOffsets(out BucketTree.Offsets offsets); - if (rc.IsFailure()) return rc.Miss(); + Result res = _table.GetOffsets(out BucketTree.Offsets offsets); + if (res.IsFailure()) return res.Miss(); size = offsets.EndOffset; return Result.Success; @@ -239,8 +239,8 @@ public class IndirectStorage : IStorage } // Check that our range is valid - Result rc = _table.GetOffsets(out BucketTree.Offsets offsets); - if (rc.IsFailure()) return rc.Miss(); + Result res = _table.GetOffsets(out BucketTree.Offsets offsets); + if (res.IsFailure()) return res.Miss(); if (!offsets.IsInclude(offset, size)) return ResultFs.OutOfRange.Log(); @@ -249,8 +249,8 @@ public class IndirectStorage : IStorage // Find the offset in our tree using var visitor = new BucketTree.Visitor(); - rc = _table.Find(ref visitor.Ref, offset); - if (rc.IsFailure()) return rc.Miss(); + res = _table.Find(ref visitor.Ref, offset); + if (res.IsFailure()) return res.Miss(); long entryOffset = visitor.Get().GetVirtualOffset(); if (entryOffset < 0 || !offsets.IsInclude(entryOffset)) @@ -278,8 +278,8 @@ public class IndirectStorage : IStorage if (!visitor.CanMoveNext()) break; - rc = visitor.MoveNext(); - if (rc.IsFailure()) return rc; + res = visitor.MoveNext(); + if (res.IsFailure()) return res.Miss(); currentEntry = visitor.Get(); } @@ -300,13 +300,13 @@ public class IndirectStorage : IStorage case OperationId.InvalidateCache: if (!_table.IsEmpty()) { - Result rc = _table.InvalidateCache(); - if (rc.IsFailure()) return rc.Miss(); + Result res = _table.InvalidateCache(); + if (res.IsFailure()) return res.Miss(); for (int i = 0; i < _dataStorage.Items.Length; i++) { - rc = _dataStorage.Items[i].OperateRange(OperationId.InvalidateCache, 0, long.MaxValue); - if (rc.IsFailure()) return rc.Miss(); + res = _dataStorage.Items[i].OperateRange(OperationId.InvalidateCache, 0, long.MaxValue); + if (res.IsFailure()) return res.Miss(); } } break; @@ -316,8 +316,8 @@ public class IndirectStorage : IStorage if (size > 0) { - Result rc = _table.GetOffsets(out BucketTree.Offsets offsets); - if (rc.IsFailure()) return rc.Miss(); + Result res = _table.GetOffsets(out BucketTree.Offsets offsets); + if (res.IsFailure()) return res.Miss(); if (!offsets.IsInclude(offset, size)) return ResultFs.OutOfRange.Log(); @@ -326,18 +326,18 @@ public class IndirectStorage : IStorage { var closure = new OperatePerEntryClosure { OperationId = operationId, InBuffer = inBuffer }; - rc = OperatePerEntry(offset, size, enableContinuousReading: false, verifyEntryRanges: true, ref closure, + res = OperatePerEntry(offset, size, enableContinuousReading: false, verifyEntryRanges: true, ref closure, static (ref ValueSubStorage storage, long physicalOffset, long virtualOffset, long processSize, ref OperatePerEntryClosure closure) => { Unsafe.SkipInit(out QueryRangeInfo currentInfo); - Result rc = storage.OperateRange(SpanHelpers.AsByteSpan(ref currentInfo), + Result res = storage.OperateRange(SpanHelpers.AsByteSpan(ref currentInfo), closure.OperationId, physicalOffset, processSize, closure.InBuffer); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); closure.InfoMerged.Merge(in currentInfo); return Result.Success; }); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); SpanHelpers.AsByteSpan(ref closure.InfoMerged).CopyTo(outBuffer); } @@ -375,8 +375,8 @@ public class IndirectStorage : IStorage return Result.Success; // Validate arguments - Result rc = _table.GetOffsets(out BucketTree.Offsets offsets); - if (rc.IsFailure()) return rc.Miss(); + Result res = _table.GetOffsets(out BucketTree.Offsets offsets); + if (res.IsFailure()) return res.Miss(); if (!offsets.IsInclude(offset, size)) return ResultFs.OutOfRange.Log(); @@ -384,8 +384,8 @@ public class IndirectStorage : IStorage // Find the offset in our tree using var visitor = new BucketTree.Visitor(); - rc = _table.Find(ref visitor.Ref, offset); - if (rc.IsFailure()) return rc; + res = _table.Find(ref visitor.Ref, offset); + if (res.IsFailure()) return res.Miss(); long entryOffset = visitor.Get().GetVirtualOffset(); if (entryOffset < 0 || !offsets.IsInclude(entryOffset)) @@ -414,9 +414,9 @@ public class IndirectStorage : IStorage { if (continuousReading.CheckNeedScan()) { - rc = visitor.ScanContinuousReading(out continuousReading, currentOffset, + res = visitor.ScanContinuousReading(out continuousReading, currentOffset, endOffset - currentOffset); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } if (continuousReading.CanDo()) @@ -432,8 +432,8 @@ public class IndirectStorage : IStorage if (verifyEntryRanges) { - rc = _dataStorage[0].GetSize(out long storageSize); - if (rc.IsFailure()) return rc.Miss(); + res = _dataStorage[0].GetSize(out long storageSize); + if (res.IsFailure()) return res.Miss(); // Ensure that we remain within range if (entryStorageOffset < 0 || entryStorageOffset > storageSize) @@ -443,8 +443,8 @@ public class IndirectStorage : IStorage return ResultFs.InvalidIndirectStorageSize.Log(); } - rc = func(ref _dataStorage[0], dataStorageOffset, currentOffset, continuousReadSize, ref closure); - if (rc.IsFailure()) return rc.Miss(); + res = func(ref _dataStorage[0], dataStorageOffset, currentOffset, continuousReadSize, ref closure); + if (res.IsFailure()) return res.Miss(); continuousReading.Done(); } @@ -454,8 +454,8 @@ public class IndirectStorage : IStorage long nextEntryOffset; if (visitor.CanMoveNext()) { - rc = visitor.MoveNext(); - if (rc.IsFailure()) return rc; + res = visitor.MoveNext(); + if (res.IsFailure()) return res.Miss(); nextEntryOffset = visitor.Get().GetVirtualOffset(); if (!offsets.IsInclude(nextEntryOffset)) @@ -497,8 +497,8 @@ public class IndirectStorage : IStorage if (verifyEntryRanges) { - rc = _dataStorage[currentEntry.StorageIndex].GetSize(out long storageSize); - if (rc.IsFailure()) return rc.Miss(); + res = _dataStorage[currentEntry.StorageIndex].GetSize(out long storageSize); + if (res.IsFailure()) return res.Miss(); // Ensure that we remain within range if (entryStorageOffset < 0 || entryStorageOffset > storageSize) @@ -508,9 +508,9 @@ public class IndirectStorage : IStorage return ResultFs.IndirectStorageCorrupted.Log(); } - rc = func(ref _dataStorage[currentEntry.StorageIndex], dataStorageOffset, currentOffset, processSize, + res = func(ref _dataStorage[currentEntry.StorageIndex], dataStorageOffset, currentOffset, processSize, ref closure); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } currentOffset += processSize; diff --git a/src/LibHac/FsSystem/IntegrityRomFsStorage.cs b/src/LibHac/FsSystem/IntegrityRomFsStorage.cs index 5d198a7e..2ab21ab1 100644 --- a/src/LibHac/FsSystem/IntegrityRomFsStorage.cs +++ b/src/LibHac/FsSystem/IntegrityRomFsStorage.cs @@ -64,9 +64,9 @@ public class IntegrityRomFsStorage : IStorage } // Initialize our integrity storage. - Result rc = _integrityStorage.Initialize(in info, ref storageInfo, _bufferManagerSet, hashGeneratorFactory, + Result res = _integrityStorage.Initialize(in info, ref storageInfo, _bufferManagerSet, hashGeneratorFactory, false, _mutex, maxDataCacheEntries, maxHashCacheEntries, bufferLevel, false, false); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/FsSystem/IntegrityVerificationStorage.cs b/src/LibHac/FsSystem/IntegrityVerificationStorage.cs index 4ca9b7c5..bd679a14 100644 --- a/src/LibHac/FsSystem/IntegrityVerificationStorage.cs +++ b/src/LibHac/FsSystem/IntegrityVerificationStorage.cs @@ -164,15 +164,15 @@ public class IntegrityVerificationStorage : IStorage if (destination.Length == 0) return Result.Success; - Result rc = _dataStorage.GetSize(out long dataSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = _dataStorage.GetSize(out long dataSize); + if (res.IsFailure()) return res.Miss(); if (dataSize < offset) return ResultFs.InvalidOffset.Log(); long alignedDataSize = Alignment.AlignUpPow2(dataSize, (uint)_verificationBlockSize); - rc = CheckAccessRange(offset, destination.Length, alignedDataSize); - if (rc.IsFailure()) return rc.Miss(); + res = CheckAccessRange(offset, destination.Length, alignedDataSize); + if (res.IsFailure()) return res.Miss(); int readSize = destination.Length; if (offset + readSize > dataSize) @@ -192,19 +192,19 @@ public class IntegrityVerificationStorage : IStorage } // Read all of the data to be validated. - rc = _dataStorage.Read(offset, destination.Slice(0, readSize)); - if (rc.IsFailure()) + res = _dataStorage.Read(offset, destination.Slice(0, readSize)); + if (res.IsFailure()) { destination.Clear(); - return rc.Log(); + return res.Log(); } // Validate the hashes of the read data blocks. Result verifyHashResult = Result.Success; using var hashGenerator = new UniqueRef(); - rc = _hashGeneratorFactory.Create(ref hashGenerator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = _hashGeneratorFactory.Create(ref hashGenerator.Ref()); + if (res.IsFailure()) return res.Miss(); int signatureCount = destination.Length >> _verificationBlockOrder; using var signatureBuffer = @@ -259,17 +259,17 @@ public class IntegrityVerificationStorage : IStorage if (source.Length == 0) return Result.Success; - Result rc = CheckOffsetAndSize(offset, source.Length); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckOffsetAndSize(offset, source.Length); + if (res.IsFailure()) return res.Miss(); - rc = _dataStorage.GetSize(out long dataSize); - if (rc.IsFailure()) return rc.Miss(); + res = _dataStorage.GetSize(out long dataSize); + if (res.IsFailure()) return res.Miss(); if (offset >= dataSize) return ResultFs.InvalidOffset.Log(); - rc = CheckAccessRange(offset, source.Length, Alignment.AlignUpPow2(dataSize, (uint)_verificationBlockSize)); - if (rc.IsFailure()) return rc.Miss(); + res = CheckAccessRange(offset, source.Length, Alignment.AlignUpPow2(dataSize, (uint)_verificationBlockSize)); + if (res.IsFailure()) return res.Miss(); Assert.SdkRequiresAligned(offset, _verificationBlockSize); Assert.SdkRequiresAligned(source.Length, _verificationBlockSize); @@ -304,8 +304,8 @@ public class IntegrityVerificationStorage : IStorage int bufferCount = Math.Min(signatureCount, signatureBuffer.GetSize() / Unsafe.SizeOf()); using var hashGenerator = new UniqueRef(); - rc = _hashGeneratorFactory.Create(ref hashGenerator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + res = _hashGeneratorFactory.Create(ref hashGenerator.Ref()); + if (res.IsFailure()) return res.Miss(); while (updatedSignatureCount < signatureCount) { @@ -339,19 +339,19 @@ public class IntegrityVerificationStorage : IStorage // If there was an error writing the updated hashes, only the data for the blocks that were // successfully updated will be written. int dataWriteSize = Math.Min(writeSize, updatedSignatureCount << _verificationBlockOrder); - rc = _dataStorage.Write(offset, source.Slice(0, dataWriteSize)); - if (rc.IsFailure()) return rc.Miss(); + res = _dataStorage.Write(offset, source.Slice(0, dataWriteSize)); + if (res.IsFailure()) return res.Miss(); return updateResult; } public override Result Flush() { - Result rc = _hashStorage.Flush(); - if (rc.IsFailure()) return rc.Miss(); + Result res = _hashStorage.Flush(); + if (res.IsFailure()) return res.Miss(); - rc = _dataStorage.Flush(); - if (rc.IsFailure()) return rc.Miss(); + res = _dataStorage.Flush(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -371,8 +371,8 @@ public class IntegrityVerificationStorage : IStorage { Assert.SdkRequires(_isWritable); - Result rc = _dataStorage.GetSize(out long dataStorageSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = _dataStorage.GetSize(out long dataStorageSize); + if (res.IsFailure()) return res.Miss(); if (offset < 0 || dataStorageSize < offset) return ResultFs.InvalidOffset.Log(); @@ -396,9 +396,9 @@ public class IntegrityVerificationStorage : IStorage { int currentSize = (int)Math.Min(remainingSize, bufferSize); - rc = _hashStorage.Write(signOffset + signSize - remainingSize, + res = _hashStorage.Write(signOffset + signSize - remainingSize, workBuffer.Span.Slice(0, currentSize)); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); remainingSize -= currentSize; } @@ -409,8 +409,8 @@ public class IntegrityVerificationStorage : IStorage { Assert.SdkRequires(_isWritable); - Result rc = _dataStorage.GetSize(out long dataStorageSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = _dataStorage.GetSize(out long dataStorageSize); + if (res.IsFailure()) return res.Miss(); if (offset < 0 || dataStorageSize < offset) return ResultFs.InvalidOffset.Log(); @@ -424,8 +424,8 @@ public class IntegrityVerificationStorage : IStorage return ResultFs.AllocationMemoryFailedInIntegrityVerificationStorageB.Log(); // Read the existing signature. - rc = _hashStorage.Read(signOffset, workBuffer.Span); - if (rc.IsFailure()) return rc.Miss(); + res = _hashStorage.Read(signOffset, workBuffer.Span); + if (res.IsFailure()) return res.Miss(); // Clear the signature. // This flips all bits, leaving the verification bit cleared. @@ -443,25 +443,25 @@ public class IntegrityVerificationStorage : IStorage if (_isWritable) return ResultFs.UnsupportedOperateRangeForWritableIntegrityVerificationStorage.Log(); - Result rc = _hashStorage.OperateRange(operationId, 0, long.MaxValue); - if (rc.IsFailure()) return rc.Miss(); + Result res = _hashStorage.OperateRange(operationId, 0, long.MaxValue); + if (res.IsFailure()) return res.Miss(); - rc = _dataStorage.OperateRange(operationId, offset, size); - if (rc.IsFailure()) return rc.Miss(); + res = _dataStorage.OperateRange(operationId, offset, size); + if (res.IsFailure()) return res.Miss(); return Result.Success; } case OperationId.QueryRange: { - Result rc = _dataStorage.GetSize(out long dataStorageSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = _dataStorage.GetSize(out long dataStorageSize); + if (res.IsFailure()) return res.Miss(); if (offset < 0 || dataStorageSize < offset) return ResultFs.InvalidOffset.Log(); long actualSize = Math.Min(size, dataStorageSize - offset); - rc = _dataStorage.OperateRange(outBuffer, operationId, offset, actualSize, inBuffer); - if (rc.IsFailure()) return rc.Miss(); + res = _dataStorage.OperateRange(outBuffer, operationId, offset, actualSize, inBuffer); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -481,8 +481,8 @@ public class IntegrityVerificationStorage : IStorage Assert.SdkGreaterEqual(destination.Length, sizeSignData); // Validate the hash storage contains the calculated range. - Result rc = _hashStorage.GetSize(out long sizeHash); - if (rc.IsFailure()) return rc.Miss(); + Result res = _hashStorage.GetSize(out long sizeHash); + if (res.IsFailure()) return res.Miss(); Assert.SdkLessEqual(offsetSignData + sizeSignData, sizeHash); @@ -490,12 +490,12 @@ public class IntegrityVerificationStorage : IStorage return ResultFs.OutOfRange.Log(); // Read the signature. - rc = _hashStorage.Read(offsetSignData, destination.Slice(0, (int)sizeSignData)); - if (rc.IsFailure()) + res = _hashStorage.Read(offsetSignData, destination.Slice(0, (int)sizeSignData)); + if (res.IsFailure()) { // Clear any read signature data if something goes wrong. destination.Slice(0, (int)sizeSignData); - return rc.Miss(); + return res.Miss(); } return Result.Success; @@ -509,8 +509,8 @@ public class IntegrityVerificationStorage : IStorage long sizeSignData = (size >> _verificationBlockOrder) * HashSize; Assert.SdkGreaterEqual(source.Length, sizeSignData); - Result rc = _hashStorage.Write(offsetSignData, source.Slice(0, (int)sizeSignData)); - if (rc.IsFailure()) return rc.Miss(); + Result res = _hashStorage.Write(offsetSignData, source.Slice(0, (int)sizeSignData)); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -520,8 +520,8 @@ public class IntegrityVerificationStorage : IStorage UnsafeHelpers.SkipParamInit(out outHash); using var hashGenerator = new UniqueRef(); - Result rc = _hashGeneratorFactory.Create(ref hashGenerator.Ref()); - if (rc.IsFailure()) return rc.Miss(); + Result res = _hashGeneratorFactory.Create(ref hashGenerator.Ref()); + if (res.IsFailure()) return res.Miss(); CalcBlockHash(out outHash, buffer, verificationBlockSize, in hashGenerator); return Result.Success; @@ -575,8 +575,8 @@ public class IntegrityVerificationStorage : IStorage // Writable storages allow using an all-zeros hash to indicate an empty block. if (_isWritable) { - Result rc = IsCleared(out bool isCleared, in hash); - if (rc.IsFailure()) return rc.Miss(); + Result res = IsCleared(out bool isCleared, in hash); + if (res.IsFailure()) return res.Miss(); if (isCleared) return ResultFs.ClearedRealDataVerificationFailed.Log(); diff --git a/src/LibHac/FsSystem/LocalFile.cs b/src/LibHac/FsSystem/LocalFile.cs index 2b774e3b..516c7c34 100644 --- a/src/LibHac/FsSystem/LocalFile.cs +++ b/src/LibHac/FsSystem/LocalFile.cs @@ -34,16 +34,16 @@ public class LocalFile : IFile { bytesRead = 0; - Result rc = DryRead(out long toRead, offset, destination.Length, in option, Mode); - if (rc.IsFailure()) return rc; + Result res = DryRead(out long toRead, offset, destination.Length, in option, Mode); + if (res.IsFailure()) return res.Miss(); return File.Read(out bytesRead, offset, destination.Slice(0, (int)toRead), option); } protected override Result DoWrite(long offset, ReadOnlySpan source, in WriteOption option) { - Result rc = DryWrite(out _, offset, source.Length, in option, Mode); - if (rc.IsFailure()) return rc; + Result res = DryWrite(out _, offset, source.Length, in option, Mode); + if (res.IsFailure()) return res.Miss(); return File.Write(offset, source, option); } diff --git a/src/LibHac/FsSystem/LocalFileSystem.cs b/src/LibHac/FsSystem/LocalFileSystem.cs index 1fd0f4f2..8072b12d 100644 --- a/src/LibHac/FsSystem/LocalFileSystem.cs +++ b/src/LibHac/FsSystem/LocalFileSystem.cs @@ -58,9 +58,9 @@ public class LocalFileSystem : IAttributeFileSystem /// The path that will be the root of the . public LocalFileSystem(string rootPath) { - Result rc = Initialize(rootPath, PathMode.DefaultCaseSensitivity, true); - if (rc.IsFailure()) - throw new HorizonResultException(rc, "Error creating LocalFileSystem."); + Result res = Initialize(rootPath, PathMode.DefaultCaseSensitivity, true); + if (res.IsFailure()) + throw new HorizonResultException(res, "Error creating LocalFileSystem."); } public static Result Create(out LocalFileSystem fileSystem, string rootPath, @@ -69,8 +69,8 @@ public class LocalFileSystem : IAttributeFileSystem UnsafeHelpers.SkipParamInit(out fileSystem); var localFs = new LocalFileSystem(); - Result rc = localFs.Initialize(rootPath, pathMode, ensurePathExists); - if (rc.IsFailure()) return rc; + Result res = localFs.Initialize(rootPath, pathMode, ensurePathExists); + if (res.IsFailure()) return res.Miss(); fileSystem = localFs; return Result.Success; @@ -78,7 +78,7 @@ public class LocalFileSystem : IAttributeFileSystem public Result Initialize(string rootPath, PathMode pathMode, bool ensurePathExists) { - Result rc; + Result res; if (rootPath == null) return ResultFs.NullptrArgument.Log(); @@ -89,11 +89,11 @@ public class LocalFileSystem : IAttributeFileSystem if (rootPath == string.Empty) { using var path = new Path(); - rc = path.InitializeAsEmpty(); - if (rc.IsFailure()) return rc; + res = path.InitializeAsEmpty(); + if (res.IsFailure()) return res.Miss(); - rc = _rootPath.Initialize(in path); - if (rc.IsFailure()) return rc; + res = _rootPath.Initialize(in path); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -133,13 +133,13 @@ public class LocalFileSystem : IAttributeFileSystem if (utf8Path.At(0) == DirectorySeparator && utf8Path.At(1) != DirectorySeparator) { - rc = pathNormalized.Initialize(utf8Path); - if (rc.IsFailure()) return rc; + res = pathNormalized.Initialize(utf8Path); + if (res.IsFailure()) return res.Miss(); } else { - rc = pathNormalized.InitializeWithReplaceUnc(utf8Path); - if (rc.IsFailure()) return rc; + res = pathNormalized.InitializeWithReplaceUnc(utf8Path); + if (res.IsFailure()) return res.Miss(); } var flags = new PathFlags(); @@ -147,11 +147,11 @@ public class LocalFileSystem : IAttributeFileSystem flags.AllowRelativePath(); flags.AllowEmptyPath(); - rc = pathNormalized.Normalize(flags); - if (rc.IsFailure()) return rc; + res = pathNormalized.Normalize(flags); + if (res.IsFailure()) return res.Miss(); - rc = _rootPath.Initialize(in pathNormalized); - if (rc.IsFailure()) return rc; + res = _rootPath.Initialize(in pathNormalized); + if (res.IsFailure()) return res.Miss(); _rootPathUtf16 = _rootPath.ToString(); @@ -166,28 +166,28 @@ public class LocalFileSystem : IAttributeFileSystem // because we don't want to allow access to anything outside the root path. using var pathNormalized = new Path(); - Result rc = pathNormalized.Initialize(path.GetString()); - if (rc.IsFailure()) return rc; + Result res = pathNormalized.Initialize(path.GetString()); + if (res.IsFailure()) return res.Miss(); var pathFlags = new PathFlags(); pathFlags.AllowWindowsPath(); pathFlags.AllowRelativePath(); pathFlags.AllowEmptyPath(); - rc = pathNormalized.Normalize(pathFlags); - if (rc.IsFailure()) return rc; + res = pathNormalized.Normalize(pathFlags); + if (res.IsFailure()) return res.Miss(); using Path rootPath = _rootPath.DangerousGetPath(); using var fullPath = new Path(); - rc = fullPath.Combine(in rootPath, in pathNormalized); - if (rc.IsFailure()) return rc; + res = fullPath.Combine(in rootPath, in pathNormalized); + if (res.IsFailure()) return res.Miss(); string utf16FullPath = fullPath.ToString(); if (_mode == PathMode.CaseSensitive && checkCaseSensitivity) { - rc = CheckPathCaseSensitively(utf16FullPath); - if (rc.IsFailure()) return rc; + res = CheckPathCaseSensitively(utf16FullPath); + if (res.IsFailure()) return res.Miss(); } outFullPath = utf16FullPath; @@ -198,11 +198,11 @@ public class LocalFileSystem : IAttributeFileSystem { UnsafeHelpers.SkipParamInit(out attributes); - Result rc = ResolveFullPath(out string fullPath, in path, true); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(out string fullPath, in path, true); + if (res.IsFailure()) return res.Miss(); - rc = GetFileInfo(out FileInfo info, fullPath); - if (rc.IsFailure()) return rc; + res = GetFileInfo(out FileInfo info, fullPath); + if (res.IsFailure()) return res.Miss(); if (info.Attributes == (FileAttributes)(-1)) { @@ -215,11 +215,11 @@ public class LocalFileSystem : IAttributeFileSystem protected override Result DoSetFileAttributes(in Path path, NxFileAttributes attributes) { - Result rc = ResolveFullPath(out string fullPath, in path, true); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(out string fullPath, in path, true); + if (res.IsFailure()) return res.Miss(); - rc = GetFileInfo(out FileInfo info, fullPath); - if (rc.IsFailure()) return rc; + res = GetFileInfo(out FileInfo info, fullPath); + if (res.IsFailure()) return res.Miss(); if (info.Attributes == (FileAttributes)(-1)) { @@ -245,11 +245,11 @@ public class LocalFileSystem : IAttributeFileSystem { UnsafeHelpers.SkipParamInit(out fileSize); - Result rc = ResolveFullPath(out string fullPath, in path, true); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(out string fullPath, in path, true); + if (res.IsFailure()) return res.Miss(); - rc = GetFileInfo(out FileInfo info, fullPath); - if (rc.IsFailure()) return rc; + res = GetFileInfo(out FileInfo info, fullPath); + if (res.IsFailure()) return res.Miss(); return GetSizeInternal(out fileSize, info); } @@ -261,11 +261,11 @@ public class LocalFileSystem : IAttributeFileSystem protected override Result DoCreateDirectory(in Path path, NxFileAttributes archiveAttribute) { - Result rc = ResolveFullPath(out string fullPath, in path, false); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(out string fullPath, in path, false); + if (res.IsFailure()) return res.Miss(); - rc = GetDirInfo(out DirectoryInfo dir, fullPath); - if (rc.IsFailure()) return rc; + res = GetDirInfo(out DirectoryInfo dir, fullPath); + if (res.IsFailure()) return res.Miss(); if (dir.Exists) { @@ -282,11 +282,11 @@ public class LocalFileSystem : IAttributeFileSystem protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { - Result rc = ResolveFullPath(out string fullPath, in path, false); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(out string fullPath, in path, false); + if (res.IsFailure()) return res.Miss(); - rc = GetFileInfo(out FileInfo file, fullPath); - if (rc.IsFailure()) return rc; + res = GetFileInfo(out FileInfo file, fullPath); + if (res.IsFailure()) return res.Miss(); if (file.Exists) { @@ -298,11 +298,11 @@ public class LocalFileSystem : IAttributeFileSystem return ResultFs.PathNotFound.Log(); } - rc = CreateFileInternal(out FileStream stream, file); + res = CreateFileInternal(out FileStream stream, file); using (stream) { - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return SetStreamLengthInternal(stream, size); } @@ -310,11 +310,11 @@ public class LocalFileSystem : IAttributeFileSystem protected override Result DoDeleteDirectory(in Path path) { - Result rc = ResolveFullPath(out string fullPath, in path, true); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(out string fullPath, in path, true); + if (res.IsFailure()) return res.Miss(); - rc = GetDirInfo(out DirectoryInfo dir, fullPath); - if (rc.IsFailure()) return rc; + res = GetDirInfo(out DirectoryInfo dir, fullPath); + if (res.IsFailure()) return res.Miss(); return TargetLockedAvoidance.RetryToAvoidTargetLocked( () => DeleteDirectoryInternal(dir, false), _fsClient); @@ -322,11 +322,11 @@ public class LocalFileSystem : IAttributeFileSystem protected override Result DoDeleteDirectoryRecursively(in Path path) { - Result rc = ResolveFullPath(out string fullPath, in path, true); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(out string fullPath, in path, true); + if (res.IsFailure()) return res.Miss(); - rc = GetDirInfo(out DirectoryInfo dir, fullPath); - if (rc.IsFailure()) return rc; + res = GetDirInfo(out DirectoryInfo dir, fullPath); + if (res.IsFailure()) return res.Miss(); return TargetLockedAvoidance.RetryToAvoidTargetLocked( () => DeleteDirectoryInternal(dir, true), _fsClient); @@ -334,22 +334,22 @@ public class LocalFileSystem : IAttributeFileSystem protected override Result DoCleanDirectoryRecursively(in Path path) { - Result rc = ResolveFullPath(out string fullPath, in path, true); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(out string fullPath, in path, true); + if (res.IsFailure()) return res.Miss(); - rc = GetDirInfo(out DirectoryInfo dir, fullPath); - if (rc.IsFailure()) return rc; + res = GetDirInfo(out DirectoryInfo dir, fullPath); + if (res.IsFailure()) return res.Miss(); return CleanDirectoryInternal(dir, _fsClient); } protected override Result DoDeleteFile(in Path path) { - Result rc = ResolveFullPath(out string fullPath, in path, true); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(out string fullPath, in path, true); + if (res.IsFailure()) return res.Miss(); - rc = GetFileInfo(out FileInfo file, fullPath); - if (rc.IsFailure()) return rc; + res = GetFileInfo(out FileInfo file, fullPath); + if (res.IsFailure()) return res.Miss(); return TargetLockedAvoidance.RetryToAvoidTargetLocked( () => DeleteFileInternal(file), _fsClient); @@ -358,11 +358,11 @@ public class LocalFileSystem : IAttributeFileSystem protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, OpenDirectoryMode mode) { - Result rc = ResolveFullPath(out string fullPath, in path, true); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(out string fullPath, in path, true); + if (res.IsFailure()) return res.Miss(); - rc = GetDirInfo(out DirectoryInfo dirInfo, fullPath); - if (rc.IsFailure()) return rc; + res = GetDirInfo(out DirectoryInfo dirInfo, fullPath); + if (res.IsFailure()) return res.Miss(); if (!dirInfo.Attributes.HasFlag(FileAttributes.Directory)) { @@ -370,9 +370,9 @@ public class LocalFileSystem : IAttributeFileSystem } IDirectory dirTemp = null; - rc = TargetLockedAvoidance.RetryToAvoidTargetLocked(() => + res = TargetLockedAvoidance.RetryToAvoidTargetLocked(() => OpenDirectoryInternal(out dirTemp, mode, dirInfo), _fsClient); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); outDirectory.Reset(dirTemp); return Result.Success; @@ -380,11 +380,11 @@ public class LocalFileSystem : IAttributeFileSystem protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) { - Result rc = ResolveFullPath(out string fullPath, in path, true); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(out string fullPath, in path, true); + if (res.IsFailure()) return res.Miss(); - rc = GetEntryType(out DirectoryEntryType entryType, path); - if (rc.IsFailure()) return rc; + res = GetEntryType(out DirectoryEntryType entryType, path); + if (res.IsFailure()) return res.Miss(); if (entryType == DirectoryEntryType.Directory) { @@ -393,9 +393,9 @@ public class LocalFileSystem : IAttributeFileSystem FileStream fileStream = null; - rc = TargetLockedAvoidance.RetryToAvoidTargetLocked(() => + res = TargetLockedAvoidance.RetryToAvoidTargetLocked(() => OpenFileInternal(out fileStream, fullPath, mode), _fsClient); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); outFile.Reset(new LocalFile(fileStream, mode)); return Result.Success; @@ -403,20 +403,20 @@ public class LocalFileSystem : IAttributeFileSystem protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) { - Result rc = ResolveFullPath(out string fullCurrentPath, in currentPath, true); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(out string fullCurrentPath, in currentPath, true); + if (res.IsFailure()) return res.Miss(); - rc = ResolveFullPath(out string fullNewPath, in newPath, false); - if (rc.IsFailure()) return rc; + res = ResolveFullPath(out string fullNewPath, in newPath, false); + if (res.IsFailure()) return res.Miss(); // Official FS behavior is to do nothing in this case if (fullCurrentPath == fullNewPath) return Result.Success; - rc = GetDirInfo(out DirectoryInfo currentDirInfo, fullCurrentPath); - if (rc.IsFailure()) return rc; + res = GetDirInfo(out DirectoryInfo currentDirInfo, fullCurrentPath); + if (res.IsFailure()) return res.Miss(); - rc = GetDirInfo(out DirectoryInfo newDirInfo, fullNewPath); - if (rc.IsFailure()) return rc; + res = GetDirInfo(out DirectoryInfo newDirInfo, fullNewPath); + if (res.IsFailure()) return res.Miss(); return TargetLockedAvoidance.RetryToAvoidTargetLocked( () => RenameDirInternal(currentDirInfo, newDirInfo), _fsClient); @@ -424,20 +424,20 @@ public class LocalFileSystem : IAttributeFileSystem protected override Result DoRenameFile(in Path currentPath, in Path newPath) { - Result rc = ResolveFullPath(out string fullCurrentPath, in currentPath, true); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(out string fullCurrentPath, in currentPath, true); + if (res.IsFailure()) return res.Miss(); - rc = ResolveFullPath(out string fullNewPath, in newPath, false); - if (rc.IsFailure()) return rc; + res = ResolveFullPath(out string fullNewPath, in newPath, false); + if (res.IsFailure()) return res.Miss(); // Official FS behavior is to do nothing in this case if (fullCurrentPath == fullNewPath) return Result.Success; - rc = GetFileInfo(out FileInfo currentFileInfo, fullCurrentPath); - if (rc.IsFailure()) return rc; + res = GetFileInfo(out FileInfo currentFileInfo, fullCurrentPath); + if (res.IsFailure()) return res.Miss(); - rc = GetFileInfo(out FileInfo newFileInfo, fullNewPath); - if (rc.IsFailure()) return rc; + res = GetFileInfo(out FileInfo newFileInfo, fullNewPath); + if (res.IsFailure()) return res.Miss(); return TargetLockedAvoidance.RetryToAvoidTargetLocked( () => RenameFileInternal(currentFileInfo, newFileInfo), _fsClient); @@ -447,11 +447,11 @@ public class LocalFileSystem : IAttributeFileSystem { UnsafeHelpers.SkipParamInit(out entryType); - Result rc = ResolveFullPath(out string fullPath, in path, true); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(out string fullPath, in path, true); + if (res.IsFailure()) return res.Miss(); - rc = GetDirInfo(out DirectoryInfo dir, fullPath); - if (rc.IsFailure()) return rc; + res = GetDirInfo(out DirectoryInfo dir, fullPath); + if (res.IsFailure()) return res.Miss(); if (dir.Exists) { @@ -459,8 +459,8 @@ public class LocalFileSystem : IAttributeFileSystem return Result.Success; } - rc = GetFileInfo(out FileInfo file, fullPath); - if (rc.IsFailure()) return rc; + res = GetFileInfo(out FileInfo file, fullPath); + if (res.IsFailure()) return res.Miss(); if (file.Exists) { @@ -475,11 +475,11 @@ public class LocalFileSystem : IAttributeFileSystem { UnsafeHelpers.SkipParamInit(out timeStamp); - Result rc = ResolveFullPath(out string fullPath, in path, true); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(out string fullPath, in path, true); + if (res.IsFailure()) return res.Miss(); - rc = GetFileInfo(out FileInfo file, fullPath); - if (rc.IsFailure()) return rc; + res = GetFileInfo(out FileInfo file, fullPath); + if (res.IsFailure()) return res.Miss(); if (!file.Exists) return ResultFs.PathNotFound.Log(); @@ -505,8 +505,8 @@ public class LocalFileSystem : IAttributeFileSystem { UnsafeHelpers.SkipParamInit(out freeSpace); - Result rc = ResolveFullPath(out string fullPath, in path, true); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(out string fullPath, in path, true); + if (res.IsFailure()) return res.Miss(); freeSpace = new DriveInfo(fullPath).AvailableFreeSpace; return Result.Success; @@ -516,8 +516,8 @@ public class LocalFileSystem : IAttributeFileSystem { UnsafeHelpers.SkipParamInit(out totalSpace); - Result rc = ResolveFullPath(out string fullPath, in path, true); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(out string fullPath, in path, true); + if (res.IsFailure()) return res.Miss(); totalSpace = new DriveInfo(fullPath).TotalSize; return Result.Success; @@ -627,16 +627,16 @@ public class LocalFileSystem : IAttributeFileSystem { foreach (FileInfo fileInfo in dir.EnumerateFiles()) { - Result rc = TargetLockedAvoidance.RetryToAvoidTargetLocked(() => DeleteFileInternal(fileInfo), + Result res = TargetLockedAvoidance.RetryToAvoidTargetLocked(() => DeleteFileInternal(fileInfo), fsClient); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); } foreach (DirectoryInfo dirInfo in dir.EnumerateDirectories()) { - Result rc = TargetLockedAvoidance.RetryToAvoidTargetLocked(() => DeleteDirectoryInternal(dirInfo, true), + Result res = TargetLockedAvoidance.RetryToAvoidTargetLocked(() => DeleteDirectoryInternal(dirInfo, true), fsClient); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); } } catch (Exception ex) when (ex.HResult < 0) @@ -662,8 +662,8 @@ public class LocalFileSystem : IAttributeFileSystem { if (recursive) { - Result rc = DeleteDirectoryRecursivelyWithReadOnly(dir); - if (rc.IsFailure()) return rc.Miss(); + Result res = DeleteDirectoryRecursivelyWithReadOnly(dir); + if (res.IsFailure()) return res.Miss(); } else { @@ -733,8 +733,8 @@ public class LocalFileSystem : IAttributeFileSystem } else if (info is DirectoryInfo dir) { - Result rc = DeleteDirectoryRecursivelyWithReadOnly(dir); - if (rc.IsFailure()) return rc.Miss(); + Result res = DeleteDirectoryRecursivelyWithReadOnly(dir); + if (res.IsFailure()) return res.Miss(); } else { @@ -881,9 +881,9 @@ public class LocalFileSystem : IAttributeFileSystem string pathUtf16 = StringUtils.Utf8ZToString(path); string workingDirectoryPathUtf16 = StringUtils.Utf8ZToString(workingDirectoryPath); - Result rc = GetCaseSensitivePathFull(out string caseSensitivePath, out int rootPathLength, pathUtf16, + Result res = GetCaseSensitivePathFull(out string caseSensitivePath, out int rootPathLength, pathUtf16, workingDirectoryPathUtf16); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); OperationStatus status = Utf8.FromUtf16(caseSensitivePath.AsSpan(rootPathLength), buffer.Slice(0, buffer.Length - 1), out _, out int utf8BytesWritten); @@ -902,8 +902,8 @@ public class LocalFileSystem : IAttributeFileSystem private Result CheckPathCaseSensitively(string path) { - Result rc = GetCaseSensitivePathFull(out string caseSensitivePath, out _, path, _rootPathUtf16); - if (rc.IsFailure()) return rc; + Result res = GetCaseSensitivePathFull(out string caseSensitivePath, out _, path, _rootPathUtf16); + if (res.IsFailure()) return res.Miss(); if (path.Length != caseSensitivePath.Length) return ResultFs.PathNotFound.Log(); @@ -950,8 +950,8 @@ public class LocalFileSystem : IAttributeFileSystem fullPath = Combine(workingDirectoryPath, path); } - Result rc = GetCorrectCasedPath(out caseSensitivePath, fullPath); - if (rc.IsFailure()) return rc; + Result res = GetCorrectCasedPath(out caseSensitivePath, fullPath); + if (res.IsFailure()) return res.Miss(); rootPathLength = workingDirectoryPathLength; return Result.Success; diff --git a/src/LibHac/FsSystem/NcaReader.cs b/src/LibHac/FsSystem/NcaReader.cs index 99ae3cb5..d5b7af12 100644 --- a/src/LibHac/FsSystem/NcaReader.cs +++ b/src/LibHac/FsSystem/NcaReader.cs @@ -90,8 +90,8 @@ public class NcaReader : IDisposable return ResultFs.AllocationMemoryFailedInNcaReaderA.Log(); // Read the decrypted header. - Result rc = headerStorage.Get.Read(0, SpanHelpers.AsByteSpan(ref _header)); - if (rc.IsFailure()) return rc.Miss(); + Result res = headerStorage.Get.Read(0, SpanHelpers.AsByteSpan(ref _header)); + if (res.IsFailure()) return res.Miss(); // Check if the NCA magic value is correct. Result signatureResult = CheckSignature(in _header); @@ -101,16 +101,16 @@ public class NcaReader : IDisposable if (cryptoConfig.IsDev) { // Read the header without decrypting it and check the magic value again. - rc = baseStorage.Get.Read(0, SpanHelpers.AsByteSpan(ref _header)); - if (rc.IsFailure()) return rc.Miss(); + res = baseStorage.Get.Read(0, SpanHelpers.AsByteSpan(ref _header)); + if (res.IsFailure()) return res.Miss(); - rc = CheckSignature(in _header); - if (rc.IsFailure()) + res = CheckSignature(in _header); + if (res.IsFailure()) return signatureResult.Miss(); // We have a plaintext header. Get an IStorage of just the header. - rc = baseStorage.Get.GetSize(out long baseStorageSize); - if (rc.IsFailure()) return rc.Miss(); + res = baseStorage.Get.GetSize(out long baseStorageSize); + if (res.IsFailure()) return res.Miss(); headerStorage.Reset(new SubStorage(in baseStorage, 0, baseStorageSize)); @@ -500,8 +500,8 @@ public class NcaFsHeaderReader { _fsIndex = -1; - Result rc = reader.ReadHeader(out _header, index); - if (rc.IsFailure()) return rc.Miss(); + Result res = reader.ReadHeader(out _header, index); + if (res.IsFailure()) return res.Miss(); Unsafe.SkipInit(out Hash hash); IHash256GeneratorFactory generator = reader.GetHashGeneratorFactorySelector().GetFactory(HashAlgorithmType.Sha2); @@ -568,8 +568,8 @@ public class NcaFsHeaderReader { Assert.SdkRequires(IsInitialized()); - Result rc = _header.GetHashTargetOffset(out outOffset); - if (rc.IsFailure()) return rc.Miss(); + Result res = _header.GetHashTargetOffset(out outOffset); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/FsSystem/PartitionFile.cs b/src/LibHac/FsSystem/PartitionFile.cs index 20acad76..487193ed 100644 --- a/src/LibHac/FsSystem/PartitionFile.cs +++ b/src/LibHac/FsSystem/PartitionFile.cs @@ -24,8 +24,8 @@ public class PartitionFile : IFile { bytesRead = 0; - Result rc = DryRead(out long toRead, offset, destination.Length, in option, Mode); - if (rc.IsFailure()) return rc; + Result res = DryRead(out long toRead, offset, destination.Length, in option, Mode); + if (res.IsFailure()) return res.Miss(); long storageOffset = Offset + offset; BaseStorage.Read(storageOffset, destination.Slice(0, (int)toRead)); @@ -36,15 +36,15 @@ public class PartitionFile : IFile protected override Result DoWrite(long offset, ReadOnlySpan source, in WriteOption option) { - Result rc = DryWrite(out bool isResizeNeeded, offset, source.Length, in option, Mode); - if (rc.IsFailure()) return rc; + Result res = DryWrite(out bool isResizeNeeded, offset, source.Length, in option, Mode); + if (res.IsFailure()) return res.Miss(); if (isResizeNeeded) return ResultFs.UnsupportedWriteForPartitionFile.Log(); if (offset > Size) return ResultFs.OutOfRange.Log(); - rc = BaseStorage.Write(offset, source); - if (rc.IsFailure()) return rc; + res = BaseStorage.Write(offset, source); + if (res.IsFailure()) return res.Miss(); // N doesn't flush if the flag is set if (option.HasFlushFlag()) diff --git a/src/LibHac/FsSystem/PartitionFileSystemCore.cs b/src/LibHac/FsSystem/PartitionFileSystemCore.cs index 38964425..75c95c2e 100644 --- a/src/LibHac/FsSystem/PartitionFileSystemCore.cs +++ b/src/LibHac/FsSystem/PartitionFileSystemCore.cs @@ -19,8 +19,8 @@ public class PartitionFileSystemCore : IFileSystem where T : unmanaged, IPart public Result Initialize(ref SharedRef baseStorage) { - Result rc = Initialize(baseStorage.Get); - if (rc.IsFailure()) return rc; + Result res = Initialize(baseStorage.Get); + if (res.IsFailure()) return res.Miss(); _baseStorageShared.SetByMove(ref baseStorage); return Result.Success; @@ -33,8 +33,8 @@ public class PartitionFileSystemCore : IFileSystem where T : unmanaged, IPart _metaData = new PartitionFileSystemMetaCore(); - Result rc = _metaData.Initialize(baseStorage); - if (rc.IsFailure()) return rc; + Result res = _metaData.Initialize(baseStorage); + if (res.IsFailure()) return res.Miss(); _baseStorage = baseStorage; _dataOffset = _metaData.Size; @@ -145,8 +145,8 @@ public class PartitionFileSystemCore : IFileSystem where T : unmanaged, IPart { UnsafeHelpers.SkipParamInit(out bytesRead); - Result rc = DryRead(out long bytesToRead, offset, destination.Length, in option, Mode); - if (rc.IsFailure()) return rc; + Result res = DryRead(out long bytesToRead, offset, destination.Length, in option, Mode); + if (res.IsFailure()) return res.Miss(); bool hashNeeded = false; long fileStorageOffset = ParentFs._dataOffset + _entry.Offset; @@ -164,7 +164,7 @@ public class PartitionFileSystemCore : IFileSystem where T : unmanaged, IPart if (!hashNeeded) { - rc = ParentFs._baseStorage.Read(fileStorageOffset + offset, destination.Slice(0, (int)bytesToRead)); + res = ParentFs._baseStorage.Read(fileStorageOffset + offset, destination.Slice(0, (int)bytesToRead)); } else { @@ -192,8 +192,8 @@ public class PartitionFileSystemCore : IFileSystem where T : unmanaged, IPart // If the area to read contains the entire hashed area if (entry.HashOffset >= offset && hashEnd <= readEnd) { - rc = ParentFs._baseStorage.Read(storageOffset, destination.Slice(0, (int)bytesToRead)); - if (rc.IsFailure()) return rc; + res = ParentFs._baseStorage.Read(storageOffset, destination.Slice(0, (int)bytesToRead)); + if (res.IsFailure()) return res.Miss(); Span hashedArea = destination.Slice((int)(entry.HashOffset - offset), entry.HashSize); sha256.Update(hashedArea); @@ -219,8 +219,8 @@ public class PartitionFileSystemCore : IFileSystem where T : unmanaged, IPart int toRead = Math.Min(hashRemaining, hashBufferSize); Span hashBufferSliced = hashBuffer.Slice(0, toRead); - rc = ParentFs._baseStorage.Read(readPos, hashBufferSliced); - if (rc.IsFailure()) return rc; + res = ParentFs._baseStorage.Read(readPos, hashBufferSliced); + if (res.IsFailure()) return res.Miss(); sha256.Update(hashBufferSliced); @@ -249,19 +249,19 @@ public class PartitionFileSystemCore : IFileSystem where T : unmanaged, IPart return ResultFs.Sha256PartitionHashVerificationFailed.Log(); } - rc = Result.Success; + res = Result.Success; } - if (rc.IsSuccess()) + if (res.IsSuccess()) bytesRead = bytesToRead; - return rc; + return res; } protected override Result DoWrite(long offset, ReadOnlySpan source, in WriteOption option) { - Result rc = DryWrite(out bool isResizeNeeded, offset, source.Length, in option, Mode); - if (rc.IsFailure()) return rc; + Result res = DryWrite(out bool isResizeNeeded, offset, source.Length, in option, Mode); + if (res.IsFailure()) return res.Miss(); if (isResizeNeeded) return ResultFs.UnsupportedWriteForPartitionFile.Log(); diff --git a/src/LibHac/FsSystem/PartitionFileSystemMetaCore.cs b/src/LibHac/FsSystem/PartitionFileSystemMetaCore.cs index 4fce01c7..014be34a 100644 --- a/src/LibHac/FsSystem/PartitionFileSystemMetaCore.cs +++ b/src/LibHac/FsSystem/PartitionFileSystemMetaCore.cs @@ -26,8 +26,8 @@ public class PartitionFileSystemMetaCore where T : unmanaged, IPartitionFileS { var header = new Header(); - Result rc = baseStorage.Read(0, SpanHelpers.AsByteSpan(ref header)); - if (rc.IsFailure()) return rc; + Result res = baseStorage.Read(0, SpanHelpers.AsByteSpan(ref header)); + if (res.IsFailure()) return res.Miss(); int pfsMetaSize = HeaderSize + header.EntryCount * EntrySize + header.StringTableSize; Buffer = new byte[pfsMetaSize]; @@ -41,8 +41,8 @@ public class PartitionFileSystemMetaCore where T : unmanaged, IPartitionFileS if (buffer.Length < HeaderSize) return ResultFs.InvalidSize.Log(); - Result rc = baseStorage.Read(0, buffer.Slice(0, HeaderSize)); - if (rc.IsFailure()) return rc; + Result res = baseStorage.Read(0, buffer.Slice(0, HeaderSize)); + if (res.IsFailure()) return res.Miss(); ref Header header = ref Unsafe.As(ref MemoryMarshal.GetReference(buffer)); @@ -62,15 +62,15 @@ public class PartitionFileSystemMetaCore where T : unmanaged, IPartitionFileS if (buffer.Length < pfsMetaSize) return ResultFs.InvalidSize.Log(); - rc = baseStorage.Read(entryTableOffset, + res = baseStorage.Read(entryTableOffset, buffer.Slice(entryTableOffset, entryTableSize + StringTableSize)); - if (rc.IsSuccess()) + if (res.IsSuccess()) { IsInitialized = true; } - return rc; + return res; } public int GetEntryCount() diff --git a/src/LibHac/FsSystem/ReadOnlyBlockCacheStorage.cs b/src/LibHac/FsSystem/ReadOnlyBlockCacheStorage.cs index 2e48ca26..ddeabe34 100644 --- a/src/LibHac/FsSystem/ReadOnlyBlockCacheStorage.cs +++ b/src/LibHac/FsSystem/ReadOnlyBlockCacheStorage.cs @@ -74,8 +74,8 @@ public class ReadOnlyBlockCacheStorage : IStorage } // The block wasn't in the cache. Read from the base storage. - Result rc = _baseStorage.Get.Read(offset, destination); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseStorage.Get.Read(offset, destination); + if (res.IsFailure()) return res.Miss(); // Add the block to the cache. using (new ScopedLock(ref _mutex)) diff --git a/src/LibHac/FsSystem/SparseStorage.cs b/src/LibHac/FsSystem/SparseStorage.cs index 94936b0f..8e5b8ae8 100644 --- a/src/LibHac/FsSystem/SparseStorage.cs +++ b/src/LibHac/FsSystem/SparseStorage.cs @@ -98,8 +98,8 @@ public class SparseStorage : IndirectStorage if (GetEntryTable().IsEmpty()) { - Result rc = GetEntryTable().GetOffsets(out BucketTree.Offsets offsets); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetEntryTable().GetOffsets(out BucketTree.Offsets offsets); + if (res.IsFailure()) return res.Miss(); if (!offsets.IsInclude(offset, destination.Length)) return ResultFs.OutOfRange.Log(); @@ -110,16 +110,16 @@ public class SparseStorage : IndirectStorage { var closure = new OperatePerEntryClosure { OutBuffer = destination, Offset = offset }; - Result rc = OperatePerEntry(offset, destination.Length, enableContinuousReading: false, verifyEntryRanges: true, ref closure, + Result res = OperatePerEntry(offset, destination.Length, enableContinuousReading: false, verifyEntryRanges: true, ref closure, static (ref ValueSubStorage storage, long physicalOffset, long virtualOffset, long size, ref OperatePerEntryClosure closure) => { int bufferPosition = (int)(virtualOffset - closure.Offset); - Result rc = storage.Read(physicalOffset, closure.OutBuffer.Slice(bufferPosition, (int)size)); - if (rc.IsFailure()) return rc.Miss(); + Result res = storage.Read(physicalOffset, closure.OutBuffer.Slice(bufferPosition, (int)size)); + if (res.IsFailure()) return res.Miss(); return Result.Success; }); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } return Result.Success; diff --git a/src/LibHac/FsSystem/StorageFile.cs b/src/LibHac/FsSystem/StorageFile.cs index aa8cfb4b..ba683abd 100644 --- a/src/LibHac/FsSystem/StorageFile.cs +++ b/src/LibHac/FsSystem/StorageFile.cs @@ -27,8 +27,8 @@ public class StorageFile : IFile Assert.SdkRequiresNotNull(_baseStorage); - Result rc = DryRead(out long readSize, offset, destination.Length, in option, _mode); - if (rc.IsFailure()) return rc; + Result res = DryRead(out long readSize, offset, destination.Length, in option, _mode); + if (res.IsFailure()) return res.Miss(); if (readSize == 0) { @@ -36,8 +36,8 @@ public class StorageFile : IFile return Result.Success; } - rc = _baseStorage.Read(offset, destination.Slice(0, (int)readSize)); - if (rc.IsFailure()) return rc; + res = _baseStorage.Read(offset, destination.Slice(0, (int)readSize)); + if (res.IsFailure()) return res.Miss(); bytesRead = readSize; return Result.Success; @@ -47,22 +47,22 @@ public class StorageFile : IFile { Assert.SdkRequiresNotNull(_baseStorage); - Result rc = DryWrite(out bool isAppendNeeded, offset, source.Length, in option, _mode); - if (rc.IsFailure()) return rc; + Result res = DryWrite(out bool isAppendNeeded, offset, source.Length, in option, _mode); + if (res.IsFailure()) return res.Miss(); if (isAppendNeeded) { - rc = DoSetSize(offset + source.Length); - if (rc.IsFailure()) return rc; + res = DoSetSize(offset + source.Length); + if (res.IsFailure()) return res.Miss(); } - rc = _baseStorage.Write(offset, source); - if (rc.IsFailure()) return rc; + res = _baseStorage.Write(offset, source); + if (res.IsFailure()) return res.Miss(); if (option.HasFlushFlag()) { - rc = Flush(); - if (rc.IsFailure()) return rc.Miss(); + res = Flush(); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -89,8 +89,8 @@ public class StorageFile : IFile { Assert.SdkRequiresNotNull(_baseStorage); - Result rc = DrySetSize(size, _mode); - if (rc.IsFailure()) return rc.Miss(); + Result res = DrySetSize(size, _mode); + if (res.IsFailure()) return res.Miss(); return _baseStorage.SetSize(size); } @@ -107,8 +107,8 @@ public class StorageFile : IFile if (!_mode.HasFlag(OpenMode.Read)) return ResultFs.ReadUnpermitted.Log(); - Result rc = _baseStorage.OperateRange(OperationId.InvalidateCache, offset, size); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseStorage.OperateRange(OperationId.InvalidateCache, offset, size); + if (res.IsFailure()) return res.Miss(); break; } @@ -117,14 +117,14 @@ public class StorageFile : IFile if (offset < 0) return ResultFs.InvalidOffset.Log(); - Result rc = GetSize(out long fileSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = GetSize(out long fileSize); + if (res.IsFailure()) return res.Miss(); long operableSize = Math.Max(0, fileSize - offset); long operateSize = Math.Min(operableSize, size); - rc = _baseStorage.OperateRange(outBuffer, operationId, offset, operateSize, inBuffer); - if (rc.IsFailure()) return rc.Miss(); + res = _baseStorage.OperateRange(outBuffer, operationId, offset, operateSize, inBuffer); + if (res.IsFailure()) return res.Miss(); break; } diff --git a/src/LibHac/FsSystem/StorageLayoutTypeSetter.cs b/src/LibHac/FsSystem/StorageLayoutTypeSetter.cs index 24ba9488..e086e2df 100644 --- a/src/LibHac/FsSystem/StorageLayoutTypeSetter.cs +++ b/src/LibHac/FsSystem/StorageLayoutTypeSetter.cs @@ -327,8 +327,8 @@ internal class StorageLayoutTypeSetFileSystem : IFileSystem using var scopedContext = new ScopedStorageLayoutTypeSetter(_storageFlag); using var baseFile = new UniqueRef(); - Result rc = _baseFileSystem.Get.OpenFile(ref baseFile.Ref(), in path, mode); - if (rc.IsFailure()) return rc; + Result res = _baseFileSystem.Get.OpenFile(ref baseFile.Ref(), in path, mode); + if (res.IsFailure()) return res.Miss(); outFile.Reset(new StorageLayoutTypeSetFile(ref baseFile.Ref(), _storageFlag)); return Result.Success; @@ -340,8 +340,8 @@ internal class StorageLayoutTypeSetFileSystem : IFileSystem using var scopedContext = new ScopedStorageLayoutTypeSetter(_storageFlag); using var baseDirectory = new UniqueRef(); - Result rc = _baseFileSystem.Get.OpenDirectory(ref baseDirectory.Ref(), in path, mode); - if (rc.IsFailure()) return rc; + Result res = _baseFileSystem.Get.OpenDirectory(ref baseDirectory.Ref(), in path, mode); + if (res.IsFailure()) return res.Miss(); outDirectory.Reset(new StorageLayoutTypeSetDirectory(ref baseDirectory.Ref(), _storageFlag)); return Result.Success; diff --git a/src/LibHac/FsSystem/SubdirectoryFileSystem.cs b/src/LibHac/FsSystem/SubdirectoryFileSystem.cs index f228811d..db31526c 100644 --- a/src/LibHac/FsSystem/SubdirectoryFileSystem.cs +++ b/src/LibHac/FsSystem/SubdirectoryFileSystem.cs @@ -48,11 +48,11 @@ public class SubdirectoryFileSystem : IFileSystem UnsafeHelpers.SkipParamInit(out entryType); using var fullPath = new Path(); - Result rc = ResolveFullPath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.GetEntryType(out entryType, in fullPath); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.GetEntryType(out entryType, in fullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -62,11 +62,11 @@ public class SubdirectoryFileSystem : IFileSystem UnsafeHelpers.SkipParamInit(out freeSpace); using var fullPath = new Path(); - Result rc = ResolveFullPath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.GetFreeSpaceSize(out freeSpace, in fullPath); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.GetFreeSpaceSize(out freeSpace, in fullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -76,11 +76,11 @@ public class SubdirectoryFileSystem : IFileSystem UnsafeHelpers.SkipParamInit(out totalSpace); using var fullPath = new Path(); - Result rc = ResolveFullPath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.GetTotalSpaceSize(out totalSpace, in fullPath); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.GetTotalSpaceSize(out totalSpace, in fullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -90,11 +90,11 @@ public class SubdirectoryFileSystem : IFileSystem UnsafeHelpers.SkipParamInit(out timeStamp); using var fullPath = new Path(); - Result rc = ResolveFullPath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.GetFileTimeStampRaw(out timeStamp, in fullPath); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.GetFileTimeStampRaw(out timeStamp, in fullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -102,11 +102,11 @@ public class SubdirectoryFileSystem : IFileSystem protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) { using var fullPath = new Path(); - Result rc = ResolveFullPath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.OpenFile(ref outFile, in fullPath, mode); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.OpenFile(ref outFile, in fullPath, mode); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -115,11 +115,11 @@ public class SubdirectoryFileSystem : IFileSystem OpenDirectoryMode mode) { using var fullPath = new Path(); - Result rc = ResolveFullPath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.OpenDirectory(ref outDirectory, in fullPath, mode); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.OpenDirectory(ref outDirectory, in fullPath, mode); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -127,11 +127,11 @@ public class SubdirectoryFileSystem : IFileSystem protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { using var fullPath = new Path(); - Result rc = ResolveFullPath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.CreateFile(in fullPath, size, option); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.CreateFile(in fullPath, size, option); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -139,11 +139,11 @@ public class SubdirectoryFileSystem : IFileSystem protected override Result DoDeleteFile(in Path path) { using var fullPath = new Path(); - Result rc = ResolveFullPath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.DeleteFile(in fullPath); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.DeleteFile(in fullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -151,11 +151,11 @@ public class SubdirectoryFileSystem : IFileSystem protected override Result DoCreateDirectory(in Path path) { using var fullPath = new Path(); - Result rc = ResolveFullPath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.CreateDirectory(in fullPath); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.CreateDirectory(in fullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -163,11 +163,11 @@ public class SubdirectoryFileSystem : IFileSystem protected override Result DoDeleteDirectory(in Path path) { using var fullPath = new Path(); - Result rc = ResolveFullPath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.DeleteDirectory(in fullPath); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.DeleteDirectory(in fullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -175,11 +175,11 @@ public class SubdirectoryFileSystem : IFileSystem protected override Result DoDeleteDirectoryRecursively(in Path path) { using var fullPath = new Path(); - Result rc = ResolveFullPath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.DeleteDirectoryRecursively(in fullPath); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.DeleteDirectoryRecursively(in fullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -187,11 +187,11 @@ public class SubdirectoryFileSystem : IFileSystem protected override Result DoCleanDirectoryRecursively(in Path path) { using var fullPath = new Path(); - Result rc = ResolveFullPath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.CleanDirectoryRecursively(in fullPath); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.CleanDirectoryRecursively(in fullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -199,15 +199,15 @@ public class SubdirectoryFileSystem : IFileSystem protected override Result DoRenameFile(in Path currentPath, in Path newPath) { using var currentFullPath = new Path(); - Result rc = ResolveFullPath(ref currentFullPath.Ref(), in currentPath); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(ref currentFullPath.Ref(), in currentPath); + if (res.IsFailure()) return res.Miss(); using var newFullPath = new Path(); - rc = ResolveFullPath(ref newFullPath.Ref(), in newPath); - if (rc.IsFailure()) return rc; + res = ResolveFullPath(ref newFullPath.Ref(), in newPath); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.RenameFile(in currentFullPath, in newFullPath); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.RenameFile(in currentFullPath, in newFullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -215,15 +215,15 @@ public class SubdirectoryFileSystem : IFileSystem protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) { using var currentFullPath = new Path(); - Result rc = ResolveFullPath(ref currentFullPath.Ref(), in currentPath); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(ref currentFullPath.Ref(), in currentPath); + if (res.IsFailure()) return res.Miss(); using var newFullPath = new Path(); - rc = ResolveFullPath(ref newFullPath.Ref(), in newPath); - if (rc.IsFailure()) return rc; + res = ResolveFullPath(ref newFullPath.Ref(), in newPath); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.RenameDirectory(in currentFullPath, in newFullPath); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.RenameDirectory(in currentFullPath, in newFullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -232,11 +232,11 @@ public class SubdirectoryFileSystem : IFileSystem in Path path) { using var fullPath = new Path(); - Result rc = ResolveFullPath(ref fullPath.Ref(), in path); - if (rc.IsFailure()) return rc; + Result res = ResolveFullPath(ref fullPath.Ref(), in path); + if (res.IsFailure()) return res.Miss(); - rc = _baseFileSystem.QueryEntry(outBuffer, inBuffer, queryId, in fullPath); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.QueryEntry(outBuffer, inBuffer, queryId, in fullPath); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/FsSystem/SwitchStorage.cs b/src/LibHac/FsSystem/SwitchStorage.cs index 4a438ba2..81f57cf7 100644 --- a/src/LibHac/FsSystem/SwitchStorage.cs +++ b/src/LibHac/FsSystem/SwitchStorage.cs @@ -41,40 +41,40 @@ public class SwitchStorage : IStorage public override Result Read(long offset, Span destination) { - Result rc = SelectStorage().Read(offset, destination); - if (rc.IsFailure()) return rc.Miss(); + Result res = SelectStorage().Read(offset, destination); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public override Result Write(long offset, ReadOnlySpan source) { - Result rc = SelectStorage().Write(offset, source); - if (rc.IsFailure()) return rc.Miss(); + Result res = SelectStorage().Write(offset, source); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public override Result Flush() { - Result rc = SelectStorage().Flush(); - if (rc.IsFailure()) return rc.Miss(); + Result res = SelectStorage().Flush(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public override Result GetSize(out long size) { - Result rc = SelectStorage().GetSize(out size); - if (rc.IsFailure()) return rc.Miss(); + Result res = SelectStorage().GetSize(out size); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public override Result SetSize(long size) { - Result rc = SelectStorage().SetSize(size); - if (rc.IsFailure()) return rc.Miss(); + Result res = SelectStorage().SetSize(size); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -86,18 +86,18 @@ public class SwitchStorage : IStorage { case OperationId.InvalidateCache: { - Result rc = _trueStorage.Get.OperateRange(outBuffer, operationId, offset, size, inBuffer); - if (rc.IsFailure()) return rc.Miss(); + Result res = _trueStorage.Get.OperateRange(outBuffer, operationId, offset, size, inBuffer); + if (res.IsFailure()) return res.Miss(); - rc = _falseStorage.Get.OperateRange(outBuffer, operationId, offset, size, inBuffer); - if (rc.IsFailure()) return rc.Miss(); + res = _falseStorage.Get.OperateRange(outBuffer, operationId, offset, size, inBuffer); + if (res.IsFailure()) return res.Miss(); return Result.Success; } case OperationId.QueryRange: { - Result rc = SelectStorage().OperateRange(outBuffer, operationId, offset, size, inBuffer); - if (rc.IsFailure()) return rc.Miss(); + Result res = SelectStorage().OperateRange(outBuffer, operationId, offset, size, inBuffer); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -199,15 +199,15 @@ public class RegionSwitchStorage : IStorage { if (CheckRegions(out long currentSize, offset + bytesRead, destination.Length - bytesRead)) { - Result rc = _insideRegionStorage.Get.Read(offset + bytesRead, + Result res = _insideRegionStorage.Get.Read(offset + bytesRead, destination.Slice(bytesRead, (int)currentSize)); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } else { - Result rc = _outsideRegionStorage.Get.Read(offset + bytesRead, + Result res = _outsideRegionStorage.Get.Read(offset + bytesRead, destination.Slice(bytesRead, (int)currentSize)); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } bytesRead += (int)currentSize; @@ -223,15 +223,15 @@ public class RegionSwitchStorage : IStorage { if (CheckRegions(out long currentSize, offset + bytesWritten, source.Length - bytesWritten)) { - Result rc = _insideRegionStorage.Get.Write(offset + bytesWritten, + Result res = _insideRegionStorage.Get.Write(offset + bytesWritten, source.Slice(bytesWritten, (int)currentSize)); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } else { - Result rc = _outsideRegionStorage.Get.Write(offset + bytesWritten, + Result res = _outsideRegionStorage.Get.Write(offset + bytesWritten, source.Slice(bytesWritten, (int)currentSize)); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } bytesWritten += (int)currentSize; @@ -242,30 +242,30 @@ public class RegionSwitchStorage : IStorage public override Result Flush() { - Result rc = _insideRegionStorage.Get.Flush(); - if (rc.IsFailure()) return rc.Miss(); + Result res = _insideRegionStorage.Get.Flush(); + if (res.IsFailure()) return res.Miss(); - rc = _outsideRegionStorage.Get.Flush(); - if (rc.IsFailure()) return rc.Miss(); + res = _outsideRegionStorage.Get.Flush(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public override Result GetSize(out long size) { - Result rc = _insideRegionStorage.Get.GetSize(out size); - if (rc.IsFailure()) return rc.Miss(); + Result res = _insideRegionStorage.Get.GetSize(out size); + if (res.IsFailure()) return res.Miss(); return Result.Success; } public override Result SetSize(long size) { - Result rc = _insideRegionStorage.Get.SetSize(size); - if (rc.IsFailure()) return rc.Miss(); + Result res = _insideRegionStorage.Get.SetSize(size); + if (res.IsFailure()) return res.Miss(); - rc = _outsideRegionStorage.Get.SetSize(size); - if (rc.IsFailure()) return rc.Miss(); + res = _outsideRegionStorage.Get.SetSize(size); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -276,11 +276,11 @@ public class RegionSwitchStorage : IStorage { case OperationId.InvalidateCache: { - Result rc = _insideRegionStorage.Get.OperateRange(outBuffer, operationId, offset, size, inBuffer); - if (rc.IsFailure()) return rc.Miss(); + Result res = _insideRegionStorage.Get.OperateRange(outBuffer, operationId, offset, size, inBuffer); + if (res.IsFailure()) return res.Miss(); - rc = _outsideRegionStorage.Get.OperateRange(outBuffer, operationId, offset, size, inBuffer); - if (rc.IsFailure()) return rc.Miss(); + res = _outsideRegionStorage.Get.OperateRange(outBuffer, operationId, offset, size, inBuffer); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -296,15 +296,15 @@ public class RegionSwitchStorage : IStorage if (CheckRegions(out long currentSize, offset + bytesProcessed, size - bytesProcessed)) { - Result rc = _insideRegionStorage.Get.OperateRange(SpanHelpers.AsByteSpan(ref currentInfo), + Result res = _insideRegionStorage.Get.OperateRange(SpanHelpers.AsByteSpan(ref currentInfo), operationId, offset + bytesProcessed, currentSize, inBuffer); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } else { - Result rc = _outsideRegionStorage.Get.OperateRange(SpanHelpers.AsByteSpan(ref currentInfo), + Result res = _outsideRegionStorage.Get.OperateRange(SpanHelpers.AsByteSpan(ref currentInfo), operationId, offset + bytesProcessed, currentSize, inBuffer); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } mergedInfo.Merge(in currentInfo); diff --git a/src/LibHac/FsSystem/TruncatedSubStorage.cs b/src/LibHac/FsSystem/TruncatedSubStorage.cs index d9b65863..cebb84f3 100644 --- a/src/LibHac/FsSystem/TruncatedSubStorage.cs +++ b/src/LibHac/FsSystem/TruncatedSubStorage.cs @@ -21,8 +21,8 @@ public class TruncatedSubStorage : SubStorage if (destination.Length == 0) return Result.Success; - Result rc = BaseStorage.GetSize(out long baseStorageSize); - if (rc.IsFailure()) return rc; + Result res = BaseStorage.GetSize(out long baseStorageSize); + if (res.IsFailure()) return res.Miss(); long availableSize = baseStorageSize - offset; long sizeToRead = Math.Min(destination.Length, availableSize); @@ -35,8 +35,8 @@ public class TruncatedSubStorage : SubStorage if (source.Length == 0) return Result.Success; - Result rc = BaseStorage.GetSize(out long baseStorageSize); - if (rc.IsFailure()) return rc; + Result res = BaseStorage.GetSize(out long baseStorageSize); + if (res.IsFailure()) return res.Miss(); long availableSize = baseStorageSize - offset; long sizeToWrite = Math.Min(source.Length, availableSize); diff --git a/src/LibHac/FsSystem/UnionStorage.cs b/src/LibHac/FsSystem/UnionStorage.cs index f5f61635..87323751 100644 --- a/src/LibHac/FsSystem/UnionStorage.cs +++ b/src/LibHac/FsSystem/UnionStorage.cs @@ -84,8 +84,8 @@ public class UnionStorage : IStorage { Assert.SdkRequiresNull(_buffer); - Result rc = logStorage.Read(0, SpanHelpers.AsByteSpan(ref _blockSize)); - if (rc.IsFailure()) return rc.Miss(); + Result res = logStorage.Read(0, SpanHelpers.AsByteSpan(ref _blockSize)); + if (res.IsFailure()) return res.Miss(); if (blockSize <= 1 || !BitUtil.IsPowerOfTwo(blockSize) || blockSize != _blockSize) return ResultFs.InvalidLogBlockSize.Log(); @@ -94,8 +94,8 @@ public class UnionStorage : IStorage for (long offset = LogHeaderSize; ; offset += GetLogSize(_blockSize)) { long offsetOriginal = 0; - rc = logStorage.Read(offset, SpanHelpers.AsByteSpan(ref offsetOriginal)); - if (rc.IsFailure()) return rc.Miss(); + res = logStorage.Read(offset, SpanHelpers.AsByteSpan(ref offsetOriginal)); + if (res.IsFailure()) return res.Miss(); if (offsetOriginal == Sentinel) break; @@ -121,11 +121,11 @@ public class UnionStorage : IStorage long tailOffset = GetLogTailOffset(_blockSize, _blockCount); long value = Sentinel; - Result rc = _logStorage.Write(tailOffset, SpanHelpers.AsReadOnlyByteSpan(in value)); - if (rc.IsFailure()) return rc.Miss(); + Result res = _logStorage.Write(tailOffset, SpanHelpers.AsReadOnlyByteSpan(in value)); + if (res.IsFailure()) return res.Miss(); - rc = _logStorage.Flush(); - if (rc.IsFailure()) return rc.Miss(); + res = _logStorage.Flush(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -143,17 +143,17 @@ public class UnionStorage : IStorage for (long offset = LogHeaderSize; offset < tailOffset; offset += logSize) { long offsetOriginal = 0; - Result rc = _logStorage.Read(offset, SpanHelpers.AsByteSpan(ref offsetOriginal)); - if (rc.IsFailure()) return rc.Miss(); + Result res = _logStorage.Read(offset, SpanHelpers.AsByteSpan(ref offsetOriginal)); + if (res.IsFailure()) return res.Miss(); if (offsetOriginal == Sentinel) return ResultFs.UnexpectedEndOfLog.Log(); - rc = _logStorage.Read(GetDataOffset(offset), _buffer); - if (rc.IsFailure()) return rc.Miss(); + res = _logStorage.Read(GetDataOffset(offset), _buffer); + if (res.IsFailure()) return res.Miss(); - rc = _baseStorage.Write(offsetOriginal, _buffer); - if (rc.IsFailure()) return rc.Miss(); + res = _baseStorage.Write(offsetOriginal, _buffer); + if (res.IsFailure()) return res.Miss(); } return _baseStorage.Flush(); @@ -180,19 +180,19 @@ public class UnionStorage : IStorage Span currentDestination = destination.Slice((int)offsetBuffer, (int)sizeToRead); // Check if the log contains the block we need - Result rc = FindLog(out bool found, out long offsetLog, offsetOriginal); - if (rc.IsFailure()) return rc.Miss(); + Result res = FindLog(out bool found, out long offsetLog, offsetOriginal); + if (res.IsFailure()) return res.Miss(); // If it does, read from the log; otherwise read from the base storage if (found) { - rc = _logStorage.Read(GetDataOffset(offsetLog) + sizeSkipBlock, currentDestination); - if (rc.IsFailure()) return rc.Miss(); + res = _logStorage.Read(GetDataOffset(offsetLog) + sizeSkipBlock, currentDestination); + if (res.IsFailure()) return res.Miss(); } else { - rc = _baseStorage.Read(offsetOriginal + sizeSkipBlock, currentDestination); - if (rc.IsFailure()) return rc.Miss(); + res = _baseStorage.Read(offsetOriginal + sizeSkipBlock, currentDestination); + if (res.IsFailure()) return res.Miss(); } offsetBuffer += sizeToRead; @@ -227,40 +227,40 @@ public class UnionStorage : IStorage ReadOnlySpan currentSource = source.Slice((int)offsetBuffer, (int)sizeToWrite); // Check if the log contains the block we need. - Result rc = FindLog(out bool found, out long offsetLog, offsetOriginal); - if (rc.IsFailure()) return rc.Miss(); + Result res = FindLog(out bool found, out long offsetLog, offsetOriginal); + if (res.IsFailure()) return res.Miss(); if (found) { // If it does, write directly to the log. _logStorage.Write(GetDataOffset(offsetLog) + sizeSkipBlock, currentSource); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } else { // Otherwise we need to add a new entry to the log. _logStorage.Write(offsetLog, SpanHelpers.AsReadOnlyByteSpan(in offsetOriginal)); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); if (sizeToWrite == _blockSize) { // If we're writing a complete block we can write the entire block directly to the log. _logStorage.Write(GetDataOffset(offsetLog) + sizeSkipBlock, currentSource); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } else { // If we're writing a partial block we need to read the existing data block from the base storage // into a buffer first. _baseStorage.Read(offsetOriginal, _buffer); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); // Fill in the appropriate parts of the buffer with our new data. currentSource.CopyTo(_buffer.AsSpan((int)sizeSkipBlock, (int)sizeToWrite)); // Write the entire modified block to the new log entry. _logStorage.Write(GetDataOffset(offsetLog), _buffer); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } _blockCount++; @@ -278,11 +278,11 @@ public class UnionStorage : IStorage { Assert.SdkRequiresNotNull(_buffer); - Result rc = _baseStorage.Flush(); - if (rc.IsFailure()) return rc.Miss(); + Result res = _baseStorage.Flush(); + if (res.IsFailure()) return res.Miss(); - rc = _logStorage.Flush(); - if (rc.IsFailure()) return rc.Miss(); + res = _logStorage.Flush(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -306,13 +306,13 @@ public class UnionStorage : IStorage currentOffset < offset + size; currentOffset += _blockSize) { - Result rc = FindLog(out bool found, out long offsetLog, currentOffset); - if (rc.IsFailure()) return rc.Miss(); + Result res = FindLog(out bool found, out long offsetLog, currentOffset); + if (res.IsFailure()) return res.Miss(); if (found) { _logStorage.OperateRange(outBuffer, operationId, offsetLog, _blockSize, inBuffer); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); } } @@ -333,8 +333,8 @@ public class UnionStorage : IStorage for (long logOffset = LogHeaderSize; logOffset < logTailOffset; logOffset += logSize) { long offset = 0; - Result rc = _logStorage.Read(logOffset, SpanHelpers.AsByteSpan(ref offset)); - if (rc.IsFailure()) return rc.Miss(); + Result res = _logStorage.Read(logOffset, SpanHelpers.AsByteSpan(ref offset)); + if (res.IsFailure()) return res.Miss(); if (offset == Sentinel) return ResultFs.LogNotFound.Log(); diff --git a/src/LibHac/FsSystem/Utility.cs b/src/LibHac/FsSystem/Utility.cs index 76569d1b..a38b2b1b 100644 --- a/src/LibHac/FsSystem/Utility.cs +++ b/src/LibHac/FsSystem/Utility.cs @@ -41,40 +41,40 @@ internal static class Utility { using var directory = new UniqueRef(); - Result rc = fs.OpenDirectory(ref directory.Ref(), in workPath, OpenDirectoryMode.All); - if (rc.IsFailure()) return rc; + Result res = fs.OpenDirectory(ref directory.Ref(), in workPath, OpenDirectoryMode.All); + if (res.IsFailure()) return res.Miss(); while (true) { - rc = directory.Get.Read(out long entriesRead, SpanHelpers.AsSpan(ref dirEntry)); - if (rc.IsFailure()) return rc; + res = directory.Get.Read(out long entriesRead, SpanHelpers.AsSpan(ref dirEntry)); + if (res.IsFailure()) return res.Miss(); if (entriesRead == 0) break; workPath.AppendChild(dirEntry.Name); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); if (dirEntry.Type == DirectoryEntryType.Directory) { - rc = onEnterDir(in workPath, in dirEntry, ref closure); - if (rc.IsFailure()) return rc; + res = onEnterDir(in workPath, in dirEntry, ref closure); + if (res.IsFailure()) return res.Miss(); - rc = IterateDirectoryRecursivelyInternal(fs, ref workPath, ref dirEntry, onEnterDir, onExitDir, + res = IterateDirectoryRecursivelyInternal(fs, ref workPath, ref dirEntry, onEnterDir, onExitDir, onFile, ref closure); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = onExitDir(in workPath, in dirEntry, ref closure); - if (rc.IsFailure()) return rc; + res = onExitDir(in workPath, in dirEntry, ref closure); + if (res.IsFailure()) return res.Miss(); } else { - rc = onFile(in workPath, in dirEntry, ref closure); - if (rc.IsFailure()) return rc; + res = onFile(in workPath, in dirEntry, ref closure); + if (res.IsFailure()) return res.Miss(); } - rc = workPath.RemoveChild(); - if (rc.IsFailure()) return rc; + res = workPath.RemoveChild(); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -88,40 +88,40 @@ internal static class Utility while (true) { - Result rc = fs.OpenDirectory(ref directory.Ref(), in workPath, OpenDirectoryMode.All); - if (rc.IsFailure()) return rc; + Result res = fs.OpenDirectory(ref directory.Ref(), in workPath, OpenDirectoryMode.All); + if (res.IsFailure()) return res.Miss(); - rc = directory.Get.Read(out long entriesRead, SpanHelpers.AsSpan(ref dirEntry)); - if (rc.IsFailure()) return rc; + res = directory.Get.Read(out long entriesRead, SpanHelpers.AsSpan(ref dirEntry)); + if (res.IsFailure()) return res.Miss(); directory.Reset(); if (entriesRead == 0) break; - rc = workPath.AppendChild(dirEntry.Name); - if (rc.IsFailure()) return rc; + res = workPath.AppendChild(dirEntry.Name); + if (res.IsFailure()) return res.Miss(); if (dirEntry.Type == DirectoryEntryType.Directory) { - rc = onEnterDir(in workPath, in dirEntry, ref closure); - if (rc.IsFailure()) return rc; + res = onEnterDir(in workPath, in dirEntry, ref closure); + if (res.IsFailure()) return res.Miss(); - rc = CleanupDirectoryRecursivelyInternal(fs, ref workPath, ref dirEntry, onEnterDir, onExitDir, + res = CleanupDirectoryRecursivelyInternal(fs, ref workPath, ref dirEntry, onEnterDir, onExitDir, onFile, ref closure); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = onExitDir(in workPath, in dirEntry, ref closure); - if (rc.IsFailure()) return rc; + res = onExitDir(in workPath, in dirEntry, ref closure); + if (res.IsFailure()) return res.Miss(); } else { - rc = onFile(in workPath, in dirEntry, ref closure); - if (rc.IsFailure()) return rc; + res = onFile(in workPath, in dirEntry, ref closure); + if (res.IsFailure()) return res.Miss(); } - rc = workPath.RemoveChild(); - if (rc.IsFailure()) return rc; + res = workPath.RemoveChild(); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -132,12 +132,12 @@ internal static class Utility ref FsIterationTaskClosure closure) { using var pathBuffer = new Path(); - Result rc = pathBuffer.Initialize(in rootPath); - if (rc.IsFailure()) return rc; + Result res = pathBuffer.Initialize(in rootPath); + if (res.IsFailure()) return res.Miss(); - rc = IterateDirectoryRecursivelyInternal(fs, ref pathBuffer.Ref(), ref dirEntry, onEnterDir, onExitDir, + res = IterateDirectoryRecursivelyInternal(fs, ref pathBuffer.Ref(), ref dirEntry, onEnterDir, onExitDir, onFile, ref closure); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -147,8 +147,8 @@ internal static class Utility ref FsIterationTaskClosure closure) { using var pathBuffer = new Path(); - Result rc = pathBuffer.Initialize(in rootPath); - if (rc.IsFailure()) return rc; + Result res = pathBuffer.Initialize(in rootPath); + if (res.IsFailure()) return res.Miss(); return CleanupDirectoryRecursivelyInternal(fs, ref pathBuffer.Ref(), ref dirEntry, onEnterDir, onExitDir, onFile, ref closure); @@ -159,18 +159,18 @@ internal static class Utility { // Open source file. using var sourceFile = new UniqueRef(); - Result rc = sourceFileSystem.OpenFile(ref sourceFile.Ref(), sourcePath, OpenMode.Read); - if (rc.IsFailure()) return rc; + Result res = sourceFileSystem.OpenFile(ref sourceFile.Ref(), sourcePath, OpenMode.Read); + if (res.IsFailure()) return res.Miss(); - rc = sourceFile.Get.GetSize(out long fileSize); - if (rc.IsFailure()) return rc; + res = sourceFile.Get.GetSize(out long fileSize); + if (res.IsFailure()) return res.Miss(); using var destFile = new UniqueRef(); - rc = destFileSystem.CreateFile(in destPath, fileSize); - if (rc.IsFailure()) return rc; + res = destFileSystem.CreateFile(in destPath, fileSize); + if (res.IsFailure()) return res.Miss(); - rc = destFileSystem.OpenFile(ref destFile.Ref(), in destPath, OpenMode.Write); - if (rc.IsFailure()) return rc; + res = destFileSystem.OpenFile(ref destFile.Ref(), in destPath, OpenMode.Write); + if (res.IsFailure()) return res.Miss(); // Read/Write file in work-buffer-sized chunks. long remaining = fileSize; @@ -178,11 +178,11 @@ internal static class Utility while (remaining > 0) { - rc = sourceFile.Get.Read(out long bytesRead, offset, workBuffer, ReadOption.None); - if (rc.IsFailure()) return rc; + res = sourceFile.Get.Read(out long bytesRead, offset, workBuffer, ReadOption.None); + if (res.IsFailure()) return res.Miss(); - rc = destFile.Get.Write(offset, workBuffer.Slice(0, (int)bytesRead), WriteOption.None); - if (rc.IsFailure()) return rc; + res = destFile.Get.Write(offset, workBuffer.Slice(0, (int)bytesRead), WriteOption.None); + if (res.IsFailure()) return res.Miss(); remaining -= bytesRead; offset += bytesRead; @@ -196,8 +196,8 @@ internal static class Utility { static Result OnEnterDir(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) { - Result rc = closure.DestinationPathBuffer.AppendChild(entry.Name); - if (rc.IsFailure()) return rc; + Result res = closure.DestinationPathBuffer.AppendChild(entry.Name); + if (res.IsFailure()) return res.Miss(); return closure.SourceFileSystem.CreateDirectory(in closure.DestinationPathBuffer); } @@ -209,12 +209,12 @@ internal static class Utility static Result OnFile(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) { - Result rc = closure.DestinationPathBuffer.AppendChild(entry.Name); - if (rc.IsFailure()) return rc; + Result res = closure.DestinationPathBuffer.AppendChild(entry.Name); + if (res.IsFailure()) return res.Miss(); - rc = CopyFile(closure.DestFileSystem, closure.SourceFileSystem, in closure.DestinationPathBuffer, + res = CopyFile(closure.DestFileSystem, closure.SourceFileSystem, in closure.DestinationPathBuffer, in path, closure.Buffer); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return closure.DestinationPathBuffer.RemoveChild(); } @@ -224,14 +224,14 @@ internal static class Utility closure.SourceFileSystem = sourceFileSystem; closure.DestFileSystem = destinationFileSystem; - Result rc = closure.DestinationPathBuffer.Initialize(destinationPath); - if (rc.IsFailure()) return rc; + Result res = closure.DestinationPathBuffer.Initialize(destinationPath); + if (res.IsFailure()) return res.Miss(); - rc = IterateDirectoryRecursively(sourceFileSystem, in sourcePath, ref dirEntry, OnEnterDir, OnExitDir, + res = IterateDirectoryRecursively(sourceFileSystem, in sourcePath, ref dirEntry, OnEnterDir, OnExitDir, OnFile, ref closure); closure.DestinationPathBuffer.Dispose(); - return rc; + return res; } public static Result CopyDirectoryRecursively(IFileSystem fileSystem, in Path destinationPath, @@ -241,13 +241,13 @@ internal static class Utility closure.Buffer = workBuffer; closure.SourceFileSystem = fileSystem; - Result rc = closure.DestinationPathBuffer.Initialize(destinationPath); - if (rc.IsFailure()) return rc; + Result res = closure.DestinationPathBuffer.Initialize(destinationPath); + if (res.IsFailure()) return res.Miss(); static Result OnEnterDir(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) { - Result rc = closure.DestinationPathBuffer.AppendChild(entry.Name); - if (rc.IsFailure()) return rc; + Result res = closure.DestinationPathBuffer.AppendChild(entry.Name); + if (res.IsFailure()) return res.Miss(); return closure.SourceFileSystem.CreateDirectory(in closure.DestinationPathBuffer); } @@ -259,21 +259,21 @@ internal static class Utility static Result OnFile(in Path path, in DirectoryEntry entry, ref FsIterationTaskClosure closure) { - Result rc = closure.DestinationPathBuffer.AppendChild(entry.Name); - if (rc.IsFailure()) return rc; + Result res = closure.DestinationPathBuffer.AppendChild(entry.Name); + if (res.IsFailure()) return res.Miss(); - rc = CopyFile(closure.SourceFileSystem, closure.SourceFileSystem, in closure.DestinationPathBuffer, + res = CopyFile(closure.SourceFileSystem, closure.SourceFileSystem, in closure.DestinationPathBuffer, in path, closure.Buffer); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return closure.DestinationPathBuffer.RemoveChild(); } - rc = IterateDirectoryRecursively(fileSystem, in sourcePath, ref dirEntry, OnEnterDir, OnExitDir, OnFile, + res = IterateDirectoryRecursively(fileSystem, in sourcePath, ref dirEntry, OnEnterDir, OnExitDir, OnFile, ref closure); closure.DestinationPathBuffer.Dispose(); - return rc; + return res; } public static Result VerifyDirectoryRecursively(IFileSystem fileSystem, Span workBuffer) @@ -285,15 +285,15 @@ internal static class Utility { using var file = new UniqueRef(); - Result rc = closure.SourceFileSystem.OpenFile(ref file.Ref(), in path, OpenMode.Read); - if (rc.IsFailure()) return rc; + Result res = closure.SourceFileSystem.OpenFile(ref file.Ref(), in path, OpenMode.Read); + if (res.IsFailure()) return res.Miss(); long offset = 0; while (true) { - rc = file.Get.Read(out long bytesRead, offset, closure.Buffer, ReadOption.None); - if (rc.IsFailure()) return rc; + res = file.Get.Read(out long bytesRead, offset, closure.Buffer, ReadOption.None); + if (res.IsFailure()) return res.Miss(); if (bytesRead < closure.Buffer.Length) break; @@ -305,8 +305,8 @@ internal static class Utility } using var rootPath = new Path(); - Result rc = PathFunctions.SetUpFixedPath(ref rootPath.Ref(), RootPath); - if (rc.IsFailure()) return rc; + Result res = PathFunctions.SetUpFixedPath(ref rootPath.Ref(), RootPath); + if (res.IsFailure()) return res.Miss(); var closure = new FsIterationTaskClosure(); closure.Buffer = workBuffer; @@ -323,38 +323,38 @@ internal static class Utility using var pathCopy = new Path(); bool isFinished; - Result rc = pathCopy.Initialize(in path); - if (rc.IsFailure()) return rc; + Result res = pathCopy.Initialize(in path); + if (res.IsFailure()) return res.Miss(); using var parser = new DirectoryPathParser(); - rc = parser.Initialize(ref pathCopy.Ref()); - if (rc.IsFailure()) return rc; + res = parser.Initialize(ref pathCopy.Ref()); + if (res.IsFailure()) return res.Miss(); do { // Check if the path exists - rc = fileSystem.GetEntryType(out DirectoryEntryType type, in parser.CurrentPath); - if (!rc.IsSuccess()) + res = fileSystem.GetEntryType(out DirectoryEntryType type, in parser.CurrentPath); + if (!res.IsSuccess()) { // Something went wrong if we get a result other than PathNotFound - if (!ResultFs.PathNotFound.Includes(rc)) - return rc; + if (!ResultFs.PathNotFound.Includes(res)) + return res; // Create the directory - rc = fileSystem.CreateDirectory(in parser.CurrentPath); - if (rc.IsFailure() && !ResultFs.PathAlreadyExists.Includes(rc)) - return rc; + res = fileSystem.CreateDirectory(in parser.CurrentPath); + if (res.IsFailure() && !ResultFs.PathAlreadyExists.Includes(res)) + return res; // Check once more if the path exists - rc = fileSystem.GetEntryType(out type, in parser.CurrentPath); - if (rc.IsFailure()) return rc; + res = fileSystem.GetEntryType(out type, in parser.CurrentPath); + if (res.IsFailure()) return res.Miss(); } if (type == DirectoryEntryType.File) return ResultFs.PathAlreadyExists.Log(); - rc = parser.ReadNext(out isFinished); - if (rc.IsFailure()) return rc; + res = parser.ReadNext(out isFinished); + if (res.IsFailure()) return res.Miss(); } while (!isFinished); return Result.Success; @@ -362,15 +362,15 @@ internal static class Utility public static Result EnsureDirectory(IFileSystem fileSystem, in Path path) { - Result rc = fileSystem.GetEntryType(out _, in path); + Result res = fileSystem.GetEntryType(out _, in path); - if (!rc.IsSuccess()) + if (!res.IsSuccess()) { - if (!ResultFs.PathNotFound.Includes(rc)) - return rc; + if (!ResultFs.PathNotFound.Includes(res)) + return res; - rc = EnsureDirectoryImpl(fileSystem, in path); - if (rc.IsFailure()) return rc; + res = EnsureDirectoryImpl(fileSystem, in path); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -413,8 +413,8 @@ internal static class Utility SemaphoreAdapter semaphore, ref SharedRef objectToPin) where T : class, IDisposable { using var semaphoreAdapter = new UniqueLock(); - Result rc = TryAcquireCountSemaphore(ref semaphoreAdapter.Ref(), semaphore); - if (rc.IsFailure()) return rc; + Result res = TryAcquireCountSemaphore(ref semaphoreAdapter.Ref(), semaphore); + if (res.IsFailure()) return res.Miss(); var lockWithPin = new UniqueLockWithPin(ref semaphoreAdapter.Ref(), ref objectToPin); using var uniqueLock = new UniqueRef(lockWithPin); diff --git a/src/LibHac/Kernel/InitialProcessBinaryReader.cs b/src/LibHac/Kernel/InitialProcessBinaryReader.cs index f677d1b2..16900abd 100644 --- a/src/LibHac/Kernel/InitialProcessBinaryReader.cs +++ b/src/LibHac/Kernel/InitialProcessBinaryReader.cs @@ -29,15 +29,15 @@ public class InitialProcessBinaryReader : IDisposable return ResultLibHac.NullArgument.Log(); // Verify there's enough data to read the header - Result rc = binaryStorage.Get.GetSize(out long iniSize); - if (rc.IsFailure()) return rc; + Result res = binaryStorage.Get.GetSize(out long iniSize); + if (res.IsFailure()) return res.Miss(); if (iniSize < Unsafe.SizeOf()) return ResultLibHac.InvalidIniFileSize.Log(); // Read the INI file header and validate some of its values. - rc = binaryStorage.Get.Read(0, SpanHelpers.AsByteSpan(ref _header)); - if (rc.IsFailure()) return rc; + res = binaryStorage.Get.Read(0, SpanHelpers.AsByteSpan(ref _header)); + if (res.IsFailure()) return res.Miss(); if (_header.Magic != ExpectedMagic) return ResultLibHac.InvalidIniMagic.Log(); @@ -47,8 +47,8 @@ public class InitialProcessBinaryReader : IDisposable // There's no metadata with the offsets of each KIP; they're all stored sequentially in the file. // Read the size of each KIP to get their offsets. - rc = GetKipOffsets(out _offsets, binaryStorage, _header.ProcessCount); - if (rc.IsFailure()) return rc; + res = GetKipOffsets(out _offsets, binaryStorage, _header.ProcessCount); + if (res.IsFailure()) return res.Miss(); _storage.SetByCopy(in binaryStorage); return Result.Success; @@ -71,8 +71,8 @@ public class InitialProcessBinaryReader : IDisposable UnsafeHelpers.SkipParamInit(out kipOffsets); - Result rc = iniStorage.Get.GetSize(out long iniStorageSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = iniStorage.Get.GetSize(out long iniStorageSize); + if (res.IsFailure()) return res.Miss(); var offsets = new (int offset, int size)[processCount]; int offset = Unsafe.SizeOf(); @@ -83,8 +83,8 @@ public class InitialProcessBinaryReader : IDisposable using var kipStorage = new SharedRef(new SubStorage(in iniStorage, offset, iniStorageSize - offset)); - rc = kipReader.Initialize(in kipStorage); - if (rc.IsFailure()) return rc; + res = kipReader.Initialize(in kipStorage); + if (res.IsFailure()) return res.Miss(); int kipSize = kipReader.GetFileSize(); offsets[i] = (offset, kipSize); diff --git a/src/LibHac/Kernel/KipReader.cs b/src/LibHac/Kernel/KipReader.cs index 901c87b6..792616dc 100644 --- a/src/LibHac/Kernel/KipReader.cs +++ b/src/LibHac/Kernel/KipReader.cs @@ -45,14 +45,14 @@ public class KipReader : IDisposable return ResultLibHac.NullArgument.Log(); // Verify there's enough data to read the header - Result rc = kipData.Get.GetSize(out long kipSize); - if (rc.IsFailure()) return rc; + Result res = kipData.Get.GetSize(out long kipSize); + if (res.IsFailure()) return res.Miss(); if (kipSize < Unsafe.SizeOf()) return ResultLibHac.InvalidKipFileSize.Log(); - rc = kipData.Get.Read(0, SpanHelpers.AsByteSpan(ref _header)); - if (rc.IsFailure()) return rc; + res = kipData.Get.Read(0, SpanHelpers.AsByteSpan(ref _header)); + if (res.IsFailure()) return res.Miss(); if (!_header.IsValid) return ResultLibHac.InvalidKipMagic.Log(); @@ -71,8 +71,8 @@ public class KipReader : IDisposable { int kipFileSize = GetFileSize(); - Result rc = _kipStorage.Get.GetSize(out long inputFileSize); - if (rc.IsFailure()) return rc; + Result res = _kipStorage.Get.GetSize(out long inputFileSize); + if (res.IsFailure()) return res.Miss(); // Verify the input KIP file isn't truncated if (inputFileSize < kipFileSize) @@ -130,8 +130,8 @@ public class KipReader : IDisposable public Result ReadSegment(SegmentType segment, Span buffer) { - Result rc = GetSegmentSize(segment, out int segmentSize); - if (rc.IsFailure()) return rc; + Result res = GetSegmentSize(segment, out int segmentSize); + if (res.IsFailure()) return res.Miss(); if (buffer.Length < segmentSize) return ResultLibHac.BufferTooSmall.Log(); @@ -152,15 +152,15 @@ public class KipReader : IDisposable int offset = CalculateSegmentOffset((int)segment); // Verify the segment offset is in-range - rc = _kipStorage.Get.GetSize(out long kipSize); - if (rc.IsFailure()) return rc; + res = _kipStorage.Get.GetSize(out long kipSize); + if (res.IsFailure()) return res.Miss(); if (kipSize < offset + segmentHeader.FileSize) return ResultLibHac.InvalidKipFileSize.Log(); // Read the segment data. - rc = _kipStorage.Get.Read(offset, buffer.Slice(0, segmentHeader.FileSize)); - if (rc.IsFailure()) return rc; + res = _kipStorage.Get.Read(offset, buffer.Slice(0, segmentHeader.FileSize)); + if (res.IsFailure()) return res.Miss(); // Decompress if necessary. bool isCompressed = segment switch @@ -173,8 +173,8 @@ public class KipReader : IDisposable if (isCompressed) { - rc = DecompressBlz(buffer, segmentHeader.FileSize); - if (rc.IsFailure()) return rc; + res = DecompressBlz(buffer, segmentHeader.FileSize); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -192,8 +192,8 @@ public class KipReader : IDisposable { if (Segments[i].FileSize != 0) { - Result rc = ReadSegment((SegmentType)i, segmentBuffer); - if (rc.IsFailure()) return rc; + Result res = ReadSegment((SegmentType)i, segmentBuffer); + if (res.IsFailure()) return res.Miss(); segmentBuffer = segmentBuffer.Slice(Segments[i].Size); } diff --git a/src/LibHac/Kvdb/FlatMapKeyValueStore.cs b/src/LibHac/Kvdb/FlatMapKeyValueStore.cs index 185405f3..f7ec5ce0 100644 --- a/src/LibHac/Kvdb/FlatMapKeyValueStore.cs +++ b/src/LibHac/Kvdb/FlatMapKeyValueStore.cs @@ -57,8 +57,8 @@ public class FlatMapKeyValueStore : IDisposable where TKey : unmanaged, IE MemoryResource memoryResource, MemoryResource autoBufferMemoryResource) { // The root path must be an existing directory - Result rc = fsClient.GetEntryType(out DirectoryEntryType rootEntryType, rootPath); - if (rc.IsFailure()) return rc; + Result res = fsClient.GetEntryType(out DirectoryEntryType rootEntryType, rootPath); + if (res.IsFailure()) return res.Miss(); if (rootEntryType == DirectoryEntryType.File) return ResultFs.PathNotFound.Log(); @@ -66,8 +66,8 @@ public class FlatMapKeyValueStore : IDisposable where TKey : unmanaged, IE var sb = new U8StringBuilder(_archivePath.Get()); sb.Append(rootPath).Append(ArchiveFileName); - rc = _index.Initialize(capacity, memoryResource); - if (rc.IsFailure()) return rc; + res = _index.Initialize(capacity, memoryResource); + if (res.IsFailure()) return res.Miss(); _fsClient = fsClient; _memoryResource = memoryResource; @@ -95,18 +95,18 @@ public class FlatMapKeyValueStore : IDisposable where TKey : unmanaged, IE try { - Result rc = ReadArchive(ref buffer); - if (rc.IsFailure()) + Result res = ReadArchive(ref buffer); + if (res.IsFailure()) { // If the file is not found, we don't have any entries to load. - if (ResultFs.PathNotFound.Includes(rc)) - return Result.Success.LogConverted(rc); + if (ResultFs.PathNotFound.Includes(res)) + return Result.Success.LogConverted(res); - return rc; + return res; } - rc = LoadFrom(buffer.Get()); - if (rc.IsFailure()) return rc; + res = LoadFrom(buffer.Get()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -124,8 +124,8 @@ public class FlatMapKeyValueStore : IDisposable where TKey : unmanaged, IE { // Create a buffer to hold the archive. var buffer = new AutoBuffer(); - Result rc = buffer.Initialize(CalculateArchiveSize(), _memoryResourceForAutoBuffers); - if (rc.IsFailure()) return rc; + Result res = buffer.Initialize(CalculateArchiveSize(), _memoryResourceForAutoBuffers); + if (res.IsFailure()) return res.Miss(); try { @@ -243,19 +243,19 @@ public class FlatMapKeyValueStore : IDisposable where TKey : unmanaged, IE /// The of the operation. private Result ReadArchive(ref AutoBuffer buffer) { - Result rc = _fsClient.OpenFile(out FileHandle file, new U8Span(_archivePath.Get()), OpenMode.Read); - if (rc.IsFailure()) return rc; + Result res = _fsClient.OpenFile(out FileHandle file, new U8Span(_archivePath.Get()), OpenMode.Read); + if (res.IsFailure()) return res.Miss(); try { - rc = _fsClient.GetFileSize(out long archiveSize, file); - if (rc.IsFailure()) return rc; + res = _fsClient.GetFileSize(out long archiveSize, file); + if (res.IsFailure()) return res.Miss(); - rc = buffer.Initialize(archiveSize, _memoryResourceForAutoBuffers); - if (rc.IsFailure()) return rc; + res = buffer.Initialize(archiveSize, _memoryResourceForAutoBuffers); + if (res.IsFailure()) return res.Miss(); - rc = _fsClient.ReadFile(file, 0, buffer.Get()); - if (rc.IsFailure()) return rc; + res = _fsClient.ReadFile(file, 0, buffer.Get()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -275,14 +275,14 @@ public class FlatMapKeyValueStore : IDisposable where TKey : unmanaged, IE { var reader = new KeyValueArchiveBufferReader(buffer); - Result rc = reader.ReadEntryCount(out int entryCount); - if (rc.IsFailure()) return rc; + Result res = reader.ReadEntryCount(out int entryCount); + if (res.IsFailure()) return res.Miss(); for (int i = 0; i < entryCount; i++) { // Get size of key/value. - rc = reader.GetKeyValueSize(out _, out int valueSize); - if (rc.IsFailure()) return rc; + res = reader.GetKeyValueSize(out _, out int valueSize); + if (res.IsFailure()) return res.Miss(); // Allocate memory for value. Buffer newValue = _memoryResource.Allocate(valueSize, Alignment); @@ -295,11 +295,11 @@ public class FlatMapKeyValueStore : IDisposable where TKey : unmanaged, IE // Read key and value. Unsafe.SkipInit(out TKey key); - rc = reader.ReadKeyValue(SpanHelpers.AsByteSpan(ref key), newValue.Span); - if (rc.IsFailure()) return rc; + res = reader.ReadKeyValue(SpanHelpers.AsByteSpan(ref key), newValue.Span); + if (res.IsFailure()) return res.Miss(); - rc = _index.AppendUnsafe(in key, newValue); - if (rc.IsFailure()) return rc; + res = _index.AppendUnsafe(in key, newValue); + if (res.IsFailure()) return res.Miss(); success = true; } @@ -336,17 +336,17 @@ public class FlatMapKeyValueStore : IDisposable where TKey : unmanaged, IE _fsClient.DeleteFile(path).IgnoreResult(); // Create new archive. - Result rc = _fsClient.CreateFile(path, buffer.Length); - if (rc.IsFailure()) return rc; + Result res = _fsClient.CreateFile(path, buffer.Length); + if (res.IsFailure()) return res.Miss(); // Write data to the archive. - rc = _fsClient.OpenFile(out FileHandle file, path, OpenMode.Write); - if (rc.IsFailure()) return rc; + res = _fsClient.OpenFile(out FileHandle file, path, OpenMode.Write); + if (res.IsFailure()) return res.Miss(); try { - rc = _fsClient.WriteFile(file, 0, buffer, WriteOption.Flush); - if (rc.IsFailure()) return rc; + res = _fsClient.WriteFile(file, 0, buffer, WriteOption.Flush); + if (res.IsFailure()) return res.Miss(); } finally { diff --git a/src/LibHac/Kvdb/KeyValueArchive.cs b/src/LibHac/Kvdb/KeyValueArchive.cs index b27ff680..45a19656 100644 --- a/src/LibHac/Kvdb/KeyValueArchive.cs +++ b/src/LibHac/Kvdb/KeyValueArchive.cs @@ -77,8 +77,8 @@ internal ref struct KeyValueArchiveBufferReader // Read and validate header. var header = new KeyValueArchiveHeader(); - Result rc = Read(SpanHelpers.AsByteSpan(ref header)); - if (rc.IsFailure()) return rc; + Result res = Read(SpanHelpers.AsByteSpan(ref header)); + if (res.IsFailure()) return res.Miss(); if (!header.IsValid()) return ResultKvdb.InvalidKeyValue.Log(); @@ -97,8 +97,8 @@ internal ref struct KeyValueArchiveBufferReader // Peek the next entry header. Unsafe.SkipInit(out KeyValueArchiveEntryHeader header); - Result rc = Peek(SpanHelpers.AsByteSpan(ref header)); - if (rc.IsFailure()) return rc; + Result res = Peek(SpanHelpers.AsByteSpan(ref header)); + if (res.IsFailure()) return res.Miss(); if (!header.IsValid()) return ResultKvdb.InvalidKeyValue.Log(); @@ -117,8 +117,8 @@ internal ref struct KeyValueArchiveBufferReader // Read the next entry header. Unsafe.SkipInit(out KeyValueArchiveEntryHeader header); - Result rc = Read(SpanHelpers.AsByteSpan(ref header)); - if (rc.IsFailure()) return rc; + Result res = Read(SpanHelpers.AsByteSpan(ref header)); + if (res.IsFailure()) return res.Miss(); if (!header.IsValid()) return ResultKvdb.InvalidKeyValue.Log(); @@ -127,11 +127,11 @@ internal ref struct KeyValueArchiveBufferReader Assert.SdkEqual(keyBuffer.Length, header.KeySize); Assert.SdkEqual(valueBuffer.Length, header.ValueSize); - rc = Read(keyBuffer); - if (rc.IsFailure()) return rc; + res = Read(keyBuffer); + if (res.IsFailure()) return res.Miss(); - rc = Read(valueBuffer); - if (rc.IsFailure()) return rc; + res = Read(valueBuffer); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -151,8 +151,8 @@ internal ref struct KeyValueArchiveBufferReader private Result Read(Span destBuffer) { - Result rc = Peek(destBuffer); - if (rc.IsFailure()) return rc; + Result res = Peek(destBuffer); + if (res.IsFailure()) return res.Miss(); _offset += destBuffer.Length; return Result.Success; diff --git a/src/LibHac/Loader/MetaLoader.cs b/src/LibHac/Loader/MetaLoader.cs index a268dc60..9b613050 100644 --- a/src/LibHac/Loader/MetaLoader.cs +++ b/src/LibHac/Loader/MetaLoader.cs @@ -25,8 +25,8 @@ public class MetaLoader _isValid = false; // Validate the meta - Result rc = GetNpdmFromBuffer(out _, npdmBuffer); - if (rc.IsFailure()) return rc; + Result res = GetNpdmFromBuffer(out _, npdmBuffer); + if (res.IsFailure()) return res.Miss(); npdmBuffer.CopyTo(_npdmBuffer); _isValid = true; @@ -38,19 +38,19 @@ public class MetaLoader _isValid = false; // Get file size - Result rc = hos.Fs.GetFileSize(out long npdmSize, file); - if (rc.IsFailure()) return rc; + Result res = hos.Fs.GetFileSize(out long npdmSize, file); + if (res.IsFailure()) return res.Miss(); if (npdmSize > MetaCacheBufferSize) return ResultLoader.TooLargeMeta.Log(); // Read data into cache buffer - rc = hos.Fs.ReadFile(file, 0, _npdmBuffer.AsSpan(0, (int)npdmSize)); - if (rc.IsFailure()) return rc; + res = hos.Fs.ReadFile(file, 0, _npdmBuffer.AsSpan(0, (int)npdmSize)); + if (res.IsFailure()) return res.Miss(); // Validate the meta - rc = GetNpdmFromBuffer(out _, _npdmBuffer); - if (rc.IsFailure()) return rc; + res = GetNpdmFromBuffer(out _, _npdmBuffer); + if (res.IsFailure()) return res.Miss(); _isValid = true; return Result.Success; @@ -80,8 +80,8 @@ public class MetaLoader if (npdmSize > MetaCacheBufferSize) return ResultLoader.TooLargeMeta.Log(); - Result rc = ValidateMeta(npdmBuffer); - if (rc.IsFailure()) return rc; + Result res = ValidateMeta(npdmBuffer); + if (res.IsFailure()) return res.Miss(); ref readonly Meta meta = ref Unsafe.As(ref MemoryMarshal.GetReference(npdmBuffer)); @@ -91,11 +91,11 @@ public class MetaLoader ref readonly AcidHeaderData acid = ref Unsafe.As(ref MemoryMarshal.GetReference(acidBuffer)); ref readonly AciHeader aci = ref Unsafe.As(ref MemoryMarshal.GetReference(aciBuffer)); - rc = ValidateAcid(acidBuffer); - if (rc.IsFailure()) return rc; + res = ValidateAcid(acidBuffer); + if (res.IsFailure()) return res.Miss(); - rc = ValidateAci(aciBuffer); - if (rc.IsFailure()) return rc; + res = ValidateAci(aciBuffer); + if (res.IsFailure()) return res.Miss(); // Set Npdm members. npdm.Meta = new ReadOnlyRef(in meta); @@ -165,13 +165,13 @@ public class MetaLoader return ResultLoader.InvalidMeta.Log(); // Validate Acid extents. - Result rc = ValidateSubregion(Unsafe.SizeOf(), metaBuffer.Length, meta.AcidOffset, + Result res = ValidateSubregion(Unsafe.SizeOf(), metaBuffer.Length, meta.AcidOffset, Unsafe.SizeOf()); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); // Validate Aci extends. - rc = ValidateSubregion(Unsafe.SizeOf(), metaBuffer.Length, meta.AciOffset, Unsafe.SizeOf()); - if (rc.IsFailure()) return rc; + res = ValidateSubregion(Unsafe.SizeOf(), metaBuffer.Length, meta.AciOffset, Unsafe.SizeOf()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -189,17 +189,17 @@ public class MetaLoader return ResultLoader.InvalidMeta.Log(); // Validate Fac, Sac, Kac. - Result rc = ValidateSubregion(Unsafe.SizeOf(), acidBuffer.Length, acid.FsAccessControlOffset, + Result res = ValidateSubregion(Unsafe.SizeOf(), acidBuffer.Length, acid.FsAccessControlOffset, acid.FsAccessControlSize); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = ValidateSubregion(Unsafe.SizeOf(), acidBuffer.Length, acid.ServiceAccessControlOffset, + res = ValidateSubregion(Unsafe.SizeOf(), acidBuffer.Length, acid.ServiceAccessControlOffset, acid.ServiceAccessControlSize); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = ValidateSubregion(Unsafe.SizeOf(), acidBuffer.Length, acid.KernelCapabilityOffset, + res = ValidateSubregion(Unsafe.SizeOf(), acidBuffer.Length, acid.KernelCapabilityOffset, acid.KernelCapabilitySize); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -217,17 +217,17 @@ public class MetaLoader return ResultLoader.InvalidMeta.Log(); // Validate Fac, Sac, Kac. - Result rc = ValidateSubregion(Unsafe.SizeOf(), aciBuffer.Length, aci.FsAccessControlOffset, + Result res = ValidateSubregion(Unsafe.SizeOf(), aciBuffer.Length, aci.FsAccessControlOffset, aci.FsAccessControlSize); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = ValidateSubregion(Unsafe.SizeOf(), aciBuffer.Length, aci.ServiceAccessControlOffset, + res = ValidateSubregion(Unsafe.SizeOf(), aciBuffer.Length, aci.ServiceAccessControlOffset, aci.ServiceAccessControlSize); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); - rc = ValidateSubregion(Unsafe.SizeOf(), aciBuffer.Length, aci.KernelCapabilityOffset, + res = ValidateSubregion(Unsafe.SizeOf(), aciBuffer.Length, aci.KernelCapabilityOffset, aci.KernelCapabilitySize); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Loader/NsoReader.cs b/src/LibHac/Loader/NsoReader.cs index 4538de88..11beb28e 100644 --- a/src/LibHac/Loader/NsoReader.cs +++ b/src/LibHac/Loader/NsoReader.cs @@ -16,8 +16,8 @@ public class NsoReader public Result Initialize(IFile nsoFile) { - Result rc = nsoFile.Read(out long bytesRead, 0, SpanHelpers.AsByteSpan(ref Header), ReadOption.None); - if (rc.IsFailure()) return rc; + Result res = nsoFile.Read(out long bytesRead, 0, SpanHelpers.AsByteSpan(ref Header), ReadOption.None); + if (res.IsFailure()) return res.Miss(); if (bytesRead != Unsafe.SizeOf()) return ResultLoader.InvalidNso.Log(); @@ -44,8 +44,8 @@ public class NsoReader public Result ReadSegment(SegmentType segment, Span buffer) { - Result rc = GetSegmentSize(segment, out uint segmentSize); - if (rc.IsFailure()) return rc; + Result res = GetSegmentSize(segment, out uint segmentSize); + if (res.IsFailure()) return res.Miss(); if (buffer.Length < segmentSize) return ResultLibHac.BufferTooSmall.Log(); @@ -73,8 +73,8 @@ public class NsoReader // Load data from file. uint loadAddress = isCompressed ? (uint)buffer.Length - fileSize : 0; - Result rc = NsoFile.Read(out long bytesRead, segment.FileOffset, buffer.Slice((int)loadAddress), ReadOption.None); - if (rc.IsFailure()) return rc; + Result res = NsoFile.Read(out long bytesRead, segment.FileOffset, buffer.Slice((int)loadAddress), ReadOption.None); + if (res.IsFailure()) return res.Miss(); if (bytesRead != fileSize) return ResultLoader.InvalidNso.Log(); diff --git a/src/LibHac/Lr/LrService.cs b/src/LibHac/Lr/LrService.cs index 14f3edb9..c9259b19 100644 --- a/src/LibHac/Lr/LrService.cs +++ b/src/LibHac/Lr/LrService.cs @@ -45,8 +45,8 @@ public static class LrService UnsafeHelpers.SkipParamInit(out outResolver); using var resolver = new SharedRef(); - Result rc = lr.Globals.LrService.LocationResolver.Get.OpenLocationResolver(ref resolver.Ref(), storageId); - if (rc.IsFailure()) return rc; + Result res = lr.Globals.LrService.LocationResolver.Get.OpenLocationResolver(ref resolver.Ref(), storageId); + if (res.IsFailure()) return res.Miss(); outResolver = new LocationResolver(ref resolver.Ref()); return Result.Success; @@ -57,8 +57,8 @@ public static class LrService UnsafeHelpers.SkipParamInit(out outResolver); using var resolver = new SharedRef(); - Result rc = lr.Globals.LrService.LocationResolver.Get.OpenRegisteredLocationResolver(ref resolver.Ref()); - if (rc.IsFailure()) return rc; + Result res = lr.Globals.LrService.LocationResolver.Get.OpenRegisteredLocationResolver(ref resolver.Ref()); + if (res.IsFailure()) return res.Miss(); outResolver = new RegisteredLocationResolver(ref resolver.Ref()); return Result.Success; @@ -69,8 +69,8 @@ public static class LrService UnsafeHelpers.SkipParamInit(out outResolver); using var resolver = new SharedRef(); - Result rc = lr.Globals.LrService.LocationResolver.Get.OpenAddOnContentLocationResolver(ref resolver.Ref()); - if (rc.IsFailure()) return rc; + Result res = lr.Globals.LrService.LocationResolver.Get.OpenAddOnContentLocationResolver(ref resolver.Ref()); + if (res.IsFailure()) return res.Miss(); outResolver = new AddOnContentLocationResolver(ref resolver.Ref()); return Result.Success; @@ -78,8 +78,8 @@ public static class LrService public static Result RefreshLocationResolver(this LrClient lr, StorageId storageId) { - Result rc = lr.Globals.LrService.LocationResolver.Get.RefreshLocationResolver(storageId); - if (rc.IsFailure()) return rc; + Result res = lr.Globals.LrService.LocationResolver.Get.RefreshLocationResolver(storageId); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -89,11 +89,11 @@ public static class LrService private static SharedRef GetLocationResolverManagerServiceObject(this LrClient lr) { using var manager = new SharedRef(); - Result rc = lr.Hos.Sm.GetService(ref manager.Ref(), "lr"); + Result res = lr.Hos.Sm.GetService(ref manager.Ref(), "lr"); - if (rc.IsFailure()) + if (res.IsFailure()) { - throw new HorizonResultException(rc, "Failed to get lr service object."); + throw new HorizonResultException(res, "Failed to get lr service object."); } return SharedRef.CreateMove(ref manager.Ref()); diff --git a/src/LibHac/Os/Impl/MultipleWaitTargetImpl-os.net.cs b/src/LibHac/Os/Impl/MultipleWaitTargetImpl-os.net.cs index 003a5a96..0da24d7f 100644 --- a/src/LibHac/Os/Impl/MultipleWaitTargetImpl-os.net.cs +++ b/src/LibHac/Os/Impl/MultipleWaitTargetImpl-os.net.cs @@ -42,9 +42,9 @@ public class MultiWaitTargetImpl : IDisposable do { - Result rc = WaitForAnyObjects(out int index, num, handles, + Result res = WaitForAnyObjects(out int index, num, handles, (int)timeoutHelper.GetTimeLeftOnTarget().GetMilliSeconds()); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); if (index == MultiWaitImpl.WaitTimedOut) { diff --git a/src/LibHac/Sm/ServiceManager.cs b/src/LibHac/Sm/ServiceManager.cs index 69f70b3d..b6d2aa30 100644 --- a/src/LibHac/Sm/ServiceManager.cs +++ b/src/LibHac/Sm/ServiceManager.cs @@ -15,8 +15,8 @@ internal class ServiceManager internal Result GetService(ref SharedRef outServiceObject, ServiceName serviceName) { - Result rc = ValidateServiceName(serviceName); - if (rc.IsFailure()) return rc; + Result res = ValidateServiceName(serviceName); + if (res.IsFailure()) return res.Miss(); if (!Services.TryGetValue(serviceName, out IServiceObject service)) { @@ -28,8 +28,8 @@ internal class ServiceManager internal Result RegisterService(IServiceObject service, ServiceName serviceName) { - Result rc = ValidateServiceName(serviceName); - if (rc.IsFailure()) return rc; + Result res = ValidateServiceName(serviceName); + if (res.IsFailure()) return res.Miss(); if (!Services.TryAdd(serviceName, service)) { @@ -41,8 +41,8 @@ internal class ServiceManager internal Result UnregisterService(ServiceName serviceName) { - Result rc = ValidateServiceName(serviceName); - if (rc.IsFailure()) return rc; + Result res = ValidateServiceName(serviceName); + if (res.IsFailure()) return res.Miss(); if (!Services.Remove(serviceName, out IServiceObject service)) { diff --git a/src/LibHac/Sm/ServiceManagerClient.cs b/src/LibHac/Sm/ServiceManagerClient.cs index bc664ff8..1e3bc70e 100644 --- a/src/LibHac/Sm/ServiceManagerClient.cs +++ b/src/LibHac/Sm/ServiceManagerClient.cs @@ -16,8 +16,8 @@ public class ServiceManagerClient { using var service = new SharedRef(); - Result rc = Server.GetService(ref service.Ref(), ServiceName.Encode(name)); - if (rc.IsFailure()) return rc.Miss(); + Result res = Server.GetService(ref service.Ref(), ServiceName.Encode(name)); + if (res.IsFailure()) return res.Miss(); if (serviceObject.TryCastSet(ref service.Ref())) { diff --git a/src/LibHac/Tools/Fs/FileSystemClientUtils.cs b/src/LibHac/Tools/Fs/FileSystemClientUtils.cs index f1b8e6bc..495aee00 100644 --- a/src/LibHac/Tools/Fs/FileSystemClientUtils.cs +++ b/src/LibHac/Tools/Fs/FileSystemClientUtils.cs @@ -13,8 +13,8 @@ public static class FileSystemClientUtils public static Result CopyDirectory(this FileSystemClient fs, string sourcePath, string destPath, CreateFileOptions options = CreateFileOptions.None, IProgressReport logger = null) { - Result rc = fs.OpenDirectory(out DirectoryHandle sourceHandle, sourcePath.ToU8Span(), OpenDirectoryMode.All); - if (rc.IsFailure()) return rc; + Result res = fs.OpenDirectory(out DirectoryHandle sourceHandle, sourcePath.ToU8Span(), OpenDirectoryMode.All); + if (res.IsFailure()) return res.Miss(); try { @@ -27,8 +27,8 @@ public static class FileSystemClientUtils { fs.EnsureDirectoryExists(subDstPath); - rc = fs.CopyDirectory(subSrcPath, subDstPath, options, logger); - if (rc.IsFailure()) return rc; + res = fs.CopyDirectory(subSrcPath, subDstPath, options, logger); + if (res.IsFailure()) return res.Miss(); } if (entry.Type == DirectoryEntryType.File) @@ -36,8 +36,8 @@ public static class FileSystemClientUtils logger?.LogMessage(subSrcPath); fs.CreateOrOverwriteFile(subDstPath, entry.Size, options); - rc = fs.CopyFile(subSrcPath, subDstPath, logger); - if (rc.IsFailure()) return rc; + res = fs.CopyFile(subSrcPath, subDstPath, logger); + if (res.IsFailure()) return res.Miss(); } } } @@ -52,21 +52,21 @@ public static class FileSystemClientUtils public static Result CopyFile(this FileSystemClient fs, string sourcePath, string destPath, IProgressReport logger = null) { - Result rc = fs.OpenFile(out FileHandle sourceHandle, sourcePath.ToU8Span(), OpenMode.Read); - if (rc.IsFailure()) return rc; + Result res = fs.OpenFile(out FileHandle sourceHandle, sourcePath.ToU8Span(), OpenMode.Read); + if (res.IsFailure()) return res.Miss(); try { - rc = fs.OpenFile(out FileHandle destHandle, destPath.ToU8Span(), + res = fs.OpenFile(out FileHandle destHandle, destPath.ToU8Span(), OpenMode.Write | OpenMode.AllowAppend); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); try { const int maxBufferSize = 0x10000; - rc = fs.GetFileSize(out long fileSize, sourceHandle); - if (rc.IsFailure()) return rc; + res = fs.GetFileSize(out long fileSize, sourceHandle); + if (res.IsFailure()) return res.Miss(); int bufferSize = (int)Math.Min(maxBufferSize, fileSize); @@ -80,11 +80,11 @@ public static class FileSystemClientUtils int toRead = (int)Math.Min(fileSize - offset, bufferSize); Span buf = buffer.AsSpan(0, toRead); - rc = fs.ReadFile(out long _, sourceHandle, offset, buf); - if (rc.IsFailure()) return rc; + res = fs.ReadFile(out long _, sourceHandle, offset, buf); + if (res.IsFailure()) return res.Miss(); - rc = fs.WriteFile(destHandle, offset, buf, WriteOption.None); - if (rc.IsFailure()) return rc; + res = fs.WriteFile(destHandle, offset, buf, WriteOption.None); + if (res.IsFailure()) return res.Miss(); logger?.ReportAdd(toRead); } @@ -95,8 +95,8 @@ public static class FileSystemClientUtils logger?.SetTotal(0); } - rc = fs.FlushFile(destHandle); - if (rc.IsFailure()) return rc; + res = fs.FlushFile(destHandle); + if (res.IsFailure()) return res.Miss(); } finally { @@ -166,16 +166,16 @@ public static class FileSystemClientUtils public static bool DirectoryExists(this FileSystemClient fs, string path) { - Result rc = fs.GetEntryType(out DirectoryEntryType type, path.ToU8Span()); + Result res = fs.GetEntryType(out DirectoryEntryType type, path.ToU8Span()); - return (rc.IsSuccess() && type == DirectoryEntryType.Directory); + return (res.IsSuccess() && type == DirectoryEntryType.Directory); } public static bool FileExists(this FileSystemClient fs, string path) { - Result rc = fs.GetEntryType(out DirectoryEntryType type, path.ToU8Span()); + Result res = fs.GetEntryType(out DirectoryEntryType type, path.ToU8Span()); - return (rc.IsSuccess() && type == DirectoryEntryType.File); + return (res.IsSuccess() && type == DirectoryEntryType.File); } public static void EnsureDirectoryExists(this FileSystemClient fs, string path) @@ -230,8 +230,8 @@ public static class FileSystemClientUtils if (fs.FileExists(path)) { - Result rc = fs.DeleteFile(u8Path); - if (rc.IsFailure()) return rc; + Result res = fs.DeleteFile(u8Path); + if (res.IsFailure()) return res.Miss(); } return fs.CreateFile(u8Path, size, CreateFileOptions.None); diff --git a/src/LibHac/Tools/Fs/InMemoryFileSystem.cs b/src/LibHac/Tools/Fs/InMemoryFileSystem.cs index 0efca041..9f2e8f74 100644 --- a/src/LibHac/Tools/Fs/InMemoryFileSystem.cs +++ b/src/LibHac/Tools/Fs/InMemoryFileSystem.cs @@ -29,11 +29,11 @@ public class InMemoryFileSystem : IAttributeFileSystem protected override Result DoCreateDirectory(in Path path, NxFileAttributes archiveAttribute) { - Result rc = FsTable.AddDirectory(new U8Span(path.GetString())); - if (rc.IsFailure()) return rc; + Result res = FsTable.AddDirectory(new U8Span(path.GetString())); + if (res.IsFailure()) return res.Miss(); - rc = FsTable.GetDirectory(new U8Span(path.GetString()), out DirectoryNode dir); - if (rc.IsFailure()) return rc; + res = FsTable.GetDirectory(new U8Span(path.GetString()), out DirectoryNode dir); + if (res.IsFailure()) return res.Miss(); dir.Attributes = archiveAttribute; return Result.Success; @@ -41,11 +41,11 @@ public class InMemoryFileSystem : IAttributeFileSystem protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { - Result rc = FsTable.AddFile(new U8Span(path.GetString())); - if (rc.IsFailure()) return rc; + Result res = FsTable.AddFile(new U8Span(path.GetString())); + if (res.IsFailure()) return res.Miss(); - rc = FsTable.GetFile(new U8Span(path.GetString()), out FileNode file); - if (rc.IsFailure()) return rc; + res = FsTable.GetFile(new U8Span(path.GetString()), out FileNode file); + if (res.IsFailure()) return res.Miss(); return file.File.SetSize(size); } @@ -73,8 +73,8 @@ public class InMemoryFileSystem : IAttributeFileSystem protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, OpenDirectoryMode mode) { - Result rc = FsTable.GetDirectory(new U8Span(path.GetString()), out DirectoryNode dirNode); - if (rc.IsFailure()) return rc; + Result res = FsTable.GetDirectory(new U8Span(path.GetString()), out DirectoryNode dirNode); + if (res.IsFailure()) return res.Miss(); outDirectory.Reset(new MemoryDirectory(dirNode, mode)); return Result.Success; @@ -82,8 +82,8 @@ public class InMemoryFileSystem : IAttributeFileSystem protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) { - Result rc = FsTable.GetFile(new U8Span(path.GetString()), out FileNode fileNode); - if (rc.IsFailure()) return rc; + Result res = FsTable.GetFile(new U8Span(path.GetString()), out FileNode fileNode); + if (res.IsFailure()) return res.Miss(); outFile.Reset(new MemoryFile(mode, fileNode.File)); @@ -276,11 +276,11 @@ public class InMemoryFileSystem : IAttributeFileSystem entry.Type = DirectoryEntryType.File; entry.Attributes = CurrentFile.Attributes; - Result rc = CurrentFile.File.GetSize(out entry.Size); - if (rc.IsFailure()) + Result res = CurrentFile.File.GetSize(out entry.Size); + if (res.IsFailure()) { entriesRead = 0; - return rc; + return res; } i++; @@ -446,8 +446,8 @@ public class InMemoryFileSystem : IAttributeFileSystem { var parentPath = new U8Span(PathTools.GetParentDirectory(path)); - Result rc = FindDirectory(parentPath, out DirectoryNode parent); - if (rc.IsFailure()) return rc; + Result res = FindDirectory(parentPath, out DirectoryNode parent); + if (res.IsFailure()) return res.Miss(); var fileName = new U8Span(PathTools.GetLastSegment(path)); @@ -458,8 +458,8 @@ public class InMemoryFileSystem : IAttributeFileSystem { var parentPath = new U8Span(PathTools.GetParentDirectory(path)); - Result rc = FindDirectory(parentPath, out DirectoryNode parent); - if (rc.IsFailure()) return rc; + Result res = FindDirectory(parentPath, out DirectoryNode parent); + if (res.IsFailure()) return res.Miss(); var dirName = new U8Span(PathTools.GetLastSegment(path)); @@ -478,13 +478,13 @@ public class InMemoryFileSystem : IAttributeFileSystem public Result RenameDirectory(U8Span oldPath, U8Span newPath) { - Result rc = FindDirectory(oldPath, out DirectoryNode directory); - if (rc.IsFailure()) return rc; + Result res = FindDirectory(oldPath, out DirectoryNode directory); + if (res.IsFailure()) return res.Miss(); var newParentPath = new U8Span(PathTools.GetParentDirectory(newPath)); - rc = FindDirectory(newParentPath, out DirectoryNode newParent); - if (rc.IsFailure()) return rc; + res = FindDirectory(newParentPath, out DirectoryNode newParent); + if (res.IsFailure()) return res.Miss(); var newName = new U8Span(PathTools.GetLastSegment(newPath)); @@ -513,13 +513,13 @@ public class InMemoryFileSystem : IAttributeFileSystem public Result RenameFile(U8Span oldPath, U8Span newPath) { - Result rc = FindFile(oldPath, out FileNode file); - if (rc.IsFailure()) return rc; + Result res = FindFile(oldPath, out FileNode file); + if (res.IsFailure()) return res.Miss(); var newParentPath = new U8Span(PathTools.GetParentDirectory(newPath)); - rc = FindDirectory(newParentPath, out DirectoryNode newParent); - if (rc.IsFailure()) return rc; + res = FindDirectory(newParentPath, out DirectoryNode newParent); + if (res.IsFailure()) return res.Miss(); var newName = new U8Span(PathTools.GetLastSegment(newPath)); @@ -549,8 +549,8 @@ public class InMemoryFileSystem : IAttributeFileSystem public Result DeleteDirectory(U8Span path, bool recursive) { - Result rc = FindDirectory(path, out DirectoryNode directory); - if (rc.IsFailure()) return rc; + Result res = FindDirectory(path, out DirectoryNode directory); + if (res.IsFailure()) return res.Miss(); if (!recursive && (directory.ChildDirectory != null || directory.ChildFile != null)) { @@ -563,8 +563,8 @@ public class InMemoryFileSystem : IAttributeFileSystem public Result DeleteFile(U8Span path) { - Result rc = FindFile(path, out FileNode file); - if (rc.IsFailure()) return rc; + Result res = FindFile(path, out FileNode file); + if (res.IsFailure()) return res.Miss(); UnlinkFile(file); return Result.Success; @@ -572,8 +572,8 @@ public class InMemoryFileSystem : IAttributeFileSystem public Result CleanDirectory(U8Span path) { - Result rc = FindDirectory(path, out DirectoryNode directory); - if (rc.IsFailure()) return rc; + Result res = FindDirectory(path, out DirectoryNode directory); + if (res.IsFailure()) return res.Miss(); directory.ChildDirectory = null; directory.ChildFile = null; @@ -625,11 +625,11 @@ public class InMemoryFileSystem : IAttributeFileSystem { var parentPath = new U8Span(PathTools.GetParentDirectory(path)); - Result rc = FindDirectory(parentPath, out DirectoryNode parentNode); - if (rc.IsFailure()) + Result res = FindDirectory(parentPath, out DirectoryNode parentNode); + if (res.IsFailure()) { UnsafeHelpers.SkipParamInit(out file); - return rc; + return res; } var fileName = new U8Span(PathTools.GetLastSegment(path)); diff --git a/src/LibHac/Tools/Fs/XciHeader.cs b/src/LibHac/Tools/Fs/XciHeader.cs index 83e027b2..ef93befd 100644 --- a/src/LibHac/Tools/Fs/XciHeader.cs +++ b/src/LibHac/Tools/Fs/XciHeader.cs @@ -194,8 +194,8 @@ public class XciHeader } Span key = stackalloc byte[0x10]; - Result rc = DecryptCardInitialData(key, InitialData, KekIndex, keySet); - if (rc.IsSuccess()) + Result res = DecryptCardInitialData(key, InitialData, KekIndex, keySet); + if (res.IsSuccess()) { DecryptedTitleKey = key.ToArray(); } @@ -252,14 +252,14 @@ public class XciHeader { UnsafeHelpers.SkipParamInit(out keyAreaStorage, out bodyStorage); - Result rc = baseStorage.GetSize(out long storageSize); - if (rc.IsFailure()) return rc.Miss(); + Result res = baseStorage.GetSize(out long storageSize); + if (res.IsFailure()) return res.Miss(); if (storageSize >= 0x1104) { uint magic = 0; - rc = baseStorage.Read(0x1100, SpanHelpers.AsByteSpan(ref magic)); - if (rc.IsFailure()) return rc.Miss(); + res = baseStorage.Read(0x1100, SpanHelpers.AsByteSpan(ref magic)); + if (res.IsFailure()) return res.Miss(); if (magic == HeaderMagicValue) { diff --git a/src/LibHac/Tools/FsSystem/Aes128CtrExStorage.cs b/src/LibHac/Tools/FsSystem/Aes128CtrExStorage.cs index a96643ad..2363af87 100644 --- a/src/LibHac/Tools/FsSystem/Aes128CtrExStorage.cs +++ b/src/LibHac/Tools/FsSystem/Aes128CtrExStorage.cs @@ -32,9 +32,9 @@ public class Aes128CtrExStorage : Aes128CtrStorage using var valueNodeStorage = new ValueSubStorage(nodeStorage, 0, nodeStorageSize); using var valueEntryStorage = new ValueSubStorage(entryStorage, 0, entryStorageSize); - Result rc = Table.Initialize(new ArrayPoolMemoryResource(), in valueNodeStorage, in valueEntryStorage, NodeSize, + Result res = Table.Initialize(new ArrayPoolMemoryResource(), in valueNodeStorage, in valueEntryStorage, NodeSize, Unsafe.SizeOf(), entryCount); - rc.ThrowIfFailure(); + res.ThrowIfFailure(); } public override Result Read(long offset, Span destination) @@ -42,16 +42,16 @@ public class Aes128CtrExStorage : Aes128CtrStorage if (destination.Length == 0) return Result.Success; - Result rc = Table.GetOffsets(out BucketTree.Offsets offsets); - if (rc.IsFailure()) return rc.Miss(); + Result res = Table.GetOffsets(out BucketTree.Offsets offsets); + if (res.IsFailure()) return res.Miss(); if (!offsets.IsInclude(offset, destination.Length)) return ResultFs.OutOfRange.Log(); using var visitor = new BucketTree.Visitor(); - rc = Table.Find(ref visitor.Ref, offset); - if (rc.IsFailure()) return rc; + res = Table.Find(ref visitor.Ref, offset); + if (res.IsFailure()) return res.Miss(); long inPos = offset; int outPos = 0; @@ -65,8 +65,8 @@ public class Aes128CtrExStorage : Aes128CtrStorage long nextEntryOffset; if (visitor.CanMoveNext()) { - rc = visitor.MoveNext(); - if (rc.IsFailure()) return rc; + res = visitor.MoveNext(); + if (res.IsFailure()) return res.Miss(); nextEntryOffset = visitor.Get().Offset; if (!offsets.IsInclude(nextEntryOffset)) @@ -83,8 +83,8 @@ public class Aes128CtrExStorage : Aes128CtrStorage { UpdateCounterSubsection((uint)currentEntry.Generation); - rc = base.Read(inPos, destination.Slice(outPos, bytesToRead)); - if (rc.IsFailure()) return rc; + res = base.Read(inPos, destination.Slice(outPos, bytesToRead)); + if (res.IsFailure()) return res.Miss(); } outPos += bytesToRead; diff --git a/src/LibHac/Tools/FsSystem/Aes128CtrStorage.cs b/src/LibHac/Tools/FsSystem/Aes128CtrStorage.cs index b3932bee..c3be4806 100644 --- a/src/LibHac/Tools/FsSystem/Aes128CtrStorage.cs +++ b/src/LibHac/Tools/FsSystem/Aes128CtrStorage.cs @@ -61,8 +61,8 @@ public class Aes128CtrStorage : SectorStorage public override Result Read(long offset, Span destination) { - Result rc = base.Read(offset, destination); - if (rc.IsFailure()) return rc; + Result res = base.Read(offset, destination); + if (res.IsFailure()) return res.Miss(); lock (_locker) { @@ -87,8 +87,8 @@ public class Aes128CtrStorage : SectorStorage _decryptor.TransformBlock(encryptedSpan); } - Result rc = base.Write(offset, encryptedSpan); - if (rc.IsFailure()) return rc; + Result res = base.Write(offset, encryptedSpan); + if (res.IsFailure()) return res.Miss(); } finally { diff --git a/src/LibHac/Tools/FsSystem/Aes128XtsStorage.cs b/src/LibHac/Tools/FsSystem/Aes128XtsStorage.cs index f5c968c4..e97260e6 100644 --- a/src/LibHac/Tools/FsSystem/Aes128XtsStorage.cs +++ b/src/LibHac/Tools/FsSystem/Aes128XtsStorage.cs @@ -49,8 +49,8 @@ public class Aes128XtsStorage : SectorStorage if (_readTransform == null) _readTransform = new Aes128XtsTransform(_key1, _key2, _decryptRead); - Result rc = base.Read(offset, _tempBuffer.AsSpan(0, size)); - if (rc.IsFailure()) return rc; + Result res = base.Read(offset, _tempBuffer.AsSpan(0, size)); + if (res.IsFailure()) return res.Miss(); _readTransform.TransformBlock(_tempBuffer, 0, size, (ulong)sectorIndex); _tempBuffer.AsSpan(0, size).CopyTo(destination); diff --git a/src/LibHac/Tools/FsSystem/AesCbcStorage.cs b/src/LibHac/Tools/FsSystem/AesCbcStorage.cs index 48fbd552..de7ac14a 100644 --- a/src/LibHac/Tools/FsSystem/AesCbcStorage.cs +++ b/src/LibHac/Tools/FsSystem/AesCbcStorage.cs @@ -28,14 +28,14 @@ public class AesCbcStorage : SectorStorage public override Result Read(long offset, Span destination) { - Result rc = CheckAccessRange(offset, destination.Length, _size); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckAccessRange(offset, destination.Length, _size); + if (res.IsFailure()) return res.Miss(); - rc = base.Read(offset, destination); - if (rc.IsFailure()) return rc; + res = base.Read(offset, destination); + if (res.IsFailure()) return res.Miss(); - rc = GetDecryptor(out ICipher cipher, offset); - if (rc.IsFailure()) return rc; + res = GetDecryptor(out ICipher cipher, offset); + if (res.IsFailure()) return res.Miss(); cipher.Transform(destination, destination); @@ -70,8 +70,8 @@ public class AesCbcStorage : SectorStorage // Need to get the output of the previous block Span prevBlock = stackalloc byte[BlockSize]; - Result rc = BaseStorage.Read(offset - BlockSize, prevBlock); - if (rc.IsFailure()) return rc; + Result res = BaseStorage.Read(offset - BlockSize, prevBlock); + if (res.IsFailure()) return res.Miss(); ICipher tmpDecryptor = Aes.CreateCbcDecryptor(_key, _iv); diff --git a/src/LibHac/Tools/FsSystem/AesXtsDirectory.cs b/src/LibHac/Tools/FsSystem/AesXtsDirectory.cs index c70ed038..940f045c 100644 --- a/src/LibHac/Tools/FsSystem/AesXtsDirectory.cs +++ b/src/LibHac/Tools/FsSystem/AesXtsDirectory.cs @@ -30,8 +30,8 @@ public class AesXtsDirectory : IDirectory protected override Result DoRead(out long entriesRead, Span entryBuffer) { - Result rc = _baseDirectory.Get.Read(out entriesRead, entryBuffer); - if (rc.IsFailure()) return rc; + Result res = _baseDirectory.Get.Read(out entriesRead, entryBuffer); + if (res.IsFailure()) return res.Miss(); for (int i = 0; i < entriesRead; i++) { @@ -73,8 +73,8 @@ public class AesXtsDirectory : IDirectory try { using var file = new UniqueRef(); - Result rc = _baseFileSystem.OpenFile(ref file.Ref(), path, OpenMode.Read); - if (rc.IsFailure()) return 0; + Result res = _baseFileSystem.OpenFile(ref file.Ref(), path, OpenMode.Read); + if (res.IsFailure()) return 0; uint magic = 0; long fileSize = 0; diff --git a/src/LibHac/Tools/FsSystem/AesXtsFile.cs b/src/LibHac/Tools/FsSystem/AesXtsFile.cs index 2b1efbb2..affd9807 100644 --- a/src/LibHac/Tools/FsSystem/AesXtsFile.cs +++ b/src/LibHac/Tools/FsSystem/AesXtsFile.cs @@ -63,11 +63,11 @@ public class AesXtsFile : IFile { UnsafeHelpers.SkipParamInit(out bytesRead); - Result rc = DryRead(out long toRead, offset, destination.Length, in option, Mode); - if (rc.IsFailure()) return rc; + Result res = DryRead(out long toRead, offset, destination.Length, in option, Mode); + if (res.IsFailure()) return res.Miss(); - rc = BaseStorage.Read(offset, destination.Slice(0, (int)toRead)); - if (rc.IsFailure()) return rc; + res = BaseStorage.Read(offset, destination.Slice(0, (int)toRead)); + if (res.IsFailure()) return res.Miss(); bytesRead = toRead; return Result.Success; @@ -75,17 +75,17 @@ public class AesXtsFile : IFile protected override Result DoWrite(long offset, ReadOnlySpan source, in WriteOption option) { - Result rc = DryWrite(out bool isResizeNeeded, offset, source.Length, in option, Mode); - if (rc.IsFailure()) return rc; + Result res = DryWrite(out bool isResizeNeeded, offset, source.Length, in option, Mode); + if (res.IsFailure()) return res.Miss(); if (isResizeNeeded) { - rc = DoSetSize(offset + source.Length); - if (rc.IsFailure()) return rc; + res = DoSetSize(offset + source.Length); + if (res.IsFailure()) return res.Miss(); } - rc = BaseStorage.Write(offset, source); - if (rc.IsFailure()) return rc; + res = BaseStorage.Write(offset, source); + if (res.IsFailure()) return res.Miss(); if (option.HasFlushFlag()) { @@ -116,8 +116,8 @@ public class AesXtsFile : IFile { Header.SetSize(size, VerificationKey); - Result rc = _baseFile.Get.Write(0, Header.ToBytes(false)); - if (rc.IsFailure()) return rc; + Result res = _baseFile.Get.Write(0, Header.ToBytes(false)); + if (res.IsFailure()) return res.Miss(); return BaseStorage.SetSize(Alignment.AlignUp(size, 0x10)); } diff --git a/src/LibHac/Tools/FsSystem/AesXtsFileSystem.cs b/src/LibHac/Tools/FsSystem/AesXtsFileSystem.cs index 477c93dc..aca77c10 100644 --- a/src/LibHac/Tools/FsSystem/AesXtsFileSystem.cs +++ b/src/LibHac/Tools/FsSystem/AesXtsFileSystem.cs @@ -62,17 +62,17 @@ public class AesXtsFileSystem : IFileSystem { long containerSize = AesXtsFile.HeaderLength + Alignment.AlignUp(size, 0x10); - Result rc = _baseFileSystem.CreateFile(in path, containerSize, options); - if (rc.IsFailure()) return rc; + Result res = _baseFileSystem.CreateFile(in path, containerSize, options); + if (res.IsFailure()) return res.Miss(); var header = new AesXtsFileHeader(key, size, path.ToString(), _kekSource, _validationKey); using var baseFile = new UniqueRef(); - rc = _baseFileSystem.OpenFile(ref baseFile.Ref(), in path, OpenMode.Write); - if (rc.IsFailure()) return rc; + res = _baseFileSystem.OpenFile(ref baseFile.Ref(), in path, OpenMode.Write); + if (res.IsFailure()) return res.Miss(); - rc = baseFile.Get.Write(0, header.ToBytes(false)); - if (rc.IsFailure()) return rc; + res = baseFile.Get.Write(0, header.ToBytes(false)); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -101,8 +101,8 @@ public class AesXtsFileSystem : IFileSystem OpenDirectoryMode mode) { using var baseDir = new UniqueRef(); - Result rc = _baseFileSystem.OpenDirectory(ref baseDir.Ref(), path, mode); - if (rc.IsFailure()) return rc; + Result res = _baseFileSystem.OpenDirectory(ref baseDir.Ref(), path, mode); + if (res.IsFailure()) return res.Miss(); outDirectory.Reset(new AesXtsDirectory(_baseFileSystem, ref baseDir.Ref(), new U8String(path.GetString().ToArray()), mode)); return Result.Success; @@ -111,8 +111,8 @@ public class AesXtsFileSystem : IFileSystem protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) { using var baseFile = new UniqueRef(); - Result rc = _baseFileSystem.OpenFile(ref baseFile.Ref(), path, mode | OpenMode.Read); - if (rc.IsFailure()) return rc; + Result res = _baseFileSystem.OpenFile(ref baseFile.Ref(), path, mode | OpenMode.Read); + if (res.IsFailure()) return res.Miss(); var xtsFile = new AesXtsFile(mode, ref baseFile.Ref(), new U8String(path.GetString().ToArray()), _kekSource, _validationKey, BlockSize); @@ -133,8 +133,8 @@ public class AesXtsFileSystem : IFileSystem // Reencrypt any modified file headers with the old path // Rename directory to the old path - Result rc = _baseFileSystem.RenameDirectory(currentPath, newPath); - if (rc.IsFailure()) return rc; + Result res = _baseFileSystem.RenameDirectory(currentPath, newPath); + if (res.IsFailure()) return res.Miss(); try { @@ -187,8 +187,8 @@ public class AesXtsFileSystem : IFileSystem AesXtsFileHeader header = ReadXtsHeader(currentPath.ToString(), currentPath.ToString()); - Result rc = _baseFileSystem.RenameFile(currentPath, newPath); - if (rc.IsFailure()) return rc; + Result res = _baseFileSystem.RenameFile(currentPath, newPath); + if (res.IsFailure()) return res.Miss(); try { @@ -264,8 +264,8 @@ public class AesXtsFileSystem : IFileSystem header = null; using var file = new UniqueRef(); - Result rc = _baseFileSystem.OpenFile(ref file.Ref(), filePath.ToU8Span(), OpenMode.Read); - if (rc.IsFailure()) return false; + Result res = _baseFileSystem.OpenFile(ref file.Ref(), filePath.ToU8Span(), OpenMode.Read); + if (res.IsFailure()) return false; header = new AesXtsFileHeader(file.Get); diff --git a/src/LibHac/Tools/FsSystem/CachedStorage.cs b/src/LibHac/Tools/FsSystem/CachedStorage.cs index cf5f140c..d7742a00 100644 --- a/src/LibHac/Tools/FsSystem/CachedStorage.cs +++ b/src/LibHac/Tools/FsSystem/CachedStorage.cs @@ -39,8 +39,8 @@ public class CachedStorage : IStorage long inOffset = offset; int outOffset = 0; - Result rc = CheckAccessRange(offset, destination.Length, Length); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckAccessRange(offset, destination.Length, Length); + if (res.IsFailure()) return res.Miss(); lock (Blocks) { @@ -69,8 +69,8 @@ public class CachedStorage : IStorage long inOffset = offset; int outOffset = 0; - Result rc = CheckAccessRange(offset, source.Length, Length); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckAccessRange(offset, source.Length, Length); + if (res.IsFailure()) return res.Miss(); lock (Blocks) { @@ -116,11 +116,11 @@ public class CachedStorage : IStorage public override Result SetSize(long size) { - Result rc = BaseStorage.SetSize(size); - if (rc.IsFailure()) return rc; + Result res = BaseStorage.SetSize(size); + if (res.IsFailure()) return res.Miss(); - rc = BaseStorage.GetSize(out long newSize); - if (rc.IsFailure()) return rc; + res = BaseStorage.GetSize(out long newSize); + if (res.IsFailure()) return res.Miss(); Length = newSize; diff --git a/src/LibHac/Tools/FsSystem/CompressedStorage.cs b/src/LibHac/Tools/FsSystem/CompressedStorage.cs index 67d09f64..b97e7f6b 100644 --- a/src/LibHac/Tools/FsSystem/CompressedStorage.cs +++ b/src/LibHac/Tools/FsSystem/CompressedStorage.cs @@ -46,9 +46,9 @@ internal class CompressedStorage : IStorage public Result Initialize(MemoryResource allocatorForBucketTree, in ValueSubStorage dataStorage, in ValueSubStorage nodeStorage, in ValueSubStorage entryStorage, int bucketTreeEntryCount) { - Result rc = _bucketTree.Initialize(allocatorForBucketTree, in nodeStorage, in entryStorage, NodeSize, + Result res = _bucketTree.Initialize(allocatorForBucketTree, in nodeStorage, in entryStorage, NodeSize, Unsafe.SizeOf(), bucketTreeEntryCount); - if (rc.IsFailure()) return rc.Miss(); + if (res.IsFailure()) return res.Miss(); _dataStorage.Set(in dataStorage); @@ -58,8 +58,8 @@ internal class CompressedStorage : IStorage public override Result Read(long offset, Span destination) { // Validate arguments - Result rc = _bucketTree.GetOffsets(out BucketTree.Offsets offsets); - if (rc.IsFailure()) return rc.Miss(); + Result res = _bucketTree.GetOffsets(out BucketTree.Offsets offsets); + if (res.IsFailure()) return res.Miss(); if (!offsets.IsInclude(offset, destination.Length)) return ResultFs.OutOfRange.Log(); @@ -67,8 +67,8 @@ internal class CompressedStorage : IStorage // Find the offset in our tree using var visitor = new BucketTree.Visitor(); - rc = _bucketTree.Find(ref visitor.Ref, offset); - if (rc.IsFailure()) return rc; + res = _bucketTree.Find(ref visitor.Ref, offset); + if (res.IsFailure()) return res.Miss(); long entryOffset = visitor.Get().VirtualOffset; if (entryOffset < 0 || !offsets.IsInclude(entryOffset)) @@ -95,8 +95,8 @@ internal class CompressedStorage : IStorage long nextEntryOffset; if (visitor.CanMoveNext()) { - rc = visitor.MoveNext(); - if (rc.IsFailure()) return rc; + res = visitor.MoveNext(); + if (res.IsFailure()) return res.Miss(); nextEntryOffset = visitor.Get().VirtualOffset; if (!offsets.IsInclude(nextEntryOffset)) @@ -129,8 +129,8 @@ internal class CompressedStorage : IStorage Span encBuffer = workBufferEnc.AsSpan(0, (int)currentEntry.PhysicalSize); Span decBuffer = workBufferDec.AsSpan(0, (int)currentEntrySize); - rc = _dataStorage.Read(currentEntry.PhysicalOffset, encBuffer); - if (rc.IsFailure()) return rc.Miss(); + res = _dataStorage.Read(currentEntry.PhysicalOffset, encBuffer); + if (res.IsFailure()) return res.Miss(); Lz4.Decompress(encBuffer, decBuffer); @@ -138,8 +138,8 @@ internal class CompressedStorage : IStorage } else if (currentEntry.CompressionType == CompressionType.None) { - rc = _dataStorage.Read(currentEntry.PhysicalOffset + dataOffsetInEntry, entryDestination); - if (rc.IsFailure()) return rc.Miss(); + res = _dataStorage.Read(currentEntry.PhysicalOffset + dataOffsetInEntry, entryDestination); + if (res.IsFailure()) return res.Miss(); } else if (currentEntry.CompressionType == CompressionType.Zeroed) { @@ -192,8 +192,8 @@ internal class CompressedStorage : IStorage { UnsafeHelpers.SkipParamInit(out size); - Result rc = _bucketTree.GetOffsets(out BucketTree.Offsets offsets); - if (rc.IsFailure()) return rc.Miss(); + Result res = _bucketTree.GetOffsets(out BucketTree.Offsets offsets); + if (res.IsFailure()) return res.Miss(); size = offsets.EndOffset; return Result.Success; diff --git a/src/LibHac/Tools/FsSystem/ConcatenationStorage.cs b/src/LibHac/Tools/FsSystem/ConcatenationStorage.cs index 10d722fc..817eb4e1 100644 --- a/src/LibHac/Tools/FsSystem/ConcatenationStorage.cs +++ b/src/LibHac/Tools/FsSystem/ConcatenationStorage.cs @@ -34,8 +34,8 @@ public class ConcatenationStorage : IStorage int outPos = 0; int remaining = destination.Length; - Result rc = CheckAccessRange(offset, destination.Length, Length); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckAccessRange(offset, destination.Length, Length); + if (res.IsFailure()) return res.Miss(); int sourceIndex = FindSource(inPos); @@ -47,8 +47,8 @@ public class ConcatenationStorage : IStorage int bytesToRead = (int)Math.Min(entryRemain, remaining); - rc = entry.Storage.Read(entryPos, destination.Slice(outPos, bytesToRead)); - if (rc.IsFailure()) return rc; + res = entry.Storage.Read(entryPos, destination.Slice(outPos, bytesToRead)); + if (res.IsFailure()) return res.Miss(); outPos += bytesToRead; inPos += bytesToRead; @@ -65,8 +65,8 @@ public class ConcatenationStorage : IStorage int outPos = 0; int remaining = source.Length; - Result rc = CheckAccessRange(offset, source.Length, Length); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckAccessRange(offset, source.Length, Length); + if (res.IsFailure()) return res.Miss(); int sourceIndex = FindSource(inPos); @@ -78,8 +78,8 @@ public class ConcatenationStorage : IStorage int bytesToWrite = (int)Math.Min(entryRemain, remaining); - rc = entry.Storage.Write(entryPos, source.Slice(outPos, bytesToWrite)); - if (rc.IsFailure()) return rc; + res = entry.Storage.Write(entryPos, source.Slice(outPos, bytesToWrite)); + if (res.IsFailure()) return res.Miss(); outPos += bytesToWrite; inPos += bytesToWrite; @@ -94,8 +94,8 @@ public class ConcatenationStorage : IStorage { foreach (ConcatSource source in Sources) { - Result rc = source.Storage.Flush(); - if (rc.IsFailure()) return rc; + Result res = source.Storage.Flush(); + if (res.IsFailure()) return res.Miss(); } return Result.Success; diff --git a/src/LibHac/Tools/FsSystem/FileSystemExtensions.cs b/src/LibHac/Tools/FsSystem/FileSystemExtensions.cs index 72c0c451..e2905564 100644 --- a/src/LibHac/Tools/FsSystem/FileSystemExtensions.cs +++ b/src/LibHac/Tools/FsSystem/FileSystemExtensions.cs @@ -24,12 +24,12 @@ public static class FileSystemExtensions var directoryEntryBuffer = new DirectoryEntry(); using var sourcePathNormalized = new Path(); - Result rc = InitializeFromString(ref sourcePathNormalized.Ref(), sourcePath); - if (rc.IsFailure()) return rc; + Result res = InitializeFromString(ref sourcePathNormalized.Ref(), sourcePath); + if (res.IsFailure()) return res.Miss(); using var destPathNormalized = new Path(); - rc = InitializeFromString(ref destPathNormalized.Ref(), destPath); - if (rc.IsFailure()) return rc; + res = InitializeFromString(ref destPathNormalized.Ref(), destPath); + if (res.IsFailure()) return res.Miss(); byte[] workBuffer = ArrayPool.Shared.Rent(bufferSize); try @@ -51,11 +51,11 @@ public static class FileSystemExtensions static Result OnEnterDir(in Path path, in DirectoryEntry entry, ref Utility.FsIterationTaskClosure closure) { - Result rc = closure.DestinationPathBuffer.AppendChild(entry.Name); - if (rc.IsFailure()) return rc; + Result res = closure.DestinationPathBuffer.AppendChild(entry.Name); + if (res.IsFailure()) return res.Miss(); - rc = closure.DestFileSystem.CreateDirectory(in closure.DestinationPathBuffer); - if (rc.IsFailure() && !ResultFs.PathAlreadyExists.Includes(rc)) return rc.Miss(); + res = closure.DestFileSystem.CreateDirectory(in closure.DestinationPathBuffer); + if (res.IsFailure() && !ResultFs.PathAlreadyExists.Includes(res)) return res.Miss(); return Result.Success; } @@ -84,14 +84,14 @@ public static class FileSystemExtensions taskClosure.SourceFileSystem = sourceFileSystem; taskClosure.DestFileSystem = destinationFileSystem; - Result rc = taskClosure.DestinationPathBuffer.Initialize(destinationPath); - if (rc.IsFailure()) return rc; + Result res = taskClosure.DestinationPathBuffer.Initialize(destinationPath); + if (res.IsFailure()) return res.Miss(); - rc = Utility.IterateDirectoryRecursively(sourceFileSystem, in sourcePath, ref dirEntry, OnEnterDir, + res = Utility.IterateDirectoryRecursively(sourceFileSystem, in sourcePath, ref dirEntry, OnEnterDir, OnExitDir, OnFile, ref taskClosure); taskClosure.DestinationPathBuffer.Dispose(); - return rc; + return res; } public static Result CopyFile(IFileSystem destFileSystem, IFileSystem sourceFileSystem, in Path destPath, @@ -100,18 +100,18 @@ public static class FileSystemExtensions { // Open source file. using var sourceFile = new UniqueRef(); - Result rc = sourceFileSystem.OpenFile(ref sourceFile.Ref(), sourcePath, OpenMode.Read); - if (rc.IsFailure()) return rc; + Result res = sourceFileSystem.OpenFile(ref sourceFile.Ref(), sourcePath, OpenMode.Read); + if (res.IsFailure()) return res.Miss(); - rc = sourceFile.Get.GetSize(out long fileSize); - if (rc.IsFailure()) return rc; + res = sourceFile.Get.GetSize(out long fileSize); + if (res.IsFailure()) return res.Miss(); - rc = CreateOrOverwriteFile(destFileSystem, in destPath, fileSize, option); - if (rc.IsFailure()) return rc; + res = CreateOrOverwriteFile(destFileSystem, in destPath, fileSize, option); + if (res.IsFailure()) return res.Miss(); using var destFile = new UniqueRef(); - rc = destFileSystem.OpenFile(ref destFile.Ref(), in destPath, OpenMode.Write); - if (rc.IsFailure()) return rc; + res = destFileSystem.OpenFile(ref destFile.Ref(), in destPath, OpenMode.Write); + if (res.IsFailure()) return res.Miss(); // Read/Write file in work buffer sized chunks. long remaining = fileSize; @@ -121,11 +121,11 @@ public static class FileSystemExtensions while (remaining > 0) { - rc = sourceFile.Get.Read(out long bytesRead, offset, workBuffer, ReadOption.None); - if (rc.IsFailure()) return rc; + res = sourceFile.Get.Read(out long bytesRead, offset, workBuffer, ReadOption.None); + if (res.IsFailure()) return res.Miss(); - rc = destFile.Get.Write(offset, workBuffer.Slice(0, (int)bytesRead), WriteOption.None); - if (rc.IsFailure()) return rc; + res = destFile.Get.Write(offset, workBuffer.Slice(0, (int)bytesRead), WriteOption.None); + if (res.IsFailure()) return res.Miss(); remaining -= bytesRead; offset += bytesRead; @@ -331,23 +331,23 @@ public static class FileSystemExtensions public static bool DirectoryExists(this IFileSystem fs, string path) { - Result rc = fs.GetEntryType(out DirectoryEntryType type, path.ToU8Span()); + Result res = fs.GetEntryType(out DirectoryEntryType type, path.ToU8Span()); - return (rc.IsSuccess() && type == DirectoryEntryType.Directory); + return (res.IsSuccess() && type == DirectoryEntryType.Directory); } public static bool FileExists(this IFileSystem fs, string path) { - Result rc = fs.GetEntryType(out DirectoryEntryType type, path.ToU8Span()); + Result res = fs.GetEntryType(out DirectoryEntryType type, path.ToU8Span()); - return (rc.IsSuccess() && type == DirectoryEntryType.File); + return (res.IsSuccess() && type == DirectoryEntryType.File); } public static Result EnsureDirectoryExists(this IFileSystem fs, string path) { using var pathNormalized = new Path(); - Result rc = InitializeFromString(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = InitializeFromString(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return Utility.EnsureDirectory(fs, in pathNormalized); } @@ -355,18 +355,18 @@ public static class FileSystemExtensions public static Result CreateOrOverwriteFile(IFileSystem fileSystem, in Path path, long size, CreateFileOptions option = CreateFileOptions.None) { - Result rc = fileSystem.CreateFile(in path, size, option); + Result res = fileSystem.CreateFile(in path, size, option); - if (rc.IsFailure()) + if (res.IsFailure()) { - if (!ResultFs.PathAlreadyExists.Includes(rc)) - return rc; + if (!ResultFs.PathAlreadyExists.Includes(res)) + return res; - rc = fileSystem.DeleteFile(in path); - if (rc.IsFailure()) return rc; + res = fileSystem.DeleteFile(in path); + if (res.IsFailure()) return res.Miss(); - rc = fileSystem.CreateFile(in path, size, option); - if (rc.IsFailure()) return rc; + res = fileSystem.CreateFile(in path, size, option); + if (res.IsFailure()) return res.Miss(); } return Result.Success; @@ -376,13 +376,13 @@ public static class FileSystemExtensions { ReadOnlySpan utf8Path = StringUtils.StringToUtf8(path); - Result rc = outPath.Initialize(utf8Path); - if (rc.IsFailure()) return rc; + Result res = outPath.Initialize(utf8Path); + if (res.IsFailure()) return res.Miss(); var pathFlags = new PathFlags(); pathFlags.AllowEmptyPath(); outPath.Normalize(pathFlags); - if (rc.IsFailure()) return rc; + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Tools/FsSystem/IntegrityVerificationStorage.cs b/src/LibHac/Tools/FsSystem/IntegrityVerificationStorage.cs index 08be66b2..ba7ea521 100644 --- a/src/LibHac/Tools/FsSystem/IntegrityVerificationStorage.cs +++ b/src/LibHac/Tools/FsSystem/IntegrityVerificationStorage.cs @@ -134,8 +134,8 @@ public class IntegrityVerificationStorage : SectorStorage long blockIndex = offset / SectorSize; long hashPos = blockIndex * DigestSize; - Result rc = GetSize(out long storageSize); - if (rc.IsFailure()) return rc; + Result res = GetSize(out long storageSize); + if (res.IsFailure()) return res.Miss(); int toWrite = (int)Math.Min(source.Length, storageSize - offset); @@ -191,8 +191,8 @@ public class IntegrityVerificationStorage : SectorStorage public override Result Flush() { - Result rc = HashStorage.Flush(); - if (rc.IsFailure()) return rc; + Result res = HashStorage.Flush(); + if (res.IsFailure()) return res.Miss(); return base.Flush(); } diff --git a/src/LibHac/Tools/FsSystem/LayeredFileSystem.cs b/src/LibHac/Tools/FsSystem/LayeredFileSystem.cs index 4598b443..5646f946 100644 --- a/src/LibHac/Tools/FsSystem/LayeredFileSystem.cs +++ b/src/LibHac/Tools/FsSystem/LayeredFileSystem.cs @@ -47,9 +47,9 @@ public class LayeredFileSystem : IFileSystem foreach (IFileSystem fs in Sources) { - Result rc = fs.GetEntryType(out DirectoryEntryType entryType, in path); + Result res = fs.GetEntryType(out DirectoryEntryType entryType, in path); - if (rc.IsSuccess()) + if (res.IsSuccess()) { // There were no directories with this path in higher levels, so the entry is a file if (entryType == DirectoryEntryType.File && singleSource is null) @@ -73,36 +73,36 @@ public class LayeredFileSystem : IFileSystem } } } - else if (!ResultFs.PathNotFound.Includes(rc)) + else if (!ResultFs.PathNotFound.Includes(res)) { - return rc; + return res; } } if (!(multipleSources is null)) { using var dir = new UniqueRef(new MergedDirectory(multipleSources, mode)); - Result rc = dir.Get.Initialize(in path); + Result res = dir.Get.Initialize(in path); - if (rc.IsSuccess()) + if (res.IsSuccess()) { outDirectory.Set(ref dir.Ref()); } - return rc; + return res; } if (!(singleSource is null)) { using var dir = new UniqueRef(); - Result rc = singleSource.OpenDirectory(ref dir.Ref(), in path, mode); + Result res = singleSource.OpenDirectory(ref dir.Ref(), in path, mode); - if (rc.IsSuccess()) + if (res.IsSuccess()) { outDirectory.Set(ref dir.Ref()); } - return rc; + return res; } return ResultFs.PathNotFound.Log(); @@ -112,9 +112,9 @@ public class LayeredFileSystem : IFileSystem { foreach (IFileSystem fs in Sources) { - Result rc = fs.GetEntryType(out DirectoryEntryType type, path); + Result res = fs.GetEntryType(out DirectoryEntryType type, path); - if (rc.IsSuccess()) + if (res.IsSuccess()) { if (type == DirectoryEntryType.File) { @@ -126,9 +126,9 @@ public class LayeredFileSystem : IFileSystem return ResultFs.PathNotFound.Log(); } } - else if (!ResultFs.PathNotFound.Includes(rc)) + else if (!ResultFs.PathNotFound.Includes(res)) { - return rc; + return res; } } @@ -220,15 +220,15 @@ public class LayeredFileSystem : IFileSystem public Result Initialize(in Path path) { - Result rc = _path.Initialize(in path); - if (rc.IsFailure()) return rc; + Result res = _path.Initialize(in path); + if (res.IsFailure()) return res.Miss(); using var dir = new UniqueRef(); foreach (IFileSystem fs in SourceFileSystems) { - rc = fs.OpenDirectory(ref dir.Ref(), in path, Mode); - if (rc.IsFailure()) return rc; + res = fs.OpenDirectory(ref dir.Ref(), in path, Mode); + if (res.IsFailure()) return res.Miss(); SourceDirs.Add(dir.Release()); } @@ -247,8 +247,8 @@ public class LayeredFileSystem : IFileSystem do { - Result rs = SourceDirs[i].Read(out subEntriesRead, entryBuffer.Slice(entryIndex, 1)); - if (rs.IsFailure()) return rs; + Result res = SourceDirs[i].Read(out subEntriesRead, entryBuffer.Slice(entryIndex, 1)); + if (res.IsFailure()) return res; if (subEntriesRead == 1 && Names.Add(StringUtils.Utf8ZToString(entryBuffer[entryIndex].Name))) { @@ -276,14 +276,14 @@ public class LayeredFileSystem : IFileSystem // Open new directories for each source because we need to remove duplicate entries foreach (IFileSystem fs in SourceFileSystems) { - Result rc = fs.OpenDirectory(ref dir.Ref(), in path, Mode); - if (rc.IsFailure()) return rc; + Result res = fs.OpenDirectory(ref dir.Ref(), in path, Mode); + if (res.IsFailure()) return res.Miss(); long entriesRead; do { - rc = dir.Get.Read(out entriesRead, SpanHelpers.AsSpan(ref entry)); - if (rc.IsFailure()) return rc; + res = dir.Get.Read(out entriesRead, SpanHelpers.AsSpan(ref entry)); + if (res.IsFailure()) return res.Miss(); if (entriesRead == 1 && names.Add(StringUtils.Utf8ZToString(entry.Name))) { diff --git a/src/LibHac/Tools/FsSystem/NullFile.cs b/src/LibHac/Tools/FsSystem/NullFile.cs index d6605617..de26f718 100644 --- a/src/LibHac/Tools/FsSystem/NullFile.cs +++ b/src/LibHac/Tools/FsSystem/NullFile.cs @@ -22,8 +22,8 @@ public class NullFile : IFile { bytesRead = 0; - Result rc = DryRead(out long toRead, offset, destination.Length, in option, Mode); - if (rc.IsFailure()) return rc; + Result res = DryRead(out long toRead, offset, destination.Length, in option, Mode); + if (res.IsFailure()) return res.Miss(); destination.Slice(0, (int)toRead).Clear(); diff --git a/src/LibHac/Tools/FsSystem/PathTools.cs b/src/LibHac/Tools/FsSystem/PathTools.cs index 2c611b62..ed3e938d 100644 --- a/src/LibHac/Tools/FsSystem/PathTools.cs +++ b/src/LibHac/Tools/FsSystem/PathTools.cs @@ -461,12 +461,12 @@ public static class PathTools public static Result GetMountName(string path, out string mountName) { - Result rc = GetMountNameLength(path, out int length); + Result res = GetMountNameLength(path, out int length); - if (rc.IsFailure()) + if (res.IsFailure()) { UnsafeHelpers.SkipParamInit(out mountName); - return rc; + return res; } mountName = path.Substring(0, length); diff --git a/src/LibHac/Tools/FsSystem/RomFs/RomFsFile.cs b/src/LibHac/Tools/FsSystem/RomFs/RomFsFile.cs index a9a85d67..3226d989 100644 --- a/src/LibHac/Tools/FsSystem/RomFs/RomFsFile.cs +++ b/src/LibHac/Tools/FsSystem/RomFs/RomFsFile.cs @@ -23,13 +23,13 @@ public class RomFsFile : IFile { UnsafeHelpers.SkipParamInit(out bytesRead); - Result rc = DryRead(out long toRead, offset, destination.Length, in option, OpenMode.Read); - if (rc.IsFailure()) return rc; + Result res = DryRead(out long toRead, offset, destination.Length, in option, OpenMode.Read); + if (res.IsFailure()) return res.Miss(); long storageOffset = Offset + offset; - rc = ConvertToApplicationResult(BaseStorage.Read(storageOffset, destination.Slice(0, (int)toRead))); - if (rc.IsFailure()) return rc; + res = ConvertToApplicationResult(BaseStorage.Read(storageOffset, destination.Slice(0, (int)toRead))); + if (res.IsFailure()) return res.Miss(); bytesRead = toRead; diff --git a/src/LibHac/Tools/FsSystem/Save/AllocationTableStorage.cs b/src/LibHac/Tools/FsSystem/Save/AllocationTableStorage.cs index 0458d32d..992f785d 100644 --- a/src/LibHac/Tools/FsSystem/Save/AllocationTableStorage.cs +++ b/src/LibHac/Tools/FsSystem/Save/AllocationTableStorage.cs @@ -47,8 +47,8 @@ public class AllocationTableStorage : IStorage int remainingInSegment = iterator.CurrentSegmentSize * BlockSize - segmentPos; int bytesToRead = Math.Min(remaining, remainingInSegment); - Result rc = BaseStorage.Read(physicalOffset, destination.Slice(outPos, bytesToRead)); - if (rc.IsFailure()) return rc; + Result res = BaseStorage.Read(physicalOffset, destination.Slice(outPos, bytesToRead)); + if (res.IsFailure()) return res.Miss(); outPos += bytesToRead; inPos += bytesToRead; @@ -81,8 +81,8 @@ public class AllocationTableStorage : IStorage int remainingInSegment = iterator.CurrentSegmentSize * BlockSize - segmentPos; int bytesToWrite = Math.Min(remaining, remainingInSegment); - Result rc = BaseStorage.Write(physicalOffset, source.Slice(outPos, bytesToWrite)); - if (rc.IsFailure()) return rc; + Result res = BaseStorage.Write(physicalOffset, source.Slice(outPos, bytesToWrite)); + if (res.IsFailure()) return res.Miss(); outPos += bytesToWrite; inPos += bytesToWrite; diff --git a/src/LibHac/Tools/FsSystem/Save/DuplexStorage.cs b/src/LibHac/Tools/FsSystem/Save/DuplexStorage.cs index 6b535543..72af3e17 100644 --- a/src/LibHac/Tools/FsSystem/Save/DuplexStorage.cs +++ b/src/LibHac/Tools/FsSystem/Save/DuplexStorage.cs @@ -33,8 +33,8 @@ public class DuplexStorage : IStorage int outPos = 0; int remaining = destination.Length; - Result rc = CheckAccessRange(offset, destination.Length, Length); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckAccessRange(offset, destination.Length, Length); + if (res.IsFailure()) return res.Miss(); while (remaining > 0) { @@ -45,8 +45,8 @@ public class DuplexStorage : IStorage IStorage data = Bitmap.Bitmap[blockNum] ? DataB : DataA; - rc = data.Read(inPos, destination.Slice(outPos, bytesToRead)); - if (rc.IsFailure()) return rc; + res = data.Read(inPos, destination.Slice(outPos, bytesToRead)); + if (res.IsFailure()) return res.Miss(); outPos += bytesToRead; inPos += bytesToRead; @@ -62,8 +62,8 @@ public class DuplexStorage : IStorage int outPos = 0; int remaining = source.Length; - Result rc = CheckAccessRange(offset, source.Length, Length); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckAccessRange(offset, source.Length, Length); + if (res.IsFailure()) return res.Miss(); while (remaining > 0) { @@ -74,8 +74,8 @@ public class DuplexStorage : IStorage IStorage data = Bitmap.Bitmap[blockNum] ? DataB : DataA; - rc = data.Write(inPos, source.Slice(outPos, bytesToWrite)); - if (rc.IsFailure()) return rc; + res = data.Write(inPos, source.Slice(outPos, bytesToWrite)); + if (res.IsFailure()) return res.Miss(); outPos += bytesToWrite; inPos += bytesToWrite; @@ -87,14 +87,14 @@ public class DuplexStorage : IStorage public override Result Flush() { - Result rc = BitmapStorage.Flush(); - if (rc.IsFailure()) return rc; + Result res = BitmapStorage.Flush(); + if (res.IsFailure()) return res.Miss(); - rc = DataA.Flush(); - if (rc.IsFailure()) return rc; + res = DataA.Flush(); + if (res.IsFailure()) return res.Miss(); - rc = DataB.Flush(); - if (rc.IsFailure()) return rc; + res = DataB.Flush(); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/src/LibHac/Tools/FsSystem/Save/JournalStorage.cs b/src/LibHac/Tools/FsSystem/Save/JournalStorage.cs index 4e3774a9..e585eb49 100644 --- a/src/LibHac/Tools/FsSystem/Save/JournalStorage.cs +++ b/src/LibHac/Tools/FsSystem/Save/JournalStorage.cs @@ -40,8 +40,8 @@ public class JournalStorage : IStorage int outPos = 0; int remaining = destination.Length; - Result rc = CheckAccessRange(offset, destination.Length, Length); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckAccessRange(offset, destination.Length, Length); + if (res.IsFailure()) return res.Miss(); while (remaining > 0) { @@ -52,8 +52,8 @@ public class JournalStorage : IStorage int bytesToRead = Math.Min(remaining, BlockSize - blockPos); - rc = BaseStorage.Read(physicalOffset, destination.Slice(outPos, bytesToRead)); - if (rc.IsFailure()) return rc; + res = BaseStorage.Read(physicalOffset, destination.Slice(outPos, bytesToRead)); + if (res.IsFailure()) return res.Miss(); outPos += bytesToRead; inPos += bytesToRead; @@ -69,8 +69,8 @@ public class JournalStorage : IStorage int outPos = 0; int remaining = source.Length; - Result rc = CheckAccessRange(offset, source.Length, Length); - if (rc.IsFailure()) return rc.Miss(); + Result res = CheckAccessRange(offset, source.Length, Length); + if (res.IsFailure()) return res.Miss(); while (remaining > 0) { @@ -81,8 +81,8 @@ public class JournalStorage : IStorage int bytesToWrite = Math.Min(remaining, BlockSize - blockPos); - rc = BaseStorage.Write(physicalOffset, source.Slice(outPos, bytesToWrite)); - if (rc.IsFailure()) return rc; + res = BaseStorage.Write(physicalOffset, source.Slice(outPos, bytesToWrite)); + if (res.IsFailure()) return res.Miss(); outPos += bytesToWrite; inPos += bytesToWrite; diff --git a/src/LibHac/Tools/FsSystem/Save/RemapStorage.cs b/src/LibHac/Tools/FsSystem/Save/RemapStorage.cs index b2867b31..2f4e23db 100644 --- a/src/LibHac/Tools/FsSystem/Save/RemapStorage.cs +++ b/src/LibHac/Tools/FsSystem/Save/RemapStorage.cs @@ -95,8 +95,8 @@ public class RemapStorage : IStorage int bytesToWrite = (int)Math.Min(entry.VirtualOffsetEnd - inPos, remaining); - Result rc = BaseStorage.Write(entry.PhysicalOffset + entryPos, source.Slice(outPos, bytesToWrite)); - if (rc.IsFailure()) return rc; + Result res = BaseStorage.Write(entry.PhysicalOffset + entryPos, source.Slice(outPos, bytesToWrite)); + if (res.IsFailure()) return res.Miss(); outPos += bytesToWrite; inPos += bytesToWrite; diff --git a/src/LibHac/Tools/FsSystem/Save/SaveDataFile.cs b/src/LibHac/Tools/FsSystem/Save/SaveDataFile.cs index fd8793cd..63ba9adc 100644 --- a/src/LibHac/Tools/FsSystem/Save/SaveDataFile.cs +++ b/src/LibHac/Tools/FsSystem/Save/SaveDataFile.cs @@ -28,8 +28,8 @@ public class SaveDataFile : IFile { UnsafeHelpers.SkipParamInit(out bytesRead); - Result rc = DryRead(out long toRead, offset, destination.Length, in option, Mode); - if (rc.IsFailure()) return rc; + Result res = DryRead(out long toRead, offset, destination.Length, in option, Mode); + if (res.IsFailure()) return res.Miss(); if (toRead == 0) { @@ -37,8 +37,8 @@ public class SaveDataFile : IFile return Result.Success; } - rc = BaseStorage.Read(offset, destination.Slice(0, (int)toRead)); - if (rc.IsFailure()) return rc; + res = BaseStorage.Read(offset, destination.Slice(0, (int)toRead)); + if (res.IsFailure()) return res.Miss(); bytesRead = toRead; return Result.Success; @@ -46,17 +46,17 @@ public class SaveDataFile : IFile protected override Result DoWrite(long offset, ReadOnlySpan source, in WriteOption option) { - Result rc = DryWrite(out bool isResizeNeeded, offset, source.Length, in option, Mode); - if (rc.IsFailure()) return rc; + Result res = DryWrite(out bool isResizeNeeded, offset, source.Length, in option, Mode); + if (res.IsFailure()) return res.Miss(); if (isResizeNeeded) { - rc = DoSetSize(offset + source.Length); - if (rc.IsFailure()) return rc; + res = DoSetSize(offset + source.Length); + if (res.IsFailure()) return res.Miss(); } - rc = BaseStorage.Write(offset, source); - if (rc.IsFailure()) return rc; + res = BaseStorage.Write(offset, source); + if (res.IsFailure()) return res.Miss(); if (option.HasFlushFlag()) { @@ -82,8 +82,8 @@ public class SaveDataFile : IFile if (size < 0) throw new ArgumentOutOfRangeException(nameof(size)); if (Size == size) return Result.Success; - Result rc = BaseStorage.SetSize(size); - if (rc.IsFailure()) return rc; + Result res = BaseStorage.SetSize(size); + if (res.IsFailure()) return res.Miss(); if (!FileTable.TryOpenFile(Path, out SaveFileInfo fileInfo)) { diff --git a/src/LibHac/Tools/FsSystem/Save/SaveDataFileSystemCore.cs b/src/LibHac/Tools/FsSystem/Save/SaveDataFileSystemCore.cs index a34b5871..272b30b3 100644 --- a/src/LibHac/Tools/FsSystem/Save/SaveDataFileSystemCore.cs +++ b/src/LibHac/Tools/FsSystem/Save/SaveDataFileSystemCore.cs @@ -34,8 +34,8 @@ public class SaveDataFileSystemCore : IFileSystem private Result CheckIfNormalized(in Path path) { - Result rc = PathNormalizer.IsNormalized(out bool isNormalized, out _, path.GetString()); - if (rc.IsFailure()) return rc; + Result res = PathNormalizer.IsNormalized(out bool isNormalized, out _, path.GetString()); + if (res.IsFailure()) return res.Miss(); if (!isNormalized) return ResultFs.NotNormalized.Log(); @@ -45,8 +45,8 @@ public class SaveDataFileSystemCore : IFileSystem protected override Result DoCreateDirectory(in Path path) { - Result rc = CheckIfNormalized(in path); - if (rc.IsFailure()) return rc; + Result res = CheckIfNormalized(in path); + if (res.IsFailure()) return res.Miss(); FileTable.AddDirectory(new U8Span(path.GetString())); @@ -55,8 +55,8 @@ public class SaveDataFileSystemCore : IFileSystem protected override Result DoCreateFile(in Path path, long size, CreateFileOptions option) { - Result rc = CheckIfNormalized(in path); - if (rc.IsFailure()) return rc; + Result res = CheckIfNormalized(in path); + if (res.IsFailure()) return res.Miss(); if (size == 0) { @@ -83,8 +83,8 @@ public class SaveDataFileSystemCore : IFileSystem protected override Result DoDeleteDirectory(in Path path) { - Result rc = CheckIfNormalized(in path); - if (rc.IsFailure()) return rc; + Result res = CheckIfNormalized(in path); + if (res.IsFailure()) return res.Miss(); FileTable.DeleteDirectory(new U8Span(path.GetString())); @@ -93,22 +93,22 @@ public class SaveDataFileSystemCore : IFileSystem protected override Result DoDeleteDirectoryRecursively(in Path path) { - Result rc = CheckIfNormalized(in path); - if (rc.IsFailure()) return rc; + Result res = CheckIfNormalized(in path); + if (res.IsFailure()) return res.Miss(); - rc = CleanDirectoryRecursively(in path); - if (rc.IsFailure()) return rc; + res = CleanDirectoryRecursively(in path); + if (res.IsFailure()) return res.Miss(); - rc = DeleteDirectory(in path); - if (rc.IsFailure()) return rc; + res = DeleteDirectory(in path); + if (res.IsFailure()) return res.Miss(); return Result.Success; } protected override Result DoCleanDirectoryRecursively(in Path path) { - Result rc = CheckIfNormalized(in path); - if (rc.IsFailure()) return rc; + Result res = CheckIfNormalized(in path); + if (res.IsFailure()) return res.Miss(); FileSystemExtensions.CleanDirectoryRecursivelyGeneric(this, new U8Span(path.GetString()).ToString()); @@ -117,8 +117,8 @@ public class SaveDataFileSystemCore : IFileSystem protected override Result DoDeleteFile(in Path path) { - Result rc = CheckIfNormalized(in path); - if (rc.IsFailure()) return rc; + Result res = CheckIfNormalized(in path); + if (res.IsFailure()) return res.Miss(); if (!FileTable.TryOpenFile(new U8Span(path.GetString()), out SaveFileInfo fileInfo)) { @@ -138,8 +138,8 @@ public class SaveDataFileSystemCore : IFileSystem protected override Result DoOpenDirectory(ref UniqueRef outDirectory, in Path path, OpenDirectoryMode mode) { - Result rc = CheckIfNormalized(in path); - if (rc.IsFailure()) return rc; + Result res = CheckIfNormalized(in path); + if (res.IsFailure()) return res.Miss(); if (!FileTable.TryOpenDirectory(new U8Span(path.GetString()), out SaveFindPosition position)) { @@ -153,8 +153,8 @@ public class SaveDataFileSystemCore : IFileSystem protected override Result DoOpenFile(ref UniqueRef outFile, in Path path, OpenMode mode) { - Result rc = CheckIfNormalized(in path); - if (rc.IsFailure()) return rc; + Result res = CheckIfNormalized(in path); + if (res.IsFailure()) return res.Miss(); if (!FileTable.TryOpenFile(new U8Span(path.GetString()), out SaveFileInfo fileInfo)) { @@ -170,22 +170,22 @@ public class SaveDataFileSystemCore : IFileSystem protected override Result DoRenameDirectory(in Path currentPath, in Path newPath) { - Result rc = CheckIfNormalized(in currentPath); - if (rc.IsFailure()) return rc; + Result res = CheckIfNormalized(in currentPath); + if (res.IsFailure()) return res.Miss(); - rc = CheckIfNormalized(in newPath); - if (rc.IsFailure()) return rc; + res = CheckIfNormalized(in newPath); + if (res.IsFailure()) return res.Miss(); return FileTable.RenameDirectory(new U8Span(currentPath.GetString()), new U8Span(newPath.GetString())); } protected override Result DoRenameFile(in Path currentPath, in Path newPath) { - Result rc = CheckIfNormalized(in currentPath); - if (rc.IsFailure()) return rc; + Result res = CheckIfNormalized(in currentPath); + if (res.IsFailure()) return res.Miss(); - rc = CheckIfNormalized(in newPath); - if (rc.IsFailure()) return rc; + res = CheckIfNormalized(in newPath); + if (res.IsFailure()) return res.Miss(); FileTable.RenameFile(new U8Span(currentPath.GetString()), new U8Span(newPath.GetString())); @@ -196,8 +196,8 @@ public class SaveDataFileSystemCore : IFileSystem { UnsafeHelpers.SkipParamInit(out entryType); - Result rc = CheckIfNormalized(in path); - if (rc.IsFailure()) return rc; + Result res = CheckIfNormalized(in path); + if (res.IsFailure()) return res.Miss(); if (FileTable.TryOpenFile(new U8Span(path.GetString()), out SaveFileInfo _)) { diff --git a/src/LibHac/Tools/FsSystem/SectorStorage.cs b/src/LibHac/Tools/FsSystem/SectorStorage.cs index c3051cbc..1d95e147 100644 --- a/src/LibHac/Tools/FsSystem/SectorStorage.cs +++ b/src/LibHac/Tools/FsSystem/SectorStorage.cs @@ -52,11 +52,11 @@ public class SectorStorage : IStorage public override Result SetSize(long size) { - Result rc = BaseStorage.SetSize(size); - if (rc.IsFailure()) return rc; + Result res = BaseStorage.SetSize(size); + if (res.IsFailure()) return res.Miss(); - rc = BaseStorage.GetSize(out long newSize); - if (rc.IsFailure()) return rc; + res = BaseStorage.GetSize(out long newSize); + if (res.IsFailure()) return res.Miss(); SectorCount = (int)BitUtil.DivideUp(newSize, SectorSize); Length = newSize; diff --git a/src/LibHac/Tools/FsSystem/StreamFile.cs b/src/LibHac/Tools/FsSystem/StreamFile.cs index 60ec7bba..470132c2 100644 --- a/src/LibHac/Tools/FsSystem/StreamFile.cs +++ b/src/LibHac/Tools/FsSystem/StreamFile.cs @@ -28,8 +28,8 @@ public class StreamFile : IFile { UnsafeHelpers.SkipParamInit(out bytesRead); - Result rc = DryRead(out long toRead, offset, destination.Length, in option, Mode); - if (rc.IsFailure()) return rc; + Result res = DryRead(out long toRead, offset, destination.Length, in option, Mode); + if (res.IsFailure()) return res.Miss(); lock (Locker) { @@ -45,8 +45,8 @@ public class StreamFile : IFile protected override Result DoWrite(long offset, ReadOnlySpan source, in WriteOption option) { - Result rc = DryWrite(out _, offset, source.Length, in option, Mode); - if (rc.IsFailure()) return rc; + Result res = DryWrite(out _, offset, source.Length, in option, Mode); + if (res.IsFailure()) return res.Miss(); lock (Locker) { diff --git a/src/hactoolnet/FsUtils.cs b/src/hactoolnet/FsUtils.cs index 1e12d8a7..a935829e 100644 --- a/src/hactoolnet/FsUtils.cs +++ b/src/hactoolnet/FsUtils.cs @@ -32,8 +32,8 @@ public static class FsUtils string sourcePathStr = sourcePath.ToString(); string destPathStr = destPath.ToString(); - Result rc = fs.OpenDirectory(out DirectoryHandle sourceHandle, sourcePath, OpenDirectoryMode.All); - if (rc.IsFailure()) return rc; + Result res = fs.OpenDirectory(out DirectoryHandle sourceHandle, sourcePath, OpenDirectoryMode.All); + if (res.IsFailure()) return res.Miss(); try { @@ -46,19 +46,19 @@ public static class FsUtils { fs.EnsureDirectoryExists(subDstPath); - rc = CopyDirectoryWithProgressInternal(fs, subSrcPath.ToU8Span(), subDstPath.ToU8Span(), options, logger); - if (rc.IsFailure()) return rc; + res = CopyDirectoryWithProgressInternal(fs, subSrcPath.ToU8Span(), subDstPath.ToU8Span(), options, logger); + if (res.IsFailure()) return res.Miss(); } if (entry.Type == DirectoryEntryType.File) { logger?.LogMessage(subSrcPath); - rc = fs.CreateOrOverwriteFile(subDstPath, entry.Size, options); - if (rc.IsFailure()) return rc; + res = fs.CreateOrOverwriteFile(subDstPath, entry.Size, options); + if (res.IsFailure()) return res.Miss(); - rc = CopyFileWithProgress(fs, subSrcPath.ToU8Span(), subDstPath.ToU8Span(), logger); - if (rc.IsFailure()) return rc; + res = CopyFileWithProgress(fs, subSrcPath.ToU8Span(), subDstPath.ToU8Span(), logger); + if (res.IsFailure()) return res.Miss(); } } } @@ -85,20 +85,20 @@ public static class FsUtils public static Result CopyFileWithProgress(FileSystemClient fs, U8Span sourcePath, U8Span destPath, IProgressReport logger = null) { - Result rc = fs.OpenFile(out FileHandle sourceHandle, sourcePath, OpenMode.Read); - if (rc.IsFailure()) return rc; + Result res = fs.OpenFile(out FileHandle sourceHandle, sourcePath, OpenMode.Read); + if (res.IsFailure()) return res.Miss(); try { - rc = fs.OpenFile(out FileHandle destHandle, destPath, OpenMode.Write | OpenMode.AllowAppend); - if (rc.IsFailure()) return rc; + res = fs.OpenFile(out FileHandle destHandle, destPath, OpenMode.Write | OpenMode.AllowAppend); + if (res.IsFailure()) return res.Miss(); try { const int maxBufferSize = 1024 * 1024; - rc = fs.GetFileSize(out long fileSize, sourceHandle); - if (rc.IsFailure()) return rc; + res = fs.GetFileSize(out long fileSize, sourceHandle); + if (res.IsFailure()) return res.Miss(); int bufferSize = (int)Math.Min(maxBufferSize, fileSize); @@ -110,11 +110,11 @@ public static class FsUtils int toRead = (int)Math.Min(fileSize - offset, bufferSize); Span buf = buffer.AsSpan(0, toRead); - rc = fs.ReadFile(out long _, sourceHandle, offset, buf); - if (rc.IsFailure()) return rc; + res = fs.ReadFile(out long _, sourceHandle, offset, buf); + if (res.IsFailure()) return res.Miss(); - rc = fs.WriteFile(destHandle, offset, buf, WriteOption.None); - if (rc.IsFailure()) return rc; + res = fs.WriteFile(destHandle, offset, buf, WriteOption.None); + if (res.IsFailure()) return res.Miss(); logger?.ReportAdd(toRead); } @@ -124,8 +124,8 @@ public static class FsUtils ArrayPool.Shared.Return(buffer); } - rc = fs.FlushFile(destHandle); - if (rc.IsFailure()) return rc; + res = fs.FlushFile(destHandle); + if (res.IsFailure()) return res.Miss(); } finally { diff --git a/src/hactoolnet/ProcessNca.cs b/src/hactoolnet/ProcessNca.cs index cf1a913b..6029be02 100644 --- a/src/hactoolnet/ProcessNca.cs +++ b/src/hactoolnet/ProcessNca.cs @@ -293,8 +293,8 @@ internal static class ProcessNca IFileSystem fs = nca.OpenFileSystem(NcaSectionType.Code, IntegrityCheckLevel.None); using var file = new UniqueRef(); - Result r = fs.OpenFile(ref file.Ref(), "/main.npdm".ToU8String(), OpenMode.Read); - if (r.IsSuccess()) + Result res = fs.OpenFile(ref file.Ref(), "/main.npdm".ToU8String(), OpenMode.Read); + if (res.IsSuccess()) { var npdm = new NpdmBinary(file.Release().AsStream(), null); PrintItem(sb, colLen, "Title Name:", npdm.TitleName); diff --git a/src/hactoolnet/ProcessPackage.cs b/src/hactoolnet/ProcessPackage.cs index b62670af..1f188a35 100644 --- a/src/hactoolnet/ProcessPackage.cs +++ b/src/hactoolnet/ProcessPackage.cs @@ -153,9 +153,9 @@ internal static class ProcessPackage private static string Print(this Package2StorageReader package2) { - Result rc = package2.VerifySignature(); + Result res = package2.VerifySignature(); - Validity signatureValidity = rc.IsSuccess() ? Validity.Valid : Validity.Invalid; + Validity signatureValidity = res.IsSuccess() ? Validity.Valid : Validity.Invalid; int colLen = 36; var sb = new StringBuilder(); diff --git a/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/SaveDataManagement.cs b/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/SaveDataManagement.cs index a3cf4783..7f997e30 100644 --- a/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/SaveDataManagement.cs +++ b/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/SaveDataManagement.cs @@ -685,8 +685,8 @@ public class SaveDataManagement for (int i = 1; i <= count; i++) { var applicationId = new Ncm.ApplicationId((uint)i); - Result rc = fs.CreateSaveData(applicationId, InvalidUserId, 0, 0x4000, 0x4000, SaveDataFlags.None); - if (rc.IsFailure()) return rc; + Result res = fs.CreateSaveData(applicationId, InvalidUserId, 0, 0x4000, 0x4000, SaveDataFlags.None); + if (res.IsFailure()) return res.Miss(); } } else @@ -696,8 +696,8 @@ public class SaveDataManagement for (int i = 1; i <= count; i++) { var applicationId = new Ncm.ApplicationId((uint)rng.Next()); - Result rc = fs.CreateSaveData(applicationId, InvalidUserId, 0, 0x4000, 0x4000, SaveDataFlags.None); - if (rc.IsFailure()) return rc; + Result res = fs.CreateSaveData(applicationId, InvalidUserId, 0, 0x4000, 0x4000, SaveDataFlags.None); + if (res.IsFailure()) return res.Miss(); } } diff --git a/tests/LibHac.Tests/Fs/FsaExtensions.cs b/tests/LibHac.Tests/Fs/FsaExtensions.cs index 5d405d11..e95a76a8 100644 --- a/tests/LibHac.Tests/Fs/FsaExtensions.cs +++ b/tests/LibHac.Tests/Fs/FsaExtensions.cs @@ -13,11 +13,11 @@ public static class FsaExtensions if (value is null) return ResultFs.NullptrArgument.Log(); - Result rc = path.Initialize(StringUtils.StringToUtf8(value)); - if (rc.IsFailure()) return rc; + Result res = path.Initialize(StringUtils.StringToUtf8(value)); + if (res.IsFailure()) return res.Miss(); - rc = path.Normalize(new PathFlags()); - if (rc.IsFailure()) return rc; + res = path.Normalize(new PathFlags()); + if (res.IsFailure()) return res.Miss(); return Result.Success; } @@ -25,8 +25,8 @@ public static class FsaExtensions public static Result CreateFile(this IFileSystem fs, string path, long size, CreateFileOptions option) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return fs.CreateFile(in pathNormalized, size, option); } @@ -39,8 +39,8 @@ public static class FsaExtensions public static Result DeleteFile(this IFileSystem fs, string path) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return fs.DeleteFile(in pathNormalized); } @@ -48,8 +48,8 @@ public static class FsaExtensions public static Result CreateDirectory(this IFileSystem fs, string path) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return fs.CreateDirectory(in pathNormalized); } @@ -57,8 +57,8 @@ public static class FsaExtensions public static Result DeleteDirectory(this IFileSystem fs, string path) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return fs.DeleteDirectory(in pathNormalized); } @@ -66,8 +66,8 @@ public static class FsaExtensions public static Result DeleteDirectoryRecursively(this IFileSystem fs, string path) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return fs.DeleteDirectoryRecursively(in pathNormalized); } @@ -75,8 +75,8 @@ public static class FsaExtensions public static Result CleanDirectoryRecursively(this IFileSystem fs, string path) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return fs.CleanDirectoryRecursively(in pathNormalized); } @@ -84,12 +84,12 @@ public static class FsaExtensions public static Result RenameFile(this IFileSystem fs, string currentPath, string newPath) { using var currentPathNormalized = new Path(); - Result rc = SetUpPath(ref currentPathNormalized.Ref(), currentPath); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref currentPathNormalized.Ref(), currentPath); + if (res.IsFailure()) return res.Miss(); using var newPathNormalized = new Path(); - rc = SetUpPath(ref newPathNormalized.Ref(), newPath); - if (rc.IsFailure()) return rc; + res = SetUpPath(ref newPathNormalized.Ref(), newPath); + if (res.IsFailure()) return res.Miss(); return fs.RenameFile(in currentPathNormalized, in newPathNormalized); } @@ -97,12 +97,12 @@ public static class FsaExtensions public static Result RenameDirectory(this IFileSystem fs, string currentPath, string newPath) { using var currentPathNormalized = new Path(); - Result rc = SetUpPath(ref currentPathNormalized.Ref(), currentPath); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref currentPathNormalized.Ref(), currentPath); + if (res.IsFailure()) return res.Miss(); using var newPathNormalized = new Path(); - rc = SetUpPath(ref newPathNormalized.Ref(), newPath); - if (rc.IsFailure()) return rc; + res = SetUpPath(ref newPathNormalized.Ref(), newPath); + if (res.IsFailure()) return res.Miss(); return fs.RenameDirectory(in currentPathNormalized, in newPathNormalized); } @@ -112,8 +112,8 @@ public static class FsaExtensions UnsafeHelpers.SkipParamInit(out entryType); using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return fs.GetEntryType(out entryType, in pathNormalized); } @@ -123,8 +123,8 @@ public static class FsaExtensions UnsafeHelpers.SkipParamInit(out freeSpace); using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return fs.GetFreeSpaceSize(out freeSpace, in pathNormalized); } @@ -134,8 +134,8 @@ public static class FsaExtensions UnsafeHelpers.SkipParamInit(out totalSpace); using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return fs.GetTotalSpaceSize(out totalSpace, in pathNormalized); } @@ -143,8 +143,8 @@ public static class FsaExtensions public static Result OpenFile(this IFileSystem fs, ref UniqueRef file, string path, OpenMode mode) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return fs.OpenFile(ref file, in pathNormalized, mode); } @@ -152,8 +152,8 @@ public static class FsaExtensions public static Result OpenDirectory(this IFileSystem fs, ref UniqueRef directory, string path, OpenDirectoryMode mode) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return fs.OpenDirectory(ref directory, in pathNormalized, mode); } @@ -163,8 +163,8 @@ public static class FsaExtensions UnsafeHelpers.SkipParamInit(out timeStamp); using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return fs.GetFileTimeStampRaw(out timeStamp, in pathNormalized); } @@ -172,8 +172,8 @@ public static class FsaExtensions public static Result QueryEntry(this IFileSystem fs, Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, string path) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return fs.QueryEntry(outBuffer, inBuffer, queryId, in pathNormalized); } @@ -181,8 +181,8 @@ public static class FsaExtensions public static Result CreateDirectory(this IAttributeFileSystem fs, string path, NxFileAttributes archiveAttribute) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return fs.CreateDirectory(in pathNormalized, archiveAttribute); } @@ -192,8 +192,8 @@ public static class FsaExtensions UnsafeHelpers.SkipParamInit(out attributes); using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return fs.GetFileAttributes(out attributes, in pathNormalized); } @@ -201,8 +201,8 @@ public static class FsaExtensions public static Result SetFileAttributes(this IAttributeFileSystem fs, string path, NxFileAttributes attributes) { using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return fs.SetFileAttributes(in pathNormalized, attributes); } @@ -212,8 +212,8 @@ public static class FsaExtensions UnsafeHelpers.SkipParamInit(out fileSize); using var pathNormalized = new Path(); - Result rc = SetUpPath(ref pathNormalized.Ref(), path); - if (rc.IsFailure()) return rc; + Result res = SetUpPath(ref pathNormalized.Ref(), path); + if (res.IsFailure()) return res.Miss(); return fs.GetFileSize(out fileSize, in pathNormalized); } diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IAttributeFileSystemTests.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IAttributeFileSystemTests.cs index b7e28776..3f262eaf 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IAttributeFileSystemTests.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IAttributeFileSystemTests.cs @@ -55,9 +55,9 @@ public abstract class IAttributeFileSystemTests : IFileSystemTests { IAttributeFileSystem fs = CreateAttributeFileSystem(); - Result rc = fs.GetFileAttributes(out _, "/path"); + Result res = fs.GetFileAttributes(out _, "/path"); - Assert.Result(ResultFs.PathNotFound, rc); + Assert.Result(ResultFs.PathNotFound, res); } [Fact] @@ -65,9 +65,9 @@ public abstract class IAttributeFileSystemTests : IFileSystemTests { IAttributeFileSystem fs = CreateAttributeFileSystem(); - Result rc = fs.SetFileAttributes("/path", NxFileAttributes.None); + Result res = fs.SetFileAttributes("/path", NxFileAttributes.None); - Assert.Result(ResultFs.PathNotFound, rc); + Assert.Result(ResultFs.PathNotFound, res); } [Fact] @@ -76,11 +76,11 @@ public abstract class IAttributeFileSystemTests : IFileSystemTests IAttributeFileSystem fs = CreateAttributeFileSystem(); fs.CreateFile("/file", 0, CreateFileOptions.None); - Result rcSet = fs.SetFileAttributes("/file", NxFileAttributes.Archive); - Result rcGet = fs.GetFileAttributes(out NxFileAttributes attributes, "/file"); + Result resultSet = fs.SetFileAttributes("/file", NxFileAttributes.Archive); + Result resultGet = fs.GetFileAttributes(out NxFileAttributes attributes, "/file"); - Assert.Success(rcSet); - Assert.Success(rcGet); + Assert.Success(resultSet); + Assert.Success(resultGet); Assert.Equal(NxFileAttributes.Archive, attributes); } @@ -90,11 +90,11 @@ public abstract class IAttributeFileSystemTests : IFileSystemTests IAttributeFileSystem fs = CreateAttributeFileSystem(); fs.CreateDirectory("/dir"); - Result rcSet = fs.SetFileAttributes("/dir", NxFileAttributes.Archive); - Result rcGet = fs.GetFileAttributes(out NxFileAttributes attributes, "/dir"); + Result resultSet = fs.SetFileAttributes("/dir", NxFileAttributes.Archive); + Result resultGet = fs.GetFileAttributes(out NxFileAttributes attributes, "/dir"); - Assert.Success(rcSet); - Assert.Success(rcGet); + Assert.Success(resultSet); + Assert.Success(resultGet); Assert.Equal(NxFileAttributes.Directory | NxFileAttributes.Archive, attributes); } @@ -114,9 +114,9 @@ public abstract class IAttributeFileSystemTests : IFileSystemTests { IAttributeFileSystem fs = CreateAttributeFileSystem(); - Result rc = fs.GetFileSize(out _, "/path"); + Result res = fs.GetFileSize(out _, "/path"); - Assert.Result(ResultFs.PathNotFound, rc); + Assert.Result(ResultFs.PathNotFound, res); } [Fact] @@ -125,8 +125,8 @@ public abstract class IAttributeFileSystemTests : IFileSystemTests IAttributeFileSystem fs = CreateAttributeFileSystem(); fs.CreateDirectory("/dir"); - Result rc = fs.GetFileSize(out _, "/dir"); + Result res = fs.GetFileSize(out _, "/dir"); - Assert.Result(ResultFs.PathNotFound, rc); + Assert.Result(ResultFs.PathNotFound, res); } } diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CleanDirectoryRecursively.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CleanDirectoryRecursively.cs index 0056d009..d0974d54 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CleanDirectoryRecursively.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CleanDirectoryRecursively.cs @@ -15,18 +15,18 @@ public abstract partial class IFileSystemTests fs.CreateDirectory("/dir/dir2"); fs.CreateFile("/dir/file1", 0, CreateFileOptions.None); - Result rcDelete = fs.CleanDirectoryRecursively("/dir"); + Result resultDelete = fs.CleanDirectoryRecursively("/dir"); - Result rcDir1Type = fs.GetEntryType(out DirectoryEntryType dir1Type, "/dir"); - Result rcDir2Type = fs.GetEntryType(out _, "/dir/dir2"); - Result rcFileType = fs.GetEntryType(out _, "/dir/file1"); + Result resultDir1Type = fs.GetEntryType(out DirectoryEntryType dir1Type, "/dir"); + Result resultDir2Type = fs.GetEntryType(out _, "/dir/dir2"); + Result resultFileType = fs.GetEntryType(out _, "/dir/file1"); - Assert.Success(rcDelete); + Assert.Success(resultDelete); - Assert.Success(rcDir1Type); + Assert.Success(resultDir1Type); Assert.Equal(DirectoryEntryType.Directory, dir1Type); - Assert.Result(ResultFs.PathNotFound, rcDir2Type); - Assert.Result(ResultFs.PathNotFound, rcFileType); + Assert.Result(ResultFs.PathNotFound, resultDir2Type); + Assert.Result(ResultFs.PathNotFound, resultFileType); } } diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CreateDirectory.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CreateDirectory.cs index 216f9c8d..9985fac4 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CreateDirectory.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CreateDirectory.cs @@ -24,9 +24,9 @@ public abstract partial class IFileSystemTests fs.CreateDirectory("/dir"); - Result rc = fs.CreateDirectory("/dir"); + Result res = fs.CreateDirectory("/dir"); - Assert.Result(ResultFs.PathAlreadyExists, rc); + Assert.Result(ResultFs.PathAlreadyExists, res); } [Fact] @@ -36,9 +36,9 @@ public abstract partial class IFileSystemTests fs.CreateFile("/file", 0, CreateFileOptions.None); - Result rc = fs.CreateDirectory("/file"); + Result res = fs.CreateDirectory("/file"); - Assert.Result(ResultFs.PathAlreadyExists, rc); + Assert.Result(ResultFs.PathAlreadyExists, res); } [Fact] @@ -46,9 +46,9 @@ public abstract partial class IFileSystemTests { IFileSystem fs = CreateFileSystem(); - Result rc = fs.CreateFile("/dir1/dir2", 0, CreateFileOptions.None); + Result res = fs.CreateFile("/dir1/dir2", 0, CreateFileOptions.None); - Assert.Result(ResultFs.PathNotFound, rc); + Assert.Result(ResultFs.PathNotFound, res); } [Fact] @@ -57,9 +57,9 @@ public abstract partial class IFileSystemTests IFileSystem fs = CreateFileSystem(); fs.CreateDirectory("/dir/"); - Result rc = fs.GetEntryType(out DirectoryEntryType type, "/dir/"); + Result res = fs.GetEntryType(out DirectoryEntryType type, "/dir/"); - Assert.Success(rc); + Assert.Success(res); Assert.Equal(DirectoryEntryType.Directory, type); } @@ -71,11 +71,11 @@ public abstract partial class IFileSystemTests fs.CreateDirectory("/dir1"); fs.CreateDirectory("/dir2"); - Result rc1 = fs.GetEntryType(out DirectoryEntryType type1, "/dir1"); - Result rc2 = fs.GetEntryType(out DirectoryEntryType type2, "/dir2"); + Result result1 = fs.GetEntryType(out DirectoryEntryType type1, "/dir1"); + Result result2 = fs.GetEntryType(out DirectoryEntryType type2, "/dir2"); - Assert.Success(rc1); - Assert.Success(rc2); + Assert.Success(result1); + Assert.Success(result2); Assert.Equal(DirectoryEntryType.Directory, type1); Assert.Equal(DirectoryEntryType.Directory, type2); } @@ -91,11 +91,11 @@ public abstract partial class IFileSystemTests fs.CreateDirectory("/dir1/dir1a"); fs.CreateDirectory("/dir2/dir2a"); - Result rc1 = fs.GetEntryType(out DirectoryEntryType type1, "/dir1/dir1a"); - Result rc2 = fs.GetEntryType(out DirectoryEntryType type2, "/dir2/dir2a"); + Result result1 = fs.GetEntryType(out DirectoryEntryType type1, "/dir1/dir1a"); + Result result2 = fs.GetEntryType(out DirectoryEntryType type2, "/dir2/dir2a"); - Assert.Success(rc1); - Assert.Success(rc2); + Assert.Success(result1); + Assert.Success(result2); Assert.Equal(DirectoryEntryType.Directory, type1); Assert.Equal(DirectoryEntryType.Directory, type2); } diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CreateFile.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CreateFile.cs index 66eb0c06..a127bd7f 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CreateFile.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CreateFile.cs @@ -13,9 +13,9 @@ public abstract partial class IFileSystemTests IFileSystem fs = CreateFileSystem(); fs.CreateFile("/file", 0, CreateFileOptions.None); - Result rc = fs.GetEntryType(out DirectoryEntryType type, "/file"); + Result res = fs.GetEntryType(out DirectoryEntryType type, "/file"); - Assert.Success(rc); + Assert.Success(res); Assert.Equal(DirectoryEntryType.File, type); } @@ -26,9 +26,9 @@ public abstract partial class IFileSystemTests fs.CreateDirectory("/dir"); - Result rc = fs.CreateFile("/dir", 0, CreateFileOptions.None); + Result res = fs.CreateFile("/dir", 0, CreateFileOptions.None); - Assert.Result(ResultFs.PathAlreadyExists, rc); + Assert.Result(ResultFs.PathAlreadyExists, res); } [Fact] @@ -38,9 +38,9 @@ public abstract partial class IFileSystemTests fs.CreateFile("/file", 0, CreateFileOptions.None); - Result rc = fs.CreateFile("/file", 0, CreateFileOptions.None); + Result res = fs.CreateFile("/file", 0, CreateFileOptions.None); - Assert.Result(ResultFs.PathAlreadyExists, rc); + Assert.Result(ResultFs.PathAlreadyExists, res); } [Fact] @@ -48,9 +48,9 @@ public abstract partial class IFileSystemTests { IFileSystem fs = CreateFileSystem(); - Result rc = fs.CreateFile("/dir/file", 0, CreateFileOptions.None); + Result res = fs.CreateFile("/dir/file", 0, CreateFileOptions.None); - Assert.Result(ResultFs.PathNotFound, rc); + Assert.Result(ResultFs.PathNotFound, res); } [Fact] @@ -88,11 +88,11 @@ public abstract partial class IFileSystemTests fs.CreateFile("/file1", 0, CreateFileOptions.None); fs.CreateFile("/file2", 0, CreateFileOptions.None); - Result rc1 = fs.GetEntryType(out DirectoryEntryType type1, "/file1"); - Result rc2 = fs.GetEntryType(out DirectoryEntryType type2, "/file2"); + Result result1 = fs.GetEntryType(out DirectoryEntryType type1, "/file1"); + Result result2 = fs.GetEntryType(out DirectoryEntryType type2, "/file2"); - Assert.Success(rc1); - Assert.Success(rc2); + Assert.Success(result1); + Assert.Success(result2); Assert.Equal(DirectoryEntryType.File, type1); Assert.Equal(DirectoryEntryType.File, type2); } @@ -108,11 +108,11 @@ public abstract partial class IFileSystemTests fs.CreateFile("/dir1/file1", 0, CreateFileOptions.None); fs.CreateFile("/dir2/file2", 0, CreateFileOptions.None); - Result rc1 = fs.GetEntryType(out DirectoryEntryType type1, "/dir1/file1"); - Result rc2 = fs.GetEntryType(out DirectoryEntryType type2, "/dir2/file2"); + Result result1 = fs.GetEntryType(out DirectoryEntryType type1, "/dir1/file1"); + Result result2 = fs.GetEntryType(out DirectoryEntryType type2, "/dir2/file2"); - Assert.Success(rc1); - Assert.Success(rc2); + Assert.Success(result1); + Assert.Success(result2); Assert.Equal(DirectoryEntryType.File, type1); Assert.Equal(DirectoryEntryType.File, type2); } diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteDirectory.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteDirectory.cs index ba37e137..4fc7bf06 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteDirectory.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteDirectory.cs @@ -11,9 +11,9 @@ public abstract partial class IFileSystemTests { IFileSystem fs = CreateFileSystem(); - Result rc = fs.DeleteDirectory("/dir"); + Result res = fs.DeleteDirectory("/dir"); - Assert.Result(ResultFs.PathNotFound, rc); + Assert.Result(ResultFs.PathNotFound, res); } [Fact] @@ -23,11 +23,11 @@ public abstract partial class IFileSystemTests fs.CreateDirectory("/dir"); - Result rcDelete = fs.DeleteDirectory("/dir"); - Result rcEntry = fs.GetEntryType(out _, "/dir"); + Result resultDelete = fs.DeleteDirectory("/dir"); + Result resultEntry = fs.GetEntryType(out _, "/dir"); - Assert.Success(rcDelete); - Assert.Result(ResultFs.PathNotFound, rcEntry); + Assert.Success(resultDelete); + Assert.Result(ResultFs.PathNotFound, resultEntry); } [Fact] @@ -37,9 +37,9 @@ public abstract partial class IFileSystemTests fs.CreateFile("/file", 0, CreateFileOptions.None); - Result rc = fs.DeleteDirectory("/file"); + Result res = fs.DeleteDirectory("/file"); - Assert.Result(ResultFs.PathNotFound, rc); + Assert.Result(ResultFs.PathNotFound, res); } [Fact] @@ -50,13 +50,13 @@ public abstract partial class IFileSystemTests fs.CreateDirectory("/dir1"); fs.CreateDirectory("/dir2"); - Result rcDelete = fs.DeleteDirectory("/dir2"); - Result rcEntry1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/dir1"); - Result rcEntry2 = fs.GetEntryType(out _, "/dir2"); + Result resultDelete = fs.DeleteDirectory("/dir2"); + Result resultEntry1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/dir1"); + Result resultEntry2 = fs.GetEntryType(out _, "/dir2"); - Assert.Success(rcDelete); - Assert.Success(rcEntry1); - Assert.Result(ResultFs.PathNotFound, rcEntry2); + Assert.Success(resultDelete); + Assert.Success(resultEntry1); + Assert.Result(ResultFs.PathNotFound, resultEntry2); Assert.Equal(DirectoryEntryType.Directory, dir1Type); } @@ -69,13 +69,13 @@ public abstract partial class IFileSystemTests fs.CreateDirectory("/dir2"); fs.CreateDirectory("/dir1"); - Result rcDelete = fs.DeleteDirectory("/dir2"); - Result rcEntry1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/dir1"); - Result rcEntry2 = fs.GetEntryType(out _, "/dir2"); + Result resultDelete = fs.DeleteDirectory("/dir2"); + Result resultEntry1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/dir1"); + Result resultEntry2 = fs.GetEntryType(out _, "/dir2"); - Assert.Success(rcDelete); - Assert.Success(rcEntry1); - Assert.Result(ResultFs.PathNotFound, rcEntry2); + Assert.Success(resultDelete); + Assert.Success(resultEntry1); + Assert.Result(ResultFs.PathNotFound, resultEntry2); Assert.Equal(DirectoryEntryType.Directory, dir1Type); } @@ -88,8 +88,8 @@ public abstract partial class IFileSystemTests fs.CreateDirectory("/dir"); fs.CreateFile("/dir/file", 0, CreateFileOptions.None); - Result rc = fs.DeleteDirectory("/dir"); + Result res = fs.DeleteDirectory("/dir"); - Assert.Result(ResultFs.DirectoryNotEmpty, rc); + Assert.Result(ResultFs.DirectoryNotEmpty, res); } } diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteDirectoryRecursively.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteDirectoryRecursively.cs index 252ee5ab..59991ad7 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteDirectoryRecursively.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteDirectoryRecursively.cs @@ -15,16 +15,16 @@ public abstract partial class IFileSystemTests fs.CreateDirectory("/dir/dir2"); fs.CreateFile("/dir/file1", 0, CreateFileOptions.None); - Result rcDelete = fs.DeleteDirectoryRecursively("/dir"); + Result resultDelete = fs.DeleteDirectoryRecursively("/dir"); - Result rcDir1Type = fs.GetEntryType(out _, "/dir"); - Result rcDir2Type = fs.GetEntryType(out _, "/dir/dir2"); - Result rcFileType = fs.GetEntryType(out _, "/dir/file1"); + Result resultDir1Type = fs.GetEntryType(out _, "/dir"); + Result resultDir2Type = fs.GetEntryType(out _, "/dir/dir2"); + Result resultFileType = fs.GetEntryType(out _, "/dir/file1"); - Assert.Success(rcDelete); + Assert.Success(resultDelete); - Assert.Result(ResultFs.PathNotFound, rcDir1Type); - Assert.Result(ResultFs.PathNotFound, rcDir2Type); - Assert.Result(ResultFs.PathNotFound, rcFileType); + Assert.Result(ResultFs.PathNotFound, resultDir1Type); + Assert.Result(ResultFs.PathNotFound, resultDir2Type); + Assert.Result(ResultFs.PathNotFound, resultFileType); } } diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteFile.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteFile.cs index 5a557c57..9470aadf 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteFile.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteFile.cs @@ -11,8 +11,8 @@ public abstract partial class IFileSystemTests { IFileSystem fs = CreateFileSystem(); - Result rc = fs.DeleteFile("/file"); - Assert.Result(ResultFs.PathNotFound, rc); + Result res = fs.DeleteFile("/file"); + Assert.Result(ResultFs.PathNotFound, res); } [Fact] @@ -22,11 +22,11 @@ public abstract partial class IFileSystemTests fs.CreateFile("/file", 0, CreateFileOptions.None); - Result rcDelete = fs.DeleteFile("/file"); - Result rcEntry = fs.GetEntryType(out _, "/file"); + Result resultDelete = fs.DeleteFile("/file"); + Result resultEntry = fs.GetEntryType(out _, "/file"); - Assert.Success(rcDelete); - Assert.Result(ResultFs.PathNotFound, rcEntry); + Assert.Success(resultDelete); + Assert.Result(ResultFs.PathNotFound, resultEntry); } [Fact] @@ -36,9 +36,9 @@ public abstract partial class IFileSystemTests fs.CreateDirectory("/dir"); - Result rc = fs.DeleteFile("/dir"); + Result res = fs.DeleteFile("/dir"); - Assert.Result(ResultFs.PathNotFound, rc); + Assert.Result(ResultFs.PathNotFound, res); } [Fact] @@ -49,13 +49,13 @@ public abstract partial class IFileSystemTests fs.CreateFile("/file1", 0, CreateFileOptions.None); fs.CreateFile("/file2", 0, CreateFileOptions.None); - Result rcDelete = fs.DeleteFile("/file2"); - Result rcEntry1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/file1"); - Result rcEntry2 = fs.GetEntryType(out _, "/file2"); + Result resultDelete = fs.DeleteFile("/file2"); + Result resultEntry1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/file1"); + Result resultEntry2 = fs.GetEntryType(out _, "/file2"); - Assert.Success(rcDelete); - Assert.Success(rcEntry1); - Assert.Result(ResultFs.PathNotFound, rcEntry2); + Assert.Success(resultDelete); + Assert.Success(resultEntry1); + Assert.Result(ResultFs.PathNotFound, resultEntry2); Assert.Equal(DirectoryEntryType.File, dir1Type); } @@ -68,13 +68,13 @@ public abstract partial class IFileSystemTests fs.CreateFile("/file2", 0, CreateFileOptions.None); fs.CreateFile("/file1", 0, CreateFileOptions.None); - Result rcDelete = fs.DeleteFile("/file2"); - Result rcEntry1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/file1"); - Result rcEntry2 = fs.GetEntryType(out _, "/file2"); + Result resultDelete = fs.DeleteFile("/file2"); + Result resultEntry1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/file1"); + Result resultEntry2 = fs.GetEntryType(out _, "/file2"); - Assert.Success(rcDelete); - Assert.Success(rcEntry1); - Assert.Result(ResultFs.PathNotFound, rcEntry2); + Assert.Success(resultDelete); + Assert.Success(resultEntry1); + Assert.Result(ResultFs.PathNotFound, resultEntry2); Assert.Equal(DirectoryEntryType.File, dir1Type); } diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Read.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Read.cs index 4e1b47d5..d42414b5 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Read.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Read.cs @@ -34,8 +34,8 @@ public abstract partial class IFileSystemTests using var file = new UniqueRef(); fs.OpenFile(ref file.Ref(), "/file", OpenMode.Read); - Result rc = file.Get.Read(out _, 1, buffer, ReadOption.None); - Assert.Result(ResultFs.OutOfRange, rc); + Result res = file.Get.Read(out _, 1, buffer, ReadOption.None); + Assert.Result(ResultFs.OutOfRange, res); } [Fact] @@ -49,8 +49,8 @@ public abstract partial class IFileSystemTests using var file = new UniqueRef(); fs.OpenFile(ref file.Ref(), "/file", OpenMode.Write); - Result rc = file.Get.Read(out _, 0, buffer, ReadOption.None); - Assert.Result(ResultFs.ReadUnpermitted, rc); + Result res = file.Get.Read(out _, 0, buffer, ReadOption.None); + Assert.Result(ResultFs.ReadUnpermitted, res); } [Fact] @@ -64,8 +64,8 @@ public abstract partial class IFileSystemTests using var file = new UniqueRef(); fs.OpenFile(ref file.Ref(), "/file", OpenMode.Write); - Result rc = file.Get.Read(out _, -5, buffer, ReadOption.None); - Assert.Result(ResultFs.OutOfRange, rc); + Result res = file.Get.Read(out _, -5, buffer, ReadOption.None); + Assert.Result(ResultFs.OutOfRange, res); } [Fact] @@ -79,8 +79,8 @@ public abstract partial class IFileSystemTests using var file = new UniqueRef(); fs.OpenFile(ref file.Ref(), "/file", OpenMode.Write); - Result rc = file.Get.Read(out _, long.MaxValue - 5, buffer, ReadOption.None); - Assert.Result(ResultFs.OutOfRange, rc); + Result res = file.Get.Read(out _, long.MaxValue - 5, buffer, ReadOption.None); + Assert.Result(ResultFs.OutOfRange, res); } [Fact] diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Size.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Size.cs index 89e65813..1895af4a 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Size.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Size.cs @@ -15,13 +15,13 @@ public abstract partial class IFileSystemTests using var file = new UniqueRef(); fs.OpenFile(ref file.Ref(), "/file", OpenMode.All); - Result rc = file.Get.SetSize(54321); + Result res = file.Get.SetSize(54321); file.Reset(); fs.OpenFile(ref file.Ref(), "/file", OpenMode.All); file.Get.GetSize(out long fileSize); - Assert.Success(rc); + Assert.Success(res); Assert.Equal(54321, fileSize); } } diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Write.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Write.cs index f0825318..041ddfc0 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Write.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Write.cs @@ -42,8 +42,8 @@ public abstract partial class IFileSystemTests using var file = new UniqueRef(); fs.OpenFile(ref file.Ref(), "/file", OpenMode.Write); - Result rc = file.Get.Write(5, buffer, WriteOption.None); - Assert.Result(ResultFs.FileExtensionWithoutOpenModeAllowAppend, rc); + Result res = file.Get.Write(5, buffer, WriteOption.None); + Assert.Result(ResultFs.FileExtensionWithoutOpenModeAllowAppend, res); } [Fact] @@ -57,8 +57,8 @@ public abstract partial class IFileSystemTests using var file = new UniqueRef(); fs.OpenFile(ref file.Ref(), "/file", OpenMode.Read); - Result rc = file.Get.Write(5, buffer, WriteOption.None); - Assert.Result(ResultFs.WriteUnpermitted, rc); + Result res = file.Get.Write(5, buffer, WriteOption.None); + Assert.Result(ResultFs.WriteUnpermitted, res); } [Fact] @@ -72,8 +72,8 @@ public abstract partial class IFileSystemTests using var file = new UniqueRef(); fs.OpenFile(ref file.Ref(), "/file", OpenMode.Read); - Result rc = file.Get.Write(-5, buffer, WriteOption.None); - Assert.Result(ResultFs.OutOfRange, rc); + Result res = file.Get.Write(-5, buffer, WriteOption.None); + Assert.Result(ResultFs.OutOfRange, res); } [Fact] @@ -87,8 +87,8 @@ public abstract partial class IFileSystemTests using var file = new UniqueRef(); fs.OpenFile(ref file.Ref(), "/file", OpenMode.Read); - Result rc = file.Get.Write(long.MaxValue - 5, buffer, WriteOption.None); - Assert.Result(ResultFs.OutOfRange, rc); + Result res = file.Get.Write(long.MaxValue - 5, buffer, WriteOption.None); + Assert.Result(ResultFs.OutOfRange, res); } [Fact] diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.OpenDirectory.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.OpenDirectory.cs index e6147867..abd482bc 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.OpenDirectory.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.OpenDirectory.cs @@ -15,9 +15,9 @@ public abstract partial class IFileSystemTests fs.CreateFile("/file", 0, CreateFileOptions.None); using var directory = new UniqueRef(); - Result rc = fs.OpenDirectory(ref directory.Ref(), "/file", OpenDirectoryMode.All); + Result res = fs.OpenDirectory(ref directory.Ref(), "/file", OpenDirectoryMode.All); - Assert.Result(ResultFs.PathNotFound, rc); + Assert.Result(ResultFs.PathNotFound, res); } [Fact] @@ -26,8 +26,8 @@ public abstract partial class IFileSystemTests IFileSystem fs = CreateFileSystem(); using var directory = new UniqueRef(); - Result rc = fs.OpenDirectory(ref directory.Ref(), "/dir", OpenDirectoryMode.All); + Result res = fs.OpenDirectory(ref directory.Ref(), "/dir", OpenDirectoryMode.All); - Assert.Result(ResultFs.PathNotFound, rc); + Assert.Result(ResultFs.PathNotFound, res); } } \ No newline at end of file diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.OpenFile.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.OpenFile.cs index a50e1d71..e7f8a6a7 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.OpenFile.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.OpenFile.cs @@ -15,9 +15,9 @@ public abstract partial class IFileSystemTests fs.CreateDirectory("/dir"); using var file = new UniqueRef(); - Result rc = fs.OpenFile(ref file.Ref(), "/dir", OpenMode.All); + Result res = fs.OpenFile(ref file.Ref(), "/dir", OpenMode.All); - Assert.Result(ResultFs.PathNotFound, rc); + Assert.Result(ResultFs.PathNotFound, res); } [Fact] @@ -26,8 +26,8 @@ public abstract partial class IFileSystemTests IFileSystem fs = CreateFileSystem(); using var file = new UniqueRef(); - Result rc = fs.OpenFile(ref file.Ref(), "/file", OpenMode.All); + Result res = fs.OpenFile(ref file.Ref(), "/file", OpenMode.All); - Assert.Result(ResultFs.PathNotFound, rc); + Assert.Result(ResultFs.PathNotFound, res); } } \ No newline at end of file diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameDirectory.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameDirectory.cs index 74a095da..597bd0df 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameDirectory.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameDirectory.cs @@ -12,17 +12,17 @@ public abstract partial class IFileSystemTests IFileSystem fs = CreateFileSystem(); fs.CreateDirectory("/dir1"); - Result rcRename = fs.RenameDirectory("/dir1", "/dir2"); + Result resultRename = fs.RenameDirectory("/dir1", "/dir2"); - Result rcDir2 = fs.GetEntryType(out DirectoryEntryType dir2Type, "/dir2"); - Result rcDir1 = fs.GetEntryType(out _, "/dir1"); + Result resultDir2 = fs.GetEntryType(out DirectoryEntryType dir2Type, "/dir2"); + Result resultDir1 = fs.GetEntryType(out _, "/dir1"); - Assert.Success(rcRename); + Assert.Success(resultRename); - Assert.Success(rcDir2); + Assert.Success(resultDir2); Assert.Equal(DirectoryEntryType.Directory, dir2Type); - Assert.Result(ResultFs.PathNotFound, rcDir1); + Assert.Result(ResultFs.PathNotFound, resultDir1); } [Fact] @@ -34,31 +34,31 @@ public abstract partial class IFileSystemTests fs.CreateDirectory("/dir1/dirC"); fs.CreateFile("/dir1/file1", 0, CreateFileOptions.None); - Result rcRename = fs.RenameDirectory("/dir1", "/dir2"); + Result resultRename = fs.RenameDirectory("/dir1", "/dir2"); // Check that renamed structure exists - Result rcDir2 = fs.GetEntryType(out DirectoryEntryType dir2Type, "/dir2"); - Result rcDirC = fs.GetEntryType(out DirectoryEntryType dir1CType, "/dir2/dirC"); - Result rcFile1 = fs.GetEntryType(out DirectoryEntryType file1Type, "/dir2/file1"); + Result resultDir2 = fs.GetEntryType(out DirectoryEntryType dir2Type, "/dir2"); + Result resultDirC = fs.GetEntryType(out DirectoryEntryType dir1CType, "/dir2/dirC"); + Result resultFile1 = fs.GetEntryType(out DirectoryEntryType file1Type, "/dir2/file1"); // Check that old structure doesn't exist - Result rcDir1 = fs.GetEntryType(out _, "/dir1"); - Result rcDirCOld = fs.GetEntryType(out _, "/dir1/dirC"); - Result rcFile1Old = fs.GetEntryType(out _, "/dir1/file1"); + Result resultDir1 = fs.GetEntryType(out _, "/dir1"); + Result resultDirCOld = fs.GetEntryType(out _, "/dir1/dirC"); + Result resultFile1Old = fs.GetEntryType(out _, "/dir1/file1"); - Assert.Success(rcRename); + Assert.Success(resultRename); - Assert.Success(rcDir2); - Assert.Success(rcDirC); - Assert.Success(rcFile1); + Assert.Success(resultDir2); + Assert.Success(resultDirC); + Assert.Success(resultFile1); Assert.Equal(DirectoryEntryType.Directory, dir2Type); Assert.Equal(DirectoryEntryType.Directory, dir1CType); Assert.Equal(DirectoryEntryType.File, file1Type); - Assert.Result(ResultFs.PathNotFound, rcDir1); - Assert.Result(ResultFs.PathNotFound, rcDirCOld); - Assert.Result(ResultFs.PathNotFound, rcFile1Old); + Assert.Result(ResultFs.PathNotFound, resultDir1); + Assert.Result(ResultFs.PathNotFound, resultDirCOld); + Assert.Result(ResultFs.PathNotFound, resultFile1Old); } [Fact] @@ -70,18 +70,18 @@ public abstract partial class IFileSystemTests fs.CreateDirectory("/parent2"); fs.CreateDirectory("/parent1/dir1"); - Result rcRename = fs.RenameDirectory("/parent1/dir1", "/parent2/dir2"); + Result resultRename = fs.RenameDirectory("/parent1/dir1", "/parent2/dir2"); - Result rcDir2 = fs.GetEntryType(out DirectoryEntryType dir2Type, "/parent2/dir2"); - Result rcDir1 = fs.GetEntryType(out _, "/parent1/dir1"); + Result resultDir2 = fs.GetEntryType(out DirectoryEntryType dir2Type, "/parent2/dir2"); + Result resultDir1 = fs.GetEntryType(out _, "/parent1/dir1"); - Assert.Success(rcRename); + Assert.Success(resultRename); - Assert.Equal(Result.Success, rcDir2); - Assert.Success(rcDir2); + Assert.Equal(Result.Success, resultDir2); + Assert.Success(resultDir2); Assert.Equal(DirectoryEntryType.Directory, dir2Type); - Assert.Result(ResultFs.PathNotFound, rcDir1); + Assert.Result(ResultFs.PathNotFound, resultDir1); } [Fact] @@ -92,15 +92,15 @@ public abstract partial class IFileSystemTests fs.CreateDirectory("/dir1"); fs.CreateDirectory("/dir2"); - Result rcRename = fs.RenameDirectory("/dir1", "/dir2"); + Result resultRename = fs.RenameDirectory("/dir1", "/dir2"); - Result rcDir1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/dir1"); - Result rcDir2 = fs.GetEntryType(out DirectoryEntryType dir2Type, "/dir2"); + Result resultDir1 = fs.GetEntryType(out DirectoryEntryType dir1Type, "/dir1"); + Result resultDir2 = fs.GetEntryType(out DirectoryEntryType dir2Type, "/dir2"); - Assert.Result(ResultFs.PathAlreadyExists, rcRename); + Assert.Result(ResultFs.PathAlreadyExists, resultRename); - Assert.Success(rcDir1); - Assert.Success(rcDir2); + Assert.Success(resultDir1); + Assert.Success(resultDir2); Assert.Equal(DirectoryEntryType.Directory, dir1Type); Assert.Equal(DirectoryEntryType.Directory, dir2Type); } diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameFile.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameFile.cs index 5165eb0c..65b7990c 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameFile.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameFile.cs @@ -17,10 +17,10 @@ public abstract partial class IFileSystemTests Assert.Success(fs.RenameFile("/file1", "/file2")); Assert.Success(fs.GetEntryType(out DirectoryEntryType type, "/file2")); - Result rc = fs.GetEntryType(out _, "/file1"); + Result res = fs.GetEntryType(out _, "/file1"); Assert.Equal(DirectoryEntryType.File, type); - Assert.Result(ResultFs.PathNotFound, rc); + Assert.Result(ResultFs.PathNotFound, res); } [Fact] public void RenameFile_DifferentParentDirectory_EntryIsRenamed() @@ -33,10 +33,10 @@ public abstract partial class IFileSystemTests Assert.Success(fs.RenameFile("/file1", "/dir/file2")); Assert.Success(fs.GetEntryType(out DirectoryEntryType type, "/dir/file2")); - Result rc = fs.GetEntryType(out _, "/file1"); + Result res = fs.GetEntryType(out _, "/file1"); Assert.Equal(DirectoryEntryType.File, type); - Assert.Result(ResultFs.PathNotFound, rc); + Assert.Result(ResultFs.PathNotFound, res); } [Fact] @@ -47,9 +47,9 @@ public abstract partial class IFileSystemTests fs.CreateFile("/file1", 0, CreateFileOptions.None); fs.CreateFile("/file2", 0, CreateFileOptions.None); - Result rc = fs.RenameFile("/file1", "/file2"); + Result res = fs.RenameFile("/file1", "/file2"); - Assert.Result(ResultFs.PathAlreadyExists, rc); + Assert.Result(ResultFs.PathAlreadyExists, res); } [Fact] @@ -60,9 +60,9 @@ public abstract partial class IFileSystemTests fs.CreateFile("/file", 0, CreateFileOptions.None); fs.CreateDirectory("/dir"); - Result rc = fs.RenameFile("/file", "/dir"); + Result res = fs.RenameFile("/file", "/dir"); - Assert.Result(ResultFs.PathAlreadyExists, rc); + Assert.Result(ResultFs.PathAlreadyExists, res); } [Fact] @@ -107,9 +107,9 @@ public abstract partial class IFileSystemTests byte[] readData = new byte[data.Length]; fs.OpenFile(ref file.Ref(), "/renamed", OpenMode.Read); - Result rc = file.Get.Read(out long bytesRead, 0, readData, ReadOption.None); + Result res = file.Get.Read(out long bytesRead, 0, readData, ReadOption.None); - Assert.Success(rc); + Assert.Success(res); Assert.Equal(data.Length, bytesRead); Assert.Equal(data, readData); } diff --git a/tests/LibHac.Tests/FsSrv/AccessControlTests.cs b/tests/LibHac.Tests/FsSrv/AccessControlTests.cs index ed6c807b..571d0df1 100644 --- a/tests/LibHac.Tests/FsSrv/AccessControlTests.cs +++ b/tests/LibHac.Tests/FsSrv/AccessControlTests.cs @@ -31,8 +31,8 @@ public class AccessControlTests StorageId.BuiltInUser, SpanHelpers.AsReadOnlyByteSpan(in dataHeader), SpanHelpers.AsReadOnlyByteSpan(in descriptor))); - Result rc = client.Fs.MountContent("test".ToU8Span(), "@System:/fake.nca".ToU8Span(), ContentType.Meta); - Assert.Result(ResultFs.PermissionDenied, rc); + Result res = client.Fs.MountContent("test".ToU8Span(), "@System:/fake.nca".ToU8Span(), ContentType.Meta); + Assert.Result(ResultFs.PermissionDenied, res); } [Fact] @@ -57,7 +57,7 @@ public class AccessControlTests SpanHelpers.AsReadOnlyByteSpan(in descriptor))); // We should get UnexpectedInNcaFileSystemServiceImplA because mounting NCAs from @System isn't allowed - Result rc = client.Fs.MountContent("test".ToU8Span(), "@System:/fake.nca".ToU8Span(), ContentType.Meta); - Assert.Result(ResultFs.UnexpectedInNcaFileSystemServiceImplA, rc); + Result res = client.Fs.MountContent("test".ToU8Span(), "@System:/fake.nca".ToU8Span(), ContentType.Meta); + Assert.Result(ResultFs.UnexpectedInNcaFileSystemServiceImplA, res); } } \ No newline at end of file diff --git a/tests/LibHac.Tests/FsSystem/BucketTreeTests.cs b/tests/LibHac.Tests/FsSystem/BucketTreeTests.cs index 6445db32..568b6629 100644 --- a/tests/LibHac.Tests/FsSystem/BucketTreeTests.cs +++ b/tests/LibHac.Tests/FsSystem/BucketTreeTests.cs @@ -88,10 +88,10 @@ public class BucketTreeTests : IClassFixture { if (i != 0) { - Result rc = visitor.MoveNext(); + Result res = visitor.MoveNext(); - if (!rc.IsSuccess()) - Assert.Success(rc); + if (!res.IsSuccess()) + Assert.Success(res); } // These tests run about 4x slower if we let Assert.Equal check the values every time @@ -127,10 +127,10 @@ public class BucketTreeTests : IClassFixture { if (i != entries.Length - 1) { - Result rc = visitor.MovePrevious(); + Result res = visitor.MovePrevious(); - if (!rc.IsSuccess()) - Assert.Success(rc); + if (!res.IsSuccess()) + Assert.Success(res); } if (visitor.CanMovePrevious() != (i != 0)) diff --git a/tests/LibHac.Tests/FsSystem/DirectorySaveDataFileSystemTests.cs b/tests/LibHac.Tests/FsSystem/DirectorySaveDataFileSystemTests.cs index ee604bbc..bc01a5dc 100644 --- a/tests/LibHac.Tests/FsSystem/DirectorySaveDataFileSystemTests.cs +++ b/tests/LibHac.Tests/FsSystem/DirectorySaveDataFileSystemTests.cs @@ -48,10 +48,10 @@ public class DirectorySaveDataFileSystemTests : CommittableIFileSystemTests FileSystemClient fsClient) { var obj = new DirectorySaveDataFileSystem(baseFileSystem, fsClient); - Result rc = obj.Initialize(isJournalingSupported, isMultiCommitSupported, isJournalingEnabled, timeStampGetter, + Result res = obj.Initialize(isJournalingSupported, isMultiCommitSupported, isJournalingEnabled, timeStampGetter, randomGenerator); - if (rc.IsSuccess()) + if (res.IsSuccess()) { created = obj; return Result.Success; @@ -59,7 +59,7 @@ public class DirectorySaveDataFileSystemTests : CommittableIFileSystemTests obj.Dispose(); UnsafeHelpers.SkipParamInit(out created); - return rc; + return res; } public static Result CreateDirSaveFs(out DirectorySaveDataFileSystem created, IFileSystem baseFileSystem, @@ -536,18 +536,18 @@ public class DirectorySaveDataFileSystemTests : CommittableIFileSystemTests { fileSystem.DeleteFile(path).IgnoreResult(); - Result rc = fileSystem.CreateFile(path, Unsafe.SizeOf()); - if (rc.IsFailure()) return rc; + Result res = fileSystem.CreateFile(path, Unsafe.SizeOf()); + if (res.IsFailure()) return res.Miss(); var extraData = new SaveDataExtraData(); extraData.DataSize = saveDataSize; using var file = new UniqueRef(); - rc = fileSystem.OpenFile(ref file.Ref(), path, OpenMode.ReadWrite); - if (rc.IsFailure()) return rc; + res = fileSystem.OpenFile(ref file.Ref(), path, OpenMode.ReadWrite); + if (res.IsFailure()) return res.Miss(); - rc = file.Get.Write(0, SpanHelpers.AsByteSpan(ref extraData), WriteOption.Flush); - if (rc.IsFailure()) return rc; + res = file.Get.Write(0, SpanHelpers.AsByteSpan(ref extraData), WriteOption.Flush); + if (res.IsFailure()) return res.Miss(); return Result.Success; } diff --git a/tests/LibHac.Tests/Kvdb/FlatMapKeyValueStoreTests.cs b/tests/LibHac.Tests/Kvdb/FlatMapKeyValueStoreTests.cs index a31f0ff2..df8e1a73 100644 --- a/tests/LibHac.Tests/Kvdb/FlatMapKeyValueStoreTests.cs +++ b/tests/LibHac.Tests/Kvdb/FlatMapKeyValueStoreTests.cs @@ -65,8 +65,8 @@ public class FlatMapKeyValueStoreTests { for (TTest i = 0; i < count; i++) { - Result rc = kvStore.Set(in i, values[i]); - if (rc.IsFailure()) return rc; + Result res = kvStore.Set(in i, values[i]); + if (res.IsFailure()) return res.Miss(); } } else @@ -76,8 +76,8 @@ public class FlatMapKeyValueStoreTests for (int i = 0; i < count; i++) { TTest index = rng.Next(); - Result rc = kvStore.Set(in index, values[index]); - if (rc.IsFailure()) return rc; + Result res = kvStore.Set(in index, values[index]); + if (res.IsFailure()) return res.Miss(); } } @@ -193,8 +193,8 @@ public class FlatMapKeyValueStoreTests TTest key = 20; byte[] value = new byte[20]; - Result rc = kvStore.Get(out int _, in key, value); - Assert.Result(ResultKvdb.KeyNotFound, rc); + Result res = kvStore.Get(out int _, in key, value); + Assert.Result(ResultKvdb.KeyNotFound, res); } [Fact] @@ -248,9 +248,9 @@ public class FlatMapKeyValueStoreTests Assert.Success(PopulateKvStore(kvStore, out byte[][] values, count)); TTest key = count; - Result rc = kvStore.Set(in key, values[0]); + Result res = kvStore.Set(in key, values[0]); - Assert.Result(ResultKvdb.OutOfKeyResource, rc); + Assert.Result(ResultKvdb.OutOfKeyResource, res); } [Theory] @@ -316,8 +316,8 @@ public class FlatMapKeyValueStoreTests (FlatMapKeyValueStore kvStore, FileSystemClient _) = Create(count); - Result rc = kvStore.Delete(in keyToDelete); - Assert.Result(ResultKvdb.KeyNotFound, rc); + Result res = kvStore.Delete(in keyToDelete); + Assert.Result(ResultKvdb.KeyNotFound, res); } [Fact] @@ -329,8 +329,8 @@ public class FlatMapKeyValueStoreTests (FlatMapKeyValueStore kvStore, FileSystemClient _) = Create(count); Assert.Success(PopulateKvStore(kvStore, out _, count)); - Result rc = kvStore.Delete(in keyToDelete); - Assert.Result(ResultKvdb.KeyNotFound, rc); + Result res = kvStore.Delete(in keyToDelete); + Assert.Result(ResultKvdb.KeyNotFound, res); } [Theory] @@ -351,8 +351,8 @@ public class FlatMapKeyValueStoreTests byte[] value = new byte[20]; - Result rc = kvStore.Get(out int _, in keyToDelete, value); - Assert.Result(ResultKvdb.KeyNotFound, rc); + Result res = kvStore.Get(out int _, in keyToDelete, value); + Assert.Result(ResultKvdb.KeyNotFound, res); } [Theory]