diff --git a/build/CodeGen/results.csv b/build/CodeGen/results.csv index 57b6c099..dd634f7f 100644 --- a/build/CodeGen/results.csv +++ b/build/CodeGen/results.csv @@ -169,6 +169,8 @@ Module,DescriptionStart,DescriptionEnd,Name,Summary 2,6069,,InvalidCacheStorageSize, 2,6070,,InvalidCacheStorageIndex, 2,6071,,InvalidCommitNameCount,Up to 10 file systems can be committed at the same time. +2,6072,,InvalidOpenMode, +2,6074,,InvalidDirectoryOpenMode, 2,6080,6099,InvalidEnumValue, 2,6081,,InvalidSaveDataState, @@ -198,6 +200,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/DirectoryAccessor.cs b/src/LibHac/Fs/Accessors/DirectoryAccessor.cs index 582e0aa6..21cea24d 100644 --- a/src/LibHac/Fs/Accessors/DirectoryAccessor.cs +++ b/src/LibHac/Fs/Accessors/DirectoryAccessor.cs @@ -1,4 +1,5 @@ using System; +using LibHac.Fs.Fsa; namespace LibHac.Fs.Accessors { diff --git a/src/LibHac/Fs/Accessors/FileAccessor.cs b/src/LibHac/Fs/Accessors/FileAccessor.cs index 030a0e8b..1c341f27 100644 --- a/src/LibHac/Fs/Accessors/FileAccessor.cs +++ b/src/LibHac/Fs/Accessors/FileAccessor.cs @@ -1,8 +1,9 @@ using System; +using LibHac.Fs.Fsa; namespace LibHac.Fs.Accessors { - public class FileAccessor : FileBase + public class FileAccessor : IFile { private IFile File { get; set; } @@ -17,35 +18,36 @@ namespace LibHac.Fs.Accessors OpenMode = mode; } - protected override Result ReadImpl(out long bytesRead, long offset, Span destination, ReadOption 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 WriteImpl(long offset, ReadOnlySpan source, WriteOption options) + protected override Result DoWrite(long offset, ReadOnlySpan source, in WriteOption option) { CheckIfDisposed(); if (source.Length == 0) { - WriteState = (WriteState)(~options & WriteOption.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 & WriteOption.Flush); + WriteState = (WriteState)(~option.Flags & WriteOptionFlag.Flush); } return rc; } - protected override Result FlushImpl() + protected override Result DoFlush() { CheckIfDisposed(); @@ -59,14 +61,19 @@ namespace LibHac.Fs.Accessors return rc; } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { CheckIfDisposed(); return File.GetSize(out size); } - protected override Result SetSizeImpl(long 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/Accessors/FileSystemAccessor.cs b/src/LibHac/Fs/Accessors/FileSystemAccessor.cs index 2178d29b..09e37668 100644 --- a/src/LibHac/Fs/Accessors/FileSystemAccessor.cs +++ b/src/LibHac/Fs/Accessors/FileSystemAccessor.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using LibHac.Common; +using LibHac.Fs.Fsa; namespace LibHac.Fs.Accessors { 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 675ad632..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 ReadImpl(out long bytesRead, long offset, Span destination, ReadOption options); - protected abstract Result WriteImpl(long offset, ReadOnlySpan source, WriteOption options); - protected abstract Result FlushImpl(); - protected abstract Result SetSizeImpl(long size); - protected abstract Result GetSizeImpl(out long size); - - protected virtual Result OperateRangeImpl(Span outBuffer, OperationId operationId, long offset, long size, - ReadOnlySpan inBuffer) - { - return ResultFs.NotImplemented.Log(); - } - - public Result Read(out long bytesRead, long offset, Span destination, ReadOption 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 ReadImpl(out bytesRead, offset, destination, options); - } - - public Result Write(long offset, ReadOnlySpan source, WriteOption options) - { - if (IsDisposed) return ResultFs.PreconditionViolation.Log(); - - if (source.Length == 0) - { - if (options.HasFlag(WriteOption.Flush)) - { - return FlushImpl(); - } - - return Result.Success; - } - - if (offset < 0) return ResultFs.OutOfRange.Log(); - if (long.MaxValue - offset < source.Length) return ResultFs.OutOfRange.Log(); - - return WriteImpl(offset, source, options); - } - - public Result Flush() - { - if (IsDisposed) return ResultFs.PreconditionViolation.Log(); - - return FlushImpl(); - } - - public Result SetSize(long size) - { - if (IsDisposed) return ResultFs.PreconditionViolation.Log(); - if (size < 0) return ResultFs.OutOfRange.Log(); - - return SetSizeImpl(size); - } - - public Result GetSize(out long size) - { - if (IsDisposed) - { - size = default; - return ResultFs.PreconditionViolation.Log(); - } - - return GetSizeImpl(out size); - } - - public Result OperateRange(Span outBuffer, OperationId operationId, long offset, long size, - ReadOnlySpan inBuffer) - { - if (IsDisposed) return ResultFs.PreconditionViolation.Log(); - - return OperateRangeImpl(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/FileHandleStorage.cs b/src/LibHac/Fs/FileHandleStorage.cs index c4a98419..95f103a8 100644 --- a/src/LibHac/Fs/FileHandleStorage.cs +++ b/src/LibHac/Fs/FileHandleStorage.cs @@ -2,7 +2,7 @@ namespace LibHac.Fs { - public class FileHandleStorage : StorageBase + public class FileHandleStorage : IStorage { private const long InvalidSize = -1; private readonly object _locker = new object(); @@ -21,7 +21,7 @@ namespace LibHac.Fs FsClient = Handle.File.Parent.FsClient; } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { lock (_locker) { @@ -36,7 +36,7 @@ namespace LibHac.Fs } } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { lock (_locker) { @@ -51,19 +51,19 @@ namespace LibHac.Fs } } - protected override Result FlushImpl() + protected override Result DoFlush() { return FsClient.FlushFile(Handle); } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { FileSize = InvalidSize; return FsClient.SetFileSize(Handle, size); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = default; diff --git a/src/LibHac/Fs/FileStorage2.cs b/src/LibHac/Fs/FileStorage2.cs index 0a5514b5..80c942bd 100644 --- a/src/LibHac/Fs/FileStorage2.cs +++ b/src/LibHac/Fs/FileStorage2.cs @@ -1,10 +1,11 @@ using System; using System.Diagnostics; using System.Runtime.CompilerServices; +using LibHac.Fs.Fsa; namespace LibHac.Fs { - public class FileStorage2 : StorageBase + public class FileStorage2 : IStorage { protected const long SizeNotInitialized = -1; @@ -39,7 +40,7 @@ namespace LibHac.Fs return Result.Success; } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { if (destination.Length == 0) return Result.Success; @@ -53,7 +54,7 @@ namespace LibHac.Fs return BaseFile.Read(out _, offset, destination, ReadOption.None); } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { if (source.Length == 0) return Result.Success; @@ -67,12 +68,12 @@ namespace LibHac.Fs return BaseFile.Write(offset, source, WriteOption.None); } - protected override Result FlushImpl() + protected override Result DoFlush() { return BaseFile.Flush(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { Result rc = UpdateSize(); if (rc.IsFailure()) @@ -85,13 +86,13 @@ namespace LibHac.Fs return Result.Success; } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { FileSize = SizeNotInitialized; return BaseFile.SetSize(size); } - protected override Result OperateRangeImpl(Span outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan inBuffer) + protected override Result DoOperateRange(Span outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan inBuffer) { switch (operationId) { diff --git a/src/LibHac/Fs/FileStorageBasedFileSystem.cs b/src/LibHac/Fs/FileStorageBasedFileSystem.cs index 35150ad3..843c840b 100644 --- a/src/LibHac/Fs/FileStorageBasedFileSystem.cs +++ b/src/LibHac/Fs/FileStorageBasedFileSystem.cs @@ -1,4 +1,5 @@ using LibHac.Common; +using LibHac.Fs.Fsa; namespace LibHac.Fs { 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 1efe1af6..a2144b6b 100644 --- a/src/LibHac/Fs/FileSystemClient.File.cs +++ b/src/LibHac/Fs/FileSystemClient.File.cs @@ -9,7 +9,7 @@ namespace LibHac.Fs return ReadFile(handle, offset, destination, ReadOption.None); } - public Result ReadFile(FileHandle handle, long offset, Span destination, ReadOption 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; @@ -24,21 +24,21 @@ namespace LibHac.Fs return ReadFile(out bytesRead, handle, offset, destination, ReadOption.None); } - public Result ReadFile(out long bytesRead, FileHandle handle, long offset, Span destination, ReadOption 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; @@ -49,23 +49,23 @@ namespace LibHac.Fs return WriteFile(handle, offset, source, WriteOption.None); } - public Result WriteFile(FileHandle handle, long offset, ReadOnlySpan source, WriteOption 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 & WriteOption.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/FileSystemClient.FileSystem.cs b/src/LibHac/Fs/FileSystemClient.FileSystem.cs index 73e40b0b..0d8aff2f 100644 --- a/src/LibHac/Fs/FileSystemClient.FileSystem.cs +++ b/src/LibHac/Fs/FileSystemClient.FileSystem.cs @@ -1,6 +1,7 @@ using System; using LibHac.Common; using LibHac.Fs.Accessors; +using LibHac.Fs.Fsa; namespace LibHac.Fs { diff --git a/src/LibHac/Fs/FileSystemClient.cs b/src/LibHac/Fs/FileSystemClient.cs index bb7e0c71..e63415e1 100644 --- a/src/LibHac/Fs/FileSystemClient.cs +++ b/src/LibHac/Fs/FileSystemClient.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.Runtime.InteropServices; using LibHac.Common; using LibHac.Fs.Accessors; +using LibHac.Fs.Fsa; using LibHac.FsService; using LibHac.FsSystem; diff --git a/src/LibHac/Fs/FileSystemClientUtils.cs b/src/LibHac/Fs/FileSystemClientUtils.cs index b104af69..331e209b 100644 --- a/src/LibHac/Fs/FileSystemClientUtils.cs +++ b/src/LibHac/Fs/FileSystemClientUtils.cs @@ -3,6 +3,7 @@ using System.Buffers; using System.Collections.Generic; using LibHac.Common; using LibHac.Fs.Accessors; +using LibHac.Fs.Fsa; using LibHac.FsSystem; namespace LibHac.Fs diff --git a/src/LibHac/Fs/FsEnums.cs b/src/LibHac/Fs/FsEnums.cs index 4704a82d..a39a281d 100644 --- a/src/LibHac/Fs/FsEnums.cs +++ b/src/LibHac/Fs/FsEnums.cs @@ -1,4 +1,5 @@ using System; +using LibHac.Fs.Fsa; namespace LibHac.Fs { @@ -127,18 +128,11 @@ namespace LibHac.Fs } [Flags] - public enum ReadOption + public enum ReadOptionFlag { None = 0 } - [Flags] - public enum WriteOption - { - None = 0, - Flush = 1 - } - public enum OperationId { Clear = 0, diff --git a/src/LibHac/Fs/Fsa/IAttributeFileSystem.cs b/src/LibHac/Fs/Fsa/IAttributeFileSystem.cs new file mode 100644 index 00000000..7e2af4b6 --- /dev/null +++ b/src/LibHac/Fs/Fsa/IAttributeFileSystem.cs @@ -0,0 +1,51 @@ +using LibHac.Common; + +namespace LibHac.Fs.Fsa +{ + // ReSharper disable once InconsistentNaming + public abstract class IAttributeFileSystem : IFileSystem + { + 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/Fsa/IDirectory.cs similarity index 60% rename from src/LibHac/Fs/IDirectory.cs rename to src/LibHac/Fs/Fsa/IDirectory.cs index 401d26d7..3d5012fa 100644 --- a/src/LibHac/Fs/IDirectory.cs +++ b/src/LibHac/Fs/Fsa/IDirectory.cs @@ -1,11 +1,12 @@ using System; -namespace LibHac.Fs +namespace LibHac.Fs.Fsa { + // 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/Fsa/IFile.cs b/src/LibHac/Fs/Fsa/IFile.cs new file mode 100644 index 00000000..ed5361bc --- /dev/null +++ b/src/LibHac/Fs/Fsa/IFile.cs @@ -0,0 +1,248 @@ +using System; +using LibHac.Diag; + +namespace LibHac.Fs.Fsa +{ + // ReSharper disable once InconsistentNaming + /// + /// Provides an interface for reading and writing a sequence of bytes. + /// + /// is similar to , and has a few main differences: + /// + /// - allows an to be set that controls read, write + /// and append permissions for the file. + /// + /// - If the cannot read or write as many bytes as requested, it will read + /// or write as many bytes as it can and return that number of bytes to the caller. + /// + /// - 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 abstract class IFile : IDisposable + { + /// + /// Reads a sequence of bytes from the current . + /// + /// 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. + /// Options for reading from the . + /// The of the requested operation. + 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 . + /// The of the requested operation. + 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. + /// + 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. + 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. + public Result GetSize(out long size) + { + return DoGetSize(out size); + } + + /// + /// Performs various operations on the file. Used to extend the functionality of the interface. + /// + /// A buffer that will contain the response from the operation. + /// The operation to be performed. + /// The offset of the range to operate on. + /// The size of the range to operate on. + /// An input buffer. Size may vary depending on the operation performed. + /// The of the requested operation. + 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); + } + } +} diff --git a/src/LibHac/Fs/IFileSystem.cs b/src/LibHac/Fs/Fsa/IFileSystem.cs similarity index 61% rename from src/LibHac/Fs/IFileSystem.cs rename to src/LibHac/Fs/Fsa/IFileSystem.cs index 99415b6b..df54e17b 100644 --- a/src/LibHac/Fs/IFileSystem.cs +++ b/src/LibHac/Fs/Fsa/IFileSystem.cs @@ -2,19 +2,20 @@ using LibHac.Common; using LibHac.FsSystem; -namespace LibHac.Fs +namespace LibHac.Fs.Fsa { + // 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/IAttributeFileSystem.cs b/src/LibHac/Fs/IAttributeFileSystem.cs deleted file mode 100644 index 39cdf430..00000000 --- a/src/LibHac/Fs/IAttributeFileSystem.cs +++ /dev/null @@ -1,12 +0,0 @@ -using LibHac.Common; - -namespace LibHac.Fs -{ - public interface 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); - } -} diff --git a/src/LibHac/Fs/IFile.cs b/src/LibHac/Fs/IFile.cs deleted file mode 100644 index 29746104..00000000 --- a/src/LibHac/Fs/IFile.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; - -namespace LibHac.Fs -{ - /// - /// Provides an interface for reading and writing a sequence of bytes. - /// - /// is similar to , and has a few main differences: - /// - /// - allows an to be set that controls read, write - /// and append permissions for the file. - /// - /// - If the cannot read or write as many bytes as requested, it will read - /// or write as many bytes as it can and return that number of bytes to the caller. - /// - /// - 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 - { - /// - /// Reads a sequence of bytes from the current . - /// - /// 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. - /// Options for reading from the . - /// The of the requested operation. - Result Read(out long bytesRead, long offset, Span destination, ReadOption options); - - /// - /// 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 . - /// The of the requested operation. - Result Write(long offset, ReadOnlySpan source, WriteOption options); - - /// - /// Causes any buffered data to be written to the underlying device. - /// - Result Flush(); - - /// - /// 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); - - /// - /// 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); - - /// - /// Performs various operations on the file. Used to extend the functionality of the interface. - /// - /// A buffer that will contain the response from the operation. - /// The operation to be performed. - /// The offset of the range to operate on. - /// 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, - ReadOnlySpan inBuffer); - } -} \ No newline at end of file diff --git a/src/LibHac/Fs/IFile2.cs b/src/LibHac/Fs/IFile2.cs new file mode 100644 index 00000000..567826fc --- /dev/null +++ b/src/LibHac/Fs/IFile2.cs @@ -0,0 +1,39 @@ +using System; + +namespace LibHac.Fs +{ + public readonly struct ReadOption + { + public readonly int Value; + + // ReSharper disable once UnusedMember.Local + private ReadOption(int value) + { + Value = value; + } + + public static ReadOption None => default; + } + + public readonly struct WriteOption + { + public readonly WriteOptionFlag Flags; + + private WriteOption(WriteOptionFlag flags) + { + Flags = flags; + } + + public bool HasFlushFlag() => Flags.HasFlag(WriteOptionFlag.Flush); + + public static WriteOption None => default; + public static WriteOption Flush => new WriteOption(WriteOptionFlag.Flush); + } + + [Flags] + public enum WriteOptionFlag + { + None = 0, + Flush = 1 + } +} diff --git a/src/LibHac/Fs/IStorage.cs b/src/LibHac/Fs/IStorage.cs index 455388ef..05121695 100644 --- a/src/LibHac/Fs/IStorage.cs +++ b/src/LibHac/Fs/IStorage.cs @@ -1,47 +1,97 @@ using System; +using System.Runtime.CompilerServices; +using System.Threading; namespace LibHac.Fs { + // ReSharper disable once InconsistentNaming /// /// Provides an interface for reading and writing a sequence of bytes. /// - public interface IStorage : IDisposable + /// + /// The official IStorage makes the Read etc. methods abstract and doesn't + /// have DoRead etc. methods. We're using them here so we can make sure + /// the object isn't disposed before calling the method implementation. + /// + public abstract class IStorage : IDisposable { + // 0 = not disposed; 1 = disposed + private int _disposedState; + private bool IsDisposed => _disposedState != 0; + /// /// Reads a sequence of bytes from the current . /// + /// 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 equal to the length of the buffer. - /// The offset in the at which to begin reading. - /// Invalid offset or the IStorage contains fewer bytes than requested. - Result Read(long offset, Span destination); + /// The of the operation. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Result Read(long offset, Span destination) + { + if (IsDisposed) + return ResultFs.PreconditionViolation.Log(); + + return DoRead(offset, destination); + } /// /// Writes a sequence of bytes to the current . /// - /// The buffer containing the bytes to be written. /// The offset in the at which to begin writing. - /// Invalid offset or - /// is too large to be written to the IStorage. - Result Write(long offset, ReadOnlySpan source); + /// The buffer containing the bytes to be written. + /// The of the operation. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Result Write(long offset, ReadOnlySpan source) + { + if (IsDisposed) + return ResultFs.PreconditionViolation.Log(); + + return DoWrite(offset, source); + } /// /// Causes any buffered data to be written to the underlying device. /// - Result Flush(); + /// The of the operation. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Result Flush() + { + if (IsDisposed) + return ResultFs.PreconditionViolation.Log(); + + return DoFlush(); + } /// - /// Sets the size of the current IStorage. + /// Sets the size of the current . /// - /// The desired size of the current IStorage in bytes. - Result SetSize(long size); + /// The desired size of the in bytes. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Result SetSize(long size) + { + if (IsDisposed) + return ResultFs.PreconditionViolation.Log(); + + return DoSetSize(size); + } /// - /// The size of the. -1 will be returned if - /// the cannot be represented as a sequence of contiguous bytes. + /// Gets the number of bytes in the . /// - /// The size of the in bytes. - Result GetSize(out long size); + /// If the operation returns successfully, the length of the file in bytes. + /// The of the operation. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Result GetSize(out long size) + { + if (IsDisposed) + { + size = default; + return ResultFs.PreconditionViolation.Log(); + } + + return DoGetSize(out size); + } /// /// Performs various operations on the file. Used to extend the functionality of the interface. @@ -51,8 +101,56 @@ namespace LibHac.Fs /// The offset of the range to operate on. /// 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, - ReadOnlySpan inBuffer); + /// The of the operation. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + 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); + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsRangeValid(long offset, long size, long totalSize) + { + return offset >= 0 && + size >= 0 && + size <= totalSize && + offset <= totalSize - size; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsOffsetAndSizeValid(long offset, long size) + { + return offset >= 0 && + size >= 0 && + offset <= offset - size; + } + + protected abstract Result DoRead(long offset, Span destination); + protected abstract Result DoWrite(long offset, ReadOnlySpan source); + protected abstract Result DoFlush(); + protected abstract Result DoGetSize(out long size); + protected abstract Result DoSetSize(long size); + + protected virtual Result DoOperateRange(Span outBuffer, OperationId operationId, long offset, long size, + ReadOnlySpan inBuffer) + { + return ResultFs.NotImplemented.Log(); + } + + 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/InMemoryFileSystem.cs b/src/LibHac/Fs/InMemoryFileSystem.cs index 048e5dbf..f6513919 100644 --- a/src/LibHac/Fs/InMemoryFileSystem.cs +++ b/src/LibHac/Fs/InMemoryFileSystem.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.IO; using LibHac.Common; +using LibHac.Fs.Fsa; using LibHac.FsSystem; namespace LibHac.Fs @@ -9,7 +10,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 +19,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 +36,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 +47,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 +78,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 +90,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 +118,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 +141,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 +158,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 +170,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 +181,8 @@ namespace LibHac.Fs Mode = mode; } - protected override Result ReadImpl(out long bytesRead, long offset, Span destination, ReadOption options) + protected override Result DoRead(out long bytesRead, long offset, Span destination, + in ReadOption option) { if (!Mode.HasFlag(OpenMode.Read)) { @@ -191,7 +193,7 @@ namespace LibHac.Fs return BaseStream.Read(out bytesRead, offset, destination); } - protected override Result WriteImpl(long offset, ReadOnlySpan source, WriteOption options) + protected override Result DoWrite(long offset, ReadOnlySpan source, in WriteOption option) { if (!Mode.HasFlag(OpenMode.Write)) { @@ -201,20 +203,25 @@ namespace LibHac.Fs return BaseStream.Write(offset, source, Mode.HasFlag(OpenMode.AllowAppend)); } - protected override Result FlushImpl() + protected override Result DoFlush() { return BaseStream.Flush(); } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { return BaseStream.SetSize(size); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { 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 +239,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 +290,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/MemoryStorage.cs b/src/LibHac/Fs/MemoryStorage.cs index 511610f2..4b0e8f12 100644 --- a/src/LibHac/Fs/MemoryStorage.cs +++ b/src/LibHac/Fs/MemoryStorage.cs @@ -2,7 +2,7 @@ namespace LibHac.Fs { - public class MemoryStorage : StorageBase + public class MemoryStorage : IStorage { private byte[] StorageBuffer { get; } @@ -11,7 +11,7 @@ namespace LibHac.Fs StorageBuffer = buffer; } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { if (destination.Length == 0) return Result.Success; @@ -24,7 +24,7 @@ namespace LibHac.Fs return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { if (source.Length == 0) return Result.Success; @@ -37,17 +37,17 @@ namespace LibHac.Fs return Result.Success; } - protected override Result FlushImpl() + protected override Result DoFlush() { return Result.Success; } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { return ResultFs.UnsupportedOperationInMemoryStorageSetSize.Log(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = StorageBuffer.Length; diff --git a/src/LibHac/Fs/ResultFs.cs b/src/LibHac/Fs/ResultFs.cs index 419eceb3..f2af9707 100644 --- a/src/LibHac/Fs/ResultFs.cs +++ b/src/LibHac/Fs/ResultFs.cs @@ -331,6 +331,10 @@ namespace LibHac.Fs public static Result.Base InvalidCacheStorageIndex => new Result.Base(ModuleFs, 6070); /// Up to 10 file systems can be committed at the same time.
Error code: 2002-6071; Inner value: 0x2f6e02
public static Result.Base InvalidCommitNameCount => new Result.Base(ModuleFs, 6071); + /// Error code: 2002-6072; Inner value: 0x2f7002 + public static Result.Base InvalidOpenMode => new Result.Base(ModuleFs, 6072); + /// Error code: 2002-6074; Inner value: 0x2f7402 + public static Result.Base InvalidDirectoryOpenMode => new Result.Base(ModuleFs, 6074); /// Error code: 2002-6080; Range: 6080-6099; Inner value: 0x2f8002 public static Result.Base InvalidEnumValue { [MethodImpl(MethodImplOptions.AggressiveInlining)] get => new Result.Base(ModuleFs, 6080, 6099); } @@ -386,6 +390,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/Fs/Shim/Application.cs b/src/LibHac/Fs/Shim/Application.cs index 109aa08e..e76cd176 100644 --- a/src/LibHac/Fs/Shim/Application.cs +++ b/src/LibHac/Fs/Shim/Application.cs @@ -1,5 +1,6 @@ using System; using LibHac.Common; +using LibHac.Fs.Fsa; using LibHac.FsService; using LibHac.FsSystem; diff --git a/src/LibHac/Fs/Shim/BcatSaveData.cs b/src/LibHac/Fs/Shim/BcatSaveData.cs index 05a5542a..98e3fa71 100644 --- a/src/LibHac/Fs/Shim/BcatSaveData.cs +++ b/src/LibHac/Fs/Shim/BcatSaveData.cs @@ -1,5 +1,6 @@ using System; using LibHac.Common; +using LibHac.Fs.Fsa; using LibHac.FsService; using LibHac.Ncm; diff --git a/src/LibHac/Fs/Shim/Bis.cs b/src/LibHac/Fs/Shim/Bis.cs index ba4f5ba5..283b52b8 100644 --- a/src/LibHac/Fs/Shim/Bis.cs +++ b/src/LibHac/Fs/Shim/Bis.cs @@ -1,6 +1,7 @@ using System; using System.Diagnostics; using LibHac.Common; +using LibHac.Fs.Fsa; using LibHac.FsService; using LibHac.FsSystem; using static LibHac.Fs.CommonMountNames; diff --git a/src/LibHac/Fs/Shim/Content.cs b/src/LibHac/Fs/Shim/Content.cs index 86435b44..5cc6c083 100644 --- a/src/LibHac/Fs/Shim/Content.cs +++ b/src/LibHac/Fs/Shim/Content.cs @@ -1,5 +1,6 @@ using System; using LibHac.Common; +using LibHac.Fs.Fsa; using LibHac.FsService; using LibHac.FsSystem; using LibHac.Ncm; diff --git a/src/LibHac/Fs/Shim/ContentStorage.cs b/src/LibHac/Fs/Shim/ContentStorage.cs index 3efa8c21..2e7324d0 100644 --- a/src/LibHac/Fs/Shim/ContentStorage.cs +++ b/src/LibHac/Fs/Shim/ContentStorage.cs @@ -1,5 +1,6 @@ using System; using LibHac.Common; +using LibHac.Fs.Fsa; using LibHac.FsService; namespace LibHac.Fs.Shim diff --git a/src/LibHac/Fs/Shim/CustomStorage.cs b/src/LibHac/Fs/Shim/CustomStorage.cs index d377e81b..8f751dc6 100644 --- a/src/LibHac/Fs/Shim/CustomStorage.cs +++ b/src/LibHac/Fs/Shim/CustomStorage.cs @@ -1,5 +1,6 @@ using System; using LibHac.Common; +using LibHac.Fs.Fsa; using LibHac.FsService; namespace LibHac.Fs.Shim diff --git a/src/LibHac/Fs/Shim/GameCard.cs b/src/LibHac/Fs/Shim/GameCard.cs index 0535a188..50123fc7 100644 --- a/src/LibHac/Fs/Shim/GameCard.cs +++ b/src/LibHac/Fs/Shim/GameCard.cs @@ -1,5 +1,6 @@ using System; using LibHac.Common; +using LibHac.Fs.Fsa; using LibHac.FsService; namespace LibHac.Fs.Shim diff --git a/src/LibHac/Fs/Shim/Host.cs b/src/LibHac/Fs/Shim/Host.cs index e26fae22..c16849d4 100644 --- a/src/LibHac/Fs/Shim/Host.cs +++ b/src/LibHac/Fs/Shim/Host.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; using LibHac.Common; +using LibHac.Fs.Fsa; using LibHac.FsService; using LibHac.FsSystem; using static LibHac.Fs.CommonMountNames; diff --git a/src/LibHac/Fs/Shim/SaveData.cs b/src/LibHac/Fs/Shim/SaveData.cs index 6f4ff330..8fde8f76 100644 --- a/src/LibHac/Fs/Shim/SaveData.cs +++ b/src/LibHac/Fs/Shim/SaveData.cs @@ -1,5 +1,6 @@ using System; using LibHac.Common; +using LibHac.Fs.Fsa; using LibHac.FsService; using LibHac.Ncm; diff --git a/src/LibHac/Fs/Shim/SdCard.cs b/src/LibHac/Fs/Shim/SdCard.cs index d0504001..3be963d9 100644 --- a/src/LibHac/Fs/Shim/SdCard.cs +++ b/src/LibHac/Fs/Shim/SdCard.cs @@ -1,5 +1,6 @@ using System; using LibHac.Common; +using LibHac.Fs.Fsa; using LibHac.FsService; namespace LibHac.Fs.Shim diff --git a/src/LibHac/Fs/Shim/SystemSaveData.cs b/src/LibHac/Fs/Shim/SystemSaveData.cs index 3bb55ef0..af98ef99 100644 --- a/src/LibHac/Fs/Shim/SystemSaveData.cs +++ b/src/LibHac/Fs/Shim/SystemSaveData.cs @@ -1,4 +1,5 @@ using LibHac.Common; +using LibHac.Fs.Fsa; using LibHac.FsService; namespace LibHac.Fs.Shim diff --git a/src/LibHac/Fs/StorageBase.cs b/src/LibHac/Fs/StorageBase.cs deleted file mode 100644 index 1ea1789b..00000000 --- a/src/LibHac/Fs/StorageBase.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Runtime.CompilerServices; -using System.Threading; - -namespace LibHac.Fs -{ - public abstract class StorageBase : IStorage - { - // 0 = not disposed; 1 = disposed - private int _disposedState; - private bool IsDisposed => _disposedState != 0; - - protected abstract Result ReadImpl(long offset, Span destination); - protected abstract Result WriteImpl(long offset, ReadOnlySpan source); - protected abstract Result FlushImpl(); - protected abstract Result GetSizeImpl(out long size); - protected abstract Result SetSizeImpl(long size); - - protected virtual Result OperateRangeImpl(Span outBuffer, OperationId operationId, long offset, long size, - ReadOnlySpan inBuffer) - { - return ResultFs.NotImplemented.Log(); - } - - public Result Read(long offset, Span destination) - { - if (IsDisposed) return ResultFs.PreconditionViolation.Log(); - - return ReadImpl(offset, destination); - } - - public Result Write(long offset, ReadOnlySpan source) - { - if (IsDisposed) return ResultFs.PreconditionViolation.Log(); - - return WriteImpl(offset, source); - } - - public Result Flush() - { - if (IsDisposed) return ResultFs.PreconditionViolation.Log(); - - return FlushImpl(); - } - - public Result SetSize(long size) - { - if (IsDisposed) return ResultFs.PreconditionViolation.Log(); - - return SetSizeImpl(size); - } - - public Result GetSize(out long size) - { - size = default; - if (IsDisposed) return ResultFs.PreconditionViolation.Log(); - - return GetSizeImpl(out size); - } - - public Result OperateRange(Span outBuffer, OperationId operationId, long offset, long size, - ReadOnlySpan inBuffer) - { - if (IsDisposed) return ResultFs.PreconditionViolation.Log(); - - return OperateRange(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) { } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsRangeValid(long offset, long size, long totalSize) - { - return offset >= 0 && size >= 0 && size <= totalSize && offset <= totalSize - size; - } - } -} diff --git a/src/LibHac/Fs/SubStorage2.cs b/src/LibHac/Fs/SubStorage2.cs index af9f7b48..3f459d7d 100644 --- a/src/LibHac/Fs/SubStorage2.cs +++ b/src/LibHac/Fs/SubStorage2.cs @@ -2,7 +2,7 @@ namespace LibHac.Fs { - public class SubStorage2 : StorageBase + public class SubStorage2 : IStorage { private IStorage BaseStorage { get; } private long Offset { get; } @@ -23,7 +23,7 @@ namespace LibHac.Fs Size = size; } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { if (BaseStorage == null) return ResultFs.SubStorageNotInitialized.Log(); if (destination.Length == 0) return Result.Success; @@ -33,7 +33,7 @@ namespace LibHac.Fs return BaseStorage.Read(Offset + offset, destination); } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { if (BaseStorage == null) return ResultFs.SubStorageNotInitialized.Log(); if (source.Length == 0) return Result.Success; @@ -43,14 +43,14 @@ namespace LibHac.Fs return BaseStorage.Write(Offset + offset, source); } - protected override Result FlushImpl() + protected override Result DoFlush() { if (BaseStorage == null) return ResultFs.SubStorageNotInitialized.Log(); return BaseStorage.Flush(); } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { if (BaseStorage == null) return ResultFs.SubStorageNotInitialized.Log(); if (!IsResizable) return ResultFs.SubStorageNotResizable.Log(); @@ -72,7 +72,7 @@ namespace LibHac.Fs return Result.Success; } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = default; diff --git a/src/LibHac/FsService/Creators/EmulatedBisFileSystemCreator.cs b/src/LibHac/FsService/Creators/EmulatedBisFileSystemCreator.cs index 2cf17e25..467f21e0 100644 --- a/src/LibHac/FsService/Creators/EmulatedBisFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/EmulatedBisFileSystemCreator.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsService.Creators { diff --git a/src/LibHac/FsService/Creators/EmulatedBisFileSystemCreatorConfig.cs b/src/LibHac/FsService/Creators/EmulatedBisFileSystemCreatorConfig.cs index 90b75a58..1dbe7b52 100644 --- a/src/LibHac/FsService/Creators/EmulatedBisFileSystemCreatorConfig.cs +++ b/src/LibHac/FsService/Creators/EmulatedBisFileSystemCreatorConfig.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsService.Creators { diff --git a/src/LibHac/FsService/Creators/EmulatedGameCardFsCreator.cs b/src/LibHac/FsService/Creators/EmulatedGameCardFsCreator.cs index f5fc1f71..3f1738d5 100644 --- a/src/LibHac/FsService/Creators/EmulatedGameCardFsCreator.cs +++ b/src/LibHac/FsService/Creators/EmulatedGameCardFsCreator.cs @@ -1,4 +1,5 @@ using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsService.Creators { diff --git a/src/LibHac/FsService/Creators/EmulatedGameCardStorageCreator.cs b/src/LibHac/FsService/Creators/EmulatedGameCardStorageCreator.cs index c8dc4bb7..11de4dc1 100644 --- a/src/LibHac/FsService/Creators/EmulatedGameCardStorageCreator.cs +++ b/src/LibHac/FsService/Creators/EmulatedGameCardStorageCreator.cs @@ -62,7 +62,7 @@ namespace LibHac.FsService.Creators throw new NotImplementedException(); } - private class ReadOnlyGameCardStorage : StorageBase + private class ReadOnlyGameCardStorage : IStorage { private EmulatedGameCard GameCard { get; } private GameCardHandle Handle { get; set; } @@ -87,7 +87,7 @@ namespace LibHac.FsService.Creators imageHash.CopyTo(ImageHash); } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { // In secure mode, if Handle is old and the card's device ID and // header hash are still the same, Handle is updated to the new handle @@ -95,22 +95,22 @@ namespace LibHac.FsService.Creators return GameCard.Read(Handle, offset, destination); } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { return ResultFs.UnsupportedOperationInRoGameCardStorageWrite.Log(); } - protected override Result FlushImpl() + protected override Result DoFlush() { return Result.Success; } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { return ResultFs.UnsupportedOperationInRoGameCardStorageSetSize.Log(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = 0; diff --git a/src/LibHac/FsService/Creators/EmulatedSdFileSystemCreator.cs b/src/LibHac/FsService/Creators/EmulatedSdFileSystemCreator.cs index ce13dc4c..881a7ba8 100644 --- a/src/LibHac/FsService/Creators/EmulatedSdFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/EmulatedSdFileSystemCreator.cs @@ -1,5 +1,6 @@ using System; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsService.Creators { diff --git a/src/LibHac/FsService/Creators/EncryptedFileSystemCreator.cs b/src/LibHac/FsService/Creators/EncryptedFileSystemCreator.cs index 11d751bb..2493935f 100644 --- a/src/LibHac/FsService/Creators/EncryptedFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/EncryptedFileSystemCreator.cs @@ -1,5 +1,6 @@ using System; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; namespace LibHac.FsService.Creators diff --git a/src/LibHac/FsService/Creators/IBuiltInStorageFileSystemCreator.cs b/src/LibHac/FsService/Creators/IBuiltInStorageFileSystemCreator.cs index b94ca90a..0ad90fcd 100644 --- a/src/LibHac/FsService/Creators/IBuiltInStorageFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/IBuiltInStorageFileSystemCreator.cs @@ -1,4 +1,5 @@ using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsService.Creators { diff --git a/src/LibHac/FsService/Creators/IEncryptedFileSystemCreator.cs b/src/LibHac/FsService/Creators/IEncryptedFileSystemCreator.cs index f6cfde96..b1445988 100644 --- a/src/LibHac/FsService/Creators/IEncryptedFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/IEncryptedFileSystemCreator.cs @@ -1,5 +1,5 @@ using System; -using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsService.Creators { diff --git a/src/LibHac/FsService/Creators/IFatFileSystemCreator.cs b/src/LibHac/FsService/Creators/IFatFileSystemCreator.cs index b86fac56..8a763db8 100644 --- a/src/LibHac/FsService/Creators/IFatFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/IFatFileSystemCreator.cs @@ -1,4 +1,5 @@ using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsService.Creators { diff --git a/src/LibHac/FsService/Creators/IGameCardFileSystemCreator.cs b/src/LibHac/FsService/Creators/IGameCardFileSystemCreator.cs index 550ce9c6..a6e98e38 100644 --- a/src/LibHac/FsService/Creators/IGameCardFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/IGameCardFileSystemCreator.cs @@ -1,4 +1,5 @@ using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsService.Creators { diff --git a/src/LibHac/FsService/Creators/IHostFileSystemCreator.cs b/src/LibHac/FsService/Creators/IHostFileSystemCreator.cs index d7c50ff5..109de58f 100644 --- a/src/LibHac/FsService/Creators/IHostFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/IHostFileSystemCreator.cs @@ -1,4 +1,4 @@ -using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsService.Creators { diff --git a/src/LibHac/FsService/Creators/IPartitionFileSystemCreator.cs b/src/LibHac/FsService/Creators/IPartitionFileSystemCreator.cs index af99e8cd..44140ba2 100644 --- a/src/LibHac/FsService/Creators/IPartitionFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/IPartitionFileSystemCreator.cs @@ -1,4 +1,5 @@ using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsService.Creators { diff --git a/src/LibHac/FsService/Creators/IRomFileSystemCreator.cs b/src/LibHac/FsService/Creators/IRomFileSystemCreator.cs index b2ea3957..0f141424 100644 --- a/src/LibHac/FsService/Creators/IRomFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/IRomFileSystemCreator.cs @@ -1,4 +1,5 @@ using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsService.Creators { diff --git a/src/LibHac/FsService/Creators/ISaveDataFileSystemCreator.cs b/src/LibHac/FsService/Creators/ISaveDataFileSystemCreator.cs index dd62d5ee..08a1d955 100644 --- a/src/LibHac/FsService/Creators/ISaveDataFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/ISaveDataFileSystemCreator.cs @@ -1,6 +1,7 @@ using System; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem.Save; namespace LibHac.FsService.Creators diff --git a/src/LibHac/FsService/Creators/ISdFileSystemCreator.cs b/src/LibHac/FsService/Creators/ISdFileSystemCreator.cs index 041f0217..b368a5a9 100644 --- a/src/LibHac/FsService/Creators/ISdFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/ISdFileSystemCreator.cs @@ -1,4 +1,4 @@ -using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsService.Creators { diff --git a/src/LibHac/FsService/Creators/IStorageOnNcaCreator.cs b/src/LibHac/FsService/Creators/IStorageOnNcaCreator.cs index 2d6d8fb3..274aa426 100644 --- a/src/LibHac/FsService/Creators/IStorageOnNcaCreator.cs +++ b/src/LibHac/FsService/Creators/IStorageOnNcaCreator.cs @@ -1,4 +1,5 @@ using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem.NcaUtils; namespace LibHac.FsService.Creators diff --git a/src/LibHac/FsService/Creators/ISubDirectoryFileSystemCreator.cs b/src/LibHac/FsService/Creators/ISubDirectoryFileSystemCreator.cs index a3510a46..39d021c4 100644 --- a/src/LibHac/FsService/Creators/ISubDirectoryFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/ISubDirectoryFileSystemCreator.cs @@ -1,5 +1,5 @@ using LibHac.Common; -using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsService.Creators { diff --git a/src/LibHac/FsService/Creators/ITargetManagerFileSystemCreator.cs b/src/LibHac/FsService/Creators/ITargetManagerFileSystemCreator.cs index cae86243..550be0c7 100644 --- a/src/LibHac/FsService/Creators/ITargetManagerFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/ITargetManagerFileSystemCreator.cs @@ -1,5 +1,5 @@ using System; -using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsService.Creators { diff --git a/src/LibHac/FsService/Creators/PartitionFileSystemCreator.cs b/src/LibHac/FsService/Creators/PartitionFileSystemCreator.cs index 3d78508f..e508faeb 100644 --- a/src/LibHac/FsService/Creators/PartitionFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/PartitionFileSystemCreator.cs @@ -1,4 +1,5 @@ using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; using LibHac.FsSystem.Detail; diff --git a/src/LibHac/FsService/Creators/RomFileSystemCreator.cs b/src/LibHac/FsService/Creators/RomFileSystemCreator.cs index a1309b51..8b8bb5b6 100644 --- a/src/LibHac/FsService/Creators/RomFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/RomFileSystemCreator.cs @@ -1,4 +1,5 @@ using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem.RomFs; namespace LibHac.FsService.Creators diff --git a/src/LibHac/FsService/Creators/SaveDataFileSystemCreator.cs b/src/LibHac/FsService/Creators/SaveDataFileSystemCreator.cs index 997954d3..6d44022b 100644 --- a/src/LibHac/FsService/Creators/SaveDataFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/SaveDataFileSystemCreator.cs @@ -1,6 +1,7 @@ using System; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; using LibHac.FsSystem.Save; diff --git a/src/LibHac/FsService/Creators/StorageOnNcaCreator.cs b/src/LibHac/FsService/Creators/StorageOnNcaCreator.cs index f93c12d4..85455dec 100644 --- a/src/LibHac/FsService/Creators/StorageOnNcaCreator.cs +++ b/src/LibHac/FsService/Creators/StorageOnNcaCreator.cs @@ -1,5 +1,6 @@ using System; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; using LibHac.FsSystem.Detail; using LibHac.FsSystem.NcaUtils; diff --git a/src/LibHac/FsService/Creators/SubDirectoryFileSystemCreator.cs b/src/LibHac/FsService/Creators/SubDirectoryFileSystemCreator.cs index 9ddbc677..bc36c475 100644 --- a/src/LibHac/FsService/Creators/SubDirectoryFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/SubDirectoryFileSystemCreator.cs @@ -1,5 +1,5 @@ using LibHac.Common; -using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; namespace LibHac.FsService.Creators diff --git a/src/LibHac/FsService/Creators/TargetManagerFileSystemCreator.cs b/src/LibHac/FsService/Creators/TargetManagerFileSystemCreator.cs index 1ccefcc8..5834b5f4 100644 --- a/src/LibHac/FsService/Creators/TargetManagerFileSystemCreator.cs +++ b/src/LibHac/FsService/Creators/TargetManagerFileSystemCreator.cs @@ -1,5 +1,5 @@ using System; -using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsService.Creators { diff --git a/src/LibHac/FsService/DefaultFsServerObjects.cs b/src/LibHac/FsService/DefaultFsServerObjects.cs index c71c406a..5fbed7f4 100644 --- a/src/LibHac/FsService/DefaultFsServerObjects.cs +++ b/src/LibHac/FsService/DefaultFsServerObjects.cs @@ -1,4 +1,4 @@ -using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsService.Creators; namespace LibHac.FsService diff --git a/src/LibHac/FsService/FileSystemProxy.cs b/src/LibHac/FsService/FileSystemProxy.cs index 1725da97..886de3f6 100644 --- a/src/LibHac/FsService/FileSystemProxy.cs +++ b/src/LibHac/FsService/FileSystemProxy.cs @@ -2,6 +2,7 @@ using System.Runtime.CompilerServices; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsService.Impl; using LibHac.FsSystem; using LibHac.Kvdb; diff --git a/src/LibHac/FsService/FileSystemProxyCore.cs b/src/LibHac/FsService/FileSystemProxyCore.cs index 0feb8a81..bfee4564 100644 --- a/src/LibHac/FsService/FileSystemProxyCore.cs +++ b/src/LibHac/FsService/FileSystemProxyCore.cs @@ -3,6 +3,7 @@ using System.Buffers.Text; using System.Runtime.CompilerServices; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.Fs.Shim; using LibHac.FsSystem; using LibHac.FsService.Creators; diff --git a/src/LibHac/FsService/IFileSystemProxy.cs b/src/LibHac/FsService/IFileSystemProxy.cs index 15711c93..d84e60e0 100644 --- a/src/LibHac/FsService/IFileSystemProxy.cs +++ b/src/LibHac/FsService/IFileSystemProxy.cs @@ -1,6 +1,7 @@ using System; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; using LibHac.Ncm; using LibHac.Spl; diff --git a/src/LibHac/FsService/IMultiCommitManager.cs b/src/LibHac/FsService/IMultiCommitManager.cs index 029946d9..5d811966 100644 --- a/src/LibHac/FsService/IMultiCommitManager.cs +++ b/src/LibHac/FsService/IMultiCommitManager.cs @@ -1,4 +1,4 @@ -using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsService { diff --git a/src/LibHac/FsService/Impl/MultiCommitManager.cs b/src/LibHac/FsService/Impl/MultiCommitManager.cs index e8a0a31b..3b77a44f 100644 --- a/src/LibHac/FsService/Impl/MultiCommitManager.cs +++ b/src/LibHac/FsService/Impl/MultiCommitManager.cs @@ -2,6 +2,7 @@ using System.Runtime.InteropServices; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.Fs.Shim; namespace LibHac.FsService.Impl diff --git a/src/LibHac/FsService/Util.cs b/src/LibHac/FsService/Util.cs index 243717b5..5e44e966 100644 --- a/src/LibHac/FsService/Util.cs +++ b/src/LibHac/FsService/Util.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; namespace LibHac.FsService diff --git a/src/LibHac/FsSystem/Aes128CtrExStorage.cs b/src/LibHac/FsSystem/Aes128CtrExStorage.cs index 491b7ac2..a6cae265 100644 --- a/src/LibHac/FsSystem/Aes128CtrExStorage.cs +++ b/src/LibHac/FsSystem/Aes128CtrExStorage.cs @@ -31,7 +31,7 @@ namespace LibHac.FsSystem SubsectionOffsets = SubsectionEntries.Select(x => x.Offset).ToList(); } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { AesSubsectionEntry entry = GetSubsectionEntry(offset); @@ -47,7 +47,7 @@ namespace LibHac.FsSystem { UpdateCounterSubsection(entry.Counter); - Result rc = base.ReadImpl(inPos, destination.Slice(outPos, bytesToRead)); + Result rc = base.DoRead(inPos, destination.Slice(outPos, bytesToRead)); if (rc.IsFailure()) return rc; } @@ -64,12 +64,12 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { return ResultFs.UnsupportedOperationInAesCtrExStorageWrite.Log(); } - protected override Result FlushImpl() + protected override Result DoFlush() { return Result.Success; } diff --git a/src/LibHac/FsSystem/Aes128CtrStorage.cs b/src/LibHac/FsSystem/Aes128CtrStorage.cs index e413bff3..01f16020 100644 --- a/src/LibHac/FsSystem/Aes128CtrStorage.cs +++ b/src/LibHac/FsSystem/Aes128CtrStorage.cs @@ -59,9 +59,9 @@ namespace LibHac.FsSystem Counter = _decryptor.Counter; } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { - Result rc = base.ReadImpl(offset, destination); + Result rc = base.DoRead(offset, destination); if (rc.IsFailure()) return rc; lock (_locker) @@ -73,7 +73,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { byte[] encrypted = ArrayPool.Shared.Rent(source.Length); try @@ -87,7 +87,7 @@ namespace LibHac.FsSystem _decryptor.TransformBlock(encryptedSpan); } - Result rc = base.WriteImpl(offset, encryptedSpan); + Result rc = base.DoWrite(offset, encryptedSpan); if (rc.IsFailure()) return rc; } finally diff --git a/src/LibHac/FsSystem/Aes128XtsStorage.cs b/src/LibHac/FsSystem/Aes128XtsStorage.cs index b879dc92..858a19f2 100644 --- a/src/LibHac/FsSystem/Aes128XtsStorage.cs +++ b/src/LibHac/FsSystem/Aes128XtsStorage.cs @@ -38,14 +38,14 @@ namespace LibHac.FsSystem _key2 = key2.ToArray(); } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { int size = destination.Length; long sectorIndex = offset / SectorSize; if (_decryptor == null) _decryptor = new Aes128XtsTransform(_key1, _key2, true); - Result rc = base.ReadImpl(offset, _tempBuffer.AsSpan(0, size)); + Result rc = base.DoRead(offset, _tempBuffer.AsSpan(0, size)); if (rc.IsFailure()) return rc; _decryptor.TransformBlock(_tempBuffer, 0, size, (ulong)sectorIndex); @@ -54,7 +54,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { int size = source.Length; long sectorIndex = offset / SectorSize; @@ -64,10 +64,10 @@ namespace LibHac.FsSystem source.CopyTo(_tempBuffer); _encryptor.TransformBlock(_tempBuffer, 0, size, (ulong)sectorIndex); - return base.WriteImpl(offset, _tempBuffer.AsSpan(0, size)); + return base.DoWrite(offset, _tempBuffer.AsSpan(0, size)); } - protected override Result FlushImpl() + protected override Result DoFlush() { return BaseStorage.Flush(); } diff --git a/src/LibHac/FsSystem/AesXtsDirectory.cs b/src/LibHac/FsSystem/AesXtsDirectory.cs index 8345a24e..542efd48 100644 --- a/src/LibHac/FsSystem/AesXtsDirectory.cs +++ b/src/LibHac/FsSystem/AesXtsDirectory.cs @@ -1,6 +1,7 @@ using System; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { @@ -20,7 +21,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 +47,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); } diff --git a/src/LibHac/FsSystem/AesXtsFile.cs b/src/LibHac/FsSystem/AesXtsFile.cs index 72a0ca35..7c5c7340 100644 --- a/src/LibHac/FsSystem/AesXtsFile.cs +++ b/src/LibHac/FsSystem/AesXtsFile.cs @@ -1,10 +1,11 @@ using System; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { - public class AesXtsFile : FileBase + public class AesXtsFile : IFile { private IFile BaseFile { get; } private U8String Path { get; } @@ -54,11 +55,11 @@ namespace LibHac.FsSystem return key; } - protected override Result ReadImpl(out long bytesRead, long offset, Span destination, ReadOption 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,21 +69,21 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source, WriteOption 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) { - rc = SetSizeImpl(offset + source.Length); + rc = DoSetSize(offset + source.Length); if (rc.IsFailure()) return rc; } rc = BaseStorage.Write(offset, source); if (rc.IsFailure()) return rc; - if ((options & WriteOption.Flush) != 0) + if (option.HasFlushFlag()) { return Flush(); } @@ -90,18 +91,24 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result FlushImpl() + protected override Result DoFlush() { return BaseStorage.Flush(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = Header.Size; return Result.Success; } - protected override Result SetSizeImpl(long size) + 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/AesXtsFileHeader.cs b/src/LibHac/FsSystem/AesXtsFileHeader.cs index 400bfd93..646c94d9 100644 --- a/src/LibHac/FsSystem/AesXtsFileHeader.cs +++ b/src/LibHac/FsSystem/AesXtsFileHeader.cs @@ -3,6 +3,7 @@ using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Text; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { diff --git a/src/LibHac/FsSystem/AesXtsFileSystem.cs b/src/LibHac/FsSystem/AesXtsFileSystem.cs index 7335f93f..8ab3c1d9 100644 --- a/src/LibHac/FsSystem/AesXtsFileSystem.cs +++ b/src/LibHac/FsSystem/AesXtsFileSystem.cs @@ -2,10 +2,11 @@ using System.Diagnostics; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { - public class AesXtsFileSystem : FileSystemBase + public class AesXtsFileSystem : IFileSystem { public int BlockSize { get; } @@ -29,12 +30,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 +69,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 +100,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 +113,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 +173,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 +197,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); diff --git a/src/LibHac/FsSystem/CachedStorage.cs b/src/LibHac/FsSystem/CachedStorage.cs index bba36958..614d50f8 100644 --- a/src/LibHac/FsSystem/CachedStorage.cs +++ b/src/LibHac/FsSystem/CachedStorage.cs @@ -4,7 +4,7 @@ using LibHac.Fs; namespace LibHac.FsSystem { - public class CachedStorage : StorageBase + public class CachedStorage : IStorage { private IStorage BaseStorage { get; } private int BlockSize { get; } @@ -33,7 +33,7 @@ namespace LibHac.FsSystem public CachedStorage(SectorStorage baseStorage, int cacheSize, bool leaveOpen) : this(baseStorage, baseStorage.SectorSize, cacheSize, leaveOpen) { } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { long remaining = destination.Length; long inOffset = offset; @@ -63,7 +63,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { long remaining = source.Length; long inOffset = offset; @@ -95,7 +95,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result FlushImpl() + protected override Result DoFlush() { lock (Blocks) { @@ -108,13 +108,13 @@ namespace LibHac.FsSystem return BaseStorage.Flush(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = Length; return Result.Success; } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { Result rc = BaseStorage.SetSize(size); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/FsSystem/ConcatenationDirectory.cs b/src/LibHac/FsSystem/ConcatenationDirectory.cs index 22d00340..36b8195f 100644 --- a/src/LibHac/FsSystem/ConcatenationDirectory.cs +++ b/src/LibHac/FsSystem/ConcatenationDirectory.cs @@ -2,6 +2,7 @@ using System.Runtime.InteropServices; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { @@ -38,7 +39,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 +82,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 c2eecf62..52bca2a1 100644 --- a/src/LibHac/FsSystem/ConcatenationFile.cs +++ b/src/LibHac/FsSystem/ConcatenationFile.cs @@ -4,10 +4,11 @@ using System.Diagnostics; using System.Linq; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { - public class ConcatenationFile : FileBase + public class ConcatenationFile : IFile { private IFileSystem BaseFileSystem { get; } private U8String FilePath { get; } @@ -34,14 +35,15 @@ namespace LibHac.FsSystem } } - protected override Result ReadImpl(out long bytesRead, long offset, Span destination, ReadOption 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 +57,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 +72,9 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source, WriteOption 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 +93,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 +101,7 @@ namespace LibHac.FsSystem remaining -= bytesToWrite; } - if (options.HasFlag(WriteOption.Flush)) + if (option.HasFlushFlag()) { return Flush(); } @@ -107,7 +109,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result FlushImpl() + protected override Result DoFlush() { foreach (IFile file in Sources) { @@ -118,7 +120,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = default; @@ -133,7 +135,12 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result SetSizeImpl(long 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) { Result rc = GetSize(out long currentSize); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/FsSystem/ConcatenationFileSystem.cs b/src/LibHac/FsSystem/ConcatenationFileSystem.cs index 38b9dca4..5a254faa 100644 --- a/src/LibHac/FsSystem/ConcatenationFileSystem.cs +++ b/src/LibHac/FsSystem/ConcatenationFileSystem.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { @@ -22,7 +23,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 +97,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 +110,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 +157,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result DeleteDirectoryImpl(U8Span path) + protected override Result DoDeleteDirectory(U8Span path) { if (IsConcatenationFile(path)) { @@ -166,21 +167,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 +206,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 +222,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 +254,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 +264,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 +276,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 +287,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/ConcatenationStorage.cs b/src/LibHac/FsSystem/ConcatenationStorage.cs index e4256d5c..112baccd 100644 --- a/src/LibHac/FsSystem/ConcatenationStorage.cs +++ b/src/LibHac/FsSystem/ConcatenationStorage.cs @@ -4,7 +4,7 @@ using LibHac.Fs; namespace LibHac.FsSystem { - public class ConcatenationStorage : StorageBase + public class ConcatenationStorage : IStorage { private ConcatSource[] Sources { get; } private long Length { get; } @@ -28,7 +28,7 @@ namespace LibHac.FsSystem Length = length; } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { long inPos = offset; int outPos = 0; @@ -59,7 +59,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { long inPos = offset; int outPos = 0; @@ -90,7 +90,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result FlushImpl() + protected override Result DoFlush() { foreach (ConcatSource source in Sources) { @@ -101,12 +101,12 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { return ResultFs.NotImplemented.Log(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = Length; return Result.Success; diff --git a/src/LibHac/FsSystem/Delta.cs b/src/LibHac/FsSystem/Delta.cs index a3869dbe..f8bc168a 100644 --- a/src/LibHac/FsSystem/Delta.cs +++ b/src/LibHac/FsSystem/Delta.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { diff --git a/src/LibHac/FsSystem/DirectorySaveDataFile.cs b/src/LibHac/FsSystem/DirectorySaveDataFile.cs index 1fd44bc7..d2ce1d30 100644 --- a/src/LibHac/FsSystem/DirectorySaveDataFile.cs +++ b/src/LibHac/FsSystem/DirectorySaveDataFile.cs @@ -1,9 +1,10 @@ using System; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { - public class DirectorySaveDataFile : FileBase + public class DirectorySaveDataFile : IFile { private IFile BaseFile { get; } private DirectorySaveDataFileSystem ParentFs { get; } @@ -16,31 +17,37 @@ namespace LibHac.FsSystem Mode = mode; } - protected override Result ReadImpl(out long bytesRead, long offset, Span destination, ReadOption 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 WriteImpl(long offset, ReadOnlySpan source, WriteOption 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 FlushImpl() + protected override Result DoFlush() { return BaseFile.Flush(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { return BaseFile.GetSize(out size); } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { 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..f6fadb93 100644 --- a/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs +++ b/src/LibHac/FsSystem/DirectorySaveDataFileSystem.cs @@ -1,6 +1,7 @@ using System; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { @@ -12,7 +13,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 +98,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 +112,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 +126,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 +140,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 +154,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 +168,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 +182,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 +200,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 +226,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 +245,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 +264,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 +282,7 @@ namespace LibHac.FsSystem } } - protected override Result CommitImpl() + protected override Result DoCommit() { lock (Locker) { @@ -315,7 +316,7 @@ namespace LibHac.FsSystem } } - protected override Result CommitProvisionallyImpl(long commitCount) + protected override Result DoCommitProvisionally(long counter) { if (!CanCommitProvisionally) return ResultFs.UnsupportedOperationInDirectorySaveDataFileSystem.Log(); @@ -323,7 +324,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 +333,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 +349,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 feaf3659..2f26bafe 100644 --- a/src/LibHac/FsSystem/DirectoryUtils.cs +++ b/src/LibHac/FsSystem/DirectoryUtils.cs @@ -1,6 +1,7 @@ using System; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { diff --git a/src/LibHac/FsSystem/FileReader.cs b/src/LibHac/FsSystem/FileReader.cs index b1c79db8..47798817 100644 --- a/src/LibHac/FsSystem/FileReader.cs +++ b/src/LibHac/FsSystem/FileReader.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using System.Runtime.InteropServices; using System.Text; -using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { diff --git a/src/LibHac/FsSystem/FileStorage.cs b/src/LibHac/FsSystem/FileStorage.cs index 29c5d240..1826f2fb 100644 --- a/src/LibHac/FsSystem/FileStorage.cs +++ b/src/LibHac/FsSystem/FileStorage.cs @@ -1,9 +1,10 @@ using System; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { - public class FileStorage : StorageBase + public class FileStorage : IStorage { protected IFile BaseFile { get; } @@ -12,27 +13,27 @@ namespace LibHac.FsSystem BaseFile = baseFile; } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { return BaseFile.Read(out long _, offset, destination); } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { return BaseFile.Write(offset, source); } - protected override Result FlushImpl() + protected override Result DoFlush() { return BaseFile.Flush(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { return BaseFile.GetSize(out size); } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { return BaseFile.SetSize(size); } diff --git a/src/LibHac/FsSystem/FileSystemExtensions.cs b/src/LibHac/FsSystem/FileSystemExtensions.cs index 858cf318..849056b5 100644 --- a/src/LibHac/FsSystem/FileSystemExtensions.cs +++ b/src/LibHac/FsSystem/FileSystemExtensions.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.IO; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { diff --git a/src/LibHac/FsSystem/HierarchicalIntegrityVerificationStorage.cs b/src/LibHac/FsSystem/HierarchicalIntegrityVerificationStorage.cs index 520436ea..3e063966 100644 --- a/src/LibHac/FsSystem/HierarchicalIntegrityVerificationStorage.cs +++ b/src/LibHac/FsSystem/HierarchicalIntegrityVerificationStorage.cs @@ -7,7 +7,7 @@ using LibHac.Fs; namespace LibHac.FsSystem { - public class HierarchicalIntegrityVerificationStorage : StorageBase + public class HierarchicalIntegrityVerificationStorage : IStorage { public IStorage[] Levels { get; } public IStorage DataLevel { get; } @@ -96,27 +96,27 @@ namespace LibHac.FsSystem return initInfo; } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { return DataLevel.Read(offset, destination); } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { return DataLevel.Write(offset, source); } - protected override Result FlushImpl() + protected override Result DoFlush() { return DataLevel.Flush(); } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { return ResultFs.UnsupportedOperationInHierarchicalIvfcStorageSetSize.Log(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = Length; return Result.Success; diff --git a/src/LibHac/FsSystem/IndirectStorage.cs b/src/LibHac/FsSystem/IndirectStorage.cs index c1387d8e..2acb3ae0 100644 --- a/src/LibHac/FsSystem/IndirectStorage.cs +++ b/src/LibHac/FsSystem/IndirectStorage.cs @@ -5,7 +5,7 @@ using LibHac.Fs; namespace LibHac.FsSystem { - public class IndirectStorage : StorageBase + public class IndirectStorage : IStorage { private List RelocationEntries { get; } private List RelocationOffsets { get; } @@ -29,7 +29,7 @@ namespace LibHac.FsSystem Length = BucketTree.BucketOffsets.OffsetEnd; } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { RelocationEntry entry = GetRelocationEntry(offset); @@ -64,23 +64,23 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { return ResultFs.UnsupportedOperationInIndirectStorageSetSize.Log(); } - protected override Result FlushImpl() + protected override Result DoFlush() { return Result.Success; } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = Length; return Result.Success; } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { return ResultFs.UnsupportedOperationInIndirectStorageSetSize.Log(); } diff --git a/src/LibHac/FsSystem/IntegrityVerificationStorage.cs b/src/LibHac/FsSystem/IntegrityVerificationStorage.cs index a0df10a0..75a86ddb 100644 --- a/src/LibHac/FsSystem/IntegrityVerificationStorage.cs +++ b/src/LibHac/FsSystem/IntegrityVerificationStorage.cs @@ -117,7 +117,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { return ReadImpl(offset, destination, IntegrityCheckLevel); } @@ -128,7 +128,7 @@ namespace LibHac.FsSystem return ReadImpl(offset, destination, integrityCheckLevel); } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { long blockIndex = offset / SectorSize; long hashPos = blockIndex * DigestSize; @@ -188,12 +188,12 @@ namespace LibHac.FsSystem } } - protected override Result FlushImpl() + protected override Result DoFlush() { Result rc = HashStorage.Flush(); if (rc.IsFailure()) return rc; - return base.FlushImpl(); + return base.DoFlush(); } public void FsTrim() diff --git a/src/LibHac/FsSystem/LayeredFileSystem.cs b/src/LibHac/FsSystem/LayeredFileSystem.cs index 0e3ca2ce..ccb5916d 100644 --- a/src/LibHac/FsSystem/LayeredFileSystem.cs +++ b/src/LibHac/FsSystem/LayeredFileSystem.cs @@ -2,10 +2,11 @@ using System.Collections.Generic; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { - public class LayeredFileSystem : FileSystemBase + public class LayeredFileSystem : IFileSystem { /// /// List of source s. @@ -35,7 +36,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 +107,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 +136,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 +153,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 +169,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 +185,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 +231,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 +256,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..933b1252 100644 --- a/src/LibHac/FsSystem/LocalDirectory.cs +++ b/src/LibHac/FsSystem/LocalDirectory.cs @@ -4,6 +4,7 @@ using System.IO; using System.Runtime.CompilerServices; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { @@ -12,7 +13,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 +22,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 +53,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 6e922cc0..22f3b7a2 100644 --- a/src/LibHac/FsSystem/LocalFile.cs +++ b/src/LibHac/FsSystem/LocalFile.cs @@ -2,10 +2,11 @@ using System.IO; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { - public class LocalFile : FileBase + public class LocalFile : IFile { private FileStream Stream { get; } private StreamFile File { get; } @@ -27,25 +28,26 @@ namespace LibHac.FsSystem File = new StreamFile(Stream, mode); } - protected override Result ReadImpl(out long bytesRead, long offset, Span destination, ReadOption 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 WriteImpl(long offset, ReadOnlySpan source, WriteOption 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 FlushImpl() + protected override Result DoFlush() { try { @@ -57,7 +59,7 @@ namespace LibHac.FsSystem } } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { try { @@ -70,7 +72,12 @@ namespace LibHac.FsSystem } } - protected override Result SetSizeImpl(long 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) { try { diff --git a/src/LibHac/FsSystem/LocalFileSystem.cs b/src/LibHac/FsSystem/LocalFileSystem.cs index 9564194a..12906dfb 100644 --- a/src/LibHac/FsSystem/LocalFileSystem.cs +++ b/src/LibHac/FsSystem/LocalFileSystem.cs @@ -4,10 +4,11 @@ using System.IO; using System.Threading; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { - public class LocalFileSystem : AttributeFileSystemBase + public class LocalFileSystem : IAttributeFileSystem { private string BasePath { get; } @@ -66,7 +67,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 +87,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 +115,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 +128,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 +154,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 +182,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 +193,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 +204,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 +230,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 +241,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 +268,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 +290,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 +313,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 +333,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 +362,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 +381,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/LocalStorage.cs b/src/LibHac/FsSystem/LocalStorage.cs index ebc47f58..0b9a4f51 100644 --- a/src/LibHac/FsSystem/LocalStorage.cs +++ b/src/LibHac/FsSystem/LocalStorage.cs @@ -4,7 +4,7 @@ using LibHac.Fs; namespace LibHac.FsSystem { - public class LocalStorage : StorageBase + public class LocalStorage : IStorage { private string Path { get; } private FileStream Stream { get; } @@ -19,27 +19,27 @@ namespace LibHac.FsSystem Storage = new StreamStorage(Stream, false); } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { return Storage.Read(offset, destination); } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { return Storage.Write(offset, source); } - protected override Result FlushImpl() + protected override Result DoFlush() { return Storage.Flush(); } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { return ResultFs.NotImplemented.Log(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { return Storage.GetSize(out size); } diff --git a/src/LibHac/FsSystem/NcaUtils/Nca.cs b/src/LibHac/FsSystem/NcaUtils/Nca.cs index d81ee843..0626f84b 100644 --- a/src/LibHac/FsSystem/NcaUtils/Nca.cs +++ b/src/LibHac/FsSystem/NcaUtils/Nca.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem.RomFs; using LibHac.Spl; diff --git a/src/LibHac/FsSystem/NcaUtils/NcaExtensions.cs b/src/LibHac/FsSystem/NcaUtils/NcaExtensions.cs index 8b906765..7ce6ab25 100644 --- a/src/LibHac/FsSystem/NcaUtils/NcaExtensions.cs +++ b/src/LibHac/FsSystem/NcaUtils/NcaExtensions.cs @@ -3,6 +3,7 @@ using System.Buffers.Binary; using System.Diagnostics; using LibHac.Crypto; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem.NcaUtils { diff --git a/src/LibHac/FsSystem/NullFile.cs b/src/LibHac/FsSystem/NullFile.cs index 4bfdbcf7..20a701c1 100644 --- a/src/LibHac/FsSystem/NullFile.cs +++ b/src/LibHac/FsSystem/NullFile.cs @@ -1,9 +1,10 @@ using System; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { - public class NullFile : FileBase + public class NullFile : IFile { private OpenMode Mode { get; } @@ -16,11 +17,12 @@ namespace LibHac.FsSystem private long Length { get; } - protected override Result ReadImpl(out long bytesRead, long offset, Span destination, ReadOption 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,23 +31,29 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source, WriteOption options) + protected override Result DoWrite(long offset, ReadOnlySpan source, in WriteOption option) { return Result.Success; } - protected override Result FlushImpl() + protected override Result DoFlush() { return Result.Success; } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = Length; return Result.Success; } - protected override Result SetSizeImpl(long size) + 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/NullStorage.cs b/src/LibHac/FsSystem/NullStorage.cs index 81b4d23e..d6e6cf18 100644 --- a/src/LibHac/FsSystem/NullStorage.cs +++ b/src/LibHac/FsSystem/NullStorage.cs @@ -6,7 +6,7 @@ namespace LibHac.FsSystem /// /// An that returns all zeros when read, and does nothing on write. /// - public class NullStorage : StorageBase + public class NullStorage : IStorage { private long Length { get; } @@ -14,28 +14,28 @@ namespace LibHac.FsSystem public NullStorage(long length) => Length = length; - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { destination.Clear(); return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { return Result.Success; } - protected override Result FlushImpl() + protected override Result DoFlush() { return Result.Success; } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { return ResultFs.NotImplemented.Log(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = Length; return Result.Success; diff --git a/src/LibHac/FsSystem/NxFileStream.cs b/src/LibHac/FsSystem/NxFileStream.cs index 00d8593e..88a7e78f 100644 --- a/src/LibHac/FsSystem/NxFileStream.cs +++ b/src/LibHac/FsSystem/NxFileStream.cs @@ -1,6 +1,7 @@ using System; using System.IO; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { diff --git a/src/LibHac/FsSystem/PartitionDirectory.cs b/src/LibHac/FsSystem/PartitionDirectory.cs index c66de8f2..03550613 100644 --- a/src/LibHac/FsSystem/PartitionDirectory.cs +++ b/src/LibHac/FsSystem/PartitionDirectory.cs @@ -3,6 +3,7 @@ using System.IO; using System.Text; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { @@ -24,7 +25,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 +56,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 0ada32ed..8ad0c829 100644 --- a/src/LibHac/FsSystem/PartitionFile.cs +++ b/src/LibHac/FsSystem/PartitionFile.cs @@ -1,9 +1,10 @@ using System; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { - public class PartitionFile : FileBase + public class PartitionFile : IFile { private IStorage BaseStorage { get; } private long Offset { get; } @@ -18,11 +19,12 @@ namespace LibHac.FsSystem Size = size; } - protected override Result ReadImpl(out long bytesRead, long offset, Span destination, ReadOption 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 +34,9 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source, WriteOption 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 +47,7 @@ namespace LibHac.FsSystem if (rc.IsFailure()) return rc; // N doesn't flush if the flag is set - if (options.HasFlag(WriteOption.Flush)) + if (option.HasFlushFlag()) { return BaseStorage.Flush(); } @@ -53,7 +55,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result FlushImpl() + protected override Result DoFlush() { if (!Mode.HasFlag(OpenMode.Write)) { @@ -63,13 +65,19 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = Size; return Result.Success; } - protected override Result SetSizeImpl(long 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) { if (!Mode.HasFlag(OpenMode.Write)) { diff --git a/src/LibHac/FsSystem/PartitionFileSystem.cs b/src/LibHac/FsSystem/PartitionFileSystem.cs index 11c514d5..4be509f1 100644 --- a/src/LibHac/FsSystem/PartitionFileSystem.cs +++ b/src/LibHac/FsSystem/PartitionFileSystem.cs @@ -6,10 +6,11 @@ using System.Text; using LibHac.Common; using LibHac.Crypto; using LibHac.Fs; +using LibHac.Fs.Fsa; 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 +33,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 +57,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 +76,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/PartitionFileSystemBuilder.cs b/src/LibHac/FsSystem/PartitionFileSystemBuilder.cs index 158f2db1..b6133b5f 100644 --- a/src/LibHac/FsSystem/PartitionFileSystemBuilder.cs +++ b/src/LibHac/FsSystem/PartitionFileSystemBuilder.cs @@ -6,6 +6,7 @@ using System.Text; using LibHac.Common; using LibHac.Crypto; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { diff --git a/src/LibHac/FsSystem/PartitionFileSystemCore.cs b/src/LibHac/FsSystem/PartitionFileSystemCore.cs index f6bb15bb..01f03440 100644 --- a/src/LibHac/FsSystem/PartitionFileSystemCore.cs +++ b/src/LibHac/FsSystem/PartitionFileSystemCore.cs @@ -3,11 +3,12 @@ using System.Runtime.CompilerServices; using LibHac.Common; using LibHac.Crypto; using LibHac.Fs; +using LibHac.Fs.Fsa; 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 +32,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 +49,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 +69,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 +96,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 +124,12 @@ namespace LibHac.FsSystem Mode = mode; } - protected override Result ReadImpl(out long bytesRead, long offset, Span destination, ReadOption 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 +242,9 @@ namespace LibHac.FsSystem return rc; } - protected override Result WriteImpl(long offset, ReadOnlySpan source, WriteOption 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) @@ -257,7 +259,7 @@ namespace LibHac.FsSystem return ParentFs.BaseStorage.Write(ParentFs.DataOffset + _entry.Offset + offset, source); } - protected override Result FlushImpl() + protected override Result DoFlush() { if (Mode.HasFlag(OpenMode.Write)) { @@ -267,7 +269,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { if (Mode.HasFlag(OpenMode.Write)) { @@ -277,14 +279,14 @@ namespace LibHac.FsSystem return ResultFs.InvalidOpenModeForWrite.Log(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = _entry.Size; return Result.Success; } - protected override Result OperateRangeImpl(Span outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan inBuffer) + protected override Result DoOperateRange(Span outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan inBuffer) { switch (operationId) { @@ -327,7 +329,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 +358,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 211f9d4d..61a1e820 100644 --- a/src/LibHac/FsSystem/ReadOnlyFile.cs +++ b/src/LibHac/FsSystem/ReadOnlyFile.cs @@ -1,9 +1,10 @@ using System; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { - public class ReadOnlyFile : FileBase + public class ReadOnlyFile : IFile { private IFile BaseFile { get; } @@ -12,29 +13,42 @@ namespace LibHac.FsSystem BaseFile = baseFile; } - protected override Result ReadImpl(out long bytesRead, long offset, Span destination, ReadOption 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 GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { return BaseFile.GetSize(out size); } - protected override Result FlushImpl() + protected override Result DoFlush() { return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source, WriteOption options) + protected override Result DoWrite(long offset, ReadOnlySpan source, in WriteOption option) { return ResultFs.InvalidOpenModeForWrite.Log(); } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { 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..f7addcfc 100644 --- a/src/LibHac/FsSystem/ReadOnlyFileSystem.cs +++ b/src/LibHac/FsSystem/ReadOnlyFileSystem.cs @@ -1,9 +1,10 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { - public class ReadOnlyFileSystem : FileSystemBase + public class ReadOnlyFileSystem : IFileSystem { private IFileSystem BaseFs { get; } @@ -12,12 +13,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 +29,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 +43,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 +51,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 +59,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/RomFsBuilder.cs b/src/LibHac/FsSystem/RomFs/RomFsBuilder.cs index dae93716..7a823195 100644 --- a/src/LibHac/FsSystem/RomFs/RomFsBuilder.cs +++ b/src/LibHac/FsSystem/RomFs/RomFsBuilder.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem.RomFs { diff --git a/src/LibHac/FsSystem/RomFs/RomFsDirectory.cs b/src/LibHac/FsSystem/RomFs/RomFsDirectory.cs index 12c19acb..6f2aaae8 100644 --- a/src/LibHac/FsSystem/RomFs/RomFsDirectory.cs +++ b/src/LibHac/FsSystem/RomFs/RomFsDirectory.cs @@ -2,6 +2,7 @@ using System.Text; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem.RomFs { @@ -22,12 +23,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 11d05b38..e3d70170 100644 --- a/src/LibHac/FsSystem/RomFs/RomFsFile.cs +++ b/src/LibHac/FsSystem/RomFs/RomFsFile.cs @@ -1,9 +1,10 @@ using System; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem.RomFs { - public class RomFsFile : FileBase + public class RomFsFile : IFile { private IStorage BaseStorage { get; } private long Offset { get; } @@ -16,11 +17,12 @@ namespace LibHac.FsSystem.RomFs Size = size; } - protected override Result ReadImpl(out long bytesRead, long offset, Span destination, ReadOption 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,25 +35,31 @@ namespace LibHac.FsSystem.RomFs return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source, WriteOption options) + protected override Result DoWrite(long offset, ReadOnlySpan source, in WriteOption option) { return ResultFs.UnsupportedOperationModifyRomFsFile.Log(); } - protected override Result FlushImpl() + protected override Result DoFlush() { return Result.Success; } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = Size; return Result.Success; } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { 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..310aa7eb 100644 --- a/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs +++ b/src/LibHac/FsSystem/RomFs/RomFsFileSystem.cs @@ -1,9 +1,10 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem.RomFs { - public class RomFsFileSystem : FileSystemBase + public class RomFsFileSystem : IFileSystem { public RomfsHeader Header { get; } @@ -23,7 +24,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 +43,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 +61,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 +85,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/AllocationTableStorage.cs b/src/LibHac/FsSystem/Save/AllocationTableStorage.cs index 05066de1..caba30bc 100644 --- a/src/LibHac/FsSystem/Save/AllocationTableStorage.cs +++ b/src/LibHac/FsSystem/Save/AllocationTableStorage.cs @@ -4,7 +4,7 @@ using LibHac.Fs; namespace LibHac.FsSystem.Save { - public class AllocationTableStorage : StorageBase + public class AllocationTableStorage : IStorage { private IStorage BaseStorage { get; } private int BlockSize { get; } @@ -23,7 +23,7 @@ namespace LibHac.FsSystem.Save _length = initialBlock == -1 ? 0 : table.GetListLength(initialBlock) * blockSize; } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { var iterator = new AllocationTableIterator(Fat, InitialBlock); @@ -57,7 +57,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { var iterator = new AllocationTableIterator(Fat, InitialBlock); @@ -91,18 +91,18 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result FlushImpl() + protected override Result DoFlush() { return BaseStorage.Flush(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = _length; return Result.Success; } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { int oldBlockCount = (int)Util.DivideByRoundUp(_length, BlockSize); int newBlockCount = (int)Util.DivideByRoundUp(size, BlockSize); diff --git a/src/LibHac/FsSystem/Save/DuplexStorage.cs b/src/LibHac/FsSystem/Save/DuplexStorage.cs index 7b6867d8..aeda29dc 100644 --- a/src/LibHac/FsSystem/Save/DuplexStorage.cs +++ b/src/LibHac/FsSystem/Save/DuplexStorage.cs @@ -3,7 +3,7 @@ using LibHac.Fs; namespace LibHac.FsSystem.Save { - public class DuplexStorage : StorageBase + public class DuplexStorage : IStorage { private int BlockSize { get; } private IStorage BitmapStorage { get; } @@ -27,7 +27,7 @@ namespace LibHac.FsSystem.Save Length = dataSize; } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { long inPos = offset; int outPos = 0; @@ -56,7 +56,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { long inPos = offset; int outPos = 0; @@ -85,7 +85,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result FlushImpl() + protected override Result DoFlush() { Result rc = BitmapStorage.Flush(); if (rc.IsFailure()) return rc; @@ -99,12 +99,12 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { return ResultFs.NotImplemented.Log(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = Length; return Result.Success; diff --git a/src/LibHac/FsSystem/Save/HierarchicalDuplexStorage.cs b/src/LibHac/FsSystem/Save/HierarchicalDuplexStorage.cs index 132b3ad5..42292cf0 100644 --- a/src/LibHac/FsSystem/Save/HierarchicalDuplexStorage.cs +++ b/src/LibHac/FsSystem/Save/HierarchicalDuplexStorage.cs @@ -3,7 +3,7 @@ using LibHac.Fs; namespace LibHac.FsSystem.Save { - public class HierarchicalDuplexStorage : StorageBase + public class HierarchicalDuplexStorage : IStorage { private DuplexStorage[] Layers { get; } private DuplexStorage DataLayer { get; } @@ -34,27 +34,27 @@ namespace LibHac.FsSystem.Save Length = dataSize; } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { return DataLayer.Read(offset, destination); } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { return DataLayer.Write(offset, source); } - protected override Result FlushImpl() + protected override Result DoFlush() { return DataLayer.Flush(); } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { return ResultFs.NotImplemented.Log(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = Length; return Result.Success; diff --git a/src/LibHac/FsSystem/Save/JournalStorage.cs b/src/LibHac/FsSystem/Save/JournalStorage.cs index 3eb6081b..b52dba43 100644 --- a/src/LibHac/FsSystem/Save/JournalStorage.cs +++ b/src/LibHac/FsSystem/Save/JournalStorage.cs @@ -5,7 +5,7 @@ using LibHac.Fs; namespace LibHac.FsSystem.Save { - public class JournalStorage : StorageBase + public class JournalStorage : IStorage { private IStorage BaseStorage { get; } private IStorage HeaderStorage { get; } @@ -33,7 +33,7 @@ namespace LibHac.FsSystem.Save LeaveOpen = leaveOpen; } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { long inPos = offset; int outPos = 0; @@ -62,7 +62,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { long inPos = offset; int outPos = 0; @@ -91,17 +91,17 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result FlushImpl() + protected override Result DoFlush() { return BaseStorage.Flush(); } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { return ResultFs.NotImplemented.Log(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = Length; return Result.Success; diff --git a/src/LibHac/FsSystem/Save/RemapStorage.cs b/src/LibHac/FsSystem/Save/RemapStorage.cs index 32432176..2f5697ea 100644 --- a/src/LibHac/FsSystem/Save/RemapStorage.cs +++ b/src/LibHac/FsSystem/Save/RemapStorage.cs @@ -6,7 +6,7 @@ using LibHac.Fs; namespace LibHac.FsSystem.Save { - public class RemapStorage : StorageBase + public class RemapStorage : IStorage { private const int MapEntryLength = 0x20; @@ -48,7 +48,7 @@ namespace LibHac.FsSystem.Save Segments = InitSegments(Header, MapEntries); } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { if (destination.Length == 0) return Result.Success; @@ -78,7 +78,7 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { if (source.Length == 0) return Result.Success; @@ -110,17 +110,17 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result FlushImpl() + protected override Result DoFlush() { return BaseStorage.Flush(); } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { return ResultFs.UnsupportedOperationInHierarchicalIvfcStorageSetSize.Log(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { // todo: Different result code size = -1; diff --git a/src/LibHac/FsSystem/Save/SaveDataDirectory.cs b/src/LibHac/FsSystem/Save/SaveDataDirectory.cs index a1a4e061..81e6ec6f 100644 --- a/src/LibHac/FsSystem/Save/SaveDataDirectory.cs +++ b/src/LibHac/FsSystem/Save/SaveDataDirectory.cs @@ -2,6 +2,7 @@ using System.Text; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem.Save { @@ -22,12 +23,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 6f40263e..9a990712 100644 --- a/src/LibHac/FsSystem/Save/SaveDataFile.cs +++ b/src/LibHac/FsSystem/Save/SaveDataFile.cs @@ -2,10 +2,11 @@ using System.IO; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem.Save { - public class SaveDataFile : FileBase + public class SaveDataFile : IFile { private AllocationTableStorage BaseStorage { get; } private U8String Path { get; } @@ -22,11 +23,12 @@ namespace LibHac.FsSystem.Save Size = size; } - protected override Result ReadImpl(out long bytesRead, long offset, Span destination, ReadOption 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,21 +44,21 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source, WriteOption 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) { - rc = SetSizeImpl(offset + source.Length); + rc = DoSetSize(offset + source.Length); if (rc.IsFailure()) return rc; } rc = BaseStorage.Write(offset, source); if (rc.IsFailure()) return rc; - if ((options & WriteOption.Flush) != 0) + if (option.HasFlushFlag()) { return Flush(); } @@ -64,18 +66,18 @@ namespace LibHac.FsSystem.Save return Result.Success; } - protected override Result FlushImpl() + protected override Result DoFlush() { return BaseStorage.Flush(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = Size; return Result.Success; } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { if (size < 0) throw new ArgumentOutOfRangeException(nameof(size)); if (Size == size) return Result.Success; @@ -97,5 +99,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..6ec53e1e 100644 --- a/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs +++ b/src/LibHac/FsSystem/Save/SaveDataFileSystem.cs @@ -3,10 +3,11 @@ using System.IO; using LibHac.Common; using LibHac.Crypto; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem.Save { - public class SaveDataFileSystem : FileSystemBase + public class SaveDataFileSystem : IFileSystem { internal const byte TrimFillValue = 0; @@ -144,98 +145,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..aa7c3fb8 100644 --- a/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs +++ b/src/LibHac/FsSystem/Save/SaveDataFileSystemCore.cs @@ -1,10 +1,11 @@ using System.IO; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem.Save { - public class SaveDataFileSystemCore : FileSystemBase + public class SaveDataFileSystemCore : IFileSystem { private IStorage BaseStorage { get; } private IStorage HeaderStorage { get; } @@ -28,7 +29,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 +42,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 +73,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 +86,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 +103,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 +116,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 +139,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 +159,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 +181,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 +197,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 +215,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 +241,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 +249,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/SectorStorage.cs b/src/LibHac/FsSystem/SectorStorage.cs index 6e0a09bc..0012f4db 100644 --- a/src/LibHac/FsSystem/SectorStorage.cs +++ b/src/LibHac/FsSystem/SectorStorage.cs @@ -3,7 +3,7 @@ using LibHac.Fs; namespace LibHac.FsSystem { - public class SectorStorage : StorageBase + public class SectorStorage : IStorage { protected IStorage BaseStorage { get; } @@ -26,30 +26,30 @@ namespace LibHac.FsSystem LeaveOpen = leaveOpen; } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { ValidateSize(destination.Length, offset); return BaseStorage.Read(offset, destination); } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { ValidateSize(source.Length, offset); return BaseStorage.Write(offset, source); } - protected override Result FlushImpl() + protected override Result DoFlush() { return BaseStorage.Flush(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = Length; return Result.Success; } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { Result rc = BaseStorage.SetSize(size); if (rc.IsFailure()) return rc; diff --git a/src/LibHac/FsSystem/StorageExtensions.cs b/src/LibHac/FsSystem/StorageExtensions.cs index 107b5a80..da2da86d 100644 --- a/src/LibHac/FsSystem/StorageExtensions.cs +++ b/src/LibHac/FsSystem/StorageExtensions.cs @@ -3,6 +3,7 @@ using System.Buffers; using System.IO; using System.Runtime.InteropServices; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { diff --git a/src/LibHac/FsSystem/StorageFile.cs b/src/LibHac/FsSystem/StorageFile.cs index 96d23a30..e32faaae 100644 --- a/src/LibHac/FsSystem/StorageFile.cs +++ b/src/LibHac/FsSystem/StorageFile.cs @@ -1,9 +1,10 @@ using System; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { - public class StorageFile : FileBase + public class StorageFile : IFile { private IStorage BaseStorage { get; } private OpenMode Mode { get; } @@ -14,11 +15,12 @@ namespace LibHac.FsSystem Mode = mode; } - protected override Result ReadImpl(out long bytesRead, long offset, Span destination, ReadOption 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,21 +36,21 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source, WriteOption 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) { - rc = SetSizeImpl(offset + source.Length); + rc = DoSetSize(offset + source.Length); if (rc.IsFailure()) return rc; } rc = BaseStorage.Write(offset, source); if (rc.IsFailure()) return rc; - if (options.HasFlag(WriteOption.Flush)) + if (option.HasFlushFlag()) { return Flush(); } @@ -56,7 +58,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result FlushImpl() + protected override Result DoFlush() { if (!Mode.HasFlag(OpenMode.Write)) return Result.Success; @@ -64,17 +66,23 @@ namespace LibHac.FsSystem return BaseStorage.Flush(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { return BaseStorage.GetSize(out size); } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { if (!Mode.HasFlag(OpenMode.Write)) return ResultFs.InvalidOpenModeForWrite.Log(); 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 12378b77..b0b8ddf4 100644 --- a/src/LibHac/FsSystem/StreamFile.cs +++ b/src/LibHac/FsSystem/StreamFile.cs @@ -1,13 +1,14 @@ using System; using System.IO; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { /// /// Provides an interface for interacting with a /// - public class StreamFile : FileBase + public class StreamFile : IFile { // todo: handle Stream exceptions @@ -21,11 +22,12 @@ namespace LibHac.FsSystem Mode = mode; } - protected override Result ReadImpl(out long bytesRead, long offset, Span destination, ReadOption 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 +42,9 @@ namespace LibHac.FsSystem } } - protected override Result WriteImpl(long offset, ReadOnlySpan source, WriteOption 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 +53,7 @@ namespace LibHac.FsSystem BaseStream.Write(source); } - if (options.HasFlag(WriteOption.Flush)) + if (option.HasFlushFlag()) { return Flush(); } @@ -59,7 +61,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result FlushImpl() + protected override Result DoFlush() { lock (Locker) { @@ -68,7 +70,7 @@ namespace LibHac.FsSystem } } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { lock (Locker) { @@ -77,7 +79,7 @@ namespace LibHac.FsSystem } } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { lock (Locker) { @@ -85,5 +87,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/StreamStorage.cs b/src/LibHac/FsSystem/StreamStorage.cs index a5d1c0bc..943b9698 100644 --- a/src/LibHac/FsSystem/StreamStorage.cs +++ b/src/LibHac/FsSystem/StreamStorage.cs @@ -4,7 +4,7 @@ using LibHac.Fs; namespace LibHac.FsSystem { - public class StreamStorage : StorageBase + public class StreamStorage : IStorage { // todo: handle Stream exceptions @@ -20,7 +20,7 @@ namespace LibHac.FsSystem LeaveOpen = leaveOpen; } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { lock (Locker) { @@ -35,7 +35,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { lock (Locker) { @@ -50,7 +50,7 @@ namespace LibHac.FsSystem return Result.Success; } - protected override Result FlushImpl() + protected override Result DoFlush() { lock (Locker) { @@ -60,12 +60,12 @@ namespace LibHac.FsSystem } } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { return ResultFs.NotImplemented.Log(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = Length; return Result.Success; diff --git a/src/LibHac/FsSystem/SubStorage.cs b/src/LibHac/FsSystem/SubStorage.cs index efaa4b7e..90991dc7 100644 --- a/src/LibHac/FsSystem/SubStorage.cs +++ b/src/LibHac/FsSystem/SubStorage.cs @@ -4,7 +4,7 @@ using LibHac.Fs; namespace LibHac.FsSystem { - public class SubStorage : StorageBase + public class SubStorage : IStorage { private IStorage BaseStorage { get; } private long Offset { get; } @@ -38,30 +38,30 @@ namespace LibHac.FsSystem Access = access; } - protected override Result ReadImpl(long offset, Span destination) + protected override Result DoRead(long offset, Span destination) { if ((Access & FileAccess.Read) == 0) throw new InvalidOperationException("Storage is not readable"); return BaseStorage.Read(offset + Offset, destination); } - protected override Result WriteImpl(long offset, ReadOnlySpan source) + protected override Result DoWrite(long offset, ReadOnlySpan source) { if ((Access & FileAccess.Write) == 0) throw new InvalidOperationException("Storage is not writable"); return BaseStorage.Write(offset + Offset, source); } - protected override Result FlushImpl() + protected override Result DoFlush() { return BaseStorage.Flush(); } - protected override Result GetSizeImpl(out long size) + protected override Result DoGetSize(out long size) { size = Length; return Result.Success; } - protected override Result SetSizeImpl(long size) + protected override Result DoSetSize(long size) { if (BaseStorage == null) return ResultFs.SubStorageNotInitialized.Log(); diff --git a/src/LibHac/FsSystem/SubdirectoryFileSystem.cs b/src/LibHac/FsSystem/SubdirectoryFileSystem.cs index d04e7071..8eb4c861 100644 --- a/src/LibHac/FsSystem/SubdirectoryFileSystem.cs +++ b/src/LibHac/FsSystem/SubdirectoryFileSystem.cs @@ -2,10 +2,11 @@ using System.Diagnostics; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { - public class SubdirectoryFileSystem : FileSystemBase + public class SubdirectoryFileSystem : IFileSystem { private IFileSystem BaseFileSystem { get; } private U8String RootPath { get; set; } @@ -72,7 +73,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 +82,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 +91,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 +100,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 +109,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 +118,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 +127,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 +138,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 +149,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 +163,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 +177,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 +190,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 +216,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 +227,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 +238,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 8e03cc33..a38efa5c 100644 --- a/src/LibHac/FsSystem/Utility.cs +++ b/src/LibHac/FsSystem/Utility.cs @@ -4,6 +4,7 @@ using System.Threading; using LibHac.Common; using LibHac.Diag; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.FsSystem { diff --git a/src/LibHac/Loader/NsoReader.cs b/src/LibHac/Loader/NsoReader.cs index 17c9039f..4266d17a 100644 --- a/src/LibHac/Loader/NsoReader.cs +++ b/src/LibHac/Loader/NsoReader.cs @@ -2,6 +2,7 @@ using System.Runtime.CompilerServices; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.Loader { diff --git a/src/LibHac/SwitchFs.cs b/src/LibHac/SwitchFs.cs index 565403be..4361002e 100644 --- a/src/LibHac/SwitchFs.cs +++ b/src/LibHac/SwitchFs.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; using LibHac.FsSystem.NcaUtils; using LibHac.FsSystem.Save; diff --git a/src/LibHac/Xci.cs b/src/LibHac/Xci.cs index e2bb6fb9..66eeab96 100644 --- a/src/LibHac/Xci.cs +++ b/src/LibHac/Xci.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; namespace LibHac diff --git a/src/hactoolnet/FsUtils.cs b/src/hactoolnet/FsUtils.cs index 8dfff38e..c8163d88 100644 --- a/src/hactoolnet/FsUtils.cs +++ b/src/hactoolnet/FsUtils.cs @@ -3,6 +3,7 @@ using System.Buffers; using LibHac; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; namespace hactoolnet diff --git a/src/hactoolnet/ProcessDelta.cs b/src/hactoolnet/ProcessDelta.cs index 9c9d03b1..00f6da1b 100644 --- a/src/hactoolnet/ProcessDelta.cs +++ b/src/hactoolnet/ProcessDelta.cs @@ -4,6 +4,7 @@ using System.Runtime.InteropServices; using System.Text; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; using LibHac.FsSystem.NcaUtils; using static hactoolnet.Print; diff --git a/src/hactoolnet/ProcessNca.cs b/src/hactoolnet/ProcessNca.cs index eef9771e..cf3755b2 100644 --- a/src/hactoolnet/ProcessNca.cs +++ b/src/hactoolnet/ProcessNca.cs @@ -3,6 +3,7 @@ using System.Text; using LibHac; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; using LibHac.FsSystem.NcaUtils; using LibHac.Npdm; diff --git a/src/hactoolnet/ProcessSave.cs b/src/hactoolnet/ProcessSave.cs index e663fccb..1b0093f5 100644 --- a/src/hactoolnet/ProcessSave.cs +++ b/src/hactoolnet/ProcessSave.cs @@ -6,6 +6,7 @@ using System.Text; using LibHac; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; using LibHac.FsSystem.Save; using static hactoolnet.Print; diff --git a/src/hactoolnet/ProcessSwitchFs.cs b/src/hactoolnet/ProcessSwitchFs.cs index 637848cd..4d9f1bd8 100644 --- a/src/hactoolnet/ProcessSwitchFs.cs +++ b/src/hactoolnet/ProcessSwitchFs.cs @@ -6,6 +6,7 @@ using System.Runtime.InteropServices; using System.Text; using LibHac; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; using LibHac.FsSystem.NcaUtils; using LibHac.FsSystem.Save; diff --git a/src/hactoolnet/ResultLogger.cs b/src/hactoolnet/ResultLogger.cs index ea9cec34..69674a50 100644 --- a/src/hactoolnet/ResultLogger.cs +++ b/src/hactoolnet/ResultLogger.cs @@ -4,6 +4,7 @@ using System.IO; using System.Reflection; using LibHac; using LibHac.Fs; +using LibHac.Fs.Fsa; namespace hactoolnet { diff --git a/tests/LibHac.Tests/Fs/AesXtsFileSystemTests.cs b/tests/LibHac.Tests/Fs/AesXtsFileSystemTests.cs index 9d02ba09..44fe7029 100644 --- a/tests/LibHac.Tests/Fs/AesXtsFileSystemTests.cs +++ b/tests/LibHac.Tests/Fs/AesXtsFileSystemTests.cs @@ -1,4 +1,5 @@ using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; using LibHac.Tests.Fs.IFileSystemTestBase; diff --git a/tests/LibHac.Tests/Fs/DirectorySaveDataFileSystemTests.cs b/tests/LibHac.Tests/Fs/DirectorySaveDataFileSystemTests.cs index 87e8eb74..c4192058 100644 --- a/tests/LibHac.Tests/Fs/DirectorySaveDataFileSystemTests.cs +++ b/tests/LibHac.Tests/Fs/DirectorySaveDataFileSystemTests.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; using LibHac.Tests.Fs.IFileSystemTestBase; using Xunit; diff --git a/tests/LibHac.Tests/Fs/FileSystemClientTests/FileSystemServerFactory.cs b/tests/LibHac.Tests/Fs/FileSystemClientTests/FileSystemServerFactory.cs index 4d95b7ea..9a628c42 100644 --- a/tests/LibHac.Tests/Fs/FileSystemClientTests/FileSystemServerFactory.cs +++ b/tests/LibHac.Tests/Fs/FileSystemClientTests/FileSystemServerFactory.cs @@ -1,4 +1,5 @@ using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsService; namespace LibHac.Tests.Fs.FileSystemClientTests diff --git a/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/Bis.cs b/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/Bis.cs index c15f1be9..e253afac 100644 --- a/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/Bis.cs +++ b/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/Bis.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.Fs.Shim; using Xunit; diff --git a/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/SdCard.cs b/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/SdCard.cs index f4742175..d102a0a8 100644 --- a/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/SdCard.cs +++ b/tests/LibHac.Tests/Fs/FileSystemClientTests/ShimTests/SdCard.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.Fs.Shim; using Xunit; diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/CommittableIFileSystemTests.Commit.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/CommittableIFileSystemTests.Commit.cs index 3cda8312..00db4445 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/CommittableIFileSystemTests.Commit.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/CommittableIFileSystemTests.Commit.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using Xunit; namespace LibHac.Tests.Fs.IFileSystemTestBase diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/CommittableIFileSystemTests.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/CommittableIFileSystemTests.cs index 8aacb0fe..1141f000 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/CommittableIFileSystemTests.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/CommittableIFileSystemTests.cs @@ -1,4 +1,4 @@ -using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.Tests.Fs.IFileSystemTestBase { diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IAttributeFileSystemTests.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IAttributeFileSystemTests.cs index 59b35933..2b3ddbf3 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IAttributeFileSystemTests.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IAttributeFileSystemTests.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using Xunit; namespace LibHac.Tests.Fs.IFileSystemTestBase diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CleanDirectoryRecursively.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CleanDirectoryRecursively.cs index 20a2bd27..95e8896b 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CleanDirectoryRecursively.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CleanDirectoryRecursively.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using Xunit; namespace LibHac.Tests.Fs.IFileSystemTestBase diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CreateDirectory.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CreateDirectory.cs index 5169b447..e9fc73c2 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CreateDirectory.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CreateDirectory.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using Xunit; namespace LibHac.Tests.Fs.IFileSystemTestBase diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CreateFile.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CreateFile.cs index 8f437383..fabad17a 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CreateFile.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.CreateFile.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using Xunit; namespace LibHac.Tests.Fs.IFileSystemTestBase diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteDirectory.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteDirectory.cs index a4f18b73..af127a6c 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteDirectory.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteDirectory.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using Xunit; namespace LibHac.Tests.Fs.IFileSystemTestBase diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteDirectoryRecursively.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteDirectoryRecursively.cs index 8d27bd17..9f2c9243 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteDirectoryRecursively.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteDirectoryRecursively.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using Xunit; namespace LibHac.Tests.Fs.IFileSystemTestBase diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteFile.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteFile.cs index c9fe658d..f8593414 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteFile.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.DeleteFile.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using Xunit; namespace LibHac.Tests.Fs.IFileSystemTestBase diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.GetEntryType.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.GetEntryType.cs index d94df8f3..70c1913a 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.GetEntryType.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.GetEntryType.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using Xunit; namespace LibHac.Tests.Fs.IFileSystemTestBase diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IDirectory.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IDirectory.cs index cb0bc160..80300da9 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IDirectory.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IDirectory.cs @@ -1,6 +1,7 @@ using System; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using Xunit; namespace LibHac.Tests.Fs.IFileSystemTestBase diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Read.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Read.cs index 8233e9ba..8eacc3d0 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Read.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Read.cs @@ -1,6 +1,7 @@ using System; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using Xunit; namespace LibHac.Tests.Fs.IFileSystemTestBase diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Size.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Size.cs index 4660e8e2..f9cce094 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Size.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Size.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using Xunit; namespace LibHac.Tests.Fs.IFileSystemTestBase diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Write.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Write.cs index 0c259473..8ca76e86 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Write.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.IFile.Write.cs @@ -1,6 +1,7 @@ using System; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using Xunit; namespace LibHac.Tests.Fs.IFileSystemTestBase diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.OpenDirectory.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.OpenDirectory.cs index 94e408bb..78188f07 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.OpenDirectory.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.OpenDirectory.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using Xunit; namespace LibHac.Tests.Fs.IFileSystemTestBase diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.OpenFile.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.OpenFile.cs index a6c5dfe6..85d6529a 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.OpenFile.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.OpenFile.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using Xunit; namespace LibHac.Tests.Fs.IFileSystemTestBase diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameDirectory.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameDirectory.cs index c6343f0f..74540f41 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameDirectory.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameDirectory.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using Xunit; namespace LibHac.Tests.Fs.IFileSystemTestBase diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameFile.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameFile.cs index f588af0d..696db645 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameFile.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.RenameFile.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using Xunit; namespace LibHac.Tests.Fs.IFileSystemTestBase diff --git a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.cs b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.cs index a5f76787..e3ea3ce1 100644 --- a/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.cs +++ b/tests/LibHac.Tests/Fs/IFileSystemTestBase/IFileSystemTests.cs @@ -1,4 +1,4 @@ -using LibHac.Fs; +using LibHac.Fs.Fsa; namespace LibHac.Tests.Fs.IFileSystemTestBase { diff --git a/tests/LibHac.Tests/Fs/InMemoryFileSystemTests.cs b/tests/LibHac.Tests/Fs/InMemoryFileSystemTests.cs index c4170dea..e99d4da8 100644 --- a/tests/LibHac.Tests/Fs/InMemoryFileSystemTests.cs +++ b/tests/LibHac.Tests/Fs/InMemoryFileSystemTests.cs @@ -1,4 +1,5 @@ using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.Tests.Fs.IFileSystemTestBase; namespace LibHac.Tests.Fs diff --git a/tests/LibHac.Tests/Fs/LayeredFileSystemTests.cs b/tests/LibHac.Tests/Fs/LayeredFileSystemTests.cs index 5e7949ee..0c9e3d22 100644 --- a/tests/LibHac.Tests/Fs/LayeredFileSystemTests.cs +++ b/tests/LibHac.Tests/Fs/LayeredFileSystemTests.cs @@ -1,6 +1,7 @@ using System; using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; using Xunit; diff --git a/tests/LibHac.Tests/Fs/SubdirectoryFileSystemTests.cs b/tests/LibHac.Tests/Fs/SubdirectoryFileSystemTests.cs index ab91e662..2046b743 100644 --- a/tests/LibHac.Tests/Fs/SubdirectoryFileSystemTests.cs +++ b/tests/LibHac.Tests/Fs/SubdirectoryFileSystemTests.cs @@ -1,5 +1,6 @@ using LibHac.Common; using LibHac.Fs; +using LibHac.Fs.Fsa; using LibHac.FsSystem; using LibHac.Tests.Fs.IFileSystemTestBase; using Xunit;