Date: Tue, 15 Jun 2021 23:43:28 +0100 From: Steve O'Hara-Smith <steve@sohara.org> To: Kurt Hackenberg <kh@panix.com> 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>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 15 Jun 2021 14:49:57 -0400 Kurt Hackenberg <kh@panix.com> 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 <steve@sohara.org>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20210615234328.b2de12c70efe6efaee17ec1e>