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