Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3281307ybt; Sat, 4 Jul 2020 11:40:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzWjHkD7qUlEkQfz3ZOGNuzXzoHpL92h8/ErVzFd6r/QuglGPL/99fH8MbC3Tj0ZJo3D9rE X-Received: by 2002:a05:6402:306a:: with SMTP id bs10mr38957123edb.51.1593888025256; Sat, 04 Jul 2020 11:40:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593888025; cv=none; d=google.com; s=arc-20160816; b=ESbrddu7ZE1pxMi97ztK3oqolcvdXOgMDzQESznVr44qGpmcXHilyF0CXXeWM2wNEX XMShZRrvhIMT+Az6IFZKw0WD8jGrh4ap2HdT6yzB5enNFOtewelK/ydA8Qp/P2BwRQRZ AH4Cy4W5FPKL1lKxcmtEKAKLBoWGvlv4wtATsXGRdfRMQmi8TPoyzk7lEBc1+/PBGr8R Olcqkofq7SlA41wWBi11LyE36BpwIPsD12yqxJhe6K9mVah490O9/bYoeOfefrd6y6Bq S2Ssm7p7w/dIlWOJ/gubYTKbJc3f4ol7T8LSz7pXhGlIPKvXhZrcnh29JtELpaGhUg23 06bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=/7ImKIfSgkzTRdy3VH0zTAz2g580OOvL55arrNBXHTU=; b=hFK0N6pWqgrVmalQL2JDBqyvVxmnz4Rw2Dzt6o++m1vXXnLwst8Ncu4gIB6PRuDulA kSnT55MFRg+QHCIGU8f+tQmOgmX0oBbcQO/qhYiiVKObHCzMpOZMGAhrZIegharEirv7 YBgSi8o+nZ40kzF/SppKzJq8zXoYEXMGpDdmk85I6O4zyDZCNOTTTnl9AbbYbmnXPMJj qs+QH9KegqRCDR/G4eAoy9EzNYRv8p9+hKtckcmnGFPYEXXi5/iTuhxd0RMGK0JWvXdE TKf3nlxXvIg+dXZrkq8GHZbbUhIN6RbU+914LLhDTMVrI2WLIzOTohQ12IbxQqbek4tx yICA== ARC-Authentication-Results: i=1; mx.google.com; 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 k4si10113634eds.446.2020.07.04.11.40.02; Sat, 04 Jul 2020 11:40:25 -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; 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 S1727118AbgGDSft (ORCPT + 99 others); Sat, 4 Jul 2020 14:35:49 -0400 Received: from mail-ot1-f66.google.com ([209.85.210.66]:44392 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726669AbgGDSft (ORCPT ); Sat, 4 Jul 2020 14:35:49 -0400 Received: by mail-ot1-f66.google.com with SMTP id 5so26811736oty.11; Sat, 04 Jul 2020 11:35:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/7ImKIfSgkzTRdy3VH0zTAz2g580OOvL55arrNBXHTU=; b=IGW+oc//6FqbAPsbOqk43/UADR7NfQF2zRMJu7TtS9T8aI5KZ2qdW1qaLYpQ3uFcN2 +wc47ZbLqz1SrwXL7DYYuzMxXT0BF5qL2R8kfaMU1c/RnYW2TVUOBfSrgk52nYZOIgfx s+g4YHEDULSwd2ljSuw05E1FGaliYbPsZTuwWBGdcOcCMLqJ3e/Ky2A8NZHyhsatmuWn de+DJdMkunGgBt+dQB005ezTAKSd5iZ9UhV2QfnZLtcJ/4ny0QEUpJ3qa9mn//OF/O4t CMOmQa7PGTldu7B66uWKDfTwMGTCY3MIdxk0PJowl6rdKz5oTDct3RU7MMhJOqksWAUO rZlw== X-Gm-Message-State: AOAM531YF1oxC5uU4OZFnsyjd+1KnBPMOsuWeJL0k2KXSh4V0uGpwsV4 OI9TkFjeUFjYsbYWsnNnt917E9H8HWPHX9s0jnBrqqGo X-Received: by 2002:a9d:1b0d:: with SMTP id l13mr2983524otl.145.1593887747708; Sat, 04 Jul 2020 11:35:47 -0700 (PDT) MIME-Version: 1.0 References: <20200704140250.423345-1-gregkh@linuxfoundation.org> <20200704140250.423345-2-gregkh@linuxfoundation.org> In-Reply-To: <20200704140250.423345-2-gregkh@linuxfoundation.org> From: Geert Uytterhoeven Date: Sat, 4 Jul 2020 20:35:36 +0200 Message-ID: Subject: Re: [PATCH 1/3] readfile: implement readfile syscall To: Greg Kroah-Hartman Cc: Al Viro , "Michael Kerrisk (man-pages)" , Shuah Khan , Linux API , Linux FS Devel , Linux Kernel Mailing List , linux-man@vger.kernel.org, "open list:KERNEL SELFTEST FRAMEWORK" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Greg, On Sat, Jul 4, 2020 at 4:05 PM Greg Kroah-Hartman wrote: > 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 Thanks for your patch! > --- a/fs/open.c > +++ b/fs/open.c > +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); Should there be a way for the user to be informed that the file doesn't fit in the provided buffer (.e.g. -EFBIG)? > + > + filp_close(file, NULL); > + > + return retval; > +} Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds