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