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