是否有可能重新从一个打开的文件描述符的文件? [英] Is it possible to recreate a file from an opened file descriptor?

查看:128
本文介绍了是否有可能重新从一个打开的文件描述符的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,这个问题似乎不可思议,它可能是,但要给予一定的情况下,我一直在阅读这个了解我节点在笔者给出了一个有趣的例子:

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.

在这里我的问题是:有没有什么办法后,以重新建立一个文件名指向的inode持有 FP 打开调用取消链接()

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()?

免责声明:我不打算这样做在实际code;我仅仅是(重新)学习的i-node,不知道这是可能的。

推荐答案

我怕,因为链接系统调用需要一个有效的文件名是不可能的(这装置,现有链接),而不是一个UNIX文件描述符。有一个在的弗林克函数=htt​​p://pubs.opengroup.org/onlinepubs/007908799/xsh/unistd.h.html相对=nofollow >单UNIX规范

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.

这篇关于是否有可能重新从一个打开的文件描述符的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆