Symbolic link

From OSDev Wiki
Jump to: navigation, search
Filesystems
Virtual Filesystems

VFS

Disk Filesystems
CD/DVD Filesystems
Network Filesystems
Flash Filesystems

Introduction

A symbolic link is a special type of file that refers to another file or directory and is most often encountered in UNIX derived/inspired operating systems and their file systems. Symbolic links are real files that contain a path which is automatically resolved when the link is accessed.

Path resolution

There are multiple ways of handling symbolic links during path resolution: Some operating systems maintain the hierarchy of the path leading to the symlink while others substitute the entire hierarchy of the path for that of the target. UNIX-like operating systems handle this in a strange way: The kernel and C library do the latter while some shells maintain a history of path changes and resolve the parent of a symlinked directory as the parent of the symlink.

Example: On a system substituting the hierarchy (Linux, glibc, shown as shell commands for clarity) :

$ ln -T /dir1/sdir1 /dir2/sdirlink1
$ cd /dir2/sdirlink1
$ pwd
/dir1/sdir1
$ cd ..
$ pwd
/dir1
$ cd /
$ cd /dir2/sdirlink1/..
$ pwd
/dir1

On a system maintaining the symlink's hierarchy (posnk (old version), newlib, shown as shell commands for clarity) :

$ ln -T /dir1/sdir1 /dir2/sdirlink1
$ cd /dir2/sdirlink1
$ pwd
/dir2/sdirlink1
$ cd ..
$ pwd
/dir2
$ cd /
$ cd /dir2/sdirlink1/..
$ pwd
/dir2
Personal tools
Namespaces
Variants
Actions
Navigation
About
Toolbox