views:

175

answers:

3

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...

+1  A: 

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.

Dolph
I'm afraid that some of this isn't quite right. Tracks are indeed as you describe, but they are almost entirely hidden by modern disk drives: I don't know of a recent file system that makes use of them. In the context of a file system, a block is almost always the basic unit of space allocation, 4kB and 8kB being traditional sizes. The block does not hold more sectors as the disk gets larger, the disk just holds more blocks. Finally, bytes do not contain words. Words are always multiple bytes. "Word" by itself usually means either 4 or 8 bytes.
Dale Hagglund
I'm just providing context for the other vocabulary. Just because tracks are abstracted away from the file system doesn't mean they're not there.
Dolph
Also, I learned this stuff when "word" by itself meant 2 bytes, thankyouverymuch. We didn't need none of yer fancy-schmancy 8-byte words!
Dolph
I'm with Dale. Tracks are a low-level concept like cylinders, platters, and heads which are specific to a physical implementation of a hard drive. SSD (Flash drives) don't have any of those things.
Gabe
True enough, although as I recall, it was the upstart x86 architecture that stole the word "word" from S/360 mainframe where it was already happily in use as meaning four bytes. Not my problem, but you're still incorrect in your statement that blocks get bigger as the disk gets bigger. You could define blocks this way, but no file system I'm aware of does so.
Dale Hagglund
When address space becomes a limitation, the only way to take advantage of a larger storage device is to increase the size of each block. I don't think this is an issue today, but it has been in the past, and it will become a problem again in the future.
Dolph
thank you for the explanation
darkie15
+3  A: 

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.

Dale Hagglund
Not all file systems use inodes. That's pretty much Unix-alikes. Lots of file systems have nothing of the sort. (The venerable FAT systems, for example.)
JUST MY correct OPINION
I used unix terminology because that's what I'm most familiar with. However, I would argue that even FAT has to have some place on the partition that represents a given file and points to its contents somehow: whatever FAT calls it, that's analogous to an "inode".
Dale Hagglund
thank you for detailed explanation
darkie15
+2  A: 

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.

Joey Adams
I really liked your answer. It was the explained in the simplest terms !! Thank you.
darkie15