From patchwork Mon May 7 08:37:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 10383587 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 3B37C60159 for ; Mon, 7 May 2018 08:47:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31B0B286DF for ; Mon, 7 May 2018 08:47:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26B0528A96; Mon, 7 May 2018 08:47:00 +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 D2D24286DF for ; Mon, 7 May 2018 08:46:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752549AbeEGIqO (ORCPT ); Mon, 7 May 2018 04:46:14 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:46620 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752156AbeEGIie (ORCPT ); Mon, 7 May 2018 04:38:34 -0400 Received: by mail-wr0-f194.google.com with SMTP id o2-v6so24927096wrj.13 for ; Mon, 07 May 2018 01:38:34 -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=Ju9fBMHQ1dJ857PZB21HwPk8bcwd0cSxl7ECiWSiAb4=; b=Tk/Nz/R2e43OQMYn62CbUNTB/KdYppDaa3ZomBAikCDmp4uOrlhbk7u/v7dyCvI++l Dk84TaTowwpCtLkqPoPLsrhym+MCtoNtGCMi/RFFIlYEhmXhH8QNZibUstHzGj1ys8LW xcD6SIunFDVRnypHsPTsuAxuLynuONnfe/I321t55rkGFW7mS/QrOKCl3gce+3wXa51o lk0VZggL/rEW7iPVWAS5MkMoBCP36PHrOt0ZgCAx8A03MvHJI3OItQqzkkiMsyZ/xTj7 DKnVKgKPpdcUybTQ5olIEiZkydqc/lNoSr//IbvYXEwxo89GrRPYvccri4sggDkBE/kb +NZQ== X-Gm-Message-State: ALQs6tAcdEgiSDsYkV6kFHLuOeiECD1RpbQWxgXOYsGZAHPcfKg9oNbi Zis4XMv5NW+cXGa+vdjD8c+W2Q== X-Google-Smtp-Source: AB8JxZrmGjUGb3xJm8z7jjPeo4kuStXp5OjNblM4F256FEC6FYDNZOICVm+MNU2AQW3NJayD3h0zJg== X-Received: by 2002:adf:b067:: with SMTP id g36-v6mr28576120wra.128.1525682313446; Mon, 07 May 2018 01:38:33 -0700 (PDT) Received: from veci.piliscsaba.redhat.com (C2B0E321.catv.pool.telekom.hu. [194.176.227.33]) by smtp.gmail.com with ESMTPSA id h8-v6sm5908050wmc.16.2018.05.07.01.38.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 May 2018 01:38:32 -0700 (PDT) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 18/35] ovl: add lsattr/chattr support Date: Mon, 7 May 2018 10:37:50 +0200 Message-Id: <20180507083807.28792-19-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180507083807.28792-1-mszeredi@redhat.com> References: <20180507083807.28792-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 3a85bbfa266a..2028f6886649 100644 --- a/fs/overlayfs/file.c +++ b/fs/overlayfs/file.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include "overlayfs.h" @@ -302,6 +303,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, @@ -311,4 +388,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, };