From patchwork Wed Nov 6 09:15:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sascha Hauer X-Patchwork-Id: 1190180 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FksJOXCX"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 477LWJ6M8Sz9sPk for ; Wed, 6 Nov 2019 20:16:28 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MZUtw5i0v0zcXAXe0lGEVjjBxTlO/zgHuQ0Y9VAXnAU=; b=FksJOXCXBNJtFX gRIe+5Al1+fO5PjXCtvFXx1Tkl5wUMPeOdgKpF47gFkSqsUb4ZBAteHgYqmz6geLYHXdVq3mT4tgE 1Hp0P2UUmsbdAf43wT+Q5rLuM6a6LFwMAhKYx22xUbBp882p0a/qODTktoQQJ85xyrOzw4YIOGeMh KF81YRreMs8j6IEhd2H6rz21jqYGtfoc+xR0bSVufgqvKRcMEK9aioqzHGA39iHq3v9mjwiW5vtoW I9ExhMOO+H5e77NeEDhlAXju6CA/0aKwKzOk/GQfYqL1527gNyHvoNETmOAag+1/uOSQnL8L+XcwJ /qX/g8NP6DdZ08fZ1reQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iSHQD-0001YC-8R; Wed, 06 Nov 2019 09:16:13 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iSHPp-000179-Ti for linux-mtd@lists.infradead.org; Wed, 06 Nov 2019 09:15:51 +0000 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iSHPg-0002eY-I9; Wed, 06 Nov 2019 10:15:40 +0100 Received: from sha by dude.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1iSHPe-0000Au-If; Wed, 06 Nov 2019 10:15:38 +0100 From: Sascha Hauer To: linux-fsdevel@vger.kernel.org Subject: [PATCH 3/7] ubifs: Add support for FS_IOC_FS[SG]ETXATTR ioctls Date: Wed, 6 Nov 2019 10:15:33 +0100 Message-Id: <20191106091537.32480-4-s.hauer@pengutronix.de> X-Mailer: git-send-email 2.24.0.rc1 In-Reply-To: <20191106091537.32480-1-s.hauer@pengutronix.de> References: <20191106091537.32480-1-s.hauer@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-mtd@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191106_011549_973894_B787ECB1 X-CRM114-Status: GOOD ( 16.10 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , Sascha Hauer , linux-mtd@lists.infradead.org, kernel@pengutronix.de, Jan Kara Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The FS_IOC_FS[SG]ETXATTR ioctls are an alternative to FS_IOC_[GS]ETFLAGS with additional features. This patch adds support for these ioctls. Signed-off-by: Sascha Hauer --- fs/ubifs/ioctl.c | 103 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 98 insertions(+), 5 deletions(-) diff --git a/fs/ubifs/ioctl.c b/fs/ubifs/ioctl.c index 8230dba5fd74..533df56beab4 100644 --- a/fs/ubifs/ioctl.c +++ b/fs/ubifs/ioctl.c @@ -95,9 +95,46 @@ static int ubifs2ioctl(int ubifs_flags) return ioctl_flags; } -static int setflags(struct file *file, int flags) +/* Transfer xflags flags to internal */ +static inline unsigned long ubifs_xflags_to_iflags(__u32 xflags) { - int oldflags, err, release; + unsigned long iflags = 0; + + if (xflags & FS_XFLAG_SYNC) + iflags |= UBIFS_APPEND_FL; + if (xflags & FS_XFLAG_IMMUTABLE) + iflags |= UBIFS_IMMUTABLE_FL; + if (xflags & FS_XFLAG_APPEND) + iflags |= UBIFS_APPEND_FL; + + return iflags; +} + +/* Transfer internal flags to xflags */ +static inline __u32 ubifs_iflags_to_xflags(unsigned long flags) +{ + __u32 xflags = 0; + + if (flags & UBIFS_APPEND_FL) + xflags |= FS_XFLAG_SYNC; + if (flags & UBIFS_IMMUTABLE_FL) + xflags |= FS_XFLAG_IMMUTABLE; + if (flags & UBIFS_APPEND_FL) + xflags |= FS_XFLAG_APPEND; + + return xflags; +} + +static void ubifs_fill_fsxattr(struct inode *inode, struct fsxattr *fa) +{ + struct ubifs_inode *ui = ubifs_inode(inode); + + simple_fill_fsxattr(fa, ubifs_iflags_to_xflags(ui->flags)); +} + +static int setflags(struct file *file, int flags, struct fsxattr *fa) +{ + int ubi_flags, oldflags, err, release; struct inode *inode = file_inode(file); struct ubifs_inode *ui = ubifs_inode(inode); struct ubifs_info *c = inode->i_sb->s_fs_info; @@ -110,6 +147,11 @@ static int setflags(struct file *file, int flags) if (!inode_owner_or_capable(inode)) return -EACCES; + if (fa) + ubi_flags = ubifs_xflags_to_iflags(fa->fsx_xflags); + else + ubi_flags = ioctl2ubifs(flags); + /* * Make sure the file-system is read-write and make sure it * will not become read-only while we are changing the flags. @@ -126,11 +168,21 @@ static int setflags(struct file *file, int flags) mutex_lock(&ui->ui_mutex); oldflags = ubifs2ioctl(ui->flags); - err = vfs_ioc_setflags_prepare(inode, oldflags, flags); + err = vfs_ioc_setflags_prepare(inode, oldflags, ubifs2ioctl(ubi_flags)); if (err) goto out_unlock; - ui->flags = ioctl2ubifs(flags); + if (fa) { + struct fsxattr old_fa; + + ubifs_fill_fsxattr(inode, &old_fa); + + err = vfs_ioc_fssetxattr_check(inode, &old_fa, fa); + if (err) + goto out_unlock; + } + + ui->flags = ubi_flags; ubifs_set_inode_flags(inode); inode->i_ctime = current_time(inode); release = ui->dirty; @@ -156,6 +208,41 @@ static int setflags(struct file *file, int flags) return err; } +static int ubifs_ioc_fsgetxattr(struct file *file, void __user *arg) +{ + struct inode *inode = file_inode(file); + struct fsxattr fa; + + ubifs_fill_fsxattr(inode, &fa); + + if (copy_to_user(arg, &fa, sizeof(fa))) + return -EFAULT; + + return 0; +} + +static int check_xflags(unsigned int flags) +{ + if (flags & ~(FS_XFLAG_SYNC | FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND)) + return -EOPNOTSUPP; + return 0; +} + +static int ubifs_ioc_fssetxattr(struct file *file, const void __user *arg) +{ + struct fsxattr fa; + int err; + + if (copy_from_user(&fa, (struct fsxattr __user *)arg, sizeof(fa))) + return -EFAULT; + + err = check_xflags(fa.fsx_xflags); + if (err) + return err; + + return setflags(file, 0, &fa); +} + long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { int flags, err; @@ -179,7 +266,7 @@ long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) flags &= ~FS_DIRSYNC_FL; - return setflags(file, flags); + return setflags(file, flags, NULL); } case FS_IOC_SET_ENCRYPTION_POLICY: { struct ubifs_info *c = inode->i_sb->s_fs_info; @@ -208,6 +295,12 @@ long ubifs_ioctl(struct file *file, unsigned int cmd, unsigned long arg) case FS_IOC_GET_ENCRYPTION_KEY_STATUS: return fscrypt_ioctl_get_key_status(file, (void __user *)arg); + case FS_IOC_FSGETXATTR: + return ubifs_ioc_fsgetxattr(file, (void __user *)arg); + + case FS_IOC_FSSETXATTR: + return ubifs_ioc_fssetxattr(file, (const void __user *)arg); + default: return -ENOTTY; }