FreeBSD/sys/fs/ext2fs/ext2_alloc.c
/*
 * Select the desired position for the next block in a file.  
 *
 * we try to mimic what Remy does in inode_getblk/block_getblk
 *
 * we note: blocknr == 0 means that we're about to allocate either
 * a direct block or a pointer block at the first level of indirection
 * (In other words, stuff that will go in i_db[] or i_ib[])
 *
 * blocknr != 0 means that we're allocating a block that is none
 * of the above. Then, blocknr tells us the number of the block
 * that will hold the pointer
 */
Select the desired position for the next block in a file.
we try to mimic what Remy does in inode_getblk/block_getblk

we note: blocknr == 0 means that we're about to allocate either
a direct block or a pointer block at the first level of indirection
(In other words, stuff that will go in i_db[] or i_ib[])

blocknr != 0 means that we're allocating a block that is none
of the above. Then, blocknr tells us the number of the block
that will hold the pointer
Select the desired position for the next block in a file . we try to mimic what Remy does in inode_getblk / block_getblk we note : blocknr == 0 means that we ' re about to allocate either a direct block or a pointer block at the first level of indirection ( In other words stuff that will go in i_db [] or i_ib [] ) blocknr ! = 0 means that we ' re allocating a block that is none of the above . Then blocknr tells us the number of the block that will hold the pointer
e4fs_daddr_t
ext2_blkpref(struct inode *ip, e2fs_lbn_t lbn, int indx, e2fs_daddr_t *bap,
    e2fs_daddr_t blocknr)
{
	int	tmp;
	mtx_assert(EXT2_MTX(ip->i_ump), MA_OWNED);
	if (ip->i_next_alloc_block == lbn && ip->i_next_alloc_goal != 0)
		return ip->i_next_alloc_goal;
	if (bap)
		for (tmp = indx - 1; tmp >= 0; tmp--) 
			if (bap[tmp]) 
				return bap[tmp];
	return blocknr ? blocknr :
			(e2fs_daddr_t)(ip->i_block_group * 
			EXT2_BLOCKS_PER_GROUP(ip->i_e2fs)) + 
			ip->i_e2fs->e2fs->e2fs_first_dblock;
}
e4fs_daddr_t ext2_blkpref ( struct inode * ip , e2fs_lbn_t lbn , int indx , e2fs_daddr_t * bap , e2fs_daddr_t blocknr ) { int tmp ; mtx_assert ( EXT2_MTX ( ip -> i_ump ) , MA_OWNED ) ; if ( ip -> i_next_alloc_block == lbn && ip -> i_next_alloc_goal != 0 ) return ip -> i_next_alloc_goal ; if ( bap ) for ( tmp = indx - 1 ; tmp >= 0 ; tmp -- ) if ( bap [ tmp ] ) return bap [ tmp ] ; return blocknr ? blocknr : ( e2fs_daddr_t ) ( ip -> i_block_group * EXT2_BLOCKS_PER_GROUP ( ip -> i_e2fs ) ) + ip -> i_e2fs -> e2fs -> e2fs_first_dblock ; }
Select the desired position for the next block in a file.
Select the desired position for the next block in a file .
/* if the next block is actually what we thought it is,
	   then set the goal to what we thought it should be
	*/ /* now check whether we were provided with an array that basically
	   tells us previous blocks to which we want to stay closeby
	*/ /* else let's fall back to the blocknr, or, if there is none,
	   follow the rule that a block should be allocated near its inode
	*/