@@ -16,6 +16,18 @@ pub use unsupported_fs::{
1616 unlink,
1717} ;
1818
19+ /// VEXos file descriptor.
20+ ///
21+ /// This stores an opaque pointer to a [FatFs file object structure] managed by VEXos
22+ /// representing an open file on disk.
23+ ///
24+ /// [FatFs file object structure]: https://github.com/Xilinx/embeddedsw/blob/master/lib/sw_services/xilffs/src/include/ff.h?rgh-link-date=2025-09-23T20%3A03%3A43Z#L215
25+ ///
26+ /// # Safety
27+ ///
28+ /// Since this platform uses a pointer to to an internal filesystem structure with a lifetime
29+ /// associated with it (rather than a UNIX-style file descriptor table), care must be taken to
30+ /// ensure that the pointer held by `FileDesc` is valid for as long as it exists.
1931#[ derive( Debug ) ]
2032struct FileDesc ( * mut vex_sdk:: FIL ) ;
2133
@@ -436,9 +448,16 @@ impl File {
436448 } else {
437449 // `vexFileSeek` does not support seeking with negative offset, meaning
438450 // we have to calculate the offset from the end of the file ourselves.
451+
452+ // Seek to the end of the file to get the end position in the open buffer.
453+ map_fresult ( vex_sdk:: vexFileSeek ( self . fd . 0 , 0 , SEEK_END ) ) ?;
454+ let end_position = self . tell ( ) ?;
455+
439456 map_fresult ( vex_sdk:: vexFileSeek (
440457 self . fd . 0 ,
441- try_convert_offset ( self . file_attr ( ) ?. size ( ) as i64 + offset) ?,
458+ // NOTE: Files internally use a 32-bit representation for stream
459+ // position, so `end_position as i64` should never overflow.
460+ try_convert_offset ( end_position as i64 + offset) ?,
442461 SEEK_SET ,
443462 ) ) ?
444463 }
@@ -517,12 +536,11 @@ pub fn lstat(p: &Path) -> io::Result<FileAttr> {
517536 stat ( p)
518537}
519538
520- // NOTE: Cannot use `copy` from `common` here, since we have no support
521- // for `File::set_permissions`.
539+ // Cannot use `copy` from `common` here, since `File::set_permissions` is unsupported on this target.
522540pub fn copy ( from : & Path , to : & Path ) -> io:: Result < u64 > {
523541 use crate :: fs:: File ;
524542
525- // If `from` is a directory, this call should fail.
543+ // NOTE: If `from` is a directory, this call should fail due to vexFileOpen* returning null .
526544 let mut reader = File :: open ( from) ?;
527545 let mut writer = File :: create ( to) ?;
528546
0 commit comments