sys/fcntl.h

Go to the documentation of this file.
00001 /*-
00002  * © Portions copyright (c) 2005 Nokia Corporation.  All rights reserved.
00003  * © Portions copyright (c) 2006 Symbian Software Ltd. All rights reserved.
00004  * Copyright (c) 1983, 1990, 1993
00005  *      The Regents of the University of California.  All rights reserved.
00006  * (c) UNIX System Laboratories, Inc.
00007  * All or some portions of this file are derived from material licensed
00008  * to the University of California by American Telephone and Telegraph
00009  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
00010  * the permission of UNIX System Laboratories, Inc.
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions
00014  * are met:
00015  * 1. Redistributions of source code must retain the above copyright
00016  *    notice, this list of conditions and the following disclaimer.
00017  * 2. Redistributions in binary form must reproduce the above copyright
00018  *    notice, this list of conditions and the following disclaimer in the
00019  *    documentation and/or other materials provided with the distribution.
00020  * 4. Neither the name of the University nor the names of its contributors
00021  *    may be used to endorse or promote products derived from this software
00022  *    without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00025  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00027  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00028  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00030  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00031  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00033  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00034  * SUCH DAMAGE.
00035  *
00036  *      @(#)fcntl.h     8.3 (Berkeley) 1/21/94
00037  * $FreeBSD: src/sys/sys/fcntl.h,v 1.16 2004/04/07 04:19:49 imp Exp $
00038  */
00039 
00040 #ifndef _SYS_FCNTL_H_
00041 #define _SYS_FCNTL_H_
00042 
00043 /*
00044  * This file includes the definitions for open and fcntl
00045  * described by POSIX for <fcntl.h>; it also includes
00046  * related kernel definitions.
00047  */
00048 
00049 #include <sys/cdefs.h>
00050 #include <sys/_types.h>
00051 
00052 #ifndef _MODE_T_DECLARED
00053 typedef __mode_t        mode_t;
00054 #define _MODE_T_DECLARED
00055 #endif
00056 
00057 #ifndef _OFF_T_DECLARED
00058 typedef __off_t         off_t;
00059 #define _OFF_T_DECLARED
00060 #endif
00061 
00062 #ifndef _PID_T_DECLARED
00063 typedef __pid_t         pid_t;
00064 #define _PID_T_DECLARED
00065 #endif
00066 
00067 /*
00068  * File status flags: these are used by open(2), fcntl(2).
00069  * They are also used (indirectly) in the kernel file structure f_flags,
00070  * which is a superset of the open/fcntl flags.  Open flags and f_flags
00071  * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags).
00072  * Open/fcntl flags begin with O_; kernel-internal flags begin with F.
00073  */
00074 /* open-only flags */
00075 #define O_RDONLY        0x0000          /* open for reading only */
00076 #define O_WRONLY        0x0001          /* open for writing only */
00077 #define O_RDWR          0x0002          /* open for reading and writing */
00078 #define O_ACCMODE       0x0003          /* mask for above modes */
00079 
00080 /*
00081  * Kernel encoding of open mode; separate read and write bits that are
00082  * independently testable: 1 greater than the above.
00083  *
00084  * XXX
00085  * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH,
00086  * which was documented to use FREAD/FWRITE, continues to work.
00087  */
00088 #if __BSD_VISIBLE
00089 #define FREAD           0x0001
00090 #define FWRITE          0x0002
00091 #endif
00092 #define O_NONBLOCK      0x0004          /* no delay */
00093 #define O_APPEND        0x0008          /* set append mode */
00094 #if __BSD_VISIBLE
00095 #define O_SHLOCK        0x0010          /* open with shared file lock */
00096 #define O_EXLOCK        0x0020          /* open with exclusive file lock */
00097 #define O_ASYNC         0x0040          /* signal pgrp when data ready */
00098 #define O_FSYNC         0x0080          /* synchronous writes */
00099 #endif
00100 #define O_SYNC          0x0080          /* POSIX synonym for O_FSYNC */
00101 #if __BSD_VISIBLE
00102 #define O_NOFOLLOW      0x0100          /* don't follow symlinks */
00103 #endif
00104 #define O_CREAT         0x0200          /* create if nonexistent */
00105 #define O_TRUNC         0x0400          /* truncate to zero length */
00106 #define O_EXCL          0x0800          /* error if already exists */
00107 #ifdef _KERNEL
00108 #define FHASLOCK        0x4000          /* descriptor holds advisory lock */
00109 #endif
00110 
00111 /* Defined by POSIX 1003.1; BSD default, but must be distinct from O_RDONLY. */
00112 #define O_NOCTTY        0x8000          /* don't assign controlling terminal */
00113 
00114 #if __BSD_VISIBLE
00115 /* Attempt to bypass buffer cache */
00116 #define O_DIRECT        0x00010000
00117 #endif
00118 
00119 //Copied from MRT1.0 fcntl.h header
00120 #define _FBUFFERED  0x10000 /* buffer at the interface to the file system */
00121 #define _FBINARY        0x10000
00122 #define _FTEXT          0x20000
00123 #define O_BINARY        _FBINARY
00124 #define O_TEXT          _FTEXT
00125 #define O_BUFFERED  _FBUFFERED
00126 
00127 /*
00128  * XXX missing O_DSYNC, O_RSYNC.
00129  */
00130 
00131 #ifdef _KERNEL
00132 /* convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE */
00133 #define FFLAGS(oflags)  ((oflags) + 1)
00134 #define OFLAGS(fflags)  ((fflags) - 1)
00135 
00136 /* bits to save after open */
00137 #define FMASK           (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK|O_DIRECT)
00138 /* bits settable by fcntl(F_SETFL, ...) */
00139 #define FCNTLFLAGS      (FAPPEND|FASYNC|FFSYNC|FNONBLOCK|FPOSIXSHM|O_DIRECT)
00140 #endif
00141 
00142 /*
00143  * The O_* flags used to have only F* names, which were used in the kernel
00144  * and by fcntl.  We retain the F* names for the kernel f_flag field
00145  * and for backward compatibility for fcntl.  These flags are deprecated.
00146  */
00147 #if __BSD_VISIBLE
00148 #define FAPPEND         O_APPEND        /* kernel/compat */
00149 #define FASYNC          O_ASYNC         /* kernel/compat */
00150 #define FFSYNC          O_FSYNC         /* kernel */
00151 #define FNONBLOCK       O_NONBLOCK      /* kernel */
00152 #define FNDELAY         O_NONBLOCK      /* compat */
00153 #define O_NDELAY        O_NONBLOCK      /* compat */
00154 #endif
00155 
00156 /*
00157  * We are out of bits in f_flag (which is a short).  However,
00158  * the flag bits not set in FMASK are only meaningful in the
00159  * initial open syscall.  Those bits can thus be given a
00160  * different meaning for fcntl(2).
00161  */
00162 #if __BSD_VISIBLE
00163 
00164 /*
00165  * Set by shm_open(3) to get automatic MAP_ASYNC behavior
00166  * for POSIX shared memory objects (which are otherwise
00167  * implemented as plain files).
00168  */
00169 #define FPOSIXSHM       O_NOFOLLOW
00170 #endif
00171 
00172 /*
00173  * Constants used for fcntl(2)
00174  */
00175 
00176 /* command values */
00177 #define F_DUPFD         0               /* duplicate file descriptor */
00178 #define F_GETFD         1               /* get file descriptor flags */
00179 #define F_SETFD         2               /* set file descriptor flags */
00180 #define F_GETFL         3               /* get file status flags */
00181 #define F_SETFL         4               /* set file status flags */
00182 #if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
00183 #define F_GETOWN        5               /* get SIGIO/SIGURG proc/pgrp */
00184 #define F_SETOWN        6               /* set SIGIO/SIGURG proc/pgrp */
00185 #endif
00186 #define F_GETLK         7               /* get record locking information */
00187 #define F_SETLK         8               /* set record locking information */
00188 #define F_SETLKW        9               /* F_SETLK; wait if blocked */
00189 
00190 /* file descriptor flags (F_GETFD, F_SETFD) */
00191 #define FD_CLOEXEC      1               /* close-on-exec flag */
00192 
00193 /* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */
00194 #define F_RDLCK         1               /* shared or read lock */
00195 #define F_UNLCK         2               /* unlock */
00196 #define F_WRLCK         3               /* exclusive or write lock */
00197 #ifdef _KERNEL
00198 #define F_WAIT          0x010           /* Wait until lock is granted */
00199 #define F_FLOCK         0x020           /* Use flock(2) semantics for lock */
00200 #define F_POSIX         0x040           /* Use POSIX semantics for lock */
00201 #endif
00202 
00203 /*
00204  * Advisory file segment locking data type -
00205  * information passed to system by user
00206  */
00207 struct flock {
00208         off_t   l_start;        /* starting offset */
00209         off_t   l_len;          /* len = 0 means until end of file */
00210         pid_t   l_pid;          /* lock owner */
00211         short   l_type;         /* lock type: read/write, etc. */
00212         short   l_whence;       /* type of l_start */
00213 };
00214 
00215 
00216 #if __BSD_VISIBLE
00217 /* lock operations for flock(2) */
00218 #define LOCK_SH         0x01            /* shared file lock */
00219 #define LOCK_EX         0x02            /* exclusive file lock */
00220 #define LOCK_NB         0x04            /* don't block when locking */
00221 #define LOCK_UN         0x08            /* unlock file */
00222 #endif
00223 
00224 /*
00225  * XXX missing posix_fadvise() and posix_fallocate(), and POSIX_FADV_* macros.
00226  */
00227 
00228 #ifndef _KERNEL
00229 __BEGIN_DECLS
00230 IMPORT_C int    open(const char *, int, ...);
00231 IMPORT_C int    creat(const char *, mode_t);
00232 IMPORT_C int    fcntl(int, int, ...);
00233 #if __BSD_VISIBLE
00234 int     flock(int, int);
00235 #endif
00236 __END_DECLS
00237 #endif
00238 
00239 #endif /* !_SYS_FCNTL_H_ */

Copyright © Nokia Corporation 2001-2008
Back to top