From owner-freebsd-questions@freebsd.org Tue Jun 15 21:40:39 2021 Return-Path: Delivered-To: freebsd-questions@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id CFB8A653F3F for ; Tue, 15 Jun 2021 21:40:39 +0000 (UTC) (envelope-from rfg@tristatelogic.com) Received: from outgoing.tristatelogic.com (segfault.tristatelogic.com [69.62.255.118]) by mx1.freebsd.org (Postfix) with ESMTP id 4G4MF26mcPz3PWR for ; Tue, 15 Jun 2021 21:40:38 +0000 (UTC) (envelope-from rfg@tristatelogic.com) Received: by segfault.tristatelogic.com (Postfix, from userid 1237) id 108CE4E657; Tue, 15 Jun 2021 14:40:38 -0700 (PDT) From: "Ronald F. Guilmette" To: freeBSD Mailing List Subject: Re: Is a successful call to write(2) atomic? In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <25765.1623793237.1@segfault.tristatelogic.com> Content-Transfer-Encoding: quoted-printable Date: Tue, 15 Jun 2021 14:40:38 -0700 Message-ID: <25766.1623793238@segfault.tristatelogic.com> X-Rspamd-Queue-Id: 4G4MF26mcPz3PWR X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of rfg@tristatelogic.com designates 69.62.255.118 as permitted sender) smtp.mailfrom=rfg@tristatelogic.com X-Spamd-Result: default: False [-2.30 / 15.00]; ARC_NA(0.00)[]; RBL_DBL_DONT_QUERY_IPS(0.00)[69.62.255.118:from]; NEURAL_HAM_MEDIUM(-1.00)[-0.999]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_SPF_ALLOW(-0.20)[+mx]; MIME_GOOD(-0.10)[text/plain]; DMARC_NA(0.00)[tristatelogic.com]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCPT_COUNT_ONE(0.00)[1]; SPAMHAUS_ZRD(0.00)[69.62.255.118:from:127.0.2.255]; TO_DN_ALL(0.00)[]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:14051, ipnet:69.62.128.0/17, country:US]; SUBJECT_ENDS_QUESTION(1.00)[]; MAILMAN_DEST(0.00)[freebsd-questions] X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Jun 2021 21:40:39 -0000 In message Michael Schuster wrote: >Let's take a step back: an atomic write() either writes everything or >nothing - and that's all. Well, it *could* just do a partial write, and then return a short write count, but my code checks for that and causes the process to die a horrible and abundantly noisy death if it ever happens. (In practice and over many many runs, it has not happened even once.) Anyway, my reading of the man page is that the only cases where write() = might return a short count is when the FD being written to is some sort of a network socket, which is not relevant in this case (because I am writing to a disk file). >There's nothing in that claim that says >"everything must be in a contiguous block", nor, that all the data must b= e >written in a single "operation" by the underlying system. Indeed, and arguably the kernel *must* break up a buffer full of data that was passed in a single call to write() into multple parts in some instances, e.g. when writing to either an SSD or a good old "spinning rust" hard drive would cross a physical block boundary. My hope, of course, is that the entire buffer passed to write() would stil= l end up being written contiguously on the physical medium. >So after consideration I don't think the observed behaviour is violating >the claim that write() is atomic - I welcome correction, of course :-) I frankly don't know. It seems highly likely to me that Posix is most probably very precise in defining the behavior, but one would have to wade through a hundred pages or so to find the exact and crisp answer. Regards, rfg