11use super :: fd:: FileDesc ;
22use super :: hermit_abi:: {
33 self , dirent64, stat as stat_struct, DT_DIR , DT_LNK , DT_REG , DT_UNKNOWN , O_APPEND , O_CREAT ,
4- O_EXCL , O_RDONLY , O_RDWR , O_TRUNC , O_WRONLY , S_IFDIR , S_IFLNK , S_IFMT , S_IFREG ,
4+ O_DIRECTORY , O_EXCL , O_RDONLY , O_RDWR , O_TRUNC , O_WRONLY , S_IFDIR , S_IFLNK , S_IFMT , S_IFREG ,
55} ;
66use crate :: ffi:: { CStr , OsStr , OsString } ;
77use crate :: fmt;
@@ -62,7 +62,7 @@ pub struct DirEntry {
6262 /// 64-bit inode number
6363 ino : u64 ,
6464 /// File type
65- type_ : u32 ,
65+ type_ : u8 ,
6666 /// name of the entry
6767 name : OsString ,
6868}
@@ -90,7 +90,7 @@ pub struct FilePermissions {
9090
9191#[ derive( Copy , Clone , Eq , Debug ) ]
9292pub struct FileType {
93- mode : u32 ,
93+ mode : u8 ,
9494}
9595
9696impl PartialEq for FileType {
@@ -113,30 +113,31 @@ pub struct DirBuilder {
113113impl FileAttr {
114114 pub fn modified ( & self ) -> io:: Result < SystemTime > {
115115 Ok ( SystemTime :: new (
116- self . stat_val . st_mtime . try_into ( ) . unwrap ( ) ,
117- self . stat_val . st_mtime_nsec . try_into ( ) . unwrap ( ) ,
116+ self . stat_val . st_mtim . tv_sec ,
117+ self . stat_val . st_mtim . tv_nsec ,
118118 ) )
119119 }
120120
121121 pub fn accessed ( & self ) -> io:: Result < SystemTime > {
122122 Ok ( SystemTime :: new (
123- self . stat_val . st_atime . try_into ( ) . unwrap ( ) ,
124- self . stat_val . st_atime_nsec . try_into ( ) . unwrap ( ) ,
123+ self . stat_val . st_atim . tv_sec ,
124+ self . stat_val . st_atim . tv_nsec ,
125125 ) )
126126 }
127127
128128 pub fn created ( & self ) -> io:: Result < SystemTime > {
129129 Ok ( SystemTime :: new (
130- self . stat_val . st_ctime . try_into ( ) . unwrap ( ) ,
131- self . stat_val . st_ctime_nsec . try_into ( ) . unwrap ( ) ,
130+ self . stat_val . st_ctim . tv_sec ,
131+ self . stat_val . st_ctim . tv_nsec ,
132132 ) )
133133 }
134134
135135 pub fn size ( & self ) -> u64 {
136136 self . stat_val . st_size as u64
137137 }
138+
138139 pub fn perm ( & self ) -> FilePermissions {
139- FilePermissions { mode : ( self . stat_val . st_mode ) }
140+ FilePermissions { mode : self . stat_val . st_mode }
140141 }
141142
142143 pub fn file_type ( & self ) -> FileType {
@@ -220,7 +221,7 @@ impl Iterator for ReadDir {
220221 let entry = DirEntry {
221222 root : self . inner . root . clone ( ) ,
222223 ino : dir. d_ino ,
223- type_ : dir. d_type as u32 ,
224+ type_ : dir. d_type ,
224225 name : OsString :: from_vec ( name_bytes. to_vec ( ) ) ,
225226 } ;
226227
@@ -251,7 +252,7 @@ impl DirEntry {
251252 }
252253
253254 pub fn file_type ( & self ) -> io:: Result < FileType > {
254- Ok ( FileType { mode : self . type_ as u32 } )
255+ Ok ( FileType { mode : self . type_ } )
255256 }
256257
257258 #[ allow( dead_code) ]
@@ -385,12 +386,12 @@ impl File {
385386 }
386387
387388 pub fn read_vectored ( & self , bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
388- crate :: io :: default_read_vectored ( |buf| self . read ( buf ) , bufs)
389+ self . 0 . read_vectored ( bufs)
389390 }
390391
391392 #[ inline]
392393 pub fn is_read_vectored ( & self ) -> bool {
393- false
394+ self . 0 . is_read_vectored ( )
394395 }
395396
396397 pub fn read_buf ( & self , cursor : BorrowedCursor < ' _ > ) -> io:: Result < ( ) > {
@@ -402,12 +403,12 @@ impl File {
402403 }
403404
404405 pub fn write_vectored ( & self , bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
405- crate :: io :: default_write_vectored ( |buf| self . write ( buf ) , bufs)
406+ self . 0 . write_vectored ( bufs)
406407 }
407408
408409 #[ inline]
409410 pub fn is_write_vectored ( & self ) -> bool {
410- false
411+ self . 0 . is_write_vectored ( )
411412 }
412413
413414 #[ inline]
@@ -439,13 +440,13 @@ impl DirBuilder {
439440
440441 pub fn mkdir ( & self , path : & Path ) -> io:: Result < ( ) > {
441442 run_path_with_cstr ( path, & |path| {
442- cvt ( unsafe { hermit_abi:: mkdir ( path. as_ptr ( ) , self . mode ) } ) . map ( |_| ( ) )
443+ cvt ( unsafe { hermit_abi:: mkdir ( path. as_ptr ( ) , self . mode . into ( ) ) } ) . map ( |_| ( ) )
443444 } )
444445 }
445446
446447 #[ allow( dead_code) ]
447448 pub fn set_mode ( & mut self , mode : u32 ) {
448- self . mode = mode as u32 ;
449+ self . mode = mode;
449450 }
450451}
451452
@@ -502,7 +503,7 @@ impl FromRawFd for File {
502503
503504pub fn readdir ( path : & Path ) -> io:: Result < ReadDir > {
504505 let fd_raw =
505- run_path_with_cstr ( path, & |path| cvt ( unsafe { hermit_abi:: opendir ( path. as_ptr ( ) ) } ) ) ?;
506+ run_path_with_cstr ( path, & |path| cvt ( unsafe { hermit_abi:: open ( path. as_ptr ( ) , O_RDONLY | O_DIRECTORY , 0 ) } ) ) ?;
506507 let fd = unsafe { FileDesc :: from_raw_fd ( fd_raw as i32 ) } ;
507508 let root = path. to_path_buf ( ) ;
508509
0 commit comments