Skip to content

Commit

Permalink
Rollup merge of rust-lang#103005 - solid-rs:patch/kmc-solid/readdir-t…
Browse files Browse the repository at this point in the history
…erminator, r=m-ou-se

kmc-solid: Handle errors returned by `SOLID_FS_ReadDir`

Fixes the issue where the `std::fs::ReadDir` implementaton of the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets silently suppressed errors returned by the underlying `SOLID_FS_ReadDir` system function. The new implementation correctly handles all cases:

- `SOLID_ERR_NOTFOUND` indicates the end of directory stream.
- `SOLID_ERR_OK` + non-empty `d_name` indicates success.
- Some old filesystem drivers may return `SOLID_ERR_OK` + empty `d_name` to indicate the end of directory stream.
- Any other negative values (per ITRON convention) represent an error.
  • Loading branch information
matthiaskrgr authored Oct 20, 2022
2 parents 4689679 + 76bec17 commit da11d2f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions library/std/src/sys/solid/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,19 @@ impl Iterator for ReadDir {
type Item = io::Result<DirEntry>;

fn next(&mut self) -> Option<io::Result<DirEntry>> {
unsafe {
let mut out_dirent = MaybeUninit::uninit();
error::SolidError::err_if_negative(abi::SOLID_FS_ReadDir(
let entry = unsafe {
let mut out_entry = MaybeUninit::uninit();
match error::SolidError::err_if_negative(abi::SOLID_FS_ReadDir(
self.inner.dirp,
out_dirent.as_mut_ptr(),
))
.ok()?;
Some(Ok(DirEntry { entry: out_dirent.assume_init(), inner: Arc::clone(&self.inner) }))
}
out_entry.as_mut_ptr(),
)) {
Ok(_) => out_entry.assume_init(),
Err(e) if e.as_raw() == abi::SOLID_ERR_NOTFOUND => return None,
Err(e) => return Some(Err(e.as_io_error())),
}
};

(entry.d_name[0] != 0).then(|| Ok(DirEntry { entry, inner: Arc::clone(&self.inner) }))
}
}

Expand Down

0 comments on commit da11d2f

Please sign in to comment.