Sepehr Ganji commented: 
https://gitlab.rtems.org/groups/rtems/-/work_items/25#note_129098


My progress continues with refining the tests and hunting down the bugs this 
week:

1. **Fixed Parent Directory Timestamp Updates**  
   FatFS was failing POSIX compliance tests because it didn’t update parent 
directory timestamps when files were created or deleted. POSIX requires that 
directory `mtime` and `ctime` reflect these changes. I extended the 
`rtems_fatfs_node_t` structure with POSIX-compliant timestamp fields and added 
a `rtems_fatfs_update_parent_dir_time()` function to update parent directory 
times during file creation or deletion. I also modified `fstat` to prioritize 
POSIX timestamps when available, ensuring compliance with minimal memory 
overhead and without modifying the core FatFS library.

2. **Implemented O_TRUNC Handling**  
   The `rtems_fatfs_openfile` function ignored the `O_TRUNC` flag, violating 
POSIX requirements that opening with `O_TRUNC` should truncate the file and 
update timestamps. I fixed this by detecting the flag and calling 
`f_truncate()`. For empty files where `f_truncate()` has no effect, I wrote a 
dummy byte and immediately truncated back to zero to force timestamp updates. 
This ensured correct POSIX behavior while leveraging FatFS’s natural mechanisms.

3. **Ensured Write Operations Update File Timestamps**  
   FatFS was not updating file timestamps during `write()` calls, leaving 
`mtime` and `ctime` unchanged. I updated the `rtems_fatfs_file_write` function 
to set `posix_mtime` and `posix_ctime` to the current system time whenever data 
is written, marking them as valid. The `rtems_fatfs_node_to_stat()` function 
now reports these updated timestamps, making write operations POSIX-compliant.

4. **Implemented utime() with Persistent POSIX Timestamp Cache**  
   RTEMS FatFS didn’t support `utime()`, causing test failures. Even after 
adding a basic implementation, the timestamps didn’t persist because `stat()` 
recreated nodes without keeping the updated values. I solved this by adding a 
filesystem-level POSIX timestamp cache (circular buffer) that stores updates 
from `utimens()` beyond node lifecycles. Now, `stat()` retrieves the correct 
POSIX timestamps, ensuring `st_ctime` reflects metadata changes properly.

5. **Added Proper statvfs Support**  
   FatFS used `rtems_filesystem_default_statvfs`, which returned `ENOSYS` and 
caused test failures. I implemented a proper `rtems_fatfs_statvfs()` function 
that uses FatFS’s `f_getfree()` to gather statistics such as free clusters, 
total clusters, and sector sizes. I replaced the default function in the 
filesystem operations table and integrated the new implementation into the 
build system. This solution maps FatFS internals into the POSIX `statvfs` 
format, handles variable sector sizes, ensures thread safety, and now passes 
the `fsstatvfs` test successfully.

-- 
View it on GitLab: 
https://gitlab.rtems.org/groups/rtems/-/work_items/25#note_129098
You're receiving this email because of your account on gitlab.rtems.org.


_______________________________________________
bugs mailing list
[email protected]
http://lists.rtems.org/mailman/listinfo/bugs

Reply via email to