As long as there is an open file descriptor pointing to a file, I can bring it back with cp
like this:
# Open for reading
exec 3< file
# Delete
rm file
# Bring it back
cp /proc/self/fd/3 file
This solution is okay with small files, but it's really slow with larger ones (like >5GiB). So I wonder, is there a way of bringing it back without copying the content? I mean, the data lies there untouched unless the descriptor is closed, so why shouldn't it be possible to link a filename to the memory area the data resides?
Please enlighten me on this. A hackish command line solution, a platform/filesystem dependent C API etc. everything is welcome; I just want to know if this is possible somehow somewhere, and if not, I want to know why.
Googling didn't help at all, all I could find is copy-of-copy articles about how to restore files with lsof
and cp
.