Skip to content

[HELP] FAT: How should unlink defer cluster-chain deletion for open files? #20037

Description

@arnavsharma990

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

  • I have verified before submitting the report.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions