xref: /netbsd-src/sys/compat/sunos/sunos_misc.c (revision 4472dbe5e3bd91ef2540bada7a7ca7384627ff9b)
1 /*	$NetBSD: sunos_misc.c,v 1.104 2000/03/30 11:27:19 augustss Exp $	*/
2 
3 /*
4  * Copyright (c) 1992, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This software was developed by the Computer Systems Engineering group
8  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9  * contributed to Berkeley.
10  *
11  * All advertising materials mentioning features or use of this software
12  * must display the following acknowledgement:
13  *	This product includes software developed by the University of
14  *	California, Lawrence Berkeley Laboratory.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  * 1. Redistributions of source code must retain the above copyright
20  *    notice, this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in the
23  *    documentation and/or other materials provided with the distribution.
24  * 3. All advertising materials mentioning features or use of this software
25  *    must display the following acknowledgement:
26  *	This product includes software developed by the University of
27  *	California, Berkeley and its contributors.
28  * 4. Neither the name of the University nor the names of its contributors
29  *    may be used to endorse or promote products derived from this software
30  *    without specific prior written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42  * SUCH DAMAGE.
43  *
44  *	@(#)sunos_misc.c	8.1 (Berkeley) 6/18/93
45  *
46  *	Header: sunos_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
47  */
48 
49 /*
50  * SunOS compatibility module.
51  *
52  * SunOS system calls that are implemented differently in BSD are
53  * handled here.
54  */
55 
56 #define COMPAT_SUNOS 1
57 
58 #include "opt_nfsserver.h"
59 #include "fs_nfs.h"
60 
61 #include <sys/param.h>
62 #include <sys/systm.h>
63 #include <sys/namei.h>
64 #include <sys/proc.h>
65 #include <sys/dirent.h>
66 #include <sys/file.h>
67 #include <sys/stat.h>
68 #include <sys/filedesc.h>
69 #include <sys/ioctl.h>
70 #include <sys/kernel.h>
71 #include <sys/reboot.h>
72 #include <sys/malloc.h>
73 #include <sys/mbuf.h>
74 #include <sys/mman.h>
75 #include <sys/mount.h>
76 #include <sys/ptrace.h>
77 #include <sys/resource.h>
78 #include <sys/resourcevar.h>
79 #include <sys/signal.h>
80 #include <sys/signalvar.h>
81 #include <sys/socket.h>
82 #include <sys/tty.h>
83 #include <sys/vnode.h>
84 #include <sys/uio.h>
85 #include <sys/wait.h>
86 #include <sys/utsname.h>
87 #include <sys/unistd.h>
88 #include <sys/syscallargs.h>
89 #include <sys/conf.h>
90 #include <sys/socketvar.h>
91 #include <sys/exec.h>
92 #include <sys/swap.h>
93 
94 #include <compat/sunos/sunos.h>
95 #include <compat/sunos/sunos_syscallargs.h>
96 #include <compat/sunos/sunos_util.h>
97 #include <compat/sunos/sunos_dirent.h>
98 
99 #include <netinet/in.h>
100 
101 #include <miscfs/specfs/specdev.h>
102 
103 #include <nfs/rpcv2.h>
104 #include <nfs/nfsproto.h>
105 #include <nfs/nfs.h>
106 #include <nfs/nfsmount.h>
107 
108 #include <vm/vm.h>
109 
110 static int sunstatfs __P((struct statfs *, caddr_t));
111 
112 int
113 sunos_sys_stime(p, v, retval)
114 	struct proc *p;
115 	void *v;
116 	register_t *retval;
117 {
118 	struct sunos_sys_stime_args *uap = v;
119 	struct sys_settimeofday_args ap;
120 	caddr_t sg = stackgap_init(p->p_emul);
121 	struct timeval tv, *sgtvp;
122 	int error;
123 
124 	error = copyin(SCARG(uap, tp), &tv.tv_sec, sizeof(tv.tv_sec));
125 	if (error)
126 		return error;
127 	tv.tv_usec = 0;
128 
129 	SCARG(&ap, tv) = sgtvp = stackgap_alloc(&sg, sizeof(struct timeval));
130 	SCARG(&ap, tzp) = NULL;
131 
132 	error = copyout(&tv, sgtvp, sizeof(struct timeval));
133 	if (error)
134 		return error;
135 
136 	return sys_settimeofday(p, &ap, retval);
137 }
138 
139 int
140 sunos_sys_wait4(p, v, retval)
141 	struct proc *p;
142 	void *v;
143 	register_t *retval;
144 {
145 	struct sunos_sys_wait4_args *uap = v;
146 	if (SCARG(uap, pid) == 0)
147 		SCARG(uap, pid) = WAIT_ANY;
148 	return (sys_wait4(p, uap, retval));
149 }
150 
151 int
152 sunos_sys_creat(p, v, retval)
153 	struct proc *p;
154 	void *v;
155 	register_t *retval;
156 {
157 	struct sunos_sys_creat_args *uap = v;
158 	struct sys_open_args ouap;
159 
160 	caddr_t sg = stackgap_init(p->p_emul);
161 	SUNOS_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
162 
163 	SCARG(&ouap, path) = SCARG(uap, path);
164 	SCARG(&ouap, flags) = O_WRONLY | O_CREAT | O_TRUNC;
165 	SCARG(&ouap, mode) = SCARG(uap, mode);
166 
167 	return (sys_open(p, &ouap, retval));
168 }
169 
170 int
171 sunos_sys_access(p, v, retval)
172 	struct proc *p;
173 	void *v;
174 	register_t *retval;
175 {
176 	struct sunos_sys_access_args *uap = v;
177 	caddr_t sg = stackgap_init(p->p_emul);
178 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
179 
180 	return (sys_access(p, uap, retval));
181 }
182 
183 int
184 sunos_sys_stat(p, v, retval)
185 	struct proc *p;
186 	void *v;
187 	register_t *retval;
188 {
189 	struct sunos_sys_stat_args *uap = v;
190 	caddr_t sg = stackgap_init(p->p_emul);
191 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
192 
193 	return (compat_43_sys_stat(p, uap, retval));
194 }
195 
196 int
197 sunos_sys_lstat(p, v, retval)
198 	struct proc *p;
199 	void *v;
200 	register_t *retval;
201 {
202 	struct sunos_sys_lstat_args *uap = v;
203 	caddr_t sg = stackgap_init(p->p_emul);
204 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
205 
206 	return (compat_43_sys_lstat(p, uap, retval));
207 }
208 
209 int
210 sunos_sys_execv(p, v, retval)
211 	struct proc *p;
212 	void *v;
213 	register_t *retval;
214 {
215 	struct sunos_sys_execv_args /* {
216 		syscallarg(const char *) path;
217 		syscallarg(char **) argv;
218 	} */ *uap = v;
219 	struct sys_execve_args ap;
220 	caddr_t sg;
221 
222 	sg = stackgap_init(p->p_emul);
223 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
224 
225 	SCARG(&ap, path) = SCARG(uap, path);
226 	SCARG(&ap, argp) = SCARG(uap, argp);
227 	SCARG(&ap, envp) = NULL;
228 
229 	return (sys_execve(p, &ap, retval));
230 }
231 
232 int
233 sunos_sys_execve(p, v, retval)
234 	struct proc *p;
235 	void *v;
236 	register_t *retval;
237 {
238 	struct sunos_sys_execve_args /* {
239 		syscallarg(const char *) path;
240 		syscallarg(char **) argv;
241 		syscallarg(char **) envp;
242 	} */ *uap = v;
243 	struct sys_execve_args ap;
244 	caddr_t sg;
245 
246 	sg = stackgap_init(p->p_emul);
247 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
248 
249 	SCARG(&ap, path) = SCARG(uap, path);
250 	SCARG(&ap, argp) = SCARG(uap, argp);
251 	SCARG(&ap, envp) = SCARG(uap, envp);
252 
253 	return (sys_execve(p, &ap, retval));
254 }
255 
256 int
257 sunos_sys_omsync(p, v, retval)
258 	struct proc *p;
259 	void *v;
260 	register_t *retval;
261 {
262 	struct sunos_sys_omsync_args *uap = v;
263 	struct sys___msync13_args ouap;
264 
265 	SCARG(&ouap, addr) = SCARG(uap, addr);
266 	SCARG(&ouap, len) = SCARG(uap, len);
267 	SCARG(&ouap, flags) = SCARG(uap, flags);
268 
269 	return (sys___msync13(p, &ouap, retval));
270 }
271 
272 int
273 sunos_sys_unmount(p, v, retval)
274 	struct proc *p;
275 	void *v;
276 	register_t *retval;
277 {
278 	struct sunos_sys_unmount_args *uap = v;
279 	struct sys_unmount_args ouap;
280 
281 	SCARG(&ouap, path) = SCARG(uap, path);
282 	SCARG(&ouap, flags) = 0;
283 
284 	return (sys_unmount(p, &ouap, retval));
285 }
286 
287 /*
288  * Conversion table for SunOS NFS mount flags.
289  */
290 static struct {
291 	int	sun_flg;
292 	int	bsd_flg;
293 } sunnfs_flgtab[] = {
294 	{ SUNNFS_SOFT,		NFSMNT_SOFT },
295 	{ SUNNFS_WSIZE,		NFSMNT_WSIZE },
296 	{ SUNNFS_RSIZE,		NFSMNT_RSIZE },
297 	{ SUNNFS_TIMEO,		NFSMNT_TIMEO },
298 	{ SUNNFS_RETRANS,	NFSMNT_RETRANS },
299 	{ SUNNFS_HOSTNAME,	0 },			/* Ignored */
300 	{ SUNNFS_INT,		NFSMNT_INT },
301 	{ SUNNFS_NOAC,		0 },			/* Ignored */
302 	{ SUNNFS_ACREGMIN,	0 },			/* Ignored */
303 	{ SUNNFS_ACREGMAX,	0 },			/* Ignored */
304 	{ SUNNFS_ACDIRMIN,	0 },			/* Ignored */
305 	{ SUNNFS_ACDIRMAX,	0 },			/* Ignored */
306 	{ SUNNFS_SECURE,	0 },			/* Ignored */
307 	{ SUNNFS_NOCTO,		0 },			/* Ignored */
308 	{ SUNNFS_POSIX,		0 }			/* Ignored */
309 };
310 
311 int
312 sunos_sys_mount(p, v, retval)
313 	struct proc *p;
314 	void *v;
315 	register_t *retval;
316 {
317 	struct sunos_sys_mount_args *uap = v;
318 	int oflags = SCARG(uap, flags), nflags, error;
319 	char fsname[MFSNAMELEN];
320 	caddr_t sg = stackgap_init(p->p_emul);
321 
322 	if (oflags & (SUNM_NOSUB | SUNM_SYS5))
323 		return (EINVAL);
324 	if ((oflags & SUNM_NEWTYPE) == 0)
325 		return (EINVAL);
326 	nflags = 0;
327 	if (oflags & SUNM_RDONLY)
328 		nflags |= MNT_RDONLY;
329 	if (oflags & SUNM_NOSUID)
330 		nflags |= MNT_NOSUID;
331 	if (oflags & SUNM_REMOUNT)
332 		nflags |= MNT_UPDATE;
333 	SCARG(uap, flags) = nflags;
334 
335 	error = copyinstr((caddr_t)SCARG(uap, type), fsname,
336 	    sizeof fsname, (size_t *)0);
337 	if (error)
338 		return (error);
339 
340 	if (strncmp(fsname, "4.2", sizeof fsname) == 0) {
341 		SCARG(uap, type) = stackgap_alloc(&sg, sizeof("ffs"));
342 		error = copyout("ffs", SCARG(uap, type), sizeof("ffs"));
343 		if (error)
344 			return (error);
345 	} else if (strncmp(fsname, "nfs", sizeof fsname) == 0) {
346 		struct sunos_nfs_args sna;
347 		struct sockaddr_in sain;
348 		struct nfs_args na;
349 		struct sockaddr sa;
350 		int n;
351 
352 		error = copyin(SCARG(uap, data), &sna, sizeof sna);
353 		if (error)
354 			return (error);
355 		error = copyin(sna.addr, &sain, sizeof sain);
356 		if (error)
357 			return (error);
358 		memcpy(&sa, &sain, sizeof sa);
359 		sa.sa_len = sizeof(sain);
360 		SCARG(uap, data) = stackgap_alloc(&sg, sizeof(na));
361 		na.version = NFS_ARGSVERSION;
362 		na.addr = stackgap_alloc(&sg, sizeof(struct sockaddr));
363 		na.addrlen = sizeof(struct sockaddr);
364 		na.sotype = SOCK_DGRAM;
365 		na.proto = IPPROTO_UDP;
366 		na.fh = (void *)sna.fh;
367 		na.fhsize = NFSX_V2FH;
368 		na.flags = 0;
369 		n = sizeof(sunnfs_flgtab) / sizeof(sunnfs_flgtab[0]);
370 		while (--n >= 0)
371 			if (sna.flags & sunnfs_flgtab[n].sun_flg)
372 				na.flags |= sunnfs_flgtab[n].bsd_flg;
373 		na.wsize = sna.wsize;
374 		na.rsize = sna.rsize;
375 		if (na.flags & NFSMNT_RSIZE) {
376 			na.flags |= NFSMNT_READDIRSIZE;
377 			na.readdirsize = na.rsize;
378 		}
379 		na.timeo = sna.timeo;
380 		na.retrans = sna.retrans;
381 		na.hostname = sna.hostname;
382 
383 		error = copyout(&sa, na.addr, sizeof sa);
384 		if (error)
385 			return (error);
386 		error = copyout(&na, SCARG(uap, data), sizeof na);
387 		if (error)
388 			return (error);
389 	}
390 	return (sys_mount(p, (struct sys_mount_args *)uap, retval));
391 }
392 
393 #if defined(NFS)
394 int
395 async_daemon(p, v, retval)
396 	struct proc *p;
397 	void *v;
398 	register_t *retval;
399 {
400 	struct sys_nfssvc_args ouap;
401 
402 	SCARG(&ouap, flag) = NFSSVC_BIOD;
403 	SCARG(&ouap, argp) = NULL;
404 
405 	return (sys_nfssvc(p, &ouap, retval));
406 }
407 #endif /* NFS */
408 
409 void	native_to_sunos_sigset __P((const sigset_t *, int *));
410 void	sunos_to_native_sigset __P((const int, sigset_t *));
411 
412 __inline__ void
413 native_to_sunos_sigset(ss, mask)
414 	const sigset_t *ss;
415 	int *mask;
416 {
417 	*mask = ss->__bits[0];
418 }
419 
420 __inline__ void
421 sunos_to_native_sigset(mask, ss)
422 	const int mask;
423 	sigset_t *ss;
424 {
425 
426 	ss->__bits[0] = mask;
427 	ss->__bits[1] = 0;
428 	ss->__bits[2] = 0;
429 	ss->__bits[3] = 0;
430 }
431 
432 int
433 sunos_sys_sigpending(p, v, retval)
434 	struct proc *p;
435 	void *v;
436 	register_t *retval;
437 {
438 	struct sunos_sys_sigpending_args *uap = v;
439 	sigset_t ss;
440 	int mask;
441 
442 	sigpending1(p, &ss);
443 	native_to_sunos_sigset(&ss, &mask);
444 
445 	return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
446 }
447 
448 int
449 sunos_sys_sigsuspend(p, v, retval)
450 	struct proc *p;
451 	void *v;
452 	register_t *retval;
453 {
454 	struct sunos_sys_sigsuspend_args /* {
455 		syscallarg(int) mask;
456 	} */ *uap = v;
457 	int mask;
458 	sigset_t ss;
459 
460 	mask = SCARG(uap, mask);
461 	sunos_to_native_sigset(mask, &ss);
462 	return (sigsuspend1(p, &ss));
463 }
464 
465 /*
466  * Read Sun-style directory entries.  We suck them into kernel space so
467  * that they can be massaged before being copied out to user code.  Like
468  * SunOS, we squish out `empty' entries.
469  *
470  * This is quite ugly, but what do you expect from compatibility code?
471  */
472 int
473 sunos_sys_getdents(p, v, retval)
474 	struct proc *p;
475 	void *v;
476 	register_t *retval;
477 {
478 	struct sunos_sys_getdents_args *uap = v;
479 	struct dirent *bdp;
480 	struct vnode *vp;
481 	caddr_t inp, buf;	/* BSD-format */
482 	int len, reclen;	/* BSD-format */
483 	caddr_t outp;		/* Sun-format */
484 	int resid, sunos_reclen;/* Sun-format */
485 	struct file *fp;
486 	struct uio auio;
487 	struct iovec aiov;
488 	struct sunos_dirent idb;
489 	off_t off;			/* true file offset */
490 	int buflen, error, eofflag;
491 	off_t *cookiebuf, *cookie;
492 	int ncookies;
493 
494 	/* getvnode() will use the descriptor for us */
495 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
496 		return (error);
497 
498 	if ((fp->f_flag & FREAD) == 0) {
499 		error = EBADF;
500 		goto out1;
501 	}
502 
503 	vp = (struct vnode *)fp->f_data;
504 	if (vp->v_type != VDIR) {
505 		error = EINVAL;
506 		goto out1;
507 	}
508 
509 	buflen = min(MAXBSIZE, SCARG(uap, nbytes));
510 	buf = malloc(buflen, M_TEMP, M_WAITOK);
511 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
512 	off = fp->f_offset;
513 again:
514 	aiov.iov_base = buf;
515 	aiov.iov_len = buflen;
516 	auio.uio_iov = &aiov;
517 	auio.uio_iovcnt = 1;
518 	auio.uio_rw = UIO_READ;
519 	auio.uio_segflg = UIO_SYSSPACE;
520 	auio.uio_procp = p;
521 	auio.uio_resid = buflen;
522 	auio.uio_offset = off;
523 	/*
524 	 * First we read into the malloc'ed buffer, then
525 	 * we massage it into user space, one record at a time.
526 	 */
527 	error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf,
528 	    &ncookies);
529 	if (error)
530 		goto out;
531 
532 	inp = buf;
533 	outp = SCARG(uap, buf);
534 	resid = SCARG(uap, nbytes);
535 	if ((len = buflen - auio.uio_resid) == 0)
536 		goto eof;
537 
538 	for (cookie = cookiebuf; len > 0; len -= reclen) {
539 		bdp = (struct dirent *)inp;
540 		reclen = bdp->d_reclen;
541 		if (reclen & 3)
542 			panic("sunos_getdents");
543 		if ((*cookie >> 32) != 0) {
544 			compat_offseterr(vp, "sunos_getdents");
545 			error = EINVAL;
546 			goto out;
547 		}
548 		if (bdp->d_fileno == 0) {
549 			inp += reclen;	/* it is a hole; squish it out */
550 			off = *cookie++;
551 			continue;
552 		}
553 		sunos_reclen = SUNOS_RECLEN(&idb, bdp->d_namlen);
554 		if (reclen > len || resid < sunos_reclen) {
555 			/* entry too big for buffer, so just stop */
556 			outp++;
557 			break;
558 		}
559 		off = *cookie++;	/* each entry points to next */
560 		/*
561 		 * Massage in place to make a Sun-shaped dirent (otherwise
562 		 * we have to worry about touching user memory outside of
563 		 * the copyout() call).
564 		 */
565 		idb.d_fileno = bdp->d_fileno;
566 		idb.d_off = off;
567 		idb.d_reclen = sunos_reclen;
568 		idb.d_namlen = bdp->d_namlen;
569 		strcpy(idb.d_name, bdp->d_name);
570 		if ((error = copyout((caddr_t)&idb, outp, sunos_reclen)) != 0)
571 			goto out;
572 		/* advance past this real entry */
573 		inp += reclen;
574 		/* advance output past Sun-shaped entry */
575 		outp += sunos_reclen;
576 		resid -= sunos_reclen;
577 	}
578 
579 	/* if we squished out the whole block, try again */
580 	if (outp == SCARG(uap, buf))
581 		goto again;
582 	fp->f_offset = off;		/* update the vnode offset */
583 
584 eof:
585 	*retval = SCARG(uap, nbytes) - resid;
586 out:
587 	VOP_UNLOCK(vp, 0);
588 	free(cookiebuf, M_TEMP);
589 	free(buf, M_TEMP);
590  out1:
591 	FILE_UNUSE(fp, p);
592 	return (error);
593 }
594 
595 #define	SUNOS__MAP_NEW	0x80000000	/* if not, old mmap & cannot handle */
596 
597 int
598 sunos_sys_mmap(p, v, retval)
599 	struct proc *p;
600 	void *v;
601 	register_t *retval;
602 {
603 	struct sunos_sys_mmap_args *uap = v;
604 	struct sys_mmap_args ouap;
605 	struct filedesc *fdp;
606 	struct file *fp;
607 	struct vnode *vp;
608 
609 	/*
610 	 * Verify the arguments.
611 	 */
612 	if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
613 		return (EINVAL);			/* XXX still needed? */
614 
615 	if ((SCARG(uap, flags) & SUNOS__MAP_NEW) == 0)
616 		return (EINVAL);
617 
618 	SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUNOS__MAP_NEW;
619 	SCARG(&ouap, addr) = SCARG(uap, addr);
620 
621 	if ((SCARG(&ouap, flags) & MAP_FIXED) == 0 &&
622 	    SCARG(&ouap, addr) != 0 &&
623 	    SCARG(&ouap, addr) < (void *)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ))
624 		SCARG(&ouap, addr) = (caddr_t)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ);
625 
626 	SCARG(&ouap, len) = SCARG(uap, len);
627 	SCARG(&ouap, prot) = SCARG(uap, prot);
628 	SCARG(&ouap, fd) = SCARG(uap, fd);
629 	SCARG(&ouap, pos) = SCARG(uap, pos);
630 
631 	/*
632 	 * Special case: if fd refers to /dev/zero, map as MAP_ANON.  (XXX)
633 	 */
634 	fdp = p->p_fd;
635 	if ((unsigned)SCARG(&ouap, fd) < fdp->fd_nfiles &&		/*XXX*/
636 	    (fp = fdp->fd_ofiles[SCARG(&ouap, fd)]) != NULL &&		/*XXX*/
637 	    fp->f_type == DTYPE_VNODE &&				/*XXX*/
638 	    (vp = (struct vnode *)fp->f_data)->v_type == VCHR &&	/*XXX*/
639 	    iszerodev(vp->v_rdev)) {					/*XXX*/
640 		SCARG(&ouap, flags) |= MAP_ANON;
641 		SCARG(&ouap, fd) = -1;
642 	}
643 
644 	return (sys_mmap(p, &ouap, retval));
645 }
646 
647 #define	MC_SYNC		1
648 #define	MC_LOCK		2
649 #define	MC_UNLOCK	3
650 #define	MC_ADVISE	4
651 #define	MC_LOCKAS	5
652 #define	MC_UNLOCKAS	6
653 
654 int
655 sunos_sys_mctl(p, v, retval)
656 	struct proc *p;
657 	void *v;
658 	register_t *retval;
659 {
660 	struct sunos_sys_mctl_args *uap = v;
661 
662 	switch (SCARG(uap, func)) {
663 	case MC_ADVISE:		/* ignore for now */
664 		return (0);
665 	case MC_SYNC:		/* translate to msync */
666 		return (sys___msync13(p, uap, retval));
667 	default:
668 		return (EINVAL);
669 	}
670 }
671 
672 int
673 sunos_sys_setsockopt(p, v, retval)
674 	struct proc *p;
675 	void *v;
676 	register_t *retval;
677 {
678 	struct sunos_sys_setsockopt_args *uap = v;
679 	struct file *fp;
680 	struct mbuf *m = NULL;
681 	int error;
682 
683 	/* getsock() will use the descriptor for us */
684 	if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
685 		return (error);
686 #define	SO_DONTLINGER (~SO_LINGER)
687 	if (SCARG(uap, name) == SO_DONTLINGER) {
688 		m = m_get(M_WAIT, MT_SOOPTS);
689 		mtod(m, struct linger *)->l_onoff = 0;
690 		m->m_len = sizeof(struct linger);
691 		error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
692 		    SO_LINGER, m);
693 		goto out;
694 	}
695 	if (SCARG(uap, level) == IPPROTO_IP) {
696 #define		SUNOS_IP_MULTICAST_IF		2
697 #define		SUNOS_IP_MULTICAST_TTL		3
698 #define		SUNOS_IP_MULTICAST_LOOP		4
699 #define		SUNOS_IP_ADD_MEMBERSHIP		5
700 #define		SUNOS_IP_DROP_MEMBERSHIP	6
701 		static int ipoptxlat[] = {
702 			IP_MULTICAST_IF,
703 			IP_MULTICAST_TTL,
704 			IP_MULTICAST_LOOP,
705 			IP_ADD_MEMBERSHIP,
706 			IP_DROP_MEMBERSHIP
707 		};
708 		if (SCARG(uap, name) >= SUNOS_IP_MULTICAST_IF &&
709 		    SCARG(uap, name) <= SUNOS_IP_DROP_MEMBERSHIP) {
710 			SCARG(uap, name) =
711 			    ipoptxlat[SCARG(uap, name) - SUNOS_IP_MULTICAST_IF];
712 		}
713 	}
714 	if (SCARG(uap, valsize) > MLEN) {
715 		error = EINVAL;
716 		goto out;
717 	}
718 	if (SCARG(uap, val)) {
719 		m = m_get(M_WAIT, MT_SOOPTS);
720 		error = copyin(SCARG(uap, val), mtod(m, caddr_t),
721 		    (u_int)SCARG(uap, valsize));
722 		if (error) {
723 			(void) m_free(m);
724 			goto out;
725 		}
726 		m->m_len = SCARG(uap, valsize);
727 	}
728 	error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
729 	    SCARG(uap, name), m);
730  out:
731 	FILE_UNUSE(fp, p);
732 	return (error);
733 }
734 
735 /*
736  * XXX: This needs cleaning up.
737  */
738 int
739 sunos_sys_auditsys(p, v, retval)
740 	struct proc *p;
741 	void *v;
742 	register_t *retval;
743 {
744 	return 0;
745 }
746 
747 int
748 sunos_sys_uname(p, v, retval)
749 	struct proc *p;
750 	void *v;
751 	register_t *retval;
752 {
753 	struct sunos_sys_uname_args *uap = v;
754 	struct sunos_utsname sut;
755 
756 	memset(&sut, 0, sizeof(sut));
757 
758 	memcpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
759 	memcpy(sut.nodename, hostname, sizeof(sut.nodename));
760 	sut.nodename[sizeof(sut.nodename)-1] = '\0';
761 	memcpy(sut.release, osrelease, sizeof(sut.release) - 1);
762 	memcpy(sut.version, "1", sizeof(sut.version) - 1);
763 	memcpy(sut.machine, machine, sizeof(sut.machine) - 1);
764 
765 	return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
766 	    sizeof(struct sunos_utsname));
767 }
768 
769 int
770 sunos_sys_setpgrp(p, v, retval)
771 	struct proc *p;
772 	void *v;
773 	register_t *retval;
774 {
775 	struct sunos_sys_setpgrp_args *uap = v;
776 
777 	/*
778 	 * difference to our setpgid call is to include backwards
779 	 * compatibility to pre-setsid() binaries. Do setsid()
780 	 * instead of setpgid() in those cases where the process
781 	 * tries to create a new session the old way.
782 	 */
783 	if (!SCARG(uap, pgid) &&
784 	    (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
785 		return sys_setsid(p, uap, retval);
786 	else
787 		return sys_setpgid(p, uap, retval);
788 }
789 
790 int
791 sunos_sys_open(p, v, retval)
792 	struct proc *p;
793 	void *v;
794 	register_t *retval;
795 {
796 	struct sunos_sys_open_args *uap = v;
797 	int l, r;
798 	int noctty;
799 	int ret;
800 
801 	caddr_t sg = stackgap_init(p->p_emul);
802 
803 	/* convert mode into NetBSD mode */
804 	l = SCARG(uap, flags);
805 	noctty = l & 0x8000;
806 	r =	(l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
807 	r |=	((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
808 	r |=	((l & 0x0080) ? O_SHLOCK : 0);
809 	r |=	((l & 0x0100) ? O_EXLOCK : 0);
810 	r |=	((l & 0x2000) ? O_FSYNC : 0);
811 
812 	if (r & O_CREAT)
813 		SUNOS_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
814 	else
815 		SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
816 
817 	SCARG(uap, flags) = r;
818 	ret = sys_open(p, (struct sys_open_args *)uap, retval);
819 
820 	if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
821 		struct filedesc *fdp = p->p_fd;
822 		struct file *fp = fdp->fd_ofiles[*retval];
823 
824 		/* ignore any error, just give it a try */
825 		if (fp->f_type == DTYPE_VNODE)
826 			(fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p);
827 	}
828 	return ret;
829 }
830 
831 #if defined (NFSSERVER)
832 int
833 sunos_sys_nfssvc(p, v, retval)
834 	struct proc *p;
835 	void *v;
836 	register_t *retval;
837 {
838 #if 0
839 	struct sunos_sys_nfssvc_args *uap = v;
840 	struct emul *e = p->p_emul;
841 	struct sys_nfssvc_args outuap;
842 	struct sockaddr sa;
843 	int error;
844 	caddr_t sg = stackgap_init(p->p_emul);
845 
846 	memset(&outuap, 0, sizeof outuap);
847 	SCARG(&outuap, fd) = SCARG(uap, fd);
848 	SCARG(&outuap, mskval) = stackgap_alloc(&sg, sizeof(sa));
849 	SCARG(&outuap, msklen) = sizeof(sa);
850 	SCARG(&outuap, mtchval) = stackgap_alloc(&sg, sizeof(sa));
851 	SCARG(&outuap, mtchlen) = sizeof(sa);
852 
853 	memset(&sa, 0, sizeof sa);
854 	if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
855 		return (error);
856 	if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
857 		return (error);
858 
859 	return nfssvc(p, &outuap, retval);
860 #else
861 	return (ENOSYS);
862 #endif
863 }
864 #endif /* NFSSERVER */
865 
866 int
867 sunos_sys_ustat(p, v, retval)
868 	struct proc *p;
869 	void *v;
870 	register_t *retval;
871 {
872 	struct sunos_sys_ustat_args *uap = v;
873 	struct sunos_ustat us;
874 	int error;
875 
876 	memset(&us, 0, sizeof us);
877 
878 	/*
879 	 * XXX: should set f_tfree and f_tinode at least
880 	 * How do we translate dev -> fstat? (and then to sunos_ustat)
881 	 */
882 
883 	if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
884 		return (error);
885 	return 0;
886 }
887 
888 int
889 sunos_sys_quotactl(p, v, retval)
890 	struct proc *p;
891 	void *v;
892 	register_t *retval;
893 {
894 
895 	return EINVAL;
896 }
897 
898 int
899 sunos_sys_vhangup(p, v, retval)
900 	struct proc *p;
901 	void *v;
902 	register_t *retval;
903 {
904 	struct session *sp = p->p_session;
905 
906 	if (sp->s_ttyvp == 0)
907 		return 0;
908 
909 	if (sp->s_ttyp && sp->s_ttyp->t_session == sp && sp->s_ttyp->t_pgrp)
910 		pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
911 
912 	(void) ttywait(sp->s_ttyp);
913 	if (sp->s_ttyvp)
914 		VOP_REVOKE(sp->s_ttyvp, REVOKEALL);
915 	if (sp->s_ttyvp)
916 		vrele(sp->s_ttyvp);
917 	sp->s_ttyvp = NULL;
918 
919 	return 0;
920 }
921 
922 static int
923 sunstatfs(sp, buf)
924 	struct statfs *sp;
925 	caddr_t buf;
926 {
927 	struct sunos_statfs ssfs;
928 
929 	memset(&ssfs, 0, sizeof ssfs);
930 	ssfs.f_type = 0;
931 	ssfs.f_bsize = sp->f_bsize;
932 	ssfs.f_blocks = sp->f_blocks;
933 	ssfs.f_bfree = sp->f_bfree;
934 	ssfs.f_bavail = sp->f_bavail;
935 	ssfs.f_files = sp->f_files;
936 	ssfs.f_ffree = sp->f_ffree;
937 	ssfs.f_fsid = sp->f_fsid;
938 	return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
939 }
940 
941 int
942 sunos_sys_statfs(p, v, retval)
943 	struct proc *p;
944 	void *v;
945 	register_t *retval;
946 {
947 	struct sunos_sys_statfs_args *uap = v;
948 	struct mount *mp;
949 	struct statfs *sp;
950 	int error;
951 	struct nameidata nd;
952 
953 	caddr_t sg = stackgap_init(p->p_emul);
954 	SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
955 
956 	NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
957 	if ((error = namei(&nd)) != 0)
958 		return (error);
959 	mp = nd.ni_vp->v_mount;
960 	sp = &mp->mnt_stat;
961 	vrele(nd.ni_vp);
962 	if ((error = VFS_STATFS(mp, sp, p)) != 0)
963 		return (error);
964 	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
965 	return sunstatfs(sp, (caddr_t)SCARG(uap, buf));
966 }
967 
968 int
969 sunos_sys_fstatfs(p, v, retval)
970 	struct proc *p;
971 	void *v;
972 	register_t *retval;
973 {
974 	struct sunos_sys_fstatfs_args *uap = v;
975 	struct file *fp;
976 	struct mount *mp;
977 	struct statfs *sp;
978 	int error;
979 
980 	/* getvnode() will use the descriptor for us */
981 	if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
982 		return (error);
983 	mp = ((struct vnode *)fp->f_data)->v_mount;
984 	sp = &mp->mnt_stat;
985 	if ((error = VFS_STATFS(mp, sp, p)) != 0)
986 		goto out;
987 	sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
988 	error = sunstatfs(sp, (caddr_t)SCARG(uap, buf));
989  out:
990 	FILE_UNUSE(fp, p);
991 	return (error);
992 }
993 
994 int
995 sunos_sys_exportfs(p, v, retval)
996 	struct proc *p;
997 	void *v;
998 	register_t *retval;
999 {
1000 	/*
1001 	 * XXX: should perhaps translate into a mount(2)
1002 	 * with MOUNT_EXPORT?
1003 	 */
1004 	return 0;
1005 }
1006 
1007 int
1008 sunos_sys_mknod(p, v, retval)
1009 	struct proc *p;
1010 	void *v;
1011 	register_t *retval;
1012 {
1013 	struct sunos_sys_mknod_args *uap = v;
1014 
1015 	caddr_t sg = stackgap_init(p->p_emul);
1016 	SUNOS_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
1017 
1018 	if (S_ISFIFO(SCARG(uap, mode)))
1019 		return sys_mkfifo(p, uap, retval);
1020 
1021 	return sys_mknod(p, (struct sys_mknod_args *)uap, retval);
1022 }
1023 
1024 #define SUNOS_SC_ARG_MAX	1
1025 #define SUNOS_SC_CHILD_MAX	2
1026 #define SUNOS_SC_CLK_TCK	3
1027 #define SUNOS_SC_NGROUPS_MAX	4
1028 #define SUNOS_SC_OPEN_MAX	5
1029 #define SUNOS_SC_JOB_CONTROL	6
1030 #define SUNOS_SC_SAVED_IDS	7
1031 #define SUNOS_SC_VERSION	8
1032 
1033 int
1034 sunos_sys_sysconf(p, v, retval)
1035 	struct proc *p;
1036 	void *v;
1037 	register_t *retval;
1038 {
1039 	struct sunos_sys_sysconf_args *uap = v;
1040 	extern int maxfiles;
1041 
1042 	switch(SCARG(uap, name)) {
1043 	case SUNOS_SC_ARG_MAX:
1044 		*retval = ARG_MAX;
1045 		break;
1046 	case SUNOS_SC_CHILD_MAX:
1047 		*retval = maxproc;
1048 		break;
1049 	case SUNOS_SC_CLK_TCK:
1050 		*retval = 60;		/* should this be `hz', ie. 100? */
1051 		break;
1052 	case SUNOS_SC_NGROUPS_MAX:
1053 		*retval = NGROUPS_MAX;
1054 		break;
1055 	case SUNOS_SC_OPEN_MAX:
1056 		*retval = maxfiles;
1057 		break;
1058 	case SUNOS_SC_JOB_CONTROL:
1059 		*retval = 1;
1060 		break;
1061 	case SUNOS_SC_SAVED_IDS:
1062 #ifdef _POSIX_SAVED_IDS
1063 		*retval = 1;
1064 #else
1065 		*retval = 0;
1066 #endif
1067 		break;
1068 	case SUNOS_SC_VERSION:
1069 		*retval = 198808;
1070 		break;
1071 	default:
1072 		return EINVAL;
1073 	}
1074 	return 0;
1075 }
1076 
1077 #define SUNOS_RLIMIT_NOFILE	6	/* Other RLIMIT_* are the same */
1078 #define SUNOS_RLIM_NLIMITS	7
1079 
1080 int
1081 sunos_sys_getrlimit(p, v, retval)
1082 	struct proc *p;
1083 	void *v;
1084 	register_t *retval;
1085 {
1086 	struct sunos_sys_getrlimit_args *uap = v;
1087 
1088 	if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
1089 		return EINVAL;
1090 
1091 	if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
1092 		SCARG(uap, which) = RLIMIT_NOFILE;
1093 
1094 	return compat_43_sys_getrlimit(p, uap, retval);
1095 }
1096 
1097 int
1098 sunos_sys_setrlimit(p, v, retval)
1099 	struct proc *p;
1100 	void *v;
1101 	register_t *retval;
1102 {
1103 	struct sunos_sys_getrlimit_args *uap = v;
1104 
1105 	if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
1106 		return EINVAL;
1107 
1108 	if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
1109 		SCARG(uap, which) = RLIMIT_NOFILE;
1110 
1111 	return compat_43_sys_setrlimit(p, uap, retval);
1112 }
1113 
1114 /* for the m68k machines */
1115 #ifndef PT_GETFPREGS
1116 #define PT_GETFPREGS -1
1117 #endif
1118 #ifndef PT_SETFPREGS
1119 #define PT_SETFPREGS -1
1120 #endif
1121 
1122 static int sreq2breq[] = {
1123 	PT_TRACE_ME,    PT_READ_I,      PT_READ_D,      -1,
1124 	PT_WRITE_I,     PT_WRITE_D,     -1,             PT_CONTINUE,
1125 	PT_KILL,        -1,             PT_ATTACH,      PT_DETACH,
1126 	PT_GETREGS,     PT_SETREGS,     PT_GETFPREGS,   PT_SETFPREGS
1127 };
1128 static int nreqs = sizeof(sreq2breq) / sizeof(sreq2breq[0]);
1129 
1130 int
1131 sunos_sys_ptrace(p, v, retval)
1132 	struct proc *p;
1133 	void *v;
1134 	register_t *retval;
1135 {
1136 	struct sunos_sys_ptrace_args *uap = v;
1137 	struct sys_ptrace_args pa;
1138 	int req;
1139 
1140 	req = SCARG(uap, req);
1141 
1142 	if (req < 0 || req >= nreqs)
1143 		return (EINVAL);
1144 
1145 	req = sreq2breq[req];
1146 	if (req == -1)
1147 		return (EINVAL);
1148 
1149 	SCARG(&pa, req) = req;
1150 	SCARG(&pa, pid) = (pid_t)SCARG(uap, pid);
1151 	SCARG(&pa, addr) = (caddr_t)SCARG(uap, addr);
1152 	SCARG(&pa, data) = SCARG(uap, data);
1153 
1154 	return sys_ptrace(p, &pa, retval);
1155 }
1156 
1157 /*
1158  * SunOS reboot system call (for compatibility).
1159  * Sun lets you pass in a boot string which the PROM
1160  * saves and provides to the next boot program.
1161  */
1162 
1163 #define SUNOS_RB_ASKNAME	0x001
1164 #define SUNOS_RB_SINGLE 	0x002
1165 #define SUNOS_RB_NOSYNC		0x004
1166 #define SUNOS_RB_HALT		0x008
1167 #define SUNOS_RB_DUMP		0x080
1168 #define	SUNOS_RB_STRING		0x200
1169 
1170 static struct sunos_howto_conv {
1171 	int sun_howto;
1172 	int bsd_howto;
1173 } sunos_howto_conv[] = {
1174 	{ SUNOS_RB_ASKNAME,	RB_ASKNAME },
1175 	{ SUNOS_RB_SINGLE,	RB_SINGLE },
1176 	{ SUNOS_RB_NOSYNC,	RB_NOSYNC },
1177 	{ SUNOS_RB_HALT,	RB_HALT },
1178 	{ SUNOS_RB_DUMP,	RB_DUMP },
1179 	{ SUNOS_RB_STRING,	RB_STRING },
1180 	{ 0x000,		0 },
1181 };
1182 
1183 int
1184 sunos_sys_reboot(p, v, retval)
1185 	struct proc *p;
1186 	void *v;
1187 	register_t *retval;
1188 {
1189 	struct sunos_sys_reboot_args *uap = v;
1190 	struct sys_reboot_args ua;
1191 	struct sunos_howto_conv *convp;
1192 	int error, bsd_howto, sun_howto;
1193 	char *bootstr;
1194 
1195 	if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
1196 		return (error);
1197 
1198 	/*
1199 	 * Convert howto bits to BSD format.
1200 	 */
1201 	sun_howto = SCARG(uap, howto);
1202 	bsd_howto = 0;
1203 	convp = sunos_howto_conv;
1204 	while (convp->sun_howto) {
1205 		if (sun_howto & convp->sun_howto)
1206 			bsd_howto |= convp->bsd_howto;
1207 		convp++;
1208 	}
1209 
1210 	/*
1211 	 * Sun RB_STRING (Get user supplied bootstring.)
1212 	 * If the machine supports passing a string to the
1213 	 * next booted kernel.
1214 	 */
1215 	if (sun_howto & SUNOS_RB_STRING) {
1216 		char bs[128];
1217 
1218 		error = copyinstr(SCARG(uap, bootstr), bs, sizeof(bs), 0);
1219 
1220 		if (error)
1221 			bootstr = NULL;
1222 		else
1223 			bootstr = bs;
1224 	} else
1225 		bootstr = NULL;
1226 
1227 	SCARG(&ua, opt) = bsd_howto;
1228 	SCARG(&ua, bootstr) = bootstr;
1229 	sys_reboot(p, &ua, retval);
1230 	return(0);
1231 }
1232 
1233 /*
1234  * Generalized interface signal handler, 4.3-compatible.
1235  */
1236 /* ARGSUSED */
1237 int
1238 sunos_sys_sigvec(p, v, retval)
1239 	struct proc *p;
1240 	void *v;
1241 	register_t *retval;
1242 {
1243 	struct sunos_sys_sigvec_args /* {
1244 		syscallarg(int) signum;
1245 		syscallarg(struct sigvec *) nsv;
1246 		syscallarg(struct sigvec *) osv;
1247 	} */ *uap = v;
1248 	struct sigvec nsv, osv;
1249 	struct sigaction nsa, osa;
1250 	int error;
1251 /*XXX*/extern	void compat_43_sigvec_to_sigaction
1252 		__P((const struct sigvec *, struct sigaction *));
1253 /*XXX*/extern	void compat_43_sigaction_to_sigvec
1254 		__P((const struct sigaction *, struct sigvec *));
1255 
1256 	if (SCARG(uap, nsv)) {
1257 		error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
1258 		if (error != 0)
1259 			return (error);
1260 
1261 		/*
1262 		 * SunOS uses the mask 0x0004 as SV_RESETHAND
1263 		 * meaning: `reset to SIG_DFL on delivery'.
1264 		 * We support only the bits in: 0xF
1265 		 * (those bits are the same as ours)
1266 		 */
1267 		if (nsv.sv_flags & ~0xF)
1268 			return (EINVAL);
1269 
1270 		compat_43_sigvec_to_sigaction(&nsv, &nsa);
1271 	}
1272 	error = sigaction1(p, SCARG(uap, signum),
1273 			   SCARG(uap, nsv) ? &nsa : 0,
1274 			   SCARG(uap, osv) ? &osa : 0);
1275 	if (error != 0)
1276 		return (error);
1277 
1278 	if (SCARG(uap, osv)) {
1279 		compat_43_sigaction_to_sigvec(&osa, &osv);
1280 		error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
1281 		if (error != 0)
1282 			return (error);
1283 	}
1284 
1285 	return (0);
1286 }
1287