Skip to content

Commit bb93d85

Browse files
committed
Fix readdirplus to send available Dirent on error
If there's an error, we can only signal it if we haven't stored any entries yet - otherwise we'd end up with wrong lookup counts for the entries that are already in the buffer. So we return what we've collected until that point. Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
1 parent 38a0d87 commit bb93d85

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/passthrough/fs.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ impl PassthroughFs {
561561
}
562562

563563
let mut rem = &buf[..];
564+
let orig_rem_len = rem.len();
564565
while !rem.is_empty() {
565566
// We only use debug asserts here because these values are coming from the kernel and we
566567
// trust them implicitly.
@@ -599,7 +600,12 @@ impl PassthroughFs {
599600
match res {
600601
Ok(0) => break,
601602
Ok(_) => rem = &rem[dirent64.d_reclen as usize..],
602-
Err(e) => return Err(e),
603+
// If there's an error, we can only signal it if we haven't
604+
// stored any entries yet - otherwise we'd end up with wrong
605+
// lookup counts for the entries that are already in the
606+
// buffer. So we return what we've collected until that point.
607+
Err(e) if rem.len() == orig_rem_len => return Err(e),
608+
Err(_) => return Ok(()),
603609
}
604610
}
605611

0 commit comments

Comments
 (0)