[NTLUG:Discuss] symbolic links
Eric Schnoebelen
eric at cirr.com
Wed Apr 16 14:44:42 CDT 2003
Kenneth Loafman writes:
- Eric Schnoebelen wrote:
- > Kenneth Loafman writes:
- > - Hard links cannot remain by themselves if the filesystem is operating
- > - properly. The hard link is literally another name for the file and
- > - every operation on the hard link, remove included, is done to the file,
- > - and to its original directory entry.
- >
- > ?original directory entry? Which one is that?
-
- Sorry, shorthand. Yes, the directory entries point to inodes, and the
- hard links are just pointers to the same inodes. Instead of directory
- entries, I was thinking back to the user that wanted the timestamp on
- symbolic links to be the same as the target file. With hard links you
- get that, the directory entry for the original file is the same as the
- directory entry for the hard link in the directory listing.
Back up a couple of paces.. Hard links are nothing more
than _more_ directory entries, with the e2d_ino (or d_ino)
field pointing to the inode with the meta data for a given file.
Once two exist, one is no more "original" than another.
- Thus, if you touch a file, you also touch its hard link, both in the
- inode on the filesystem, and in directory entry listings (ls -l).
You're actually updating the meta-data in the inode
itself, not in the directory entry. A directory entry consists
of nothing more than the file name, basic file type (why here,
speed?), and the inode that contains the meta-data.
- One thing we were both wrong about... you can delete the original file
- and the hard link will keep the file inode active. The following was
- run under Linux 2.4.18:
That's why I asked about "the original file". There is
an original directory entry, but as far as the kernel and file
system is concerned, the data is just a sequence of blocks as
described by an inode. The open(2) and stat(2) system calls end
up with a bunch of (common) code to turn a pathname into an
inode.
You can also keep the file allocated by having it open
when the directory entry is unlinked. It' finally disappear
when closed, unless you manage to restore a directory entry to
it.
For more information, please see chapter 4 of _The
Design of the UNIX Operating System_; Maurice J. Bach;
Prentice-Hall; 1986 (or later editions.)
See also chapter 7 of _The Design and Implementation of
the 4.4 BSD Operating System_; Marshall Kirk McKusick, Keith
Bostic, Michael J. Karels, and John S. Quarterman; Addison
Wesley, 1996.
--
Eric Schnoebelen eric at cirr.com http://www.cirr.com
"A cat spends her life conflicted between a deep, passionate and profound
desire for fish and an equally deep, passionate and profound desire to
avoid getting wet. This is the defining metaphor of my life right now."
More information about the Discuss
mailing list