@@ -5,7 +5,7 @@ use crate::fmt;
5
5
use crate :: hash:: Hash ;
6
6
use crate :: io:: { self , IoSlice , IoSliceMut , ReadBuf , SeekFrom } ;
7
7
use crate :: path:: { Path , PathBuf } ;
8
- use crate :: sys:: time:: { SystemTime , UNIX_EPOCH } ;
8
+ use crate :: sys:: time:: SystemTime ;
9
9
use crate :: sys:: unsupported;
10
10
use r_efi:: protocols:: file;
11
11
@@ -20,7 +20,8 @@ pub struct FileAttr {
20
20
perm : FilePermissions ,
21
21
file_type : FileType ,
22
22
created_time : SystemTime ,
23
- file_times : FileTimes ,
23
+ last_accessed_time : SystemTime ,
24
+ modification_time : SystemTime ,
24
25
}
25
26
26
27
pub struct ReadDir {
@@ -55,8 +56,8 @@ pub struct FileType {
55
56
56
57
#[ derive( Copy , Clone , Debug ) ]
57
58
pub struct FileTimes {
58
- last_accessed_time : SystemTime ,
59
- modification_time : SystemTime ,
59
+ last_accessed_time : Option < SystemTime > ,
60
+ modification_time : Option < SystemTime > ,
60
61
}
61
62
62
63
#[ derive( Debug ) ]
@@ -83,12 +84,12 @@ impl FileAttr {
83
84
84
85
#[ inline]
85
86
pub fn modified ( & self ) -> io:: Result < SystemTime > {
86
- Ok ( self . file_times . modification_time )
87
+ Ok ( self . modification_time )
87
88
}
88
89
89
90
#[ inline]
90
91
pub fn accessed ( & self ) -> io:: Result < SystemTime > {
91
- Ok ( self . file_times . last_accessed_time )
92
+ Ok ( self . last_accessed_time )
92
93
}
93
94
94
95
#[ inline]
@@ -103,11 +104,9 @@ impl From<&file::Info> for FileAttr {
103
104
size : info. file_size ,
104
105
perm : FilePermissions { attr : info. attribute } ,
105
106
file_type : FileType { attr : info. attribute } ,
106
- file_times : FileTimes {
107
- last_accessed_time : SystemTime :: from ( info. last_access_time ) ,
108
- modification_time : SystemTime :: from ( info. modification_time ) ,
109
- } ,
110
107
created_time : SystemTime :: from ( info. create_time ) ,
108
+ last_accessed_time : SystemTime :: from ( info. last_access_time ) ,
109
+ modification_time : SystemTime :: from ( info. modification_time ) ,
111
110
}
112
111
}
113
112
}
@@ -177,19 +176,19 @@ impl Iterator for ReadDir {
177
176
impl FileTimes {
178
177
#[ inline]
179
178
pub fn set_accessed ( & mut self , t : SystemTime ) {
180
- self . last_accessed_time = t ;
179
+ self . last_accessed_time = Some ( t ) ;
181
180
}
182
181
183
182
#[ inline]
184
183
pub fn set_modified ( & mut self , t : SystemTime ) {
185
- self . modification_time = t ;
184
+ self . modification_time = Some ( t ) ;
186
185
}
187
186
}
188
187
189
188
impl Default for FileTimes {
190
189
#[ inline]
191
190
fn default ( ) -> Self {
192
- Self { last_accessed_time : UNIX_EPOCH , modification_time : UNIX_EPOCH }
191
+ Self { last_accessed_time : None , modification_time : None }
193
192
}
194
193
}
195
194
@@ -382,8 +381,9 @@ impl File {
382
381
self . ptr . set_file_attr ( perm. attr )
383
382
}
384
383
385
- pub fn set_times ( & self , _times : FileTimes ) -> io:: Result < ( ) > {
386
- unsupported ( )
384
+ #[ inline]
385
+ pub fn set_times ( & self , times : FileTimes ) -> io:: Result < ( ) > {
386
+ self . ptr . set_file_times ( times)
387
387
}
388
388
}
389
389
@@ -548,6 +548,7 @@ fn cascade_delete(file: uefi_fs::FileProtocol, path: &Path) -> io::Result<()> {
548
548
}
549
549
550
550
mod uefi_fs {
551
+ use super :: FileTimes ;
551
552
use super :: { DirEntry , FileAttr } ;
552
553
use crate :: default:: Default ;
553
554
use crate :: ffi:: OsStr ;
@@ -891,6 +892,34 @@ mod uefi_fs {
891
892
}
892
893
}
893
894
895
+ pub fn set_file_times ( & self , file_times : FileTimes ) -> io:: Result < ( ) > {
896
+ let mut old_info = self . get_file_info ( ) ?;
897
+
898
+ if let Some ( t) = file_times. last_accessed_time {
899
+ old_info. last_access_time = super :: super :: time:: uefi_time_from_duration (
900
+ t. get_duration ( ) ,
901
+ old_info. last_access_time . daylight ,
902
+ old_info. last_access_time . timezone ,
903
+ ) ;
904
+ }
905
+ if let Some ( t) = file_times. modification_time {
906
+ old_info. modification_time = super :: super :: time:: uefi_time_from_duration (
907
+ t. get_duration ( ) ,
908
+ old_info. modification_time . daylight ,
909
+ old_info. modification_time . timezone ,
910
+ ) ;
911
+ }
912
+
913
+ unsafe {
914
+ Self :: set_info_raw (
915
+ self . inner . as_ptr ( ) ,
916
+ file:: INFO_ID ,
917
+ old_info. layout ( ) . size ( ) ,
918
+ old_info. as_mut ( ) as * mut _ as * mut crate :: ffi:: c_void ,
919
+ )
920
+ }
921
+ }
922
+
894
923
// Delete a file.
895
924
pub fn delete ( self ) -> io:: Result < ( ) > {
896
925
// Deleting the file makes the pointer invalid. Thus calling drop on it later will
@@ -899,6 +928,7 @@ mod uefi_fs {
899
928
unsafe { Self :: delete_raw ( file. inner . as_ptr ( ) ) }
900
929
}
901
930
931
+ #[ inline]
902
932
unsafe fn open_raw (
903
933
rootfs : * mut file:: Protocol ,
904
934
file_opened : * mut * mut file:: Protocol ,
@@ -910,21 +940,25 @@ mod uefi_fs {
910
940
if r. is_error ( ) { Err ( status_to_io_error ( r) ) } else { Ok ( ( ) ) }
911
941
}
912
942
943
+ #[ inline]
913
944
unsafe fn set_position_raw ( protocol : * mut file:: Protocol , pos : u64 ) -> io:: Result < ( ) > {
914
945
let r = unsafe { ( ( * protocol) . set_position ) ( protocol, pos) } ;
915
946
if r. is_error ( ) { Err ( status_to_io_error ( r) ) } else { Ok ( ( ) ) }
916
947
}
917
948
949
+ #[ inline]
918
950
unsafe fn get_position_raw ( protocol : * mut file:: Protocol , pos : * mut u64 ) -> io:: Result < ( ) > {
919
951
let r = unsafe { ( ( * protocol) . get_position ) ( protocol, pos) } ;
920
952
if r. is_error ( ) { Err ( status_to_io_error ( r) ) } else { Ok ( ( ) ) }
921
953
}
922
954
955
+ #[ inline]
923
956
unsafe fn flush_raw ( protocol : * mut file:: Protocol ) -> io:: Result < ( ) > {
924
957
let r = unsafe { ( ( * protocol) . flush ) ( protocol) } ;
925
958
if r. is_error ( ) { Err ( status_to_io_error ( r) ) } else { Ok ( ( ) ) }
926
959
}
927
960
961
+ #[ inline]
928
962
unsafe fn write_raw (
929
963
protocol : * mut file:: Protocol ,
930
964
buf_size : * mut usize ,
@@ -939,6 +973,7 @@ mod uefi_fs {
939
973
if r. is_error ( ) { Err ( status_to_io_error ( r) ) } else { Ok ( ( ) ) }
940
974
}
941
975
976
+ #[ inline]
942
977
unsafe fn read_raw (
943
978
protocol : * mut file:: Protocol ,
944
979
buf_size : * mut usize ,
@@ -948,6 +983,7 @@ mod uefi_fs {
948
983
if r. is_error ( ) { Err ( status_to_io_error ( r) ) } else { Ok ( ( ) ) }
949
984
}
950
985
986
+ #[ inline]
951
987
unsafe fn get_info_raw (
952
988
protocol : * mut file:: Protocol ,
953
989
mut info_guid : r_efi:: efi:: Guid ,
@@ -958,6 +994,7 @@ mod uefi_fs {
958
994
if r. is_error ( ) { Err ( status_to_io_error ( r) ) } else { Ok ( ( ) ) }
959
995
}
960
996
997
+ #[ inline]
961
998
unsafe fn set_info_raw (
962
999
protocol : * mut file:: Protocol ,
963
1000
mut info_guid : r_efi:: efi:: Guid ,
@@ -968,13 +1005,15 @@ mod uefi_fs {
968
1005
if r. is_error ( ) { Err ( status_to_io_error ( r) ) } else { Ok ( ( ) ) }
969
1006
}
970
1007
1008
+ #[ inline]
971
1009
unsafe fn delete_raw ( protocol : * mut file:: Protocol ) -> io:: Result < ( ) > {
972
1010
let r = unsafe { ( ( * protocol) . delete ) ( protocol) } ;
973
1011
if r. is_error ( ) { Err ( status_to_io_error ( r) ) } else { Ok ( ( ) ) }
974
1012
}
975
1013
}
976
1014
977
1015
impl Drop for FileProtocol {
1016
+ #[ inline]
978
1017
fn drop ( & mut self ) {
979
1018
let protocol = self . inner . as_ptr ( ) ;
980
1019
// Always returns EFI_SUCCESS
0 commit comments