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