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