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