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