From patchwork Tue May 29 14:43:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 10436087 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 4C137601C7 for ; Tue, 29 May 2018 15:11:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E8B728858 for ; Tue, 29 May 2018 15:11:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C7702886E; Tue, 29 May 2018 15:11:32 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable 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 B459B2888E for ; Tue, 29 May 2018 15:11:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935492AbeE2PLQ (ORCPT ); Tue, 29 May 2018 11:11:16 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:40691 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935683AbeE2OoH (ORCPT ); Tue, 29 May 2018 10:44:07 -0400 Received: by mail-wm0-f68.google.com with SMTP id x2-v6so33947967wmh.5 for ; Tue, 29 May 2018 07:44:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tycFrXomZ2LQ3ZNAXOaD95Iousaw6QxL/rMCceB8VEQ=; b=NJ3YZxAmB+aGYIKY3jwlHS3M5PwluX5emsrxxPk8nzHpaoYVuK2kZebHfCzjXOvVqu 7tBlYRBAmb5ENqkrCLK7OxBOj+YxYxxvYEwZWQ05xyFCsXLQGGX6WqB+vlRfdLZl3yhv 82Z4Ry/IbS1km2ZRM4lcAKo+xHPJilF5pf40tc24Kt0BMZlHtB9w6JjJ+lRmPLghIDXp fKLyJLUUhbPwLncvm4YtNRUrGBdRtNuigi6RPofprHanJep9r1XfJtj+3ZUceX3yldi0 q9JuiG49XGGEYII/ENNL5WmDGSl01j70llbl8Y3Ba7lDaIst3dFccxeM6HnzFMYd6PAv xY4g== X-Gm-Message-State: ALKqPwdgIwZ1Mo++oulr35qVg8TkyXV9HxT3sglRV/bXDvfAHd1UirBj GRmpfAxPtD6ZwWvWFVP0wuc9Uw== X-Google-Smtp-Source: ADUXVKL7JCovi9YkyqP8XDvNpk3OHiqPamv2ale20+QsiB/mnB7DNKo11SqKaqQNuSq/jbk0iw+9cg== X-Received: by 2002:a1c:ec82:: with SMTP id h2-v6mr10887570wmi.137.1527605046312; Tue, 29 May 2018 07:44:06 -0700 (PDT) Received: from veci.piliscsaba.redhat.com (catv-176-63-54-97.catv.broadband.hu. [176.63.54.97]) by smtp.gmail.com with ESMTPSA id t198-v6sm18834422wmt.23.2018.05.29.07.44.05 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 29 May 2018 07:44:05 -0700 (PDT) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 21/39] ovl: add lsattr/chattr support Date: Tue, 29 May 2018 16:43:21 +0200 Message-Id: <20180529144339.16538-22-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180529144339.16538-1-mszeredi@redhat.com> References: <20180529144339.16538-1-mszeredi@redhat.com> 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 Implement FS_IOC_GETFLAGS and FS_IOC_SETFLAGS. Signed-off-by: Miklos Szeredi --- fs/overlayfs/file.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/fs/overlayfs/file.c b/fs/overlayfs/file.c index 069599d53511..3f610a5b38e4 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include "overlayfs.h" @@ -305,6 +306,82 @@ static long ovl_fallocate(struct file *file, int mode, loff_t offset, loff_t len return ret; } +static long ovl_real_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) +{ + struct fd real; + const struct cred *old_cred; + long ret; + + ret = ovl_real_fdget(file, &real); + if (ret) + return ret; + + old_cred = ovl_override_creds(file_inode(file)->i_sb); + ret = vfs_ioctl(real.file, cmd, arg); + revert_creds(old_cred); + + fdput(real); + + return ret; +} + +static long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +{ + long ret; + struct inode *inode = file_inode(file); + + switch (cmd) { + case FS_IOC_GETFLAGS: + ret = ovl_real_ioctl(file, cmd, arg); + break; + + case FS_IOC_SETFLAGS: + if (!inode_owner_or_capable(inode)) + return -EACCES; + + ret = mnt_want_write_file(file); + if (ret) + return ret; + + ret = ovl_copy_up(file_dentry(file)); + if (!ret) { + ret = ovl_real_ioctl(file, cmd, arg); + + inode_lock(inode); + ovl_copyflags(ovl_inode_real(inode), inode); + inode_unlock(inode); + } + + mnt_drop_write_file(file); + break; + + default: + ret = -ENOTTY; + } + + return ret; +} + +static long ovl_compat_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) +{ + switch (cmd) { + case FS_IOC32_GETFLAGS: + cmd = FS_IOC_GETFLAGS; + break; + + case FS_IOC32_SETFLAGS: + cmd = FS_IOC_SETFLAGS; + break; + + default: + return -ENOIOCTLCMD; + } + + return ovl_ioctl(file, cmd, arg); +} + const struct file_operations ovl_file_operations = { .open = ovl_open, .release = ovl_release, @@ -314,4 +391,6 @@ const struct file_operations ovl_file_operations = { .fsync = ovl_fsync, .mmap = ovl_mmap, .fallocate = ovl_fallocate, + .unlocked_ioctl = ovl_ioctl, + .compat_ioctl = ovl_compat_ioctl, };