Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp708262pxb; Wed, 20 Jan 2021 19:26:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJyA4E3uNs8UNHkd9oiIAck9JtQlmaVvgvn+spDoPDjhQ87dOYDnFyl2fbgkDdASsYLfExaK X-Received: by 2002:a05:6402:d1:: with SMTP id i17mr452382edu.85.1611199569444; Wed, 20 Jan 2021 19:26:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611199569; cv=none; d=google.com; s=arc-20160816; b=jN65Xspw1lQdSYjIgWHkBXSb2WFFP0N1GSwuXlgBqnPjE44VL13hoeSy86KuxlakVR DGUhQ2bTi+kSQEysIhnPGiF3fIgnx3aDoQFZy65EhvrnTlDv96XbDdqe5s0nSK9PfL6U msauNaF/AaBPULeQ1LN1wynvq04T50V5QBy66wWRPjtGxyZvCobz3uIvcTO9PVZfh8gz dx7tTNveXJqsvyh4Ff3eFPCnZJK1JL8uhfOaiDEYd2uxPdo7yu7bnb61rpZWZE01Nl8L 4R0gEcOhP40b8lYH7qzWJCIyBtpEkeCF8dBDcN+cYSa3z6dSuA1+XhGYbSHech365cHT fGvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=dhz2YVwViwTzCs4U4eXHuTd8zwhLvzz0i/pTnpmwoe0=; b=KQmE+cFyK2vxOKLCF4ooFC/GtgZVZwpVE8Ai4OVEQifDkih9+JH1t8kDwOiT5kQ/yx 9/Yt+ep0EAOWHQK4nvKZKbuoQiBHovd4y1efxMIM2ia239vzxfltGIy1MNkmUrAaRQcI 5cQOfYsyXZzN26reR3JSVga25FhK36KUnw2U/NXymVEQmwF1rewSL1PjKNTTB70uNlX4 5ERvPS5iyrQYJB9273gzoxofexB1yZtcYCFEXyX4LkcrVoCQEVVtjZ0K2DHm+mcNCamX B2cNn8iINVrGdKt6fAzwoB+put4k8n5hLGipIEuEjkyh0FY9STtzEy/g1M4m/O1vhoxS z2Fg== 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 ov19si1327900ejb.684.2021.01.20.19.25.46; Wed, 20 Jan 2021 19:26:09 -0800 (PST) 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 S2393049AbhAUB7k (ORCPT + 99 others); Wed, 20 Jan 2021 20:59:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392612AbhAUBq7 (ORCPT ); Wed, 20 Jan 2021 20:46:59 -0500 Received: from zeniv-ca.linux.org.uk (zeniv-ca.linux.org.uk [IPv6:2607:5300:60:148a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83A52C061575 for ; Wed, 20 Jan 2021 17:45:55 -0800 (PST) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94 #2 (Red Hat Linux)) id 1l2P2O-0043lS-5S; Thu, 21 Jan 2021 01:45:28 +0000 Date: Thu, 21 Jan 2021 01:45:28 +0000 From: Al Viro To: Linus Torvalds Cc: Christoph Hellwig , Johannes Berg , Oliver Giles , Linux Kernel Mailing List , Greg Kroah-Hartman Subject: Re: Splicing to/from a tty Message-ID: <20210121014528.GG740243@zeniv-ca> References: <20210118193457.GA736435@zeniv-ca> <20210118195400.GC736435@zeniv-ca> <20210120162608.GB740243@zeniv-ca> <20210120191116.GC740243@zeniv-ca> <20210120231439.GE740243@zeniv-ca> <20210121003835.GF740243@zeniv-ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 20, 2021 at 05:04:17PM -0800, Linus Torvalds wrote: > The whole point of O_APPEND is that the position shouldn't matter. > > And the whole point of "pwrite()" is that you specify a position. > > So the two just do not go together - although we may have legacy > issues, of course. Our pwrite(2): BUGS POSIX requires that opening a file with the O_APPEND flag should have no effect on the location at which pwrite() writes data. However, on Linux, if a file is opened with O_APPEND, pwrite() appends data to the end of the file, regardless of the value of offset. POSIX pwrite(2): The pwrite() function shall be equivalent to write(), except that it writes into a given position and does not change the file offset (regardless of whether O_APPEND is set). The first three arguments to pwrite() are the same as write() with the addition of a fourth argument offset for the desired position inside the file. An attempt to perform a pwrite() on a file that is incapable of seeking shall result in an error. I don't believe that we could change behaviour of our pwrite(2) without breaking userland, even if we wanted to. It's been that way since 2.1.60 when pwrite() had been first introduced - 23 years ago is more than enough to have it cast in stone. We do allow pwrite(2) with O_APPEND and on such descriptors it acts like write(2) on the same. > Now, splice() is able to do *both* write() and pwrite(), because > unlike pwrite() it doesn't take a "pos" argument, it takes a _pointer_ > to pos. So with a NULL pointer, it's like read/write, and with a > non-NULL pointer it is like pread/pwrite. > > So I do think that "splice with non-NULL off_out and O_APPEND" should > cause an error in general. splice() triggers an error for seekable destination with O_APPEND and with NULL off_out. Same for splice() to socket with fcntl(sock_fd, F_SETFL, O_APPEND); done first. > Honestly, I don't think it's a huge deal. O_APPEND isn't that > interesting, but I do hope that if we allow O_APPEND and a file > position, then O_APPEND always overrides it. It does, when it is allowed.