From bf7f80a9372ce196172e332ac12d0671c3eda12f Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 27 Aug 2025 17:56:23 +0300 Subject: [PATCH] core/io: Switch Unix I/O to use libc::pwrite() We use libc elsewhere for fault injection reasons, so let's do this call-site too. --- core/io/unix.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/core/io/unix.rs b/core/io/unix.rs index b7567b683..601f20c83 100644 --- a/core/io/unix.rs +++ b/core/io/unix.rs @@ -219,15 +219,22 @@ impl File for UnixFile { #[instrument(err, skip_all, level = Level::TRACE)] fn pwrite(&self, pos: usize, buffer: Arc, c: Completion) -> Result { let file = self.file.lock(); - let result = { rustix::io::pwrite(file.as_fd(), buffer.as_slice(), pos as u64) }; - match result { - Ok(n) => { - trace!("pwrite n: {}", n); - // Read succeeded immediately - c.complete(n as i32); - Ok(c) - } - Err(e) => Err(e.into()), + let result = unsafe { + libc::pwrite( + file.as_raw_fd(), + buffer.as_slice().as_ptr() as *const libc::c_void, + buffer.as_slice().len(), + pos as libc::off_t, + ) + }; + if result == -1 { + let e = std::io::Error::last_os_error(); + Err(e.into()) + } else { + trace!("pwrite n: {}", result); + // Write succeeded immediately + c.complete(result as i32); + Ok(c) } }