From f1d704b8f8951e528080a43bb969d36e49452b7a Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Mon, 27 Dec 2021 18:12:43 -0700 Subject: [PATCH] Mark the versions of IFileSystem interfaces --- src/LibHac/Fs/Fsa/IDirectory.cs | 7 +-- src/LibHac/Fs/Fsa/IFile.cs | 43 +++++++++--------- src/LibHac/Fs/Fsa/IFileSystem.cs | 77 ++++++++++++++++---------------- 3 files changed, 64 insertions(+), 63 deletions(-) diff --git a/src/LibHac/Fs/Fsa/IDirectory.cs b/src/LibHac/Fs/Fsa/IDirectory.cs index 4207cd41..389a7109 100644 --- a/src/LibHac/Fs/Fsa/IDirectory.cs +++ b/src/LibHac/Fs/Fsa/IDirectory.cs @@ -6,8 +6,11 @@ namespace LibHac.Fs.Fsa; /// /// Provides an interface for enumerating the child entries of a directory. /// +/// Based on FS 13.1.0 (nnSdk 13.4.0) public abstract class IDirectory : IDisposable { + public virtual void Dispose() { } + /// /// Retrieves the next entries that this directory contains. Does not search subdirectories. /// @@ -43,6 +46,4 @@ public abstract class IDirectory : IDisposable protected abstract Result DoRead(out long entriesRead, Span entryBuffer); protected abstract Result DoGetEntryCount(out long entryCount); - - public virtual void Dispose() { } -} +} \ No newline at end of file diff --git a/src/LibHac/Fs/Fsa/IFile.cs b/src/LibHac/Fs/Fsa/IFile.cs index c9417e07..dac96ba5 100644 --- a/src/LibHac/Fs/Fsa/IFile.cs +++ b/src/LibHac/Fs/Fsa/IFile.cs @@ -10,17 +10,20 @@ namespace LibHac.Fs.Fsa; /// /// is similar to , and has a few main differences: /// -/// - allows an to be set that controls read, write -/// and append permissions for the file. +/// - 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 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 , +/// - 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. +/// the file will be expanded so that it is large enough to contain the written data. +/// Based on FS 13.1.0 (nnSdk 13.4.0) public abstract class IFile : IDisposable { + public virtual void Dispose() { } + /// /// Reads a sequence of bytes from the current . /// @@ -174,15 +177,6 @@ public abstract class IFile : IDisposable return Result.Success; } - protected Result DrySetSize(long size, OpenMode openMode) - { - // Check that we can write. - if (!openMode.HasFlag(OpenMode.Write)) - return ResultFs.WriteUnpermitted.Log(); - - return Result.Success; - } - protected Result DryWrite(out bool needsAppend, long offset, long size, in WriteOption option, OpenMode openMode) { @@ -196,6 +190,8 @@ public abstract class IFile : IDisposable Result rc = GetSize(out long fileSize); if (rc.IsFailure()) return rc; + needsAppend = false; + if (fileSize < offset + size) { if (!openMode.HasFlag(OpenMode.AllowAppend)) @@ -203,10 +199,15 @@ public abstract class IFile : IDisposable needsAppend = true; } - else - { - needsAppend = false; - } + + return Result.Success; + } + + protected Result DrySetSize(long size, OpenMode openMode) + { + // Check that we can write. + if (!openMode.HasFlag(OpenMode.Write)) + return ResultFs.WriteUnpermitted.Log(); return Result.Success; } @@ -218,6 +219,4 @@ public abstract class IFile : IDisposable protected abstract Result DoGetSize(out long size); protected abstract Result DoOperateRange(Span outBuffer, OperationId operationId, long offset, long size, ReadOnlySpan inBuffer); - - public virtual void Dispose() { } -} +} \ No newline at end of file diff --git a/src/LibHac/Fs/Fsa/IFileSystem.cs b/src/LibHac/Fs/Fsa/IFileSystem.cs index 913655b3..b405de69 100644 --- a/src/LibHac/Fs/Fsa/IFileSystem.cs +++ b/src/LibHac/Fs/Fsa/IFileSystem.cs @@ -8,8 +8,11 @@ namespace LibHac.Fs.Fsa; /// /// Provides an interface for accessing a file system. / is used as the path delimiter. /// +/// Based on FS 13.1.0 (nnSdk 13.4.0) public abstract class IFileSystem : IDisposable { + public virtual void Dispose() { } + /// /// Creates or overwrites a file at the specified path. /// @@ -171,25 +174,22 @@ public abstract class IFileSystem : IDisposable } /// - /// Gets the amount of available free space on a drive, in bytes. + /// Opens an instance for the specified path. /// - /// 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. - public Result GetFreeSpaceSize(out long freeSpace, in Path path) + /// If the operation returns successfully, + /// An instance for the specified path. + /// The full path of the file to open. + /// Specifies the access permissions of the created . + /// : The operation was successful.
+ /// : The specified path does not exist or is a directory.
+ /// : When opening as , + /// the file is already opened as .
+ public Result OpenFile(ref UniqueRef file, in Path path, OpenMode mode) { - return DoGetFreeSpaceSize(out freeSpace, in path); - } + if ((mode & OpenMode.ReadWrite) == 0 || (mode & ~OpenMode.All) != 0) + return ResultFs.InvalidModeForFileOpen.Log(); - /// - /// Gets the total size of storage space on a drive, in bytes. - /// - /// 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. - public Result GetTotalSpaceSize(out long totalSpace, in Path path) - { - return DoGetTotalSpaceSize(out totalSpace, in path); + return DoOpenFile(ref file, in path, mode); } /// @@ -215,25 +215,6 @@ public abstract class IFileSystem : IDisposable return DoOpenFile(ref file, in pathNormalized, mode); } - /// - /// Opens an instance for the specified path. - /// - /// If the operation returns successfully, - /// An instance for the specified path. - /// The full path of the file to open. - /// Specifies the access permissions of the created . - /// : The operation was successful.
- /// : The specified path does not exist or is a directory.
- /// : When opening as , - /// the file is already opened as .
- public Result OpenFile(ref UniqueRef file, in Path path, OpenMode mode) - { - if ((mode & OpenMode.ReadWrite) == 0 || (mode & ~OpenMode.All) != 0) - return ResultFs.InvalidModeForFileOpen.Log(); - - return DoOpenFile(ref file, in path, mode); - } - /// /// Creates an instance for enumerating the specified directory. /// @@ -264,6 +245,28 @@ public abstract class IFileSystem : IDisposable public Result Flush() => DoFlush(); + /// + /// Gets the amount of available free space on a drive, in bytes. + /// + /// 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. + public Result GetFreeSpaceSize(out long freeSpace, in Path path) + { + return DoGetFreeSpaceSize(out freeSpace, in path); + } + + /// + /// Gets the total size of storage space on a drive, in bytes. + /// + /// 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. + public Result GetTotalSpaceSize(out long totalSpace, in Path path) + { + return DoGetTotalSpaceSize(out totalSpace, in path); + } + /// /// Gets the creation, last accessed, and last modified timestamps of a file or directory. /// @@ -333,8 +336,6 @@ public abstract class IFileSystem : IDisposable protected virtual Result DoQueryEntry(Span outBuffer, ReadOnlySpan inBuffer, QueryId queryId, in Path path) => ResultFs.NotImplemented.Log(); - - public virtual void Dispose() { } } /// @@ -372,4 +373,4 @@ public enum QueryId UpdateMac = 1, IsSignedSystemPartitionOnSdCardValid = 2, QueryUnpreparedFileInformation = 3 -} +} \ No newline at end of file