Reload remote file to directory

Is it possible for a program to re-bind a file to a filesystem tree that has been deleted, but to which it still has an open file descriptor?

i.e. if the program has executed

int fd = open("/dir/myfile", O_RDONLY);


is there something like

linkfd(fd, "myfile", "/otherdir/");


which will create /otherdir/myfile

both an entry in the same file used in /dir/myfile


I know it is possible to restore the contents of such a file with a deleted but still open file via /proc/<PID>/fd/<num>

, but this creates a new file with a different inode number. I want to know if the same file can be reattached so that it /otherdir/myfile

has the same inode number as the remote one /dir/myfile



source to share

1 answer

I believe that if it was deleted it no longer has an inode. The file may not be considered content, but an entry into a directory, and it disappeared.

As you say, the content is not lost yet, but the inode is not being restored.



All Articles