From: Andrew Ayer <agwa@andrewayer.name>
To: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 1/2] vfs: Add POSIX-compliant version of fchmodat syscall
Date: Fri, 30 Dec 2011 16:26:50 -0800 [thread overview]
Message-ID: <1325291211-30354-2-git-send-email-agwa@andrewayer.name> (raw)
In-Reply-To: <1325291211-30354-1-git-send-email-agwa@andrewayer.name>
This adds a 4 argument version of fchmodat (fchmodat4) that
supports a flag argument, as specified by POSIX. It supports
the same two flags as fchownat: AT_SYMLINK_NOFOLLOW and AT_EMPTY_PATH.
Signed-off-by: Andrew Ayer <agwa@andrewayer.name>
---
fs/open.c | 21 +++++++++++++++++++--
include/linux/syscalls.h | 2 ++
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/fs/open.c b/fs/open.c
index 22c41b5..c3dfdaa 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -452,6 +452,9 @@ static int chmod_common(struct path *path, umode_t mode)
struct iattr newattrs;
int error;
+ if (S_ISLNK(inode->i_mode))
+ return -EOPNOTSUPP;
+
error = mnt_want_write(path->mnt);
if (error)
return error;
@@ -484,10 +487,24 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, mode_t, mode)
SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, mode_t, mode)
{
+ return sys_fchmodat4(dfd, filename, mode, 0);
+}
+
+SYSCALL_DEFINE4(fchmodat4, int, dfd, const char __user *, filename,
+ mode_t, mode, int, flag)
+{
struct path path;
int error;
+ int lookup_flags;
+
+ if ((flag & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) != 0)
+ return -EINVAL;
- error = user_path_at(dfd, filename, LOOKUP_FOLLOW, &path);
+ lookup_flags = (flag & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW;
+ if (flag & AT_EMPTY_PATH)
+ lookup_flags |= LOOKUP_EMPTY;
+
+ error = user_path_at(dfd, filename, lookup_flags, &path);
if (!error) {
error = chmod_common(&path, mode);
path_put(&path);
@@ -497,7 +514,7 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, mode_t, mode)
SYSCALL_DEFINE2(chmod, const char __user *, filename, mode_t, mode)
{
- return sys_fchmodat(AT_FDCWD, filename, mode);
+ return sys_fchmodat4(AT_FDCWD, filename, mode, 0);
}
static int chown_common(struct path *path, uid_t user, gid_t group)
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 86a24b1..c84795b 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -770,6 +770,8 @@ asmlinkage long sys_futimesat(int dfd, const char __user *filename,
asmlinkage long sys_faccessat(int dfd, const char __user *filename, int mode);
asmlinkage long sys_fchmodat(int dfd, const char __user * filename,
mode_t mode);
+asmlinkage long sys_fchmodat4(int dfd, const char __user * filename,
+ mode_t mode, int flag);
asmlinkage long sys_fchownat(int dfd, const char __user *filename, uid_t user,
gid_t group, int flag);
asmlinkage long sys_openat(int dfd, const char __user *filename, int flags,
--
1.7.1
next prev parent reply other threads:[~2011-12-31 0:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-31 0:26 [PATCH 0/2] vfs: POSIX-compliant version of fchmodat with flag argument Andrew Ayer
2011-12-31 0:26 ` Andrew Ayer [this message]
2011-12-31 0:26 ` [PATCH 2/2] x86: Hook up new fchmodat4 syscall Andrew Ayer
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=1325291211-30354-2-git-send-email-agwa@andrewayer.name \
--to=agwa@andrewayer.name \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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).