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