|
|
Subscribe / Log in / New account

Can the O_TMPFILE later be saved with real name ?

Can the O_TMPFILE later be saved with real name ?

Posted Jul 22, 2013 14:38 UTC (Mon) by ernest (guest, #2355)
Parent article: Kernel prepatch 3.11-rc2

I haven't look at it yet, but I was wondering if such a temporary file could be given a name and path later. The trouble seems to be that the open with O_TMPFILE only provides a file handle which afaik does not allow a rename (which requires the old file name).

Note that I was just curious. I realize that a create of the final file followed by a data copy would certainly fit the purpose, furthermore the old tmp file name mechanisms still works if I needed this.


to post comments

Can the O_TMPFILE later be saved with real name ?

Posted Jul 22, 2013 14:46 UTC (Mon) by josh (subscriber, #17465) [Link] (1 responses)

Linux doesn't have an flink system call that would allow this. See http://marc.info/?l=linux-kernel&m=104965452917349 for a request for one, and http://marc.info/?l=linux-kernel&m=104973707408577 for Linus saying it won't happen without some additional infrastructure changes.

Can the O_TMPFILE later be saved with real name ?

Posted Jul 22, 2013 15:08 UTC (Mon) by andresfreund (subscriber, #69562) [Link]

Al somewhere in this thread told it could be done via linkat()'ing /proc/self/fd/$fd to the new location.

Can the O_TMPFILE later be saved with real name ?

Posted Jul 22, 2013 15:07 UTC (Mon) by sbohrer (guest, #61058) [Link] (3 responses)

I believe you can do that using the linkat trick described by Al Viro here https://lwn.net/Articles/559147/

Can the O_TMPFILE later be saved with real name ?

Posted Jul 22, 2013 16:08 UTC (Mon) by lambda (subscriber, #40735) [Link] (2 responses)

That works for creating a new file atomically, but not for rewriting an existing file, since you can't use linkat() on a path that already exists.

One of the big use cases for an O_TMPFILE feature would be to improve the pattern of creating a temporary file and renaming it over the original file atomically, so that you don't have a stray temporary file left lying around if something goes wrong, and don't need to worry about races or the other issues with creating a named temporary file. But unless linkat() could be used to overwrite a file atomically, you're going to have to use rename(), which requires that the file have a name to begin with.

Can the O_TMPFILE later be saved with real name ?

Posted Jul 24, 2013 5:49 UTC (Wed) by kevinm (guest, #69913) [Link]

I don't see any impediment to adding an AT_REPLACE flag to linkat(2), which allows replacing an existing destination name just like rename(2) does.

Can the O_TMPFILE later be saved with real name ?

Posted Jul 24, 2013 6:14 UTC (Wed) by jzbiciak (guest, #5246) [Link]

Fair enough.

You could always create the new file with /path/to/replace_gobbledegook_hash_suffix before atomically moving it over the file you're replacing. You lose the anonymity benefit, though, because you are eventually forced to come up with a filename.

I guess the AT_REPLACE suggestion kevinm made earlier would close everything up nicely.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds