Description
Hi NuttX community,
I'm looking into the TODO in fs/fat/fs_fat32.c regarding rmdir()/unlink() behavior when a file or directory is still open:
"Need to defer deleting cluster chain if the file is open."
I've been investigating the current FAT implementation and prototyped a small fix using a pending-delete state on struct fat_file_s and the existing fs_head open-file list.
However, I ran into an identity/lifetime question.
Using ff_startcluster to determine whether an open handle belongs to the unlinked file does not seem safe because:
- an empty file has
ff_startcluster == 0 and can acquire a cluster later when written;
- cluster numbers can be reused;
ff_dirsector / ff_dirindex represent the directory entry location, but directory entries can be moved by rename and reused after unlink;
fat_dup() currently creates another fat_file_s rather than sharing a canonical underlying file object.
So I'm wondering what the intended design is here.
Would the preferred approach be to introduce some small FAT-local per-file identity/lifetime state (for example, a canonical fat_file_s with a reference count and pending-delete state), or is there an existing FAT/VFS mechanism that should be used for associating open handles with the underlying file across unlink/rename?
I would appreciate any guidance on the intended approach before I open a PR.
Thanks!
Verification
Description
Hi NuttX community,
I'm looking into the TODO in
fs/fat/fs_fat32.cregardingrmdir()/unlink()behavior when a file or directory is still open:I've been investigating the current FAT implementation and prototyped a small fix using a
pending-deletestate onstruct fat_file_sand the existingfs_headopen-file list.However, I ran into an identity/lifetime question.
Using
ff_startclusterto determine whether an open handle belongs to the unlinked file does not seem safe because:ff_startcluster == 0and can acquire a cluster later when written;ff_dirsector/ff_dirindexrepresent the directory entry location, but directory entries can be moved by rename and reused after unlink;fat_dup()currently creates anotherfat_file_srather than sharing a canonical underlying file object.So I'm wondering what the intended design is here.
Would the preferred approach be to introduce some small FAT-local per-file identity/lifetime state (for example, a canonical
fat_file_swith a reference count and pending-delete state), or is there an existing FAT/VFS mechanism that should be used for associating open handles with the underlying file across unlink/rename?I would appreciate any guidance on the intended approach before I open a PR.
Thanks!
Verification