Re: Can I create a link to an inode?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux