From ef1481b04c5bcd99c741b279da935bbd563572f1 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sun, 7 Jun 2020 15:23:51 -0700 Subject: [PATCH] Replace old fsa classes with new ones --- build/CodeGen/results.csv | 1 + src/LibHac/Fs/Accessors/FileAccessor.cs | 20 +- src/LibHac/Fs/AttributeFileSystemBase.cs | 48 ---- src/LibHac/Fs/FileBase.cs | 150 ---------- src/LibHac/Fs/FileStorage2.cs | 4 +- src/LibHac/Fs/FileSystemBase.cs | 258 ------------------ src/LibHac/Fs/FileSystemClient.File.cs | 22 +- src/LibHac/Fs/IAttributeFileSystem.cs | 49 +++- src/LibHac/Fs/IDirectory.cs | 32 ++- src/LibHac/Fs/IFile.cs | 195 ++++++++++++- src/LibHac/Fs/IFileSystem.cs | 233 ++++++++++++++-- src/LibHac/Fs/InMemoryFileSystem.cs | 50 ++-- src/LibHac/Fs/ResultFs.cs | 2 + src/LibHac/FsService/FileSystemProxy.cs | 2 +- .../FsService/Impl/MultiCommitManager.cs | 4 +- src/LibHac/FsService/SaveDataIndexer.cs | 2 +- src/LibHac/FsSystem/AesXtsDirectory.cs | 8 +- src/LibHac/FsSystem/AesXtsFile.cs | 18 +- src/LibHac/FsSystem/AesXtsFileSystem.cs | 42 +-- src/LibHac/FsSystem/ConcatenationDirectory.cs | 4 +- src/LibHac/FsSystem/ConcatenationFile.cs | 22 +- .../FsSystem/ConcatenationFileSystem.cs | 40 +-- src/LibHac/FsSystem/DirectorySaveDataFile.cs | 16 +- .../FsSystem/DirectorySaveDataFileSystem.cs | 34 +-- src/LibHac/FsSystem/DirectoryUtils.cs | 4 +- src/LibHac/FsSystem/FileSystemExtensions.cs | 4 +- src/LibHac/FsSystem/LayeredFileSystem.cs | 34 +-- src/LibHac/FsSystem/LocalDirectory.cs | 6 +- src/LibHac/FsSystem/LocalFile.cs | 20 +- src/LibHac/FsSystem/LocalFileSystem.cs | 44 +-- src/LibHac/FsSystem/NullFile.cs | 15 +- src/LibHac/FsSystem/PartitionDirectory.cs | 4 +- src/LibHac/FsSystem/PartitionFile.cs | 19 +- src/LibHac/FsSystem/PartitionFileSystem.cs | 26 +- .../FsSystem/PartitionFileSystemCore.cs | 43 +-- src/LibHac/FsSystem/ReadOnlyFile.cs | 21 +- src/LibHac/FsSystem/ReadOnlyFileSystem.cs | 32 +-- src/LibHac/FsSystem/RomFs/RomFsDirectory.cs | 4 +- src/LibHac/FsSystem/RomFs/RomFsFile.cs | 15 +- src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs | 32 +-- src/LibHac/FsSystem/Save/SaveDataDirectory.cs | 4 +- src/LibHac/FsSystem/Save/SaveDataFile.cs | 18 +- .../FsSystem/Save/SaveDataFileSystem.cs | 30 +- .../FsSystem/Save/SaveDataFileSystemCore.cs | 30 +- src/LibHac/FsSystem/StorageFile.cs | 19 +- src/LibHac/FsSystem/StreamFile.cs | 19 +- src/LibHac/FsSystem/SubdirectoryFileSystem.cs | 40 +-- src/LibHac/FsSystem/Utility.cs | 4 +- src/LibHac/Kvdb/KeyValueDatabase.cs | 2 +- src/LibHac/Loader/NsoReader.cs | 4 +- .../CommittableIFileSystemTests.Commit.cs | 14 +- .../IFileSystemTests.IFile.Read.cs | 16 +- .../IFileSystemTests.IFile.Write.cs | 22 +- .../IFileSystemTests.RenameFile.cs | 4 +- 54 files changed, 935 insertions(+), 870 deletions(-) delete mode 100644 src/LibHac/Fs/AttributeFileSystemBase.cs delete mode 100644 src/LibHac/Fs/FileBase.cs delete mode 100644 src/LibHac/Fs/FileSystemBase.cs diff --git a/build/CodeGen/results.csv b/build/CodeGen/results.csv index 38f49070..fb1bc386 100644 --- a/build/CodeGen/results.csv +++ b/build/CodeGen/results.csv @@ -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, diff --git a/src/LibHac/Fs/Accessors/FileAccessor.cs b/src/LibHac/Fs/Accessors/FileAccessor.cs index 6ccca63b..93307b55 100644 --- a/src/LibHac/Fs/Accessors/FileAccessor.cs +++ b/src/LibHac/Fs/Accessors/FileAccessor.cs @@ -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 destination, ReadOptionFlag options) + protected override Result DoRead(out long bytesRead, long offset, Span 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 source, WriteOptionFlag options) + protected override Result DoWrite(long offset, ReadOnlySpan 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 outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan inBuffer) + { + return ResultFs.NotImplemented.Log(); + } + protected override Result DoSetSize(long size) { CheckIfDisposed(); diff --git a/src/LibHac/Fs/AttributeFileSystemBase.cs b/src/LibHac/Fs/AttributeFileSystemBase.cs deleted file mode 100644 index 2da813c0..00000000 --- a/src/LibHac/Fs/AttributeFileSystemBase.cs +++ /dev/null @@ -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); - } - } -} diff --git a/src/LibHac/Fs/FileBase.cs b/src/LibHac/Fs/FileBase.cs deleted file mode 100644 index 5f521f97..00000000 --- a/src/LibHac/Fs/FileBase.cs +++ /dev/null @@ -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 destination, ReadOptionFlag options); - protected abstract Result DoWrite(long offset, ReadOnlySpan 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 outBuffer, OperationId operationId, long offset, long size, - ReadOnlySpan inBuffer) - { - return ResultFs.NotImplemented.Log(); - } - - public Result Read(out long bytesRead, long offset, Span 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 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 outBuffer, OperationId operationId, long offset, long size, - ReadOnlySpan 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; - } - } -} diff --git a/src/LibHac/Fs/FileStorage2.cs b/src/LibHac/Fs/FileStorage2.cs index 91bb5de7..0a5514b5 100644 --- a/src/LibHac/Fs/FileStorage2.cs +++ b/src/LibHac/Fs/FileStorage2.cs @@ -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 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() diff --git a/src/LibHac/Fs/FileSystemBase.cs b/src/LibHac/Fs/FileSystemBase.cs deleted file mode 100644 index 5e8fdc08..00000000 --- a/src/LibHac/Fs/FileSystemBase.cs +++ /dev/null @@ -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 outBuffer, ReadOnlySpan 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 outBuffer, ReadOnlySpan 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) { } - } -} diff --git a/src/LibHac/Fs/FileSystemClient.File.cs b/src/LibHac/Fs/FileSystemClient.File.cs index 1524e630..a2144b6b 100644 --- a/src/LibHac/Fs/FileSystemClient.File.cs +++ b/src/LibHac/Fs/FileSystemClient.File.cs @@ -6,10 +6,10 @@ namespace LibHac.Fs { public Result ReadFile(FileHandle handle, long offset, Span destination) { - return ReadFile(handle, offset, destination, ReadOptionFlag.None); + return ReadFile(handle, offset, destination, ReadOption.None); } - public Result ReadFile(FileHandle handle, long offset, Span destination, ReadOptionFlag option) + public Result ReadFile(FileHandle handle, long offset, Span 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 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 destination, ReadOptionFlag option) + public Result ReadFile(out long bytesRead, FileHandle handle, long offset, Span 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 source) { - return WriteFile(handle, offset, source, WriteOptionFlag.None); + return WriteFile(handle, offset, source, WriteOption.None); } - public Result WriteFile(FileHandle handle, long offset, ReadOnlySpan source, WriteOptionFlag option) + public Result WriteFile(FileHandle handle, long offset, ReadOnlySpan 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; diff --git a/src/LibHac/Fs/IAttributeFileSystem.cs b/src/LibHac/Fs/IAttributeFileSystem.cs index 39cdf430..450b73fc 100644 --- a/src/LibHac/Fs/IAttributeFileSystem.cs +++ b/src/LibHac/Fs/IAttributeFileSystem.cs @@ -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); } } diff --git a/src/LibHac/Fs/IDirectory.cs b/src/LibHac/Fs/IDirectory.cs index 401d26d7..5ec28a40 100644 --- a/src/LibHac/Fs/IDirectory.cs +++ b/src/LibHac/Fs/IDirectory.cs @@ -2,10 +2,11 @@ namespace LibHac.Fs { + // ReSharper disable once InconsistentNaming /// /// Provides an interface for enumerating the child entries of a directory. /// - public interface IDirectory + public abstract class IDirectory : IDisposable { /// /// 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 will /// read 0 entries into the buffer. - Result Read(out long entriesRead, Span entryBuffer); + public Result Read(out long entriesRead, Span entryBuffer) + { + if (entryBuffer.IsEmpty) + { + entriesRead = 0; + return Result.Success; + } + + return DoRead(out entriesRead, entryBuffer); + } /// /// Retrieves the number of file system entries that this directory contains. Does not search subdirectories. /// /// The number of child entries the directory contains. /// The of the requested operation. - Result GetEntryCount(out long entryCount); + public Result GetEntryCount(out long entryCount) + { + return DoGetEntryCount(out entryCount); + } + + protected abstract Result DoRead(out long entriesRead, Span entryBuffer); + protected abstract Result DoGetEntryCount(out long entryCount); + + protected virtual void Dispose(bool disposing) { } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } } -} \ No newline at end of file +} diff --git a/src/LibHac/Fs/IFile.cs b/src/LibHac/Fs/IFile.cs index 5907fa47..08a81d3d 100644 --- a/src/LibHac/Fs/IFile.cs +++ b/src/LibHac/Fs/IFile.cs @@ -1,7 +1,9 @@ using System; +using LibHac.Diag; namespace LibHac.Fs { + // ReSharper disable once InconsistentNaming /// /// Provides an interface for reading and writing a sequence of bytes. /// @@ -16,7 +18,7 @@ namespace LibHac.Fs /// - If is called on an offset past the end of the , /// the mode is set and the file supports expansion, /// the file will be expanded so that it is large enough to contain the written data. - public interface IFile : IDisposable + public abstract class IFile : IDisposable { /// /// Reads a sequence of bytes from the current . @@ -26,37 +28,104 @@ namespace LibHac.Fs /// The offset in the at which to begin reading. /// The buffer where the read bytes will be stored. /// The number of bytes read will be no larger than the length of the buffer. - /// Options for reading from the . + /// Options for reading from the . /// The of the requested operation. - Result Read(out long bytesRead, long offset, Span destination, ReadOptionFlag options); + public Result Read(out long bytesRead, long offset, Span 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); + } + + /// + /// Reads a sequence of bytes from the current with no s. + /// + /// 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. + /// The offset in the at which to begin reading. + /// The buffer where the read bytes will be stored. + /// The number of bytes read will be no larger than the length of the buffer. + /// The of the requested operation. + public Result Read(out long bytesRead, long offset, Span destination) + { + return Read(out bytesRead, offset, destination, ReadOption.None); + } /// /// Writes a sequence of bytes to the current . /// /// The offset in the at which to begin writing. /// The buffer containing the bytes to be written. - /// Options for writing to the . + /// Options for writing to the . /// The of the requested operation. - Result Write(long offset, ReadOnlySpan source, WriteOptionFlag options); + public Result Write(long offset, ReadOnlySpan 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); + } /// /// Causes any buffered data to be written to the underlying device. /// - Result Flush(); + public Result Flush() + { + return DoFlush(); + } /// /// Sets the size of the file in bytes. /// /// The desired size of the file in bytes. /// The of the requested operation. - Result SetSize(long size); + public Result SetSize(long size) + { + if (size < 0) + return ResultFs.OutOfRange.Log(); + + return DoSetSize(size); + } /// /// Gets the number of bytes in the file. /// /// If the operation returns successfully, the length of the file in bytes. /// The of the requested operation. - Result GetSize(out long size); + public Result GetSize(out long size) + { + return DoGetSize(out size); + } /// /// Performs various operations on the file. Used to extend the functionality of the interface. @@ -67,7 +136,113 @@ namespace LibHac.Fs /// The size of the range to operate on. /// An input buffer. Size may vary depending on the operation performed. /// The of the requested operation. - Result OperateRange(Span outBuffer, OperationId operationId, long offset, long size, + public Result OperateRange(Span outBuffer, OperationId operationId, long offset, long size, + ReadOnlySpan inBuffer) + { + return DoOperateRange(outBuffer, operationId, offset, size, inBuffer); + } + + /// + /// Performs various operations on the file. Used to extend the functionality of the interface. + /// + /// The operation to be performed. + /// The offset of the range to operate on. + /// The size of the range to operate on. + /// The of the requested operation. + public Result OperateRange(OperationId operationId, long offset, long size) + { + return DoOperateRange(Span.Empty, operationId, offset, size, ReadOnlySpan.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 destination, in ReadOption option); + protected abstract Result DoWrite(long offset, ReadOnlySpan 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 outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan inBuffer); + + protected virtual void Dispose(bool disposing) { } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } } -} \ No newline at end of file +} diff --git a/src/LibHac/Fs/IFileSystem.cs b/src/LibHac/Fs/IFileSystem.cs index 99415b6b..57304eda 100644 --- a/src/LibHac/Fs/IFileSystem.cs +++ b/src/LibHac/Fs/IFileSystem.cs @@ -4,17 +4,18 @@ using LibHac.FsSystem; namespace LibHac.Fs { + // ReSharper disable once InconsistentNaming /// /// Provides an interface for accessing a file system. / is used as the path delimiter. /// - public interface IFileSystem : IDisposable + public abstract class IFileSystem : IDisposable { /// /// Creates or overwrites a file at the specified path. /// /// The full path of the file to create. /// The initial size of the created file. - /// Flags to control how the file is created. + /// Flags to control how the file is created. /// Should usually be /// The of the requested operation. /// @@ -24,7 +25,16 @@ namespace LibHac.Fs /// Specified path already exists as either a file or directory: /// Insufficient free space to create the file: /// - 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); + } /// /// Deletes the specified file. @@ -36,7 +46,13 @@ namespace LibHac.Fs /// /// The specified path does not exist or is a directory: /// - Result DeleteFile(U8Span path); + public Result DeleteFile(U8Span path) + { + if (path.IsNull()) + return ResultFs.NullptrArgument.Log(); + + return DoDeleteFile(path); + } /// /// 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: /// Insufficient free space to create the directory: /// - Result CreateDirectory(U8Span path); + public Result CreateDirectory(U8Span path) + { + if (path.IsNull()) + return ResultFs.NullptrArgument.Log(); + + return DoCreateDirectory(path); + } /// /// Deletes the specified directory. @@ -63,7 +85,13 @@ namespace LibHac.Fs /// The specified path does not exist or is a file: /// The specified directory is not empty: /// - Result DeleteDirectory(U8Span path); + public Result DeleteDirectory(U8Span path) + { + if (path.IsNull()) + return ResultFs.NullptrArgument.Log(); + + return DoDeleteDirectory(path); + } /// /// 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: /// - Result DeleteDirectoryRecursively(U8Span path); + public Result DeleteDirectoryRecursively(U8Span path) + { + if (path.IsNull()) + return ResultFs.NullptrArgument.Log(); + + return DoDeleteDirectoryRecursively(path); + } /// /// 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: /// - Result CleanDirectoryRecursively(U8Span path); + public Result CleanDirectoryRecursively(U8Span path) + { + if (path.IsNull()) + return ResultFs.NullptrArgument.Log(); + + return DoCleanDirectoryRecursively(path); + } /// /// Renames or moves a file to a new location. @@ -103,7 +143,16 @@ namespace LibHac.Fs /// 's parent directory does not exist: /// already exists as either a file or directory: /// - 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); + } /// /// Renames or moves a directory to a new location. @@ -120,7 +169,16 @@ namespace LibHac.Fs /// already exists as either a file or directory: /// Either or is a subpath of the other: /// - 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); + } /// /// Determines whether the specified path is a file or directory, or does not exist. @@ -128,7 +186,16 @@ namespace LibHac.Fs /// If the operation returns successfully, the of the file. /// The full path to check. /// The of the requested operation. - 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); + } /// /// Gets the amount of available free space on a drive, in bytes. @@ -136,7 +203,16 @@ namespace LibHac.Fs /// If the operation returns successfully, the amount of free space available on the drive, in bytes. /// The path of the drive to query. Unused in almost all cases. /// The of the requested operation. - 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); + } /// /// Gets the total size of storage space on a drive, in bytes. @@ -144,7 +220,16 @@ namespace LibHac.Fs /// If the operation returns successfully, the total size of the drive, in bytes. /// The path of the drive to query. Unused in almost all cases. /// The of the requested operation. - 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); + } /// /// Opens an instance for the specified path. @@ -159,7 +244,28 @@ namespace LibHac.Fs /// /// The specified path does not exist or is a directory: /// - 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); + } /// /// Creates an instance for enumerating the specified directory. @@ -174,20 +280,41 @@ namespace LibHac.Fs /// /// The specified path does not exist or is a file: /// - 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); + } /// /// Commits any changes to a transactional file system. /// Does nothing if called on a non-transactional file system. /// /// The of the requested operation. - 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(); /// /// 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: /// - 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); + } /// /// Performs a query on the specified file. @@ -215,7 +351,60 @@ namespace LibHac.Fs /// The type of query to perform. /// The full path of the file to query. /// The of the requested operation. - Result QueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, U8Span path); + public Result QueryEntry(Span outBuffer, ReadOnlySpan 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 outBuffer, ReadOnlySpan inBuffer, QueryId queryId, + U8Span path) => ResultFs.NotImplemented.Log(); + + protected virtual void Dispose(bool disposing) { } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } } /// @@ -251,4 +440,4 @@ namespace LibHac.Fs /// MakeConcatFile = 0 } -} \ No newline at end of file +} diff --git a/src/LibHac/Fs/InMemoryFileSystem.cs b/src/LibHac/Fs/InMemoryFileSystem.cs index d74b567a..09642fec 100644 --- a/src/LibHac/Fs/InMemoryFileSystem.cs +++ b/src/LibHac/Fs/InMemoryFileSystem.cs @@ -9,7 +9,7 @@ namespace LibHac.Fs /// /// A filesystem stored in-memory. Mainly used for testing. /// - 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 destination, ReadOptionFlag options) + protected override Result DoRead(out long bytesRead, long offset, Span 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 source, WriteOptionFlag options) + protected override Result DoWrite(long offset, ReadOnlySpan 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 outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan 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 entryBuffer) + protected override Result DoRead(out long entriesRead, Span 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; diff --git a/src/LibHac/Fs/ResultFs.cs b/src/LibHac/Fs/ResultFs.cs index d9c06d7d..8f98d43c 100644 --- a/src/LibHac/Fs/ResultFs.cs +++ b/src/LibHac/Fs/ResultFs.cs @@ -388,6 +388,8 @@ namespace LibHac.Fs public static Result.Base UnsupportedOperationReadOnlyFileSystemGetSpace => new Result.Base(ModuleFs, 6371); /// Error code: 2002-6372; Inner value: 0x31c802 public static Result.Base UnsupportedOperationModifyReadOnlyFile => new Result.Base(ModuleFs, 6372); + /// Error code: 2002-6373; Inner value: 0x31ca02 + public static Result.Base UnsupportedOperationInReadOnlyFile => new Result.Base(ModuleFs, 6373); /// Error code: 2002-6374; Inner value: 0x31cc02 public static Result.Base UnsupportedOperationModifyPartitionFileSystem => new Result.Base(ModuleFs, 6374); /// Called PartitionFileSystemCore::CommitProvisionally.
Error code: 2002-6375; Inner value: 0x31ce02
diff --git a/src/LibHac/FsService/FileSystemProxy.cs b/src/LibHac/FsService/FileSystemProxy.cs index c5c2d629..1725da97 100644 --- a/src/LibHac/FsService/FileSystemProxy.cs +++ b/src/LibHac/FsService/FileSystemProxy.cs @@ -379,7 +379,7 @@ namespace LibHac.FsService ReadOnlySpan metaFileData = stackalloc byte[0x20]; - rc = metaFile.Write(0, metaFileData, WriteOptionFlag.Flush); + rc = metaFile.Write(0, metaFileData, WriteOption.Flush); if (rc.IsFailure()) return rc; } } diff --git a/src/LibHac/FsService/Impl/MultiCommitManager.cs b/src/LibHac/FsService/Impl/MultiCommitManager.cs index 97edd7d1..e8a0a31b 100644 --- a/src/LibHac/FsService/Impl/MultiCommitManager.cs +++ b/src/LibHac/FsService/Impl/MultiCommitManager.cs @@ -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(); diff --git a/src/LibHac/FsService/SaveDataIndexer.cs b/src/LibHac/FsService/SaveDataIndexer.cs index f53ff746..3d8759b5 100644 --- a/src/LibHac/FsService/SaveDataIndexer.cs +++ b/src/LibHac/FsService/SaveDataIndexer.cs @@ -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); diff --git a/src/LibHac/FsSystem/AesXtsDirectory.cs b/src/LibHac/FsSystem/AesXtsDirectory.cs index 4f32f6f2..ddf2d8a2 100644 --- a/src/LibHac/FsSystem/AesXtsDirectory.cs +++ b/src/LibHac/FsSystem/AesXtsDirectory.cs @@ -20,7 +20,7 @@ namespace LibHac.FsSystem Path = path; } - public Result Read(out long entriesRead, Span entryBuffer) + protected override Result DoRead(out long entriesRead, Span 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; diff --git a/src/LibHac/FsSystem/AesXtsFile.cs b/src/LibHac/FsSystem/AesXtsFile.cs index 391fa2b0..cb09d90c 100644 --- a/src/LibHac/FsSystem/AesXtsFile.cs +++ b/src/LibHac/FsSystem/AesXtsFile.cs @@ -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 destination, ReadOptionFlag options) + protected override Result DoRead(out long bytesRead, long offset, Span 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 source, WriteOptionFlag options) + protected override Result DoWrite(long offset, ReadOnlySpan 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 outBuffer, OperationId operationId, long offset, long size, + ReadOnlySpan inBuffer) + { + throw new NotImplementedException(); + } + protected override Result DoSetSize(long size) { Header.SetSize(size, VerificationKey); diff --git a/src/LibHac/FsSystem/AesXtsFileSystem.cs b/src/LibHac/FsSystem/AesXtsFileSystem.cs index e0d81c68..88ff6f38 100644 --- a/src/LibHac/FsSystem/AesXtsFileSystem.cs +++ b/src/LibHac/FsSystem/AesXtsFileSystem.cs @@ -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 outBuffer, ReadOnlySpan inBuffer, QueryId queryId, + protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan 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(); } } } diff --git a/src/LibHac/FsSystem/ConcatenationDirectory.cs b/src/LibHac/FsSystem/ConcatenationDirectory.cs index 22d00340..5e3e0ff0 100644 --- a/src/LibHac/FsSystem/ConcatenationDirectory.cs +++ b/src/LibHac/FsSystem/ConcatenationDirectory.cs @@ -38,7 +38,7 @@ namespace LibHac.FsSystem _path.Str[PathTools.MaxPathLength] = StringTraits.NullTerminator; } - public Result Read(out long entriesRead, Span entryBuffer) + protected override Result DoRead(out long entriesRead, Span 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; diff --git a/src/LibHac/FsSystem/ConcatenationFile.cs b/src/LibHac/FsSystem/ConcatenationFile.cs index 3f752a1c..4dc30989 100644 --- a/src/LibHac/FsSystem/ConcatenationFile.cs +++ b/src/LibHac/FsSystem/ConcatenationFile.cs @@ -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 destination, ReadOptionFlag options) + protected override Result DoRead(out long bytesRead, long offset, Span 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 source, WriteOptionFlag options) + protected override Result DoWrite(long offset, ReadOnlySpan 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 outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan inBuffer) + { + return ResultFs.NotImplemented.Log(); + } + protected override Result DoSetSize(long size) { Result rc = GetSize(out long currentSize); diff --git a/src/LibHac/FsSystem/ConcatenationFileSystem.cs b/src/LibHac/FsSystem/ConcatenationFileSystem.cs index 38b9dca4..b65b5cc6 100644 --- a/src/LibHac/FsSystem/ConcatenationFileSystem.cs +++ b/src/LibHac/FsSystem/ConcatenationFileSystem.cs @@ -22,7 +22,7 @@ namespace LibHac.FsSystem /// Each sub-file except the final one must have the size that was specified /// at the creation of the . /// - 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 outBuffer, ReadOnlySpan inBuffer, QueryId queryId, + protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, U8Span path) { if (queryId != QueryId.MakeConcatFile) return ResultFs.UnsupportedOperationInConcatFsQueryEntry.Log(); diff --git a/src/LibHac/FsSystem/DirectorySaveDataFile.cs b/src/LibHac/FsSystem/DirectorySaveDataFile.cs index 1ba9cd86..0a02b6be 100644 --- a/src/LibHac/FsSystem/DirectorySaveDataFile.cs +++ b/src/LibHac/FsSystem/DirectorySaveDataFile.cs @@ -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 destination, ReadOptionFlag options) + protected override Result DoRead(out long bytesRead, long offset, Span 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 source, WriteOptionFlag options) + protected override Result DoWrite(long offset, ReadOnlySpan 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 outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan inBuffer) + { + return BaseFile.OperateRange(outBuffer, operationId, offset, size, inBuffer); + } + protected override void Dispose(bool disposing) { if (Mode.HasFlag(OpenMode.Write)) diff --git a/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs b/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs index a054f283..821b49e1 100644 --- a/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs +++ b/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs @@ -12,7 +12,7 @@ namespace LibHac.FsSystem /// underlying is atomic. /// This class is based on nn::fssystem::DirectorySaveDataFileSystem in SDK 10.4.0 used in FS 10.0.0 /// - 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; diff --git a/src/LibHac/FsSystem/DirectoryUtils.cs b/src/LibHac/FsSystem/DirectoryUtils.cs index 5be86fa0..feaf3659 100644 --- a/src/LibHac/FsSystem/DirectoryUtils.cs +++ b/src/LibHac/FsSystem/DirectoryUtils.cs @@ -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; diff --git a/src/LibHac/FsSystem/FileSystemExtensions.cs b/src/LibHac/FsSystem/FileSystemExtensions.cs index f9ad2701..858cf318 100644 --- a/src/LibHac/FsSystem/FileSystemExtensions.cs +++ b/src/LibHac/FsSystem/FileSystemExtensions.cs @@ -224,12 +224,12 @@ namespace LibHac.FsSystem public static Result Read(this IFile file, out long bytesRead, long offset, Span 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 source) { - return file.Write(offset, source, WriteOptionFlag.None); + return file.Write(offset, source, WriteOption.None); } public static bool DirectoryExists(this IFileSystem fs, string path) diff --git a/src/LibHac/FsSystem/LayeredFileSystem.cs b/src/LibHac/FsSystem/LayeredFileSystem.cs index 0e3ca2ce..d37be7d8 100644 --- a/src/LibHac/FsSystem/LayeredFileSystem.cs +++ b/src/LibHac/FsSystem/LayeredFileSystem.cs @@ -5,7 +5,7 @@ using LibHac.Fs; namespace LibHac.FsSystem { - public class LayeredFileSystem : FileSystemBase + public class LayeredFileSystem : IFileSystem { /// /// List of source 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 outBuffer, ReadOnlySpan inBuffer, QueryId queryId, + protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan 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 entryBuffer) + protected override Result DoRead(out long entriesRead, Span 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; diff --git a/src/LibHac/FsSystem/LocalDirectory.cs b/src/LibHac/FsSystem/LocalDirectory.cs index f7cde12b..12bdf853 100644 --- a/src/LibHac/FsSystem/LocalDirectory.cs +++ b/src/LibHac/FsSystem/LocalDirectory.cs @@ -12,7 +12,7 @@ namespace LibHac.FsSystem private OpenDirectoryMode Mode { get; } private DirectoryInfo DirInfo { get; } private IEnumerator EntryEnumerator { get; } - + public LocalDirectory(IEnumerator entryEnumerator, DirectoryInfo dirInfo, OpenDirectoryMode mode) { @@ -21,7 +21,7 @@ namespace LibHac.FsSystem Mode = mode; } - public Result Read(out long entriesRead, Span entryBuffer) + protected override Result DoRead(out long entriesRead, Span 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; diff --git a/src/LibHac/FsSystem/LocalFile.cs b/src/LibHac/FsSystem/LocalFile.cs index d333ed7d..9cd7c1e6 100644 --- a/src/LibHac/FsSystem/LocalFile.cs +++ b/src/LibHac/FsSystem/LocalFile.cs @@ -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 destination, ReadOptionFlag options) + protected override Result DoRead(out long bytesRead, long offset, Span 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 source, WriteOptionFlag options) + protected override Result DoWrite(long offset, ReadOnlySpan 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 outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan inBuffer) + { + return ResultFs.NotImplemented.Log(); + } + protected override Result DoSetSize(long size) { try diff --git a/src/LibHac/FsSystem/LocalFileSystem.cs b/src/LibHac/FsSystem/LocalFileSystem.cs index 9564194a..99745ee9 100644 --- a/src/LibHac/FsSystem/LocalFileSystem.cs +++ b/src/LibHac/FsSystem/LocalFileSystem.cs @@ -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 outBuffer, ReadOnlySpan inBuffer, QueryId queryId, + protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, U8Span path) { return ResultFs.UnsupportedOperation.Log(); diff --git a/src/LibHac/FsSystem/NullFile.cs b/src/LibHac/FsSystem/NullFile.cs index 1ab3195c..3cd238ee 100644 --- a/src/LibHac/FsSystem/NullFile.cs +++ b/src/LibHac/FsSystem/NullFile.cs @@ -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 destination, ReadOptionFlag options) + protected override Result DoRead(out long bytesRead, long offset, Span 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 source, WriteOptionFlag options) + protected override Result DoWrite(long offset, ReadOnlySpan source, in WriteOption option) { return Result.Success; } @@ -45,6 +46,12 @@ namespace LibHac.FsSystem return Result.Success; } + protected override Result DoOperateRange(Span outBuffer, OperationId operationId, long offset, long size, + ReadOnlySpan inBuffer) + { + return Result.Success; + } + protected override Result DoSetSize(long size) { return ResultFs.UnsupportedOperation.Log(); diff --git a/src/LibHac/FsSystem/PartitionDirectory.cs b/src/LibHac/FsSystem/PartitionDirectory.cs index c66de8f2..d563fc19 100644 --- a/src/LibHac/FsSystem/PartitionDirectory.cs +++ b/src/LibHac/FsSystem/PartitionDirectory.cs @@ -24,7 +24,7 @@ namespace LibHac.FsSystem CurrentIndex = 0; } - public Result Read(out long entriesRead, Span entryBuffer) + protected override Result DoRead(out long entriesRead, Span 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; diff --git a/src/LibHac/FsSystem/PartitionFile.cs b/src/LibHac/FsSystem/PartitionFile.cs index 7e9b2b9e..5cbcf6e7 100644 --- a/src/LibHac/FsSystem/PartitionFile.cs +++ b/src/LibHac/FsSystem/PartitionFile.cs @@ -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 destination, ReadOptionFlag options) + protected override Result DoRead(out long bytesRead, long offset, Span 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 source, WriteOptionFlag options) + protected override Result DoWrite(long offset, ReadOnlySpan 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 outBuffer, OperationId operationId, long offset, long size, + ReadOnlySpan inBuffer) + { + return ResultFs.NotImplemented.Log(); + } + protected override Result DoSetSize(long size) { if (!Mode.HasFlag(OpenMode.Write)) diff --git a/src/LibHac/FsSystem/PartitionFileSystem.cs b/src/LibHac/FsSystem/PartitionFileSystem.cs index 11c514d5..aa299e58 100644 --- a/src/LibHac/FsSystem/PartitionFileSystem.cs +++ b/src/LibHac/FsSystem/PartitionFileSystem.cs @@ -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; } diff --git a/src/LibHac/FsSystem/PartitionFileSystemCore.cs b/src/LibHac/FsSystem/PartitionFileSystemCore.cs index 5c8555d0..5497707d 100644 --- a/src/LibHac/FsSystem/PartitionFileSystemCore.cs +++ b/src/LibHac/FsSystem/PartitionFileSystemCore.cs @@ -7,7 +7,7 @@ using LibHac.FsSystem.Detail; namespace LibHac.FsSystem { - public class PartitionFileSystemCore : FileSystemBase where T : unmanaged, IPartitionFileSystemEntry + public class PartitionFileSystemCore : IFileSystem where T : unmanaged, IPartitionFileSystemEntry { private IStorage BaseStorage { get; set; } private PartitionFileSystemMetaCore 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 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 destination, ReadOptionFlag options) + protected override Result DoRead(out long bytesRead, long offset, Span 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 source, WriteOptionFlag options) + protected override Result DoWrite(long offset, ReadOnlySpan 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 entryBuffer) + protected override Result DoRead(out long entriesRead, Span 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)) { diff --git a/src/LibHac/FsSystem/ReadOnlyFile.cs b/src/LibHac/FsSystem/ReadOnlyFile.cs index a5bc4e44..0c0a2378 100644 --- a/src/LibHac/FsSystem/ReadOnlyFile.cs +++ b/src/LibHac/FsSystem/ReadOnlyFile.cs @@ -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 destination, ReadOptionFlag options) + protected override Result DoRead(out long bytesRead, long offset, Span 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 source, WriteOptionFlag options) + protected override Result DoWrite(long offset, ReadOnlySpan source, in WriteOption option) { return ResultFs.InvalidOpenModeForWrite.Log(); } @@ -36,5 +37,17 @@ namespace LibHac.FsSystem { return ResultFs.InvalidOpenModeForWrite.Log(); } + + protected override Result DoOperateRange(Span outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan inBuffer) + { + switch (operationId) + { + case OperationId.InvalidateCache: + case OperationId.QueryRange: + return BaseFile.OperateRange(outBuffer, operationId, offset, size, inBuffer); + default: + return ResultFs.UnsupportedOperationInReadOnlyFile.Log(); + } + } } } diff --git a/src/LibHac/FsSystem/ReadOnlyFileSystem.cs b/src/LibHac/FsSystem/ReadOnlyFileSystem.cs index c61d959e..72f0d493 100644 --- a/src/LibHac/FsSystem/ReadOnlyFileSystem.cs +++ b/src/LibHac/FsSystem/ReadOnlyFileSystem.cs @@ -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(); } } diff --git a/src/LibHac/FsSystem/RomFs/RomFsDirectory.cs b/src/LibHac/FsSystem/RomFs/RomFsDirectory.cs index 12c19acb..3f5733cc 100644 --- a/src/LibHac/FsSystem/RomFs/RomFsDirectory.cs +++ b/src/LibHac/FsSystem/RomFs/RomFsDirectory.cs @@ -22,12 +22,12 @@ namespace LibHac.FsSystem.RomFs Mode = mode; } - public Result Read(out long entriesRead, Span entryBuffer) + protected override Result DoRead(out long entriesRead, Span entryBuffer) { return ReadImpl(out entriesRead, ref _currentPosition, entryBuffer); } - public Result GetEntryCount(out long entryCount) + protected override Result DoGetEntryCount(out long entryCount) { FindPosition position = InitialPosition; diff --git a/src/LibHac/FsSystem/RomFs/RomFsFile.cs b/src/LibHac/FsSystem/RomFs/RomFsFile.cs index 0d7c1809..22907666 100644 --- a/src/LibHac/FsSystem/RomFs/RomFsFile.cs +++ b/src/LibHac/FsSystem/RomFs/RomFsFile.cs @@ -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 destination, ReadOptionFlag options) + protected override Result DoRead(out long bytesRead, long offset, Span 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 source, WriteOptionFlag options) + protected override Result DoWrite(long offset, ReadOnlySpan 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 outBuffer, OperationId operationId, long offset, long size, + ReadOnlySpan inBuffer) + { + return ResultFs.NotImplemented.Log(); + } } } diff --git a/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs b/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs index fdc7399e..9b7c96fc 100644 --- a/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs +++ b/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs @@ -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(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(); diff --git a/src/LibHac/FsSystem/Save/SaveDataDirectory.cs b/src/LibHac/FsSystem/Save/SaveDataDirectory.cs index a1a4e061..21b70e55 100644 --- a/src/LibHac/FsSystem/Save/SaveDataDirectory.cs +++ b/src/LibHac/FsSystem/Save/SaveDataDirectory.cs @@ -22,12 +22,12 @@ namespace LibHac.FsSystem.Save Mode = mode; } - public Result Read(out long entriesRead, Span entryBuffer) + protected override Result DoRead(out long entriesRead, Span entryBuffer) { return ReadImpl(out entriesRead, ref _currentPosition, entryBuffer); } - public Result GetEntryCount(out long entryCount) + protected override Result DoGetEntryCount(out long entryCount) { SaveFindPosition position = InitialPosition; diff --git a/src/LibHac/FsSystem/Save/SaveDataFile.cs b/src/LibHac/FsSystem/Save/SaveDataFile.cs index fa30796f..a8abd814 100644 --- a/src/LibHac/FsSystem/Save/SaveDataFile.cs +++ b/src/LibHac/FsSystem/Save/SaveDataFile.cs @@ -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 destination, ReadOptionFlag options) + protected override Result DoRead(out long bytesRead, long offset, Span 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 source, WriteOptionFlag options) + protected override Result DoWrite(long offset, ReadOnlySpan 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 outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan inBuffer) + { + return ResultFs.NotImplemented.Log(); + } } } diff --git a/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs b/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs index f36cf6fd..311de5f5 100644 --- a/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs +++ b/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs @@ -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); diff --git a/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs b/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs index a20b56b9..f48c3273 100644 --- a/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs +++ b/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs @@ -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; } diff --git a/src/LibHac/FsSystem/StorageFile.cs b/src/LibHac/FsSystem/StorageFile.cs index ce55682e..9c6d362a 100644 --- a/src/LibHac/FsSystem/StorageFile.cs +++ b/src/LibHac/FsSystem/StorageFile.cs @@ -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 destination, ReadOptionFlag options) + protected override Result DoRead(out long bytesRead, long offset, Span 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 source, WriteOptionFlag options) + protected override Result DoWrite(long offset, ReadOnlySpan 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 outBuffer, OperationId operationId, long offset, long size, + ReadOnlySpan inBuffer) + { + return ResultFs.NotImplemented.Log(); + } } } diff --git a/src/LibHac/FsSystem/StreamFile.cs b/src/LibHac/FsSystem/StreamFile.cs index b1e652cb..f45e1627 100644 --- a/src/LibHac/FsSystem/StreamFile.cs +++ b/src/LibHac/FsSystem/StreamFile.cs @@ -7,7 +7,7 @@ namespace LibHac.FsSystem /// /// Provides an interface for interacting with a /// - 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 destination, ReadOptionFlag options) + protected override Result DoRead(out long bytesRead, long offset, Span 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 source, WriteOptionFlag options) + protected override Result DoWrite(long offset, ReadOnlySpan 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 outBuffer, OperationId operationId, long offset, long size, + ReadOnlySpan inBuffer) + { + return ResultFs.NotImplemented.Log(); + } } } diff --git a/src/LibHac/FsSystem/SubdirectoryFileSystem.cs b/src/LibHac/FsSystem/SubdirectoryFileSystem.cs index d04e7071..1ce09c4f 100644 --- a/src/LibHac/FsSystem/SubdirectoryFileSystem.cs +++ b/src/LibHac/FsSystem/SubdirectoryFileSystem.cs @@ -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 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 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 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 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 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 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 fullOldPath = stackalloc byte[PathTools.MaxPathLength + 1]; Span 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 fullOldPath = stackalloc byte[PathTools.MaxPathLength + 1]; Span 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 outBuffer, ReadOnlySpan inBuffer, QueryId queryId, + protected override Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, U8Span path) { Span fullPath = stackalloc byte[PathTools.MaxPathLength + 1]; diff --git a/src/LibHac/FsSystem/Utility.cs b/src/LibHac/FsSystem/Utility.cs index b7eeaadc..8e03cc33 100644 --- a/src/LibHac/FsSystem/Utility.cs +++ b/src/LibHac/FsSystem/Utility.cs @@ -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; diff --git a/src/LibHac/Kvdb/KeyValueDatabase.cs b/src/LibHac/Kvdb/KeyValueDatabase.cs index 62147c07..1ea5680d 100644 --- a/src/LibHac/Kvdb/KeyValueDatabase.cs +++ b/src/LibHac/Kvdb/KeyValueDatabase.cs @@ -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; diff --git a/src/LibHac/Loader/NsoReader.cs b/src/LibHac/Loader/NsoReader.cs index 628fb25e..17c9039f 100644 --- a/src/LibHac/Loader/NsoReader.cs +++ b/src/LibHac/Loader/NsoReader.cs @@ -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()) @@ -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) diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/CommittableIFileSystemTests.Commit.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/CommittableIFileSystemTests.Commit.cs index 39893cf7..3cda8312 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/CommittableIFileSystemTests.Commit.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/CommittableIFileSystemTests.Commit.cs @@ -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); } diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Read.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Read.cs index 6e06280f..8233e9ba 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Read.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Read.cs @@ -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); } } diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Write.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Write.cs index a004acc2..0c259473 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Write.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Write.cs @@ -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); } } diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameFile.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameFile.cs index 07cdce09..f588af0d 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameFile.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameFile.cs @@ -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());