[PATCH] VFS: refactor sys_fchmod and sys_fchmodat

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Create chmod_common with code shared by sys_fchmod and sys_fchmodat and
have them call it.

Signed-off-by: David M. Richter <richterd@xxxxxxxxxxxxxx>
---
 fs/open.c |   65 ++++++++++++++++++++++--------------------------------------
 1 files changed, 24 insertions(+), 41 deletions(-)

diff --git a/fs/open.c b/fs/open.c
index b70e766..a8585b0 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -561,40 +561,44 @@ out:
 	return error;
 }
 
-asmlinkage long sys_fchmod(unsigned int fd, mode_t mode)
+static int chmod_common(struct path *path, mode_t mode)
 {
-	struct inode * inode;
-	struct dentry * dentry;
-	struct file * file;
-	int err = -EBADF;
+	int err;
 	struct iattr newattrs;
+	struct inode *inode = path->dentry->d_inode;
 
-	file = fget(fd);
-	if (!file)
-		goto out;
-
-	dentry = file->f_path.dentry;
-	inode = dentry->d_inode;
-
-	audit_inode(NULL, dentry);
-
-	err = mnt_want_write(file->f_path.mnt);
+	err = mnt_want_write(path->mnt);
 	if (err)
-		goto out_putf;
+		goto out;
 	err = -EPERM;
 	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
 		goto out_drop_write;
+
 	mutex_lock(&inode->i_mutex);
 	if (mode == (mode_t) -1)
 		mode = inode->i_mode;
 	newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
 	newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
-	err = notify_change(dentry, &newattrs);
+	err = notify_change(path->dentry, &newattrs);
 	mutex_unlock(&inode->i_mutex);
 
 out_drop_write:
-	mnt_drop_write(file->f_path.mnt);
-out_putf:
+	mnt_drop_write(path->mnt);
+out:
+	return err;
+}
+
+asmlinkage long sys_fchmod(unsigned int fd, mode_t mode)
+{
+	struct file *file;
+	int err = -EBADF;
+
+	file = fget(fd);
+	if (!file)
+		goto out;
+
+	audit_inode(NULL, file->f_path.dentry);
+	err = chmod_common(&file->f_path, mode);
 	fput(file);
 out:
 	return err;
@@ -604,34 +608,13 @@ asmlinkage long sys_fchmodat(int dfd, const char __user *filename,
 			     mode_t mode)
 {
 	struct nameidata nd;
-	struct inode * inode;
 	int error;
-	struct iattr newattrs;
 
 	error = __user_walk_fd(dfd, filename, LOOKUP_FOLLOW, &nd);
 	if (error)
 		goto out;
-	inode = nd.path.dentry->d_inode;
 
-	error = mnt_want_write(nd.path.mnt);
-	if (error)
-		goto dput_and_out;
-
-	error = -EPERM;
-	if (IS_IMMUTABLE(inode) || IS_APPEND(inode))
-		goto out_drop_write;
-
-	mutex_lock(&inode->i_mutex);
-	if (mode == (mode_t) -1)
-		mode = inode->i_mode;
-	newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
-	newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
-	error = notify_change(nd.path.dentry, &newattrs);
-	mutex_unlock(&inode->i_mutex);
-
-out_drop_write:
-	mnt_drop_write(nd.path.mnt);
-dput_and_out:
+	error = chmod_common(&nd.path, mode);
 	path_put(&nd.path);
 out:
 	return error;
-- 
1.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux