From 2a658e273334f1a2183971e9b75213d918d209a7 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sun, 19 Dec 2021 14:36:32 -0700 Subject: [PATCH] Update FileSystemInterfaceAdapter for 13.1.0 --- .../FsSrv/Impl/FileSystemInterfaceAdapter.cs | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs b/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs index 7b0552de..cd5dfe6e 100644 --- a/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs +++ b/src/LibHac/FsSrv/Impl/FileSystemInterfaceAdapter.cs @@ -20,7 +20,7 @@ namespace LibHac.FsSrv.Impl; /// /// Wraps an to allow interfacing with it via the interface over IPC. /// -/// Based on FS 12.1.0 (nnSdk 12.3.1) +/// Based on FS 13.1.0 (nnSdk 13.4.0) public class FileInterfaceAdapter : IFileSf { private SharedRef _parentFs; @@ -49,15 +49,18 @@ public class FileInterfaceAdapter : IFileSf if (offset < 0) return ResultFs.InvalidOffset.Log(); - if (destination.Size < 0 || destination.Size < (int)size) + if (destination.Size < 0) + return ResultFs.InvalidSize.Log(); + + if (destination.Size < (int)size) return ResultFs.InvalidSize.Log(); Result rc = Result.Success; - long tmpBytesRead = 0; + long readSize = 0; for (int tryNum = 0; tryNum < maxTryCount; tryNum++) { - rc = _baseFile.Get.Read(out tmpBytesRead, offset, destination.Buffer.Slice(0, (int)size), option); + rc = _baseFile.Get.Read(out readSize, offset, destination.Buffer.Slice(0, (int)size), option); // Retry on ResultDataCorrupted if (!ResultFs.DataCorrupted.Includes(rc)) @@ -66,7 +69,7 @@ public class FileInterfaceAdapter : IFileSf if (rc.IsFailure()) return rc; - bytesRead = tmpBytesRead; + bytesRead = readSize; return Result.Success; } @@ -75,7 +78,10 @@ public class FileInterfaceAdapter : IFileSf if (offset < 0) return ResultFs.InvalidOffset.Log(); - if (source.Size < 0 || source.Size < (int)size) + if (source.Size < 0) + return ResultFs.InvalidSize.Log(); + + if (source.Size < (int)size) return ResultFs.InvalidSize.Log(); using var scopedPriorityChanger = @@ -175,7 +181,7 @@ public class FileInterfaceAdapter : IFileSf /// /// Wraps an to allow interfacing with it via the interface over IPC. /// -/// Based on FS 12.1.0 (nnSdk 12.3.1) +/// Based on FS 13.1.0 (nnSdk 13.4.0) public class DirectoryInterfaceAdapter : IDirectorySf { private SharedRef _parentFs; @@ -235,13 +241,11 @@ public class DirectoryInterfaceAdapter : IDirectorySf /// Wraps an to allow interfacing with it via the interface over IPC. /// All incoming paths are normalized before they are passed to the base . /// -/// Based on FS 12.1.0 (nnSdk 12.3.1) +/// Based on FS 13.1.0 (nnSdk 13.4.0) public class FileSystemInterfaceAdapter : IFileSystemSf { private SharedRef _baseFileSystem; private PathFlags _pathFlags; - - // This field is always false in FS 12.0.0. Not sure what it's actually used for. private bool _allowAllOperations; // In FS, FileSystemInterfaceAdapter is derived from ISharedObject, so that's used for ref-counting when @@ -593,4 +597,4 @@ public class FileSystemInterfaceAdapter : IFileSystemSf fileSystem.SetByCopy(in _baseFileSystem); return Result.Success; } -} +} \ No newline at end of file