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:
parent
810c1b2e48
commit
69102e9b4b
1 changed files with 14 additions and 38 deletions
52
fs/hfs/dir.c
52
fs/hfs/dir.c
|
@ -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.
|
||||||
|
*
|
||||||
|
* 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;
|
int res;
|
||||||
|
|
||||||
inode = dentry->d_inode;
|
if (S_ISDIR(inode->i_mode) && inode->i_size != 2)
|
||||||
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)
|
|
||||||
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,
|
||||||
|
|
||||||
/* 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 = {
|
||||||
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,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue