Is it possible to recreate a file from an opened f

2020-06-13 13:33发布

Now, this question may seem weird, and it probably is, but to give some context, I've been reading this to learn about i-nodes in which the author gives an interesting example:

{
  FILE *fp;

  fp = fopen("some.hidden.file","w");
  unlink("some.hidden.file"); /* deletes the filename part */

  /* some.hidden.file no longer has a filename and is truly hidden */
  fprintf(fp,"This data won't be found\n"); /* access the data part */
  /*etc*/
  fclose(fp); /* finally release the data part */
}

This allows to create a "hidden" temporary file.

My question here being: is there any way to recreate a filename that points to the inode held opened by fp after the call to unlink()?

Disclaimer: I do not intend to do this in real code; I'm merely (re)learning about i-nodes and wonder if this is possible.

1条回答
该账号已被封号
2楼-- · 2020-06-13 14:04

I'm afraid it is not possible because the link system call demands a valid file name (which means, an existing link) rather than an UNIX file descriptor. There is no flink function in the Single UNIX Specification.

查看更多
登录 后发表回答