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>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
37 struct kernel_dirent {
40 unsigned short d_reclen;
46 unsigned short st_dev;
48 unsigned short st_mode;
50 unsigned short st_uid;
51 unsigned short st_gid;
52 unsigned short st_rdev;
55 unsigned int __unused1;
57 unsigned int __unused2;
59 unsigned int __unused3;
62 unsigned int __unused4[2];
69 unsigned int st_nlink;
79 unsigned long __unused4[2];
82 # define stat kernel_stat
83 # include <asm/stat.h>
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
104 # include <asm/stat.h>
117 # define mode_t mode_t
118 # define nlink_t nlink_t
122 # define loff_t loff_t
125 #ifdef HPPA /* asm-parisc/stat.h defines stat64 */
128 #define stat libc_stat
129 #define stat64 libc_stat64
130 #include <sys/stat.h>
133 /* These might be macros. */
138 # define stat64 hpux_stat64
143 #ifdef HAVE_SYS_VFS_H
144 # include <sys/vfs.h>
147 #ifdef HAVE_LINUX_XATTR_H
148 # include <linux/xattr.h>
150 # define XATTR_CREATE 1
151 # define XATTR_REPLACE 2
155 # ifdef HAVE_INTTYPES_H
156 # include <inttypes.h>
158 # define PRId64 "lld"
159 # define PRIu64 "llu"
163 #if HAVE_LONG_LONG_OFF_T
165 * Ugly hacks for systems that have typedef long long off_t
169 # define HAVE_STAT64 1 /* Ugly hack */
171 # define sys_stat64 sys_stat
172 # define sys_fstat64 sys_fstat
173 # define sys_lstat64 sys_lstat
174 # define sys_lseek64 sys_lseek
175 # define sys_truncate64 sys_truncate
176 # define sys_ftruncate64 sys_ftruncate
179 #ifdef MAJOR_IN_SYSMACROS
180 # include <sys/sysmacros.h>
183 #ifdef MAJOR_IN_MKDEV
184 # include <sys/mkdev.h>
187 #ifdef HAVE_SYS_ASYNCH_H
188 # include <sys/asynch.h>
191 const struct xlat open_access_modes[] = {
192 { O_RDONLY, "O_RDONLY" },
193 { O_WRONLY, "O_WRONLY" },
194 { O_RDWR, "O_RDWR" },
196 { O_ACCMODE, "O_ACCMODE" },
201 const struct xlat open_mode_flags[] = {
202 { O_CREAT, "O_CREAT" },
203 { O_EXCL, "O_EXCL" },
204 { O_NOCTTY, "O_NOCTTY" },
205 { O_TRUNC, "O_TRUNC" },
206 { O_APPEND, "O_APPEND" },
207 { O_NONBLOCK, "O_NONBLOCK" },
209 { O_SYNC, "O_SYNC" },
212 { O_ASYNC, "O_ASYNC" },
215 { O_DSYNC, "O_DSYNC" },
218 { O_RSYNC, "O_RSYNC" },
220 #if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
221 { O_NDELAY, "O_NDELAY" },
224 { O_PRIV, "O_PRIV" },
227 { O_DIRECT, "O_DIRECT" },
230 # if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
233 # define O_LARGEFILE 0x40000
234 # elif defined X86_64 || defined S390X
235 # define O_LARGEFILE 0100000
239 { O_LARGEFILE, "O_LARGEFILE" },
243 { O_DIRECTORY, "O_DIRECTORY" },
246 { O_NOFOLLOW, "O_NOFOLLOW" },
249 { O_NOATIME, "O_NOATIME" },
252 { O_CLOEXEC, "O_CLOEXEC" },
255 { FNDELAY, "FNDELAY" },
258 { FAPPEND, "FAPPEND" },
264 { FDEFER, "FDEFER" },
267 { FASYNC, "FASYNC" },
270 { FSHLOCK, "FSHLOCK" },
273 { FEXLOCK, "FEXLOCK" },
276 { FCREAT, "FCREAT" },
279 { FTRUNC, "FTRUNC" },
291 { FNOCTTY, "FNOCTTY" },
294 { O_SHLOCK, "O_SHLOCK" },
297 { O_EXLOCK, "O_EXLOCK" },
303 # define AT_FDCWD -100
306 /* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
307 * extension to get the right value. We do this by declaring fd as int here.
310 print_dirfd(struct tcb *tcp, int fd)
313 tprints("AT_FDCWD, ");
321 * low bits of the open(2) flags define access mode,
322 * other bits are real flags.
325 sprint_open_modes(mode_t flags)
327 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
331 const struct xlat *x;
334 p = stpcpy(outstr, "flags");
335 str = xlookup(open_access_modes, flags & 3);
345 for (x = open_mode_flags; x->str; x++) {
346 if ((flags & x->val) == x->val) {
348 p = stpcpy(p, x->str);
355 /* flags is still nonzero */
357 sprintf(p, "%#x", flags);
362 tprint_open_modes(mode_t flags)
364 tprints(sprint_open_modes(flags) + sizeof("flags"));
368 decode_open(struct tcb *tcp, int offset)
371 printpath(tcp, tcp->u_arg[offset]);
374 tprint_open_modes(tcp->u_arg[offset + 1]);
375 if (tcp->u_arg[offset + 1] & O_CREAT) {
377 tprintf(", %#lo", tcp->u_arg[offset + 2]);
384 sys_open(struct tcb *tcp)
386 return decode_open(tcp, 0);
390 sys_openat(struct tcb *tcp)
393 print_dirfd(tcp, tcp->u_arg[0]);
394 return decode_open(tcp, 1);
398 static const struct xlat openmodessol[] = {
402 { 0x80, "O_NONBLOCK" },
404 { 0x100, "O_CREAT" },
405 { 0x200, "O_TRUNC" },
407 { 0x800, "O_NOCTTY" },
410 { 0x8000, "O_RSYNC" },
412 { 0x1000, "O_PRIV" },
417 solaris_open(struct tcb *tcp)
420 printpath(tcp, tcp->u_arg[0]);
423 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
424 if (tcp->u_arg[1] & 0x100) {
426 tprintf(", %#lo", tcp->u_arg[2]);
435 sys_creat(struct tcb *tcp)
438 printpath(tcp, tcp->u_arg[0]);
439 tprintf(", %#lo", tcp->u_arg[1]);
444 static const struct xlat access_flags[] = {
450 { EFF_ONLY_OK, "EFF_ONLY_OK" },
459 decode_access(struct tcb *tcp, int offset)
462 printpath(tcp, tcp->u_arg[offset]);
464 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
470 sys_access(struct tcb *tcp)
472 return decode_access(tcp, 0);
476 sys_faccessat(struct tcb *tcp)
479 print_dirfd(tcp, tcp->u_arg[0]);
480 return decode_access(tcp, 1);
484 sys_umask(struct tcb *tcp)
487 tprintf("%#lo", tcp->u_arg[0]);
492 static const struct xlat whence[] = {
493 { SEEK_SET, "SEEK_SET" },
494 { SEEK_CUR, "SEEK_CUR" },
495 { SEEK_END, "SEEK_END" },
499 #ifndef HAVE_LONG_LONG_OFF_T
500 #if defined(LINUX_MIPSN32)
502 sys_lseek(struct tcb *tcp)
508 printfd(tcp, tcp->u_arg[0]);
510 offset = tcp->ext_arg[1];
511 _whence = tcp->u_arg[2];
512 if (_whence == SEEK_SET)
513 tprintf("%llu, ", offset);
515 tprintf("%lld, ", offset);
516 printxval(whence, _whence, "SEEK_???");
518 return RVAL_UDECIMAL;
520 #else /* !LINUX_MIPSN32 */
522 sys_lseek(struct tcb *tcp)
528 printfd(tcp, tcp->u_arg[0]);
530 offset = tcp->u_arg[1];
531 _whence = tcp->u_arg[2];
532 if (_whence == SEEK_SET)
533 tprintf("%lu, ", offset);
535 tprintf("%ld, ", offset);
536 printxval(whence, _whence, "SEEK_???");
538 return RVAL_UDECIMAL;
540 #endif /* LINUX_MIPSN32 */
544 sys_llseek(struct tcb *tcp)
547 printfd(tcp, tcp->u_arg[0]);
549 * This one call takes explicitly two 32-bit arguments hi, lo,
550 * rather than one 64-bit argument for which LONG_LONG works
551 * appropriate for the native byte order.
553 if (tcp->u_arg[4] == SEEK_SET)
555 ((long long int) tcp->u_arg[1]) << 32 |
556 (unsigned long long) (unsigned) tcp->u_arg[2]);
559 ((long long int) tcp->u_arg[1]) << 32 |
560 (unsigned long long) (unsigned) tcp->u_arg[2]);
564 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
565 tprintf("%#lx, ", tcp->u_arg[3]);
567 tprintf("[%llu], ", off);
568 printxval(whence, tcp->u_arg[4], "SEEK_???");
574 sys_readahead(struct tcb *tcp)
578 printfd(tcp, tcp->u_arg[0]);
580 argn = printllval(tcp, "%lld", 1);
581 tprintf(", %ld", tcp->u_arg[argn]);
586 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
588 sys_lseek64(struct tcb *tcp)
592 printfd(tcp, tcp->u_arg[0]);
594 if (tcp->u_arg[3] == SEEK_SET)
595 argn = printllval(tcp, "%llu, ", 1);
597 argn = printllval(tcp, "%lld, ", 1);
598 printxval(whence, tcp->u_arg[argn], "SEEK_???");
600 return RVAL_LUDECIMAL;
604 #ifndef HAVE_LONG_LONG_OFF_T
606 sys_truncate(struct tcb *tcp)
609 printpath(tcp, tcp->u_arg[0]);
610 tprintf(", %lu", tcp->u_arg[1]);
616 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
618 sys_truncate64(struct tcb *tcp)
621 printpath(tcp, tcp->u_arg[0]);
622 printllval(tcp, ", %llu", 1);
628 #ifndef HAVE_LONG_LONG_OFF_T
630 sys_ftruncate(struct tcb *tcp)
633 printfd(tcp, tcp->u_arg[0]);
634 tprintf(", %lu", tcp->u_arg[1]);
640 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
642 sys_ftruncate64(struct tcb *tcp)
645 printfd(tcp, tcp->u_arg[0]);
647 printllval(tcp, "%llu", 1);
655 static const struct xlat modetypes[] = {
656 { S_IFREG, "S_IFREG" },
657 { S_IFSOCK, "S_IFSOCK" },
658 { S_IFIFO, "S_IFIFO" },
659 { S_IFLNK, "S_IFLNK" },
660 { S_IFDIR, "S_IFDIR" },
661 { S_IFBLK, "S_IFBLK" },
662 { S_IFCHR, "S_IFCHR" },
669 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
674 if ((mode & S_IFMT) == 0)
676 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
677 sprintf(buf, "%#o", mode);
680 s = buf + sprintf(buf, "%s%s%s%s", s,
681 (mode & S_ISUID) ? "|S_ISUID" : "",
682 (mode & S_ISGID) ? "|S_ISGID" : "",
683 (mode & S_ISVTX) ? "|S_ISVTX" : "");
684 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
686 sprintf((char*)s, "|%#o", mode);
687 s = (*buf == '|') ? buf + 1 : buf;
695 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
703 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
704 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
705 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
707 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
720 int st_pad1[3]; /* network id */
729 int st_pad3; /* st_size, off_t expansion */
730 timestruct_t st_atime;
731 timestruct_t st_mtime;
732 timestruct_t st_ctime;
736 int st_pad4[8]; /* expansion area */
740 printstatsol(struct tcb *tcp, long addr)
742 struct solstat statbuf;
744 if (umove(tcp, addr, &statbuf) < 0) {
749 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
750 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
751 (unsigned long) (statbuf.st_dev & 0x3ffff),
752 (unsigned long) statbuf.st_ino,
753 sprintmode(statbuf.st_mode));
754 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
755 (unsigned long) statbuf.st_nlink,
756 (unsigned long) statbuf.st_uid,
757 (unsigned long) statbuf.st_gid);
758 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
759 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
762 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
763 switch (statbuf.st_mode & S_IFMT) {
764 case S_IFCHR: case S_IFBLK:
765 tprintf("st_rdev=makedev(%lu, %lu), ",
766 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
767 (unsigned long) (statbuf.st_rdev & 0x3ffff));
770 tprintf("st_size=%u, ", statbuf.st_size);
774 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
775 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
776 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
784 printstat_sparc64(struct tcb *tcp, long addr)
786 struct stat_sparc64 statbuf;
788 if (umove(tcp, addr, &statbuf) < 0) {
794 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
795 (unsigned long) major(statbuf.st_dev),
796 (unsigned long) minor(statbuf.st_dev),
797 (unsigned long) statbuf.st_ino,
798 sprintmode(statbuf.st_mode));
799 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
800 (unsigned long) statbuf.st_nlink,
801 (unsigned long) statbuf.st_uid,
802 (unsigned long) statbuf.st_gid);
803 tprintf("st_blksize=%lu, ",
804 (unsigned long) statbuf.st_blksize);
805 tprintf("st_blocks=%lu, ",
806 (unsigned long) statbuf.st_blocks);
809 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
810 switch (statbuf.st_mode & S_IFMT) {
811 case S_IFCHR: case S_IFBLK:
812 tprintf("st_rdev=makedev(%lu, %lu), ",
813 (unsigned long) major(statbuf.st_rdev),
814 (unsigned long) minor(statbuf.st_rdev));
817 tprintf("st_size=%lu, ", statbuf.st_size);
821 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
822 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
823 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
829 #endif /* LINUXSPARC */
831 #if defined POWERPC64
832 struct stat_powerpc32 {
835 unsigned int st_mode;
836 unsigned short st_nlink;
839 unsigned int st_rdev;
840 unsigned int st_size;
841 unsigned int st_blksize;
842 unsigned int st_blocks;
843 unsigned int st_atime;
844 unsigned int st_atime_nsec;
845 unsigned int st_mtime;
846 unsigned int st_mtime_nsec;
847 unsigned int st_ctime;
848 unsigned int st_ctime_nsec;
849 unsigned int __unused4;
850 unsigned int __unused5;
854 printstat_powerpc32(struct tcb *tcp, long addr)
856 struct stat_powerpc32 statbuf;
858 if (umove(tcp, addr, &statbuf) < 0) {
864 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
865 major(statbuf.st_dev), minor(statbuf.st_dev),
867 sprintmode(statbuf.st_mode));
868 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
869 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
870 tprintf("st_blksize=%u, ", statbuf.st_blksize);
871 tprintf("st_blocks=%u, ", statbuf.st_blocks);
874 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
875 switch (statbuf.st_mode & S_IFMT) {
876 case S_IFCHR: case S_IFBLK:
877 tprintf("st_rdev=makedev(%lu, %lu), ",
878 (unsigned long) major(statbuf.st_rdev),
879 (unsigned long) minor(statbuf.st_rdev));
882 tprintf("st_size=%u, ", statbuf.st_size);
886 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
887 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
888 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
893 #endif /* POWERPC64 */
895 static const struct xlat fileflags[] = {
899 #ifndef HAVE_LONG_LONG_OFF_T
901 realprintstat(struct tcb *tcp, struct stat *statbuf)
904 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
905 (unsigned long) major(statbuf->st_dev),
906 (unsigned long) minor(statbuf->st_dev),
907 (unsigned long) statbuf->st_ino,
908 sprintmode(statbuf->st_mode));
909 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
910 (unsigned long) statbuf->st_nlink,
911 (unsigned long) statbuf->st_uid,
912 (unsigned long) statbuf->st_gid);
913 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
914 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
916 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
917 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
921 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
922 switch (statbuf->st_mode & S_IFMT) {
923 case S_IFCHR: case S_IFBLK:
924 #ifdef HAVE_STRUCT_STAT_ST_RDEV
925 tprintf("st_rdev=makedev(%lu, %lu), ",
926 (unsigned long) major(statbuf->st_rdev),
927 (unsigned long) minor(statbuf->st_rdev));
928 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
929 tprintf("st_size=makedev(%lu, %lu), ",
930 (unsigned long) major(statbuf->st_size),
931 (unsigned long) minor(statbuf->st_size));
932 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
935 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
939 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
940 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
941 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
942 #if HAVE_STRUCT_STAT_ST_FLAGS
943 tprints(", st_flags=");
944 printflags(fileflags, statbuf->st_flags, "UF_???");
946 #if HAVE_STRUCT_STAT_ST_ACLCNT
947 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
949 #if HAVE_STRUCT_STAT_ST_LEVEL
950 tprintf(", st_level=%ld", statbuf->st_level);
952 #if HAVE_STRUCT_STAT_ST_FSTYPE
953 tprintf(", st_fstype=%.*s",
954 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
956 #if HAVE_STRUCT_STAT_ST_GEN
957 tprintf(", st_gen=%u", statbuf->st_gen);
966 printstat(struct tcb *tcp, long addr)
974 if (syserror(tcp) || !verbose(tcp)) {
975 tprintf("%#lx", addr);
980 if (current_personality == 1) {
981 printstatsol(tcp, addr);
985 else if (current_personality == 2) {
986 printstat_sparc64(tcp, addr);
990 #endif /* LINUXSPARC */
992 #if defined POWERPC64
993 if (current_personality == 1) {
994 printstat_powerpc32(tcp, addr);
999 if (umove(tcp, addr, &statbuf) < 0) {
1004 realprintstat(tcp, &statbuf);
1006 #endif /* !HAVE_LONG_LONG_OFF_T */
1008 #if !defined HAVE_STAT64 && defined X86_64
1010 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1011 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1012 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1013 * __GNUC__ is needed for the required __attribute__ below.
1016 unsigned long long st_dev;
1017 unsigned char __pad0[4];
1018 unsigned int __st_ino;
1019 unsigned int st_mode;
1020 unsigned int st_nlink;
1021 unsigned int st_uid;
1022 unsigned int st_gid;
1023 unsigned long long st_rdev;
1024 unsigned char __pad3[4];
1026 unsigned int st_blksize;
1027 unsigned long long st_blocks;
1028 unsigned int st_atime;
1029 unsigned int st_atime_nsec;
1030 unsigned int st_mtime;
1031 unsigned int st_mtime_nsec;
1032 unsigned int st_ctime;
1033 unsigned int st_ctime_nsec;
1034 unsigned long long st_ino;
1035 } __attribute__((packed));
1036 # define HAVE_STAT64 1
1037 # define STAT64_SIZE 96
1042 printstat64(struct tcb *tcp, long addr)
1044 struct stat64 statbuf;
1047 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1054 if (syserror(tcp) || !verbose(tcp)) {
1055 tprintf("%#lx", addr);
1060 if (current_personality == 1) {
1061 printstatsol(tcp, addr);
1065 else if (current_personality == 2) {
1066 printstat_sparc64(tcp, addr);
1070 #endif /* LINUXSPARC */
1073 if (current_personality == 0) {
1074 printstat(tcp, addr);
1079 if (umove(tcp, addr, &statbuf) < 0) {
1085 #ifdef HAVE_LONG_LONG
1086 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1088 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
1090 (unsigned long) major(statbuf.st_dev),
1091 (unsigned long) minor(statbuf.st_dev),
1092 #ifdef HAVE_LONG_LONG
1093 (unsigned long long) statbuf.st_ino,
1095 (unsigned long) statbuf.st_ino,
1097 sprintmode(statbuf.st_mode));
1098 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1099 (unsigned long) statbuf.st_nlink,
1100 (unsigned long) statbuf.st_uid,
1101 (unsigned long) statbuf.st_gid);
1102 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1103 tprintf("st_blksize=%lu, ",
1104 (unsigned long) statbuf.st_blksize);
1105 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1106 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
1107 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1108 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
1111 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1112 switch (statbuf.st_mode & S_IFMT) {
1113 case S_IFCHR: case S_IFBLK:
1114 #ifdef HAVE_STRUCT_STAT_ST_RDEV
1115 tprintf("st_rdev=makedev(%lu, %lu), ",
1116 (unsigned long) major(statbuf.st_rdev),
1117 (unsigned long) minor(statbuf.st_rdev));
1118 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
1119 tprintf("st_size=makedev(%lu, %lu), ",
1120 (unsigned long) major(statbuf.st_size),
1121 (unsigned long) minor(statbuf.st_size));
1122 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
1125 #ifdef HAVE_LONG_LONG
1126 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1128 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1133 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1134 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1135 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1136 #if HAVE_STRUCT_STAT_ST_FLAGS
1137 tprints(", st_flags=");
1138 printflags(fileflags, statbuf.st_flags, "UF_???");
1140 #if HAVE_STRUCT_STAT_ST_ACLCNT
1141 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1143 #if HAVE_STRUCT_STAT_ST_LEVEL
1144 tprintf(", st_level=%ld", statbuf.st_level);
1146 #if HAVE_STRUCT_STAT_ST_FSTYPE
1147 tprintf(", st_fstype=%.*s",
1148 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1150 #if HAVE_STRUCT_STAT_ST_GEN
1151 tprintf(", st_gen=%u", statbuf.st_gen);
1158 #endif /* HAVE_STAT64 */
1160 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1162 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
1164 newbuf->st_dev = oldbuf->st_dev;
1165 newbuf->st_ino = oldbuf->st_ino;
1166 newbuf->st_mode = oldbuf->st_mode;
1167 newbuf->st_nlink = oldbuf->st_nlink;
1168 newbuf->st_uid = oldbuf->st_uid;
1169 newbuf->st_gid = oldbuf->st_gid;
1170 newbuf->st_rdev = oldbuf->st_rdev;
1171 newbuf->st_size = oldbuf->st_size;
1172 newbuf->st_atime = oldbuf->st_atime;
1173 newbuf->st_mtime = oldbuf->st_mtime;
1174 newbuf->st_ctime = oldbuf->st_ctime;
1175 newbuf->st_blksize = 0; /* not supported in old_stat */
1176 newbuf->st_blocks = 0; /* not supported in old_stat */
1180 printoldstat(struct tcb *tcp, long addr)
1182 struct __old_kernel_stat statbuf;
1183 struct stat newstatbuf;
1189 if (syserror(tcp) || !verbose(tcp)) {
1190 tprintf("%#lx", addr);
1195 if (current_personality == 1) {
1196 printstatsol(tcp, addr);
1201 if (umove(tcp, addr, &statbuf) < 0) {
1206 convertoldstat(&statbuf, &newstatbuf);
1207 realprintstat(tcp, &newstatbuf);
1211 #ifndef HAVE_LONG_LONG_OFF_T
1213 sys_stat(struct tcb *tcp)
1215 if (entering(tcp)) {
1216 printpath(tcp, tcp->u_arg[0]);
1219 printstat(tcp, tcp->u_arg[1]);
1226 sys_stat64(struct tcb *tcp)
1229 if (entering(tcp)) {
1230 printpath(tcp, tcp->u_arg[0]);
1233 printstat64(tcp, tcp->u_arg[1]);
1237 return printargs(tcp);
1241 static const struct xlat fstatatflags[] = {
1242 #ifndef AT_SYMLINK_NOFOLLOW
1243 # define AT_SYMLINK_NOFOLLOW 0x100
1245 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1248 #define utimensatflags fstatatflags
1251 sys_newfstatat(struct tcb *tcp)
1253 if (entering(tcp)) {
1254 print_dirfd(tcp, tcp->u_arg[0]);
1255 printpath(tcp, tcp->u_arg[1]);
1259 if (current_personality == 0)
1260 printstat(tcp, tcp->u_arg[2]);
1262 printstat64(tcp, tcp->u_arg[2]);
1263 #elif defined HAVE_STAT64
1264 printstat64(tcp, tcp->u_arg[2]);
1266 printstat(tcp, tcp->u_arg[2]);
1269 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1274 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1276 sys_oldstat(struct tcb *tcp)
1278 if (entering(tcp)) {
1279 printpath(tcp, tcp->u_arg[0]);
1282 printoldstat(tcp, tcp->u_arg[1]);
1288 #ifndef HAVE_LONG_LONG_OFF_T
1290 sys_fstat(struct tcb *tcp)
1292 if (entering(tcp)) {
1293 printfd(tcp, tcp->u_arg[0]);
1296 printstat(tcp, tcp->u_arg[1]);
1303 sys_fstat64(struct tcb *tcp)
1306 if (entering(tcp)) {
1307 printfd(tcp, tcp->u_arg[0]);
1310 printstat64(tcp, tcp->u_arg[1]);
1314 return printargs(tcp);
1318 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1320 sys_oldfstat(struct tcb *tcp)
1322 if (entering(tcp)) {
1323 printfd(tcp, tcp->u_arg[0]);
1326 printoldstat(tcp, tcp->u_arg[1]);
1332 #ifndef HAVE_LONG_LONG_OFF_T
1334 sys_lstat(struct tcb *tcp)
1336 if (entering(tcp)) {
1337 printpath(tcp, tcp->u_arg[0]);
1340 printstat(tcp, tcp->u_arg[1]);
1347 sys_lstat64(struct tcb *tcp)
1350 if (entering(tcp)) {
1351 printpath(tcp, tcp->u_arg[0]);
1354 printstat64(tcp, tcp->u_arg[1]);
1358 return printargs(tcp);
1362 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1364 sys_oldlstat(struct tcb *tcp)
1366 if (entering(tcp)) {
1367 printpath(tcp, tcp->u_arg[0]);
1370 printoldstat(tcp, tcp->u_arg[1]);
1376 #if defined(LINUXSPARC)
1379 sys_xstat(struct tcb *tcp)
1381 if (entering(tcp)) {
1382 tprintf("%ld, ", tcp->u_arg[0]);
1383 printpath(tcp, tcp->u_arg[1]);
1387 if (tcp->u_arg[0] == _STAT64_VER)
1388 printstat64(tcp, tcp->u_arg[2]);
1391 printstat(tcp, tcp->u_arg[2]);
1397 sys_fxstat(struct tcb *tcp)
1400 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1403 if (tcp->u_arg[0] == _STAT64_VER)
1404 printstat64(tcp, tcp->u_arg[2]);
1407 printstat(tcp, tcp->u_arg[2]);
1413 sys_lxstat(struct tcb *tcp)
1415 if (entering(tcp)) {
1416 tprintf("%ld, ", tcp->u_arg[0]);
1417 printpath(tcp, tcp->u_arg[1]);
1421 if (tcp->u_arg[0] == _STAT64_VER)
1422 printstat64(tcp, tcp->u_arg[2]);
1425 printstat(tcp, tcp->u_arg[2]);
1431 sys_xmknod(struct tcb *tcp)
1433 int mode = tcp->u_arg[2];
1435 if (entering(tcp)) {
1436 tprintf("%ld, ", tcp->u_arg[0]);
1437 printpath(tcp, tcp->u_arg[1]);
1438 tprintf(", %s", sprintmode(mode));
1439 switch (mode & S_IFMT) {
1440 case S_IFCHR: case S_IFBLK:
1441 tprintf(", makedev(%lu, %lu)",
1442 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1443 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1452 # ifdef HAVE_SYS_ACL_H
1454 # include <sys/acl.h>
1456 static const struct xlat aclcmds[] = {
1458 { SETACL, "SETACL" },
1461 { GETACL, "GETACL" },
1464 { GETACLCNT, "GETACLCNT" },
1467 { ACL_GET, "ACL_GET" },
1470 { ACL_SET, "ACL_SET" },
1473 { ACL_CNT, "ACL_CNT" },
1479 sys_acl(struct tcb *tcp)
1481 if (entering(tcp)) {
1482 printpath(tcp, tcp->u_arg[0]);
1484 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1485 tprintf(", %ld", tcp->u_arg[2]);
1487 * FIXME - dump out the list of aclent_t's pointed to
1488 * by "tcp->u_arg[3]" if it's not NULL.
1491 tprintf(", %#lx", tcp->u_arg[3]);
1499 sys_facl(struct tcb *tcp)
1501 if (entering(tcp)) {
1502 tprintf("%ld, ", tcp->u_arg[0]);
1503 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1504 tprintf(", %ld", tcp->u_arg[2]);
1506 * FIXME - dump out the list of aclent_t's pointed to
1507 * by "tcp->u_arg[3]" if it's not NULL.
1510 tprintf(", %#lx", tcp->u_arg[3]);
1517 static const struct xlat aclipc[] = {
1519 { IPC_SHM, "IPC_SHM" },
1522 { IPC_SEM, "IPC_SEM" },
1525 { IPC_MSG, "IPC_MSG" },
1531 sys_aclipc(struct tcb *tcp)
1533 if (entering(tcp)) {
1534 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1535 tprintf(", %#lx, ", tcp->u_arg[1]);
1536 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1537 tprintf(", %ld", tcp->u_arg[3]);
1539 * FIXME - dump out the list of aclent_t's pointed to
1540 * by "tcp->u_arg[4]" if it's not NULL.
1543 tprintf(", %#lx", tcp->u_arg[4]);
1550 # endif /* HAVE_SYS_ACL_H */
1552 #endif /* LINUXSPARC */
1554 static const struct xlat fsmagic[] = {
1555 { 0x73757245, "CODA_SUPER_MAGIC" },
1556 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1557 { 0x1373, "DEVFS_SUPER_MAGIC" },
1558 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1559 { 0x414A53, "EFS_SUPER_MAGIC" },
1560 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1561 { 0xef53, "EXT2_SUPER_MAGIC" },
1562 { 0x137d, "EXT_SUPER_MAGIC" },
1563 { 0xf995e849, "HPFS_SUPER_MAGIC" },
1564 { 0x9660, "ISOFS_SUPER_MAGIC" },
1565 { 0x137f, "MINIX_SUPER_MAGIC" },
1566 { 0x138f, "MINIX_SUPER_MAGIC2" },
1567 { 0x2468, "MINIX2_SUPER_MAGIC" },
1568 { 0x2478, "MINIX2_SUPER_MAGIC2" },
1569 { 0x4d44, "MSDOS_SUPER_MAGIC" },
1570 { 0x564c, "NCP_SUPER_MAGIC" },
1571 { 0x6969, "NFS_SUPER_MAGIC" },
1572 { 0x9fa0, "PROC_SUPER_MAGIC" },
1573 { 0x002f, "QNX4_SUPER_MAGIC" },
1574 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1575 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1576 { 0x517b, "SMB_SUPER_MAGIC" },
1577 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1578 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1579 { 0x00011954, "UFS_MAGIC" },
1580 { 0x54190100, "UFS_CIGAM" },
1581 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
1582 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
1583 { 0x62656572, "SYSFS_MAGIC" },
1588 sprintfstype(int magic)
1590 static char buf[32];
1593 s = xlookup(fsmagic, magic);
1595 sprintf(buf, "\"%s\"", s);
1598 sprintf(buf, "%#x", magic);
1603 printstatfs(struct tcb *tcp, long addr)
1605 struct statfs statbuf;
1607 if (syserror(tcp) || !verbose(tcp)) {
1608 tprintf("%#lx", addr);
1611 if (umove(tcp, addr, &statbuf) < 0) {
1617 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1618 sprintfstype(statbuf.f_type),
1619 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1620 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1621 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
1622 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1625 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1626 sprintfstype(statbuf.f_type),
1627 (unsigned long)statbuf.f_bsize,
1628 (unsigned long)statbuf.f_blocks,
1629 (unsigned long)statbuf.f_bfree);
1630 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1631 (unsigned long)statbuf.f_bavail,
1632 (unsigned long)statbuf.f_files,
1633 (unsigned long)statbuf.f_ffree,
1634 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1635 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1637 #ifdef _STATFS_F_FRSIZE
1638 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1644 sys_statfs(struct tcb *tcp)
1646 if (entering(tcp)) {
1647 printpath(tcp, tcp->u_arg[0]);
1650 printstatfs(tcp, tcp->u_arg[1]);
1656 sys_fstatfs(struct tcb *tcp)
1658 if (entering(tcp)) {
1659 printfd(tcp, tcp->u_arg[0]);
1662 printstatfs(tcp, tcp->u_arg[1]);
1667 #if defined HAVE_STATFS64
1669 printstatfs64(struct tcb *tcp, long addr)
1671 struct statfs64 statbuf;
1673 if (syserror(tcp) || !verbose(tcp)) {
1674 tprintf("%#lx", addr);
1677 if (umove(tcp, addr, &statbuf) < 0) {
1681 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
1682 sprintfstype(statbuf.f_type),
1683 (unsigned long long)statbuf.f_bsize,
1684 (unsigned long long)statbuf.f_blocks,
1685 (unsigned long long)statbuf.f_bfree);
1686 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1687 (unsigned long long)statbuf.f_bavail,
1688 (unsigned long long)statbuf.f_files,
1689 (unsigned long long)statbuf.f_ffree,
1690 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1691 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1692 #ifdef _STATFS_F_FRSIZE
1693 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
1695 #ifdef _STATFS_F_FLAGS
1696 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1701 struct compat_statfs64 {
1713 uint32_t f_spare[4];
1715 #if defined(X86_64) || defined(IA64)
1716 __attribute__ ((packed, aligned(4)))
1721 printcompat_statfs64(struct tcb *tcp, long addr)
1723 struct compat_statfs64 statbuf;
1725 if (syserror(tcp) || !verbose(tcp)) {
1726 tprintf("%#lx", addr);
1729 if (umove(tcp, addr, &statbuf) < 0) {
1733 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1734 sprintfstype(statbuf.f_type),
1735 (unsigned long)statbuf.f_bsize,
1736 (unsigned long long)statbuf.f_blocks,
1737 (unsigned long long)statbuf.f_bfree);
1738 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1739 (unsigned long long)statbuf.f_bavail,
1740 (unsigned long long)statbuf.f_files,
1741 (unsigned long long)statbuf.f_ffree,
1742 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1743 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1744 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1745 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
1749 sys_statfs64(struct tcb *tcp)
1751 if (entering(tcp)) {
1752 printpath(tcp, tcp->u_arg[0]);
1753 tprintf(", %lu, ", tcp->u_arg[1]);
1755 if (tcp->u_arg[1] == sizeof(struct statfs64))
1756 printstatfs64(tcp, tcp->u_arg[2]);
1757 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1758 printcompat_statfs64(tcp, tcp->u_arg[2]);
1766 sys_fstatfs64(struct tcb *tcp)
1768 if (entering(tcp)) {
1769 printfd(tcp, tcp->u_arg[0]);
1770 tprintf(", %lu, ", tcp->u_arg[1]);
1772 if (tcp->u_arg[1] == sizeof(struct statfs64))
1773 printstatfs64(tcp, tcp->u_arg[2]);
1774 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1775 printcompat_statfs64(tcp, tcp->u_arg[2]);
1785 osf_statfs(struct tcb *tcp)
1787 if (entering(tcp)) {
1788 printpath(tcp, tcp->u_arg[0]);
1791 printstatfs(tcp, tcp->u_arg[1]);
1792 tprintf(", %lu", tcp->u_arg[2]);
1798 osf_fstatfs(struct tcb *tcp)
1800 if (entering(tcp)) {
1801 tprintf("%lu, ", tcp->u_arg[0]);
1803 printstatfs(tcp, tcp->u_arg[1]);
1804 tprintf(", %lu", tcp->u_arg[2]);
1812 sys_chdir(struct tcb *tcp)
1814 if (entering(tcp)) {
1815 printpath(tcp, tcp->u_arg[0]);
1821 decode_mkdir(struct tcb *tcp, int offset)
1823 if (entering(tcp)) {
1824 printpath(tcp, tcp->u_arg[offset]);
1825 tprintf(", %#lo", tcp->u_arg[offset + 1]);
1831 sys_mkdir(struct tcb *tcp)
1833 return decode_mkdir(tcp, 0);
1837 sys_mkdirat(struct tcb *tcp)
1840 print_dirfd(tcp, tcp->u_arg[0]);
1841 return decode_mkdir(tcp, 1);
1845 sys_link(struct tcb *tcp)
1847 if (entering(tcp)) {
1848 printpath(tcp, tcp->u_arg[0]);
1850 printpath(tcp, tcp->u_arg[1]);
1856 sys_linkat(struct tcb *tcp)
1858 if (entering(tcp)) {
1859 print_dirfd(tcp, tcp->u_arg[0]);
1860 printpath(tcp, tcp->u_arg[1]);
1862 print_dirfd(tcp, tcp->u_arg[2]);
1863 printpath(tcp, tcp->u_arg[3]);
1865 printfd(tcp, tcp->u_arg[4]);
1870 static const struct xlat unlinkatflags[] = {
1871 #ifndef AT_REMOVEDIR
1872 # define AT_REMOVEDIR 0x200
1874 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1879 sys_unlinkat(struct tcb *tcp)
1881 if (entering(tcp)) {
1882 print_dirfd(tcp, tcp->u_arg[0]);
1883 printpath(tcp, tcp->u_arg[1]);
1885 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1891 sys_symlinkat(struct tcb *tcp)
1893 if (entering(tcp)) {
1894 printpath(tcp, tcp->u_arg[0]);
1896 print_dirfd(tcp, tcp->u_arg[1]);
1897 printpath(tcp, tcp->u_arg[2]);
1903 decode_readlink(struct tcb *tcp, int offset)
1905 if (entering(tcp)) {
1906 printpath(tcp, tcp->u_arg[offset]);
1910 tprintf("%#lx", tcp->u_arg[offset + 1]);
1912 /* Used to use printpathn(), but readlink
1913 * neither includes NUL in the returned count,
1914 * nor actually writes it into memory.
1915 * printpathn() would decide on printing
1916 * "..." continuation based on garbage
1917 * past return buffer's end.
1919 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1920 tprintf(", %lu", tcp->u_arg[offset + 2]);
1926 sys_readlink(struct tcb *tcp)
1928 return decode_readlink(tcp, 0);
1932 sys_readlinkat(struct tcb *tcp)
1935 print_dirfd(tcp, tcp->u_arg[0]);
1936 return decode_readlink(tcp, 1);
1940 sys_renameat(struct tcb *tcp)
1942 if (entering(tcp)) {
1943 print_dirfd(tcp, tcp->u_arg[0]);
1944 printpath(tcp, tcp->u_arg[1]);
1946 print_dirfd(tcp, tcp->u_arg[2]);
1947 printpath(tcp, tcp->u_arg[3]);
1953 sys_chown(struct tcb *tcp)
1955 if (entering(tcp)) {
1956 printpath(tcp, tcp->u_arg[0]);
1957 printuid(", ", tcp->u_arg[1]);
1958 printuid(", ", tcp->u_arg[2]);
1964 sys_fchownat(struct tcb *tcp)
1966 if (entering(tcp)) {
1967 print_dirfd(tcp, tcp->u_arg[0]);
1968 printpath(tcp, tcp->u_arg[1]);
1969 printuid(", ", tcp->u_arg[2]);
1970 printuid(", ", tcp->u_arg[3]);
1972 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
1978 sys_fchown(struct tcb *tcp)
1980 if (entering(tcp)) {
1981 printfd(tcp, tcp->u_arg[0]);
1982 printuid(", ", tcp->u_arg[1]);
1983 printuid(", ", tcp->u_arg[2]);
1989 decode_chmod(struct tcb *tcp, int offset)
1991 if (entering(tcp)) {
1992 printpath(tcp, tcp->u_arg[offset]);
1993 tprintf(", %#lo", tcp->u_arg[offset + 1]);
1999 sys_chmod(struct tcb *tcp)
2001 return decode_chmod(tcp, 0);
2005 sys_fchmodat(struct tcb *tcp)
2008 print_dirfd(tcp, tcp->u_arg[0]);
2009 return decode_chmod(tcp, 1);
2013 sys_fchmod(struct tcb *tcp)
2015 if (entering(tcp)) {
2016 printfd(tcp, tcp->u_arg[0]);
2017 tprintf(", %#lo", tcp->u_arg[1]);
2024 sys_osf_utimes(struct tcb *tcp)
2026 if (entering(tcp)) {
2027 printpath(tcp, tcp->u_arg[0]);
2029 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2036 decode_utimes(struct tcb *tcp, int offset, int special)
2038 if (entering(tcp)) {
2039 printpath(tcp, tcp->u_arg[offset]);
2041 if (tcp->u_arg[offset + 1] == 0)
2045 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2046 BITNESS_CURRENT, special);
2048 printtv_bitness(tcp, tcp->u_arg[offset + 1]
2049 + sizeof(struct timeval),
2050 BITNESS_CURRENT, special);
2058 sys_utimes(struct tcb *tcp)
2060 return decode_utimes(tcp, 0, 0);
2064 sys_futimesat(struct tcb *tcp)
2067 print_dirfd(tcp, tcp->u_arg[0]);
2068 return decode_utimes(tcp, 1, 0);
2072 sys_utimensat(struct tcb *tcp)
2074 if (entering(tcp)) {
2075 print_dirfd(tcp, tcp->u_arg[0]);
2076 decode_utimes(tcp, 1, 1);
2078 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2084 sys_utime(struct tcb *tcp)
2090 unsigned wordsize = personality_wordsize[current_personality];
2092 if (entering(tcp)) {
2093 printpath(tcp, tcp->u_arg[0]);
2097 else if (!verbose(tcp))
2098 tprintf("%#lx", tcp->u_arg[1]);
2099 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
2101 else if (wordsize == sizeof u.utl[0]) {
2102 tprintf("[%s,", sprinttime(u.utl[0]));
2103 tprintf(" %s]", sprinttime(u.utl[1]));
2105 else if (wordsize == sizeof u.uti[0]) {
2106 tprintf("[%s,", sprinttime(u.uti[0]));
2107 tprintf(" %s]", sprinttime(u.uti[1]));
2116 decode_mknod(struct tcb *tcp, int offset)
2118 int mode = tcp->u_arg[offset + 1];
2120 if (entering(tcp)) {
2121 printpath(tcp, tcp->u_arg[offset]);
2122 tprintf(", %s", sprintmode(mode));
2123 switch (mode & S_IFMT) {
2127 if (current_personality == 1)
2128 tprintf(", makedev(%lu, %lu)",
2129 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2130 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
2133 tprintf(", makedev(%lu, %lu)",
2134 (unsigned long) major(tcp->u_arg[offset + 2]),
2135 (unsigned long) minor(tcp->u_arg[offset + 2]));
2145 sys_mknod(struct tcb *tcp)
2147 return decode_mknod(tcp, 0);
2151 sys_mknodat(struct tcb *tcp)
2154 print_dirfd(tcp, tcp->u_arg[0]);
2155 return decode_mknod(tcp, 1);
2159 sys_fsync(struct tcb *tcp)
2161 if (entering(tcp)) {
2162 printfd(tcp, tcp->u_arg[0]);
2168 printdir(struct tcb *tcp, long addr)
2172 if (!verbose(tcp)) {
2173 tprintf("%#lx", addr);
2176 if (umove(tcp, addr, &d) < 0) {
2180 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
2182 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2187 sys_readdir(struct tcb *tcp)
2189 if (entering(tcp)) {
2190 printfd(tcp, tcp->u_arg[0]);
2193 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2194 tprintf("%#lx", tcp->u_arg[1]);
2196 printdir(tcp, tcp->u_arg[1]);
2197 /* Not much point in printing this out, it is always 1. */
2198 if (tcp->u_arg[2] != 1)
2199 tprintf(", %lu", tcp->u_arg[2]);
2204 static const struct xlat direnttypes[] = {
2205 { DT_UNKNOWN, "DT_UNKNOWN" },
2206 { DT_FIFO, "DT_FIFO" },
2207 { DT_CHR, "DT_CHR" },
2208 { DT_DIR, "DT_DIR" },
2209 { DT_BLK, "DT_BLK" },
2210 { DT_REG, "DT_REG" },
2211 { DT_LNK, "DT_LNK" },
2212 { DT_SOCK, "DT_SOCK" },
2213 { DT_WHT, "DT_WHT" },
2218 sys_getdents(struct tcb *tcp)
2220 int i, len, dents = 0;
2223 if (entering(tcp)) {
2224 printfd(tcp, tcp->u_arg[0]);
2228 if (syserror(tcp) || !verbose(tcp)) {
2229 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2233 /* Beware of insanely large or negative values in tcp->u_rval */
2234 if (tcp->u_rval > 1024*1024)
2236 if (tcp->u_rval < 0)
2238 buf = len ? malloc(len) : NULL;
2240 die_out_of_memory();
2241 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2242 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2248 for (i = 0; i < len;) {
2249 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2251 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2252 i ? " " : "", d->d_ino, d->d_off);
2253 tprintf("d_reclen=%u, d_name=\"%s\"}",
2254 d->d_reclen, d->d_name);
2257 tprints("/* d_reclen == 0, problem here */");
2266 tprintf("/* %u entries */", dents);
2267 tprintf(", %lu", tcp->u_arg[2]);
2272 #if _LFS64_LARGEFILE
2274 sys_getdents64(struct tcb *tcp)
2276 int i, len, dents = 0;
2279 if (entering(tcp)) {
2280 printfd(tcp, tcp->u_arg[0]);
2284 if (syserror(tcp) || !verbose(tcp)) {
2285 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2290 /* Beware of insanely large or negative tcp->u_rval */
2291 if (tcp->u_rval > 1024*1024)
2293 if (tcp->u_rval < 0)
2295 buf = len ? malloc(len) : NULL;
2297 die_out_of_memory();
2299 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2300 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2306 for (i = 0; i < len;) {
2307 struct dirent64 *d = (struct dirent64 *) &buf[i];
2309 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
2314 printxval(direnttypes, d->d_type, "DT_???");
2316 tprintf("d_reclen=%u, d_name=\"%s\"}",
2317 d->d_reclen, d->d_name);
2320 tprints("/* d_reclen == 0, problem here */");
2329 tprintf("/* %u entries */", dents);
2330 tprintf(", %lu", tcp->u_arg[2]);
2337 sys_getcwd(struct tcb *tcp)
2341 tprintf("%#lx", tcp->u_arg[0]);
2343 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2344 tprintf(", %lu", tcp->u_arg[1]);
2349 #ifdef HAVE_SYS_ASYNCH_H
2352 sys_aioread(struct tcb *tcp)
2354 struct aio_result_t res;
2356 if (entering(tcp)) {
2357 tprintf("%lu, ", tcp->u_arg[0]);
2360 tprintf("%#lx", tcp->u_arg[1]);
2362 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2363 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2364 printxval(whence, tcp->u_arg[4], "L_???");
2365 if (syserror(tcp) || tcp->u_arg[5] == 0
2366 || umove(tcp, tcp->u_arg[5], &res) < 0)
2367 tprintf(", %#lx", tcp->u_arg[5]);
2369 tprintf(", {aio_return %d aio_errno %d}",
2370 res.aio_return, res.aio_errno);
2376 sys_aiowrite(struct tcb *tcp)
2378 struct aio_result_t res;
2380 if (entering(tcp)) {
2381 tprintf("%lu, ", tcp->u_arg[0]);
2382 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2383 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2384 printxval(whence, tcp->u_arg[4], "L_???");
2387 if (tcp->u_arg[5] == 0)
2389 else if (syserror(tcp)
2390 || umove(tcp, tcp->u_arg[5], &res) < 0)
2391 tprintf(", %#lx", tcp->u_arg[5]);
2393 tprintf(", {aio_return %d aio_errno %d}",
2394 res.aio_return, res.aio_errno);
2400 sys_aiowait(struct tcb *tcp)
2403 printtv(tcp, tcp->u_arg[0]);
2408 sys_aiocancel(struct tcb *tcp)
2410 struct aio_result_t res;
2413 if (tcp->u_arg[0] == 0)
2415 else if (syserror(tcp)
2416 || umove(tcp, tcp->u_arg[0], &res) < 0)
2417 tprintf("%#lx", tcp->u_arg[0]);
2419 tprintf("{aio_return %d aio_errno %d}",
2420 res.aio_return, res.aio_errno);
2425 #endif /* HAVE_SYS_ASYNCH_H */
2427 static const struct xlat xattrflags[] = {
2429 { XATTR_CREATE, "XATTR_CREATE" },
2430 { XATTR_REPLACE, "XATTR_REPLACE" },
2436 print_xattr_val(struct tcb *tcp, int failed,
2438 unsigned long insize,
2442 unsigned long capacity = 4 * size + 1;
2443 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2444 if (buf == NULL || /* probably a bogus size argument */
2445 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2449 unsigned char *out = buf;
2450 unsigned char *in = &buf[3 * size];
2452 for (i = 0; i < size; ++i) {
2456 #define tohex(n) "0123456789abcdef"[n]
2459 *out++ = tohex(in[i] / 16);
2460 *out++ = tohex(in[i] % 16);
2463 /* Don't print terminating NUL if there is one. */
2464 if (i > 0 && in[i - 1] == '\0')
2467 tprintf(", \"%s\", %ld", buf, insize);
2472 tprintf(", 0x%lx, %ld", arg, insize);
2476 sys_setxattr(struct tcb *tcp)
2478 if (entering(tcp)) {
2479 printpath(tcp, tcp->u_arg[0]);
2481 printstr(tcp, tcp->u_arg[1], -1);
2482 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2484 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2490 sys_fsetxattr(struct tcb *tcp)
2492 if (entering(tcp)) {
2493 printfd(tcp, tcp->u_arg[0]);
2495 printstr(tcp, tcp->u_arg[1], -1);
2496 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2498 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2504 sys_getxattr(struct tcb *tcp)
2506 if (entering(tcp)) {
2507 printpath(tcp, tcp->u_arg[0]);
2509 printstr(tcp, tcp->u_arg[1], -1);
2511 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2518 sys_fgetxattr(struct tcb *tcp)
2520 if (entering(tcp)) {
2521 printfd(tcp, tcp->u_arg[0]);
2523 printstr(tcp, tcp->u_arg[1], -1);
2525 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2532 sys_listxattr(struct tcb *tcp)
2534 if (entering(tcp)) {
2535 printpath(tcp, tcp->u_arg[0]);
2537 /* XXX Print value in format */
2538 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2544 sys_flistxattr(struct tcb *tcp)
2546 if (entering(tcp)) {
2547 printfd(tcp, tcp->u_arg[0]);
2549 /* XXX Print value in format */
2550 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2556 sys_removexattr(struct tcb *tcp)
2558 if (entering(tcp)) {
2559 printpath(tcp, tcp->u_arg[0]);
2561 printstr(tcp, tcp->u_arg[1], -1);
2567 sys_fremovexattr(struct tcb *tcp)
2569 if (entering(tcp)) {
2570 printfd(tcp, tcp->u_arg[0]);
2572 printstr(tcp, tcp->u_arg[1], -1);
2577 static const struct xlat advise[] = {
2578 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2579 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2580 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2581 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2582 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2583 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2588 sys_fadvise64(struct tcb *tcp)
2590 if (entering(tcp)) {
2592 printfd(tcp, tcp->u_arg[0]);
2594 argn = printllval(tcp, "%lld", 1);
2595 tprintf(", %ld, ", tcp->u_arg[argn++]);
2596 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2602 sys_fadvise64_64(struct tcb *tcp)
2604 if (entering(tcp)) {
2606 printfd(tcp, tcp->u_arg[0]);
2608 #if defined ARM || defined POWERPC
2609 argn = printllval(tcp, "%lld, ", 2);
2611 argn = printllval(tcp, "%lld, ", 1);
2613 argn = printllval(tcp, "%lld, ", argn);
2614 #if defined ARM || defined POWERPC
2615 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
2617 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2623 static const struct xlat inotify_modes[] = {
2624 { 0x00000001, "IN_ACCESS" },
2625 { 0x00000002, "IN_MODIFY" },
2626 { 0x00000004, "IN_ATTRIB" },
2627 { 0x00000008, "IN_CLOSE_WRITE"},
2628 { 0x00000010, "IN_CLOSE_NOWRITE"},
2629 { 0x00000020, "IN_OPEN" },
2630 { 0x00000040, "IN_MOVED_FROM" },
2631 { 0x00000080, "IN_MOVED_TO" },
2632 { 0x00000100, "IN_CREATE" },
2633 { 0x00000200, "IN_DELETE" },
2634 { 0x00000400, "IN_DELETE_SELF"},
2635 { 0x00000800, "IN_MOVE_SELF" },
2636 { 0x00002000, "IN_UNMOUNT" },
2637 { 0x00004000, "IN_Q_OVERFLOW" },
2638 { 0x00008000, "IN_IGNORED" },
2639 { 0x01000000, "IN_ONLYDIR" },
2640 { 0x02000000, "IN_DONT_FOLLOW"},
2641 { 0x20000000, "IN_MASK_ADD" },
2642 { 0x40000000, "IN_ISDIR" },
2643 { 0x80000000, "IN_ONESHOT" },
2647 static const struct xlat inotify_init_flags[] = {
2648 { 0x00000800, "IN_NONBLOCK" },
2649 { 0x00080000, "IN_CLOEXEC" },
2654 sys_inotify_add_watch(struct tcb *tcp)
2656 if (entering(tcp)) {
2657 printfd(tcp, tcp->u_arg[0]);
2659 printpath(tcp, tcp->u_arg[1]);
2661 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2667 sys_inotify_rm_watch(struct tcb *tcp)
2669 if (entering(tcp)) {
2670 printfd(tcp, tcp->u_arg[0]);
2671 tprintf(", %ld", tcp->u_arg[1]);
2677 sys_inotify_init1(struct tcb *tcp)
2680 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
2685 sys_fallocate(struct tcb *tcp)
2687 if (entering(tcp)) {
2689 printfd(tcp, tcp->u_arg[0]); /* fd */
2691 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
2692 argn = printllval(tcp, "%llu, ", 2); /* offset */
2693 printllval(tcp, "%llu", argn); /* len */