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 -4
View File
@@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0
use crate::vhd::VhdFooter;
use crate::BlockBackend;
use std::fs::File;
use std::io::{Read, Seek, SeekFrom, Write};
use std::os::unix::io::{AsRawFd, RawFd};
@@ -24,10 +25,6 @@ impl FixedVhd {
position: 0,
})
}
pub fn size(&self) -> u64 {
self.size
}
}
impl AsRawFd for FixedVhd {
@@ -76,6 +73,12 @@ impl Seek for FixedVhd {
}
}
impl BlockBackend for FixedVhd {
fn size(&self) -> std::result::Result<u64, crate::Error> {
Ok(self.size)
}
}
impl Clone for FixedVhd {
fn clone(&self) -> Self {
Self {