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