diff --git a/src/LibHac/Fs/Impl/FileServiceObjectAdapter.cs b/src/LibHac/Fs/Impl/FileServiceObjectAdapter.cs index 9973e9a3..3781c2ae 100644 --- a/src/LibHac/Fs/Impl/FileServiceObjectAdapter.cs +++ b/src/LibHac/Fs/Impl/FileServiceObjectAdapter.cs @@ -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 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 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 outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan inBuffer) + protected override Result DoOperateRange(Span outBuffer, OperationId operationId, long offset, long size, + ReadOnlySpan inBuffer) { switch (operationId) { @@ -72,4 +74,4 @@ namespace LibHac.Fs.Impl base.Dispose(disposing); } } -} +} \ No newline at end of file diff --git a/src/LibHac/Fs/Impl/StorageServiceObjectAdapter.cs b/src/LibHac/Fs/Impl/StorageServiceObjectAdapter.cs index d0d110ae..49cbb4f0 100644 --- a/src/LibHac/Fs/Impl/StorageServiceObjectAdapter.cs +++ b/src/LibHac/Fs/Impl/StorageServiceObjectAdapter.cs @@ -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 destination) { - return BaseStorage.Target.Read(offset, destination); + return BaseStorage.Target.Read(offset, new OutBuffer(destination), destination.Length); } protected override Result DoWrite(long offset, ReadOnlySpan 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 outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan inBuffer) + protected override Result DoOperateRange(Span outBuffer, OperationId operationId, long offset, long size, + ReadOnlySpan inBuffer) { switch (operationId) { @@ -82,4 +84,4 @@ namespace LibHac.Fs.Impl base.Dispose(disposing); } } -} +} \ No newline at end of file diff --git a/src/LibHac/FsSrv/Impl/FileInterfaceAdapter.cs b/src/LibHac/FsSrv/Impl/FileInterfaceAdapter.cs index 5394d0ec..1f70a85b 100644 --- a/src/LibHac/FsSrv/Impl/FileInterfaceAdapter.cs +++ b/src/LibHac/FsSrv/Impl/FileInterfaceAdapter.cs @@ -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 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 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.Empty); + Result rc = BaseFile.OperateRange(SpanHelpers.AsByteSpan(ref info), OperationId.QueryRange, offset, + size, ReadOnlySpan.Empty); if (rc.IsFailure()) return rc; rangeInfo.Merge(in info); @@ -129,4 +130,4 @@ namespace LibHac.FsSrv.Impl ParentFs?.Dispose(); } } -} +} \ No newline at end of file diff --git a/src/LibHac/FsSrv/Impl/StorageInterfaceAdapter.cs b/src/LibHac/FsSrv/Impl/StorageInterfaceAdapter.cs index d59b50cd..1d178d65 100644 --- a/src/LibHac/FsSrv/Impl/StorageInterfaceAdapter.cs +++ b/src/LibHac/FsSrv/Impl/StorageInterfaceAdapter.cs @@ -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 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 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; } } -} +} \ No newline at end of file diff --git a/src/LibHac/FsSrv/Sf/IFile.cs b/src/LibHac/FsSrv/Sf/IFile.cs index 3e35af92..5236bf59 100644 --- a/src/LibHac/FsSrv/Sf/IFile.cs +++ b/src/LibHac/FsSrv/Sf/IFile.cs @@ -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 destination, ReadOption option); - Result Write(long offset, ReadOnlySpan 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); } -} +} \ No newline at end of file diff --git a/src/LibHac/FsSrv/Sf/IStorage.cs b/src/LibHac/FsSrv/Sf/IStorage.cs index 264dbd49..5074556d 100644 --- a/src/LibHac/FsSrv/Sf/IStorage.cs +++ b/src/LibHac/FsSrv/Sf/IStorage.cs @@ -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 destination); - Result Write(long offset, ReadOnlySpan 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); } -} +} \ No newline at end of file