mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2025-02-09 13:14:46 +01:00
Replace old fsa classes with new ones
This commit is contained in:
parent
ba1bf2f1c8
commit
ef1481b04c
@ -199,6 +199,7 @@ Module,DescriptionStart,DescriptionEnd,Name,Summary
|
||||
2,6369,,UnsupportedOperationModifyReadOnlyFileSystem,
|
||||
2,6371,,UnsupportedOperationReadOnlyFileSystemGetSpace,
|
||||
2,6372,,UnsupportedOperationModifyReadOnlyFile,
|
||||
2,6373,,UnsupportedOperationInReadOnlyFile,
|
||||
2,6374,,UnsupportedOperationModifyPartitionFileSystem,
|
||||
2,6375,,UnsupportedOperationInPartitionFileSystem,Called PartitionFileSystemCore::CommitProvisionally.
|
||||
2,6376,,UnsupportedOperationInPartitionFileSetSize,
|
||||
|
Can't render this file because it has a wrong number of fields in line 135.
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace LibHac.Fs.Accessors
|
||||
{
|
||||
public class FileAccessor : FileBase
|
||||
public class FileAccessor : IFile
|
||||
{
|
||||
private IFile File { get; set; }
|
||||
|
||||
@ -17,29 +17,30 @@ namespace LibHac.Fs.Accessors
|
||||
OpenMode = mode;
|
||||
}
|
||||
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination, ReadOptionFlag options)
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination,
|
||||
in ReadOption option)
|
||||
{
|
||||
CheckIfDisposed();
|
||||
|
||||
return File.Read(out bytesRead, offset, destination, options);
|
||||
return File.Read(out bytesRead, offset, destination, in option);
|
||||
}
|
||||
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, WriteOptionFlag options)
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
CheckIfDisposed();
|
||||
|
||||
if (source.Length == 0)
|
||||
{
|
||||
WriteState = (WriteState)(~options & WriteOptionFlag.Flush);
|
||||
WriteState = (WriteState)(~option.Flags & WriteOptionFlag.Flush);
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
Result rc = File.Write(offset, source, options);
|
||||
Result rc = File.Write(offset, source, in option);
|
||||
|
||||
if (rc.IsSuccess())
|
||||
{
|
||||
WriteState = (WriteState)(~options & WriteOptionFlag.Flush);
|
||||
WriteState = (WriteState)(~option.Flags & WriteOptionFlag.Flush);
|
||||
}
|
||||
|
||||
return rc;
|
||||
@ -66,6 +67,11 @@ namespace LibHac.Fs.Accessors
|
||||
return File.GetSize(out size);
|
||||
}
|
||||
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected override Result DoSetSize(long size)
|
||||
{
|
||||
CheckIfDisposed();
|
||||
|
@ -1,48 +0,0 @@
|
||||
using LibHac.Common;
|
||||
|
||||
namespace LibHac.Fs
|
||||
{
|
||||
public abstract class AttributeFileSystemBase : FileSystemBase, IAttributeFileSystem
|
||||
{
|
||||
protected abstract Result CreateDirectoryImpl(U8Span path, NxFileAttributes archiveAttribute);
|
||||
protected abstract Result GetFileAttributesImpl(out NxFileAttributes attributes, U8Span path);
|
||||
protected abstract Result SetFileAttributesImpl(U8Span path, NxFileAttributes attributes);
|
||||
protected abstract Result GetFileSizeImpl(out long fileSize, U8Span path);
|
||||
|
||||
public Result CreateDirectory(U8Span path, NxFileAttributes archiveAttribute)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return CreateDirectoryImpl(path, archiveAttribute);
|
||||
}
|
||||
|
||||
public Result GetFileAttributes(out NxFileAttributes attributes, U8Span path)
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
attributes = default;
|
||||
return ResultFs.PreconditionViolation.Log();
|
||||
}
|
||||
|
||||
return GetFileAttributesImpl(out attributes, path);
|
||||
}
|
||||
|
||||
public Result SetFileAttributes(U8Span path, NxFileAttributes attributes)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return SetFileAttributesImpl(path, attributes);
|
||||
}
|
||||
|
||||
public Result GetFileSize(out long fileSize, U8Span path)
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
fileSize = default;
|
||||
return ResultFs.PreconditionViolation.Log();
|
||||
}
|
||||
|
||||
return GetFileSizeImpl(out fileSize, path);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,150 +0,0 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace LibHac.Fs
|
||||
{
|
||||
public abstract class FileBase : IFile
|
||||
{
|
||||
// 0 = not disposed; 1 = disposed
|
||||
private int _disposedState;
|
||||
private bool IsDisposed => _disposedState != 0;
|
||||
|
||||
protected abstract Result DoRead(out long bytesRead, long offset, Span<byte> destination, ReadOptionFlag options);
|
||||
protected abstract Result DoWrite(long offset, ReadOnlySpan<byte> source, WriteOptionFlag options);
|
||||
protected abstract Result DoFlush();
|
||||
protected abstract Result DoSetSize(long size);
|
||||
protected abstract Result DoGetSize(out long size);
|
||||
|
||||
protected virtual Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
public Result Read(out long bytesRead, long offset, Span<byte> destination, ReadOptionFlag options)
|
||||
{
|
||||
bytesRead = default;
|
||||
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
if (destination.Length == 0) return Result.Success;
|
||||
if (offset < 0) return ResultFs.OutOfRange.Log();
|
||||
if (long.MaxValue - offset < destination.Length) return ResultFs.OutOfRange.Log();
|
||||
|
||||
return DoRead(out bytesRead, offset, destination, options);
|
||||
}
|
||||
|
||||
public Result Write(long offset, ReadOnlySpan<byte> source, WriteOptionFlag options)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
if (source.Length == 0)
|
||||
{
|
||||
if (options.HasFlag(WriteOptionFlag.Flush))
|
||||
{
|
||||
return DoFlush();
|
||||
}
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
if (offset < 0) return ResultFs.OutOfRange.Log();
|
||||
if (long.MaxValue - offset < source.Length) return ResultFs.OutOfRange.Log();
|
||||
|
||||
return DoWrite(offset, source, options);
|
||||
}
|
||||
|
||||
public Result Flush()
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return DoFlush();
|
||||
}
|
||||
|
||||
public Result SetSize(long size)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
if (size < 0) return ResultFs.OutOfRange.Log();
|
||||
|
||||
return DoSetSize(size);
|
||||
}
|
||||
|
||||
public Result GetSize(out long size)
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
size = default;
|
||||
return ResultFs.PreconditionViolation.Log();
|
||||
}
|
||||
|
||||
return DoGetSize(out size);
|
||||
}
|
||||
|
||||
public Result OperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return DoOperateRange(outBuffer, operationId, offset, size, inBuffer);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Make sure Dispose is only called once
|
||||
if (Interlocked.CompareExchange(ref _disposedState, 1, 0) == 0)
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing) { }
|
||||
|
||||
protected Result ValidateReadParams(out long bytesToRead, long offset, int size, OpenMode openMode)
|
||||
{
|
||||
bytesToRead = default;
|
||||
|
||||
if (!openMode.HasFlag(OpenMode.Read))
|
||||
{
|
||||
return ResultFs.InvalidOpenModeForRead.Log();
|
||||
}
|
||||
|
||||
Result rc = GetSize(out long fileSize);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
if (offset > fileSize)
|
||||
{
|
||||
return ResultFs.OutOfRange.Log();
|
||||
}
|
||||
|
||||
bytesToRead = Math.Min(fileSize - offset, size);
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected Result ValidateWriteParams(long offset, int size, OpenMode openMode, out bool isResizeNeeded)
|
||||
{
|
||||
isResizeNeeded = false;
|
||||
|
||||
if (!openMode.HasFlag(OpenMode.Write))
|
||||
{
|
||||
return ResultFs.InvalidOpenModeForWrite.Log();
|
||||
}
|
||||
|
||||
Result rc = GetSize(out long fileSize);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
if (offset + size > fileSize)
|
||||
{
|
||||
isResizeNeeded = true;
|
||||
|
||||
if (!openMode.HasFlag(OpenMode.AllowAppend))
|
||||
{
|
||||
return ResultFs.FileExtensionWithoutOpenModeAllowAppend.Log();
|
||||
}
|
||||
}
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
}
|
@ -50,7 +50,7 @@ namespace LibHac.Fs
|
||||
if (!IsRangeValid(offset, destination.Length, FileSize))
|
||||
return ResultFs.OutOfRange.Log();
|
||||
|
||||
return BaseFile.Read(out _, offset, destination, ReadOptionFlag.None);
|
||||
return BaseFile.Read(out _, offset, destination, ReadOption.None);
|
||||
}
|
||||
|
||||
protected override Result WriteImpl(long offset, ReadOnlySpan<byte> source)
|
||||
@ -64,7 +64,7 @@ namespace LibHac.Fs
|
||||
if (!IsRangeValid(offset, source.Length, FileSize))
|
||||
return ResultFs.OutOfRange.Log();
|
||||
|
||||
return BaseFile.Write(offset, source, WriteOptionFlag.None);
|
||||
return BaseFile.Write(offset, source, WriteOption.None);
|
||||
}
|
||||
|
||||
protected override Result FlushImpl()
|
||||
|
@ -1,258 +0,0 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using LibHac.Common;
|
||||
|
||||
namespace LibHac.Fs
|
||||
{
|
||||
public abstract class FileSystemBase : IFileSystem
|
||||
{
|
||||
// 0 = not disposed; 1 = disposed
|
||||
private int _disposedState;
|
||||
protected bool IsDisposed => _disposedState != 0;
|
||||
|
||||
protected abstract Result CreateDirectoryImpl(U8Span path);
|
||||
protected abstract Result CreateFileImpl(U8Span path, long size, CreateFileOptions options);
|
||||
protected abstract Result DeleteDirectoryImpl(U8Span path);
|
||||
protected abstract Result DeleteDirectoryRecursivelyImpl(U8Span path);
|
||||
protected abstract Result CleanDirectoryRecursivelyImpl(U8Span path);
|
||||
protected abstract Result DeleteFileImpl(U8Span path);
|
||||
protected abstract Result OpenDirectoryImpl(out IDirectory directory, U8Span path, OpenDirectoryMode mode);
|
||||
protected abstract Result OpenFileImpl(out IFile file, U8Span path, OpenMode mode);
|
||||
protected abstract Result RenameDirectoryImpl(U8Span oldPath, U8Span newPath);
|
||||
protected abstract Result RenameFileImpl(U8Span oldPath, U8Span newPath);
|
||||
protected abstract Result GetEntryTypeImpl(out DirectoryEntryType entryType, U8Span path);
|
||||
protected abstract Result CommitImpl();
|
||||
|
||||
protected virtual Result GetFreeSpaceSizeImpl(out long freeSpace, U8Span path)
|
||||
{
|
||||
freeSpace = default;
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected virtual Result GetTotalSpaceSizeImpl(out long totalSpace, U8Span path)
|
||||
{
|
||||
totalSpace = default;
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected virtual Result CommitProvisionallyImpl(long commitCount)
|
||||
{
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected virtual Result RollbackImpl()
|
||||
{
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected virtual Result FlushImpl()
|
||||
{
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected virtual Result GetFileTimeStampRawImpl(out FileTimeStampRaw timeStamp, U8Span path)
|
||||
{
|
||||
timeStamp = default;
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected virtual Result QueryEntryImpl(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId,
|
||||
U8Span path)
|
||||
{
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
public Result CreateDirectory(U8Span path)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return CreateDirectoryImpl(path);
|
||||
}
|
||||
|
||||
public Result CreateFile(U8Span path, long size, CreateFileOptions options)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return CreateFileImpl(path, size, options);
|
||||
}
|
||||
|
||||
public Result DeleteDirectory(U8Span path)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return DeleteDirectoryImpl(path);
|
||||
}
|
||||
|
||||
public Result DeleteDirectoryRecursively(U8Span path)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return DeleteDirectoryRecursivelyImpl(path);
|
||||
}
|
||||
|
||||
public Result CleanDirectoryRecursively(U8Span path)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return CleanDirectoryRecursivelyImpl(path);
|
||||
}
|
||||
|
||||
public Result DeleteFile(U8Span path)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return DeleteFileImpl(path);
|
||||
}
|
||||
|
||||
public Result OpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
directory = default;
|
||||
return ResultFs.PreconditionViolation.Log();
|
||||
}
|
||||
|
||||
if (path.IsNull())
|
||||
{
|
||||
directory = default;
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
}
|
||||
|
||||
if ((mode & ~OpenDirectoryMode.All) != 0 || (mode & OpenDirectoryMode.All) == 0)
|
||||
{
|
||||
directory = default;
|
||||
return ResultFs.InvalidArgument.Log();
|
||||
}
|
||||
|
||||
return OpenDirectoryImpl(out directory, path, mode);
|
||||
}
|
||||
|
||||
public Result OpenFile(out IFile file, U8Span path, OpenMode mode)
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
file = default;
|
||||
return ResultFs.PreconditionViolation.Log();
|
||||
}
|
||||
|
||||
if (path.IsNull())
|
||||
{
|
||||
file = default;
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
}
|
||||
|
||||
if ((mode & ~OpenMode.All) != 0 || (mode & OpenMode.ReadWrite) == 0)
|
||||
{
|
||||
file = default;
|
||||
return ResultFs.InvalidArgument.Log();
|
||||
}
|
||||
|
||||
return OpenFileImpl(out file, path, mode);
|
||||
}
|
||||
|
||||
public Result RenameDirectory(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return RenameDirectoryImpl(oldPath, newPath);
|
||||
}
|
||||
|
||||
public Result RenameFile(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return RenameFileImpl(oldPath, newPath);
|
||||
}
|
||||
|
||||
public Result GetEntryType(out DirectoryEntryType entryType, U8Span path)
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
entryType = default;
|
||||
return ResultFs.PreconditionViolation.Log();
|
||||
}
|
||||
|
||||
return GetEntryTypeImpl(out entryType, path);
|
||||
}
|
||||
|
||||
public Result GetFreeSpaceSize(out long freeSpace, U8Span path)
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
freeSpace = default;
|
||||
return ResultFs.PreconditionViolation.Log();
|
||||
}
|
||||
|
||||
return GetFreeSpaceSizeImpl(out freeSpace, path);
|
||||
}
|
||||
|
||||
public Result GetTotalSpaceSize(out long totalSpace, U8Span path)
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
totalSpace = default;
|
||||
return ResultFs.PreconditionViolation.Log();
|
||||
}
|
||||
|
||||
return GetTotalSpaceSizeImpl(out totalSpace, path);
|
||||
}
|
||||
|
||||
public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path)
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
timeStamp = default;
|
||||
return ResultFs.PreconditionViolation.Log();
|
||||
}
|
||||
|
||||
return GetFileTimeStampRawImpl(out timeStamp, path);
|
||||
}
|
||||
|
||||
public Result Commit()
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return CommitImpl();
|
||||
}
|
||||
|
||||
public Result CommitProvisionally(long commitCount)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return CommitProvisionallyImpl(commitCount);
|
||||
}
|
||||
|
||||
public Result Rollback()
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return RollbackImpl();
|
||||
}
|
||||
|
||||
public Result Flush()
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return FlushImpl();
|
||||
}
|
||||
|
||||
public Result QueryEntry(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId, U8Span path)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return QueryEntryImpl(outBuffer, inBuffer, queryId, path);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Make sure Dispose is only called once
|
||||
if (Interlocked.CompareExchange(ref _disposedState, 1, 0) == 0)
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing) { }
|
||||
}
|
||||
}
|
@ -6,10 +6,10 @@ namespace LibHac.Fs
|
||||
{
|
||||
public Result ReadFile(FileHandle handle, long offset, Span<byte> destination)
|
||||
{
|
||||
return ReadFile(handle, offset, destination, ReadOptionFlag.None);
|
||||
return ReadFile(handle, offset, destination, ReadOption.None);
|
||||
}
|
||||
|
||||
public Result ReadFile(FileHandle handle, long offset, Span<byte> destination, ReadOptionFlag option)
|
||||
public Result ReadFile(FileHandle handle, long offset, Span<byte> destination, in ReadOption option)
|
||||
{
|
||||
Result rc = ReadFile(out long bytesRead, handle, offset, destination, option);
|
||||
if (rc.IsFailure()) return rc;
|
||||
@ -21,24 +21,24 @@ namespace LibHac.Fs
|
||||
|
||||
public Result ReadFile(out long bytesRead, FileHandle handle, long offset, Span<byte> destination)
|
||||
{
|
||||
return ReadFile(out bytesRead, handle, offset, destination, ReadOptionFlag.None);
|
||||
return ReadFile(out bytesRead, handle, offset, destination, ReadOption.None);
|
||||
}
|
||||
|
||||
public Result ReadFile(out long bytesRead, FileHandle handle, long offset, Span<byte> destination, ReadOptionFlag option)
|
||||
public Result ReadFile(out long bytesRead, FileHandle handle, long offset, Span<byte> destination, in ReadOption option)
|
||||
{
|
||||
Result rc;
|
||||
|
||||
if (IsEnabledAccessLog() && IsEnabledHandleAccessLog(handle))
|
||||
{
|
||||
TimeSpan startTime = Time.GetCurrent();
|
||||
rc = handle.File.Read(out bytesRead, offset, destination, option);
|
||||
rc = handle.File.Read(out bytesRead, offset, destination, in option);
|
||||
TimeSpan endTime = Time.GetCurrent();
|
||||
|
||||
OutputAccessLog(rc, startTime, endTime, handle, $", offset: {offset}, size: {destination.Length}");
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = handle.File.Read(out bytesRead, offset, destination, option);
|
||||
rc = handle.File.Read(out bytesRead, offset, destination, in option);
|
||||
}
|
||||
|
||||
return rc;
|
||||
@ -46,26 +46,26 @@ namespace LibHac.Fs
|
||||
|
||||
public Result WriteFile(FileHandle handle, long offset, ReadOnlySpan<byte> source)
|
||||
{
|
||||
return WriteFile(handle, offset, source, WriteOptionFlag.None);
|
||||
return WriteFile(handle, offset, source, WriteOption.None);
|
||||
}
|
||||
|
||||
public Result WriteFile(FileHandle handle, long offset, ReadOnlySpan<byte> source, WriteOptionFlag option)
|
||||
public Result WriteFile(FileHandle handle, long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
Result rc;
|
||||
|
||||
if (IsEnabledAccessLog() && IsEnabledHandleAccessLog(handle))
|
||||
{
|
||||
TimeSpan startTime = Time.GetCurrent();
|
||||
rc = handle.File.Write(offset, source, option);
|
||||
rc = handle.File.Write(offset, source, in option);
|
||||
TimeSpan endTime = Time.GetCurrent();
|
||||
|
||||
string optionString = (option & WriteOptionFlag.Flush) == 0 ? "" : $", write_option: {option}";
|
||||
string optionString = option.HasFlushFlag() ? "" : $", write_option: {option}";
|
||||
|
||||
OutputAccessLog(rc, startTime, endTime, handle, $", offset: {offset}, size: {source.Length}{optionString}");
|
||||
}
|
||||
else
|
||||
{
|
||||
rc = handle.File.Write(offset, source, option);
|
||||
rc = handle.File.Write(offset, source, in option);
|
||||
}
|
||||
|
||||
return rc;
|
||||
|
@ -2,11 +2,50 @@
|
||||
|
||||
namespace LibHac.Fs
|
||||
{
|
||||
public interface IAttributeFileSystem : IFileSystem
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public abstract class IAttributeFileSystem : IFileSystem
|
||||
{
|
||||
Result CreateDirectory(U8Span path, NxFileAttributes archiveAttribute);
|
||||
Result GetFileAttributes(out NxFileAttributes attributes, U8Span path);
|
||||
Result SetFileAttributes(U8Span path, NxFileAttributes attributes);
|
||||
Result GetFileSize(out long fileSize, U8Span path);
|
||||
public Result CreateDirectory(U8Span path, NxFileAttributes archiveAttribute)
|
||||
{
|
||||
if (path.IsNull())
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
|
||||
return DoCreateDirectory(path, archiveAttribute);
|
||||
}
|
||||
|
||||
public Result GetFileAttributes(out NxFileAttributes attributes, U8Span path)
|
||||
{
|
||||
if (path.IsNull())
|
||||
{
|
||||
attributes = default;
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
}
|
||||
|
||||
return DoGetFileAttributes(out attributes, path);
|
||||
}
|
||||
|
||||
public Result SetFileAttributes(U8Span path, NxFileAttributes attributes)
|
||||
{
|
||||
if (path.IsNull())
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
|
||||
return DoSetFileAttributes(path, attributes);
|
||||
}
|
||||
|
||||
public Result GetFileSize(out long fileSize, U8Span path)
|
||||
{
|
||||
if (path.IsNull())
|
||||
{
|
||||
fileSize = default;
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
}
|
||||
|
||||
return DoGetFileSize(out fileSize, path);
|
||||
}
|
||||
|
||||
protected abstract Result DoCreateDirectory(U8Span path, NxFileAttributes archiveAttribute);
|
||||
protected abstract Result DoGetFileAttributes(out NxFileAttributes attributes, U8Span path);
|
||||
protected abstract Result DoSetFileAttributes(U8Span path, NxFileAttributes attributes);
|
||||
protected abstract Result DoGetFileSize(out long fileSize, U8Span path);
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,11 @@
|
||||
|
||||
namespace LibHac.Fs
|
||||
{
|
||||
// ReSharper disable once InconsistentNaming
|
||||
/// <summary>
|
||||
/// Provides an interface for enumerating the child entries of a directory.
|
||||
/// </summary>
|
||||
public interface IDirectory
|
||||
public abstract class IDirectory : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves the next entries that this directory contains. Does not search subdirectories.
|
||||
@ -19,13 +20,36 @@ namespace LibHac.Fs
|
||||
/// Each call will attempt to read as many entries as the buffer can contain.
|
||||
/// Once all the entries have been read, all subsequent calls to <see cref="Read"/> will
|
||||
/// read 0 entries into the buffer.</remarks>
|
||||
Result Read(out long entriesRead, Span<DirectoryEntry> entryBuffer);
|
||||
public Result Read(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
{
|
||||
if (entryBuffer.IsEmpty)
|
||||
{
|
||||
entriesRead = 0;
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
return DoRead(out entriesRead, entryBuffer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the number of file system entries that this directory contains. Does not search subdirectories.
|
||||
/// </summary>
|
||||
/// <param name="entryCount">The number of child entries the directory contains.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
Result GetEntryCount(out long entryCount);
|
||||
public Result GetEntryCount(out long entryCount)
|
||||
{
|
||||
return DoGetEntryCount(out entryCount);
|
||||
}
|
||||
|
||||
protected abstract Result DoRead(out long entriesRead, Span<DirectoryEntry> entryBuffer);
|
||||
protected abstract Result DoGetEntryCount(out long entryCount);
|
||||
|
||||
protected virtual void Dispose(bool disposing) { }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using LibHac.Diag;
|
||||
|
||||
namespace LibHac.Fs
|
||||
{
|
||||
// ReSharper disable once InconsistentNaming
|
||||
/// <summary>
|
||||
/// Provides an interface for reading and writing a sequence of bytes.
|
||||
/// </summary>
|
||||
@ -16,7 +18,7 @@ namespace LibHac.Fs
|
||||
/// - If <see cref="Write"/> is called on an offset past the end of the <see cref="IFile"/>,
|
||||
/// the <see cref="OpenMode.AllowAppend"/> mode is set and the file supports expansion,
|
||||
/// the file will be expanded so that it is large enough to contain the written data.</remarks>
|
||||
public interface IFile : IDisposable
|
||||
public abstract class IFile : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Reads a sequence of bytes from the current <see cref="IFile"/>.
|
||||
@ -26,37 +28,104 @@ namespace LibHac.Fs
|
||||
/// <param name="offset">The offset in the <see cref="IFile"/> at which to begin reading.</param>
|
||||
/// <param name="destination">The buffer where the read bytes will be stored.
|
||||
/// The number of bytes read will be no larger than the length of the buffer.</param>
|
||||
/// <param name="options">Options for reading from the <see cref="IFile"/>.</param>
|
||||
/// <param name="option">Options for reading from the <see cref="IFile"/>.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
Result Read(out long bytesRead, long offset, Span<byte> destination, ReadOptionFlag options);
|
||||
public Result Read(out long bytesRead, long offset, Span<byte> destination, in ReadOption option)
|
||||
{
|
||||
if (destination.IsEmpty)
|
||||
{
|
||||
bytesRead = 0;
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
if (offset < 0)
|
||||
{
|
||||
bytesRead = 0;
|
||||
return ResultFs.OutOfRange.Log();
|
||||
}
|
||||
|
||||
if (long.MaxValue - offset < destination.Length)
|
||||
{
|
||||
bytesRead = 0;
|
||||
return ResultFs.OutOfRange.Log();
|
||||
}
|
||||
|
||||
return DoRead(out bytesRead, offset, destination, in option);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a sequence of bytes from the current <see cref="IFile"/> with no <see cref="ReadOption"/>s.
|
||||
/// </summary>
|
||||
/// <param name="bytesRead">If the operation returns successfully, The total number of bytes read into
|
||||
/// the buffer. This can be less than the size of the buffer if the IFile is too short to fulfill the request.</param>
|
||||
/// <param name="offset">The offset in the <see cref="IFile"/> at which to begin reading.</param>
|
||||
/// <param name="destination">The buffer where the read bytes will be stored.
|
||||
/// The number of bytes read will be no larger than the length of the buffer.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
public Result Read(out long bytesRead, long offset, Span<byte> destination)
|
||||
{
|
||||
return Read(out bytesRead, offset, destination, ReadOption.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes a sequence of bytes to the current <see cref="IFile"/>.
|
||||
/// </summary>
|
||||
/// <param name="offset">The offset in the <see cref="IStorage"/> at which to begin writing.</param>
|
||||
/// <param name="source">The buffer containing the bytes to be written.</param>
|
||||
/// <param name="options">Options for writing to the <see cref="IFile"/>.</param>
|
||||
/// <param name="option">Options for writing to the <see cref="IFile"/>.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
Result Write(long offset, ReadOnlySpan<byte> source, WriteOptionFlag options);
|
||||
public Result Write(long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
if (source.IsEmpty)
|
||||
{
|
||||
if (option.HasFlushFlag())
|
||||
{
|
||||
Result rc = Flush();
|
||||
if (rc.IsFailure()) return rc;
|
||||
}
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
if (offset < 0)
|
||||
return ResultFs.OutOfRange.Log();
|
||||
|
||||
if (long.MaxValue - offset < source.Length)
|
||||
return ResultFs.OutOfRange.Log();
|
||||
|
||||
return DoWrite(offset, source, in option);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Causes any buffered data to be written to the underlying device.
|
||||
/// </summary>
|
||||
Result Flush();
|
||||
public Result Flush()
|
||||
{
|
||||
return DoFlush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the size of the file in bytes.
|
||||
/// </summary>
|
||||
/// <param name="size">The desired size of the file in bytes.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
Result SetSize(long size);
|
||||
public Result SetSize(long size)
|
||||
{
|
||||
if (size < 0)
|
||||
return ResultFs.OutOfRange.Log();
|
||||
|
||||
return DoSetSize(size);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of bytes in the file.
|
||||
/// </summary>
|
||||
/// <param name="size">If the operation returns successfully, the length of the file in bytes.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
Result GetSize(out long size);
|
||||
public Result GetSize(out long size)
|
||||
{
|
||||
return DoGetSize(out size);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs various operations on the file. Used to extend the functionality of the <see cref="IFile"/> interface.
|
||||
@ -67,7 +136,113 @@ namespace LibHac.Fs
|
||||
/// <param name="size">The size of the range to operate on.</param>
|
||||
/// <param name="inBuffer">An input buffer. Size may vary depending on the operation performed.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
Result OperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
public Result OperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
return DoOperateRange(outBuffer, operationId, offset, size, inBuffer);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs various operations on the file. Used to extend the functionality of the <see cref="IFile"/> interface.
|
||||
/// </summary>
|
||||
/// <param name="operationId">The operation to be performed.</param>
|
||||
/// <param name="offset">The offset of the range to operate on.</param>
|
||||
/// <param name="size">The size of the range to operate on.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
public Result OperateRange(OperationId operationId, long offset, long size)
|
||||
{
|
||||
return DoOperateRange(Span<byte>.Empty, operationId, offset, size, ReadOnlySpan<byte>.Empty);
|
||||
}
|
||||
|
||||
protected Result DryRead(out long readableBytes, long offset, long size, in ReadOption option,
|
||||
OpenMode openMode)
|
||||
{
|
||||
// Check that we can read.
|
||||
if (!openMode.HasFlag(OpenMode.Read))
|
||||
{
|
||||
readableBytes = default;
|
||||
return ResultFs.InvalidOpenModeForRead.Log();
|
||||
}
|
||||
|
||||
// Get the file size, and validate our offset.
|
||||
Result rc = GetSize(out long fileSize);
|
||||
if (rc.IsFailure())
|
||||
{
|
||||
readableBytes = default;
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (offset > fileSize)
|
||||
{
|
||||
readableBytes = default;
|
||||
return ResultFs.OutOfRange.Log();
|
||||
}
|
||||
|
||||
readableBytes = Math.Min(fileSize - offset, size);
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected Result DrySetSize(long size, OpenMode openMode)
|
||||
{
|
||||
// Check that we can write.
|
||||
if (!openMode.HasFlag(OpenMode.Write))
|
||||
return ResultFs.InvalidOpenModeForWrite.Log();
|
||||
|
||||
Assert.AssertTrue(size >= 0);
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected Result DryWrite(out bool needsAppend, long offset, long size, in WriteOption option,
|
||||
OpenMode openMode)
|
||||
{
|
||||
// Check that we can write.
|
||||
if (!openMode.HasFlag(OpenMode.Write))
|
||||
{
|
||||
needsAppend = default;
|
||||
return ResultFs.InvalidOpenModeForWrite.Log();
|
||||
}
|
||||
|
||||
// Get the file size.
|
||||
Result rc = GetSize(out long fileSize);
|
||||
if (rc.IsFailure())
|
||||
{
|
||||
needsAppend = default;
|
||||
return rc;
|
||||
}
|
||||
|
||||
if (fileSize < offset + size)
|
||||
{
|
||||
if (!openMode.HasFlag(OpenMode.AllowAppend))
|
||||
{
|
||||
needsAppend = default;
|
||||
return ResultFs.FileExtensionWithoutOpenModeAllowAppend.Log();
|
||||
}
|
||||
|
||||
needsAppend = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
needsAppend = false;
|
||||
}
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected abstract Result DoRead(out long bytesRead, long offset, Span<byte> destination, in ReadOption option);
|
||||
protected abstract Result DoWrite(long offset, ReadOnlySpan<byte> source, in WriteOption option);
|
||||
protected abstract Result DoFlush();
|
||||
protected abstract Result DoSetSize(long size);
|
||||
protected abstract Result DoGetSize(out long size);
|
||||
protected abstract Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer);
|
||||
|
||||
protected virtual void Dispose(bool disposing) { }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,17 +4,18 @@ using LibHac.FsSystem;
|
||||
|
||||
namespace LibHac.Fs
|
||||
{
|
||||
// ReSharper disable once InconsistentNaming
|
||||
/// <summary>
|
||||
/// Provides an interface for accessing a file system. <c>/</c> is used as the path delimiter.
|
||||
/// </summary>
|
||||
public interface IFileSystem : IDisposable
|
||||
public abstract class IFileSystem : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates or overwrites a file at the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The full path of the file to create.</param>
|
||||
/// <param name="size">The initial size of the created file.</param>
|
||||
/// <param name="options">Flags to control how the file is created.
|
||||
/// <param name="option">Flags to control how the file is created.
|
||||
/// Should usually be <see cref="CreateFileOptions.None"/></param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
/// <remarks>
|
||||
@ -24,7 +25,16 @@ namespace LibHac.Fs
|
||||
/// Specified path already exists as either a file or directory: <see cref="ResultFs.PathAlreadyExists"/>
|
||||
/// Insufficient free space to create the file: <see cref="ResultFs.InsufficientFreeSpace"/>
|
||||
/// </remarks>
|
||||
Result CreateFile(U8Span path, long size, CreateFileOptions options);
|
||||
public Result CreateFile(U8Span path, long size, CreateFileOptions option)
|
||||
{
|
||||
if (path.IsNull())
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
|
||||
if (size < 0)
|
||||
return ResultFs.OutOfRange.Log();
|
||||
|
||||
return DoCreateFile(path, size, option);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified file.
|
||||
@ -36,7 +46,13 @@ namespace LibHac.Fs
|
||||
///
|
||||
/// The specified path does not exist or is a directory: <see cref="ResultFs.PathNotFound"/>
|
||||
/// </remarks>
|
||||
Result DeleteFile(U8Span path);
|
||||
public Result DeleteFile(U8Span path)
|
||||
{
|
||||
if (path.IsNull())
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
|
||||
return DoDeleteFile(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates all directories and subdirectories in the specified path unless they already exist.
|
||||
@ -50,7 +66,13 @@ namespace LibHac.Fs
|
||||
/// Specified path already exists as either a file or directory: <see cref="ResultFs.PathAlreadyExists"/>
|
||||
/// Insufficient free space to create the directory: <see cref="ResultFs.InsufficientFreeSpace"/>
|
||||
/// </remarks>
|
||||
Result CreateDirectory(U8Span path);
|
||||
public Result CreateDirectory(U8Span path)
|
||||
{
|
||||
if (path.IsNull())
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
|
||||
return DoCreateDirectory(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified directory.
|
||||
@ -63,7 +85,13 @@ namespace LibHac.Fs
|
||||
/// The specified path does not exist or is a file: <see cref="ResultFs.PathNotFound"/>
|
||||
/// The specified directory is not empty: <see cref="ResultFs.DirectoryNotEmpty"/>
|
||||
/// </remarks>
|
||||
Result DeleteDirectory(U8Span path);
|
||||
public Result DeleteDirectory(U8Span path)
|
||||
{
|
||||
if (path.IsNull())
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
|
||||
return DoDeleteDirectory(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified directory and any subdirectories and files in the directory.
|
||||
@ -75,7 +103,13 @@ namespace LibHac.Fs
|
||||
///
|
||||
/// The specified path does not exist or is a file: <see cref="ResultFs.PathNotFound"/>
|
||||
/// </remarks>
|
||||
Result DeleteDirectoryRecursively(U8Span path);
|
||||
public Result DeleteDirectoryRecursively(U8Span path)
|
||||
{
|
||||
if (path.IsNull())
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
|
||||
return DoDeleteDirectoryRecursively(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deletes any subdirectories and files in the specified directory.
|
||||
@ -87,7 +121,13 @@ namespace LibHac.Fs
|
||||
///
|
||||
/// The specified path does not exist or is a file: <see cref="ResultFs.PathNotFound"/>
|
||||
/// </remarks>
|
||||
Result CleanDirectoryRecursively(U8Span path);
|
||||
public Result CleanDirectoryRecursively(U8Span path)
|
||||
{
|
||||
if (path.IsNull())
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
|
||||
return DoCleanDirectoryRecursively(path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renames or moves a file to a new location.
|
||||
@ -103,7 +143,16 @@ namespace LibHac.Fs
|
||||
/// <paramref name="newPath"/>'s parent directory does not exist: <see cref="ResultFs.PathNotFound"/>
|
||||
/// <paramref name="newPath"/> already exists as either a file or directory: <see cref="ResultFs.PathAlreadyExists"/>
|
||||
/// </remarks>
|
||||
Result RenameFile(U8Span oldPath, U8Span newPath);
|
||||
public Result RenameFile(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
if (oldPath.IsNull())
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
|
||||
if (newPath.IsNull())
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
|
||||
return DoRenameFile(oldPath, newPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renames or moves a directory to a new location.
|
||||
@ -120,7 +169,16 @@ namespace LibHac.Fs
|
||||
/// <paramref name="newPath"/> already exists as either a file or directory: <see cref="ResultFs.PathAlreadyExists"/>
|
||||
/// Either <paramref name="oldPath"/> or <paramref name="newPath"/> is a subpath of the other: <see cref="ResultFs.DestinationIsSubPathOfSource"/>
|
||||
/// </remarks>
|
||||
Result RenameDirectory(U8Span oldPath, U8Span newPath);
|
||||
public Result RenameDirectory(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
if (oldPath.IsNull())
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
|
||||
if (newPath.IsNull())
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
|
||||
return DoRenameDirectory(oldPath, newPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified path is a file or directory, or does not exist.
|
||||
@ -128,7 +186,16 @@ namespace LibHac.Fs
|
||||
/// <param name="entryType">If the operation returns successfully, the <see cref="DirectoryEntryType"/> of the file.</param>
|
||||
/// <param name="path">The full path to check.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
Result GetEntryType(out DirectoryEntryType entryType, U8Span path);
|
||||
public Result GetEntryType(out DirectoryEntryType entryType, U8Span path)
|
||||
{
|
||||
if (path.IsNull())
|
||||
{
|
||||
entryType = default;
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
}
|
||||
|
||||
return DoGetEntryType(out entryType, path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the amount of available free space on a drive, in bytes.
|
||||
@ -136,7 +203,16 @@ namespace LibHac.Fs
|
||||
/// <param name="freeSpace">If the operation returns successfully, the amount of free space available on the drive, in bytes.</param>
|
||||
/// <param name="path">The path of the drive to query. Unused in almost all cases.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
Result GetFreeSpaceSize(out long freeSpace, U8Span path);
|
||||
public Result GetFreeSpaceSize(out long freeSpace, U8Span path)
|
||||
{
|
||||
if (path.IsNull())
|
||||
{
|
||||
freeSpace = default;
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
}
|
||||
|
||||
return DoGetFreeSpaceSize(out freeSpace, path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the total size of storage space on a drive, in bytes.
|
||||
@ -144,7 +220,16 @@ namespace LibHac.Fs
|
||||
/// <param name="totalSpace">If the operation returns successfully, the total size of the drive, in bytes.</param>
|
||||
/// <param name="path">The path of the drive to query. Unused in almost all cases.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
Result GetTotalSpaceSize(out long totalSpace, U8Span path);
|
||||
public Result GetTotalSpaceSize(out long totalSpace, U8Span path)
|
||||
{
|
||||
if (path.IsNull())
|
||||
{
|
||||
totalSpace = default;
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
}
|
||||
|
||||
return DoGetTotalSpaceSize(out totalSpace, path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens an <see cref="IFile"/> instance for the specified path.
|
||||
@ -159,7 +244,28 @@ namespace LibHac.Fs
|
||||
///
|
||||
/// The specified path does not exist or is a directory: <see cref="ResultFs.PathNotFound"/>
|
||||
/// </remarks>
|
||||
Result OpenFile(out IFile file, U8Span path, OpenMode mode);
|
||||
public Result OpenFile(out IFile file, U8Span path, OpenMode mode)
|
||||
{
|
||||
if (path.IsNull())
|
||||
{
|
||||
file = default;
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
}
|
||||
|
||||
if ((mode & OpenMode.ReadWrite) == 0)
|
||||
{
|
||||
file = default;
|
||||
return ResultFs.InvalidOpenMode.Log();
|
||||
}
|
||||
|
||||
if ((mode & ~OpenMode.All) != 0)
|
||||
{
|
||||
file = default;
|
||||
return ResultFs.InvalidOpenMode.Log();
|
||||
}
|
||||
|
||||
return DoOpenFile(out file, path, mode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="IDirectory"/> instance for enumerating the specified directory.
|
||||
@ -174,20 +280,41 @@ namespace LibHac.Fs
|
||||
///
|
||||
/// The specified path does not exist or is a file: <see cref="ResultFs.PathNotFound"/>
|
||||
/// </remarks>
|
||||
Result OpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode);
|
||||
public Result OpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
{
|
||||
if (path.IsNull())
|
||||
{
|
||||
directory = default;
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
}
|
||||
|
||||
if ((mode & OpenDirectoryMode.All) == 0)
|
||||
{
|
||||
directory = default;
|
||||
return ResultFs.InvalidOpenMode.Log();
|
||||
}
|
||||
|
||||
if ((mode & ~(OpenDirectoryMode.All | OpenDirectoryMode.NoFileSize)) != 0)
|
||||
{
|
||||
directory = default;
|
||||
return ResultFs.InvalidOpenMode.Log();
|
||||
}
|
||||
|
||||
return DoOpenDirectory(out directory, path, mode);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Commits any changes to a transactional file system.
|
||||
/// Does nothing if called on a non-transactional file system.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
Result Commit();
|
||||
public Result Commit() => DoCommit();
|
||||
|
||||
Result CommitProvisionally(long commitCount);
|
||||
public Result CommitProvisionally(long counter) => DoCommitProvisionally(counter);
|
||||
|
||||
Result Rollback();
|
||||
public Result Rollback() => DoRollback();
|
||||
|
||||
Result Flush();
|
||||
public Result Flush() => DoFlush();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the creation, last accessed, and last modified timestamps of a file or directory.
|
||||
@ -201,7 +328,16 @@ namespace LibHac.Fs
|
||||
///
|
||||
/// The specified path does not exist: <see cref="ResultFs.PathNotFound"/>
|
||||
/// </remarks>
|
||||
Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path);
|
||||
public Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path)
|
||||
{
|
||||
if (path.IsNull())
|
||||
{
|
||||
timeStamp = default;
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
}
|
||||
|
||||
return DoGetFileTimeStampRaw(out timeStamp, path);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a query on the specified file.
|
||||
@ -215,7 +351,60 @@ namespace LibHac.Fs
|
||||
/// <param name="queryId">The type of query to perform.</param>
|
||||
/// <param name="path">The full path of the file to query.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
Result QueryEntry(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId, U8Span path);
|
||||
public Result QueryEntry(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId, U8Span path)
|
||||
{
|
||||
if (path.IsNull())
|
||||
return ResultFs.NullptrArgument.Log();
|
||||
|
||||
return DoQueryEntry(outBuffer, inBuffer, queryId, path);
|
||||
}
|
||||
|
||||
protected abstract Result DoCreateFile(U8Span path, long size, CreateFileOptions option);
|
||||
protected abstract Result DoDeleteFile(U8Span path);
|
||||
protected abstract Result DoCreateDirectory(U8Span path);
|
||||
protected abstract Result DoDeleteDirectory(U8Span path);
|
||||
protected abstract Result DoDeleteDirectoryRecursively(U8Span path);
|
||||
protected abstract Result DoCleanDirectoryRecursively(U8Span path);
|
||||
protected abstract Result DoRenameFile(U8Span oldPath, U8Span newPath);
|
||||
protected abstract Result DoRenameDirectory(U8Span oldPath, U8Span newPath);
|
||||
protected abstract Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path);
|
||||
|
||||
protected virtual Result DoGetFreeSpaceSize(out long freeSpace, U8Span path)
|
||||
{
|
||||
freeSpace = default;
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected virtual Result DoGetTotalSpaceSize(out long totalSpace, U8Span path)
|
||||
{
|
||||
totalSpace = default;
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected abstract Result DoOpenFile(out IFile file, U8Span path, OpenMode mode);
|
||||
protected abstract Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode);
|
||||
protected abstract Result DoCommit();
|
||||
|
||||
protected virtual Result DoCommitProvisionally(long counter) => ResultFs.NotImplemented.Log();
|
||||
protected virtual Result DoRollback() => ResultFs.NotImplemented.Log();
|
||||
protected virtual Result DoFlush() => ResultFs.NotImplemented.Log();
|
||||
|
||||
protected virtual Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path)
|
||||
{
|
||||
timeStamp = default;
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected virtual Result DoQueryEntry(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId,
|
||||
U8Span path) => ResultFs.NotImplemented.Log();
|
||||
|
||||
protected virtual void Dispose(bool disposing) { }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -251,4 +440,4 @@ namespace LibHac.Fs
|
||||
/// </summary>
|
||||
MakeConcatFile = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace LibHac.Fs
|
||||
/// <summary>
|
||||
/// A filesystem stored in-memory. Mainly used for testing.
|
||||
/// </summary>
|
||||
public class InMemoryFileSystem : AttributeFileSystemBase
|
||||
public class InMemoryFileSystem : IAttributeFileSystem
|
||||
{
|
||||
private FileTable FsTable { get; }
|
||||
|
||||
@ -18,12 +18,12 @@ namespace LibHac.Fs
|
||||
FsTable = new FileTable();
|
||||
}
|
||||
|
||||
protected override Result CreateDirectoryImpl(U8Span path)
|
||||
protected override Result DoCreateDirectory(U8Span path)
|
||||
{
|
||||
return FsTable.AddDirectory(new U8Span(path));
|
||||
}
|
||||
|
||||
protected override Result CreateDirectoryImpl(U8Span path, NxFileAttributes archiveAttribute)
|
||||
protected override Result DoCreateDirectory(U8Span path, NxFileAttributes archiveAttribute)
|
||||
{
|
||||
Result rc = FsTable.AddDirectory(path);
|
||||
if (rc.IsFailure()) return rc;
|
||||
@ -35,7 +35,7 @@ namespace LibHac.Fs
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result CreateFileImpl(U8Span path, long size, CreateFileOptions options)
|
||||
protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions options)
|
||||
{
|
||||
Result rc = FsTable.AddFile(path);
|
||||
if (rc.IsFailure()) return rc;
|
||||
@ -46,27 +46,27 @@ namespace LibHac.Fs
|
||||
return file.File.SetSize(size);
|
||||
}
|
||||
|
||||
protected override Result DeleteDirectoryImpl(U8Span path)
|
||||
protected override Result DoDeleteDirectory(U8Span path)
|
||||
{
|
||||
return FsTable.DeleteDirectory(new U8Span(path), false);
|
||||
}
|
||||
|
||||
protected override Result DeleteDirectoryRecursivelyImpl(U8Span path)
|
||||
protected override Result DoDeleteDirectoryRecursively(U8Span path)
|
||||
{
|
||||
return FsTable.DeleteDirectory(new U8Span(path), true);
|
||||
}
|
||||
|
||||
protected override Result CleanDirectoryRecursivelyImpl(U8Span path)
|
||||
protected override Result DoCleanDirectoryRecursively(U8Span path)
|
||||
{
|
||||
return FsTable.CleanDirectory(new U8Span(path));
|
||||
}
|
||||
|
||||
protected override Result DeleteFileImpl(U8Span path)
|
||||
protected override Result DoDeleteFile(U8Span path)
|
||||
{
|
||||
return FsTable.DeleteFile(new U8Span(path));
|
||||
}
|
||||
|
||||
protected override Result OpenDirectoryImpl(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
{
|
||||
directory = default;
|
||||
|
||||
@ -77,7 +77,7 @@ namespace LibHac.Fs
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result OpenFileImpl(out IFile file, U8Span path, OpenMode mode)
|
||||
protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
|
||||
{
|
||||
file = default;
|
||||
|
||||
@ -89,17 +89,17 @@ namespace LibHac.Fs
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result RenameDirectoryImpl(U8Span oldPath, U8Span newPath)
|
||||
protected override Result DoRenameDirectory(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
return FsTable.RenameDirectory(new U8Span(oldPath), new U8Span(newPath));
|
||||
}
|
||||
|
||||
protected override Result RenameFileImpl(U8Span oldPath, U8Span newPath)
|
||||
protected override Result DoRenameFile(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
return FsTable.RenameFile(new U8Span(oldPath), new U8Span(newPath));
|
||||
}
|
||||
|
||||
protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, U8Span path)
|
||||
protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path)
|
||||
{
|
||||
if (FsTable.GetFile(path, out _).IsSuccess())
|
||||
{
|
||||
@ -117,12 +117,12 @@ namespace LibHac.Fs
|
||||
return ResultFs.PathNotFound.Log();
|
||||
}
|
||||
|
||||
protected override Result CommitImpl()
|
||||
protected override Result DoCommit()
|
||||
{
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result GetFileAttributesImpl(out NxFileAttributes attributes, U8Span path)
|
||||
protected override Result DoGetFileAttributes(out NxFileAttributes attributes, U8Span path)
|
||||
{
|
||||
if (FsTable.GetFile(path, out FileNode file).IsSuccess())
|
||||
{
|
||||
@ -140,7 +140,7 @@ namespace LibHac.Fs
|
||||
return ResultFs.PathNotFound.Log();
|
||||
}
|
||||
|
||||
protected override Result SetFileAttributesImpl(U8Span path, NxFileAttributes attributes)
|
||||
protected override Result DoSetFileAttributes(U8Span path, NxFileAttributes attributes)
|
||||
{
|
||||
if (FsTable.GetFile(path, out FileNode file).IsSuccess())
|
||||
{
|
||||
@ -157,7 +157,7 @@ namespace LibHac.Fs
|
||||
return ResultFs.PathNotFound.Log();
|
||||
}
|
||||
|
||||
protected override Result GetFileSizeImpl(out long fileSize, U8Span path)
|
||||
protected override Result DoGetFileSize(out long fileSize, U8Span path)
|
||||
{
|
||||
if (FsTable.GetFile(path, out FileNode file).IsSuccess())
|
||||
{
|
||||
@ -169,7 +169,7 @@ namespace LibHac.Fs
|
||||
}
|
||||
|
||||
// todo: Make a more generic MemoryFile-type class
|
||||
private class MemoryFile : FileBase
|
||||
private class MemoryFile : IFile
|
||||
{
|
||||
private OpenMode Mode { get; }
|
||||
private MemoryStreamAccessor BaseStream { get; }
|
||||
@ -180,7 +180,8 @@ namespace LibHac.Fs
|
||||
Mode = mode;
|
||||
}
|
||||
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination, ReadOptionFlag options)
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination,
|
||||
in ReadOption option)
|
||||
{
|
||||
if (!Mode.HasFlag(OpenMode.Read))
|
||||
{
|
||||
@ -191,7 +192,7 @@ namespace LibHac.Fs
|
||||
return BaseStream.Read(out bytesRead, offset, destination);
|
||||
}
|
||||
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, WriteOptionFlag options)
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
if (!Mode.HasFlag(OpenMode.Write))
|
||||
{
|
||||
@ -215,6 +216,11 @@ namespace LibHac.Fs
|
||||
{
|
||||
return BaseStream.GetSize(out size);
|
||||
}
|
||||
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
private class MemoryDirectory : IDirectory
|
||||
@ -232,7 +238,7 @@ namespace LibHac.Fs
|
||||
CurrentFile = directory.ChildFile;
|
||||
}
|
||||
|
||||
public Result Read(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
protected override Result DoRead(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
@ -283,7 +289,7 @@ namespace LibHac.Fs
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public Result GetEntryCount(out long entryCount)
|
||||
protected override Result DoGetEntryCount(out long entryCount)
|
||||
{
|
||||
long count = 0;
|
||||
|
||||
|
@ -388,6 +388,8 @@ namespace LibHac.Fs
|
||||
public static Result.Base UnsupportedOperationReadOnlyFileSystemGetSpace => new Result.Base(ModuleFs, 6371);
|
||||
/// <summary>Error code: 2002-6372; Inner value: 0x31c802</summary>
|
||||
public static Result.Base UnsupportedOperationModifyReadOnlyFile => new Result.Base(ModuleFs, 6372);
|
||||
/// <summary>Error code: 2002-6373; Inner value: 0x31ca02</summary>
|
||||
public static Result.Base UnsupportedOperationInReadOnlyFile => new Result.Base(ModuleFs, 6373);
|
||||
/// <summary>Error code: 2002-6374; Inner value: 0x31cc02</summary>
|
||||
public static Result.Base UnsupportedOperationModifyPartitionFileSystem => new Result.Base(ModuleFs, 6374);
|
||||
/// <summary>Called PartitionFileSystemCore::CommitProvisionally.<br/>Error code: 2002-6375; Inner value: 0x31ce02</summary>
|
||||
|
@ -379,7 +379,7 @@ namespace LibHac.FsService
|
||||
|
||||
ReadOnlySpan<byte> metaFileData = stackalloc byte[0x20];
|
||||
|
||||
rc = metaFile.Write(0, metaFileData, WriteOptionFlag.Flush);
|
||||
rc = metaFile.Write(0, metaFileData, WriteOption.Flush);
|
||||
if (rc.IsFailure()) return rc;
|
||||
}
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ namespace LibHac.FsService.Impl
|
||||
_context.CommitCount = commitCount;
|
||||
|
||||
// Write the initial context to the file
|
||||
rc = contextFile.Write(0, SpanHelpers.AsByteSpan(ref _context), WriteOptionFlag.None);
|
||||
rc = contextFile.Write(0, SpanHelpers.AsByteSpan(ref _context), WriteOption.None);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
rc = contextFile.Flush();
|
||||
@ -232,7 +232,7 @@ namespace LibHac.FsService.Impl
|
||||
|
||||
_context.State = CommitState.ProvisionallyCommitted;
|
||||
|
||||
rc = contextFile.Write(0, SpanHelpers.AsByteSpan(ref _context), WriteOptionFlag.None);
|
||||
rc = contextFile.Write(0, SpanHelpers.AsByteSpan(ref _context), WriteOption.None);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
rc = contextFile.Flush();
|
||||
|
@ -86,7 +86,7 @@ namespace LibHac.FsService
|
||||
{
|
||||
ulong lastId = LastPublishedId;
|
||||
|
||||
rc = FsClient.WriteFile(handle, 0, SpanHelpers.AsByteSpan(ref lastId), WriteOptionFlag.None);
|
||||
rc = FsClient.WriteFile(handle, 0, SpanHelpers.AsByteSpan(ref lastId), WriteOption.None);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
rc = FsClient.FlushFile(handle);
|
||||
|
@ -20,7 +20,7 @@ namespace LibHac.FsSystem
|
||||
Path = path;
|
||||
}
|
||||
|
||||
public Result Read(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
protected override Result DoRead(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
{
|
||||
Result rc = BaseDirectory.Read(out entriesRead, entryBuffer);
|
||||
if (rc.IsFailure()) return rc;
|
||||
@ -46,7 +46,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public Result GetEntryCount(out long entryCount)
|
||||
protected override Result DoGetEntryCount(out long entryCount)
|
||||
{
|
||||
return BaseDirectory.GetEntryCount(out entryCount);
|
||||
}
|
||||
@ -73,10 +73,10 @@ namespace LibHac.FsSystem
|
||||
long fileSize = 0;
|
||||
long bytesRead;
|
||||
|
||||
file.Read(out bytesRead, magicOffset, SpanHelpers.AsByteSpan(ref magic), ReadOptionFlag.None);
|
||||
file.Read(out bytesRead, magicOffset, SpanHelpers.AsByteSpan(ref magic), ReadOption.None);
|
||||
if (bytesRead != sizeof(uint) || magic != AesXtsFileHeader.AesXtsFileMagic) return 0;
|
||||
|
||||
file.Read(out bytesRead, fileSizeOffset, SpanHelpers.AsByteSpan(ref fileSize), ReadOptionFlag.None);
|
||||
file.Read(out bytesRead, fileSizeOffset, SpanHelpers.AsByteSpan(ref fileSize), ReadOption.None);
|
||||
if (bytesRead != sizeof(long) || magic != AesXtsFileHeader.AesXtsFileMagic) return 0;
|
||||
|
||||
return fileSize;
|
||||
|
@ -4,7 +4,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem
|
||||
{
|
||||
public class AesXtsFile : FileBase
|
||||
public class AesXtsFile : IFile
|
||||
{
|
||||
private IFile BaseFile { get; }
|
||||
private U8String Path { get; }
|
||||
@ -54,11 +54,11 @@ namespace LibHac.FsSystem
|
||||
return key;
|
||||
}
|
||||
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination, ReadOptionFlag options)
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination, in ReadOption option)
|
||||
{
|
||||
bytesRead = default;
|
||||
|
||||
Result rc = ValidateReadParams(out long toRead, offset, destination.Length, Mode);
|
||||
Result rc = DryRead(out long toRead, offset, destination.Length, in option, Mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
rc = BaseStorage.Read(offset, destination.Slice(0, (int)toRead));
|
||||
@ -68,9 +68,9 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, WriteOptionFlag options)
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
Result rc = ValidateWriteParams(offset, source.Length, Mode, out bool isResizeNeeded);
|
||||
Result rc = DryWrite(out bool isResizeNeeded, offset, source.Length, in option, Mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
if (isResizeNeeded)
|
||||
@ -82,7 +82,7 @@ namespace LibHac.FsSystem
|
||||
rc = BaseStorage.Write(offset, source);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
if ((options & WriteOptionFlag.Flush) != 0)
|
||||
if (option.HasFlushFlag())
|
||||
{
|
||||
return Flush();
|
||||
}
|
||||
@ -101,6 +101,12 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected override Result DoSetSize(long size)
|
||||
{
|
||||
Header.SetSize(size, VerificationKey);
|
||||
|
@ -5,7 +5,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem
|
||||
{
|
||||
public class AesXtsFileSystem : FileSystemBase
|
||||
public class AesXtsFileSystem : IFileSystem
|
||||
{
|
||||
public int BlockSize { get; }
|
||||
|
||||
@ -29,12 +29,12 @@ namespace LibHac.FsSystem
|
||||
BlockSize = blockSize;
|
||||
}
|
||||
|
||||
protected override Result CreateDirectoryImpl(U8Span path)
|
||||
protected override Result DoCreateDirectory(U8Span path)
|
||||
{
|
||||
return BaseFileSystem.CreateDirectory(path);
|
||||
}
|
||||
|
||||
protected override Result CreateFileImpl(U8Span path, long size, CreateFileOptions options)
|
||||
protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions options)
|
||||
{
|
||||
return CreateFile(path, size, options, new byte[0x20]);
|
||||
}
|
||||
@ -68,27 +68,27 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DeleteDirectoryImpl(U8Span path)
|
||||
protected override Result DoDeleteDirectory(U8Span path)
|
||||
{
|
||||
return BaseFileSystem.DeleteDirectory(path);
|
||||
}
|
||||
|
||||
protected override Result DeleteDirectoryRecursivelyImpl(U8Span path)
|
||||
protected override Result DoDeleteDirectoryRecursively(U8Span path)
|
||||
{
|
||||
return BaseFileSystem.DeleteDirectoryRecursively(path);
|
||||
}
|
||||
|
||||
protected override Result CleanDirectoryRecursivelyImpl(U8Span path)
|
||||
protected override Result DoCleanDirectoryRecursively(U8Span path)
|
||||
{
|
||||
return BaseFileSystem.CleanDirectoryRecursively(path);
|
||||
}
|
||||
|
||||
protected override Result DeleteFileImpl(U8Span path)
|
||||
protected override Result DoDeleteFile(U8Span path)
|
||||
{
|
||||
return BaseFileSystem.DeleteFile(path);
|
||||
}
|
||||
|
||||
protected override Result OpenDirectoryImpl(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
{
|
||||
directory = default;
|
||||
|
||||
@ -99,7 +99,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result OpenFileImpl(out IFile file, U8Span path, OpenMode mode)
|
||||
protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
|
||||
{
|
||||
file = default;
|
||||
|
||||
@ -112,7 +112,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result RenameDirectoryImpl(U8Span oldPath, U8Span newPath)
|
||||
protected override Result DoRenameDirectory(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
// todo: Return proper result codes
|
||||
|
||||
@ -172,7 +172,7 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result RenameFileImpl(U8Span oldPath, U8Span newPath)
|
||||
protected override Result DoRenameFile(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
// todo: Return proper result codes
|
||||
|
||||
@ -196,42 +196,42 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, U8Span path)
|
||||
protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path)
|
||||
{
|
||||
return BaseFileSystem.GetEntryType(out entryType, path);
|
||||
}
|
||||
|
||||
protected override Result GetFileTimeStampRawImpl(out FileTimeStampRaw timeStamp, U8Span path)
|
||||
protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path)
|
||||
{
|
||||
return BaseFileSystem.GetFileTimeStampRaw(out timeStamp, path);
|
||||
}
|
||||
|
||||
protected override Result GetFreeSpaceSizeImpl(out long freeSpace, U8Span path)
|
||||
protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path)
|
||||
{
|
||||
return BaseFileSystem.GetFreeSpaceSize(out freeSpace, path);
|
||||
}
|
||||
|
||||
protected override Result GetTotalSpaceSizeImpl(out long totalSpace, U8Span path)
|
||||
protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path)
|
||||
{
|
||||
return BaseFileSystem.GetTotalSpaceSize(out totalSpace, path);
|
||||
}
|
||||
|
||||
protected override Result CommitImpl()
|
||||
protected override Result DoCommit()
|
||||
{
|
||||
return BaseFileSystem.Commit();
|
||||
}
|
||||
|
||||
protected override Result CommitProvisionallyImpl(long commitCount)
|
||||
protected override Result DoCommitProvisionally(long counter)
|
||||
{
|
||||
return BaseFileSystem.CommitProvisionally(commitCount);
|
||||
return BaseFileSystem.CommitProvisionally(counter);
|
||||
}
|
||||
|
||||
protected override Result RollbackImpl()
|
||||
protected override Result DoRollback()
|
||||
{
|
||||
return BaseFileSystem.Rollback();
|
||||
}
|
||||
|
||||
protected override Result QueryEntryImpl(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId,
|
||||
protected override Result DoQueryEntry(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId,
|
||||
U8Span path)
|
||||
{
|
||||
return BaseFileSystem.QueryEntry(outBuffer, inBuffer, queryId, path);
|
||||
@ -276,7 +276,7 @@ namespace LibHac.FsSystem
|
||||
|
||||
using (file)
|
||||
{
|
||||
file.Write(0, header.ToBytes(false), WriteOptionFlag.Flush).ThrowIfFailure();
|
||||
file.Write(0, header.ToBytes(false), WriteOption.Flush).ThrowIfFailure();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ namespace LibHac.FsSystem
|
||||
_path.Str[PathTools.MaxPathLength] = StringTraits.NullTerminator;
|
||||
}
|
||||
|
||||
public Result Read(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
protected override Result DoRead(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
{
|
||||
entriesRead = 0;
|
||||
var entry = new DirectoryEntry();
|
||||
@ -81,7 +81,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public Result GetEntryCount(out long entryCount)
|
||||
protected override Result DoGetEntryCount(out long entryCount)
|
||||
{
|
||||
entryCount = 0;
|
||||
long count = 0;
|
||||
|
@ -7,7 +7,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem
|
||||
{
|
||||
public class ConcatenationFile : FileBase
|
||||
public class ConcatenationFile : IFile
|
||||
{
|
||||
private IFileSystem BaseFileSystem { get; }
|
||||
private U8String FilePath { get; }
|
||||
@ -34,14 +34,15 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination, ReadOptionFlag options)
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination,
|
||||
in ReadOption option)
|
||||
{
|
||||
bytesRead = default;
|
||||
|
||||
long inPos = offset;
|
||||
int outPos = 0;
|
||||
|
||||
Result rc = ValidateReadParams(out long remaining, offset, destination.Length, Mode);
|
||||
Result rc = DryRead(out long remaining, offset, destination.Length, in option, Mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
GetSize(out long fileSize).ThrowIfFailure();
|
||||
@ -55,7 +56,7 @@ namespace LibHac.FsSystem
|
||||
long fileEndOffset = Math.Min((fileIndex + 1) * SubFileSize, fileSize);
|
||||
int bytesToRead = (int)Math.Min(fileEndOffset - inPos, remaining);
|
||||
|
||||
rc = file.Read(out long subFileBytesRead, fileOffset, destination.Slice(outPos, bytesToRead), options);
|
||||
rc = file.Read(out long subFileBytesRead, fileOffset, destination.Slice(outPos, bytesToRead), option);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
outPos += (int)subFileBytesRead;
|
||||
@ -70,9 +71,9 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, WriteOptionFlag options)
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
Result rc = ValidateWriteParams(offset, source.Length, Mode, out _);
|
||||
Result rc = DryWrite(out _, offset, source.Length, in option, Mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
int inPos = 0;
|
||||
@ -91,7 +92,7 @@ namespace LibHac.FsSystem
|
||||
long fileEndOffset = Math.Min((fileIndex + 1) * SubFileSize, fileSize);
|
||||
int bytesToWrite = (int)Math.Min(fileEndOffset - outPos, remaining);
|
||||
|
||||
rc = file.Write(fileOffset, source.Slice(inPos, bytesToWrite), options);
|
||||
rc = file.Write(fileOffset, source.Slice(inPos, bytesToWrite), option);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
outPos += bytesToWrite;
|
||||
@ -99,7 +100,7 @@ namespace LibHac.FsSystem
|
||||
remaining -= bytesToWrite;
|
||||
}
|
||||
|
||||
if (options.HasFlag(WriteOptionFlag.Flush))
|
||||
if (option.HasFlushFlag())
|
||||
{
|
||||
return Flush();
|
||||
}
|
||||
@ -133,6 +134,11 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected override Result DoSetSize(long size)
|
||||
{
|
||||
Result rc = GetSize(out long currentSize);
|
||||
|
@ -22,7 +22,7 @@ namespace LibHac.FsSystem
|
||||
/// Each sub-file except the final one must have the size <see cref="SubFileSize"/> that was specified
|
||||
/// at the creation of the <see cref="ConcatenationFileSystem"/>.
|
||||
/// </remarks>
|
||||
public class ConcatenationFileSystem : FileSystemBase
|
||||
public class ConcatenationFileSystem : IFileSystem
|
||||
{
|
||||
private const long DefaultSubFileSize = 0xFFFF0000; // Hard-coded value used by FS
|
||||
private IAttributeFileSystem BaseFileSystem { get; }
|
||||
@ -96,7 +96,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.SetFileAttributes(path, NxFileAttributes.Archive);
|
||||
}
|
||||
|
||||
protected override Result CreateDirectoryImpl(U8Span path)
|
||||
protected override Result DoCreateDirectory(U8Span path)
|
||||
{
|
||||
var parent = new U8Span(PathTools.GetParentDirectory(path));
|
||||
|
||||
@ -109,7 +109,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.CreateDirectory(path);
|
||||
}
|
||||
|
||||
protected override Result CreateFileImpl(U8Span path, long size, CreateFileOptions options)
|
||||
protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions options)
|
||||
{
|
||||
CreateFileOptions newOptions = options & ~CreateFileOptions.CreateConcatenationFile;
|
||||
|
||||
@ -156,7 +156,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DeleteDirectoryImpl(U8Span path)
|
||||
protected override Result DoDeleteDirectory(U8Span path)
|
||||
{
|
||||
if (IsConcatenationFile(path))
|
||||
{
|
||||
@ -166,21 +166,21 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.DeleteDirectory(path);
|
||||
}
|
||||
|
||||
protected override Result DeleteDirectoryRecursivelyImpl(U8Span path)
|
||||
protected override Result DoDeleteDirectoryRecursively(U8Span path)
|
||||
{
|
||||
if (IsConcatenationFile(path)) return ResultFs.PathNotFound.Log();
|
||||
|
||||
return BaseFileSystem.DeleteDirectoryRecursively(path);
|
||||
}
|
||||
|
||||
protected override Result CleanDirectoryRecursivelyImpl(U8Span path)
|
||||
protected override Result DoCleanDirectoryRecursively(U8Span path)
|
||||
{
|
||||
if (IsConcatenationFile(path)) return ResultFs.PathNotFound.Log();
|
||||
|
||||
return BaseFileSystem.CleanDirectoryRecursively(path);
|
||||
}
|
||||
|
||||
protected override Result DeleteFileImpl(U8Span path)
|
||||
protected override Result DoDeleteFile(U8Span path)
|
||||
{
|
||||
if (!IsConcatenationFile(path))
|
||||
{
|
||||
@ -205,7 +205,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.DeleteDirectory(path);
|
||||
}
|
||||
|
||||
protected override Result OpenDirectoryImpl(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
{
|
||||
directory = default;
|
||||
|
||||
@ -221,7 +221,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result OpenFileImpl(out IFile file, U8Span path, OpenMode mode)
|
||||
protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
|
||||
{
|
||||
file = default;
|
||||
|
||||
@ -253,7 +253,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result RenameDirectoryImpl(U8Span oldPath, U8Span newPath)
|
||||
protected override Result DoRenameDirectory(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
if (IsConcatenationFile(oldPath))
|
||||
{
|
||||
@ -263,7 +263,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.RenameDirectory(oldPath, newPath);
|
||||
}
|
||||
|
||||
protected override Result RenameFileImpl(U8Span oldPath, U8Span newPath)
|
||||
protected override Result DoRenameFile(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
if (IsConcatenationFile(oldPath))
|
||||
{
|
||||
@ -275,7 +275,7 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, U8Span path)
|
||||
protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path)
|
||||
{
|
||||
if (IsConcatenationFile(path))
|
||||
{
|
||||
@ -286,37 +286,37 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.GetEntryType(out entryType, path);
|
||||
}
|
||||
|
||||
protected override Result GetFreeSpaceSizeImpl(out long freeSpace, U8Span path)
|
||||
protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path)
|
||||
{
|
||||
return BaseFileSystem.GetFreeSpaceSize(out freeSpace, path);
|
||||
}
|
||||
|
||||
protected override Result GetTotalSpaceSizeImpl(out long totalSpace, U8Span path)
|
||||
protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path)
|
||||
{
|
||||
return BaseFileSystem.GetTotalSpaceSize(out totalSpace, path);
|
||||
}
|
||||
|
||||
protected override Result GetFileTimeStampRawImpl(out FileTimeStampRaw timeStamp, U8Span path)
|
||||
protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path)
|
||||
{
|
||||
return BaseFileSystem.GetFileTimeStampRaw(out timeStamp, path);
|
||||
}
|
||||
|
||||
protected override Result CommitImpl()
|
||||
protected override Result DoCommit()
|
||||
{
|
||||
return BaseFileSystem.Commit();
|
||||
}
|
||||
|
||||
protected override Result CommitProvisionallyImpl(long commitCount)
|
||||
protected override Result DoCommitProvisionally(long counter)
|
||||
{
|
||||
return BaseFileSystem.CommitProvisionally(commitCount);
|
||||
return BaseFileSystem.CommitProvisionally(counter);
|
||||
}
|
||||
|
||||
protected override Result FlushImpl()
|
||||
protected override Result DoFlush()
|
||||
{
|
||||
return BaseFileSystem.Flush();
|
||||
}
|
||||
|
||||
protected override Result QueryEntryImpl(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId,
|
||||
protected override Result DoQueryEntry(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId,
|
||||
U8Span path)
|
||||
{
|
||||
if (queryId != QueryId.MakeConcatFile) return ResultFs.UnsupportedOperationInConcatFsQueryEntry.Log();
|
||||
|
@ -3,7 +3,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem
|
||||
{
|
||||
public class DirectorySaveDataFile : FileBase
|
||||
public class DirectorySaveDataFile : IFile
|
||||
{
|
||||
private IFile BaseFile { get; }
|
||||
private DirectorySaveDataFileSystem ParentFs { get; }
|
||||
@ -16,14 +16,15 @@ namespace LibHac.FsSystem
|
||||
Mode = mode;
|
||||
}
|
||||
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination, ReadOptionFlag options)
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination,
|
||||
in ReadOption option)
|
||||
{
|
||||
return BaseFile.Read(out bytesRead, offset, destination, options);
|
||||
return BaseFile.Read(out bytesRead, offset, destination, in option);
|
||||
}
|
||||
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, WriteOptionFlag options)
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
return BaseFile.Write(offset, source, options);
|
||||
return BaseFile.Write(offset, source, in option);
|
||||
}
|
||||
|
||||
protected override Result DoFlush()
|
||||
@ -41,6 +42,11 @@ namespace LibHac.FsSystem
|
||||
return BaseFile.SetSize(size);
|
||||
}
|
||||
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
return BaseFile.OperateRange(outBuffer, operationId, offset, size, inBuffer);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (Mode.HasFlag(OpenMode.Write))
|
||||
|
@ -12,7 +12,7 @@ namespace LibHac.FsSystem
|
||||
/// underlying <see cref="IFileSystem"/> is atomic.
|
||||
/// This class is based on nn::fssystem::DirectorySaveDataFileSystem in SDK 10.4.0 used in FS 10.0.0
|
||||
/// </remarks>
|
||||
public class DirectorySaveDataFileSystem : FileSystemBase
|
||||
public class DirectorySaveDataFileSystem : IFileSystem
|
||||
{
|
||||
private const int IdealWorkBufferSize = 0x100000; // 1 MiB
|
||||
|
||||
@ -97,7 +97,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFs.RenameDirectory(SynchronizingDirectoryPath, CommittedDirectoryPath);
|
||||
}
|
||||
|
||||
protected override Result CreateDirectoryImpl(U8Span path)
|
||||
protected override Result DoCreateDirectory(U8Span path)
|
||||
{
|
||||
FsPath fullPath;
|
||||
unsafe { _ = &fullPath; } // workaround for CS0165
|
||||
@ -111,7 +111,7 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result CreateFileImpl(U8Span path, long size, CreateFileOptions options)
|
||||
protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions options)
|
||||
{
|
||||
FsPath fullPath;
|
||||
unsafe { _ = &fullPath; } // workaround for CS0165
|
||||
@ -125,7 +125,7 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result DeleteDirectoryImpl(U8Span path)
|
||||
protected override Result DoDeleteDirectory(U8Span path)
|
||||
{
|
||||
FsPath fullPath;
|
||||
unsafe { _ = &fullPath; } // workaround for CS0165
|
||||
@ -139,7 +139,7 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result DeleteDirectoryRecursivelyImpl(U8Span path)
|
||||
protected override Result DoDeleteDirectoryRecursively(U8Span path)
|
||||
{
|
||||
FsPath fullPath;
|
||||
unsafe { _ = &fullPath; } // workaround for CS0165
|
||||
@ -153,7 +153,7 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result CleanDirectoryRecursivelyImpl(U8Span path)
|
||||
protected override Result DoCleanDirectoryRecursively(U8Span path)
|
||||
{
|
||||
FsPath fullPath;
|
||||
unsafe { _ = &fullPath; } // workaround for CS0165
|
||||
@ -167,7 +167,7 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result DeleteFileImpl(U8Span path)
|
||||
protected override Result DoDeleteFile(U8Span path)
|
||||
{
|
||||
FsPath fullPath;
|
||||
unsafe { _ = &fullPath; } // workaround for CS0165
|
||||
@ -181,7 +181,7 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result OpenDirectoryImpl(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
{
|
||||
FsPath fullPath;
|
||||
unsafe { _ = &fullPath; } // workaround for CS0165
|
||||
@ -199,7 +199,7 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result OpenFileImpl(out IFile file, U8Span path, OpenMode mode)
|
||||
protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
|
||||
{
|
||||
file = default;
|
||||
|
||||
@ -225,7 +225,7 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result RenameDirectoryImpl(U8Span oldPath, U8Span newPath)
|
||||
protected override Result DoRenameDirectory(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
FsPath fullCurrentPath;
|
||||
FsPath fullNewPath;
|
||||
@ -244,7 +244,7 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result RenameFileImpl(U8Span oldPath, U8Span newPath)
|
||||
protected override Result DoRenameFile(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
FsPath fullCurrentPath;
|
||||
FsPath fullNewPath;
|
||||
@ -263,7 +263,7 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, U8Span path)
|
||||
protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path)
|
||||
{
|
||||
FsPath fullPath;
|
||||
unsafe { _ = &fullPath; } // workaround for CS0165
|
||||
@ -281,7 +281,7 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result CommitImpl()
|
||||
protected override Result DoCommit()
|
||||
{
|
||||
lock (Locker)
|
||||
{
|
||||
@ -315,7 +315,7 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result CommitProvisionallyImpl(long commitCount)
|
||||
protected override Result DoCommitProvisionally(long counter)
|
||||
{
|
||||
if (!CanCommitProvisionally)
|
||||
return ResultFs.UnsupportedOperationInDirectorySaveDataFileSystem.Log();
|
||||
@ -323,7 +323,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result RollbackImpl()
|
||||
protected override Result DoRollback()
|
||||
{
|
||||
// No old data is kept for temporary save data, so there's nothing to rollback to
|
||||
if (!IsPersistentSaveData)
|
||||
@ -332,7 +332,7 @@ namespace LibHac.FsSystem
|
||||
return Initialize(IsPersistentSaveData, CanCommitProvisionally);
|
||||
}
|
||||
|
||||
protected override Result GetFreeSpaceSizeImpl(out long freeSpace, U8Span path)
|
||||
protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path)
|
||||
{
|
||||
freeSpace = default;
|
||||
|
||||
@ -348,7 +348,7 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result GetTotalSpaceSizeImpl(out long totalSpace, U8Span path)
|
||||
protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path)
|
||||
{
|
||||
totalSpace = default;
|
||||
|
||||
|
@ -61,10 +61,10 @@ namespace LibHac.FsSystem
|
||||
|
||||
while (offset < fileSize)
|
||||
{
|
||||
rc = srcFile.Read(out long bytesRead, offset, copyBuffer, ReadOptionFlag.None);
|
||||
rc = srcFile.Read(out long bytesRead, offset, copyBuffer, ReadOption.None);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
rc = dstFile.Write(offset, copyBuffer.Slice(0, (int)bytesRead), WriteOptionFlag.None);
|
||||
rc = dstFile.Write(offset, copyBuffer.Slice(0, (int)bytesRead), WriteOption.None);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
offset += bytesRead;
|
||||
|
@ -224,12 +224,12 @@ namespace LibHac.FsSystem
|
||||
|
||||
public static Result Read(this IFile file, out long bytesRead, long offset, Span<byte> destination)
|
||||
{
|
||||
return file.Read(out bytesRead, offset, destination, ReadOptionFlag.None);
|
||||
return file.Read(out bytesRead, offset, destination, ReadOption.None);
|
||||
}
|
||||
|
||||
public static Result Write(this IFile file, long offset, ReadOnlySpan<byte> source)
|
||||
{
|
||||
return file.Write(offset, source, WriteOptionFlag.None);
|
||||
return file.Write(offset, source, WriteOption.None);
|
||||
}
|
||||
|
||||
public static bool DirectoryExists(this IFileSystem fs, string path)
|
||||
|
@ -5,7 +5,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem
|
||||
{
|
||||
public class LayeredFileSystem : FileSystemBase
|
||||
public class LayeredFileSystem : IFileSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// List of source <see cref="IFileSystem"/>s.
|
||||
@ -35,7 +35,7 @@ namespace LibHac.FsSystem
|
||||
Sources.AddRange(sourceFileSystems);
|
||||
}
|
||||
|
||||
protected override Result OpenDirectoryImpl(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
{
|
||||
directory = default;
|
||||
|
||||
@ -106,7 +106,7 @@ namespace LibHac.FsSystem
|
||||
return ResultFs.PathNotFound.Log();
|
||||
}
|
||||
|
||||
protected override Result OpenFileImpl(out IFile file, U8Span path, OpenMode mode)
|
||||
protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
|
||||
{
|
||||
file = default;
|
||||
|
||||
@ -135,7 +135,7 @@ namespace LibHac.FsSystem
|
||||
return ResultFs.PathNotFound.Log();
|
||||
}
|
||||
|
||||
protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, U8Span path)
|
||||
protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path)
|
||||
{
|
||||
foreach (IFileSystem fs in Sources)
|
||||
{
|
||||
@ -152,7 +152,7 @@ namespace LibHac.FsSystem
|
||||
return ResultFs.PathNotFound.Log();
|
||||
}
|
||||
|
||||
protected override Result GetFileTimeStampRawImpl(out FileTimeStampRaw timeStamp, U8Span path)
|
||||
protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path)
|
||||
{
|
||||
foreach (IFileSystem fs in Sources)
|
||||
{
|
||||
@ -168,7 +168,7 @@ namespace LibHac.FsSystem
|
||||
return ResultFs.PathNotFound.Log();
|
||||
}
|
||||
|
||||
protected override Result QueryEntryImpl(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId,
|
||||
protected override Result DoQueryEntry(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId,
|
||||
U8Span path)
|
||||
{
|
||||
foreach (IFileSystem fs in Sources)
|
||||
@ -184,19 +184,19 @@ namespace LibHac.FsSystem
|
||||
return ResultFs.PathNotFound.Log();
|
||||
}
|
||||
|
||||
protected override Result CommitImpl()
|
||||
protected override Result DoCommit()
|
||||
{
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result CreateDirectoryImpl(U8Span path) => ResultFs.UnsupportedOperation.Log();
|
||||
protected override Result CreateFileImpl(U8Span path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperation.Log();
|
||||
protected override Result DeleteDirectoryImpl(U8Span path) => ResultFs.UnsupportedOperation.Log();
|
||||
protected override Result DeleteDirectoryRecursivelyImpl(U8Span path) => ResultFs.UnsupportedOperation.Log();
|
||||
protected override Result CleanDirectoryRecursivelyImpl(U8Span path) => ResultFs.UnsupportedOperation.Log();
|
||||
protected override Result DeleteFileImpl(U8Span path) => ResultFs.UnsupportedOperation.Log();
|
||||
protected override Result RenameDirectoryImpl(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperation.Log();
|
||||
protected override Result RenameFileImpl(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperation.Log();
|
||||
protected override Result DoCreateDirectory(U8Span path) => ResultFs.UnsupportedOperation.Log();
|
||||
protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperation.Log();
|
||||
protected override Result DoDeleteDirectory(U8Span path) => ResultFs.UnsupportedOperation.Log();
|
||||
protected override Result DoDeleteDirectoryRecursively(U8Span path) => ResultFs.UnsupportedOperation.Log();
|
||||
protected override Result DoCleanDirectoryRecursively(U8Span path) => ResultFs.UnsupportedOperation.Log();
|
||||
protected override Result DoDeleteFile(U8Span path) => ResultFs.UnsupportedOperation.Log();
|
||||
protected override Result DoRenameDirectory(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperation.Log();
|
||||
protected override Result DoRenameFile(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperation.Log();
|
||||
|
||||
private class MergedDirectory : IDirectory
|
||||
{
|
||||
@ -230,7 +230,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public Result Read(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
protected override Result DoRead(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
{
|
||||
entriesRead = 0;
|
||||
int entryIndex = 0;
|
||||
@ -255,7 +255,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public Result GetEntryCount(out long entryCount)
|
||||
protected override Result DoGetEntryCount(out long entryCount)
|
||||
{
|
||||
entryCount = 0;
|
||||
long totalEntryCount = 0;
|
||||
|
@ -12,7 +12,7 @@ namespace LibHac.FsSystem
|
||||
private OpenDirectoryMode Mode { get; }
|
||||
private DirectoryInfo DirInfo { get; }
|
||||
private IEnumerator<FileSystemInfo> EntryEnumerator { get; }
|
||||
|
||||
|
||||
public LocalDirectory(IEnumerator<FileSystemInfo> entryEnumerator, DirectoryInfo dirInfo,
|
||||
OpenDirectoryMode mode)
|
||||
{
|
||||
@ -21,7 +21,7 @@ namespace LibHac.FsSystem
|
||||
Mode = mode;
|
||||
}
|
||||
|
||||
public Result Read(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
protected override Result DoRead(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
@ -52,7 +52,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public Result GetEntryCount(out long entryCount)
|
||||
protected override Result DoGetEntryCount(out long entryCount)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
|
@ -5,7 +5,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem
|
||||
{
|
||||
public class LocalFile : FileBase
|
||||
public class LocalFile : IFile
|
||||
{
|
||||
private FileStream Stream { get; }
|
||||
private StreamFile File { get; }
|
||||
@ -27,22 +27,23 @@ namespace LibHac.FsSystem
|
||||
File = new StreamFile(Stream, mode);
|
||||
}
|
||||
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination, ReadOptionFlag options)
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination,
|
||||
in ReadOption option)
|
||||
{
|
||||
bytesRead = 0;
|
||||
|
||||
Result rc = ValidateReadParams(out long toRead, offset, destination.Length, Mode);
|
||||
Result rc = DryRead(out long toRead, offset, destination.Length, in option, Mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
return File.Read(out bytesRead, offset, destination.Slice(0, (int)toRead), options);
|
||||
return File.Read(out bytesRead, offset, destination.Slice(0, (int)toRead), option);
|
||||
}
|
||||
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, WriteOptionFlag options)
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
Result rc = ValidateWriteParams(offset, source.Length, Mode, out _);
|
||||
Result rc = DryWrite(out _, offset, source.Length, in option, Mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
return File.Write(offset, source, options);
|
||||
return File.Write(offset, source, option);
|
||||
}
|
||||
|
||||
protected override Result DoFlush()
|
||||
@ -70,6 +71,11 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected override Result DoSetSize(long size)
|
||||
{
|
||||
try
|
||||
|
@ -7,7 +7,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem
|
||||
{
|
||||
public class LocalFileSystem : AttributeFileSystemBase
|
||||
public class LocalFileSystem : IAttributeFileSystem
|
||||
{
|
||||
private string BasePath { get; }
|
||||
|
||||
@ -66,7 +66,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result GetFileAttributesImpl(out NxFileAttributes attributes, U8Span path)
|
||||
protected override Result DoGetFileAttributes(out NxFileAttributes attributes, U8Span path)
|
||||
{
|
||||
attributes = default;
|
||||
|
||||
@ -86,7 +86,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result SetFileAttributesImpl(U8Span path, NxFileAttributes attributes)
|
||||
protected override Result DoSetFileAttributes(U8Span path, NxFileAttributes attributes)
|
||||
{
|
||||
Result rc = ResolveFullPath(out string fullPath, path);
|
||||
if (rc.IsFailure()) return rc;
|
||||
@ -114,7 +114,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result GetFileSizeImpl(out long fileSize, U8Span path)
|
||||
protected override Result DoGetFileSize(out long fileSize, U8Span path)
|
||||
{
|
||||
fileSize = default;
|
||||
|
||||
@ -127,12 +127,12 @@ namespace LibHac.FsSystem
|
||||
return GetSizeInternal(out fileSize, info);
|
||||
}
|
||||
|
||||
protected override Result CreateDirectoryImpl(U8Span path)
|
||||
protected override Result DoCreateDirectory(U8Span path)
|
||||
{
|
||||
return CreateDirectory(path, NxFileAttributes.None);
|
||||
return DoCreateDirectory(path, NxFileAttributes.None);
|
||||
}
|
||||
|
||||
protected override Result CreateDirectoryImpl(U8Span path, NxFileAttributes archiveAttribute)
|
||||
protected override Result DoCreateDirectory(U8Span path, NxFileAttributes archiveAttribute)
|
||||
{
|
||||
Result rc = ResolveFullPath(out string fullPath, path);
|
||||
if (rc.IsFailure()) return rc;
|
||||
@ -153,7 +153,7 @@ namespace LibHac.FsSystem
|
||||
return CreateDirInternal(dir, archiveAttribute);
|
||||
}
|
||||
|
||||
protected override Result CreateFileImpl(U8Span path, long size, CreateFileOptions options)
|
||||
protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions options)
|
||||
{
|
||||
Result rc = ResolveFullPath(out string fullPath, path);
|
||||
if (rc.IsFailure()) return rc;
|
||||
@ -181,7 +181,7 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result DeleteDirectoryImpl(U8Span path)
|
||||
protected override Result DoDeleteDirectory(U8Span path)
|
||||
{
|
||||
Result rc = ResolveFullPath(out string fullPath, path);
|
||||
if (rc.IsFailure()) return rc;
|
||||
@ -192,7 +192,7 @@ namespace LibHac.FsSystem
|
||||
return DeleteDirectoryInternal(dir, false);
|
||||
}
|
||||
|
||||
protected override Result DeleteDirectoryRecursivelyImpl(U8Span path)
|
||||
protected override Result DoDeleteDirectoryRecursively(U8Span path)
|
||||
{
|
||||
Result rc = ResolveFullPath(out string fullPath, path);
|
||||
if (rc.IsFailure()) return rc;
|
||||
@ -203,7 +203,7 @@ namespace LibHac.FsSystem
|
||||
return DeleteDirectoryInternal(dir, true);
|
||||
}
|
||||
|
||||
protected override Result CleanDirectoryRecursivelyImpl(U8Span path)
|
||||
protected override Result DoCleanDirectoryRecursively(U8Span path)
|
||||
{
|
||||
Result rc = ResolveFullPath(out string fullPath, path);
|
||||
if (rc.IsFailure()) return rc;
|
||||
@ -229,7 +229,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DeleteFileImpl(U8Span path)
|
||||
protected override Result DoDeleteFile(U8Span path)
|
||||
{
|
||||
Result rc = ResolveFullPath(out string fullPath, path);
|
||||
if (rc.IsFailure()) return rc;
|
||||
@ -240,7 +240,7 @@ namespace LibHac.FsSystem
|
||||
return DeleteFileInternal(file);
|
||||
}
|
||||
|
||||
protected override Result OpenDirectoryImpl(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
{
|
||||
directory = default;
|
||||
Result rc = ResolveFullPath(out string fullPath, path);
|
||||
@ -267,7 +267,7 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result OpenFileImpl(out IFile file, U8Span path, OpenMode mode)
|
||||
protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
|
||||
{
|
||||
file = default;
|
||||
|
||||
@ -289,7 +289,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result RenameDirectoryImpl(U8Span oldPath, U8Span newPath)
|
||||
protected override Result DoRenameDirectory(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
Result rc = CheckSubPath(oldPath, newPath);
|
||||
if (rc.IsFailure()) return rc;
|
||||
@ -312,7 +312,7 @@ namespace LibHac.FsSystem
|
||||
return RenameDirInternal(currentDirInfo, newDirInfo);
|
||||
}
|
||||
|
||||
protected override Result RenameFileImpl(U8Span oldPath, U8Span newPath)
|
||||
protected override Result DoRenameFile(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
Result rc = ResolveFullPath(out string fullCurrentPath, oldPath);
|
||||
if (rc.IsFailure()) return rc;
|
||||
@ -332,7 +332,7 @@ namespace LibHac.FsSystem
|
||||
return RenameFileInternal(currentFileInfo, newFileInfo);
|
||||
}
|
||||
|
||||
protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, U8Span path)
|
||||
protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path)
|
||||
{
|
||||
entryType = default;
|
||||
|
||||
@ -361,7 +361,7 @@ namespace LibHac.FsSystem
|
||||
return ResultFs.PathNotFound.Log();
|
||||
}
|
||||
|
||||
protected override Result GetFileTimeStampRawImpl(out FileTimeStampRaw timeStamp, U8Span path)
|
||||
protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path)
|
||||
{
|
||||
timeStamp = default;
|
||||
|
||||
@ -380,24 +380,24 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result GetFreeSpaceSizeImpl(out long freeSpace, U8Span path)
|
||||
protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path)
|
||||
{
|
||||
freeSpace = new DriveInfo(BasePath).AvailableFreeSpace;
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result GetTotalSpaceSizeImpl(out long totalSpace, U8Span path)
|
||||
protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path)
|
||||
{
|
||||
totalSpace = new DriveInfo(BasePath).TotalSize;
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result CommitImpl()
|
||||
protected override Result DoCommit()
|
||||
{
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result QueryEntryImpl(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId,
|
||||
protected override Result DoQueryEntry(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId,
|
||||
U8Span path)
|
||||
{
|
||||
return ResultFs.UnsupportedOperation.Log();
|
||||
|
@ -3,7 +3,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem
|
||||
{
|
||||
public class NullFile : FileBase
|
||||
public class NullFile : IFile
|
||||
{
|
||||
private OpenMode Mode { get; }
|
||||
|
||||
@ -16,11 +16,12 @@ namespace LibHac.FsSystem
|
||||
|
||||
private long Length { get; }
|
||||
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination, ReadOptionFlag options)
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination,
|
||||
in ReadOption option)
|
||||
{
|
||||
bytesRead = 0;
|
||||
|
||||
Result rc = ValidateReadParams(out long toRead, offset, destination.Length, Mode);
|
||||
Result rc = DryRead(out long toRead, offset, destination.Length, in option, Mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
destination.Slice(0, (int)toRead).Clear();
|
||||
@ -29,7 +30,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, WriteOptionFlag options)
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
return Result.Success;
|
||||
}
|
||||
@ -45,6 +46,12 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DoSetSize(long size)
|
||||
{
|
||||
return ResultFs.UnsupportedOperation.Log();
|
||||
|
@ -24,7 +24,7 @@ namespace LibHac.FsSystem
|
||||
CurrentIndex = 0;
|
||||
}
|
||||
|
||||
public Result Read(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
protected override Result DoRead(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
{
|
||||
if (!Mode.HasFlag(OpenDirectoryMode.File))
|
||||
{
|
||||
@ -55,7 +55,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public Result GetEntryCount(out long entryCount)
|
||||
protected override Result DoGetEntryCount(out long entryCount)
|
||||
{
|
||||
int count = 0;
|
||||
|
||||
|
@ -3,7 +3,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem
|
||||
{
|
||||
public class PartitionFile : FileBase
|
||||
public class PartitionFile : IFile
|
||||
{
|
||||
private IStorage BaseStorage { get; }
|
||||
private long Offset { get; }
|
||||
@ -18,11 +18,12 @@ namespace LibHac.FsSystem
|
||||
Size = size;
|
||||
}
|
||||
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination, ReadOptionFlag options)
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination,
|
||||
in ReadOption option)
|
||||
{
|
||||
bytesRead = 0;
|
||||
|
||||
Result rc = ValidateReadParams(out long toRead, offset, destination.Length, Mode);
|
||||
Result rc = DryRead(out long toRead, offset, destination.Length, in option, Mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
long storageOffset = Offset + offset;
|
||||
@ -32,9 +33,9 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, WriteOptionFlag options)
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
Result rc = ValidateWriteParams(offset, source.Length, Mode, out bool isResizeNeeded);
|
||||
Result rc = DryWrite(out bool isResizeNeeded, offset, source.Length, in option, Mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
if (isResizeNeeded) return ResultFs.UnsupportedOperationInPartitionFileSetSize.Log();
|
||||
@ -45,7 +46,7 @@ namespace LibHac.FsSystem
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
// N doesn't flush if the flag is set
|
||||
if (options.HasFlag(WriteOptionFlag.Flush))
|
||||
if (option.HasFlushFlag())
|
||||
{
|
||||
return BaseStorage.Flush();
|
||||
}
|
||||
@ -69,6 +70,12 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected override Result DoSetSize(long size)
|
||||
{
|
||||
if (!Mode.HasFlag(OpenMode.Write))
|
||||
|
@ -9,7 +9,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem
|
||||
{
|
||||
public class PartitionFileSystem : FileSystemBase
|
||||
public class PartitionFileSystem : IFileSystem
|
||||
{
|
||||
// todo Re-add way of checking a file hash
|
||||
public PartitionFileSystemHeader Header { get; }
|
||||
@ -32,13 +32,13 @@ namespace LibHac.FsSystem
|
||||
BaseStorage = storage;
|
||||
}
|
||||
|
||||
protected override Result OpenDirectoryImpl(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
{
|
||||
directory = new PartitionDirectory(this, path.ToString(), mode);
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result OpenFileImpl(out IFile file, U8Span path, OpenMode mode)
|
||||
protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
|
||||
{
|
||||
path = PathTools.Normalize(path.ToString()).TrimStart('/').ToU8Span();
|
||||
|
||||
@ -56,7 +56,7 @@ namespace LibHac.FsSystem
|
||||
return new PartitionFile(BaseStorage, HeaderSize + entry.Offset, entry.Size, mode);
|
||||
}
|
||||
|
||||
protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, U8Span path)
|
||||
protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path)
|
||||
{
|
||||
entryType = default;
|
||||
|
||||
@ -75,16 +75,16 @@ namespace LibHac.FsSystem
|
||||
return ResultFs.PathNotFound.Log();
|
||||
}
|
||||
|
||||
protected override Result CreateDirectoryImpl(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result CreateFileImpl(U8Span path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DeleteDirectoryImpl(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DeleteDirectoryRecursivelyImpl(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result CleanDirectoryRecursivelyImpl(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DeleteFileImpl(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result RenameDirectoryImpl(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result RenameFileImpl(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DoCreateDirectory(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DoDeleteDirectory(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DoDeleteDirectoryRecursively(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DoCleanDirectoryRecursively(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DoDeleteFile(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DoRenameDirectory(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DoRenameFile(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
|
||||
protected override Result CommitImpl()
|
||||
protected override Result DoCommit()
|
||||
{
|
||||
return Result.Success;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ using LibHac.FsSystem.Detail;
|
||||
|
||||
namespace LibHac.FsSystem
|
||||
{
|
||||
public class PartitionFileSystemCore<T> : FileSystemBase where T : unmanaged, IPartitionFileSystemEntry
|
||||
public class PartitionFileSystemCore<T> : IFileSystem where T : unmanaged, IPartitionFileSystemEntry
|
||||
{
|
||||
private IStorage BaseStorage { get; set; }
|
||||
private PartitionFileSystemMetaCore<T> MetaData { get; set; }
|
||||
@ -31,7 +31,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result OpenDirectoryImpl(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
{
|
||||
directory = default;
|
||||
|
||||
@ -48,7 +48,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result OpenFileImpl(out IFile file, U8Span path, OpenMode mode)
|
||||
protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
|
||||
{
|
||||
file = default;
|
||||
|
||||
@ -68,7 +68,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, U8Span path)
|
||||
protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path)
|
||||
{
|
||||
entryType = default;
|
||||
|
||||
@ -95,22 +95,22 @@ namespace LibHac.FsSystem
|
||||
return ResultFs.PathNotFound.Log();
|
||||
}
|
||||
|
||||
protected override Result CommitImpl()
|
||||
protected override Result DoCommit()
|
||||
{
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result CreateDirectoryImpl(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result CreateFileImpl(U8Span path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DeleteDirectoryImpl(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DeleteDirectoryRecursivelyImpl(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result CleanDirectoryRecursivelyImpl(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DeleteFileImpl(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result RenameDirectoryImpl(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result RenameFileImpl(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result CommitProvisionallyImpl(long commitCount) => ResultFs.UnsupportedOperationInPartitionFileSystem.Log();
|
||||
protected override Result DoCreateDirectory(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DoDeleteDirectory(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DoDeleteDirectoryRecursively(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DoCleanDirectoryRecursively(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DoDeleteFile(U8Span path) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DoRenameDirectory(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DoRenameFile(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperationModifyPartitionFileSystem.Log();
|
||||
protected override Result DoCommitProvisionally(long counter) => ResultFs.UnsupportedOperationInPartitionFileSystem.Log();
|
||||
|
||||
private class PartitionFile : FileBase
|
||||
private class PartitionFile : IFile
|
||||
{
|
||||
private PartitionFileSystemCore<T> ParentFs { get; }
|
||||
private OpenMode Mode { get; }
|
||||
@ -123,11 +123,12 @@ namespace LibHac.FsSystem
|
||||
Mode = mode;
|
||||
}
|
||||
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination, ReadOptionFlag options)
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination,
|
||||
in ReadOption option)
|
||||
{
|
||||
bytesRead = default;
|
||||
|
||||
Result rc = ValidateReadParams(out long bytesToRead, offset, destination.Length, Mode);
|
||||
Result rc = DryRead(out long bytesToRead, offset, destination.Length, in option, Mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
bool hashNeeded = false;
|
||||
@ -240,9 +241,9 @@ namespace LibHac.FsSystem
|
||||
return rc;
|
||||
}
|
||||
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, WriteOptionFlag options)
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
Result rc = ValidateWriteParams(offset, source.Length, Mode, out bool isResizeNeeded);
|
||||
Result rc = DryWrite(out bool isResizeNeeded, offset, source.Length, in option, Mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
if (isResizeNeeded)
|
||||
@ -327,7 +328,7 @@ namespace LibHac.FsSystem
|
||||
Mode = mode;
|
||||
}
|
||||
|
||||
public Result Read(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
protected override Result DoRead(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
{
|
||||
if (Mode.HasFlag(OpenDirectoryMode.File))
|
||||
{
|
||||
@ -356,7 +357,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
public Result GetEntryCount(out long entryCount)
|
||||
protected override Result DoGetEntryCount(out long entryCount)
|
||||
{
|
||||
if (Mode.HasFlag(OpenDirectoryMode.File))
|
||||
{
|
||||
|
@ -3,7 +3,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem
|
||||
{
|
||||
public class ReadOnlyFile : FileBase
|
||||
public class ReadOnlyFile : IFile
|
||||
{
|
||||
private IFile BaseFile { get; }
|
||||
|
||||
@ -12,9 +12,10 @@ namespace LibHac.FsSystem
|
||||
BaseFile = baseFile;
|
||||
}
|
||||
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination, ReadOptionFlag options)
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination,
|
||||
in ReadOption option)
|
||||
{
|
||||
return BaseFile.Read(out bytesRead, offset, destination, options);
|
||||
return BaseFile.Read(out bytesRead, offset, destination, option);
|
||||
}
|
||||
|
||||
protected override Result DoGetSize(out long size)
|
||||
@ -27,7 +28,7 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, WriteOptionFlag options)
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
return ResultFs.InvalidOpenModeForWrite.Log();
|
||||
}
|
||||
@ -36,5 +37,17 @@ namespace LibHac.FsSystem
|
||||
{
|
||||
return ResultFs.InvalidOpenModeForWrite.Log();
|
||||
}
|
||||
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
switch (operationId)
|
||||
{
|
||||
case OperationId.InvalidateCache:
|
||||
case OperationId.QueryRange:
|
||||
return BaseFile.OperateRange(outBuffer, operationId, offset, size, inBuffer);
|
||||
default:
|
||||
return ResultFs.UnsupportedOperationInReadOnlyFile.Log();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem
|
||||
{
|
||||
public class ReadOnlyFileSystem : FileSystemBase
|
||||
public class ReadOnlyFileSystem : IFileSystem
|
||||
{
|
||||
private IFileSystem BaseFs { get; }
|
||||
|
||||
@ -12,12 +12,12 @@ namespace LibHac.FsSystem
|
||||
BaseFs = baseFileSystem;
|
||||
}
|
||||
|
||||
protected override Result OpenDirectoryImpl(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
{
|
||||
return BaseFs.OpenDirectory(out directory, path, mode);
|
||||
}
|
||||
|
||||
protected override Result OpenFileImpl(out IFile file, U8Span path, OpenMode mode)
|
||||
protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
|
||||
{
|
||||
file = default;
|
||||
|
||||
@ -28,12 +28,12 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, U8Span path)
|
||||
protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path)
|
||||
{
|
||||
return BaseFs.GetEntryType(out entryType, path);
|
||||
}
|
||||
|
||||
protected override Result GetFreeSpaceSizeImpl(out long freeSpace, U8Span path)
|
||||
protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path)
|
||||
{
|
||||
freeSpace = 0;
|
||||
return Result.Success;
|
||||
@ -42,7 +42,7 @@ namespace LibHac.FsSystem
|
||||
// return ResultFs.UnsupportedOperationReadOnlyFileSystemGetSpace.Log();
|
||||
}
|
||||
|
||||
protected override Result GetTotalSpaceSizeImpl(out long totalSpace, U8Span path)
|
||||
protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path)
|
||||
{
|
||||
return BaseFs.GetTotalSpaceSize(out totalSpace, path);
|
||||
|
||||
@ -50,7 +50,7 @@ namespace LibHac.FsSystem
|
||||
// return ResultFs.UnsupportedOperationReadOnlyFileSystemGetSpace.Log();
|
||||
}
|
||||
|
||||
protected override Result GetFileTimeStampRawImpl(out FileTimeStampRaw timeStamp, U8Span path)
|
||||
protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path)
|
||||
{
|
||||
return BaseFs.GetFileTimeStampRaw(out timeStamp, path);
|
||||
|
||||
@ -58,25 +58,25 @@ namespace LibHac.FsSystem
|
||||
// return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected override Result CommitImpl()
|
||||
protected override Result DoCommit()
|
||||
{
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result CreateDirectoryImpl(U8Span path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log();
|
||||
protected override Result DoCreateDirectory(U8Span path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log();
|
||||
|
||||
protected override Result CreateFileImpl(U8Span path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log();
|
||||
protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log();
|
||||
|
||||
protected override Result DeleteDirectoryImpl(U8Span path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log();
|
||||
protected override Result DoDeleteDirectory(U8Span path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log();
|
||||
|
||||
protected override Result DeleteDirectoryRecursivelyImpl(U8Span path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log();
|
||||
protected override Result DoDeleteDirectoryRecursively(U8Span path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log();
|
||||
|
||||
protected override Result CleanDirectoryRecursivelyImpl(U8Span path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log();
|
||||
protected override Result DoCleanDirectoryRecursively(U8Span path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log();
|
||||
|
||||
protected override Result DeleteFileImpl(U8Span path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log();
|
||||
protected override Result DoDeleteFile(U8Span path) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log();
|
||||
|
||||
protected override Result RenameDirectoryImpl(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log();
|
||||
protected override Result DoRenameDirectory(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log();
|
||||
|
||||
protected override Result RenameFileImpl(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log();
|
||||
protected override Result DoRenameFile(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperationModifyReadOnlyFileSystem.Log();
|
||||
}
|
||||
}
|
||||
|
@ -22,12 +22,12 @@ namespace LibHac.FsSystem.RomFs
|
||||
Mode = mode;
|
||||
}
|
||||
|
||||
public Result Read(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
protected override Result DoRead(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
{
|
||||
return ReadImpl(out entriesRead, ref _currentPosition, entryBuffer);
|
||||
}
|
||||
|
||||
public Result GetEntryCount(out long entryCount)
|
||||
protected override Result DoGetEntryCount(out long entryCount)
|
||||
{
|
||||
FindPosition position = InitialPosition;
|
||||
|
||||
|
@ -3,7 +3,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem.RomFs
|
||||
{
|
||||
public class RomFsFile : FileBase
|
||||
public class RomFsFile : IFile
|
||||
{
|
||||
private IStorage BaseStorage { get; }
|
||||
private long Offset { get; }
|
||||
@ -16,11 +16,12 @@ namespace LibHac.FsSystem.RomFs
|
||||
Size = size;
|
||||
}
|
||||
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination, ReadOptionFlag options)
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination,
|
||||
in ReadOption option)
|
||||
{
|
||||
bytesRead = default;
|
||||
|
||||
Result rc = ValidateReadParams(out long toRead, offset, destination.Length, OpenMode.Read);
|
||||
Result rc = DryRead(out long toRead, offset, destination.Length, in option, OpenMode.Read);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
long storageOffset = Offset + offset;
|
||||
@ -33,7 +34,7 @@ namespace LibHac.FsSystem.RomFs
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, WriteOptionFlag options)
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
return ResultFs.UnsupportedOperationModifyRomFsFile.Log();
|
||||
}
|
||||
@ -53,5 +54,11 @@ namespace LibHac.FsSystem.RomFs
|
||||
{
|
||||
return ResultFs.UnsupportedOperationModifyRomFsFile.Log();
|
||||
}
|
||||
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem.RomFs
|
||||
{
|
||||
public class RomFsFileSystem : FileSystemBase
|
||||
public class RomFsFileSystem : IFileSystem
|
||||
{
|
||||
public RomfsHeader Header { get; }
|
||||
|
||||
@ -23,7 +23,7 @@ namespace LibHac.FsSystem.RomFs
|
||||
FileTable = new HierarchicalRomFileTable<RomFileInfo>(dirHashTable, dirEntryTable, fileHashTable, fileEntryTable);
|
||||
}
|
||||
|
||||
protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, U8Span path)
|
||||
protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path)
|
||||
{
|
||||
entryType = default;
|
||||
|
||||
@ -42,12 +42,12 @@ namespace LibHac.FsSystem.RomFs
|
||||
return ResultFs.PathNotFound.Log();
|
||||
}
|
||||
|
||||
protected override Result CommitImpl()
|
||||
protected override Result DoCommit()
|
||||
{
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result OpenDirectoryImpl(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
{
|
||||
directory = default;
|
||||
|
||||
@ -60,7 +60,7 @@ namespace LibHac.FsSystem.RomFs
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result OpenFileImpl(out IFile file, U8Span path, OpenMode mode)
|
||||
protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
|
||||
{
|
||||
file = default;
|
||||
|
||||
@ -84,23 +84,23 @@ namespace LibHac.FsSystem.RomFs
|
||||
return BaseStorage;
|
||||
}
|
||||
|
||||
protected override Result CreateDirectoryImpl(U8Span path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log();
|
||||
protected override Result CreateFileImpl(U8Span path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log();
|
||||
protected override Result DeleteDirectoryImpl(U8Span path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log();
|
||||
protected override Result DeleteDirectoryRecursivelyImpl(U8Span path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log();
|
||||
protected override Result CleanDirectoryRecursivelyImpl(U8Span path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log();
|
||||
protected override Result DeleteFileImpl(U8Span path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log();
|
||||
protected override Result RenameDirectoryImpl(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log();
|
||||
protected override Result RenameFileImpl(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log();
|
||||
protected override Result CommitProvisionallyImpl(long commitCount) => ResultFs.UnsupportedOperationInRomFsFileSystem.Log();
|
||||
protected override Result DoCreateDirectory(U8Span path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log();
|
||||
protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions options) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log();
|
||||
protected override Result DoDeleteDirectory(U8Span path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log();
|
||||
protected override Result DoDeleteDirectoryRecursively(U8Span path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log();
|
||||
protected override Result DoCleanDirectoryRecursively(U8Span path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log();
|
||||
protected override Result DoDeleteFile(U8Span path) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log();
|
||||
protected override Result DoRenameDirectory(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log();
|
||||
protected override Result DoRenameFile(U8Span oldPath, U8Span newPath) => ResultFs.UnsupportedOperationModifyRomFsFileSystem.Log();
|
||||
protected override Result DoCommitProvisionally(long counter) => ResultFs.UnsupportedOperationInRomFsFileSystem.Log();
|
||||
|
||||
protected override Result GetFreeSpaceSizeImpl(out long freeSpace, U8Span path)
|
||||
protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path)
|
||||
{
|
||||
freeSpace = default;
|
||||
return ResultFs.UnsupportedOperationRomFsFileSystemGetSpace.Log();
|
||||
}
|
||||
|
||||
protected override Result GetTotalSpaceSizeImpl(out long totalSpace, U8Span path)
|
||||
protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path)
|
||||
{
|
||||
totalSpace = default;
|
||||
return ResultFs.UnsupportedOperationRomFsFileSystemGetSpace.Log();
|
||||
|
@ -22,12 +22,12 @@ namespace LibHac.FsSystem.Save
|
||||
Mode = mode;
|
||||
}
|
||||
|
||||
public Result Read(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
protected override Result DoRead(out long entriesRead, Span<DirectoryEntry> entryBuffer)
|
||||
{
|
||||
return ReadImpl(out entriesRead, ref _currentPosition, entryBuffer);
|
||||
}
|
||||
|
||||
public Result GetEntryCount(out long entryCount)
|
||||
protected override Result DoGetEntryCount(out long entryCount)
|
||||
{
|
||||
SaveFindPosition position = InitialPosition;
|
||||
|
||||
|
@ -5,7 +5,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem.Save
|
||||
{
|
||||
public class SaveDataFile : FileBase
|
||||
public class SaveDataFile : IFile
|
||||
{
|
||||
private AllocationTableStorage BaseStorage { get; }
|
||||
private U8String Path { get; }
|
||||
@ -22,11 +22,12 @@ namespace LibHac.FsSystem.Save
|
||||
Size = size;
|
||||
}
|
||||
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination, ReadOptionFlag options)
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination,
|
||||
in ReadOption option)
|
||||
{
|
||||
bytesRead = default;
|
||||
|
||||
Result rc = ValidateReadParams(out long toRead, offset, destination.Length, Mode);
|
||||
Result rc = DryRead(out long toRead, offset, destination.Length, in option, Mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
if (toRead == 0)
|
||||
@ -42,9 +43,9 @@ namespace LibHac.FsSystem.Save
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, WriteOptionFlag options)
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
Result rc = ValidateWriteParams(offset, source.Length, Mode, out bool isResizeNeeded);
|
||||
Result rc = DryWrite(out bool isResizeNeeded, offset, source.Length, in option, Mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
if (isResizeNeeded)
|
||||
@ -55,7 +56,7 @@ namespace LibHac.FsSystem.Save
|
||||
|
||||
BaseStorage.Write(offset, source);
|
||||
|
||||
if ((options & WriteOptionFlag.Flush) != 0)
|
||||
if (option.HasFlushFlag())
|
||||
{
|
||||
return Flush();
|
||||
}
|
||||
@ -96,5 +97,10 @@ namespace LibHac.FsSystem.Save
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem.Save
|
||||
{
|
||||
public class SaveDataFileSystem : FileSystemBase
|
||||
public class SaveDataFileSystem : IFileSystem
|
||||
{
|
||||
internal const byte TrimFillValue = 0;
|
||||
|
||||
@ -144,98 +144,98 @@ namespace LibHac.FsSystem.Save
|
||||
IntegrityStorageType.Save, integrityCheckLevel, LeaveOpen);
|
||||
}
|
||||
|
||||
protected override Result CreateDirectoryImpl(U8Span path)
|
||||
protected override Result DoCreateDirectory(U8Span path)
|
||||
{
|
||||
Result result = SaveDataFileSystemCore.CreateDirectory(path);
|
||||
|
||||
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
|
||||
}
|
||||
|
||||
protected override Result CreateFileImpl(U8Span path, long size, CreateFileOptions options)
|
||||
protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions options)
|
||||
{
|
||||
Result result = SaveDataFileSystemCore.CreateFile(path, size, options);
|
||||
|
||||
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
|
||||
}
|
||||
|
||||
protected override Result DeleteDirectoryImpl(U8Span path)
|
||||
protected override Result DoDeleteDirectory(U8Span path)
|
||||
{
|
||||
Result result = SaveDataFileSystemCore.DeleteDirectory(path);
|
||||
|
||||
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
|
||||
}
|
||||
|
||||
protected override Result DeleteDirectoryRecursivelyImpl(U8Span path)
|
||||
protected override Result DoDeleteDirectoryRecursively(U8Span path)
|
||||
{
|
||||
Result result = SaveDataFileSystemCore.DeleteDirectoryRecursively(path);
|
||||
|
||||
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
|
||||
}
|
||||
|
||||
protected override Result CleanDirectoryRecursivelyImpl(U8Span path)
|
||||
protected override Result DoCleanDirectoryRecursively(U8Span path)
|
||||
{
|
||||
Result result = SaveDataFileSystemCore.CleanDirectoryRecursively(path);
|
||||
|
||||
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
|
||||
}
|
||||
|
||||
protected override Result DeleteFileImpl(U8Span path)
|
||||
protected override Result DoDeleteFile(U8Span path)
|
||||
{
|
||||
Result result = SaveDataFileSystemCore.DeleteFile(path);
|
||||
|
||||
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
|
||||
}
|
||||
|
||||
protected override Result OpenDirectoryImpl(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
{
|
||||
Result result = SaveDataFileSystemCore.OpenDirectory(out directory, path, mode);
|
||||
|
||||
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
|
||||
}
|
||||
|
||||
protected override Result OpenFileImpl(out IFile file, U8Span path, OpenMode mode)
|
||||
protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
|
||||
{
|
||||
Result result = SaveDataFileSystemCore.OpenFile(out file, path, mode);
|
||||
|
||||
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
|
||||
}
|
||||
|
||||
protected override Result RenameDirectoryImpl(U8Span oldPath, U8Span newPath)
|
||||
protected override Result DoRenameDirectory(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
Result result = SaveDataFileSystemCore.RenameDirectory(oldPath, newPath);
|
||||
|
||||
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
|
||||
}
|
||||
|
||||
protected override Result RenameFileImpl(U8Span oldPath, U8Span newPath)
|
||||
protected override Result DoRenameFile(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
Result result = SaveDataFileSystemCore.RenameFile(oldPath, newPath);
|
||||
|
||||
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
|
||||
}
|
||||
|
||||
protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, U8Span path)
|
||||
protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path)
|
||||
{
|
||||
Result result = SaveDataFileSystemCore.GetEntryType(out entryType, path);
|
||||
|
||||
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
|
||||
}
|
||||
|
||||
protected override Result GetFreeSpaceSizeImpl(out long freeSpace, U8Span path)
|
||||
protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path)
|
||||
{
|
||||
Result result = SaveDataFileSystemCore.GetFreeSpaceSize(out freeSpace, path);
|
||||
|
||||
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
|
||||
}
|
||||
|
||||
protected override Result GetTotalSpaceSizeImpl(out long totalSpace, U8Span path)
|
||||
protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path)
|
||||
{
|
||||
Result result = SaveDataFileSystemCore.GetTotalSpaceSize(out totalSpace, path);
|
||||
|
||||
return SaveResults.ConvertToExternalResult(result).LogConverted(result);
|
||||
}
|
||||
|
||||
protected override Result CommitImpl()
|
||||
protected override Result DoCommit()
|
||||
{
|
||||
Result result = Commit(Keyset);
|
||||
|
||||
|
@ -4,7 +4,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem.Save
|
||||
{
|
||||
public class SaveDataFileSystemCore : FileSystemBase
|
||||
public class SaveDataFileSystemCore : IFileSystem
|
||||
{
|
||||
private IStorage BaseStorage { get; }
|
||||
private IStorage HeaderStorage { get; }
|
||||
@ -28,7 +28,7 @@ namespace LibHac.FsSystem.Save
|
||||
FileTable = new HierarchicalSaveFileTable(dirTableStorage, fileTableStorage);
|
||||
}
|
||||
|
||||
protected override Result CreateDirectoryImpl(U8Span path)
|
||||
protected override Result DoCreateDirectory(U8Span path)
|
||||
{
|
||||
FsPath normalizedPath;
|
||||
unsafe { _ = &normalizedPath; } // workaround for CS0165
|
||||
@ -41,7 +41,7 @@ namespace LibHac.FsSystem.Save
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result CreateFileImpl(U8Span path, long size, CreateFileOptions options)
|
||||
protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions options)
|
||||
{
|
||||
FsPath normalizedPath;
|
||||
unsafe { _ = &normalizedPath; } // workaround for CS0165
|
||||
@ -72,7 +72,7 @@ namespace LibHac.FsSystem.Save
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DeleteDirectoryImpl(U8Span path)
|
||||
protected override Result DoDeleteDirectory(U8Span path)
|
||||
{
|
||||
FsPath normalizedPath;
|
||||
unsafe { _ = &normalizedPath; } // workaround for CS0165
|
||||
@ -85,7 +85,7 @@ namespace LibHac.FsSystem.Save
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DeleteDirectoryRecursivelyImpl(U8Span path)
|
||||
protected override Result DoDeleteDirectoryRecursively(U8Span path)
|
||||
{
|
||||
FsPath normalizedPath;
|
||||
unsafe { _ = &normalizedPath; } // workaround for CS0165
|
||||
@ -102,7 +102,7 @@ namespace LibHac.FsSystem.Save
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result CleanDirectoryRecursivelyImpl(U8Span path)
|
||||
protected override Result DoCleanDirectoryRecursively(U8Span path)
|
||||
{
|
||||
FsPath normalizedPath;
|
||||
unsafe { _ = &normalizedPath; } // workaround for CS0165
|
||||
@ -115,7 +115,7 @@ namespace LibHac.FsSystem.Save
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DeleteFileImpl(U8Span path)
|
||||
protected override Result DoDeleteFile(U8Span path)
|
||||
{
|
||||
FsPath normalizedPath;
|
||||
unsafe { _ = &normalizedPath; } // workaround for CS0165
|
||||
@ -138,7 +138,7 @@ namespace LibHac.FsSystem.Save
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result OpenDirectoryImpl(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
{
|
||||
directory = default;
|
||||
|
||||
@ -158,7 +158,7 @@ namespace LibHac.FsSystem.Save
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result OpenFileImpl(out IFile file, U8Span path, OpenMode mode)
|
||||
protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
|
||||
{
|
||||
file = default;
|
||||
|
||||
@ -180,7 +180,7 @@ namespace LibHac.FsSystem.Save
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result RenameDirectoryImpl(U8Span oldPath, U8Span newPath)
|
||||
protected override Result DoRenameDirectory(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
FsPath normalizedCurrentPath;
|
||||
FsPath normalizedNewPath;
|
||||
@ -196,7 +196,7 @@ namespace LibHac.FsSystem.Save
|
||||
return FileTable.RenameDirectory(normalizedCurrentPath, normalizedNewPath);
|
||||
}
|
||||
|
||||
protected override Result RenameFileImpl(U8Span oldPath, U8Span newPath)
|
||||
protected override Result DoRenameFile(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
FsPath normalizedCurrentPath;
|
||||
FsPath normalizedNewPath;
|
||||
@ -214,7 +214,7 @@ namespace LibHac.FsSystem.Save
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, U8Span path)
|
||||
protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path)
|
||||
{
|
||||
entryType = default;
|
||||
|
||||
@ -240,7 +240,7 @@ namespace LibHac.FsSystem.Save
|
||||
return ResultFs.PathNotFound.Log();
|
||||
}
|
||||
|
||||
protected override Result GetFreeSpaceSizeImpl(out long freeSpace, U8Span path)
|
||||
protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path)
|
||||
{
|
||||
int freeBlockCount = AllocationTable.GetFreeListLength();
|
||||
freeSpace = Header.BlockSize * freeBlockCount;
|
||||
@ -248,14 +248,14 @@ namespace LibHac.FsSystem.Save
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result GetTotalSpaceSizeImpl(out long totalSpace, U8Span path)
|
||||
protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path)
|
||||
{
|
||||
totalSpace = Header.BlockSize * Header.BlockCount;
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result CommitImpl()
|
||||
protected override Result DoCommit()
|
||||
{
|
||||
return Result.Success;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem
|
||||
{
|
||||
public class StorageFile : FileBase
|
||||
public class StorageFile : IFile
|
||||
{
|
||||
private IStorage BaseStorage { get; }
|
||||
private OpenMode Mode { get; }
|
||||
@ -14,11 +14,12 @@ namespace LibHac.FsSystem
|
||||
Mode = mode;
|
||||
}
|
||||
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination, ReadOptionFlag options)
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination,
|
||||
in ReadOption option)
|
||||
{
|
||||
bytesRead = default;
|
||||
|
||||
Result rc = ValidateReadParams(out long toRead, offset, destination.Length, Mode);
|
||||
Result rc = DryRead(out long toRead, offset, destination.Length, in option, Mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
if (toRead == 0)
|
||||
@ -34,9 +35,9 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, WriteOptionFlag options)
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
Result rc = ValidateWriteParams(offset, source.Length, Mode, out bool isResizeNeeded);
|
||||
Result rc = DryWrite(out bool isResizeNeeded, offset, source.Length, in option, Mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
if (isResizeNeeded)
|
||||
@ -48,7 +49,7 @@ namespace LibHac.FsSystem
|
||||
rc = BaseStorage.Write(offset, source);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
if (options.HasFlag(WriteOptionFlag.Flush))
|
||||
if (option.HasFlushFlag())
|
||||
{
|
||||
return Flush();
|
||||
}
|
||||
@ -76,5 +77,11 @@ namespace LibHac.FsSystem
|
||||
|
||||
return BaseStorage.SetSize(size);
|
||||
}
|
||||
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ namespace LibHac.FsSystem
|
||||
/// <summary>
|
||||
/// Provides an <see cref="IFile"/> interface for interacting with a <see cref="Stream"/>
|
||||
/// </summary>
|
||||
public class StreamFile : FileBase
|
||||
public class StreamFile : IFile
|
||||
{
|
||||
// todo: handle Stream exceptions
|
||||
|
||||
@ -21,11 +21,12 @@ namespace LibHac.FsSystem
|
||||
Mode = mode;
|
||||
}
|
||||
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination, ReadOptionFlag options)
|
||||
protected override Result DoRead(out long bytesRead, long offset, Span<byte> destination,
|
||||
in ReadOption option)
|
||||
{
|
||||
bytesRead = default;
|
||||
|
||||
Result rc = ValidateReadParams(out long toRead, offset, destination.Length, Mode);
|
||||
Result rc = DryRead(out long toRead, offset, destination.Length, in option, Mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
lock (Locker)
|
||||
@ -40,9 +41,9 @@ namespace LibHac.FsSystem
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, WriteOptionFlag options)
|
||||
protected override Result DoWrite(long offset, ReadOnlySpan<byte> source, in WriteOption option)
|
||||
{
|
||||
Result rc = ValidateWriteParams(offset, source.Length, Mode, out _);
|
||||
Result rc = DryWrite(out _, offset, source.Length, in option, Mode);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
lock (Locker)
|
||||
@ -51,7 +52,7 @@ namespace LibHac.FsSystem
|
||||
BaseStream.Write(source);
|
||||
}
|
||||
|
||||
if (options.HasFlag(WriteOptionFlag.Flush))
|
||||
if (option.HasFlushFlag())
|
||||
{
|
||||
return Flush();
|
||||
}
|
||||
@ -85,5 +86,11 @@ namespace LibHac.FsSystem
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
|
||||
protected override Result DoOperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ using LibHac.Fs;
|
||||
|
||||
namespace LibHac.FsSystem
|
||||
{
|
||||
public class SubdirectoryFileSystem : FileSystemBase
|
||||
public class SubdirectoryFileSystem : IFileSystem
|
||||
{
|
||||
private IFileSystem BaseFileSystem { get; }
|
||||
private U8String RootPath { get; set; }
|
||||
@ -72,7 +72,7 @@ namespace LibHac.FsSystem
|
||||
return PathTool.Normalize(outPath.Slice(RootPath.Length - 2), out _, relativePath, PreserveUnc, false);
|
||||
}
|
||||
|
||||
protected override Result CreateDirectoryImpl(U8Span path)
|
||||
protected override Result DoCreateDirectory(U8Span path)
|
||||
{
|
||||
Span<byte> fullPath = stackalloc byte[PathTools.MaxPathLength + 1];
|
||||
Result rc = ResolveFullPath(fullPath, path);
|
||||
@ -81,7 +81,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.CreateDirectory(new U8Span(fullPath));
|
||||
}
|
||||
|
||||
protected override Result CreateFileImpl(U8Span path, long size, CreateFileOptions options)
|
||||
protected override Result DoCreateFile(U8Span path, long size, CreateFileOptions options)
|
||||
{
|
||||
Span<byte> fullPath = stackalloc byte[PathTools.MaxPathLength + 1];
|
||||
Result rc = ResolveFullPath(fullPath, path);
|
||||
@ -90,7 +90,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.CreateFile(new U8Span(fullPath), size, options);
|
||||
}
|
||||
|
||||
protected override Result DeleteDirectoryImpl(U8Span path)
|
||||
protected override Result DoDeleteDirectory(U8Span path)
|
||||
{
|
||||
Span<byte> fullPath = stackalloc byte[PathTools.MaxPathLength + 1];
|
||||
Result rc = ResolveFullPath(fullPath, path);
|
||||
@ -99,7 +99,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.DeleteDirectory(new U8Span(fullPath));
|
||||
}
|
||||
|
||||
protected override Result DeleteDirectoryRecursivelyImpl(U8Span path)
|
||||
protected override Result DoDeleteDirectoryRecursively(U8Span path)
|
||||
{
|
||||
Span<byte> fullPath = stackalloc byte[PathTools.MaxPathLength + 1];
|
||||
Result rc = ResolveFullPath(fullPath, path);
|
||||
@ -108,7 +108,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.DeleteDirectoryRecursively(new U8Span(fullPath));
|
||||
}
|
||||
|
||||
protected override Result CleanDirectoryRecursivelyImpl(U8Span path)
|
||||
protected override Result DoCleanDirectoryRecursively(U8Span path)
|
||||
{
|
||||
Span<byte> fullPath = stackalloc byte[PathTools.MaxPathLength + 1];
|
||||
Result rc = ResolveFullPath(fullPath, path);
|
||||
@ -117,7 +117,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.CleanDirectoryRecursively(new U8Span(fullPath));
|
||||
}
|
||||
|
||||
protected override Result DeleteFileImpl(U8Span path)
|
||||
protected override Result DoDeleteFile(U8Span path)
|
||||
{
|
||||
Span<byte> fullPath = stackalloc byte[PathTools.MaxPathLength + 1];
|
||||
Result rc = ResolveFullPath(fullPath, path);
|
||||
@ -126,7 +126,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.DeleteFile(new U8Span(fullPath));
|
||||
}
|
||||
|
||||
protected override Result OpenDirectoryImpl(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
protected override Result DoOpenDirectory(out IDirectory directory, U8Span path, OpenDirectoryMode mode)
|
||||
{
|
||||
directory = default;
|
||||
|
||||
@ -137,7 +137,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.OpenDirectory(out directory, new U8Span(fullPath), mode);
|
||||
}
|
||||
|
||||
protected override Result OpenFileImpl(out IFile file, U8Span path, OpenMode mode)
|
||||
protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
|
||||
{
|
||||
file = default;
|
||||
|
||||
@ -148,7 +148,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.OpenFile(out file, new U8Span(fullPath), mode);
|
||||
}
|
||||
|
||||
protected override Result RenameDirectoryImpl(U8Span oldPath, U8Span newPath)
|
||||
protected override Result DoRenameDirectory(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
Span<byte> fullOldPath = stackalloc byte[PathTools.MaxPathLength + 1];
|
||||
Span<byte> fullNewPath = stackalloc byte[PathTools.MaxPathLength + 1];
|
||||
@ -162,7 +162,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.RenameDirectory(new U8Span(fullOldPath), new U8Span(fullNewPath));
|
||||
}
|
||||
|
||||
protected override Result RenameFileImpl(U8Span oldPath, U8Span newPath)
|
||||
protected override Result DoRenameFile(U8Span oldPath, U8Span newPath)
|
||||
{
|
||||
Span<byte> fullOldPath = stackalloc byte[PathTools.MaxPathLength + 1];
|
||||
Span<byte> fullNewPath = stackalloc byte[PathTools.MaxPathLength + 1];
|
||||
@ -176,7 +176,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.RenameFile(new U8Span(fullOldPath), new U8Span(fullNewPath));
|
||||
}
|
||||
|
||||
protected override Result GetEntryTypeImpl(out DirectoryEntryType entryType, U8Span path)
|
||||
protected override Result DoGetEntryType(out DirectoryEntryType entryType, U8Span path)
|
||||
{
|
||||
entryType = default;
|
||||
|
||||
@ -189,22 +189,22 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.GetEntryType(out entryType, fullPath);
|
||||
}
|
||||
|
||||
protected override Result CommitImpl()
|
||||
protected override Result DoCommit()
|
||||
{
|
||||
return BaseFileSystem.Commit();
|
||||
}
|
||||
|
||||
protected override Result CommitProvisionallyImpl(long commitCount)
|
||||
protected override Result DoCommitProvisionally(long counter)
|
||||
{
|
||||
return BaseFileSystem.CommitProvisionally(commitCount);
|
||||
return BaseFileSystem.CommitProvisionally(counter);
|
||||
}
|
||||
|
||||
protected override Result RollbackImpl()
|
||||
protected override Result DoRollback()
|
||||
{
|
||||
return BaseFileSystem.Rollback();
|
||||
}
|
||||
|
||||
protected override Result GetFreeSpaceSizeImpl(out long freeSpace, U8Span path)
|
||||
protected override Result DoGetFreeSpaceSize(out long freeSpace, U8Span path)
|
||||
{
|
||||
freeSpace = default;
|
||||
|
||||
@ -215,7 +215,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.GetFreeSpaceSize(out freeSpace, new U8Span(fullPath));
|
||||
}
|
||||
|
||||
protected override Result GetTotalSpaceSizeImpl(out long totalSpace, U8Span path)
|
||||
protected override Result DoGetTotalSpaceSize(out long totalSpace, U8Span path)
|
||||
{
|
||||
totalSpace = default;
|
||||
|
||||
@ -226,7 +226,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.GetTotalSpaceSize(out totalSpace, new U8Span(fullPath));
|
||||
}
|
||||
|
||||
protected override Result GetFileTimeStampRawImpl(out FileTimeStampRaw timeStamp, U8Span path)
|
||||
protected override Result DoGetFileTimeStampRaw(out FileTimeStampRaw timeStamp, U8Span path)
|
||||
{
|
||||
timeStamp = default;
|
||||
|
||||
@ -237,7 +237,7 @@ namespace LibHac.FsSystem
|
||||
return BaseFileSystem.GetFileTimeStampRaw(out timeStamp, new U8Span(fullPath));
|
||||
}
|
||||
|
||||
protected override Result QueryEntryImpl(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId,
|
||||
protected override Result DoQueryEntry(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId,
|
||||
U8Span path)
|
||||
{
|
||||
Span<byte> fullPath = stackalloc byte[PathTools.MaxPathLength + 1];
|
||||
|
@ -209,10 +209,10 @@ namespace LibHac.FsSystem
|
||||
|
||||
while (remaining > 0)
|
||||
{
|
||||
rc = sourceFile.Read(out long bytesRead, offset, workBuffer, ReadOptionFlag.None);
|
||||
rc = sourceFile.Read(out long bytesRead, offset, workBuffer, ReadOption.None);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
rc = destFile.Write(offset, workBuffer.Slice(0, (int)bytesRead), WriteOptionFlag.None);
|
||||
rc = destFile.Write(offset, workBuffer.Slice(0, (int)bytesRead), WriteOption.None);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
remaining -= bytesRead;
|
||||
|
@ -190,7 +190,7 @@ namespace LibHac.Kvdb
|
||||
rc = FsClient.OpenFile(out FileHandle handle, FileName, OpenMode.Write);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
rc = FsClient.WriteFile(handle, 0, data, WriteOptionFlag.Flush);
|
||||
rc = FsClient.WriteFile(handle, 0, data, WriteOption.Flush);
|
||||
FsClient.CloseFile(handle);
|
||||
|
||||
return rc;
|
||||
|
@ -13,7 +13,7 @@ namespace LibHac.Loader
|
||||
|
||||
public Result Initialize(IFile nsoFile)
|
||||
{
|
||||
Result rc = nsoFile.Read(out long bytesRead, 0, SpanHelpers.AsByteSpan(ref Header), ReadOptionFlag.None);
|
||||
Result rc = nsoFile.Read(out long bytesRead, 0, SpanHelpers.AsByteSpan(ref Header), ReadOption.None);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
if (bytesRead != Unsafe.SizeOf<NsoHeader>())
|
||||
@ -69,7 +69,7 @@ namespace LibHac.Loader
|
||||
// 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), ReadOptionFlag.None);
|
||||
Result rc = NsoFile.Read(out long bytesRead, segment.FileOffset, buffer.Slice((int)loadAddress), ReadOption.None);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
if (bytesRead != fileSize)
|
||||
|
@ -26,8 +26,8 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out IFile file1, "/dir1/file".ToU8Span(), OpenMode.Write).ThrowIfFailure();
|
||||
fs.OpenFile(out IFile file2, "/dir2/file".ToU8Span(), OpenMode.Write).ThrowIfFailure();
|
||||
|
||||
file1.Write(0, data1, WriteOptionFlag.Flush).ThrowIfFailure();
|
||||
file2.Write(0, data2, WriteOptionFlag.Flush).ThrowIfFailure();
|
||||
file1.Write(0, data1, WriteOption.Flush).ThrowIfFailure();
|
||||
file2.Write(0, data2, WriteOption.Flush).ThrowIfFailure();
|
||||
|
||||
file1.Dispose();
|
||||
file2.Dispose();
|
||||
@ -45,7 +45,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
|
||||
using (file1)
|
||||
{
|
||||
Assert.Success(file1.Read(out long bytesRead, 0, readData1, ReadOptionFlag.None));
|
||||
Assert.Success(file1.Read(out long bytesRead, 0, readData1, ReadOption.None));
|
||||
Assert.Equal(data1.Length, bytesRead);
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
|
||||
using (file2)
|
||||
{
|
||||
Assert.Success(file2.Read(out long bytesRead, 0, readData2, ReadOptionFlag.None));
|
||||
Assert.Success(file2.Read(out long bytesRead, 0, readData2, ReadOption.None));
|
||||
Assert.Equal(data2.Length, bytesRead);
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.CreateFile("/dir/file".ToU8Span(), data1.Length, CreateFileOptions.None).ThrowIfFailure();
|
||||
|
||||
fs.OpenFile(out IFile file, "/dir/file".ToU8Span(), OpenMode.Write).ThrowIfFailure();
|
||||
file.Write(0, data1, WriteOptionFlag.Flush).ThrowIfFailure();
|
||||
file.Write(0, data1, WriteOption.Flush).ThrowIfFailure();
|
||||
file.Dispose();
|
||||
|
||||
// Commit and reopen the file system
|
||||
@ -121,7 +121,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
|
||||
// Make changes to the file
|
||||
fs.OpenFile(out file, "/dir/file".ToU8Span(), OpenMode.Write).ThrowIfFailure();
|
||||
file.Write(0, data2, WriteOptionFlag.Flush).ThrowIfFailure();
|
||||
file.Write(0, data2, WriteOption.Flush).ThrowIfFailure();
|
||||
file.Dispose();
|
||||
|
||||
Assert.Success(fs.Rollback());
|
||||
@ -133,7 +133,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
|
||||
using (file)
|
||||
{
|
||||
Assert.Success(file.Read(out long bytesRead, 0, readData, ReadOptionFlag.None));
|
||||
Assert.Success(file.Read(out long bytesRead, 0, readData, ReadOption.None));
|
||||
Assert.Equal(data1.Length, bytesRead);
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out IFile file, "/file".ToU8Span(), OpenMode.Read);
|
||||
using (file)
|
||||
{
|
||||
Assert.True(file.Read(out long bytesRead, 50, buffer, ReadOptionFlag.None).IsSuccess());
|
||||
Assert.True(file.Read(out long bytesRead, 50, buffer, ReadOption.None).IsSuccess());
|
||||
Assert.Equal(20, bytesRead);
|
||||
}
|
||||
}
|
||||
@ -34,7 +34,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out IFile file, "/file".ToU8Span(), OpenMode.Read);
|
||||
using (file)
|
||||
{
|
||||
Result rc = file.Read(out _, 1, buffer, ReadOptionFlag.None);
|
||||
Result rc = file.Read(out _, 1, buffer, ReadOption.None);
|
||||
Assert.Equal(ResultFs.OutOfRange.Value, rc);
|
||||
}
|
||||
}
|
||||
@ -50,7 +50,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out IFile file, "/file".ToU8Span(), OpenMode.Write);
|
||||
using (file)
|
||||
{
|
||||
Result rc = file.Read(out _, 0, buffer, ReadOptionFlag.None);
|
||||
Result rc = file.Read(out _, 0, buffer, ReadOption.None);
|
||||
Assert.Equal(ResultFs.InvalidOpenModeForRead.Value, rc);
|
||||
}
|
||||
}
|
||||
@ -66,7 +66,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out IFile file, "/file".ToU8Span(), OpenMode.Write);
|
||||
using (file)
|
||||
{
|
||||
Result rc = file.Read(out _, -5, buffer, ReadOptionFlag.None);
|
||||
Result rc = file.Read(out _, -5, buffer, ReadOption.None);
|
||||
Assert.Equal(ResultFs.OutOfRange.Value, rc);
|
||||
}
|
||||
}
|
||||
@ -82,7 +82,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out IFile file, "/file".ToU8Span(), OpenMode.Write);
|
||||
using (file)
|
||||
{
|
||||
Result rc = file.Read(out _, long.MaxValue - 5, buffer, ReadOptionFlag.None);
|
||||
Result rc = file.Read(out _, long.MaxValue - 5, buffer, ReadOption.None);
|
||||
Assert.Equal(ResultFs.OutOfRange.Value, rc);
|
||||
}
|
||||
}
|
||||
@ -98,7 +98,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out IFile file, "/file".ToU8Span(), OpenMode.Read);
|
||||
using (file)
|
||||
{
|
||||
Assert.True(file.Read(out long bytesRead, 90, buffer, ReadOptionFlag.None).IsSuccess());
|
||||
Assert.True(file.Read(out long bytesRead, 90, buffer, ReadOption.None).IsSuccess());
|
||||
Assert.Equal(10, bytesRead);
|
||||
}
|
||||
}
|
||||
@ -114,7 +114,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out IFile file, "/file".ToU8Span(), OpenMode.Write);
|
||||
using (file)
|
||||
{
|
||||
file.Write(0, new byte[100], WriteOptionFlag.None);
|
||||
file.Write(0, new byte[100], WriteOption.None);
|
||||
}
|
||||
|
||||
var bufferExpected = new byte[200];
|
||||
@ -126,7 +126,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out file, "/file".ToU8Span(), OpenMode.Read);
|
||||
using (file)
|
||||
{
|
||||
Assert.True(file.Read(out _, 90, buffer, ReadOptionFlag.None).IsSuccess());
|
||||
Assert.True(file.Read(out _, 90, buffer, ReadOption.None).IsSuccess());
|
||||
Assert.Equal(bufferExpected, buffer);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.CreateFile("/file".ToU8Span(), data.Length, CreateFileOptions.None);
|
||||
|
||||
fs.OpenFile(out IFile file, "/file".ToU8Span(), OpenMode.Write);
|
||||
file.Write(0, data, WriteOptionFlag.None);
|
||||
file.Write(0, data, WriteOption.None);
|
||||
file.Dispose();
|
||||
|
||||
var readData = new byte[data.Length];
|
||||
@ -25,7 +25,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out file, "/file".ToU8Span(), OpenMode.Read);
|
||||
using (file)
|
||||
{
|
||||
Assert.True(file.Read(out long bytesRead, 0, readData, ReadOptionFlag.None).IsSuccess());
|
||||
Assert.True(file.Read(out long bytesRead, 0, readData, ReadOption.None).IsSuccess());
|
||||
Assert.Equal(data.Length, bytesRead);
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out IFile file, "/file".ToU8Span(), OpenMode.Write);
|
||||
using (file)
|
||||
{
|
||||
Result rc = file.Write(5, buffer, WriteOptionFlag.None);
|
||||
Result rc = file.Write(5, buffer, WriteOption.None);
|
||||
Assert.Equal(ResultFs.FileExtensionWithoutOpenModeAllowAppend.Value, rc);
|
||||
}
|
||||
}
|
||||
@ -59,7 +59,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out IFile file, "/file".ToU8Span(), OpenMode.Read);
|
||||
using (file)
|
||||
{
|
||||
Result rc = file.Write(5, buffer, WriteOptionFlag.None);
|
||||
Result rc = file.Write(5, buffer, WriteOption.None);
|
||||
Assert.Equal(ResultFs.InvalidOpenModeForWrite.Value, rc);
|
||||
}
|
||||
}
|
||||
@ -75,7 +75,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out IFile file, "/file".ToU8Span(), OpenMode.Read);
|
||||
using (file)
|
||||
{
|
||||
Result rc = file.Write(-5, buffer, WriteOptionFlag.None);
|
||||
Result rc = file.Write(-5, buffer, WriteOption.None);
|
||||
Assert.Equal(ResultFs.OutOfRange.Value, rc);
|
||||
}
|
||||
}
|
||||
@ -91,7 +91,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out IFile file, "/file".ToU8Span(), OpenMode.Read);
|
||||
using (file)
|
||||
{
|
||||
Result rc = file.Write(long.MaxValue - 5, buffer, WriteOptionFlag.None);
|
||||
Result rc = file.Write(long.MaxValue - 5, buffer, WriteOption.None);
|
||||
Assert.Equal(ResultFs.OutOfRange.Value, rc);
|
||||
}
|
||||
}
|
||||
@ -107,7 +107,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out IFile file, "/file".ToU8Span(), OpenMode.All);
|
||||
using (file)
|
||||
{
|
||||
Assert.True(file.Write(5, buffer, WriteOptionFlag.None).IsSuccess());
|
||||
Assert.True(file.Write(5, buffer, WriteOption.None).IsSuccess());
|
||||
|
||||
file.GetSize(out long newSize);
|
||||
Assert.Equal(15, newSize);
|
||||
@ -125,7 +125,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out IFile file, "/file".ToU8Span(), OpenMode.All);
|
||||
using (file)
|
||||
{
|
||||
Assert.True(file.Write(15, buffer, WriteOptionFlag.None).IsSuccess());
|
||||
Assert.True(file.Write(15, buffer, WriteOption.None).IsSuccess());
|
||||
|
||||
file.GetSize(out long newSize);
|
||||
Assert.Equal(25, newSize);
|
||||
@ -148,10 +148,10 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out IFile file, "/file".ToU8Span(), OpenMode.All);
|
||||
using (file)
|
||||
{
|
||||
Assert.True(file.Write(15, writeBuffer, WriteOptionFlag.None).IsSuccess());
|
||||
Assert.True(file.Write(15, writeBuffer, WriteOption.None).IsSuccess());
|
||||
|
||||
// Unwritten portions of new files are undefined, so write to the other portions
|
||||
file.Write(0, new byte[15], WriteOptionFlag.None);
|
||||
file.Write(0, new byte[15], WriteOption.None);
|
||||
}
|
||||
|
||||
var readBuffer = new byte[25];
|
||||
@ -159,7 +159,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.OpenFile(out file, "/file".ToU8Span(), OpenMode.Read);
|
||||
using (file)
|
||||
{
|
||||
file.Read(out _, 0, readBuffer, ReadOptionFlag.None);
|
||||
file.Read(out _, 0, readBuffer, ReadOption.None);
|
||||
Assert.Equal(bufferExpected, readBuffer);
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
fs.CreateFile("/file".ToU8Span(), data.Length, CreateFileOptions.None);
|
||||
|
||||
fs.OpenFile(out IFile file, "/file".ToU8Span(), OpenMode.Write);
|
||||
file.Write(0, data, WriteOptionFlag.None);
|
||||
file.Write(0, data, WriteOption.None);
|
||||
file.Dispose();
|
||||
|
||||
fs.RenameFile("/file".ToU8Span(), "/renamed".ToU8Span());
|
||||
@ -106,7 +106,7 @@ namespace LibHac.Tests.Fs.IFileSystemTestBase
|
||||
var readData = new byte[data.Length];
|
||||
|
||||
fs.OpenFile(out file, "/renamed".ToU8Span(), OpenMode.Read);
|
||||
Result rc = file.Read(out long bytesRead, 0, readData, ReadOptionFlag.None);
|
||||
Result rc = file.Read(out long bytesRead, 0, readData, ReadOption.None);
|
||||
file.Dispose();
|
||||
|
||||
Assert.True(rc.IsSuccess());
|
||||
|
Loading…
x
Reference in New Issue
Block a user