block: introduce trait BlockBackend for block types

This commit introduces the trait `BlockBackend` with generic ops
including read, write and seek, which can be used for common I/O
interfaces for the block types without using `DiskFile` and `AsyncIo`.

Signed-off-by: Yu Li <liyu.yukiteru@bytedance.com>
This commit is contained in:
Yu Li
2023-07-12 10:27:45 +08:00
committed by Rob Bradford
parent 447cad3861
commit 741d640330
7 changed files with 71 additions and 8 deletions
+7
View File
@@ -8,6 +8,7 @@ use crate::vhdx::{
vhdx_io::VhdxIoError,
vhdx_metadata::{DiskSpec, VhdxMetadataError},
};
use crate::BlockBackend;
use byteorder::{BigEndian, ByteOrder};
use remain::sorted;
use std::collections::btree_map::BTreeMap;
@@ -208,6 +209,12 @@ impl Seek for Vhdx {
}
}
impl BlockBackend for Vhdx {
fn size(&self) -> std::result::Result<u64, crate::Error> {
Ok(self.virtual_disk_size())
}
}
impl Clone for Vhdx {
fn clone(&self) -> Self {
Vhdx {