1/*
2 * Copyright (c) 1995 Scott Bartram
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <sys/param.h>
29#include <sys/systm.h>
30#include <sys/namei.h>
31#include <sys/proc.h>
32#include <sys/file.h>
33#include <sys/stat.h>
34#include <sys/filedesc.h>
35#include <sys/ioctl.h>
36#include <sys/kernel.h>
37#include <sys/mount.h>
38#include <sys/malloc.h>
39#include <sys/sysproto.h>
40
41#include <i386/ibcs2/ibcs2_types.h>
42#include <i386/ibcs2/ibcs2_fcntl.h>
43#include <i386/ibcs2/ibcs2_signal.h>
44#include <i386/ibcs2/ibcs2_proto.h>
45#include <i386/ibcs2/ibcs2_util.h>
46
47static void cvt_iflock2flock __P((struct ibcs2_flock *, struct flock *));
48static void cvt_flock2iflock __P((struct flock *, struct ibcs2_flock *));
49static int cvt_o_flags __P((int));
50static int oflags2ioflags __P((int));
51static int ioflags2oflags __P((int));
52
53static int
54cvt_o_flags(flags)
55 int flags;
56{
57 int r = 0;
58
59 /* convert mode into NetBSD mode */
60 if (flags & IBCS2_O_WRONLY) r |= O_WRONLY;
61 if (flags & IBCS2_O_RDWR) r |= O_RDWR;
62 if (flags & (IBCS2_O_NDELAY | IBCS2_O_NONBLOCK)) r |= O_NONBLOCK;
63 if (flags & IBCS2_O_APPEND) r |= O_APPEND;
64 if (flags & IBCS2_O_SYNC) r |= O_FSYNC;
65 if (flags & IBCS2_O_CREAT) r |= O_CREAT;
66 if (flags & IBCS2_O_TRUNC) r |= O_TRUNC /* | O_CREAT ??? */;
67 if (flags & IBCS2_O_EXCL) r |= O_EXCL;
68 if (flags & IBCS2_O_RDONLY) r |= O_RDONLY;
69 if (flags & IBCS2_O_PRIV) r |= O_EXLOCK;
70 if (flags & IBCS2_O_NOCTTY) r |= O_NOCTTY;
71 return r;
72}
73
74static void
75cvt_flock2iflock(flp, iflp)
76 struct flock *flp;
77 struct ibcs2_flock *iflp;
78{
79 switch (flp->l_type) {
80 case F_RDLCK:
81 iflp->l_type = IBCS2_F_RDLCK;
82 break;
83 case F_WRLCK:
84 iflp->l_type = IBCS2_F_WRLCK;
85 break;
86 case F_UNLCK:
87 iflp->l_type = IBCS2_F_UNLCK;
88 break;
89 }
90 iflp->l_whence = (short)flp->l_whence;
91 iflp->l_start = (ibcs2_off_t)flp->l_start;
92 iflp->l_len = (ibcs2_off_t)flp->l_len;
93 iflp->l_sysid = 0;
94 iflp->l_pid = (ibcs2_pid_t)flp->l_pid;
95}
96
97#ifdef DEBUG_IBCS2
98static void
99print_flock(struct flock *flp)
100{
101 printf("flock: start=%x len=%x pid=%d type=%d whence=%d\n",
102 (int)flp->l_start, (int)flp->l_len, (int)flp->l_pid,
103 flp->l_type, flp->l_whence);
104}
105#endif
106
107static void
108cvt_iflock2flock(iflp, flp)
109 struct ibcs2_flock *iflp;
110 struct flock *flp;
111{
112 flp->l_start = (off_t)iflp->l_start;
113 flp->l_len = (off_t)iflp->l_len;
114 flp->l_pid = (pid_t)iflp->l_pid;
115 switch (iflp->l_type) {
116 case IBCS2_F_RDLCK:
117 flp->l_type = F_RDLCK;
118 break;
119 case IBCS2_F_WRLCK:
120 flp->l_type = F_WRLCK;
121 break;
122 case IBCS2_F_UNLCK:
123 flp->l_type = F_UNLCK;
124 break;
125 }
126 flp->l_whence = iflp->l_whence;
127}
128
129/* convert iBCS2 mode into NetBSD mode */
130static int
131ioflags2oflags(flags)
132 int flags;
133{
134 int r = 0;
135
136 if (flags & IBCS2_O_RDONLY) r |= O_RDONLY;
137 if (flags & IBCS2_O_WRONLY) r |= O_WRONLY;
138 if (flags & IBCS2_O_RDWR) r |= O_RDWR;
139 if (flags & IBCS2_O_NDELAY) r |= O_NONBLOCK;
140 if (flags & IBCS2_O_APPEND) r |= O_APPEND;
141 if (flags & IBCS2_O_SYNC) r |= O_FSYNC;
142 if (flags & IBCS2_O_NONBLOCK) r |= O_NONBLOCK;
143 if (flags & IBCS2_O_CREAT) r |= O_CREAT;
144 if (flags & IBCS2_O_TRUNC) r |= O_TRUNC;
145 if (flags & IBCS2_O_EXCL) r |= O_EXCL;
146 if (flags & IBCS2_O_NOCTTY) r |= O_NOCTTY;
147 return r;
148}
149
150/* convert NetBSD mode into iBCS2 mode */
151static int
152oflags2ioflags(flags)
153 int flags;
154{
155 int r = 0;
156
157 if (flags & O_RDONLY) r |= IBCS2_O_RDONLY;
158 if (flags & O_WRONLY) r |= IBCS2_O_WRONLY;
159 if (flags & O_RDWR) r |= IBCS2_O_RDWR;
160 if (flags & O_NDELAY) r |= IBCS2_O_NONBLOCK;
161 if (flags & O_APPEND) r |= IBCS2_O_APPEND;
162 if (flags & O_FSYNC) r |= IBCS2_O_SYNC;
163 if (flags & O_NONBLOCK) r |= IBCS2_O_NONBLOCK;
164 if (flags & O_CREAT) r |= IBCS2_O_CREAT;
165 if (flags & O_TRUNC) r |= IBCS2_O_TRUNC;
166 if (flags & O_EXCL) r |= IBCS2_O_EXCL;
167 if (flags & O_NOCTTY) r |= IBCS2_O_NOCTTY;
168 return r;
169}
170
171int
172ibcs2_open(p, uap, retval)
173 struct proc *p;
174 struct ibcs2_open_args *uap;
175 int *retval;
176{
177 int noctty = SCARG(uap, flags) & IBCS2_O_NOCTTY;
178 int ret;
179 caddr_t sg = stackgap_init();
180
181 SCARG(uap, flags) = cvt_o_flags(SCARG(uap, flags));
182 if (SCARG(uap, flags) & O_CREAT)
183 CHECKALTCREAT(p, &sg, SCARG(uap, path));
184 else
185 CHECKALTEXIST(p, &sg, SCARG(uap, path));
186 ret = open(p, (struct open_args *)uap, retval);
187
188 if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
189 struct filedesc *fdp = p->p_fd;
190 struct file *fp = fdp->fd_ofiles[*retval];
191
192 /* ignore any error, just give it a try */
193 if (fp->f_type == DTYPE_VNODE)
194 (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t) 0, p);
195 }
196 return ret;
197}
198
199int
200ibcs2_creat(p, uap, retval)
201 struct proc *p;
202 struct ibcs2_creat_args *uap;
203 int *retval;
204{
205 struct open_args cup;
206 caddr_t sg = stackgap_init();
207
208 CHECKALTCREAT(p, &sg, SCARG(uap, path));
209 SCARG(&cup, path) = SCARG(uap, path);
210 SCARG(&cup, mode) = SCARG(uap, mode);
211 SCARG(&cup, flags) = O_WRONLY | O_CREAT | O_TRUNC;
212 return open(p, &cup, retval);
213}
214
215int
216ibcs2_access(p, uap, retval)
217 struct proc *p;
218 struct ibcs2_access_args *uap;
219 int *retval;
220{
221 struct access_args cup;
222 caddr_t sg = stackgap_init();
223
224 CHECKALTEXIST(p, &sg, SCARG(uap, path));
225 SCARG(&cup, path) = SCARG(uap, path);
226 SCARG(&cup, flags) = SCARG(uap, flags);
227 return access(p, &cup, retval);
228}
229
230int
231ibcs2_fcntl(p, uap, retval)
232 struct proc *p;
233 struct ibcs2_fcntl_args *uap;
234 int *retval;
235{
236 int error;
237 struct fcntl_args fa;
238 struct flock *flp;
239 struct ibcs2_flock ifl;
240
241 switch(SCARG(uap, cmd)) {
242 case IBCS2_F_DUPFD:
243 SCARG(&fa, fd) = SCARG(uap, fd);
244 SCARG(&fa, cmd) = F_DUPFD;
245 SCARG(&fa, arg) = SCARG(uap, arg);
246 return fcntl(p, &fa, retval);
247 case IBCS2_F_GETFD:
248 SCARG(&fa, fd) = SCARG(uap, fd);
249 SCARG(&fa, cmd) = F_GETFD;
250 SCARG(&fa, arg) = SCARG(uap, arg);
251 return fcntl(p, &fa, retval);
252 case IBCS2_F_SETFD:
253 SCARG(&fa, fd) = SCARG(uap, fd);
254 SCARG(&fa, cmd) = F_SETFD;
255 SCARG(&fa, arg) = SCARG(uap, arg);
256 return fcntl(p, &fa, retval);
257 case IBCS2_F_GETFL:
258 SCARG(&fa, fd) = SCARG(uap, fd);
259 SCARG(&fa, cmd) = F_GETFL;
260 SCARG(&fa, arg) = SCARG(uap, arg);
261 error = fcntl(p, &fa, retval);
262 if (error)
263 return error;
264 *retval = oflags2ioflags(*retval);
265 return error;
266 case IBCS2_F_SETFL:
267 SCARG(&fa, fd) = SCARG(uap, fd);
268 SCARG(&fa, cmd) = F_SETFL;
269 SCARG(&fa, arg) = (void *)ioflags2oflags((int)SCARG(uap, arg));
270 return fcntl(p, &fa, retval);
271
272 case IBCS2_F_GETLK:
273 {
274 caddr_t sg = stackgap_init();
275 flp = stackgap_alloc(&sg, sizeof(*flp));
276 error = copyin((caddr_t)SCARG(uap, arg), (caddr_t)&ifl,
277 ibcs2_flock_len);
278 if (error)
279 return error;
280 cvt_iflock2flock(&ifl, flp);
281 SCARG(&fa, fd) = SCARG(uap, fd);
282 SCARG(&fa, cmd) = F_GETLK;
283 SCARG(&fa, arg) = (void *)flp;
284 error = fcntl(p, &fa, retval);
285 if (error)
286 return error;
287 cvt_flock2iflock(flp, &ifl);
288 return copyout((caddr_t)&ifl, (caddr_t)SCARG(uap, arg),
289 ibcs2_flock_len);
290 }
291
292 case IBCS2_F_SETLK:
293 {
294 caddr_t sg = stackgap_init();
295 flp = stackgap_alloc(&sg, sizeof(*flp));
296 error = copyin((caddr_t)SCARG(uap, arg), (caddr_t)&ifl,
297 ibcs2_flock_len);
298 if (error)
299 return error;
300 cvt_iflock2flock(&ifl, flp);
301 SCARG(&fa, fd) = SCARG(uap, fd);
302 SCARG(&fa, cmd) = F_SETLK;
303 SCARG(&fa, arg) = (void *)flp;
304
305 return fcntl(p, &fa, retval);
306 }
307
308 case IBCS2_F_SETLKW:
309 {
310 caddr_t sg = stackgap_init();
311 flp = stackgap_alloc(&sg, sizeof(*flp));
312 error = copyin((caddr_t)SCARG(uap, arg), (caddr_t)&ifl,
313 ibcs2_flock_len);
314 if (error)
315 return error;
316 cvt_iflock2flock(&ifl, flp);
317 SCARG(&fa, fd) = SCARG(uap, fd);
318 SCARG(&fa, cmd) = F_SETLKW;
319 SCARG(&fa, arg) = (void *)flp;
320 return fcntl(p, &fa, retval);
321 }
322 }
323 return ENOSYS;
324}
2 * Copyright (c) 1995 Scott Bartram
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <sys/param.h>
29#include <sys/systm.h>
30#include <sys/namei.h>
31#include <sys/proc.h>
32#include <sys/file.h>
33#include <sys/stat.h>
34#include <sys/filedesc.h>
35#include <sys/ioctl.h>
36#include <sys/kernel.h>
37#include <sys/mount.h>
38#include <sys/malloc.h>
39#include <sys/sysproto.h>
40
41#include <i386/ibcs2/ibcs2_types.h>
42#include <i386/ibcs2/ibcs2_fcntl.h>
43#include <i386/ibcs2/ibcs2_signal.h>
44#include <i386/ibcs2/ibcs2_proto.h>
45#include <i386/ibcs2/ibcs2_util.h>
46
47static void cvt_iflock2flock __P((struct ibcs2_flock *, struct flock *));
48static void cvt_flock2iflock __P((struct flock *, struct ibcs2_flock *));
49static int cvt_o_flags __P((int));
50static int oflags2ioflags __P((int));
51static int ioflags2oflags __P((int));
52
53static int
54cvt_o_flags(flags)
55 int flags;
56{
57 int r = 0;
58
59 /* convert mode into NetBSD mode */
60 if (flags & IBCS2_O_WRONLY) r |= O_WRONLY;
61 if (flags & IBCS2_O_RDWR) r |= O_RDWR;
62 if (flags & (IBCS2_O_NDELAY | IBCS2_O_NONBLOCK)) r |= O_NONBLOCK;
63 if (flags & IBCS2_O_APPEND) r |= O_APPEND;
64 if (flags & IBCS2_O_SYNC) r |= O_FSYNC;
65 if (flags & IBCS2_O_CREAT) r |= O_CREAT;
66 if (flags & IBCS2_O_TRUNC) r |= O_TRUNC /* | O_CREAT ??? */;
67 if (flags & IBCS2_O_EXCL) r |= O_EXCL;
68 if (flags & IBCS2_O_RDONLY) r |= O_RDONLY;
69 if (flags & IBCS2_O_PRIV) r |= O_EXLOCK;
70 if (flags & IBCS2_O_NOCTTY) r |= O_NOCTTY;
71 return r;
72}
73
74static void
75cvt_flock2iflock(flp, iflp)
76 struct flock *flp;
77 struct ibcs2_flock *iflp;
78{
79 switch (flp->l_type) {
80 case F_RDLCK:
81 iflp->l_type = IBCS2_F_RDLCK;
82 break;
83 case F_WRLCK:
84 iflp->l_type = IBCS2_F_WRLCK;
85 break;
86 case F_UNLCK:
87 iflp->l_type = IBCS2_F_UNLCK;
88 break;
89 }
90 iflp->l_whence = (short)flp->l_whence;
91 iflp->l_start = (ibcs2_off_t)flp->l_start;
92 iflp->l_len = (ibcs2_off_t)flp->l_len;
93 iflp->l_sysid = 0;
94 iflp->l_pid = (ibcs2_pid_t)flp->l_pid;
95}
96
97#ifdef DEBUG_IBCS2
98static void
99print_flock(struct flock *flp)
100{
101 printf("flock: start=%x len=%x pid=%d type=%d whence=%d\n",
102 (int)flp->l_start, (int)flp->l_len, (int)flp->l_pid,
103 flp->l_type, flp->l_whence);
104}
105#endif
106
107static void
108cvt_iflock2flock(iflp, flp)
109 struct ibcs2_flock *iflp;
110 struct flock *flp;
111{
112 flp->l_start = (off_t)iflp->l_start;
113 flp->l_len = (off_t)iflp->l_len;
114 flp->l_pid = (pid_t)iflp->l_pid;
115 switch (iflp->l_type) {
116 case IBCS2_F_RDLCK:
117 flp->l_type = F_RDLCK;
118 break;
119 case IBCS2_F_WRLCK:
120 flp->l_type = F_WRLCK;
121 break;
122 case IBCS2_F_UNLCK:
123 flp->l_type = F_UNLCK;
124 break;
125 }
126 flp->l_whence = iflp->l_whence;
127}
128
129/* convert iBCS2 mode into NetBSD mode */
130static int
131ioflags2oflags(flags)
132 int flags;
133{
134 int r = 0;
135
136 if (flags & IBCS2_O_RDONLY) r |= O_RDONLY;
137 if (flags & IBCS2_O_WRONLY) r |= O_WRONLY;
138 if (flags & IBCS2_O_RDWR) r |= O_RDWR;
139 if (flags & IBCS2_O_NDELAY) r |= O_NONBLOCK;
140 if (flags & IBCS2_O_APPEND) r |= O_APPEND;
141 if (flags & IBCS2_O_SYNC) r |= O_FSYNC;
142 if (flags & IBCS2_O_NONBLOCK) r |= O_NONBLOCK;
143 if (flags & IBCS2_O_CREAT) r |= O_CREAT;
144 if (flags & IBCS2_O_TRUNC) r |= O_TRUNC;
145 if (flags & IBCS2_O_EXCL) r |= O_EXCL;
146 if (flags & IBCS2_O_NOCTTY) r |= O_NOCTTY;
147 return r;
148}
149
150/* convert NetBSD mode into iBCS2 mode */
151static int
152oflags2ioflags(flags)
153 int flags;
154{
155 int r = 0;
156
157 if (flags & O_RDONLY) r |= IBCS2_O_RDONLY;
158 if (flags & O_WRONLY) r |= IBCS2_O_WRONLY;
159 if (flags & O_RDWR) r |= IBCS2_O_RDWR;
160 if (flags & O_NDELAY) r |= IBCS2_O_NONBLOCK;
161 if (flags & O_APPEND) r |= IBCS2_O_APPEND;
162 if (flags & O_FSYNC) r |= IBCS2_O_SYNC;
163 if (flags & O_NONBLOCK) r |= IBCS2_O_NONBLOCK;
164 if (flags & O_CREAT) r |= IBCS2_O_CREAT;
165 if (flags & O_TRUNC) r |= IBCS2_O_TRUNC;
166 if (flags & O_EXCL) r |= IBCS2_O_EXCL;
167 if (flags & O_NOCTTY) r |= IBCS2_O_NOCTTY;
168 return r;
169}
170
171int
172ibcs2_open(p, uap, retval)
173 struct proc *p;
174 struct ibcs2_open_args *uap;
175 int *retval;
176{
177 int noctty = SCARG(uap, flags) & IBCS2_O_NOCTTY;
178 int ret;
179 caddr_t sg = stackgap_init();
180
181 SCARG(uap, flags) = cvt_o_flags(SCARG(uap, flags));
182 if (SCARG(uap, flags) & O_CREAT)
183 CHECKALTCREAT(p, &sg, SCARG(uap, path));
184 else
185 CHECKALTEXIST(p, &sg, SCARG(uap, path));
186 ret = open(p, (struct open_args *)uap, retval);
187
188 if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
189 struct filedesc *fdp = p->p_fd;
190 struct file *fp = fdp->fd_ofiles[*retval];
191
192 /* ignore any error, just give it a try */
193 if (fp->f_type == DTYPE_VNODE)
194 (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t) 0, p);
195 }
196 return ret;
197}
198
199int
200ibcs2_creat(p, uap, retval)
201 struct proc *p;
202 struct ibcs2_creat_args *uap;
203 int *retval;
204{
205 struct open_args cup;
206 caddr_t sg = stackgap_init();
207
208 CHECKALTCREAT(p, &sg, SCARG(uap, path));
209 SCARG(&cup, path) = SCARG(uap, path);
210 SCARG(&cup, mode) = SCARG(uap, mode);
211 SCARG(&cup, flags) = O_WRONLY | O_CREAT | O_TRUNC;
212 return open(p, &cup, retval);
213}
214
215int
216ibcs2_access(p, uap, retval)
217 struct proc *p;
218 struct ibcs2_access_args *uap;
219 int *retval;
220{
221 struct access_args cup;
222 caddr_t sg = stackgap_init();
223
224 CHECKALTEXIST(p, &sg, SCARG(uap, path));
225 SCARG(&cup, path) = SCARG(uap, path);
226 SCARG(&cup, flags) = SCARG(uap, flags);
227 return access(p, &cup, retval);
228}
229
230int
231ibcs2_fcntl(p, uap, retval)
232 struct proc *p;
233 struct ibcs2_fcntl_args *uap;
234 int *retval;
235{
236 int error;
237 struct fcntl_args fa;
238 struct flock *flp;
239 struct ibcs2_flock ifl;
240
241 switch(SCARG(uap, cmd)) {
242 case IBCS2_F_DUPFD:
243 SCARG(&fa, fd) = SCARG(uap, fd);
244 SCARG(&fa, cmd) = F_DUPFD;
245 SCARG(&fa, arg) = SCARG(uap, arg);
246 return fcntl(p, &fa, retval);
247 case IBCS2_F_GETFD:
248 SCARG(&fa, fd) = SCARG(uap, fd);
249 SCARG(&fa, cmd) = F_GETFD;
250 SCARG(&fa, arg) = SCARG(uap, arg);
251 return fcntl(p, &fa, retval);
252 case IBCS2_F_SETFD:
253 SCARG(&fa, fd) = SCARG(uap, fd);
254 SCARG(&fa, cmd) = F_SETFD;
255 SCARG(&fa, arg) = SCARG(uap, arg);
256 return fcntl(p, &fa, retval);
257 case IBCS2_F_GETFL:
258 SCARG(&fa, fd) = SCARG(uap, fd);
259 SCARG(&fa, cmd) = F_GETFL;
260 SCARG(&fa, arg) = SCARG(uap, arg);
261 error = fcntl(p, &fa, retval);
262 if (error)
263 return error;
264 *retval = oflags2ioflags(*retval);
265 return error;
266 case IBCS2_F_SETFL:
267 SCARG(&fa, fd) = SCARG(uap, fd);
268 SCARG(&fa, cmd) = F_SETFL;
269 SCARG(&fa, arg) = (void *)ioflags2oflags((int)SCARG(uap, arg));
270 return fcntl(p, &fa, retval);
271
272 case IBCS2_F_GETLK:
273 {
274 caddr_t sg = stackgap_init();
275 flp = stackgap_alloc(&sg, sizeof(*flp));
276 error = copyin((caddr_t)SCARG(uap, arg), (caddr_t)&ifl,
277 ibcs2_flock_len);
278 if (error)
279 return error;
280 cvt_iflock2flock(&ifl, flp);
281 SCARG(&fa, fd) = SCARG(uap, fd);
282 SCARG(&fa, cmd) = F_GETLK;
283 SCARG(&fa, arg) = (void *)flp;
284 error = fcntl(p, &fa, retval);
285 if (error)
286 return error;
287 cvt_flock2iflock(flp, &ifl);
288 return copyout((caddr_t)&ifl, (caddr_t)SCARG(uap, arg),
289 ibcs2_flock_len);
290 }
291
292 case IBCS2_F_SETLK:
293 {
294 caddr_t sg = stackgap_init();
295 flp = stackgap_alloc(&sg, sizeof(*flp));
296 error = copyin((caddr_t)SCARG(uap, arg), (caddr_t)&ifl,
297 ibcs2_flock_len);
298 if (error)
299 return error;
300 cvt_iflock2flock(&ifl, flp);
301 SCARG(&fa, fd) = SCARG(uap, fd);
302 SCARG(&fa, cmd) = F_SETLK;
303 SCARG(&fa, arg) = (void *)flp;
304
305 return fcntl(p, &fa, retval);
306 }
307
308 case IBCS2_F_SETLKW:
309 {
310 caddr_t sg = stackgap_init();
311 flp = stackgap_alloc(&sg, sizeof(*flp));
312 error = copyin((caddr_t)SCARG(uap, arg), (caddr_t)&ifl,
313 ibcs2_flock_len);
314 if (error)
315 return error;
316 cvt_iflock2flock(&ifl, flp);
317 SCARG(&fa, fd) = SCARG(uap, fd);
318 SCARG(&fa, cmd) = F_SETLKW;
319 SCARG(&fa, arg) = (void *)flp;
320 return fcntl(p, &fa, retval);
321 }
322 }
323 return ENOSYS;
324}