1
1
mod known_disk;
2
2
3
3
use uefi:: prelude:: * ;
4
- use uefi:: proto:: media:: file:: { Directory , File , FileSystemInfo , FileSystemVolumeLabel } ;
4
+ use uefi:: proto:: media:: file:: {
5
+ Directory , File , FileAttribute , FileMode , FileSystemInfo , FileSystemVolumeLabel , FileType ,
6
+ } ;
5
7
use uefi:: proto:: media:: fs:: SimpleFileSystem ;
6
8
use uefi:: proto:: media:: partition:: PartitionInfo ;
9
+ use uefi:: table:: boot:: { OpenProtocolAttributes , OpenProtocolParams } ;
10
+ use uefi:: CString16 ;
7
11
8
12
/// Test `FileSystemInfo` and `FileSystemVolumeLabel`.
9
13
fn test_file_system_info ( directory : & mut Directory ) {
@@ -23,18 +27,18 @@ fn test_file_system_info(directory: &mut Directory) {
23
27
assert_eq ! ( fs_info. volume_label( ) , fs_vol. volume_label( ) ) ;
24
28
}
25
29
26
- pub fn test ( bt : & BootServices ) {
27
- info ! ( "Testing Media Access protocols " ) ;
30
+ pub fn test_simple_file_system_protocol ( image : Handle , bt : & BootServices ) {
31
+ info ! ( "Testing Simple File System Protocol " ) ;
28
32
29
33
if let Ok ( handle) = bt. get_handle_for_protocol :: < SimpleFileSystem > ( ) {
30
34
let mut sfs = bt
31
35
. open_protocol_exclusive :: < SimpleFileSystem > ( handle)
32
36
. expect ( "failed to open SimpleFileSystem protocol" ) ;
33
37
34
- let mut directory = sfs. open_volume ( ) . unwrap ( ) ;
38
+ let mut root_directory = sfs. open_volume ( ) . unwrap ( ) ;
35
39
let mut buffer = vec ! [ 0 ; 128 ] ;
36
40
loop {
37
- let file_info = match directory . read_entry ( & mut buffer) {
41
+ let file_info = match root_directory . read_entry ( & mut buffer) {
38
42
Ok ( info) => {
39
43
if let Some ( info) = info {
40
44
info
@@ -52,12 +56,35 @@ pub fn test(bt: &BootServices) {
52
56
} ;
53
57
info ! ( "Root directory entry: {:?}" , file_info) ;
54
58
}
55
- directory . reset_entry_readout ( ) . unwrap ( ) ;
59
+ root_directory . reset_entry_readout ( ) . unwrap ( ) ;
56
60
57
- test_file_system_info ( & mut directory) ;
61
+ test_file_system_info ( & mut root_directory) ;
62
+
63
+ assert_eq ! ( Ok ( true ) , root_directory. is_directory( ) ) ;
64
+ assert_eq ! ( Ok ( false ) , root_directory. is_regular_file( ) ) ;
65
+
66
+ info ! ( "creating file in root volume" ) ;
67
+ let created_file = root_directory
68
+ . open (
69
+ CString16 :: try_from ( "foo" ) . unwrap ( ) . as_ref ( ) ,
70
+ FileMode :: CreateReadWrite ,
71
+ FileAttribute :: empty ( ) ,
72
+ )
73
+ . unwrap ( ) ;
74
+ assert_eq ! ( Ok ( true ) , created_file. is_regular_file( ) ) ;
75
+ let created_file = match created_file. into_type ( ) . unwrap ( ) {
76
+ FileType :: Regular ( file) => file,
77
+ _ => panic ! ( "unsupported value" ) ,
78
+ } ;
79
+ assert_eq ! ( Ok ( true ) , created_file. is_regular_file( ) ) ;
80
+ assert_eq ! ( Ok ( false ) , created_file. is_directory( ) ) ;
58
81
} else {
59
82
warn ! ( "`SimpleFileSystem` protocol is not available" ) ;
60
83
}
84
+ }
85
+
86
+ pub fn test_partition_info_protocol ( image : Handle , bt : & BootServices ) {
87
+ info ! ( "Testing Partition Info protocols" ) ;
61
88
62
89
let handles = bt
63
90
. find_handles :: < PartitionInfo > ( )
0 commit comments