From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 22D1F3858D3C for ; Wed, 1 Feb 2023 22:34:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 22D1F3858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gnu.org Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNLgF-0004sf-Fm; Wed, 01 Feb 2023 17:34:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=In-Reply-To:MIME-Version:References:Subject:To:From: Date; bh=JarE7XgCCA/5BArJEX9x+nvohR0YKC6J2dpLwRomwcE=; b=hVnV8UkRgY1LiN7VTtpP UX9Dv/FqhW/p+ZkloNQ+ixQWI7de3M7M++spU/SCXV4hN/d5mVe8vT59AGItrRXHczGdG+l28ItXa GOuc4f3A30C9TmLvIkPAbcDRpos4PwS2x6+tPEJU7i3ruqi8ctvMFegQ6cTgbvsfETmx6LK1b3uSJ mf6epbtf0hzEfbgRXPq1T2+WskrIDN6kyv2+i7rz+LSeAMeoqPwtEJ0gVAoWMJ1VkAAnmMpVg9e/M xPaCO5xuxDysZbp/x9QpChbMk8/qwY9fQ5ZmOjyQPCrDUf18zfCBkOjeRM6vaUmjLUPlOMY8fEKVq fScx4/92wNTgtg==; Received: from lfbn-bor-1-1163-184.w92-158.abo.wanadoo.fr ([92.158.138.184] helo=begin) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pNLgE-0002gd-EY; Wed, 01 Feb 2023 17:34:15 -0500 Received: from samy by begin with local (Exim 4.96) (envelope-from ) id 1pNLgB-00Bvo1-0G; Wed, 01 Feb 2023 23:34:11 +0100 Date: Wed, 1 Feb 2023 23:34:11 +0100 From: Samuel Thibault To: Sergey Bugaev Cc: bug-hurd@gnu.org, libc-alpha@sourceware.org Subject: Re: [PATCH v2 2/3] hurd: Implement O_TMPFILE Message-ID: <20230201223411.hphlf5m47s37czz6@begin> Mail-Followup-To: Sergey Bugaev , bug-hurd@gnu.org, libc-alpha@sourceware.org References: <20230130095907.mlvp3pbmtarkhhql@begin> <20230130125216.6254-3-bugaevc@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230130125216.6254-3-bugaevc@gmail.com> Organization: I am not organized User-Agent: NeoMutt/20170609 (1.8.3) X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Applied, thanks! Sergey Bugaev, le lun. 30 janv. 2023 15:52:15 +0300, a ecrit: > This is a flag that causes open () to create a new, unnamed file in the > same filesystem as the given directory. The file descriptor can be > simply used in the creating process as a temporary file, or shared with > children processes via fork (), or sent over a Unix socket. The file can > be left anonymous, in which case it will be deleted from the backing > file system once all copies of the file descriptor are closed, or given > a permanent name with a linkat () call, such as the following: > > int fd = open ("/tmp", O_TMPFILE | O_RDWR, 0700); > /* Do something with the file... */ > linkat (fd, "", AT_FDCWD, "/tmp/filename", AT_EMPTY_PATH); > > In between creating the file and linking it to the file system, it is > possible to set the file content, mode, ownership, author, and other > attributes, so that the file visibly appears in the file system (perhaps > replacing another file) atomically, with all of its attributes already > set up. > > The Hurd support for O_TMPFILE directly exposes the dir_mkfile RPC to > user programs. Previously, dir_mkfile was used by glibc internally, in > particular for implementing tmpfile (), but not exposed to user programs > through a Unix-level API. > > O_TMPFILE was initially introduced by Linux. This implementation is > intended to be compatible with the Linux implementation, except that the > O_EXCL flag is not given the special meaning when used together with > O_TMPFILE, unlike on Linux. > > Signed-off-by: Sergey Bugaev > --- > hurd/lookup-at.c | 21 +++++++++++++++++++++ > sysdeps/mach/hurd/bits/fcntl.h | 4 ++++ > 2 files changed, 25 insertions(+) > > diff --git a/hurd/lookup-at.c b/hurd/lookup-at.c > index 25dab5a1..88c83779 100644 > --- a/hurd/lookup-at.c > +++ b/hurd/lookup-at.c > @@ -29,6 +29,7 @@ __file_name_lookup_at (int fd, int at_flags, > error_t err; > file_t result; > int empty = at_flags & AT_EMPTY_PATH; > + int orig_flags; > > at_flags &= ~AT_EMPTY_PATH; > > @@ -53,6 +54,10 @@ __file_name_lookup_at (int fd, int at_flags, > return err ? (__hurd_dfail (fd, err), MACH_PORT_NULL) : result; > } > > + orig_flags = flags; > + if (flags & O_TMPFILE) > + flags = O_DIRECTORY; > + > if (fd == AT_FDCWD || file_name[0] == '/') > { > err = __hurd_file_name_lookup (&_hurd_ports_use, &__getdport, 0, > @@ -90,6 +95,22 @@ __file_name_lookup_at (int fd, int at_flags, > } > } > > + if (orig_flags & O_TMPFILE) > + { > + /* What we have looked up is not the file itself, but actually > + the directory to create the file in. Do that now. */ > + file_t dir = result; > + > + err = __dir_mkfile (dir, orig_flags & ~(O_TMPFILE | O_DIRECTORY), > + mode, &result); > + __mach_port_deallocate (__mach_task_self (), dir); > + if (err) > + { > + __hurd_fail (err); > + return MACH_PORT_NULL; > + } > + } > + > return result; > } > > diff --git a/sysdeps/mach/hurd/bits/fcntl.h b/sysdeps/mach/hurd/bits/fcntl.h > index 970f79b8..c24a819e 100644 > --- a/sysdeps/mach/hurd/bits/fcntl.h > +++ b/sysdeps/mach/hurd/bits/fcntl.h > @@ -123,6 +123,10 @@ > # define O_CLOEXEC 0x00400000 /* Set FD_CLOEXEC. */ > #endif > > +#ifdef __USE_GNU > +# define O_TMPFILE 0x00800000 /* Make a new unnamed file. */ > +#endif > + > > /* Controlling terminal flags. These are understood only by `open', > and are not preserved once the file has been opened. */ > -- > 2.39.1 > -- Samuel --- Pour une évaluation indépendante, transparente et rigoureuse ! Je soutiens la Commission d'Évaluation de l'Inria.