Relinking an anonymous (unlinked but open) file

前端 未结 5 1234
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 08:39

In Unix, it\'s possible to create a handle to an anonymous file by, e.g., creating and opening it with creat() and then removing the directory link with unlink() - leaving y

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 08:52

    Clearly, this is possible -- fsck does it, for example. However, fsck does it with major localized file system mojo and will clearly not be portable, nor executable as an unprivileged user. It's similar to the debugfs comment above.

    Writing that flink(2) call would be an interesting exercise. As ijw points out, it would offer some advantages over current practice of temporary file renaming (rename, note, is guaranteed atomic).

提交回复
热议问题