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