1 Kernel Data Structures Review
1.每个进程都有一个process table,索引是文件描述符,指向filetable
2.file table中有对文件状态的描述,比如offset
3.v-node(是虚拟文件,一切皆文件) i-node(实际的物理装置信息)
2 Hard Links
- v-nodes are the file system enteries
- i-nodes represent the underlying storage mechanisms for that data within that file.
- hard-link
-
there are two virtual v-nodes that reference the same i-node
-
the file exists in multiple places within the file system, and can have different names. But, whenever you open that file, it is the same underlying data that is accessed.
-
2.1 Creating Links with ln
1)创建文件f,此时links是1
#> touch f
#> ls -l
-rw-r--r-- 1 aviv staff 0 Mar 23 12:51 f
# 解释
links--. .--file size
\ /
-rw-r--r-- 1 aviv staff 0 Mar 23 12:51 f
\________/ \_________/ \__________/ \_
| | | |
permissions user/group mod time file name
2)创建硬链接
#> ln f hl #Create a hard link to f named hl
#> ls -l
total 0
-rw-r--r-- 2 aviv staff 0 Mar 23 12:51 f
-rw-r--r-- 2 aviv staff 0 Mar 23 12:51 hl
2.2 Hard Links and Directories
1..
有两个连接:1).
本身 2)具体的路径
2...
有三个连接:两个来自于.
,还有一个来自..
本身
#> ls -lia
34996362 drwxr-x--- 2 aviv scs 4096 Mar 23 18:14 .
34996236 drwxr-x--- 3 aviv scs 4096 Mar 23 18:14 ..
34996364 -rw-r----- 2 aviv scs 0 Mar 23 18:14 f
34996364 -rw-r----- 2 aviv scs 0 Mar 23 18:14 hl
2.3 Un-linking is the same as removal
1.un-linked hl is that we removed it, and that is exactly what remove does
2. In other terms, the unlink command removes an entry from the file system by removing a link.
#> ls -li
total 0
34996364 -rw-r----- 2 aviv scs 0 Mar 23 18:14 f
34996364 -rw-r----- 2 aviv scs 0 Mar 23 18:14 hl
#> unlink hl
#>ls -l
total 0
-rw-r----- 1 aviv scs 0 Mar 23 18:14 f
2.4 Hard-linking across file systems
3 Symbolic Links
- Symbolic Links
-
Symbolic Linking is when one file links to another file, which refernces the underlying file block.
-
类似于win的shortcut
-
3.1 Creating Symbolic Links
#> ln -s f sl
#> ls -l
-rw-r----- 1 aviv scs 0 Mar 23 18:14 f
lrwxrwxrwx 1 aviv scs 1 Mar 23 18:44 sl -> f
3.2 Dangling Links
#> rm f
rm: remove regular empty file `f'? y
#> ls -l
lrwxrwxrwx 1 aviv scs 1 Mar 23 18:44 sl -> f
#> cat sl
cat: sl: No such file or directory
3.3 Symbolic Links across Files Systems
来源:CSDN
作者:Claroja
链接:https://blog.csdn.net/claroja/article/details/103599046