Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 9: The Extended Filesystem Family


Whilekeyindicates the block number,pis a pointer to the address in memory where the key resides. A
buffer head (bh) is used to keep the block data in memory.

In the case of a fully filledIndirectinstance, the information on the block number is stored redundantly
inkeyand in*p. This again becomes clear when we examine the auxiliary function to fillIndirect:

fs/ext2/inode.c
static inline void add_chain(Indirect *p, struct buffer_head *bh, u32 *v)
{
p->key = *(p->p = v);
p->bh = bh;
}

If, when traversing the block path,ext2_get_branchdetects that there is no pointer to the next indirec-
tion level (or to a data block if direct allocation is used), an incompleteIndirectinstance is returned.
Although thepelement points to the position where the number of the next indirection or data block
should be located in the indirection block, the number itself is 0 because the block has not yet been
allocated.

Figure 9-11 illustrates this fact graphically. The fourth data block to be addressed by the simple indirec-
tion block is not present but should be used. The returnedIndirectinstance contains a pointer to the
position in the indirection block where the block number must be inserted (namely, 1,003 because the
indirection block starts at the address 1,000 and the fourth element is of interest). However, the value of
the key is 0 because the associated data block has not yet been allocated.

Direct
pointers

0x1000

Indirect = <p=0x1003, key=0, bh=NULL>

0x1234
0x7f3c
0x9831
0x0
0x0
0x0

Figure 9-11: Return ofext2_get_branch.

Now that the position in the indirection chain in whichno further blocks are allocated is clear, the Second
Extended Filesystem must find out where there is space in the partition to add one or more new blocks to
the file. This is not a trivial task because ideally the blocks of a file should be contiguous or, if this is not
feasible, at least as close together as possible. This ensures that fragmentation is minimized and results
not only in better utilization of hard disk capacity but in faster read/write operations because read/write
head travel is reduced.
Free download pdf