4

There has been a trend over the past few years to create more "f" system calls such as fstat, fchmod, ftruncate, etc. which perform operations on an inode that is identified to by an open file descriptor, rather than one that is identified by a path.

I am curious about whether any version of Unix has ever had an "flink" system call, analogous to link(2), except that where link has the following interface:

  int link(const char *oldpath, const char *newpath);

this hypothetical flink would have:

 int flink(int fd, const char *newpath);

It would behave exactly the same, except that istead of using iname internally to resolve oldpath to an inode, it would just use the inode pointed to by the fd structure.

If this hasn't ever been done, is there something obviously wrong with the idea?

Mark Dominus
  • 1,726
  • 12
  • 38
  • One potential problem: People who create nameless temporary files with `tmpfile` might be surprised to learn that another program, receiving the open file descriptor, had then used `flink` to make the temporary file permanent. This seems like a minor issue. – Mark Dominus Jan 22 '14 at 22:05
  • 2
    I'm not aware of a standardized one, but it would not be surprising if someone somewhere in the world had created one at some time or another. It would actually be very useful; you could work with an anonymous temporary file (with automatic cleanup if the program failed), and then give it a name when the work is complete. It would presumably fail with EXDEV if you tried to give it a name off its home file system, and EEXIST if the name already existed. – Jonathan Leffler Jan 22 '14 at 22:05
  • [mark4o's answer here](http://stackoverflow.com/a/4174216/1277934) says “A patch for a proposed Linux `flink()` system call was submitted several years ago, but when Linus stated "there is no way in HELL we can do this securely without major other incursions", that pretty much ended the debate on whether to add this.”. – Mark Dominus Jan 22 '14 at 22:16
  • The [`linkat` system call](http://man7.org/linux/man-pages/man2/linkat.2.html) will do this. – Mark Dominus Aug 29 '14 at 18:53
  • Interesting! That ([`linkat()`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/linkat.html)) is a complex system call, and the answer in the duplicate question suggests that you still can't link an anonymous file even with `linkat()`, or at least, not always. – Jonathan Leffler Aug 29 '14 at 20:41

0 Answers0