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