1
1
//! Module for [`FileSystem`].
2
2
3
3
use crate :: fs:: * ;
4
- use crate :: table:: boot:: ScopedProtocol ;
5
4
use crate :: Status ;
6
5
use alloc:: boxed:: Box ;
7
6
use alloc:: string:: String ;
@@ -14,20 +13,29 @@ use core::ops::Deref;
14
13
/// Return type for public [`FileSystem`] operations.
15
14
pub type FileSystemResult < T > = Result < T , Error > ;
16
15
16
+ /// Contents of the `FileSystem` struct, allowing either variant of
17
+ /// `ScopedProtocol` to be used. This is temporary; once `BootServices` and the
18
+ /// associated `ScopedProtocol<'a>` structs are removed this inner type can be
19
+ /// removed as well.
20
+ enum FileSystemInner < ' a > {
21
+ WithLifetime ( uefi:: table:: boot:: ScopedProtocol < ' a , SimpleFileSystemProtocol > ) ,
22
+ WithoutLifetime ( uefi:: boot:: ScopedProtocol < SimpleFileSystemProtocol > ) ,
23
+ }
24
+
17
25
/// High-level file-system abstraction for UEFI volumes with an API that is
18
26
/// close to `std::fs`. It acts as convenient accessor around the
19
27
/// [`SimpleFileSystemProtocol`].
20
28
///
21
29
/// Please refer to the [module documentation] for more information.
22
30
///
23
31
/// [module documentation]: uefi::fs
24
- pub struct FileSystem < ' a > ( ScopedProtocol < ' a , SimpleFileSystemProtocol > ) ;
32
+ pub struct FileSystem < ' a > ( FileSystemInner < ' a > ) ;
25
33
26
34
impl < ' a > FileSystem < ' a > {
27
35
/// Constructor.
28
36
#[ must_use]
29
- pub const fn new ( proto : ScopedProtocol < ' a , SimpleFileSystemProtocol > ) -> Self {
30
- Self ( proto)
37
+ pub fn new ( proto : impl Into < Self > ) -> Self {
38
+ proto. into ( )
31
39
}
32
40
33
41
/// Returns `Ok(true)` if the path points at an existing file.
@@ -387,7 +395,11 @@ impl<'a> FileSystem<'a> {
387
395
388
396
/// Opens a fresh handle to the root directory of the volume.
389
397
fn open_root ( & mut self ) -> FileSystemResult < UefiDirectoryHandle > {
390
- self . 0 . open_volume ( ) . map_err ( |err| {
398
+ match & mut self . 0 {
399
+ FileSystemInner :: WithLifetime ( proto) => proto. open_volume ( ) ,
400
+ FileSystemInner :: WithoutLifetime ( proto) => proto. open_volume ( ) ,
401
+ }
402
+ . map_err ( |err| {
391
403
Error :: Io ( IoError {
392
404
path : {
393
405
let mut path = PathBuf :: new ( ) ;
@@ -434,8 +446,22 @@ impl<'a> FileSystem<'a> {
434
446
435
447
impl < ' a > Debug for FileSystem < ' a > {
436
448
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
437
- f. debug_tuple ( "FileSystem(<>))" )
438
- . field ( & ( self . 0 . deref ( ) as * const _ ) )
439
- . finish ( )
449
+ let ptr: * const _ = match & self . 0 {
450
+ FileSystemInner :: WithLifetime ( proto) => proto. deref ( ) ,
451
+ FileSystemInner :: WithoutLifetime ( proto) => proto. deref ( ) ,
452
+ } ;
453
+ f. debug_tuple ( "FileSystem" ) . field ( & ptr) . finish ( )
454
+ }
455
+ }
456
+
457
+ impl < ' a > From < uefi:: table:: boot:: ScopedProtocol < ' a , SimpleFileSystemProtocol > > for FileSystem < ' a > {
458
+ fn from ( proto : uefi:: table:: boot:: ScopedProtocol < ' a , SimpleFileSystemProtocol > ) -> Self {
459
+ Self ( FileSystemInner :: WithLifetime ( proto) )
460
+ }
461
+ }
462
+
463
+ impl < ' a > From < uefi:: boot:: ScopedProtocol < SimpleFileSystemProtocol > > for FileSystem < ' a > {
464
+ fn from ( proto : uefi:: boot:: ScopedProtocol < SimpleFileSystemProtocol > ) -> Self {
465
+ Self ( FileSystemInner :: WithoutLifetime ( proto) )
440
466
}
441
467
}
0 commit comments