Go to the previous, next section.

Blocks and Fragments

Blocks are the basic building blocks of a file system. The file system manager requests to read or write from the disk are always translated to a query to read or write an integral number of blocks from the disk.

Some blocks on the file system are reserved for the exclusive use of the superuser. This information is recorded in the s_r_blocks_count member of the superblock structure. See section Superblock Whenever the total number of free blocks becomes equal to the number of reserved blocks, the normal users can no longer allocate blocks for their use. Only the superuser may allocate new blocks. Without this provision for reserved blocks, filling up the file system might make the computer unbootable. Whenever the startup tasks would try to allocate a block, the computer would crash. With reserved blocks, we ensure a minimum space for booting and allowing the superuser to clean up the disk.

This is all very simple. However, computer scientists like to complicates things a bit. There are in fact two kinds of blocks, logical blocks and physical blocks. The addressing scheme and size of these two kind of blocks may vary. What happens is that when a request is made to manipulate the range `[a,b]' of some file, this range is first converted by the higher parts of the file system into a request to manipulate an integral number of logical blocks: `a' is rounded down to a logical block boundary and, `b' is rounded up to a logical block boundary. Then, this range of logical blocks is converted by lower parts of the file system into a request to manipulate an integral number of physical blocks. The logical block size must be the physical block size multiplied by a power of two (2). So when going from logical to physical addressing we just have to multiply the address by this power of two.

The logical addresses of the file system goes from zero up to the total number of blocks minus one. Block zero is the boot block and is usually only accessed during special operations.

Now, the problem with blocks is that if we have a file that is not an integral number of blocks, space at the end of the last block is wasted. On average, one half block is wasted per file. On most file systems this means a lot of wasted space.

To circumvent this inconvenience, the file system uses fragments. The fragment size must be the physical block size multiplied by a power of two (3). A file is therefore a sequence of blocks followed by a small sequence of consecutive fragments. When a file has enough ending fragments to fill a block, those fragments are grouped into a block. When a file is shortened, the last block may be broken into many contiguous fragments.

The general relationship between sizes is:

Go to the previous, next section.