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