FreeBSD/sys/fs/ext2fs/ext2_alloc.c
/*
 * Free a block or fragment.
 *
 */
Free a block or fragment.
Free a block or fragment .
void
ext2_blkfree(struct inode *ip, e4fs_daddr_t bno, long size)
{
	struct m_ext2fs *fs;
	struct buf *bp;
	struct ext2mount *ump;
	int cg, error;
	char *bbp;
	fs = ip->i_e2fs;
	ump = ip->i_ump;
	cg = dtog(fs, bno);
	if ((u_int)bno >= fs->e2fs->e2fs_bcount) {
		printf("bad block %lld, ino %ju\n", (long long)bno,
		    (uintmax_t)ip->i_number);
		ext2_fserr(fs, ip->i_uid, "bad block");
		return;
	}
	error = bread(ip->i_devvp,
		fsbtodb(fs, fs->e2fs_gd[cg].ext2bgd_b_bitmap),
		(int)fs->e2fs_bsize, NOCRED, &bp);
	if (error) {
		brelse(bp);
		return;
	}
	bbp = (char *)bp->b_data;
	bno = dtogd(fs, bno);
	if (isclr(bbp, bno)) {
		printf("block = %lld, fs = %s\n",
		     (long long)bno, fs->e2fs_fsmnt);
		panic("ext2_blkfree: freeing free block");
	}
	clrbit(bbp, bno);
	EXT2_LOCK(ump);
	ext2_clusteracct(fs, bbp, cg, bno, 1);
	fs->e2fs->e2fs_fbcount++;
	fs->e2fs_gd[cg].ext2bgd_nbfree++;
	fs->e2fs_fmod = 1;
	EXT2_UNLOCK(ump);
	bdwrite(bp);
}
void ext2_blkfree ( struct inode * ip , e4fs_daddr_t bno , long size ) { struct m_ext2fs * fs ; struct buf * bp ; struct ext2mount * ump ; int cg , error ; char * bbp ; fs = ip -> i_e2fs ; ump = ip -> i_ump ; cg = dtog ( fs , bno ) ; if ( ( u_int ) bno >= fs -> e2fs -> e2fs_bcount ) { printf ( " \n " , ( long long ) bno , ( uintmax_t ) ip -> i_number ) ; ext2_fserr ( fs , ip -> i_uid , " " ) ; return ; } error = bread ( ip -> i_devvp , fsbtodb ( fs , fs -> e2fs_gd [ cg ] . ext2bgd_b_bitmap ) , ( int ) fs -> e2fs_bsize , NOCRED , & bp ) ; if ( error ) { brelse ( bp ) ; return ; } bbp = ( char * ) bp -> b_data ; bno = dtogd ( fs , bno ) ; if ( isclr ( bbp , bno ) ) { printf ( " \n " , ( long long ) bno , fs -> e2fs_fsmnt ) ; panic ( " " ) ; } clrbit ( bbp , bno ) ; EXT2_LOCK ( ump ) ; ext2_clusteracct ( fs , bbp , cg , bno , 1 ) ; fs -> e2fs -> e2fs_fbcount ++ ; fs -> e2fs_gd [ cg ] . ext2bgd_nbfree ++ ; fs -> e2fs_fmod = 1 ; EXT2_UNLOCK ( ump ) ; bdwrite ( bp ) ; }
Free a block or fragment.
Free a block or fragment .