Scrap DEC Alpha support.
[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.15 2004/10/12 19:20:42 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.h"
51 #include "svr4_types.h"
52 #include "svr4_signal.h"
53 #include "svr4_proto.h"
54 #include "svr4_util.h"
55 #include "svr4_fcntl.h"
56
57 static int svr4_to_bsd_flags (int);
58 static u_long svr4_to_bsd_cmd (u_long);
59 static int fd_revoke (struct thread *, int);
60 static int fd_truncate (struct thread *, int, struct flock *, int *);
61 static int bsd_to_svr4_flags (int);
62 static void bsd_to_svr4_flock (struct flock *, struct svr4_flock *);
63 static void svr4_to_bsd_flock (struct svr4_flock *, struct flock *);
64 static void bsd_to_svr4_flock64 (struct flock *, struct svr4_flock64 *);
65 static void svr4_to_bsd_flock64 (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;
254
255         KKASSERT(p);
256
257         fdp = p->p_fd;
258         if ((u_int)fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL)
259                 return EBADF;
260
261         if (fp->f_type != DTYPE_VNODE) 
262                 return EINVAL;
263
264         vp = (struct vnode *) fp->f_data;
265
266         if ((error = vx_get(vp)) != 0)
267                 return (error);
268
269         if (vp->v_type != VCHR && vp->v_type != VBLK) {
270                 error = EINVAL;
271                 goto out;
272         }
273
274         if ((error = VOP_GETATTR(vp, &vattr, td)) != 0)
275                 goto out;
276
277         if (p->p_ucred->cr_uid != vattr.va_uid &&
278             (error = suser(p->p_thread)) != 0)
279                 goto out;
280
281         if (vcount(vp) > 1)
282                 VOP_REVOKE(vp, REVOKEALL);
283 out:
284         vx_put(vp);
285         return error;
286 }
287
288
289 static int
290 fd_truncate(struct thread *td, int fd, struct flock *flp, int *retval)
291 {
292         struct proc *p = td->td_proc;
293         struct filedesc *fdp;
294         struct file *fp;
295         off_t start, length;
296         struct vnode *vp;
297         struct vattr vattr;
298         int error;
299         struct ftruncate_args ft;
300
301         KKASSERT(p);
302         fdp = p->p_fd;
303
304         /*
305          * We only support truncating the file.
306          */
307         if ((u_int)fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL)
308                 return EBADF;
309
310         vp = (struct vnode *)fp->f_data;
311         if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO)
312                 return ESPIPE;
313
314         if ((error = VOP_GETATTR(vp, &vattr, td)) != 0)
315                 return error;
316
317         length = vattr.va_size;
318
319         switch (flp->l_whence) {
320         case SEEK_CUR:
321                 start = fp->f_offset + flp->l_start;
322                 break;
323
324         case SEEK_END:
325                 start = flp->l_start + length;
326                 break;
327
328         case SEEK_SET:
329                 start = flp->l_start;
330                 break;
331
332         default:
333                 return EINVAL;
334         }
335
336         if (start + flp->l_len < length) {
337                 /* We don't support free'ing in the middle of the file */
338                 return EINVAL;
339         }
340
341         SCARG(&ft, fd) = fd;
342         SCARG(&ft, length) = start;
343         error = ftruncate(&ft);
344         *retval = ft.sysmsg_result;
345         return(error);
346 }
347
348 int
349 svr4_sys_open(struct svr4_sys_open_args *uap)
350 {
351         struct thread *td = curthread;  /* XXX */
352         struct proc *p = td->td_proc;
353         struct open_args cup;
354         int     error, retval;
355
356         caddr_t sg = stackgap_init();
357         CHECKALTEXIST(&sg, SCARG(uap, path));
358
359         cup.sysmsg_result = 0;
360         cup.path = uap->path;
361         cup.flags = svr4_to_bsd_flags(uap->flags);
362         cup.mode = uap->mode;
363         error = open(&cup);
364
365         if (error) {
366           /*            uprintf("svr4_open(%s, 0x%0x, 0%o): %d\n", uap->path,
367                         uap->flags, uap->mode, error);*/
368                 return error;
369         }
370
371         KKASSERT(p);
372         retval = uap->sysmsg_result = cup.sysmsg_result;
373
374         if (!(SCARG(&cup, flags) & O_NOCTTY) && SESS_LEADER(p) &&
375             !(p->p_flag & P_CONTROLT)) {
376 #if defined(NOTYET)
377                 struct filedesc *fdp = p->p_fd;
378                 struct file     *fp = fdp->fd_ofiles[retval];
379
380                 /* ignore any error, just give it a try */
381                 if (fp->f_type == DTYPE_VNODE)
382                         fo_ioctl(fp, TIOCSCTTY, (caddr_t) 0, p);
383 #endif
384         }
385         return error;
386 }
387
388 int
389 svr4_sys_open64(struct svr4_sys_open64_args *uap)
390 {
391         return svr4_sys_open((struct svr4_sys_open_args *)uap);
392 }
393
394 int
395 svr4_sys_creat(struct svr4_sys_creat_args *uap)
396 {
397         struct open_args cup;
398         int error;
399
400         caddr_t sg = stackgap_init();
401         CHECKALTEXIST(&sg, SCARG(uap, path));
402
403         SCARG(&cup, path) = SCARG(uap, path);
404         SCARG(&cup, mode) = SCARG(uap, mode);
405         SCARG(&cup, flags) = O_WRONLY | O_CREAT | O_TRUNC;
406
407         cup.sysmsg_result = 0;
408         error = open(&cup);
409         uap->sysmsg_result = cup.sysmsg_result;
410         return(error);
411 }
412
413 int
414 svr4_sys_creat64(struct svr4_sys_creat64_args *uap)
415 {
416         return svr4_sys_creat((struct svr4_sys_creat_args *)uap);
417 }
418
419 int
420 svr4_sys_llseek(struct svr4_sys_llseek_args *v)
421 {
422         struct svr4_sys_llseek_args *uap = v;
423         struct lseek_args ap;
424
425         SCARG(&ap, fd) = SCARG(uap, fd);
426
427 #if BYTE_ORDER == BIG_ENDIAN
428         SCARG(&ap, offset) = (((long long) SCARG(uap, offset1)) << 32) | 
429                 SCARG(uap, offset2);
430 #else
431         SCARG(&ap, offset) = (((long long) SCARG(uap, offset2)) << 32) | 
432                 SCARG(uap, offset1);
433 #endif
434         SCARG(&ap, whence) = SCARG(uap, whence);
435
436         return lseek(&ap);
437 }
438
439 int
440 svr4_sys_access(struct svr4_sys_access_args *uap)
441 {
442         struct access_args cup;
443         int error;
444
445         caddr_t sg = stackgap_init();
446         CHECKALTEXIST(&sg, SCARG(uap, path));
447
448         SCARG(&cup, path) = SCARG(uap, path);
449         SCARG(&cup, flags) = SCARG(uap, flags);
450         cup.sysmsg_result = 0;
451         error = access(&cup);
452         uap->sysmsg_result = cup.sysmsg_result;
453         return(error);
454 }
455
456 #if defined(NOTYET)
457 int
458 svr4_sys_pread(struct svr4_sys_pread_args *uap)
459 {
460         struct pread_args pra;
461         int error;
462
463         /*
464          * Just translate the args structure and call the NetBSD
465          * pread(2) system call (offset type is 64-bit in NetBSD).
466          */
467         SCARG(&pra, fd) = SCARG(uap, fd);
468         SCARG(&pra, buf) = SCARG(uap, buf);
469         SCARG(&pra, nbyte) = SCARG(uap, nbyte);
470         SCARG(&pra, offset) = SCARG(uap, off);
471
472         pra.sysmsg_result = 0;
473         error = pread(&pra);
474         uap->sysmsg_result = pra.sysmsg_result;
475         return(error);
476 }
477 #endif
478
479 #if defined(NOTYET)
480 int
481 svr4_sys_pread64(struct thread *td, void *v, register_t *retval)
482 {
483         struct svr4_sys_pread64_args *uap = v;
484         struct sys_pread_args pra;
485         int error;
486
487         /*
488          * Just translate the args structure and call the NetBSD
489          * pread(2) system call (offset type is 64-bit in NetBSD).
490          */
491         SCARG(&pra, fd) = SCARG(uap, fd);
492         SCARG(&pra, buf) = SCARG(uap, buf);
493         SCARG(&pra, nbyte) = SCARG(uap, nbyte);
494         SCARG(&pra, offset) = SCARG(uap, off);
495
496         pra.sysmsg_result = 0;
497         error = sys_pread(&pra, retval);
498         uap->sysmsg_result = pra.sysmsg_result;
499         return(error);
500 }
501 #endif /* NOTYET */
502
503 #if defined(NOTYET)
504 int
505 svr4_sys_pwrite(struct svr4_sys_pwrite_args *uap)
506 {
507         struct pwrite_args pwa;
508         int error;
509
510         /*
511          * Just translate the args structure and call the NetBSD
512          * pwrite(2) system call (offset type is 64-bit in NetBSD).
513          */
514         SCARG(&pwa, fd) = SCARG(uap, fd);
515         SCARG(&pwa, buf) = SCARG(uap, buf);
516         SCARG(&pwa, nbyte) = SCARG(uap, nbyte);
517         SCARG(&pwa, offset) = SCARG(uap, off);
518
519         pwa.sysmsg_result = 0;
520         error = pwrite(&pwa);
521         uap->sysmsg_result = pwa.sysmsg_result;
522         return(error);
523 }
524 #endif
525
526 #if defined(NOTYET)
527 int
528 svr4_sys_pwrite64(struct thread *td, void *v, register_t *retval)
529 {
530         struct svr4_sys_pwrite64_args *uap = v;
531         struct sys_pwrite_args pwa;
532
533         /*
534          * Just translate the args structure and call the NetBSD
535          * pwrite(2) system call (offset type is 64-bit in NetBSD).
536          */
537         SCARG(&pwa, fd) = SCARG(uap, fd);
538         SCARG(&pwa, buf) = SCARG(uap, buf);
539         SCARG(&pwa, nbyte) = SCARG(uap, nbyte);
540         SCARG(&pwa, offset) = SCARG(uap, off);
541
542         return (sys_pwrite(p, &pwa, retval));
543 }
544 #endif /* NOTYET */
545
546 int
547 svr4_sys_fcntl(struct svr4_sys_fcntl_args *uap)
548 {
549         struct thread *td = curthread;  /* XXX */
550         int                             error;
551         struct fcntl_args               fa;
552         int                             *retval;
553
554         retval = &uap->sysmsg_result;
555
556         SCARG(&fa, fd) = SCARG(uap, fd);
557         SCARG(&fa, cmd) = svr4_to_bsd_cmd(SCARG(uap, cmd));
558
559         switch (SCARG(&fa, cmd)) {
560         case F_DUPFD:
561         case F_GETFD:
562         case F_SETFD:
563                 SCARG(&fa, arg) = (long) SCARG(uap, arg);
564                 fa.sysmsg_result = 0;
565                 error = fcntl(&fa);
566                 *retval = fa.sysmsg_result;
567                 return error;
568
569         case F_GETFL:
570                 SCARG(&fa, arg) = (long) SCARG(uap, arg);
571                 error = fcntl(&fa);
572                 if (error)
573                         return error;
574                 *retval = bsd_to_svr4_flags(fa.sysmsg_result);
575                 return error;
576
577         case F_SETFL:
578                 {
579                         /*
580                          * we must save the O_ASYNC flag, as that is
581                          * handled by ioctl(_, I_SETSIG, _) emulation.
582                          */
583                         long cmd;
584                         int flags;
585
586                         DPRINTF(("Setting flags %p\n", SCARG(uap, arg)));
587                         cmd = SCARG(&fa, cmd); /* save it for a while */
588
589                         SCARG(&fa, cmd) = F_GETFL;
590                         if ((error = fcntl(&fa)) != 0)
591                                 return error;
592                         flags = fa.sysmsg_result;
593                         flags &= O_ASYNC;
594                         flags |= svr4_to_bsd_flags((u_long) SCARG(uap, arg));
595                         SCARG(&fa, cmd) = cmd;
596                         SCARG(&fa, arg) = (long) flags;
597                         error = fcntl(&fa);
598                         *retval = fa.sysmsg_result;
599                         return error;
600                 }
601
602         case F_GETLK:
603         case F_SETLK:
604         case F_SETLKW:
605                 {
606                         struct svr4_flock        ifl;
607                         struct flock            *flp, fl;
608                         caddr_t sg = stackgap_init();
609
610                         flp = stackgap_alloc(&sg, sizeof(struct flock));
611                         SCARG(&fa, arg) = (long) flp;
612
613                         error = copyin(SCARG(uap, arg), &ifl, sizeof ifl);
614                         if (error)
615                                 return error;
616
617                         svr4_to_bsd_flock(&ifl, &fl);
618
619                         error = copyout(&fl, flp, sizeof fl);
620                         if (error)
621                                 return error;
622
623                         fa.sysmsg_result = 0;
624                         error = fcntl(&fa);
625                         *retval = fa.sysmsg_result;
626                         if (error || SCARG(&fa, cmd) != F_GETLK)
627                                 return error;
628
629                         error = copyin(flp, &fl, sizeof fl);
630                         if (error)
631                                 return error;
632
633                         bsd_to_svr4_flock(&fl, &ifl);
634
635                         return copyout(&ifl, SCARG(uap, arg), sizeof ifl);
636                 }
637         case -1:
638                 switch (SCARG(uap, cmd)) {
639                 case SVR4_F_DUP2FD:
640                         {
641                                 struct dup2_args du;
642
643                                 SCARG(&du, from) = SCARG(uap, fd);
644                                 SCARG(&du, to) = (int)SCARG(uap, arg);
645                                 error = dup2(&du);
646                                 if (error)
647                                         return error;
648                                 *retval = SCARG(&du, to);
649                                 return 0;
650                         }
651
652                 case SVR4_F_FREESP:
653                         {
654                                 struct svr4_flock        ifl;
655                                 struct flock             fl;
656
657                                 error = copyin(SCARG(uap, arg), &ifl,
658                                     sizeof ifl);
659                                 if (error)
660                                         return error;
661                                 svr4_to_bsd_flock(&ifl, &fl);
662                                 return fd_truncate(td, SCARG(uap, fd), &fl, retval);
663                         }
664
665                 case SVR4_F_GETLK64:
666                 case SVR4_F_SETLK64:
667                 case SVR4_F_SETLKW64:
668                         {
669                                 struct svr4_flock64      ifl;
670                                 struct flock            *flp, fl;
671                                 caddr_t sg = stackgap_init();
672
673                                 flp = stackgap_alloc(&sg, sizeof(struct flock));
674                                 SCARG(&fa, arg) = (long) flp;
675
676                                 error = copyin(SCARG(uap, arg), &ifl,
677                                     sizeof ifl);
678                                 if (error)
679                                         return error;
680
681                                 svr4_to_bsd_flock64(&ifl, &fl);
682
683                                 error = copyout(&fl, flp, sizeof fl);
684                                 if (error)
685                                         return error;
686
687                                 fa.sysmsg_result = 0;
688                                 error = fcntl(&fa);
689                                 *retval = fa.sysmsg_result;
690                                 if (error || SCARG(&fa, cmd) != F_GETLK)
691                                         return error;
692
693                                 error = copyin(flp, &fl, sizeof fl);
694                                 if (error)
695                                         return error;
696
697                                 bsd_to_svr4_flock64(&fl, &ifl);
698
699                                 return copyout(&ifl, SCARG(uap, arg),
700                                     sizeof ifl);
701                         }
702
703                 case SVR4_F_FREESP64:
704                         {
705                                 struct svr4_flock64      ifl;
706                                 struct flock             fl;
707
708                                 error = copyin(SCARG(uap, arg), &ifl,
709                                     sizeof ifl);
710                                 if (error)
711                                         return error;
712                                 svr4_to_bsd_flock64(&ifl, &fl);
713                                 return fd_truncate(td, SCARG(uap, fd), &fl, retval);
714                         }
715
716                 case SVR4_F_REVOKE:
717                         return fd_revoke(td, SCARG(uap, fd));
718
719                 default:
720                         return ENOSYS;
721                 }
722
723         default:
724                 return ENOSYS;
725         }
726 }