From: "David M. Richter" <richterd@citi.umich.edu>
To: linux-fsdevel@vger.kernel.org
Cc: "David M. Richter" <richterd@citi.umich.edu>
Subject: [PATCH] VFS: refactor sys_fchmod and sys_fchmodat
Date: Wed, 23 Apr 2008 16:34:00 -0400 [thread overview]
Message-ID: <1208982840-18306-1-git-send-email-richterd@citi.umich.edu> (raw)
Create chmod_common with code shared by sys_fchmod and sys_fchmodat and
have them call it.
Signed-off-by: David M. Richter <richterd@citi.umich.edu>
---
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
reply other threads:[~2008-04-23 20:34 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1208982840-18306-1-git-send-email-richterd@citi.umich.edu \
--to=richterd@citi.umich.edu \
--cc=linux-fsdevel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).