Files
duplicati/proprietary/DiskImage/Filesystem/Interfaces.cs
T

167 lines
6.0 KiB
C#
Raw Normal View History

2026-02-04 09:42:38 +01:00
using System;
using System.Collections;
using System.Collections.Generic;
2026-02-04 10:41:07 +01:00
using System.IO;
2026-02-04 09:42:38 +01:00
using System.Threading;
using System.Threading.Tasks;
using Duplicati.Proprietary.DiskImage.General;
2026-02-04 09:42:38 +01:00
using Duplicati.Proprietary.DiskImage.Partition;
namespace Duplicati.Proprietary.DiskImage.Filesystem;
2026-02-15 12:45:59 +01:00
/// <summary>
/// Interface for filesystem access on a partition.
/// Provides methods for listing, reading, and writing files within a filesystem.
/// </summary>
internal interface IFilesystem : IDisposable
2026-02-04 09:42:38 +01:00
{
2026-02-04 10:41:07 +01:00
/// <summary>
/// Gets the parent partition.
/// </summary>
IPartition Partition { get; }
2026-02-04 09:42:38 +01:00
2026-02-04 10:41:07 +01:00
/// <summary>
/// Gets the filesystem type.
/// </summary>
FileSystemType Type { get; }
/// <summary>
/// Gets filesystem-specific metadata. E.g. for journal filesystems, this could be the journal file.
/// </summary>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A task that resolves to filesystem-specific metadata.</returns>
Task<object?> GetFilesystemMetadataAsync(CancellationToken cancellationToken);
/// <summary>
/// Lists top-level files in the filesystem.
/// </summary>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A task that resolves to a collection of top-level files.</returns>
2026-02-04 13:03:16 +01:00
IAsyncEnumerable<IFile> ListFilesAsync(CancellationToken cancellationToken);
2026-02-04 10:41:07 +01:00
/// <summary>
/// Lists files in a directory.
/// </summary>
/// <param name="directory">The directory to list files from.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A task that resolves to a collection of files in the specified directory.</returns>
/// <throws cref="ArgumentNullException">Thrown if <paramref name="directory"/> is null.</throws>
/// <throws cref="ArgumentException">Thrown if <paramref name="directory"/> is not a directory.</throws>
2026-02-04 13:03:16 +01:00
IAsyncEnumerable<IFile> ListFilesAsync(IFile directory, CancellationToken cancellationToken);
2026-02-04 10:41:07 +01:00
2026-02-15 12:45:59 +01:00
/// <summary>
/// Opens a stream for reading a file.
/// </summary>
/// <param name="file">The file to open.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A stream for reading the file contents.</returns>
Task<Stream> OpenReadStreamAsync(IFile file, CancellationToken cancellationToken);
2026-02-15 12:45:59 +01:00
/// <summary>
/// Opens a stream for writing a file.
/// </summary>
/// <param name="file">The file to open.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A stream for writing the file contents.</returns>
Task<Stream> OpenWriteStreamAsync(IFile file, CancellationToken cancellationToken);
2026-02-15 12:45:59 +01:00
/// <summary>
/// Opens a stream for reading and writing a file.
/// </summary>
/// <param name="file">The file to open.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A stream for reading and writing the file contents.</returns>
Task<Stream> OpenReadWriteStreamAsync(IFile file, CancellationToken cancellationToken);
2026-02-15 12:45:59 +01:00
/// <summary>
/// Gets the length of a file.
/// </summary>
/// <param name="file">The file to get the length of.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>The file length in bytes.</returns>
Task<long> GetFileLengthAsync(IFile file, CancellationToken cancellationToken);
2026-02-15 12:45:59 +01:00
/// <summary>
/// Opens a stream for reading a file by path.
/// </summary>
/// <param name="path">The path to the file.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A stream for reading the file contents.</returns>
Task<Stream> OpenReadStreamAsync(string path, CancellationToken cancellationToken);
2026-02-15 12:45:59 +01:00
/// <summary>
/// Opens a stream for writing a file by path.
/// </summary>
/// <param name="path">The path to the file.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A stream for writing the file contents.</returns>
Task<Stream> OpenWriteStreamAsync(string path, CancellationToken cancellationToken);
2026-02-15 12:45:59 +01:00
/// <summary>
/// Opens a stream for reading and writing a file by path.
/// </summary>
/// <param name="path">The path to the file.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A stream for reading and writing the file contents.</returns>
Task<Stream> OpenReadWriteStreamAsync(string path, CancellationToken cancellationToken);
2026-02-15 12:45:59 +01:00
/// <summary>
/// Gets the length of a file by path.
/// </summary>
/// <param name="path">The path to the file.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>The file length in bytes.</returns>
Task<long> GetFileLengthAsync(string path, CancellationToken cancellationToken);
2026-02-04 10:41:07 +01:00
}
2026-02-15 12:45:59 +01:00
/// <summary>
/// Represents a file or directory within a filesystem.
/// </summary>
2026-02-04 10:41:07 +01:00
public interface IFile
{
2026-02-15 12:45:59 +01:00
/// <summary>
/// Gets the file path.
/// </summary>
2026-02-04 10:41:07 +01:00
string? Path { get; }
2026-02-15 12:45:59 +01:00
/// <summary>
/// Gets the physical address on disk (for raw block access).
/// </summary>
2026-02-04 10:41:07 +01:00
long? Address { get; }
2026-02-15 12:45:59 +01:00
/// <summary>
/// Gets the file size in bytes.
/// </summary>
2026-02-04 10:41:07 +01:00
long Size { get; }
2026-02-15 12:45:59 +01:00
/// <summary>
/// Gets a value indicating whether this is a directory.
/// </summary>
2026-02-04 10:41:07 +01:00
bool IsDirectory { get; }
}
2026-02-15 12:45:59 +01:00
/// <summary>
/// Represents file metadata including timestamps.
/// </summary>
2026-02-04 10:41:07 +01:00
public interface IFileMetadata
{
2026-02-15 12:45:59 +01:00
/// <summary>
/// Gets the raw metadata bytes from the filesystem.
/// </summary>
2026-02-04 10:41:07 +01:00
byte[]? RawMetadata { get; }
2026-02-15 12:45:59 +01:00
/// <summary>
/// Gets the creation time.
/// </summary>
2026-02-04 10:41:07 +01:00
DateTimeOffset? Created { get; }
2026-02-15 12:45:59 +01:00
/// <summary>
/// Gets the last modification time.
/// </summary>
2026-02-04 10:41:07 +01:00
DateTimeOffset? Modified { get; }
2026-02-15 12:45:59 +01:00
/// <summary>
/// Gets the last access time.
/// </summary>
2026-02-04 10:41:07 +01:00
DateTimeOffset? Accessed { get; }
2026-02-04 09:42:38 +01:00
}