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 ;
7
9
use uefi:: table:: boot:: { OpenProtocolAttributes , OpenProtocolParams } ;
10
+ use uefi:: CString16 ;
8
11
9
12
/// Test `FileSystemInfo` and `FileSystemVolumeLabel`.
10
13
fn test_file_system_info ( directory : & mut Directory ) {
@@ -24,8 +27,8 @@ fn test_file_system_info(directory: &mut Directory) {
24
27
assert_eq ! ( fs_info. volume_label( ) , fs_vol. volume_label( ) ) ;
25
28
}
26
29
27
- pub fn test ( image : Handle , bt : & BootServices ) {
28
- info ! ( "Testing Media Access protocols " ) ;
30
+ pub fn test_simple_file_system_protocol ( image : Handle , bt : & BootServices ) {
31
+ info ! ( "Testing Simple File System Protocol " ) ;
29
32
30
33
if let Ok ( handle) = bt. get_handle_for_protocol :: < SimpleFileSystem > ( ) {
31
34
let mut sfs = bt
@@ -39,10 +42,10 @@ pub fn test(image: Handle, bt: &BootServices) {
39
42
)
40
43
. expect ( "failed to open SimpleFileSystem protocol" ) ;
41
44
42
- let mut directory = sfs. open_volume ( ) . unwrap ( ) ;
45
+ let mut root_directory = sfs. open_volume ( ) . unwrap ( ) ;
43
46
let mut buffer = vec ! [ 0 ; 128 ] ;
44
47
loop {
45
- let file_info = match directory . read_entry ( & mut buffer) {
48
+ let file_info = match root_directory . read_entry ( & mut buffer) {
46
49
Ok ( info) => {
47
50
if let Some ( info) = info {
48
51
info
@@ -60,12 +63,35 @@ pub fn test(image: Handle, bt: &BootServices) {
60
63
} ;
61
64
info ! ( "Root directory entry: {:?}" , file_info) ;
62
65
}
63
- directory . reset_entry_readout ( ) . unwrap ( ) ;
66
+ root_directory . reset_entry_readout ( ) . unwrap ( ) ;
64
67
65
- test_file_system_info ( & mut directory) ;
68
+ test_file_system_info ( & mut root_directory) ;
69
+
70
+ assert_eq ! ( Ok ( true ) , root_directory. is_directory( ) ) ;
71
+ assert_eq ! ( Ok ( false ) , root_directory. is_regular_file( ) ) ;
72
+
73
+ info ! ( "creating file in root volume" ) ;
74
+ let created_file = root_directory
75
+ . open (
76
+ CString16 :: try_from ( "foo" ) . unwrap ( ) . as_ref ( ) ,
77
+ FileMode :: CreateReadWrite ,
78
+ FileAttribute :: empty ( ) ,
79
+ )
80
+ . unwrap ( ) ;
81
+ assert_eq ! ( Ok ( true ) , created_file. is_regular_file( ) ) ;
82
+ let created_file = match created_file. into_type ( ) . unwrap ( ) {
83
+ FileType :: Regular ( file) => file,
84
+ _ => panic ! ( "unsupported value" ) ,
85
+ } ;
86
+ assert_eq ! ( Ok ( true ) , created_file. is_regular_file( ) ) ;
87
+ assert_eq ! ( Ok ( false ) , created_file. is_directory( ) ) ;
66
88
} else {
67
89
warn ! ( "`SimpleFileSystem` protocol is not available" ) ;
68
90
}
91
+ }
92
+
93
+ pub fn test_partition_info_protocol ( image : Handle , bt : & BootServices ) {
94
+ info ! ( "Testing Partition Info protocols" ) ;
69
95
70
96
let handles = bt
71
97
. find_handles :: < PartitionInfo > ( )
0 commit comments