26.07.2013 Views

File Systems and Disk Layout I/O: The Big Picture

File Systems and Disk Layout I/O: The Big Picture

File Systems and Disk Layout I/O: The Big Picture

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Unix <strong>File</strong> Naming (Hard Links)<br />

A Unix file may have multiple names.<br />

Each directory entry naming the<br />

file is called a hard link.<br />

Each inode contains a reference count<br />

showing how many hard links name it.<br />

link system call<br />

link (existing name, new name)<br />

create a new name for an existing file<br />

increment inode link count<br />

directory A directory B<br />

0<br />

wind: 18<br />

rain: 32<br />

0<br />

hail: 48<br />

sleet: 48<br />

inode link<br />

count = 2<br />

inode 48<br />

unlink system call (“remove”)<br />

unlink(name)<br />

destroy directory entry<br />

decrement inode link count<br />

if count = 0 <strong>and</strong> file is not in active use<br />

free blocks (recursively) <strong>and</strong> on-disk inode<br />

Unix Symbolic (Soft) Links<br />

Unix files may also be named by symbolic (soft) links.<br />

directory A<br />

0<br />

rain: 32<br />

hail: 48<br />

• Asoftlinkisafilecontainingapathnameofsomeotherfile.<br />

inode link<br />

count = 1<br />

inode 48<br />

directory B<br />

wind: 18<br />

0<br />

sleet: 67<br />

inode 67<br />

symlink system call<br />

symlink (existing name, new name)<br />

allocate a new file (inode) with type symlink<br />

initialize file contents with existing name<br />

create directory entry for new file with new name<br />

../A/hail/0<br />

<strong>The</strong> target of the link may be<br />

removed at any time, leaving<br />

a dangling reference.<br />

How should the kernel<br />

h<strong>and</strong>le recursive soft links?<br />

8

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!