@@ -6,9 +6,9 @@ use crate::path::{Path, PathBuf};
6
6
use crate :: sys:: time:: SystemTime ;
7
7
use crate :: sys:: unsupported;
8
8
9
- struct Fd ( * mut vex_sdk:: FIL ) ;
9
+ struct FileDesc ( * mut vex_sdk:: FIL ) ;
10
10
11
- pub struct File ( Fd ) ;
11
+ pub struct File ( FileDesc ) ;
12
12
13
13
//TODO: We may be able to get some of this info
14
14
#[ derive( Clone ) ]
@@ -173,7 +173,7 @@ impl File {
173
173
if file. is_null ( ) {
174
174
Err ( io:: Error :: new ( io:: ErrorKind :: NotFound , "Could not open file" ) )
175
175
} else {
176
- Ok ( Self ( Fd ( file) ) )
176
+ Ok ( Self ( FileDesc ( file) ) )
177
177
}
178
178
}
179
179
@@ -182,73 +182,75 @@ impl File {
182
182
}
183
183
184
184
pub fn fsync ( & self ) -> io:: Result < ( ) > {
185
- todo ! ( )
185
+ self . flush ( )
186
186
}
187
187
188
188
pub fn datasync ( & self ) -> io:: Result < ( ) > {
189
- todo ! ( )
189
+ self . flush ( )
190
190
}
191
191
192
192
pub fn truncate ( & self , _size : u64 ) -> io:: Result < ( ) > {
193
- todo ! ( )
193
+ unsupported ( )
194
194
}
195
195
196
196
pub fn read ( & self , buf : & mut [ u8 ] ) -> io:: Result < usize > {
197
197
let len = buf. len ( ) as _ ;
198
198
let buf_ptr = buf. as_mut_ptr ( ) ;
199
199
let read = unsafe { vex_sdk:: vexFileRead ( buf_ptr. cast ( ) , 1 , len, self . 0 . 0 ) } ;
200
200
if read < 0 {
201
- Err ( io:: Error :: new (
202
- io:: ErrorKind :: Other ,
203
- "Could not read from file" ,
204
- ) )
201
+ Err ( io:: Error :: new ( io:: ErrorKind :: Other , "Could not read from file" ) )
205
202
} else {
206
203
Ok ( read as usize )
207
204
}
208
205
}
209
206
210
- pub fn read_vectored ( & self , _bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
211
- todo ! ( )
207
+ pub fn read_vectored ( & self , bufs : & mut [ IoSliceMut < ' _ > ] ) -> io:: Result < usize > {
208
+ crate :: io :: default_read_vectored ( |buf| self . read ( buf ) , bufs )
212
209
}
213
210
211
+ #[ inline]
214
212
pub fn is_read_vectored ( & self ) -> bool {
215
- todo ! ( )
213
+ false
216
214
}
217
215
218
- pub fn read_buf ( & self , _cursor : BorrowedCursor < ' _ > ) -> io:: Result < ( ) > {
219
- todo ! ( )
216
+ pub fn read_buf ( & self , cursor : BorrowedCursor < ' _ > ) -> io:: Result < ( ) > {
217
+ crate :: io :: default_read_buf ( |b| self . read ( b ) , cursor )
220
218
}
221
219
222
220
pub fn write ( & self , _buf : & [ u8 ] ) -> io:: Result < usize > {
223
221
todo ! ( )
224
222
}
225
223
226
- pub fn write_vectored ( & self , _bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
227
- todo ! ( )
224
+ pub fn write_vectored ( & self , bufs : & [ IoSlice < ' _ > ] ) -> io:: Result < usize > {
225
+ crate :: io :: default_write_vectored ( |buf| self . write ( buf ) , bufs )
228
226
}
229
227
228
+ #[ inline]
230
229
pub fn is_write_vectored ( & self ) -> bool {
231
- todo ! ( )
230
+ false
232
231
}
233
232
234
233
pub fn flush ( & self ) -> io:: Result < ( ) > {
235
- todo ! ( )
234
+ unsafe {
235
+ vex_sdk:: vexFileSync ( self . 0 . 0 ) ;
236
+ }
237
+ Ok ( ( ) )
236
238
}
237
239
238
240
pub fn seek ( & self , _pos : SeekFrom ) -> io:: Result < u64 > {
239
- todo ! ( )
241
+ todo ! ( ) ;
240
242
}
241
243
242
244
pub fn duplicate ( & self ) -> io:: Result < File > {
243
- todo ! ( )
245
+ unsupported ! ( )
244
246
}
245
247
246
248
pub fn set_permissions ( & self , _perm : FilePermissions ) -> io:: Result < ( ) > {
247
- todo ! ( )
249
+ unsupported ( )
248
250
}
249
251
250
252
pub fn set_times ( & self , _times : FileTimes ) -> io:: Result < ( ) > {
251
- todo ! ( )
253
+ unsupported ( )
252
254
}
253
255
}
254
256
0 commit comments