kernels/linux-2.4.0/fs/affs/bitmap.c
/* Allocate a new data block. */
Allocate a new data block.
Allocate a new data block .
s32
affs_new_data(struct inode *inode)
{
	int			 empty, old;
	unsigned long		 oldest;
	struct affs_zone	*zone;
	struct super_block	*sb;
	int			 i = 0;
	s32			 block;
	pr_debug("AFFS: new_data(ino=%lu)\n",inode->i_ino);
	sb = inode->i_sb;
	lock_super(sb);
	if (inode->u.affs_i.i_pa_cnt) {
		inode->u.affs_i.i_pa_cnt--;
		unlock_super(sb);
		block = inode->u.affs_i.i_data[inode->u.affs_i.i_pa_next++];
		inode->u.affs_i.i_pa_next &= AFFS_MAX_PREALLOC - 1;
		return block;
	}
	unlock_super(sb);
	oldest = jiffies;
	old    = 0;
	empty  = 0;
	zone   = &sb->u.affs_sb.s_zones[inode->u.affs_i.i_zone];
	if (zone->z_ino == inode->i_ino) {
		i = inode->u.affs_i.i_zone;
		goto found;
	}
	for (i = 1; i < MAX_ZONES; i++) {
		zone = &sb->u.affs_sb.s_zones[i];
		if (!empty && zone->z_bm && !zone->z_ino)
			empty = i;
		if (zone->z_bm && zone->z_lru_time < oldest) {
			old    = i;
			oldest = zone->z_lru_time;
		}
	}
	if (empty)
		i = empty;
	else if (old)
		i = old;
	else {
		inode->u.affs_i.i_zone = 0;
		return affs_new_header(inode);
	}
	inode->u.affs_i.i_zone = i;
	zone->z_ino            = inode->i_ino;
found:
	zone = &sb->u.affs_sb.s_zones[i];
	if (!(block = affs_balloc(inode,i))) {		
		while (affs_find_new_zone(sb,i)) {
			if ((block = affs_balloc(inode,i)))
				return block;
			schedule();
		}
		inode->u.affs_i.i_zone = 0;
		zone->z_ino            = -1;
		return 0;
	}
	return block;
}
s32 affs_new_data ( struct inode * inode ) { int empty , old ; unsigned long oldest ; struct affs_zone * zone ; struct super_block * sb ; int i = 0 ; s32 block ; pr_debug ( " \n " , inode -> i_ino ) ; sb = inode -> i_sb ; lock_super ( sb ) ; if ( inode -> u . affs_i . i_pa_cnt ) { inode -> u . affs_i . i_pa_cnt -- ; unlock_super ( sb ) ; block = inode -> u . affs_i . i_data [ inode -> u . affs_i . i_pa_next ++ ] ; inode -> u . affs_i . i_pa_next &= AFFS_MAX_PREALLOC - 1 ; return block ; } unlock_super ( sb ) ; oldest = jiffies ; old = 0 ; empty = 0 ; zone = & sb -> u . affs_sb . s_zones [ inode -> u . affs_i . i_zone ] ; if ( zone -> z_ino == inode -> i_ino ) { i = inode -> u . affs_i . i_zone ; goto found ; } for ( i = 1 ; i < MAX_ZONES ; i ++ ) { zone = & sb -> u . affs_sb . s_zones [ i ] ; if ( ! empty && zone -> z_bm && ! zone -> z_ino ) empty = i ; if ( zone -> z_bm && zone -> z_lru_time < oldest ) { old = i ; oldest = zone -> z_lru_time ; } } if ( empty ) i = empty ; else if ( old ) i = old ; else { inode -> u . affs_i . i_zone = 0 ; return affs_new_header ( inode ) ; } inode -> u . affs_i . i_zone = i ; zone -> z_ino = inode -> i_ino ; found : zone = & sb -> u . affs_sb . s_zones [ i ] ; if ( ! ( block = affs_balloc ( inode , i ) ) ) { while ( affs_find_new_zone ( sb , i ) ) { if ( ( block = affs_balloc ( inode , i ) ) ) return block ; schedule ( ) ; } inode -> u . affs_i . i_zone = 0 ; zone -> z_ino = -1 ; return 0 ; } return block ; }
Allocate a new data block.
Allocate a new data block .
/* No data zones left */