FreeBSD/sys/fs/ext2fs/ext2_alloc.c
/*
 * Implement the cylinder overflow algorithm.
 *
 * The policy implemented by this algorithm is:
 *   1) allocate the block in its requested cylinder group.
 *   2) quadradically rehash on the cylinder group number.
 *   3) brute force search for a free block.
 */
Implement the cylinder overflow algorithm.
The policy implemented by this algorithm is:
1) allocate the block in its requested cylinder group.
2) quadradically rehash on the cylinder group number.
3) brute force search for a free block.
Implement the cylinder overflow algorithm . The policy implemented by this algorithm is : 1 ) allocate the block in its requested cylinder group . 2 ) quadradically rehash on the cylinder group number . 3 ) brute force search for a free block .
static u_long
ext2_hashalloc(struct inode *ip, int cg, long pref, int size,
                daddr_t (*allocator)(struct inode *, int, daddr_t, int))
{
	struct m_ext2fs *fs;
	ino_t result;
	int i, icg = cg;
	mtx_assert(EXT2_MTX(ip->i_ump), MA_OWNED);
	fs = ip->i_e2fs;
	result = (*allocator)(ip, cg, pref, size);
	if (result)
		return (result);
	for (i = 1; i < fs->e2fs_gcount; i *= 2) {
		cg += i;
		if (cg >= fs->e2fs_gcount)
			cg -= fs->e2fs_gcount;
		result = (*allocator)(ip, cg, 0, size);
		if (result)
			return (result);
	}
	cg = (icg + 2) % fs->e2fs_gcount;
	for (i = 2; i < fs->e2fs_gcount; i++) {
		result = (*allocator)(ip, cg, 0, size);
		if (result)
			return (result);
		cg++;
		if (cg == fs->e2fs_gcount)
			cg = 0;
	}
	return (0);
}
static u_long ext2_hashalloc ( struct inode * ip , int cg , long pref , int size , daddr_t ( * allocator ) ( struct inode * , int , daddr_t , int ) ) { struct m_ext2fs * fs ; ino_t result ; int i , icg = cg ; mtx_assert ( EXT2_MTX ( ip -> i_ump ) , MA_OWNED ) ; fs = ip -> i_e2fs ; result = ( * allocator ) ( ip , cg , pref , size ) ; if ( result ) return ( result ) ; for ( i = 1 ; i < fs -> e2fs_gcount ; i *= 2 ) { cg += i ; if ( cg >= fs -> e2fs_gcount ) cg -= fs -> e2fs_gcount ; result = ( * allocator ) ( ip , cg , 0 , size ) ; if ( result ) return ( result ) ; } cg = ( icg + 2 ) % fs -> e2fs_gcount ; for ( i = 2 ; i < fs -> e2fs_gcount ; i ++ ) { result = ( * allocator ) ( ip , cg , 0 , size ) ; if ( result ) return ( result ) ; cg ++ ; if ( cg == fs -> e2fs_gcount ) cg = 0 ; } return ( 0 ) ; }
Implement the cylinder overflow algorithm.
Implement the cylinder overflow algorithm .
/*
	 * 1: preferred cylinder group
	 */ /*
	 * 2: quadratic rehash
	 */ /*
	 * 3: brute force search
	 * Note that we start at i == 2, since 0 was checked initially,
	 * and 1 is always checked in the quadratic rehash.
	 */