Print this page
3665 Implement O_CLOEXEC as an open() flag
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Gordon Ross <gwr@nexenta.com>
Reviewed by: Dan McDonald <danmcd@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/sys/file.h
+++ new/usr/src/uts/common/sys/file.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 */
25 25
26 26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 27 /* All Rights Reserved */
28 28
29 +/* Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved. */
30 +
29 31 #ifndef _SYS_FILE_H
30 32 #define _SYS_FILE_H
31 33
32 34 #include <sys/t_lock.h>
33 35 #ifdef _KERNEL
34 36 #include <sys/model.h>
35 37 #include <sys/user.h>
36 38 #endif
37 39
38 40 #ifdef __cplusplus
39 41 extern "C" {
40 42 #endif
41 43
42 44 /*
43 45 * fio locking:
44 46 * f_rwlock protects f_vnode and f_cred
45 47 * f_tlock protects the rest
46 48 *
47 49 * The purpose of locking in this layer is to keep the kernel
48 50 * from panicing if, for example, a thread calls close() while
49 51 * another thread is doing a read(). It is up to higher levels
50 52 * to make sure 2 threads doing I/O to the same file don't
51 53 * screw each other up.
52 54 */
53 55 /*
54 56 * One file structure is allocated for each open/creat/pipe call.
55 57 * Main use is to hold the read/write pointer associated with
56 58 * each open file.
57 59 */
58 60 typedef struct file {
59 61 kmutex_t f_tlock; /* short term lock */
60 62 ushort_t f_flag;
61 63 ushort_t f_flag2; /* extra flags (FSEARCH, FEXEC) */
62 64 struct vnode *f_vnode; /* pointer to vnode structure */
63 65 offset_t f_offset; /* read/write character pointer */
64 66 struct cred *f_cred; /* credentials of user who opened it */
65 67 struct f_audit_data *f_audit_data; /* file audit data */
66 68 int f_count; /* reference count */
67 69 } file_t;
68 70
69 71 /*
70 72 * fpollinfo struct - used by poll caching to track who has polled the fd
71 73 */
72 74 typedef struct fpollinfo {
73 75 struct _kthread *fp_thread; /* thread caching poll info */
74 76 struct fpollinfo *fp_next;
75 77 } fpollinfo_t;
76 78
77 79 /* f_flag */
78 80
79 81 #define FOPEN 0xffffffff
80 82 #define FREAD 0x01 /* <sys/aiocb.h> LIO_READ must be identical */
81 83 #define FWRITE 0x02 /* <sys/aiocb.h> LIO_WRITE must be identical */
82 84 #define FNDELAY 0x04
83 85 #define FAPPEND 0x08
84 86 #define FSYNC 0x10 /* file (data+inode) integrity while writing */
85 87 #define FREVOKED 0x20 /* Object reuse Revoked file */
86 88 #define FDSYNC 0x40 /* file data only integrity while writing */
87 89 #define FNONBLOCK 0x80
88 90
89 91 #define FMASK 0xa0ff /* all flags that can be changed by F_SETFL */
90 92
91 93 /* open-only modes */
92 94
93 95 #define FCREAT 0x0100
94 96 #define FTRUNC 0x0200
95 97 #define FEXCL 0x0400
96 98 #define FASYNC 0x1000 /* asyncio in progress pseudo flag */
97 99 #define FOFFMAX 0x2000 /* large file */
98 100 #define FXATTR 0x4000 /* open as extended attribute */
99 101 #define FNOCTTY 0x0800
100 102 #define FRSYNC 0x8000 /* sync read operations at same level of */
101 103 /* integrity as specified for writes by */
102 104 /* FSYNC and FDSYNC flags */
103 105
104 106 #define FNODSYNC 0x10000 /* fsync pseudo flag */
105 107
↓ open down ↓ |
67 lines elided |
↑ open up ↑ |
106 108 #define FNOFOLLOW 0x20000 /* don't follow symlinks */
107 109 #define FNOLINKS 0x40000 /* don't allow multiple hard links */
108 110 #define FIGNORECASE 0x80000 /* request case-insensitive lookups */
109 111 #define FXATTRDIROPEN 0x100000 /* only opening hidden attribute directory */
110 112
111 113 /* f_flag2 (open-only) */
112 114
113 115 #define FSEARCH 0x200000 /* O_SEARCH = 0x200000 */
114 116 #define FEXEC 0x400000 /* O_EXEC = 0x400000 */
115 117
118 +#define FCLOEXEC 0x800000 /* O_CLOEXEC = 0x800000 */
119 +
116 120 #ifdef _KERNEL
117 121
118 122 /*
119 123 * Fake flags for driver ioctl calls to inform them of the originating
120 124 * process' model. See <sys/model.h>
121 125 *
122 126 * Part of the Solaris 2.6+ DDI/DKI
123 127 */
124 128 #define FMODELS DATAMODEL_MASK /* Note: 0x0ff00000 */
125 129 #define FILP32 DATAMODEL_ILP32
126 130 #define FLP64 DATAMODEL_LP64
127 131 #define FNATIVE DATAMODEL_NATIVE
128 132
129 133 /*
130 134 * Large Files: The macro gets the offset maximum (refer to LFS API doc)
131 135 * corresponding to a file descriptor. We had the choice of storing
132 136 * this value in file descriptor. Right now we only have two
133 137 * offset maximums one if MAXOFF_T and other is MAXOFFSET_T. It is
134 138 * inefficient to store these two values in a separate member in
135 139 * file descriptor. To avoid wasting spaces we define this macro.
136 140 * The day there are more than two offset maximum we may want to
137 141 * rewrite this macro.
138 142 */
139 143
140 144 #define OFFSET_MAX(fd) ((fd->f_flag & FOFFMAX) ? MAXOFFSET_T : MAXOFF32_T)
141 145
142 146 /*
143 147 * Fake flag => internal ioctl call for layered drivers.
144 148 * Note that this flag deliberately *won't* fit into
145 149 * the f_flag field of a file_t.
146 150 *
147 151 * Part of the Solaris 2.x DDI/DKI.
148 152 */
149 153 #define FKIOCTL 0x80000000 /* ioctl addresses are from kernel */
150 154
151 155 /*
152 156 * Fake flag => this time to specify that the open(9E)
153 157 * comes from another part of the kernel, not userland.
154 158 *
155 159 * Part of the Solaris 2.x DDI/DKI.
156 160 */
157 161 #define FKLYR 0x40000000 /* layered driver call */
158 162
159 163 #endif /* _KERNEL */
160 164
161 165 /* miscellaneous defines */
162 166
163 167 #ifndef L_SET
164 168 #define L_SET 0 /* for lseek */
165 169 #endif /* L_SET */
166 170
167 171 #if defined(_KERNEL)
168 172
169 173 /*
170 174 * Routines dealing with user per-open file flags and
171 175 * user open files.
172 176 */
173 177 struct proc; /* forward reference for function prototype */
174 178 struct vnodeops;
175 179 struct vattr;
176 180
177 181 extern file_t *getf(int);
178 182 extern void releasef(int);
179 183 extern void areleasef(int, uf_info_t *);
180 184 #ifndef _BOOT
181 185 extern void closeall(uf_info_t *);
182 186 #endif
183 187 extern void flist_fork(uf_info_t *, uf_info_t *);
184 188 extern int closef(file_t *);
185 189 extern int closeandsetf(int, file_t *);
186 190 extern int ufalloc_file(int, file_t *);
187 191 extern int ufalloc(int);
188 192 extern int ufcanalloc(struct proc *, uint_t);
189 193 extern int falloc(struct vnode *, int, file_t **, int *);
190 194 extern void finit(void);
191 195 extern void unfalloc(file_t *);
192 196 extern void setf(int, file_t *);
193 197 extern int f_getfd_error(int, int *);
194 198 extern char f_getfd(int);
195 199 extern int f_setfd_error(int, int);
196 200 extern void f_setfd(int, char);
197 201 extern int f_getfl(int, int *);
198 202 extern int f_badfd(int, int *, int);
199 203 extern int fassign(struct vnode **, int, int *);
200 204 extern void fcnt_add(uf_info_t *, int);
201 205 extern void close_exec(uf_info_t *);
202 206 extern void clear_stale_fd(void);
203 207 extern void clear_active_fd(int);
204 208 extern void free_afd(afd_t *afd);
205 209 extern int fgetstartvp(int, char *, struct vnode **);
206 210 extern int fsetattrat(int, char *, int, struct vattr *);
207 211 extern int fisopen(struct vnode *);
208 212 extern void delfpollinfo(int);
209 213 extern void addfpollinfo(int);
210 214 extern int sock_getfasync(struct vnode *);
211 215 extern int files_can_change_zones(void);
212 216 #ifdef DEBUG
213 217 /* The following functions are only used in ASSERT()s */
214 218 extern void checkwfdlist(struct vnode *, fpollinfo_t *);
215 219 extern void checkfpollinfo(void);
216 220 extern int infpollinfo(int);
217 221 #endif /* DEBUG */
218 222
219 223 #endif /* defined(_KERNEL) */
220 224
221 225 #ifdef __cplusplus
222 226 }
223 227 #endif
224 228
225 229 #endif /* _SYS_FILE_H */
↓ open down ↓ |
100 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX