2 * Copyright (c) 1998 Mark Newton
3 * Copyright (c) 1994 Christos Zoulas
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
36 #include <sys/filedesc.h>
38 #include <sys/kernel.h>
39 #include <sys/malloc.h>
40 #include <sys/unistd.h>
42 #include <sys/syscallsubr.h>
43 #include <sys/sysctl.h>
44 #include <sys/sysproto.h>
49 #include <netinet/in.h>
51 #include <compat/svr4/svr4.h>
52 #include <compat/svr4/svr4_types.h>
53 #include <compat/svr4/svr4_signal.h>
54 #include <compat/svr4/svr4_proto.h>
55 #include <compat/svr4/svr4_util.h>
56 #include <compat/svr4/svr4_stat.h>
57 #include <compat/svr4/svr4_ustat.h>
58 #include <compat/svr4/svr4_utsname.h>
59 #include <compat/svr4/svr4_systeminfo.h>
60 #include <compat/svr4/svr4_socket.h>
61 #include <compat/svr4/svr4_time.h>
63 #include "svr4_fuser.h"
68 * Solaris-2.4 on the sparc has the old stat call using the new
69 * stat data structure...
71 # define SVR4_NO_OSTAT
74 struct svr4_ustat_args {
76 struct svr4_ustat * name;
79 static void bsd_to_svr4_xstat(struct stat *, struct svr4_xstat *);
80 static void bsd_to_svr4_stat64(struct stat *, struct svr4_stat64 *);
81 int svr4_ustat(struct thread *, struct svr4_ustat_args *);
82 static int svr4_to_bsd_pathconf(int);
85 * SVR4 uses named pipes as named sockets, so we tell programs
86 * that sockets are named pipes with mode 0
88 #define BSD_TO_SVR4_MODE(mode) (S_ISSOCK(mode) ? S_IFIFO : (mode))
92 static void bsd_to_svr4_stat(struct stat *, struct svr4_stat *);
95 bsd_to_svr4_stat(st, st4)
97 struct svr4_stat *st4;
99 memset(st4, 0, sizeof(*st4));
100 st4->st_dev = bsd_to_svr4_odev_t(st->st_dev);
101 st4->st_ino = st->st_ino;
102 st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
103 st4->st_nlink = st->st_nlink;
104 st4->st_uid = st->st_uid;
105 st4->st_gid = st->st_gid;
106 st4->st_rdev = bsd_to_svr4_odev_t(st->st_rdev);
107 st4->st_size = st->st_size;
108 st4->st_atim = st->st_atimespec.tv_sec;
109 st4->st_mtim = st->st_mtimespec.tv_sec;
110 st4->st_ctim = st->st_ctimespec.tv_sec;
116 bsd_to_svr4_xstat(st, st4)
118 struct svr4_xstat *st4;
120 memset(st4, 0, sizeof(*st4));
121 st4->st_dev = bsd_to_svr4_dev_t(st->st_dev);
122 st4->st_ino = st->st_ino;
123 st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
124 st4->st_nlink = st->st_nlink;
125 st4->st_uid = st->st_uid;
126 st4->st_gid = st->st_gid;
127 st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
128 st4->st_size = st->st_size;
129 st4->st_atim = st->st_atimespec;
130 st4->st_mtim = st->st_mtimespec;
131 st4->st_ctim = st->st_ctimespec;
132 st4->st_blksize = st->st_blksize;
133 st4->st_blocks = st->st_blocks;
134 strcpy(st4->st_fstype, "unknown");
139 bsd_to_svr4_stat64(st, st4)
141 struct svr4_stat64 *st4;
143 memset(st4, 0, sizeof(*st4));
144 st4->st_dev = bsd_to_svr4_dev_t(st->st_dev);
145 st4->st_ino = st->st_ino;
146 st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
147 st4->st_nlink = st->st_nlink;
148 st4->st_uid = st->st_uid;
149 st4->st_gid = st->st_gid;
150 st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
151 st4->st_size = st->st_size;
152 st4->st_atim = st->st_atimespec;
153 st4->st_mtim = st->st_mtimespec;
154 st4->st_ctim = st->st_ctimespec;
155 st4->st_blksize = st->st_blksize;
156 st4->st_blocks = st->st_blocks;
157 strcpy(st4->st_fstype, "unknown");
161 svr4_sys_stat(td, uap)
163 struct svr4_sys_stat_args *uap;
165 struct svr4_stat svr4_st;
170 CHECKALTEXIST(td, uap->path, &path);
172 error = kern_stat(td, path, UIO_SYSSPACE, &st);
176 bsd_to_svr4_stat(&st, &svr4_st);
178 if (S_ISSOCK(st.st_mode))
179 (void) svr4_add_socket(td, uap->path, &st);
181 return (copyout(&svr4_st, uap->ub, sizeof svr4_st));
186 svr4_sys_lstat(td, uap)
187 register struct thread *td;
188 struct svr4_sys_lstat_args *uap;
190 struct svr4_stat svr4_st;
195 CHECKALTEXIST(td, uap->path, &path);
197 error = kern_lstat(td, path, UIO_SYSSPACE, &st);
201 bsd_to_svr4_stat(&st, &svr4_st);
203 if (S_ISSOCK(st.st_mode))
204 (void) svr4_add_socket(td, uap->path, &st);
206 return (copyout(&svr4_st, uap->ub, sizeof svr4_st));
211 svr4_sys_fstat(td, uap)
212 register struct thread *td;
213 struct svr4_sys_fstat_args *uap;
215 struct svr4_stat svr4_st;
220 error = kern_fstat(td, uap->fd, &st);
223 bsd_to_svr4_stat(&st, &svr4_st);
224 return (copyout(&svr4_st, uap->sb, sizeof svr4_st));
229 svr4_sys_xstat(td, uap)
230 register struct thread *td;
231 struct svr4_sys_xstat_args *uap;
233 struct svr4_xstat svr4_st;
238 CHECKALTEXIST(td, uap->path, &path);
240 error = kern_stat(td, path, UIO_SYSSPACE, &st);
245 bsd_to_svr4_xstat(&st, &svr4_st);
247 #if defined(SOCKET_NOTYET)
248 if (S_ISSOCK(st.st_mode))
249 (void) svr4_add_socket(td, uap->path, &st);
252 return (copyout(&svr4_st, uap->ub, sizeof svr4_st));
256 svr4_sys_lxstat(td, uap)
257 register struct thread *td;
258 struct svr4_sys_lxstat_args *uap;
260 struct svr4_xstat svr4_st;
265 CHECKALTEXIST(td, uap->path, &path);
267 error = kern_lstat(td, path, UIO_SYSSPACE, &st);
272 bsd_to_svr4_xstat(&st, &svr4_st);
274 #if defined(SOCKET_NOTYET)
275 if (S_ISSOCK(st.st_mode))
276 (void) svr4_add_socket(td, uap->path, &st);
278 return (copyout(&svr4_st, uap->ub, sizeof svr4_st));
283 svr4_sys_fxstat(td, uap)
284 register struct thread *td;
285 struct svr4_sys_fxstat_args *uap;
287 struct svr4_xstat svr4_st;
292 error = kern_fstat(td, uap->fd, &st);
295 bsd_to_svr4_xstat(&st, &svr4_st);
296 return (copyout(&svr4_st, uap->sb, sizeof svr4_st));
300 svr4_sys_stat64(td, uap)
301 register struct thread *td;
302 struct svr4_sys_stat64_args *uap;
304 struct svr4_stat64 svr4_st;
309 CHECKALTEXIST(td, uap->path, &path);
311 error = kern_stat(td, path, UIO_SYSSPACE, &st);
316 bsd_to_svr4_stat64(&st, &svr4_st);
318 if (S_ISSOCK(st.st_mode))
319 (void) svr4_add_socket(td, uap->path, &st);
321 return (copyout(&svr4_st, uap->sb, sizeof svr4_st));
326 svr4_sys_lstat64(td, uap)
327 register struct thread *td;
328 struct svr4_sys_lstat64_args *uap;
330 struct svr4_stat64 svr4_st;
335 CHECKALTEXIST(td, uap->path, &path);
337 error = kern_lstat(td, path, UIO_SYSSPACE, &st);
342 bsd_to_svr4_stat64(&st, &svr4_st);
344 if (S_ISSOCK(st.st_mode))
345 (void) svr4_add_socket(td, uap->path, &st);
347 return (copyout(&svr4_st, uap->sb, sizeof svr4_st));
352 svr4_sys_fstat64(td, uap)
353 register struct thread *td;
354 struct svr4_sys_fstat64_args *uap;
356 struct svr4_stat64 svr4_st;
360 error = kern_fstat(td, uap->fd, &st);
363 bsd_to_svr4_stat64(&st, &svr4_st);
364 return (copyout(&svr4_st, uap->sb, sizeof svr4_st));
370 register struct thread *td;
371 struct svr4_ustat_args *uap;
373 struct svr4_ustat us;
376 memset(&us, 0, sizeof us);
379 * XXX: should set f_tfree and f_tinode at least
380 * How do we translate dev -> fstat? (and then to svr4_ustat)
382 if ((error = copyout(&us, uap->name, sizeof us)) != 0)
388 /*extern char ostype[], hostname[], osrelease[], version[], machine[];*/
391 svr4_sys_uname(td, uap)
392 register struct thread *td;
393 struct svr4_sys_uname_args *uap;
395 struct svr4_utsname sut;
397 memset(&sut, 0, sizeof(sut));
399 strlcpy(sut.sysname, ostype, sizeof(sut.sysname));
400 getcredhostname(td->td_ucred, sut.nodename, sizeof(sut.nodename));
401 strlcpy(sut.release, osrelease, sizeof(sut.release));
402 strlcpy(sut.version, version, sizeof(sut.version));
403 strlcpy(sut.machine, machine, sizeof(sut.machine));
405 return copyout((caddr_t) &sut, (caddr_t) uap->name,
406 sizeof(struct svr4_utsname));
410 svr4_sys_systeminfo(td, uap)
412 struct svr4_sys_systeminfo_args *uap;
416 register_t *retval = td->td_retval;
418 char buf[1]; /* XXX NetBSD uses 256, but that seems
419 like awfully excessive kstack usage
420 for an empty string... */
421 u_int rlen = uap->len;
424 case SVR4_SI_SYSNAME:
428 case SVR4_SI_HOSTNAME:
432 case SVR4_SI_RELEASE:
436 case SVR4_SI_VERSION:
440 case SVR4_SI_MACHINE:
444 case SVR4_SI_ARCHITECTURE:
448 case SVR4_SI_HW_SERIAL:
452 case SVR4_SI_HW_PROVIDER:
456 case SVR4_SI_SRPC_DOMAIN:
460 case SVR4_SI_PLATFORM:
468 case SVR4_SI_KERB_REALM:
471 #if defined(WHY_DOES_AN_EMULATOR_WANT_TO_SET_HOSTNAMES)
472 case SVR4_SI_SET_HOSTNAME:
473 name = KERN_HOSTNAME;
474 return kern_sysctl(&name, 1, 0, 0, uap->buf, rlen, td);
476 case SVR4_SI_SET_SRPC_DOMAIN:
477 name = KERN_NISDOMAINNAME;
478 return kern_sysctl(&name, 1, 0, 0, uap->buf, rlen, td);
480 case SVR4_SI_SET_HOSTNAME:
481 case SVR4_SI_SET_SRPC_DOMAIN:
484 case SVR4_SI_SET_KERB_REALM:
488 DPRINTF(("Bad systeminfo command %d\n", uap->what));
493 len = strlen(str) + 1;
498 error = copyout(str, uap->buf, len);
501 /* make sure we are NULL terminated */
503 error = copyout(buf, &(uap->buf[len - 1]), 1);
508 /* XXX NetBSD has hostname setting stuff here. Why would an emulator
516 svr4_sys_utssys(td, uap)
517 register struct thread *td;
518 struct svr4_sys_utssys_args *uap;
521 case 0: /* uname(2) */
523 struct svr4_sys_uname_args ua;
525 return svr4_sys_uname(td, &ua);
528 case 2: /* ustat(2) */
530 struct svr4_ustat_args ua;
531 ua.dev = (svr4_dev_t) uap->a2;
533 return svr4_ustat(td, &ua);
536 case 3: /* fusers(2) */
547 svr4_sys_utime(td, uap)
548 register struct thread *td;
549 struct svr4_sys_utime_args *uap;
551 struct svr4_utimbuf ub;
552 struct timeval tbuf[2], *tp;
556 if (uap->ubuf != NULL) {
557 error = copyin(uap->ubuf, &ub, sizeof(ub));
560 tbuf[0].tv_sec = ub.actime;
562 tbuf[1].tv_sec = ub.modtime;
568 CHECKALTEXIST(td, uap->path, &path);
569 error = kern_utimes(td, path, UIO_SYSSPACE, tp, UIO_SYSSPACE);
576 svr4_sys_utimes(td, uap)
577 register struct thread *td;
578 struct svr4_sys_utimes_args *uap;
583 CHECKALTEXIST(td, uap->path, &path);
584 error = kern_utimes(td, path, UIO_SYSSPACE, uap->tptr, UIO_USERSPACE);
590 svr4_to_bsd_pathconf(name)
594 case SVR4_PC_LINK_MAX:
597 case SVR4_PC_MAX_CANON:
598 return _PC_MAX_CANON;
600 case SVR4_PC_MAX_INPUT:
601 return _PC_MAX_INPUT;
603 case SVR4_PC_NAME_MAX:
606 case SVR4_PC_PATH_MAX:
609 case SVR4_PC_PIPE_BUF:
612 case SVR4_PC_NO_TRUNC:
615 case SVR4_PC_VDISABLE:
618 case SVR4_PC_CHOWN_RESTRICTED:
619 return _PC_CHOWN_RESTRICTED;
620 case SVR4_PC_SYNC_IO:
621 #if defined(_PC_SYNC_IO)
626 case SVR4_PC_ASYNC_IO:
627 case SVR4_PC_PRIO_IO:
639 svr4_sys_pathconf(td, uap)
640 register struct thread *td;
641 struct svr4_sys_pathconf_args *uap;
646 name = svr4_to_bsd_pathconf(uap->name);
650 td->td_retval[0] = -1;
653 td->td_retval[0] = 0;
656 CHECKALTEXIST(td, uap->path, &path);
657 error = kern_pathconf(td, path, UIO_SYSSPACE, name);
665 svr4_sys_fpathconf(td, uap)
666 register struct thread *td;
667 struct svr4_sys_fpathconf_args *uap;
669 register_t *retval = td->td_retval;
671 uap->name = svr4_to_bsd_pathconf(uap->name);
681 return fpathconf(td, (struct fpathconf_args *)uap);