XenevaOS
Loading...
Searching...
No Matches
fcntl.h
Go to the documentation of this file.
1#ifndef __LINUX_FCNTL_H__
2#define __LINUX_FCNTL_H__
3
4/*
5 * DCL <linux/fcntl.h> -- open(2) flags and the F_* commands.
6 *
7 * Ported from mainline's uapi/asm-generic/fcntl.h (what arm64 uses), values
8 * verbatim. The header exists because <linux/tty.h> tests file->f_flags:
9 * tty_io_nonblock() is `file->f_flags & O_NONBLOCK || ...`, and an undefined
10 * O_NONBLOCK would turn into an implicit declaration of an identifier the
11 * preprocessor never saw -- it would not be "always false", it would not
12 * compile.
13 *
14 * ---------------------------------------------------------------------------
15 * KNOWN DIVERGENCE, recorded here because the day it matters will be the day
16 * someone opens /dev/ttyS0 with O_NONBLOCK from userspace.
17 *
18 * Xeneva's userspace libc (Libs/XEClib/includes/fcntl.h) assigns a different
19 * bit layout entirely:
20 *
21 * userspace (XEClib) this header (asm-generic)
22 * O_NONBLOCK 0x0080 O_NONBLOCK 0x0800 (1 << 11)
23 * O_NOCTTY 0x0004 O_NOCTTY 0x0100 (1 << 8)
24 * O_RDWR 0x0800 O_RDWR 0x0002
25 * F_SETFL 0x0010 F_SETFL 0x0004
26 *
27 * This header follows mainline for two reasons: every ported file is written
28 * against mainline's numbers, and DCL's own cdev bridge already picked one --
29 * linux_cdev_shim.c:507 defines DCL_O_NONBLOCK as 0x800 with the comment
30 * "asm-generic fcntl.h: 00004000". Changing it now would silently change
31 * behaviour that already works.
32 *
33 * It is safe *today* because nothing yet carries a userspace flag into
34 * f_flags: there is no `f_flags =` assignment anywhere in the tree (the only
35 * writer is that cdev selftest, which ORs the value in by hand), so every
36 * open file reads as flags == 0 and the tty layer behaves blocking, which is
37 * the correct default. The reconciliation -- most likely teaching XEClib the
38 * Linux layout, since ported code assumes it -- belongs with the stage that
39 * first wires a real open() through to tty_open(). It is listed in the
40 * tracker rather than resolved here, because guessing which side should move
41 * without a working open path would be exactly that: a guess.
42 * ---------------------------------------------------------------------------
43 */
44
45#define O_ACCMODE 3
46#define O_RDONLY 0
47#define O_WRONLY (1 << 0)
48#define O_RDWR (1 << 1)
49#ifndef O_CREAT
50#define O_CREAT (1 << 6) /* not fcntl */
51#endif
52#ifndef O_EXCL
53#define O_EXCL (1 << 7) /* not fcntl */
54#endif
55#ifndef O_NOCTTY
56#define O_NOCTTY (1 << 8) /* not fcntl */
57#endif
58#ifndef O_TRUNC
59#define O_TRUNC (1 << 9) /* not fcntl */
60#endif
61#ifndef O_APPEND
62#define O_APPEND (1 << 10)
63#endif
64#ifndef O_NONBLOCK
65#define O_NONBLOCK (1 << 11)
66#endif
67#ifndef O_DSYNC
68#define O_DSYNC (1 << 12)
69#endif
70#ifndef FASYNC
71#define FASYNC (1 << 13) /* fcntl, for BSD compatibility */
72#endif
73#ifndef O_DIRECT
74#define O_DIRECT (1 << 14)
75#endif
76#ifndef O_LARGEFILE
77#define O_LARGEFILE (1 << 15)
78#endif
79#ifndef O_DIRECTORY
80#define O_DIRECTORY (1 << 16)
81#endif
82#ifndef O_NOFOLLOW
83#define O_NOFOLLOW (1 << 17)
84#endif
85#ifndef O_NOATIME
86#define O_NOATIME (1 << 18)
87#endif
88#ifndef O_CLOEXEC
89#define O_CLOEXEC (1 << 19)
90#endif
91#ifndef O_SYNC
92#define __O_SYNC (1 << 20)
93#define O_SYNC (__O_SYNC | O_DSYNC)
94#endif
95#ifndef O_PATH
96#define O_PATH (1 << 21)
97#endif
98#ifndef __O_TMPFILE
99#define __O_TMPFILE (1 << 22)
100#endif
101#ifndef O_EMPTYPATH
102#define O_EMPTYPATH (1 << 26)
103#endif
104
105#define O_TMPFILE (__O_TMPFILE | O_DIRECTORY)
106
107#ifndef O_NDELAY
108#define O_NDELAY O_NONBLOCK
109#endif
110
111#define F_DUPFD 0 /* dup */
112#define F_GETFD 1 /* get close_on_exec */
113#define F_SETFD 2 /* set/clear close_on_exec */
114#define F_GETFL 3 /* get file->f_flags */
115#define F_SETFL 4 /* set file->f_flags */
116#ifndef F_GETLK
117#define F_GETLK 5
118#define F_SETLK 6
119#define F_SETLKW 7
120#endif
121#ifndef F_SETOWN
122#define F_SETOWN 8 /* for sockets. */
123#define F_GETOWN 9 /* for sockets. */
124#endif
125#ifndef F_SETSIG
126#define F_SETSIG 10 /* for sockets. */
127#define F_GETSIG 11 /* for sockets. */
128#endif
129#ifndef F_GETLK64
130#define F_GETLK64 12
131#define F_SETLK64 13
132#define F_SETLKW64 14
133#endif
134#ifndef F_SETOWN_EX
135#define F_SETOWN_EX 15
136#define F_GETOWN_EX 16
137#endif
138#ifndef F_GETOWNER_UIDS
139#define F_GETOWNER_UIDS 17
140#endif
141
142#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
143
144#ifndef F_RDLCK
145#define F_RDLCK 0
146#define F_WRLCK 1
147#define F_UNLCK 2
148#endif
149
150#define LOCK_SH 1 /* shared lock */
151#define LOCK_EX 2 /* exclusive lock */
152#define LOCK_NB 4 /* or'd with one of the above to prevent
153 * blocking */
154#define LOCK_UN 8 /* remove lock */
156#define F_LINUX_SPECIFIC_BASE 1024
157
158/*
159 * Deliberately *not* <linux/types.h>, which mainline's fcntl.h does include.
160 *
161 * mainline needs it because the full uapi surface carries types: struct
162 * flock, struct f_owner_ex, flock64, struct falloc and the __kernel_* types
163 * they are built from. DCL's port is every #define above and nothing else --
164 * grep for a non-# line in this file and there are none -- so types.h was
165 * carrying nothing.
166 *
167 * It was carrying something, though, and it is worth recording why it is
168 * gone: types.h's only include is <linux/kernel.h> (types.h:21), which is the
169 * aggregator -- virtio.h, completion.h, wait.h, sched.h. So a header of
170 * numeric constants was reaching <linux/sched.h>, which `#undef current` and
171 * redefines the word as a macro. struct __VFS_NODE__ (BaseHdr/Fs/vfs.h:105)
172 * has a `uint64_t current` member, so a file that includes <Fs/vfs.h> after
173 * anything which touched this header came out with "field declared as a
174 * function" pointing at that member. linux_cdev_shim.c hit exactly that: it
175 * includes <linux/file.h> at line 9 and <Fs/vfs.h> at line 11, and file.h
176 * owes this header because mainline's fs.h includes it.
177 *
178 * If anyone adds struct flock or any other type here, <linux/types.h> comes
179 * back with it, and the collision comes back with that. The way round it
180 * then is to include <linux/fcntl.h> before <Fs/vfs.h>, not to make the
181 * member go away -- Xeneva's VFS layout is not this tree's to move.
182 */
183
184#endif /* __LINUX_FCNTL_H__ */