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