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