From patchwork Wed Nov 2 22:53:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jose Lopes X-Patchwork-Id: 9409999 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DB5C06022E for ; Wed, 2 Nov 2016 22:54:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAF052A5AD for ; Wed, 2 Nov 2016 22:54:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDA9F2A601; Wed, 2 Nov 2016 22:54:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 612012A5AD for ; Wed, 2 Nov 2016 22:54:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757141AbcKBWyH (ORCPT ); Wed, 2 Nov 2016 18:54:07 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:36279 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754442AbcKBWyG (ORCPT ); Wed, 2 Nov 2016 18:54:06 -0400 Received: by mail-wm0-f65.google.com with SMTP id c17so5189343wmc.3 for ; Wed, 02 Nov 2016 15:54:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=H6MsyhlzFmwe894EtCveqbhJ9rv/78nFBTfVjwkJ75M=; b=zqahA+/TwjrEWitABAJi7TgEbX401BWsChzVPt3DhYSNdrCKDCK5bT8Drxkr0tsLpL GMGuWGomPdvtZw9IUOtiMecagWAh4T6I9xGKrpHR+1umtHXE2NH/6ZcSik7qJwAGT1PT p53Qu0gGEtf4pnTfjyU7Kq4JQ6Bk+pgW6i8T1th6bWxyKO/yI7IvI21p1JjzAze0T7FA lE3bFhMBbRW/LqdALs4CrrTSH9hAEDQ2yeBYOUTHe1WwVLPk8HjV2uZpolwM18szDEiL rDlWInCyG/QjNmKQnw0fup5yl+BxdTlSBzPAc0lxv4tqgKdug2NotJ44aLlLG0JzQMrp p7Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=H6MsyhlzFmwe894EtCveqbhJ9rv/78nFBTfVjwkJ75M=; b=axXOYRf6Ztmw0dQAfXNBc/xZhej2NmCvHMVoqcbYe7kElAVsXxwSI8CedciIEU/vun NZteXh+w/FlyBcRZCI8AgAvazS6PyRa3G6nw7ejnYmd6P1YdyxryPVfkaC0iVe02N0I8 58oCUAw6QS0yg4kPQJXRAQN0SGW+HegksS6yOnar1rNCtFh6IACVYDOG8d/n8olPzzKk r9RGkJad6dKz+pLFhHbq9Oy4y75kvqE764CHZ5cq8xdUKwx6WJZFF5UQsgE/Bgt+X7RE uH9Y0Obplb9d48y9OCqsPpys6SB2vr3Lu0q8VSt3UbuoWnNNPuRaIb6DklTs2UlXim6c 4Qsw== X-Gm-Message-State: ABUngvev0TH8i0MaakHbhdw4cS7qe7TYw5RO1hHMXU135EzDMOOZyzuNFK4J9Yde+M47dg== X-Received: by 10.28.46.202 with SMTP id u193mr4921192wmu.53.1478127244926; Wed, 02 Nov 2016 15:54:04 -0700 (PDT) Received: from tower.fritz.box ([2001:a61:2081:fe01:e98a:5451:3812:6db8]) by smtp.googlemail.com with ESMTPSA id q134sm38968916wme.3.2016.11.02.15.54.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Nov 2016 15:54:04 -0700 (PDT) From: Jose Lopes To: Alexander Viro Cc: Jose Lopes , linux-fsdevel@vger.kernel.org, fuse-devel@lists.sourceforge.net Subject: [PATCH] Make file struct available to fchmod FS handlers. Date: Wed, 2 Nov 2016 23:53:40 +0100 Message-Id: <20161102225340.11613-1-jabolopes@gmail.com> X-Mailer: git-send-email 2.9.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Syscall 'ftruncate' makes the 'file' struct available to filesystem handlers. This makes it possible, e.g., for filesystems, such as, FUSE, to access the file handle associated with the file descriptor that was passed to 'ftruncate'. In the specific case of FUSE, this also makes it possible for (userspace) FUSE-based filesystems to distinguish between calls to 'truncate' and 'ftruncate'. From an implementation point of view, this is possible because the 'ftruncate' syscall passes the 'file' struct to the underlying filesystem handlers via the 'ia_file' field and the 'ia_valid' field mask. Similarly to 'ftruncate', pass the 'file' struct to 'fchmod', which allows filesystem handlers to get the file handle associated with the file descriptor passed to 'fchmod' and allows FUSE-based filesystems to distinguish between calls to 'chmod' and 'fchmod'. In a future patch, make a similar change to the 'fchown' and 'futimens' syscalls. Signed-off-by: Jose Lopes Tested-by: Nikolaus Rath --- fs/open.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/open.c b/fs/open.c index d3ed817..00214c5 100644 --- a/fs/open.c +++ b/fs/open.c @@ -516,7 +516,8 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename) return error; } -static int chmod_common(const struct path *path, umode_t mode) +static int chmod_common(const struct path *path, umode_t mode, + struct file *filp) { struct inode *inode = path->dentry->d_inode; struct inode *delegated_inode = NULL; @@ -533,6 +534,10 @@ static int chmod_common(const struct path *path, umode_t mode) goto out_unlock; newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO); newattrs.ia_valid = ATTR_MODE | ATTR_CTIME; + if (filp) { + newattrs.ia_file = filp; + newattrs.ia_valid |= ATTR_FILE; + } error = notify_change(path->dentry, &newattrs, &delegated_inode); out_unlock: inode_unlock(inode); @@ -552,7 +557,7 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, umode_t, mode) if (f.file) { audit_file(f.file); - err = chmod_common(&f.file->f_path, mode); + err = chmod_common(&f.file->f_path, mode, f.file); fdput(f); } return err; @@ -566,7 +571,7 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, umode_t, mode retry: error = user_path_at(dfd, filename, lookup_flags, &path); if (!error) { - error = chmod_common(&path, mode); + error = chmod_common(&path, mode, NULL); path_put(&path); if (retry_estale(error, lookup_flags)) { lookup_flags |= LOOKUP_REVAL;