kernels/linux-2.4.0/fs/ext2/ialloc.c
/*
 * load_inode_bitmap loads the inode bitmap for a blocks group
 *
 * It maintains a cache for the last bitmaps loaded.  This cache is managed
 * with a LRU algorithm.
 *
 * Notes:
 * 1/ There is one cache per mounted file system.
 * 2/ If the file system contains less than EXT2_MAX_GROUP_LOADED groups,
 *    this function reads the bitmap without maintaining a LRU cache.
 * 
 * Return the slot used to store the bitmap, or a -ve error code.
 */
load_inode_bitmap loads the inode bitmap for a blocks group
It maintains a cache for the last bitmaps loaded.  This cache is managed
with a LRU algorithm.

1/ There is one cache per mounted file system.
2/ If the file system contains less than EXT2_MAX_GROUP_LOADED groups,
this function reads the bitmap without maintaining a LRU cache.

Return the slot used to store the bitmap, or a -ve error code.
load_inode_bitmap loads the inode bitmap for a blocks group It maintains a cache for the last bitmaps loaded . This cache is managed with a LRU algorithm . 1 / There is one cache per mounted file system . 2 / If the file system contains less than EXT2_MAX_GROUP_LOADED groups this function reads the bitmap without maintaining a LRU cache . Return the slot used to store the bitmap or a - ve error code .
static int load_inode_bitmap (struct super_block * sb,
			      unsigned int block_group)
{
	int i, j, retval = 0;
	unsigned long inode_bitmap_number;
	struct buffer_head * inode_bitmap;
	if (block_group >= sb->u.ext2_sb.s_groups_count)
		ext2_panic (sb, "load_inode_bitmap",
			    "block_group >= groups_count - "
			    "block_group = %d, groups_count = %lu",
			     block_group, sb->u.ext2_sb.s_groups_count);
	if (sb->u.ext2_sb.s_loaded_inode_bitmaps > 0 &&
	    sb->u.ext2_sb.s_inode_bitmap_number[0] == block_group &&
	    sb->u.ext2_sb.s_inode_bitmap[0] != NULL)
		return 0;
	if (sb->u.ext2_sb.s_groups_count <= EXT2_MAX_GROUP_LOADED) {
		if (sb->u.ext2_sb.s_inode_bitmap[block_group]) {
			if (sb->u.ext2_sb.s_inode_bitmap_number[block_group] != block_group)
				ext2_panic (sb, "load_inode_bitmap",
					    "block_group != inode_bitmap_number");
			else
				return block_group;
		} else {
			retval = read_inode_bitmap (sb, block_group,
						    block_group);
			if (retval < 0)
				return retval;
			return block_group;
		}
	}
	for (i = 0; i < sb->u.ext2_sb.s_loaded_inode_bitmaps &&
		    sb->u.ext2_sb.s_inode_bitmap_number[i] != block_group;
	     i++)
		;
	if (i < sb->u.ext2_sb.s_loaded_inode_bitmaps &&
  	    sb->u.ext2_sb.s_inode_bitmap_number[i] == block_group) {
		inode_bitmap_number = sb->u.ext2_sb.s_inode_bitmap_number[i];
		inode_bitmap = sb->u.ext2_sb.s_inode_bitmap[i];
		for (j = i; j > 0; j--) {
			sb->u.ext2_sb.s_inode_bitmap_number[j] =
				sb->u.ext2_sb.s_inode_bitmap_number[j - 1];
			sb->u.ext2_sb.s_inode_bitmap[j] =
				sb->u.ext2_sb.s_inode_bitmap[j - 1];
		}
		sb->u.ext2_sb.s_inode_bitmap_number[0] = inode_bitmap_number;
		sb->u.ext2_sb.s_inode_bitmap[0] = inode_bitmap;
		if (!inode_bitmap)
			retval = read_inode_bitmap (sb, block_group, 0);
	} else {
		if (sb->u.ext2_sb.s_loaded_inode_bitmaps < EXT2_MAX_GROUP_LOADED)
			sb->u.ext2_sb.s_loaded_inode_bitmaps++;
		else
			brelse (sb->u.ext2_sb.s_inode_bitmap[EXT2_MAX_GROUP_LOADED - 1]);
		for (j = sb->u.ext2_sb.s_loaded_inode_bitmaps - 1; j > 0; j--) {
			sb->u.ext2_sb.s_inode_bitmap_number[j] =
				sb->u.ext2_sb.s_inode_bitmap_number[j - 1];
			sb->u.ext2_sb.s_inode_bitmap[j] =
				sb->u.ext2_sb.s_inode_bitmap[j - 1];
		}
		retval = read_inode_bitmap (sb, block_group, 0);
	}
	return retval;
}
static int load_inode_bitmap ( struct super_block * sb , unsigned int block_group ) { int i , j , retval = 0 ; unsigned long inode_bitmap_number ; struct buffer_head * inode_bitmap ; if ( block_group >= sb -> u . ext2_sb . s_groups_count ) ext2_panic ( sb , " " , " " " " , block_group , sb -> u . ext2_sb . s_groups_count ) ; if ( sb -> u . ext2_sb . s_loaded_inode_bitmaps > 0 && sb -> u . ext2_sb . s_inode_bitmap_number [ 0 ] == block_group && sb -> u . ext2_sb . s_inode_bitmap [ 0 ] != NULL ) return 0 ; if ( sb -> u . ext2_sb . s_groups_count <= EXT2_MAX_GROUP_LOADED ) { if ( sb -> u . ext2_sb . s_inode_bitmap [ block_group ] ) { if ( sb -> u . ext2_sb . s_inode_bitmap_number [ block_group ] != block_group ) ext2_panic ( sb , " " , " " ) ; else return block_group ; } else { retval = read_inode_bitmap ( sb , block_group , block_group ) ; if ( retval < 0 ) return retval ; return block_group ; } } for ( i = 0 ; i < sb -> u . ext2_sb . s_loaded_inode_bitmaps && sb -> u . ext2_sb . s_inode_bitmap_number [ i ] != block_group ; i ++ ) ; if ( i < sb -> u . ext2_sb . s_loaded_inode_bitmaps && sb -> u . ext2_sb . s_inode_bitmap_number [ i ] == block_group ) { inode_bitmap_number = sb -> u . ext2_sb . s_inode_bitmap_number [ i ] ; inode_bitmap = sb -> u . ext2_sb . s_inode_bitmap [ i ] ; for ( j = i ; j > 0 ; j -- ) { sb -> u . ext2_sb . s_inode_bitmap_number [ j ] = sb -> u . ext2_sb . s_inode_bitmap_number [ j - 1 ] ; sb -> u . ext2_sb . s_inode_bitmap [ j ] = sb -> u . ext2_sb . s_inode_bitmap [ j - 1 ] ; } sb -> u . ext2_sb . s_inode_bitmap_number [ 0 ] = inode_bitmap_number ; sb -> u . ext2_sb . s_inode_bitmap [ 0 ] = inode_bitmap ; if ( ! inode_bitmap ) retval = read_inode_bitmap ( sb , block_group , 0 ) ; } else { if ( sb -> u . ext2_sb . s_loaded_inode_bitmaps < EXT2_MAX_GROUP_LOADED ) sb -> u . ext2_sb . s_loaded_inode_bitmaps ++ ; else brelse ( sb -> u . ext2_sb . s_inode_bitmap [ EXT2_MAX_GROUP_LOADED - 1 ] ) ; for ( j = sb -> u . ext2_sb . s_loaded_inode_bitmaps - 1 ; j > 0 ; j -- ) { sb -> u . ext2_sb . s_inode_bitmap_number [ j ] = sb -> u . ext2_sb . s_inode_bitmap_number [ j - 1 ] ; sb -> u . ext2_sb . s_inode_bitmap [ j ] = sb -> u . ext2_sb . s_inode_bitmap [ j - 1 ] ; } retval = read_inode_bitmap ( sb , block_group , 0 ) ; } return retval ; }
load_inode_bitmap loads the inode bitmap for a blocks group
 It maintains a cache for the last bitmaps loaded.
load_inode_bitmap loads the inode bitmap for a blocks group It maintains a cache for the last bitmaps loaded .
/*
		 * There's still one special case here --- if inode_bitmap == 0
		 * then our last attempt to read the bitmap failed and we have
		 * just ended up caching that failure.  Try again to read it.
		 */