O_DIRECTORY|O_TMPFILE
O_DIRECTORY|O_TMPFILE
Posted Jul 31, 2026 19:23 UTC (Fri) by donald.buczek (subscriber, #112892)In reply to: O_DIRECTORY|O_TMPFILE by neilbrown
Parent article: Reconsidering O_CREAT|O_DIRECTORY
Presumably you particularly want the dir tree to disappear when the root is no longer open.
Yes, the guaranteed cleanup by the system would be the main point of this wish. Additionally, it would be convenient if you were able to create a temporary directory without the need to address name clashes and races.
That would be an interesting challenge but I suspect a tmpfs implementation wouldn't be too intrusive.
That would be nice to have, although I also have use cases for persistent filesystems like the root filesystem or big, secondary filesystems.
What is your compelling use case?
I think about all the bash scripts which use mktemp and trap, which is unreliable. I imagine a wrapper to create an unlinked directory and call a command (script) maybe with cwd in it or with TMPDIR or another environment variable pointing to /proc/self/fd/N for the scripts usage. The script could just use that directory for all its scratch files including calling external tools (e.g. git clone) without the need to address cleanup or name collisions in any way. Yes, the wrapper could do the cleanup, too, but this would also not be reliable. For example, the wrapper could be killed by the user or the users session manager before completing the cleanup. Even if you make the wrapper privileged or a us a privileged service, you still would have the cleanup problem if the system goes down (not on tmpfs, though).
I think you don't necessarily need a script to be called from a wrapper, the script could also make use of the feature by its own code and a helper program: For example, bash could use coproc to run an external program which creates the directory, echos the fd-number to stdout and than waits forever or for a reply. bash would read the fdnum, open the directory via /proc/PID/fd/N itself and than kill the coproc or tell it to finish.
For the system disk usage: We distribute system software by sending tar archives to clients. These tar archives are extracted to a temporary directory on the system disk and than the files are moved into place.
For the usage on real on-disk filesystems: Just programs which need lot of scratch space that don't fit into a memory filesystem.
We have more interest in non-tmpfs solutions, because we operate multi-user systems. We don't want users to exhaust memory by using /tmp , so our /tmp is not tmpfs. Users should use "real" filesystems for temporary data and we hope that the filesystem caches partly compensates for the performance loss.
