Mark the versions of IFileSystem interfaces

This commit is contained in:
Alex Barney 2021-12-27 18:12:43 -07:00
parent 3940ca9d76
commit f1d704b8f8
3 changed files with 64 additions and 63 deletions

View file

@ -6,8 +6,11 @@ namespace LibHac.Fs.Fsa;
/// <summary>
/// Provides an interface for enumerating the child entries of a directory.
/// </summary>
/// <remarks>Based on FS 13.1.0 (nnSdk 13.4.0)</remarks>
public abstract class IDirectory : IDisposable
{
public virtual void Dispose() { }
/// <summary>
/// Retrieves the next entries that this directory contains. Does not search subdirectories.
/// </summary>
@ -43,6 +46,4 @@ public abstract class IDirectory : IDisposable
protected abstract Result DoRead(out long entriesRead, Span<DirectoryEntry> entryBuffer);
protected abstract Result DoGetEntryCount(out long entryCount);
public virtual void Dispose() { }
}
}

View file

@ -10,17 +10,20 @@ namespace LibHac.Fs.Fsa;
/// </summary>
/// <remarks><see cref="IFile"/> is similar to <see cref="IStorage"/>, and has a few main differences:
///
/// - <see cref="IFile"/> allows an <see cref="OpenMode"/> to be set that controls read, write
/// and append permissions for the file.
/// <para>- <see cref="IFile"/> allows an <see cref="OpenMode"/> to be set that controls read, write
/// and append permissions for the file.</para>
///
/// - If the <see cref="IFile"/> 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.
/// <para>- If the <see cref="IFile"/> 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.</para>
///
/// - If <see cref="Write"/> is called on an offset past the end of the <see cref="IFile"/>,
/// <para>- If <see cref="Write"/> is called on an offset past the end of the <see cref="IFile"/>,
/// the <see cref="OpenMode.AllowAppend"/> mode is set and the file supports expansion,
/// the file will be expanded so that it is large enough to contain the written data.</remarks>
/// the file will be expanded so that it is large enough to contain the written data.</para>
/// <para>Based on FS 13.1.0 (nnSdk 13.4.0)</para></remarks>
public abstract class IFile : IDisposable
{
public virtual void Dispose() { }
/// <summary>
/// Reads a sequence of bytes from the current <see cref="IFile"/>.
/// </summary>
@ -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<byte> outBuffer, OperationId operationId, long offset, long size,
ReadOnlySpan<byte> inBuffer);
public virtual void Dispose() { }
}
}

View file

@ -8,8 +8,11 @@ namespace LibHac.Fs.Fsa;
/// <summary>
/// Provides an interface for accessing a file system. <c>/</c> is used as the path delimiter.
/// </summary>
/// <remarks>Based on FS 13.1.0 (nnSdk 13.4.0)</remarks>
public abstract class IFileSystem : IDisposable
{
public virtual void Dispose() { }
/// <summary>
/// Creates or overwrites a file at the specified path.
/// </summary>
@ -171,25 +174,22 @@ public abstract class IFileSystem : IDisposable
}
/// <summary>
/// Gets the amount of available free space on a drive, in bytes.
/// Opens an <see cref="IFile"/> instance for the specified path.
/// </summary>
/// <param name="freeSpace">If the operation returns successfully, the amount of free space available on the drive, in bytes.</param>
/// <param name="path">The path of the drive to query. Unused in almost all cases.</param>
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
public Result GetFreeSpaceSize(out long freeSpace, in Path path)
/// <param name="file">If the operation returns successfully,
/// An <see cref="IFile"/> instance for the specified path.</param>
/// <param name="path">The full path of the file to open.</param>
/// <param name="mode">Specifies the access permissions of the created <see cref="IFile"/>.</param>
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/>
/// <see cref="ResultFs.PathNotFound"/>: The specified path does not exist or is a directory.<br/>
/// <see cref="ResultFs.TargetLocked"/>: When opening as <see cref="OpenMode.Write"/>,
/// the file is already opened as <see cref="OpenMode.Write"/>.</returns>
public Result OpenFile(ref UniqueRef<IFile> 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();
/// <summary>
/// Gets the total size of storage space on a drive, in bytes.
/// </summary>
/// <param name="totalSpace">If the operation returns successfully, the total size of the drive, in bytes.</param>
/// <param name="path">The path of the drive to query. Unused in almost all cases.</param>
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
public Result GetTotalSpaceSize(out long totalSpace, in Path path)
{
return DoGetTotalSpaceSize(out totalSpace, in path);
return DoOpenFile(ref file, in path, mode);
}
/// <summary>
@ -215,25 +215,6 @@ public abstract class IFileSystem : IDisposable
return DoOpenFile(ref file, in pathNormalized, mode);
}
/// <summary>
/// Opens an <see cref="IFile"/> instance for the specified path.
/// </summary>
/// <param name="file">If the operation returns successfully,
/// An <see cref="IFile"/> instance for the specified path.</param>
/// <param name="path">The full path of the file to open.</param>
/// <param name="mode">Specifies the access permissions of the created <see cref="IFile"/>.</param>
/// <returns><see cref="Result.Success"/>: The operation was successful.<br/>
/// <see cref="ResultFs.PathNotFound"/>: The specified path does not exist or is a directory.<br/>
/// <see cref="ResultFs.TargetLocked"/>: When opening as <see cref="OpenMode.Write"/>,
/// the file is already opened as <see cref="OpenMode.Write"/>.</returns>
public Result OpenFile(ref UniqueRef<IFile> 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);
}
/// <summary>
/// Creates an <see cref="IDirectory"/> instance for enumerating the specified directory.
/// </summary>
@ -264,6 +245,28 @@ public abstract class IFileSystem : IDisposable
public Result Flush() => DoFlush();
/// <summary>
/// Gets the amount of available free space on a drive, in bytes.
/// </summary>
/// <param name="freeSpace">If the operation returns successfully, the amount of free space available on the drive, in bytes.</param>
/// <param name="path">The path of the drive to query. Unused in almost all cases.</param>
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
public Result GetFreeSpaceSize(out long freeSpace, in Path path)
{
return DoGetFreeSpaceSize(out freeSpace, in path);
}
/// <summary>
/// Gets the total size of storage space on a drive, in bytes.
/// </summary>
/// <param name="totalSpace">If the operation returns successfully, the total size of the drive, in bytes.</param>
/// <param name="path">The path of the drive to query. Unused in almost all cases.</param>
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
public Result GetTotalSpaceSize(out long totalSpace, in Path path)
{
return DoGetTotalSpaceSize(out totalSpace, in path);
}
/// <summary>
/// Gets the creation, last accessed, and last modified timestamps of a file or directory.
/// </summary>
@ -333,8 +336,6 @@ public abstract class IFileSystem : IDisposable
protected virtual Result DoQueryEntry(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId,
in Path path) => ResultFs.NotImplemented.Log();
public virtual void Dispose() { }
}
/// <summary>
@ -372,4 +373,4 @@ public enum QueryId
UpdateMac = 1,
IsSignedSystemPartitionOnSdCardValid = 2,
QueryUnpreparedFileInformation = 3
}
}