162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 262306a36Sopenharmony_ci#ifndef _ASM_GENERIC_FCNTL_H 362306a36Sopenharmony_ci#define _ASM_GENERIC_FCNTL_H 462306a36Sopenharmony_ci 562306a36Sopenharmony_ci#include <linux/types.h> 662306a36Sopenharmony_ci 762306a36Sopenharmony_ci/* 862306a36Sopenharmony_ci * FMODE_EXEC is 0x20 962306a36Sopenharmony_ci * FMODE_NONOTIFY is 0x4000000 1062306a36Sopenharmony_ci * These cannot be used by userspace O_* until internal and external open 1162306a36Sopenharmony_ci * flags are split. 1262306a36Sopenharmony_ci * -Eric Paris 1362306a36Sopenharmony_ci */ 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci/* 1662306a36Sopenharmony_ci * When introducing new O_* bits, please check its uniqueness in fcntl_init(). 1762306a36Sopenharmony_ci */ 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci#define O_ACCMODE 00000003 2062306a36Sopenharmony_ci#define O_RDONLY 00000000 2162306a36Sopenharmony_ci#define O_WRONLY 00000001 2262306a36Sopenharmony_ci#define O_RDWR 00000002 2362306a36Sopenharmony_ci#ifndef O_CREAT 2462306a36Sopenharmony_ci#define O_CREAT 00000100 /* not fcntl */ 2562306a36Sopenharmony_ci#endif 2662306a36Sopenharmony_ci#ifndef O_EXCL 2762306a36Sopenharmony_ci#define O_EXCL 00000200 /* not fcntl */ 2862306a36Sopenharmony_ci#endif 2962306a36Sopenharmony_ci#ifndef O_NOCTTY 3062306a36Sopenharmony_ci#define O_NOCTTY 00000400 /* not fcntl */ 3162306a36Sopenharmony_ci#endif 3262306a36Sopenharmony_ci#ifndef O_TRUNC 3362306a36Sopenharmony_ci#define O_TRUNC 00001000 /* not fcntl */ 3462306a36Sopenharmony_ci#endif 3562306a36Sopenharmony_ci#ifndef O_APPEND 3662306a36Sopenharmony_ci#define O_APPEND 00002000 3762306a36Sopenharmony_ci#endif 3862306a36Sopenharmony_ci#ifndef O_NONBLOCK 3962306a36Sopenharmony_ci#define O_NONBLOCK 00004000 4062306a36Sopenharmony_ci#endif 4162306a36Sopenharmony_ci#ifndef O_DSYNC 4262306a36Sopenharmony_ci#define O_DSYNC 00010000 /* used to be O_SYNC, see below */ 4362306a36Sopenharmony_ci#endif 4462306a36Sopenharmony_ci#ifndef FASYNC 4562306a36Sopenharmony_ci#define FASYNC 00020000 /* fcntl, for BSD compatibility */ 4662306a36Sopenharmony_ci#endif 4762306a36Sopenharmony_ci#ifndef O_DIRECT 4862306a36Sopenharmony_ci#define O_DIRECT 00040000 /* direct disk access hint */ 4962306a36Sopenharmony_ci#endif 5062306a36Sopenharmony_ci#ifndef O_LARGEFILE 5162306a36Sopenharmony_ci#define O_LARGEFILE 00100000 5262306a36Sopenharmony_ci#endif 5362306a36Sopenharmony_ci#ifndef O_DIRECTORY 5462306a36Sopenharmony_ci#define O_DIRECTORY 00200000 /* must be a directory */ 5562306a36Sopenharmony_ci#endif 5662306a36Sopenharmony_ci#ifndef O_NOFOLLOW 5762306a36Sopenharmony_ci#define O_NOFOLLOW 00400000 /* don't follow links */ 5862306a36Sopenharmony_ci#endif 5962306a36Sopenharmony_ci#ifndef O_NOATIME 6062306a36Sopenharmony_ci#define O_NOATIME 01000000 6162306a36Sopenharmony_ci#endif 6262306a36Sopenharmony_ci#ifndef O_CLOEXEC 6362306a36Sopenharmony_ci#define O_CLOEXEC 02000000 /* set close_on_exec */ 6462306a36Sopenharmony_ci#endif 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci/* 6762306a36Sopenharmony_ci * Before Linux 2.6.33 only O_DSYNC semantics were implemented, but using 6862306a36Sopenharmony_ci * the O_SYNC flag. We continue to use the existing numerical value 6962306a36Sopenharmony_ci * for O_DSYNC semantics now, but using the correct symbolic name for it. 7062306a36Sopenharmony_ci * This new value is used to request true Posix O_SYNC semantics. It is 7162306a36Sopenharmony_ci * defined in this strange way to make sure applications compiled against 7262306a36Sopenharmony_ci * new headers get at least O_DSYNC semantics on older kernels. 7362306a36Sopenharmony_ci * 7462306a36Sopenharmony_ci * This has the nice side-effect that we can simply test for O_DSYNC 7562306a36Sopenharmony_ci * wherever we do not care if O_DSYNC or O_SYNC is used. 7662306a36Sopenharmony_ci * 7762306a36Sopenharmony_ci * Note: __O_SYNC must never be used directly. 7862306a36Sopenharmony_ci */ 7962306a36Sopenharmony_ci#ifndef O_SYNC 8062306a36Sopenharmony_ci#define __O_SYNC 04000000 8162306a36Sopenharmony_ci#define O_SYNC (__O_SYNC|O_DSYNC) 8262306a36Sopenharmony_ci#endif 8362306a36Sopenharmony_ci 8462306a36Sopenharmony_ci#ifndef O_PATH 8562306a36Sopenharmony_ci#define O_PATH 010000000 8662306a36Sopenharmony_ci#endif 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci#ifndef __O_TMPFILE 8962306a36Sopenharmony_ci#define __O_TMPFILE 020000000 9062306a36Sopenharmony_ci#endif 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci/* a horrid kludge trying to make sure that this will fail on old kernels */ 9362306a36Sopenharmony_ci#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY) 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci#ifndef O_NDELAY 9662306a36Sopenharmony_ci#define O_NDELAY O_NONBLOCK 9762306a36Sopenharmony_ci#endif 9862306a36Sopenharmony_ci 9962306a36Sopenharmony_ci#define F_DUPFD 0 /* dup */ 10062306a36Sopenharmony_ci#define F_GETFD 1 /* get close_on_exec */ 10162306a36Sopenharmony_ci#define F_SETFD 2 /* set/clear close_on_exec */ 10262306a36Sopenharmony_ci#define F_GETFL 3 /* get file->f_flags */ 10362306a36Sopenharmony_ci#define F_SETFL 4 /* set file->f_flags */ 10462306a36Sopenharmony_ci#ifndef F_GETLK 10562306a36Sopenharmony_ci#define F_GETLK 5 10662306a36Sopenharmony_ci#define F_SETLK 6 10762306a36Sopenharmony_ci#define F_SETLKW 7 10862306a36Sopenharmony_ci#endif 10962306a36Sopenharmony_ci#ifndef F_SETOWN 11062306a36Sopenharmony_ci#define F_SETOWN 8 /* for sockets. */ 11162306a36Sopenharmony_ci#define F_GETOWN 9 /* for sockets. */ 11262306a36Sopenharmony_ci#endif 11362306a36Sopenharmony_ci#ifndef F_SETSIG 11462306a36Sopenharmony_ci#define F_SETSIG 10 /* for sockets. */ 11562306a36Sopenharmony_ci#define F_GETSIG 11 /* for sockets. */ 11662306a36Sopenharmony_ci#endif 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci#if __BITS_PER_LONG == 32 || defined(__KERNEL__) 11962306a36Sopenharmony_ci#ifndef F_GETLK64 12062306a36Sopenharmony_ci#define F_GETLK64 12 /* using 'struct flock64' */ 12162306a36Sopenharmony_ci#define F_SETLK64 13 12262306a36Sopenharmony_ci#define F_SETLKW64 14 12362306a36Sopenharmony_ci#endif 12462306a36Sopenharmony_ci#endif /* __BITS_PER_LONG == 32 || defined(__KERNEL__) */ 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_ci#ifndef F_SETOWN_EX 12762306a36Sopenharmony_ci#define F_SETOWN_EX 15 12862306a36Sopenharmony_ci#define F_GETOWN_EX 16 12962306a36Sopenharmony_ci#endif 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci#ifndef F_GETOWNER_UIDS 13262306a36Sopenharmony_ci#define F_GETOWNER_UIDS 17 13362306a36Sopenharmony_ci#endif 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ci/* 13662306a36Sopenharmony_ci * Open File Description Locks 13762306a36Sopenharmony_ci * 13862306a36Sopenharmony_ci * Usually record locks held by a process are released on *any* close and are 13962306a36Sopenharmony_ci * not inherited across a fork(). 14062306a36Sopenharmony_ci * 14162306a36Sopenharmony_ci * These cmd values will set locks that conflict with process-associated 14262306a36Sopenharmony_ci * record locks, but are "owned" by the open file description, not the 14362306a36Sopenharmony_ci * process. This means that they are inherited across fork() like BSD (flock) 14462306a36Sopenharmony_ci * locks, and they are only released automatically when the last reference to 14562306a36Sopenharmony_ci * the the open file against which they were acquired is put. 14662306a36Sopenharmony_ci */ 14762306a36Sopenharmony_ci#define F_OFD_GETLK 36 14862306a36Sopenharmony_ci#define F_OFD_SETLK 37 14962306a36Sopenharmony_ci#define F_OFD_SETLKW 38 15062306a36Sopenharmony_ci 15162306a36Sopenharmony_ci#define F_OWNER_TID 0 15262306a36Sopenharmony_ci#define F_OWNER_PID 1 15362306a36Sopenharmony_ci#define F_OWNER_PGRP 2 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_cistruct f_owner_ex { 15662306a36Sopenharmony_ci int type; 15762306a36Sopenharmony_ci __kernel_pid_t pid; 15862306a36Sopenharmony_ci}; 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci/* for F_[GET|SET]FL */ 16162306a36Sopenharmony_ci#define FD_CLOEXEC 1 /* actually anything with low bit set goes */ 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ci/* for posix fcntl() and lockf() */ 16462306a36Sopenharmony_ci#ifndef F_RDLCK 16562306a36Sopenharmony_ci#define F_RDLCK 0 16662306a36Sopenharmony_ci#define F_WRLCK 1 16762306a36Sopenharmony_ci#define F_UNLCK 2 16862306a36Sopenharmony_ci#endif 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_ci/* for old implementation of bsd flock () */ 17162306a36Sopenharmony_ci#ifndef F_EXLCK 17262306a36Sopenharmony_ci#define F_EXLCK 4 /* or 3 */ 17362306a36Sopenharmony_ci#define F_SHLCK 8 /* or 4 */ 17462306a36Sopenharmony_ci#endif 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci/* operations for bsd flock(), also used by the kernel implementation */ 17762306a36Sopenharmony_ci#define LOCK_SH 1 /* shared lock */ 17862306a36Sopenharmony_ci#define LOCK_EX 2 /* exclusive lock */ 17962306a36Sopenharmony_ci#define LOCK_NB 4 /* or'd with one of the above to prevent 18062306a36Sopenharmony_ci blocking */ 18162306a36Sopenharmony_ci#define LOCK_UN 8 /* remove lock */ 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_ci/* 18462306a36Sopenharmony_ci * LOCK_MAND support has been removed from the kernel. We leave the symbols 18562306a36Sopenharmony_ci * here to not break legacy builds, but these should not be used in new code. 18662306a36Sopenharmony_ci */ 18762306a36Sopenharmony_ci#define LOCK_MAND 32 /* This is a mandatory flock ... */ 18862306a36Sopenharmony_ci#define LOCK_READ 64 /* which allows concurrent read operations */ 18962306a36Sopenharmony_ci#define LOCK_WRITE 128 /* which allows concurrent write operations */ 19062306a36Sopenharmony_ci#define LOCK_RW 192 /* which allows concurrent read & write ops */ 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ci#define F_LINUX_SPECIFIC_BASE 1024 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ci#ifndef HAVE_ARCH_STRUCT_FLOCK 19562306a36Sopenharmony_cistruct flock { 19662306a36Sopenharmony_ci short l_type; 19762306a36Sopenharmony_ci short l_whence; 19862306a36Sopenharmony_ci __kernel_off_t l_start; 19962306a36Sopenharmony_ci __kernel_off_t l_len; 20062306a36Sopenharmony_ci __kernel_pid_t l_pid; 20162306a36Sopenharmony_ci#ifdef __ARCH_FLOCK_EXTRA_SYSID 20262306a36Sopenharmony_ci __ARCH_FLOCK_EXTRA_SYSID 20362306a36Sopenharmony_ci#endif 20462306a36Sopenharmony_ci#ifdef __ARCH_FLOCK_PAD 20562306a36Sopenharmony_ci __ARCH_FLOCK_PAD 20662306a36Sopenharmony_ci#endif 20762306a36Sopenharmony_ci}; 20862306a36Sopenharmony_ci 20962306a36Sopenharmony_cistruct flock64 { 21062306a36Sopenharmony_ci short l_type; 21162306a36Sopenharmony_ci short l_whence; 21262306a36Sopenharmony_ci __kernel_loff_t l_start; 21362306a36Sopenharmony_ci __kernel_loff_t l_len; 21462306a36Sopenharmony_ci __kernel_pid_t l_pid; 21562306a36Sopenharmony_ci#ifdef __ARCH_FLOCK64_PAD 21662306a36Sopenharmony_ci __ARCH_FLOCK64_PAD 21762306a36Sopenharmony_ci#endif 21862306a36Sopenharmony_ci}; 21962306a36Sopenharmony_ci#endif /* HAVE_ARCH_STRUCT_FLOCK */ 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_ci#endif /* _ASM_GENERIC_FCNTL_H */ 222