]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/Include/sys/fcntl.h
Standard Libraries for EDK II.
[mirror_edk2.git] / StdLib / Include / sys / fcntl.h
1 /** @file
2 This file includes the definitions for open and fcntl described by POSIX
3 for <fcntl.h>; it also includes related kernel definitions.
4
5 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials are licensed and made
7 available under the terms and conditions of the BSD License which
8 accompanies this distribution. The full text of the license may be found
9 at http://opensource.org/licenses/bsd-license.php.
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 Copyright (c) 1983, 1990, 1993
15 The Regents of the University of California. All rights reserved.
16 (c) UNIX System Laboratories, Inc.
17 All or some portions of this file are derived from material licensed
18 to the University of California by American Telephone and Telegraph
19 Co. or Unix System Laboratories, Inc. and are reproduced herein with
20 the permission of UNIX System Laboratories, Inc.
21
22 Redistribution and use in source and binary forms, with or without
23 modification, are permitted provided that the following conditions
24 are met:
25 1. Redistributions of source code must retain the above copyright
26 notice, this list of conditions and the following disclaimer.
27 2. Redistributions in binary form must reproduce the above copyright
28 notice, this list of conditions and the following disclaimer in the
29 documentation and/or other materials provided with the distribution.
30 3. Neither the name of the University nor the names of its contributors
31 may be used to endorse or promote products derived from this software
32 without specific prior written permission.
33
34 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
35 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
38 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
40 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
41 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
43 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 SUCH DAMAGE.
45
46 fcntl.h 8.3 (Berkeley) 1/21/94
47 NetBSD: fcntl.h,v 1.34 2006/10/05 14:48:33 chs Exp
48 */
49 #ifndef _SYS_FCNTL_H_
50 #define _SYS_FCNTL_H_
51
52 #include <sys/featuretest.h>
53 #include <sys/types.h>
54
55 #include <sys/stat.h>
56
57 /*
58 * File status flags: these are used by open(2), fcntl(2).
59 * They are also used (indirectly) in the kernel file structure f_flags,
60 * which is a superset of the open/fcntl flags. Open flags and f_flags
61 * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags).
62 * Open/fcntl flags begin with O_; kernel-internal flags begin with F.
63 */
64 /* open-only flags */
65 #define O_RDONLY 0x00000000 /* open for reading only */
66 #define O_WRONLY 0x00000001 /* open for writing only */
67 #define O_RDWR 0x00000002 /* open for reading and writing */
68 #define O_ACCMODE 0x00000003 /* mask for above modes */
69
70 /*
71 * Kernel encoding of open mode; separate read and write bits that are
72 * independently testable: 1 greater than the above.
73 *
74 * XXX
75 * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH,
76 * which was documented to use FREAD/FWRITE, continues to work.
77 */
78 #define FREAD 0x00000001
79 #define FWRITE 0x00000002
80 #define O_NONBLOCK 0x00000004 /* no delay */
81 #define O_APPEND 0x00000008 /* set append mode */
82 #define O_CREAT 0x00000200 /* create if nonexistent */
83 #define O_TRUNC 0x00000400 /* truncate to zero length */
84 #define O_EXCL 0x00000800 /* error if already exists */
85
86 //#define O_DIRECT 0x00080000 /* direct I/O hint */
87
88 #define O_SETMASK 0x0000000F /* Flags modifiable by F_SETFD (fcntl) */
89
90 /*
91 * Constants used for fcntl(2)
92 */
93
94 /* command values */
95 #define F_DUPFD 0 /* duplicate file descriptor */
96 #define F_GETFD 1 /* get file descriptor flags */
97 #define F_SETFD 2 /* set file descriptor flags */
98 #define F_GETFL 3 /* get file status flags */
99 #define F_SETFL 4 /* set file status flags */
100 #define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */
101 #define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */
102 #define F_GETLK 7 /* get record locking information */
103 #define F_SETLK 8 /* set record locking information */
104 #define F_SETLKW 9 /* F_SETLK; wait if blocked */
105 #define F_CLOSEM 10 /* close all fds >= to the one given */
106 #define F_MAXFD 11 /* return the max open fd */
107
108 /* file descriptor flags (F_GETFD, F_SETFD) */
109 #define FD_CLOEXEC 1 /* close-on-exec flag */
110
111 /* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */
112 #define F_RDLCK 1 /* shared or read lock */
113 #define F_UNLCK 2 /* unlock */
114 #define F_WRLCK 3 /* exclusive or write lock */
115
116 /* Constants for fcntl's passed to the underlying fs - like ioctl's. */
117 #define F_PARAM_MASK 0xfff
118 #define F_PARAM_LEN(x) (((x) >> 16) & F_PARAM_MASK)
119 #define F_PARAM_MAX 4095
120 #define F_FSCTL (int)0x80000000 /* This fcntl goes to the fs */
121 #define F_FSVOID (int)0x40000000 /* no parameters */
122 #define F_FSOUT (int)0x20000000 /* copy out parameter */
123 #define F_FSIN (int)0x10000000 /* copy in parameter */
124 #define F_FSINOUT (F_FSIN | F_FSOUT)
125 #define F_FSDIRMASK (int)0x70000000 /* mask for IN/OUT/VOID */
126 #define F_FSPRIV (int)0x00008000 /* command is fs-specific */
127
128 /* Always ensure that these are consistent with <stdio.h> and <unistd.h>! */
129 #ifndef SEEK_SET
130 #define SEEK_SET 0 /* set file offset to offset */
131 #endif
132 #ifndef SEEK_CUR
133 #define SEEK_CUR 1 /* set file offset to current plus offset */
134 #endif
135 #ifndef SEEK_END
136 #define SEEK_END 2 /* set file offset to EOF plus offset */
137 #endif
138
139 #include <sys/EfiCdefs.h>
140
141 __BEGIN_DECLS
142 #ifndef __FCNTL_SYSCALLS_DECLARED
143 #define __FCNTL_SYSCALLS_DECLARED
144 int open(const char *, int, int );
145 int creat(const char *, mode_t);
146 int fcntl(int, int, ...);
147 #endif // __FCNTL_SYSCALLS_DECLARED
148 __END_DECLS
149
150 #endif /* !_SYS_FCNTL_H_ */