From owner-freebsd-questions@freebsd.org Tue Jun 15 22:43:36 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 2BD896555E5 for ; Tue, 15 Jun 2021 22:43:36 +0000 (UTC) (envelope-from 4250.82.1d4d20004bafe8c.1454481cb1f1e5d487d869eaf5c6e173@email-od.com) Received: from s1-b0c6.socketlabs.email-od.com (s1-b0c6.socketlabs.email-od.com [142.0.176.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4G4Ndg3nZnz3k0W for ; Tue, 15 Jun 2021 22:43:35 +0000 (UTC) (envelope-from 4250.82.1d4d20004bafe8c.1454481cb1f1e5d487d869eaf5c6e173@email-od.com) DKIM-Signature: v=1; a=rsa-sha256; d=email-od.com;i=@email-od.com;s=dkim; c=relaxed/relaxed; q=dns/txt; t=1623797015; x=1626389015; h=content-transfer-encoding:content-type:mime-version:references:in-reply-to:message-id:subject:cc:to:from:date:x-thread-info; bh=3FIBWjNh1eKCo8Kw6SeQvco4pcwsWFP/yy4aVlapvyA=; b=JXFe4y2xs5DqC92tOmWBBOVGulL3B/xWgXXSaU3h0faJi5HRX22gUjapg5ccHRg9X8xhcT6PjZG0kcGKyzL2kL1wSuqNYK3si4oqibrdDt4BX/+/shAxX3Z6VPGMsivm2LVsN20LSYRFv5rEvi3VwlHxG/ZIMisKYa5jBWc3nps= X-Thread-Info: NDI1MC4xMi4xZDRkMjAwMDRiYWZlOGMuZnJlZWJzZC1xdWVzdGlvbnM9ZnJlZWJzZC5vcmc= Received: from r3.sg.in.socketlabs.com (r3.sg.in.socketlabs.com [142.0.179.13]) by mxsg2.email-od.com with ESMTP; Tue, 15 Jun 2021 18:43:31 -0400 Received: from smtp.lan.sohara.org (EMTPY [185.202.17.215]) by r3.sg.in.socketlabs.com with ESMTP(version=Tls12 cipher=Aes256 bits=256); Tue, 15 Jun 2021 18:43:30 -0400 Received: from [192.168.63.1] (helo=steve.lan.sohara.org) by smtp.lan.sohara.org with smtp (Exim 4.94 (FreeBSD)) (envelope-from ) id 1ltHmK-000PN8-UJ; Tue, 15 Jun 2021 23:43:29 +0100 Date: Tue, 15 Jun 2021 23:43:28 +0100 From: Steve O'Hara-Smith To: Kurt Hackenberg Cc: freebsd-questions@freebsd.org Subject: Re: Is a successful call to write(2) atomic? Message-Id: <20210615234328.b2de12c70efe6efaee17ec1e@sohara.org> In-Reply-To: <44e15917-0c92-08f2-462e-a1b3705f9afb@panix.com> References: <22440.1623740785@segfault.tristatelogic.com> <44e15917-0c92-08f2-462e-a1b3705f9afb@panix.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; amd64-portbld-freebsd12.1) X-Clacks-Overhead: "GNU Terry Pratchett" Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 4G4Ndg3nZnz3k0W X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=pass header.d=email-od.com header.s=dkim header.b=JXFe4y2x; dmarc=none; spf=pass (mx1.freebsd.org: domain of 4250.82.1d4d20004bafe8c.1454481cb1f1e5d487d869eaf5c6e173@email-od.com designates 142.0.176.198 as permitted sender) smtp.mailfrom=4250.82.1d4d20004bafe8c.1454481cb1f1e5d487d869eaf5c6e173@email-od.com X-Spamd-Result: default: False [-1.70 / 15.00]; ARC_NA(0.00)[]; RBL_DBL_DONT_QUERY_IPS(0.00)[142.0.176.198:from]; R_DKIM_ALLOW(-0.20)[email-od.com:s=dkim]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:142.0.176.0/20:c]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_LAST(0.00)[]; DMARC_NA(0.00)[sohara.org]; SPAMHAUS_ZRD(0.00)[142.0.176.198:from:127.0.2.255]; RCVD_COUNT_THREE(0.00)[4]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[email-od.com:+]; RCPT_COUNT_TWO(0.00)[2]; NEURAL_HAM_SHORT(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; FORGED_SENDER(0.30)[steve@sohara.org,4250.82.1d4d20004bafe8c.1454481cb1f1e5d487d869eaf5c6e173@email-od.com]; MIME_TRACE(0.00)[0:+]; SUBJECT_ENDS_QUESTION(1.00)[]; ASN(0.00)[asn:7381, ipnet:142.0.176.0/22, country:US]; FROM_NEQ_ENVFROM(0.00)[steve@sohara.org,4250.82.1d4d20004bafe8c.1454481cb1f1e5d487d869eaf5c6e173@email-od.com]; 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 22:43:36 -0000 On Tue, 15 Jun 2021 14:49:57 -0400 Kurt Hackenberg wrote: > No, write(2) is not guaranteed atomic, and that's not obvious. Probably > a lot of people have learned that the hard way. Strangely (after posting a confident no it isn't guaranteed) I noticed this in write(2) which implies that it is guaranteed to write a contiguous block (at least for seekable objects): -------------- On objects capable of seeking, the write() starts at a position given by the pointer associated with fd, see lseek(2). Upon return from write(), the pointer is incremented by the number of bytes which were written. -------------- I've always been sure it wasn't so this is something of a surprise. That being said there is no guarantee that another process won't see EOF at an intermediate point in the write and use that as the starting point for its write which would then cause corruption. -- Steve O'Hara-Smith