mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: Implement FileExt for RawFile
Implement std::os::unix::fs::FileExt for RawFile by delegating to the inner File. This enables callers holding a reference to a RawFile to use read_exact_at and write_all_at directly for non-cursor I/O (like pread, etc) without going through custom helper functions. Assisted-by: Claude:Opus-4.6 Signed-off-by: Rob Bradford <rbradford@meta.com>
This commit is contained in:
@@ -12,6 +12,7 @@ use std::alloc::{Layout, alloc_zeroed, dealloc};
|
||||
use std::fs::{File, Metadata};
|
||||
use std::io::{self, Read, Seek, SeekFrom, Write};
|
||||
use std::os::fd::{AsFd, BorrowedFd};
|
||||
use std::os::unix::fs::FileExt;
|
||||
use std::os::unix::io::{AsRawFd, RawFd};
|
||||
use std::{result, slice};
|
||||
|
||||
@@ -404,3 +405,13 @@ impl AsFd for RawFile {
|
||||
self.file.as_fd()
|
||||
}
|
||||
}
|
||||
|
||||
impl FileExt for RawFile {
|
||||
fn read_at(&self, buf: &mut [u8], offset: u64) -> io::Result<usize> {
|
||||
self.file.read_at(buf, offset)
|
||||
}
|
||||
|
||||
fn write_at(&self, buf: &[u8], offset: u64) -> io::Result<usize> {
|
||||
self.file.write_at(buf, offset)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user