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:
Rob Bradford
2026-06-12 12:23:03 +01:00
parent aad8ea0bd7
commit a8b059328f

View File

@@ -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)
}
}