OSDN Git Service

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