if (i == cgp->cg_nclusterblks)
if (i >= cgp->cg_nclusterblks)
ffs_clusteralloc(ip, cg, bpref, len)	struct inode *ip;	int cg;	daddr_t bpref;	int len;{	register struct fs *fs;	register struct cg *cgp;	struct buf *bp;	int i, run, bno, bit, map;	u_char *mapp;	int32_t *lp;	fs = ip->i_fs;	if (fs->fs_maxcluster[cg] < len)		return (NULL);	if (bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize,	    NOCRED, &bp))		goto fail;	cgp = (struct cg *)bp->b_data;	if (!cg_chkmagic(cgp))		goto fail;	/*	 * Check to see if a cluster of the needed size (or bigger) is	 * available in this cylinder group.	 */	lp = &cg_clustersum(cgp)[len];	for (i = len; i <= fs->fs_contigsumsize; i++)		if (*lp++ > 0)			break;	if (i > fs->fs_contigsumsize) {		/*		 * This is the first time looking for a cluster in this		 * cylinder group. Update the cluster summary information		 * to reflect the true maximum sized cluster so that		 * future cluster allocation requests can avoid reading		 * the cylinder group map only to find no clusters.		 */		lp = &cg_clustersum(cgp)[len - 1];		for (i = len - 1; i > 0; i--)			if (*lp-- > 0)				break;		fs->fs_maxcluster[cg] = i;		goto fail;	}	/*	 * Search the cluster map to find a big enough cluster.	 * We take the first one that we find, even if it is larger	 * than we need as we prefer to get one close to the previous	 * block allocation. We do not search before the current	 * preference point as we do not want to allocate a block	 * that is allocated before the previous one (as we will	 * then have to wait for another pass of the elevator	 * algorithm before it will be read). We prefer to fail and	 * be recalled to try an allocation in the next cylinder group.	 */	if (dtog(fs, bpref) != cg)		bpref = 0;	else		bpref = fragstoblks(fs, dtogd(fs, blknum(fs, bpref)));	mapp = &cg_clustersfree(cgp)[bpref / NBBY];	map = *mapp++;	bit = 1 << (bpref % NBBY);	for (run = 0, i = bpref; i < cgp->cg_nclusterblks; i++) {		if ((map & bit) == 0) {			run = 0;		} else {			run++;			if (run == len)				break;		}		if ((i & (NBBY - 1)) != (NBBY - 1)) {			bit <<= 1;		} else {			map = *mapp++;			bit = 1;		}	}	if (i == cgp->cg_nclusterblks)		goto fail;	/*	 * Allocate the cluster that we have found.	 */	bno = cg * fs->fs_fpg + blkstofrags(fs, i - run + 1);	len = blkstofrags(fs, len);	for (i = 0; i < len; i += fs->fs_frag)		if (ffs_alloccgblk(fs, cgp, bno + i) != bno + i)			panic("ffs_clusteralloc: lost block");	bdwrite(bp);	return (bno);fail:	brelse(bp);	return (0);}