Commit 69102e9b authored by Al Viro's avatar Al Viro

hfs: fix rename() over non-empty directory

merge hfs_unlink() and hfs_rmdir(), while we are at it.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 810c1b2e
...@@ -238,46 +238,22 @@ static int hfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) ...@@ -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 * This serves as both unlink() and rmdir() in the inode_operations
* regular HFS directories. The purpose is to delete an existing * structure for regular HFS directories. The purpose is to delete
* file, given the inode for the parent directory and the name * an existing child, given the inode for the parent directory and
* (and its length) of the existing file. * the name (and its length) of the existing directory.
*/
static int hfs_unlink(struct inode *dir, struct dentry *dentry)
{
struct inode *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 * HFS does not have hardlinks, so both rmdir and unlink set the
* regular HFS directories. The purpose is to delete an existing * link count to 0. The only difference is the emptiness check.
* 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) static int hfs_remove(struct inode *dir, struct dentry *dentry)
{ {
struct inode *inode; struct inode *inode = dentry->d_inode;
int res; int res;
inode = dentry->d_inode; if (S_ISDIR(inode->i_mode) && inode->i_size != 2)
if (inode->i_size != 2)
return -ENOTEMPTY; return -ENOTEMPTY;
res = hfs_cat_delete(inode->i_ino, dir, &dentry->d_name); res = hfs_cat_delete(inode->i_ino, dir, &dentry->d_name);
if (res) if (res)
...@@ -307,7 +283,7 @@ static int hfs_rename(struct inode *old_dir, struct dentry *old_dentry, ...@@ -307,7 +283,7 @@ static int hfs_rename(struct inode *old_dir, struct dentry *old_dentry,
/* Unlink destination if it already exists */ /* Unlink destination if it already exists */
if (new_dentry->d_inode) { if (new_dentry->d_inode) {
res = hfs_unlink(new_dir, new_dentry); res = hfs_remove(new_dir, new_dentry);
if (res) if (res)
return res; return res;
} }
...@@ -332,9 +308,9 @@ const struct file_operations hfs_dir_operations = { ...@@ -332,9 +308,9 @@ const struct file_operations hfs_dir_operations = {
const struct inode_operations hfs_dir_inode_operations = { const struct inode_operations hfs_dir_inode_operations = {
.create = hfs_create, .create = hfs_create,
.lookup = hfs_lookup, .lookup = hfs_lookup,
.unlink = hfs_unlink, .unlink = hfs_remove,
.mkdir = hfs_mkdir, .mkdir = hfs_mkdir,
.rmdir = hfs_rmdir, .rmdir = hfs_remove,
.rename = hfs_rename, .rename = hfs_rename,
.setattr = hfs_inode_setattr, .setattr = hfs_inode_setattr,
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment