casaroli opened a new pull request, #3998: URL: https://github.com/apache/nuttx-apps/pull/3998
depends-on: apache/nuttx/pull/21599 ## Summary This PR has two commits: - fsutils/mkfatfs: Write the right FAT32 FSINFO free cluster count. For FAT32, `fv_nclusters` is the number of data clusters less the root directory cluster: `mkfatfs_clustersearch()` takes the sectors of that cluster out of the available sectors. `mkfatfs_initfsinfo()` wrote `fv_nclusters - 1` as FSI_Free_Count, so the count was one too low (68888 on a new 34 MiB volume with 512-byte clusters, where a file gets 68889 clusters). On a new volume only the root directory cluster is in use, so the count is now `fv_nclusters`. - testing/fs/fatgap: Add cases for O_APPEND, ftruncate(), statfs() and stat(). New cases for the FAT fixes of apache/nuttx#21599 and for the mkfatfs fix. `fatgap` already makes FAT12, FAT16 and FAT32 volumes on RAM disks; the new cases run on each volume after the write past EOF cases. The new cases: - `append_seek`, `append_setfl`, `append_pwrite`, `append_twofd`: with O_APPEND each `write()` must go to the end of the file, also after `lseek(fd, 0, SEEK_SET)`, after `fcntl(F_SETFL)`, with `pwrite()`, and from two handles that write whole sectors in turn. - `full_volume`: 3000-byte writes until the volume is full. The counts that `write()` returns must add up to the offset and to the file size, and the write after the short one must fail with ENOSPC. - `trunc_twofd`: `ftruncate()` on one handle cuts the file to 100 bytes and makes it longer again. A second handle must read zeros, in the same sector and on a new cluster. - `free_count`: `statfs()` `f_bfree` must be the number of clusters that a file gets when it fills the volume, and 0 on the full volume. On FAT32 the case first sets the FSINFO free count to unknown (0xffffffff), so that the file system counts the free clusters in the FAT. - `stat_open`: `stat()` and `fstat()` must give the size of an open file after a write, before a sync, on a second handle and after a `rename()` of the open file. - `fsinfo` (FAT32, on the new volume): the free count in the FSINFO sector must be the number of data clusters less the root directory cluster. Each case reads the file back on a new handle or after a remount where it applies, and checks that the free cluster count after the unlink is the count of the new volume. The Kconfig prompts and the help text now say "FAT file system test". ## Impact - mkfatfs: a new FAT32 volume has the right free cluster count in its FSINFO sector. FAT uses that count for `statfs()` unless `CONFIG_FAT_COMPUTE_FSINFO` is set, so `df` shows one more free cluster (the right value). FAT12 and FAT16 have no FSINFO sector and do not change. - fatgap: test only. The option, its dependencies and the gap cases do not change. No defconfig sets `TESTING_FATGAP`, so CI does not build or run it. ## Testing `fatgap`, HVF, pass / fail cases (this PR on apps 19cbea35a; the runs on nuttx master used the same test on apps a9ac52328): | Configuration | nuttx master 02ba3229954 | nuttx with apache/nuttx#21599 | ostest | |---|---|---|---| | qemu-armv8a:nsh (flat), FAT12/16/32 | 128 / 23 | 151 / 0 | status 0 with both | | qemu-armv8a:knsh (kernel), FAT12/16 (no memory for the FAT32 RAM disk) | 85 / 15 | 100 / 0 | status 0 with both | | qemu-armv8a:nsh (flat), apache/nuttx#21599, this PR with the old `writefat.c` | - | 146 / 5 | status 0 | On nuttx master every new case except `fsinfo` fails on every FAT type (`free_count` passes on FAT12): for example `append_seek` `offset after the write 2, want 12`, `full_volume` `offset 505856, the counts add up to 504000`, `trunc_twofd` `zeros in the sector: byte 100 is 0x61, want 0x00`, `free_count` `4331 free clusters, a file gets 4333` (FAT16), `stat_open` `new file: stat: size 0, want 1000`. With the old `writefat.c`, `fsinfo` fails (`free count 68888, want 68889 (68890 clusters, one for the root directory)`), and on FAT32 the free count after the unlink of `full_volume` and the later cases is 68889, one more than the count of the new volume. The builds have no warnings, also stm32f4discovery:mmcsdspi (32-bit, built with the test, not run). `tools/checkpatch.sh -c -u -m -g` passes. Not run: CMake, real storage, sector sizes other than 512, protected builds. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
