kernels/linux-2.4.0/fs/minix/namei.c
/*
 * Anybody can rename anything with this: the permission checks are left to the
 * higher-level routines.
 */
Anybody can rename anything with this: the permission checks are left to the
higher-level routines.
Anybody can rename anything with this : the permission checks are left to the higher - level routines .
static int minix_rename(struct inode * old_dir, struct dentry *old_dentry,
			   struct inode * new_dir, struct dentry *new_dentry)
{
	struct inode * old_inode, * new_inode;
	struct buffer_head * old_bh, * new_bh, * dir_bh;
	struct minix_dir_entry * old_de, * new_de;
	struct minix_sb_info * info;
	int retval;
	info = &old_dir->i_sb->u.minix_sb;
	new_bh = dir_bh = NULL;
	old_inode = old_dentry->d_inode;
	new_inode = new_dentry->d_inode;
	old_bh = minix_find_entry(old_dir, old_dentry->d_name.name,
				  old_dentry->d_name.len, &old_de);
	retval = -ENOENT;
	if (!old_bh || old_de->inode != old_inode->i_ino)
		goto end_rename;
	retval = -EPERM;
	new_bh = minix_find_entry(new_dir, new_dentry->d_name.name,
				  new_dentry->d_name.len, &new_de);
	if (new_bh) {
		if (!new_inode) {
			brelse(new_bh);
			new_bh = NULL;
		}
	}
	if (S_ISDIR(old_inode->i_mode)) {
		if (new_inode) {
			retval = -ENOTEMPTY;
			if (!empty_dir(new_inode))
				goto end_rename;
		}
		retval = -EIO;
		dir_bh = minix_bread(old_inode,0,0);
		if (!dir_bh)
			goto end_rename;
		if (PARENT_INO(dir_bh->b_data) != old_dir->i_ino)
			goto end_rename;
		retval = -EMLINK;
		if (!new_inode && new_dir != old_dir &&
				new_dir->i_nlink >= info->s_link_max)
			goto end_rename;
	}
	if (!new_bh) {
		retval = minix_add_entry(new_dir,
					 new_dentry->d_name.name,
					 new_dentry->d_name.len,
					 &new_bh, &new_de);
		if (retval)
			goto end_rename;
	}
	new_de->inode = old_inode->i_ino;
	old_de->inode = 0;
	old_dir->i_ctime = old_dir->i_mtime = CURRENT_TIME;
	old_dir->i_version = ++event;
	mark_inode_dirty(old_dir);
	new_dir->i_ctime = new_dir->i_mtime = CURRENT_TIME;
	new_dir->i_version = ++event;
	mark_inode_dirty(new_dir);
	if (new_inode) {
		new_inode->i_nlink--;
		new_inode->i_ctime = CURRENT_TIME;
		mark_inode_dirty(new_inode);
	}
	mark_buffer_dirty(old_bh);
	mark_buffer_dirty(new_bh);
	if (dir_bh) {
		PARENT_INO(dir_bh->b_data) = new_dir->i_ino;
		mark_buffer_dirty(dir_bh);
		old_dir->i_nlink--;
		mark_inode_dirty(old_dir);
		if (new_inode) {
			new_inode->i_nlink--;
			mark_inode_dirty(new_inode);
		} else {
			new_dir->i_nlink++;
			mark_inode_dirty(new_dir);
		}
	}
	retval = 0;
end_rename:
	brelse(dir_bh);
	brelse(old_bh);
	brelse(new_bh);
	return retval;
}
static int minix_rename ( struct inode * old_dir , struct dentry * old_dentry , struct inode * new_dir , struct dentry * new_dentry ) { struct inode * old_inode , * new_inode ; struct buffer_head * old_bh , * new_bh , * dir_bh ; struct minix_dir_entry * old_de , * new_de ; struct minix_sb_info * info ; int retval ; info = & old_dir -> i_sb -> u . minix_sb ; new_bh = dir_bh = NULL ; old_inode = old_dentry -> d_inode ; new_inode = new_dentry -> d_inode ; old_bh = minix_find_entry ( old_dir , old_dentry -> d_name . name , old_dentry -> d_name . len , & old_de ) ; retval = - ENOENT ; if ( ! old_bh || old_de -> inode != old_inode -> i_ino ) goto end_rename ; retval = - EPERM ; new_bh = minix_find_entry ( new_dir , new_dentry -> d_name . name , new_dentry -> d_name . len , & new_de ) ; if ( new_bh ) { if ( ! new_inode ) { brelse ( new_bh ) ; new_bh = NULL ; } } if ( S_ISDIR ( old_inode -> i_mode ) ) { if ( new_inode ) { retval = - ENOTEMPTY ; if ( ! empty_dir ( new_inode ) ) goto end_rename ; } retval = - EIO ; dir_bh = minix_bread ( old_inode , 0 , 0 ) ; if ( ! dir_bh ) goto end_rename ; if ( PARENT_INO ( dir_bh -> b_data ) != old_dir -> i_ino ) goto end_rename ; retval = - EMLINK ; if ( ! new_inode && new_dir != old_dir && new_dir -> i_nlink >= info -> s_link_max ) goto end_rename ; } if ( ! new_bh ) { retval = minix_add_entry ( new_dir , new_dentry -> d_name . name , new_dentry -> d_name . len , & new_bh , & new_de ) ; if ( retval ) goto end_rename ; } new_de -> inode = old_inode -> i_ino ; old_de -> inode = 0 ; old_dir -> i_ctime = old_dir -> i_mtime = CURRENT_TIME ; old_dir -> i_version = ++ event ; mark_inode_dirty ( old_dir ) ; new_dir -> i_ctime = new_dir -> i_mtime = CURRENT_TIME ; new_dir -> i_version = ++ event ; mark_inode_dirty ( new_dir ) ; if ( new_inode ) { new_inode -> i_nlink -- ; new_inode -> i_ctime = CURRENT_TIME ; mark_inode_dirty ( new_inode ) ; } mark_buffer_dirty ( old_bh ) ; mark_buffer_dirty ( new_bh ) ; if ( dir_bh ) { PARENT_INO ( dir_bh -> b_data ) = new_dir -> i_ino ; mark_buffer_dirty ( dir_bh ) ; old_dir -> i_nlink -- ; mark_inode_dirty ( old_dir ) ; if ( new_inode ) { new_inode -> i_nlink -- ; mark_inode_dirty ( new_inode ) ; } else { new_dir -> i_nlink ++ ; mark_inode_dirty ( new_dir ) ; } } retval = 0 ; end_rename : brelse ( dir_bh ) ; brelse ( old_bh ) ; brelse ( new_bh ) ; return retval ; }
Anybody can rename anything with this: the permission checks are left to the
 higher-level routines.
Anybody can rename anything with this : the permission checks are left to the higher - level routines .
/* ok, that's it */