Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752227AbbEKCO0 (ORCPT ); Sun, 10 May 2015 22:14:26 -0400 Received: from cyan.worrbase.com ([208.79.95.114]:18416 "EHLO cyan.worrbase.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751644AbbEKCOX (ORCPT ); Sun, 10 May 2015 22:14:23 -0400 X-Greylist: delayed 399 seconds by postgrey-1.27 at vger.kernel.org; Sun, 10 May 2015 22:14:19 EDT Authentication-Results: cyan.worrbase.com (amavisd-new); dkim=pass (4096-bit key) reason="pass (just generated, assumed good)" header.d=worrbase.com From: William Orr To: linux-kernel@vger.kernel.org Cc: William Orr Subject: [PATCH 1/2] Implement fchmodat4 syscall Date: Sun, 10 May 2015 19:07:21 -0700 Message-Id: <1431310042-52247-2-git-send-email-will@worrbase.com> X-Mailer: git-send-email 2.3.7 In-Reply-To: <1431310042-52247-1-git-send-email-will@worrbase.com> References: <1431310042-52247-1-git-send-email-will@worrbase.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2685 Lines: 77 Adds fchmodat4 which more closely matches POSIX by taking 4 arguments, including the flags argument. flags are the same as fchownat(2), implementing both AT_SYMLINK_NOFOLLOW and AT_EMPTY_PATH Based heavily off of Andrew Ayer's patch from 2012. --- fs/open.c | 19 +++++++++++++++++-- include/linux/syscalls.h | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/fs/open.c b/fs/open.c index 98e5a52..00dd0f7 100644 --- a/fs/open.c +++ b/fs/open.c @@ -504,6 +504,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; @@ -541,9 +544,21 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode) SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, umode_t, mode) { + return sys_fchmodat4(dfd, filename, mode, 0); +} + +SYSCALL_DEFINE4(fchmodat4, int, dfd, const char __user *, filename, umode_t, mode, int, flags) +{ struct path path; int error; - unsigned int lookup_flags = LOOKUP_FOLLOW; + unsigned int lookup_flags; + + if (flags & ~(AT_SYMLINK_NOFOLLOW | AT_EMPTY_PATH)) + return -EINVAL; + + lookup_flags = (flags & AT_SYMLINK_NOFOLLOW) ? 0 : LOOKUP_FOLLOW; + if (flags & AT_EMPTY_PATH) + lookup_flags |= LOOKUP_EMPTY; retry: error = user_path_at(dfd, filename, lookup_flags, &path); if (!error) { @@ -559,7 +574,7 @@ retry: SYSCALL_DEFINE2(chmod, const char __user *, filename, umode_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 76d1e38..d6e9602 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -769,6 +769,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, umode_t mode); +asmlinkage long sys_fchmodat4(int dfd, const char __user * filename, + umode_t mode, int flags); 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, -- 2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/