interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / uefi / src / fs / dir_entry_iter.rs

40 lines · 1132 bytes Raw Blame History
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! Module for directory iteration. See [`UefiDirectoryIter`].
4
5use super::*;
6use crate::{CStr16, Result, cstr16};
7use alloc::boxed::Box;
8
9/// Common skip dirs in UEFI/FAT-style file systems.
10pub 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)]
18pub struct UefiDirectoryIter(UefiDirectoryHandle);
19
20impl UefiDirectoryIter {
21 /// Constructor.
22 #[must_use]
23 pub const fn new(handle: UefiDirectoryHandle) -> Self {
24 Self(handle)
25 }
26}
27
28impl 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}