using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Duplicati.Proprietary.DiskImage.Disk;
using Duplicati.Proprietary.DiskImage.General;
namespace Duplicati.Proprietary.DiskImage.Partition;
///
/// Represents a single partition on a disk.
///
internal interface IPartition : IDisposable
{
///
/// Gets the parent partition table.
///
IPartitionTable PartitionTable { get; }
///
/// Gets the partition number (1-based).
///
int PartitionNumber { get; }
///
/// Gets the partition type identifier.
///
PartitionType Type { get; }
///
/// Gets the starting offset in bytes.
///
long StartOffset { get; }
///
/// Gets the size in bytes.
///
long Size { get; }
///
/// Gets the partition name (if available).
///
string? Name { get; }
///
/// Gets the filesystem type (if detectable).
///
FileSystemType FilesystemType { get; }
///
/// Gets the volume GUID (for GPT).
///
Guid? VolumeGuid { get; }
///
/// Creates a stream to read the raw partition data.
///
/// Cancellation token.
/// Stream for reading partition data.
Task OpenReadAsync(CancellationToken cancellationToken);
///
/// Creates a stream to write the raw partition data.
///
/// Cancellation token.
/// Stream for writing partition data.
Task OpenWriteAsync(CancellationToken cancellationToken);
}
///
/// Partition table parsing interface.
///
internal interface IPartitionTable : IDisposable
{
///
/// Gets the raw disk this table was parsed from. Null if the table was created from a byte array.
///
IRawDisk? RawDisk { get; }
///
/// Gets the partition table type.
///
PartitionTableType TableType { get; }
///
/// Enumerates all partitions on the disk.
///
/// Cancellation token.
/// Async enumerable of partitions.
IAsyncEnumerable EnumeratePartitions(CancellationToken cancellationToken);
///
/// Gets a specific partition by number.
///
/// The partition number.
/// The partition, or null if not found.
Task GetPartitionAsync(int partitionNumber, CancellationToken cancellationToken);
///
/// Gets the protective MBR (for GPT disks).
///
Task GetProtectiveMbrAsync(CancellationToken cancellationToken);
///
/// Gets the raw partition table data for backup/restore purposes.
/// For MBR: returns the MBR sector (512 bytes).
/// For GPT: returns the protective MBR + GPT header + partition entries.
///
Task GetPartitionTableDataAsync(CancellationToken cancellationToken);
}