std: sys: fs: uefi: Implement File::write

Tested using OVMF on QEMU.

Signed-off-by: Ayush Singh <ayush@beagleboard.org>
This commit is contained in:
Ayush Singh
2026-01-09 09:32:20 +05:30
parent 3fda0e426c
commit ccc86f2228
+21 -2
View File
@@ -336,8 +336,8 @@ pub fn read_buf(&self, cursor: BorrowedCursor<'_>) -> io::Result<()> {
crate::io::default_read_buf(|buf| self.read(buf), cursor)
}
pub fn write(&self, _buf: &[u8]) -> io::Result<usize> {
unsupported()
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
self.0.write(buf)
}
pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
@@ -692,6 +692,25 @@ pub(crate) fn read_dir_entry(&self) -> io::Result<Option<UefiBox<file::Info>>> {
}
}
pub(crate) fn write(&self, buf: &[u8]) -> io::Result<usize> {
let file_ptr = self.protocol.as_ptr();
let mut buf_size = buf.len();
let r = unsafe {
((*file_ptr).write)(
file_ptr,
&mut buf_size,
buf.as_ptr().cast::<crate::ffi::c_void>().cast_mut(),
)
};
if buf_size == 0 && r.is_error() {
Err(io::Error::from_raw_os_error(r.as_usize()))
} else {
Ok(buf_size)
}
}
pub(crate) fn file_info(&self) -> io::Result<UefiBox<file::Info>> {
let file_ptr = self.protocol.as_ptr();
let mut info_id = file::INFO_ID;