]> granicus.if.org Git - strace/blob - file.c
50fdd4ac87b96f8413b0fa3e1166c454469d40d9
[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 int
354 sys_lseek(tcp)
355 struct tcb *tcp;
356 {
357         off_t offset;
358         int _whence;
359
360         if (entering(tcp)) {
361                 tprintf("%ld, ", tcp->u_arg[0]);
362 #ifndef FREEBSD
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 #else /* FREEBSD */
370                 offset = ((off_t) tcp->u_arg[1] << 32) +  tcp->u_arg[2];
371                 _whence = tcp->u_arg[4];
372                 if (_whence == SEEK_SET)
373                         tprintf("%llu, ", offset);
374                 else
375                         tprintf("%lld, ", offset);              
376 #endif          
377                 printxval(whence, _whence, "SEEK_???");
378         } 
379 #ifdef FREEBSD
380         else
381                 if (!syserror(tcp))
382                         return RVAL_LUDECIMAL;
383 #endif /* FREEBSD */
384         return RVAL_UDECIMAL;
385 }
386
387 #ifdef linux
388 int
389 sys_llseek (tcp)
390 struct tcb *tcp;
391 {
392     if (entering(tcp)) {
393         if (tcp->u_arg[4] == SEEK_SET)
394             tprintf("%ld, %llu, ", tcp->u_arg[0],
395                     (((long long int) tcp->u_arg[1]) << 32
396                      | (unsigned long long) tcp->u_arg[2]));
397         else
398             tprintf("%ld, %lld, ", tcp->u_arg[0],
399                     (((long long int) tcp->u_arg[1]) << 32
400                      | (unsigned long long) tcp->u_arg[2]));
401     }
402     else {
403         long long int off;
404         if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
405             tprintf("%#lx, ", tcp->u_arg[3]);
406         else
407             tprintf("[%llu], ", off);
408         printxval(whence, tcp->u_arg[4], "SEEK_???");
409     }
410     return 0;
411 }
412 #endif
413
414 int
415 sys_truncate(tcp)
416 struct tcb *tcp;
417 {
418         if (entering(tcp)) {
419                 printpath(tcp, tcp->u_arg[0]);
420 #ifndef FREEBSD
421                 tprintf(", %lu", tcp->u_arg[1]);
422 #else
423                 tprintf(", %llu", ((off_t) tcp->u_arg[1] << 32) + tcp->u_arg[2]);
424 #endif          
425         }
426         return 0;
427 }
428
429 int
430 sys_ftruncate(tcp)
431 struct tcb *tcp;
432 {
433         if (entering(tcp)) {
434 #ifndef FREEBSD
435                 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
436 #else
437                 tprintf("%ld, %llu", tcp->u_arg[0],
438                         ((off_t) tcp->u_arg[1] << 32) + tcp->u_arg[2]);
439 #endif          
440         }
441         return 0;
442 }
443
444 /* several stats */
445
446 static struct xlat modetypes[] = {
447         { S_IFREG,      "S_IFREG"       },
448         { S_IFSOCK,     "S_IFSOCK"      },
449         { S_IFIFO,      "S_IFIFO"       },
450         { S_IFLNK,      "S_IFLNK"       },
451         { S_IFDIR,      "S_IFDIR"       },
452         { S_IFBLK,      "S_IFBLK"       },
453         { S_IFCHR,      "S_IFCHR"       },
454         { 0,            NULL            },
455 };
456
457 static char *
458 sprintmode(mode)
459 int mode;
460 {
461         static char buf[64];
462         char *s;
463
464         if ((mode & S_IFMT) == 0)
465                 s = "";
466         else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
467                 sprintf(buf, "%#o", mode);
468                 return buf;
469         }
470         sprintf(buf, "%s%s%s%s", s,
471                 (mode & S_ISUID) ? "|S_ISUID" : "",
472                 (mode & S_ISGID) ? "|S_ISGID" : "",
473                 (mode & S_ISVTX) ? "|S_ISVTX" : "");
474         mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
475         if (mode)
476                 sprintf(buf + strlen(buf), "|%#o", mode);
477         s = (*buf == '|') ? buf + 1 : buf;
478         return *s ? s : "0";
479 }
480
481 static char *
482 sprinttime(t)
483 time_t t;
484 {
485         struct tm *tmp;
486         static char buf[32];
487
488         if (t == 0) {
489                 sprintf(buf, "0");
490                 return buf;
491         }
492         tmp = localtime(&t);
493         sprintf(buf, "%02d/%02d/%02d-%02d:%02d:%02d",
494                 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
495                 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
496         return buf;
497 }
498
499 #ifdef LINUXSPARC
500 typedef struct {
501         int     tv_sec;
502         int     tv_nsec;
503 } timestruct_t;
504
505 struct solstat {
506         unsigned        st_dev;
507         int             st_pad1[3];     /* network id */
508         unsigned        st_ino;
509         unsigned        st_mode;
510         unsigned        st_nlink;
511         unsigned        st_uid;
512         unsigned        st_gid;
513         unsigned        st_rdev;
514         int             st_pad2[2];
515         int             st_size;
516         int             st_pad3;        /* st_size, off_t expansion */
517         timestruct_t    st_atime;
518         timestruct_t    st_mtime;
519         timestruct_t    st_ctime;
520         int             st_blksize;
521         int             st_blocks;
522         char            st_fstype[16];
523         int             st_pad4[8];     /* expansion area */
524 };
525
526 static void
527 printstatsol(tcp, addr)
528 struct tcb *tcp;
529 long addr;
530 {
531         struct solstat statbuf;
532
533         if (!addr) {
534                 tprintf("NULL");
535                 return;
536         }
537         if (syserror(tcp) || !verbose(tcp)) {
538                 tprintf("%#lx", addr);
539                 return;
540         }
541         if (umove(tcp, addr, &statbuf) < 0) {
542                 tprintf("{...}");
543                 return;
544         }
545         if (!abbrev(tcp)) {
546                 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
547                         (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
548                         (unsigned long) (statbuf.st_dev & 0x3ffff),
549                         (unsigned long) statbuf.st_ino,
550                         sprintmode(statbuf.st_mode));
551                 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
552                         (unsigned long) statbuf.st_nlink,
553                         (unsigned long) statbuf.st_uid,
554                         (unsigned long) statbuf.st_gid);
555                 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
556                 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
557         }
558         else
559                 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
560         switch (statbuf.st_mode & S_IFMT) {
561         case S_IFCHR: case S_IFBLK:
562                 tprintf("st_rdev=makedev(%lu, %lu), ",
563                         (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
564                         (unsigned long) (statbuf.st_rdev & 0x3ffff));
565                 break;
566         default:
567                 tprintf("st_size=%u, ", statbuf.st_size);
568                 break;
569         }
570         if (!abbrev(tcp)) {
571                 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
572                 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
573                 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
574         }
575         else
576                 tprintf("...}");
577 }
578 #endif /* LINUXSPARC */
579
580 #ifdef FREEBSD
581 static struct xlat fileflags[] = {
582         { UF_NODUMP,    "UF_NODUMP"     },
583         { UF_IMMUTABLE, "UF_IMMUTABLE"  },
584         { UF_APPEND,    "UF_APPEND"     },
585         { UF_OPAQUE,    "UF_OPAQUE"     },
586         { UF_NOUNLINK,  "UF_NOUNLINK"   },
587         { SF_ARCHIVED,  "SF_ARCHIVED"   },
588         { SF_IMMUTABLE, "SF_IMMUTABLE"  },
589         { SF_APPEND,    "SF_APPEND"     },
590         { SF_NOUNLINK,  "SF_NOUNLINK"   },
591         { 0,            NULL            },
592 };
593
594 int
595 sys_chflags(tcp)
596 struct tcb *tcp;
597 {
598         if (entering(tcp)) {
599                 printpath(tcp, tcp->u_arg[0]);
600                 tprintf(", ");
601                 if (tcp->u_arg[1])
602                         printflags(fileflags, tcp->u_arg[1]);
603                 else
604                         tprintf("0");
605         }
606         return 0;
607 }
608
609 int
610 sys_fchflags(tcp)
611 struct tcb *tcp;
612 {
613         if (entering(tcp)) {
614                 tprintf("%ld, ", tcp->u_arg[0]);
615                 if (tcp->u_arg[1])
616                         printflags(fileflags, tcp->u_arg[1]);
617                 else
618                         tprintf("0");
619         }
620         return 0;
621 }
622 #endif
623
624 static void
625 realprintstat(tcp, statbuf)
626 struct tcb *tcp;
627 struct stat *statbuf;
628 {
629     if (!abbrev(tcp)) {
630             tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
631                     (unsigned long) major(statbuf->st_dev),
632                     (unsigned long) minor(statbuf->st_dev),
633                     (unsigned long) statbuf->st_ino,
634                     sprintmode(statbuf->st_mode));
635             tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
636                     (unsigned long) statbuf->st_nlink,
637                     (unsigned long) statbuf->st_uid,
638                     (unsigned long) statbuf->st_gid);
639 #ifdef HAVE_ST_BLKSIZE
640             tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
641 #endif /* HAVE_ST_BLKSIZE */
642 #ifdef HAVE_ST_BLOCKS
643             tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
644 #endif /* HAVE_ST_BLOCKS */
645     }
646     else
647             tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
648     switch (statbuf->st_mode & S_IFMT) {
649     case S_IFCHR: case S_IFBLK:
650 #ifdef HAVE_ST_RDEV
651             tprintf("st_rdev=makedev(%lu, %lu), ",
652                     (unsigned long) major(statbuf->st_rdev),
653                     (unsigned long) minor(statbuf->st_rdev));
654 #else /* !HAVE_ST_RDEV */
655             tprintf("st_size=makedev(%lu, %lu), ",
656                     (unsigned long) major(statbuf->st_size),
657                     (unsigned long) minor(statbuf->st_size));
658 #endif /* !HAVE_ST_RDEV */
659             break;
660     default:
661             tprintf("st_size=%lu, ", statbuf->st_size);
662             break;
663     }
664     if (!abbrev(tcp)) {
665             tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
666             tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
667 #ifndef FREEBSD
668             tprintf("st_ctime=%s}", sprinttime(statbuf->st_ctime));
669 #else /* FREEBSD */
670             tprintf("st_ctime=%s, ", sprinttime(statbuf->st_ctime));
671             tprintf("st_flags=");
672             if (statbuf->st_flags) {
673                     printflags(fileflags, statbuf->st_flags);
674             } else
675                     tprintf("0");
676             tprintf(", st_gen=%u}", statbuf->st_gen);
677 #endif /* FREEBSD */
678     }
679     else
680             tprintf("...}");
681 }
682
683
684 static void
685 printstat(tcp, addr)
686 struct tcb *tcp;
687 long addr;
688 {
689         struct stat statbuf;
690
691 #ifdef LINUXSPARC
692         if (current_personality == 1) {
693                 printstatsol(tcp, addr);
694                 return;
695         }
696 #endif /* LINUXSPARC */
697
698         if (!addr) {
699                 tprintf("NULL");
700                 return;
701         }
702         if (syserror(tcp) || !verbose(tcp)) {
703                 tprintf("%#lx", addr);
704                 return;
705         }
706         if (umove(tcp, addr, &statbuf) < 0) {
707                 tprintf("{...}");
708                 return;
709         }
710
711         realprintstat(tcp, &statbuf);
712 }
713
714 #ifdef HAVE_STAT64
715 static void
716 printstat64(tcp, addr)
717 struct tcb *tcp;
718 long addr;
719 {
720         struct stat64 statbuf;
721
722 #ifdef LINUXSPARC
723         if (current_personality == 1) {
724                 printstatsol(tcp, addr);
725                 return;
726         }
727 #endif /* LINUXSPARC */
728
729         if (!addr) {
730                 tprintf("NULL");
731                 return;
732         }
733         if (syserror(tcp) || !verbose(tcp)) {
734                 tprintf("%#lx", addr);
735                 return;
736         }
737         if (umove(tcp, addr, &statbuf) < 0) {
738                 tprintf("{...}");
739                 return;
740         }
741
742         if (!abbrev(tcp)) {
743 #ifdef HAVE_LONG_LONG
744                 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
745 #else
746                 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
747 #endif
748                         (unsigned long) major(statbuf.st_dev),
749                         (unsigned long) minor(statbuf.st_dev),
750 #ifdef HAVE_LONG_LONG
751                         (unsigned long long) statbuf.st_ino,
752 #else
753                         (unsigned long) statbuf.st_ino,
754 #endif
755                         sprintmode(statbuf.st_mode));
756                 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
757                         (unsigned long) statbuf.st_nlink,
758                         (unsigned long) statbuf.st_uid,
759                         (unsigned long) statbuf.st_gid);
760 #ifdef HAVE_ST_BLKSIZE
761                 tprintf("st_blksize=%lu, ",
762                         (unsigned long) statbuf.st_blksize);
763 #endif /* HAVE_ST_BLKSIZE */
764 #ifdef HAVE_ST_BLOCKS
765                 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
766 #endif /* HAVE_ST_BLOCKS */
767         }
768         else
769                 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
770         switch (statbuf.st_mode & S_IFMT) {
771         case S_IFCHR: case S_IFBLK:
772 #ifdef HAVE_ST_RDEV
773                 tprintf("st_rdev=makedev(%lu, %lu), ",
774                         (unsigned long) major(statbuf.st_rdev),
775                         (unsigned long) minor(statbuf.st_rdev));
776 #else /* !HAVE_ST_RDEV */
777                 tprintf("st_size=makedev(%lu, %lu), ",
778                         (unsigned long) major(statbuf.st_size),
779                         (unsigned long) minor(statbuf.st_size));
780 #endif /* !HAVE_ST_RDEV */
781                 break;
782         default:
783                 tprintf("st_size=%llu, ", statbuf.st_size);
784                 break;
785         }
786         if (!abbrev(tcp)) {
787                 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
788                 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
789                 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
790         }
791         else
792                 tprintf("...}");
793 }
794 #endif /* HAVE_STAT64 */
795
796 #if defined(linux) && !defined(IA64)
797 static void
798 convertoldstat(oldbuf, newbuf)
799 const struct __old_kernel_stat *oldbuf;
800 struct stat *newbuf;
801 {
802     newbuf->st_dev=oldbuf->st_dev;
803     newbuf->st_ino=oldbuf->st_ino;
804     newbuf->st_mode=oldbuf->st_mode;
805     newbuf->st_nlink=oldbuf->st_nlink;
806     newbuf->st_uid=oldbuf->st_uid;
807     newbuf->st_gid=oldbuf->st_gid;
808     newbuf->st_rdev=oldbuf->st_rdev;
809     newbuf->st_size=oldbuf->st_size;
810     newbuf->st_atime=oldbuf->st_atime;
811     newbuf->st_mtime=oldbuf->st_mtime;
812     newbuf->st_ctime=oldbuf->st_ctime;
813     newbuf->st_blksize=0;       /* not supported in old_stat */
814     newbuf->st_blocks=0;                /* not supported in old_stat */
815 }
816
817
818 static void
819 printoldstat(tcp, addr)
820 struct tcb *tcp;
821 long addr;
822 {
823         struct __old_kernel_stat statbuf;
824         struct stat newstatbuf;
825
826 #ifdef LINUXSPARC
827         if (current_personality == 1) {
828                 printstatsol(tcp, addr);
829                 return;
830         }
831 #endif /* LINUXSPARC */
832
833         if (!addr) {
834                 tprintf("NULL");
835                 return;
836         }
837         if (syserror(tcp) || !verbose(tcp)) {
838                 tprintf("%#lx", addr);
839                 return;
840         }
841         if (umove(tcp, addr, &statbuf) < 0) {
842                 tprintf("{...}");
843                 return;
844         }
845
846         convertoldstat(&statbuf, &newstatbuf);
847         realprintstat(tcp, &newstatbuf);
848 }
849 #endif /* linux && !IA64 */
850
851
852 int
853 sys_stat(tcp)
854 struct tcb *tcp;
855 {
856         if (entering(tcp)) {
857                 printpath(tcp, tcp->u_arg[0]);
858                 tprintf(", ");
859         } else {
860                 printstat(tcp, tcp->u_arg[1]);
861         }
862         return 0;
863 }
864
865 #ifdef linux
866 int
867 sys_stat64(tcp)
868 struct tcb *tcp;
869 {
870 #ifdef HAVE_STAT64
871         if (entering(tcp)) {
872                 printpath(tcp, tcp->u_arg[0]);
873                 tprintf(", ");
874         } else {
875                 printstat64(tcp, tcp->u_arg[1]);
876         }
877         return 0;
878 #else
879         return printargs(tcp);
880 #endif
881 }
882
883 # if !defined(IA64)
884 int
885 sys_oldstat(tcp)
886 struct tcb *tcp;
887 {
888         if (entering(tcp)) {
889                 printpath(tcp, tcp->u_arg[0]);
890                 tprintf(", ");
891         } else {
892                 printoldstat(tcp, tcp->u_arg[1]);
893         }
894         return 0;
895 }
896 # endif /* !IA64 */
897 #endif /* linux */
898
899 int
900 sys_fstat(tcp)
901 struct tcb *tcp;
902 {
903         if (entering(tcp))
904                 tprintf("%ld, ", tcp->u_arg[0]);
905         else {
906                 printstat(tcp, tcp->u_arg[1]);
907         }
908         return 0;
909 }
910
911 #ifdef linux
912 int
913 sys_fstat64(tcp)
914 struct tcb *tcp;
915 {
916 #ifdef HAVE_STAT64
917         if (entering(tcp))
918                 tprintf("%ld, ", tcp->u_arg[0]);
919         else {
920                 printstat64(tcp, tcp->u_arg[1]);
921         }
922         return 0;
923 #else
924         return printargs(tcp);
925 #endif
926 }
927
928 # if !defined(IA64)
929 int
930 sys_oldfstat(tcp)
931 struct tcb *tcp;
932 {
933         if (entering(tcp))
934                 tprintf("%ld, ", tcp->u_arg[0]);
935         else {
936                 printoldstat(tcp, tcp->u_arg[1]);
937         }
938         return 0;
939 }
940 # endif /* !IA64 */
941 #endif
942
943 int
944 sys_lstat(tcp)
945 struct tcb *tcp;
946 {
947         if (entering(tcp)) {
948                 printpath(tcp, tcp->u_arg[0]);
949                 tprintf(", ");
950         } else {
951                 printstat(tcp, tcp->u_arg[1]);
952         }
953         return 0;
954 }
955
956 #ifdef linux
957 int
958 sys_lstat64(tcp)
959 struct tcb *tcp;
960 {
961 #ifdef HAVE_STAT64
962         if (entering(tcp)) {
963                 printpath(tcp, tcp->u_arg[0]);
964                 tprintf(", ");
965         } else {
966                 printstat64(tcp, tcp->u_arg[1]);
967         }
968         return 0;
969 #else
970         return printargs(tcp);
971 #endif
972 }
973
974 # if !defined(IA64)
975 int
976 sys_oldlstat(tcp)
977 struct tcb *tcp;
978 {
979         if (entering(tcp)) {
980                 printpath(tcp, tcp->u_arg[0]);
981                 tprintf(", ");
982         } else {
983                 printoldstat(tcp, tcp->u_arg[1]);
984         }
985         return 0;
986 }
987 # endif /* !IA64 */
988 #endif
989
990
991 #if defined(SVR4) || defined(LINUXSPARC)
992
993 int
994 sys_xstat(tcp)
995 struct tcb *tcp;
996 {
997         if (entering(tcp)) {
998                 tprintf("%ld, ", tcp->u_arg[0]);
999                 printpath(tcp, tcp->u_arg[1]);
1000                 tprintf(", ");
1001         } else {
1002 #ifdef _STAT64_VER
1003                 if (tcp->u_arg[0] == _STAT64_VER)
1004                         printstat64 (tcp, tcp->u_arg[2]);
1005                 else
1006 #endif
1007                 printstat(tcp, tcp->u_arg[2]);
1008         }
1009         return 0;
1010 }
1011
1012 int
1013 sys_fxstat(tcp)
1014 struct tcb *tcp;
1015 {
1016         if (entering(tcp))
1017                 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1018         else {
1019 #ifdef _STAT64_VER
1020                 if (tcp->u_arg[0] == _STAT64_VER)
1021                         printstat64 (tcp, tcp->u_arg[2]);
1022                 else
1023 #endif
1024                 printstat(tcp, tcp->u_arg[2]);
1025         }
1026         return 0;
1027 }
1028
1029 int
1030 sys_lxstat(tcp)
1031 struct tcb *tcp;
1032 {
1033         if (entering(tcp)) {
1034                 tprintf("%ld, ", tcp->u_arg[0]);
1035                 printpath(tcp, tcp->u_arg[1]);
1036                 tprintf(", ");
1037         } else {
1038 #ifdef _STAT64_VER
1039                 if (tcp->u_arg[0] == _STAT64_VER)
1040                         printstat64 (tcp, tcp->u_arg[2]);
1041                 else
1042 #endif
1043                 printstat(tcp, tcp->u_arg[2]);
1044         }
1045         return 0;
1046 }
1047
1048 int
1049 sys_xmknod(tcp)
1050 struct tcb *tcp;
1051 {
1052         int mode = tcp->u_arg[2];
1053
1054         if (entering(tcp)) {
1055                 tprintf("%ld, ", tcp->u_arg[0]);
1056                 printpath(tcp, tcp->u_arg[1]);
1057                 tprintf(", %s", sprintmode(mode));
1058                 switch (mode & S_IFMT) {
1059                 case S_IFCHR: case S_IFBLK:
1060 #ifdef LINUXSPARC
1061                         tprintf(", makedev(%lu, %lu)",
1062                                 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1063                                 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1064 #else           
1065                         tprintf(", makedev(%lu, %lu)",
1066                                 (unsigned long) major(tcp->u_arg[3]),
1067                                 (unsigned long) minor(tcp->u_arg[3]));
1068 #endif                          
1069                         break;
1070                 default:
1071                         break;
1072                 }
1073         }
1074         return 0;
1075 }
1076
1077 #ifdef HAVE_SYS_ACL_H
1078
1079 #include <sys/acl.h>
1080
1081 struct xlat aclcmds[] = {
1082 #ifdef SETACL
1083         { SETACL,       "SETACL"        },
1084 #endif
1085 #ifdef GETACL
1086         { GETACL,       "GETACL"        },
1087 #endif
1088 #ifdef GETACLCNT
1089         { GETACLCNT,    "GETACLCNT"     },
1090 #endif
1091 #ifdef ACL_GET
1092         { ACL_GET,      "ACL_GET"       },
1093 #endif  
1094 #ifdef ACL_SET
1095         { ACL_SET,      "ACL_SET"       },
1096 #endif  
1097 #ifdef ACL_CNT
1098         { ACL_CNT,      "ACL_CNT"       },
1099 #endif  
1100         { 0,            NULL            },
1101 };
1102
1103 int
1104 sys_acl(tcp)
1105 struct tcb *tcp;
1106 {
1107         if (entering(tcp)) {
1108                 printpath(tcp, tcp->u_arg[0]);
1109                 tprintf(", ");
1110                 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1111                 tprintf(", %ld", tcp->u_arg[2]);
1112                 /*
1113                  * FIXME - dump out the list of aclent_t's pointed to
1114                  * by "tcp->u_arg[3]" if it's not NULL.
1115                  */
1116                 if (tcp->u_arg[3])
1117                         tprintf(", %#lx", tcp->u_arg[3]);
1118                 else
1119                         tprintf(", NULL");
1120         }
1121         return 0;
1122 }
1123
1124
1125 int
1126 sys_facl(tcp)
1127 struct tcb *tcp;
1128 {
1129         if (entering(tcp)) {
1130                 tprintf("%ld, ", tcp->u_arg[0]);
1131                 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1132                 tprintf(", %ld", tcp->u_arg[2]);
1133                 /*
1134                  * FIXME - dump out the list of aclent_t's pointed to
1135                  * by "tcp->u_arg[3]" if it's not NULL.
1136                  */
1137                 if (tcp->u_arg[3])
1138                         tprintf(", %#lx", tcp->u_arg[3]);
1139                 else
1140                         tprintf(", NULL");
1141         }
1142         return 0;
1143 }
1144
1145
1146 struct xlat aclipc[] = {
1147 #ifdef IPC_SHM
1148         { IPC_SHM,      "IPC_SHM"       },
1149 #endif  
1150 #ifdef IPC_SEM
1151         { IPC_SEM,      "IPC_SEM"       },
1152 #endif  
1153 #ifdef IPC_MSG
1154         { IPC_MSG,      "IPC_MSG"       },
1155 #endif  
1156         { 0,            NULL            },
1157 };
1158
1159
1160 int
1161 sys_aclipc(tcp)
1162 struct tcb *tcp;
1163 {
1164         if (entering(tcp)) {
1165                 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1166                 tprintf(", %#lx, ", tcp->u_arg[1]);
1167                 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1168                 tprintf(", %ld", tcp->u_arg[3]);
1169                 /*
1170                  * FIXME - dump out the list of aclent_t's pointed to
1171                  * by "tcp->u_arg[4]" if it's not NULL.
1172                  */
1173                 if (tcp->u_arg[4])
1174                         tprintf(", %#lx", tcp->u_arg[4]);
1175                 else
1176                         tprintf(", NULL");
1177         }
1178         return 0;
1179 }
1180
1181
1182
1183 #endif /* HAVE_SYS_ACL_H */
1184
1185 #endif /* SVR4 || LINUXSPARC */
1186
1187 #ifdef linux
1188
1189 static struct xlat fsmagic[] = {
1190         { 0x73757245,   "CODA_SUPER_MAGIC"      },
1191         { 0x012ff7b7,   "COH_SUPER_MAGIC"       },
1192         { 0x1373,       "DEVFS_SUPER_MAGIC"     },
1193         { 0x1cd1,       "DEVPTS_SUPER_MAGIC"    },
1194         { 0x414A53,     "EFS_SUPER_MAGIC"       },
1195         { 0xef51,       "EXT2_OLD_SUPER_MAGIC"  },
1196         { 0xef53,       "EXT2_SUPER_MAGIC"      },
1197         { 0x137d,       "EXT_SUPER_MAGIC"       },
1198         { 0xf995e849,   "HPFS_SUPER_MAGIC"      },
1199         { 0x9660,       "ISOFS_SUPER_MAGIC"     },
1200         { 0x137f,       "MINIX_SUPER_MAGIC"     },
1201         { 0x138f,       "MINIX_SUPER_MAGIC2"    },
1202         { 0x2468,       "MINIX2_SUPER_MAGIC"    },
1203         { 0x2478,       "MINIX2_SUPER_MAGIC2"   },
1204         { 0x4d44,       "MSDOS_SUPER_MAGIC"     },
1205         { 0x564c,       "NCP_SUPER_MAGIC"       },
1206         { 0x6969,       "NFS_SUPER_MAGIC"       },
1207         { 0x9fa0,       "PROC_SUPER_MAGIC"      },
1208         { 0x002f,       "QNX4_SUPER_MAGIC"      },
1209         { 0x52654973,   "REISERFS_SUPER_MAGIC"  },
1210         { 0x02011994,   "SHMFS_SUPER_MAGIC"     },
1211         { 0x517b,       "SMB_SUPER_MAGIC"       },
1212         { 0x012ff7b6,   "SYSV2_SUPER_MAGIC"     },
1213         { 0x012ff7b5,   "SYSV4_SUPER_MAGIC"     },
1214         { 0x00011954,   "UFS_MAGIC"             },
1215         { 0x54190100,   "UFS_CIGAM"             },
1216         { 0x012ff7b4,   "XENIX_SUPER_MAGIC"     },
1217         { 0x012fd16d,   "XIAFS_SUPER_MAGIC"     },
1218         { 0,            NULL                    },
1219 };
1220
1221 #endif /* linux */
1222
1223 #ifndef SVR4
1224
1225 static char *
1226 sprintfstype(magic)
1227 int magic;
1228 {
1229         static char buf[32];
1230 #ifdef linux
1231         char *s;
1232
1233         s = xlookup(fsmagic, magic);
1234         if (s) {
1235                 sprintf(buf, "\"%s\"", s);
1236                 return buf;
1237         }
1238 #endif /* linux */
1239         sprintf(buf, "%#x", magic);
1240         return buf;
1241 }
1242
1243 static void
1244 printstatfs(tcp, addr)
1245 struct tcb *tcp;
1246 long addr;
1247 {
1248         struct statfs statbuf;
1249
1250         if (syserror(tcp) || !verbose(tcp)) {
1251                 tprintf("%#lx", addr);
1252                 return;
1253         }
1254         if (umove(tcp, addr, &statbuf) < 0) {
1255                 tprintf("{...}");
1256                 return;
1257         }
1258 #ifdef ALPHA
1259
1260         tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1261                 sprintfstype(statbuf.f_type),
1262                 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1263         tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_namelen=%u",
1264                 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree, statbuf.f_namelen);
1265 #else /* !ALPHA */
1266         tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1267                 sprintfstype(statbuf.f_type),
1268                 (unsigned long)statbuf.f_bsize,
1269                 (unsigned long)statbuf.f_blocks,
1270                 (unsigned long)statbuf.f_bfree);
1271         tprintf("f_files=%lu, f_ffree=%lu",
1272                 (unsigned long)statbuf.f_files,
1273                 (unsigned long)statbuf.f_ffree);
1274 #ifdef linux
1275         tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1276 #endif /* linux */
1277 #endif /* !ALPHA */
1278         tprintf("}");
1279 }
1280
1281 int
1282 sys_statfs(tcp)
1283 struct tcb *tcp;
1284 {
1285         if (entering(tcp)) {
1286                 printpath(tcp, tcp->u_arg[0]);
1287                 tprintf(", ");
1288         } else {
1289                 printstatfs(tcp, tcp->u_arg[1]);
1290         }
1291         return 0;
1292 }
1293
1294 int
1295 sys_fstatfs(tcp)
1296 struct tcb *tcp;
1297 {
1298         if (entering(tcp)) {
1299                 tprintf("%lu, ", tcp->u_arg[0]);
1300         } else {
1301                 printstatfs(tcp, tcp->u_arg[1]);
1302         }
1303         return 0;
1304 }
1305
1306 #if defined(linux) && defined(__alpha)
1307
1308 int
1309 osf_statfs(tcp)
1310 struct tcb *tcp;
1311 {
1312         if (entering(tcp)) {
1313                 printpath(tcp, tcp->u_arg[0]);
1314                 tprintf(", ");
1315         } else {
1316                 printstatfs(tcp, tcp->u_arg[1]);
1317                 tprintf(", %lu", tcp->u_arg[2]);
1318         }
1319         return 0;
1320 }
1321
1322 int
1323 osf_fstatfs(tcp)
1324 struct tcb *tcp;
1325 {
1326         if (entering(tcp)) {
1327                 tprintf("%lu, ", tcp->u_arg[0]);
1328         } else {
1329                 printstatfs(tcp, tcp->u_arg[1]);
1330                 tprintf(", %lu", tcp->u_arg[2]);
1331         }
1332         return 0;
1333 }
1334 #endif /* linux && __alpha */
1335
1336 #endif /* !SVR4 */
1337
1338 #ifdef SUNOS4
1339
1340 int
1341 sys_ustat(tcp)
1342 struct tcb *tcp;
1343 {
1344         struct ustat statbuf;
1345
1346         if (entering(tcp)) {
1347                 tprintf("makedev(%lu, %lu), ",
1348                                 (long) major(tcp->u_arg[0]),
1349                                 (long) minor(tcp->u_arg[0]));
1350         }
1351         else {
1352                 if (syserror(tcp) || !verbose(tcp))
1353                         tprintf("%#lx", tcp->u_arg[1]);
1354                 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1355                         tprintf("{...}");
1356                 else {
1357                         tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1358                                 statbuf.f_tfree, statbuf.f_tinode);
1359                         tprintf("f_fname=\"%.*s\", ",
1360                                 (int) sizeof(statbuf.f_fname),
1361                                 statbuf.f_fname);
1362                         tprintf("f_fpack=\"%.*s\"}",
1363                                 (int) sizeof(statbuf.f_fpack),
1364                                 statbuf.f_fpack);
1365                 }
1366         }
1367         return 0;
1368 }
1369
1370 #endif /* SUNOS4 */
1371
1372 int
1373 sys_pivotroot(tcp)
1374 struct tcb *tcp;
1375 {
1376         if (entering(tcp)) {
1377                 printpath(tcp, tcp->u_arg[0]);
1378                 tprintf(", ");
1379                 printpath(tcp, tcp->u_arg[1]);
1380         }
1381         return 0;
1382 }
1383
1384
1385 /* directory */
1386 int
1387 sys_chdir(tcp)
1388 struct tcb *tcp;
1389 {
1390         if (entering(tcp)) {
1391                 printpath(tcp, tcp->u_arg[0]);
1392         }
1393         return 0;
1394 }
1395
1396 int
1397 sys_mkdir(tcp)
1398 struct tcb *tcp;
1399 {
1400         if (entering(tcp)) {
1401                 printpath(tcp, tcp->u_arg[0]);
1402                 tprintf(", %#lo", tcp->u_arg[1]);
1403         }
1404         return 0;
1405 }
1406
1407 int
1408 sys_rmdir(tcp)
1409 struct tcb *tcp;
1410 {
1411         if (entering(tcp)) {
1412                 printpath(tcp, tcp->u_arg[0]);
1413         }
1414         return 0;
1415 }
1416
1417 int
1418 sys_fchdir(tcp)
1419 struct tcb *tcp;
1420 {
1421         if (entering(tcp)) {
1422                 tprintf("%ld", tcp->u_arg[0]);
1423         }
1424         return 0;
1425 }
1426
1427 int
1428 sys_chroot(tcp)
1429 struct tcb *tcp;
1430 {
1431         if (entering(tcp)) {
1432                 printpath(tcp, tcp->u_arg[0]);
1433         }
1434         return 0;
1435 }
1436
1437 int
1438 sys_fchroot(tcp)
1439 struct tcb *tcp;
1440 {
1441         if (entering(tcp)) {
1442                 tprintf("%ld", tcp->u_arg[0]);
1443         }
1444         return 0;
1445 }
1446
1447 int
1448 sys_link(tcp)
1449 struct tcb *tcp;
1450 {
1451         if (entering(tcp)) {
1452                 printpath(tcp, tcp->u_arg[0]);
1453                 tprintf(", ");
1454                 printpath(tcp, tcp->u_arg[1]);
1455         }
1456         return 0;
1457 }
1458
1459 int
1460 sys_unlink(tcp)
1461 struct tcb *tcp;
1462 {
1463         if (entering(tcp)) {
1464                 printpath(tcp, tcp->u_arg[0]);
1465         }
1466         return 0;
1467 }
1468
1469 int
1470 sys_symlink(tcp)
1471 struct tcb *tcp;
1472 {
1473         if (entering(tcp)) {
1474                 printpath(tcp, tcp->u_arg[0]);
1475                 tprintf(", ");
1476                 printpath(tcp, tcp->u_arg[1]);
1477         }
1478         return 0;
1479 }
1480
1481 int
1482 sys_readlink(tcp)
1483 struct tcb *tcp;
1484 {
1485         if (entering(tcp)) {
1486                 printpath(tcp, tcp->u_arg[0]);
1487                 tprintf(", ");
1488         } else {
1489                 if (syserror(tcp))
1490                         tprintf("%#lx", tcp->u_arg[1]);
1491                 else
1492                         printpathn(tcp, tcp->u_arg[1], tcp->u_rval);
1493                 tprintf(", %lu", tcp->u_arg[2]);
1494         }
1495         return 0;
1496 }
1497
1498 int
1499 sys_rename(tcp)
1500 struct tcb *tcp;
1501 {
1502         if (entering(tcp)) {
1503                 printpath(tcp, tcp->u_arg[0]);
1504                 tprintf(", ");
1505                 printpath(tcp, tcp->u_arg[1]);
1506         }
1507         return 0;
1508 }
1509
1510 int
1511 sys_chown(tcp)
1512 struct tcb *tcp;
1513 {
1514         if (entering(tcp)) {
1515                 printpath(tcp, tcp->u_arg[0]);
1516                 tprintf(", %lu, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1517         }
1518         return 0;
1519 }
1520
1521 int
1522 sys_fchown(tcp)
1523 struct tcb *tcp;
1524 {
1525         if (entering(tcp)) {
1526                 tprintf("%ld, %lu, %lu",
1527                         tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
1528         }
1529         return 0;
1530 }
1531
1532 int
1533 sys_chmod(tcp)
1534 struct tcb *tcp;
1535 {
1536         if (entering(tcp)) {
1537                 printpath(tcp, tcp->u_arg[0]);
1538                 tprintf(", %#lo", tcp->u_arg[1]);
1539         }
1540         return 0;
1541 }
1542
1543 int
1544 sys_fchmod(tcp)
1545 struct tcb *tcp;
1546 {
1547         if (entering(tcp)) {
1548                 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
1549         }
1550         return 0;
1551 }
1552
1553 #ifdef ALPHA
1554 int
1555 sys_osf_utimes(tcp)
1556 struct tcb *tcp;
1557 {
1558     if (entering(tcp)) {
1559         printpath(tcp, tcp->u_arg[0]);
1560         tprintf(", ");
1561         printtv32(tcp, tcp->u_arg[1]);
1562     }
1563     return 0;
1564 }
1565 #endif
1566
1567 int
1568 sys_utimes(tcp)
1569 struct tcb *tcp;
1570 {
1571         if (entering(tcp)) {
1572                 printpath(tcp, tcp->u_arg[0]);
1573                 tprintf(", ");
1574                 printtv(tcp, tcp->u_arg[1]);
1575         }
1576         return 0;
1577 }
1578
1579 int
1580 sys_utime(tcp)
1581 struct tcb *tcp;
1582 {
1583         long ut[2];
1584
1585         if (entering(tcp)) {
1586                 printpath(tcp, tcp->u_arg[0]);
1587                 tprintf(", ");
1588                 if (!tcp->u_arg[1])
1589                         tprintf("NULL");
1590                 else if (!verbose(tcp))
1591                         tprintf("%#lx", tcp->u_arg[1]);
1592                 else if (umoven(tcp, tcp->u_arg[1], sizeof ut,
1593                     (char *) ut) < 0)
1594                         tprintf("[?, ?]");
1595                 else {
1596                         tprintf("[%s,", sprinttime(ut[0]));
1597                         tprintf(" %s]", sprinttime(ut[1]));
1598                 }
1599         }
1600         return 0;
1601 }
1602
1603 int
1604 sys_mknod(tcp)
1605 struct tcb *tcp;
1606 {
1607         int mode = tcp->u_arg[1];
1608
1609         if (entering(tcp)) {
1610                 printpath(tcp, tcp->u_arg[0]);
1611                 tprintf(", %s", sprintmode(mode));
1612                 switch (mode & S_IFMT) {
1613                 case S_IFCHR: case S_IFBLK:
1614 #ifdef LINUXSPARC
1615                         if (current_personality == 1)
1616                         tprintf(", makedev(%lu, %lu)",
1617                                 (unsigned long) ((tcp->u_arg[2] >> 18) & 0x3fff),
1618                                 (unsigned long) (tcp->u_arg[2] & 0x3ffff));
1619                         else
1620 #endif  
1621                         tprintf(", makedev(%lu, %lu)",
1622                                 (unsigned long) major(tcp->u_arg[2]),
1623                                 (unsigned long) minor(tcp->u_arg[2]));
1624                         break;
1625                 default:
1626                         break;
1627                 }
1628         }
1629         return 0;
1630 }
1631
1632 int
1633 sys_mkfifo(tcp)
1634 struct tcb *tcp;
1635 {
1636         if (entering(tcp)) {
1637                 printpath(tcp, tcp->u_arg[0]);
1638                 tprintf(", %#lo", tcp->u_arg[1]);
1639         }
1640         return 0;
1641 }
1642
1643 int
1644 sys_fsync(tcp)
1645 struct tcb *tcp;
1646 {
1647         if (entering(tcp)) {
1648                 tprintf("%ld", tcp->u_arg[0]);
1649         }
1650         return 0;
1651 }
1652
1653 #ifdef linux
1654
1655 static void
1656 printdir(tcp, addr)
1657 struct tcb *tcp;
1658 long addr;
1659 {
1660         struct dirent d;
1661
1662         if (!verbose(tcp)) {
1663                 tprintf("%#lx", addr);
1664                 return;
1665         }
1666         if (umove(tcp, addr, &d) < 0) {
1667                 tprintf("{...}");
1668                 return;
1669         }
1670         tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
1671         tprintf("d_name=");
1672         printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
1673         tprintf("}");
1674 }
1675
1676 int
1677 sys_readdir(tcp)
1678 struct tcb *tcp;
1679 {
1680         if (entering(tcp)) {
1681                 tprintf("%lu, ", tcp->u_arg[0]);
1682         } else {
1683                 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
1684                         tprintf("%#lx", tcp->u_arg[1]);
1685                 else
1686                         printdir(tcp, tcp->u_arg[1]);
1687                 /* Not much point in printing this out, it is always 1. */
1688                 if (tcp->u_arg[2] != 1)
1689                         tprintf(", %lu", tcp->u_arg[2]);
1690         }
1691         return 0;
1692 }
1693
1694 #endif /* linux */
1695
1696 #ifdef FREEBSD
1697 struct xlat direnttypes[] = {
1698         { DT_FIFO,      "DT_FIFO"       },
1699         { DT_CHR,       "DT_CHR"        },
1700         { DT_DIR,       "DT_DIR"        },
1701         { DT_BLK,       "DT_BLK"        },
1702         { DT_REG,       "DT_REG"        },
1703         { DT_LNK,       "DT_LNK"        },
1704         { DT_SOCK,      "DT_SOCK"       },
1705         { DT_WHT,       "DT_WHT"        },
1706         { 0,            NULL            },
1707 };
1708
1709 #endif
1710
1711 int
1712 sys_getdents(tcp)
1713 struct tcb *tcp;
1714 {
1715         int i, len, dents = 0;
1716         char *buf;
1717
1718         if (entering(tcp)) {
1719                 tprintf("%lu, ", tcp->u_arg[0]);
1720                 return 0;
1721         }
1722         if (syserror(tcp) || !verbose(tcp)) {
1723                 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
1724                 return 0;
1725         }
1726         len = tcp->u_rval;
1727         if ((buf = malloc(len)) == NULL) {
1728                 tprintf("out of memory\n");
1729                 return 0;
1730         }
1731         if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1732                 tprintf("{...}, %lu", tcp->u_arg[2]);
1733                 free(buf);
1734                 return 0;
1735         }
1736         if (!abbrev(tcp))
1737                 tprintf("{");
1738         for (i = 0; i < len;) {
1739                 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
1740 #ifdef linux
1741                 if (!abbrev(tcp)) {
1742                         tprintf("%s{d_ino=%lu, d_off=%lu, ",
1743                                 i ? " " : "", d->d_ino, d->d_off);
1744                         tprintf("d_reclen=%u, d_name=\"%s\"}",
1745                                 d->d_reclen, d->d_name);
1746                 }
1747 #endif /* linux */
1748 #ifdef SVR4
1749                 if (!abbrev(tcp)) {
1750                         tprintf("%s{d_ino=%lu, d_off=%lu, ",
1751                                 i ? " " : "", d->d_ino, d->d_off);
1752                         tprintf("d_reclen=%u, d_name=\"%s\"}",
1753                                 d->d_reclen, d->d_name);
1754                 }
1755 #endif /* SVR4 */
1756 #ifdef SUNOS4
1757                 if (!abbrev(tcp)) {
1758                         tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
1759                                 i ? " " : "", d->d_off, d->d_fileno,
1760                                 d->d_reclen);
1761                         tprintf("d_namlen=%u, d_name=\"%.*s\"}",
1762                                 d->d_namlen, d->d_namlen, d->d_name);
1763                 }
1764 #endif /* SUNOS4 */
1765 #ifdef FREEBSD
1766                 if (!abbrev(tcp)) {
1767                         tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
1768                                 i ? " " : "", d->d_fileno, d->d_reclen);
1769                         printxval(direnttypes, d->d_type, "DT_???");
1770                         tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
1771                                 d->d_namlen, d->d_namlen, d->d_name);
1772                 }
1773 #endif /* FREEBSD */            
1774                 if (!d->d_reclen) {
1775                         tprintf("/* d_reclen == 0, problem here */");
1776                         break;
1777                 }
1778                 i += d->d_reclen;
1779                 dents++;
1780         }
1781         if (!abbrev(tcp))
1782                 tprintf("}");
1783         else
1784                 tprintf("/* %u entries */", dents);
1785         tprintf(", %lu", tcp->u_arg[2]);
1786         free(buf);
1787         return 0;
1788 }
1789
1790 #ifdef FREEBSD
1791 int
1792 sys_getdirentries(tcp)
1793 struct tcb * tcp;
1794 {
1795         int i, len, dents = 0;
1796         long basep;
1797         char *buf;
1798
1799         if (entering(tcp)) {
1800                 tprintf("%lu, ", tcp->u_arg[0]);
1801                 return 0;
1802         }
1803         if (syserror(tcp) || !verbose(tcp)) {
1804                 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
1805                 return 0;
1806         }
1807         len = tcp->u_rval;
1808         if ((buf = malloc(len)) == NULL) {
1809                 tprintf("out of memory\n");
1810                 return 0;
1811         }
1812         if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
1813                 tprintf("{...}, %lu, %#lx", tcp->u_arg[2], tcp->u_arg[3]);
1814                 free(buf);
1815                 return 0;
1816         }
1817         if (!abbrev(tcp))
1818                 tprintf("{");
1819         for (i = 0; i < len;) {
1820                 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
1821                 if (!abbrev(tcp)) {
1822                         tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
1823                                 i ? " " : "", d->d_fileno, d->d_reclen);
1824                         printxval(direnttypes, d->d_type, "DT_???");
1825                         tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
1826                                 d->d_namlen, d->d_namlen, d->d_name);
1827                 }
1828                 i += d->d_reclen;
1829                 dents++;
1830         }
1831         if (!abbrev(tcp))
1832                 tprintf("}");
1833         else
1834                 tprintf("/* %u entries */", dents);
1835         free(buf);
1836         tprintf(", %lu", tcp->u_arg[2]);
1837         if (umove(tcp, tcp->u_arg[3], &basep) < 0)
1838                 tprintf(", %#lx", tcp->u_arg[3]);
1839         else
1840                 tprintf(", [%lu]", basep);
1841         return 0;
1842 }
1843 #endif
1844
1845 #ifdef linux
1846 int
1847 sys_getcwd(tcp)
1848 struct tcb *tcp;
1849 {
1850     if (exiting(tcp)) {
1851         if (syserror(tcp))
1852             tprintf("%#lx", tcp->u_arg[0]);
1853         else
1854             printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
1855         tprintf(", %lu", tcp->u_arg[1]);
1856     }
1857     return 0;
1858 }
1859 #endif /* linux */
1860
1861 #ifdef FREEBSD
1862 int
1863 sys___getcwd(tcp)
1864 struct tcb *tcp;
1865 {
1866     if (exiting(tcp)) {
1867         if (syserror(tcp))
1868             tprintf("%#lx", tcp->u_arg[0]);
1869         else
1870             printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
1871         tprintf(", %lu", tcp->u_arg[1]);
1872     }
1873     return 0;
1874 }
1875 #endif
1876
1877 #ifdef HAVE_SYS_ASYNCH_H
1878
1879 int
1880 sys_aioread(tcp)
1881 struct tcb *tcp;
1882 {
1883         struct aio_result_t res;
1884
1885         if (entering(tcp)) {
1886                 tprintf("%lu, ", tcp->u_arg[0]);
1887         } else {
1888                 if (syserror(tcp))
1889                         tprintf("%#lx", tcp->u_arg[1]);
1890                 else
1891                         printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1892                 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
1893                 printxval(whence, tcp->u_arg[4], "L_???");
1894                 if (syserror(tcp) || tcp->u_arg[5] == 0
1895                     || umove(tcp, tcp->u_arg[5], &res) < 0)
1896                         tprintf(", %#lx", tcp->u_arg[5]);
1897                 else
1898                         tprintf(", {aio_return %d aio_errno %d}",
1899                                 res.aio_return, res.aio_errno);
1900         }
1901         return 0;
1902 }
1903
1904 int
1905 sys_aiowrite(tcp)
1906 struct tcb *tcp;
1907 {
1908         struct aio_result_t res;
1909
1910         if (entering(tcp)) {
1911                 tprintf("%lu, ", tcp->u_arg[0]);
1912                 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1913                 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
1914                 printxval(whence, tcp->u_arg[4], "L_???");
1915         }
1916         else {
1917                 if (tcp->u_arg[5] == 0)
1918                         tprintf(", NULL");
1919                 else if (syserror(tcp)
1920                     || umove(tcp, tcp->u_arg[5], &res) < 0)
1921                         tprintf(", %#lx", tcp->u_arg[5]);
1922                 else
1923                         tprintf(", {aio_return %d aio_errno %d}",
1924                                 res.aio_return, res.aio_errno);
1925         }
1926         return 0;
1927 }
1928
1929 int
1930 sys_aiowait(tcp)
1931 struct tcb *tcp;
1932 {
1933         if (entering(tcp))
1934                 printtv(tcp, tcp->u_arg[0]);
1935         return 0;
1936 }
1937
1938 int
1939 sys_aiocancel(tcp)
1940 struct tcb *tcp;
1941 {
1942         struct aio_result_t res;
1943
1944         if (exiting(tcp)) {
1945                 if (tcp->u_arg[0] == 0)
1946                         tprintf("NULL");
1947                 else if (syserror(tcp)
1948                     || umove(tcp, tcp->u_arg[0], &res) < 0)
1949                         tprintf("%#lx", tcp->u_arg[0]);
1950                 else
1951                         tprintf("{aio_return %d aio_errno %d}",
1952                                 res.aio_return, res.aio_errno);
1953         }
1954         return 0;
1955 }
1956
1957 #endif /* HAVE_SYS_ASYNCH_H */
1958
1959 #if UNIXWARE >= 7
1960 int
1961 sys_lseek64 (tcp)
1962 struct tcb *tcp;
1963 {
1964         if (entering(tcp)) {
1965                 long long offset = * (long long *) & tcp->u_arg [1];
1966                 if (tcp->u_arg[3] == SEEK_SET)
1967                         tprintf("%ld, %llu, ", tcp->u_arg[0], offset);
1968                 else
1969                         tprintf("%ld, %lld, ", tcp->u_arg[0], offset);
1970                 printxval(whence, tcp->u_arg[3], "SEEK_???");
1971         }
1972         return RVAL_LDECIMAL;
1973 }
1974 #endif