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