using System; using System.Collections.Generic; using System.IO; using System.Threading; using System.Threading.Tasks; using Duplicati.Proprietary.DiskImage.General; namespace Duplicati.Proprietary.DiskImage.Disk; /// /// Low-level disk access interface for raw disk reading and writing. /// internal interface IRawDisk : IDisposable { /// /// Gets the platform-specific prefix for disk entries (e.g., "\\.\" on Windows, "/dev/" on Unix). /// static abstract string Prefix { get; } /// /// Gets the disk identifier (e.g., "\\.\PhysicalDrive0" or "/dev/sda") /// string DevicePath { get; } /// /// Gets the total size of the disk in bytes. /// long Size { get; } /// /// Gets the sector size in bytes. /// int SectorSize { get; } /// /// Gets the number of sectors on the disk. /// int Sectors { get; } /// /// Gets whether the disk is opened for write access. /// bool IsWriteable { get; } /// /// Automatically unmounts the target disk. /// /// Cancellation token. /// True if the disk was successfully unmounted. Task AutoUnmountAsync(CancellationToken cancellationToken); /// /// Initializes the disk access interface. /// /// Cancellation token. /// True if initialization was successful. Task InitializeAsync(CancellationToken cancellationToken); /// /// Initializes the disk access interface with write access. /// /// Whether to enable write access. /// Cancellation token. /// True if initialization was successful. Task InitializeAsync(bool enableWrite, CancellationToken cancellationToken); /// /// Finalizes the disk access interface. /// /// Cancellation token. /// True if finalization was successful. Task FinalizeAsync(CancellationToken cancellationToken); /// /// Reads raw sectors from the disk. /// /// The starting sector number. /// The number of sectors to read. /// Cancellation token. /// Stream containing the raw sector data. Task ReadSectorsAsync(long startSector, int sectorCount, CancellationToken cancellationToken); /// /// Reads a specific byte range from the disk. /// /// The byte offset. /// The number of bytes to read. /// Cancellation token. /// Stream containing the raw data. Task ReadBytesAsync(long offset, int length, CancellationToken cancellationToken); /// /// Reads a specific byte range from the disk into a caller-provided buffer. /// /// The byte offset. /// The buffer to read data into. /// Cancellation token. /// The number of bytes read. Task ReadBytesAsync(long offset, Memory destination, CancellationToken cancellationToken); /// /// Writes raw sectors to the disk. /// /// The starting sector number. /// The data to write (must be sector-aligned). /// Cancellation token. /// The number of bytes written. Task WriteSectorsAsync(long startSector, byte[] data, CancellationToken cancellationToken); /// /// Writes a specific byte range to the disk. /// /// The byte offset. /// The data to write. /// Cancellation token. /// The number of bytes written. Task WriteBytesAsync(long offset, byte[] data, CancellationToken cancellationToken); /// /// Writes a specific byte range to the disk from a caller-provided buffer. /// /// The byte offset. /// The data to write. /// Cancellation token. /// The number of bytes written. Task WriteBytesAsync(long offset, ReadOnlyMemory data, CancellationToken cancellationToken); /// /// Lists available physical drives on the system, returning a mapping of device paths to friendly names. /// /// Cancellation token. /// A list of physical drive information. static abstract IAsyncEnumerable ListPhysicalDrivesAsync(CancellationToken cancellationToken); }