Skip to content

Commit 2f15f20

Browse files
committed
fix Qid size calculation
The size of Qid was being calculated using std::mem::size_of_val. This function counts padding due to the Rust compiler aligning fields which results in an incorrect wire size. This patch adds a size function similar to other structures to explicitly calculate the size of Qid without padding.
1 parent 6d9b62a commit 2f15f20

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/fcall.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,14 @@ pub struct Qid {
288288
pub path: u64,
289289
}
290290

291+
impl Qid {
292+
pub fn size(&self) -> u32 {
293+
(size_of::<QidType>()
294+
+ size_of::<u32>()
295+
+ size_of::<u64>()) as u32
296+
}
297+
}
298+
291299
/// Filesystem information corresponding to `struct statfs` of Linux.
292300
///
293301
/// # Protocol
@@ -437,7 +445,7 @@ pub struct DirEntry {
437445

438446
impl DirEntry {
439447
pub fn size(&self) -> u32 {
440-
(size_of_val(&self.qid)
448+
(self.qid.size() as usize
441449
+ size_of_val(&self.offset)
442450
+ size_of_val(&self.typ)
443451
+ size_of::<u16>()

0 commit comments

Comments
 (0)