1 /* $NetBSD: svr4_32_stat.c,v 1.15 2005/02/26 23:10:21 perry Exp $ */
2
3 /*-
4 * Copyright (c) 1994 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: svr4_32_stat.c,v 1.15 2005/02/26 23:10:21 perry Exp $");
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/namei.h>
45 #include <sys/proc.h>
46 #include <sys/file.h>
47 #include <sys/stat.h>
48 #include <sys/filedesc.h>
49 #include <sys/ioctl.h>
50 #include <sys/kernel.h>
51 #include <sys/mount.h>
52 #include <sys/malloc.h>
53 #include <sys/unistd.h>
54
55 #include <sys/time.h>
56 #include <sys/ucred.h>
57 #include <uvm/uvm_extern.h>
58 #include <sys/sysctl.h>
59
60 #include <sys/sa.h>
61 #include <sys/syscallargs.h>
62
63 #include <compat/svr4_32/svr4_32_types.h>
64 #include <compat/svr4_32/svr4_32_signal.h>
65 #include <compat/svr4_32/svr4_32_lwp.h>
66 #include <compat/svr4_32/svr4_32_ucontext.h>
67 #include <compat/svr4_32/svr4_32_syscallargs.h>
68 #include <compat/svr4_32/svr4_32_util.h>
69 #include <compat/svr4_32/svr4_32_stat.h>
70 #include <compat/svr4_32/svr4_32_ustat.h>
71 #include <compat/svr4_32/svr4_32_fuser.h>
72 #include <compat/svr4/svr4_utsname.h>
73 #include <compat/svr4/svr4_systeminfo.h>
74 #include <compat/svr4_32/svr4_32_time.h>
75 #include <compat/svr4_32/svr4_32_socket.h>
76
77 #if defined(__sparc__) || defined(__sparc_v9__) || defined(__sparc64__)
78 /*
79 * Solaris-2.4 on the sparc has the old stat call using the new
80 * stat data structure...
81 */
82 # define SVR4_NO_OSTAT
83 #endif
84
85 static void bsd_to_svr4_32_xstat __P((struct stat *, struct svr4_32_xstat *));
86 static void bsd_to_svr4_32_stat64 __P((struct stat *, struct svr4_32_stat64 *));
87 int svr4_32_ustat __P((struct lwp *, void *, register_t *));
88 static int svr4_32_to_bsd_pathconf __P((int));
89
90 /*
91 * SVR4 uses named pipes as named sockets, so we tell programs
92 * that sockets are named pipes with mode 0
93 */
94 #define BSD_TO_SVR4_MODE(mode) (S_ISSOCK(mode) ? S_IFIFO : (mode))
95
96
97 #ifndef SVR4_NO_OSTAT
98 static void bsd_to_svr4_32_stat __P((struct stat *, struct svr4_32_stat *));
99
100 static void
101 bsd_to_svr4_32_stat(st, st4)
102 struct stat *st;
103 struct svr4_32_stat *st4;
104 {
105 memset(st4, 0, sizeof(*st4));
106 st4->st_dev = bsd_to_svr4_odev_t(st->st_dev);
107 st4->st_ino = st->st_ino;
108 st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
109 st4->st_nlink = st->st_nlink;
110 st4->st_uid = st->st_uid;
111 st4->st_gid = st->st_gid;
112 st4->st_rdev = bsd_to_svr4_odev_t(st->st_rdev);
113 st4->st_size = st->st_size;
114 st4->st_atim = st->st_atimespec.tv_sec;
115 st4->st_mtim = st->st_mtimespec.tv_sec;
116 st4->st_ctim = st->st_ctimespec.tv_sec;
117 }
118 #endif
119
120
121 static void
122 bsd_to_svr4_32_xstat(st, st4)
123 struct stat *st;
124 struct svr4_32_xstat *st4;
125 {
126 memset(st4, 0, sizeof(*st4));
127 st4->st_dev = bsd_to_svr4_dev_t(st->st_dev);
128 st4->st_ino = st->st_ino;
129 st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
130 st4->st_nlink = st->st_nlink;
131 st4->st_uid = st->st_uid;
132 st4->st_gid = st->st_gid;
133 st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
134 st4->st_size = st->st_size;
135 st4->st_atim.tv_sec = st->st_atimespec.tv_sec;
136 st4->st_atim.tv_nsec = st->st_atimespec.tv_nsec;
137 st4->st_mtim.tv_sec = st->st_mtimespec.tv_sec;
138 st4->st_mtim.tv_nsec = st->st_mtimespec.tv_nsec;
139 st4->st_ctim.tv_sec = st->st_ctimespec.tv_sec;
140 st4->st_ctim.tv_nsec = st->st_ctimespec.tv_nsec;
141 st4->st_blksize = st->st_blksize;
142 st4->st_blocks = st->st_blocks;
143 strlcpy(st4->st_fstype, "unknown", sizeof(st4->st_fstype));
144 }
145
146
147 static void
148 bsd_to_svr4_32_stat64(st, st4)
149 struct stat *st;
150 struct svr4_32_stat64 *st4;
151 {
152 memset(st4, 0, sizeof(*st4));
153 st4->st_dev = bsd_to_svr4_dev_t(st->st_dev);
154 st4->st_ino = st->st_ino;
155 st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
156 st4->st_nlink = st->st_nlink;
157 st4->st_uid = st->st_uid;
158 st4->st_gid = st->st_gid;
159 st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
160 st4->st_size = st->st_size;
161 st4->st_atim.tv_sec = st->st_atimespec.tv_sec;
162 st4->st_atim.tv_nsec = st->st_atimespec.tv_nsec;
163 st4->st_mtim.tv_sec = st->st_mtimespec.tv_sec;
164 st4->st_mtim.tv_nsec = st->st_mtimespec.tv_nsec;
165 st4->st_ctim.tv_sec = st->st_ctimespec.tv_sec;
166 st4->st_ctim.tv_nsec = st->st_ctimespec.tv_nsec;
167 st4->st_blocks = st->st_blocks;
168 strlcpy(st4->st_fstype, "unknown", sizeof(st4->st_fstype));
169 }
170
171
172 int
173 svr4_32_sys_stat(l, v, retval)
174 struct lwp *l;
175 void *v;
176 register_t *retval;
177 {
178 struct svr4_32_sys_stat_args *uap = v;
179 #ifdef SVR4_NO_OSTAT
180 struct svr4_32_sys_xstat_args_noconst {
181 syscallarg(int) two;
182 syscallarg(netbsd32_charp) path;
183 syscallarg(svr4_32_xstat_tp) ub;
184 } cup;
185
186 SCARG(&cup, two) = 2;
187 SCARG(&cup, path) = SCARG(uap, path);
188 SCARG(&cup, ub) = SCARG(uap, ub);
189 return svr4_32_sys_xstat(l, &cup, retval);
190 #else
191 struct proc *p = l->l_proc;
192 struct stat st;
193 struct svr4_32_stat svr4_st;
194 struct sys___stat13_args cup;
195 int error;
196
197 caddr_t sg = stackgap_init(p, 0);
198 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
199 SCARG(&cup, path) = SCARG(uap, path);
200 SCARG(&cup, path) = (char *)(u_long)SCARG(uap, path);
201 CHECK_ALT_EXIST(p, &sg, SCARG(&cup, path));
202
203 if ((error = sys___stat13(p, &cup, retval)) != 0)
204 return error;
205
206 if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
207 return error;
208
209 bsd_to_svr4_32_stat(&st, &svr4_st);
210
211 if (S_ISSOCK(st.st_mode))
212 (void) svr4_add_socket(p, SCARG(&cup, path), &st);
213
214 if ((error = copyout(&svr4_st, (vaddr_t)(u_long)SCARG(uap, ub),
215 sizeof svr4_st)) != 0)
216 return error;
217
218 return 0;
219 #endif
220 }
221
222
223 int
224 svr4_32_sys_lstat(l, v, retval)
225 struct lwp *l;
226 void *v;
227 register_t *retval;
228 {
229 struct svr4_32_sys_lstat_args *uap = v;
230 #ifdef SVR4_NO_OSTAT
231 struct svr4_32_sys_lxstat_args_noconst {
232 syscallarg(int) two;
233 syscallarg(netbsd32_charp) path;
234 syscallarg(svr4_32_xstat_tp) ub;
235 } cup;
236
237 SCARG(&cup, two) = 2;
238 SCARG(&cup, path) = SCARG(uap, path);
239 SCARG(&cup, ub) = SCARG(uap, ub);
240 return svr4_32_sys_lxstat(l, &cup, retval);
241 #else
242 struct stat st;
243 struct svr4_32_stat svr4_st;
244 struct sys___lstat13_args cup;
245 int error;
246
247 caddr_t sg = stackgap_init(p, 0);
248 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
249 SCARG(&cup, path) = (char *)(u_long)SCARG(uap, path);
250 CHECK_ALT_EXIST(p, &sg, SCARG(&cup, path));
251
252 if ((error = sys___lstat13(p, &cup, retval)) != 0)
253 return error;
254
255 if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
256 return error;
257
258 bsd_to_svr4_32_stat(&st, &svr4_st);
259
260 if (S_ISSOCK(st.st_mode))
261 (void) svr4_add_socket(p, SCARG(&cup, path), &st);
262
263 if ((error = copyout(&svr4_st, (caddr_t)(u_long)SCARG(uap, ub),
264 sizeof svr4_st)) != 0)
265 return error;
266
267 return 0;
268 #endif
269 }
270
271
272 int
273 svr4_32_sys_fstat(l, v, retval)
274 struct lwp *l;
275 void *v;
276 register_t *retval;
277 {
278 struct svr4_32_sys_fstat_args *uap = v;
279 #ifdef SVR4_NO_OSTAT
280 struct svr4_32_sys_fxstat_args cup;
281
282 SCARG(&cup, two) = 2;
283 SCARG(&cup, fd) = SCARG(uap, fd);
284 SCARG(&cup, sb) = SCARG(uap, sb);
285 return svr4_32_sys_fxstat(l, &cup, retval);
286 #else
287 struct stat st;
288 struct svr4_32_stat svr4_st;
289 struct sys___fstat13_args cup;
290 int error;
291
292 caddr_t sg = stackgap_init(p, 0);
293
294 SCARG(&cup, fd) = SCARG(uap, fd);
295 SCARG(&cup, sb) = stackgap_alloc(p, &sg, sizeof(struct stat));
296
297 if ((error = sys___fstat13(p, &cup, retval)) != 0)
298 return error;
299
300 if ((error = copyin(SCARG(&cup, sb), &st, sizeof st)) != 0)
301 return error;
302
303 bsd_to_svr4_32_stat(&st, &svr4_st);
304
305 if ((error = copyout(&svr4_st, (caddr_t)(u_long)SCARG(uap, sb),
306 sizeof svr4_st)) != 0)
307 return error;
308
309 return 0;
310 #endif
311 }
312
313
314 int
315 svr4_32_sys_xstat(l, v, retval)
316 struct lwp *l;
317 void *v;
318 register_t *retval;
319 {
320 struct svr4_32_sys_xstat_args *uap = v;
321 struct proc *p = l->l_proc;
322 struct stat st;
323 struct svr4_32_xstat svr4_st;
324 struct sys___stat13_args cup;
325 int error;
326
327 caddr_t sg = stackgap_init(p, 0);
328
329 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
330 SCARG(&cup, path) = (const char *)(u_long)SCARG(uap, path);
331 CHECK_ALT_EXIST(p, &sg, SCARG(&cup, path));
332
333 if ((error = sys___stat13(l, &cup, retval)) != 0)
334 return error;
335
336 if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
337 return error;
338
339 bsd_to_svr4_32_xstat(&st, &svr4_st);
340
341 if (S_ISSOCK(st.st_mode))
342 (void) svr4_add_socket(p, (const char *)(u_long)SCARG(uap, path),
343 &st);
344
345 if ((error = copyout(&svr4_st, (caddr_t)(u_long)SCARG(uap, ub),
346 sizeof svr4_st)) != 0)
347 return error;
348
349 return 0;
350 }
351
352
353 int
354 svr4_32_sys_lxstat(l, v, retval)
355 struct lwp *l;
356 void *v;
357 register_t *retval;
358 {
359 struct svr4_32_sys_lxstat_args *uap = v;
360 struct proc *p = l->l_proc;
361 struct stat st;
362 struct svr4_32_xstat svr4_st;
363 struct sys___lstat13_args cup;
364 int error;
365
366 caddr_t sg = stackgap_init(p, 0);
367
368 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
369 SCARG(&cup, path) = (const char *)(u_long)SCARG(uap, path);
370 CHECK_ALT_EXIST(p, &sg, SCARG(&cup, path));
371
372 if ((error = sys___lstat13(l, &cup, retval)) != 0)
373 return error;
374
375 if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
376 return error;
377
378 bsd_to_svr4_32_xstat(&st, &svr4_st);
379
380 if (S_ISSOCK(st.st_mode))
381 (void) svr4_add_socket(p, (const char *)(u_long)SCARG(uap, path),
382 &st);
383
384 if ((error = copyout(&svr4_st, (caddr_t)(u_long)SCARG(uap, ub),
385 sizeof svr4_st)) != 0)
386 return error;
387
388 return 0;
389 }
390
391
392 int
393 svr4_32_sys_fxstat(l, v, retval)
394 struct lwp *l;
395 void *v;
396 register_t *retval;
397 {
398 struct svr4_32_sys_fxstat_args *uap = v;
399 struct proc *p = l->l_proc;
400 struct stat st;
401 struct svr4_32_xstat svr4_st;
402 struct sys___fstat13_args cup;
403 int error;
404
405 caddr_t sg = stackgap_init(p, 0);
406
407 SCARG(&cup, fd) = SCARG(uap, fd);
408 SCARG(&cup, sb) = stackgap_alloc(p, &sg, sizeof(struct stat));
409
410 if ((error = sys___fstat13(l, &cup, retval)) != 0)
411 return error;
412
413 if ((error = copyin(SCARG(&cup, sb), &st, sizeof st)) != 0)
414 return error;
415
416 bsd_to_svr4_32_xstat(&st, &svr4_st);
417
418 if ((error = copyout(&svr4_st, (caddr_t)(u_long)SCARG(uap, sb),
419 sizeof svr4_st)) != 0)
420 return error;
421
422 return 0;
423 }
424
425
426 int
427 svr4_32_sys_stat64(l, v, retval)
428 struct lwp *l;
429 void *v;
430 register_t *retval;
431 {
432 struct svr4_32_sys_stat64_args *uap = v;
433 struct proc *p = l->l_proc;
434 struct stat st;
435 struct svr4_32_stat64 svr4_st;
436 struct sys___stat13_args cup;
437 int error;
438
439 caddr_t sg = stackgap_init(p, 0);
440
441 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
442 SCARG(&cup, path) = (const char *)(u_long)SCARG(uap, path);
443 CHECK_ALT_EXIST(p, &sg, SCARG(&cup, path));
444
445 if ((error = sys___stat13(l, &cup, retval)) != 0)
446 return error;
447
448 if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
449 return error;
450
451 bsd_to_svr4_32_stat64(&st, &svr4_st);
452
453 if (S_ISSOCK(st.st_mode))
454 (void) svr4_add_socket(p, (const char *)(u_long)SCARG(uap, path),
455 &st);
456
457 if ((error = copyout(&svr4_st, (caddr_t)(u_long)SCARG(uap, sb),
458 sizeof svr4_st)) != 0)
459 return error;
460
461 return 0;
462 }
463
464
465 int
466 svr4_32_sys_lstat64(l, v, retval)
467 struct lwp *l;
468 void *v;
469 register_t *retval;
470 {
471 struct svr4_32_sys_lstat64_args *uap = v;
472 struct proc *p = l->l_proc;
473 struct stat st;
474 struct svr4_32_stat64 svr4_st;
475 struct sys___lstat13_args cup;
476 int error;
477
478 caddr_t sg = stackgap_init(p, 0);
479
480 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
481 SCARG(&cup, path) = (const char *)(u_long)SCARG(uap, path);
482 CHECK_ALT_EXIST(p, &sg, SCARG(&cup, path));
483
484 if ((error = sys___lstat13(l, &cup, retval)) != 0)
485 return error;
486
487 if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
488 return error;
489
490 bsd_to_svr4_32_stat64(&st, &svr4_st);
491
492 if (S_ISSOCK(st.st_mode))
493 (void) svr4_add_socket(p, (const char *)(u_long)SCARG(uap, path),
494 &st);
495
496 if ((error = copyout(&svr4_st, (caddr_t)(u_long)SCARG(uap, sb),
497 sizeof svr4_st)) != 0)
498 return error;
499
500 return 0;
501 }
502
503
504 int
505 svr4_32_sys_fstat64(l, v, retval)
506 struct lwp *l;
507 void *v;
508 register_t *retval;
509 {
510 struct svr4_32_sys_fstat64_args *uap = v;
511 struct proc *p = l->l_proc;
512 struct stat st;
513 struct svr4_32_stat64 svr4_st;
514 struct sys___fstat13_args cup;
515 int error;
516
517 caddr_t sg = stackgap_init(p, 0);
518
519 SCARG(&cup, fd) = SCARG(uap, fd);
520 SCARG(&cup, sb) = stackgap_alloc(p, &sg, sizeof(struct stat));
521
522 if ((error = sys___fstat13(l, &cup, retval)) != 0)
523 return error;
524
525 if ((error = copyin(SCARG(&cup, sb), &st, sizeof st)) != 0)
526 return error;
527
528 bsd_to_svr4_32_stat64(&st, &svr4_st);
529
530 if ((error = copyout(&svr4_st, (caddr_t)(u_long)SCARG(uap, sb),
531 sizeof svr4_st)) != 0)
532 return error;
533
534 return 0;
535 }
536
537
538 struct svr4_32_ustat_args {
539 syscallarg(svr4_dev_t) dev;
540 syscallarg(svr4_32_ustatp) name;
541 };
542
543 int
544 svr4_32_ustat(l, v, retval)
545 struct lwp *l;
546 void *v;
547 register_t *retval;
548 {
549 struct svr4_32_ustat_args /* {
550 syscallarg(svr4_dev_t) dev;
551 syscallarg(svr4_32_ustatp) name;
552 } */ *uap = v;
553 struct svr4_32_ustat us;
554 int error;
555
556 memset(&us, 0, sizeof us);
557
558 /*
559 * XXX: should set f_tfree and f_tinode at least
560 * How do we translate dev -> fstat? (and then to svr4_32_ustat)
561 */
562 if ((error = copyout(&us, (caddr_t)(u_long)SCARG(uap, name),
563 sizeof us)) != 0)
564 return (error);
565
566 return 0;
567 }
568
569
570
571 int
572 svr4_32_sys_uname(l, v, retval)
573 struct lwp *l;
574 void *v;
575 register_t *retval;
576 {
577 struct svr4_32_sys_uname_args *uap = v;
578 struct svr4_utsname sut;
579
580 memset(&sut, 0, sizeof(sut));
581
582 strncpy(sut.sysname, ostype, sizeof(sut.sysname));
583 sut.sysname[sizeof(sut.sysname) - 1] = '\0';
584
585 strncpy(sut.nodename, hostname, sizeof(sut.nodename));
586 sut.nodename[sizeof(sut.nodename) - 1] = '\0';
587
588 strncpy(sut.release, osrelease, sizeof(sut.release));
589 sut.release[sizeof(sut.release) - 1] = '\0';
590
591 strncpy(sut.version, version, sizeof(sut.version));
592 sut.version[sizeof(sut.version) - 1] = '\0';
593
594 strncpy(sut.machine, machine, sizeof(sut.machine));
595 sut.machine[sizeof(sut.machine) - 1] = '\0';
596
597 return copyout((caddr_t) &sut, (caddr_t)(u_long)SCARG(uap, name),
598 sizeof(struct svr4_utsname));
599 }
600
601
602 int
603 svr4_32_sys_systeminfo(l, v, retval)
604 struct lwp *l;
605 void *v;
606 register_t *retval;
607 {
608 struct svr4_32_sys_systeminfo_args *uap = v;
609 struct proc *p = l->l_proc;
610 const char *str = NULL;
611 int name[2];
612 int error;
613 size_t len;
614 char buf[256];
615
616 u_int rlen = SCARG(uap, len);
617
618 switch (SCARG(uap, what)) {
619 case SVR4_SI_SYSNAME:
620 str = ostype;
621 break;
622
623 case SVR4_SI_HOSTNAME:
624 str = hostname;
625 break;
626
627 case SVR4_SI_RELEASE:
628 str = osrelease;
629 break;
630
631 case SVR4_SI_VERSION:
632 str = version;
633 break;
634
635 case SVR4_SI_MACHINE:
636 str = "sun4u"; /* XXXX -- this only runs on sparcv9 */
637 break;
638
639 case SVR4_SI_ARCHITECTURE:
640 str = machine_arch;
641 break;
642
643 case SVR4_SI_HW_SERIAL:
644 snprintf(buf, sizeof(buf), "%lu", hostid);
645 str = buf;
646 break;
647
648 case SVR4_SI_HW_PROVIDER:
649 str = ostype;
650 break;
651
652 case SVR4_SI_SRPC_DOMAIN:
653 str = domainname;
654 break;
655
656 case SVR4_SI_PLATFORM:
657 #ifdef __i386__
658 str = "i86pc";
659 #elif __sparc__
660 {
661 extern char machine_model[];
662
663 str = machine_model;
664 }
665 #else
666 str = "unknown";
667 #endif
668 break;
669
670 case SVR4_SI_KERB_REALM:
671 str = "unsupported";
672 break;
673
674 case SVR4_SI_SET_HOSTNAME:
675 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
676 return error;
677 name[1] = KERN_HOSTNAME;
678 break;
679
680 case SVR4_SI_SET_SRPC_DOMAIN:
681 if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
682 return error;
683 name[1] = KERN_DOMAINNAME;
684 break;
685
686 case SVR4_SI_SET_KERB_REALM:
687 return 0;
688
689 default:
690 DPRINTF(("Bad systeminfo command %d\n", SCARG(uap, what)));
691 return ENOSYS;
692 }
693
694 if (str) {
695 len = strlen(str) + 1;
696 if (len > rlen)
697 len = rlen;
698
699 if (SCARG(uap, buf)) {
700 error = copyout(str, (caddr_t)(u_long)SCARG(uap, buf), len);
701 if (error)
702 return error;
703 /* make sure we are NULL terminated */
704 buf[0] = '\0';
705 error = copyout(buf, &(((caddr_t)(u_long)
706 SCARG(uap, buf))[len - 1]), 1);
707 }
708 else
709 error = 0;
710 }
711 else {
712 error = copyinstr((caddr_t)(u_long)SCARG(uap, buf), buf,
713 sizeof(buf), &len);
714 if (error)
715 return error;
716 name[0] = CTL_KERN;
717 error = old_sysctl(&name[0], 1, 0, 0, buf, len, NULL);
718 }
719
720 *retval = len;
721 return error;
722 }
723
724
725 int
726 svr4_32_sys_utssys(l, v, retval)
727 struct lwp *l;
728 void *v;
729 register_t *retval;
730 {
731 struct svr4_32_sys_utssys_args *uap = v;
732
733 switch (SCARG(uap, sel)) {
734 case 0: /* uname(2) */
735 {
736 struct svr4_32_sys_uname_args ua;
737 SCARG(&ua, name) = SCARG(uap, a1);
738 return svr4_32_sys_uname(l, &ua, retval);
739 }
740
741 case 2: /* ustat(2) */
742 {
743 struct svr4_32_ustat_args ua;
744 SCARG(&ua, dev) = (svr4_32_dev_t) SCARG(uap, a2);
745 SCARG(&ua, name) = SCARG(uap, a1);
746 return svr4_32_ustat(l, &ua, retval);
747 }
748
749 case 3: /* fusers(2) */
750 return ENOSYS;
751
752 default:
753 return ENOSYS;
754 }
755 return ENOSYS;
756 }
757
758
759 int
760 svr4_32_sys_utime(l, v, retval)
761 struct lwp *l;
762 void *v;
763 register_t *retval;
764 {
765 struct svr4_32_sys_utime_args *uap = v;
766 struct proc *p = l->l_proc;
767 struct svr4_32_utimbuf ub;
768 struct timeval tbuf[2];
769 struct sys_utimes_args ap;
770 int error;
771 void *ttp;
772 caddr_t sg = stackgap_init(p, 0);
773
774 ttp = stackgap_alloc(p, &sg, sizeof(tbuf));
775 SCARG(&ap, path) = (const char *)(u_long)SCARG(uap, path);
776 CHECK_ALT_EXIST(p, &sg, SCARG(&ap, path));
777 if (SCARG(uap, ubuf)) {
778 if ((error = copyin((caddr_t)(u_long)SCARG(uap, ubuf),
779 &ub, sizeof(ub))) != 0)
780 return error;
781 tbuf[0].tv_sec = ub.actime;
782 tbuf[0].tv_usec = 0;
783 tbuf[1].tv_sec = ub.modtime;
784 tbuf[1].tv_usec = 0;
785 error = copyout(tbuf, ttp, sizeof(tbuf));
786 if (error)
787 return error;
788 SCARG(&ap, tptr) = ttp;
789 }
790 else
791 SCARG(&ap, tptr) = NULL;
792 return sys_utimes(l, &ap, retval);
793 }
794
795
796 int
797 svr4_32_sys_utimes(l, v, retval)
798 struct lwp *l;
799 void *v;
800 register_t *retval;
801 {
802 struct svr4_32_sys_utimes_args *uap = v;
803 struct proc *p = l->l_proc;
804 struct sys_utimes_args ua;
805 caddr_t sg = stackgap_init(p, 0);
806 SCARG(&ua, path) = (const char *)(u_long)SCARG(uap, path);
807 CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
808 SCARG(&ua, tptr) = (const struct timeval *)(u_long)SCARG(uap, tptr);
809
810 return sys_utimes(l, &ua, retval);
811 }
812
813
814 static int
815 svr4_32_to_bsd_pathconf(name)
816 int name;
817 {
818 switch (name) {
819 case SVR4_PC_LINK_MAX:
820 return _PC_LINK_MAX;
821
822 case SVR4_PC_MAX_CANON:
823 return _PC_MAX_CANON;
824
825 case SVR4_PC_MAX_INPUT:
826 return _PC_MAX_INPUT;
827
828 case SVR4_PC_NAME_MAX:
829 return _PC_NAME_MAX;
830
831 case SVR4_PC_PATH_MAX:
832 return _PC_PATH_MAX;
833
834 case SVR4_PC_PIPE_BUF:
835 return _PC_PIPE_BUF;
836
837 case SVR4_PC_NO_TRUNC:
838 return _PC_NO_TRUNC;
839
840 case SVR4_PC_VDISABLE:
841 return _PC_VDISABLE;
842
843 case SVR4_PC_CHOWN_RESTRICTED:
844 return _PC_CHOWN_RESTRICTED;
845
846 case SVR4_PC_SYNC_IO:
847 return _PC_SYNC_IO;
848
849 case SVR4_PC_FILESIZEBITS:
850 return _PC_FILESIZEBITS;
851
852 case SVR4_PC_ASYNC_IO:
853 case SVR4_PC_PRIO_IO:
854 /* Not supported */
855 return 0;
856
857 default:
858 /* Invalid */
859 return -1;
860 }
861 }
862
863
864 int
865 svr4_32_sys_pathconf(l, v, retval)
866 struct lwp *l;
867 void *v;
868 register_t *retval;
869 {
870 struct svr4_32_sys_pathconf_args *uap = v;
871 struct proc *p = l->l_proc;
872 struct sys_pathconf_args /* {
873 syscallarg(char *) path;
874 syscallarg(int) name;
875 } */ ua;
876 caddr_t sg = stackgap_init(p, 0);
877
878 SCARG(&ua, path) = (char *)(u_long)SCARG(uap, path);
879
880 CHECK_ALT_EXIST(p, &sg, SCARG(&ua, path));
881
882 SCARG(&ua, name) = svr4_32_to_bsd_pathconf(SCARG(&ua, name));
883
884 switch (SCARG(&ua, name)) {
885 case -1:
886 *retval = -1;
887 return EINVAL;
888 case 0:
889 *retval = 0;
890 return 0;
891 default:
892 return sys_pathconf(l, uap, retval);
893 }
894 }
895
896
897 int
898 svr4_32_sys_fpathconf(l, v, retval)
899 struct lwp *l;
900 void *v;
901 register_t *retval;
902 {
903 struct svr4_32_sys_fpathconf_args *uap = v;
904
905 SCARG(uap, name) = svr4_32_to_bsd_pathconf(SCARG(uap, name));
906
907 switch (SCARG(uap, name)) {
908 case -1:
909 *retval = -1;
910 return EINVAL;
911 case 0:
912 *retval = 0;
913 return 0;
914 default:
915 return sys_fpathconf(l, uap, retval);
916 }
917 }
Cache object: 0139bc45ed9acd477e27489ebbfd12b7
|