hfs: fix rename() over non-empty directory

merge hfs_unlink() and hfs_rmdir(), while we are at it.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro 2011-03-02 23:46:51 -05:00
parent 810c1b2e48
commit 69102e9b4b
1 changed files with 14 additions and 38 deletions

View File

@ -238,46 +238,22 @@ static int hfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
}
/*
* hfs_unlink()
* hfs_remove()
*
* This is the unlink() entry in the inode_operations structure for
* regular HFS directories. The purpose is to delete an existing
* file, given the inode for the parent directory and the name
* (and its length) of the existing file.
* This serves as both unlink() and rmdir() in the inode_operations
* structure for regular HFS directories. The purpose is to delete
* an existing child, given the inode for the parent directory and
* the name (and its length) of the existing directory.
*
* HFS does not have hardlinks, so both rmdir and unlink set the
* link count to 0. The only difference is the emptiness check.
*/
static int hfs_unlink(struct inode *dir, struct dentry *dentry)
static int hfs_remove(struct inode *dir, struct dentry *dentry)
{
struct inode *inode;
struct inode *inode = dentry->d_inode;
int res;
inode = dentry->d_inode;
res = hfs_cat_delete(inode->i_ino, dir, &dentry->d_name);
if (res)
return res;
drop_nlink(inode);
hfs_delete_inode(inode);
inode->i_ctime = CURRENT_TIME_SEC;
mark_inode_dirty(inode);
return res;
}
/*
* hfs_rmdir()
*
* This is the rmdir() entry in the inode_operations structure for
* regular HFS directories. The purpose is to delete an existing
* directory, given the inode for the parent directory and the name
* (and its length) of the existing directory.
*/
static int hfs_rmdir(struct inode *dir, struct dentry *dentry)
{
struct inode *inode;
int res;
inode = dentry->d_inode;
if (inode->i_size != 2)
if (S_ISDIR(inode->i_mode) && inode->i_size != 2)
return -ENOTEMPTY;
res = hfs_cat_delete(inode->i_ino, dir, &dentry->d_name);
if (res)
@ -307,7 +283,7 @@ static int hfs_rename(struct inode *old_dir, struct dentry *old_dentry,
/* Unlink destination if it already exists */
if (new_dentry->d_inode) {
res = hfs_unlink(new_dir, new_dentry);
res = hfs_remove(new_dir, new_dentry);
if (res)
return res;
}
@ -332,9 +308,9 @@ const struct file_operations hfs_dir_operations = {
const struct inode_operations hfs_dir_inode_operations = {
.create = hfs_create,
.lookup = hfs_lookup,
.unlink = hfs_unlink,
.unlink = hfs_remove,
.mkdir = hfs_mkdir,
.rmdir = hfs_rmdir,
.rmdir = hfs_remove,
.rename = hfs_rename,
.setattr = hfs_inode_setattr,
};