diff --git a/core/io/io_uring.rs b/core/io/io_uring.rs index b0f1ed269..be8083032 100644 --- a/core/io/io_uring.rs +++ b/core/io/io_uring.rs @@ -354,10 +354,10 @@ impl File for UringFile { Ok(self.file.metadata()?.len()) } - fn truncate(&self, len: u64, c: Completion) -> Result> { + fn truncate(&self, len: usize, c: Completion) -> Result> { let mut io = self.io.borrow_mut(); let truncate = with_fd!(self, |fd| { - io_uring::opcode::Ftruncate::new(fd, len) + io_uring::opcode::Ftruncate::new(fd, len as u64) .build() .user_data(io.ring.get_key()) }); diff --git a/core/io/memory.rs b/core/io/memory.rs index 93c248571..037a0b0f7 100644 --- a/core/io/memory.rs +++ b/core/io/memory.rs @@ -174,7 +174,7 @@ impl File for MemoryFile { Ok(c) } - fn truncate(&self, len: u64, c: Completion) -> Result> { + fn truncate(&self, len: usize, c: Completion) -> Result> { let new_size = len as usize; if new_size < self.size.get() { // Truncate pages diff --git a/core/io/mod.rs b/core/io/mod.rs index 0113db0eb..10b64339d 100644 --- a/core/io/mod.rs +++ b/core/io/mod.rs @@ -19,7 +19,7 @@ pub trait File: Send + Sync { -> Result; fn sync(&self, c: Completion) -> Result; fn size(&self) -> Result; - fn truncate(&self, len: u64, c: Completion) -> Result>; + fn truncate(&self, len: usize, c: Completion) -> Result>; } #[derive(Debug, Copy, Clone, PartialEq)] diff --git a/core/io/unix.rs b/core/io/unix.rs index 0eee99321..a98943836 100644 --- a/core/io/unix.rs +++ b/core/io/unix.rs @@ -452,9 +452,9 @@ impl File for UnixFile<'_> { } #[instrument(err, skip_all, level = Level::INFO)] - fn truncate(&self, len: u64, c: Completion) -> Result> { + fn truncate(&self, len: usize, c: Completion) -> Result> { let file = self.file.borrow(); - let result = file.set_len(len); + let result = file.set_len(len as u64); let c = Arc::new(c); match result { Ok(()) => { diff --git a/core/io/vfs.rs b/core/io/vfs.rs index a34d8dda1..50873636e 100644 --- a/core/io/vfs.rs +++ b/core/io/vfs.rs @@ -166,7 +166,7 @@ impl File for VfsFileImpl { } } - fn truncate(&self, len: u64, c: Completion) -> Result> { + fn truncate(&self, len: usize, c: Completion) -> Result> { if self.vfs.is_null() { return Err(LimboError::ExtensionError("VFS is null".to_string())); } diff --git a/macros/src/ext/vfs_derive.rs b/macros/src/ext/vfs_derive.rs index eb2115ac1..5e813410a 100644 --- a/macros/src/ext/vfs_derive.rs +++ b/macros/src/ext/vfs_derive.rs @@ -192,17 +192,17 @@ pub fn derive_vfs_module(input: TokenStream) -> TokenStream { } #[no_mangle] - pub unsafe extern "C" fn #trunc_fn_name(file_ptr: *const ::std::ffi::c_void, len: i64) -> i32 { + pub unsafe extern "C" fn #trunc_fn_name(file_ptr: *const ::std::ffi::c_void, len: i64) -> ::turso_ext::ResultCode { if file_ptr.is_null() { - return -1; + return ::turso_ext::ResultCode::Error; } let vfs_file: &mut ::turso_ext::VfsFileImpl = &mut *(file_ptr as *mut ::turso_ext::VfsFileImpl); let file: &mut <#struct_name as ::turso_ext::VfsExtension>::File = &mut *(vfs_file.file as *mut <#struct_name as ::turso_ext::VfsExtension>::File); if <#struct_name as ::turso_ext::VfsExtension>::File::truncate(file, len).is_err() { - return -1; + return ::turso_ext::ResultCode::Error; } - 0 + ::turso_ext::ResultCode::OK } #[no_mangle]