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