block: disk_file: Add DiskFd trait

Backing file descriptor access for disk images backed by
a file. Returns a BorrowedDiskFd that wraps the raw fd
with lifetime tracking. Not available for network or
memory backed disk formats.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-03-12 20:19:00 +01:00
committed by Rob Bradford
parent 2df731b8d3
commit 2fa877e087

View File

@@ -36,6 +36,7 @@
use std::fmt::Debug;
use crate::BlockResult;
use crate::async_io::BorrowedDiskFd;
/// Reported capacity of a disk image.
pub trait DiskSize: Send + Debug {
@@ -48,3 +49,9 @@ pub trait PhysicalSize: Send + Debug {
/// Actual bytes occupied on the host filesystem.
fn physical_size(&self) -> BlockResult<u64>;
}
/// Backing file descriptor access for disk images backed by a file.
pub trait DiskFd: Send + Debug {
/// Borrows the underlying file descriptor.
fn fd(&self) -> BorrowedDiskFd<'_>;
}