文件系统实现的基本概念

发布于 2024-08-31 04:38:55 字数 143 浏览 4 评论 0原文

我不清楚文件系统的实现。具体来说(操作系统 - Tannenbaum(第 3 版),第 275 页)指出“每个块的第一个字用作指向下一个字的指针。块的其余部分是数据”。

谁能向我解释一下这里的部门层次结构吗?比如,每个磁盘分区都包含块,块包含字?等等...

I am a unclear about file system implementation. Specifically (Operating Systems - Tannenbaum (Edition 3), Page 275) states "The first word of each block is used as a pointer to the next one. The rest of block is data".

Can anyone please explain to me the hierarchy of the division here? Like, each disk partition contains blocks, blocks contain words? and so on...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北凤男飞 2024-09-07 04:38:55

我面前没有这本书,但我怀疑引用的句子并不是真正谈论文件、目录或其他文件系统结构。 (请注意,分区通常不是文件系统概念)。我认为你引用的句子实际上只是指出了存储在磁盘块中的数据结构如何链接在一起的一些事情。它的意思就是它所说的。每个块(通常是 4k,但可能只是 512B)看起来非常粗略像这样:

+------------------+------------- . . . . --------------+
| next blk pointer | another 4k - 4 or 8 bytes of stuff |
+------------------+------------- . . . . --------------+

下一个块指针后面的内容取决于该特定块中存储的内容。仅从给出的句子来看,我无法判断代码是如何计算出来的。

关于文件系统结构:

  • 磁盘扇区的数组,大小几乎总是512B。在内部,磁盘是由盘片构成的,盘片是覆盖着铁锈的旋转盘状物体,每个盘片分为许多同心磁道。然而,ATA 或 SCSI 磁盘接口硬件对操作系统完全隐藏了这些详细信息。
  • 操作系统将扇区数组划分为分区。分区是连续的扇区范围,并且分区不重叠。 (事实上​​,这在某些操作系统上是允许的,但只是想想就令人困惑。)
  • 因此,分区也是一个扇区数组。

到目前为止,文件系统还没有真正出现在图中。大多数文件系统都构建在分区内。文件系统通常有以下几个概念。 (我使用的名称来自 UNIX 传统,但其他操作系统也会有类似的想法。)

  • 分区上某个固定位置是超级块。超级块是所有文件系统数据结构的根,并且包含足够的信息来指向所有其他实体。 (事实上​​,通常有多个超级块分散在分区中,作为一种简单的容错形式。)

  • 文件系统的基本概念是inode,即“眼节点”。索引节点代表构成文件系统的各种类型的对象,其中最重要的是普通文件和目录。一个索引节点可能是它自己的块,但某些文件系统将多个索引节点打包到一个块中。索引节点可以指向一组构成文件或目录实际内容的数据块。文件的数据块如何在磁盘上组织和索引是文件系统的关键任务之一。对于目录,数据块保存目录中包含的文件和子目录的信息,对于普通文件,数据块保存文件的内容。

  • 数据块是分区上的大部分块。有些被分配给各种索引节点(即目录和文件),而另一些则是空闲的。另一个关键的文件系统任务是在数据写入文件时分配空闲数据块,以及在截断或删除文件时释放文件中的数据块。

所有这些概念都有很多变体,我确信在某些文件系统中我上面所说的与现实不太相符。但是,通过上述内容,您应该能够推断文件系统如何完成其​​工作,并至少了解一点在任何特定文件系统中遇到的差异。

I don't have the book in front of me, but I'm suspect that quoted sentence isn't really talking about files, directories, or other file system structures. (Note that a partition isn't a file system concept, generally). I think your quoted sentence is really just pointing out something about how the data structures stored in disk blocks are chained together. It means just what it says. Each block (usually 4k, but maybe just 512B) looks very roughly like this:

+------------------+------------- . . . . --------------+
| next blk pointer | another 4k - 4 or 8 bytes of stuff |
+------------------+------------- . . . . --------------+

The stuff after the next block pointer depends on what's stored in this particular block. From just the sentence given, I can't tell how the code figures that out.

With regard to file system structures:

  • A disk is an array of sectors, almost always 512B in size. Internally, disks are built of platters, which are the spinning disk-shaped things covered in rust, and each platter is divided up into many concentric tracks. However, these details are entirely hidden from the operating system by the ATA or SCSI disk interface hardware.
  • The operating system divides the array of sectors up into partitions. Partitions are contiguous ranges of sectors, and partitions don't overlap. (In fact this is allowed on some operating systems, but it's just confusing to think about.)
  • So, a partition is also an array of sectors.

So far, the file system isn't really in the picture yet. Most file systems are built within a partition. The file system usually has the following concepts. (The names I'm using are those from the unix tradition, but other operating systems will have similar ideas.)

  • At some fixed location on the partition is the superblock. The superblock is the root of all the file system data structures, and contains enough information to point to all the other entities. (In fact, there are usually multiple superblocks scattered across the partition as a simple form of fault tolerance.)

  • The fundamental concept of the file system is the inode, said "eye-node". Inodes represent the various types of objects that make up the file system, the most important being plain files and directories. An inode might be it's own block, but some file system pack multiple inodes into a single block. Inodes can point to a set of data blocks that make up the actual contents of the file or directory. How the data blocks for a file is organized and indexed on disk is one of the key tasks of a file system. For a directory, the data blocks hold information about files and subdirectories contained within the directory, and for a plain file, the data blocks hold the contents of the file.

  • Data blocks are the bulk of the blocks on the partition. Some are allocated to various inodes (ie, to directories and files), while others are free. Another key file system task is allocating free data blocks as data is written to files, and freeing data blocks from files when they are truncated or deleted.

There are many many variations on all of these concepts, and I'm sure there are file systems where what I've said above doesn't line up with reality very well. However, with the above, you should be in a position to reason about how file systems do their job, and understand, at least a bit, the differences you run across in any specific file system.

淡写薰衣草的香 2024-09-07 04:38:55

我不知道这句话的上下文,但它似乎在描述一个块的链接列表。一般来说,“块”是少量字节(通常是2的幂)。它可能是 4096 字节,也可能是 512 字节,这取决于情况。硬盘驱动器的设计目的是一次检索一个数据块;如果你想获取第 1234567 个字节,则必须获取它所在的整个块。“字”要小得多,指的是单个数字。它可以低至2字节(16位)或高至8字节(64位);同样,这取决于文件系统。

当然,块和字并不是文件系统的全部。文件系统通常实现某种 B-tree 来加快查找速度(它不会不必搜索整个文件系统来查找文件,只需沿着树走下去即可)。在文件系统 B 树中,每个节点都存储在一个块中。许多文件系统使用 B 树的一种变体,称为 B+ 树,它将叶子通过链接连接在一起,以使遍历速度更快。这里描述的结构可能描述 B+ 树的叶子,也可能描述用于存储单个大文件的块链。

总之,磁盘就像一个巨大的字节数组,可以分为字(通常为 2-8 字节)和块(通常为 512-4096 字节)。还有其他方法可以将其分解,例如磁头、柱面、扇区等。在这些原语之上,实现了更高级别的索引结构。通过了解文件系统开发人员需要满足的约束(通过一次存储/检索块来有效地模拟文件树),文件系统设计应该非常直观。

I don't know the context of this sentence, but it appears to be describing a linked list of blocks. Generally speaking, a "block" is a small number of bytes (usually a power of two). It might be 4096 bytes, it might be 512 bytes, it depends. Hard drives are designed to retrieve data a block at a time; if you want to get the 1234567th byte, you'll have to get the entire block it's in. A "word" is much smaller and refers to a single number. It may be as low as 2 bytes (16-bit) or as high as 8 bytes (64-bit); again, it depends on the filesystem.

Of course, blocks and words isn't all there is to filesystems. Filesystems typically implement a B-tree of some sort to make lookups fast (it won't have to search the whole filesystem to find a file, just walk down the tree). In a filesystem B-tree, each node is stored in a block. Many filesystems use a variant of the B-tree called a B+-tree, which connects the leaves together with links to make traversal faster. The structure described here might be describing the leaves of a B+-tree, or it might be describing a chain of blocks used to store a single large file.

In summary, a disk is like a giant array of bytes which can be broken down into words, which are usually 2-8 bytes, and blocks, which are usually 512-4096 bytes. There are other ways to break it down, such as heads, cylinders, sectors, etc.. On top of these primitives, higher-level index structures are implemented. By understanding the constraints a filesystem developer needs to satisfy (emulate a tree of files efficiently by storing/retrieving blocks at a time), filesystem design should be quite intuitive.

染墨丶若流云 2024-09-07 04:38:55

曲目>> >> 部门>> 单词>> 字节>> 小咬>>

磁道是磁盘盘片从内到外的同心环。

每个轨道都分为称为扇区的片。

是一组扇区(1、2、4、8、16 等)。驱动器越大,一个块可以容纳的扇区就越多。

是CPU一次可以处理的位数(16位、32位、64位等),在您的示例中,存储以下地址(或可能是偏移量)下一个块。

字节包含半字节。 1 个字节 = 2 个半字节; 1 个半字节 = 4 位。

Tracks >> Blocks >> Sectors >> Words >> Bytes >> Nibbles >> Bits

Tracks are concentric rings from inside to the outside of the disk platter.

Each track is divided into slices called sectors.

A block is a group of sectors (1, 2, 4, 8, 16, etc). The bigger the drive, the more sectors that a block will hold.

A word is the number of bits a CPU can handle at once (16-bit, 32-bit, 64-bit, etc), and in your example, stores the address (or perhaps offset) of the next block.

Bytes contain nibbles and bits. 1 Byte = 2 Nibbles; 1 Nibble = 4 Bits.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文