Skip to content

Commit 6b46576

Browse files
Fabian FrederickAl Viro
authored andcommitted
fs/affs: add rename exchange
Process RENAME_EXCHANGE in affs_rename2() adding static affs_xrename() based on affs_rename(). We remove headers from respective directories then affect bh to other inode directory entries for swapping. Signed-off-by: Fabian Frederick <fabf@skynet.be> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent c618402 commit 6b46576

1 file changed

Lines changed: 57 additions & 1 deletion

File tree

‎fs/affs/namei.c‎

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,17 +441,73 @@ affs_rename(struct inode *old_dir, struct dentry *old_dentry,
441441
return retval;
442442
}
443443

444+
static int
445+
affs_xrename(struct inode *old_dir, struct dentry *old_dentry,
446+
struct inode *new_dir, struct dentry *new_dentry)
447+
{
448+
449+
struct super_block *sb = old_dir->i_sb;
450+
struct buffer_head *bh_old = NULL;
451+
struct buffer_head *bh_new = NULL;
452+
int retval;
453+
454+
bh_old = affs_bread(sb, d_inode(old_dentry)->i_ino);
455+
if (!bh_old)
456+
return -EIO;
457+
458+
bh_new = affs_bread(sb, d_inode(new_dentry)->i_ino);
459+
if (!bh_new)
460+
return -EIO;
461+
462+
/* Remove old header from its parent directory. */
463+
affs_lock_dir(old_dir);
464+
retval = affs_remove_hash(old_dir, bh_old);
465+
affs_unlock_dir(old_dir);
466+
if (retval)
467+
goto done;
468+
469+
/* Remove new header from its parent directory. */
470+
affs_lock_dir(new_dir);
471+
retval = affs_remove_hash(new_dir, bh_new);
472+
affs_unlock_dir(new_dir);
473+
if (retval)
474+
goto done;
475+
476+
/* Insert old into the new directory with the new name. */
477+
affs_copy_name(AFFS_TAIL(sb, bh_old)->name, new_dentry);
478+
affs_fix_checksum(sb, bh_old);
479+
affs_lock_dir(new_dir);
480+
retval = affs_insert_hash(new_dir, bh_old);
481+
affs_unlock_dir(new_dir);
482+
483+
/* Insert new into the old directory with the old name. */
484+
affs_copy_name(AFFS_TAIL(sb, bh_new)->name, old_dentry);
485+
affs_fix_checksum(sb, bh_new);
486+
affs_lock_dir(old_dir);
487+
retval = affs_insert_hash(old_dir, bh_new);
488+
affs_unlock_dir(old_dir);
489+
done:
490+
mark_buffer_dirty_inode(bh_old, new_dir);
491+
mark_buffer_dirty_inode(bh_new, old_dir);
492+
affs_brelse(bh_old);
493+
affs_brelse(bh_new);
494+
return retval;
495+
}
496+
444497
int affs_rename2(struct inode *old_dir, struct dentry *old_dentry,
445498
struct inode *new_dir, struct dentry *new_dentry,
446499
unsigned int flags)
447500
{
448501

449-
if (flags & ~RENAME_NOREPLACE)
502+
if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE))
450503
return -EINVAL;
451504

452505
pr_debug("%s(old=%lu,\"%pd\" to new=%lu,\"%pd\")\n", __func__,
453506
old_dir->i_ino, old_dentry, new_dir->i_ino, new_dentry);
454507

508+
if (flags & RENAME_EXCHANGE)
509+
return affs_xrename(old_dir, old_dentry, new_dir, new_dentry);
510+
455511
return affs_rename(old_dir, old_dentry, new_dir, new_dentry);
456512
}
457513

0 commit comments

Comments
 (0)