aboutsummaryrefslogtreecommitdiffstats
path: root/fs/hostfs
diff options
context:
space:
mode:
authorMiklos Szeredi <mszeredi@suse.cz>2014-07-23 09:15:35 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2014-08-07 14:40:09 -0400
commit9a423bb6e3577bb372942edfb5d9d26632741d43 (patch)
tree73482f4b4fc8495d3695e6bbf0abf1db59cd6ae7 /fs/hostfs
parent37456771c58be10dd813fb4510035d0d67a969aa (diff)
hostfs: support rename flags
Support RENAME_NOREPLACE and RENAME_EXCHANGE flags on hostfs if the underlying filesystem supports it. Since renameat2(2) is not yet in any libc, use syscall(2) to invoke the renameat2 syscall. Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Cc: Richard Weinberger <richard@nod.at> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/hostfs')
-rw-r--r--fs/hostfs/hostfs.h1
-rw-r--r--fs/hostfs/hostfs_kern.c30
-rw-r--r--fs/hostfs/hostfs_user.c28
3 files changed, 49 insertions, 10 deletions
diff --git a/fs/hostfs/hostfs.h b/fs/hostfs/hostfs.h
index 9c88da0e855a..4fcd40d6f308 100644
--- a/fs/hostfs/hostfs.h
+++ b/fs/hostfs/hostfs.h
@@ -89,6 +89,7 @@ extern int do_mknod(const char *file, int mode, unsigned int major,
89extern int link_file(const char *from, const char *to); 89extern int link_file(const char *from, const char *to);
90extern int hostfs_do_readlink(char *file, char *buf, int size); 90extern int hostfs_do_readlink(char *file, char *buf, int size);
91extern int rename_file(char *from, char *to); 91extern int rename_file(char *from, char *to);
92extern int rename2_file(char *from, char *to, unsigned int flags);
92extern int do_statfs(char *root, long *bsize_out, long long *blocks_out, 93extern int do_statfs(char *root, long *bsize_out, long long *blocks_out,
93 long long *bfree_out, long long *bavail_out, 94 long long *bfree_out, long long *bavail_out,
94 long long *files_out, long long *ffree_out, 95 long long *files_out, long long *ffree_out,
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index bb529f3b7f2b..fd62cae0fdcb 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -741,21 +741,31 @@ static int hostfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
741 return err; 741 return err;
742} 742}
743 743
744static int hostfs_rename(struct inode *from_ino, struct dentry *from, 744static int hostfs_rename2(struct inode *old_dir, struct dentry *old_dentry,
745 struct inode *to_ino, struct dentry *to) 745 struct inode *new_dir, struct dentry *new_dentry,
746 unsigned int flags)
746{ 747{
747 char *from_name, *to_name; 748 char *old_name, *new_name;
748 int err; 749 int err;
749 750
750 if ((from_name = dentry_name(from)) == NULL) 751 if (flags & ~(RENAME_NOREPLACE | RENAME_EXCHANGE))
752 return -EINVAL;
753
754 old_name = dentry_name(old_dentry);
755 if (old_name == NULL)
751 return -ENOMEM; 756 return -ENOMEM;
752 if ((to_name = dentry_name(to)) == NULL) { 757 new_name = dentry_name(new_dentry);
753 __putname(from_name); 758 if (new_name == NULL) {
759 __putname(old_name);
754 return -ENOMEM; 760 return -ENOMEM;
755 } 761 }
756 err = rename_file(from_name, to_name); 762 if (!flags)
757 __putname(from_name); 763 err = rename_file(old_name, new_name);
758 __putname(to_name); 764 else
765 err = rename2_file(old_name, new_name, flags);
766
767 __putname(old_name);
768 __putname(new_name);
759 return err; 769 return err;
760} 770}
761 771
@@ -867,7 +877,7 @@ static const struct inode_operations hostfs_dir_iops = {
867 .mkdir = hostfs_mkdir, 877 .mkdir = hostfs_mkdir,
868 .rmdir = hostfs_rmdir, 878 .rmdir = hostfs_rmdir,
869 .mknod = hostfs_mknod, 879 .mknod = hostfs_mknod,
870 .rename = hostfs_rename, 880 .rename2 = hostfs_rename2,
871 .permission = hostfs_permission, 881 .permission = hostfs_permission,
872 .setattr = hostfs_setattr, 882 .setattr = hostfs_setattr,
873}; 883};
diff --git a/fs/hostfs/hostfs_user.c b/fs/hostfs/hostfs_user.c
index 67838f3aa20a..9765dab95cbd 100644
--- a/fs/hostfs/hostfs_user.c
+++ b/fs/hostfs/hostfs_user.c
@@ -14,6 +14,7 @@
14#include <sys/time.h> 14#include <sys/time.h>
15#include <sys/types.h> 15#include <sys/types.h>
16#include <sys/vfs.h> 16#include <sys/vfs.h>
17#include <sys/syscall.h>
17#include "hostfs.h" 18#include "hostfs.h"
18#include <utime.h> 19#include <utime.h>
19 20
@@ -360,6 +361,33 @@ int rename_file(char *from, char *to)
360 return 0; 361 return 0;
361} 362}
362 363
364int rename2_file(char *from, char *to, unsigned int flags)
365{
366 int err;
367
368#ifndef SYS_renameat2
369# ifdef __x86_64__
370# define SYS_renameat2 316
371# endif
372# ifdef __i386__
373# define SYS_renameat2 353
374# endif
375#endif
376
377#ifdef SYS_renameat2
378 err = syscall(SYS_renameat2, AT_FDCWD, from, AT_FDCWD, to, flags);
379 if (err < 0) {
380 if (errno != ENOSYS)
381 return -errno;
382 else
383 return -EINVAL;
384 }
385 return 0;
386#else
387 return -EINVAL;
388#endif
389}
390
363int do_statfs(char *root, long *bsize_out, long long *blocks_out, 391int do_statfs(char *root, long *bsize_out, long long *blocks_out,
364 long long *bfree_out, long long *bavail_out, 392 long long *bfree_out, long long *bavail_out,
365 long long *files_out, long long *ffree_out, 393 long long *files_out, long long *ffree_out,