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