On Monday 16 May 2005 09:24 am, Corey Edwards wrote:
> On Mon, 2005-05-16 at 09:06 -0600, Wade Preston Shearer wrote:
> > I have read the man page but am still confused. What is the
> > difference between hard and software links. I have tested both and
> > it
> > doesn't make sense to me. Hard links don't seem to be links at all.
>
> That would be a "soft" link, not a "software" link. They're all software
> after all.
>
> Every file starts with an inode. That's the basic building block of
> files. They're small, usually 4k or so, and you string together a bunch
> of them to make larger files. A file is basically just a collection of
> inodes, and the file name is tied to the first inode.

Not exactly.  What you're describing alludes more to how a FAT filesystem 
works.  In an fs with inodes (unix-like) a file is one or more *blocks*, 
exactly one inode, with one or more references to it.  Each inode contains a 
pointer to all of the blocks that contain the file (directly or indirectly 
depending on the size of the file, but only one inode regardless), as well as 
the related permissions and ownership information.  References are
just entries in a directory file.

touch a
ls -il a
329032 -rw-r--r--  1 nick users 0 May 16 09:50 a

ln a b
ls -il a b
329032 -r--r--r--  2 nick users 0 May 16 09:50 a
329032 -r--r--r--  2 nick users 0 May 16 09:50 b

chmod a+w a
ls -il a b
329032 -rw-rw-rw-  2 nick users 0 May 16 09:50 a
329032 -rw-rw-rw-  2 nick users 0 May 16 09:50 b

ln -s a c
ls -il a b c
 329032 -rw-rw-rw-  2 nick users 0 May 16 09:50 a
 329032 -rw-rw-rw-  2 nick users 0 May 16 09:50 b
2949872 lrwxrwxrwx  1 nick users 1 May 16 09:52 c -> a

'-i' parameter to ls makes it show the inode number first.  The number 
following the permissions is the reference count in the inode.  Until this 
goes to zero, the inode will persist--there is a reference to it somewhere in 
the fs.

Both a and b share the same inode, and thus permissions as stated in other 
posts.  c has its own inode, and at least in Linux, its permissions are 
totally ignored.

Note that you can also do:
ln c d
ls -il a b c d
 329032 -rw-rw-rw-  2 nick users 0 May 16 09:50 a
 329032 -rw-rw-rw-  2 nick users 0 May 16 09:50 b
2949872 lrwxrwxrwx  2 nick users 1 May 16 09:52 c -> a
2949872 lrwxrwxrwx  2 nick users 1 May 16 09:52 d -> a

since c is a file in and of itself.  I don't know if you could do so for 
non-regular files.

So, in short:

A hard link is simply creating another entry in a directory file that 
references the same inode with either another label or in a different 
directory.

A soft link is a file (with its own inode) whose contents are the pathname to 
the file to which it refers.  As its own file, it also must have at least one 
entry in a directory file.

>
> Well, when you create a hard link you just make another file that points
> to that first inode. Same data, just a different name. One important
> point about hard links is that since an inode is only deleted when all
> references to it are removed, adding more hard links prevents the file
> from being deleted. All hard links have to be removed before the file is
> gone. And since inodes are specific to a filesystem, they can't cross
> boundaries, ie. you can't link across mount points.

This is correct.

>
> Soft links are files in and of themselves. The content of the file is
> basically the name of the file they point to. The act the opposite of
> hard links in regards to deleting and mount points.

opposite? in what regard?  Since they are their own file, they are acted upon 
as their own file unless a utility chooses to dereference it and act upon the 
file to which they refer.  You delete a soft link, you delete the link, not 
the other file.  Since it is just a file with text contents, it can, of 
course have text that represents a path to any location, partition, fs, 
resource, etc.  You can have a symlink such as:

ln -s "http://www.google.com"; g

ls -il g
1291334 lrwxrwxrwx  1 nick users 21 May 16 10:07 g -> http://www.google.com

Some utilities might be smart enough to use this.  I would think this could be 
a handy way to store bookmarks.

>
> One important point to remember is that file permissions are tied to the
> inode, not to the file names. Changing permission on a hard link will
> change the permission on every hard link to that file. Soft links don't
> even bother with permissions but rather push that back to the linked
> file. That's why they always show up with "rwxrwxrwx" permissions.

Yes.


-- 
Respectfully,

Nicholas Leippe
Sales Team Automation, LLC
1335 West 1650 North, Suite C
Springville, UT  84663 +1 801.853.4090
http://www.salesteamautomation.com
.===================================.
| This has been a P.L.U.G. mailing. |
|      Don't Fear the Penguin.      |
|  IRC: #utah at irc.freenode.net   |
`==================================='

Reply via email to