Back to index

glibc  2.9
fcntl.h
Go to the documentation of this file.
00001 /* O_*, F_*, FD_* bit values for GNU.
00002    Copyright (C) 1993,1994,1996,1997,1998,1999,2000,2001,2004,2007
00003        Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #ifndef _FCNTL_H
00022 # error "Never use <bits/fcntl.h> directly; include <fcntl.h> instead."
00023 #endif
00024 
00025 #include <sys/types.h>
00026 
00027 /* File access modes.  These are understood by io servers; they can be
00028    passed in `dir_lookup', and are returned by `io_get_openmodes'.
00029    Consequently they can be passed to `open', `hurd_file_name_lookup', and
00030    `file_name_lookup'; and are returned by `fcntl' with the F_GETFL
00031    command.  */
00032 
00033 /* In GNU, read and write are bits (unlike BSD).  */
00034 #ifdef __USE_GNU
00035 # define O_READ             O_RDONLY /* Open for reading.  */
00036 # define O_WRITE     O_WRONLY /* Open for writing.  */
00037 # define O_EXEC             0x0004 /* Open for execution.  */
00038 # define O_NORW             0      /* Open without R/W access.  */
00039 #endif
00040 /* POSIX.1 standard names.  */
00041 #define       O_RDONLY      0x0001 /* Open read-only.  */
00042 #define       O_WRONLY      0x0002 /* Open write-only.  */
00043 #define       O_RDWR        (O_RDONLY|O_WRONLY) /* Open for reading and writing. */
00044 #define       O_ACCMODE     O_RDWR /* Mask for file access modes.  */
00045 
00046 #define O_LARGEFILE  0
00047 
00048 
00049 /* File name translation flags.  These are understood by io servers;
00050    they can be passed in `dir_lookup', and consequently to `open',
00051    `hurd_file_name_lookup', and `file_name_lookup'.  */
00052 
00053 #define       O_CREAT              0x0010 /* Create file if it doesn't exist.  */
00054 #define       O_EXCL        0x0020 /* Fail if file already exists.  */
00055 #ifdef __USE_GNU
00056 # define O_NOLINK    0x0040 /* No name mappings on final component.  */
00057 # define O_NOTRANS   0x0080 /* No translator on final component. */
00058 
00059 # define O_NOFOLLOW  0x00100000 /* Produce ENOENT if file is a symlink.  */
00060 # define O_DIRECTORY 0x00200000 /* Produce ENOTDIR if not a directory.  */
00061 #endif
00062 
00063 
00064 /* I/O operating modes.  These are understood by io servers; they can be
00065    passed in `dir_lookup' and set or fetched with `io_*_openmodes'.
00066    Consequently they can be passed to `open', `hurd_file_name_lookup',
00067    `file_name_lookup', and `fcntl' with the F_SETFL command; and are
00068    returned by `fcntl' with the F_GETFL command.  */
00069 
00070 #define       O_APPEND      0x0100 /* Writes always append to the file.  */
00071 #define O_ASYNC             0x0200 /* Send SIGIO to owner when data is ready.  */
00072 #define O_FSYNC             0x0400 /* Synchronous writes.  */
00073 #define O_SYNC              O_FSYNC
00074 #ifdef __USE_GNU
00075 # define O_NOATIME   0x0800 /* Don't set access time on read (owner).  */
00076 #endif
00077 #ifdef __USE_MISC
00078 # define O_SHLOCK    0x00020000 /* Open with shared file lock.  */
00079 # define O_EXLOCK    0x00040000 /* Open with exclusive file lock.  */
00080 #endif
00081 
00082 /* These are lesser flavors of partial synchronization that are
00083    implied by our one flag (O_FSYNC).  */
00084 #if defined __USE_POSIX199309 || defined __USE_UNIX98
00085 # define O_DSYNC     O_SYNC /* Synchronize data.  */
00086 # define O_RSYNC     O_SYNC /* Synchronize read operations.     */
00087 #endif
00088 
00089 
00090 /* The name O_NONBLOCK is unfortunately overloaded; it is both a file name
00091    translation flag and an I/O operating mode.  O_NDELAY is the deprecated
00092    BSD name for the same flag, overloaded in the same way.
00093 
00094    When used in `dir_lookup' (and consequently `open', `hurd_file_name_lookup',
00095    or `file_name_lookup'), O_NONBLOCK says the open should return immediately
00096    instead of blocking for any significant length of time (e.g., to wait
00097    for carrier detect on a serial line).  It is also saved as an I/O
00098    operating mode, and after open has the following meaning.
00099 
00100    When used in `io_*_openmodes' (and consequently `fcntl' with the F_SETFL
00101    command), the O_NONBLOCK flag means to do nonblocking i/o: any i/o
00102    operation that would block for any significant length of time will instead
00103    fail with EAGAIN.  */
00104 
00105 #define       O_NONBLOCK    0x0008 /* Non-blocking open or non-blocking I/O.  */
00106 #ifdef __USE_BSD
00107 # define O_NDELAY    O_NONBLOCK /* Deprecated.  */
00108 #endif
00109 
00110 
00111 #ifdef __USE_GNU
00112 /* Mask of bits which are understood by io servers.  */
00113 # define O_HURD             (0xffff | O_EXLOCK | O_SHLOCK)
00114 #endif
00115 
00116 
00117 /* Open-time action flags.  These are understood by `hurd_file_name_lookup'
00118    and consequently by `open' and `file_name_lookup'.  They are not preserved
00119    once the file has been opened.  */
00120 
00121 #define       O_TRUNC              0x00010000 /* Truncate file to zero length.  */
00122 #ifdef __USE_GNU
00123 # define O_CLOEXEC   0x00400000 /* Set FD_CLOEXEC.  */
00124 #endif
00125 
00126 
00127 /* Controlling terminal flags.  These are understood only by `open',
00128    and are not preserved once the file has been opened.  */
00129 
00130 #ifdef __USE_GNU
00131 # define O_IGNORE_CTTY      0x00080000 /* Don't do any ctty magic at all.  */
00132 #endif
00133 /* `open' never assigns a controlling terminal in GNU.  */
00134 #define       O_NOCTTY      0      /* Don't assign a controlling terminal.  */
00135 
00136 
00137 #ifdef __USE_BSD
00138 /* Bits in the file status flags returned by F_GETFL.  */
00139 # define FREAD              O_RDONLY
00140 # define FWRITE             O_WRONLY
00141 
00142 /* Traditional BSD names the O_* bits.  */
00143 # define FASYNC             O_ASYNC
00144 # define FCREAT             O_CREAT
00145 # define FEXCL              O_EXCL
00146 # define FTRUNC             O_TRUNC
00147 # define FNOCTTY     O_NOCTTY
00148 # define FFSYNC             O_FSYNC
00149 # define FSYNC              O_SYNC
00150 # define FAPPEND     O_APPEND
00151 # define FNONBLOCK   O_NONBLOCK
00152 # define FNDELAY     O_NDELAY
00153 #endif
00154 
00155 
00156 /* Values for the second argument to `fcntl'.  */
00157 #define       F_DUPFD              0      /* Duplicate file descriptor.  */
00158 #define       F_GETFD              1      /* Get file descriptor flags.  */
00159 #define       F_SETFD              2      /* Set file descriptor flags.  */
00160 #define       F_GETFL              3      /* Get file status flags.  */
00161 #define       F_SETFL              4      /* Set file status flags.  */
00162 #if defined __USE_BSD || defined __USE_UNIX98
00163 # define F_GETOWN    5      /* Get owner (receiver of SIGIO).  */
00164 # define F_SETOWN    6      /* Set owner (receiver of SIGIO).  */
00165 #endif
00166 #define       F_GETLK              7      /* Get record locking info.  */
00167 #define       F_SETLK              8      /* Set record locking info (non-blocking).  */
00168 #define       F_SETLKW      9      /* Set record locking info (blocking).  */
00169 
00170 #ifdef __USE_GNU
00171 # define F_DUPFD_CLOEXEC 1030      /* Duplicate, set FD_CLOEXEC on new one.  */
00172 #endif
00173 
00174 
00175 /* File descriptor flags used with F_GETFD and F_SETFD.  */
00176 #define       FD_CLOEXEC    1      /* Close on exec.  */
00177 
00178 
00179 #include <bits/types.h>
00180 
00181 /* The structure describing an advisory lock.  This is the type of the third
00182    argument to `fcntl' for the F_GETLK, F_SETLK, and F_SETLKW requests.  */
00183 struct flock
00184   {
00185     int l_type;             /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
00186     int l_whence;    /* Where `l_start' is relative to (like `lseek').  */
00187 #ifndef __USE_FILE_OFFSET64
00188     __off_t l_start; /* Offset where the lock begins.  */
00189     __off_t l_len;   /* Size of the locked area; zero means until EOF.  */
00190 #else
00191     __off64_t l_start;      /* Offset where the lock begins.  */
00192     __off64_t l_len; /* Size of the locked area; zero means until EOF.  */
00193 #endif
00194     __pid_t l_pid;   /* Process holding the lock.  */
00195   };
00196 
00197 #ifdef __USE_LARGEFILE64
00198 struct flock64
00199   {
00200     int l_type;             /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
00201     int l_whence;    /* Where `l_start' is relative to (like `lseek').  */
00202     __off64_t l_start;      /* Offset where the lock begins.  */
00203     __off64_t l_len; /* Size of the locked area; zero means until EOF.  */
00204     __pid_t l_pid;   /* Process holding the lock.  */
00205   };
00206 #endif
00207 
00208 /* Values for the `l_type' field of a `struct flock'.  */
00209 #define       F_RDLCK       1      /* Read lock.  */
00210 #define       F_WRLCK       2      /* Write lock.  */
00211 #define       F_UNLCK       3      /* Remove lock.  */
00212 
00213 /* Advise to `posix_fadvise'.  */
00214 #ifdef __USE_XOPEN2K
00215 # define POSIX_FADV_NORMAL  0 /* No further special treatment.  */
00216 # define POSIX_FADV_RANDOM  1 /* Expect random page references.  */
00217 # define POSIX_FADV_SEQUENTIAL     2 /* Expect sequential page references.  */
00218 # define POSIX_FADV_WILLNEED       3 /* Will need these pages.  */
00219 # define POSIX_FADV_DONTNEED       4 /* Don't need these pages.  */
00220 # define POSIX_FADV_NOREUSE 5 /* Data will be accessed once.  */
00221 #endif