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