Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3125189ybt; Sat, 4 Jul 2020 07:03:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwB0msOaSPQVHi18zChcATpc5Oxn6Ceo6PXCHmpq3TPAon0N+EbnUeDRsbc2+UHd6PFCy3O X-Received: by 2002:aa7:c3d8:: with SMTP id l24mr38648521edr.97.1593871426435; Sat, 04 Jul 2020 07:03:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593871426; cv=none; d=google.com; s=arc-20160816; b=lShlX4WySWPKzuybI7flMSyq76Z+M8AxnUAjz7rBMJzqBjPqosn+SkvYmPeI5pYdTt Lc+qnP0wQNcxei6fF5S1qFBluMPpyZtFph9GB+/nMrlhcaC9397cZBE1BLXA0GU+gNr/ zKpXV85CvRS9Bj8jKY+Mm/VNVW7or9aTTt0Vbegu8vDrZccbPAqpcXtny7BgwoBeU1gt gWLogxZTtz88dm2euGdDJpLznLrpwDcItITL4Ltpw9laoYKhIlAq/Uhkaufaw4Y52xZK ZqJqJuekjV97hObmZT/pbBdC2HKsRLXDwqzkADZ4ueN9PiB3XUu2blCTnFu7/gLky20j IpOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=bQVAMroH2yWQQtQ7pk9TpZlzCGZTzXmSEy7P47Crt3A=; b=0b5UNaHJJIxnrlSuy0Kms/JHW8Fnprqut5Rz1PKsDyY26GzHA3DpDTPg854LQs4Ulh Ocj7vKD2n4BZb7Lv7UfXPEYUFdy7dT8wPxSUWqiqcBO7VlwX5J54OnIgthFlDoV9HTCa LQzkIITsgkla+ZKi4NNQlYrvHg/mXpL1MqKFLi5+5gny84A+Tcak0gHVishcE9nGBPtH vvsUC6BNC6FYs+jzhl9adzCAMmoRlWtsekLvC0pA9yjrAXL5Y8+/AYVCtV+KER05/Ri9 DQxYkgFQoi4bQeLFkeMCkQp7leBuMzgHBs23olRKzXKF23IbyLbBnX7OHSkOCk/KlfiD itpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cpZ0pA1T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t26si10121138edt.427.2020.07.04.07.03.11; Sat, 04 Jul 2020 07:03:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cpZ0pA1T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727972AbgGDODB (ORCPT + 99 others); Sat, 4 Jul 2020 10:03:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:51448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726911AbgGDODB (ORCPT ); Sat, 4 Jul 2020 10:03:01 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DB100208E4; Sat, 4 Jul 2020 14:02:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593871380; bh=xs1zP9GNU8J5zuCbFQztvpkhuGbsiHC1+/zg9xzu7G4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cpZ0pA1TFa+d/hZn3AL6AcUd7ZENK1xNVj8odkHqPPyY/k78tHYQYezmJxQjUanaf yaqnmszrddcDQ2uX3TnpoOqWWBYiP7nlYrxBEatzLVpvJRmuULaSskUTC2oEgnck9s x2jmAwrItpBJc/andHUDEUToFaLwXQ7KwFaJrN7M= From: Greg Kroah-Hartman To: viro@zeniv.linux.org.uk, mtk.manpages@gmail.com, shuah@kernel.org, linux-api@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-man@vger.kernel.org, linux-kselftest@vger.kernel.org, Greg Kroah-Hartman Subject: [PATCH 1/3] readfile: implement readfile syscall Date: Sat, 4 Jul 2020 16:02:47 +0200 Message-Id: <20200704140250.423345-2-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200704140250.423345-1-gregkh@linuxfoundation.org> References: <20200704140250.423345-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It's a tiny syscall, meant to allow a user to do a single "open this file, read into this buffer, and close the file" all in a single shot. Should be good for reading "tiny" files like sysfs, procfs, and other "small" files. There is no restarting the syscall, this is a "simple" syscall, with the attempt to make reading "simple" files easier with less syscall overhead. Cc: Alexander Viro Signed-off-by: Greg Kroah-Hartman --- fs/open.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/fs/open.c b/fs/open.c index 6cd48a61cda3..4469faa9379c 100644 --- a/fs/open.c +++ b/fs/open.c @@ -1370,3 +1370,53 @@ int stream_open(struct inode *inode, struct file *filp) } EXPORT_SYMBOL(stream_open); + +static struct file *readfile_open(int dfd, const char __user *filename, + struct open_flags *op) +{ + struct filename *tmp; + struct file *f; + + tmp = getname(filename); + if (IS_ERR(tmp)) + return (struct file *)tmp; + + f = do_filp_open(dfd, tmp, op); + if (!IS_ERR(f)) + fsnotify_open(f); + + putname(tmp); + return f; +} + +SYSCALL_DEFINE5(readfile, int, dfd, const char __user *, filename, + char __user *, buffer, size_t, bufsize, int, flags) +{ + struct open_flags op; + struct open_how how; + struct file *file; + loff_t pos = 0; + int retval; + + /* only accept a small subset of O_ flags that make sense */ + if ((flags & (O_NOFOLLOW | O_NOATIME)) != flags) + return -EINVAL; + + /* add some needed flags to be able to open the file properly */ + flags |= O_RDONLY | O_LARGEFILE; + + how = build_open_how(flags, 0000); + retval = build_open_flags(&how, &op); + if (retval) + return retval; + + file = readfile_open(dfd, filename, &op); + if (IS_ERR(file)) + return PTR_ERR(file); + + retval = vfs_read(file, buffer, bufsize, &pos); + + filp_close(file, NULL); + + return retval; +} -- 2.27.0