]> granicus.if.org Git - strace/blob - file.c
e4780b5fa3b71263e627346c01ce45583f0a6992
[strace] / file.c
1 /*
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  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  *      $Id$
31  */
32
33 #include "defs.h"
34
35 #include <dirent.h>
36 #ifdef linux
37 #define dirent kernel_dirent
38 #include <linux/types.h>
39 #include <linux/dirent.h>
40 #undef dirent
41 #else
42 #define kernel_dirent dirent
43 #endif
44
45 #ifdef linux
46 #  ifdef LINUXSPARC
47 struct stat {
48         unsigned short  st_dev;
49         unsigned int    st_ino;
50         unsigned short  st_mode;
51         short           st_nlink;
52         unsigned short  st_uid;
53         unsigned short  st_gid;
54         unsigned short  st_rdev;
55         unsigned int    st_size;
56         int             st_atime;
57         unsigned int    __unused1;
58         int             st_mtime;
59         unsigned int    __unused2;
60         int             st_ctime;
61         unsigned int    __unused3;
62         int             st_blksize;
63         int             st_blocks;
64         unsigned int    __unused4[2];
65 };
66 #    define stat kernel_stat
67 #    include <asm/stat.h>
68 #    undef stat
69 #  else
70 #    undef dev_t
71 #    undef ino_t
72 #    undef mode_t
73 #    undef nlink_t
74 #    undef uid_t
75 #    undef gid_t
76 #    undef off_t
77 #    undef loff_t
78
79 #    define dev_t __kernel_dev_t
80 #    define ino_t __kernel_ino_t
81 #    define mode_t __kernel_mode_t
82 #    define nlink_t __kernel_nlink_t
83 #    define uid_t __kernel_uid_t
84 #    define gid_t __kernel_gid_t
85 #    define off_t __kernel_off_t
86 #    define loff_t __kernel_loff_t
87
88 #    include <asm/stat.h>
89
90 #    undef dev_t
91 #    undef ino_t
92 #    undef mode_t
93 #    undef nlink_t
94 #    undef uid_t
95 #    undef gid_t
96 #    undef off_t
97 #    undef loff_t
98
99 #    define dev_t dev_t
100 #    define ino_t ino_t
101 #    define mode_t mode_t
102 #    define nlink_t nlink_t
103 #    define uid_t uid_t
104 #    define gid_t gid_t
105 #    define off_t off_t
106 #    define loff_t loff_t
107 #  endif
108 #  define stat libc_stat
109 #  define stat64 libc_stat64
110 #  include <sys/stat.h>
111 #  undef stat
112 #  undef stat64
113 #else
114 #  include <sys/stat.h>
115 #endif
116
117 #include <fcntl.h>
118
119 #ifdef SVR4
120 #  include <sys/cred.h>
121 #endif /* SVR4 */
122
123 #include <sys/vfs.h>
124
125 #ifdef MAJOR_IN_SYSMACROS
126 #include <sys/sysmacros.h>
127 #endif
128
129 #ifdef MAJOR_IN_MKDEV
130 #include <sys/mkdev.h>
131 #endif
132
133 #ifdef HAVE_SYS_ASYNCH_H
134 #include <sys/asynch.h>
135 #endif
136
137 #ifdef SUNOS4
138 #include <ustat.h>
139 #endif
140
141 /*
142  * This is a really dirty trick but it should always work.  Traditional
143  * Unix says r/w/rw are 0/1/2, so we make them true flags 1/2/3 by
144  * adding 1.  Just remember to add 1 to any arg decoded with openmodes.
145  */
146 struct xlat openmodes[] = {
147         { O_RDWR+1,     "O_RDWR"        },
148         { O_RDONLY+1,   "O_RDONLY"      },
149         { O_WRONLY+1,   "O_WRONLY"      },
150         { O_NONBLOCK,   "O_NONBLOCK"    },
151         { O_APPEND,     "O_APPEND"      },
152         { O_CREAT,      "O_CREAT"       },
153         { O_TRUNC,      "O_TRUNC"       },
154         { O_EXCL,       "O_EXCL"        },
155         { O_NOCTTY,     "O_NOCTTY"      },
156 #ifdef O_SYNC
157         { O_SYNC,       "O_SYNC"        },
158 #endif
159 #ifdef O_ASYNC
160         { O_ASYNC,      "O_ASYNC"       },
161 #endif
162 #ifdef O_DSYNC
163         { O_DSYNC,      "O_DSYNC"       },
164 #endif
165 #ifdef O_RSYNC
166         { O_RSYNC,      "O_RSYNC"       },
167 #endif
168 #ifdef O_NDELAY
169         { O_NDELAY,     "O_NDELAY"      },
170 #endif
171 #ifdef O_PRIV
172         { O_PRIV,       "O_PRIV"        },
173 #endif
174 #ifdef O_DIRECT
175    { O_DIRECT, "O_DIRECT"  },
176 #endif
177 #ifdef O_LARGEFILE
178    { O_LARGEFILE,  "O_LARGEFILE"   },
179 #endif
180 #ifdef O_DIRECTORY
181    { O_DIRECTORY,  "O_DIRECTORY"   },
182 #endif
183
184 #ifdef FNDELAY
185         { FNDELAY,      "FNDELAY"       },
186 #endif
187 #ifdef FAPPEND
188         { FAPPEND,      "FAPPEND"       },
189 #endif
190 #ifdef FMARK
191         { FMARK,        "FMARK"         },
192 #endif
193 #ifdef FDEFER
194         { FDEFER,       "FDEFER"        },
195 #endif
196 #ifdef FASYNC
197         { FASYNC,       "FASYNC"        },
198 #endif
199 #ifdef FSHLOCK
200         { FSHLOCK,      "FSHLOCK"       },
201 #endif
202 #ifdef FEXLOCK
203         { FEXLOCK,      "FEXLOCK"       },
204 #endif
205 #ifdef FCREAT
206         { FCREAT,       "FCREAT"        },
207 #endif
208 #ifdef FTRUNC
209         { FTRUNC,       "FTRUNC"        },
210 #endif
211 #ifdef FEXCL
212         { FEXCL,        "FEXCL"         },
213 #endif
214 #ifdef FNBIO
215         { FNBIO,        "FNBIO"         },
216 #endif
217 #ifdef FSYNC
218         { FSYNC,        "FSYNC"         },
219 #endif
220 #ifdef FNOCTTY
221         { FNOCTTY,      "FNOCTTY"       },
222 #endif
223         { 0,            NULL            },
224 };
225
226 int
227 sys_open(tcp)
228 struct tcb *tcp;
229 {
230         if (entering(tcp)) {
231                 printpath(tcp, tcp->u_arg[0]);
232                 tprintf(", ");
233                 /* flags */
234                 printflags(openmodes, tcp->u_arg[1] + 1);
235                 if (tcp->u_arg[1] & O_CREAT) {
236                         /* mode */
237                         tprintf(", %#lo", tcp->u_arg[2]);
238                 }
239         }
240         return 0;
241 }
242
243 #ifdef LINUXSPARC
244 struct xlat openmodessol[] = {
245         { 0,            "O_RDWR"        },
246         { 1,            "O_RDONLY"      },
247         { 2,            "O_WRONLY"      },
248         { 0x80,         "O_NONBLOCK"    },
249         { 8,            "O_APPEND"      },
250         { 0x100,        "O_CREAT"       },
251         { 0x200,        "O_TRUNC"       },
252         { 0x400,        "O_EXCL"        },
253         { 0x800,        "O_NOCTTY"      },
254         { 0x10,         "O_SYNC"        },
255         { 0x40,         "O_DSYNC"       },
256         { 0x8000,       "O_RSYNC"       },
257         { 4,            "O_NDELAY"      },
258         { 0x1000,       "O_PRIV"        },
259         { 0,            NULL            },
260 };
261
262 int
263 solaris_open(tcp)
264 struct tcb *tcp;
265 {
266         if (entering(tcp)) {
267                 printpath(tcp, tcp->u_arg[0]);
268                 tprintf(", ");
269                 /* flags */
270                 printflags(openmodessol, tcp->u_arg[1] + 1);
271                 if (tcp->u_arg[1] & 0x100) {
272                         /* mode */
273                         tprintf(", %#lo", tcp->u_arg[2]);
274                 }
275         }
276         return 0;
277 }
278
279 #endif
280
281 int
282 sys_creat(tcp)
283 struct tcb *tcp;
284 {
285         if (entering(tcp)) {
286                 printpath(tcp, tcp->u_arg[0]);
287                 tprintf(", %#lo", tcp->u_arg[1]);
288         }
289         return 0;
290 }
291
292 static struct xlat access_flags[] = {
293         { F_OK,         "F_OK",         },
294         { R_OK,         "R_OK"          },
295         { W_OK,         "W_OK"          },
296         { X_OK,         "X_OK"          },
297 #ifdef EFF_ONLY_OK
298         { EFF_ONLY_OK,  "EFF_ONLY_OK"   },
299 #endif
300 #ifdef EX_OK
301         { EX_OK,        "EX_OK"         },
302 #endif
303         { 0,            NULL            },
304 };
305
306 int
307 sys_access(tcp)
308 struct tcb *tcp;
309 {
310         if (entering(tcp)) {
311                 printpath(tcp, tcp->u_arg[0]);
312                 tprintf(", ");
313                 printflags(access_flags, tcp->u_arg[1]);
314         }
315         return 0;
316 }
317
318 int
319 sys_umask(tcp)
320 struct tcb *tcp;
321 {
322         if (entering(tcp)) {
323                 tprintf("%#lo", tcp->u_arg[0]);
324         }
325         return RVAL_OCTAL;
326 }
327
328 static struct xlat whence[] = {
329         { SEEK_SET,     "SEEK_SET"      },
330         { SEEK_CUR,     "SEEK_CUR"      },
331         { SEEK_END,     "SEEK_END"      },
332         { 0,            NULL            },
333 };
334
335 int
336 sys_lseek(tcp)
337 struct tcb *tcp;
338 {
339         if (entering(tcp)) {
340                 tprintf("%ld, ", tcp->u_arg[0]);
341                 if (tcp->u_arg[2] == SEEK_SET)
342                         tprintf("%lu, ", tcp->u_arg[1]);
343                 else
344                         tprintf("%ld, ", tcp->u_arg[1]);
345                 printxval(whence, tcp->u_arg[2], "SEEK_???");
346         }
347         return RVAL_UDECIMAL;
348 }
349
350 #ifdef linux
351 int
352 sys_llseek (tcp)
353 struct tcb *tcp;
354 {
355     if (entering(tcp)) {
356         if (tcp->u_arg[4] == SEEK_SET)
357             tprintf("%ld, %llu, ", tcp->u_arg[0],
358                     (((long long int) tcp->u_arg[1]) << 32
359                      | (unsigned long long) tcp->u_arg[2]));
360         else
361             tprintf("%ld, %lld, ", tcp->u_arg[0],
362                     (((long long int) tcp->u_arg[1]) << 32
363                      | (unsigned long long) tcp->u_arg[2]));
364     }
365     else {
366         long long int off;
367         if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
368             tprintf("%#lx, ", tcp->u_arg[3]);
369         else
370             tprintf("[%llu], ", off);
371         printxval(whence, tcp->u_arg[4], "SEEK_???");
372     }
373     return 0;
374 }
375 #endif
376
377 int
378 sys_truncate(tcp)
379 struct tcb *tcp;
380 {
381         if (entering(tcp)) {
382                 printpath(tcp, tcp->u_arg[0]);
383                 tprintf(", %lu", tcp->u_arg[1]);
384         }
385         return 0;
386 }
387
388 int
389 sys_ftruncate(tcp)
390 struct tcb *tcp;
391 {
392         if (entering(tcp)) {
393                 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
394         }
395         return 0;
396 }
397
398 /* several stats */
399
400 static struct xlat modetypes[] = {
401         { S_IFREG,      "S_IFREG"       },
402         { S_IFSOCK,     "S_IFSOCK"      },
403         { S_IFIFO,      "S_IFIFO"       },
404         { S_IFLNK,      "S_IFLNK"       },
405         { S_IFDIR,      "S_IFDIR"       },
406         { S_IFBLK,      "S_IFBLK"       },
407         { S_IFCHR,      "S_IFCHR"       },
408         { 0,            NULL            },
409 };
410
411 static char *
412 sprintmode(mode)
413 int mode;
414 {
415         static char buf[64];
416         char *s;
417
418         if ((mode & S_IFMT) == 0)
419                 s = "";
420         else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
421                 sprintf(buf, "%#o", mode);
422                 return buf;
423         }
424         sprintf(buf, "%s%s%s%s", s,
425                 (mode & S_ISUID) ? "|S_ISUID" : "",
426                 (mode & S_ISGID) ? "|S_ISGID" : "",
427                 (mode & S_ISVTX) ? "|S_ISVTX" : "");
428         mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
429         if (mode)
430                 sprintf(buf + strlen(buf), "|%#o", mode);
431         s = (*buf == '|') ? buf + 1 : buf;
432         return *s ? s : "0";
433 }
434
435 static char *
436 sprinttime(t)
437 time_t t;
438 {
439         struct tm *tmp;
440         static char buf[32];
441
442         if (t == 0) {
443                 sprintf(buf, "0");
444                 return buf;
445         }
446         tmp = localtime(&t);
447         sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
448                 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
449                 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
450         return buf;
451 }
452
453 #ifdef LINUXSPARC
454 typedef struct {
455         int     tv_sec;
456         int     tv_nsec;
457 } timestruct_t;
458
459 struct solstat {
460         unsigned        st_dev;
461         int             st_pad1[3];     /* network id */
462         unsigned        st_ino;
463         unsigned        st_mode;
464         unsigned        st_nlink;
465         unsigned        st_uid;
466         unsigned        st_gid;
467         unsigned        st_rdev;
468         int             st_pad2[2];
469         int             st_size;
470         int             st_pad3;        /* st_size, off_t expansion */
471         timestruct_t    st_atime;
472         timestruct_t    st_mtime;
473         timestruct_t    st_ctime;
474         int             st_blksize;
475         int             st_blocks;
476         char            st_fstype[16];
477         int             st_pad4[8];     /* expansion area */
478 };
479
480 static void
481 printstatsol(tcp, addr)
482 struct tcb *tcp;
483 long addr;
484 {
485         struct solstat statbuf;
486
487         if (!addr) {
488                 tprintf("NULL");
489                 return;
490         }
491         if (syserror(tcp) || !verbose(tcp)) {
492                 tprintf("%#lx", addr);
493                 return;
494         }
495         if (umove(tcp, addr, &statbuf) < 0) {
496                 tprintf("{...}");
497                 return;
498         }
499         if (!abbrev(tcp)) {
500                 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
501                         (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
502                         (unsigned long) (statbuf.st_dev & 0x3ffff),
503                         (unsigned long) statbuf.st_ino,
504                         sprintmode(statbuf.st_mode));
505                 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
506                         (unsigned long) statbuf.st_nlink,
507                         (unsigned long) statbuf.st_uid,
508                         (unsigned long) statbuf.st_gid);
509                 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
510                 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
511         }
512         else
513                 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
514         switch (statbuf.st_mode & S_IFMT) {
515         case S_IFCHR: case S_IFBLK:
516                 tprintf("st_rdev=makedev(%lu, %lu), ",
517                         (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
518                         (unsigned long) (statbuf.st_rdev & 0x3ffff));
519                 break;
520         default:
521                 tprintf("st_size=%u, ", statbuf.st_size);
522                 break;
523         }
524         if (!abbrev(tcp)) {
525                 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
526                 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
527                 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
528         }
529         else
530                 tprintf("...}");
531 }
532 #endif /* LINUXSPARC */
533
534 static void
535 realprintstat(tcp, statbuf)
536 struct tcb *tcp;
537 struct stat *statbuf;
538 {
539     if (!abbrev(tcp)) {
540             tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
541                     (unsigned long) major(statbuf->st_dev),
542                     (unsigned long) minor(statbuf->st_dev),
543                     (unsigned long) statbuf->st_ino,
544                     sprintmode(statbuf->st_mode));
545             tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
546                     (unsigned long) statbuf->st_nlink,
547                     (unsigned long) statbuf->st_uid,
548                     (unsigned long) statbuf->st_gid);
549 #ifdef HAVE_ST_BLKSIZE
550             tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
551 #endif /* HAVE_ST_BLKSIZE */
552 #ifdef HAVE_ST_BLOCKS
553             tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
554 #endif /* HAVE_ST_BLOCKS */
555     }
556     else
557             tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
558     switch (statbuf->st_mode & S_IFMT) {
559     case S_IFCHR: case S_IFBLK:
560 #ifdef HAVE_ST_RDEV
561             tprintf("st_rdev=makedev(%lu, %lu), ",
562                     (unsigned long) major(statbuf->st_rdev),
563                     (unsigned long) minor(statbuf->st_rdev));
564 #else /* !HAVE_ST_RDEV */
565             tprintf("st_size=makedev(%lu, %lu), ",
566                     (unsigned long) major(statbuf->st_size),
567                     (unsigned long) minor(statbuf->st_size));
568 #endif /* !HAVE_ST_RDEV */
569             break;
570     default:
571             tprintf("st_size=%lu, ", statbuf->st_size);
572             break;
573     }
574     if (!abbrev(tcp)) {
575             tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
576             tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
577             tprintf("st_ctime=%s}", sprinttime(statbuf->st_ctime));
578     }
579     else
580             tprintf("...}");
581 }
582
583
584 static void
585 printstat(tcp, addr)
586 struct tcb *tcp;
587 long addr;
588 {
589         struct stat statbuf;
590
591 #ifdef LINUXSPARC
592         if (current_personality == 1) {
593                 printstatsol(tcp, addr);
594                 return;
595         }
596 #endif /* LINUXSPARC */
597
598         if (!addr) {
599                 tprintf("NULL");
600                 return;
601         }
602         if (syserror(tcp) || !verbose(tcp)) {
603                 tprintf("%#lx", addr);
604                 return;
605         }
606         if (umove(tcp, addr, &statbuf) < 0) {
607                 tprintf("{...}");
608                 return;
609         }
610
611         realprintstat(tcp, &statbuf);
612 }
613
614 #ifdef HAVE_STAT64
615 static void
616 printstat64(tcp, addr)
617 struct tcb *tcp;
618 long addr;
619 {
620         struct stat64 statbuf;
621
622 #ifdef LINUXSPARC
623         if (current_personality == 1) {
624                 printstatsol(tcp, addr);
625                 return;
626         }
627 #endif /* LINUXSPARC */
628
629         if (!addr) {
630                 tprintf("NULL");
631                 return;
632         }
633         if (syserror(tcp) || !verbose(tcp)) {
634                 tprintf("%#lx", addr);
635                 return;
636         }
637         if (umove(tcp, addr, &statbuf) < 0) {
638                 tprintf("{...}");
639                 return;
640         }
641
642         if (!abbrev(tcp)) {
643                 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
644                         (unsigned long) major(statbuf.st_dev),
645                         (unsigned long) minor(statbuf.st_dev),
646                         (unsigned long) statbuf.st_ino,
647                         sprintmode(statbuf.st_mode));
648                 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
649                         (unsigned long) statbuf.st_nlink,
650                         (unsigned long) statbuf.st_uid,
651                         (unsigned long) statbuf.st_gid);
652 #ifdef HAVE_ST_BLKSIZE
653                 tprintf("st_blksize=%lu, ",
654                         (unsigned long) statbuf.st_blksize);
655 #endif /* HAVE_ST_BLKSIZE */
656 #ifdef HAVE_ST_BLOCKS
657                 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
658 #endif /* HAVE_ST_BLOCKS */
659         }
660         else
661                 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
662         switch (statbuf.st_mode & S_IFMT) {
663         case S_IFCHR: case S_IFBLK:
664 #ifdef HAVE_ST_RDEV
665                 tprintf("st_rdev=makedev(%lu, %lu), ",
666                         (unsigned long) major(statbuf.st_rdev),
667                         (unsigned long) minor(statbuf.st_rdev));
668 #else /* !HAVE_ST_RDEV */
669                 tprintf("st_size=makedev(%lu, %lu), ",
670                         (unsigned long) major(statbuf.st_size),
671                         (unsigned long) minor(statbuf.st_size));
672 #endif /* !HAVE_ST_RDEV */
673                 break;
674         default:
675                 tprintf("st_size=%llu, ", statbuf.st_size);
676                 break;
677         }
678         if (!abbrev(tcp)) {
679                 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
680                 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
681                 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
682         }
683         else
684                 tprintf("...}");
685 }
686 #endif /* HAVE_STAT64 */
687
688 #if defined(linux) && !defined(IA64)
689 static void
690 convertoldstat(oldbuf, newbuf)
691 const struct __old_kernel_stat *oldbuf;
692 struct stat *newbuf;
693 {
694     newbuf->st_dev=oldbuf->st_dev;
695     newbuf->st_ino=oldbuf->st_ino;
696     newbuf->st_mode=oldbuf->st_mode;
697     newbuf->st_nlink=oldbuf->st_nlink;
698     newbuf->st_uid=oldbuf->st_uid;
699     newbuf->st_gid=oldbuf->st_gid;
700     newbuf->st_rdev=oldbuf->st_rdev;
701     newbuf->st_size=oldbuf->st_size;
702     newbuf->st_atime=oldbuf->st_atime;
703     newbuf->st_mtime=oldbuf->st_mtime;
704     newbuf->st_ctime=oldbuf->st_ctime;
705     newbuf->st_blksize=0;       /* not supported in old_stat */
706     newbuf->st_blocks=0;                /* not supported in old_stat */
707 }
708
709
710 static void
711 printoldstat(tcp, addr)
712 struct tcb *tcp;
713 long addr;
714 {
715         struct __old_kernel_stat statbuf;
716         struct stat newstatbuf;
717
718 #ifdef LINUXSPARC
719         if (current_personality == 1) {
720                 printstatsol(tcp, addr);
721                 return;
722         }
723 #endif /* LINUXSPARC */
724
725         if (!addr) {
726                 tprintf("NULL");
727                 return;
728         }
729         if (syserror(tcp) || !verbose(tcp)) {
730                 tprintf("%#lx", addr);
731                 return;
732         }
733         if (umove(tcp, addr, &statbuf) < 0) {
734                 tprintf("{...}");
735                 return;
736         }
737
738         convertoldstat(&statbuf, &newstatbuf);
739         realprintstat(tcp, &newstatbuf);
740 }
741 #endif /* linux && !IA64 */
742
743
744 int
745 sys_stat(tcp)
746 struct tcb *tcp;
747 {
748         if (entering(tcp)) {
749                 printpath(tcp, tcp->u_arg[0]);
750                 tprintf(", ");
751         } else {
752                 printstat(tcp, tcp->u_arg[1]);
753         }
754         return 0;
755 }
756
757 #ifdef linux
758 int
759 sys_stat64(tcp)
760 struct tcb *tcp;
761 {
762 #ifdef HAVE_STAT64
763         if (entering(tcp)) {
764                 printpath(tcp, tcp->u_arg[0]);
765                 tprintf(", ");
766         } else {
767                 printstat64(tcp, tcp->u_arg[1]);
768         }
769         return 0;
770 #else
771         return printargs(tcp);
772 #endif
773 }
774
775 # if !defined(IA64)
776 int
777 sys_oldstat(tcp)
778 struct tcb *tcp;
779 {
780         if (entering(tcp)) {
781                 printpath(tcp, tcp->u_arg[0]);
782                 tprintf(", ");
783         } else {
784                 printoldstat(tcp, tcp->u_arg[1]);
785         }
786         return 0;
787 }
788 # endif /* !IA64 */
789 #endif /* linux */
790
791 int
792 sys_fstat(tcp)
793 struct tcb *tcp;
794 {
795         if (entering(tcp))
796                 tprintf("%ld, ", tcp->u_arg[0]);
797         else {
798                 printstat(tcp, tcp->u_arg[1]);
799         }
800         return 0;
801 }
802
803 #ifdef linux
804 int
805 sys_fstat64(tcp)
806 struct tcb *tcp;
807 {
808 #ifdef HAVE_STAT64
809         if (entering(tcp))
810                 tprintf("%ld, ", tcp->u_arg[0]);
811         else {
812                 printstat64(tcp, tcp->u_arg[1]);
813         }
814         return 0;
815 #else
816         return printargs(tcp);
817 #endif
818 }
819
820 # if !defined(IA64)
821 int
822 sys_oldfstat(tcp)
823 struct tcb *tcp;
824 {
825         if (entering(tcp))
826                 tprintf("%ld, ", tcp->u_arg[0]);
827         else {
828                 printoldstat(tcp, tcp->u_arg[1]);
829         }
830         return 0;
831 }
832 # endif /* !IA64 */
833 #endif
834
835 int
836 sys_lstat(tcp)
837 struct tcb *tcp;
838 {
839         if (entering(tcp)) {
840                 printpath(tcp, tcp->u_arg[0]);
841                 tprintf(", ");
842         } else {
843                 printstat(tcp, tcp->u_arg[1]);
844         }
845         return 0;
846 }
847
848 #ifdef linux
849 int
850 sys_lstat64(tcp)
851 struct tcb *tcp;
852 {
853 #ifdef HAVE_STAT64
854         if (entering(tcp)) {
855                 printpath(tcp, tcp->u_arg[0]);
856                 tprintf(", ");
857         } else {
858                 printstat64(tcp, tcp->u_arg[1]);
859         }
860         return 0;
861 #else
862         return printargs(tcp);
863 #endif
864 }
865
866 # if !defined(IA64)
867 int
868 sys_oldlstat(tcp)
869 struct tcb *tcp;
870 {
871         if (entering(tcp)) {
872                 printpath(tcp, tcp->u_arg[0]);
873                 tprintf(", ");
874         } else {
875                 printoldstat(tcp, tcp->u_arg[1]);
876         }
877         return 0;
878 }
879 # endif /* !IA64 */
880 #endif
881
882
883 #if defined(SVR4) || defined(LINUXSPARC)
884
885 int
886 sys_xstat(tcp)
887 struct tcb *tcp;
888 {
889         if (entering(tcp)) {
890                 tprintf("%ld, ", tcp->u_arg[0]);
891                 printpath(tcp, tcp->u_arg[1]);
892                 tprintf(", ");
893         } else {
894                 printstat(tcp, tcp->u_arg[2]);
895         }
896         return 0;
897 }
898
899 int
900 sys_fxstat(tcp)
901 struct tcb *tcp;
902 {
903         if (entering(tcp))
904                 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
905         else {
906                 printstat(tcp, tcp->u_arg[2]);
907         }
908         return 0;
909 }
910
911 int
912 sys_lxstat(tcp)
913 struct tcb *tcp;
914 {
915         if (entering(tcp)) {
916                 tprintf("%ld, ", tcp->u_arg[0]);
917                 printpath(tcp, tcp->u_arg[1]);
918                 tprintf(", ");
919         } else {
920                 printstat(tcp, tcp->u_arg[2]);
921         }
922         return 0;
923 }
924
925 int
926 sys_xmknod(tcp)
927 struct tcb *tcp;
928 {
929         int mode = tcp->u_arg[2];
930
931         if (entering(tcp)) {
932                 tprintf("%ld, ", tcp->u_arg[0]);
933                 printpath(tcp, tcp->u_arg[1]);
934                 tprintf(", %s", sprintmode(mode));
935                 switch (mode & S_IFMT) {
936                 case S_IFCHR: case S_IFBLK:
937 #ifdef LINUXSPARC
938                         tprintf(", makedev(%lu, %lu)",
939                                 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
940                                 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
941 #else           
942                         tprintf(", makedev(%lu, %lu)",
943                                 (unsigned long) major(tcp->u_arg[3]),
944                                 (unsigned long) minor(tcp->u_arg[3]));
945 #endif                          
946                         break;
947                 default:
948                         break;
949                 }
950         }
951         return 0;
952 }
953
954 #ifdef HAVE_SYS_ACL_H
955
956 #include <sys/acl.h>
957
958 struct xlat aclcmds[] = {
959 #ifdef SETACL
960         { SETACL,       "SETACL"        },
961 #endif
962 #ifdef GETACL
963         { GETACL,       "GETACL"        },
964 #endif
965 #ifdef GETACLCNT
966         { GETACLCNT,    "GETACLCNT"     },
967 #endif
968 #ifdef ACL_GET
969         { ACL_GET,      "ACL_GET"       },
970 #endif  
971 #ifdef ACL_SET
972         { ACL_SET,      "ACL_SET"       },
973 #endif  
974 #ifdef ACL_CNT
975         { ACL_CNT,      "ACL_CNT"       },
976 #endif  
977         { 0,            NULL            },
978 };
979
980 int
981 sys_acl(tcp)
982 struct tcb *tcp;
983 {
984         if (entering(tcp)) {
985                 printpath(tcp, tcp->u_arg[0]);
986                 tprintf(", ");
987                 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
988                 tprintf(", %ld", tcp->u_arg[2]);
989                 /*
990                  * FIXME - dump out the list of aclent_t's pointed to
991                  * by "tcp->u_arg[3]" if it's not NULL.
992                  */
993                 if (tcp->u_arg[3])
994                         tprintf(", %#lx", tcp->u_arg[3]);
995                 else
996                         tprintf(", NULL");
997         }
998         return 0;
999 }
1000
1001
1002 int
1003 sys_facl(tcp)
1004 struct tcb *tcp;
1005 {
1006         if (entering(tcp)) {
1007                 tprintf("%ld, ", tcp->u_arg[0]);
1008                 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1009                 tprintf(", %ld", tcp->u_arg[2]);
1010                 /*
1011                  * FIXME - dump out the list of aclent_t's pointed to
1012                  * by "tcp->u_arg[3]" if it's not NULL.
1013                  */
1014                 if (tcp->u_arg[3])
1015                         tprintf(", %#lx", tcp->u_arg[3]);
1016                 else
1017                         tprintf(", NULL");
1018         }
1019         return 0;
1020 }
1021
1022
1023 struct xlat aclipc[] = {
1024 #ifdef IPC_SHM
1025         { IPC_SHM,      "IPC_SHM"       },
1026 #endif  
1027 #ifdef IPC_SEM
1028         { IPC_SEM,      "IPC_SEM"       },
1029 #endif  
1030 #ifdef IPC_MSG
1031         { IPC_MSG,      "IPC_MSG"       },
1032 #endif  
1033         { 0,            NULL            },
1034 };
1035
1036
1037 int
1038 sys_aclipc(tcp)
1039 struct tcb *tcp;
1040 {
1041         if (entering(tcp)) {
1042                 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1043                 tprintf(", %#lx, ", tcp->u_arg[1]);
1044                 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1045                 tprintf(", %ld", tcp->u_arg[3]);
1046                 /*
1047                  * FIXME - dump out the list of aclent_t's pointed to
1048                  * by "tcp->u_arg[4]" if it's not NULL.
1049                  */
1050                 if (tcp->u_arg[4])
1051                         tprintf(", %#lx", tcp->u_arg[4]);
1052                 else
1053                         tprintf(", NULL");
1054         }
1055         return 0;
1056 }
1057
1058
1059
1060 #endif /* HAVE_SYS_ACL_H */
1061
1062 #endif /* SVR4 || LINUXSPARC */
1063
1064 #ifdef linux
1065
1066 static struct xlat fsmagic[] = {
1067         { 0xef51,       "EXT2_OLD_SUPER_MAGIC"  },
1068         { 0xef53,       "EXT2_SUPER_MAGIC"      },
1069         { 0x137d,       "EXT_SUPER_MAGIC"       },
1070         { 0x9660,       "ISOFS_SUPER_MAGIC"     },
1071         { 0x137f,       "MINIX_SUPER_MAGIC"     },
1072         { 0x138f,       "MINIX_SUPER_MAGIC2"    },
1073         { 0x2468,       "MINIX2_SUPER_MAGIC"    },
1074         { 0x2478,       "MINIX2_SUPER_MAGIC2"   },
1075         { 0x4d44,       "MSDOS_SUPER_MAGIC"     },
1076         { 0x6969,       "NFS_SUPER_MAGIC"       },
1077         { 0x9fa0,       "PROC_SUPER_MAGIC"      },
1078         { 0x012fd16d,   "XIAFS_SUPER_MAGIC"     },
1079         { 0,            NULL                    },
1080 };
1081
1082 #endif /* linux */
1083
1084 #ifndef SVR4
1085
1086 static char *
1087 sprintfstype(magic)
1088 int magic;
1089 {
1090         static char buf[32];
1091 #ifdef linux
1092         char *s;
1093
1094         s = xlookup(fsmagic, magic);
1095         if (s) {
1096                 sprintf(buf, "\"%s\"", s);
1097                 return buf;
1098         }
1099 #endif /* linux */
1100         sprintf(buf, "%#x", magic);
1101         return buf;
1102 }
1103
1104 static void
1105 printstatfs(tcp, addr)
1106 struct tcb *tcp;
1107 long addr;
1108 {
1109         struct statfs statbuf;
1110
1111         if (syserror(tcp) || !verbose(tcp)) {
1112                 tprintf("%#lx", addr);
1113                 return;
1114         }
1115         if (umove(tcp, addr, &statbuf) < 0) {
1116                 tprintf("{...}");
1117                 return;
1118         }
1119 #ifdef ALPHA
1120
1121         tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1122                 sprintfstype(statbuf.f_type),
1123                 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1124         tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_namelen=%u",
1125                 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree, statbuf.f_namelen);
1126 #else /* !ALPHA */
1127         tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1128                 sprintfstype(statbuf.f_type),
1129                 (unsigned long)statbuf.f_bsize,
1130                 (unsigned long)statbuf.f_blocks,
1131                 (unsigned long)statbuf.f_bfree);
1132         tprintf("f_files=%lu, f_ffree=%lu",
1133                 (unsigned long)statbuf.f_files,
1134                 (unsigned long)statbuf.f_ffree);
1135 #ifdef linux
1136         tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1137 #endif /* linux */
1138 #endif /* !ALPHA */
1139         tprintf("}");
1140 }
1141
1142 int
1143 sys_statfs(tcp)
1144 struct tcb *tcp;
1145 {
1146         if (entering(tcp)) {
1147                 printpath(tcp, tcp->u_arg[0]);
1148                 tprintf(", ");
1149         } else {
1150                 printstatfs(tcp, tcp->u_arg[1]);
1151         }
1152         return 0;
1153 }
1154
1155 int
1156 sys_fstatfs(tcp)
1157 struct tcb *tcp;
1158 {
1159         if (entering(tcp)) {
1160                 tprintf("%lu, ", tcp->u_arg[0]);
1161         } else {
1162                 printstatfs(tcp, tcp->u_arg[1]);
1163         }
1164         return 0;
1165 }
1166
1167 #if defined(linux) && defined(__alpha)
1168
1169 int
1170 osf_statfs(tcp)
1171 struct tcb *tcp;
1172 {
1173         if (entering(tcp)) {
1174                 printpath(tcp, tcp->u_arg[0]);
1175                 tprintf(", ");
1176         } else {
1177                 printstatfs(tcp, tcp->u_arg[1]);
1178                 tprintf(", %lu", tcp->u_arg[2]);
1179         }
1180         return 0;
1181 }
1182
1183 int
1184 osf_fstatfs(tcp)
1185 struct tcb *tcp;
1186 {
1187         if (entering(tcp)) {
1188                 tprintf("%lu, ", tcp->u_arg[0]);
1189         } else {
1190                 printstatfs(tcp, tcp->u_arg[1]);
1191                 tprintf(", %lu", tcp->u_arg[2]);
1192         }
1193         return 0;
1194 }
1195 #endif /* linux && __alpha */
1196
1197 #endif /* !SVR4 */
1198
1199 #ifdef SUNOS4
1200
1201 int
1202 sys_ustat(tcp)
1203 struct tcb *tcp;
1204 {
1205         struct ustat statbuf;
1206
1207         if (entering(tcp)) {
1208                 tprintf("makedev(%lu, %lu), ",
1209                                 (long) major(tcp->u_arg[0]),
1210                                 (long) minor(tcp->u_arg[0]));
1211         }
1212         else {
1213                 if (syserror(tcp) || !verbose(tcp))
1214                         tprintf("%#lx", tcp->u_arg[1]);
1215                 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1216                         tprintf("{...}");
1217                 else {
1218                         tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1219                                 statbuf.f_tfree, statbuf.f_tinode);
1220                         tprintf("f_fname=\"%.*s\", ",
1221                                 (int) sizeof(statbuf.f_fname),
1222                                 statbuf.f_fname);
1223                         tprintf("f_fpack=\"%.*s\"}",
1224                                 (int) sizeof(statbuf.f_fpack),
1225                                 statbuf.f_fpack);
1226                 }
1227         }
1228         return 0;
1229 }
1230
1231 #endif /* SUNOS4 */
1232
1233 int
1234 sys_pivotroot(tcp)
1235 struct tcb *tcp;
1236 {
1237         if (entering(tcp)) {
1238                 printpath(tcp, tcp->u_arg[0]);
1239                 tprintf(", ");
1240                 printpath(tcp, tcp->u_arg[1]);
1241         }
1242         return 0;
1243 }
1244
1245
1246 /* directory */
1247 int
1248 sys_chdir(tcp)
1249 struct tcb *tcp;
1250 {
1251         if (entering(tcp)) {
1252                 printpath(tcp, tcp->u_arg[0]);
1253         }
1254         return 0;
1255 }
1256
1257 int
1258 sys_mkdir(tcp)
1259 struct tcb *tcp;
1260 {
1261         if (entering(tcp)) {
1262                 printpath(tcp, tcp->u_arg[0]);
1263                 tprintf(", %#lo", tcp->u_arg[1]);
1264         }
1265         return 0;
1266 }
1267
1268 int
1269 sys_rmdir(tcp)
1270 struct tcb *tcp;
1271 {
1272         if (entering(tcp)) {
1273                 printpath(tcp, tcp->u_arg[0]);
1274         }
1275         return 0;
1276 }
1277
1278 int
1279 sys_fchdir(tcp)
1280 struct tcb *tcp;
1281 {
1282         if (entering(tcp)) {
1283                 tprintf("%ld", tcp->u_arg[0]);
1284         }
1285         return 0;
1286 }
1287
1288 int
1289 sys_chroot(tcp)
1290 struct tcb *tcp;
1291 {
1292         if (entering(tcp)) {
1293                 printpath(tcp, tcp->u_arg[0]);
1294         }
1295         return 0;
1296 }
1297
1298 int
1299 sys_fchroot(tcp)
1300 struct tcb *tcp;
1301 {
1302         if (entering(tcp)) {
1303                 tprintf("%ld", tcp->u_arg[0]);
1304         }
1305         return 0;
1306 }
1307
1308 int
1309 sys_link(tcp)
1310 struct tcb *tcp;
1311 {
1312         if (entering(tcp)) {
1313                 printpath(tcp, tcp->u_arg[0]);
1314                 tprintf(", ");
1315                 printpath(tcp, tcp->u_arg[1]);
1316         }
1317         return 0;
1318 }
1319
1320 int
1321 sys_unlink(tcp)
1322 struct tcb *tcp;
1323 {
1324         if (entering(tcp)) {
1325                 printpath(tcp, tcp->u_arg[0]);
1326         }
1327         return 0;
1328 }
1329
1330 int
1331 sys_symlink(tcp)
1332 struct tcb *tcp;
1333 {
1334         if (entering(tcp)) {
1335                 printpath(tcp, tcp->u_arg[0]);
1336                 tprintf(", ");
1337                 printpath(tcp, tcp->u_arg[1]);
1338         }
1339         return 0;
1340 }
1341
1342 int
1343 sys_readlink(tcp)
1344 struct tcb *tcp;
1345 {
1346         if (entering(tcp)) {
1347                 printpath(tcp, tcp->u_arg[0]);
1348                 tprintf(", ");
1349         } else {
1350                 if (syserror(tcp))
1351                         tprintf("%#lx", tcp->u_arg[1]);
1352                 else
1353                         printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
1354                 tprintf(", %lu", tcp->u_arg[2]);
1355         }
1356         return 0;
1357 }
1358
1359 int
1360 sys_rename(tcp)
1361 struct tcb *tcp;
1362 {
1363         if (entering(tcp)) {
1364                 printpath(tcp, tcp->u_arg[0]);
1365                 tprintf(", ");
1366                 printpath(tcp, tcp->u_arg[1]);
1367         }
1368         return 0;
1369 }
1370
1371 int
1372 sys_chown(tcp)
1373 struct tcb *tcp;
1374 {
1375         if (entering(tcp)) {
1376                 printpath(tcp, tcp->u_arg[0]);
1377                 tprintf(", %lu, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1378         }
1379         return 0;
1380 }
1381
1382 int
1383 sys_fchown(tcp)
1384 struct tcb *tcp;
1385 {
1386         if (entering(tcp)) {
1387                 tprintf("%ld, %lu, %lu",
1388                         tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1389         }
1390         return 0;
1391 }
1392
1393 int
1394 sys_chmod(tcp)
1395 struct tcb *tcp;
1396 {
1397         if (entering(tcp)) {
1398                 printpath(tcp, tcp->u_arg[0]);
1399                 tprintf(", %#lo", tcp->u_arg[1]);
1400         }
1401         return 0;
1402 }
1403
1404 int
1405 sys_fchmod(tcp)
1406 struct tcb *tcp;
1407 {
1408         if (entering(tcp)) {
1409                 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
1410         }
1411         return 0;
1412 }
1413
1414 #ifdef ALPHA
1415 int
1416 sys_osf_utimes(tcp)
1417 struct tcb *tcp;
1418 {
1419     if (entering(tcp)) {
1420         printpath(tcp, tcp->u_arg[0]);
1421         tprintf(", ");
1422         printtv32(tcp, tcp->u_arg[1]);
1423     }
1424     return 0;
1425 }
1426 #endif
1427
1428 int
1429 sys_utimes(tcp)
1430 struct tcb *tcp;
1431 {
1432         if (entering(tcp)) {
1433                 printpath(tcp, tcp->u_arg[0]);
1434                 tprintf(", ");
1435                 printtv(tcp, tcp->u_arg[1]);
1436         }
1437         return 0;
1438 }
1439
1440 int
1441 sys_utime(tcp)
1442 struct tcb *tcp;
1443 {
1444         long ut[2];
1445
1446         if (entering(tcp)) {
1447                 printpath(tcp, tcp->u_arg[0]);
1448                 tprintf(", ");
1449                 if (!tcp->u_arg[1])
1450                         tprintf("NULL");
1451                 else if (!verbose(tcp))
1452                         tprintf("%#lx", tcp->u_arg[1]);
1453                 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
1454                     (char *) ut) < 0)
1455                         tprintf("[?, ?]");
1456                 else {
1457                         tprintf("[%s,", sprinttime(ut[0]));
1458                         tprintf(" %s]", sprinttime(ut[1]));
1459                 }
1460         }
1461         return 0;
1462 }
1463
1464 int
1465 sys_mknod(tcp)
1466 struct tcb *tcp;
1467 {
1468         int mode = tcp->u_arg[1];
1469
1470         if (entering(tcp)) {
1471                 printpath(tcp, tcp->u_arg[0]);
1472                 tprintf(", %s", sprintmode(mode));
1473                 switch (mode & S_IFMT) {
1474                 case S_IFCHR: case S_IFBLK:
1475 #ifdef LINUXSPARC
1476                         if (current_personality == 1)
1477                         tprintf(", makedev(%lu, %lu)",
1478                                 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
1479                                 (unsigned long) (tcp->u_arg[2] & 0x3ffff));
1480                         else
1481 #endif  
1482                         tprintf(", makedev(%lu, %lu)",
1483                                 (unsigned long) major(tcp->u_arg[2]),
1484                                 (unsigned long) minor(tcp->u_arg[2]));
1485                         break;
1486                 default:
1487                         break;
1488                 }
1489         }
1490         return 0;
1491 }
1492
1493 int
1494 sys_mkfifo(tcp)
1495 struct tcb *tcp;
1496 {
1497         if (entering(tcp)) {
1498                 printpath(tcp, tcp->u_arg[0]);
1499                 tprintf(", %#lo", tcp->u_arg[1]);
1500         }
1501         return 0;
1502 }
1503
1504 int
1505 sys_fsync(tcp)
1506 struct tcb *tcp;
1507 {
1508         if (entering(tcp)) {
1509                 tprintf("%ld", tcp->u_arg[0]);
1510         }
1511         return 0;
1512 }
1513
1514 #ifdef linux
1515
1516 static void
1517 printdir(tcp, addr)
1518 struct tcb *tcp;
1519 long addr;
1520 {
1521         struct dirent d;
1522
1523         if (!verbose(tcp)) {
1524                 tprintf("%#lx", addr);
1525                 return;
1526         }
1527         if (umove(tcp, addr, &d) < 0) {
1528                 tprintf("{...}");
1529                 return;
1530         }
1531         tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
1532         tprintf("d_name=");
1533         printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
1534         tprintf("}");
1535 }
1536
1537 int
1538 sys_readdir(tcp)
1539 struct tcb *tcp;
1540 {
1541         if (entering(tcp)) {
1542                 tprintf("%lu, ", tcp->u_arg[0]);
1543         } else {
1544                 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
1545                         tprintf("%#lx", tcp->u_arg[1]);
1546                 else
1547                         printdir(tcp, tcp->u_arg[1]);
1548                 /* Not much point in printing this out, it is always 1. */
1549                 if (tcp->u_arg[2] != 1)
1550                         tprintf(", %lu", tcp->u_arg[2]);
1551         }
1552         return 0;
1553 }
1554
1555 #endif /* linux */
1556
1557 int
1558 sys_getdents(tcp)
1559 struct tcb *tcp;
1560 {
1561         int i, len, dents = 0;
1562         char *buf;
1563
1564         if (entering(tcp)) {
1565                 tprintf("%lu, ", tcp->u_arg[0]);
1566                 return 0;
1567         }
1568         if (syserror(tcp) || !verbose(tcp)) {
1569                 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1570                 return 0;
1571         }
1572         len = tcp->u_rval;
1573         if ((buf = malloc(len)) == NULL) {
1574                 tprintf("out of memory\n");
1575                 return 0;
1576         }
1577         if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1578                 tprintf("{...}, %lu", tcp->u_arg[2]);
1579                 free(buf);
1580                 return 0;
1581         }
1582         if (!abbrev(tcp))
1583                 tprintf("{");
1584         for (i = 0; i < len;) {
1585                 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
1586 #ifdef linux
1587                 if (!abbrev(tcp)) {
1588                         tprintf("%s{d_ino=%lu, d_off=%lu, ",
1589                                 i ? " " : "", d->d_ino, d->d_off);
1590                         tprintf("d_reclen=%u, d_name=\"%s\"}",
1591                                 d->d_reclen, d->d_name);
1592                 }
1593 #endif /* linux */
1594 #ifdef SVR4
1595                 if (!abbrev(tcp)) {
1596                         tprintf("%s{d_ino=%lu, d_off=%lu, ",
1597                                 i ? " " : "", d->d_ino, d->d_off);
1598                         tprintf("d_reclen=%u, d_name=\"%s\"}",
1599                                 d->d_reclen, d->d_name);
1600                 }
1601 #endif /* SVR4 */
1602 #ifdef SUNOS4
1603                 if (!abbrev(tcp)) {
1604                         tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
1605                                 i ? " " : "", d->d_off, d->d_fileno,
1606                                 d->d_reclen);
1607                         tprintf("d_namlen=%u, d_name=\"%.*s\"}",
1608                                 d->d_namlen, d->d_namlen, d->d_name);
1609                 }
1610 #endif /* SUNOS4 */
1611                 if (!d->d_reclen) {
1612                         tprintf("/* d_reclen == 0, problem here */");
1613                         break;
1614                 }
1615                 i += d->d_reclen;
1616                 dents++;
1617         }
1618         if (!abbrev(tcp))
1619                 tprintf("}");
1620         else
1621                 tprintf("/* %u entries */", dents);
1622         tprintf(", %lu", tcp->u_arg[2]);
1623         free(buf);
1624         return 0;
1625 }
1626
1627 #ifdef linux
1628
1629 int
1630 sys_getcwd(tcp)
1631 struct tcb *tcp;
1632 {
1633     if (exiting(tcp)) {
1634         if (syserror(tcp))
1635             tprintf("%#lx", tcp->u_arg[0]);
1636         else
1637             printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
1638         tprintf(", %lu", tcp->u_arg[1]);
1639     }
1640     return 0;
1641 }
1642 #endif /* linux */
1643
1644 #ifdef HAVE_SYS_ASYNCH_H
1645
1646 int
1647 sys_aioread(tcp)
1648 struct tcb *tcp;
1649 {
1650         struct aio_result_t res;
1651
1652         if (entering(tcp)) {
1653                 tprintf("%lu, ", tcp->u_arg[0]);
1654         } else {
1655                 if (syserror(tcp))
1656                         tprintf("%#lx", tcp->u_arg[1]);
1657                 else
1658                         printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1659                 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
1660                 printxval(whence, tcp->u_arg[4], "L_???");
1661                 if (syserror(tcp) || tcp->u_arg[5] == 0
1662                     || umove(tcp, tcp->u_arg[5], &res) < 0)
1663                         tprintf(", %#lx", tcp->u_arg[5]);
1664                 else
1665                         tprintf(", {aio_return %d aio_errno %d}",
1666                                 res.aio_return, res.aio_errno);
1667         }
1668         return 0;
1669 }
1670
1671 int
1672 sys_aiowrite(tcp)
1673 struct tcb *tcp;
1674 {
1675         struct aio_result_t res;
1676
1677         if (entering(tcp)) {
1678                 tprintf("%lu, ", tcp->u_arg[0]);
1679                 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1680                 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
1681                 printxval(whence, tcp->u_arg[4], "L_???");
1682         }
1683         else {
1684                 if (tcp->u_arg[5] == 0)
1685                         tprintf(", NULL");
1686                 else if (syserror(tcp)
1687                     || umove(tcp, tcp->u_arg[5], &res) < 0)
1688                         tprintf(", %#lx", tcp->u_arg[5]);
1689                 else
1690                         tprintf(", {aio_return %d aio_errno %d}",
1691                                 res.aio_return, res.aio_errno);
1692         }
1693         return 0;
1694 }
1695
1696 int
1697 sys_aiowait(tcp)
1698 struct tcb *tcp;
1699 {
1700         if (entering(tcp))
1701                 printtv(tcp, tcp->u_arg[0]);
1702         return 0;
1703 }
1704
1705 int
1706 sys_aiocancel(tcp)
1707 struct tcb *tcp;
1708 {
1709         struct aio_result_t res;
1710
1711         if (exiting(tcp)) {
1712                 if (tcp->u_arg[0] == 0)
1713                         tprintf("NULL");
1714                 else if (syserror(tcp)
1715                     || umove(tcp, tcp->u_arg[0], &res) < 0)
1716                         tprintf("%#lx", tcp->u_arg[0]);
1717                 else
1718                         tprintf("{aio_return %d aio_errno %d}",
1719                                 res.aio_return, res.aio_errno);
1720         }
1721         return 0;
1722 }
1723
1724 #endif /* HAVE_SYS_ASYNCH_H */