A symbolic link is an indirect pointer to a file. He is different from the hard link in the previous section. The hard link points directly to the I node of the file. The reason for introducing symbolic links is to avoid some of the limitations of hard links.
Hard links often require links and files to reside on the same file system.
Only super users can create hard links to directories.
There is no file system restriction on symbolic links and what objects he points to. Any user can create a symbolic link to a directory. Symbolic links are typically used to move a file or this directory structure to another location on the system.
When you use a function that references a file by name, you should know whether the function handles symbolic links. That is, whether the function follows a symbolic link to a file that is in the chain section. If the function has the ability to handle symbolic links, its path name parameter refers to the file pointed to by the symbolic link. Otherwise, the path name parameter refers to the link itself. Rather than the file that the link points to. The following table lists the functions that are described in this chapter to handle symbolic links.
Function |
Do not follow symbolic links |
Follow Symbolic Links |
Access |
|
|
ChDir |
|
|
chmod |
|
|
Chown |
|
|
creat |
|
|
Exec |
|
|
Lchown |
|
|
Link |
|
|
Lstat |
|
|
|
|
Opendir |
|
|
Pathconf |
|
|
Readlink |
|
|
Remove |
|
|
Rename |
|
|
Stat |
|
|
Truncate |
|
|
Unlink |
|
|
The Mkdir,mkinfo,mknod and rmdir these functions are not listed in the table above. The reason for this is that when the pathname is a symbolic link, they all appear to be returned incorrectly. Some functions that take a file descriptor as parameters are also not listed in the table. The reason for this is that the processing of the link to the regal is performed by the function colleague who returned the file descriptor is open. Whether the chown follows the symbolic link depends on the implementation.
An exception to the table above is to call the Open function with both o_creat and O_EXCL. In this case, if the path name references a symbolic link, the Open function returns an error. and set the errno to Eexist. The intent of this approach is to block a security vulnerability. A process that makes it privileged will not be tricked into writing to a file that is not appropriate.
Instance:
Using symbolic links may introduce loops in the file system. Most functions that find path names will return the value Eloop and errno when they occur in this case.
[Devis@gdmss unix_pro]$ mkdir foo
[Devis@gdmss unix_pro]$ touch foo/a
[Devis@gdmss unix_pro]$] ln-s. /foo foo/testdir
[devis@gdmss unix_pro]$ ls-l foo
Total 0
-rw-rw-r--1 devis devis 0 10-24 22:03 a
lrwxrwxrwx 1 devis devis 6 10-24 22:03 testdir-> ... /foo