O_DIRECTORY|O_TMPFILE
O_DIRECTORY|O_TMPFILE
Posted Aug 4, 2026 23:16 UTC (Tue) by neilbrown (subscriber, #359)In reply to: O_DIRECTORY|O_TMPFILE by koverstreet
Parent article: Reconsidering O_CREAT|O_DIRECTORY
I think there's actually no need for unlinked-but-open directories, it's the rm -rf on close that we want
"man 2 open" identifies 4 important aspects of O_TMPFILE:
- are automatically deleted when closed;
- can never be reached via any pathname;
- are not subject to symlink attacks; and
- do not require the caller to devise unique names.
I think these are all important. However this is the VFS view, not the internal FS view. For example, I imagine a filesystem could implement these just like regular directories which are subdirs of the root, but with names that contain a "/'. .iterate_shared() would skip over these. This would answer 2 and 3. The fs would choose a unique name (sprintf(s, "/%d", i->i_ino) which would answer 4. Then you just need the "rm -rf" on close which the VFS could handle most of.
Maybe the fs would provide:
- .tmpdir() which does .mkdir() in the root directory with a synthesized name
- .mvtmp() which take a dentry and moves it to the root with a sythesized name
- .iterate_tmp() which is like iterate_shared() but returns dentries for the hidden objects, which can be passed to .unlink() or .rmdir()
The VFS could have code that uses iterate_tmp() and everything that it finds which isn't open is unlink()ed if a file, rmdir()ed if an empty directory, or iterate_shared() with everything passed to .mvtmp() (or maybe unlink()). This code would be called at mount time and whenever a tmp file/dir is closed for the last time.
So yes, the FS doesn't need to have a concept of unlinked-but-open, but the VFS must have access to "open, but no link that is visible/accessable".
