From 1b8e3f7c05d8c1962eed7ca504f806b359d534a6 Mon Sep 17 00:00:00 2001 From: "Bryant G. Duffy-Ly" Date: Fri, 19 Nov 2021 16:45:41 -0600 Subject: [PATCH] Add basic renameat2 syscall support Support generic renameat2 syscall then add support for the RENAME_NOREPLACE flag. To suppor the flag we need to check the existance of both entries and return -EXIST. Signed-off-by: Bryant G. Duffy-Ly --- kmod/src/dir.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/kmod/src/dir.c b/kmod/src/dir.c index f380a5d8..7470244c 100644 --- a/kmod/src/dir.c +++ b/kmod/src/dir.c @@ -1615,8 +1615,9 @@ static int verify_ancestors(struct super_block *sb, u64 p1, u64 p2, * from using parent/child locking orders as two groups can have both * parent and child relationships to each other. */ -static int scoutfs_rename(struct inode *old_dir, struct dentry *old_dentry, - struct inode *new_dir, struct dentry *new_dentry) +static int scoutfs_rename_common(struct inode *old_dir, + struct dentry *old_dentry, struct inode *new_dir, + struct dentry *new_dentry, unsigned int flags) { struct super_block *sb = old_dir->i_sb; struct inode *old_inode = old_dentry->d_inode; @@ -1688,6 +1689,11 @@ static int scoutfs_rename(struct inode *old_dir, struct dentry *old_dentry, if (ret) goto out_unlock; + if ((flags & RENAME_NOREPLACE) && (new_inode != NULL)) { + ret = -EEXIST; + goto out_unlock; + } + if (should_orphan(new_inode)) { ret = scoutfs_lock_orphan(sb, SCOUTFS_LOCK_WRITE_ONLY, 0, scoutfs_ino(new_inode), &orph_lock); @@ -1870,6 +1876,23 @@ out_unlock: return ret; } +static int scoutfs_rename(struct inode *old_dir, + struct dentry *old_dentry, struct inode *new_dir, + struct dentry *new_dentry) +{ + return scoutfs_rename_common(old_dir, old_dentry, new_dir, new_dentry, 0); +} + +static int scoutfs_rename2(struct inode *old_dir, + struct dentry *old_dentry, struct inode *new_dir, + struct dentry *new_dentry, unsigned int flags) +{ + if (flags & ~RENAME_NOREPLACE) + return -EINVAL; + + return scoutfs_rename_common(old_dir, old_dentry, new_dir, new_dentry, flags); +} + #ifdef KC_FMODE_KABI_ITERATE /* we only need this to set the iterate flag for kabi :/ */ static int scoutfs_dir_open(struct inode *inode, struct file *file) @@ -1960,6 +1983,7 @@ const struct inode_operations_wrapper scoutfs_dir_iops = { .permission = scoutfs_permission, }, .tmpfile = scoutfs_tmpfile, + .rename2 = scoutfs_rename2, }; void scoutfs_dir_exit(void)