1 /* Copyright (c) 2007 Jeff Johnston <jjohnstn@redhat.com> */ 2 3 #ifndef _SYS__DEFAULT_FCNTL_H_ 4 #define _SYS__DEFAULT_FCNTL_H_ 5 #include <sys/cdefs.h> 6 #include <sys/_types.h> 7 8 _BEGIN_STD_C 9 10 #ifndef _MODE_T_DECLARED 11 typedef __mode_t mode_t; /* permissions */ 12 #define _MODE_T_DECLARED 13 #endif 14 #ifndef _OFF_T_DECLARED 15 typedef __off_t off_t; /* file offset */ 16 #define _OFF_T_DECLARED 17 #endif 18 #ifndef _PID_T_DECLARED 19 typedef __pid_t pid_t; /* process id */ 20 #define _PID_T_DECLARED 21 #endif 22 23 #define _FOPEN (-1) /* from sys/file.h, kernel use only */ 24 #define _FREAD 0x0001 /* read enabled */ 25 #define _FWRITE 0x0002 /* write enabled */ 26 #define _FAPPEND 0x0400 /* append (writes guaranteed at the end) */ 27 #define _FMARK 0x0010 /* internal; mark during gc() */ 28 #define _FDEFER 0x0020 /* internal; defer for next gc pass */ 29 #define _FASYNC 0x0008 /* signal pgrp when data ready */ 30 #define _FSHLOCK 0x0080 /* BSD flock() shared lock present */ 31 #define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */ 32 #define _FCREAT 0x0040 /* open with file create */ 33 #define _FTRUNC 0x0200 /* open with truncation */ 34 #define _FEXCL 0x0800 /* error on open if file exists */ 35 #define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */ 36 #define _FSYNC 0x2000 /* do all writes synchronously */ 37 #define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */ 38 #define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */ 39 #define _FNOCTTY 0x8000 /* don't assign a ctty on this open */ 40 #define _FNOINHERIT 0x40000 41 #define _FDIRECT 0x80000 42 #define _FNOFOLLOW 0x100000 43 #define _FDIRECTORY 0x200000 44 #define _FEXECSRCH 0x400000 45 46 #define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR) 47 48 /* 49 * Flag values for open(2) and fcntl(2) 50 * The kernel adds 1 to the open modes to turn it into some 51 * combination of FREAD and FWRITE. 52 */ 53 #define O_RDONLY 0 /* +1 == FREAD */ 54 #define O_WRONLY 1 /* +1 == FWRITE */ 55 #define O_RDWR 2 /* +1 == FREAD|FWRITE */ 56 #define O_APPEND _FAPPEND 57 #define O_CREAT _FCREAT 58 #define O_TRUNC _FTRUNC 59 #define O_EXCL _FEXCL 60 #define O_SYNC _FSYNC 61 /* O_NDELAY _FNDELAY set in include/fcntl.h */ 62 /* O_NDELAY _FNBIO set in include/fcntl.h */ 63 #define O_NONBLOCK _FNONBLOCK 64 #define O_NOCTTY _FNOCTTY 65 66 /* POSIX-1.2008 specific flags */ 67 #if __POSIX_VISIBLE >= 200809 68 #define O_CLOEXEC _FNOINHERIT 69 #define O_NOFOLLOW _FNOFOLLOW 70 #define O_DIRECTORY _FDIRECTORY 71 #define O_EXEC _FEXECSRCH 72 #define O_SEARCH _FEXECSRCH 73 #endif 74 75 #if __BSD_VISIBLE 76 #define O_DIRECT _FDIRECT 77 #endif 78 79 #define O_DSYNC _FSYNC 80 #define O_RSYNC _FSYNC 81 82 #if __MISC_VISIBLE 83 84 /* 85 * Flags that work for fcntl(fd, F_SETFL, FXXXX) 86 */ 87 #define FAPPEND _FAPPEND 88 #define FSYNC _FSYNC 89 #define FASYNC _FASYNC 90 #define FNBIO _FNBIO 91 #define FNONBIO _FNONBLOCK /* XXX fix to be NONBLOCK everywhere */ 92 #define FNDELAY _FNDELAY 93 94 /* 95 * Flags that are disallowed for fcntl's (FCNTLCANT); 96 * used for opens, internal state, or locking. 97 */ 98 #define FREAD _FREAD 99 #define FWRITE _FWRITE 100 #define FMARK _FMARK 101 #define FDEFER _FDEFER 102 #define FSHLOCK _FSHLOCK 103 #define FEXLOCK _FEXLOCK 104 105 /* 106 * The rest of the flags, used only for opens 107 */ 108 #define FOPEN _FOPEN 109 #define FCREAT _FCREAT 110 #define FTRUNC _FTRUNC 111 #define FEXCL _FEXCL 112 #define FNOCTTY _FNOCTTY 113 114 #endif /* __MISC_VISIBLE */ 115 116 #if __BSD_VISIBLE 117 #define FNONBLOCK _FNONBLOCK 118 #endif /* __BSD_VISIBLE */ 119 120 /* XXX close on exec request; must match UF_EXCLOSE in user.h */ 121 #define FD_CLOEXEC 1 /* posix */ 122 123 /* fcntl(2) requests */ 124 #define F_DUPFD 0 /* Duplicate fildes */ 125 #define F_GETFD 1 /* Get fildes flags (close on exec) */ 126 #define F_SETFD 2 /* Set fildes flags (close on exec) */ 127 #define F_GETFL 3 /* Get file flags */ 128 #define F_SETFL 4 /* Set file flags */ 129 #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 130 #define F_GETOWN 5 /* Get owner - for ASYNC */ 131 #define F_SETOWN 6 /* Set owner - for ASYNC */ 132 #endif /* __BSD_VISIBLE || __POSIX_VISIBLE >= 200112 */ 133 #define F_GETLK 7 /* Get record-locking information */ 134 #define F_SETLK 8 /* Set or Clear a record-lock (Non-Blocking) */ 135 #define F_SETLKW 9 /* Set or Clear a record-lock (Blocking) */ 136 #if __MISC_VISIBLE 137 #define F_RGETLK 10 /* Test a remote lock to see if it is blocked */ 138 #define F_RSETLK 11 /* Set or unlock a remote lock */ 139 #define F_CNVT 12 /* Convert a fhandle to an open fd */ 140 #define F_RSETLKW 13 /* Set or Clear remote record-lock(Blocking) */ 141 #endif /* __MISC_VISIBLE */ 142 #if __POSIX_VISIBLE >= 200809 143 #define F_DUPFD_CLOEXEC 14 /* As F_DUPFD, but set close-on-exec flag */ 144 #endif 145 146 /* fcntl(2) flags (l_type field of flock structure) */ 147 #define F_RDLCK 1 /* read lock */ 148 #define F_WRLCK 2 /* write lock */ 149 #define F_UNLCK 3 /* remove lock(s) */ 150 #if __MISC_VISIBLE 151 #define F_UNLKSYS 4 /* remove remote locks for a given system */ 152 #endif /* __MISC_VISIBLE */ 153 154 #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 155 /* Special descriptor value to denote the cwd in calls to openat(2) etc. */ 156 #define AT_FDCWD -2 157 158 /* Flag values for faccessat2) et al. */ 159 #define AT_EACCESS 0x0001 160 #define AT_SYMLINK_NOFOLLOW 0x0002 161 #define AT_SYMLINK_FOLLOW 0x0004 162 #define AT_REMOVEDIR 0x0008 163 #if __GNU_VISIBLE 164 #define AT_EMPTY_PATH 0x0010 165 #define _AT_NULL_PATHNAME_ALLOWED 0x4000 /* Internal flag used by futimesat */ 166 #endif 167 #endif 168 169 #if __BSD_VISIBLE 170 /* lock operations for flock(2) */ 171 #define LOCK_SH 0x01 /* shared file lock */ 172 #define LOCK_EX 0x02 /* exclusive file lock */ 173 #define LOCK_NB 0x04 /* don't block when locking */ 174 #define LOCK_UN 0x08 /* unlock file */ 175 #endif 176 177 /* file segment locking set data type - information passed to system by user */ 178 struct flock { 179 short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */ 180 short l_whence; /* flag to choose starting offset */ 181 long l_start; /* relative offset, in bytes */ 182 long l_len; /* length, in bytes; 0 means lock to EOF */ 183 short l_pid; /* returned with F_GETLK */ 184 short l_xxx; /* reserved for future use */ 185 }; 186 187 #if __MISC_VISIBLE 188 /* extended file segment locking set data type */ 189 struct eflock { 190 short l_type; /* F_RDLCK, F_WRLCK, or F_UNLCK */ 191 short l_whence; /* flag to choose starting offset */ 192 long l_start; /* relative offset, in bytes */ 193 long l_len; /* length, in bytes; 0 means lock to EOF */ 194 short l_pid; /* returned with F_GETLK */ 195 short l_xxx; /* reserved for future use */ 196 long l_rpid; /* Remote process id wanting this lock */ 197 long l_rsys; /* Remote system id wanting this lock */ 198 }; 199 #endif /* __MISC_VISIBLE */ 200 201 extern int open (const char *, int, ...); 202 #if __ATFILE_VISIBLE 203 extern int openat (int, const char *, int, ...); 204 #endif 205 extern int creat (const char *, mode_t); 206 extern int fcntl (int, int, ...); 207 #if __BSD_VISIBLE 208 extern int flock (int, int); 209 #endif 210 211 /* Provide _<systemcall> prototypes for functions provided by some versions 212 of newlib. */ 213 #ifdef _LIBC 214 extern int open (const char *, int, ...); 215 extern int fcntl (int, int, ...); 216 #ifdef __LARGE64_FILES 217 extern int open64 (const char *, int, ...); 218 #endif 219 #endif 220 221 _END_STD_C 222 223 #endif /* !_SYS__DEFAULT_FCNTL_H_ */ 224