aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / uefi / src / fs / dir_entry_iter.rs
| 1 | // SPDX-License-Identifier: MIT OR Apache-2.0 |
| 2 | |
| 3 | //! Module for directory iteration. See [`UefiDirectoryIter`]. |
| 4 | |
| 5 | use super::*; |
| 6 | use crate::{CStr16, Result, cstr16}; |
| 7 | use alloc::boxed::Box; |
| 8 | |
| 9 | /// Common skip dirs in UEFI/FAT-style file systems. |
| 10 | pub const COMMON_SKIP_DIRS: &[&CStr16] = &[cstr16!("."), cstr16!("..")]; |
| 11 | |
| 12 | /// Iterates over the entries of a UEFI directory. It returns boxed values of |
| 13 | /// type [`UefiFileInfo`]. |
| 14 | /// |
| 15 | /// Note that on UEFI/FAT-style file systems, the root dir usually doesn't |
| 16 | /// return the entries `.` and `..`, whereas sub directories do. |
| 17 | #[derive(Debug)] |
| 18 | pub struct UefiDirectoryIter(UefiDirectoryHandle); |
| 19 | |
| 20 | impl UefiDirectoryIter { |
| 21 | /// Constructor. |
| 22 | #[must_use] |
| 23 | pub const fn new(handle: UefiDirectoryHandle) -> Self { |
| 24 | Self(handle) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | impl Iterator for UefiDirectoryIter { |
| 29 | type Item = Result<Box<UefiFileInfo>, ()>; |
| 30 | |
| 31 | fn next(&mut self) -> Option<Self::Item> { |
| 32 | let e = self.0.read_entry_boxed(); |
| 33 | match e { |
| 34 | // no more entries |
| 35 | Ok(None) => None, |
| 36 | Ok(Some(e)) => Some(Ok(e)), |
| 37 | Err(e) => Some(Err(e)), |
| 38 | } |
| 39 | } |
| 40 | } |