[comp.unix.wizards] Symbolic linking vs. Hard linking on BSD

DBLCU@CUNYVM.CUNY.EDU (12/15/87)

Can anyone out there please describe for me the difference between
symbolic & hard linking in the BSD environment?
     
I was looking at all the BSD documentation I have and could not find
anything that describes the difference between the two. It seems
that symbolic linking will allow linking across file systems while
hard linking does not, but I do not understand the process.
     
Thanks in advance.
     

matt@oddjob.uchicago.EDU (My Name Here) (12/19/87)

In article <926DBLCU@CUNYVM> you write:
) Can anyone out there please describe for me the difference between
) symbolic & hard linking in the BSD environment?

This question belonged in comp.unix.questions, not ...wizards.

A normal everyday file has a bunch of data blocks that hold the
contents of the file.  There is also something called an "inode"
which contains the addresses of the data blocks, the total size of
the file, the owner, the permission bits, last access and
modification time, and a few other bits.  The inode does not include
the name of the file anywhere.

Some directory has an entry for a certain name, along with the number
of an inode.  The name is now a name for the file described by the
inode.

A "hard link" to a file is merely another entry (in the same or a
different directory) which indicates the same inode number.  Inode
numbers start from 1 on each disk partition, so there is no way for a
directory to have an entry for a file on another filesystem.  Also,
there is no way to distinguish the "first" entry for a file from any
others.  All hard links are equal.  If you delete the original entry,
the file still exists under its other names.  The inode and the data
blocks are not released for re-use until all entries for the file
have been removed.

A "soft link" is a special kind of file.  It's inode has a code in it
that says "I am a symbolic link".  The content of the file is just
the name of the file that this is a link to.  That target file may or
may not exist at any given moment.  Since the symbolic link contains
a name rather than an inode number, the referenced file (if it does
exist) may be on any filesystem.
________________________________________________________
Matt	     University		matt@oddjob.uchicago.edu
Crawford     of Chicago     {astrovax,ihnp4}!oddjob!matt

gwyn@brl-smoke.ARPA (Doug Gwyn ) (12/19/87)

In article <926DBLCU@CUNYVM> DBLCU@CUNYVM.CUNY.EDU writes:
>It seems that symbolic linking will allow linking across file systems while
>hard linking does not, but I do not understand the process.

That's the main operational difference from the user's perspective.
(Also, some versions of "ls" flag symbolic links specially.)

How it works is simple.  A "hard link" is just an entry in a
directory file that includes a name and an index into the disk
"inode" pool (an inode contains data blocks, user ID, protection
mode, etc. associated with the actual data file.)

A symbolic link is a small file (itself registered as a hard
link in some directory, that indexes a special type of inode)
containing the pathname to be followed to reach the referenced
data file.

The operating system kernel notices when it encounters a
symbolic link while opening a file (it does this by seeing
that the inode type of the symlink is special), and takes
special action by reading the small file to find out where to
go next.