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