1 | //! File system support protocols. |
2 | |
3 | use super::file::{Directory, FileHandle, FileImpl}; |
4 | use crate::proto::unsafe_protocol ; |
5 | use crate::{Result, Status}; |
6 | use core::ptr; |
7 | |
8 | /// Allows access to a FAT-12/16/32 file system. |
9 | /// |
10 | /// This interface is implemented by some storage devices |
11 | /// to allow file access to the contained file systems. |
12 | /// |
13 | /// # Accessing `SimpleFileSystem` protocol |
14 | /// |
15 | /// Use [`BootServices::get_image_file_system`] to retrieve the `SimpleFileSystem` |
16 | /// protocol associated with a given image handle. |
17 | /// |
18 | /// See the [`BootServices`] documentation for more details of how to open a protocol. |
19 | /// |
20 | /// [`BootServices::get_image_file_system`]: crate::table::boot::BootServices::get_image_file_system |
21 | /// [`BootServices`]: crate::table::boot::BootServices#accessing-protocols |
22 | #[repr (C)] |
23 | #[unsafe_protocol ("964e5b22-6459-11d2-8e39-00a0c969723b" )] |
24 | pub struct SimpleFileSystem { |
25 | revision: u64, |
26 | open_volume: |
27 | extern "efiapi" fn(this: &mut SimpleFileSystem, root: &mut *mut FileImpl) -> Status, |
28 | } |
29 | |
30 | impl SimpleFileSystem { |
31 | /// Open the root directory on a volume. |
32 | /// |
33 | /// # Errors |
34 | /// |
35 | /// See section `EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume()` in the UEFI Specification |
36 | /// for more details. |
37 | /// |
38 | /// If you can't find the function definition, try searching for |
39 | /// `EFI_SIMPLE_FILE SYSTEM_PROTOCOL.OpenVolume()` (this has a space in between FILE and |
40 | /// SYSTEM; it could be a typo in the UEFI spec). |
41 | /// |
42 | /// * [`uefi::Status::UNSUPPORTED`] |
43 | /// * [`uefi::Status::NO_MEDIA`] |
44 | /// * [`uefi::Status::DEVICE_ERROR`] |
45 | /// * [`uefi::Status::VOLUME_CORRUPTED`] |
46 | /// * [`uefi::Status::ACCESS_DENIED`] |
47 | /// * [`uefi::Status::OUT_OF_RESOURCES`] |
48 | /// * [`uefi::Status::MEDIA_CHANGED`] |
49 | pub fn open_volume(&mut self) -> Result<Directory> { |
50 | let mut ptr = ptr::null_mut(); |
51 | (self.open_volume)(self, &mut ptr) |
52 | .into_with_val(|| unsafe { Directory::new(FileHandle::new(ptr)) }) |
53 | } |
54 | } |
55 | |