unlink 的讨论
时间:2010-08-18 来源:海上的帆
1,unlink is a system call, rm is a shell utility that calls unlink.
2,On some flavors of Unix, unlink can delete things that rm can't, such as
directories, if you're running as superuser
3,In the ancient past, creating a directory consisted of three steps
(now done with mkdir()):
1). create an empty directory node with mknod().
2). Link (hard) a "." entry to that directory node.
3). Link (hard) a ".." entry to the directory's parent.
Removing a directory consisted of three steps (now done with rmdir(),
which also does some type checks first):
1). unlink() the ".." entry
2). unlink() the "." entry
3). unlink() the directory itself
unlink (run as root) would remove a name entry regardless of its type.
With a combination of link() and unlink() you could do all sorts
of evil things to the directory tree by repointing "." and ".."
entries. You could also orphan subtrees that take disk space but
have no references from the outside.
2,On some flavors of Unix, unlink can delete things that rm can't, such as
directories, if you're running as superuser
3,In the ancient past, creating a directory consisted of three steps
(now done with mkdir()):
1). create an empty directory node with mknod().
2). Link (hard) a "." entry to that directory node.
3). Link (hard) a ".." entry to the directory's parent.
Removing a directory consisted of three steps (now done with rmdir(),
which also does some type checks first):
1). unlink() the ".." entry
2). unlink() the "." entry
3). unlink() the directory itself
unlink (run as root) would remove a name entry regardless of its type.
With a combination of link() and unlink() you could do all sorts
of evil things to the directory tree by repointing "." and ".."
entries. You could also orphan subtrees that take disk space but
have no references from the outside.
相关阅读 更多 +