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 / proto / media / fs.rs

61 lines · 2120 bytes Raw Blame History
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! File system support protocols.
4
5use super::file::{Directory, FileHandle};
6use crate::proto::unsafe_protocol;
7use crate::{Result, StatusExt};
8use core::ptr;
9use uefi_raw::protocol::file_system::SimpleFileSystemProtocol;
10
11#[cfg(doc)]
12use crate::Status;
13
14/// Simple File System [`Protocol`]. Allows access to a FAT-12/16/32 file
15/// system.
16///
17/// This interface is implemented by some storage devices
18/// to allow file access to the contained file systems.
19///
20/// # Accessing `SimpleFileSystem` protocol
21///
22/// Use [`boot::get_image_file_system`] to retrieve the `SimpleFileSystem`
23/// protocol associated with a given image handle.
24///
25/// See the [`boot`] documentation for more details of how to open a protocol.
26///
27/// [`boot::get_image_file_system`]: crate::boot::get_image_file_system
28/// [`boot`]: crate::boot#accessing-protocols
29/// [`Protocol`]: uefi::proto::Protocol
30#[derive(Debug)]
31#[repr(transparent)]
32#[unsafe_protocol(SimpleFileSystemProtocol::GUID)]
33pub struct SimpleFileSystem(SimpleFileSystemProtocol);
34
35impl SimpleFileSystem {
36 /// Open the root directory on a volume.
37 ///
38 /// # Errors
39 ///
40 /// See section `EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume()` in the UEFI Specification
41 /// for more details.
42 ///
43 /// If you can't find the function definition, try searching for
44 /// `EFI_SIMPLE_FILE SYSTEM_PROTOCOL.OpenVolume()` (this has a space in between FILE and
45 /// SYSTEM; it could be a typo in the UEFI spec).
46 ///
47 /// * [`Status::UNSUPPORTED`]
48 /// * [`Status::NO_MEDIA`]
49 /// * [`Status::DEVICE_ERROR`]
50 /// * [`Status::VOLUME_CORRUPTED`]
51 /// * [`Status::ACCESS_DENIED`]
52 /// * [`Status::OUT_OF_RESOURCES`]
53 /// * [`Status::MEDIA_CHANGED`]
54 pub fn open_volume(&mut self) -> Result<Directory> {
55 let mut ptr = ptr::null_mut();
56 // SAFETY: The memory is valid.
57 unsafe { (self.0.open_volume)(&mut self.0, &mut ptr) }
58 // SAFETY: The memory is valid.
59 .to_result_with_val(|| unsafe { Directory::new(FileHandle::new(ptr.cast())) })
60 }
61}