Browse Source

open: Add support for O_TMPFILE

Since Linux 3.11, O_TMPFILE allows to create unnamed files that can be
linked later on.  It is internally defined as (O_TMPFILE | O_DIRECTORY)
to make it fail on old kernels.

Copying definitions from glibc for O_TMPFILE is not enough to support
O_TMPFILE; The open() wrapper also need to pass the mode when the flag
contains O_TMPFILE, otherwise, it will pass mode 000 which will succeed
but yield unexpected results.

openat() is curiously not affected since it passes the mode
unconditionally..

Signed-off-by: Nicolas Cavallari <nicolas.cavallari@green-communications.fr>
Nicolas Cavallari 3 years ago
parent
commit
221f2898b9
34 changed files with 37 additions and 5 deletions
  1. 3 2
      include/fcntl.h
  2. 1 0
      libc/sysdeps/linux/aarch64/bits/fcntl.h
  3. 1 0
      libc/sysdeps/linux/alpha/bits/fcntl.h
  4. 1 0
      libc/sysdeps/linux/arc/bits/fcntl.h
  5. 1 0
      libc/sysdeps/linux/arm/bits/fcntl.h
  6. 1 0
      libc/sysdeps/linux/avr32/bits/fcntl.h
  7. 1 0
      libc/sysdeps/linux/bfin/bits/fcntl.h
  8. 1 0
      libc/sysdeps/linux/c6x/bits/fcntl.h
  9. 1 1
      libc/sysdeps/linux/common/open.c
  10. 2 2
      libc/sysdeps/linux/common/open64.c
  11. 1 0
      libc/sysdeps/linux/cris/bits/fcntl.h
  12. 1 0
      libc/sysdeps/linux/csky/bits/fcntl.h
  13. 1 0
      libc/sysdeps/linux/frv/bits/fcntl.h
  14. 1 0
      libc/sysdeps/linux/h8300/bits/fcntl.h
  15. 1 0
      libc/sysdeps/linux/hppa/bits/fcntl.h
  16. 1 0
      libc/sysdeps/linux/i386/bits/fcntl.h
  17. 1 0
      libc/sysdeps/linux/ia64/bits/fcntl.h
  18. 1 0
      libc/sysdeps/linux/kvx/bits/fcntl.h
  19. 1 0
      libc/sysdeps/linux/lm32/bits/fcntl.h
  20. 1 0
      libc/sysdeps/linux/m68k/bits/fcntl.h
  21. 1 0
      libc/sysdeps/linux/metag/bits/fcntl.h
  22. 1 0
      libc/sysdeps/linux/microblaze/bits/fcntl.h
  23. 1 0
      libc/sysdeps/linux/mips/bits/fcntl.h
  24. 1 0
      libc/sysdeps/linux/nds32/bits/fcntl.h
  25. 1 0
      libc/sysdeps/linux/nios2/bits/fcntl.h
  26. 1 0
      libc/sysdeps/linux/or1k/bits/fcntl.h
  27. 1 0
      libc/sysdeps/linux/powerpc/bits/fcntl.h
  28. 1 0
      libc/sysdeps/linux/riscv64/bits/fcntl.h
  29. 1 0
      libc/sysdeps/linux/sh/bits/fcntl.h
  30. 1 0
      libc/sysdeps/linux/sparc/bits/fcntl.h
  31. 1 0
      libc/sysdeps/linux/sparc64/bits/fcntl.h
  32. 1 0
      libc/sysdeps/linux/tile/bits/fcntl.h
  33. 1 0
      libc/sysdeps/linux/x86_64/bits/fcntl.h
  34. 1 0
      libc/sysdeps/linux/xtensa/bits/fcntl.h

+ 3 - 2
include/fcntl.h

@@ -104,8 +104,9 @@ libc_hidden_proto(fcntl64)
 #endif
 
 /* Open FILE and return a new file descriptor for it, or -1 on error.
-   OFLAG determines the type of access used.  If O_CREAT is on OFLAG,
-   the third argument is taken as a `mode_t', the mode of the created file.
+   OFLAG determines the type of access used.  If O_CREAT or O_TMPFILE
+   is on OFLAG, the third argument is taken as a `mode_t', the mode of
+   the created file.
 
    This function is a cancellation point and therefore not marked with
    __THROW.  */

+ 1 - 0
libc/sysdeps/linux/aarch64/bits/fcntl.h

@@ -52,6 +52,7 @@
 # define O_DIRECT	0200000
 # define O_NOATIME     01000000
 # define O_PATH       010000000
+# define O_TMPFILE    020040000
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.

+ 1 - 0
libc/sysdeps/linux/alpha/bits/fcntl.h

@@ -54,6 +54,7 @@
 # define O_DIRECT      02000000 /* Direct disk access.  */
 # define O_NOATIME     04000000 /* Do not set atime.  */
 # define O_PATH       040000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE   0100100000 /* Atomically create nameless file.  */
 #endif
 
 #ifdef __USE_LARGEFILE64

+ 1 - 0
libc/sysdeps/linux/arc/bits/fcntl.h

@@ -41,6 +41,7 @@
 # define O_DIRECT	040000	/* Direct disk access.	*/
 # define O_NOATIME    01000000	/* Do not set atime.  */
 # define O_PATH	     010000000  /* Resolve pathname but do not open file.  */
+# define O_TMPFILE   020200000  /* Atomically create nameless file.  */
 #endif
 
 #ifdef __USE_LARGEFILE64

+ 1 - 0
libc/sysdeps/linux/arm/bits/fcntl.h

@@ -54,6 +54,7 @@
 # define O_DIRECT	0200000	/* Direct disk access.	*/
 # define O_NOATIME     01000000 /* Do not set atime.  */
 # define O_PATH       010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE    020040000 /* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.

+ 1 - 0
libc/sysdeps/linux/avr32/bits/fcntl.h

@@ -35,6 +35,7 @@
 # define O_DIRECT	00040000	/* must be a directory */
 # define O_NOATIME	01000000	/* don't set atime */
 # define O_PATH        010000000	/* Resolve pathname but do not open file.  */
+# define O_TMPFILE     020200000	/* Atomically create nameless file.  */
 #endif
 
 #ifdef __USE_LARGEFILE64

+ 1 - 0
libc/sysdeps/linux/bfin/bits/fcntl.h

@@ -53,6 +53,7 @@
 # define O_DIRECT	0200000	/* Direct disk access.	*/
 # define O_NOATIME	01000000	/* don't set atime */
 # define O_PATH        010000000	/* Resolve pathname but do not open file.  */
+# define O_TMPFILE     020040000	/* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.

+ 1 - 0
libc/sysdeps/linux/c6x/bits/fcntl.h

@@ -54,6 +54,7 @@
 # define O_LARGEFILE	0100000
 # define O_NOATIME      01000000
 # define O_PATH        010000000/* Resolve pathname but do not open file.  */
+# define O_TMPFILE     020200000/* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.

+ 1 - 1
libc/sysdeps/linux/common/open.c

@@ -31,7 +31,7 @@ int open(const char *file, int oflag, ...)
 	int oldtype, result;
 #endif
 
-	if (oflag & O_CREAT) {
+	if (oflag & (O_CREAT | (O_TMPFILE &~ O_DIRECTORY))) {
 		va_list arg;
 		va_start(arg, oflag);
 		mode = va_arg(arg, mode_t);

+ 2 - 2
libc/sysdeps/linux/common/open64.c

@@ -10,13 +10,13 @@
 #include <stdarg.h>
 #include <cancel.h>
 
-/* Open FILE with access OFLAG.  If OFLAG includes O_CREAT,
+/* Open FILE with access OFLAG.  If OFLAG includes O_CREAT or O_TMPFILE,
    a third argument is the file protection.  */
 int open64(const char *file, int oflag, ...)
 {
 	mode_t mode = 0;
 
-	if (oflag & O_CREAT) {
+	if (oflag & (O_CREAT | (O_TMPFILE &~ O_DIRECTORY))) {
 		va_list arg;
 		va_start (arg, oflag);
 		mode = va_arg (arg, mode_t);

+ 1 - 0
libc/sysdeps/linux/cris/bits/fcntl.h

@@ -54,6 +54,7 @@
 # define O_DIRECT	 040000	/* Direct disk access.	*/
 # define O_NOATIME	01000000 /* Do not set atime.  */
 # define O_PATH        010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE     020200000 /* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.

+ 1 - 0
libc/sysdeps/linux/csky/bits/fcntl.h

@@ -42,6 +42,7 @@
 # define O_DIRECT      00040000	/* direct disk access hint */
 # define O_NOATIME     01000000 /* Do not set atime.  */
 # define O_PATH       010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE    020200000 /* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.

+ 1 - 0
libc/sysdeps/linux/frv/bits/fcntl.h

@@ -53,6 +53,7 @@
 # define O_DIRECT	 040000	/* Direct disk access.  */
 # define O_NOATIME	01000000 /* don't set atime */
 # define O_PATH        010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE     020200000 /* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.

+ 1 - 0
libc/sysdeps/linux/h8300/bits/fcntl.h

@@ -53,6 +53,7 @@
 # define O_DIRECT	 040000	/* Direct disk access.	*/
 # define O_NOATIME     01000000 /* Do not set atime.  */
 # define O_PATH       010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE    020200000 /* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.

+ 1 - 0
libc/sysdeps/linux/hppa/bits/fcntl.h

@@ -53,6 +53,7 @@
 # define O_DIRECT	00040000 /* Direct disk access. */
 # define O_NOATIME	04000000 /* Do not set atime. */
 # define O_PATH		020000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE     040010000 /* Atomically create nameless file.  */
 #endif
 
 #ifdef __USE_LARGEFILE64

+ 1 - 0
libc/sysdeps/linux/i386/bits/fcntl.h

@@ -54,6 +54,7 @@
 # define O_DIRECT	 040000	/* Direct disk access.	*/
 # define O_NOATIME     01000000 /* Do not set atime.  */
 # define O_PATH       010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE    020200000 /* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.

+ 1 - 0
libc/sysdeps/linux/ia64/bits/fcntl.h

@@ -53,6 +53,7 @@
 # define O_DIRECT	040000
 # define O_NOATIME	01000000 /* Do not set atime.  */
 # define O_PATH        010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE     020200000 /* Atomically create nameless file.  */
 #endif
 
 #ifdef __USE_LARGEFILE64

+ 1 - 0
libc/sysdeps/linux/kvx/bits/fcntl.h

@@ -42,6 +42,7 @@
 # define O_DIRECT	040000	/* Direct disk access.	*/
 # define O_NOATIME    01000000	/* Do not set atime.  */
 # define O_PATH	     010000000  /* Resolve pathname but do not open file.  */
+# define O_TMPFILE   020200000  /* Atomically create nameless file.  */
 #endif
 
 #ifdef __USE_LARGEFILE64

+ 1 - 0
libc/sysdeps/linux/lm32/bits/fcntl.h

@@ -53,6 +53,7 @@
 # define O_DIRECT	040000	/* Direct disk access.	*/
 # define O_NOATIME     01000000 /* Do not set atime.  */
 # define O_PATH       010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE    020200000 /* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.

+ 1 - 0
libc/sysdeps/linux/m68k/bits/fcntl.h

@@ -53,6 +53,7 @@
 # define O_DIRECT	0200000	/* Direct disk access.	*/
 # define O_NOATIME	01000000 /* Do not set atime.  */
 # define O_PATH        010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE     020040000 /* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.

+ 1 - 0
libc/sysdeps/linux/metag/bits/fcntl.h

@@ -54,6 +54,7 @@
 # define O_DIRECT	 040000	/* Direct disk access.	*/
 # define O_NOATIME     01000000 /* Do not set atime.  */
 # define O_PATH       010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE    020200000 /* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.

+ 1 - 0
libc/sysdeps/linux/microblaze/bits/fcntl.h

@@ -53,6 +53,7 @@
 # define O_DIRECT	040000	/* Direct disk access.	*/
 # define O_NOATIME     01000000 /* Do not set atime.  */
 # define O_PATH       010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE    020200000 /* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.

+ 1 - 0
libc/sysdeps/linux/mips/bits/fcntl.h

@@ -55,6 +55,7 @@
 # define O_DIRECT	0x8000	/* Direct disk access hint.  */
 # define O_NOATIME	0x40000	/* Do not set atime.  */
 # define O_PATH       010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE     0x410000 /* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has no synchronisity options for data and read operations.

+ 1 - 0
libc/sysdeps/linux/nds32/bits/fcntl.h

@@ -58,6 +58,7 @@
 # define O_DIRECT	 040000	/* Direct disk access.	*/
 # define O_NOATIME     01000000 /* Do not set atime.  */
 # define O_PATH       010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE    020200000 /* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.

+ 1 - 0
libc/sysdeps/linux/nios2/bits/fcntl.h

@@ -53,6 +53,7 @@
 # define O_DIRECT	 040000	/* Direct disk access.	*/
 # define O_NOATIME     01000000 /* Do not set atime.  */
 # define O_PATH       010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE    020200000 /* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.

+ 1 - 0
libc/sysdeps/linux/or1k/bits/fcntl.h

@@ -53,6 +53,7 @@
 # define O_DIRECT	 040000	/* Direct disk access.	*/
 # define O_NOATIME     01000000 /* Do not set atime.  */
 # define O_PATH       010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE    020200000 /* Atomically create nameless file.  */
 #endif
 
 #ifdef __USE_LARGEFILE64

+ 1 - 0
libc/sysdeps/linux/powerpc/bits/fcntl.h

@@ -54,6 +54,7 @@
 # define O_DIRECT	0400000	/* Direct disk access.	*/
 # define O_NOATIME     01000000 /* Do not set atime.  */
 # define O_PATH       010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE    020040000 /* Atomically create nameless file.  */
 #endif
 
 #ifdef __USE_LARGEFILE64

+ 1 - 0
libc/sysdeps/linux/riscv64/bits/fcntl.h

@@ -40,6 +40,7 @@
 # define O_DIRECT	00040000	/* Direct disk access.	*/
 # define O_NOATIME	01000000	/* Do not set atime.  */
 # define O_PATH		010000000  	/* Resolve pathname but do not open file.  */
+# define O_TMPFILE      020200000	/* Atomically create nameless file.  */
 #endif
 
 #ifdef __USE_LARGEFILE64

+ 1 - 0
libc/sysdeps/linux/sh/bits/fcntl.h

@@ -54,6 +54,7 @@
 # define O_DIRECT	 040000	/* Direct disk access.	*/
 # define O_NOATIME     01000000 /* Do not set atime.  */
 # define O_PATH       010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE    020200000 /* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.

+ 1 - 0
libc/sysdeps/linux/sparc/bits/fcntl.h

@@ -51,6 +51,7 @@
 # define O_DIRECT      0x100000 /* direct disk access hint */
 # define O_NOATIME     0x200000 /* Do not set atime.  */
 # define O_PATH       0x1000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE    0x2010000 /* Atomically create nameless file.  */
 #endif
 
 #ifdef __USE_LARGEFILE64

+ 1 - 0
libc/sysdeps/linux/sparc64/bits/fcntl.h

@@ -47,6 +47,7 @@
 # define O_NOATIME     0x200000 /* Do not set atime.  */
 # define O_CLOEXEC     0x400000 /* Set close_on_exit.  */
 # define O_PATH       0x1000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE    0x2010000 /* Atomically create nameless file.  */
 #endif
 
 #ifdef __USE_LARGEFILE64

+ 1 - 0
libc/sysdeps/linux/tile/bits/fcntl.h

@@ -40,6 +40,7 @@
 # define O_DIRECT	040000	/* Direct disk access.	*/
 # define O_NOATIME    01000000	/* Do not set atime.  */
 # define O_PATH	     010000000  /* Resolve pathname but do not open file.  */
+# define O_TMPFILE   020200000  /* Atomically create nameless file.  */
 #endif
 
 #ifdef __USE_LARGEFILE64

+ 1 - 0
libc/sysdeps/linux/x86_64/bits/fcntl.h

@@ -54,6 +54,7 @@
 # define O_DIRECT	 040000	/* Direct disk access.	*/
 # define O_NOATIME     01000000 /* Do not set atime.  */
 # define O_PATH       010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE    020200000 /* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.

+ 1 - 0
libc/sysdeps/linux/xtensa/bits/fcntl.h

@@ -54,6 +54,7 @@
 # define O_DIRECT	 040000	/* Direct disk access.	*/
 # define O_NOATIME     01000000 /* Do not set atime.  */
 # define O_PATH       010000000 /* Resolve pathname but do not open file.  */
+# define O_TMPFILE    020200000 /* Atomically create nameless file.  */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.