kernels/linux-2.4.0/fs/minix/namei.c
/*
 * routine to check that the specified directory is empty (for rmdir)
 */
routine to check that the specified directory is empty (for rmdir)
routine to check that the specified directory is empty ( for rmdir )
static int empty_dir(struct inode * inode)
{
	unsigned int block, offset;
	struct buffer_head * bh;
	struct minix_dir_entry * de;
	struct minix_sb_info * info;
	info = &inode->i_sb->u.minix_sb;
	block = 0;
	bh = NULL;
	offset = 2*info->s_dirsize;
	if (inode->i_size & (info->s_dirsize-1))
		goto bad_dir;
	if (inode->i_size < offset)
		goto bad_dir;
	bh = minix_bread(inode,0,0);
	if (!bh)
		goto bad_dir;
	de = (struct minix_dir_entry *) bh->b_data;
	if (!de->inode || strcmp(de->name,"."))
		goto bad_dir;
	de = (struct minix_dir_entry *) (bh->b_data + info->s_dirsize);
	if (!de->inode || strcmp(de->name,".."))
		goto bad_dir;
	while (block*BLOCK_SIZE+offset < inode->i_size) {
		if (!bh) {
			bh = minix_bread(inode,block,0);
			if (!bh) {
				block++;
				continue;
			}
		}
		de = (struct minix_dir_entry *) (bh->b_data + offset);
		offset += info->s_dirsize;
		if (de->inode) {
			brelse(bh);
			return 0;
		}
		if (offset < bh->b_size)
			continue;
		brelse(bh);
		bh = NULL;
		offset = 0;
		block++;
	}
	brelse(bh);
	return 1;
bad_dir:
	brelse(bh);
	printk("Bad directory on device %s\n",
	       kdevname(inode->i_dev));
	return 1;
}
static int empty_dir ( struct inode * inode ) { unsigned int block , offset ; struct buffer_head * bh ; struct minix_dir_entry * de ; struct minix_sb_info * info ; info = & inode -> i_sb -> u . minix_sb ; block = 0 ; bh = NULL ; offset = 2 * info -> s_dirsize ; if ( inode -> i_size & ( info -> s_dirsize - 1 ) ) goto bad_dir ; if ( inode -> i_size < offset ) goto bad_dir ; bh = minix_bread ( inode , 0 , 0 ) ; if ( ! bh ) goto bad_dir ; de = ( struct minix_dir_entry * ) bh -> b_data ; if ( ! de -> inode || strcmp ( de -> name , " " ) ) goto bad_dir ; de = ( struct minix_dir_entry * ) ( bh -> b_data + info -> s_dirsize ) ; if ( ! de -> inode || strcmp ( de -> name , " " ) ) goto bad_dir ; while ( block * BLOCK_SIZE + offset < inode -> i_size ) { if ( ! bh ) { bh = minix_bread ( inode , block , 0 ) ; if ( ! bh ) { block ++ ; continue ; } } de = ( struct minix_dir_entry * ) ( bh -> b_data + offset ) ; offset += info -> s_dirsize ; if ( de -> inode ) { brelse ( bh ) ; return 0 ; } if ( offset < bh -> b_size ) continue ; brelse ( bh ) ; bh = NULL ; offset = 0 ; block ++ ; } brelse ( bh ) ; return 1 ; bad_dir : brelse ( bh ) ; printk ( " \n " , kdevname ( inode -> i_dev ) ) ; return 1 ; }
routine to check that the specified directory is empty (for rmdir)
routine to check that the specified directory is empty ( for rmdir )