]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/Include/sys/fcntl.h
StdLib: Fix some build problems and obscure bugs.
[mirror_edk2.git] / StdLib / Include / sys / fcntl.h
CommitLineData
2aa62f2b 1/** @file\r
2 This file includes the definitions for open and fcntl described by POSIX\r
3 for <fcntl.h>; it also includes related kernel definitions.\r
4\r
0164fc8e 5 Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
2aa62f2b 6 This program and the accompanying materials are licensed and made\r
7 available under the terms and conditions of the BSD License which\r
8 accompanies this distribution. The full text of the license may be found\r
8379337c 9 at http://opensource.org/licenses/bsd-license.\r
2aa62f2b 10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14 Copyright (c) 1983, 1990, 1993\r
15 The Regents of the University of California. All rights reserved.\r
16 (c) UNIX System Laboratories, Inc.\r
17 All or some portions of this file are derived from material licensed\r
18 to the University of California by American Telephone and Telegraph\r
19 Co. or Unix System Laboratories, Inc. and are reproduced herein with\r
20 the permission of UNIX System Laboratories, Inc.\r
21\r
22 Redistribution and use in source and binary forms, with or without\r
23 modification, are permitted provided that the following conditions\r
24 are met:\r
25 1. Redistributions of source code must retain the above copyright\r
26 notice, this list of conditions and the following disclaimer.\r
27 2. Redistributions in binary form must reproduce the above copyright\r
28 notice, this list of conditions and the following disclaimer in the\r
29 documentation and/or other materials provided with the distribution.\r
30 3. Neither the name of the University nor the names of its contributors\r
31 may be used to endorse or promote products derived from this software\r
32 without specific prior written permission.\r
33\r
34 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
35 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
36 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
37 ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
38 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
39 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
40 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
41 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
42 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
43 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
44 SUCH DAMAGE.\r
45\r
46 fcntl.h 8.3 (Berkeley) 1/21/94\r
47 NetBSD: fcntl.h,v 1.34 2006/10/05 14:48:33 chs Exp\r
48 */\r
49#ifndef _SYS_FCNTL_H_\r
50#define _SYS_FCNTL_H_\r
51\r
52#include <sys/featuretest.h>\r
53#include <sys/types.h>\r
54\r
55#include <sys/stat.h>\r
56\r
0c1992fb 57/** @{\r
58 File status flags used by open(2), fcntl(2).\r
8379337c 59 They are also used (indirectly) in the kernel file structure f_flags,\r
60 which is a superset of the open/fcntl flags.\r
61 Open/fcntl flags begin with O_; kernel-internal flags begin with F.\r
8379337c 62**/\r
2aa62f2b 63/* open-only flags */\r
8379337c 64#define O_RDONLY 0x00000000 ///< open for reading only\r
65#define O_WRONLY 0x00000001 ///< open for writing only\r
66#define O_RDWR 0x00000002 ///< open for reading and writing\r
67#define O_ACCMODE 0x00000003 ///< mask for above modes\r
68\r
69#define O_NONBLOCK 0x00000004 ///< no delay\r
70#define O_APPEND 0x00000008 ///< set append mode\r
71#define O_CREAT 0x00000200 ///< create if nonexistent\r
72#define O_TRUNC 0x00000400 ///< truncate to zero length\r
0164fc8e 73#define O_EXCL 0x00000800 ///< Grant EXCLusive access, or error if already exists and O_CREAT\r
0c1992fb 74\r
c352b298 75#define O_DIRECTORY 0x00001000 ///< error if path is not a directory\r
76#define O_NOCTTY 0x00002000 ///< Don't make this the controlling TTY\r
77#define O_TTY_INIT 0x00004000 ///< Initialize TTY to "sane" values on open\r
78\r
0c1992fb 79/* UEFI-specific open-only flags. */\r
80#define O_HIDDEN 0x00010000 ///< Hidden file attribute\r
81#define O_SYSTEM 0x00020000 ///< System file attribute\r
82#define O_ARCHIVE 0x00040000 ///< Archive file attribute\r
8379337c 83/// @}\r
2aa62f2b 84\r
8379337c 85#define O_SETMASK 0x0000000F ///< Flags modifiable by F_SETFD (fcntl)\r
2aa62f2b 86\r
87/*\r
88 * Constants used for fcntl(2)\r
89 */\r
90\r
0c1992fb 91/** @{ command values used for fcntl(2). **/\r
8379337c 92#define F_DUPFD 0 ///< duplicate file descriptor\r
93#define F_GETFD 1 ///< get file descriptor flags\r
94#define F_SETFD 2 ///< set file descriptor flags\r
95#define F_GETFL 3 ///< get file status flags\r
96#define F_SETFL 4 ///< set file status flags\r
97#define F_GETOWN 5 ///< get SIGIO/SIGURG proc/pgrp\r
98#define F_SETOWN 6 ///< set SIGIO/SIGURG proc/pgrp\r
99#define F_GETLK 7 ///< get record locking information\r
100#define F_SETLK 8 ///< set record locking information\r
101#define F_SETLKW 9 ///< F_SETLK; wait if blocked\r
102#define F_CLOSEM 10 ///< close all fds >= to the one given\r
103#define F_MAXFD 11 ///< return the max open fd\r
104/// @}\r
105\r
106/** file descriptor flags (F_GETFD, F_SETFD). **/\r
107#define FD_CLOEXEC 1 ///< close-on-exec flag\r
108\r
0c1992fb 109/** @{ record locking flags (F_GETLK, F_SETLK, F_SETLKW). **/\r
8379337c 110#define F_RDLCK 1 ///< shared or read lock\r
111#define F_UNLCK 2 ///< unlock\r
112#define F_WRLCK 3 ///< exclusive or write lock\r
113/// @}\r
114\r
0c1992fb 115/** @{ Constants for fcntl's passed to the underlying fs - like ioctl's. **/\r
2aa62f2b 116#define F_PARAM_MASK 0xfff\r
117#define F_PARAM_LEN(x) (((x) >> 16) & F_PARAM_MASK)\r
118#define F_PARAM_MAX 4095\r
8379337c 119#define F_FSCTL (int)0x80000000 ///< This fcntl goes to the fs\r
120#define F_FSVOID (int)0x40000000 ///< no parameters\r
121#define F_FSOUT (int)0x20000000 ///< copy out parameter\r
122#define F_FSIN (int)0x10000000 ///< copy in parameter\r
2aa62f2b 123#define F_FSINOUT (F_FSIN | F_FSOUT)\r
8379337c 124#define F_FSDIRMASK (int)0x70000000 ///< mask for IN/OUT/VOID\r
125#define F_FSPRIV (int)0x00008000 ///< command is fs-specific\r
126/// @}\r
2aa62f2b 127\r
128/* Always ensure that these are consistent with <stdio.h> and <unistd.h>! */\r
129#ifndef SEEK_SET\r
130 #define SEEK_SET 0 /* set file offset to offset */\r
131#endif\r
132#ifndef SEEK_CUR\r
133 #define SEEK_CUR 1 /* set file offset to current plus offset */\r
134#endif\r
135#ifndef SEEK_END\r
136 #define SEEK_END 2 /* set file offset to EOF plus offset */\r
137#endif\r
138\r
139#include <sys/EfiCdefs.h>\r
140\r
141__BEGIN_DECLS\r
142#ifndef __FCNTL_SYSCALLS_DECLARED\r
143 #define __FCNTL_SYSCALLS_DECLARED\r
8379337c 144\r
145 /** The open() function establishes the connection between a file and a file\r
146 descriptor. It creates an open file description that refers to a file\r
147 and a file descriptor that refers to that open file description. The file\r
148 descriptor is used by other I/O functions to refer to that file.\r
149\r
150 The open() function returns a file descriptor for the named file that is\r
151 the lowest file descriptor not currently open for that process. The open\r
152 file description is new, and therefore the file descriptor shall not\r
153 share it with any other process in the system.\r
154\r
155 The file offset used to mark the current position within the file is set\r
156 to the beginning of the file.\r
157\r
158 The file status flags and file access modes of the open file description\r
159 are set according to the value of oflags.\r
160\r
161 Values for oflags are constructed by a bitwise-inclusive OR of flags from\r
162 the following list, defined in <fcntl.h>. Applications shall specify\r
163 exactly one of { O_RDONLY, O_RDWR, O_WRONLY } in the value of oflags.\r
164 Any combination of { O_NONBLOCK, O_APPEND, O_CREAT, O_TRUNC, O_EXCL } may\r
165 also be specified in oflags.\r
166\r
167 Values for mode specify the access permissions for newly created files.\r
168\r
169 @param[in] Path The path argument points to a pathname naming the\r
170 object to be opened.\r
171 @param[in] oflags File status flags and file access modes of the\r
172 open file description.\r
173 @param[in] mode File access permission bits as defined in\r
174 <sys/stat.h>.\r
175\r
176 @return Upon successful completion, open() opens the file and returns\r
177 a non-negative integer representing the lowest numbered\r
178 unused file descriptor. Otherwise, open returns -1 and sets\r
179 errno to indicate the error. If a negative value is\r
180 returned, no files are created or modified.\r
181\r
182 @retval EMFILE No file descriptors available -- Max number already open.\r
183 @retval EINVAL Bad value specified for oflags or mode.\r
184 @retval ENOMEM Failure allocating memory for internal buffers.\r
185 @retval EEXIST File exists and open attempted with (O_EXCL | O_CREAT) set.\r
186 @retval EIO UEFI failure. Check value in EFIerrno.\r
187 **/\r
188 int open(const char *Path, int oflags, int mode);\r
189\r
190 /**\r
191 **/\r
2aa62f2b 192 int creat(const char *, mode_t);\r
8379337c 193\r
194 /**\r
195 **/\r
2aa62f2b 196 int fcntl(int, int, ...);\r
197#endif // __FCNTL_SYSCALLS_DECLARED\r
198__END_DECLS\r
199\r
200#endif /* !_SYS_FCNTL_H_ */\r