Unix 文件系统:文件名如何转换为磁盘扇区? [英] Unix File System: How are file names translated to disk sectors?

查看:25
本文介绍了Unix 文件系统:文件名如何转换为磁盘扇区?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个非常基本的问题.当我尝试通过提供文件的完全限定路径来打开文件描述符时,执行的确切步骤顺序是什么.

A very basic question. What is the exact sequence of steps executed when I try to open a file-descriptor, by providing fully-qualified path to the file.

我在找

  • 这在 Linux 上的工作原理
  • 给定一个文件名 - 如何将其转换为 inode 和磁盘扇区
  • Linux 文件系统(特别是 ext3 和 ext4)是否维护某种文件名到 inode 的映射?

推荐答案

除了tmp的回答:

文件确实是inode.

通常,给定文件在某个目录中有一些条目指向它的 inode.目录是将名称映射到inode,目录是一种文件.请参阅 stat(2) 了解 inode 包含的内容(以及可以通过应用程序代码查询),特别是对于各种文件类型(普通文件、目录、字符或块设备、fifo、符号链接......).因此,目录通常是将字符串映射到 inode 的字典(以各种文件系统特定的方式实现).因此,在目录 /bin/ 中通常有一个条目将 bash 关联到 bash shell 的 ELF 可执行文件的 inode(即 >/bin/bash).使用 readdir(3) - 依次调用 getdents(2)- 读取目录中的条目.

Usually, a given file has some entry in some directory pointing to its inode. Directories are mapping names to inodes, and directories are a kind of file. See stat(2) for what an inode contains (and can be queried by application code), in particular for the various file types (plain file, directory, char or block device, fifo, symlink, ....). So a directory is often a dictionnary (implemented in various, file system specific, ways) mapping strings to inodes. So in the directory /bin/ there is usually an entry associating bash to the inode for the ELF executable of the bash shell (i.e. /bin/bash). Use readdir(3) -which in turn calls getdents(2)- to read the entries in a directory.

一个给定的 inode 可能无法通过某个名称访问.当进程是 open(2) 时,尤其会发生这种情况-ing 一个文件,然后 unlink(2)-ing它(同时保留打开的文件描述符).这是制作临时文件的首选方式.(当没有更多进程使用它们时,它们将由内核释放).

It may happen that a given inode is not any more reachable by some name. This happens in particular when a process is open(2)-ing a file, then unlink(2)-ing it (while keep the opened file descriptor). This is the preferred way to make temporary files. (They will be released by the kernel when no more processes use them).

一个给定的 inode 也可能有 几个 目录条目指向它.(即一个文件有几个名称")这发生在 link(2) 系统调用.(符号链接文件是使用 symlink(2) 创建的).

It may also happen that a given inode has several directories entries pointing to it. (i.e. a file has "several names") This happens with link(2) syscall. (symlink files are created with symlink(2)).

另见 path_resolution(7)unix 文件系统 &文件系统 &ext2 &ext3 &ext4 &btrfs &文件系统比较 wikipages.另请阅读这个旧的 文件系统 描述(有些细节已经烂了,但是大意就在这里,特别是VFS)

See also path_resolution(7) and unix file system & file system & ext2 & ext3 & ext4 & btrfs & comparison of file systems wikipages. Read also this old file system description (some details are rotten, but the general idea is here, notably the role of VFS)

这篇关于Unix 文件系统:文件名如何转换为磁盘扇区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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