mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Use more accurate Sf IFile and IStorage function signatures
This commit is contained in:
parent
880916e117
commit
4d3a1418f6
6 changed files with 39 additions and 31 deletions
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using LibHac.Common;
|
||||
using LibHac.Sf;
|
||||
using IFile = LibHac.Fs.Fsa.IFile;
|
||||
using IFileSf = LibHac.FsSrv.Sf.IFile;
|
||||
|
||||
|
@ -21,12 +22,12 @@ namespace LibHac.Fs.Impl
|
|||
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination, in ReadOption option)
|
||||
{
|
||||
return BaseFile.Target.Read(out bytesRead, offset, destination, option);
|
||||
return BaseFile.Target.Read(out bytesRead, offset, new OutBuffer(destination), destination.Length, option);
|
||||
}
|
||||
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
return BaseFile.Target.Write(offset, source, option);
|
||||
return BaseFile.Target.Write(offset, new InBuffer(source), source.Length, option);
|
||||
}
|
||||
|
||||
protected override Result DoFlush()
|
||||
|
@ -44,7 +45,8 @@ namespace LibHac.Fs.Impl
|
|||
return BaseFile.Target.GetSize(out size);
|
||||
}
|
||||
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan<byte> inBuffer)
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
switch (operationId)
|
||||
{
|
||||
|
@ -72,4 +74,4 @@ namespace LibHac.Fs.Impl
|
|||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using LibHac.Common;
|
||||
using LibHac.Sf;
|
||||
using IStorageSf = LibHac.FsSrv.Sf.IStorage;
|
||||
|
||||
namespace LibHac.Fs.Impl
|
||||
|
@ -31,12 +32,12 @@ namespace LibHac.Fs.Impl
|
|||
|
||||
protected override Result DoRead(long offset, Span<byte> destination)
|
||||
{
|
||||
return BaseStorage.Target.Read(offset, destination);
|
||||
return BaseStorage.Target.Read(offset, new OutBuffer(destination), destination.Length);
|
||||
}
|
||||
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source)
|
||||
{
|
||||
return BaseStorage.Target.Write(offset, source);
|
||||
return BaseStorage.Target.Write(offset, new InBuffer(source), source.Length);
|
||||
}
|
||||
|
||||
protected override Result DoFlush()
|
||||
|
@ -54,7 +55,8 @@ namespace LibHac.Fs.Impl
|
|||
return BaseStorage.Target.GetSize(out size);
|
||||
}
|
||||
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan<byte> inBuffer)
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
switch (operationId)
|
||||
{
|
||||
|
@ -82,4 +84,4 @@ namespace LibHac.Fs.Impl
|
|||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using LibHac.Common;
|
||||
using LibHac.Fs;
|
||||
using LibHac.Sf;
|
||||
using IFile = LibHac.Fs.Fsa.IFile;
|
||||
using IFileSf = LibHac.FsSrv.Sf.IFile;
|
||||
|
||||
|
@ -20,7 +21,7 @@ namespace LibHac.FsSrv.Impl
|
|||
parentFileSystem = null;
|
||||
}
|
||||
|
||||
public Result Read(out long bytesRead, long offset, Span<byte> destination, ReadOption option)
|
||||
public Result Read(out long bytesRead, long offset, OutBuffer destination, long size, ReadOption option)
|
||||
{
|
||||
const int maxTryCount = 2;
|
||||
UnsafeHelpers.SkipParamInit(out bytesRead);
|
||||
|
@ -28,7 +29,7 @@ namespace LibHac.FsSrv.Impl
|
|||
if (offset < 0)
|
||||
return ResultFs.InvalidOffset.Log();
|
||||
|
||||
if (destination.Length < 0)
|
||||
if (destination.Size < 0)
|
||||
return ResultFs.InvalidSize.Log();
|
||||
|
||||
Result rc = Result.Success;
|
||||
|
@ -36,7 +37,7 @@ namespace LibHac.FsSrv.Impl
|
|||
|
||||
for (int tryNum = 0; tryNum < maxTryCount; tryNum++)
|
||||
{
|
||||
rc = BaseFile.Read(out tmpBytesRead, offset, destination, option);
|
||||
rc = BaseFile.Read(out tmpBytesRead, offset, destination.Buffer.Slice(0, (int)size), option);
|
||||
|
||||
// Retry on ResultDataCorrupted
|
||||
if (!ResultFs.DataCorrupted.Includes(rc))
|
||||
|
@ -49,17 +50,17 @@ namespace LibHac.FsSrv.Impl
|
|||
return Result.Success;
|
||||
}
|
||||
|
||||
public Result Write(long offset, ReadOnlySpan<byte> source, WriteOption option)
|
||||
public Result Write(long offset, InBuffer source, long size, WriteOption option)
|
||||
{
|
||||
if (offset < 0)
|
||||
return ResultFs.InvalidOffset.Log();
|
||||
|
||||
if (source.Length < 0)
|
||||
if (source.Size < 0)
|
||||
return ResultFs.InvalidSize.Log();
|
||||
|
||||
// Note: Thread priority is temporarily when writing in FS
|
||||
// Note: Thread priority is temporarily increased when writing in FS
|
||||
|
||||
return BaseFile.Write(offset, source, option);
|
||||
return BaseFile.Write(offset, source.Buffer.Slice(0, (int)size), option);
|
||||
}
|
||||
|
||||
public Result Flush()
|
||||
|
@ -113,8 +114,8 @@ namespace LibHac.FsSrv.Impl
|
|||
{
|
||||
Unsafe.SkipInit(out QueryRangeInfo info);
|
||||
|
||||
Result rc = BaseFile.OperateRange(SpanHelpers.AsByteSpan(ref info), OperationId.QueryRange, offset, size,
|
||||
ReadOnlySpan<byte>.Empty);
|
||||
Result rc = BaseFile.OperateRange(SpanHelpers.AsByteSpan(ref info), OperationId.QueryRange, offset,
|
||||
size, ReadOnlySpan<byte>.Empty);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
rangeInfo.Merge(in info);
|
||||
|
@ -129,4 +130,4 @@ namespace LibHac.FsSrv.Impl
|
|||
ParentFs?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using LibHac.Common;
|
||||
using LibHac.Fs;
|
||||
using LibHac.Sf;
|
||||
using IStorageSf = LibHac.FsSrv.Sf.IStorage;
|
||||
|
||||
namespace LibHac.FsSrv.Impl
|
||||
|
@ -27,21 +28,21 @@ namespace LibHac.FsSrv.Impl
|
|||
BaseStorage?.Dispose();
|
||||
}
|
||||
|
||||
public Result Read(long offset, Span<byte> destination)
|
||||
public Result Read(long offset, OutBuffer destination, long size)
|
||||
{
|
||||
const int maxTryCount = 2;
|
||||
|
||||
if (offset < 0)
|
||||
return ResultFs.InvalidOffset.Log();
|
||||
|
||||
if (destination.Length < 0)
|
||||
if (destination.Size < 0)
|
||||
return ResultFs.InvalidSize.Log();
|
||||
|
||||
Result rc = Result.Success;
|
||||
|
||||
for (int tryNum = 0; tryNum < maxTryCount; tryNum++)
|
||||
{
|
||||
rc = BaseStorage.Target.Read(offset, destination);
|
||||
rc = BaseStorage.Target.Read(offset, destination.Buffer.Slice(0, (int)size));
|
||||
|
||||
// Retry on ResultDataCorrupted
|
||||
if (!ResultFs.DataCorrupted.Includes(rc))
|
||||
|
@ -51,17 +52,17 @@ namespace LibHac.FsSrv.Impl
|
|||
return rc;
|
||||
}
|
||||
|
||||
public Result Write(long offset, ReadOnlySpan<byte> source)
|
||||
public Result Write(long offset, InBuffer source, long size)
|
||||
{
|
||||
if (offset < 0)
|
||||
return ResultFs.InvalidOffset.Log();
|
||||
|
||||
if (source.Length < 0)
|
||||
if (source.Size < 0)
|
||||
return ResultFs.InvalidSize.Log();
|
||||
|
||||
// Note: Thread priority is temporarily increased when writing in FS
|
||||
|
||||
return BaseStorage.Target.Write(offset, source);
|
||||
return BaseStorage.Target.Write(offset, source.Buffer.Slice(0, (int)size));
|
||||
}
|
||||
|
||||
public Result Flush()
|
||||
|
@ -107,4 +108,4 @@ namespace LibHac.FsSrv.Impl
|
|||
return Result.Success;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +1,16 @@
|
|||
using System;
|
||||
using LibHac.Fs;
|
||||
using LibHac.Sf;
|
||||
|
||||
namespace LibHac.FsSrv.Sf
|
||||
{
|
||||
public interface IFile : IDisposable
|
||||
{
|
||||
Result Read(out long bytesRead, long offset, Span<byte> destination, ReadOption option);
|
||||
Result Write(long offset, ReadOnlySpan<byte> source, WriteOption option);
|
||||
Result Read(out long bytesRead, long offset, OutBuffer destination, long size, ReadOption option);
|
||||
Result Write(long offset, InBuffer source, long size, WriteOption option);
|
||||
Result Flush();
|
||||
Result SetSize(long size);
|
||||
Result GetSize(out long size);
|
||||
Result OperateRange(out QueryRangeInfo rangeInfo, int operationId, long offset, long size);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +1,16 @@
|
|||
using System;
|
||||
using LibHac.Fs;
|
||||
using LibHac.Sf;
|
||||
|
||||
namespace LibHac.FsSrv.Sf
|
||||
{
|
||||
public interface IStorage : IDisposable
|
||||
{
|
||||
Result Read(long offset, Span<byte> destination);
|
||||
Result Write(long offset, ReadOnlySpan<byte> source);
|
||||
Result Read(long offset, OutBuffer destination, long size);
|
||||
Result Write(long offset, InBuffer source, long size);
|
||||
Result Flush();
|
||||
Result SetSize(long size);
|
||||
Result GetSize(out long size);
|
||||
Result OperateRange(out QueryRangeInfo rangeInfo, int operationId, long offset, long size);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue