yushuailong opened a new pull request, #21462: URL: https://github.com/apache/nuttx/pull/21462
## Summary Fix FAT file truncation leaving retained cluster chains, directory cache contents and traversal cursors inconsistent with the file's new length. When shrinking a file, the retained tail cluster is currently marked free instead of being terminated with an end-of-chain marker. FAT traversal also reuses the directory cache, and a file that has grown without synchronization may still have an outdated start cluster in its directory entry. When extending a file, the traversal cursor may not point to the actual EOF. This can affect retained data, zero-filling and subsequent writes, including recovery after an extension runs out of space. This PR: - Uses FAT_EOF for the retained tail cluster in both linked and open-but-unlinked files. - Restores the directory sector after FAT traversal and uses the shared start cluster when the directory entry has not been synced. - Positions extension at the actual EOF while preserving the caller's file offset. - Resets shared traversal cursors after truncation or failed extension and marks changed metadata for synchronization. The first commit contains the functional fix. The second commit only aligns three assignment lines introduced by the fix; it changes no non-whitespace text. ## Impact - Applies to FAT12, FAT16 and FAT32 in the common FAT filesystem layer. - Fixes retained data, zero-extension, subsequent writes and metadata persistence after truncation. - Covers shared file handles and files unlinked while still open. - No API, Kconfig or on-disk format changes. - No dependency on board-specific changes or the local contiguous cluster I/O optimization. ## Testing Build host: macOS 26.6.2 ARM64, Apple Clang 21.0.0. Target: sim:ostest. Build: make completes successfully with LD: nuttx. Static checks: nxstyle, checkpatch pass. Runtime smoke test: ./nuttx starts and proceeds through enabled OSTest cases without an assertion in the observed run. -- 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]
