Back to index

glibc  2.9
fcntl.h
Go to the documentation of this file.
00001 /* O_*, F_*, FD_* bit values for Linux/SPARC.
00002    Copyright (C) 1995, 1996, 1997, 1998, 2000, 2003, 2004, 2006, 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 #include <bits/wordsize.h>
00027 #ifdef __USE_GNU
00028 # include <bits/uio.h>
00029 #endif
00030 
00031 /* open/fcntl - O_SYNC is only implemented on blocks devices and on files
00032    located on an ext2 file system */
00033 #define O_RDONLY     0x0000
00034 #define O_WRONLY     0x0001
00035 #define O_RDWR              0x0002
00036 #define O_ACCMODE    0x0003
00037 #define O_APPEND     0x0008
00038 #define O_ASYNC             0x0040
00039 #define O_CREAT             0x0200 /* not fcntl */
00040 #define O_TRUNC             0x0400 /* not fcntl */
00041 #define O_EXCL              0x0800 /* not fcntl */
00042 #define O_SYNC              0x2000
00043 #define O_NONBLOCK   0x4000
00044 #define O_NDELAY     (0x0004 | O_NONBLOCK)
00045 #define O_NOCTTY     0x8000 /* not fcntl */
00046 
00047 #ifdef __USE_GNU
00048 # define O_DIRECTORY 0x10000 /* must be a directory */
00049 # define O_NOFOLLOW  0x20000 /* don't follow links */
00050 # define O_DIRECT    0x100000 /* direct disk access hint */
00051 # define O_NOATIME   0x200000 /* Do not set atime.  */
00052 # define O_CLOEXEC   0x400000 /* Set close_on_exit.  */
00053 #endif
00054 
00055 #ifdef __USE_LARGEFILE64
00056 # if __WORDSIZE == 64
00057 #  define O_LARGEFILE       0
00058 # else
00059 #  define O_LARGEFILE       0x40000
00060 # endif
00061 #endif
00062 
00063 /* For now Linux has no synchronisity options for data and read
00064    operations.  We define the symbols here but let them do the same as
00065    O_SYNC since this is a superset.  */
00066 #if defined __USE_POSIX199309 || defined __USE_UNIX98
00067 # define O_DSYNC     O_SYNC /* Synchronize data.  */
00068 # define O_RSYNC     O_SYNC /* Synchronize read operations.  */
00069 #endif
00070 
00071 /* For now Linux has synchronisity options for data and read operations.
00072    We define the symbols here but let them do the same as O_SYNC since
00073    this is a superset.  */
00074 #if defined __USE_POSIX199309 || defined __USE_UNIX98
00075 # define O_DSYNC        O_SYNC  /* Synchronize data.  */
00076 # define O_RSYNC        O_SYNC  /* Synchronize read operations.  */
00077 #endif
00078 
00079 /* Values for the second argument to `fcntl'.  */
00080 #define F_DUPFD             0      /* Duplicate file descriptor.  */
00081 #define F_GETFD             1      /* Get file descriptor flags.  */
00082 #define F_SETFD             2      /* Set file descriptor flags.  */
00083 #define F_GETFL             3      /* Get file status flags.  */
00084 #define F_SETFL             4      /* Set file status flags.  */
00085 #if defined __USE_BSD || defined __USE_UNIX98
00086 # define F_GETOWN    5      /* Get owner of socket (receiver of SIGIO).  */
00087 # define F_SETOWN    6      /* Set owner of socket (receiver of SIGIO).  */
00088 #endif
00089 #ifndef __USE_FILE_OFFSET64
00090 # define F_GETLK     7      /* Get record locking info.  */
00091 # define F_SETLK     8      /* Set record locking info (non-blocking).  */
00092 # define F_SETLKW    9      /* Set record locking info (blocking).  */
00093 #else
00094 # define F_GETLK     F_GETLK64  /* Get record locking info.  */
00095 # define F_SETLK     F_SETLK64  /* Set record locking info (non-blocking).*/
00096 # define F_SETLKW    F_SETLKW64 /* Set record locking info (blocking).  */
00097 #endif
00098 
00099 #ifdef __USE_GNU
00100 # define F_SETSIG    10     /* Set number of signal to be sent.  */
00101 # define F_GETSIG    11     /* Get number of signal to be sent.  */
00102 #endif
00103 
00104 #ifdef __USE_GNU
00105 # define F_SETLEASE     1024       /* Set a lease.  */
00106 # define F_GETLEASE     1025       /* Enquire what lease is active.  */
00107 # define F_NOTIFY       1026       /* Request notfications on a directory.  */
00108 # define F_DUPFD_CLOEXEC 1030      /* Duplicate file descriptor with
00109                                close-on-exit set.  */
00110 #endif
00111 
00112 #if __WORDSIZE == 64
00113 # define F_GETLK64   7      /* Get record locking info.  */
00114 # define F_SETLK64   8      /* Set record locking info (non-blocking).  */
00115 # define F_SETLKW64  9      /* Set record locking info (blocking).  */
00116 #else
00117 # define F_GETLK64   12     /* Get record locking info.  */
00118 # define F_SETLK64   13     /* Set record locking info (non-blocking).  */
00119 # define F_SETLKW64  14     /* Set record locking info (blocking).  */
00120 #endif
00121 
00122 /* for F_[GET|SET]FD */
00123 #define FD_CLOEXEC   1      /* actually anything with low bit set goes */
00124 
00125 /* For posix fcntl() and `l_type' field of a `struct flock' for lockf().  */
00126 #define F_RDLCK             1      /* Read lock.  */
00127 #define F_WRLCK             2      /* Write lock.  */
00128 #define F_UNLCK             3      /* Remove lock.  */
00129 
00130 /* for old implementation of bsd flock () */
00131 #define F_EXLCK             4      /* or 3 */
00132 #define F_SHLCK             8      /* or 4 */
00133 
00134 #ifdef __USE_BSD
00135 /* Operations for bsd flock(), also used by the kernel implementation */
00136 # define LOCK_SH     1      /* shared lock */
00137 # define LOCK_EX     2      /* exclusive lock */
00138 # define LOCK_NB     4      /* or'd with one of the above to prevent
00139                                blocking */
00140 # define LOCK_UN     8      /* remove lock */
00141 #endif
00142 
00143 #ifdef __USE_GNU
00144 # define LOCK_MAND   32     /* This is a mandatory flock:      */
00145 # define LOCK_READ   64     /* ... which allows concurrent read operations.   */
00146 # define LOCK_WRITE  128    /* ... which allows concurrent write operations.  */
00147 # define LOCK_RW     192    /* ... Which allows concurrent read & write operations.  */
00148 #endif
00149 
00150 #ifdef __USE_GNU
00151 /* Types of directory notifications that may be requested with F_NOTIFY.  */
00152 # define DN_ACCESS   0x00000001    /* File accessed.  */
00153 # define DN_MODIFY   0x00000002    /* File modified.  */
00154 # define DN_CREATE   0x00000004    /* File created.  */
00155 # define DN_DELETE   0x00000008    /* File removed.  */
00156 # define DN_RENAME   0x00000010    /* File renamed.  */
00157 # define DN_ATTRIB   0x00000020    /* File changed attibutes.  */
00158 # define DN_MULTISHOT       0x80000000    /* Don't remove notifier.  */
00159 #endif
00160 
00161 struct flock
00162   {
00163     short int l_type;       /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
00164     short int l_whence;     /* Where `l_start' is relative to (like `lseek').  */
00165 #ifndef __USE_FILE_OFFSET64
00166     __off_t l_start; /* Offset where the lock begins.  */
00167     __off_t l_len;   /* Size of the locked area; zero means until EOF.  */
00168 #else
00169     __off64_t l_start;      /* Offset where the lock begins.  */
00170     __off64_t l_len; /* Size of the locked area; zero means until EOF.  */
00171 #endif
00172     __pid_t l_pid;   /* Process holding the lock.  */
00173     short int __unused;
00174   };
00175 
00176 #ifdef __USE_LARGEFILE64
00177 struct flock64
00178   {
00179     short int l_type;       /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK.  */
00180     short int l_whence;     /* Where `l_start' is relative to (like `lseek').  */
00181     __off64_t l_start;      /* Offset where the lock begins.  */
00182     __off64_t l_len; /* Size of the locked area; zero means until EOF.  */
00183     __pid_t l_pid;   /* Process holding the lock.  */
00184     short int __unused;
00185   };
00186 #endif
00187 
00188 /* Define some more compatibility macros to be backward compatible with
00189    BSD systems which did not managed to hide these kernel macros.  */
00190 #ifdef __USE_BSD
00191 # define FAPPEND     O_APPEND
00192 # define FFSYNC             O_FSYNC
00193 # define FASYNC             O_ASYNC
00194 # define FNONBLOCK   O_NONBLOCK
00195 # define FNDELAY     O_NDELAY
00196 #endif /* Use BSD.  */
00197 
00198 /* Advise to `posix_fadvise'.  */
00199 #ifdef __USE_XOPEN2K
00200 # define POSIX_FADV_NORMAL  0 /* No further special treatment.  */
00201 # define POSIX_FADV_RANDOM  1 /* Expect random page references.  */
00202 # define POSIX_FADV_SEQUENTIAL     2 /* Expect sequential page references.  */
00203 # define POSIX_FADV_WILLNEED       3 /* Will need these pages.  */
00204 # define POSIX_FADV_DONTNEED       4 /* Don't need these pages.  */
00205 # define POSIX_FADV_NOREUSE 5 /* Data will be accessed once.  */
00206 #endif
00207 
00208 
00209 #ifdef __USE_GNU
00210 /* Flags for SYNC_FILE_RANGE.  */
00211 # define SYNC_FILE_RANGE_WAIT_BEFORE      1 /* Wait upon writeout of all pages
00212                                         in the range before performing the
00213                                         write.  */
00214 # define SYNC_FILE_RANGE_WRITE            2 /* Initiate writeout of all those
00215                                         dirty pages in the range which are
00216                                         not presently under writeback.  */
00217 # define SYNC_FILE_RANGE_WAIT_AFTER       4 /* Wait upon writeout of all pages in
00218                                         the range after performing the
00219                                         write.  */
00220 
00221 /* Flags for SPLICE and VMSPLICE.  */
00222 # define SPLICE_F_MOVE             1      /* Move pages instead of copying.  */
00223 # define SPLICE_F_NONBLOCK  2      /* Don't block on the pipe splicing
00224                                       (but we may still block on the fd
00225                                       we splice from/to).  */
00226 # define SPLICE_F_MORE             4      /* Expect more data.  */
00227 # define SPLICE_F_GIFT             8      /* Pages passed in are a gift.  */
00228 #endif
00229 
00230 __BEGIN_DECLS
00231 
00232 #ifdef __USE_GNU
00233 
00234 /* Provide kernel hint to read ahead.  */
00235 extern ssize_t readahead (int __fd, __off64_t __offset, size_t __count)
00236     __THROW;
00237 
00238 
00239 /* Selective file content synch'ing.  */
00240 extern int sync_file_range (int __fd, __off64_t __from, __off64_t __to,
00241                          unsigned int __flags);
00242 
00243 
00244 /* Splice address range into a pipe.  */
00245 extern ssize_t vmsplice (int __fdout, const struct iovec *__iov,
00246                       size_t __count, unsigned int __flags);
00247 
00248 /* Splice two files together.  */
00249 extern ssize_t splice (int __fdin, __off64_t *__offin, int __fdout,
00250                      __off64_t *__offout, size_t __len,
00251                      unsigned int __flags);
00252 
00253 /* In-kernel implementation of tee for pipe buffers.  */
00254 extern ssize_t tee (int __fdin, int __fdout, size_t __len,
00255                   unsigned int __flags);
00256 
00257 #endif
00258 
00259 __END_DECLS