From c4990a4b0936a15d1e82362c4bde34139cd12e17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fatay=20Yi=C4=9Fit=20=C5=9Eahin?= Date: Tue, 26 Mar 2024 15:11:07 +0100 Subject: [PATCH] fuse: fix length calculation for header Solves #1111 --- src/fs/fuse.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/fs/fuse.rs b/src/fs/fuse.rs index 01830a94ef..d23fb6365f 100644 --- a/src/fs/fuse.rs +++ b/src/fs/fuse.rs @@ -482,7 +482,9 @@ where fn new(nodeid: u64, op_header: O::InStruct) -> Box { Box::new(Cmd { in_header: fuse_abi::InHeader { - len: Layout::new::().size() as u32, + // The length we need the provide in the header is not the same as the size of the struct because of padding, so we need to calculate it manually. + len: (core::mem::size_of::() + + core::mem::size_of::()) as u32, opcode: O::OP_CODE as u32, nodeid, unique: 1, @@ -498,7 +500,10 @@ impl Cmd { fn with_capacity(nodeid: u64, op_header: O::InStruct, len: usize) -> Box> { let mut cmd = unsafe { Self::new_uninit(len) }; cmd.in_header = MaybeUninit::new(fuse_abi::InHeader { - len: core::mem::size_of_val(cmd.as_ref()) + // The length we need the provide in the header is not the same as the size of the struct because of padding, so we need to calculate it manually. + len: (core::mem::size_of::() + + core::mem::size_of::() + + len) .try_into() .expect("The command is too large"), opcode: O::OP_CODE as u32,