Deleted Added
full compact
svr4_stat.c (107849) svr4_stat.c (115550)
1/*
2 * Copyright (c) 1998 Mark Newton
3 * Copyright (c) 1994 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. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
16 *
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.
27 *
1/*
2 * Copyright (c) 1998 Mark Newton
3 * Copyright (c) 1994 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. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
16 *
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.
27 *
28 * $FreeBSD: head/sys/compat/svr4/svr4_stat.c 107849 2002-12-14 01:56:26Z alfred $
28 * $FreeBSD: head/sys/compat/svr4/svr4_stat.c 115550 2003-05-31 20:33:18Z phk $
29 */
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/proc.h>
34#include <sys/stat.h>
35#include <sys/filedesc.h>
36#include <sys/jail.h>
37#include <sys/kernel.h>
38#include <sys/unistd.h>
39#include <sys/time.h>
40#include <sys/sysctl.h>
41#include <sys/sysproto.h>
29 */
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/proc.h>
34#include <sys/stat.h>
35#include <sys/filedesc.h>
36#include <sys/jail.h>
37#include <sys/kernel.h>
38#include <sys/unistd.h>
39#include <sys/time.h>
40#include <sys/sysctl.h>
41#include <sys/sysproto.h>
42#include <sys/un.h>
42
43#include <vm/vm.h>
44
45#include <netinet/in.h>
46
47#include <compat/svr4/svr4.h>
48#include <compat/svr4/svr4_types.h>
49#include <compat/svr4/svr4_signal.h>
50#include <compat/svr4/svr4_proto.h>
51#include <compat/svr4/svr4_util.h>
52#include <compat/svr4/svr4_stat.h>
53#include <compat/svr4/svr4_ustat.h>
54#include <compat/svr4/svr4_utsname.h>
55#include <compat/svr4/svr4_systeminfo.h>
56#include <compat/svr4/svr4_socket.h>
57#include <compat/svr4/svr4_time.h>
58#if defined(NOTYET)
59#include "svr4_fuser.h"
60#endif
61
62#ifdef sparc
63/*
64 * Solaris-2.4 on the sparc has the old stat call using the new
65 * stat data structure...
66 */
67# define SVR4_NO_OSTAT
68#endif
69
70struct svr4_ustat_args {
71 svr4_dev_t dev;
72 struct svr4_ustat * name;
73};
74
75static void bsd_to_svr4_xstat(struct stat *, struct svr4_xstat *);
76static void bsd_to_svr4_stat64(struct stat *, struct svr4_stat64 *);
77int svr4_ustat(struct thread *, struct svr4_ustat_args *);
78static int svr4_to_bsd_pathconf(int);
79
80/*
81 * SVR4 uses named pipes as named sockets, so we tell programs
82 * that sockets are named pipes with mode 0
83 */
84#define BSD_TO_SVR4_MODE(mode) (S_ISSOCK(mode) ? S_IFIFO : (mode))
85
86
87#ifndef SVR4_NO_OSTAT
88static void bsd_to_svr4_stat(struct stat *, struct svr4_stat *);
89
90static void
91bsd_to_svr4_stat(st, st4)
92 struct stat *st;
93 struct svr4_stat *st4;
94{
95 memset(st4, 0, sizeof(*st4));
96 st4->st_dev = bsd_to_svr4_odev_t(st->st_dev);
97 st4->st_ino = st->st_ino;
98 st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
99 st4->st_nlink = st->st_nlink;
100 st4->st_uid = st->st_uid;
101 st4->st_gid = st->st_gid;
102 st4->st_rdev = bsd_to_svr4_odev_t(st->st_rdev);
103 st4->st_size = st->st_size;
104 st4->st_atim = st->st_atimespec.tv_sec;
105 st4->st_mtim = st->st_mtimespec.tv_sec;
106 st4->st_ctim = st->st_ctimespec.tv_sec;
107}
108#endif
109
110
111static void
112bsd_to_svr4_xstat(st, st4)
113 struct stat *st;
114 struct svr4_xstat *st4;
115{
116 memset(st4, 0, sizeof(*st4));
117 st4->st_dev = bsd_to_svr4_dev_t(st->st_dev);
118 st4->st_ino = st->st_ino;
119 st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
120 st4->st_nlink = st->st_nlink;
121 st4->st_uid = st->st_uid;
122 st4->st_gid = st->st_gid;
123 st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
124 st4->st_size = st->st_size;
125 st4->st_atim = st->st_atimespec;
126 st4->st_mtim = st->st_mtimespec;
127 st4->st_ctim = st->st_ctimespec;
128 st4->st_blksize = st->st_blksize;
129 st4->st_blocks = st->st_blocks;
130 strcpy(st4->st_fstype, "unknown");
131}
132
133
134static void
135bsd_to_svr4_stat64(st, st4)
136 struct stat *st;
137 struct svr4_stat64 *st4;
138{
139 memset(st4, 0, sizeof(*st4));
140 st4->st_dev = bsd_to_svr4_dev_t(st->st_dev);
141 st4->st_ino = st->st_ino;
142 st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
143 st4->st_nlink = st->st_nlink;
144 st4->st_uid = st->st_uid;
145 st4->st_gid = st->st_gid;
146 st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
147 st4->st_size = st->st_size;
148 st4->st_atim = st->st_atimespec;
149 st4->st_mtim = st->st_mtimespec;
150 st4->st_ctim = st->st_ctimespec;
151 st4->st_blksize = st->st_blksize;
152 st4->st_blocks = st->st_blocks;
153 strcpy(st4->st_fstype, "unknown");
154}
155
156int
157svr4_sys_stat(td, uap)
158 struct thread *td;
159 struct svr4_sys_stat_args *uap;
160{
161 struct stat st;
162 struct svr4_stat svr4_st;
163 struct stat_args cup;
164 int error;
165 caddr_t sg = stackgap_init();
166
167 CHECKALTEXIST(td, &sg, uap->path);
168
169 cup.path = uap->path;
170 cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
171
172
173 if ((error = stat(td, &cup)) != 0)
174 return error;
175
176 if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
177 return error;
178
179 bsd_to_svr4_stat(&st, &svr4_st);
180
181 if (S_ISSOCK(st.st_mode))
182 (void) svr4_add_socket(td, uap->path, &st);
183
184 if ((error = copyout(&svr4_st, uap->ub, sizeof svr4_st)) != 0)
185 return error;
186
187 return 0;
188}
189
190
191int
192svr4_sys_lstat(td, uap)
193 register struct thread *td;
194 struct svr4_sys_lstat_args *uap;
195{
196 struct stat st;
197 struct svr4_stat svr4_st;
198 struct lstat_args cup;
199 int error;
200 caddr_t sg = stackgap_init();
201
202 CHECKALTEXIST(td, &sg, uap->path);
203
204 cup.path = uap->path;
205 cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
206
207 if ((error = lstat(td, &cup)) != 0)
208 return error;
209
210 if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
211 return error;
212
213 bsd_to_svr4_stat(&st, &svr4_st);
214
215 if (S_ISSOCK(st.st_mode))
216 (void) svr4_add_socket(td, uap->path, &st);
217
218 if ((error = copyout(&svr4_st, uap->ub, sizeof svr4_st)) != 0)
219 return error;
220
221 return 0;
222}
223
224
225int
226svr4_sys_fstat(td, uap)
227 register struct thread *td;
228 struct svr4_sys_fstat_args *uap;
229{
230 struct stat st;
231 struct svr4_stat svr4_st;
232 struct fstat_args cup;
233 int error;
234 caddr_t sg = stackgap_init();
235
236 cup.fd = uap->fd;
237 cup.sb = stackgap_alloc(&sg, sizeof(struct stat));
238
239 if ((error = fstat(td, &cup)) != 0)
240 return error;
241
242 if ((error = copyin(cup.sb, &st, sizeof st)) != 0)
243 return error;
244
245 bsd_to_svr4_stat(&st, &svr4_st);
246
247 if ((error = copyout(&svr4_st, uap->sb, sizeof svr4_st)) != 0)
248 return error;
249
250 return 0;
251}
252
253
254int
255svr4_sys_xstat(td, uap)
256 register struct thread *td;
257 struct svr4_sys_xstat_args *uap;
258{
259 struct stat st;
260 struct svr4_xstat svr4_st;
261 struct stat_args cup;
262 int error;
263
264 caddr_t sg = stackgap_init();
265 CHECKALTEXIST(td, &sg, uap->path);
266
267 cup.path = uap->path;
268 cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
269
270 if ((error = stat(td, &cup)) != 0)
271 return error;
272
273 if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
274 return error;
275
276 bsd_to_svr4_xstat(&st, &svr4_st);
277
278#if defined(SOCKET_NOTYET)
279 if (S_ISSOCK(st.st_mode))
280 (void) svr4_add_socket(td, uap->path, &st);
281#endif
282
283 if ((error = copyout(&svr4_st, uap->ub, sizeof svr4_st)) != 0)
284 return error;
285
286 return 0;
287}
288
289int
290svr4_sys_lxstat(td, uap)
291 register struct thread *td;
292 struct svr4_sys_lxstat_args *uap;
293{
294 struct stat st;
295 struct svr4_xstat svr4_st;
296 struct lstat_args cup;
297 int error;
298 caddr_t sg = stackgap_init();
299 CHECKALTEXIST(td, &sg, uap->path);
300
301 cup.path = uap->path;
302 cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
303
304 if ((error = lstat(td, &cup)) != 0)
305 return error;
306
307 if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
308 return error;
309
310 bsd_to_svr4_xstat(&st, &svr4_st);
311
312#if defined(SOCKET_NOTYET)
313 if (S_ISSOCK(st.st_mode))
314 (void) svr4_add_socket(td, uap->path, &st);
315#endif
316 if ((error = copyout(&svr4_st, uap->ub, sizeof svr4_st)) != 0)
317 return error;
318
319 return 0;
320}
321
322
323int
324svr4_sys_fxstat(td, uap)
325 register struct thread *td;
326 struct svr4_sys_fxstat_args *uap;
327{
328 struct stat st;
329 struct svr4_xstat svr4_st;
330 struct fstat_args cup;
331 int error;
332
333 caddr_t sg = stackgap_init();
334
335 cup.fd = uap->fd;
336 cup.sb = stackgap_alloc(&sg, sizeof(struct stat));
337
338 if ((error = fstat(td, &cup)) != 0)
339 return error;
340
341 if ((error = copyin(cup.sb, &st, sizeof st)) != 0)
342 return error;
343
344 bsd_to_svr4_xstat(&st, &svr4_st);
345
346 if ((error = copyout(&svr4_st, uap->sb, sizeof svr4_st)) != 0)
347 return error;
348
349 return 0;
350}
351
352int
353svr4_sys_stat64(td, uap)
354 register struct thread *td;
355 struct svr4_sys_stat64_args *uap;
356{
357 struct stat st;
358 struct svr4_stat64 svr4_st;
359 struct stat_args cup;
360 int error;
361 caddr_t sg = stackgap_init();
362
363 CHECKALTEXIST(td, &sg, uap->path);
364
365 cup.path = uap->path;
366 cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
367
368 if ((error = stat(td, &cup)) != 0)
369 return error;
370
371 if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
372 return error;
373
374 bsd_to_svr4_stat64(&st, &svr4_st);
375
376 if (S_ISSOCK(st.st_mode))
377 (void) svr4_add_socket(td, uap->path, &st);
378
379 if ((error = copyout(&svr4_st, uap->sb, sizeof svr4_st)) != 0)
380 return error;
381
382 return 0;
383}
384
385
386int
387svr4_sys_lstat64(td, uap)
388 register struct thread *td;
389 struct svr4_sys_lstat64_args *uap;
390{
391 struct stat st;
392 struct svr4_stat64 svr4_st;
393 struct stat_args cup;
394 int error;
395 caddr_t sg = stackgap_init();
396
397 CHECKALTEXIST(td, &sg, (char *) uap->path);
398
399 cup.path = uap->path;
400 cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
401
402 if ((error = lstat(td, (struct lstat_args *)&cup)) != 0)
403 return error;
404
405 if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
406 return error;
407
408 bsd_to_svr4_stat64(&st, &svr4_st);
409
410 if (S_ISSOCK(st.st_mode))
411 (void) svr4_add_socket(td, uap->path, &st);
412
413 if ((error = copyout(&svr4_st, uap->sb, sizeof svr4_st)) != 0)
414 return error;
415
416 return 0;
417}
418
419
420int
421svr4_sys_fstat64(td, uap)
422 register struct thread *td;
423 struct svr4_sys_fstat64_args *uap;
424{
425 struct stat st;
426 struct svr4_stat64 svr4_st;
427 struct fstat_args cup;
428 int error;
429 caddr_t sg = stackgap_init();
430
431 cup.fd = uap->fd;
432 cup.sb = stackgap_alloc(&sg, sizeof(struct stat));
433
434 if ((error = fstat(td, &cup)) != 0)
435 return error;
436
437 if ((error = copyin(cup.sb, &st, sizeof st)) != 0)
438 return error;
439
440 bsd_to_svr4_stat64(&st, &svr4_st);
441
442 if ((error = copyout(&svr4_st, uap->sb, sizeof svr4_st)) != 0)
443 return error;
444
445 return 0;
446}
447
448
449int
450svr4_ustat(td, uap)
451 register struct thread *td;
452 struct svr4_ustat_args *uap;
453{
454 struct svr4_ustat us;
455 int error;
456
457 memset(&us, 0, sizeof us);
458
459 /*
460 * XXX: should set f_tfree and f_tinode at least
461 * How do we translate dev -> fstat? (and then to svr4_ustat)
462 */
463 if ((error = copyout(&us, uap->name, sizeof us)) != 0)
464 return (error);
465
466 return 0;
467}
468
469/*extern char ostype[], hostname[], osrelease[], version[], machine[];*/
470
471int
472svr4_sys_uname(td, uap)
473 register struct thread *td;
474 struct svr4_sys_uname_args *uap;
475{
476 struct svr4_utsname sut;
477
478 memset(&sut, 0, sizeof(sut));
479
480 strlcpy(sut.sysname, ostype, sizeof(sut.sysname));
481 getcredhostname(td->td_ucred, sut.nodename, sizeof(sut.nodename));
482 strlcpy(sut.release, osrelease, sizeof(sut.release));
483 strlcpy(sut.version, version, sizeof(sut.version));
484 strlcpy(sut.machine, machine, sizeof(sut.machine));
485
486 return copyout((caddr_t) &sut, (caddr_t) uap->name,
487 sizeof(struct svr4_utsname));
488}
489
490int
491svr4_sys_systeminfo(td, uap)
492 struct thread *td;
493 struct svr4_sys_systeminfo_args *uap;
494{
495 char *str = NULL;
496 int error = 0;
497 register_t *retval = td->td_retval;
498 size_t len = 0;
499 char buf[1]; /* XXX NetBSD uses 256, but that seems
500 like awfully excessive kstack usage
501 for an empty string... */
502 u_int rlen = uap->len;
503
504 switch (uap->what) {
505 case SVR4_SI_SYSNAME:
506 str = ostype;
507 break;
508
509 case SVR4_SI_HOSTNAME:
510 str = hostname;
511 break;
512
513 case SVR4_SI_RELEASE:
514 str = osrelease;
515 break;
516
517 case SVR4_SI_VERSION:
518 str = version;
519 break;
520
521 case SVR4_SI_MACHINE:
522 str = machine;
523 break;
524
525 case SVR4_SI_ARCHITECTURE:
526 str = machine;
527 break;
528
529 case SVR4_SI_HW_SERIAL:
530 str = "0";
531 break;
532
533 case SVR4_SI_HW_PROVIDER:
534 str = ostype;
535 break;
536
537 case SVR4_SI_SRPC_DOMAIN:
538 str = domainname;
539 break;
540
541 case SVR4_SI_PLATFORM:
542#ifdef __i386__
543 str = "i86pc";
544#else
545 str = "unknown";
546#endif
547 break;
548
549 case SVR4_SI_KERB_REALM:
550 str = "unsupported";
551 break;
552#if defined(WHY_DOES_AN_EMULATOR_WANT_TO_SET_HOSTNAMES)
553 case SVR4_SI_SET_HOSTNAME:
554 if ((error = suser(td)) != 0)
555 return error;
556 name = KERN_HOSTNAME;
557 return kern_sysctl(&name, 1, 0, 0, uap->buf, rlen, td);
558
559 case SVR4_SI_SET_SRPC_DOMAIN:
560 if ((error = suser(td)) != 0)
561 return error;
562 name = KERN_NISDOMAINNAME;
563 return kern_sysctl(&name, 1, 0, 0, uap->buf, rlen, td);
564#else
565 case SVR4_SI_SET_HOSTNAME:
566 case SVR4_SI_SET_SRPC_DOMAIN:
567 /* FALLTHROUGH */
568#endif
569 case SVR4_SI_SET_KERB_REALM:
570 return 0;
571
572 default:
573 DPRINTF(("Bad systeminfo command %d\n", uap->what));
574 return ENOSYS;
575 }
576
577 if (str) {
578 len = strlen(str) + 1;
579 if (len > rlen)
580 len = rlen;
581
582 if (uap->buf) {
583 error = copyout(str, uap->buf, len);
584 if (error)
585 return error;
586 /* make sure we are NULL terminated */
587 buf[0] = '\0';
588 error = copyout(buf, &(uap->buf[len - 1]), 1);
589 }
590 else
591 error = 0;
592 }
593 /* XXX NetBSD has hostname setting stuff here. Why would an emulator
594 want to do that? */
595
596 *retval = len;
597 return error;
598}
599
600int
601svr4_sys_utssys(td, uap)
602 register struct thread *td;
603 struct svr4_sys_utssys_args *uap;
604{
605 switch (uap->sel) {
606 case 0: /* uname(2) */
607 {
608 struct svr4_sys_uname_args ua;
609 ua.name = uap->a1;
610 return svr4_sys_uname(td, &ua);
611 }
612
613 case 2: /* ustat(2) */
614 {
615 struct svr4_ustat_args ua;
616 ua.dev = (svr4_dev_t) uap->a2;
617 ua.name = uap->a1;
618 return svr4_ustat(td, &ua);
619 }
620
621 case 3: /* fusers(2) */
622 return ENOSYS;
623
624 default:
625 return ENOSYS;
626 }
627 return ENOSYS;
628}
629
630
631int
632svr4_sys_utime(td, uap)
633 register struct thread *td;
634 struct svr4_sys_utime_args *uap;
635{
636 struct svr4_utimbuf ub;
637 struct timeval tbuf[2];
638 struct utimes_args ap;
639 int error;
640 caddr_t sg = stackgap_init();
641 void *ttp;
642
643 CHECKALTEXIST(td, &sg, uap->path);
644 ap.path = uap->path;
645 if (uap->ubuf != NULL) {
646 if ((error = copyin(uap->ubuf, &ub, sizeof(ub))) != 0)
647 return error;
648 tbuf[0].tv_sec = ub.actime;
649 tbuf[0].tv_usec = 0;
650 tbuf[1].tv_sec = ub.modtime;
651 tbuf[1].tv_usec = 0;
652 ttp = stackgap_alloc(&sg, sizeof(tbuf));
653 error = copyout(tbuf, ttp, sizeof(tbuf));
654 if (error)
655 return error;
656 ap.tptr = ttp;
657 }
658 else
659 ap.tptr = NULL;
660 return utimes(td, &ap);
661}
662
663
664int
665svr4_sys_utimes(td, uap)
666 register struct thread *td;
667 struct svr4_sys_utimes_args *uap;
668{
669 caddr_t sg = stackgap_init();
670 CHECKALTEXIST(td, &sg, uap->path);
671 return utimes(td, (struct utimes_args *)uap);
672}
673
674static int
675svr4_to_bsd_pathconf(name)
676 int name;
677{
678 switch (name) {
679 case SVR4_PC_LINK_MAX:
680 return _PC_LINK_MAX;
681
682 case SVR4_PC_MAX_CANON:
683 return _PC_MAX_CANON;
684
685 case SVR4_PC_MAX_INPUT:
686 return _PC_MAX_INPUT;
687
688 case SVR4_PC_NAME_MAX:
689 return _PC_NAME_MAX;
690
691 case SVR4_PC_PATH_MAX:
692 return _PC_PATH_MAX;
693
694 case SVR4_PC_PIPE_BUF:
695 return _PC_PIPE_BUF;
696
697 case SVR4_PC_NO_TRUNC:
698 return _PC_NO_TRUNC;
699
700 case SVR4_PC_VDISABLE:
701 return _PC_VDISABLE;
702
703 case SVR4_PC_CHOWN_RESTRICTED:
704 return _PC_CHOWN_RESTRICTED;
705 case SVR4_PC_SYNC_IO:
706#if defined(_PC_SYNC_IO)
707 return _PC_SYNC_IO;
708#else
709 return 0;
710#endif
711 case SVR4_PC_ASYNC_IO:
712 case SVR4_PC_PRIO_IO:
713 /* Not supported */
714 return 0;
715
716 default:
717 /* Invalid */
718 return -1;
719 }
720}
721
722
723int
724svr4_sys_pathconf(td, uap)
725 register struct thread *td;
726 struct svr4_sys_pathconf_args *uap;
727{
728 caddr_t sg = stackgap_init();
729 register_t *retval = td->td_retval;
730
731 CHECKALTEXIST(td, &sg, uap->path);
732
733 uap->name = svr4_to_bsd_pathconf(uap->name);
734
735 switch (uap->name) {
736 case -1:
737 *retval = -1;
738 return EINVAL;
739 case 0:
740 *retval = 0;
741 return 0;
742 default:
743 return pathconf(td, (struct pathconf_args *)uap);
744 }
745}
746
747
748int
749svr4_sys_fpathconf(td, uap)
750 register struct thread *td;
751 struct svr4_sys_fpathconf_args *uap;
752{
753 register_t *retval = td->td_retval;
754
755 uap->name = svr4_to_bsd_pathconf(uap->name);
756
757 switch (uap->name) {
758 case -1:
759 *retval = -1;
760 return EINVAL;
761 case 0:
762 *retval = 0;
763 return 0;
764 default:
765 return fpathconf(td, (struct fpathconf_args *)uap);
766 }
767}
43
44#include <vm/vm.h>
45
46#include <netinet/in.h>
47
48#include <compat/svr4/svr4.h>
49#include <compat/svr4/svr4_types.h>
50#include <compat/svr4/svr4_signal.h>
51#include <compat/svr4/svr4_proto.h>
52#include <compat/svr4/svr4_util.h>
53#include <compat/svr4/svr4_stat.h>
54#include <compat/svr4/svr4_ustat.h>
55#include <compat/svr4/svr4_utsname.h>
56#include <compat/svr4/svr4_systeminfo.h>
57#include <compat/svr4/svr4_socket.h>
58#include <compat/svr4/svr4_time.h>
59#if defined(NOTYET)
60#include "svr4_fuser.h"
61#endif
62
63#ifdef sparc
64/*
65 * Solaris-2.4 on the sparc has the old stat call using the new
66 * stat data structure...
67 */
68# define SVR4_NO_OSTAT
69#endif
70
71struct svr4_ustat_args {
72 svr4_dev_t dev;
73 struct svr4_ustat * name;
74};
75
76static void bsd_to_svr4_xstat(struct stat *, struct svr4_xstat *);
77static void bsd_to_svr4_stat64(struct stat *, struct svr4_stat64 *);
78int svr4_ustat(struct thread *, struct svr4_ustat_args *);
79static int svr4_to_bsd_pathconf(int);
80
81/*
82 * SVR4 uses named pipes as named sockets, so we tell programs
83 * that sockets are named pipes with mode 0
84 */
85#define BSD_TO_SVR4_MODE(mode) (S_ISSOCK(mode) ? S_IFIFO : (mode))
86
87
88#ifndef SVR4_NO_OSTAT
89static void bsd_to_svr4_stat(struct stat *, struct svr4_stat *);
90
91static void
92bsd_to_svr4_stat(st, st4)
93 struct stat *st;
94 struct svr4_stat *st4;
95{
96 memset(st4, 0, sizeof(*st4));
97 st4->st_dev = bsd_to_svr4_odev_t(st->st_dev);
98 st4->st_ino = st->st_ino;
99 st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
100 st4->st_nlink = st->st_nlink;
101 st4->st_uid = st->st_uid;
102 st4->st_gid = st->st_gid;
103 st4->st_rdev = bsd_to_svr4_odev_t(st->st_rdev);
104 st4->st_size = st->st_size;
105 st4->st_atim = st->st_atimespec.tv_sec;
106 st4->st_mtim = st->st_mtimespec.tv_sec;
107 st4->st_ctim = st->st_ctimespec.tv_sec;
108}
109#endif
110
111
112static void
113bsd_to_svr4_xstat(st, st4)
114 struct stat *st;
115 struct svr4_xstat *st4;
116{
117 memset(st4, 0, sizeof(*st4));
118 st4->st_dev = bsd_to_svr4_dev_t(st->st_dev);
119 st4->st_ino = st->st_ino;
120 st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
121 st4->st_nlink = st->st_nlink;
122 st4->st_uid = st->st_uid;
123 st4->st_gid = st->st_gid;
124 st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
125 st4->st_size = st->st_size;
126 st4->st_atim = st->st_atimespec;
127 st4->st_mtim = st->st_mtimespec;
128 st4->st_ctim = st->st_ctimespec;
129 st4->st_blksize = st->st_blksize;
130 st4->st_blocks = st->st_blocks;
131 strcpy(st4->st_fstype, "unknown");
132}
133
134
135static void
136bsd_to_svr4_stat64(st, st4)
137 struct stat *st;
138 struct svr4_stat64 *st4;
139{
140 memset(st4, 0, sizeof(*st4));
141 st4->st_dev = bsd_to_svr4_dev_t(st->st_dev);
142 st4->st_ino = st->st_ino;
143 st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
144 st4->st_nlink = st->st_nlink;
145 st4->st_uid = st->st_uid;
146 st4->st_gid = st->st_gid;
147 st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
148 st4->st_size = st->st_size;
149 st4->st_atim = st->st_atimespec;
150 st4->st_mtim = st->st_mtimespec;
151 st4->st_ctim = st->st_ctimespec;
152 st4->st_blksize = st->st_blksize;
153 st4->st_blocks = st->st_blocks;
154 strcpy(st4->st_fstype, "unknown");
155}
156
157int
158svr4_sys_stat(td, uap)
159 struct thread *td;
160 struct svr4_sys_stat_args *uap;
161{
162 struct stat st;
163 struct svr4_stat svr4_st;
164 struct stat_args cup;
165 int error;
166 caddr_t sg = stackgap_init();
167
168 CHECKALTEXIST(td, &sg, uap->path);
169
170 cup.path = uap->path;
171 cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
172
173
174 if ((error = stat(td, &cup)) != 0)
175 return error;
176
177 if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
178 return error;
179
180 bsd_to_svr4_stat(&st, &svr4_st);
181
182 if (S_ISSOCK(st.st_mode))
183 (void) svr4_add_socket(td, uap->path, &st);
184
185 if ((error = copyout(&svr4_st, uap->ub, sizeof svr4_st)) != 0)
186 return error;
187
188 return 0;
189}
190
191
192int
193svr4_sys_lstat(td, uap)
194 register struct thread *td;
195 struct svr4_sys_lstat_args *uap;
196{
197 struct stat st;
198 struct svr4_stat svr4_st;
199 struct lstat_args cup;
200 int error;
201 caddr_t sg = stackgap_init();
202
203 CHECKALTEXIST(td, &sg, uap->path);
204
205 cup.path = uap->path;
206 cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
207
208 if ((error = lstat(td, &cup)) != 0)
209 return error;
210
211 if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
212 return error;
213
214 bsd_to_svr4_stat(&st, &svr4_st);
215
216 if (S_ISSOCK(st.st_mode))
217 (void) svr4_add_socket(td, uap->path, &st);
218
219 if ((error = copyout(&svr4_st, uap->ub, sizeof svr4_st)) != 0)
220 return error;
221
222 return 0;
223}
224
225
226int
227svr4_sys_fstat(td, uap)
228 register struct thread *td;
229 struct svr4_sys_fstat_args *uap;
230{
231 struct stat st;
232 struct svr4_stat svr4_st;
233 struct fstat_args cup;
234 int error;
235 caddr_t sg = stackgap_init();
236
237 cup.fd = uap->fd;
238 cup.sb = stackgap_alloc(&sg, sizeof(struct stat));
239
240 if ((error = fstat(td, &cup)) != 0)
241 return error;
242
243 if ((error = copyin(cup.sb, &st, sizeof st)) != 0)
244 return error;
245
246 bsd_to_svr4_stat(&st, &svr4_st);
247
248 if ((error = copyout(&svr4_st, uap->sb, sizeof svr4_st)) != 0)
249 return error;
250
251 return 0;
252}
253
254
255int
256svr4_sys_xstat(td, uap)
257 register struct thread *td;
258 struct svr4_sys_xstat_args *uap;
259{
260 struct stat st;
261 struct svr4_xstat svr4_st;
262 struct stat_args cup;
263 int error;
264
265 caddr_t sg = stackgap_init();
266 CHECKALTEXIST(td, &sg, uap->path);
267
268 cup.path = uap->path;
269 cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
270
271 if ((error = stat(td, &cup)) != 0)
272 return error;
273
274 if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
275 return error;
276
277 bsd_to_svr4_xstat(&st, &svr4_st);
278
279#if defined(SOCKET_NOTYET)
280 if (S_ISSOCK(st.st_mode))
281 (void) svr4_add_socket(td, uap->path, &st);
282#endif
283
284 if ((error = copyout(&svr4_st, uap->ub, sizeof svr4_st)) != 0)
285 return error;
286
287 return 0;
288}
289
290int
291svr4_sys_lxstat(td, uap)
292 register struct thread *td;
293 struct svr4_sys_lxstat_args *uap;
294{
295 struct stat st;
296 struct svr4_xstat svr4_st;
297 struct lstat_args cup;
298 int error;
299 caddr_t sg = stackgap_init();
300 CHECKALTEXIST(td, &sg, uap->path);
301
302 cup.path = uap->path;
303 cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
304
305 if ((error = lstat(td, &cup)) != 0)
306 return error;
307
308 if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
309 return error;
310
311 bsd_to_svr4_xstat(&st, &svr4_st);
312
313#if defined(SOCKET_NOTYET)
314 if (S_ISSOCK(st.st_mode))
315 (void) svr4_add_socket(td, uap->path, &st);
316#endif
317 if ((error = copyout(&svr4_st, uap->ub, sizeof svr4_st)) != 0)
318 return error;
319
320 return 0;
321}
322
323
324int
325svr4_sys_fxstat(td, uap)
326 register struct thread *td;
327 struct svr4_sys_fxstat_args *uap;
328{
329 struct stat st;
330 struct svr4_xstat svr4_st;
331 struct fstat_args cup;
332 int error;
333
334 caddr_t sg = stackgap_init();
335
336 cup.fd = uap->fd;
337 cup.sb = stackgap_alloc(&sg, sizeof(struct stat));
338
339 if ((error = fstat(td, &cup)) != 0)
340 return error;
341
342 if ((error = copyin(cup.sb, &st, sizeof st)) != 0)
343 return error;
344
345 bsd_to_svr4_xstat(&st, &svr4_st);
346
347 if ((error = copyout(&svr4_st, uap->sb, sizeof svr4_st)) != 0)
348 return error;
349
350 return 0;
351}
352
353int
354svr4_sys_stat64(td, uap)
355 register struct thread *td;
356 struct svr4_sys_stat64_args *uap;
357{
358 struct stat st;
359 struct svr4_stat64 svr4_st;
360 struct stat_args cup;
361 int error;
362 caddr_t sg = stackgap_init();
363
364 CHECKALTEXIST(td, &sg, uap->path);
365
366 cup.path = uap->path;
367 cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
368
369 if ((error = stat(td, &cup)) != 0)
370 return error;
371
372 if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
373 return error;
374
375 bsd_to_svr4_stat64(&st, &svr4_st);
376
377 if (S_ISSOCK(st.st_mode))
378 (void) svr4_add_socket(td, uap->path, &st);
379
380 if ((error = copyout(&svr4_st, uap->sb, sizeof svr4_st)) != 0)
381 return error;
382
383 return 0;
384}
385
386
387int
388svr4_sys_lstat64(td, uap)
389 register struct thread *td;
390 struct svr4_sys_lstat64_args *uap;
391{
392 struct stat st;
393 struct svr4_stat64 svr4_st;
394 struct stat_args cup;
395 int error;
396 caddr_t sg = stackgap_init();
397
398 CHECKALTEXIST(td, &sg, (char *) uap->path);
399
400 cup.path = uap->path;
401 cup.ub = stackgap_alloc(&sg, sizeof(struct stat));
402
403 if ((error = lstat(td, (struct lstat_args *)&cup)) != 0)
404 return error;
405
406 if ((error = copyin(cup.ub, &st, sizeof st)) != 0)
407 return error;
408
409 bsd_to_svr4_stat64(&st, &svr4_st);
410
411 if (S_ISSOCK(st.st_mode))
412 (void) svr4_add_socket(td, uap->path, &st);
413
414 if ((error = copyout(&svr4_st, uap->sb, sizeof svr4_st)) != 0)
415 return error;
416
417 return 0;
418}
419
420
421int
422svr4_sys_fstat64(td, uap)
423 register struct thread *td;
424 struct svr4_sys_fstat64_args *uap;
425{
426 struct stat st;
427 struct svr4_stat64 svr4_st;
428 struct fstat_args cup;
429 int error;
430 caddr_t sg = stackgap_init();
431
432 cup.fd = uap->fd;
433 cup.sb = stackgap_alloc(&sg, sizeof(struct stat));
434
435 if ((error = fstat(td, &cup)) != 0)
436 return error;
437
438 if ((error = copyin(cup.sb, &st, sizeof st)) != 0)
439 return error;
440
441 bsd_to_svr4_stat64(&st, &svr4_st);
442
443 if ((error = copyout(&svr4_st, uap->sb, sizeof svr4_st)) != 0)
444 return error;
445
446 return 0;
447}
448
449
450int
451svr4_ustat(td, uap)
452 register struct thread *td;
453 struct svr4_ustat_args *uap;
454{
455 struct svr4_ustat us;
456 int error;
457
458 memset(&us, 0, sizeof us);
459
460 /*
461 * XXX: should set f_tfree and f_tinode at least
462 * How do we translate dev -> fstat? (and then to svr4_ustat)
463 */
464 if ((error = copyout(&us, uap->name, sizeof us)) != 0)
465 return (error);
466
467 return 0;
468}
469
470/*extern char ostype[], hostname[], osrelease[], version[], machine[];*/
471
472int
473svr4_sys_uname(td, uap)
474 register struct thread *td;
475 struct svr4_sys_uname_args *uap;
476{
477 struct svr4_utsname sut;
478
479 memset(&sut, 0, sizeof(sut));
480
481 strlcpy(sut.sysname, ostype, sizeof(sut.sysname));
482 getcredhostname(td->td_ucred, sut.nodename, sizeof(sut.nodename));
483 strlcpy(sut.release, osrelease, sizeof(sut.release));
484 strlcpy(sut.version, version, sizeof(sut.version));
485 strlcpy(sut.machine, machine, sizeof(sut.machine));
486
487 return copyout((caddr_t) &sut, (caddr_t) uap->name,
488 sizeof(struct svr4_utsname));
489}
490
491int
492svr4_sys_systeminfo(td, uap)
493 struct thread *td;
494 struct svr4_sys_systeminfo_args *uap;
495{
496 char *str = NULL;
497 int error = 0;
498 register_t *retval = td->td_retval;
499 size_t len = 0;
500 char buf[1]; /* XXX NetBSD uses 256, but that seems
501 like awfully excessive kstack usage
502 for an empty string... */
503 u_int rlen = uap->len;
504
505 switch (uap->what) {
506 case SVR4_SI_SYSNAME:
507 str = ostype;
508 break;
509
510 case SVR4_SI_HOSTNAME:
511 str = hostname;
512 break;
513
514 case SVR4_SI_RELEASE:
515 str = osrelease;
516 break;
517
518 case SVR4_SI_VERSION:
519 str = version;
520 break;
521
522 case SVR4_SI_MACHINE:
523 str = machine;
524 break;
525
526 case SVR4_SI_ARCHITECTURE:
527 str = machine;
528 break;
529
530 case SVR4_SI_HW_SERIAL:
531 str = "0";
532 break;
533
534 case SVR4_SI_HW_PROVIDER:
535 str = ostype;
536 break;
537
538 case SVR4_SI_SRPC_DOMAIN:
539 str = domainname;
540 break;
541
542 case SVR4_SI_PLATFORM:
543#ifdef __i386__
544 str = "i86pc";
545#else
546 str = "unknown";
547#endif
548 break;
549
550 case SVR4_SI_KERB_REALM:
551 str = "unsupported";
552 break;
553#if defined(WHY_DOES_AN_EMULATOR_WANT_TO_SET_HOSTNAMES)
554 case SVR4_SI_SET_HOSTNAME:
555 if ((error = suser(td)) != 0)
556 return error;
557 name = KERN_HOSTNAME;
558 return kern_sysctl(&name, 1, 0, 0, uap->buf, rlen, td);
559
560 case SVR4_SI_SET_SRPC_DOMAIN:
561 if ((error = suser(td)) != 0)
562 return error;
563 name = KERN_NISDOMAINNAME;
564 return kern_sysctl(&name, 1, 0, 0, uap->buf, rlen, td);
565#else
566 case SVR4_SI_SET_HOSTNAME:
567 case SVR4_SI_SET_SRPC_DOMAIN:
568 /* FALLTHROUGH */
569#endif
570 case SVR4_SI_SET_KERB_REALM:
571 return 0;
572
573 default:
574 DPRINTF(("Bad systeminfo command %d\n", uap->what));
575 return ENOSYS;
576 }
577
578 if (str) {
579 len = strlen(str) + 1;
580 if (len > rlen)
581 len = rlen;
582
583 if (uap->buf) {
584 error = copyout(str, uap->buf, len);
585 if (error)
586 return error;
587 /* make sure we are NULL terminated */
588 buf[0] = '\0';
589 error = copyout(buf, &(uap->buf[len - 1]), 1);
590 }
591 else
592 error = 0;
593 }
594 /* XXX NetBSD has hostname setting stuff here. Why would an emulator
595 want to do that? */
596
597 *retval = len;
598 return error;
599}
600
601int
602svr4_sys_utssys(td, uap)
603 register struct thread *td;
604 struct svr4_sys_utssys_args *uap;
605{
606 switch (uap->sel) {
607 case 0: /* uname(2) */
608 {
609 struct svr4_sys_uname_args ua;
610 ua.name = uap->a1;
611 return svr4_sys_uname(td, &ua);
612 }
613
614 case 2: /* ustat(2) */
615 {
616 struct svr4_ustat_args ua;
617 ua.dev = (svr4_dev_t) uap->a2;
618 ua.name = uap->a1;
619 return svr4_ustat(td, &ua);
620 }
621
622 case 3: /* fusers(2) */
623 return ENOSYS;
624
625 default:
626 return ENOSYS;
627 }
628 return ENOSYS;
629}
630
631
632int
633svr4_sys_utime(td, uap)
634 register struct thread *td;
635 struct svr4_sys_utime_args *uap;
636{
637 struct svr4_utimbuf ub;
638 struct timeval tbuf[2];
639 struct utimes_args ap;
640 int error;
641 caddr_t sg = stackgap_init();
642 void *ttp;
643
644 CHECKALTEXIST(td, &sg, uap->path);
645 ap.path = uap->path;
646 if (uap->ubuf != NULL) {
647 if ((error = copyin(uap->ubuf, &ub, sizeof(ub))) != 0)
648 return error;
649 tbuf[0].tv_sec = ub.actime;
650 tbuf[0].tv_usec = 0;
651 tbuf[1].tv_sec = ub.modtime;
652 tbuf[1].tv_usec = 0;
653 ttp = stackgap_alloc(&sg, sizeof(tbuf));
654 error = copyout(tbuf, ttp, sizeof(tbuf));
655 if (error)
656 return error;
657 ap.tptr = ttp;
658 }
659 else
660 ap.tptr = NULL;
661 return utimes(td, &ap);
662}
663
664
665int
666svr4_sys_utimes(td, uap)
667 register struct thread *td;
668 struct svr4_sys_utimes_args *uap;
669{
670 caddr_t sg = stackgap_init();
671 CHECKALTEXIST(td, &sg, uap->path);
672 return utimes(td, (struct utimes_args *)uap);
673}
674
675static int
676svr4_to_bsd_pathconf(name)
677 int name;
678{
679 switch (name) {
680 case SVR4_PC_LINK_MAX:
681 return _PC_LINK_MAX;
682
683 case SVR4_PC_MAX_CANON:
684 return _PC_MAX_CANON;
685
686 case SVR4_PC_MAX_INPUT:
687 return _PC_MAX_INPUT;
688
689 case SVR4_PC_NAME_MAX:
690 return _PC_NAME_MAX;
691
692 case SVR4_PC_PATH_MAX:
693 return _PC_PATH_MAX;
694
695 case SVR4_PC_PIPE_BUF:
696 return _PC_PIPE_BUF;
697
698 case SVR4_PC_NO_TRUNC:
699 return _PC_NO_TRUNC;
700
701 case SVR4_PC_VDISABLE:
702 return _PC_VDISABLE;
703
704 case SVR4_PC_CHOWN_RESTRICTED:
705 return _PC_CHOWN_RESTRICTED;
706 case SVR4_PC_SYNC_IO:
707#if defined(_PC_SYNC_IO)
708 return _PC_SYNC_IO;
709#else
710 return 0;
711#endif
712 case SVR4_PC_ASYNC_IO:
713 case SVR4_PC_PRIO_IO:
714 /* Not supported */
715 return 0;
716
717 default:
718 /* Invalid */
719 return -1;
720 }
721}
722
723
724int
725svr4_sys_pathconf(td, uap)
726 register struct thread *td;
727 struct svr4_sys_pathconf_args *uap;
728{
729 caddr_t sg = stackgap_init();
730 register_t *retval = td->td_retval;
731
732 CHECKALTEXIST(td, &sg, uap->path);
733
734 uap->name = svr4_to_bsd_pathconf(uap->name);
735
736 switch (uap->name) {
737 case -1:
738 *retval = -1;
739 return EINVAL;
740 case 0:
741 *retval = 0;
742 return 0;
743 default:
744 return pathconf(td, (struct pathconf_args *)uap);
745 }
746}
747
748
749int
750svr4_sys_fpathconf(td, uap)
751 register struct thread *td;
752 struct svr4_sys_fpathconf_args *uap;
753{
754 register_t *retval = td->td_retval;
755
756 uap->name = svr4_to_bsd_pathconf(uap->name);
757
758 switch (uap->name) {
759 case -1:
760 *retval = -1;
761 return EINVAL;
762 case 0:
763 *retval = 0;
764 return 0;
765 default:
766 return fpathconf(td, (struct fpathconf_args *)uap);
767 }
768}