proc->thread stage 5: BUF/VFS clearance! Remove the ucred argument from
[dragonfly.git] / sys / emulation / svr4 / svr4_fcntl.c
1 /*
2  * Copyright (c) 1998 Mark Newton
3  * Copyright (c) 1994, 1997 Christos Zoulas.  
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. All advertising materials mentioning features or use of this software
15  *    must display the following acknowledgement:
16  *      This product includes software developed by Christos Zoulas.
17  * 4. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  * 
31  * $FreeBSD: src/sys/svr4/svr4_fcntl.c,v 1.7 1999/12/12 10:27:04 newton Exp $
32  * $DragonFly: src/sys/emulation/svr4/Attic/svr4_fcntl.c,v 1.6 2003/06/26 05:55:19 dillon Exp $
33  */
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/proc.h>
37 #include <sys/namei.h>
38 #include <sys/file.h>
39 #include <sys/stat.h>
40 #include <sys/filedesc.h>
41 /*#include <sys/ioctl.h>*/
42 #include <sys/kernel.h>
43 #include <sys/mount.h>
44 #include <sys/malloc.h>
45 #include <sys/vnode.h>
46 #include <sys/unistd.h>
47
48 #include <sys/sysproto.h>
49
50 #include <svr4/svr4.h>
51 #include <svr4/svr4_types.h>
52 #include <svr4/svr4_signal.h>
53 #include <svr4/svr4_proto.h>
54 #include <svr4/svr4_util.h>
55 #include <svr4/svr4_fcntl.h>
56
57 static int svr4_to_bsd_flags __P((int));
58 static u_long svr4_to_bsd_cmd __P((u_long));
59 static int fd_revoke __P((struct thread *, int));
60 static int fd_truncate __P((struct thread *, int, struct flock *));
61 static int bsd_to_svr4_flags __P((int));
62 static void bsd_to_svr4_flock __P((struct flock *, struct svr4_flock *));
63 static void svr4_to_bsd_flock __P((struct svr4_flock *, struct flock *));
64 static void bsd_to_svr4_flock64 __P((struct flock *, struct svr4_flock64 *));
65 static void svr4_to_bsd_flock64 __P((struct svr4_flock64 *, struct flock *));
66
67 static u_long
68 svr4_to_bsd_cmd(cmd)
69         u_long  cmd;
70 {
71         switch (cmd) {
72         case SVR4_F_DUPFD:
73                 return F_DUPFD;
74         case SVR4_F_GETFD:
75                 return F_GETFD;
76         case SVR4_F_SETFD:
77                 return F_SETFD;
78         case SVR4_F_GETFL:
79                 return F_GETFL;
80         case SVR4_F_SETFL:
81                 return F_SETFL;
82         case SVR4_F_GETLK:
83                 return F_GETLK;
84         case SVR4_F_SETLK:
85                 return F_SETLK;
86         case SVR4_F_SETLKW:
87                 return F_SETLKW;
88         default:
89                 return -1;
90         }
91 }
92
93 static int
94 svr4_to_bsd_flags(l)
95         int     l;
96 {
97         int     r = 0;
98         r |= (l & SVR4_O_RDONLY) ? O_RDONLY : 0;
99         r |= (l & SVR4_O_WRONLY) ? O_WRONLY : 0;
100         r |= (l & SVR4_O_RDWR) ? O_RDWR : 0;
101         r |= (l & SVR4_O_NDELAY) ? O_NONBLOCK : 0;
102         r |= (l & SVR4_O_APPEND) ? O_APPEND : 0;
103         r |= (l & SVR4_O_SYNC) ? O_FSYNC : 0;
104         r |= (l & SVR4_O_NONBLOCK) ? O_NONBLOCK : 0;
105         r |= (l & SVR4_O_PRIV) ? O_EXLOCK : 0;
106         r |= (l & SVR4_O_CREAT) ? O_CREAT : 0;
107         r |= (l & SVR4_O_TRUNC) ? O_TRUNC : 0;
108         r |= (l & SVR4_O_EXCL) ? O_EXCL : 0;
109         r |= (l & SVR4_O_NOCTTY) ? O_NOCTTY : 0;
110         return r;
111 }
112
113 static int
114 bsd_to_svr4_flags(l)
115         int     l;
116 {
117         int     r = 0;
118         r |= (l & O_RDONLY) ? SVR4_O_RDONLY : 0;
119         r |= (l & O_WRONLY) ? SVR4_O_WRONLY : 0;
120         r |= (l & O_RDWR) ? SVR4_O_RDWR : 0;
121         r |= (l & O_NDELAY) ? SVR4_O_NONBLOCK : 0;
122         r |= (l & O_APPEND) ? SVR4_O_APPEND : 0;
123         r |= (l & O_FSYNC) ? SVR4_O_SYNC : 0;
124         r |= (l & O_NONBLOCK) ? SVR4_O_NONBLOCK : 0;
125         r |= (l & O_EXLOCK) ? SVR4_O_PRIV : 0;
126         r |= (l & O_CREAT) ? SVR4_O_CREAT : 0;
127         r |= (l & O_TRUNC) ? SVR4_O_TRUNC : 0;
128         r |= (l & O_EXCL) ? SVR4_O_EXCL : 0;
129         r |= (l & O_NOCTTY) ? SVR4_O_NOCTTY : 0;
130         return r;
131 }
132
133
134 static void
135 bsd_to_svr4_flock(iflp, oflp)
136         struct flock            *iflp;
137         struct svr4_flock       *oflp;
138 {
139         switch (iflp->l_type) {
140         case F_RDLCK:
141                 oflp->l_type = SVR4_F_RDLCK;
142                 break;
143         case F_WRLCK:
144                 oflp->l_type = SVR4_F_WRLCK;
145                 break;
146         case F_UNLCK:
147                 oflp->l_type = SVR4_F_UNLCK;
148                 break;
149         default:
150                 oflp->l_type = -1;
151                 break;
152         }
153
154         oflp->l_whence = (short) iflp->l_whence;
155         oflp->l_start = (svr4_off_t) iflp->l_start;
156         oflp->l_len = (svr4_off_t) iflp->l_len;
157         oflp->l_sysid = 0;
158         oflp->l_pid = (svr4_pid_t) iflp->l_pid;
159 }
160
161
162 static void
163 svr4_to_bsd_flock(iflp, oflp)
164         struct svr4_flock       *iflp;
165         struct flock            *oflp;
166 {
167         switch (iflp->l_type) {
168         case SVR4_F_RDLCK:
169                 oflp->l_type = F_RDLCK;
170                 break;
171         case SVR4_F_WRLCK:
172                 oflp->l_type = F_WRLCK;
173                 break;
174         case SVR4_F_UNLCK:
175                 oflp->l_type = F_UNLCK;
176                 break;
177         default:
178                 oflp->l_type = -1;
179                 break;
180         }
181
182         oflp->l_whence = iflp->l_whence;
183         oflp->l_start = (off_t) iflp->l_start;
184         oflp->l_len = (off_t) iflp->l_len;
185         oflp->l_pid = (pid_t) iflp->l_pid;
186
187 }
188
189 static void
190 bsd_to_svr4_flock64(iflp, oflp)
191         struct flock            *iflp;
192         struct svr4_flock64     *oflp;
193 {
194         switch (iflp->l_type) {
195         case F_RDLCK:
196                 oflp->l_type = SVR4_F_RDLCK;
197                 break;
198         case F_WRLCK:
199                 oflp->l_type = SVR4_F_WRLCK;
200                 break;
201         case F_UNLCK:
202                 oflp->l_type = SVR4_F_UNLCK;
203                 break;
204         default:
205                 oflp->l_type = -1;
206                 break;
207         }
208
209         oflp->l_whence = (short) iflp->l_whence;
210         oflp->l_start = (svr4_off64_t) iflp->l_start;
211         oflp->l_len = (svr4_off64_t) iflp->l_len;
212         oflp->l_sysid = 0;
213         oflp->l_pid = (svr4_pid_t) iflp->l_pid;
214 }
215
216
217 static void
218 svr4_to_bsd_flock64(iflp, oflp)
219         struct svr4_flock64     *iflp;
220         struct flock            *oflp;
221 {
222         switch (iflp->l_type) {
223         case SVR4_F_RDLCK:
224                 oflp->l_type = F_RDLCK;
225                 break;
226         case SVR4_F_WRLCK:
227                 oflp->l_type = F_WRLCK;
228                 break;
229         case SVR4_F_UNLCK:
230                 oflp->l_type = F_UNLCK;
231                 break;
232         default:
233                 oflp->l_type = -1;
234                 break;
235         }
236
237         oflp->l_whence = iflp->l_whence;
238         oflp->l_start = (off_t) iflp->l_start;
239         oflp->l_len = (off_t) iflp->l_len;
240         oflp->l_pid = (pid_t) iflp->l_pid;
241
242 }
243
244
245 static int
246 fd_revoke(struct thread *td, int fd)
247 {
248         struct proc *p = td->td_proc;
249         struct filedesc *fdp;
250         struct file *fp;
251         struct vnode *vp;
252         struct vattr vattr;
253         int error, *retval;
254
255         KKASSERT(p);
256
257         fdp = p->p_fd;
258         retval = p->p_retval;
259         if ((u_int)fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL)
260                 return EBADF;
261
262         if (fp->f_type != DTYPE_VNODE) 
263                 return EINVAL;
264
265         vp = (struct vnode *) fp->f_data;
266
267         if (vp->v_type != VCHR && vp->v_type != VBLK) {
268                 error = EINVAL;
269                 goto out;
270         }
271
272         if ((error = VOP_GETATTR(vp, &vattr, td)) != 0)
273                 goto out;
274
275         if (p->p_ucred->cr_uid != vattr.va_uid &&
276             (error = suser(p->p_thread)) != 0)
277                 goto out;
278
279         if (vcount(vp) > 1)
280                 VOP_REVOKE(vp, REVOKEALL);
281 out:
282         vrele(vp);
283         return error;
284 }
285
286
287 static int
288 fd_truncate(struct thread *td, int fd, struct flock *flp)
289 {
290         struct proc *p = td->td_proc;
291         struct filedesc *fdp;
292         struct file *fp;
293         off_t start, length;
294         struct vnode *vp;
295         struct vattr vattr;
296         int error, *retval;
297         struct ftruncate_args ft;
298
299         KKASSERT(p);
300         fdp = p->p_fd;
301         retval = p->p_retval;
302
303         /*
304          * We only support truncating the file.
305          */
306         if ((u_int)fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL)
307                 return EBADF;
308
309         vp = (struct vnode *)fp->f_data;
310         if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO)
311                 return ESPIPE;
312
313         if ((error = VOP_GETATTR(vp, &vattr, td)) != 0)
314                 return error;
315
316         length = vattr.va_size;
317
318         switch (flp->l_whence) {
319         case SEEK_CUR:
320                 start = fp->f_offset + flp->l_start;
321                 break;
322
323         case SEEK_END:
324                 start = flp->l_start + length;
325                 break;
326
327         case SEEK_SET:
328                 start = flp->l_start;
329                 break;
330
331         default:
332                 return EINVAL;
333         }
334
335         if (start + flp->l_len < length) {
336                 /* We don't support free'ing in the middle of the file */
337                 return EINVAL;
338         }
339
340         SCARG(&ft, fd) = fd;
341         SCARG(&ft, length) = start;
342
343         return ftruncate(&ft);
344 }
345
346 int
347 svr4_sys_open(struct svr4_sys_open_args *uap)
348 {
349         struct thread *td = curthread;  /* XXX */
350         struct proc *p = td->td_proc;
351         struct open_args cup;
352         int     error, retval;
353
354         caddr_t sg = stackgap_init();
355         CHECKALTEXIST(&sg, SCARG(uap, path));
356
357         (&cup)->path = uap->path;
358         (&cup)->flags = svr4_to_bsd_flags(uap->flags);
359         (&cup)->mode = uap->mode;
360         error = open(&cup);
361
362         if (error) {
363           /*            uprintf("svr4_open(%s, 0x%0x, 0%o): %d\n", uap->path,
364                         uap->flags, uap->mode, error);*/
365                 return error;
366         }
367
368         KKASSERT(p);
369         retval = p->p_retval[0];
370
371         if (!(SCARG(&cup, flags) & O_NOCTTY) && SESS_LEADER(p) &&
372             !(p->p_flag & P_CONTROLT)) {
373 #if defined(NOTYET)
374                 struct filedesc *fdp = p->p_fd;
375                 struct file     *fp = fdp->fd_ofiles[retval];
376
377                 /* ignore any error, just give it a try */
378                 if (fp->f_type == DTYPE_VNODE)
379                         fo_ioctl(fp, TIOCSCTTY, (caddr_t) 0, p);
380 #endif
381         }
382         return error;
383 }
384
385 int
386 svr4_sys_open64(struct svr4_sys_open64_args *uap)
387 {
388         return svr4_sys_open((struct svr4_sys_open_args *)uap);
389 }
390
391 int
392 svr4_sys_creat(struct svr4_sys_creat_args *uap)
393 {
394         struct open_args cup;
395
396         caddr_t sg = stackgap_init();
397         CHECKALTEXIST(&sg, SCARG(uap, path));
398
399         SCARG(&cup, path) = SCARG(uap, path);
400         SCARG(&cup, mode) = SCARG(uap, mode);
401         SCARG(&cup, flags) = O_WRONLY | O_CREAT | O_TRUNC;
402
403         return open(&cup);
404 }
405
406 int
407 svr4_sys_creat64(struct svr4_sys_creat64_args *uap)
408 {
409         return svr4_sys_creat((struct svr4_sys_creat_args *)uap);
410 }
411
412 int
413 svr4_sys_llseek(struct svr4_sys_llseek_args *v)
414 {
415         struct svr4_sys_llseek_args *uap = v;
416         struct lseek_args ap;
417
418         SCARG(&ap, fd) = SCARG(uap, fd);
419
420 #if BYTE_ORDER == BIG_ENDIAN
421         SCARG(&ap, offset) = (((long long) SCARG(uap, offset1)) << 32) | 
422                 SCARG(uap, offset2);
423 #else
424         SCARG(&ap, offset) = (((long long) SCARG(uap, offset2)) << 32) | 
425                 SCARG(uap, offset1);
426 #endif
427         SCARG(&ap, whence) = SCARG(uap, whence);
428
429         return lseek(&ap);
430 }
431
432 int
433 svr4_sys_access(struct svr4_sys_access_args *uap)
434 {
435         struct thread *td = curthread;  /* XXX */
436         struct proc *p = td->td_proc;
437         struct access_args cup;
438         int *retval;
439
440         caddr_t sg = stackgap_init();
441         CHECKALTEXIST(&sg, SCARG(uap, path));
442
443         KKASSERT(p);
444         retval = p->p_retval;
445
446         SCARG(&cup, path) = SCARG(uap, path);
447         SCARG(&cup, flags) = SCARG(uap, flags);
448
449         return access(&cup);
450 }
451
452 #if defined(NOTYET)
453 int
454 svr4_sys_pread(struct svr4_sys_pread_args *uap)
455 {
456         struct pread_args pra;
457
458         /*
459          * Just translate the args structure and call the NetBSD
460          * pread(2) system call (offset type is 64-bit in NetBSD).
461          */
462         SCARG(&pra, fd) = SCARG(uap, fd);
463         SCARG(&pra, buf) = SCARG(uap, buf);
464         SCARG(&pra, nbyte) = SCARG(uap, nbyte);
465         SCARG(&pra, offset) = SCARG(uap, off);
466
467         return pread(&pra);
468 }
469 #endif
470
471 #if defined(NOTYET)
472 int
473 svr4_sys_pread64(struct thread *td, void *v, register_t *retval)
474 {
475         struct svr4_sys_pread64_args *uap = v;
476         struct sys_pread_args pra;
477
478         /*
479          * Just translate the args structure and call the NetBSD
480          * pread(2) system call (offset type is 64-bit in NetBSD).
481          */
482         SCARG(&pra, fd) = SCARG(uap, fd);
483         SCARG(&pra, buf) = SCARG(uap, buf);
484         SCARG(&pra, nbyte) = SCARG(uap, nbyte);
485         SCARG(&pra, offset) = SCARG(uap, off);
486
487         return (sys_pread(&pra, retval));
488 }
489 #endif /* NOTYET */
490
491 #if defined(NOTYET)
492 int
493 svr4_sys_pwrite(struct svr4_sys_pwrite_args *uap)
494 {
495         struct pwrite_args pwa;
496
497         /*
498          * Just translate the args structure and call the NetBSD
499          * pwrite(2) system call (offset type is 64-bit in NetBSD).
500          */
501         SCARG(&pwa, fd) = SCARG(uap, fd);
502         SCARG(&pwa, buf) = SCARG(uap, buf);
503         SCARG(&pwa, nbyte) = SCARG(uap, nbyte);
504         SCARG(&pwa, offset) = SCARG(uap, off);
505
506         return pwrite(&pwa);
507 }
508 #endif
509
510 #if defined(NOTYET)
511 int
512 svr4_sys_pwrite64(struct thread *td, void *v, register_t *retval)
513 {
514         struct svr4_sys_pwrite64_args *uap = v;
515         struct sys_pwrite_args pwa;
516
517         /*
518          * Just translate the args structure and call the NetBSD
519          * pwrite(2) system call (offset type is 64-bit in NetBSD).
520          */
521         SCARG(&pwa, fd) = SCARG(uap, fd);
522         SCARG(&pwa, buf) = SCARG(uap, buf);
523         SCARG(&pwa, nbyte) = SCARG(uap, nbyte);
524         SCARG(&pwa, offset) = SCARG(uap, off);
525
526         return (sys_pwrite(p, &pwa, retval));
527 }
528 #endif /* NOTYET */
529
530 int
531 svr4_sys_fcntl(struct svr4_sys_fcntl_args *uap)
532 {
533         struct thread *td = curthread;  /* XXX */
534         struct proc *p = td->td_proc;
535         int                             error;
536         struct fcntl_args               fa;
537         int                             *retval;
538
539         KKASSERT(p);
540         retval = p->p_retval;
541
542         SCARG(&fa, fd) = SCARG(uap, fd);
543         SCARG(&fa, cmd) = svr4_to_bsd_cmd(SCARG(uap, cmd));
544
545         switch (SCARG(&fa, cmd)) {
546         case F_DUPFD:
547         case F_GETFD:
548         case F_SETFD:
549                 SCARG(&fa, arg) = (long) SCARG(uap, arg);
550                 return fcntl(&fa);
551
552         case F_GETFL:
553                 SCARG(&fa, arg) = (long) SCARG(uap, arg);
554                 error = fcntl(&fa);
555                 if (error)
556                         return error;
557                 *retval = bsd_to_svr4_flags(*retval);
558                 return error;
559
560         case F_SETFL:
561                 {
562                         /*
563                          * we must save the O_ASYNC flag, as that is
564                          * handled by ioctl(_, I_SETSIG, _) emulation.
565                          */
566                         long cmd;
567                         int flags;
568
569                         DPRINTF(("Setting flags %p\n", SCARG(uap, arg)));
570                         cmd = SCARG(&fa, cmd); /* save it for a while */
571
572                         SCARG(&fa, cmd) = F_GETFL;
573                         if ((error = fcntl(&fa)) != 0)
574                                 return error;
575                         flags = *retval;
576                         flags &= O_ASYNC;
577                         flags |= svr4_to_bsd_flags((u_long) SCARG(uap, arg));
578                         SCARG(&fa, cmd) = cmd;
579                         SCARG(&fa, arg) = (long) flags;
580                         return fcntl(&fa);
581                 }
582
583         case F_GETLK:
584         case F_SETLK:
585         case F_SETLKW:
586                 {
587                         struct svr4_flock        ifl;
588                         struct flock            *flp, fl;
589                         caddr_t sg = stackgap_init();
590
591                         flp = stackgap_alloc(&sg, sizeof(struct flock));
592                         SCARG(&fa, arg) = (long) flp;
593
594                         error = copyin(SCARG(uap, arg), &ifl, sizeof ifl);
595                         if (error)
596                                 return error;
597
598                         svr4_to_bsd_flock(&ifl, &fl);
599
600                         error = copyout(&fl, flp, sizeof fl);
601                         if (error)
602                                 return error;
603
604                         error = fcntl(&fa);
605                         if (error || SCARG(&fa, cmd) != F_GETLK)
606                                 return error;
607
608                         error = copyin(flp, &fl, sizeof fl);
609                         if (error)
610                                 return error;
611
612                         bsd_to_svr4_flock(&fl, &ifl);
613
614                         return copyout(&ifl, SCARG(uap, arg), sizeof ifl);
615                 }
616         case -1:
617                 switch (SCARG(uap, cmd)) {
618                 case SVR4_F_DUP2FD:
619                         {
620                                 struct dup2_args du;
621
622                                 SCARG(&du, from) = SCARG(uap, fd);
623                                 SCARG(&du, to) = (int)SCARG(uap, arg);
624                                 error = dup2(&du);
625                                 if (error)
626                                         return error;
627                                 *retval = SCARG(&du, to);
628                                 return 0;
629                         }
630
631                 case SVR4_F_FREESP:
632                         {
633                                 struct svr4_flock        ifl;
634                                 struct flock             fl;
635
636                                 error = copyin(SCARG(uap, arg), &ifl,
637                                     sizeof ifl);
638                                 if (error)
639                                         return error;
640                                 svr4_to_bsd_flock(&ifl, &fl);
641                                 return fd_truncate(td, SCARG(uap, fd), &fl);
642                         }
643
644                 case SVR4_F_GETLK64:
645                 case SVR4_F_SETLK64:
646                 case SVR4_F_SETLKW64:
647                         {
648                                 struct svr4_flock64      ifl;
649                                 struct flock            *flp, fl;
650                                 caddr_t sg = stackgap_init();
651
652                                 flp = stackgap_alloc(&sg, sizeof(struct flock));
653                                 SCARG(&fa, arg) = (long) flp;
654
655                                 error = copyin(SCARG(uap, arg), &ifl,
656                                     sizeof ifl);
657                                 if (error)
658                                         return error;
659
660                                 svr4_to_bsd_flock64(&ifl, &fl);
661
662                                 error = copyout(&fl, flp, sizeof fl);
663                                 if (error)
664                                         return error;
665
666                                 error = fcntl(&fa);
667                                 if (error || SCARG(&fa, cmd) != F_GETLK)
668                                         return error;
669
670                                 error = copyin(flp, &fl, sizeof fl);
671                                 if (error)
672                                         return error;
673
674                                 bsd_to_svr4_flock64(&fl, &ifl);
675
676                                 return copyout(&ifl, SCARG(uap, arg),
677                                     sizeof ifl);
678                         }
679
680                 case SVR4_F_FREESP64:
681                         {
682                                 struct svr4_flock64      ifl;
683                                 struct flock             fl;
684
685                                 error = copyin(SCARG(uap, arg), &ifl,
686                                     sizeof ifl);
687                                 if (error)
688                                         return error;
689                                 svr4_to_bsd_flock64(&ifl, &fl);
690                                 return fd_truncate(td, SCARG(uap, fd), &fl);
691                         }
692
693                 case SVR4_F_REVOKE:
694                         return fd_revoke(td, SCARG(uap, fd));
695
696                 default:
697                         return ENOSYS;
698                 }
699
700         default:
701                 return ENOSYS;
702         }
703 }