public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Samuel Thibault <samuel.thibault@gnu.org>
To: Sergey Bugaev <bugaevc@gmail.com>
Cc: bug-hurd@gnu.org, libc-alpha@sourceware.org
Subject: Re: [PATCH v2 2/3] hurd: Implement O_TMPFILE
Date: Wed, 1 Feb 2023 23:34:11 +0100	[thread overview]
Message-ID: <20230201223411.hphlf5m47s37czz6@begin> (raw)
In-Reply-To: <20230130125216.6254-3-bugaevc@gmail.com>

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 <bugaevc@gmail.com>
> ---
>  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.

  reply	other threads:[~2023-02-01 22:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-12 11:46 [RFC PATCH 0/3] O_TMPFILE and SHM_ANON for the Hurd Sergey Bugaev
2022-12-12 11:46 ` [RFC PATCH 1/3] hurd: Consolidate file_name_lookup implementation Sergey Bugaev
2022-12-12 11:46 ` [RFC PATCH 2/3] hurd: Implement O_TMPFILE Sergey Bugaev
2023-01-29 23:25   ` Samuel Thibault
2023-01-30  9:53     ` Sergey Bugaev
2023-01-30  9:59       ` Samuel Thibault
2023-01-30 12:52         ` [PATCH v2 0/3] O_TMPFILE and SHM_ANON for the Hurd Sergey Bugaev
2023-01-30 12:52         ` [PATCH v2 1/3] hurd: Consolidate file_name_lookup implementation Sergey Bugaev
2023-02-01 19:06           ` Samuel Thibault
2023-01-30 12:52         ` [PATCH v2 2/3] hurd: Implement O_TMPFILE Sergey Bugaev
2023-02-01 22:34           ` Samuel Thibault [this message]
2023-01-30 12:52         ` [PATCH v2 3/3] hurd: Implement SHM_ANON Sergey Bugaev
2023-02-01 22:36           ` Samuel Thibault
2022-12-12 11:46 ` [RFC PATCH " Sergey Bugaev
2023-01-29 23:31 ` [RFC PATCH 0/3] O_TMPFILE and SHM_ANON for the Hurd Samuel Thibault

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230201223411.hphlf5m47s37czz6@begin \
    --to=samuel.thibault@gnu.org \
    --cc=bug-hurd@gnu.org \
    --cc=bugaevc@gmail.com \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).