11use crate :: ffi:: { CString , OsString } ;
22use crate :: fmt;
3+ use crate :: fs:: TryLockError ;
34use crate :: hash:: Hash ;
45use crate :: io:: { self , BorrowedCursor , IoSlice , IoSliceMut , SeekFrom } ;
56use crate :: path:: { Path , PathBuf } ;
67use crate :: sys:: time:: SystemTime ;
7- use crate :: sys:: unsupported;
8+ use crate :: sys:: { unsupported, unsupported_err } ;
89
910#[ derive( Debug ) ]
1011struct FileDesc ( * mut vex_sdk:: FIL ) ;
@@ -19,12 +20,8 @@ pub struct FileAttr {
1920 is_dir : bool ,
2021}
2122
22- #[ derive( Debug ) ]
23- pub struct ReadDir {
24- entries : Vec < DirEntry > ,
25- }
23+ pub struct ReadDir ( !) ;
2624
27- #[ derive( Debug ) ]
2825pub struct DirEntry {
2926 path : PathBuf ,
3027}
@@ -39,18 +36,18 @@ pub struct OpenOptions {
3936}
4037
4138#[ derive( Copy , Clone , Debug , Default ) ]
42- pub struct FileTimes ( ( ) ) ;
39+ pub struct FileTimes { }
4340
44- #[ derive( Clone , Debug , PartialEq , Eq ) ]
45- pub struct FilePermissions ;
41+ #[ derive( Clone , PartialEq , Eq , Debug ) ]
42+ pub struct FilePermissions { }
4643
47- #[ derive( Clone , Debug , Copy , PartialEq , Eq , Hash ) ]
44+ #[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug ) ]
4845pub struct FileType {
4946 is_dir : bool ,
5047}
5148
5249#[ derive( Debug ) ]
53- pub struct DirBuilder ( ( ) ) ;
50+ pub struct DirBuilder { }
5451
5552impl FileAttr {
5653 /// Creates a FileAttr by getting data from an opened file.
@@ -79,9 +76,8 @@ impl FileAttr {
7976 let mut opts = OpenOptions :: new ( ) ;
8077 opts. read ( true ) ;
8178 let file = File :: open ( path, & opts) ?;
82- let fd = file. fd . 0 ;
8379
84- Self :: from_fd ( fd )
80+ Self :: from_fd ( file . fd . 0 )
8581 }
8682 }
8783
@@ -90,7 +86,7 @@ impl FileAttr {
9086 }
9187
9288 pub fn perm ( & self ) -> FilePermissions {
93- FilePermissions
89+ FilePermissions { }
9490 }
9591
9692 pub fn file_type ( & self ) -> FileType {
@@ -135,15 +131,22 @@ impl FileType {
135131 }
136132
137133 pub fn is_symlink ( & self ) -> bool {
134+ // No symlinks in vexos; entries are either files or directories.
138135 false
139136 }
140137}
141138
139+ impl fmt:: Debug for ReadDir {
140+ fn fmt ( & self , _f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
141+ self . 0
142+ }
143+ }
144+
142145impl Iterator for ReadDir {
143146 type Item = io:: Result < DirEntry > ;
144147
145148 fn next ( & mut self ) -> Option < io:: Result < DirEntry > > {
146- self . entries . pop ( ) . map ( Ok )
149+ self . 0
147150 }
148151}
149152
@@ -191,6 +194,7 @@ impl OpenOptions {
191194}
192195
193196impl File {
197+ // TODO
194198 pub fn open ( path : & Path , opts : & OpenOptions ) -> io:: Result < File > {
195199 // Mount sdcard volume as FAT filesystem
196200 map_fresult ( unsafe { vex_sdk:: vexFileMountSD ( ) } ) ?;
@@ -265,12 +269,12 @@ impl File {
265269 unsupported ( )
266270 }
267271
268- pub fn try_lock ( & self ) -> io :: Result < bool > {
269- unsupported ( )
272+ pub fn try_lock ( & self ) -> Result < ( ) , TryLockError > {
273+ Err ( TryLockError :: Error ( unsupported_err ( ) ) )
270274 }
271275
272- pub fn try_lock_shared ( & self ) -> io :: Result < bool > {
273- unsupported ( )
276+ pub fn try_lock_shared ( & self ) -> Result < ( ) , TryLockError > {
277+ Err ( TryLockError :: Error ( unsupported_err ( ) ) )
274278 }
275279
276280 pub fn unlock ( & self ) -> io:: Result < ( ) > {
@@ -333,13 +337,17 @@ impl File {
333337 Ok ( ( ) )
334338 }
335339
336- fn tell ( & self ) -> io:: Result < u64 > {
340+ pub fn tell ( & self ) -> io:: Result < u64 > {
337341 let position = unsafe { vex_sdk:: vexFileTell ( self . fd . 0 ) } ;
338342 position. try_into ( ) . map_err ( |_| {
339343 io:: Error :: new ( io:: ErrorKind :: InvalidData , "Failed to get current location in file" )
340344 } )
341345 }
342346
347+ pub fn size ( & self ) -> Option < io:: Result < u64 > > {
348+ None
349+ }
350+
343351 pub fn seek ( & self , pos : SeekFrom ) -> io:: Result < u64 > {
344352 const SEEK_SET : i32 = 0 ;
345353 const SEEK_CUR : i32 = 1 ;
@@ -412,7 +420,7 @@ impl File {
412420
413421impl DirBuilder {
414422 pub fn new ( ) -> DirBuilder {
415- DirBuilder ( ( ) )
423+ DirBuilder { }
416424 }
417425
418426 pub fn mkdir ( & self , _p : & Path ) -> io:: Result < ( ) > {
0 commit comments