1 /*- 2 * Copyright (c) 1983, 1990, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)fcntl.h 8.2 (Berkeley) 01/04/94 8 */ 9 10 #ifndef _SYS_FCNTL_H_ 11 #define _SYS_FCNTL_H_ 12 13 /* 14 * This file includes the definitions for open and fcntl 15 * described by POSIX for <fcntl.h>; it also includes 16 * related kernel definitions. 17 */ 18 19 #ifndef KERNEL 20 #include <sys/types.h> 21 #endif 22 23 /* 24 * File status flags: these are used by open(2), fcntl(2). 25 * They are also used (indirectly) in the kernel file structure f_flags, 26 * which is a superset of the open/fcntl flags. Open flags and f_flags 27 * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags). 28 * Open/fcntl flags begin with O_; kernel-internal flags begin with F. 29 */ 30 /* open-only flags */ 31 #define O_RDONLY 0x0000 /* open for reading only */ 32 #define O_WRONLY 0x0001 /* open for writing only */ 33 #define O_RDWR 0x0002 /* open for reading and writing */ 34 #define O_ACCMODE 0x0003 /* mask for above modes */ 35 36 /* 37 * Kernel encoding of open mode; separate read and write bits that are 38 * independently testable: 1 greater than the above. 39 * 40 * XXX 41 * FREAD and FWRITE are excluded from the #ifdef KERNEL so that TIOCFLUSH, 42 * which was documented to use FREAD/FWRITE, continues to work. 43 */ 44 #ifndef _POSIX_SOURCE 45 #define FREAD 0x0001 46 #define FWRITE 0x0002 47 #endif 48 #define O_NONBLOCK 0x0004 /* no delay */ 49 #define O_APPEND 0x0008 /* set append mode */ 50 #ifndef _POSIX_SOURCE 51 #define O_SHLOCK 0x0010 /* open with shared file lock */ 52 #define O_EXLOCK 0x0020 /* open with exclusive file lock */ 53 #define O_ASYNC 0x0040 /* signal pgrp when data ready */ 54 #define O_FSYNC 0x0080 /* synchronous writes */ 55 #endif 56 #define O_CREAT 0x0200 /* create if nonexistant */ 57 #define O_TRUNC 0x0400 /* truncate to zero length */ 58 #define O_EXCL 0x0800 /* error if already exists */ 59 #ifdef KERNEL 60 #define FMARK 0x1000 /* mark during gc() */ 61 #define FDEFER 0x2000 /* defer for next gc pass */ 62 #define FHASLOCK 0x4000 /* descriptor holds advisory lock */ 63 #endif 64 65 /* defined by POSIX 1003.1; BSD default, so no bit required */ 66 #define O_NOCTTY 0 /* don't assign controlling terminal */ 67 68 #ifdef KERNEL 69 /* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */ 70 #define FFLAGS(oflags) ((oflags) + 1) 71 #define OFLAGS(fflags) ((fflags) - 1) 72 73 /* bits to save after open */ 74 #define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK) 75 /* bits settable by fcntl(F_SETFL, ...) */ 76 #define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK) 77 #endif 78 79 /* 80 * The O_* flags used to have only F* names, which were used in the kernel 81 * and by fcntl. We retain the F* names for the kernel f_flags field 82 * and for backward compatibility for fcntl. 83 */ 84 #ifndef _POSIX_SOURCE 85 #define FAPPEND O_APPEND /* kernel/compat */ 86 #define FASYNC O_ASYNC /* kernel/compat */ 87 #define FFSYNC O_FSYNC /* kernel */ 88 #define FNONBLOCK O_NONBLOCK /* kernel */ 89 #define FNDELAY O_NONBLOCK /* compat */ 90 #define O_NDELAY O_NONBLOCK /* compat */ 91 #endif 92 93 /* 94 * Constants used for fcntl(2) 95 */ 96 97 /* command values */ 98 #define F_DUPFD 0 /* duplicate file descriptor */ 99 #define F_GETFD 1 /* get file descriptor flags */ 100 #define F_SETFD 2 /* set file descriptor flags */ 101 #define F_GETFL 3 /* get file status flags */ 102 #define F_SETFL 4 /* set file status flags */ 103 #ifndef _POSIX_SOURCE 104 #define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */ 105 #define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */ 106 #endif 107 #define F_GETLK 7 /* get record locking information */ 108 #define F_SETLK 8 /* set record locking information */ 109 #define F_SETLKW 9 /* F_SETLK; wait if blocked */ 110 111 /* file descriptor flags (F_GETFD, F_SETFD) */ 112 #define FD_CLOEXEC 1 /* close-on-exec flag */ 113 114 /* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */ 115 #define F_RDLCK 1 /* shared or read lock */ 116 #define F_UNLCK 2 /* unlock */ 117 #define F_WRLCK 3 /* exclusive or write lock */ 118 #ifdef KERNEL 119 #define F_WAIT 0x010 /* Wait until lock is granted */ 120 #define F_FLOCK 0x020 /* Use flock(2) semantics for lock */ 121 #define F_POSIX 0x040 /* Use POSIX semantics for lock */ 122 #endif 123 124 /* 125 * Advisory file segment locking data type - 126 * information passed to system by user 127 */ 128 struct flock { 129 off_t l_start; /* starting offset */ 130 off_t l_len; /* len = 0 means until end of file */ 131 pid_t l_pid; /* lock owner */ 132 short l_type; /* lock type: read/write, etc. */ 133 short l_whence; /* type of l_start */ 134 }; 135 136 137 #ifndef _POSIX_SOURCE 138 /* lock operations for flock(2) */ 139 #define LOCK_SH 0x01 /* shared file lock */ 140 #define LOCK_EX 0x02 /* exclusive file lock */ 141 #define LOCK_NB 0x04 /* don't block when locking */ 142 #define LOCK_UN 0x08 /* unlock file */ 143 #endif 144 145 146 #ifndef KERNEL 147 #include <sys/cdefs.h> 148 149 __BEGIN_DECLS 150 int open __P((const char *, int, ...)); 151 int creat __P((const char *, mode_t)); 152 int fcntl __P((int, int, ...)); 153 #ifndef _POSIX_SOURCE 154 int flock __P((int, int)); 155 #endif /* !_POSIX_SOURCE */ 156 __END_DECLS 157 #endif 158 159 #endif /* !_SYS_FCNTL_H_ */ 160