]> granicus.if.org Git - strace/blob - file.c
Reindent defs.h preprocessor directives
[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
37 struct kernel_dirent {
38         unsigned long   d_ino;
39         unsigned long   d_off;
40         unsigned short  d_reclen;
41         char            d_name[1];
42 };
43
44 #ifdef LINUXSPARC
45 struct stat {
46         unsigned short  st_dev;
47         unsigned int    st_ino;
48         unsigned short  st_mode;
49         short           st_nlink;
50         unsigned short  st_uid;
51         unsigned short  st_gid;
52         unsigned short  st_rdev;
53         unsigned int    st_size;
54         int             st_atime;
55         unsigned int    __unused1;
56         int             st_mtime;
57         unsigned int    __unused2;
58         int             st_ctime;
59         unsigned int    __unused3;
60         int             st_blksize;
61         int             st_blocks;
62         unsigned int    __unused4[2];
63 };
64 # if defined(SPARC64)
65 struct stat_sparc64 {
66         unsigned int    st_dev;
67         unsigned long   st_ino;
68         unsigned int    st_mode;
69         unsigned int    st_nlink;
70         unsigned int    st_uid;
71         unsigned int    st_gid;
72         unsigned int    st_rdev;
73         long            st_size;
74         long            st_atime;
75         long            st_mtime;
76         long            st_ctime;
77         long            st_blksize;
78         long            st_blocks;
79         unsigned long   __unused4[2];
80 };
81 # endif /* SPARC64 */
82 # define stat kernel_stat
83 # include <asm/stat.h>
84 # undef stat
85 #else
86 # undef dev_t
87 # undef ino_t
88 # undef mode_t
89 # undef nlink_t
90 # undef uid_t
91 # undef gid_t
92 # undef off_t
93 # undef loff_t
94
95 # define dev_t __kernel_dev_t
96 # define ino_t __kernel_ino_t
97 # define mode_t __kernel_mode_t
98 # define nlink_t __kernel_nlink_t
99 # define uid_t __kernel_uid_t
100 # define gid_t __kernel_gid_t
101 # define off_t __kernel_off_t
102 # define loff_t __kernel_loff_t
103
104 # include <asm/stat.h>
105
106 # undef dev_t
107 # undef ino_t
108 # undef mode_t
109 # undef nlink_t
110 # undef uid_t
111 # undef gid_t
112 # undef off_t
113 # undef loff_t
114
115 # define dev_t dev_t
116 # define ino_t ino_t
117 # define mode_t mode_t
118 # define nlink_t nlink_t
119 # define uid_t uid_t
120 # define gid_t gid_t
121 # define off_t off_t
122 # define loff_t loff_t
123 #endif
124
125 #ifdef HPPA     /* asm-parisc/stat.h defines stat64 */
126 # undef stat64
127 #endif
128 #define stat libc_stat
129 #define stat64 libc_stat64
130 #include <sys/stat.h>
131 #undef stat
132 #undef stat64
133  /* These might be macros. */
134 #undef st_atime
135 #undef st_mtime
136 #undef st_ctime
137 #ifdef HPPA
138 # define stat64 hpux_stat64
139 #endif
140
141 #include <fcntl.h>
142
143
144 #ifdef HAVE_SYS_VFS_H
145 # include <sys/vfs.h>
146 #endif
147
148 #ifdef HAVE_LINUX_XATTR_H
149 # include <linux/xattr.h>
150 #else
151 # define XATTR_CREATE 1
152 # define XATTR_REPLACE 2
153 #endif
154
155
156 #if _LFS64_LARGEFILE
157 # ifdef HAVE_INTTYPES_H
158 #  include <inttypes.h>
159 # else
160 #  define PRId64 "lld"
161 #  define PRIu64 "llu"
162 # endif
163 #endif
164
165 #if HAVE_LONG_LONG_OFF_T
166 /*
167  * Ugly hacks for systems that have typedef long long off_t
168  */
169
170 # define stat64 stat
171 # define HAVE_STAT64 1  /* Ugly hack */
172
173 # define sys_stat64     sys_stat
174 # define sys_fstat64    sys_fstat
175 # define sys_lstat64    sys_lstat
176 # define sys_lseek64    sys_lseek
177 # define sys_truncate64 sys_truncate
178 # define sys_ftruncate64        sys_ftruncate
179 #endif
180
181 #ifdef MAJOR_IN_SYSMACROS
182 # include <sys/sysmacros.h>
183 #endif
184
185 #ifdef MAJOR_IN_MKDEV
186 # include <sys/mkdev.h>
187 #endif
188
189 #ifdef HAVE_SYS_ASYNCH_H
190 # include <sys/asynch.h>
191 #endif
192
193
194 const struct xlat open_access_modes[] = {
195         { O_RDONLY,     "O_RDONLY"      },
196         { O_WRONLY,     "O_WRONLY"      },
197         { O_RDWR,       "O_RDWR"        },
198 #ifdef O_ACCMODE
199         { O_ACCMODE,    "O_ACCMODE"     },
200 #endif
201         { 0,            NULL            },
202 };
203
204 const struct xlat open_mode_flags[] = {
205         { O_CREAT,      "O_CREAT"       },
206         { O_EXCL,       "O_EXCL"        },
207         { O_NOCTTY,     "O_NOCTTY"      },
208         { O_TRUNC,      "O_TRUNC"       },
209         { O_APPEND,     "O_APPEND"      },
210         { O_NONBLOCK,   "O_NONBLOCK"    },
211 #ifdef O_SYNC
212         { O_SYNC,       "O_SYNC"        },
213 #endif
214 #ifdef O_ASYNC
215         { O_ASYNC,      "O_ASYNC"       },
216 #endif
217 #ifdef O_DSYNC
218         { O_DSYNC,      "O_DSYNC"       },
219 #endif
220 #ifdef O_RSYNC
221         { O_RSYNC,      "O_RSYNC"       },
222 #endif
223 #if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
224         { O_NDELAY,     "O_NDELAY"      },
225 #endif
226 #ifdef O_PRIV
227         { O_PRIV,       "O_PRIV"        },
228 #endif
229 #ifdef O_DIRECT
230         { O_DIRECT,     "O_DIRECT"      },
231 #endif
232 #ifdef O_LARGEFILE
233 # if O_LARGEFILE == 0           /* biarch platforms in 64-bit mode */
234 #  undef O_LARGEFILE
235 #  ifdef SPARC64
236 #   define O_LARGEFILE  0x40000
237 #  elif defined X86_64 || defined S390X
238 #   define O_LARGEFILE  0100000
239 #  endif
240 # endif
241 # ifdef O_LARGEFILE
242         { O_LARGEFILE,  "O_LARGEFILE"   },
243 # endif
244 #endif
245 #ifdef O_DIRECTORY
246         { O_DIRECTORY,  "O_DIRECTORY"   },
247 #endif
248 #ifdef O_NOFOLLOW
249         { O_NOFOLLOW,   "O_NOFOLLOW"    },
250 #endif
251 #ifdef O_NOATIME
252         { O_NOATIME,    "O_NOATIME"     },
253 #endif
254 #ifdef O_CLOEXEC
255         { O_CLOEXEC,    "O_CLOEXEC"     },
256 #endif
257 #ifdef FNDELAY
258         { FNDELAY,      "FNDELAY"       },
259 #endif
260 #ifdef FAPPEND
261         { FAPPEND,      "FAPPEND"       },
262 #endif
263 #ifdef FMARK
264         { FMARK,        "FMARK"         },
265 #endif
266 #ifdef FDEFER
267         { FDEFER,       "FDEFER"        },
268 #endif
269 #ifdef FASYNC
270         { FASYNC,       "FASYNC"        },
271 #endif
272 #ifdef FSHLOCK
273         { FSHLOCK,      "FSHLOCK"       },
274 #endif
275 #ifdef FEXLOCK
276         { FEXLOCK,      "FEXLOCK"       },
277 #endif
278 #ifdef FCREAT
279         { FCREAT,       "FCREAT"        },
280 #endif
281 #ifdef FTRUNC
282         { FTRUNC,       "FTRUNC"        },
283 #endif
284 #ifdef FEXCL
285         { FEXCL,        "FEXCL"         },
286 #endif
287 #ifdef FNBIO
288         { FNBIO,        "FNBIO"         },
289 #endif
290 #ifdef FSYNC
291         { FSYNC,        "FSYNC"         },
292 #endif
293 #ifdef FNOCTTY
294         { FNOCTTY,      "FNOCTTY"       },
295 #endif
296 #ifdef O_SHLOCK
297         { O_SHLOCK,     "O_SHLOCK"      },
298 #endif
299 #ifdef O_EXLOCK
300         { O_EXLOCK,     "O_EXLOCK"      },
301 #endif
302         { 0,            NULL            },
303 };
304
305
306 #ifndef AT_FDCWD
307 # define AT_FDCWD                -100
308 #endif
309
310 /* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
311  * extension to get the right value.  We do this by declaring fd as int here.
312  */
313 static void
314 print_dirfd(struct tcb *tcp, int fd)
315 {
316         if (fd == AT_FDCWD)
317                 tprints("AT_FDCWD, ");
318         else {
319                 printfd(tcp, fd);
320                 tprints(", ");
321         }
322 }
323
324 /*
325  * low bits of the open(2) flags define access mode,
326  * other bits are real flags.
327  */
328 const char *
329 sprint_open_modes(mode_t flags)
330 {
331         static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
332         char *p;
333         char sep;
334         const char *str;
335         const struct xlat *x;
336
337         sep = ' ';
338         p = stpcpy(outstr, "flags");
339         str = xlookup(open_access_modes, flags & 3);
340         if (str) {
341                 *p++ = sep;
342                 p = stpcpy(p, str);
343                 flags &= ~3;
344                 if (!flags)
345                         return outstr;
346                 sep = '|';
347         }
348
349         for (x = open_mode_flags; x->str; x++) {
350                 if ((flags & x->val) == x->val) {
351                         *p++ = sep;
352                         p = stpcpy(p, x->str);
353                         flags &= ~x->val;
354                         if (!flags)
355                                 return outstr;
356                         sep = '|';
357                 }
358         }
359         /* flags is still nonzero */
360         *p++ = sep;
361         sprintf(p, "%#x", flags);
362         return outstr;
363 }
364
365 void
366 tprint_open_modes(mode_t flags)
367 {
368         tprints(sprint_open_modes(flags) + sizeof("flags"));
369 }
370
371 static int
372 decode_open(struct tcb *tcp, int offset)
373 {
374         if (entering(tcp)) {
375                 printpath(tcp, tcp->u_arg[offset]);
376                 tprints(", ");
377                 /* flags */
378                 tprint_open_modes(tcp->u_arg[offset + 1]);
379                 if (tcp->u_arg[offset + 1] & O_CREAT) {
380                         /* mode */
381                         tprintf(", %#lo", tcp->u_arg[offset + 2]);
382                 }
383         }
384         return 0;
385 }
386
387 int
388 sys_open(struct tcb *tcp)
389 {
390         return decode_open(tcp, 0);
391 }
392
393 int
394 sys_openat(struct tcb *tcp)
395 {
396         if (entering(tcp))
397                 print_dirfd(tcp, tcp->u_arg[0]);
398         return decode_open(tcp, 1);
399 }
400
401 #ifdef LINUXSPARC
402 static const struct xlat openmodessol[] = {
403         { 0,            "O_RDWR"        },
404         { 1,            "O_RDONLY"      },
405         { 2,            "O_WRONLY"      },
406         { 0x80,         "O_NONBLOCK"    },
407         { 8,            "O_APPEND"      },
408         { 0x100,        "O_CREAT"       },
409         { 0x200,        "O_TRUNC"       },
410         { 0x400,        "O_EXCL"        },
411         { 0x800,        "O_NOCTTY"      },
412         { 0x10,         "O_SYNC"        },
413         { 0x40,         "O_DSYNC"       },
414         { 0x8000,       "O_RSYNC"       },
415         { 4,            "O_NDELAY"      },
416         { 0x1000,       "O_PRIV"        },
417         { 0,            NULL            },
418 };
419
420 int
421 solaris_open(struct tcb *tcp)
422 {
423         if (entering(tcp)) {
424                 printpath(tcp, tcp->u_arg[0]);
425                 tprints(", ");
426                 /* flags */
427                 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
428                 if (tcp->u_arg[1] & 0x100) {
429                         /* mode */
430                         tprintf(", %#lo", tcp->u_arg[2]);
431                 }
432         }
433         return 0;
434 }
435
436 #endif
437
438 int
439 sys_creat(struct tcb *tcp)
440 {
441         if (entering(tcp)) {
442                 printpath(tcp, tcp->u_arg[0]);
443                 tprintf(", %#lo", tcp->u_arg[1]);
444         }
445         return 0;
446 }
447
448 static const struct xlat access_flags[] = {
449         { F_OK,         "F_OK",         },
450         { R_OK,         "R_OK"          },
451         { W_OK,         "W_OK"          },
452         { X_OK,         "X_OK"          },
453 #ifdef EFF_ONLY_OK
454         { EFF_ONLY_OK,  "EFF_ONLY_OK"   },
455 #endif
456 #ifdef EX_OK
457         { EX_OK,        "EX_OK"         },
458 #endif
459         { 0,            NULL            },
460 };
461
462 static int
463 decode_access(struct tcb *tcp, int offset)
464 {
465         if (entering(tcp)) {
466                 printpath(tcp, tcp->u_arg[offset]);
467                 tprints(", ");
468                 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
469         }
470         return 0;
471 }
472
473 int
474 sys_access(struct tcb *tcp)
475 {
476         return decode_access(tcp, 0);
477 }
478
479 int
480 sys_faccessat(struct tcb *tcp)
481 {
482         if (entering(tcp))
483                 print_dirfd(tcp, tcp->u_arg[0]);
484         return decode_access(tcp, 1);
485 }
486
487 int
488 sys_umask(struct tcb *tcp)
489 {
490         if (entering(tcp)) {
491                 tprintf("%#lo", tcp->u_arg[0]);
492         }
493         return RVAL_OCTAL;
494 }
495
496 static const struct xlat whence[] = {
497         { SEEK_SET,     "SEEK_SET"      },
498         { SEEK_CUR,     "SEEK_CUR"      },
499         { SEEK_END,     "SEEK_END"      },
500         { 0,            NULL            },
501 };
502
503 #ifndef HAVE_LONG_LONG_OFF_T
504 #if defined (LINUX_MIPSN32)
505 int
506 sys_lseek(struct tcb *tcp)
507 {
508         long long offset;
509         int _whence;
510
511         if (entering(tcp)) {
512                 printfd(tcp, tcp->u_arg[0]);
513                 tprints(", ");
514                 offset = tcp->ext_arg[1];
515                 _whence = tcp->u_arg[2];
516                 if (_whence == SEEK_SET)
517                         tprintf("%llu, ", offset);
518                 else
519                         tprintf("%lld, ", offset);
520                 printxval(whence, _whence, "SEEK_???");
521         }
522         return RVAL_UDECIMAL;
523 }
524 #else /* !LINUX_MIPSN32 */
525 int
526 sys_lseek(struct tcb *tcp)
527 {
528         off_t offset;
529         int _whence;
530
531         if (entering(tcp)) {
532                 printfd(tcp, tcp->u_arg[0]);
533                 tprints(", ");
534                 offset = tcp->u_arg[1];
535                 _whence = tcp->u_arg[2];
536                 if (_whence == SEEK_SET)
537                         tprintf("%lu, ", offset);
538                 else
539                         tprintf("%ld, ", offset);
540                 printxval(whence, _whence, "SEEK_???");
541         }
542         return RVAL_UDECIMAL;
543 }
544 #endif /* LINUX_MIPSN32 */
545 #endif
546
547 int
548 sys_llseek(struct tcb *tcp)
549 {
550         if (entering(tcp)) {
551                 printfd(tcp, tcp->u_arg[0]);
552                 /*
553                  * This one call takes explicitly two 32-bit arguments hi, lo,
554                  * rather than one 64-bit argument for which LONG_LONG works
555                  * appropriate for the native byte order.
556                  */
557                 if (tcp->u_arg[4] == SEEK_SET)
558                         tprintf(", %llu, ",
559                                 ((long long int) tcp->u_arg[1]) << 32 |
560                                 (unsigned long long) (unsigned) tcp->u_arg[2]);
561                 else
562                         tprintf(", %lld, ",
563                                 ((long long int) tcp->u_arg[1]) << 32 |
564                                 (unsigned long long) (unsigned) tcp->u_arg[2]);
565         }
566         else {
567                 long long int off;
568                 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
569                         tprintf("%#lx, ", tcp->u_arg[3]);
570                 else
571                         tprintf("[%llu], ", off);
572                 printxval(whence, tcp->u_arg[4], "SEEK_???");
573         }
574         return 0;
575 }
576
577 int
578 sys_readahead(struct tcb *tcp)
579 {
580         if (entering(tcp)) {
581                 int argn;
582                 printfd(tcp, tcp->u_arg[0]);
583                 tprints(", ");
584                 argn = printllval(tcp, "%lld", 1);
585                 tprintf(", %ld", tcp->u_arg[argn]);
586         }
587         return 0;
588 }
589
590 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
591 int
592 sys_lseek64(struct tcb *tcp)
593 {
594         if (entering(tcp)) {
595                 int argn;
596                 printfd(tcp, tcp->u_arg[0]);
597                 tprints(", ");
598                 if (tcp->u_arg[3] == SEEK_SET)
599                         argn = printllval(tcp, "%llu, ", 1);
600                 else
601                         argn = printllval(tcp, "%lld, ", 1);
602                 printxval(whence, tcp->u_arg[argn], "SEEK_???");
603         }
604         return RVAL_LUDECIMAL;
605 }
606 #endif
607
608 #ifndef HAVE_LONG_LONG_OFF_T
609 int
610 sys_truncate(struct tcb *tcp)
611 {
612         if (entering(tcp)) {
613                 printpath(tcp, tcp->u_arg[0]);
614                 tprintf(", %lu", tcp->u_arg[1]);
615         }
616         return 0;
617 }
618 #endif
619
620 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
621 int
622 sys_truncate64(struct tcb *tcp)
623 {
624         if (entering(tcp)) {
625                 printpath(tcp, tcp->u_arg[0]);
626                 printllval(tcp, ", %llu", 1);
627         }
628         return 0;
629 }
630 #endif
631
632 #ifndef HAVE_LONG_LONG_OFF_T
633 int
634 sys_ftruncate(struct tcb *tcp)
635 {
636         if (entering(tcp)) {
637                 printfd(tcp, tcp->u_arg[0]);
638                 tprintf(", %lu", tcp->u_arg[1]);
639         }
640         return 0;
641 }
642 #endif
643
644 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
645 int
646 sys_ftruncate64(struct tcb *tcp)
647 {
648         if (entering(tcp)) {
649                 printfd(tcp, tcp->u_arg[0]);
650                 tprints(", ");
651                 printllval(tcp, "%llu", 1);
652         }
653         return 0;
654 }
655 #endif
656
657 /* several stats */
658
659 static const struct xlat modetypes[] = {
660         { S_IFREG,      "S_IFREG"       },
661         { S_IFSOCK,     "S_IFSOCK"      },
662         { S_IFIFO,      "S_IFIFO"       },
663         { S_IFLNK,      "S_IFLNK"       },
664         { S_IFDIR,      "S_IFDIR"       },
665         { S_IFBLK,      "S_IFBLK"       },
666         { S_IFCHR,      "S_IFCHR"       },
667         { 0,            NULL            },
668 };
669
670 static const char *
671 sprintmode(int mode)
672 {
673         static char buf[64];
674         const char *s;
675
676         if ((mode & S_IFMT) == 0)
677                 s = "";
678         else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
679                 sprintf(buf, "%#o", mode);
680                 return buf;
681         }
682         sprintf(buf, "%s%s%s%s", s,
683                 (mode & S_ISUID) ? "|S_ISUID" : "",
684                 (mode & S_ISGID) ? "|S_ISGID" : "",
685                 (mode & S_ISVTX) ? "|S_ISVTX" : "");
686         mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
687         if (mode)
688                 sprintf(buf + strlen(buf), "|%#o", mode);
689         s = (*buf == '|') ? buf + 1 : buf;
690         return *s ? s : "0";
691 }
692
693 static char *
694 sprinttime(time_t t)
695 {
696         struct tm *tmp;
697         static char buf[32];
698
699         if (t == 0) {
700                 strcpy(buf, "0");
701                 return buf;
702         }
703         tmp = localtime(&t);
704         if (tmp)
705                 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
706                         tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
707                         tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
708         else
709                 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
710
711         return buf;
712 }
713
714 #ifdef LINUXSPARC
715 typedef struct {
716         int     tv_sec;
717         int     tv_nsec;
718 } timestruct_t;
719
720 struct solstat {
721         unsigned        st_dev;
722         int             st_pad1[3];     /* network id */
723         unsigned        st_ino;
724         unsigned        st_mode;
725         unsigned        st_nlink;
726         unsigned        st_uid;
727         unsigned        st_gid;
728         unsigned        st_rdev;
729         int             st_pad2[2];
730         int             st_size;
731         int             st_pad3;        /* st_size, off_t expansion */
732         timestruct_t    st_atime;
733         timestruct_t    st_mtime;
734         timestruct_t    st_ctime;
735         int             st_blksize;
736         int             st_blocks;
737         char            st_fstype[16];
738         int             st_pad4[8];     /* expansion area */
739 };
740
741 static void
742 printstatsol(struct tcb *tcp, long addr)
743 {
744         struct solstat statbuf;
745
746         if (umove(tcp, addr, &statbuf) < 0) {
747                 tprints("{...}");
748                 return;
749         }
750         if (!abbrev(tcp)) {
751                 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
752                         (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
753                         (unsigned long) (statbuf.st_dev & 0x3ffff),
754                         (unsigned long) statbuf.st_ino,
755                         sprintmode(statbuf.st_mode));
756                 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
757                         (unsigned long) statbuf.st_nlink,
758                         (unsigned long) statbuf.st_uid,
759                         (unsigned long) statbuf.st_gid);
760                 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
761                 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
762         }
763         else
764                 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
765         switch (statbuf.st_mode & S_IFMT) {
766         case S_IFCHR: case S_IFBLK:
767                 tprintf("st_rdev=makedev(%lu, %lu), ",
768                         (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
769                         (unsigned long) (statbuf.st_rdev & 0x3ffff));
770                 break;
771         default:
772                 tprintf("st_size=%u, ", statbuf.st_size);
773                 break;
774         }
775         if (!abbrev(tcp)) {
776                 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
777                 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
778                 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
779         }
780         else
781                 tprints("...}");
782 }
783
784 #if defined (SPARC64)
785 static void
786 printstat_sparc64(struct tcb *tcp, long addr)
787 {
788         struct stat_sparc64 statbuf;
789
790         if (umove(tcp, addr, &statbuf) < 0) {
791                 tprints("{...}");
792                 return;
793         }
794
795         if (!abbrev(tcp)) {
796                 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
797                         (unsigned long) major(statbuf.st_dev),
798                         (unsigned long) minor(statbuf.st_dev),
799                         (unsigned long) statbuf.st_ino,
800                         sprintmode(statbuf.st_mode));
801                 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
802                         (unsigned long) statbuf.st_nlink,
803                         (unsigned long) statbuf.st_uid,
804                         (unsigned long) statbuf.st_gid);
805                 tprintf("st_blksize=%lu, ",
806                         (unsigned long) statbuf.st_blksize);
807                 tprintf("st_blocks=%lu, ",
808                         (unsigned long) statbuf.st_blocks);
809         }
810         else
811                 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
812         switch (statbuf.st_mode & S_IFMT) {
813         case S_IFCHR: case S_IFBLK:
814                 tprintf("st_rdev=makedev(%lu, %lu), ",
815                         (unsigned long) major(statbuf.st_rdev),
816                         (unsigned long) minor(statbuf.st_rdev));
817                 break;
818         default:
819                 tprintf("st_size=%lu, ", statbuf.st_size);
820                 break;
821         }
822         if (!abbrev(tcp)) {
823                 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
824                 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
825                 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
826                 tprints("}");
827         }
828         else
829                 tprints("...}");
830 }
831 #endif /* SPARC64 */
832 #endif /* LINUXSPARC */
833
834 #if defined POWERPC64
835 struct stat_powerpc32 {
836         unsigned int    st_dev;
837         unsigned int    st_ino;
838         unsigned int    st_mode;
839         unsigned short  st_nlink;
840         unsigned int    st_uid;
841         unsigned int    st_gid;
842         unsigned int    st_rdev;
843         unsigned int    st_size;
844         unsigned int    st_blksize;
845         unsigned int    st_blocks;
846         unsigned int    st_atime;
847         unsigned int    st_atime_nsec;
848         unsigned int    st_mtime;
849         unsigned int    st_mtime_nsec;
850         unsigned int    st_ctime;
851         unsigned int    st_ctime_nsec;
852         unsigned int    __unused4;
853         unsigned int    __unused5;
854 };
855
856 static void
857 printstat_powerpc32(struct tcb *tcp, long addr)
858 {
859         struct stat_powerpc32 statbuf;
860
861         if (umove(tcp, addr, &statbuf) < 0) {
862                 tprints("{...}");
863                 return;
864         }
865
866         if (!abbrev(tcp)) {
867                 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
868                         major(statbuf.st_dev), minor(statbuf.st_dev),
869                         statbuf.st_ino,
870                         sprintmode(statbuf.st_mode));
871                 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
872                         statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
873                 tprintf("st_blksize=%u, ", statbuf.st_blksize);
874                 tprintf("st_blocks=%u, ", statbuf.st_blocks);
875         }
876         else
877                 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
878         switch (statbuf.st_mode & S_IFMT) {
879         case S_IFCHR: case S_IFBLK:
880                 tprintf("st_rdev=makedev(%lu, %lu), ",
881                         (unsigned long) major(statbuf.st_rdev),
882                         (unsigned long) minor(statbuf.st_rdev));
883                 break;
884         default:
885                 tprintf("st_size=%u, ", statbuf.st_size);
886                 break;
887         }
888         if (!abbrev(tcp)) {
889                 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
890                 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
891                 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
892                 tprints("}");
893         }
894         else
895                 tprints("...}");
896 }
897 #endif /* POWERPC64 */
898
899 static const struct xlat fileflags[] = {
900         { 0,            NULL            },
901 };
902
903
904 #ifndef HAVE_LONG_LONG_OFF_T
905 static void
906 realprintstat(struct tcb *tcp, struct stat *statbuf)
907 {
908         if (!abbrev(tcp)) {
909                 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
910                         (unsigned long) major(statbuf->st_dev),
911                         (unsigned long) minor(statbuf->st_dev),
912                         (unsigned long) statbuf->st_ino,
913                         sprintmode(statbuf->st_mode));
914                 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
915                         (unsigned long) statbuf->st_nlink,
916                         (unsigned long) statbuf->st_uid,
917                         (unsigned long) statbuf->st_gid);
918 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
919                 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
920 #endif
921 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
922                 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
923 #endif
924         }
925         else
926                 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
927         switch (statbuf->st_mode & S_IFMT) {
928         case S_IFCHR: case S_IFBLK:
929 #ifdef HAVE_STRUCT_STAT_ST_RDEV
930                 tprintf("st_rdev=makedev(%lu, %lu), ",
931                         (unsigned long) major(statbuf->st_rdev),
932                         (unsigned long) minor(statbuf->st_rdev));
933 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
934                 tprintf("st_size=makedev(%lu, %lu), ",
935                         (unsigned long) major(statbuf->st_size),
936                         (unsigned long) minor(statbuf->st_size));
937 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
938                 break;
939         default:
940                 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
941                 break;
942         }
943         if (!abbrev(tcp)) {
944                 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
945                 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
946                 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
947 #if HAVE_STRUCT_STAT_ST_FLAGS
948                 tprints(", st_flags=");
949                 printflags(fileflags, statbuf->st_flags, "UF_???");
950 #endif
951 #if HAVE_STRUCT_STAT_ST_ACLCNT
952                 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
953 #endif
954 #if HAVE_STRUCT_STAT_ST_LEVEL
955                 tprintf(", st_level=%ld", statbuf->st_level);
956 #endif
957 #if HAVE_STRUCT_STAT_ST_FSTYPE
958                 tprintf(", st_fstype=%.*s",
959                         (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
960 #endif
961 #if HAVE_STRUCT_STAT_ST_GEN
962                 tprintf(", st_gen=%u", statbuf->st_gen);
963 #endif
964                 tprints("}");
965         }
966         else
967                 tprints("...}");
968 }
969
970
971 static void
972 printstat(struct tcb *tcp, long addr)
973 {
974         struct stat statbuf;
975
976         if (!addr) {
977                 tprints("NULL");
978                 return;
979         }
980         if (syserror(tcp) || !verbose(tcp)) {
981                 tprintf("%#lx", addr);
982                 return;
983         }
984
985 #ifdef LINUXSPARC
986         if (current_personality == 1) {
987                 printstatsol(tcp, addr);
988                 return;
989         }
990 #ifdef SPARC64
991         else if (current_personality == 2) {
992                 printstat_sparc64(tcp, addr);
993                 return;
994         }
995 #endif
996 #endif /* LINUXSPARC */
997
998 #if defined POWERPC64
999         if (current_personality == 1) {
1000                 printstat_powerpc32(tcp, addr);
1001                 return;
1002         }
1003 #endif
1004
1005         if (umove(tcp, addr, &statbuf) < 0) {
1006                 tprints("{...}");
1007                 return;
1008         }
1009
1010         realprintstat(tcp, &statbuf);
1011 }
1012 #endif  /* !HAVE_LONG_LONG_OFF_T */
1013
1014 #if !defined HAVE_STAT64 && defined X86_64
1015 /*
1016  * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1017  * `struct stat64'.  Its <asm-i386/stat.h> definition expects 32-bit `long'.
1018  * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1019  * __GNUC__ is needed for the required __attribute__ below.
1020  */
1021 struct stat64 {
1022         unsigned long long      st_dev;
1023         unsigned char   __pad0[4];
1024         unsigned int    __st_ino;
1025         unsigned int    st_mode;
1026         unsigned int    st_nlink;
1027         unsigned int    st_uid;
1028         unsigned int    st_gid;
1029         unsigned long long      st_rdev;
1030         unsigned char   __pad3[4];
1031         long long       st_size;
1032         unsigned int    st_blksize;
1033         unsigned long long      st_blocks;
1034         unsigned int    st_atime;
1035         unsigned int    st_atime_nsec;
1036         unsigned int    st_mtime;
1037         unsigned int    st_mtime_nsec;
1038         unsigned int    st_ctime;
1039         unsigned int    st_ctime_nsec;
1040         unsigned long long      st_ino;
1041 } __attribute__((packed));
1042 # define HAVE_STAT64    1
1043 # define STAT64_SIZE    96
1044 #endif
1045
1046 #ifdef HAVE_STAT64
1047 static void
1048 printstat64(struct tcb *tcp, long addr)
1049 {
1050         struct stat64 statbuf;
1051
1052 #ifdef STAT64_SIZE
1053         (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1054 #endif
1055
1056         if (!addr) {
1057                 tprints("NULL");
1058                 return;
1059         }
1060         if (syserror(tcp) || !verbose(tcp)) {
1061                 tprintf("%#lx", addr);
1062                 return;
1063         }
1064
1065 #ifdef LINUXSPARC
1066         if (current_personality == 1) {
1067                 printstatsol(tcp, addr);
1068                 return;
1069         }
1070 # ifdef SPARC64
1071         else if (current_personality == 2) {
1072                 printstat_sparc64(tcp, addr);
1073                 return;
1074         }
1075 # endif
1076 #endif /* LINUXSPARC */
1077
1078 #if defined X86_64
1079         if (current_personality == 0) {
1080                 printstat(tcp, addr);
1081                 return;
1082         }
1083 #endif
1084
1085         if (umove(tcp, addr, &statbuf) < 0) {
1086                 tprints("{...}");
1087                 return;
1088         }
1089
1090         if (!abbrev(tcp)) {
1091 #ifdef HAVE_LONG_LONG
1092                 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1093 #else
1094                 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
1095 #endif
1096                         (unsigned long) major(statbuf.st_dev),
1097                         (unsigned long) minor(statbuf.st_dev),
1098 #ifdef HAVE_LONG_LONG
1099                         (unsigned long long) statbuf.st_ino,
1100 #else
1101                         (unsigned long) statbuf.st_ino,
1102 #endif
1103                         sprintmode(statbuf.st_mode));
1104                 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1105                         (unsigned long) statbuf.st_nlink,
1106                         (unsigned long) statbuf.st_uid,
1107                         (unsigned long) statbuf.st_gid);
1108 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1109                 tprintf("st_blksize=%lu, ",
1110                         (unsigned long) statbuf.st_blksize);
1111 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1112 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
1113                 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1114 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
1115         }
1116         else
1117                 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1118         switch (statbuf.st_mode & S_IFMT) {
1119         case S_IFCHR: case S_IFBLK:
1120 #ifdef HAVE_STRUCT_STAT_ST_RDEV
1121                 tprintf("st_rdev=makedev(%lu, %lu), ",
1122                         (unsigned long) major(statbuf.st_rdev),
1123                         (unsigned long) minor(statbuf.st_rdev));
1124 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
1125                 tprintf("st_size=makedev(%lu, %lu), ",
1126                         (unsigned long) major(statbuf.st_size),
1127                         (unsigned long) minor(statbuf.st_size));
1128 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
1129                 break;
1130         default:
1131 #ifdef HAVE_LONG_LONG
1132                 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1133 #else
1134                 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1135 #endif
1136                 break;
1137         }
1138         if (!abbrev(tcp)) {
1139                 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1140                 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1141                 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1142 #if HAVE_STRUCT_STAT_ST_FLAGS
1143                 tprints(", st_flags=");
1144                 printflags(fileflags, statbuf.st_flags, "UF_???");
1145 #endif
1146 #if HAVE_STRUCT_STAT_ST_ACLCNT
1147                 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1148 #endif
1149 #if HAVE_STRUCT_STAT_ST_LEVEL
1150                 tprintf(", st_level=%ld", statbuf.st_level);
1151 #endif
1152 #if HAVE_STRUCT_STAT_ST_FSTYPE
1153                 tprintf(", st_fstype=%.*s",
1154                         (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1155 #endif
1156 #if HAVE_STRUCT_STAT_ST_GEN
1157                 tprintf(", st_gen=%u", statbuf.st_gen);
1158 #endif
1159                 tprints("}");
1160         }
1161         else
1162                 tprints("...}");
1163 }
1164 #endif /* HAVE_STAT64 */
1165
1166 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1167 static void
1168 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
1169 {
1170         newbuf->st_dev = oldbuf->st_dev;
1171         newbuf->st_ino = oldbuf->st_ino;
1172         newbuf->st_mode = oldbuf->st_mode;
1173         newbuf->st_nlink = oldbuf->st_nlink;
1174         newbuf->st_uid = oldbuf->st_uid;
1175         newbuf->st_gid = oldbuf->st_gid;
1176         newbuf->st_rdev = oldbuf->st_rdev;
1177         newbuf->st_size = oldbuf->st_size;
1178         newbuf->st_atime = oldbuf->st_atime;
1179         newbuf->st_mtime = oldbuf->st_mtime;
1180         newbuf->st_ctime = oldbuf->st_ctime;
1181         newbuf->st_blksize = 0; /* not supported in old_stat */
1182         newbuf->st_blocks = 0; /* not supported in old_stat */
1183 }
1184
1185
1186 static void
1187 printoldstat(struct tcb *tcp, long addr)
1188 {
1189         struct __old_kernel_stat statbuf;
1190         struct stat newstatbuf;
1191
1192         if (!addr) {
1193                 tprints("NULL");
1194                 return;
1195         }
1196         if (syserror(tcp) || !verbose(tcp)) {
1197                 tprintf("%#lx", addr);
1198                 return;
1199         }
1200
1201 # ifdef LINUXSPARC
1202         if (current_personality == 1) {
1203                 printstatsol(tcp, addr);
1204                 return;
1205         }
1206 # endif
1207
1208         if (umove(tcp, addr, &statbuf) < 0) {
1209                 tprints("{...}");
1210                 return;
1211         }
1212
1213         convertoldstat(&statbuf, &newstatbuf);
1214         realprintstat(tcp, &newstatbuf);
1215 }
1216 #endif
1217
1218 #ifndef HAVE_LONG_LONG_OFF_T
1219 int
1220 sys_stat(struct tcb *tcp)
1221 {
1222         if (entering(tcp)) {
1223                 printpath(tcp, tcp->u_arg[0]);
1224                 tprints(", ");
1225         } else {
1226                 printstat(tcp, tcp->u_arg[1]);
1227         }
1228         return 0;
1229 }
1230 #endif
1231
1232 int
1233 sys_stat64(struct tcb *tcp)
1234 {
1235 #ifdef HAVE_STAT64
1236         if (entering(tcp)) {
1237                 printpath(tcp, tcp->u_arg[0]);
1238                 tprints(", ");
1239         } else {
1240                 printstat64(tcp, tcp->u_arg[1]);
1241         }
1242         return 0;
1243 #else
1244         return printargs(tcp);
1245 #endif
1246 }
1247
1248 static const struct xlat fstatatflags[] = {
1249 #ifndef AT_SYMLINK_NOFOLLOW
1250 # define AT_SYMLINK_NOFOLLOW     0x100
1251 #endif
1252         { AT_SYMLINK_NOFOLLOW,  "AT_SYMLINK_NOFOLLOW"   },
1253         { 0,                    NULL                    },
1254 };
1255 #define utimensatflags fstatatflags
1256
1257 int
1258 sys_newfstatat(struct tcb *tcp)
1259 {
1260         if (entering(tcp)) {
1261                 print_dirfd(tcp, tcp->u_arg[0]);
1262                 printpath(tcp, tcp->u_arg[1]);
1263                 tprints(", ");
1264         } else {
1265 #ifdef POWERPC64
1266                 if (current_personality == 0)
1267                         printstat(tcp, tcp->u_arg[2]);
1268                 else
1269                         printstat64(tcp, tcp->u_arg[2]);
1270 #elif defined HAVE_STAT64
1271                 printstat64(tcp, tcp->u_arg[2]);
1272 #else
1273                 printstat(tcp, tcp->u_arg[2]);
1274 #endif
1275                 tprints(", ");
1276                 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1277         }
1278         return 0;
1279 }
1280
1281 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1282 int
1283 sys_oldstat(struct tcb *tcp)
1284 {
1285         if (entering(tcp)) {
1286                 printpath(tcp, tcp->u_arg[0]);
1287                 tprints(", ");
1288         } else {
1289                 printoldstat(tcp, tcp->u_arg[1]);
1290         }
1291         return 0;
1292 }
1293 #endif
1294
1295 #ifndef HAVE_LONG_LONG_OFF_T
1296 int
1297 sys_fstat(struct tcb *tcp)
1298 {
1299         if (entering(tcp)) {
1300                 printfd(tcp, tcp->u_arg[0]);
1301                 tprints(", ");
1302         } else {
1303                 printstat(tcp, tcp->u_arg[1]);
1304         }
1305         return 0;
1306 }
1307 #endif
1308
1309 int
1310 sys_fstat64(struct tcb *tcp)
1311 {
1312 #ifdef HAVE_STAT64
1313         if (entering(tcp)) {
1314                 printfd(tcp, tcp->u_arg[0]);
1315                 tprints(", ");
1316         } else {
1317                 printstat64(tcp, tcp->u_arg[1]);
1318         }
1319         return 0;
1320 #else
1321         return printargs(tcp);
1322 #endif
1323 }
1324
1325 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1326 int
1327 sys_oldfstat(struct tcb *tcp)
1328 {
1329         if (entering(tcp)) {
1330                 printfd(tcp, tcp->u_arg[0]);
1331                 tprints(", ");
1332         } else {
1333                 printoldstat(tcp, tcp->u_arg[1]);
1334         }
1335         return 0;
1336 }
1337 #endif
1338
1339 #ifndef HAVE_LONG_LONG_OFF_T
1340 int
1341 sys_lstat(struct tcb *tcp)
1342 {
1343         if (entering(tcp)) {
1344                 printpath(tcp, tcp->u_arg[0]);
1345                 tprints(", ");
1346         } else {
1347                 printstat(tcp, tcp->u_arg[1]);
1348         }
1349         return 0;
1350 }
1351 #endif
1352
1353 int
1354 sys_lstat64(struct tcb *tcp)
1355 {
1356 #ifdef HAVE_STAT64
1357         if (entering(tcp)) {
1358                 printpath(tcp, tcp->u_arg[0]);
1359                 tprints(", ");
1360         } else {
1361                 printstat64(tcp, tcp->u_arg[1]);
1362         }
1363         return 0;
1364 #else
1365         return printargs(tcp);
1366 #endif
1367 }
1368
1369 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1370 int
1371 sys_oldlstat(struct tcb *tcp)
1372 {
1373         if (entering(tcp)) {
1374                 printpath(tcp, tcp->u_arg[0]);
1375                 tprints(", ");
1376         } else {
1377                 printoldstat(tcp, tcp->u_arg[1]);
1378         }
1379         return 0;
1380 }
1381 #endif
1382
1383
1384 #if defined(LINUXSPARC)
1385
1386 int
1387 sys_xstat(struct tcb *tcp)
1388 {
1389         if (entering(tcp)) {
1390                 tprintf("%ld, ", tcp->u_arg[0]);
1391                 printpath(tcp, tcp->u_arg[1]);
1392                 tprints(", ");
1393         } else {
1394 # ifdef _STAT64_VER
1395                 if (tcp->u_arg[0] == _STAT64_VER)
1396                         printstat64 (tcp, tcp->u_arg[2]);
1397                 else
1398 # endif
1399                 printstat(tcp, tcp->u_arg[2]);
1400         }
1401         return 0;
1402 }
1403
1404 int
1405 sys_fxstat(struct tcb *tcp)
1406 {
1407         if (entering(tcp))
1408                 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1409         else {
1410 # ifdef _STAT64_VER
1411                 if (tcp->u_arg[0] == _STAT64_VER)
1412                         printstat64 (tcp, tcp->u_arg[2]);
1413                 else
1414 # endif
1415                 printstat(tcp, tcp->u_arg[2]);
1416         }
1417         return 0;
1418 }
1419
1420 int
1421 sys_lxstat(struct tcb *tcp)
1422 {
1423         if (entering(tcp)) {
1424                 tprintf("%ld, ", tcp->u_arg[0]);
1425                 printpath(tcp, tcp->u_arg[1]);
1426                 tprints(", ");
1427         } else {
1428 # ifdef _STAT64_VER
1429                 if (tcp->u_arg[0] == _STAT64_VER)
1430                         printstat64 (tcp, tcp->u_arg[2]);
1431                 else
1432 # endif
1433                 printstat(tcp, tcp->u_arg[2]);
1434         }
1435         return 0;
1436 }
1437
1438 int
1439 sys_xmknod(struct tcb *tcp)
1440 {
1441         int mode = tcp->u_arg[2];
1442
1443         if (entering(tcp)) {
1444                 tprintf("%ld, ", tcp->u_arg[0]);
1445                 printpath(tcp, tcp->u_arg[1]);
1446                 tprintf(", %s", sprintmode(mode));
1447                 switch (mode & S_IFMT) {
1448                 case S_IFCHR: case S_IFBLK:
1449                         tprintf(", makedev(%lu, %lu)",
1450                                 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1451                                 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1452                         break;
1453                 default:
1454                         break;
1455                 }
1456         }
1457         return 0;
1458 }
1459
1460 # ifdef HAVE_SYS_ACL_H
1461
1462 #  include <sys/acl.h>
1463
1464 static const struct xlat aclcmds[] = {
1465 #  ifdef SETACL
1466         { SETACL,       "SETACL"        },
1467 #  endif
1468 #  ifdef GETACL
1469         { GETACL,       "GETACL"        },
1470 #  endif
1471 #  ifdef GETACLCNT
1472         { GETACLCNT,    "GETACLCNT"     },
1473 #  endif
1474 #  ifdef ACL_GET
1475         { ACL_GET,      "ACL_GET"       },
1476 #  endif
1477 #  ifdef ACL_SET
1478         { ACL_SET,      "ACL_SET"       },
1479 #  endif
1480 #  ifdef ACL_CNT
1481         { ACL_CNT,      "ACL_CNT"       },
1482 #  endif
1483         { 0,            NULL            },
1484 };
1485
1486 int
1487 sys_acl(struct tcb *tcp)
1488 {
1489         if (entering(tcp)) {
1490                 printpath(tcp, tcp->u_arg[0]);
1491                 tprints(", ");
1492                 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1493                 tprintf(", %ld", tcp->u_arg[2]);
1494                 /*
1495                  * FIXME - dump out the list of aclent_t's pointed to
1496                  * by "tcp->u_arg[3]" if it's not NULL.
1497                  */
1498                 if (tcp->u_arg[3])
1499                         tprintf(", %#lx", tcp->u_arg[3]);
1500                 else
1501                         tprints(", NULL");
1502         }
1503         return 0;
1504 }
1505
1506
1507 int
1508 sys_facl(struct tcb *tcp)
1509 {
1510         if (entering(tcp)) {
1511                 tprintf("%ld, ", tcp->u_arg[0]);
1512                 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1513                 tprintf(", %ld", tcp->u_arg[2]);
1514                 /*
1515                  * FIXME - dump out the list of aclent_t's pointed to
1516                  * by "tcp->u_arg[3]" if it's not NULL.
1517                  */
1518                 if (tcp->u_arg[3])
1519                         tprintf(", %#lx", tcp->u_arg[3]);
1520                 else
1521                         tprints(", NULL");
1522         }
1523         return 0;
1524 }
1525
1526
1527 static const struct xlat aclipc[] = {
1528 #  ifdef IPC_SHM
1529         { IPC_SHM,      "IPC_SHM"       },
1530 #  endif
1531 #  ifdef IPC_SEM
1532         { IPC_SEM,      "IPC_SEM"       },
1533 #  endif
1534 #  ifdef IPC_MSG
1535         { IPC_MSG,      "IPC_MSG"       },
1536 #  endif
1537         { 0,            NULL            },
1538 };
1539
1540
1541 int
1542 sys_aclipc(struct tcb *tcp)
1543 {
1544         if (entering(tcp)) {
1545                 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1546                 tprintf(", %#lx, ", tcp->u_arg[1]);
1547                 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1548                 tprintf(", %ld", tcp->u_arg[3]);
1549                 /*
1550                  * FIXME - dump out the list of aclent_t's pointed to
1551                  * by "tcp->u_arg[4]" if it's not NULL.
1552                  */
1553                 if (tcp->u_arg[4])
1554                         tprintf(", %#lx", tcp->u_arg[4]);
1555                 else
1556                         tprints(", NULL");
1557         }
1558         return 0;
1559 }
1560
1561 # endif /* HAVE_SYS_ACL_H */
1562
1563 #endif /* LINUXSPARC */
1564
1565
1566 static const struct xlat fsmagic[] = {
1567         { 0x73757245,   "CODA_SUPER_MAGIC"      },
1568         { 0x012ff7b7,   "COH_SUPER_MAGIC"       },
1569         { 0x1373,       "DEVFS_SUPER_MAGIC"     },
1570         { 0x1cd1,       "DEVPTS_SUPER_MAGIC"    },
1571         { 0x414A53,     "EFS_SUPER_MAGIC"       },
1572         { 0xef51,       "EXT2_OLD_SUPER_MAGIC"  },
1573         { 0xef53,       "EXT2_SUPER_MAGIC"      },
1574         { 0x137d,       "EXT_SUPER_MAGIC"       },
1575         { 0xf995e849,   "HPFS_SUPER_MAGIC"      },
1576         { 0x9660,       "ISOFS_SUPER_MAGIC"     },
1577         { 0x137f,       "MINIX_SUPER_MAGIC"     },
1578         { 0x138f,       "MINIX_SUPER_MAGIC2"    },
1579         { 0x2468,       "MINIX2_SUPER_MAGIC"    },
1580         { 0x2478,       "MINIX2_SUPER_MAGIC2"   },
1581         { 0x4d44,       "MSDOS_SUPER_MAGIC"     },
1582         { 0x564c,       "NCP_SUPER_MAGIC"       },
1583         { 0x6969,       "NFS_SUPER_MAGIC"       },
1584         { 0x9fa0,       "PROC_SUPER_MAGIC"      },
1585         { 0x002f,       "QNX4_SUPER_MAGIC"      },
1586         { 0x52654973,   "REISERFS_SUPER_MAGIC"  },
1587         { 0x02011994,   "SHMFS_SUPER_MAGIC"     },
1588         { 0x517b,       "SMB_SUPER_MAGIC"       },
1589         { 0x012ff7b6,   "SYSV2_SUPER_MAGIC"     },
1590         { 0x012ff7b5,   "SYSV4_SUPER_MAGIC"     },
1591         { 0x00011954,   "UFS_MAGIC"             },
1592         { 0x54190100,   "UFS_CIGAM"             },
1593         { 0x012ff7b4,   "XENIX_SUPER_MAGIC"     },
1594         { 0x012fd16d,   "XIAFS_SUPER_MAGIC"     },
1595         { 0x62656572,   "SYSFS_MAGIC"           },
1596         { 0,            NULL                    },
1597 };
1598
1599
1600
1601 static const char *
1602 sprintfstype(int magic)
1603 {
1604         static char buf[32];
1605         const char *s;
1606
1607         s = xlookup(fsmagic, magic);
1608         if (s) {
1609                 sprintf(buf, "\"%s\"", s);
1610                 return buf;
1611         }
1612         sprintf(buf, "%#x", magic);
1613         return buf;
1614 }
1615
1616 static void
1617 printstatfs(struct tcb *tcp, long addr)
1618 {
1619         struct statfs statbuf;
1620
1621         if (syserror(tcp) || !verbose(tcp)) {
1622                 tprintf("%#lx", addr);
1623                 return;
1624         }
1625         if (umove(tcp, addr, &statbuf) < 0) {
1626                 tprints("{...}");
1627                 return;
1628         }
1629 #ifdef ALPHA
1630
1631         tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1632                 sprintfstype(statbuf.f_type),
1633                 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1634         tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1635                 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
1636                 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1637                 statbuf.f_namelen);
1638 #else /* !ALPHA */
1639         tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1640                 sprintfstype(statbuf.f_type),
1641                 (unsigned long)statbuf.f_bsize,
1642                 (unsigned long)statbuf.f_blocks,
1643                 (unsigned long)statbuf.f_bfree);
1644         tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1645                 (unsigned long)statbuf.f_bavail,
1646                 (unsigned long)statbuf.f_files,
1647                 (unsigned long)statbuf.f_ffree,
1648                 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1649         tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1650 #endif /* !ALPHA */
1651 #ifdef _STATFS_F_FRSIZE
1652         tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1653 #endif
1654         tprints("}");
1655 }
1656
1657 int
1658 sys_statfs(struct tcb *tcp)
1659 {
1660         if (entering(tcp)) {
1661                 printpath(tcp, tcp->u_arg[0]);
1662                 tprints(", ");
1663         } else {
1664                 printstatfs(tcp, tcp->u_arg[1]);
1665         }
1666         return 0;
1667 }
1668
1669 int
1670 sys_fstatfs(struct tcb *tcp)
1671 {
1672         if (entering(tcp)) {
1673                 printfd(tcp, tcp->u_arg[0]);
1674                 tprints(", ");
1675         } else {
1676                 printstatfs(tcp, tcp->u_arg[1]);
1677         }
1678         return 0;
1679 }
1680
1681 #if defined HAVE_STATFS64
1682 static void
1683 printstatfs64(struct tcb *tcp, long addr)
1684 {
1685         struct statfs64 statbuf;
1686
1687         if (syserror(tcp) || !verbose(tcp)) {
1688                 tprintf("%#lx", addr);
1689                 return;
1690         }
1691         if (umove(tcp, addr, &statbuf) < 0) {
1692                 tprints("{...}");
1693                 return;
1694         }
1695         tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
1696                 sprintfstype(statbuf.f_type),
1697                 (unsigned long long)statbuf.f_bsize,
1698                 (unsigned long long)statbuf.f_blocks,
1699                 (unsigned long long)statbuf.f_bfree);
1700         tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1701                 (unsigned long long)statbuf.f_bavail,
1702                 (unsigned long long)statbuf.f_files,
1703                 (unsigned long long)statbuf.f_ffree,
1704                 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1705         tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1706 #ifdef _STATFS_F_FRSIZE
1707         tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
1708 #endif
1709 #ifdef _STATFS_F_FLAGS
1710         tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1711 #endif
1712         tprints("}");
1713 }
1714
1715 struct compat_statfs64 {
1716         uint32_t f_type;
1717         uint32_t f_bsize;
1718         uint64_t f_blocks;
1719         uint64_t f_bfree;
1720         uint64_t f_bavail;
1721         uint64_t f_files;
1722         uint64_t f_ffree;
1723         fsid_t f_fsid;
1724         uint32_t f_namelen;
1725         uint32_t f_frsize;
1726         uint32_t f_flags;
1727         uint32_t f_spare[4];
1728 }
1729 #if defined(X86_64) || defined(IA64)
1730   __attribute__ ((packed, aligned(4)))
1731 #endif
1732 ;
1733
1734 static void
1735 printcompat_statfs64(struct tcb *tcp, long addr)
1736 {
1737         struct compat_statfs64 statbuf;
1738
1739         if (syserror(tcp) || !verbose(tcp)) {
1740                 tprintf("%#lx", addr);
1741                 return;
1742         }
1743         if (umove(tcp, addr, &statbuf) < 0) {
1744                 tprints("{...}");
1745                 return;
1746         }
1747         tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1748                 sprintfstype(statbuf.f_type),
1749                 (unsigned long)statbuf.f_bsize,
1750                 (unsigned long long)statbuf.f_blocks,
1751                 (unsigned long long)statbuf.f_bfree);
1752         tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1753                 (unsigned long long)statbuf.f_bavail,
1754                 (unsigned long long)statbuf.f_files,
1755                 (unsigned long long)statbuf.f_ffree,
1756                 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1757         tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1758         tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1759         tprintf(", f_flags=%lu", (unsigned long)statbuf.f_frsize);
1760         tprints("}");
1761 }
1762
1763 int
1764 sys_statfs64(struct tcb *tcp)
1765 {
1766         if (entering(tcp)) {
1767                 printpath(tcp, tcp->u_arg[0]);
1768                 tprintf(", %lu, ", tcp->u_arg[1]);
1769         } else {
1770                 if (tcp->u_arg[1] == sizeof(struct statfs64))
1771                         printstatfs64(tcp, tcp->u_arg[2]);
1772                 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1773                         printcompat_statfs64(tcp, tcp->u_arg[2]);
1774                 else
1775                         tprints("{???}");
1776         }
1777         return 0;
1778 }
1779
1780 int
1781 sys_fstatfs64(struct tcb *tcp)
1782 {
1783         if (entering(tcp)) {
1784                 printfd(tcp, tcp->u_arg[0]);
1785                 tprintf(", %lu, ", tcp->u_arg[1]);
1786         } else {
1787                 if (tcp->u_arg[1] == sizeof(struct statfs64))
1788                         printstatfs64(tcp, tcp->u_arg[2]);
1789                 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1790                         printcompat_statfs64(tcp, tcp->u_arg[2]);
1791                 else
1792                         tprints("{???}");
1793         }
1794         return 0;
1795 }
1796 #endif
1797
1798 #if defined(__alpha)
1799 int
1800 osf_statfs(struct tcb *tcp)
1801 {
1802         if (entering(tcp)) {
1803                 printpath(tcp, tcp->u_arg[0]);
1804                 tprints(", ");
1805         } else {
1806                 printstatfs(tcp, tcp->u_arg[1]);
1807                 tprintf(", %lu", tcp->u_arg[2]);
1808         }
1809         return 0;
1810 }
1811
1812 int
1813 osf_fstatfs(struct tcb *tcp)
1814 {
1815         if (entering(tcp)) {
1816                 tprintf("%lu, ", tcp->u_arg[0]);
1817         } else {
1818                 printstatfs(tcp, tcp->u_arg[1]);
1819                 tprintf(", %lu", tcp->u_arg[2]);
1820         }
1821         return 0;
1822 }
1823 #endif
1824
1825
1826 /* directory */
1827 int
1828 sys_chdir(struct tcb *tcp)
1829 {
1830         if (entering(tcp)) {
1831                 printpath(tcp, tcp->u_arg[0]);
1832         }
1833         return 0;
1834 }
1835
1836 static int
1837 decode_mkdir(struct tcb *tcp, int offset)
1838 {
1839         if (entering(tcp)) {
1840                 printpath(tcp, tcp->u_arg[offset]);
1841                 tprintf(", %#lo", tcp->u_arg[offset + 1]);
1842         }
1843         return 0;
1844 }
1845
1846 int
1847 sys_mkdir(struct tcb *tcp)
1848 {
1849         return decode_mkdir(tcp, 0);
1850 }
1851
1852 int
1853 sys_mkdirat(struct tcb *tcp)
1854 {
1855         if (entering(tcp))
1856                 print_dirfd(tcp, tcp->u_arg[0]);
1857         return decode_mkdir(tcp, 1);
1858 }
1859
1860 int
1861 sys_link(struct tcb *tcp)
1862 {
1863         if (entering(tcp)) {
1864                 printpath(tcp, tcp->u_arg[0]);
1865                 tprints(", ");
1866                 printpath(tcp, tcp->u_arg[1]);
1867         }
1868         return 0;
1869 }
1870
1871 int
1872 sys_linkat(struct tcb *tcp)
1873 {
1874         if (entering(tcp)) {
1875                 print_dirfd(tcp, tcp->u_arg[0]);
1876                 printpath(tcp, tcp->u_arg[1]);
1877                 tprints(", ");
1878                 print_dirfd(tcp, tcp->u_arg[2]);
1879                 printpath(tcp, tcp->u_arg[3]);
1880                 tprints(", ");
1881                 printfd(tcp, tcp->u_arg[4]);
1882         }
1883         return 0;
1884 }
1885
1886 static const struct xlat unlinkatflags[] = {
1887 #ifndef AT_REMOVEDIR
1888 # define AT_REMOVEDIR            0x200
1889 #endif
1890         { AT_REMOVEDIR, "AT_REMOVEDIR"  },
1891         { 0,            NULL            },
1892 };
1893
1894 int
1895 sys_unlinkat(struct tcb *tcp)
1896 {
1897         if (entering(tcp)) {
1898                 print_dirfd(tcp, tcp->u_arg[0]);
1899                 printpath(tcp, tcp->u_arg[1]);
1900                 tprints(", ");
1901                 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1902         }
1903         return 0;
1904 }
1905
1906 int
1907 sys_symlinkat(struct tcb *tcp)
1908 {
1909         if (entering(tcp)) {
1910                 printpath(tcp, tcp->u_arg[0]);
1911                 tprints(", ");
1912                 print_dirfd(tcp, tcp->u_arg[1]);
1913                 printpath(tcp, tcp->u_arg[2]);
1914         }
1915         return 0;
1916 }
1917
1918 static int
1919 decode_readlink(struct tcb *tcp, int offset)
1920 {
1921         if (entering(tcp)) {
1922                 printpath(tcp, tcp->u_arg[offset]);
1923                 tprints(", ");
1924         } else {
1925                 if (syserror(tcp))
1926                         tprintf("%#lx", tcp->u_arg[offset + 1]);
1927                 else
1928                         /* Used to use printpathn(), but readlink
1929                          * neither includes NUL in the returned count,
1930                          * nor actually writes it into memory.
1931                          * printpathn() would decide on printing
1932                          * "..." continuation based on garbage
1933                          * past return buffer's end.
1934                          */
1935                         printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1936                 tprintf(", %lu", tcp->u_arg[offset + 2]);
1937         }
1938         return 0;
1939 }
1940
1941 int
1942 sys_readlink(struct tcb *tcp)
1943 {
1944         return decode_readlink(tcp, 0);
1945 }
1946
1947 int
1948 sys_readlinkat(struct tcb *tcp)
1949 {
1950         if (entering(tcp))
1951                 print_dirfd(tcp, tcp->u_arg[0]);
1952         return decode_readlink(tcp, 1);
1953 }
1954
1955 int
1956 sys_renameat(struct tcb *tcp)
1957 {
1958         if (entering(tcp)) {
1959                 print_dirfd(tcp, tcp->u_arg[0]);
1960                 printpath(tcp, tcp->u_arg[1]);
1961                 tprints(", ");
1962                 print_dirfd(tcp, tcp->u_arg[2]);
1963                 printpath(tcp, tcp->u_arg[3]);
1964         }
1965         return 0;
1966 }
1967
1968 int
1969 sys_chown(struct tcb *tcp)
1970 {
1971         if (entering(tcp)) {
1972                 printpath(tcp, tcp->u_arg[0]);
1973                 printuid(", ", tcp->u_arg[1]);
1974                 printuid(", ", tcp->u_arg[2]);
1975         }
1976         return 0;
1977 }
1978
1979 int
1980 sys_fchownat(struct tcb *tcp)
1981 {
1982         if (entering(tcp)) {
1983                 print_dirfd(tcp, tcp->u_arg[0]);
1984                 printpath(tcp, tcp->u_arg[1]);
1985                 printuid(", ", tcp->u_arg[2]);
1986                 printuid(", ", tcp->u_arg[3]);
1987                 tprints(", ");
1988                 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
1989         }
1990         return 0;
1991 }
1992
1993 int
1994 sys_fchown(struct tcb *tcp)
1995 {
1996         if (entering(tcp)) {
1997                 printfd(tcp, tcp->u_arg[0]);
1998                 printuid(", ", tcp->u_arg[1]);
1999                 printuid(", ", tcp->u_arg[2]);
2000         }
2001         return 0;
2002 }
2003
2004 static int
2005 decode_chmod(struct tcb *tcp, int offset)
2006 {
2007         if (entering(tcp)) {
2008                 printpath(tcp, tcp->u_arg[offset]);
2009                 tprintf(", %#lo", tcp->u_arg[offset + 1]);
2010         }
2011         return 0;
2012 }
2013
2014 int
2015 sys_chmod(struct tcb *tcp)
2016 {
2017         return decode_chmod(tcp, 0);
2018 }
2019
2020 int
2021 sys_fchmodat(struct tcb *tcp)
2022 {
2023         if (entering(tcp))
2024                 print_dirfd(tcp, tcp->u_arg[0]);
2025         return decode_chmod(tcp, 1);
2026 }
2027
2028 int
2029 sys_fchmod(struct tcb *tcp)
2030 {
2031         if (entering(tcp)) {
2032                 printfd(tcp, tcp->u_arg[0]);
2033                 tprintf(", %#lo", tcp->u_arg[1]);
2034         }
2035         return 0;
2036 }
2037
2038 #ifdef ALPHA
2039 int
2040 sys_osf_utimes(struct tcb *tcp)
2041 {
2042         if (entering(tcp)) {
2043                 printpath(tcp, tcp->u_arg[0]);
2044                 tprints(", ");
2045                 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32,  0);
2046         }
2047         return 0;
2048 }
2049 #endif
2050
2051 static int
2052 decode_utimes(struct tcb *tcp, int offset, int special)
2053 {
2054         if (entering(tcp)) {
2055                 printpath(tcp, tcp->u_arg[offset]);
2056                 tprints(", ");
2057                 if (tcp->u_arg[offset + 1] == 0)
2058                         tprints("NULL");
2059                 else {
2060                         tprints("{");
2061                         printtv_bitness(tcp, tcp->u_arg[offset + 1],
2062                                         BITNESS_CURRENT, special);
2063                         tprints(", ");
2064                         printtv_bitness(tcp, tcp->u_arg[offset + 1]
2065                                         + sizeof(struct timeval),
2066                                         BITNESS_CURRENT, special);
2067                         tprints("}");
2068                 }
2069         }
2070         return 0;
2071 }
2072
2073 int
2074 sys_utimes(struct tcb *tcp)
2075 {
2076         return decode_utimes(tcp, 0, 0);
2077 }
2078
2079 int
2080 sys_futimesat(struct tcb *tcp)
2081 {
2082         if (entering(tcp))
2083                 print_dirfd(tcp, tcp->u_arg[0]);
2084         return decode_utimes(tcp, 1, 0);
2085 }
2086
2087 int
2088 sys_utimensat(struct tcb *tcp)
2089 {
2090         if (entering(tcp)) {
2091                 print_dirfd(tcp, tcp->u_arg[0]);
2092                 decode_utimes(tcp, 1, 1);
2093                 tprints(", ");
2094                 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2095         }
2096         return 0;
2097 }
2098
2099 int
2100 sys_utime(struct tcb *tcp)
2101 {
2102         union {
2103                 long utl[2];
2104                 int uti[2];
2105         } u;
2106
2107         if (entering(tcp)) {
2108                 printpath(tcp, tcp->u_arg[0]);
2109                 tprints(", ");
2110                 if (!tcp->u_arg[1])
2111                         tprints("NULL");
2112                 else if (!verbose(tcp))
2113                         tprintf("%#lx", tcp->u_arg[1]);
2114                 else if (umoven(tcp, tcp->u_arg[1],
2115                                 2 * personality_wordsize[current_personality],
2116                                 (char *) &u) < 0)
2117                         tprints("[?, ?]");
2118                 else if (personality_wordsize[current_personality]
2119                          == sizeof u.utl[0]) {
2120                         tprintf("[%s,", sprinttime(u.utl[0]));
2121                         tprintf(" %s]", sprinttime(u.utl[1]));
2122                 }
2123                 else if (personality_wordsize[current_personality]
2124                          == sizeof u.uti[0]) {
2125                         tprintf("[%s,", sprinttime(u.uti[0]));
2126                         tprintf(" %s]", sprinttime(u.uti[1]));
2127                 }
2128                 else
2129                         abort();
2130         }
2131         return 0;
2132 }
2133
2134 static int
2135 decode_mknod(struct tcb *tcp, int offset)
2136 {
2137         int mode = tcp->u_arg[offset + 1];
2138
2139         if (entering(tcp)) {
2140                 printpath(tcp, tcp->u_arg[offset]);
2141                 tprintf(", %s", sprintmode(mode));
2142                 switch (mode & S_IFMT) {
2143                 case S_IFCHR: case S_IFBLK:
2144 #ifdef LINUXSPARC
2145                         if (current_personality == 1)
2146                         tprintf(", makedev(%lu, %lu)",
2147                                 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2148                                 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
2149                         else
2150 #endif
2151                         tprintf(", makedev(%lu, %lu)",
2152                                 (unsigned long) major(tcp->u_arg[offset + 2]),
2153                                 (unsigned long) minor(tcp->u_arg[offset + 2]));
2154                         break;
2155                 default:
2156                         break;
2157                 }
2158         }
2159         return 0;
2160 }
2161
2162 int
2163 sys_mknod(struct tcb *tcp)
2164 {
2165         return decode_mknod(tcp, 0);
2166 }
2167
2168 int
2169 sys_mknodat(struct tcb *tcp)
2170 {
2171         if (entering(tcp))
2172                 print_dirfd(tcp, tcp->u_arg[0]);
2173         return decode_mknod(tcp, 1);
2174 }
2175
2176
2177 int
2178 sys_fsync(struct tcb *tcp)
2179 {
2180         if (entering(tcp)) {
2181                 printfd(tcp, tcp->u_arg[0]);
2182         }
2183         return 0;
2184 }
2185
2186
2187 static void
2188 printdir(struct tcb *tcp, long addr)
2189 {
2190         struct dirent d;
2191
2192         if (!verbose(tcp)) {
2193                 tprintf("%#lx", addr);
2194                 return;
2195         }
2196         if (umove(tcp, addr, &d) < 0) {
2197                 tprints("{...}");
2198                 return;
2199         }
2200         tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
2201         tprints("d_name=");
2202         printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2203         tprints("}");
2204 }
2205
2206 int
2207 sys_readdir(struct tcb *tcp)
2208 {
2209         if (entering(tcp)) {
2210                 printfd(tcp, tcp->u_arg[0]);
2211                 tprints(", ");
2212         } else {
2213                 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2214                         tprintf("%#lx", tcp->u_arg[1]);
2215                 else
2216                         printdir(tcp, tcp->u_arg[1]);
2217                 /* Not much point in printing this out, it is always 1. */
2218                 if (tcp->u_arg[2] != 1)
2219                         tprintf(", %lu", tcp->u_arg[2]);
2220         }
2221         return 0;
2222 }
2223
2224
2225 static const struct xlat direnttypes[] = {
2226         { DT_UNKNOWN,   "DT_UNKNOWN"    },
2227         { DT_FIFO,      "DT_FIFO"       },
2228         { DT_CHR,       "DT_CHR"        },
2229         { DT_DIR,       "DT_DIR"        },
2230         { DT_BLK,       "DT_BLK"        },
2231         { DT_REG,       "DT_REG"        },
2232         { DT_LNK,       "DT_LNK"        },
2233         { DT_SOCK,      "DT_SOCK"       },
2234         { DT_WHT,       "DT_WHT"        },
2235         { 0,            NULL            },
2236 };
2237
2238
2239 int
2240 sys_getdents(struct tcb *tcp)
2241 {
2242         int i, len, dents = 0;
2243         char *buf;
2244
2245         if (entering(tcp)) {
2246                 printfd(tcp, tcp->u_arg[0]);
2247                 tprints(", ");
2248                 return 0;
2249         }
2250         if (syserror(tcp) || !verbose(tcp)) {
2251                 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2252                 return 0;
2253         }
2254         len = tcp->u_rval;
2255         /* Beware of insanely large or negative values in tcp->u_rval */
2256         if (tcp->u_rval > 1024*1024)
2257                 len = 1024*1024;
2258         if (tcp->u_rval < 0)
2259                 len = 0;
2260         buf = len ? malloc(len) : NULL;
2261         if (len && !buf)
2262                 die_out_of_memory();
2263         if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2264                 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2265                 free(buf);
2266                 return 0;
2267         }
2268         if (!abbrev(tcp))
2269                 tprints("{");
2270         for (i = 0; i < len;) {
2271                 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2272                 if (!abbrev(tcp)) {
2273                         tprintf("%s{d_ino=%lu, d_off=%lu, ",
2274                                 i ? " " : "", d->d_ino, d->d_off);
2275                         tprintf("d_reclen=%u, d_name=\"%s\"}",
2276                                 d->d_reclen, d->d_name);
2277                 }
2278                 if (!d->d_reclen) {
2279                         tprints("/* d_reclen == 0, problem here */");
2280                         break;
2281                 }
2282                 i += d->d_reclen;
2283                 dents++;
2284         }
2285         if (!abbrev(tcp))
2286                 tprints("}");
2287         else
2288                 tprintf("/* %u entries */", dents);
2289         tprintf(", %lu", tcp->u_arg[2]);
2290         free(buf);
2291         return 0;
2292 }
2293
2294
2295 #if _LFS64_LARGEFILE
2296 int
2297 sys_getdents64(struct tcb *tcp)
2298 {
2299         int i, len, dents = 0;
2300         char *buf;
2301
2302         if (entering(tcp)) {
2303                 printfd(tcp, tcp->u_arg[0]);
2304                 tprints(", ");
2305                 return 0;
2306         }
2307         if (syserror(tcp) || !verbose(tcp)) {
2308                 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2309                 return 0;
2310         }
2311
2312         len = tcp->u_rval;
2313         /* Beware of insanely large or negative tcp->u_rval */
2314         if (tcp->u_rval > 1024*1024)
2315                 len = 1024*1024;
2316         if (tcp->u_rval < 0)
2317                 len = 0;
2318         buf = len ? malloc(len) : NULL;
2319         if (len && !buf)
2320                 die_out_of_memory();
2321
2322         if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2323                 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2324                 free(buf);
2325                 return 0;
2326         }
2327         if (!abbrev(tcp))
2328                 tprints("{");
2329         for (i = 0; i < len;) {
2330                 struct dirent64 *d = (struct dirent64 *) &buf[i];
2331                 if (!abbrev(tcp)) {
2332                         tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
2333                                 i ? " " : "",
2334                                 d->d_ino,
2335                                 d->d_off);
2336                         tprints("d_type=");
2337                         printxval(direnttypes, d->d_type, "DT_???");
2338                         tprints(", ");
2339                         tprintf("d_reclen=%u, d_name=\"%s\"}",
2340                                 d->d_reclen, d->d_name);
2341                 }
2342                 if (!d->d_reclen) {
2343                         tprints("/* d_reclen == 0, problem here */");
2344                         break;
2345                 }
2346                 i += d->d_reclen;
2347                 dents++;
2348         }
2349         if (!abbrev(tcp))
2350                 tprints("}");
2351         else
2352                 tprintf("/* %u entries */", dents);
2353         tprintf(", %lu", tcp->u_arg[2]);
2354         free(buf);
2355         return 0;
2356 }
2357 #endif
2358
2359
2360 int
2361 sys_getcwd(struct tcb *tcp)
2362 {
2363         if (exiting(tcp)) {
2364                 if (syserror(tcp))
2365                         tprintf("%#lx", tcp->u_arg[0]);
2366                 else
2367                         printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2368                 tprintf(", %lu", tcp->u_arg[1]);
2369         }
2370         return 0;
2371 }
2372
2373
2374 #ifdef HAVE_SYS_ASYNCH_H
2375
2376 int
2377 sys_aioread(struct tcb *tcp)
2378 {
2379         struct aio_result_t res;
2380
2381         if (entering(tcp)) {
2382                 tprintf("%lu, ", tcp->u_arg[0]);
2383         } else {
2384                 if (syserror(tcp))
2385                         tprintf("%#lx", tcp->u_arg[1]);
2386                 else
2387                         printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2388                 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2389                 printxval(whence, tcp->u_arg[4], "L_???");
2390                 if (syserror(tcp) || tcp->u_arg[5] == 0
2391                     || umove(tcp, tcp->u_arg[5], &res) < 0)
2392                         tprintf(", %#lx", tcp->u_arg[5]);
2393                 else
2394                         tprintf(", {aio_return %d aio_errno %d}",
2395                                 res.aio_return, res.aio_errno);
2396         }
2397         return 0;
2398 }
2399
2400 int
2401 sys_aiowrite(struct tcb *tcp)
2402 {
2403         struct aio_result_t res;
2404
2405         if (entering(tcp)) {
2406                 tprintf("%lu, ", tcp->u_arg[0]);
2407                 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2408                 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2409                 printxval(whence, tcp->u_arg[4], "L_???");
2410         }
2411         else {
2412                 if (tcp->u_arg[5] == 0)
2413                         tprints(", NULL");
2414                 else if (syserror(tcp)
2415                     || umove(tcp, tcp->u_arg[5], &res) < 0)
2416                         tprintf(", %#lx", tcp->u_arg[5]);
2417                 else
2418                         tprintf(", {aio_return %d aio_errno %d}",
2419                                 res.aio_return, res.aio_errno);
2420         }
2421         return 0;
2422 }
2423
2424 int
2425 sys_aiowait(struct tcb *tcp)
2426 {
2427         if (entering(tcp))
2428                 printtv(tcp, tcp->u_arg[0]);
2429         return 0;
2430 }
2431
2432 int
2433 sys_aiocancel(struct tcb *tcp)
2434 {
2435         struct aio_result_t res;
2436
2437         if (exiting(tcp)) {
2438                 if (tcp->u_arg[0] == 0)
2439                         tprints("NULL");
2440                 else if (syserror(tcp)
2441                     || umove(tcp, tcp->u_arg[0], &res) < 0)
2442                         tprintf("%#lx", tcp->u_arg[0]);
2443                 else
2444                         tprintf("{aio_return %d aio_errno %d}",
2445                                 res.aio_return, res.aio_errno);
2446         }
2447         return 0;
2448 }
2449
2450 #endif /* HAVE_SYS_ASYNCH_H */
2451
2452 static const struct xlat xattrflags[] = {
2453 #ifdef XATTR_CREATE
2454         { XATTR_CREATE,  "XATTR_CREATE" },
2455         { XATTR_REPLACE, "XATTR_REPLACE" },
2456 #endif
2457         { 0,             NULL }
2458 };
2459
2460 static void
2461 print_xattr_val(struct tcb *tcp, int failed,
2462                 unsigned long arg,
2463                 unsigned long insize,
2464                 unsigned long size)
2465 {
2466         if (!failed) {
2467                 unsigned long capacity = 4 * size + 1;
2468                 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2469                 if (buf == NULL || /* probably a bogus size argument */
2470                         umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2471                         failed = 1;
2472                 }
2473                 else {
2474                         unsigned char *out = buf;
2475                         unsigned char *in = &buf[3 * size];
2476                         size_t i;
2477                         for (i = 0; i < size; ++i) {
2478                                 if (isprint(in[i]))
2479                                         *out++ = in[i];
2480                                 else {
2481 #define tohex(n) "0123456789abcdef"[n]
2482                                         *out++ = '\\';
2483                                         *out++ = 'x';
2484                                         *out++ = tohex(in[i] / 16);
2485                                         *out++ = tohex(in[i] % 16);
2486                                 }
2487                         }
2488                         /* Don't print terminating NUL if there is one.  */
2489                         if (i > 0 && in[i - 1] == '\0')
2490                                 out -= 4;
2491                         *out = '\0';
2492                         tprintf(", \"%s\", %ld", buf, insize);
2493                 }
2494                 free(buf);
2495         }
2496         if (failed)
2497                 tprintf(", 0x%lx, %ld", arg, insize);
2498 }
2499
2500 int
2501 sys_setxattr(struct tcb *tcp)
2502 {
2503         if (entering(tcp)) {
2504                 printpath(tcp, tcp->u_arg[0]);
2505                 tprints(", ");
2506                 printstr(tcp, tcp->u_arg[1], -1);
2507                 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2508                 tprints(", ");
2509                 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2510         }
2511         return 0;
2512 }
2513
2514 int
2515 sys_fsetxattr(struct tcb *tcp)
2516 {
2517         if (entering(tcp)) {
2518                 printfd(tcp, tcp->u_arg[0]);
2519                 tprints(", ");
2520                 printstr(tcp, tcp->u_arg[1], -1);
2521                 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2522                 tprints(", ");
2523                 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2524         }
2525         return 0;
2526 }
2527
2528 int
2529 sys_getxattr(struct tcb *tcp)
2530 {
2531         if (entering(tcp)) {
2532                 printpath(tcp, tcp->u_arg[0]);
2533                 tprints(", ");
2534                 printstr(tcp, tcp->u_arg[1], -1);
2535         } else {
2536                 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2537                                 tcp->u_rval);
2538         }
2539         return 0;
2540 }
2541
2542 int
2543 sys_fgetxattr(struct tcb *tcp)
2544 {
2545         if (entering(tcp)) {
2546                 printfd(tcp, tcp->u_arg[0]);
2547                 tprints(", ");
2548                 printstr(tcp, tcp->u_arg[1], -1);
2549         } else {
2550                 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2551                                 tcp->u_rval);
2552         }
2553         return 0;
2554 }
2555
2556 int
2557 sys_listxattr(struct tcb *tcp)
2558 {
2559         if (entering(tcp)) {
2560                 printpath(tcp, tcp->u_arg[0]);
2561         } else {
2562                 /* XXX Print value in format */
2563                 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2564         }
2565         return 0;
2566 }
2567
2568 int
2569 sys_flistxattr(struct tcb *tcp)
2570 {
2571         if (entering(tcp)) {
2572                 printfd(tcp, tcp->u_arg[0]);
2573         } else {
2574                 /* XXX Print value in format */
2575                 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2576         }
2577         return 0;
2578 }
2579
2580 int
2581 sys_removexattr(struct tcb *tcp)
2582 {
2583         if (entering(tcp)) {
2584                 printpath(tcp, tcp->u_arg[0]);
2585                 tprints(", ");
2586                 printstr(tcp, tcp->u_arg[1], -1);
2587         }
2588         return 0;
2589 }
2590
2591 int
2592 sys_fremovexattr(struct tcb *tcp)
2593 {
2594         if (entering(tcp)) {
2595                 printfd(tcp, tcp->u_arg[0]);
2596                 tprints(", ");
2597                 printstr(tcp, tcp->u_arg[1], -1);
2598         }
2599         return 0;
2600 }
2601
2602
2603 static const struct xlat advise[] = {
2604   { POSIX_FADV_NORMAL,          "POSIX_FADV_NORMAL"     },
2605   { POSIX_FADV_RANDOM,          "POSIX_FADV_RANDOM"     },
2606   { POSIX_FADV_SEQUENTIAL,      "POSIX_FADV_SEQUENTIAL" },
2607   { POSIX_FADV_WILLNEED,        "POSIX_FADV_WILLNEED"   },
2608   { POSIX_FADV_DONTNEED,        "POSIX_FADV_DONTNEED"   },
2609   { POSIX_FADV_NOREUSE,         "POSIX_FADV_NOREUSE"    },
2610   { 0,                          NULL                    }
2611 };
2612
2613
2614 int
2615 sys_fadvise64(struct tcb *tcp)
2616 {
2617         if (entering(tcp)) {
2618                 int argn;
2619                 printfd(tcp, tcp->u_arg[0]);
2620                 tprints(", ");
2621                 argn = printllval(tcp, "%lld", 1);
2622                 tprintf(", %ld, ", tcp->u_arg[argn++]);
2623                 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2624         }
2625         return 0;
2626 }
2627
2628
2629 int
2630 sys_fadvise64_64(struct tcb *tcp)
2631 {
2632         if (entering(tcp)) {
2633                 int argn;
2634                 printfd(tcp, tcp->u_arg[0]);
2635                 tprints(", ");
2636 #if defined ARM || defined POWERPC
2637                 argn = printllval(tcp, "%lld, ", 2);
2638 #else
2639                 argn = printllval(tcp, "%lld, ", 1);
2640 #endif
2641                 argn = printllval(tcp, "%lld, ", argn);
2642 #if defined ARM || defined POWERPC
2643                 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
2644 #else
2645                 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2646 #endif
2647         }
2648         return 0;
2649 }
2650
2651 static const struct xlat inotify_modes[] = {
2652         { 0x00000001,   "IN_ACCESS"     },
2653         { 0x00000002,   "IN_MODIFY"     },
2654         { 0x00000004,   "IN_ATTRIB"     },
2655         { 0x00000008,   "IN_CLOSE_WRITE"},
2656         { 0x00000010,   "IN_CLOSE_NOWRITE"},
2657         { 0x00000020,   "IN_OPEN"       },
2658         { 0x00000040,   "IN_MOVED_FROM" },
2659         { 0x00000080,   "IN_MOVED_TO"   },
2660         { 0x00000100,   "IN_CREATE"     },
2661         { 0x00000200,   "IN_DELETE"     },
2662         { 0x00000400,   "IN_DELETE_SELF"},
2663         { 0x00000800,   "IN_MOVE_SELF"  },
2664         { 0x00002000,   "IN_UNMOUNT"    },
2665         { 0x00004000,   "IN_Q_OVERFLOW" },
2666         { 0x00008000,   "IN_IGNORED"    },
2667         { 0x01000000,   "IN_ONLYDIR"    },
2668         { 0x02000000,   "IN_DONT_FOLLOW"},
2669         { 0x20000000,   "IN_MASK_ADD"   },
2670         { 0x40000000,   "IN_ISDIR"      },
2671         { 0x80000000,   "IN_ONESHOT"    },
2672         { 0,            NULL            }
2673 };
2674
2675 static const struct xlat inotify_init_flags[] = {
2676         { 0x00000800,   "IN_NONBLOCK"   },
2677         { 0x00080000,   "IN_CLOEXEC"    },
2678         { 0,            NULL            }
2679 };
2680
2681 int
2682 sys_inotify_add_watch(struct tcb *tcp)
2683 {
2684         if (entering(tcp)) {
2685                 printfd(tcp, tcp->u_arg[0]);
2686                 tprints(", ");
2687                 printpath(tcp, tcp->u_arg[1]);
2688                 tprints(", ");
2689                 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2690         }
2691         return 0;
2692 }
2693
2694 int
2695 sys_inotify_rm_watch(struct tcb *tcp)
2696 {
2697         if (entering(tcp)) {
2698                 printfd(tcp, tcp->u_arg[0]);
2699                 tprintf(", %ld", tcp->u_arg[1]);
2700         }
2701         return 0;
2702 }
2703
2704 int
2705 sys_inotify_init1(struct tcb *tcp)
2706 {
2707         if (entering(tcp))
2708                 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
2709         return 0;
2710 }
2711
2712 int
2713 sys_fallocate(struct tcb *tcp)
2714 {
2715         if (entering(tcp)) {
2716                 int argn;
2717                 printfd(tcp, tcp->u_arg[0]);            /* fd */
2718                 tprints(", ");
2719                 tprintf("%#lo, ", tcp->u_arg[1]);       /* mode */
2720                 argn = printllval(tcp, "%llu, ", 2);    /* offset */
2721                 printllval(tcp, "%llu", argn);          /* len */
2722         }
2723         return 0;
2724 }