1 /* $NetBSD: svr4_32_stat.c,v 1.20 2006/07/23 22:06:10 ad 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.20 2006/07/23 22:06:10 ad 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 #include <sys/kauth.h>
55
56 #include <sys/time.h>
57 #include <sys/ucred.h>
58 #include <uvm/uvm_extern.h>
59 #include <sys/sysctl.h>
60
61 #include <sys/sa.h>
62 #include <sys/syscallargs.h>
63
64 #include <compat/svr4_32/svr4_32_types.h>
65 #include <compat/svr4_32/svr4_32_signal.h>
66 #include <compat/svr4_32/svr4_32_lwp.h>
67 #include <compat/svr4_32/svr4_32_ucontext.h>
68 #include <compat/svr4_32/svr4_32_syscallargs.h>
69 #include <compat/svr4_32/svr4_32_util.h>
70 #include <compat/svr4_32/svr4_32_stat.h>
71 #include <compat/svr4_32/svr4_32_ustat.h>
72 #include <compat/svr4_32/svr4_32_fuser.h>
73 #include <compat/svr4/svr4_utsname.h>
74 #include <compat/svr4/svr4_systeminfo.h>
75 #include <compat/svr4_32/svr4_32_time.h>
76 #include <compat/svr4_32/svr4_32_socket.h>
77
78 #if defined(__sparc__) || defined(__sparc_v9__) || defined(__sparc64__)
79 /*
80 * Solaris-2.4 on the sparc has the old stat call using the new
81 * stat data structure...
82 */
83 # define SVR4_NO_OSTAT
84 #endif
85
86 static void bsd_to_svr4_32_xstat __P((struct stat *, struct svr4_32_xstat *));
87 static void bsd_to_svr4_32_stat64 __P((struct stat *, struct svr4_32_stat64 *));
88 int svr4_32_ustat __P((struct lwp *, void *, register_t *));
89 static int svr4_32_to_bsd_pathconf __P((int));
90
91 /*
92 * SVR4 uses named pipes as named sockets, so we tell programs
93 * that sockets are named pipes with mode 0
94 */
95 #define BSD_TO_SVR4_MODE(mode) (S_ISSOCK(mode) ? S_IFIFO : (mode))
96
97
98 #ifndef SVR4_NO_OSTAT
99 static void bsd_to_svr4_32_stat __P((struct stat *, struct svr4_32_stat *));
100
101 static void
102 bsd_to_svr4_32_stat(st, st4)
103 struct stat *st;
104 struct svr4_32_stat *st4;
105 {
106 memset(st4, 0, sizeof(*st4));
107 st4->st_dev = bsd_to_svr4_odev_t(st->st_dev);
108 st4->st_ino = st->st_ino;
109 st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
110 st4->st_nlink = st->st_nlink;
111 st4->st_uid = st->st_uid;
112 st4->st_gid = st->st_gid;
113 st4->st_rdev = bsd_to_svr4_odev_t(st->st_rdev);
114 st4->st_size = st->st_size;
115 st4->st_atim = st->st_atimespec.tv_sec;
116 st4->st_mtim = st->st_mtimespec.tv_sec;
117 st4->st_ctim = st->st_ctimespec.tv_sec;
118 }
119 #endif
120
121
122 static void
123 bsd_to_svr4_32_xstat(st, st4)
124 struct stat *st;
125 struct svr4_32_xstat *st4;
126 {
127 memset(st4, 0, sizeof(*st4));
128 st4->st_dev = bsd_to_svr4_dev_t(st->st_dev);
129 st4->st_ino = st->st_ino;
130 st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
131 st4->st_nlink = st->st_nlink;
132 st4->st_uid = st->st_uid;
133 st4->st_gid = st->st_gid;
134 st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
135 st4->st_size = st->st_size;
136 st4->st_atim.tv_sec = st->st_atimespec.tv_sec;
137 st4->st_atim.tv_nsec = st->st_atimespec.tv_nsec;
138 st4->st_mtim.tv_sec = st->st_mtimespec.tv_sec;
139 st4->st_mtim.tv_nsec = st->st_mtimespec.tv_nsec;
140 st4->st_ctim.tv_sec = st->st_ctimespec.tv_sec;
141 st4->st_ctim.tv_nsec = st->st_ctimespec.tv_nsec;
142 st4->st_blksize = st->st_blksize;
143 st4->st_blocks = st->st_blocks;
144 strlcpy(st4->st_fstype, "unknown", sizeof(st4->st_fstype));
145 }
146
147
148 static void
149 bsd_to_svr4_32_stat64(st, st4)
150 struct stat *st;
151 struct svr4_32_stat64 *st4;
152 {
153 memset(st4, 0, sizeof(*st4));
154 st4->st_dev = bsd_to_svr4_dev_t(st->st_dev);
155 st4->st_ino = st->st_ino;
156 st4->st_mode = BSD_TO_SVR4_MODE(st->st_mode);
157 st4->st_nlink = st->st_nlink;
158 st4->st_uid = st->st_uid;
159 st4->st_gid = st->st_gid;
160 st4->st_rdev = bsd_to_svr4_dev_t(st->st_rdev);
161 st4->st_size = st->st_size;
162 st4->st_atim.tv_sec = st->st_atimespec.tv_sec;
163 st4->st_atim.tv_nsec = st->st_atimespec.tv_nsec;
164 st4->st_mtim.tv_sec = st->st_mtimespec.tv_sec;
165 st4->st_mtim.tv_nsec = st->st_mtimespec.tv_nsec;
166 st4->st_ctim.tv_sec = st->st_ctimespec.tv_sec;
167 st4->st_ctim.tv_nsec = st->st_ctimespec.tv_nsec;
168 st4->st_blocks = st->st_blocks;
169 strlcpy(st4->st_fstype, "unknown", sizeof(st4->st_fstype));
170 }
171
172
173 int
174 svr4_32_sys_stat(l, v, retval)
175 struct lwp *l;
176 void *v;
177 register_t *retval;
178 {
179 struct svr4_32_sys_stat_args *uap = v;
180 #ifdef SVR4_NO_OSTAT
181 struct svr4_32_sys_xstat_args_noconst {
182 syscallarg(int) two;
183 syscallarg(netbsd32_charp) path;
184 syscallarg(svr4_32_xstat_tp) ub;
185 } cup;
186
187 SCARG(&cup, two) = 2;
188 SCARG(&cup, path) = SCARG(uap, path);
189 SCARG(&cup, ub) = SCARG(uap, ub);
190 return svr4_32_sys_xstat(l, &cup, retval);
191 #else
192 struct proc *p = l->l_proc;
193 struct stat st;
194 struct svr4_32_stat svr4_st;
195 struct sys___stat13_args cup;
196 int error;
197
198 caddr_t sg = stackgap_init(p, 0);
199 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
200 SCARG(&cup, path) = SCARG(uap, path);
201 SCARG(&cup, path) = (char *)(u_long)SCARG(uap, path);
202 CHECK_ALT_EXIST(l, &sg, SCARG(&cup, path));
203
204 if ((error = sys___stat13(p, &cup, retval)) != 0)
205 return error;
206
207 if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
208 return error;
209
210 bsd_to_svr4_32_stat(&st, &svr4_st);
211
212 if (S_ISSOCK(st.st_mode))
213 (void) svr4_add_socket(p, SCARG(&cup, path), &st);
214
215 if ((error = copyout(&svr4_st, (vaddr_t)(u_long)SCARG(uap, ub),
216 sizeof svr4_st)) != 0)
217 return error;
218
219 return 0;
220 #endif
221 }
222
223
224 int
225 svr4_32_sys_lstat(l, v, retval)
226 struct lwp *l;
227 void *v;
228 register_t *retval;
229 {
230 struct svr4_32_sys_lstat_args *uap = v;
231 #ifdef SVR4_NO_OSTAT
232 struct svr4_32_sys_lxstat_args_noconst {
233 syscallarg(int) two;
234 syscallarg(netbsd32_charp) path;
235 syscallarg(svr4_32_xstat_tp) ub;
236 } cup;
237
238 SCARG(&cup, two) = 2;
239 SCARG(&cup, path) = SCARG(uap, path);
240 SCARG(&cup, ub) = SCARG(uap, ub);
241 return svr4_32_sys_lxstat(l, &cup, retval);
242 #else
243 struct stat st;
244 struct svr4_32_stat svr4_st;
245 struct sys___lstat13_args cup;
246 int error;
247
248 caddr_t sg = stackgap_init(p, 0);
249 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
250 SCARG(&cup, path) = (char *)(u_long)SCARG(uap, path);
251 CHECK_ALT_EXIST(l, &sg, SCARG(&cup, path));
252
253 if ((error = sys___lstat13(p, &cup, retval)) != 0)
254 return error;
255
256 if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
257 return error;
258
259 bsd_to_svr4_32_stat(&st, &svr4_st);
260
261 if (S_ISSOCK(st.st_mode))
262 (void) svr4_add_socket(p, SCARG(&cup, path), &st);
263
264 if ((error = copyout(&svr4_st, (caddr_t)(u_long)SCARG(uap, ub),
265 sizeof svr4_st)) != 0)
266 return error;
267
268 return 0;
269 #endif
270 }
271
272
273 int
274 svr4_32_sys_fstat(l, v, retval)
275 struct lwp *l;
276 void *v;
277 register_t *retval;
278 {
279 struct svr4_32_sys_fstat_args *uap = v;
280 #ifdef SVR4_NO_OSTAT
281 struct svr4_32_sys_fxstat_args cup;
282
283 SCARG(&cup, two) = 2;
284 SCARG(&cup, fd) = SCARG(uap, fd);
285 SCARG(&cup, sb) = SCARG(uap, sb);
286 return svr4_32_sys_fxstat(l, &cup, retval);
287 #else
288 struct stat st;
289 struct svr4_32_stat svr4_st;
290 struct sys___fstat13_args cup;
291 int error;
292
293 caddr_t sg = stackgap_init(p, 0);
294
295 SCARG(&cup, fd) = SCARG(uap, fd);
296 SCARG(&cup, sb) = stackgap_alloc(p, &sg, sizeof(struct stat));
297
298 if ((error = sys___fstat13(p, &cup, retval)) != 0)
299 return error;
300
301 if ((error = copyin(SCARG(&cup, sb), &st, sizeof st)) != 0)
302 return error;
303
304 bsd_to_svr4_32_stat(&st, &svr4_st);
305
306 if ((error = copyout(&svr4_st, (caddr_t)(u_long)SCARG(uap, sb),
307 sizeof svr4_st)) != 0)
308 return error;
309
310 return 0;
311 #endif
312 }
313
314
315 int
316 svr4_32_sys_xstat(l, v, retval)
317 struct lwp *l;
318 void *v;
319 register_t *retval;
320 {
321 struct svr4_32_sys_xstat_args *uap = v;
322 struct proc *p = l->l_proc;
323 struct stat st;
324 struct svr4_32_xstat svr4_st;
325 struct sys___stat30_args cup;
326 int error;
327
328 caddr_t sg = stackgap_init(p, 0);
329
330 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
331 SCARG(&cup, path) = (const char *)(u_long)SCARG(uap, path);
332 CHECK_ALT_EXIST(l, &sg, SCARG(&cup, path));
333
334 if ((error = sys___stat30(l, &cup, retval)) != 0)
335 return error;
336
337 if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
338 return error;
339
340 bsd_to_svr4_32_xstat(&st, &svr4_st);
341
342 if (S_ISSOCK(st.st_mode))
343 (void) svr4_add_socket(p, (const char *)(u_long)SCARG(uap, path),
344 &st);
345
346 if ((error = copyout(&svr4_st, (caddr_t)(u_long)SCARG(uap, ub),
347 sizeof svr4_st)) != 0)
348 return error;
349
350 return 0;
351 }
352
353
354 int
355 svr4_32_sys_lxstat(l, v, retval)
356 struct lwp *l;
357 void *v;
358 register_t *retval;
359 {
360 struct svr4_32_sys_lxstat_args *uap = v;
361 struct proc *p = l->l_proc;
362 struct stat st;
363 struct svr4_32_xstat svr4_st;
364 struct sys___lstat30_args cup;
365 int error;
366
367 caddr_t sg = stackgap_init(p, 0);
368
369 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
370 SCARG(&cup, path) = (const char *)(u_long)SCARG(uap, path);
371 CHECK_ALT_EXIST(l, &sg, SCARG(&cup, path));
372
373 if ((error = sys___lstat30(l, &cup, retval)) != 0)
374 return error;
375
376 if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
377 return error;
378
379 bsd_to_svr4_32_xstat(&st, &svr4_st);
380
381 if (S_ISSOCK(st.st_mode))
382 (void) svr4_add_socket(p, (const char *)(u_long)SCARG(uap, path),
383 &st);
384
385 if ((error = copyout(&svr4_st, (caddr_t)(u_long)SCARG(uap, ub),
386 sizeof svr4_st)) != 0)
387 return error;
388
389 return 0;
390 }
391
392
393 int
394 svr4_32_sys_fxstat(l, v, retval)
395 struct lwp *l;
396 void *v;
397 register_t *retval;
398 {
399 struct svr4_32_sys_fxstat_args *uap = v;
400 struct proc *p = l->l_proc;
401 struct stat st;
402 struct svr4_32_xstat svr4_st;
403 struct sys___fstat30_args cup;
404 int error;
405
406 caddr_t sg = stackgap_init(p, 0);
407
408 SCARG(&cup, fd) = SCARG(uap, fd);
409 SCARG(&cup, sb) = stackgap_alloc(p, &sg, sizeof(struct stat));
410
411 if ((error = sys___fstat30(l, &cup, retval)) != 0)
412 return error;
413
414 if ((error = copyin(SCARG(&cup, sb), &st, sizeof st)) != 0)
415 return error;
416
417 bsd_to_svr4_32_xstat(&st, &svr4_st);
418
419 if ((error = copyout(&svr4_st, (caddr_t)(u_long)SCARG(uap, sb),
420 sizeof svr4_st)) != 0)
421 return error;
422
423 return 0;
424 }
425
426
427 int
428 svr4_32_sys_stat64(l, v, retval)
429 struct lwp *l;
430 void *v;
431 register_t *retval;
432 {
433 struct svr4_32_sys_stat64_args *uap = v;
434 struct proc *p = l->l_proc;
435 struct stat st;
436 struct svr4_32_stat64 svr4_st;
437 struct sys___stat30_args cup;
438 int error;
439
440 caddr_t sg = stackgap_init(p, 0);
441
442 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
443 SCARG(&cup, path) = (const char *)(u_long)SCARG(uap, path);
444 CHECK_ALT_EXIST(l, &sg, SCARG(&cup, path));
445
446 if ((error = sys___stat30(l, &cup, retval)) != 0)
447 return error;
448
449 if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
450 return error;
451
452 bsd_to_svr4_32_stat64(&st, &svr4_st);
453
454 if (S_ISSOCK(st.st_mode))
455 (void) svr4_add_socket(p, (const char *)(u_long)SCARG(uap, path),
456 &st);
457
458 if ((error = copyout(&svr4_st, (caddr_t)(u_long)SCARG(uap, sb),
459 sizeof svr4_st)) != 0)
460 return error;
461
462 return 0;
463 }
464
465
466 int
467 svr4_32_sys_lstat64(l, v, retval)
468 struct lwp *l;
469 void *v;
470 register_t *retval;
471 {
472 struct svr4_32_sys_lstat64_args *uap = v;
473 struct proc *p = l->l_proc;
474 struct stat st;
475 struct svr4_32_stat64 svr4_st;
476 struct sys___lstat30_args cup;
477 int error;
478
479 caddr_t sg = stackgap_init(p, 0);
480
481 SCARG(&cup, ub) = stackgap_alloc(p, &sg, sizeof(struct stat));
482 SCARG(&cup, path) = (const char *)(u_long)SCARG(uap, path);
483 CHECK_ALT_EXIST(l, &sg, SCARG(&cup, path));
484
485 if ((error = sys___lstat30(l, &cup, retval)) != 0)
486 return error;
487
488 if ((error = copyin(SCARG(&cup, ub), &st, sizeof st)) != 0)
489 return error;
490
491 bsd_to_svr4_32_stat64(&st, &svr4_st);
492
493 if (S_ISSOCK(st.st_mode))
494 (void) svr4_add_socket(p, (const char *)(u_long)SCARG(uap, path),
495 &st);
496
497 if ((error = copyout(&svr4_st, (caddr_t)(u_long)SCARG(uap, sb),
498 sizeof svr4_st)) != 0)
499 return error;
500
501 return 0;
502 }
503
504
505 int
506 svr4_32_sys_fstat64(l, v, retval)
507 struct lwp *l;
508 void *v;
509 register_t *retval;
510 {
511 struct svr4_32_sys_fstat64_args *uap = v;
512 struct proc *p = l->l_proc;
513 struct stat st;
514 struct svr4_32_stat64 svr4_st;
515 struct sys___fstat30_args cup;
516 int error;
517
518 caddr_t sg = stackgap_init(p, 0);
519
520 SCARG(&cup, fd) = SCARG(uap, fd);
521 SCARG(&cup, sb) = stackgap_alloc(p, &sg, sizeof(struct stat));
522
523 if ((error = sys___fstat30(l, &cup, retval)) != 0)
524 return error;
525
526 if ((error = copyin(SCARG(&cup, sb), &st, sizeof st)) != 0)
527 return error;
528
529 bsd_to_svr4_32_stat64(&st, &svr4_st);
530
531 if ((error = copyout(&svr4_st, (caddr_t)(u_long)SCARG(uap, sb),
532 sizeof svr4_st)) != 0)
533 return error;
534
535 return 0;
536 }
537
538
539 struct svr4_32_ustat_args {
540 syscallarg(svr4_dev_t) dev;
541 syscallarg(svr4_32_ustatp) name;
542 };
543
544 int
545 svr4_32_ustat(l, v, retval)
546 struct lwp *l;
547 void *v;
548 register_t *retval;
549 {
550 struct svr4_32_ustat_args /* {
551 syscallarg(svr4_dev_t) dev;
552 syscallarg(svr4_32_ustatp) name;
553 } */ *uap = v;
554 struct svr4_32_ustat us;
555 int error;
556
557 memset(&us, 0, sizeof us);
558
559 /*
560 * XXX: should set f_tfree and f_tinode at least
561 * How do we translate dev -> fstat? (and then to svr4_32_ustat)
562 */
563 if ((error = copyout(&us, (caddr_t)(u_long)SCARG(uap, name),
564 sizeof us)) != 0)
565 return (error);
566
567 return 0;
568 }
569
570
571
572 int
573 svr4_32_sys_uname(l, v, retval)
574 struct lwp *l;
575 void *v;
576 register_t *retval;
577 {
578 struct svr4_32_sys_uname_args *uap = v;
579 struct svr4_utsname sut;
580
581 memset(&sut, 0, sizeof(sut));
582
583 strncpy(sut.sysname, ostype, sizeof(sut.sysname));
584 sut.sysname[sizeof(sut.sysname) - 1] = '\0';
585
586 strncpy(sut.nodename, hostname, sizeof(sut.nodename));
587 sut.nodename[sizeof(sut.nodename) - 1] = '\0';
588
589 strncpy(sut.release, osrelease, sizeof(sut.release));
590 sut.release[sizeof(sut.release) - 1] = '\0';
591
592 strncpy(sut.version, version, sizeof(sut.version));
593 sut.version[sizeof(sut.version) - 1] = '\0';
594
595 strncpy(sut.machine, machine, sizeof(sut.machine));
596 sut.machine[sizeof(sut.machine) - 1] = '\0';
597
598 return copyout((caddr_t) &sut, (caddr_t)(u_long)SCARG(uap, name),
599 sizeof(struct svr4_utsname));
600 }
601
602
603 int
604 svr4_32_sys_systeminfo(l, v, retval)
605 struct lwp *l;
606 void *v;
607 register_t *retval;
608 {
609 struct svr4_32_sys_systeminfo_args *uap = v;
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 = "sun4m"; /* Lie, pretend we are 4m */
637 break;
638
639 case SVR4_SI_ARCHITECTURE:
640 #if defined(__sparc__)
641 str = "sparc";
642 #else
643 str = machine_arch;
644 #endif
645 break;
646
647 case SVR4_SI_ISALIST:
648 #if defined(__sparc__)
649 str = "sparcv8 sparcv8-fsmuld sparcv7 sparc";
650 #elif defined(__i386__)
651 str = "i386";
652 #else
653 str = "unknown";
654 #endif
655 break;
656
657 case SVR4_SI_HW_SERIAL:
658 snprintf(buf, sizeof(buf), "%lu", hostid);
659 str = buf;
660 break;
661
662 case SVR4_SI_HW_PROVIDER:
663 str = ostype;
664 break;
665
666 case SVR4_SI_SRPC_DOMAIN:
667 str = domainname;
668 break;
669
670 case SVR4_SI_PLATFORM:
671 #if defined(__i386__)
672 str = "i86pc";
673 #elif defined(__sparc__)
674 {
675 extern char machine_model[];
676
677 str = machine_model;
678 }
679 #else
680 str = "unknown";
681 #endif
682 break;
683
684 case SVR4_SI_KERB_REALM:
685 str = "unsupported";
686 break;
687
688 case SVR4_SI_SET_HOSTNAME:
689 if ((error = kauth_authorize_generic(l->l_cred,
690 KAUTH_GENERIC_ISSUSER, &l->l_acflag)) != 0)
691 return error;
692 name[1] = KERN_HOSTNAME;
693 break;
694
695 case SVR4_SI_SET_SRPC_DOMAIN:
696 if ((error = kauth_authorize_generic(l->l_cred,
697 KAUTH_GENERIC_ISSUSER, &l->l_acflag)) != 0)
698 return error;
699 name[1] = KERN_DOMAINNAME;
700 break;
701
702 case SVR4_SI_SET_KERB_REALM:
703 return 0;
704
705 default:
706 DPRINTF(("Bad systeminfo command %d\n", SCARG(uap, what)));
707 return ENOSYS;
708 }
709
710 if (str) {
711 len = strlen(str) + 1;
712 if (len < rlen)
713 rlen = len;
714
715 if (SCARG(uap, buf)) {
716 error = copyout(str, (caddr_t)(u_long)SCARG(uap, buf),
717 rlen);
718 if (error)
719 return error;
720 if (rlen > 0) {
721 /* make sure we are NULL terminated */
722 buf[0] = '\0';
723 error = copyout(buf, &(((caddr_t)(u_long)
724 SCARG(uap, buf))[rlen - 1]), 1);
725 }
726 }
727 else
728 error = 0;
729 }
730 else {
731 error = copyinstr((caddr_t)(u_long)SCARG(uap, buf), buf,
732 sizeof(buf), &len);
733 if (error)
734 return error;
735 name[0] = CTL_KERN;
736 error = old_sysctl(&name[0], 1, 0, 0, buf, len, NULL);
737 }
738
739 *retval = len;
740 return error;
741 }
742
743
744 int
745 svr4_32_sys_utssys(l, v, retval)
746 struct lwp *l;
747 void *v;
748 register_t *retval;
749 {
750 struct svr4_32_sys_utssys_args *uap = v;
751
752 switch (SCARG(uap, sel)) {
753 case 0: /* uname(2) */
754 {
755 struct svr4_32_sys_uname_args ua;
756 SCARG(&ua, name) = SCARG(uap, a1);
757 return svr4_32_sys_uname(l, &ua, retval);
758 }
759
760 case 2: /* ustat(2) */
761 {
762 struct svr4_32_ustat_args ua;
763 SCARG(&ua, dev) = (svr4_32_dev_t) SCARG(uap, a2);
764 SCARG(&ua, name) = SCARG(uap, a1);
765 return svr4_32_ustat(l, &ua, retval);
766 }
767
768 case 3: /* fusers(2) */
769 return ENOSYS;
770
771 default:
772 return ENOSYS;
773 }
774 return ENOSYS;
775 }
776
777
778 int
779 svr4_32_sys_utime(l, v, retval)
780 struct lwp *l;
781 void *v;
782 register_t *retval;
783 {
784 struct svr4_32_sys_utime_args *uap = v;
785 struct proc *p = l->l_proc;
786 struct svr4_32_utimbuf ub;
787 struct timeval tbuf[2];
788 struct sys_utimes_args ap;
789 int error;
790 void *ttp;
791 caddr_t sg = stackgap_init(p, 0);
792
793 ttp = stackgap_alloc(p, &sg, sizeof(tbuf));
794 SCARG(&ap, path) = (const char *)(u_long)SCARG(uap, path);
795 CHECK_ALT_EXIST(l, &sg, SCARG(&ap, path));
796 if (SCARG(uap, ubuf)) {
797 if ((error = copyin((caddr_t)(u_long)SCARG(uap, ubuf),
798 &ub, sizeof(ub))) != 0)
799 return error;
800 tbuf[0].tv_sec = ub.actime;
801 tbuf[0].tv_usec = 0;
802 tbuf[1].tv_sec = ub.modtime;
803 tbuf[1].tv_usec = 0;
804 error = copyout(tbuf, ttp, sizeof(tbuf));
805 if (error)
806 return error;
807 SCARG(&ap, tptr) = ttp;
808 }
809 else
810 SCARG(&ap, tptr) = NULL;
811 return sys_utimes(l, &ap, retval);
812 }
813
814
815 int
816 svr4_32_sys_utimes(l, v, retval)
817 struct lwp *l;
818 void *v;
819 register_t *retval;
820 {
821 struct svr4_32_sys_utimes_args *uap = v;
822 struct proc *p = l->l_proc;
823 struct sys_utimes_args ua;
824 caddr_t sg = stackgap_init(p, 0);
825 SCARG(&ua, path) = (const char *)(u_long)SCARG(uap, path);
826 CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));
827 SCARG(&ua, tptr) = (const struct timeval *)(u_long)SCARG(uap, tptr);
828
829 return sys_utimes(l, &ua, retval);
830 }
831
832
833 static int
834 svr4_32_to_bsd_pathconf(name)
835 int name;
836 {
837 switch (name) {
838 case SVR4_PC_LINK_MAX:
839 return _PC_LINK_MAX;
840
841 case SVR4_PC_MAX_CANON:
842 return _PC_MAX_CANON;
843
844 case SVR4_PC_MAX_INPUT:
845 return _PC_MAX_INPUT;
846
847 case SVR4_PC_NAME_MAX:
848 return _PC_NAME_MAX;
849
850 case SVR4_PC_PATH_MAX:
851 return _PC_PATH_MAX;
852
853 case SVR4_PC_PIPE_BUF:
854 return _PC_PIPE_BUF;
855
856 case SVR4_PC_NO_TRUNC:
857 return _PC_NO_TRUNC;
858
859 case SVR4_PC_VDISABLE:
860 return _PC_VDISABLE;
861
862 case SVR4_PC_CHOWN_RESTRICTED:
863 return _PC_CHOWN_RESTRICTED;
864
865 case SVR4_PC_SYNC_IO:
866 return _PC_SYNC_IO;
867
868 case SVR4_PC_FILESIZEBITS:
869 return _PC_FILESIZEBITS;
870
871 case SVR4_PC_ASYNC_IO:
872 case SVR4_PC_PRIO_IO:
873 /* Not supported */
874 return 0;
875
876 default:
877 /* Invalid */
878 return -1;
879 }
880 }
881
882
883 int
884 svr4_32_sys_pathconf(l, v, retval)
885 struct lwp *l;
886 void *v;
887 register_t *retval;
888 {
889 struct svr4_32_sys_pathconf_args *uap = v;
890 struct proc *p = l->l_proc;
891 struct sys_pathconf_args /* {
892 syscallarg(char *) path;
893 syscallarg(int) name;
894 } */ ua;
895 caddr_t sg = stackgap_init(p, 0);
896
897 SCARG(&ua, path) = (char *)(u_long)SCARG(uap, path);
898
899 CHECK_ALT_EXIST(l, &sg, SCARG(&ua, path));
900
901 SCARG(&ua, name) = svr4_32_to_bsd_pathconf(SCARG(&ua, name));
902
903 switch (SCARG(&ua, name)) {
904 case -1:
905 *retval = -1;
906 return EINVAL;
907 case 0:
908 *retval = 0;
909 return 0;
910 default:
911 return sys_pathconf(l, uap, retval);
912 }
913 }
914
915
916 int
917 svr4_32_sys_fpathconf(l, v, retval)
918 struct lwp *l;
919 void *v;
920 register_t *retval;
921 {
922 struct svr4_32_sys_fpathconf_args *uap = v;
923
924 SCARG(uap, name) = svr4_32_to_bsd_pathconf(SCARG(uap, name));
925
926 switch (SCARG(uap, name)) {
927 case -1:
928 *retval = -1;
929 return EINVAL;
930 case 0:
931 *retval = 0;
932 return 0;
933 default:
934 return sys_fpathconf(l, uap, retval);
935 }
936 }
Cache object: 983ff1107c91a39c8d8da6cb6256ec9d
|