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