]> granicus.if.org Git - strace/blob - file.c
2007-01-11 Dmitry V. Levin <ldv@altlinux.org>
[strace] / file.c
1 /*
2 #ifdef LINUX
3  * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
4  * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
5  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
6  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. The name of the author may not be used to endorse or promote products
18  *    derived from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  *      $Id$
32  */
33
34 #include "defs.h"
35
36 #include <dirent.h>
37 #ifdef LINUX
38 #define dirent kernel_dirent
39 #define dirent64 kernel_dirent64
40 #include <linux/types.h>
41 #include <linux/dirent.h>
42 #undef dirent
43 #undef dirent64
44 #else
45 #define kernel_dirent dirent
46 #endif
47
48 #ifdef LINUX
49 #  ifdef LINUXSPARC
50 struct stat {
51         unsigned short  st_dev;
52         unsigned int    st_ino;
53         unsigned short  st_mode;
54         short           st_nlink;
55         unsigned short  st_uid;
56         unsigned short  st_gid;
57         unsigned short  st_rdev;
58         unsigned int    st_size;
59         int             st_atime;
60         unsigned int    __unused1;
61         int             st_mtime;
62         unsigned int    __unused2;
63         int             st_ctime;
64         unsigned int    __unused3;
65         int             st_blksize;
66         int             st_blocks;
67         unsigned int    __unused4[2];
68 };
69 #if defined(SPARC64)
70 struct stat_sparc64 {
71         unsigned int    st_dev;
72         unsigned long   st_ino;
73         unsigned int    st_mode;
74         unsigned int    st_nlink;
75         unsigned int    st_uid;
76         unsigned int    st_gid;
77         unsigned int    st_rdev;
78         long            st_size;
79         long            st_atime;
80         long            st_mtime;
81         long            st_ctime;
82         long            st_blksize;
83         long            st_blocks;
84         unsigned long   __unused4[2];
85 };
86 #endif /* SPARC64 */
87 #    define stat kernel_stat
88 #    include <asm/stat.h>
89 #    undef stat
90 #  else
91 #    undef dev_t
92 #    undef ino_t
93 #    undef mode_t
94 #    undef nlink_t
95 #    undef uid_t
96 #    undef gid_t
97 #    undef off_t
98 #    undef loff_t
99
100 #    define dev_t __kernel_dev_t
101 #    define ino_t __kernel_ino_t
102 #    define mode_t __kernel_mode_t
103 #    define nlink_t __kernel_nlink_t
104 #    define uid_t __kernel_uid_t
105 #    define gid_t __kernel_gid_t
106 #    define off_t __kernel_off_t
107 #    define loff_t __kernel_loff_t
108
109 #    include <asm/stat.h>
110
111 #    undef dev_t
112 #    undef ino_t
113 #    undef mode_t
114 #    undef nlink_t
115 #    undef uid_t
116 #    undef gid_t
117 #    undef off_t
118 #    undef loff_t
119
120 #    define dev_t dev_t
121 #    define ino_t ino_t
122 #    define mode_t mode_t
123 #    define nlink_t nlink_t
124 #    define uid_t uid_t
125 #    define gid_t gid_t
126 #    define off_t off_t
127 #    define loff_t loff_t
128 #  endif
129 #  ifdef HPPA   /* asm-parisc/stat.h defines stat64 */
130 #    undef stat64
131 #  endif
132 #  define stat libc_stat
133 #  define stat64 libc_stat64
134 #  include <sys/stat.h>
135 #  undef stat
136 #  undef stat64
137    /* These might be macros. */
138 #  undef st_atime
139 #  undef st_mtime
140 #  undef st_ctime
141 #  ifdef HPPA
142 #    define stat64 hpux_stat64
143 #  endif
144 #else
145 #  include <sys/stat.h>
146 #endif
147
148 #include <fcntl.h>
149
150 #ifdef SVR4
151 #  include <sys/cred.h>
152 #endif /* SVR4 */
153
154 #ifdef HAVE_SYS_VFS_H
155 #include <sys/vfs.h>
156 #endif
157
158 #ifdef HAVE_LINUX_XATTR_H
159 #include <linux/xattr.h>
160 #elif defined linux
161 #define XATTR_CREATE 1
162 #define XATTR_REPLACE 2
163 #endif
164
165 #ifdef FREEBSD
166 #include <sys/param.h>
167 #include <sys/mount.h>
168 #include <sys/stat.h>
169 #endif
170
171 #if _LFS64_LARGEFILE && (defined(LINUX) || defined(SVR4))
172 # ifdef HAVE_INTTYPES_H
173 #  include <inttypes.h>
174 # else
175 #  define PRId64 "lld"
176 #  define PRIu64 "llu"
177 # endif
178 #endif
179
180 #if HAVE_LONG_LONG_OFF_T
181 /*
182  * Ugly hacks for systems that have typedef long long off_t
183  */
184
185 #define stat64 stat
186 #define HAVE_STAT64 1   /* Ugly hack */
187
188 #define sys_stat64      sys_stat
189 #define sys_fstat64     sys_fstat
190 #define sys_lstat64     sys_lstat
191 #define sys_lseek64     sys_lseek
192 #define sys_truncate64  sys_truncate
193 #define sys_ftruncate64 sys_ftruncate
194 #endif
195
196 #ifdef MAJOR_IN_SYSMACROS
197 #include <sys/sysmacros.h>
198 #endif
199
200 #ifdef MAJOR_IN_MKDEV
201 #include <sys/mkdev.h>
202 #endif
203
204 #ifdef HAVE_SYS_ASYNCH_H
205 #include <sys/asynch.h>
206 #endif
207
208 #ifdef SUNOS4
209 #include <ustat.h>
210 #endif
211
212 const struct xlat open_access_modes[] = {
213         { O_RDONLY,     "O_RDONLY"      },
214         { O_WRONLY,     "O_WRONLY"      },
215         { O_RDWR,       "O_RDWR"        },
216 #ifdef O_ACCMODE
217         { O_ACCMODE,    "O_ACCMODE"     },
218 #endif
219         { 0,            NULL            },
220 };
221
222 const struct xlat open_mode_flags[] = {
223         { O_CREAT,      "O_CREAT"       },
224         { O_EXCL,       "O_EXCL"        },
225         { O_NOCTTY,     "O_NOCTTY"      },
226         { O_TRUNC,      "O_TRUNC"       },
227         { O_APPEND,     "O_APPEND"      },
228         { O_NONBLOCK,   "O_NONBLOCK"    },
229 #ifdef O_SYNC
230         { O_SYNC,       "O_SYNC"        },
231 #endif
232 #ifdef O_ASYNC
233         { O_ASYNC,      "O_ASYNC"       },
234 #endif
235 #ifdef O_DSYNC
236         { O_DSYNC,      "O_DSYNC"       },
237 #endif
238 #ifdef O_RSYNC
239         { O_RSYNC,      "O_RSYNC"       },
240 #endif
241 #ifdef O_NDELAY
242         { O_NDELAY,     "O_NDELAY"      },
243 #endif
244 #ifdef O_PRIV
245         { O_PRIV,       "O_PRIV"        },
246 #endif
247 #ifdef O_DIRECT
248         { O_DIRECT,     "O_DIRECT"      },
249 #endif
250 #ifdef O_LARGEFILE
251 # if O_LARGEFILE == 0           /* biarch platforms in 64-bit mode */
252 #  undef O_LARGEFILE
253 #  ifdef SPARC64
254 #   define O_LARGEFILE  0x40000
255 #  elif defined X86_64 || defined S390X
256 #   define O_LARGEFILE  0100000
257 #  endif
258 # endif
259 # ifdef O_LARGEFILE
260         { O_LARGEFILE,  "O_LARGEFILE"   },
261 # endif
262 #endif
263 #ifdef O_DIRECTORY
264         { O_DIRECTORY,  "O_DIRECTORY"   },
265 #endif
266 #ifdef O_NOFOLLOW
267         { O_NOFOLLOW,   "O_NOFOLLOW"    },
268 #endif
269 #ifdef O_NOATIME
270         { O_NOATIME,    "O_NOATIME"     },
271 #endif
272
273 #ifdef FNDELAY
274         { FNDELAY,      "FNDELAY"       },
275 #endif
276 #ifdef FAPPEND
277         { FAPPEND,      "FAPPEND"       },
278 #endif
279 #ifdef FMARK
280         { FMARK,        "FMARK"         },
281 #endif
282 #ifdef FDEFER
283         { FDEFER,       "FDEFER"        },
284 #endif
285 #ifdef FASYNC
286         { FASYNC,       "FASYNC"        },
287 #endif
288 #ifdef FSHLOCK
289         { FSHLOCK,      "FSHLOCK"       },
290 #endif
291 #ifdef FEXLOCK
292         { FEXLOCK,      "FEXLOCK"       },
293 #endif
294 #ifdef FCREAT
295         { FCREAT,       "FCREAT"        },
296 #endif
297 #ifdef FTRUNC
298         { FTRUNC,       "FTRUNC"        },
299 #endif
300 #ifdef FEXCL
301         { FEXCL,        "FEXCL"         },
302 #endif
303 #ifdef FNBIO
304         { FNBIO,        "FNBIO"         },
305 #endif
306 #ifdef FSYNC
307         { FSYNC,        "FSYNC"         },
308 #endif
309 #ifdef FNOCTTY
310         { FNOCTTY,      "FNOCTTY"       },
311 #endif
312 #ifdef O_SHLOCK
313         { O_SHLOCK,     "O_SHLOCK"      },
314 #endif
315 #ifdef O_EXLOCK
316         { O_EXLOCK,     "O_EXLOCK"      },
317 #endif
318         { 0,            NULL            },
319 };
320
321 #ifdef LINUX
322
323 #ifndef AT_FDCWD
324 # define AT_FDCWD                -100
325 #endif
326
327 static void
328 print_dirfd(long fd)
329 {
330         if (fd == AT_FDCWD)
331                 tprintf("AT_FDCWD, ");
332         else
333                 tprintf("%ld, ", fd);
334 }
335 #endif
336
337 /*
338  * low bits of the open(2) flags define access mode,
339  * other bits are real flags.
340  */
341 void
342 tprint_open_modes(struct tcb *tcp, mode_t flags)
343 {
344         const char *str = xlookup(open_access_modes, flags & 3);
345
346         if (str)
347         {
348                 tprintf("%s", str);
349                 flags &= ~3;
350                 if (!flags)
351                         return;
352                 tprintf("|");
353         }
354         printflags(open_mode_flags, flags, "O_???");
355 }
356
357 static int
358 decode_open(struct tcb *tcp, int offset)
359 {
360         if (entering(tcp)) {
361                 printpath(tcp, tcp->u_arg[offset]);
362                 tprintf(", ");
363                 /* flags */
364                 tprint_open_modes(tcp, tcp->u_arg[offset + 1]);
365                 if (tcp->u_arg[offset + 1] & O_CREAT) {
366                         /* mode */
367                         tprintf(", %#lo", tcp->u_arg[offset + 2]);
368                 }
369         }
370         return 0;
371 }
372
373 int
374 sys_open(struct tcb *tcp)
375 {
376         return decode_open(tcp, 0);
377 }
378
379 #ifdef LINUX
380 int
381 sys_openat(struct tcb *tcp)
382 {
383         if (entering(tcp))
384                 print_dirfd(tcp->u_arg[0]);
385         return decode_open(tcp, 1);
386 }
387 #endif
388
389 #ifdef LINUXSPARC
390 static const struct xlat openmodessol[] = {
391         { 0,            "O_RDWR"        },
392         { 1,            "O_RDONLY"      },
393         { 2,            "O_WRONLY"      },
394         { 0x80,         "O_NONBLOCK"    },
395         { 8,            "O_APPEND"      },
396         { 0x100,        "O_CREAT"       },
397         { 0x200,        "O_TRUNC"       },
398         { 0x400,        "O_EXCL"        },
399         { 0x800,        "O_NOCTTY"      },
400         { 0x10,         "O_SYNC"        },
401         { 0x40,         "O_DSYNC"       },
402         { 0x8000,       "O_RSYNC"       },
403         { 4,            "O_NDELAY"      },
404         { 0x1000,       "O_PRIV"        },
405         { 0,            NULL            },
406 };
407
408 int
409 solaris_open(tcp)
410 struct tcb *tcp;
411 {
412         if (entering(tcp)) {
413                 printpath(tcp, tcp->u_arg[0]);
414                 tprintf(", ");
415                 /* flags */
416                 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
417                 if (tcp->u_arg[1] & 0x100) {
418                         /* mode */
419                         tprintf(", %#lo", tcp->u_arg[2]);
420                 }
421         }
422         return 0;
423 }
424
425 #endif
426
427 int
428 sys_creat(tcp)
429 struct tcb *tcp;
430 {
431         if (entering(tcp)) {
432                 printpath(tcp, tcp->u_arg[0]);
433                 tprintf(", %#lo", tcp->u_arg[1]);
434         }
435         return 0;
436 }
437
438 static const struct xlat access_flags[] = {
439         { F_OK,         "F_OK",         },
440         { R_OK,         "R_OK"          },
441         { W_OK,         "W_OK"          },
442         { X_OK,         "X_OK"          },
443 #ifdef EFF_ONLY_OK
444         { EFF_ONLY_OK,  "EFF_ONLY_OK"   },
445 #endif
446 #ifdef EX_OK
447         { EX_OK,        "EX_OK"         },
448 #endif
449         { 0,            NULL            },
450 };
451
452 static int
453 decode_access(struct tcb *tcp, int offset)
454 {
455         if (entering(tcp)) {
456                 printpath(tcp, tcp->u_arg[offset]);
457                 tprintf(", ");
458                 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
459         }
460         return 0;
461 }
462
463 int
464 sys_access(struct tcb *tcp)
465 {
466         return decode_access(tcp, 0);
467 }
468
469 #ifdef LINUX
470 int
471 sys_faccessat(struct tcb *tcp)
472 {
473         if (entering(tcp))
474                 print_dirfd(tcp->u_arg[0]);
475         return decode_access(tcp, 1);
476 }
477 #endif
478
479 int
480 sys_umask(tcp)
481 struct tcb *tcp;
482 {
483         if (entering(tcp)) {
484                 tprintf("%#lo", tcp->u_arg[0]);
485         }
486         return RVAL_OCTAL;
487 }
488
489 static const struct xlat whence[] = {
490         { SEEK_SET,     "SEEK_SET"      },
491         { SEEK_CUR,     "SEEK_CUR"      },
492         { SEEK_END,     "SEEK_END"      },
493         { 0,            NULL            },
494 };
495
496 #ifndef HAVE_LONG_LONG_OFF_T
497 int
498 sys_lseek(tcp)
499 struct tcb *tcp;
500 {
501         off_t offset;
502         int _whence;
503
504         if (entering(tcp)) {
505                 tprintf("%ld, ", tcp->u_arg[0]);
506                 offset = tcp->u_arg[1];
507                 _whence = tcp->u_arg[2];
508                 if (_whence == SEEK_SET)
509                         tprintf("%lu, ", offset);
510                 else
511                         tprintf("%ld, ", offset);
512                 printxval(whence, _whence, "SEEK_???");
513         }
514         return RVAL_UDECIMAL;
515 }
516 #endif
517
518 #ifdef LINUX
519 int
520 sys_llseek (tcp)
521 struct tcb *tcp;
522 {
523     if (entering(tcp)) {
524         /*
525          * This one call takes explicitly two 32-bit arguments hi, lo,
526          * rather than one 64-bit argument for which LONG_LONG works
527          * appropriate for the native byte order.
528          */
529         if (tcp->u_arg[4] == SEEK_SET)
530             tprintf("%ld, %llu, ", tcp->u_arg[0],
531                     (((long long int) tcp->u_arg[1]) << 32
532                      | (unsigned long long) (unsigned) tcp->u_arg[2]));
533         else
534             tprintf("%ld, %lld, ", tcp->u_arg[0],
535                     (((long long int) tcp->u_arg[1]) << 32
536                      | (unsigned long long) (unsigned) tcp->u_arg[2]));
537     }
538     else {
539         long long int off;
540         if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
541             tprintf("%#lx, ", tcp->u_arg[3]);
542         else
543             tprintf("[%llu], ", off);
544         printxval(whence, tcp->u_arg[4], "SEEK_???");
545     }
546     return 0;
547 }
548
549 int
550 sys_readahead (tcp)
551 struct tcb *tcp;
552 {
553     if (entering(tcp)) {
554         tprintf("%ld, %lld, %ld", tcp->u_arg[0],
555 # if defined IA64 || defined X86_64 || defined ALPHA
556                 (long long int) tcp->u_arg[1], tcp->u_arg[2]
557 # else
558                 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]
559 # endif
560                 );
561     }
562     return 0;
563 }
564 #endif
565
566 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
567 int
568 sys_lseek64 (tcp)
569 struct tcb *tcp;
570 {
571         if (entering(tcp)) {
572                 long long offset;
573                 ALIGN64 (tcp, 1);       /* FreeBSD aligns off_t args */
574                 offset = LONG_LONG(tcp->u_arg [1], tcp->u_arg[2]);
575                 if (tcp->u_arg[3] == SEEK_SET)
576                         tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
577                 else
578                         tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
579                 printxval(whence, tcp->u_arg[3], "SEEK_???");
580         }
581         return RVAL_LUDECIMAL;
582 }
583 #endif
584
585 #ifndef HAVE_LONG_LONG_OFF_T
586 int
587 sys_truncate(tcp)
588 struct tcb *tcp;
589 {
590         if (entering(tcp)) {
591                 printpath(tcp, tcp->u_arg[0]);
592                 tprintf(", %lu", tcp->u_arg[1]);
593         }
594         return 0;
595 }
596 #endif
597
598 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
599 int
600 sys_truncate64(tcp)
601 struct tcb *tcp;
602 {
603         if (entering(tcp)) {
604                 ALIGN64 (tcp, 1);
605                 printpath(tcp, tcp->u_arg[0]);
606                 tprintf(", %llu", LONG_LONG(tcp->u_arg[1],tcp->u_arg[2]));
607         }
608         return 0;
609 }
610 #endif
611
612 #ifndef HAVE_LONG_LONG_OFF_T
613 int
614 sys_ftruncate(tcp)
615 struct tcb *tcp;
616 {
617         if (entering(tcp)) {
618                 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
619         }
620         return 0;
621 }
622 #endif
623
624 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
625 int
626 sys_ftruncate64(tcp)
627 struct tcb *tcp;
628 {
629         if (entering(tcp)) {
630                 ALIGN64 (tcp, 1);
631                 tprintf("%ld, %llu", tcp->u_arg[0],
632                         LONG_LONG(tcp->u_arg[1] ,tcp->u_arg[2]));
633         }
634         return 0;
635 }
636 #endif
637
638 /* several stats */
639
640 static const struct xlat modetypes[] = {
641         { S_IFREG,      "S_IFREG"       },
642         { S_IFSOCK,     "S_IFSOCK"      },
643         { S_IFIFO,      "S_IFIFO"       },
644         { S_IFLNK,      "S_IFLNK"       },
645         { S_IFDIR,      "S_IFDIR"       },
646         { S_IFBLK,      "S_IFBLK"       },
647         { S_IFCHR,      "S_IFCHR"       },
648         { 0,            NULL            },
649 };
650
651 static const char *
652 sprintmode(mode)
653 int mode;
654 {
655         static char buf[64];
656         const char *s;
657
658         if ((mode & S_IFMT) == 0)
659                 s = "";
660         else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
661                 sprintf(buf, "%#o", mode);
662                 return buf;
663         }
664         sprintf(buf, "%s%s%s%s", s,
665                 (mode & S_ISUID) ? "|S_ISUID" : "",
666                 (mode & S_ISGID) ? "|S_ISGID" : "",
667                 (mode & S_ISVTX) ? "|S_ISVTX" : "");
668         mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
669         if (mode)
670                 sprintf(buf + strlen(buf), "|%#o", mode);
671         s = (*buf == '|') ? buf + 1 : buf;
672         return *s ? s : "0";
673 }
674
675 static char *
676 sprinttime(t)
677 time_t t;
678 {
679         struct tm *tmp;
680         static char buf[32];
681
682         if (t == 0) {
683                 sprintf(buf, "0");
684                 return buf;
685         }
686         tmp = localtime(&t);
687         sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
688                 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
689                 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
690         return buf;
691 }
692
693 #ifdef LINUXSPARC
694 typedef struct {
695         int     tv_sec;
696         int     tv_nsec;
697 } timestruct_t;
698
699 struct solstat {
700         unsigned        st_dev;
701         int             st_pad1[3];     /* network id */
702         unsigned        st_ino;
703         unsigned        st_mode;
704         unsigned        st_nlink;
705         unsigned        st_uid;
706         unsigned        st_gid;
707         unsigned        st_rdev;
708         int             st_pad2[2];
709         int             st_size;
710         int             st_pad3;        /* st_size, off_t expansion */
711         timestruct_t    st_atime;
712         timestruct_t    st_mtime;
713         timestruct_t    st_ctime;
714         int             st_blksize;
715         int             st_blocks;
716         char            st_fstype[16];
717         int             st_pad4[8];     /* expansion area */
718 };
719
720 static void
721 printstatsol(tcp, addr)
722 struct tcb *tcp;
723 long addr;
724 {
725         struct solstat statbuf;
726
727         if (!addr) {
728                 tprintf("NULL");
729                 return;
730         }
731         if (syserror(tcp) || !verbose(tcp)) {
732                 tprintf("%#lx", addr);
733                 return;
734         }
735         if (umove(tcp, addr, &statbuf) < 0) {
736                 tprintf("{...}");
737                 return;
738         }
739         if (!abbrev(tcp)) {
740                 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
741                         (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
742                         (unsigned long) (statbuf.st_dev & 0x3ffff),
743                         (unsigned long) statbuf.st_ino,
744                         sprintmode(statbuf.st_mode));
745                 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
746                         (unsigned long) statbuf.st_nlink,
747                         (unsigned long) statbuf.st_uid,
748                         (unsigned long) statbuf.st_gid);
749                 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
750                 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
751         }
752         else
753                 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
754         switch (statbuf.st_mode & S_IFMT) {
755         case S_IFCHR: case S_IFBLK:
756                 tprintf("st_rdev=makedev(%lu, %lu), ",
757                         (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
758                         (unsigned long) (statbuf.st_rdev & 0x3ffff));
759                 break;
760         default:
761                 tprintf("st_size=%u, ", statbuf.st_size);
762                 break;
763         }
764         if (!abbrev(tcp)) {
765                 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
766                 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
767                 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
768         }
769         else
770                 tprintf("...}");
771 }
772
773 #if defined (SPARC64)
774 static void
775 printstat_sparc64(tcp, addr)
776 struct tcb *tcp;
777 long addr;
778 {
779         struct stat_sparc64 statbuf;
780
781         if (!addr) {
782                 tprintf("NULL");
783                 return;
784         }
785         if (syserror(tcp) || !verbose(tcp)) {
786                 tprintf("%#lx", addr);
787                 return;
788         }
789         if (umove(tcp, addr, &statbuf) < 0) {
790                 tprintf("{...}");
791                 return;
792         }
793
794         if (!abbrev(tcp)) {
795                 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
796                         (unsigned long) major(statbuf.st_dev),
797                         (unsigned long) minor(statbuf.st_dev),
798                         (unsigned long) statbuf.st_ino,
799                         sprintmode(statbuf.st_mode));
800                 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
801                         (unsigned long) statbuf.st_nlink,
802                         (unsigned long) statbuf.st_uid,
803                         (unsigned long) statbuf.st_gid);
804                 tprintf("st_blksize=%lu, ",
805                         (unsigned long) statbuf.st_blksize);
806                 tprintf("st_blocks=%lu, ",
807                         (unsigned long) statbuf.st_blocks);
808         }
809         else
810                 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
811         switch (statbuf.st_mode & S_IFMT) {
812         case S_IFCHR: case S_IFBLK:
813                 tprintf("st_rdev=makedev(%lu, %lu), ",
814                         (unsigned long) major(statbuf.st_rdev),
815                         (unsigned long) minor(statbuf.st_rdev));
816                 break;
817         default:
818                 tprintf("st_size=%lu, ", statbuf.st_size);
819                 break;
820         }
821         if (!abbrev(tcp)) {
822                 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
823                 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
824                 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
825                 tprintf("}");
826         }
827         else
828                 tprintf("...}");
829 }
830 #endif /* SPARC64 */
831 #endif /* LINUXSPARC */
832
833 static const struct xlat fileflags[] = {
834 #ifdef FREEBSD
835         { UF_NODUMP,    "UF_NODUMP"     },
836         { UF_IMMUTABLE, "UF_IMMUTABLE"  },
837         { UF_APPEND,    "UF_APPEND"     },
838         { UF_OPAQUE,    "UF_OPAQUE"     },
839         { UF_NOUNLINK,  "UF_NOUNLINK"   },
840         { SF_ARCHIVED,  "SF_ARCHIVED"   },
841         { SF_IMMUTABLE, "SF_IMMUTABLE"  },
842         { SF_APPEND,    "SF_APPEND"     },
843         { SF_NOUNLINK,  "SF_NOUNLINK"   },
844 #elif UNIXWARE >= 2
845 #ifdef  _S_ISMLD
846         { _S_ISMLD,     "_S_ISMLD"      },
847 #endif
848 #ifdef  _S_ISMOUNTED
849         { _S_ISMOUNTED, "_S_ISMOUNTED"  },
850 #endif
851 #endif
852         { 0,            NULL            },
853 };
854
855 #ifdef FREEBSD
856 int
857 sys_chflags(tcp)
858 struct tcb *tcp;
859 {
860         if (entering(tcp)) {
861                 printpath(tcp, tcp->u_arg[0]);
862                 tprintf(", ");
863                 printflags(fileflags, tcp->u_arg[1], "UF_???");
864         }
865         return 0;
866 }
867
868 int
869 sys_fchflags(tcp)
870 struct tcb *tcp;
871 {
872         if (entering(tcp)) {
873                 tprintf("%ld, ", tcp->u_arg[0]);
874                 printflags(fileflags, tcp->u_arg[1], "UF_???");
875         }
876         return 0;
877 }
878 #endif
879
880 #ifndef HAVE_LONG_LONG_OFF_T
881 static void
882 realprintstat(tcp, statbuf)
883 struct tcb *tcp;
884 struct stat *statbuf;
885 {
886     if (!abbrev(tcp)) {
887             tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
888                     (unsigned long) major(statbuf->st_dev),
889                     (unsigned long) minor(statbuf->st_dev),
890                     (unsigned long) statbuf->st_ino,
891                     sprintmode(statbuf->st_mode));
892             tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
893                     (unsigned long) statbuf->st_nlink,
894                     (unsigned long) statbuf->st_uid,
895                     (unsigned long) statbuf->st_gid);
896 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
897             tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
898 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
899 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
900             tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
901 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
902     }
903     else
904             tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
905     switch (statbuf->st_mode & S_IFMT) {
906     case S_IFCHR: case S_IFBLK:
907 #ifdef HAVE_STRUCT_STAT_ST_RDEV
908             tprintf("st_rdev=makedev(%lu, %lu), ",
909                     (unsigned long) major(statbuf->st_rdev),
910                     (unsigned long) minor(statbuf->st_rdev));
911 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
912             tprintf("st_size=makedev(%lu, %lu), ",
913                     (unsigned long) major(statbuf->st_size),
914                     (unsigned long) minor(statbuf->st_size));
915 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
916             break;
917     default:
918             tprintf("st_size=%lu, ", statbuf->st_size);
919             break;
920     }
921     if (!abbrev(tcp)) {
922             tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
923             tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
924             tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
925 #if HAVE_STRUCT_STAT_ST_FLAGS
926                 tprintf(", st_flags=");
927                 printflags(fileflags, statbuf->st_flags, "UF_???");
928 #endif
929 #if HAVE_STRUCT_STAT_ST_ACLCNT
930                 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
931 #endif
932 #if HAVE_STRUCT_STAT_ST_LEVEL
933                 tprintf(", st_level=%ld", statbuf->st_level);
934 #endif
935 #if HAVE_STRUCT_STAT_ST_FSTYPE
936                 tprintf(", st_fstype=%.*s",
937                         (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
938 #endif
939 #if HAVE_STRUCT_STAT_ST_GEN
940                 tprintf(", st_gen=%u", statbuf->st_gen);
941 #endif
942                 tprintf("}");
943     }
944     else
945             tprintf("...}");
946 }
947
948
949 static void
950 printstat(tcp, addr)
951 struct tcb *tcp;
952 long addr;
953 {
954         struct stat statbuf;
955
956 #ifdef LINUXSPARC
957         if (current_personality == 1) {
958                 printstatsol(tcp, addr);
959                 return;
960         }
961 #ifdef SPARC64
962         else if (current_personality == 2) {
963                 printstat_sparc64(tcp, addr);
964                 return;
965         }
966 #endif
967 #endif /* LINUXSPARC */
968
969         if (!addr) {
970                 tprintf("NULL");
971                 return;
972         }
973         if (syserror(tcp) || !verbose(tcp)) {
974                 tprintf("%#lx", addr);
975                 return;
976         }
977         if (umove(tcp, addr, &statbuf) < 0) {
978                 tprintf("{...}");
979                 return;
980         }
981
982         realprintstat(tcp, &statbuf);
983 }
984 #endif  /* !HAVE_LONG_LONG_OFF_T */
985
986 #ifdef HAVE_STAT64
987 static void
988 printstat64(tcp, addr)
989 struct tcb *tcp;
990 long addr;
991 {
992         struct stat64 statbuf;
993
994 #ifdef LINUXSPARC
995         if (current_personality == 1) {
996                 printstatsol(tcp, addr);
997                 return;
998         }
999 #ifdef SPARC64
1000         else if (current_personality == 2) {
1001                 printstat_sparc64(tcp, addr);
1002                 return;
1003         }
1004 #endif
1005 #endif /* LINUXSPARC */
1006
1007         if (!addr) {
1008                 tprintf("NULL");
1009                 return;
1010         }
1011         if (syserror(tcp) || !verbose(tcp)) {
1012                 tprintf("%#lx", addr);
1013                 return;
1014         }
1015         if (umove(tcp, addr, &statbuf) < 0) {
1016                 tprintf("{...}");
1017                 return;
1018         }
1019
1020         if (!abbrev(tcp)) {
1021 #ifdef HAVE_LONG_LONG
1022                 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1023 #else
1024                 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
1025 #endif
1026                         (unsigned long) major(statbuf.st_dev),
1027                         (unsigned long) minor(statbuf.st_dev),
1028 #ifdef HAVE_LONG_LONG
1029                         (unsigned long long) statbuf.st_ino,
1030 #else
1031                         (unsigned long) statbuf.st_ino,
1032 #endif
1033                         sprintmode(statbuf.st_mode));
1034                 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1035                         (unsigned long) statbuf.st_nlink,
1036                         (unsigned long) statbuf.st_uid,
1037                         (unsigned long) statbuf.st_gid);
1038 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1039                 tprintf("st_blksize=%lu, ",
1040                         (unsigned long) statbuf.st_blksize);
1041 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1042 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
1043                 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1044 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
1045         }
1046         else
1047                 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1048         switch (statbuf.st_mode & S_IFMT) {
1049         case S_IFCHR: case S_IFBLK:
1050 #ifdef HAVE_STRUCT_STAT_ST_RDEV
1051                 tprintf("st_rdev=makedev(%lu, %lu), ",
1052                         (unsigned long) major(statbuf.st_rdev),
1053                         (unsigned long) minor(statbuf.st_rdev));
1054 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
1055                 tprintf("st_size=makedev(%lu, %lu), ",
1056                         (unsigned long) major(statbuf.st_size),
1057                         (unsigned long) minor(statbuf.st_size));
1058 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
1059                 break;
1060         default:
1061                 tprintf("st_size=%llu, ", statbuf.st_size);
1062                 break;
1063         }
1064         if (!abbrev(tcp)) {
1065                 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1066                 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1067                 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1068 #if HAVE_STRUCT_STAT_ST_FLAGS
1069                 tprintf(", st_flags=");
1070                 printflags(fileflags, statbuf.st_flags, "UF_???");
1071 #endif
1072 #if HAVE_STRUCT_STAT_ST_ACLCNT
1073                 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1074 #endif
1075 #if HAVE_STRUCT_STAT_ST_LEVEL
1076                 tprintf(", st_level=%ld", statbuf.st_level);
1077 #endif
1078 #if HAVE_STRUCT_STAT_ST_FSTYPE
1079                 tprintf(", st_fstype=%.*s",
1080                         (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1081 #endif
1082 #if HAVE_STRUCT_STAT_ST_GEN
1083                 tprintf(", st_gen=%u", statbuf.st_gen);
1084 #endif
1085                 tprintf("}");
1086         }
1087         else
1088                 tprintf("...}");
1089 }
1090 #endif /* HAVE_STAT64 */
1091
1092 #if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1093 static void
1094 convertoldstat(oldbuf, newbuf)
1095 const struct __old_kernel_stat *oldbuf;
1096 struct stat *newbuf;
1097 {
1098     newbuf->st_dev=oldbuf->st_dev;
1099     newbuf->st_ino=oldbuf->st_ino;
1100     newbuf->st_mode=oldbuf->st_mode;
1101     newbuf->st_nlink=oldbuf->st_nlink;
1102     newbuf->st_uid=oldbuf->st_uid;
1103     newbuf->st_gid=oldbuf->st_gid;
1104     newbuf->st_rdev=oldbuf->st_rdev;
1105     newbuf->st_size=oldbuf->st_size;
1106     newbuf->st_atime=oldbuf->st_atime;
1107     newbuf->st_mtime=oldbuf->st_mtime;
1108     newbuf->st_ctime=oldbuf->st_ctime;
1109     newbuf->st_blksize=0;       /* not supported in old_stat */
1110     newbuf->st_blocks=0;                /* not supported in old_stat */
1111 }
1112
1113
1114 static void
1115 printoldstat(tcp, addr)
1116 struct tcb *tcp;
1117 long addr;
1118 {
1119         struct __old_kernel_stat statbuf;
1120         struct stat newstatbuf;
1121
1122 #ifdef LINUXSPARC
1123         if (current_personality == 1) {
1124                 printstatsol(tcp, addr);
1125                 return;
1126         }
1127 #endif /* LINUXSPARC */
1128
1129         if (!addr) {
1130                 tprintf("NULL");
1131                 return;
1132         }
1133         if (syserror(tcp) || !verbose(tcp)) {
1134                 tprintf("%#lx", addr);
1135                 return;
1136         }
1137         if (umove(tcp, addr, &statbuf) < 0) {
1138                 tprintf("{...}");
1139                 return;
1140         }
1141
1142         convertoldstat(&statbuf, &newstatbuf);
1143         realprintstat(tcp, &newstatbuf);
1144 }
1145 #endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
1146
1147 #ifndef HAVE_LONG_LONG_OFF_T
1148 int
1149 sys_stat(tcp)
1150 struct tcb *tcp;
1151 {
1152         if (entering(tcp)) {
1153                 printpath(tcp, tcp->u_arg[0]);
1154                 tprintf(", ");
1155         } else {
1156                 printstat(tcp, tcp->u_arg[1]);
1157         }
1158         return 0;
1159 }
1160 #endif
1161
1162 int
1163 sys_stat64(tcp)
1164 struct tcb *tcp;
1165 {
1166 #ifdef HAVE_STAT64
1167         if (entering(tcp)) {
1168                 printpath(tcp, tcp->u_arg[0]);
1169                 tprintf(", ");
1170         } else {
1171                 printstat64(tcp, tcp->u_arg[1]);
1172         }
1173         return 0;
1174 #else
1175         return printargs(tcp);
1176 #endif
1177 }
1178
1179 #ifdef LINUX
1180 static const struct xlat fstatatflags[] = {
1181 #ifndef AT_SYMLINK_NOFOLLOW
1182 # define AT_SYMLINK_NOFOLLOW     0x100
1183 #endif
1184         { AT_SYMLINK_NOFOLLOW,  "AT_SYMLINK_NOFOLLOW"   },
1185         { 0,                    NULL                    },
1186 };
1187
1188 int
1189 sys_newfstatat(struct tcb *tcp)
1190 {
1191         if (entering(tcp)) {
1192                 print_dirfd(tcp->u_arg[0]);
1193                 printpath(tcp, tcp->u_arg[1]);
1194                 tprintf(", ");
1195         } else {
1196 #ifdef HAVE_STAT64
1197                 printstat64(tcp, tcp->u_arg[2]);
1198 #else
1199                 printstat(tcp, tcp->u_arg[2]);
1200 #endif
1201                 tprintf(", ");
1202                 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1203         }
1204         return 0;
1205 }
1206 #endif
1207
1208 #if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1209 int
1210 sys_oldstat(tcp)
1211 struct tcb *tcp;
1212 {
1213         if (entering(tcp)) {
1214                 printpath(tcp, tcp->u_arg[0]);
1215                 tprintf(", ");
1216         } else {
1217                 printoldstat(tcp, tcp->u_arg[1]);
1218         }
1219         return 0;
1220 }
1221 #endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
1222
1223 #ifndef HAVE_LONG_LONG_OFF_T
1224 int
1225 sys_fstat(tcp)
1226 struct tcb *tcp;
1227 {
1228         if (entering(tcp))
1229                 tprintf("%ld, ", tcp->u_arg[0]);
1230         else {
1231                 printstat(tcp, tcp->u_arg[1]);
1232         }
1233         return 0;
1234 }
1235 #endif
1236
1237 int
1238 sys_fstat64(tcp)
1239 struct tcb *tcp;
1240 {
1241 #ifdef HAVE_STAT64
1242         if (entering(tcp))
1243                 tprintf("%ld, ", tcp->u_arg[0]);
1244         else {
1245                 printstat64(tcp, tcp->u_arg[1]);
1246         }
1247         return 0;
1248 #else
1249         return printargs(tcp);
1250 #endif
1251 }
1252
1253 #if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1254 int
1255 sys_oldfstat(tcp)
1256 struct tcb *tcp;
1257 {
1258         if (entering(tcp))
1259                 tprintf("%ld, ", tcp->u_arg[0]);
1260         else {
1261                 printoldstat(tcp, tcp->u_arg[1]);
1262         }
1263         return 0;
1264 }
1265 #endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
1266
1267 #ifndef HAVE_LONG_LONG_OFF_T
1268 int
1269 sys_lstat(tcp)
1270 struct tcb *tcp;
1271 {
1272         if (entering(tcp)) {
1273                 printpath(tcp, tcp->u_arg[0]);
1274                 tprintf(", ");
1275         } else {
1276                 printstat(tcp, tcp->u_arg[1]);
1277         }
1278         return 0;
1279 }
1280 #endif
1281
1282 int
1283 sys_lstat64(tcp)
1284 struct tcb *tcp;
1285 {
1286 #ifdef HAVE_STAT64
1287         if (entering(tcp)) {
1288                 printpath(tcp, tcp->u_arg[0]);
1289                 tprintf(", ");
1290         } else {
1291                 printstat64(tcp, tcp->u_arg[1]);
1292         }
1293         return 0;
1294 #else
1295         return printargs(tcp);
1296 #endif
1297 }
1298
1299 #if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1300 int
1301 sys_oldlstat(tcp)
1302 struct tcb *tcp;
1303 {
1304         if (entering(tcp)) {
1305                 printpath(tcp, tcp->u_arg[0]);
1306                 tprintf(", ");
1307         } else {
1308                 printoldstat(tcp, tcp->u_arg[1]);
1309         }
1310         return 0;
1311 }
1312 #endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
1313
1314
1315 #if defined(SVR4) || defined(LINUXSPARC)
1316
1317 int
1318 sys_xstat(tcp)
1319 struct tcb *tcp;
1320 {
1321         if (entering(tcp)) {
1322                 tprintf("%ld, ", tcp->u_arg[0]);
1323                 printpath(tcp, tcp->u_arg[1]);
1324                 tprintf(", ");
1325         } else {
1326 #ifdef _STAT64_VER
1327                 if (tcp->u_arg[0] == _STAT64_VER)
1328                         printstat64 (tcp, tcp->u_arg[2]);
1329                 else
1330 #endif
1331                 printstat(tcp, tcp->u_arg[2]);
1332         }
1333         return 0;
1334 }
1335
1336 int
1337 sys_fxstat(tcp)
1338 struct tcb *tcp;
1339 {
1340         if (entering(tcp))
1341                 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1342         else {
1343 #ifdef _STAT64_VER
1344                 if (tcp->u_arg[0] == _STAT64_VER)
1345                         printstat64 (tcp, tcp->u_arg[2]);
1346                 else
1347 #endif
1348                 printstat(tcp, tcp->u_arg[2]);
1349         }
1350         return 0;
1351 }
1352
1353 int
1354 sys_lxstat(tcp)
1355 struct tcb *tcp;
1356 {
1357         if (entering(tcp)) {
1358                 tprintf("%ld, ", tcp->u_arg[0]);
1359                 printpath(tcp, tcp->u_arg[1]);
1360                 tprintf(", ");
1361         } else {
1362 #ifdef _STAT64_VER
1363                 if (tcp->u_arg[0] == _STAT64_VER)
1364                         printstat64 (tcp, tcp->u_arg[2]);
1365                 else
1366 #endif
1367                 printstat(tcp, tcp->u_arg[2]);
1368         }
1369         return 0;
1370 }
1371
1372 int
1373 sys_xmknod(tcp)
1374 struct tcb *tcp;
1375 {
1376         int mode = tcp->u_arg[2];
1377
1378         if (entering(tcp)) {
1379                 tprintf("%ld, ", tcp->u_arg[0]);
1380                 printpath(tcp, tcp->u_arg[1]);
1381                 tprintf(", %s", sprintmode(mode));
1382                 switch (mode & S_IFMT) {
1383                 case S_IFCHR: case S_IFBLK:
1384 #ifdef LINUXSPARC
1385                         tprintf(", makedev(%lu, %lu)",
1386                                 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1387                                 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1388 #else
1389                         tprintf(", makedev(%lu, %lu)",
1390                                 (unsigned long) major(tcp->u_arg[3]),
1391                                 (unsigned long) minor(tcp->u_arg[3]));
1392 #endif
1393                         break;
1394                 default:
1395                         break;
1396                 }
1397         }
1398         return 0;
1399 }
1400
1401 #ifdef HAVE_SYS_ACL_H
1402
1403 #include <sys/acl.h>
1404
1405 static const struct xlat aclcmds[] = {
1406 #ifdef SETACL
1407         { SETACL,       "SETACL"        },
1408 #endif
1409 #ifdef GETACL
1410         { GETACL,       "GETACL"        },
1411 #endif
1412 #ifdef GETACLCNT
1413         { GETACLCNT,    "GETACLCNT"     },
1414 #endif
1415 #ifdef ACL_GET
1416         { ACL_GET,      "ACL_GET"       },
1417 #endif
1418 #ifdef ACL_SET
1419         { ACL_SET,      "ACL_SET"       },
1420 #endif
1421 #ifdef ACL_CNT
1422         { ACL_CNT,      "ACL_CNT"       },
1423 #endif
1424         { 0,            NULL            },
1425 };
1426
1427 int
1428 sys_acl(tcp)
1429 struct tcb *tcp;
1430 {
1431         if (entering(tcp)) {
1432                 printpath(tcp, tcp->u_arg[0]);
1433                 tprintf(", ");
1434                 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1435                 tprintf(", %ld", tcp->u_arg[2]);
1436                 /*
1437                  * FIXME - dump out the list of aclent_t's pointed to
1438                  * by "tcp->u_arg[3]" if it's not NULL.
1439                  */
1440                 if (tcp->u_arg[3])
1441                         tprintf(", %#lx", tcp->u_arg[3]);
1442                 else
1443                         tprintf(", NULL");
1444         }
1445         return 0;
1446 }
1447
1448
1449 int
1450 sys_facl(tcp)
1451 struct tcb *tcp;
1452 {
1453         if (entering(tcp)) {
1454                 tprintf("%ld, ", tcp->u_arg[0]);
1455                 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1456                 tprintf(", %ld", tcp->u_arg[2]);
1457                 /*
1458                  * FIXME - dump out the list of aclent_t's pointed to
1459                  * by "tcp->u_arg[3]" if it's not NULL.
1460                  */
1461                 if (tcp->u_arg[3])
1462                         tprintf(", %#lx", tcp->u_arg[3]);
1463                 else
1464                         tprintf(", NULL");
1465         }
1466         return 0;
1467 }
1468
1469
1470 static const struct xlat aclipc[] = {
1471 #ifdef IPC_SHM
1472         { IPC_SHM,      "IPC_SHM"       },
1473 #endif
1474 #ifdef IPC_SEM
1475         { IPC_SEM,      "IPC_SEM"       },
1476 #endif
1477 #ifdef IPC_MSG
1478         { IPC_MSG,      "IPC_MSG"       },
1479 #endif
1480         { 0,            NULL            },
1481 };
1482
1483
1484 int
1485 sys_aclipc(tcp)
1486 struct tcb *tcp;
1487 {
1488         if (entering(tcp)) {
1489                 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1490                 tprintf(", %#lx, ", tcp->u_arg[1]);
1491                 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1492                 tprintf(", %ld", tcp->u_arg[3]);
1493                 /*
1494                  * FIXME - dump out the list of aclent_t's pointed to
1495                  * by "tcp->u_arg[4]" if it's not NULL.
1496                  */
1497                 if (tcp->u_arg[4])
1498                         tprintf(", %#lx", tcp->u_arg[4]);
1499                 else
1500                         tprintf(", NULL");
1501         }
1502         return 0;
1503 }
1504
1505
1506
1507 #endif /* HAVE_SYS_ACL_H */
1508
1509 #endif /* SVR4 || LINUXSPARC */
1510
1511 #ifdef LINUX
1512
1513 static const struct xlat fsmagic[] = {
1514         { 0x73757245,   "CODA_SUPER_MAGIC"      },
1515         { 0x012ff7b7,   "COH_SUPER_MAGIC"       },
1516         { 0x1373,       "DEVFS_SUPER_MAGIC"     },
1517         { 0x1cd1,       "DEVPTS_SUPER_MAGIC"    },
1518         { 0x414A53,     "EFS_SUPER_MAGIC"       },
1519         { 0xef51,       "EXT2_OLD_SUPER_MAGIC"  },
1520         { 0xef53,       "EXT2_SUPER_MAGIC"      },
1521         { 0x137d,       "EXT_SUPER_MAGIC"       },
1522         { 0xf995e849,   "HPFS_SUPER_MAGIC"      },
1523         { 0x9660,       "ISOFS_SUPER_MAGIC"     },
1524         { 0x137f,       "MINIX_SUPER_MAGIC"     },
1525         { 0x138f,       "MINIX_SUPER_MAGIC2"    },
1526         { 0x2468,       "MINIX2_SUPER_MAGIC"    },
1527         { 0x2478,       "MINIX2_SUPER_MAGIC2"   },
1528         { 0x4d44,       "MSDOS_SUPER_MAGIC"     },
1529         { 0x564c,       "NCP_SUPER_MAGIC"       },
1530         { 0x6969,       "NFS_SUPER_MAGIC"       },
1531         { 0x9fa0,       "PROC_SUPER_MAGIC"      },
1532         { 0x002f,       "QNX4_SUPER_MAGIC"      },
1533         { 0x52654973,   "REISERFS_SUPER_MAGIC"  },
1534         { 0x02011994,   "SHMFS_SUPER_MAGIC"     },
1535         { 0x517b,       "SMB_SUPER_MAGIC"       },
1536         { 0x012ff7b6,   "SYSV2_SUPER_MAGIC"     },
1537         { 0x012ff7b5,   "SYSV4_SUPER_MAGIC"     },
1538         { 0x00011954,   "UFS_MAGIC"             },
1539         { 0x54190100,   "UFS_CIGAM"             },
1540         { 0x012ff7b4,   "XENIX_SUPER_MAGIC"     },
1541         { 0x012fd16d,   "XIAFS_SUPER_MAGIC"     },
1542         { 0x62656572,   "SYSFS_MAGIC"           },
1543         { 0,            NULL                    },
1544 };
1545
1546 #endif /* LINUX */
1547
1548 #ifndef SVR4
1549
1550 static const char *
1551 sprintfstype(magic)
1552 int magic;
1553 {
1554         static char buf[32];
1555 #ifdef LINUX
1556         const char *s;
1557
1558         s = xlookup(fsmagic, magic);
1559         if (s) {
1560                 sprintf(buf, "\"%s\"", s);
1561                 return buf;
1562         }
1563 #endif /* LINUX */
1564         sprintf(buf, "%#x", magic);
1565         return buf;
1566 }
1567
1568 static void
1569 printstatfs(tcp, addr)
1570 struct tcb *tcp;
1571 long addr;
1572 {
1573         struct statfs statbuf;
1574
1575         if (syserror(tcp) || !verbose(tcp)) {
1576                 tprintf("%#lx", addr);
1577                 return;
1578         }
1579         if (umove(tcp, addr, &statbuf) < 0) {
1580                 tprintf("{...}");
1581                 return;
1582         }
1583 #ifdef ALPHA
1584
1585         tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1586                 sprintfstype(statbuf.f_type),
1587                 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1588         tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1589                 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1590                 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1591                 statbuf.f_namelen);
1592 #else /* !ALPHA */
1593         tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1594                 sprintfstype(statbuf.f_type),
1595                 (unsigned long)statbuf.f_bsize,
1596                 (unsigned long)statbuf.f_blocks,
1597                 (unsigned long)statbuf.f_bfree);
1598         tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1599                 (unsigned long)statbuf.f_bavail,
1600                 (unsigned long)statbuf.f_files,
1601                 (unsigned long)statbuf.f_ffree,
1602                 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1603 #ifdef LINUX
1604         tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1605 #endif /* LINUX */
1606 #endif /* !ALPHA */
1607 #ifdef _STATFS_F_FRSIZE
1608         tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1609 #endif
1610         tprintf("}");
1611 }
1612
1613 int
1614 sys_statfs(tcp)
1615 struct tcb *tcp;
1616 {
1617         if (entering(tcp)) {
1618                 printpath(tcp, tcp->u_arg[0]);
1619                 tprintf(", ");
1620         } else {
1621                 printstatfs(tcp, tcp->u_arg[1]);
1622         }
1623         return 0;
1624 }
1625
1626 int
1627 sys_fstatfs(tcp)
1628 struct tcb *tcp;
1629 {
1630         if (entering(tcp)) {
1631                 tprintf("%lu, ", tcp->u_arg[0]);
1632         } else {
1633                 printstatfs(tcp, tcp->u_arg[1]);
1634         }
1635         return 0;
1636 }
1637
1638 #ifdef LINUX
1639 static void
1640 printstatfs64(tcp, addr)
1641 struct tcb *tcp;
1642 long addr;
1643 {
1644         struct statfs64 statbuf;
1645
1646         if (syserror(tcp) || !verbose(tcp)) {
1647                 tprintf("%#lx", addr);
1648                 return;
1649         }
1650         if (umove(tcp, addr, &statbuf) < 0) {
1651                 tprintf("{...}");
1652                 return;
1653         }
1654         tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
1655                 sprintfstype(statbuf.f_type),
1656                 (unsigned long long)statbuf.f_bsize,
1657                 (unsigned long long)statbuf.f_blocks,
1658                 (unsigned long long)statbuf.f_bfree);
1659         tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1660                 (unsigned long long)statbuf.f_bavail,
1661                 (unsigned long long)statbuf.f_files,
1662                 (unsigned long long)statbuf.f_ffree,
1663                 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1664         tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1665 #ifdef _STATFS_F_FRSIZE
1666         tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
1667 #endif
1668         tprintf("}");
1669 }
1670
1671 int
1672 sys_statfs64(tcp)
1673 struct tcb *tcp;
1674 {
1675         if (entering(tcp)) {
1676                 printpath(tcp, tcp->u_arg[0]);
1677                 tprintf(", %lu, ", tcp->u_arg[1]);
1678         } else {
1679                 if (tcp->u_arg[1] == sizeof (struct statfs64))
1680                         printstatfs64(tcp, tcp->u_arg[2]);
1681                 else
1682                         tprintf("{???}");
1683         }
1684         return 0;
1685 }
1686
1687 int
1688 sys_fstatfs64(tcp)
1689 struct tcb *tcp;
1690 {
1691         if (entering(tcp)) {
1692                 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1693         } else {
1694                 if (tcp->u_arg[1] == sizeof (struct statfs64))
1695                         printstatfs64(tcp, tcp->u_arg[2]);
1696                 else
1697                         tprintf("{???}");
1698         }
1699         return 0;
1700 }
1701 #endif
1702
1703 #if defined(LINUX) && defined(__alpha)
1704
1705 int
1706 osf_statfs(tcp)
1707 struct tcb *tcp;
1708 {
1709         if (entering(tcp)) {
1710                 printpath(tcp, tcp->u_arg[0]);
1711                 tprintf(", ");
1712         } else {
1713                 printstatfs(tcp, tcp->u_arg[1]);
1714                 tprintf(", %lu", tcp->u_arg[2]);
1715         }
1716         return 0;
1717 }
1718
1719 int
1720 osf_fstatfs(tcp)
1721 struct tcb *tcp;
1722 {
1723         if (entering(tcp)) {
1724                 tprintf("%lu, ", tcp->u_arg[0]);
1725         } else {
1726                 printstatfs(tcp, tcp->u_arg[1]);
1727                 tprintf(", %lu", tcp->u_arg[2]);
1728         }
1729         return 0;
1730 }
1731 #endif /* LINUX && __alpha */
1732
1733 #endif /* !SVR4 */
1734
1735 #ifdef SUNOS4
1736
1737 int
1738 sys_ustat(tcp)
1739 struct tcb *tcp;
1740 {
1741         struct ustat statbuf;
1742
1743         if (entering(tcp)) {
1744                 tprintf("makedev(%lu, %lu), ",
1745                                 (long) major(tcp->u_arg[0]),
1746                                 (long) minor(tcp->u_arg[0]));
1747         }
1748         else {
1749                 if (syserror(tcp) || !verbose(tcp))
1750                         tprintf("%#lx", tcp->u_arg[1]);
1751                 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1752                         tprintf("{...}");
1753                 else {
1754                         tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1755                                 statbuf.f_tfree, statbuf.f_tinode);
1756                         tprintf("f_fname=\"%.*s\", ",
1757                                 (int) sizeof(statbuf.f_fname),
1758                                 statbuf.f_fname);
1759                         tprintf("f_fpack=\"%.*s\"}",
1760                                 (int) sizeof(statbuf.f_fpack),
1761                                 statbuf.f_fpack);
1762                 }
1763         }
1764         return 0;
1765 }
1766
1767 #endif /* SUNOS4 */
1768
1769 int
1770 sys_pivotroot(tcp)
1771 struct tcb *tcp;
1772 {
1773         if (entering(tcp)) {
1774                 printpath(tcp, tcp->u_arg[0]);
1775                 tprintf(", ");
1776                 printpath(tcp, tcp->u_arg[1]);
1777         }
1778         return 0;
1779 }
1780
1781
1782 /* directory */
1783 int
1784 sys_chdir(tcp)
1785 struct tcb *tcp;
1786 {
1787         if (entering(tcp)) {
1788                 printpath(tcp, tcp->u_arg[0]);
1789         }
1790         return 0;
1791 }
1792
1793 static int
1794 decode_mkdir(struct tcb *tcp, int offset)
1795 {
1796         if (entering(tcp)) {
1797                 printpath(tcp, tcp->u_arg[offset]);
1798                 tprintf(", %#lo", tcp->u_arg[offset + 1]);
1799         }
1800         return 0;
1801 }
1802
1803 int
1804 sys_mkdir(struct tcb *tcp)
1805 {
1806         return decode_mkdir(tcp, 0);
1807 }
1808
1809 #ifdef LINUX
1810 int
1811 sys_mkdirat(struct tcb *tcp)
1812 {
1813         if (entering(tcp))
1814                 print_dirfd(tcp->u_arg[0]);
1815         return decode_mkdir(tcp, 1);
1816 }
1817 #endif
1818
1819 int
1820 sys_rmdir(tcp)
1821 struct tcb *tcp;
1822 {
1823         if (entering(tcp)) {
1824                 printpath(tcp, tcp->u_arg[0]);
1825         }
1826         return 0;
1827 }
1828
1829 int
1830 sys_fchdir(tcp)
1831 struct tcb *tcp;
1832 {
1833         if (entering(tcp)) {
1834                 tprintf("%ld", tcp->u_arg[0]);
1835         }
1836         return 0;
1837 }
1838
1839 int
1840 sys_chroot(tcp)
1841 struct tcb *tcp;
1842 {
1843         if (entering(tcp)) {
1844                 printpath(tcp, tcp->u_arg[0]);
1845         }
1846         return 0;
1847 }
1848
1849 #if defined(SUNOS4) || defined(SVR4)
1850 int
1851 sys_fchroot(tcp)
1852 struct tcb *tcp;
1853 {
1854         if (entering(tcp)) {
1855                 tprintf("%ld", tcp->u_arg[0]);
1856         }
1857         return 0;
1858 }
1859 #endif /* SUNOS4 || SVR4 */
1860
1861 int
1862 sys_link(tcp)
1863 struct tcb *tcp;
1864 {
1865         if (entering(tcp)) {
1866                 printpath(tcp, tcp->u_arg[0]);
1867                 tprintf(", ");
1868                 printpath(tcp, tcp->u_arg[1]);
1869         }
1870         return 0;
1871 }
1872
1873 #ifdef LINUX
1874 int
1875 sys_linkat(struct tcb *tcp)
1876 {
1877         if (entering(tcp)) {
1878                 print_dirfd(tcp->u_arg[0]);
1879                 printpath(tcp, tcp->u_arg[1]);
1880                 tprintf(", ");
1881                 print_dirfd(tcp->u_arg[2]);
1882                 printpath(tcp, tcp->u_arg[3]);
1883                 tprintf(", %ld", tcp->u_arg[4]);
1884         }
1885         return 0;
1886 }
1887 #endif
1888
1889 int
1890 sys_unlink(tcp)
1891 struct tcb *tcp;
1892 {
1893         if (entering(tcp)) {
1894                 printpath(tcp, tcp->u_arg[0]);
1895         }
1896         return 0;
1897 }
1898
1899 #ifdef LINUX
1900 static const struct xlat unlinkatflags[] = {
1901 #ifndef AT_REMOVEDIR
1902 # define AT_REMOVEDIR            0x200
1903 #endif
1904         { AT_REMOVEDIR, "AT_REMOVEDIR"  },
1905         { 0,            NULL            },
1906 };
1907
1908 int
1909 sys_unlinkat(struct tcb *tcp)
1910 {
1911         if (entering(tcp)) {
1912                 print_dirfd(tcp->u_arg[0]);
1913                 printpath(tcp, tcp->u_arg[1]);
1914                 tprintf(", ");
1915                 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1916         }
1917         return 0;
1918 }
1919 #endif
1920
1921 int
1922 sys_symlink(tcp)
1923 struct tcb *tcp;
1924 {
1925         if (entering(tcp)) {
1926                 printpath(tcp, tcp->u_arg[0]);
1927                 tprintf(", ");
1928                 printpath(tcp, tcp->u_arg[1]);
1929         }
1930         return 0;
1931 }
1932
1933 #ifdef LINUX
1934 int
1935 sys_symlinkat(struct tcb *tcp)
1936 {
1937         if (entering(tcp)) {
1938                 printpath(tcp, tcp->u_arg[0]);
1939                 tprintf(", ");
1940                 print_dirfd(tcp->u_arg[1]);
1941                 printpath(tcp, tcp->u_arg[2]);
1942         }
1943         return 0;
1944 }
1945 #endif
1946
1947 static int
1948 decode_readlink(struct tcb *tcp, int offset)
1949 {
1950         if (entering(tcp)) {
1951                 printpath(tcp, tcp->u_arg[offset]);
1952                 tprintf(", ");
1953         } else {
1954                 if (syserror(tcp))
1955                         tprintf("%#lx", tcp->u_arg[offset + 1]);
1956                 else
1957                         printpathn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1958                 tprintf(", %lu", tcp->u_arg[offset + 2]);
1959         }
1960         return 0;
1961 }
1962
1963 int
1964 sys_readlink(struct tcb *tcp)
1965 {
1966         return decode_readlink(tcp, 0);
1967 }
1968
1969 #ifdef LINUX
1970 int
1971 sys_readlinkat(struct tcb *tcp)
1972 {
1973         if (entering(tcp))
1974                 print_dirfd(tcp->u_arg[0]);
1975         return decode_readlink(tcp, 1);
1976 }
1977 #endif
1978
1979 int
1980 sys_rename(tcp)
1981 struct tcb *tcp;
1982 {
1983         if (entering(tcp)) {
1984                 printpath(tcp, tcp->u_arg[0]);
1985                 tprintf(", ");
1986                 printpath(tcp, tcp->u_arg[1]);
1987         }
1988         return 0;
1989 }
1990
1991 #ifdef LINUX
1992 int
1993 sys_renameat(struct tcb *tcp)
1994 {
1995         if (entering(tcp)) {
1996                 print_dirfd(tcp->u_arg[0]);
1997                 printpath(tcp, tcp->u_arg[1]);
1998                 tprintf(", ");
1999                 print_dirfd(tcp->u_arg[2]);
2000                 printpath(tcp, tcp->u_arg[3]);
2001         }
2002         return 0;
2003 }
2004 #endif
2005
2006 int
2007 sys_chown(tcp)
2008 struct tcb *tcp;
2009 {
2010         if (entering(tcp)) {
2011                 printpath(tcp, tcp->u_arg[0]);
2012                 printuid(", ", tcp->u_arg[1]);
2013                 printuid(", ", tcp->u_arg[2]);
2014         }
2015         return 0;
2016 }
2017
2018 #ifdef LINUX
2019 int
2020 sys_fchownat(struct tcb *tcp)
2021 {
2022         if (entering(tcp)) {
2023                 print_dirfd(tcp->u_arg[0]);
2024                 printpath(tcp, tcp->u_arg[1]);
2025                 printuid(", ", tcp->u_arg[2]);
2026                 printuid(", ", tcp->u_arg[3]);
2027                 tprintf(", ");
2028                 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
2029         }
2030         return 0;
2031 }
2032 #endif
2033
2034 int
2035 sys_fchown(tcp)
2036 struct tcb *tcp;
2037 {
2038         if (entering(tcp)) {
2039                 tprintf("%ld", tcp->u_arg[0]);
2040                 printuid(", ", tcp->u_arg[1]);
2041                 printuid(", ", tcp->u_arg[2]);
2042         }
2043         return 0;
2044 }
2045
2046 static int
2047 decode_chmod(struct tcb *tcp, int offset)
2048 {
2049         if (entering(tcp)) {
2050                 printpath(tcp, tcp->u_arg[offset]);
2051                 tprintf(", %#lo", tcp->u_arg[offset + 1]);
2052         }
2053         return 0;
2054 }
2055
2056 int
2057 sys_chmod(struct tcb *tcp)
2058 {
2059         return decode_chmod(tcp, 0);
2060 }
2061
2062 #ifdef LINUX
2063 int
2064 sys_fchmodat(struct tcb *tcp)
2065 {
2066         if (entering(tcp))
2067                 print_dirfd(tcp->u_arg[0]);
2068         return decode_chmod(tcp, 1);
2069 }
2070 #endif
2071
2072 int
2073 sys_fchmod(tcp)
2074 struct tcb *tcp;
2075 {
2076         if (entering(tcp)) {
2077                 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
2078         }
2079         return 0;
2080 }
2081
2082 #ifdef ALPHA
2083 int
2084 sys_osf_utimes(tcp)
2085 struct tcb *tcp;
2086 {
2087     if (entering(tcp)) {
2088         printpath(tcp, tcp->u_arg[0]);
2089         tprintf(", ");
2090         printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32);
2091     }
2092     return 0;
2093 }
2094 #endif
2095
2096 static int
2097 decode_utimes(struct tcb *tcp, int offset)
2098 {
2099         if (entering(tcp)) {
2100                 printpath(tcp, tcp->u_arg[offset]);
2101                 tprintf(", ");
2102                 printtv(tcp, tcp->u_arg[offset + 1]);
2103         }
2104         return 0;
2105 }
2106
2107 int
2108 sys_utimes(struct tcb *tcp)
2109 {
2110         return decode_utimes(tcp, 0);
2111 }
2112
2113 #ifdef LINUX
2114 int
2115 sys_futimesat(struct tcb *tcp)
2116 {
2117         if (entering(tcp))
2118                 print_dirfd(tcp->u_arg[0]);
2119         return decode_utimes(tcp, 1);
2120 }
2121 #endif
2122
2123 int
2124 sys_utime(tcp)
2125 struct tcb *tcp;
2126 {
2127         long ut[2];
2128
2129         if (entering(tcp)) {
2130                 printpath(tcp, tcp->u_arg[0]);
2131                 tprintf(", ");
2132                 if (!tcp->u_arg[1])
2133                         tprintf("NULL");
2134                 else if (!verbose(tcp))
2135                         tprintf("%#lx", tcp->u_arg[1]);
2136                 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
2137                     (char *) ut) < 0)
2138                         tprintf("[?, ?]");
2139                 else {
2140                         tprintf("[%s,", sprinttime(ut[0]));
2141                         tprintf(" %s]", sprinttime(ut[1]));
2142                 }
2143         }
2144         return 0;
2145 }
2146
2147 static int
2148 decode_mknod(struct tcb *tcp, int offset)
2149 {
2150         int mode = tcp->u_arg[offset + 1];
2151
2152         if (entering(tcp)) {
2153                 printpath(tcp, tcp->u_arg[offset]);
2154                 tprintf(", %s", sprintmode(mode));
2155                 switch (mode & S_IFMT) {
2156                 case S_IFCHR: case S_IFBLK:
2157 #ifdef LINUXSPARC
2158                         if (current_personality == 1)
2159                         tprintf(", makedev(%lu, %lu)",
2160                                 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2161                                 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
2162                         else
2163 #endif
2164                         tprintf(", makedev(%lu, %lu)",
2165                                 (unsigned long) major(tcp->u_arg[offset + 2]),
2166                                 (unsigned long) minor(tcp->u_arg[offset + 2]));
2167                         break;
2168                 default:
2169                         break;
2170                 }
2171         }
2172         return 0;
2173 }
2174
2175 int
2176 sys_mknod(struct tcb *tcp)
2177 {
2178         return decode_mknod(tcp, 0);
2179 }
2180
2181 #ifdef LINUX
2182 int
2183 sys_mknodat(struct tcb *tcp)
2184 {
2185         if (entering(tcp))
2186                 print_dirfd(tcp->u_arg[0]);
2187         return decode_mknod(tcp, 1);
2188 }
2189 #endif
2190
2191 #ifdef FREEBSD
2192 int
2193 sys_mkfifo(tcp)
2194 struct tcb *tcp;
2195 {
2196         if (entering(tcp)) {
2197                 printpath(tcp, tcp->u_arg[0]);
2198                 tprintf(", %#lo", tcp->u_arg[1]);
2199         }
2200         return 0;
2201 }
2202 #endif /* FREEBSD */
2203
2204 int
2205 sys_fsync(tcp)
2206 struct tcb *tcp;
2207 {
2208         if (entering(tcp)) {
2209                 tprintf("%ld", tcp->u_arg[0]);
2210         }
2211         return 0;
2212 }
2213
2214 #ifdef LINUX
2215
2216 static void
2217 printdir(tcp, addr)
2218 struct tcb *tcp;
2219 long addr;
2220 {
2221         struct dirent d;
2222
2223         if (!verbose(tcp)) {
2224                 tprintf("%#lx", addr);
2225                 return;
2226         }
2227         if (umove(tcp, addr, &d) < 0) {
2228                 tprintf("{...}");
2229                 return;
2230         }
2231         tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
2232         tprintf("d_name=");
2233         printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2234         tprintf("}");
2235 }
2236
2237 int
2238 sys_readdir(tcp)
2239 struct tcb *tcp;
2240 {
2241         if (entering(tcp)) {
2242                 tprintf("%lu, ", tcp->u_arg[0]);
2243         } else {
2244                 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2245                         tprintf("%#lx", tcp->u_arg[1]);
2246                 else
2247                         printdir(tcp, tcp->u_arg[1]);
2248                 /* Not much point in printing this out, it is always 1. */
2249                 if (tcp->u_arg[2] != 1)
2250                         tprintf(", %lu", tcp->u_arg[2]);
2251         }
2252         return 0;
2253 }
2254
2255 #endif /* LINUX */
2256
2257 #if defined FREEBSD || defined LINUX
2258 static const struct xlat direnttypes[] = {
2259         { DT_UNKNOWN,   "DT_UNKNOWN"    },
2260         { DT_FIFO,      "DT_FIFO"       },
2261         { DT_CHR,       "DT_CHR"        },
2262         { DT_DIR,       "DT_DIR"        },
2263         { DT_BLK,       "DT_BLK"        },
2264         { DT_REG,       "DT_REG"        },
2265         { DT_LNK,       "DT_LNK"        },
2266         { DT_SOCK,      "DT_SOCK"       },
2267         { DT_WHT,       "DT_WHT"        },
2268         { 0,            NULL            },
2269 };
2270
2271 #endif
2272
2273 int
2274 sys_getdents(tcp)
2275 struct tcb *tcp;
2276 {
2277         int i, len, dents = 0;
2278         char *buf;
2279
2280         if (entering(tcp)) {
2281                 tprintf("%lu, ", tcp->u_arg[0]);
2282                 return 0;
2283         }
2284         if (syserror(tcp) || !verbose(tcp)) {
2285                 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2286                 return 0;
2287         }
2288         len = tcp->u_rval;
2289         if ((buf = malloc(len)) == NULL) {
2290                 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2291                 fprintf(stderr, "out of memory\n");
2292                 return 0;
2293         }
2294         if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2295                 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2296                 free(buf);
2297                 return 0;
2298         }
2299         if (!abbrev(tcp))
2300                 tprintf("{");
2301         for (i = 0; i < len;) {
2302                 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2303 #ifdef LINUX
2304                 if (!abbrev(tcp)) {
2305                         tprintf("%s{d_ino=%lu, d_off=%lu, ",
2306                                 i ? " " : "", d->d_ino, d->d_off);
2307                         tprintf("d_reclen=%u, d_name=\"%s\"}",
2308                                 d->d_reclen, d->d_name);
2309                 }
2310 #endif /* LINUX */
2311 #ifdef SVR4
2312                 if (!abbrev(tcp)) {
2313                         tprintf("%s{d_ino=%lu, d_off=%lu, ",
2314                                 i ? " " : "",
2315                                 (unsigned long) d->d_ino,
2316                                 (unsigned long) d->d_off);
2317                         tprintf("d_reclen=%u, d_name=\"%s\"}",
2318                                 d->d_reclen, d->d_name);
2319                 }
2320 #endif /* SVR4 */
2321 #ifdef SUNOS4
2322                 if (!abbrev(tcp)) {
2323                         tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2324                                 i ? " " : "", d->d_off, d->d_fileno,
2325                                 d->d_reclen);
2326                         tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2327                                 d->d_namlen, d->d_namlen, d->d_name);
2328                 }
2329 #endif /* SUNOS4 */
2330 #ifdef FREEBSD
2331                 if (!abbrev(tcp)) {
2332                         tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2333                                 i ? " " : "", d->d_fileno, d->d_reclen);
2334                         printxval(direnttypes, d->d_type, "DT_???");
2335                         tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2336                                 d->d_namlen, d->d_namlen, d->d_name);
2337                 }
2338 #endif /* FREEBSD */
2339                 if (!d->d_reclen) {
2340                         tprintf("/* d_reclen == 0, problem here */");
2341                         break;
2342                 }
2343                 i += d->d_reclen;
2344                 dents++;
2345         }
2346         if (!abbrev(tcp))
2347                 tprintf("}");
2348         else
2349                 tprintf("/* %u entries */", dents);
2350         tprintf(", %lu", tcp->u_arg[2]);
2351         free(buf);
2352         return 0;
2353 }
2354
2355
2356 #if _LFS64_LARGEFILE
2357 int
2358 sys_getdents64(tcp)
2359 struct tcb *tcp;
2360 {
2361         int i, len, dents = 0;
2362         char *buf;
2363
2364         if (entering(tcp)) {
2365                 tprintf("%lu, ", tcp->u_arg[0]);
2366                 return 0;
2367         }
2368         if (syserror(tcp) || !verbose(tcp)) {
2369                 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2370                 return 0;
2371         }
2372         len = tcp->u_rval;
2373         if ((buf = malloc(len)) == NULL) {
2374                 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2375                 fprintf(stderr, "out of memory\n");
2376                 return 0;
2377         }
2378         if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2379                 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2380                 free(buf);
2381                 return 0;
2382         }
2383         if (!abbrev(tcp))
2384                 tprintf("{");
2385         for (i = 0; i < len;) {
2386                 struct dirent64 *d = (struct dirent64 *) &buf[i];
2387 #if defined(LINUX) || defined(SVR4)
2388                 if (!abbrev(tcp)) {
2389                         tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
2390                                 i ? " " : "",
2391                                 d->d_ino,
2392                                 d->d_off);
2393 #ifdef LINUX
2394                         tprintf("d_type=");
2395                         printxval(direnttypes, d->d_type, "DT_???");
2396                         tprintf(", ");
2397 #endif
2398                         tprintf("d_reclen=%u, d_name=\"%s\"}",
2399                                 d->d_reclen, d->d_name);
2400                 }
2401 #endif /* LINUX || SVR4 */
2402 #ifdef SUNOS4
2403                 if (!abbrev(tcp)) {
2404                         tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2405                                 i ? " " : "", d->d_off, d->d_fileno,
2406                                 d->d_reclen);
2407                         tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2408                                 d->d_namlen, d->d_namlen, d->d_name);
2409                 }
2410 #endif /* SUNOS4 */
2411                 i += d->d_reclen;
2412                 dents++;
2413         }
2414         if (!abbrev(tcp))
2415                 tprintf("}");
2416         else
2417                 tprintf("/* %u entries */", dents);
2418         tprintf(", %lu", tcp->u_arg[2]);
2419         free(buf);
2420         return 0;
2421 }
2422 #endif
2423
2424 #ifdef FREEBSD
2425 int
2426 sys_getdirentries(tcp)
2427 struct tcb * tcp;
2428 {
2429         int i, len, dents = 0;
2430         long basep;
2431         char *buf;
2432
2433         if (entering(tcp)) {
2434                 tprintf("%lu, ", tcp->u_arg[0]);
2435                 return 0;
2436         }
2437         if (syserror(tcp) || !verbose(tcp)) {
2438                 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2439                 return 0;
2440         }
2441         len = tcp->u_rval;
2442         if ((buf = malloc(len)) == NULL) {
2443                 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2444                 fprintf(stderr, "out of memory\n");
2445                 return 0;
2446         }
2447         if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2448                 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2449                 free(buf);
2450                 return 0;
2451         }
2452         if (!abbrev(tcp))
2453                 tprintf("{");
2454         for (i = 0; i < len;) {
2455                 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2456                 if (!abbrev(tcp)) {
2457                         tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2458                                 i ? " " : "", d->d_fileno, d->d_reclen);
2459                         printxval(direnttypes, d->d_type, "DT_???");
2460                         tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2461                                 d->d_namlen, d->d_namlen, d->d_name);
2462                 }
2463                 i += d->d_reclen;
2464                 dents++;
2465         }
2466         if (!abbrev(tcp))
2467                 tprintf("}");
2468         else
2469                 tprintf("/* %u entries */", dents);
2470         free(buf);
2471         tprintf(", %lu", tcp->u_arg[2]);
2472         if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2473                 tprintf(", %#lx", tcp->u_arg[3]);
2474         else
2475                 tprintf(", [%lu]", basep);
2476         return 0;
2477 }
2478 #endif
2479
2480 #ifdef LINUX
2481 int
2482 sys_getcwd(tcp)
2483 struct tcb *tcp;
2484 {
2485     if (exiting(tcp)) {
2486         if (syserror(tcp))
2487             tprintf("%#lx", tcp->u_arg[0]);
2488         else
2489             printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2490         tprintf(", %lu", tcp->u_arg[1]);
2491     }
2492     return 0;
2493 }
2494 #endif /* LINUX */
2495
2496 #ifdef FREEBSD
2497 int
2498 sys___getcwd(tcp)
2499 struct tcb *tcp;
2500 {
2501     if (exiting(tcp)) {
2502         if (syserror(tcp))
2503             tprintf("%#lx", tcp->u_arg[0]);
2504         else
2505             printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2506         tprintf(", %lu", tcp->u_arg[1]);
2507     }
2508     return 0;
2509 }
2510 #endif
2511
2512 #ifdef HAVE_SYS_ASYNCH_H
2513
2514 int
2515 sys_aioread(tcp)
2516 struct tcb *tcp;
2517 {
2518         struct aio_result_t res;
2519
2520         if (entering(tcp)) {
2521                 tprintf("%lu, ", tcp->u_arg[0]);
2522         } else {
2523                 if (syserror(tcp))
2524                         tprintf("%#lx", tcp->u_arg[1]);
2525                 else
2526                         printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2527                 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2528                 printxval(whence, tcp->u_arg[4], "L_???");
2529                 if (syserror(tcp) || tcp->u_arg[5] == 0
2530                     || umove(tcp, tcp->u_arg[5], &res) < 0)
2531                         tprintf(", %#lx", tcp->u_arg[5]);
2532                 else
2533                         tprintf(", {aio_return %d aio_errno %d}",
2534                                 res.aio_return, res.aio_errno);
2535         }
2536         return 0;
2537 }
2538
2539 int
2540 sys_aiowrite(tcp)
2541 struct tcb *tcp;
2542 {
2543         struct aio_result_t res;
2544
2545         if (entering(tcp)) {
2546                 tprintf("%lu, ", tcp->u_arg[0]);
2547                 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2548                 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2549                 printxval(whence, tcp->u_arg[4], "L_???");
2550         }
2551         else {
2552                 if (tcp->u_arg[5] == 0)
2553                         tprintf(", NULL");
2554                 else if (syserror(tcp)
2555                     || umove(tcp, tcp->u_arg[5], &res) < 0)
2556                         tprintf(", %#lx", tcp->u_arg[5]);
2557                 else
2558                         tprintf(", {aio_return %d aio_errno %d}",
2559                                 res.aio_return, res.aio_errno);
2560         }
2561         return 0;
2562 }
2563
2564 int
2565 sys_aiowait(tcp)
2566 struct tcb *tcp;
2567 {
2568         if (entering(tcp))
2569                 printtv(tcp, tcp->u_arg[0]);
2570         return 0;
2571 }
2572
2573 int
2574 sys_aiocancel(tcp)
2575 struct tcb *tcp;
2576 {
2577         struct aio_result_t res;
2578
2579         if (exiting(tcp)) {
2580                 if (tcp->u_arg[0] == 0)
2581                         tprintf("NULL");
2582                 else if (syserror(tcp)
2583                     || umove(tcp, tcp->u_arg[0], &res) < 0)
2584                         tprintf("%#lx", tcp->u_arg[0]);
2585                 else
2586                         tprintf("{aio_return %d aio_errno %d}",
2587                                 res.aio_return, res.aio_errno);
2588         }
2589         return 0;
2590 }
2591
2592 #endif /* HAVE_SYS_ASYNCH_H */
2593
2594 static const struct xlat xattrflags[] = {
2595 #ifdef XATTR_CREATE
2596         { XATTR_CREATE,  "XATTR_CREATE" },
2597         { XATTR_REPLACE, "XATTR_REPLACE" },
2598 #endif
2599         { 0,             NULL }
2600 };
2601
2602 static void
2603 print_xattr_val(tcp, failed, arg, insize, size)
2604 struct tcb *tcp;
2605 int failed;
2606 unsigned long arg;
2607 unsigned long insize, size;
2608 {
2609     if (!failed) {
2610         unsigned long capacity = 4 * size + 1;
2611         unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2612         if (buf == NULL || /* probably a bogus size argument */
2613             umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2614             failed = 1;
2615         }
2616         else {
2617             unsigned char *out = buf;
2618             unsigned char *in = &buf[3 * size];
2619             size_t i;
2620             for (i = 0; i < size; ++i)
2621                 if (isprint(in[i]))
2622                     *out++ = in[i];
2623                 else {
2624 #define tohex(n) "0123456789abcdef"[n]
2625                     *out++ = '\\';
2626                     *out++ = 'x';
2627                     *out++ = tohex(in[i] / 16);
2628                     *out++ = tohex(in[i] % 16);
2629                 }
2630             /* Don't print terminating NUL if there is one.  */
2631             if (i > 0 && in[i - 1] == '\0')
2632                 out -= 4;
2633             *out = '\0';
2634             tprintf(", \"%s\", %ld", buf, insize);
2635         }
2636         free(buf);
2637     }
2638     if (failed)
2639         tprintf(", 0x%lx, %ld", arg, insize);
2640 }
2641
2642 int
2643 sys_setxattr(tcp)
2644 struct tcb *tcp;
2645 {
2646     if (entering(tcp)) {
2647         printpath(tcp, tcp->u_arg[0]);
2648         tprintf(", ");
2649         printstr(tcp, tcp->u_arg[1], -1);
2650         print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2651         tprintf(", ");
2652         printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2653     }
2654     return 0;
2655 }
2656
2657 int
2658 sys_fsetxattr(tcp)
2659 struct tcb *tcp;
2660 {
2661     if (entering(tcp)) {
2662         tprintf("%ld, ", tcp->u_arg[0]);
2663         printstr(tcp, tcp->u_arg[1], -1);
2664         print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2665         tprintf(", ");
2666         printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2667     }
2668     return 0;
2669 }
2670
2671 int
2672 sys_getxattr(tcp)
2673 struct tcb *tcp;
2674 {
2675     if (entering(tcp)) {
2676         printpath(tcp, tcp->u_arg[0]);
2677         tprintf(", ");
2678         printstr(tcp, tcp->u_arg[1], -1);
2679     } else {
2680         print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2681                         tcp->u_rval);
2682     }
2683     return 0;
2684 }
2685
2686 int
2687 sys_fgetxattr(tcp)
2688 struct tcb *tcp;
2689 {
2690     if (entering(tcp)) {
2691         tprintf("%ld, ", tcp->u_arg[0]);
2692         printstr(tcp, tcp->u_arg[1], -1);
2693     } else {
2694         print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2695                         tcp->u_rval);
2696     }
2697     return 0;
2698 }
2699
2700 int
2701 sys_listxattr(tcp)
2702 struct tcb *tcp;
2703 {
2704     if (entering(tcp)) {
2705         printpath(tcp, tcp->u_arg[0]);
2706     } else {
2707         /* XXX Print value in format */
2708         tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2709     }
2710     return 0;
2711 }
2712
2713 int
2714 sys_flistxattr(tcp)
2715 struct tcb *tcp;
2716 {
2717     if (entering(tcp)) {
2718         tprintf("%ld", tcp->u_arg[0]);
2719     } else {
2720         /* XXX Print value in format */
2721         tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2722     }
2723     return 0;
2724 }
2725
2726 int
2727 sys_removexattr(tcp)
2728 struct tcb *tcp;
2729 {
2730     if (entering(tcp)) {
2731         printpath(tcp, tcp->u_arg[0]);
2732         tprintf(", ");
2733         printstr(tcp, tcp->u_arg[1], -1);
2734     }
2735     return 0;
2736 }
2737
2738 int
2739 sys_fremovexattr(tcp)
2740 struct tcb *tcp;
2741 {
2742     if (entering(tcp)) {
2743         tprintf("%ld, ", tcp->u_arg[0]);
2744         printstr(tcp, tcp->u_arg[1], -1);
2745     }
2746     return 0;
2747 }
2748
2749
2750 static const struct xlat advise[] = {
2751   { POSIX_FADV_NORMAL,          "POSIX_FADV_NORMAL"     },
2752   { POSIX_FADV_RANDOM,          "POSIX_FADV_RANDOM"     },
2753   { POSIX_FADV_SEQUENTIAL,      "POSIX_FADV_SEQUENTIAL" },
2754   { POSIX_FADV_WILLNEED,        "POSIX_FADV_WILLNEED"   },
2755   { POSIX_FADV_DONTNEED,        "POSIX_FADV_DONTNEED"   },
2756   { POSIX_FADV_NOREUSE,         "POSIX_FADV_NOREUSE"    },
2757   { 0,                          NULL                    }
2758 };
2759
2760
2761 #ifdef LINUX
2762 int
2763 sys_fadvise64(tcp)
2764 struct tcb *tcp;
2765 {
2766     if (entering(tcp)) {
2767         tprintf("%ld, %lld, %ld, ",
2768                 tcp->u_arg[0],
2769 # if defined IA64 || defined X86_64 || defined ALPHA
2770                 (long long int) tcp->u_arg[1], tcp->u_arg[2]);
2771         printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2772 #else
2773                 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
2774         printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
2775 #endif
2776     }
2777     return 0;
2778 }
2779 #endif
2780
2781
2782 int
2783 sys_fadvise64_64(tcp)
2784 struct tcb *tcp;
2785 {
2786     if (entering(tcp)) {
2787         tprintf("%ld, %lld, %lld, ",
2788                 tcp->u_arg[0],
2789 # if defined IA64 || defined X86_64 || defined ALPHA
2790                 (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
2791         printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
2792 #else
2793                 LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
2794                 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
2795         printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
2796 #endif
2797     }
2798     return 0;
2799 }
2800
2801 #ifdef LINUX
2802 static const struct xlat inotify_modes[] = {
2803         { 0x00000001, "IN_ACCESS" },
2804         { 0x00000002, "IN_MODIFY" },
2805         { 0x00000004, "IN_ATTRIB" },
2806         { 0x00000008, "IN_CLOSE_WRITE" },
2807         { 0x00000010, "IN_CLOSE_NOWRITE" },
2808         { 0x00000020, "IN_OPEN" },
2809         { 0x00000040, "IN_MOVED_FROM" },
2810         { 0x00000080, "IN_MOVED_TO" },
2811         { 0x00000100, "IN_CREATE" },
2812         { 0x00000200, "IN_DELETE" },
2813         { 0x00000400, "IN_DELETE_SELF" },
2814         { 0x00000800, "IN_MOVE_SELF" },
2815         { 0x00002000, "IN_UNMOUNT" },
2816         { 0x00004000, "IN_Q_OVERFLOW" },
2817         { 0x00008000, "IN_IGNORED" },
2818         { 0x01000000, "IN_ONLYDIR" },
2819         { 0x02000000, "IN_DONT_FOLLOW" },
2820         { 0x20000000, "IN_MASK_ADD" },
2821         { 0x40000000, "IN_ISDIR" },
2822         { 0x80000000, "IN_ONESHOT" }
2823 };
2824
2825 int
2826 sys_inotify_add_watch(struct tcb *tcp)
2827 {
2828         if (entering(tcp)) {
2829                 tprintf("%ld, ", tcp->u_arg[0]);
2830                 printpath(tcp, tcp->u_arg[1]);
2831                 tprintf(", ");
2832                 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2833         }
2834         return 0;
2835 }
2836
2837 int
2838 sys_inotify_rm_watch(struct tcb *tcp)
2839 {
2840         if (entering(tcp)) {
2841                 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
2842         }
2843         return 0;
2844 }
2845 #endif