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