mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Add OperateRange to IFile and IStorage. Reorder methods
This commit is contained in:
parent
8390e10ae0
commit
576049ce88
7 changed files with 161 additions and 101 deletions
|
@ -12,8 +12,14 @@ namespace LibHac.Fs
|
|||
protected abstract Result ReadImpl(out long bytesRead, long offset, Span<byte> destination, ReadOption options);
|
||||
protected abstract Result WriteImpl(long offset, ReadOnlySpan<byte> source, WriteOption options);
|
||||
protected abstract Result FlushImpl();
|
||||
protected abstract Result GetSizeImpl(out long size);
|
||||
protected abstract Result SetSizeImpl(long size);
|
||||
protected abstract Result GetSizeImpl(out long size);
|
||||
|
||||
protected virtual Result OperateRangeImpl(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
public Result Read(out long bytesRead, long offset, Span<byte> destination, ReadOption options)
|
||||
{
|
||||
|
@ -53,6 +59,14 @@ namespace LibHac.Fs
|
|||
return FlushImpl();
|
||||
}
|
||||
|
||||
public Result SetSize(long size)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
if (size < 0) return ResultFs.ValueOutOfRange.Log();
|
||||
|
||||
return SetSizeImpl(size);
|
||||
}
|
||||
|
||||
public Result GetSize(out long size)
|
||||
{
|
||||
if (IsDisposed)
|
||||
|
@ -64,12 +78,12 @@ namespace LibHac.Fs
|
|||
return GetSizeImpl(out size);
|
||||
}
|
||||
|
||||
public Result SetSize(long size)
|
||||
public Result OperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
if (size < 0) return ResultFs.ValueOutOfRange.Log();
|
||||
|
||||
return SetSizeImpl(size);
|
||||
return OperateRange(outBuffer, operationId, offset, size, inBuffer);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
|
@ -22,6 +22,29 @@ namespace LibHac.Fs
|
|||
protected abstract Result GetEntryTypeImpl(out DirectoryEntryType entryType, string path);
|
||||
protected abstract Result CommitImpl();
|
||||
|
||||
protected virtual Result GetFreeSpaceSizeImpl(out long freeSpace, string path)
|
||||
{
|
||||
freeSpace = default;
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected virtual Result GetTotalSpaceSizeImpl(out long totalSpace, string path)
|
||||
{
|
||||
totalSpace = default;
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected virtual Result GetFileTimeStampRawImpl(out FileTimeStampRaw timeStamp, string path)
|
||||
{
|
||||
timeStamp = default;
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected virtual Result QueryEntryImpl(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId, string path)
|
||||
{
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
public Result CreateDirectory(string path)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
@ -169,28 +192,5 @@ namespace LibHac.Fs
|
|||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing) { }
|
||||
|
||||
protected virtual Result GetFreeSpaceSizeImpl(out long freeSpace, string path)
|
||||
{
|
||||
freeSpace = default;
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected virtual Result GetTotalSpaceSizeImpl(out long totalSpace, string path)
|
||||
{
|
||||
totalSpace = default;
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected virtual Result GetFileTimeStampRawImpl(out FileTimeStampRaw timeStamp, string path)
|
||||
{
|
||||
timeStamp = default;
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
protected virtual Result QueryEntryImpl(Span<byte> outBuffer, ReadOnlySpan<byte> inBuffer, QueryId queryId, string path)
|
||||
{
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,4 +119,12 @@ namespace LibHac.Fs
|
|||
None = 0,
|
||||
Flush = 1
|
||||
}
|
||||
|
||||
public enum OperationId
|
||||
{
|
||||
Clear = 0,
|
||||
ClearSignature = 1,
|
||||
InvalidateCache = 2,
|
||||
QueryRange = 3
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,13 @@ namespace LibHac.Fs
|
|||
/// </summary>
|
||||
Result Flush();
|
||||
|
||||
/// <summary>
|
||||
/// Sets the size of the file in bytes.
|
||||
/// </summary>
|
||||
/// <param name="size">The desired size of the file in bytes.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
Result SetSize(long size);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of bytes in the file.
|
||||
/// </summary>
|
||||
|
@ -52,10 +59,15 @@ namespace LibHac.Fs
|
|||
Result GetSize(out long size);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the size of the file in bytes.
|
||||
/// Performs various operations on the file. Used to extend the functionality of the <see cref="IFile"/> interface.
|
||||
/// </summary>
|
||||
/// <param name="size">The desired size of the file in bytes.</param>
|
||||
/// <param name="outBuffer">A buffer that will contain the response from the operation.</param>
|
||||
/// <param name="operationId">The operation to be performed.</param>
|
||||
/// <param name="offset">The offset of the range to operate on.</param>
|
||||
/// <param name="size">The size of the range to operate on.</param>
|
||||
/// <param name="inBuffer">An input buffer. Size may vary depending on the operation performed.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
Result SetSize(long size);
|
||||
Result OperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer);
|
||||
}
|
||||
}
|
|
@ -8,20 +8,6 @@ namespace LibHac.Fs
|
|||
/// </summary>
|
||||
public interface IFileSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates all directories and subdirectories in the specified path unless they already exist.
|
||||
/// </summary>
|
||||
/// <param name="path">The full path of the directory to create.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
/// <remarks>
|
||||
/// The following <see cref="Result"/> codes may be returned under certain conditions:
|
||||
///
|
||||
/// The parent directory of the specified path does not exist: <see cref="ResultFs.PathNotFound"/>
|
||||
/// Specified path already exists as either a file or directory: <see cref="ResultFs.PathAlreadyExists"/>
|
||||
/// Insufficient free space to create the directory: <see cref="ResultFs.InsufficientFreeSpace"/>
|
||||
/// </remarks>
|
||||
Result CreateDirectory(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Creates or overwrites a file at the specified path.
|
||||
/// </summary>
|
||||
|
@ -39,6 +25,32 @@ namespace LibHac.Fs
|
|||
/// </remarks>
|
||||
Result CreateFile(string path, long size, CreateFileOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified file.
|
||||
/// </summary>
|
||||
/// <param name="path">The full path of the file to delete.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
/// <remarks>
|
||||
/// The following <see cref="Result"/> codes may be returned under certain conditions:
|
||||
///
|
||||
/// The specified path does not exist or is a directory: <see cref="ResultFs.PathNotFound"/>
|
||||
/// </remarks>
|
||||
Result DeleteFile(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Creates all directories and subdirectories in the specified path unless they already exist.
|
||||
/// </summary>
|
||||
/// <param name="path">The full path of the directory to create.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
/// <remarks>
|
||||
/// The following <see cref="Result"/> codes may be returned under certain conditions:
|
||||
///
|
||||
/// The parent directory of the specified path does not exist: <see cref="ResultFs.PathNotFound"/>
|
||||
/// Specified path already exists as either a file or directory: <see cref="ResultFs.PathAlreadyExists"/>
|
||||
/// Insufficient free space to create the directory: <see cref="ResultFs.InsufficientFreeSpace"/>
|
||||
/// </remarks>
|
||||
Result CreateDirectory(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified directory.
|
||||
/// </summary>
|
||||
|
@ -77,46 +89,20 @@ namespace LibHac.Fs
|
|||
Result CleanDirectoryRecursively(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Deletes the specified file.
|
||||
/// Renames or moves a file to a new location.
|
||||
/// </summary>
|
||||
/// <param name="path">The full path of the file to delete.</param>
|
||||
/// <param name="oldPath">The full path of the file to rename.</param>
|
||||
/// <param name="newPath">The new full path of the file.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
/// <remarks>
|
||||
/// If <paramref name="oldPath"/> and <paramref name="newPath"/> are the same, this function does nothing and returns successfully.
|
||||
/// The following <see cref="Result"/> codes may be returned under certain conditions:
|
||||
///
|
||||
/// The specified path does not exist or is a directory: <see cref="ResultFs.PathNotFound"/>
|
||||
/// <paramref name="oldPath"/> does not exist or is a directory: <see cref="ResultFs.PathNotFound"/>
|
||||
/// <paramref name="newPath"/>'s parent directory does not exist: <see cref="ResultFs.PathNotFound"/>
|
||||
/// <paramref name="newPath"/> already exists as either a file or directory: <see cref="ResultFs.PathAlreadyExists"/>
|
||||
/// </remarks>
|
||||
Result DeleteFile(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="IDirectory"/> instance for enumerating the specified directory.
|
||||
/// </summary>
|
||||
/// <param name="directory">If the operation returns successfully,
|
||||
/// An <see cref="IDirectory"/> instance for the specified directory.</param>
|
||||
/// <param name="path">The directory's full path.</param>
|
||||
/// <param name="mode">Specifies which sub-entries should be enumerated.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
/// <remarks>
|
||||
/// The following <see cref="Result"/> codes may be returned under certain conditions:
|
||||
///
|
||||
/// The specified path does not exist or is a file: <see cref="ResultFs.PathNotFound"/>
|
||||
/// </remarks>
|
||||
Result OpenDirectory(out IDirectory directory, string path, OpenDirectoryMode 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>The <see cref="Result"/> of the requested operation.</returns>
|
||||
/// <remarks>
|
||||
/// The following <see cref="Result"/> codes may be returned under certain conditions:
|
||||
///
|
||||
/// The specified path does not exist or is a directory: <see cref="ResultFs.PathNotFound"/>
|
||||
/// </remarks>
|
||||
Result OpenFile(out IFile file, string path, OpenMode mode);
|
||||
Result RenameFile(string oldPath, string newPath);
|
||||
|
||||
/// <summary>
|
||||
/// Renames or moves a directory to a new location.
|
||||
|
@ -135,22 +121,6 @@ namespace LibHac.Fs
|
|||
/// </remarks>
|
||||
Result RenameDirectory(string oldPath, string newPath);
|
||||
|
||||
/// <summary>
|
||||
/// Renames or moves a file to a new location.
|
||||
/// </summary>
|
||||
/// <param name="oldPath">The full path of the file to rename.</param>
|
||||
/// <param name="newPath">The new full path of the file.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
/// <remarks>
|
||||
/// If <paramref name="oldPath"/> and <paramref name="newPath"/> are the same, this function does nothing and returns successfully.
|
||||
/// The following <see cref="Result"/> codes may be returned under certain conditions:
|
||||
///
|
||||
/// <paramref name="oldPath"/> does not exist or is a directory: <see cref="ResultFs.PathNotFound"/>
|
||||
/// <paramref name="newPath"/>'s parent directory does not exist: <see cref="ResultFs.PathNotFound"/>
|
||||
/// <paramref name="newPath"/> already exists as either a file or directory: <see cref="ResultFs.PathAlreadyExists"/>
|
||||
/// </remarks>
|
||||
Result RenameFile(string oldPath, string newPath);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the specified path is a file or directory, or does not exist.
|
||||
/// </summary>
|
||||
|
@ -180,6 +150,43 @@ namespace LibHac.Fs
|
|||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
Result GetTotalSpaceSize(out long totalSpace, string path);
|
||||
|
||||
/// <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>The <see cref="Result"/> of the requested operation.</returns>
|
||||
/// <remarks>
|
||||
/// The following <see cref="Result"/> codes may be returned under certain conditions:
|
||||
///
|
||||
/// The specified path does not exist or is a directory: <see cref="ResultFs.PathNotFound"/>
|
||||
/// </remarks>
|
||||
Result OpenFile(out IFile file, string path, OpenMode mode);
|
||||
|
||||
/// <summary>
|
||||
/// Creates an <see cref="IDirectory"/> instance for enumerating the specified directory.
|
||||
/// </summary>
|
||||
/// <param name="directory">If the operation returns successfully,
|
||||
/// An <see cref="IDirectory"/> instance for the specified directory.</param>
|
||||
/// <param name="path">The directory's full path.</param>
|
||||
/// <param name="mode">Specifies which sub-entries should be enumerated.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
/// <remarks>
|
||||
/// The following <see cref="Result"/> codes may be returned under certain conditions:
|
||||
///
|
||||
/// The specified path does not exist or is a file: <see cref="ResultFs.PathNotFound"/>
|
||||
/// </remarks>
|
||||
Result OpenDirectory(out IDirectory directory, string path, OpenDirectoryMode mode);
|
||||
|
||||
/// <summary>
|
||||
/// Commits any changes to a transactional file system.
|
||||
/// Does nothing if called on a non-transactional file system.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
Result Commit();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the creation, last accessed, and last modified timestamps of a file or directory.
|
||||
/// </summary>
|
||||
|
@ -194,13 +201,6 @@ namespace LibHac.Fs
|
|||
/// </remarks>
|
||||
Result GetFileTimeStampRaw(out FileTimeStampRaw timeStamp, string path);
|
||||
|
||||
/// <summary>
|
||||
/// Commits any changes to a transactional file system.
|
||||
/// Does nothing if called on a non-transactional file system.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
Result Commit();
|
||||
|
||||
/// <summary>
|
||||
/// Performs a query on the specified file.
|
||||
/// </summary>
|
||||
|
|
|
@ -42,5 +42,17 @@ namespace LibHac.Fs
|
|||
/// </summary>
|
||||
/// <returns>The size of the <see cref="IStorage"/> in bytes.</returns>
|
||||
Result GetSize(out long size);
|
||||
|
||||
/// <summary>
|
||||
/// Performs various operations on the file. Used to extend the functionality of the <see cref="IStorage"/> interface.
|
||||
/// </summary>
|
||||
/// <param name="outBuffer">A buffer that will contain the response from the operation.</param>
|
||||
/// <param name="operationId">The operation to be performed.</param>
|
||||
/// <param name="offset">The offset of the range to operate on.</param>
|
||||
/// <param name="size">The size of the range to operate on.</param>
|
||||
/// <param name="inBuffer">An input buffer. Size may vary depending on the operation performed.</param>
|
||||
/// <returns>The <see cref="Result"/> of the requested operation.</returns>
|
||||
Result OperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,12 @@ namespace LibHac.Fs
|
|||
protected abstract Result GetSizeImpl(out long size);
|
||||
protected abstract Result SetSizeImpl(long size);
|
||||
|
||||
protected virtual Result OperateRangeImpl(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
return ResultFs.NotImplemented.Log();
|
||||
}
|
||||
|
||||
public Result Read(long offset, Span<byte> destination)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
@ -51,6 +57,14 @@ namespace LibHac.Fs
|
|||
return GetSizeImpl(out size);
|
||||
}
|
||||
|
||||
public Result OperateRange(Span<byte> outBuffer, OperationId operationId, long offset, long size,
|
||||
ReadOnlySpan<byte> inBuffer)
|
||||
{
|
||||
if (IsDisposed) return ResultFs.PreconditionViolation.Log();
|
||||
|
||||
return OperateRange(outBuffer, operationId, offset, size, inBuffer);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Make sure Dispose is only called once
|
||||
|
|
Loading…
Reference in a new issue