Update FileSystemInterfaceAdapter for 13.1.0

This commit is contained in:
Alex Barney 2021-12-19 14:36:32 -07:00
parent c4783f4589
commit 2a658e2733

View file

@ -20,7 +20,7 @@ namespace LibHac.FsSrv.Impl;
/// <summary> /// <summary>
/// Wraps an <see cref="IFile"/> to allow interfacing with it via the <see cref="IFileSf"/> interface over IPC. /// Wraps an <see cref="IFile"/> to allow interfacing with it via the <see cref="IFileSf"/> interface over IPC.
/// </summary> /// </summary>
/// <remarks>Based on FS 12.1.0 (nnSdk 12.3.1)</remarks> /// <remarks>Based on FS 13.1.0 (nnSdk 13.4.0)</remarks>
public class FileInterfaceAdapter : IFileSf public class FileInterfaceAdapter : IFileSf
{ {
private SharedRef<FileSystemInterfaceAdapter> _parentFs; private SharedRef<FileSystemInterfaceAdapter> _parentFs;
@ -49,15 +49,18 @@ public class FileInterfaceAdapter : IFileSf
if (offset < 0) if (offset < 0)
return ResultFs.InvalidOffset.Log(); 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(); return ResultFs.InvalidSize.Log();
Result rc = Result.Success; Result rc = Result.Success;
long tmpBytesRead = 0; long readSize = 0;
for (int tryNum = 0; tryNum < maxTryCount; tryNum++) 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 // Retry on ResultDataCorrupted
if (!ResultFs.DataCorrupted.Includes(rc)) if (!ResultFs.DataCorrupted.Includes(rc))
@ -66,7 +69,7 @@ public class FileInterfaceAdapter : IFileSf
if (rc.IsFailure()) return rc; if (rc.IsFailure()) return rc;
bytesRead = tmpBytesRead; bytesRead = readSize;
return Result.Success; return Result.Success;
} }
@ -75,7 +78,10 @@ public class FileInterfaceAdapter : IFileSf
if (offset < 0) if (offset < 0)
return ResultFs.InvalidOffset.Log(); 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(); return ResultFs.InvalidSize.Log();
using var scopedPriorityChanger = using var scopedPriorityChanger =
@ -175,7 +181,7 @@ public class FileInterfaceAdapter : IFileSf
/// <summary> /// <summary>
/// Wraps an <see cref="IDirectory"/> to allow interfacing with it via the <see cref="IDirectorySf"/> interface over IPC. /// Wraps an <see cref="IDirectory"/> to allow interfacing with it via the <see cref="IDirectorySf"/> interface over IPC.
/// </summary> /// </summary>
/// <remarks>Based on FS 12.1.0 (nnSdk 12.3.1)</remarks> /// <remarks>Based on FS 13.1.0 (nnSdk 13.4.0)</remarks>
public class DirectoryInterfaceAdapter : IDirectorySf public class DirectoryInterfaceAdapter : IDirectorySf
{ {
private SharedRef<FileSystemInterfaceAdapter> _parentFs; private SharedRef<FileSystemInterfaceAdapter> _parentFs;
@ -235,13 +241,11 @@ public class DirectoryInterfaceAdapter : IDirectorySf
/// Wraps an <see cref="IFileSystem"/> to allow interfacing with it via the <see cref="IFileSystemSf"/> interface over IPC. /// Wraps an <see cref="IFileSystem"/> to allow interfacing with it via the <see cref="IFileSystemSf"/> interface over IPC.
/// All incoming paths are normalized before they are passed to the base <see cref="IFileSystem"/>. /// All incoming paths are normalized before they are passed to the base <see cref="IFileSystem"/>.
/// </summary> /// </summary>
/// <remarks>Based on FS 12.1.0 (nnSdk 12.3.1)</remarks> /// <remarks>Based on FS 13.1.0 (nnSdk 13.4.0)</remarks>
public class FileSystemInterfaceAdapter : IFileSystemSf public class FileSystemInterfaceAdapter : IFileSystemSf
{ {
private SharedRef<IFileSystem> _baseFileSystem; private SharedRef<IFileSystem> _baseFileSystem;
private PathFlags _pathFlags; private PathFlags _pathFlags;
// This field is always false in FS 12.0.0. Not sure what it's actually used for.
private bool _allowAllOperations; private bool _allowAllOperations;
// In FS, FileSystemInterfaceAdapter is derived from ISharedObject, so that's used for ref-counting when // 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); fileSystem.SetByCopy(in _baseFileSystem);
return Result.Success; return Result.Success;
} }
} }