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

[cobalt-users] Re: Default FTP login on RaQ2/3



On Sat, 18 Mar 2000, Jeff Lasman wrote:

> Fathi Said wrote:
> 
> > Can you tell me, what is the difference between a symbolic and a hard link?
> 

  Symbolic links are resolved as simple text substitutions on the
filename, as such the system doesn't care what the symlink points to, it 
just does the substitution before it tries to resolve the filename,

so, for example if foo is a symlink to bar, opening the file

 /home/foo/file.txt will be changed by the system to /home/bar/file.txt
>before< it makes any attempt to access/open the file, there is no
requirement that 'bar' actully exist, it's treated as just a text
fragment, it can also point to another disk, or anywhere else, or to
anything that can be crammed into a filename.
since symlinks are resolved before file access, the ownership and
permissions are taked from the result, not the initial filename.
however, the symlink itself has to be readable and executable by the user,
so you can make a symlink to a file more restrictive than the actual file
it points to, but you can't give away permissions...

Hard links on the other hand, cause two or more filenames to point to 
the same actual block of data (the 'inode') on the disk,
 since filenames can only
reference data on the same disk they are located on,
 hard links can not point to
another disk, and the file obviously has to exist. File ownership and
permissions on unix are associated with data, not the filename btw..
so changing the permission on one filename 
will change it on the other.(hard linked filename)

Hard links have been around since the beginning of unix, symlinks were
added later to solve 2 problems, the issue of crossing filesystems, which
hard links can not do, and the 'directory problem', using hard links on
directorys is actully truely evil, it fails assumptions about there being
a one to one mapping between directory blocks and file allocation blocks,
on earlier linux versions this can cause fsck to corrupt the filesystem
during filesystem checking, there are also issues about filename changes
being atomic, ie what happens is 2 directories refer to the same filename
and you modify the file, the timestamps in (apparently) 2 directorys
change, this actully causes problems for some programs, plus programs like
tar won't necessarily realize that 2 directorys actully refer to the same
data, so it will back the data up twice....and restoring the data will
create 2 directorys, this doesn't happen with symlinks because programs
like tar know what symlinks are and realizes they just point to copies of
data somewhere else....

Hard links in directory paths can also subvert chroot , beware, you can 
open security holes this way. When 2 inodes refer to the same directory,
there is no way to resolve the 'absolute path' to a file, there are
two ways to get there.

One last detail on both types of links, editing
 a file that is a link to another
file will often cause something unexpected to happen
...most editors rename the file
to a backup file and then copy the data back to the original, some do it the
other way around, the problem is you end up with a local copy of the file
instead of changing the original, which is now the backup file...

Yeash...looks like the start of a book (and there are more subtle issues here)

> Actually, no.
> 
> I just looked this up in five different books, and while the concept is
> simple, the real difference is hard to understand well enough to explain
> <frown>.
> 
> Symbolic links can be across partitions.  Hard links have to be removed
> before the original file can be removed.
> 
> Some of the books say hard links are better.  Some say symbolic links
> are better.  None go into them in enough detail, not even the one about
> programming and linux internals <frown>.
> 
> I remember, when I was a little boy, mom used to tell me not to use hard
> links for directories.

Always listen to mom....-/

[]