From owner-freebsd-hackers Sat Jan 11 13: 6: 3 2003 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3046237B401 for ; Sat, 11 Jan 2003 13:06:02 -0800 (PST) Received: from harmony.village.org (rover.bsdimp.com [204.144.255.66]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4F23943EB2 for ; Sat, 11 Jan 2003 13:06:01 -0800 (PST) (envelope-from imp@bsdimp.com) Received: from localhost (warner@rover2.village.org [10.0.0.1]) by harmony.village.org (8.12.6/8.12.3) with ESMTP id h0BL5p1e001386; Sat, 11 Jan 2003 14:06:00 -0700 (MST) (envelope-from imp@bsdimp.com) Date: Sat, 11 Jan 2003 14:04:23 -0700 (MST) Message-Id: <20030111.140423.14801122.imp@bsdimp.com> To: rsharpe@richardsharpe.com Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: What prevents there from being a race with open(...,O_CREAT | O_EXCL,...) From: "M. Warner Losh" In-Reply-To: References: X-Mailer: Mew version 2.1 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In message: Richard Sharpe writes: : Hi, : : In looking at vn_open, I see that it calls namei and then a little while : later calls VOP_CREATE. : : If the user did open(..., ... O_CREAT | O_EXCL, ...), what prevents a race : where one process discovers that the name doesn't already exist but : another gets in and creates the name? The kernel locks out such possibilities. The 'create on open' stuff is an atomic operation. The O_EXCL precludes others from opening the file as well as forcing an error to be returned if someone else had just created the file an instance before the open happened. Warner To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message