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