Blocks, Files, and Inodes


The different ways of looking at data on a disk can get fairly confusing, but the details are important for understanding how to read the output of tools such as df and fsck. Let's take a closer look at how storage is divided up and used.

The data block is a unit of data storage; the default size for a data block is 8,192 bytes. A block is divided into eight fragments of 1,024 bytes each. A file that does not take up an entire data block is stored in fragments and shares that block with other files. This process is actually what fsck is referring to when it reports fragmentation.

However, if a file that is currently sharing a data block with another file grows to the point where it will no longer fit in the current block, FreeBSD moves the entire file to a different block. In the same circumstance, Windows simply fragments the file into an adjacent block. FreeBSD's approach ensures that for files smaller than 8,192 bytes, all the fragments for a single file are always stored in one data block. It also ensures that a file of any size is stored across as few different blocks as possible. You will never have a small file that has fragments in more then one data block. This, of course, improves access time, and it prevents fragmentation from getting to the dizzy levels seen in consumer-grade operating systems.

A "file" really just provides a way of looking at an inode, which is the fundamental grouping of related data that we think of as a file. This model is necessary for a true multiuser operating system to be able to share files efficiently. Here is all the information that is contained in an inode:

  • The type of file and the access modes

  • The user ID and group ID of the owner

  • The size of the file

  • The time the file was last accessed and modified, and the inode changed

  • The number of data blocks used by or allocated to the file

  • The direct and indirect pointers to these data blocks

FreeBSD accesses data blocks with pointers located in the inodes. There are 12 direct pointers, each of which can access one block. This allows direct access to a file up to 96KB. In addition, there are three levels of indirect pointers: single, double, and triple. These pointers are what allows FreeBSD to support files of extremely large sizes, spanning huge numbers of blocks.

The single indirect pointer refers to a filesystem block that contains pointers to data blocks. The filesystem block contains 2,048 additional addresses of 8KB data blocks, thus allowing access to a file up to 16MB in size. The double indirect pointer refers to a filesystem block containing 2,048 addresses that each point to a filesystem block containing a single indirect pointer, and each one of those 2,048 single indirect pointers refers to a filesystem block containing 2,048 addresses of 8KB data blocks. This allows access to a file up to 32GB in size. Finally, the triple indirect pointer contains 2,048 addresses that each point to a filesystem block containing a double indirect pointer. 2,048 double indirect pointers times 2,048 subsequent single indirect pointers times 2,048 8KB data blocks allows the triple indirect pointer to access a file that is 70TB (terabytes) in size! FFS limits the maximum file size to 1TB, though, so don't get too excited.




FreeBSD 6 Unleashed
FreeBSD 6 Unleashed
ISBN: 0672328755
EAN: 2147483647
Year: 2006
Pages: 355
Authors: Brian Tiemann

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net