diff options
author | Sergey Bugaev <bugaevc@gmail.com> | 2023-01-30 15:52:15 +0300 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2023-02-01 23:32:21 +0100 |
commit | 65392c84782a53b0d7705ca0207c95c3da41c7dc (patch) | |
tree | ace56ea31baef53a4e2d7b5f2ff412664bbada3e /sysdeps/mach | |
parent | d011ab5708c2be4e2cc7eb8851c9e2c614410bd3 (diff) | |
download | glibc-65392c84782a53b0d7705ca0207c95c3da41c7dc.zip glibc-65392c84782a53b0d7705ca0207c95c3da41c7dc.tar.gz glibc-65392c84782a53b0d7705ca0207c95c3da41c7dc.tar.bz2 |
hurd: Implement O_TMPFILE
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>
Message-Id: <20230130125216.6254-3-bugaevc@gmail.com>
Diffstat (limited to 'sysdeps/mach')
-rw-r--r-- | sysdeps/mach/hurd/bits/fcntl.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/sysdeps/mach/hurd/bits/fcntl.h b/sysdeps/mach/hurd/bits/fcntl.h index 970f79b..c24a819 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. */ |