符号链接背后是什么? [英] What is there behind a symbolic link?

查看:41
本文介绍了符号链接背后是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UNIX/Linux 系统如何在内部管理符号链接.众所周知,即使没有实际的目标文件(悬空链接),符号链接也可能存在.那么什么是内部代表符号链接的东西.

How are symbolic links managed internally by UNIX/Linux systems. It is known that a symbolic link may exist even without an actual target file (Dangling link). So what is that which represents a symbolic link internally.

在 Windows 中,答案是重新分析点.

In Windows, the answer is a reparse point.

问题:

UNIX/Linux 中的答案是 inode 吗?

Is the answer an inode in UNIX/Linux?

如果是,那么目标和链接的 inode 编号是否相同?

If yes, then will the inode number be same for target and links?

如果是,链接inode是否可以拥有与目标inode不同的权限(如果存在)?

If yes, can the link inode can have permissions different from that of target's inode (if one exists)?

推荐答案

这不是关于 UNIX/Linux,而是关于文件系统实现 - 但是是的,Unix/Linux 在内核级别使用 inode 并且文件系统实现有 inode(至少是虚拟的)).

It is not about UNIX/Linux but about filesystem implementation - but yes, Unix/Linux uses inodes at kernel level and filesystem implementations have inodes (at least virtual ones).

一般来说,符号链接只是文件(顺便说一句,目录也是文件),具有:

In the general, symbolic links are simply files (btw, directories are also files), that have:

  • 在inode"中的flag file-type 告诉系统这个文件是一个符号链接"
  • file-content:目标路径 - 换句话说:符号链接只是一个文件,其中包含一个文件名,在 inode 中带有一个标志.
  • the flag file-type in the "inode" that tells to the system this file is a "symbolic link"
  • file-content: path to the target - in other words: a symbolic link is simply a file which contains a filename with a flag in the inode.

虚拟文件系统也可以有符号链接,因此,请检查 FUSE 或其他一些文件系统实现源.(ext2/ext3/ufs..etc)

Virtual filesystems can have symbolic links too, so, check FUSE or some other filesystem implementation sources. (ext2/ext3/ufs..etc)

所以,

答案是 UNIX/Linux 中的 inode 吗?

Is the answer an inode in UNIX/Linux?

取决于文件系统的实现,但是是的,通常 inode 包含文件类型"(以及所有者、访问权限、时间戳、大小、指向数据块的指针).有些文件系统没有inode(在物理实现中),但只有虚拟inode"以保持与内核的兼容性.

depends on filesystem implementation, but yes, generally the inode contains a "file-type" (and owners, access rights, timestamps, size, pointers to data blocks). There are filesystems that don't have inodes (in a physical implementation) but have only "virtual inodes" for maintaining compatibility with the kernel.

如果是,那么目标和链接的 inode 编号是否相同?

If yes, then will the inode number be same for target and links?

.通常,符号链接是具有自己的 inode 的文件,(具有文件类型、自己的数据块等)

No. Usually, the symlink is a file with its own inode, (with file-type, own data blocks, etc.)

如果是,链接inode可以有和target不同的权限吗?inode(如果存在)?

If yes, can the link inode can have permissions different from that of target's inode(if one exists)?

这是关于如何处理符号链接文件.通常,内核不允许更改符号链接权限 - 符号链接始终具有默认权限.您可以编写自己的文件系统来允许符号链接的不同权限,但是您会遇到麻烦,因为像 chmod 这样的常见程序不会更改符号链接本身的权限,因此无论如何制作这样的文件系统都是毫无意义的)

This is about how symlink files are handled. Usually, the kernel doesn't allow changes to the symlink permissions - and symlinks always have default permissions. You could write your own filesystem that would allow different permissions for symlinks, but you would get into trouble because common programs like chmod don't change permissions on symlinks themselves, so making such a filesystem would be pointless anyway)

要了解硬链接和符号链接之间的区别,您应该先了解目录.

To understand the difference between hard links and symlinks, you should understand directories first.

目录是告诉内核将此文件作为file-nameinode_number的映射来处理"的文件(由inode中的标志区分).硬链接只是映射到相同inode 的文件名.所以如果目录文件包含:

Directories are files (with differentiated by a flag in the inode) that tell the kernel, "handle this file as a map of file-name to inode_number". Hard-links are simply file names that map to the same inode. So if the directory-file contains:

file_a: 1000
file_b: 1001
file_c: 1000

上面的意思是,在这个目录下,有3个文件:

the above means, in this directory, are 3 files:

  • inode 1000 描述的文件_a
  • 由 inode 1001 描述的 file_b 和
  • file_c 再次由 inode 1000 描述(因此它是 file_a 的硬链接,而不是 file_a 的硬链接 - 因为无法分辨哪个文件名先出现 - 它们是相同的).
  • file_a described by inode 1000
  • file_b described by inode 1001 and
  • file_c again described by inode 1000 (so it is a hard link with file_a, not hardlink to file_a - because it is impossible to tell which filename came first - they are identical).

这是与符号链接的主要区别,其中file_b(inode 1001)的inode 可以具有内容file_a"和一个表示这是一个符号链接"的标志.在这种情况下,file_b 将是指向 file_a 的符号链接.

This is the main difference to symlinks, where the inode of file_b (inode 1001) could have content "file_a" and a flag meaning "this is a symlink". In this case, file_b would be a symlink pointing to file_a.

这篇关于符号链接背后是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆