Skip to content
/ linux Public
forked from torvalds/linux

Commit

Permalink
fs: support RENAME_NOREPLACE for local filesystems
Browse files Browse the repository at this point in the history
This is trivial to do:

 - add flags argument to foo_rename()
 - check if flags doesn't have any other than RENAME_NOREPLACE
 - assign foo_rename() to .rename2 instead of .rename

Filesystems converted:

affs, bfs, exofs, ext2, hfs, hfsplus, jffs2, jfs, logfs, minix, msdos,
nilfs2, omfs, reiserfs, sysvfs, ubifs, udf, ufs, vfat.

Signed-off-by: Miklos Szeredi <[email protected]>
Acked-by: Boaz Harrosh <[email protected]>
Acked-by: Richard Weinberger <[email protected]>
Acked-by: Bob Copeland <[email protected]>
Acked-by: Jan Kara <[email protected]>
Cc: Theodore Ts'o <[email protected]>
Cc: Jaegeuk Kim <[email protected]>
Cc: OGAWA Hirofumi <[email protected]>
Cc: Mikulas Patocka <[email protected]>
Cc: David Woodhouse <[email protected]>
Cc: Dave Kleikamp <[email protected]>
Cc: Ryusuke Konishi <[email protected]>
Cc: Christoph Hellwig <[email protected]>
  • Loading branch information
Miklos Szeredi committed Sep 27, 2016
1 parent 9a232de commit f03b8ad
Show file tree
Hide file tree
Showing 22 changed files with 123 additions and 42 deletions.
3 changes: 2 additions & 1 deletion fs/affs/affs.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ extern int affs_link(struct dentry *olddentry, struct inode *dir,
extern int affs_symlink(struct inode *dir, struct dentry *dentry,
const char *symname);
extern int affs_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry);
struct inode *new_dir, struct dentry *new_dentry,
unsigned int flags);

/* inode.c */

Expand Down
2 changes: 1 addition & 1 deletion fs/affs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const struct inode_operations affs_dir_inode_operations = {
.symlink = affs_symlink,
.mkdir = affs_mkdir,
.rmdir = affs_rmdir,
.rename = affs_rename,
.rename2 = affs_rename,
.setattr = affs_notify_change,
};

Expand Down
6 changes: 5 additions & 1 deletion fs/affs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,16 @@ affs_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry)

int
affs_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry)
struct inode *new_dir, struct dentry *new_dentry,
unsigned int flags)
{
struct super_block *sb = old_dir->i_sb;
struct buffer_head *bh = NULL;
int retval;

if (flags & ~RENAME_NOREPLACE)
return -EINVAL;

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

Expand Down
8 changes: 6 additions & 2 deletions fs/bfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,18 @@ static int bfs_unlink(struct inode *dir, struct dentry *dentry)
}

static int bfs_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry)
struct inode *new_dir, struct dentry *new_dentry,
unsigned int flags)
{
struct inode *old_inode, *new_inode;
struct buffer_head *old_bh, *new_bh;
struct bfs_dirent *old_de, *new_de;
struct bfs_sb_info *info;
int error = -ENOENT;

if (flags & ~RENAME_NOREPLACE)
return -EINVAL;

old_bh = new_bh = NULL;
old_inode = d_inode(old_dentry);
if (S_ISDIR(old_inode->i_mode))
Expand Down Expand Up @@ -270,7 +274,7 @@ const struct inode_operations bfs_dir_inops = {
.lookup = bfs_lookup,
.link = bfs_link,
.unlink = bfs_unlink,
.rename = bfs_rename,
.rename2 = bfs_rename,
};

static int bfs_add_entry(struct inode *dir, const unsigned char *name,
Expand Down
8 changes: 6 additions & 2 deletions fs/exofs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ static int exofs_rmdir(struct inode *dir, struct dentry *dentry)
}

static int exofs_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry)
struct inode *new_dir, struct dentry *new_dentry,
unsigned int flags)
{
struct inode *old_inode = d_inode(old_dentry);
struct inode *new_inode = d_inode(new_dentry);
Expand All @@ -237,6 +238,9 @@ static int exofs_rename(struct inode *old_dir, struct dentry *old_dentry,
struct exofs_dir_entry *old_de;
int err = -ENOENT;

if (flags & ~RENAME_NOREPLACE)
return -EINVAL;

old_de = exofs_find_entry(old_dir, old_dentry, &old_page);
if (!old_de)
goto out;
Expand Down Expand Up @@ -310,7 +314,7 @@ const struct inode_operations exofs_dir_inode_operations = {
.mkdir = exofs_mkdir,
.rmdir = exofs_rmdir,
.mknod = exofs_mknod,
.rename = exofs_rename,
.rename2 = exofs_rename,
.setattr = exofs_setattr,
};

Expand Down
8 changes: 6 additions & 2 deletions fs/ext2/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ static int ext2_rmdir (struct inode * dir, struct dentry *dentry)
}

static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
struct inode * new_dir, struct dentry * new_dentry )
struct inode * new_dir, struct dentry * new_dentry,
unsigned int flags)
{
struct inode * old_inode = d_inode(old_dentry);
struct inode * new_inode = d_inode(new_dentry);
Expand All @@ -338,6 +339,9 @@ static int ext2_rename (struct inode * old_dir, struct dentry * old_dentry,
struct ext2_dir_entry_2 * old_de;
int err;

if (flags & ~RENAME_NOREPLACE)
return -EINVAL;

err = dquot_initialize(old_dir);
if (err)
goto out;
Expand Down Expand Up @@ -426,7 +430,7 @@ const struct inode_operations ext2_dir_inode_operations = {
.mkdir = ext2_mkdir,
.rmdir = ext2_rmdir,
.mknod = ext2_mknod,
.rename = ext2_rename,
.rename2 = ext2_rename,
#ifdef CONFIG_EXT2_FS_XATTR
.setxattr = generic_setxattr,
.getxattr = generic_getxattr,
Expand Down
8 changes: 6 additions & 2 deletions fs/fat/namei_msdos.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,16 @@ static int do_msdos_rename(struct inode *old_dir, unsigned char *old_name,

/***** Rename, a wrapper for rename_same_dir & rename_diff_dir */
static int msdos_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry)
struct inode *new_dir, struct dentry *new_dentry,
unsigned int flags)
{
struct super_block *sb = old_dir->i_sb;
unsigned char old_msdos_name[MSDOS_NAME], new_msdos_name[MSDOS_NAME];
int err, is_hid;

if (flags & ~RENAME_NOREPLACE)
return -EINVAL;

mutex_lock(&MSDOS_SB(sb)->s_lock);

err = msdos_format_name(old_dentry->d_name.name,
Expand Down Expand Up @@ -633,7 +637,7 @@ static const struct inode_operations msdos_dir_inode_operations = {
.unlink = msdos_unlink,
.mkdir = msdos_mkdir,
.rmdir = msdos_rmdir,
.rename = msdos_rename,
.rename2 = msdos_rename,
.setattr = fat_setattr,
.getattr = fat_getattr,
};
Expand Down
8 changes: 6 additions & 2 deletions fs/fat/namei_vfat.c
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,8 @@ static int vfat_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
}

static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry)
struct inode *new_dir, struct dentry *new_dentry,
unsigned int flags)
{
struct buffer_head *dotdot_bh;
struct msdos_dir_entry *dotdot_de;
Expand All @@ -914,6 +915,9 @@ static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
int err, is_dir, update_dotdot, corrupt = 0;
struct super_block *sb = old_dir->i_sb;

if (flags & ~RENAME_NOREPLACE)
return -EINVAL;

old_sinfo.bh = sinfo.bh = dotdot_bh = NULL;
old_inode = d_inode(old_dentry);
new_inode = d_inode(new_dentry);
Expand Down Expand Up @@ -1036,7 +1040,7 @@ static const struct inode_operations vfat_dir_inode_operations = {
.unlink = vfat_unlink,
.mkdir = vfat_mkdir,
.rmdir = vfat_rmdir,
.rename = vfat_rename,
.rename2 = vfat_rename,
.setattr = fat_setattr,
.getattr = fat_getattr,
};
Expand Down
8 changes: 6 additions & 2 deletions fs/hfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,14 @@ static int hfs_remove(struct inode *dir, struct dentry *dentry)
* XXX: how do you handle must_be dir?
*/
static int hfs_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry)
struct inode *new_dir, struct dentry *new_dentry,
unsigned int flags)
{
int res;

if (flags & ~RENAME_NOREPLACE)
return -EINVAL;

/* Unlink destination if it already exists */
if (d_really_is_positive(new_dentry)) {
res = hfs_remove(new_dir, new_dentry);
Expand Down Expand Up @@ -320,6 +324,6 @@ const struct inode_operations hfs_dir_inode_operations = {
.unlink = hfs_remove,
.mkdir = hfs_mkdir,
.rmdir = hfs_remove,
.rename = hfs_rename,
.rename2 = hfs_rename,
.setattr = hfs_inode_setattr,
};
8 changes: 6 additions & 2 deletions fs/hfsplus/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,14 @@ static int hfsplus_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
}

static int hfsplus_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry)
struct inode *new_dir, struct dentry *new_dentry,
unsigned int flags)
{
int res;

if (flags & ~RENAME_NOREPLACE)
return -EINVAL;

/* Unlink destination if it already exists */
if (d_really_is_positive(new_dentry)) {
if (d_is_dir(new_dentry))
Expand Down Expand Up @@ -561,7 +565,7 @@ const struct inode_operations hfsplus_dir_inode_operations = {
.rmdir = hfsplus_rmdir,
.symlink = hfsplus_symlink,
.mknod = hfsplus_mknod,
.rename = hfsplus_rename,
.rename2 = hfsplus_rename,
.setxattr = generic_setxattr,
.getxattr = generic_getxattr,
.listxattr = hfsplus_listxattr,
Expand Down
8 changes: 6 additions & 2 deletions fs/hpfs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,8 @@ const struct address_space_operations hpfs_symlink_aops = {
};

static int hpfs_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry)
struct inode *new_dir, struct dentry *new_dentry,
unsigned int flags)
{
const unsigned char *old_name = old_dentry->d_name.name;
unsigned old_len = old_dentry->d_name.len;
Expand All @@ -524,6 +525,9 @@ static int hpfs_rename(struct inode *old_dir, struct dentry *old_dentry,
struct fnode *fnode;
int err;

if (flags & ~RENAME_NOREPLACE)
return -EINVAL;

if ((err = hpfs_chk_name(new_name, &new_len))) return err;
err = 0;
hpfs_adjust_length(old_name, &old_len);
Expand Down Expand Up @@ -618,6 +622,6 @@ const struct inode_operations hpfs_dir_iops =
.mkdir = hpfs_mkdir,
.rmdir = hpfs_rmdir,
.mknod = hpfs_mknod,
.rename = hpfs_rename,
.rename2 = hpfs_rename,
.setattr = hpfs_setattr,
};
11 changes: 8 additions & 3 deletions fs/jffs2/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ static int jffs2_mkdir (struct inode *,struct dentry *,umode_t);
static int jffs2_rmdir (struct inode *,struct dentry *);
static int jffs2_mknod (struct inode *,struct dentry *,umode_t,dev_t);
static int jffs2_rename (struct inode *, struct dentry *,
struct inode *, struct dentry *);
struct inode *, struct dentry *,
unsigned int);

const struct file_operations jffs2_dir_operations =
{
Expand All @@ -57,7 +58,7 @@ const struct inode_operations jffs2_dir_inode_operations =
.mkdir = jffs2_mkdir,
.rmdir = jffs2_rmdir,
.mknod = jffs2_mknod,
.rename = jffs2_rename,
.rename2 = jffs2_rename,
.get_acl = jffs2_get_acl,
.set_acl = jffs2_set_acl,
.setattr = jffs2_setattr,
Expand Down Expand Up @@ -759,14 +760,18 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, umode_t mode
}

static int jffs2_rename (struct inode *old_dir_i, struct dentry *old_dentry,
struct inode *new_dir_i, struct dentry *new_dentry)
struct inode *new_dir_i, struct dentry *new_dentry,
unsigned int flags)
{
int ret;
struct jffs2_sb_info *c = JFFS2_SB_INFO(old_dir_i->i_sb);
struct jffs2_inode_info *victim_f = NULL;
uint8_t type;
uint32_t now;

if (flags & ~RENAME_NOREPLACE)
return -EINVAL;

/* The VFS will check for us and prevent trying to rename a
* file over a directory and vice versa, but if it's a directory,
* the VFS can't check whether the victim is empty. The filesystem
Expand Down
7 changes: 5 additions & 2 deletions fs/jfs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,8 @@ static int jfs_symlink(struct inode *dip, struct dentry *dentry,
* FUNCTION: rename a file or directory
*/
static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry)
struct inode *new_dir, struct dentry *new_dentry,
unsigned int flags)
{
struct btstack btstack;
ino_t ino;
Expand All @@ -1097,6 +1098,8 @@ static int jfs_rename(struct inode *old_dir, struct dentry *old_dentry,
s64 new_size = 0;
int commit_flag;

if (flags & ~RENAME_NOREPLACE)
return -EINVAL;

jfs_info("jfs_rename: %pd %pd", old_dentry, new_dentry);

Expand Down Expand Up @@ -1536,7 +1539,7 @@ const struct inode_operations jfs_dir_inode_operations = {
.mkdir = jfs_mkdir,
.rmdir = jfs_rmdir,
.mknod = jfs_mknod,
.rename = jfs_rename,
.rename2 = jfs_rename,
.setxattr = generic_setxattr,
.getxattr = generic_getxattr,
.listxattr = jfs_listxattr,
Expand Down
8 changes: 6 additions & 2 deletions fs/logfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,12 @@ static int logfs_rename_target(struct inode *old_dir, struct dentry *old_dentry,
}

static int logfs_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry)
struct inode *new_dir, struct dentry *new_dentry,
unsigned int flags)
{
if (flags & ~RENAME_NOREPLACE)
return -EINVAL;

if (d_really_is_positive(new_dentry))
return logfs_rename_target(old_dir, old_dentry,
new_dir, new_dentry);
Expand Down Expand Up @@ -783,7 +787,7 @@ const struct inode_operations logfs_dir_iops = {
.lookup = logfs_lookup,
.mkdir = logfs_mkdir,
.mknod = logfs_mknod,
.rename = logfs_rename,
.rename2 = logfs_rename,
.rmdir = logfs_rmdir,
.symlink = logfs_symlink,
.unlink = logfs_unlink,
Expand Down
8 changes: 6 additions & 2 deletions fs/minix/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ static int minix_rmdir(struct inode * dir, struct dentry *dentry)
}

static int minix_rename(struct inode * old_dir, struct dentry *old_dentry,
struct inode * new_dir, struct dentry *new_dentry)
struct inode * new_dir, struct dentry *new_dentry,
unsigned int flags)
{
struct inode * old_inode = d_inode(old_dentry);
struct inode * new_inode = d_inode(new_dentry);
Expand All @@ -195,6 +196,9 @@ static int minix_rename(struct inode * old_dir, struct dentry *old_dentry,
struct minix_dir_entry * old_de;
int err = -ENOENT;

if (flags & ~RENAME_NOREPLACE)
return -EINVAL;

old_de = minix_find_entry(old_dentry, &old_page);
if (!old_de)
goto out;
Expand Down Expand Up @@ -264,7 +268,7 @@ const struct inode_operations minix_dir_inode_operations = {
.mkdir = minix_mkdir,
.rmdir = minix_rmdir,
.mknod = minix_mknod,
.rename = minix_rename,
.rename2 = minix_rename,
.getattr = minix_getattr,
.tmpfile = minix_tmpfile,
};
Loading

0 comments on commit f03b8ad

Please sign in to comment.