blob: 7da1241717892ed26bc9f5f9b9075d950ab42b93 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3 * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $Id$
30 */
31
32#include "defs.h"
33
34#include <dirent.h>
35
36#include <sys/stat.h>
37#include <fcntl.h>
38
39#ifdef SVR4
40# include <sys/cred.h>
41#endif /* SVR4 */
42
43#include <sys/vfs.h>
44
45#ifdef MAJOR_IN_SYSMACROS
46#include <sys/sysmacros.h>
47#endif
48
49#ifdef MAJOR_IN_MKDEV
50#include <sys/mkdev.h>
51#endif
52
53#ifdef HAVE_SYS_ASYNCH_H
54#include <sys/asynch.h>
55#endif
56
57#ifdef SUNOS4
58#include <ustat.h>
59#endif
60
61/*
62 * This is a really dirty trick but it should always work. Traditional
63 * Unix says r/w/rw are 0/1/2, so we make them true flags 1/2/3 by
64 * adding 1. Just remember to add 1 to any arg decoded with openmodes.
65 */
66struct xlat openmodes[] = {
67 { O_RDWR+1, "O_RDWR" },
68 { O_RDONLY+1, "O_RDONLY" },
69 { O_WRONLY+1, "O_WRONLY" },
70 { O_NONBLOCK, "O_NONBLOCK" },
71 { O_APPEND, "O_APPEND" },
72 { O_CREAT, "O_CREAT" },
73 { O_TRUNC, "O_TRUNC" },
74 { O_EXCL, "O_EXCL" },
75 { O_NOCTTY, "O_NOCTTY" },
76#ifdef O_SYNC
77 { O_SYNC, "O_SYNC" },
78#endif
79#ifdef O_ASYNC
80 { O_ASYNC, "O_ASYNC" },
81#endif
82#ifdef O_DSYNC
83 { O_DSYNC, "O_DSYNC" },
84#endif
85#ifdef O_RSYNC
86 { O_RSYNC, "O_RSYNC" },
87#endif
88#ifdef O_NDELAY
89 { O_NDELAY, "O_NDELAY" },
90#endif
91#ifdef O_PRIV
92 { O_PRIV, "O_PRIV" },
93#endif
94#ifdef O_DIRECT
95 { O_DIRECT, "O_DIRECT" },
96#endif
97#ifdef O_LARGEFILE
98 { O_LARGEFILE, "O_LARGEFILE" },
99#endif
100#ifdef O_DIRECTORY
101 { O_DIRECTORY, "O_DIRECTORY" },
102#endif
103
104#ifdef FNDELAY
105 { FNDELAY, "FNDELAY" },
106#endif
107#ifdef FAPPEND
108 { FAPPEND, "FAPPEND" },
109#endif
110#ifdef FMARK
111 { FMARK, "FMARK" },
112#endif
113#ifdef FDEFER
114 { FDEFER, "FDEFER" },
115#endif
116#ifdef FASYNC
117 { FASYNC, "FASYNC" },
118#endif
119#ifdef FSHLOCK
120 { FSHLOCK, "FSHLOCK" },
121#endif
122#ifdef FEXLOCK
123 { FEXLOCK, "FEXLOCK" },
124#endif
125#ifdef FCREAT
126 { FCREAT, "FCREAT" },
127#endif
128#ifdef FTRUNC
129 { FTRUNC, "FTRUNC" },
130#endif
131#ifdef FEXCL
132 { FEXCL, "FEXCL" },
133#endif
134#ifdef FNBIO
135 { FNBIO, "FNBIO" },
136#endif
137#ifdef FSYNC
138 { FSYNC, "FSYNC" },
139#endif
140#ifdef FNOCTTY
141 { FNOCTTY, "FNOCTTY" },
142#endif
143 { 0, NULL },
144};
145
146int
147sys_open(tcp)
148struct tcb *tcp;
149{
150 if (entering(tcp)) {
151 printpath(tcp, tcp->u_arg[0]);
152 tprintf(", ");
153 /* flags */
154 printflags(openmodes, tcp->u_arg[1] + 1);
155 if (tcp->u_arg[1] & O_CREAT) {
156 /* mode */
157 tprintf(", %#lo", tcp->u_arg[2]);
158 }
159 }
160 return 0;
161}
162
163#ifdef LINUXSPARC
164struct xlat openmodessol[] = {
165 { 0, "O_RDWR" },
166 { 1, "O_RDONLY" },
167 { 2, "O_WRONLY" },
168 { 0x80, "O_NONBLOCK" },
169 { 8, "O_APPEND" },
170 { 0x100, "O_CREAT" },
171 { 0x200, "O_TRUNC" },
172 { 0x400, "O_EXCL" },
173 { 0x800, "O_NOCTTY" },
174 { 0x10, "O_SYNC" },
175 { 0x40, "O_DSYNC" },
176 { 0x8000, "O_RSYNC" },
177 { 4, "O_NDELAY" },
178 { 0x1000, "O_PRIV" },
179 { 0, NULL },
180};
181
182int
183solaris_open(tcp)
184struct tcb *tcp;
185{
186 if (entering(tcp)) {
187 printpath(tcp, tcp->u_arg[0]);
188 tprintf(", ");
189 /* flags */
190 printflags(openmodessol, tcp->u_arg[1] + 1);
191 if (tcp->u_arg[1] & 0x100) {
192 /* mode */
193 tprintf(", %#lo", tcp->u_arg[2]);
194 }
195 }
196 return 0;
197}
198
199#endif
200
201int
202sys_creat(tcp)
203struct tcb *tcp;
204{
205 if (entering(tcp)) {
206 printpath(tcp, tcp->u_arg[0]);
207 tprintf(", %#lo", tcp->u_arg[1]);
208 }
209 return 0;
210}
211
212static struct xlat access_flags[] = {
213 { F_OK, "F_OK", },
214 { R_OK, "R_OK" },
215 { W_OK, "W_OK" },
216 { X_OK, "X_OK" },
217#ifdef EFF_ONLY_OK
218 { EFF_ONLY_OK, "EFF_ONLY_OK" },
219#endif
220#ifdef EX_OK
221 { EX_OK, "EX_OK" },
222#endif
223 { 0, NULL },
224};
225
226int
227sys_access(tcp)
228struct tcb *tcp;
229{
230 if (entering(tcp)) {
231 printpath(tcp, tcp->u_arg[0]);
232 tprintf(", ");
233 printflags(access_flags, tcp->u_arg[1]);
234 }
235 return 0;
236}
237
238int
239sys_umask(tcp)
240struct tcb *tcp;
241{
242 if (entering(tcp)) {
243 tprintf("%#lo", tcp->u_arg[0]);
244 }
245 return RVAL_OCTAL;
246}
247
248static struct xlat whence[] = {
249 { SEEK_SET, "SEEK_SET" },
250 { SEEK_CUR, "SEEK_CUR" },
251 { SEEK_END, "SEEK_END" },
252 { 0, NULL },
253};
254
255int
256sys_lseek(tcp)
257struct tcb *tcp;
258{
259 if (entering(tcp)) {
260 tprintf("%ld, ", tcp->u_arg[0]);
261 if (tcp->u_arg[2] == SEEK_SET)
262 tprintf("%lu, ", tcp->u_arg[1]);
263 else
264 tprintf("%ld, ", tcp->u_arg[1]);
265 printxval(whence, tcp->u_arg[2], "SEEK_???");
266 }
267 return RVAL_UDECIMAL;
268}
269
270#ifdef LINUX
271int
272sys_llseek (tcp)
273struct tcb *tcp;
274{
275 if (entering(tcp)) {
276 if (tcp->u_arg[4] == SEEK_SET)
277 tprintf("%ld, %llu, ", tcp->u_arg[0],
278 (((unsigned long long int) tcp->u_arg[1]) << 32
279 | (unsigned long) tcp->u_arg[2]));
280 else
281 tprintf("%ld, %lld, ", tcp->u_arg[0],
282 (((long long int) tcp->u_arg[1]) << 32
283 | (unsigned long) tcp->u_arg[2]));
284 }
285 else {
286 if (syserror(tcp))
287 tprintf("%#lx, ", tcp->u_arg[3]);
288 else {
289 long long int off;
290 umove(tcp, tcp->u_arg[3], &off);
291 tprintf("{%lld}, ", off);
292 }
293 printxval(whence, tcp->u_arg[4], "SEEK_???");
294 }
295 return 0;
296}
297#endif
298
299int
300sys_truncate(tcp)
301struct tcb *tcp;
302{
303 if (entering(tcp)) {
304 printpath(tcp, tcp->u_arg[0]);
305 tprintf(", %lu", tcp->u_arg[1]);
306 }
307 return 0;
308}
309
310int
311sys_ftruncate(tcp)
312struct tcb *tcp;
313{
314 if (entering(tcp)) {
315 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
316 }
317 return 0;
318}
319
320/* several stats */
321
322static struct xlat modetypes[] = {
323 { S_IFREG, "S_IFREG" },
324 { S_IFSOCK, "S_IFSOCK" },
325 { S_IFIFO, "S_IFIFO" },
326 { S_IFLNK, "S_IFLNK" },
327 { S_IFDIR, "S_IFDIR" },
328 { S_IFBLK, "S_IFBLK" },
329 { S_IFCHR, "S_IFCHR" },
330 { 0, NULL },
331};
332
333static char *
334sprintmode(mode)
335int mode;
336{
337 static char buf[64];
338 char *s;
339
340 if ((mode & S_IFMT) == 0)
341 s = "";
342 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
343 sprintf(buf, "%#o", mode);
344 return buf;
345 }
346 sprintf(buf, "%s%s%s%s", s,
347 (mode & S_ISUID) ? "|S_ISUID" : "",
348 (mode & S_ISGID) ? "|S_ISGID" : "",
349 (mode & S_ISVTX) ? "|S_ISVTX" : "");
350 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
351 if (mode)
352 sprintf(buf + strlen(buf), "|%#o", mode);
353 s = (*buf == '|') ? buf + 1 : buf;
354 return *s ? s : "0";
355}
356
357static char *
358sprinttime(t)
359time_t t;
360{
361 struct tm *tmp;
362 static char buf[32];
363
364 if (t == 0) {
365 sprintf(buf, "0");
366 return buf;
367 }
368 tmp = localtime(&t);
369 sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
370 tmp->tm_year, tmp->tm_mon + 1, tmp->tm_mday,
371 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
372 return buf;
373}
374
375#ifdef LINUXSPARC
376typedef struct {
377 int tv_sec;
378 int tv_nsec;
379} timestruct_t;
380
381struct solstat {
382 unsigned st_dev;
383 int st_pad1[3]; /* network id */
384 unsigned st_ino;
385 unsigned st_mode;
386 unsigned st_nlink;
387 unsigned st_uid;
388 unsigned st_gid;
389 unsigned st_rdev;
390 int st_pad2[2];
391 int st_size;
392 int st_pad3; /* st_size, off_t expansion */
393 timestruct_t st_atime;
394 timestruct_t st_mtime;
395 timestruct_t st_ctime;
396 int st_blksize;
397 int st_blocks;
398 char st_fstype[16];
399 int st_pad4[8]; /* expansion area */
400};
401
402static void
403printstatsol(tcp, addr)
404struct tcb *tcp;
405int addr;
406{
407 struct solstat statbuf;
408
409 if (!addr) {
410 tprintf("NULL");
411 return;
412 }
413 if (syserror(tcp) || !verbose(tcp)) {
414 tprintf("%#x", addr);
415 return;
416 }
417 if (umove(tcp, addr, &statbuf) < 0) {
418 tprintf("{...}");
419 return;
420 }
421 if (!abbrev(tcp)) {
422 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
423 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
424 (unsigned long) (statbuf.st_dev & 0x3ffff),
425 (unsigned long) statbuf.st_ino,
426 sprintmode(statbuf.st_mode));
427 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
428 (unsigned long) statbuf.st_nlink,
429 (unsigned long) statbuf.st_uid,
430 (unsigned long) statbuf.st_gid);
431 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
432 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
433 }
434 else
435 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
436 switch (statbuf.st_mode & S_IFMT) {
437 case S_IFCHR: case S_IFBLK:
438 tprintf("st_rdev=makedev(%lu, %lu), ",
439 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
440 (unsigned long) (statbuf.st_rdev & 0x3ffff));
441 break;
442 default:
443 tprintf("st_size=%u, ", statbuf.st_size);
444 break;
445 }
446 if (!abbrev(tcp)) {
447 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
448 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
449 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
450 }
451 else
452 tprintf("...}");
453}
454#endif
455
456#ifdef LINUXSPARC
457/* Ugly, bug GLIBC makes this necessary. */
458struct kernel_stat
459{
460 unsigned short int st_dev;
461 unsigned long int st_ino;
462 unsigned short int st_mode;
463 short int st_nlink;
464 unsigned short int st_uid;
465 unsigned short int st_gid;
466 unsigned short int st_rdev;
467 long int st_size;
468 long int st_atime;
469 unsigned long int __unused1;
470 long int st_mtime;
471 unsigned long int __unused2;
472 long int st_ctime;
473 unsigned long int __unused3;
474 long int st_blksize;
475 long int st_blocks;
476 unsigned long int __unused4;
477 unsigned long int __unused5;
478};
479#endif
480static void
481printstat(tcp, addr)
482struct tcb *tcp;
483int addr;
484{
485 struct stat statbuf;
486
487#ifdef LINUXSPARC
488 if (current_personality == 1) {
489 printstatsol(tcp, addr);
490 return;
491 }
492#endif /* LINUXSPARC */
493
494 if (!addr) {
495 tprintf("NULL");
496 return;
497 }
498 if (syserror(tcp) || !verbose(tcp)) {
499 tprintf("%#x", addr);
500 return;
501 }
502 if (umove(tcp, addr, &statbuf) < 0) {
503 tprintf("{...}");
504 return;
505 }
506 if (!abbrev(tcp)) {
507 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
508 (unsigned long) major(statbuf.st_dev),
509 (unsigned long) minor(statbuf.st_dev),
510 (unsigned long) statbuf.st_ino,
511 sprintmode(statbuf.st_mode));
512 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
513 (unsigned long) statbuf.st_nlink,
514 (unsigned long) statbuf.st_uid,
515 (unsigned long) statbuf.st_gid);
516#ifdef HAVE_ST_BLKSIZE
517 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
518#endif /* HAVE_ST_BLKSIZE */
519#ifdef HAVE_ST_BLOCKS
520 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
521#endif /* HAVE_ST_BLOCKS */
522 }
523 else
524 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
525 switch (statbuf.st_mode & S_IFMT) {
526 case S_IFCHR: case S_IFBLK:
527#ifdef HAVE_ST_RDEV
528 tprintf("st_rdev=makedev(%lu, %lu), ",
529 (unsigned long) major(statbuf.st_rdev),
530 (unsigned long) minor(statbuf.st_rdev));
531#else /* !HAVE_ST_RDEV */
532 tprintf("st_size=makedev(%lu, %lu), ",
533 (unsigned long) major(statbuf.st_size),
534 (unsigned long) minor(statbuf.st_size));
535#endif /* !HAVE_ST_RDEV */
536 break;
537 default:
538 tprintf("st_size=%lu, ", statbuf.st_size);
539 break;
540 }
541 if (!abbrev(tcp)) {
542 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
543 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
544 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
545 }
546 else
547 tprintf("...}");
548}
549
550int
551sys_stat(tcp)
552struct tcb *tcp;
553{
554 if (entering(tcp)) {
555 printpath(tcp, tcp->u_arg[0]);
556 tprintf(", ");
557 } else {
558 printstat(tcp, tcp->u_arg[1]);
559 }
560 return 0;
561}
562
563int
564sys_fstat(tcp)
565struct tcb *tcp;
566{
567 if (entering(tcp))
568 tprintf("%ld, ", tcp->u_arg[0]);
569 else {
570 printstat(tcp, tcp->u_arg[1]);
571 }
572 return 0;
573}
574
575int
576sys_lstat(tcp)
577struct tcb *tcp;
578{
579 if (entering(tcp)) {
580 printpath(tcp, tcp->u_arg[0]);
581 tprintf(", ");
582 } else {
583 printstat(tcp, tcp->u_arg[1]);
584 }
585 return 0;
586}
587
588#if defined(SVR4) || defined(LINUXSPARC)
589
590int
591sys_xstat(tcp)
592struct tcb *tcp;
593{
594 if (entering(tcp)) {
595 tprintf("%ld, ", tcp->u_arg[0]);
596 printpath(tcp, tcp->u_arg[1]);
597 tprintf(", ");
598 } else {
599 printstat(tcp, tcp->u_arg[2]);
600 }
601 return 0;
602}
603
604int
605sys_fxstat(tcp)
606struct tcb *tcp;
607{
608 if (entering(tcp))
609 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
610 else {
611 printstat(tcp, tcp->u_arg[2]);
612 }
613 return 0;
614}
615
616int
617sys_lxstat(tcp)
618struct tcb *tcp;
619{
620 if (entering(tcp)) {
621 tprintf("%ld, ", tcp->u_arg[0]);
622 printpath(tcp, tcp->u_arg[1]);
623 tprintf(", ");
624 } else {
625 printstat(tcp, tcp->u_arg[2]);
626 }
627 return 0;
628}
629
630int
631sys_xmknod(tcp)
632struct tcb *tcp;
633{
634 int mode = tcp->u_arg[2];
635
636 if (entering(tcp)) {
637 tprintf("%ld, ", tcp->u_arg[0]);
638 printpath(tcp, tcp->u_arg[1]);
639 tprintf(", %s", sprintmode(mode));
640 switch (mode & S_IFMT) {
641 case S_IFCHR: case S_IFBLK:
642#ifdef LINUXSPARC
643 tprintf(", makedev(%lu, %lu)",
644 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
645 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
646#else
647 tprintf(", makedev(%lu, %lu)",
648 (unsigned long) major(tcp->u_arg[3]),
649 (unsigned long) minor(tcp->u_arg[3]));
650#endif
651 break;
652 default:
653 break;
654 }
655 }
656 return 0;
657}
658
659#endif /* SVR4 || LINUXSPARC */
660
661#ifdef LINUX
662
663static struct xlat fsmagic[] = {
664 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
665 { 0xef53, "EXT2_SUPER_MAGIC" },
666 { 0x137d, "EXT_SUPER_MAGIC" },
667 { 0x9660, "ISOFS_SUPER_MAGIC" },
668 { 0x137f, "MINIX_SUPER_MAGIC" },
669 { 0x138f, "MINIX_SUPER_MAGIC2" },
670 { 0x2468, "NEW_MINIX_SUPER_MAGIC" },
671 { 0x4d44, "MSDOS_SUPER_MAGIC" },
672 { 0x6969, "NFS_SUPER_MAGIC" },
673 { 0x9fa0, "PROC_SUPER_MAGIC" },
674 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
675 { 0, NULL },
676};
677
678#endif /* LINUX */
679
680#ifndef SVR4
681
682static char *
683sprintfstype(magic)
684int magic;
685{
686 static char buf[32];
687#ifdef LINUX
688 char *s;
689
690 s = xlookup(fsmagic, magic);
691 if (s) {
692 sprintf(buf, "\"%s\"", s);
693 return buf;
694 }
695#endif /* LINUX */
696 sprintf(buf, "%#x", magic);
697 return buf;
698}
699
700static void
701printstatfs(tcp, addr)
702struct tcb *tcp;
703long addr;
704{
705 struct statfs statbuf;
706
707 if (syserror(tcp) || !verbose(tcp)) {
708 tprintf("%#lx", addr);
709 return;
710 }
711 if (umove(tcp, addr, &statbuf) < 0) {
712 tprintf("{...}");
713 return;
714 }
715#ifdef ALPHA
716
717 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
718 sprintfstype(statbuf.f_type),
719 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
720 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_namelen=%u}",
721 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree, statbuf.f_namelen);
722#else /* !ALPHA */
723 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
724 sprintfstype(statbuf.f_type),
725 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
726 tprintf("f_files=%lu, f_ffree=%lu",
727 statbuf.f_files, statbuf.f_ffree);
728#ifdef LINUX
729 tprintf(", f_namelen=%lu}", statbuf.f_namelen);
730#endif /* LINUX */
731#endif /* !ALPHA */
732 tprintf("}");
733}
734
735int
736sys_statfs(tcp)
737struct tcb *tcp;
738{
739 if (entering(tcp)) {
740 printpath(tcp, tcp->u_arg[0]);
741 tprintf(", ");
742 } else {
743 printstatfs(tcp, tcp->u_arg[1]);
744 }
745 return 0;
746}
747
748int
749sys_fstatfs(tcp)
750struct tcb *tcp;
751{
752 if (entering(tcp)) {
753 tprintf("%lu, ", tcp->u_arg[0]);
754 } else {
755 printstatfs(tcp, tcp->u_arg[1]);
756 }
757 return 0;
758}
759
760#ifdef LINUX
761#ifdef ALPHA
762
763int
764osf_statfs(tcp)
765struct tcb *tcp;
766{
767 if (entering(tcp)) {
768 printpath(tcp, tcp->u_arg[0]);
769 tprintf(", ");
770 } else {
771 printstatfs(tcp, tcp->u_arg[1]);
772 tprintf(", %lu", tcp->u_arg[2]);
773 }
774 return 0;
775}
776
777int
778osf_fstatfs(tcp)
779struct tcb *tcp;
780{
781 if (entering(tcp)) {
782 tprintf("%lu, ", tcp->u_arg[0]);
783 } else {
784 printstatfs(tcp, tcp->u_arg[1]);
785 tprintf(", %lu", tcp->u_arg[2]);
786 }
787 return 0;
788}
789#endif /* ALPHA */
790#endif /* LINUX */
791
792#endif /* !SVR4 */
793
794#ifdef SUNOS4
795
796int
797sys_ustat(tcp)
798struct tcb *tcp;
799{
800 struct ustat statbuf;
801
802 if (entering(tcp)) {
803 tprintf("makedev(%lu, %lu), ",
804 (long) major(tcp->u_arg[0]),
805 (long) minor(tcp->u_arg[0]));
806 }
807 else {
808 if (syserror(tcp) || !verbose(tcp))
809 tprintf("%#lx", tcp->u_arg[1]);
810 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
811 tprintf("{...}");
812 else {
813 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
814 statbuf.f_tfree, statbuf.f_tinode);
815 tprintf("f_fname=\"%.*s\", ",
816 (int) sizeof(statbuf.f_fname),
817 statbuf.f_fname);
818 tprintf("f_fpack=\"%.*s\"}",
819 (int) sizeof(statbuf.f_fpack),
820 statbuf.f_fpack);
821 }
822 }
823 return 0;
824}
825
826#endif /* SUNOS4 */
827
828/* directory */
829int
830sys_chdir(tcp)
831struct tcb *tcp;
832{
833 if (entering(tcp)) {
834 printpath(tcp, tcp->u_arg[0]);
835 }
836 return 0;
837}
838
839int
840sys_mkdir(tcp)
841struct tcb *tcp;
842{
843 if (entering(tcp)) {
844 printpath(tcp, tcp->u_arg[0]);
845 tprintf(", %#lo", tcp->u_arg[1]);
846 }
847 return 0;
848}
849
850int
851sys_rmdir(tcp)
852struct tcb *tcp;
853{
854 if (entering(tcp)) {
855 printpath(tcp, tcp->u_arg[0]);
856 }
857 return 0;
858}
859
860int
861sys_fchdir(tcp)
862struct tcb *tcp;
863{
864 if (entering(tcp)) {
865 tprintf("%ld", tcp->u_arg[0]);
866 }
867 return 0;
868}
869
870int
871sys_chroot(tcp)
872struct tcb *tcp;
873{
874 if (entering(tcp)) {
875 printpath(tcp, tcp->u_arg[0]);
876 }
877 return 0;
878}
879
880int
881sys_fchroot(tcp)
882struct tcb *tcp;
883{
884 if (entering(tcp)) {
885 tprintf("%ld", tcp->u_arg[0]);
886 }
887 return 0;
888}
889
890int
891sys_link(tcp)
892struct tcb *tcp;
893{
894 if (entering(tcp)) {
895 printpath(tcp, tcp->u_arg[0]);
896 tprintf(", ");
897 printpath(tcp, tcp->u_arg[1]);
898 }
899 return 0;
900}
901
902int
903sys_unlink(tcp)
904struct tcb *tcp;
905{
906 if (entering(tcp)) {
907 printpath(tcp, tcp->u_arg[0]);
908 }
909 return 0;
910}
911
912int
913sys_symlink(tcp)
914struct tcb *tcp;
915{
916 if (entering(tcp)) {
917 printpath(tcp, tcp->u_arg[0]);
918 tprintf(", ");
919 printpath(tcp, tcp->u_arg[1]);
920 }
921 return 0;
922}
923
924int
925sys_readlink(tcp)
926struct tcb *tcp;
927{
928 if (entering(tcp)) {
929 printpath(tcp, tcp->u_arg[0]);
930 tprintf(", ");
931 } else {
932 if (syserror(tcp))
933 tprintf("%#lx", tcp->u_arg[1]);
934 else
935 printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
936 tprintf(", %lu", tcp->u_arg[2]);
937 }
938 return 0;
939}
940
941int
942sys_rename(tcp)
943struct tcb *tcp;
944{
945 if (entering(tcp)) {
946 printpath(tcp, tcp->u_arg[0]);
947 tprintf(", ");
948 printpath(tcp, tcp->u_arg[1]);
949 }
950 return 0;
951}
952
953int
954sys_chown(tcp)
955struct tcb *tcp;
956{
957 if (entering(tcp)) {
958 printpath(tcp, tcp->u_arg[0]);
959 tprintf(", %lu, %lu", tcp->u_arg[1], tcp->u_arg[2]);
960 }
961 return 0;
962}
963
964int
965sys_fchown(tcp)
966struct tcb *tcp;
967{
968 if (entering(tcp)) {
969 tprintf("%ld, %lu, %lu",
970 tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
971 }
972 return 0;
973}
974
975int
976sys_chmod(tcp)
977struct tcb *tcp;
978{
979 if (entering(tcp)) {
980 printpath(tcp, tcp->u_arg[0]);
981 tprintf(", %#lo", tcp->u_arg[1]);
982 }
983 return 0;
984}
985
986int
987sys_fchmod(tcp)
988struct tcb *tcp;
989{
990 if (entering(tcp)) {
991 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
992 }
993 return 0;
994}
995
996int
997sys_utimes(tcp)
998struct tcb *tcp;
999{
1000 if (entering(tcp)) {
1001 printpath(tcp, tcp->u_arg[0]);
1002 tprintf(", ");
1003 printtv(tcp, tcp->u_arg[1]);
1004 }
1005 return 0;
1006}
1007
1008int
1009sys_utime(tcp)
1010struct tcb *tcp;
1011{
1012 long ut[2];
1013
1014 if (entering(tcp)) {
1015 printpath(tcp, tcp->u_arg[0]);
1016 tprintf(", ");
1017 if (!tcp->u_arg[1])
1018 tprintf("NULL");
1019 else if (!verbose(tcp))
1020 tprintf("%#lx", tcp->u_arg[1]);
1021 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
1022 (char *) ut) < 0)
1023 tprintf("[?, ?]");
1024 else {
1025 tprintf("[%s,", sprinttime(ut[0]));
1026 tprintf(" %s]", sprinttime(ut[1]));
1027 }
1028 }
1029 return 0;
1030}
1031
1032int
1033sys_mknod(tcp)
1034struct tcb *tcp;
1035{
1036 int mode = tcp->u_arg[1];
1037
1038 if (entering(tcp)) {
1039 printpath(tcp, tcp->u_arg[0]);
1040 tprintf(", %s", sprintmode(mode));
1041 switch (mode & S_IFMT) {
1042 case S_IFCHR: case S_IFBLK:
1043#ifdef LINUXSPARC
1044 if (current_personality == 1)
1045 tprintf(", makedev(%lu, %lu)",
1046 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
1047 (unsigned long) (tcp->u_arg[2] & 0x3ffff));
1048 else
1049#endif
1050 tprintf(", makedev(%lu, %lu)",
1051 (unsigned long) major(tcp->u_arg[2]),
1052 (unsigned long) minor(tcp->u_arg[2]));
1053 break;
1054 default:
1055 break;
1056 }
1057 }
1058 return 0;
1059}
1060
1061int
1062sys_mkfifo(tcp)
1063struct tcb *tcp;
1064{
1065 if (entering(tcp)) {
1066 printpath(tcp, tcp->u_arg[0]);
1067 tprintf(", %#lo", tcp->u_arg[1]);
1068 }
1069 return 0;
1070}
1071
1072int
1073sys_fsync(tcp)
1074struct tcb *tcp;
1075{
1076 if (entering(tcp)) {
1077 tprintf("%ld", tcp->u_arg[0]);
1078 }
1079 return 0;
1080}
1081
1082#ifdef LINUX
1083
1084static void
1085printdir(tcp, addr)
1086struct tcb *tcp;
1087long addr;
1088{
1089 struct dirent d;
1090
1091 if (!verbose(tcp)) {
1092 tprintf("%#lx", addr);
1093 return;
1094 }
1095 if (umove(tcp, addr, &d) < 0) {
1096 tprintf("{...}");
1097 return;
1098 }
1099 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
1100#ifndef LINUX
1101 /* This contains garbage under Linux. */
1102 tprintf("d_off=%d, ", d.d_off);
1103#endif /* !LINUX */
1104#ifndef LINUX
1105 /* No point in printing this out since the syscall returns it. */
1106 tprintf("d_reclen=%u, ", d.d_reclen);
1107#endif /* !LINUX */
1108 tprintf("d_name=");
1109 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
1110 tprintf("}");
1111}
1112
1113int
1114sys_readdir(tcp)
1115struct tcb *tcp;
1116{
1117 if (entering(tcp)) {
1118 tprintf("%lu, ", tcp->u_arg[0]);
1119 } else {
1120 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
1121 tprintf("%#lx", tcp->u_arg[1]);
1122 else
1123 printdir(tcp, tcp->u_arg[1]);
1124 /* Not much point in printing this out, it is always 1. */
1125 if (tcp->u_arg[2] != 1)
1126 tprintf(", %lu", tcp->u_arg[2]);
1127 }
1128 return 0;
1129}
1130
1131#endif /* LINUX */
1132
1133int
1134sys_getdents(tcp)
1135struct tcb *tcp;
1136{
1137 int i, len, dents = 0;
1138 char *buf;
1139
1140 if (entering(tcp)) {
1141 tprintf("%lu, ", tcp->u_arg[0]);
1142 return 0;
1143 }
1144 if (syserror(tcp) || !verbose(tcp)) {
1145 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1146 return 0;
1147 }
1148#ifdef linux
1149#ifdef __sparc__
1150 tprintf (" = Unknown value\n");
1151 return 0;
1152#endif
1153#endif
1154 len = tcp->u_rval;
1155 if ((buf = malloc(len)) == NULL) {
1156 tprintf("out of memory\n");
1157 return 0;
1158 }
1159 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1160 tprintf("{...}, %lu", tcp->u_arg[2]);
1161 free(buf);
1162 return 0;
1163 }
1164 if (!abbrev(tcp))
1165 tprintf("{");
1166 for (i = 0; i < len;) {
1167 struct dirent *d = (struct dirent *) &buf[i];
1168#ifdef LINUX
1169 if (!abbrev(tcp)) {
1170 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1171 i ? " " : "", d->d_ino, d->d_off);
1172 tprintf("d_reclen=%u, d_name=\"%s\"}",
1173 d->d_reclen, d->d_name);
1174 }
1175#endif /* LINUX */
1176#ifdef SVR4
1177 if (!abbrev(tcp)) {
1178 tprintf("%s{d_ino=%lu, d_off=%lu, ",
1179 i ? " " : "", d->d_ino, d->d_off);
1180 tprintf("d_reclen=%u, d_name=\"%s\"}",
1181 d->d_reclen, d->d_name);
1182 }
1183#endif /* SVR4 */
1184#ifdef SUNOS4
1185 if (!abbrev(tcp)) {
1186 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
1187 i ? " " : "", d->d_off, d->d_fileno,
1188 d->d_reclen);
1189 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
1190 d->d_namlen, d->d_namlen, d->d_name);
1191 }
1192#endif /* SUNOS4 */
1193 i += d->d_reclen;
1194 dents++;
1195 }
1196 if (!abbrev(tcp))
1197 tprintf("}");
1198 else
1199 tprintf("/* %u entries */", dents);
1200 tprintf(", %lu", tcp->u_arg[2]);
1201 free(buf);
1202 return 0;
1203}
1204
1205#ifdef LINUX
1206
1207int
1208sys_getcwd(tcp)
1209struct tcb *tcp;
1210{
1211 if (exiting(tcp)) {
1212 if (syserror(tcp))
1213 tprintf("%#lx", tcp->u_arg[0]);
1214 else
1215 printstr(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1216 tprintf(", %lu", tcp->u_arg[1]);
1217 }
1218 return 0;
1219}
1220#endif /* LINUX */
1221
1222#ifdef HAVE_SYS_ASYNCH_H
1223
1224int
1225sys_aioread(tcp)
1226struct tcb *tcp;
1227{
1228 struct aio_result_t res;
1229
1230 if (entering(tcp)) {
1231 tprintf("%lu, ", tcp->u_arg[0]);
1232 } else {
1233 if (syserror(tcp))
1234 tprintf("%#lx", tcp->u_arg[1]);
1235 else
1236 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1237 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
1238 printxval(whence, tcp->u_arg[4], "L_???");
1239 if (syserror(tcp) || tcp->u_arg[5] == 0
1240 || umove(tcp, tcp->u_arg[5], &res) < 0)
1241 tprintf(", %#lx", tcp->u_arg[5]);
1242 else
1243 tprintf(", {aio_return %d aio_errno %d}",
1244 res.aio_return, res.aio_errno);
1245 }
1246 return 0;
1247}
1248
1249int
1250sys_aiowrite(tcp)
1251struct tcb *tcp;
1252{
1253 struct aio_result_t res;
1254
1255 if (entering(tcp)) {
1256 tprintf("%lu, ", tcp->u_arg[0]);
1257 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1258 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
1259 printxval(whence, tcp->u_arg[4], "L_???");
1260 }
1261 else {
1262 if (tcp->u_arg[5] == 0)
1263 tprintf(", NULL");
1264 else if (syserror(tcp)
1265 || umove(tcp, tcp->u_arg[5], &res) < 0)
1266 tprintf(", %#lx", tcp->u_arg[5]);
1267 else
1268 tprintf(", {aio_return %d aio_errno %d}",
1269 res.aio_return, res.aio_errno);
1270 }
1271 return 0;
1272}
1273
1274int
1275sys_aiowait(tcp)
1276struct tcb *tcp;
1277{
1278 if (entering(tcp))
1279 printtv(tcp, tcp->u_arg[0]);
1280 return 0;
1281}
1282
1283int
1284sys_aiocancel(tcp)
1285struct tcb *tcp;
1286{
1287 struct aio_result_t res;
1288
1289 if (exiting(tcp)) {
1290 if (tcp->u_arg[0] == 0)
1291 tprintf("NULL");
1292 else if (syserror(tcp)
1293 || umove(tcp, tcp->u_arg[0], &res) < 0)
1294 tprintf("%#lx", tcp->u_arg[0]);
1295 else
1296 tprintf("{aio_return %d aio_errno %d}",
1297 res.aio_return, res.aio_errno);
1298 }
1299 return 0;
1300}
1301
1302#endif /* HAVE_SYS_ASYNCH_H */