Can I create a link to an inode?
Joe Smith
jes at martnet.com
Sat Aug 16 03:09:50 UTC 2008
Doug Wyatt wrote:
>
> Jose Celestino wrote:
>> ...
>> 1. locate the open (deleted) file you want from the opening pid on
>> /proc/$PID/fd/*
>> 2. cp /proc/$PID/fd/$FD somewhere
>>
>
> I think I read, somewhere, that in doing that I could end up
> with garbage bytes at the end of the last block in the copy,
> and would need to use the size from the original inode to
> trim the copied file. Don't know if that's fact or not.
>
> Also, by re-linking you preserve the mtime w/o hassling with
> touch.
Interesting topic--I was wondering about this just the other day.
A quick test shows that Jose's approach does not suffer from either of
these problems. I'm using F9/ext3.
I can't say /how/ it works, but it works perfectly:
$ cp -p ~/Music/lib/Various\ Artists/Unknown/afm_St9RvdtvLeE.ogg .
$ ls -li afm_St9RvdtvLeE.ogg
233608 -rw-rw-r-- 1 joe joe 2246026 2008-07-11 21:15 afm_St9RvdtvLeE.ogg
$ audacious afm_St9RvdtvLeE.ogg &
[1] 16404
$ file /proc/16404/fd/10
/proc/16404/fd/10: symbolic link to `/home/joe/tmp/afm_St9RvdtvLeE.ogg'
$ ls -l /proc/16404/fd/10
lr-x------ 1 joe joe 64 2008-08-15 22:15 /proc/16404/fd/10 ->
/home/joe/tmp/afm_St9RvdtvLeE.ogg
$ rm afm_St9RvdtvLeE.ogg
$ ls -l /proc/16404/fd/10
lr-x------ 1 joe joe 64 2008-08-15 22:15 /proc/16404/fd/10 ->
/home/joe/tmp/afm_St9RvdtvLeE.ogg (deleted)
$ file /proc/16404/fd/10
/proc/16404/fd/10: broken symbolic link to
`/home/joe/tmp/afm_St9RvdtvLeE.ogg (deleted)'
$ cp -p /proc/16404/fd/10 afm_back_cp.ogg
$ ls -li afm_back_cp.ogg
233609 -rw-rw-r-- 1 joe joe 2246026 2008-07-11 21:15 afm_back_cp.ogg
$
[1]+ Done audacious afm_St9RvdtvLeE.ogg
$ cmp afm_back_cp.ogg ~/Music/lib/Various\
Artists/Unknown/afm_St9RvdtvLeE.ogg
$
Note that the copy has the exact same size, mtime and contents as the
original file--there's no need at all to use debugfs for this.
Even though the /proc/$PID/fd/$FD appears as a symlink in the
filesystem, it doesn't behave like a normal symlink. A plain symlink
definitely won't support this sort of copy after the target file is deleted.
<Joe
More information about the fedora-list
mailing list