Can I create a link to an inode?
Jose Celestino
japc at co.sapo.pt
Fri Aug 15 10:54:59 UTC 2008
Words by Doug Wyatt [Fri, Aug 15, 2008 at 05:47:55AM -0500]:
>
>
> Russell Miller wrote:
>>
>>
>> On Fri, Aug 15, 2008 at 12:30 AM, Russell Miller <duskglow at gmail.com
>> <mailto:duskglow at gmail.com>> wrote:
>>
>>
>>
>> On Fri, Aug 15, 2008 at 12:17 AM, Doug Wyatt <dwyatt at sunflower.com
>> <mailto:dwyatt at sunflower.com>> wrote:
>>
>> Here's the situation - I have video file, currently open
>> in Mplayer, which I accidentally deleted from its directory.
>>
>> So, the storage and inode still exist as long as I don't
>> close the Mplayer.
>>
>> Does anyone know of a way, using available commands or via
>> system calls in a program, to reestablish a link from a
>> directory to the inode?
>>
>>
>>
>> You might try going into debugfs, finding the inode, and seeing if
>> you can tell it it's not deleted anymore. It's not actually deleted
>> until all the references are closed, so I think it might be possible
>> (I don't know the internal details of what happens when a file is
>> deleted but not closed so I may be wrong).
>>
>>
>> Oh hey. Look what I found.
>>
>> http://dag.wieers.com/blog/undeleting-an-open-file-by-inode
>>
>> Still risky but at least you won't be flying blind.
>>
>> --Russell
>>
>
> Excellent!
>
> Debugfs was exactly what I was looking for. I already had the
> inode number from lsof. Going into debugfs and using 'ln' and
> 'set_inode_field' (for incrementing the link count) took care
> of my problem.
>
> I did download the source for 'fdlink', mentioned in a comment
> on <dag.wieers.com>, and looked it over. But I decided, for
> this situation, debugfs was less likely to cause a problem.
>
There's a much easier way. Well, you don't really relink the inode but
copy the original file instead:
1. locate the open (deleted) file you want from the opening pid on /proc/$PID/fd/*
2. cp /proc/$PID/fd/$FD somewhere
--
Jose Celestino | http://japc.uncovering.org/files/japc-pgpkey.asc
----------------------------------------------------------------
"One man’s theology is another man’s belly laugh." -- Robert A. Heinlein
More information about the fedora-list
mailing list