Sample Header Ad - 728x90

Creating a filename for an opened file descriptor

3 votes
2 answers
203 views
I have a file on the filesystem. I'm opening the file with the open(2) function to get the file descriptor to that file. Now I remove the file. But I still have the file descriptor, so I can read and write to that file without problems, because the filesystem will not remove the file allocation of my file until last file descriptor is closed. But after I remove the file, and while I still hold the file descriptor, can I somehow re-create (re-bind) the filename to that file descriptor? So the file would appear again on the filesystem, so it won't be removed when I close the file descriptor? (all I have is an opened file descriptor and nothing else). I'm mostly interested if this can be done on macOS (on Linux/glibc it seems to be possible to do by using linkat with the AT_EMPTY_PATH flag).
Asked by antekone (722 rep)
Oct 5, 2023, 05:56 AM
Last activity: Jun 19, 2024, 09:16 AM