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.
35 #if defined(SPARC) || defined(SPARC64)
37 unsigned short st_dev;
39 unsigned short st_mode;
41 unsigned short st_uid;
42 unsigned short st_gid;
43 unsigned short st_rdev;
46 unsigned int __unused1;
48 unsigned int __unused2;
50 unsigned int __unused3;
53 unsigned int __unused4[2];
60 unsigned int st_nlink;
70 unsigned long __unused4[2];
73 # define stat kernel_stat
74 # include <asm/stat.h>
78 unsigned long long st_dev;
79 unsigned long long st_ino;
80 unsigned long long st_nlink;
86 unsigned long long st_rdev;
91 unsigned long long st_atime;
92 unsigned long long st_atime_nsec;
93 unsigned long long st_mtime;
94 unsigned long long st_mtime_nsec;
95 unsigned long long st_ctime;
96 unsigned long long st_ctime_nsec;
97 long long __unused[3];
101 unsigned long long st_dev;
102 unsigned char __pad0[4];
103 unsigned long __st_ino;
104 unsigned int st_mode;
105 unsigned int st_nlink;
106 unsigned long st_uid;
107 unsigned long st_gid;
108 unsigned long long st_rdev;
109 unsigned char __pad3[4];
111 unsigned long st_blksize;
112 unsigned long long st_blocks;
113 unsigned long st_atime;
114 unsigned long st_atime_nsec;
115 unsigned long st_mtime;
116 unsigned int st_mtime_nsec;
117 unsigned long st_ctime;
118 unsigned long st_ctime_nsec;
119 unsigned long long st_ino;
120 } __attribute__((packed));
121 # define HAVE_STAT64 1
123 struct __old_kernel_stat {
124 unsigned short st_dev;
125 unsigned short st_ino;
126 unsigned short st_mode;
127 unsigned short st_nlink;
128 unsigned short st_uid;
129 unsigned short st_gid;
130 unsigned short st_rdev;
131 unsigned int st_size;
132 unsigned int st_atime;
133 unsigned int st_mtime;
134 unsigned int st_ctime;
145 # define dev_t __kernel_dev_t
146 # define ino_t __kernel_ino_t
147 # define mode_t __kernel_mode_t
148 # define nlink_t __kernel_nlink_t
149 # define uid_t __kernel_uid_t
150 # define gid_t __kernel_gid_t
151 # define off_t __kernel_off_t
152 # define loff_t __kernel_loff_t
154 # include <asm/stat.h>
166 # define mode_t mode_t
167 # define nlink_t nlink_t
171 # define loff_t loff_t
174 #define stat libc_stat
175 #define stat64 libc_stat64
176 #include <sys/stat.h>
179 /* These might be macros. */
189 #ifdef HAVE_SYS_VFS_H
190 # include <sys/vfs.h>
192 #ifdef HAVE_LINUX_XATTR_H
193 # include <linux/xattr.h>
195 # define XATTR_CREATE 1
196 # define XATTR_REPLACE 2
199 #ifdef MAJOR_IN_SYSMACROS
200 # include <sys/sysmacros.h>
203 #ifdef MAJOR_IN_MKDEV
204 # include <sys/mkdev.h>
207 #ifdef HAVE_SYS_ASYNCH_H
208 # include <sys/asynch.h>
211 struct kernel_dirent {
214 unsigned short d_reclen;
218 const struct xlat open_access_modes[] = {
228 const struct xlat open_mode_flags[] = {
247 #if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
257 # if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
260 # define O_LARGEFILE 0x40000
261 # elif defined X86_64 || defined S390X
262 # define O_LARGEFILE 0100000
333 # define AT_FDCWD -100
336 /* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
337 * extension to get the right value. We do this by declaring fd as int here.
340 print_dirfd(struct tcb *tcp, int fd)
343 tprints("AT_FDCWD, ");
351 * low bits of the open(2) flags define access mode,
352 * other bits are real flags.
355 sprint_open_modes(mode_t flags)
357 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
361 const struct xlat *x;
364 p = stpcpy(outstr, "flags");
365 str = xlookup(open_access_modes, flags & 3);
375 for (x = open_mode_flags; x->str; x++) {
376 if ((flags & x->val) == x->val) {
378 p = stpcpy(p, x->str);
385 /* flags is still nonzero */
387 sprintf(p, "%#x", flags);
392 tprint_open_modes(mode_t flags)
394 tprints(sprint_open_modes(flags) + sizeof("flags"));
398 decode_open(struct tcb *tcp, int offset)
401 printpath(tcp, tcp->u_arg[offset]);
404 tprint_open_modes(tcp->u_arg[offset + 1]);
405 if (tcp->u_arg[offset + 1] & O_CREAT) {
407 tprintf(", %#lo", tcp->u_arg[offset + 2]);
414 sys_open(struct tcb *tcp)
416 return decode_open(tcp, 0);
420 sys_openat(struct tcb *tcp)
423 print_dirfd(tcp, tcp->u_arg[0]);
424 return decode_open(tcp, 1);
427 #if defined(SPARC) || defined(SPARC64)
428 static const struct xlat openmodessol[] = {
432 { 0x80, "O_NONBLOCK" },
434 { 0x100, "O_CREAT" },
435 { 0x200, "O_TRUNC" },
437 { 0x800, "O_NOCTTY" },
440 { 0x8000, "O_RSYNC" },
442 { 0x1000, "O_PRIV" },
447 solaris_open(struct tcb *tcp)
450 printpath(tcp, tcp->u_arg[0]);
453 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
454 if (tcp->u_arg[1] & 0x100) {
456 tprintf(", %#lo", tcp->u_arg[2]);
465 sys_creat(struct tcb *tcp)
468 printpath(tcp, tcp->u_arg[0]);
469 tprintf(", %#lo", tcp->u_arg[1]);
474 static const struct xlat access_flags[] = {
489 decode_access(struct tcb *tcp, int offset)
492 printpath(tcp, tcp->u_arg[offset]);
494 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
500 sys_access(struct tcb *tcp)
502 return decode_access(tcp, 0);
506 sys_faccessat(struct tcb *tcp)
509 print_dirfd(tcp, tcp->u_arg[0]);
510 return decode_access(tcp, 1);
514 sys_umask(struct tcb *tcp)
517 tprintf("%#lo", tcp->u_arg[0]);
522 const struct xlat whence_codes[] = {
535 /* Linux kernel has exactly one version of lseek:
536 * fs/read_write.c::SYSCALL_DEFINE3(lseek, unsigned, fd, off_t, offset, unsigned, origin)
537 * In kernel, off_t is always the same as (kernel's) long
538 * (see include/uapi/asm-generic/posix_types.h),
539 * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
540 * Use test/x32_lseek.c to test lseek decoding.
542 #if defined(LINUX_MIPSN32) || defined(X32)
544 sys_lseek(struct tcb *tcp)
550 printfd(tcp, tcp->u_arg[0]);
551 offset = tcp->ext_arg[1];
552 whence = tcp->u_arg[2];
553 if (whence == SEEK_SET)
554 tprintf(", %llu, ", offset);
556 tprintf(", %lld, ", offset);
557 printxval(whence_codes, whence, "SEEK_???");
559 return RVAL_LUDECIMAL;
563 sys_lseek(struct tcb *tcp)
569 printfd(tcp, tcp->u_arg[0]);
570 offset = tcp->u_arg[1];
571 whence = tcp->u_arg[2];
572 if (whence == SEEK_SET)
573 tprintf(", %lu, ", offset);
575 tprintf(", %ld, ", offset);
576 printxval(whence_codes, whence, "SEEK_???");
578 return RVAL_UDECIMAL;
582 /* llseek syscall takes explicitly two ulong arguments hi, lo,
583 * rather than one 64-bit argument for which LONG_LONG works
584 * appropriate for the native byte order.
586 * See kernel's fs/read_write.c::SYSCALL_DEFINE5(llseek, ...)
588 * hi,lo are "unsigned longs" and combined exactly this way in kernel:
589 * ((loff_t) hi << 32) | lo
590 * Note that for architectures with kernel's long wider than userspace long
591 * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
592 * for hi and lo. We would need to use tcp->ext_arg[N] on x32...
593 * ...however, x32 (and x86_64) does not _have_ llseek syscall as such.
596 sys_llseek(struct tcb *tcp)
599 printfd(tcp, tcp->u_arg[0]);
600 if (tcp->u_arg[4] == SEEK_SET)
602 ((long long) tcp->u_arg[1]) << 32 |
603 (unsigned long long) (unsigned) tcp->u_arg[2]);
606 ((long long) tcp->u_arg[1]) << 32 |
607 (unsigned long long) (unsigned) tcp->u_arg[2]);
611 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
612 tprintf("%#lx, ", tcp->u_arg[3]);
614 tprintf("[%llu], ", off);
615 printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
621 sys_readahead(struct tcb *tcp)
625 printfd(tcp, tcp->u_arg[0]);
626 argn = printllval(tcp, ", %lld", 1);
627 tprintf(", %ld", tcp->u_arg[argn]);
633 sys_truncate(struct tcb *tcp)
636 printpath(tcp, tcp->u_arg[0]);
637 tprintf(", %lu", tcp->u_arg[1]);
643 sys_truncate64(struct tcb *tcp)
646 printpath(tcp, tcp->u_arg[0]);
647 printllval(tcp, ", %llu", 1);
653 sys_ftruncate(struct tcb *tcp)
656 printfd(tcp, tcp->u_arg[0]);
657 tprintf(", %lu", tcp->u_arg[1]);
663 sys_ftruncate64(struct tcb *tcp)
666 printfd(tcp, tcp->u_arg[0]);
667 printllval(tcp, ", %llu", 1);
674 static const struct xlat modetypes[] = {
688 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
693 if ((mode & S_IFMT) == 0)
695 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
696 sprintf(buf, "%#o", mode);
699 s = buf + sprintf(buf, "%s%s%s%s", s,
700 (mode & S_ISUID) ? "|S_ISUID" : "",
701 (mode & S_ISGID) ? "|S_ISGID" : "",
702 (mode & S_ISVTX) ? "|S_ISVTX" : "");
703 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
705 sprintf((char*)s, "|%#o", mode);
706 s = (*buf == '|') ? buf + 1 : buf;
714 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
722 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
723 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
724 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
726 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
731 #if defined(SPARC) || defined(SPARC64)
739 int st_pad1[3]; /* network id */
748 int st_pad3; /* st_size, off_t expansion */
749 timestruct_t st_atime;
750 timestruct_t st_mtime;
751 timestruct_t st_ctime;
755 int st_pad4[8]; /* expansion area */
759 printstatsol(struct tcb *tcp, long addr)
761 struct solstat statbuf;
763 if (umove(tcp, addr, &statbuf) < 0) {
768 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
769 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
770 (unsigned long) (statbuf.st_dev & 0x3ffff),
771 (unsigned long) statbuf.st_ino,
772 sprintmode(statbuf.st_mode));
773 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
774 (unsigned long) statbuf.st_nlink,
775 (unsigned long) statbuf.st_uid,
776 (unsigned long) statbuf.st_gid);
777 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
778 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
781 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
782 switch (statbuf.st_mode & S_IFMT) {
783 case S_IFCHR: case S_IFBLK:
784 tprintf("st_rdev=makedev(%lu, %lu), ",
785 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
786 (unsigned long) (statbuf.st_rdev & 0x3ffff));
789 tprintf("st_size=%u, ", statbuf.st_size);
793 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
794 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
795 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
801 # if defined(SPARC64)
803 printstat_sparc64(struct tcb *tcp, long addr)
805 struct stat_sparc64 statbuf;
807 if (umove(tcp, addr, &statbuf) < 0) {
813 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
814 (unsigned long) major(statbuf.st_dev),
815 (unsigned long) minor(statbuf.st_dev),
816 (unsigned long) statbuf.st_ino,
817 sprintmode(statbuf.st_mode));
818 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
819 (unsigned long) statbuf.st_nlink,
820 (unsigned long) statbuf.st_uid,
821 (unsigned long) statbuf.st_gid);
822 tprintf("st_blksize=%lu, ",
823 (unsigned long) statbuf.st_blksize);
824 tprintf("st_blocks=%lu, ",
825 (unsigned long) statbuf.st_blocks);
828 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
829 switch (statbuf.st_mode & S_IFMT) {
830 case S_IFCHR: case S_IFBLK:
831 tprintf("st_rdev=makedev(%lu, %lu), ",
832 (unsigned long) major(statbuf.st_rdev),
833 (unsigned long) minor(statbuf.st_rdev));
836 tprintf("st_size=%lu, ", statbuf.st_size);
840 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
841 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
842 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
847 # endif /* SPARC64 */
848 #endif /* SPARC[64] */
850 #if defined POWERPC64
851 struct stat_powerpc32 {
854 unsigned int st_mode;
855 unsigned short st_nlink;
858 unsigned int st_rdev;
859 unsigned int st_size;
860 unsigned int st_blksize;
861 unsigned int st_blocks;
862 unsigned int st_atime;
863 unsigned int st_atime_nsec;
864 unsigned int st_mtime;
865 unsigned int st_mtime_nsec;
866 unsigned int st_ctime;
867 unsigned int st_ctime_nsec;
868 unsigned int __unused4;
869 unsigned int __unused5;
873 printstat_powerpc32(struct tcb *tcp, long addr)
875 struct stat_powerpc32 statbuf;
877 if (umove(tcp, addr, &statbuf) < 0) {
883 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
884 major(statbuf.st_dev), minor(statbuf.st_dev),
886 sprintmode(statbuf.st_mode));
887 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
888 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
889 tprintf("st_blksize=%u, ", statbuf.st_blksize);
890 tprintf("st_blocks=%u, ", statbuf.st_blocks);
893 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
894 switch (statbuf.st_mode & S_IFMT) {
895 case S_IFCHR: case S_IFBLK:
896 tprintf("st_rdev=makedev(%lu, %lu), ",
897 (unsigned long) major(statbuf.st_rdev),
898 (unsigned long) minor(statbuf.st_rdev));
901 tprintf("st_size=%u, ", statbuf.st_size);
905 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
906 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
907 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
912 #endif /* POWERPC64 */
914 static const struct xlat fileflags[] = {
919 realprintstat(struct tcb *tcp, struct stat *statbuf)
922 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
923 (unsigned long) major(statbuf->st_dev),
924 (unsigned long) minor(statbuf->st_dev),
925 (unsigned long) statbuf->st_ino,
926 sprintmode(statbuf->st_mode));
927 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
928 (unsigned long) statbuf->st_nlink,
929 (unsigned long) statbuf->st_uid,
930 (unsigned long) statbuf->st_gid);
931 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
932 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
934 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
935 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
939 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
940 switch (statbuf->st_mode & S_IFMT) {
941 case S_IFCHR: case S_IFBLK:
942 #ifdef HAVE_STRUCT_STAT_ST_RDEV
943 tprintf("st_rdev=makedev(%lu, %lu), ",
944 (unsigned long) major(statbuf->st_rdev),
945 (unsigned long) minor(statbuf->st_rdev));
946 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
947 tprintf("st_size=makedev(%lu, %lu), ",
948 (unsigned long) major(statbuf->st_size),
949 (unsigned long) minor(statbuf->st_size));
950 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
953 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
957 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
958 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
959 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
960 #if HAVE_STRUCT_STAT_ST_FLAGS
961 tprints(", st_flags=");
962 printflags(fileflags, statbuf->st_flags, "UF_???");
964 #if HAVE_STRUCT_STAT_ST_ACLCNT
965 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
967 #if HAVE_STRUCT_STAT_ST_LEVEL
968 tprintf(", st_level=%ld", statbuf->st_level);
970 #if HAVE_STRUCT_STAT_ST_FSTYPE
971 tprintf(", st_fstype=%.*s",
972 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
974 #if HAVE_STRUCT_STAT_ST_GEN
975 tprintf(", st_gen=%u", statbuf->st_gen);
985 printstat(struct tcb *tcp, long addr)
993 if (syserror(tcp) || !verbose(tcp)) {
994 tprintf("%#lx", addr);
998 #if defined(SPARC) || defined(SPARC64)
999 if (current_personality == 1) {
1000 printstatsol(tcp, addr);
1004 else if (current_personality == 2) {
1005 printstat_sparc64(tcp, addr);
1009 #endif /* SPARC[64] */
1011 #if defined POWERPC64
1012 if (current_personality == 1) {
1013 printstat_powerpc32(tcp, addr);
1018 if (umove(tcp, addr, &statbuf) < 0) {
1023 realprintstat(tcp, &statbuf);
1026 # define printstat printstat64
1029 #if !defined HAVE_STAT64 && defined X86_64
1031 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1032 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1033 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1034 * __GNUC__ is needed for the required __attribute__ below.
1037 unsigned long long st_dev;
1038 unsigned char __pad0[4];
1039 unsigned int __st_ino;
1040 unsigned int st_mode;
1041 unsigned int st_nlink;
1042 unsigned int st_uid;
1043 unsigned int st_gid;
1044 unsigned long long st_rdev;
1045 unsigned char __pad3[4];
1047 unsigned int st_blksize;
1048 unsigned long long st_blocks;
1049 unsigned int st_atime;
1050 unsigned int st_atime_nsec;
1051 unsigned int st_mtime;
1052 unsigned int st_mtime_nsec;
1053 unsigned int st_ctime;
1054 unsigned int st_ctime_nsec;
1055 unsigned long long st_ino;
1056 } __attribute__((packed));
1057 # define HAVE_STAT64 1
1058 # define STAT64_SIZE 96
1063 printstat64(struct tcb *tcp, long addr)
1066 struct stat statbuf;
1068 struct stat64 statbuf;
1072 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1079 if (syserror(tcp) || !verbose(tcp)) {
1080 tprintf("%#lx", addr);
1084 #if defined(SPARC) || defined(SPARC64)
1085 if (current_personality == 1) {
1086 printstatsol(tcp, addr);
1090 else if (current_personality == 2) {
1091 printstat_sparc64(tcp, addr);
1095 #endif /* SPARC[64] */
1098 if (current_personality != 1) {
1099 printstat(tcp, addr);
1104 if (umove(tcp, addr, &statbuf) < 0) {
1110 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1111 (unsigned long) major(statbuf.st_dev),
1112 (unsigned long) minor(statbuf.st_dev),
1113 (unsigned long long) statbuf.st_ino,
1114 sprintmode(statbuf.st_mode));
1115 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1116 (unsigned long) statbuf.st_nlink,
1117 (unsigned long) statbuf.st_uid,
1118 (unsigned long) statbuf.st_gid);
1119 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1120 tprintf("st_blksize=%lu, ",
1121 (unsigned long) statbuf.st_blksize);
1122 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1123 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
1124 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1125 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
1128 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1129 switch (statbuf.st_mode & S_IFMT) {
1130 case S_IFCHR: case S_IFBLK:
1131 #ifdef HAVE_STRUCT_STAT_ST_RDEV
1132 tprintf("st_rdev=makedev(%lu, %lu), ",
1133 (unsigned long) major(statbuf.st_rdev),
1134 (unsigned long) minor(statbuf.st_rdev));
1135 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
1136 tprintf("st_size=makedev(%lu, %lu), ",
1137 (unsigned long) major(statbuf.st_size),
1138 (unsigned long) minor(statbuf.st_size));
1139 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
1142 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1146 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1147 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1148 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1149 #if HAVE_STRUCT_STAT_ST_FLAGS
1150 tprints(", st_flags=");
1151 printflags(fileflags, statbuf.st_flags, "UF_???");
1153 #if HAVE_STRUCT_STAT_ST_ACLCNT
1154 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1156 #if HAVE_STRUCT_STAT_ST_LEVEL
1157 tprintf(", st_level=%ld", statbuf.st_level);
1159 #if HAVE_STRUCT_STAT_ST_FSTYPE
1160 tprintf(", st_fstype=%.*s",
1161 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1163 #if HAVE_STRUCT_STAT_ST_GEN
1164 tprintf(", st_gen=%u", statbuf.st_gen);
1171 #endif /* HAVE_STAT64 */
1173 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1175 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
1177 newbuf->st_dev = oldbuf->st_dev;
1178 newbuf->st_ino = oldbuf->st_ino;
1179 newbuf->st_mode = oldbuf->st_mode;
1180 newbuf->st_nlink = oldbuf->st_nlink;
1181 newbuf->st_uid = oldbuf->st_uid;
1182 newbuf->st_gid = oldbuf->st_gid;
1183 newbuf->st_rdev = oldbuf->st_rdev;
1184 newbuf->st_size = oldbuf->st_size;
1185 newbuf->st_atime = oldbuf->st_atime;
1186 newbuf->st_mtime = oldbuf->st_mtime;
1187 newbuf->st_ctime = oldbuf->st_ctime;
1188 newbuf->st_blksize = 0; /* not supported in old_stat */
1189 newbuf->st_blocks = 0; /* not supported in old_stat */
1193 printoldstat(struct tcb *tcp, long addr)
1195 struct __old_kernel_stat statbuf;
1196 struct stat newstatbuf;
1202 if (syserror(tcp) || !verbose(tcp)) {
1203 tprintf("%#lx", addr);
1207 # if defined(SPARC) || defined(SPARC64)
1208 if (current_personality == 1) {
1209 printstatsol(tcp, addr);
1214 if (umove(tcp, addr, &statbuf) < 0) {
1219 convertoldstat(&statbuf, &newstatbuf);
1220 realprintstat(tcp, &newstatbuf);
1225 sys_stat(struct tcb *tcp)
1227 if (entering(tcp)) {
1228 printpath(tcp, tcp->u_arg[0]);
1231 printstat(tcp, tcp->u_arg[1]);
1238 printstat64_x32(struct tcb *tcp, long addr)
1240 struct stat64 statbuf;
1246 if (syserror(tcp) || !verbose(tcp)) {
1247 tprintf("%#lx", addr);
1251 if (umove(tcp, addr, &statbuf) < 0) {
1257 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1258 (unsigned long) major(statbuf.st_dev),
1259 (unsigned long) minor(statbuf.st_dev),
1260 (unsigned long long) statbuf.st_ino,
1261 sprintmode(statbuf.st_mode));
1262 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1263 (unsigned long) statbuf.st_nlink,
1264 (unsigned long) statbuf.st_uid,
1265 (unsigned long) statbuf.st_gid);
1266 tprintf("st_blksize=%lu, ",
1267 (unsigned long) statbuf.st_blksize);
1268 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1271 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1272 switch (statbuf.st_mode & S_IFMT) {
1273 case S_IFCHR: case S_IFBLK:
1274 tprintf("st_rdev=makedev(%lu, %lu), ",
1275 (unsigned long) major(statbuf.st_rdev),
1276 (unsigned long) minor(statbuf.st_rdev));
1279 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1283 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1284 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1285 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1294 sys_stat64(struct tcb *tcp)
1297 if (entering(tcp)) {
1298 printpath(tcp, tcp->u_arg[0]);
1302 printstat64_x32(tcp, tcp->u_arg[1]);
1304 printstat64(tcp, tcp->u_arg[1]);
1309 return printargs(tcp);
1313 #ifndef AT_SYMLINK_NOFOLLOW
1314 # define AT_SYMLINK_NOFOLLOW 0x100
1316 #ifndef AT_REMOVEDIR
1317 # define AT_REMOVEDIR 0x200
1319 #ifndef AT_SYMLINK_FOLLOW
1320 # define AT_SYMLINK_FOLLOW 0x400
1322 #ifndef AT_NO_AUTOMOUNT
1323 # define AT_NO_AUTOMOUNT 0x800
1325 #ifndef AT_EMPTY_PATH
1326 # define AT_EMPTY_PATH 0x1000
1329 static const struct xlat at_flags[] = {
1330 XLAT(AT_SYMLINK_NOFOLLOW),
1332 XLAT(AT_SYMLINK_FOLLOW),
1333 XLAT(AT_NO_AUTOMOUNT),
1334 XLAT(AT_EMPTY_PATH),
1339 sys_newfstatat(struct tcb *tcp)
1341 if (entering(tcp)) {
1342 print_dirfd(tcp, tcp->u_arg[0]);
1343 printpath(tcp, tcp->u_arg[1]);
1347 if (current_personality == 0)
1348 printstat(tcp, tcp->u_arg[2]);
1350 printstat64(tcp, tcp->u_arg[2]);
1351 #elif defined HAVE_STAT64
1352 printstat64(tcp, tcp->u_arg[2]);
1354 printstat(tcp, tcp->u_arg[2]);
1357 printflags(at_flags, tcp->u_arg[3], "AT_???");
1362 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1364 sys_oldstat(struct tcb *tcp)
1366 if (entering(tcp)) {
1367 printpath(tcp, tcp->u_arg[0]);
1370 printoldstat(tcp, tcp->u_arg[1]);
1377 sys_fstat(struct tcb *tcp)
1379 if (entering(tcp)) {
1380 printfd(tcp, tcp->u_arg[0]);
1383 printstat(tcp, tcp->u_arg[1]);
1389 sys_fstat64(struct tcb *tcp)
1392 if (entering(tcp)) {
1393 printfd(tcp, tcp->u_arg[0]);
1397 printstat64_x32(tcp, tcp->u_arg[1]);
1399 printstat64(tcp, tcp->u_arg[1]);
1404 return printargs(tcp);
1408 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1410 sys_oldfstat(struct tcb *tcp)
1412 if (entering(tcp)) {
1413 printfd(tcp, tcp->u_arg[0]);
1416 printoldstat(tcp, tcp->u_arg[1]);
1422 #if defined(SPARC) || defined(SPARC64)
1425 sys_xstat(struct tcb *tcp)
1427 if (entering(tcp)) {
1428 tprintf("%ld, ", tcp->u_arg[0]);
1429 printpath(tcp, tcp->u_arg[1]);
1433 if (tcp->u_arg[0] == _STAT64_VER)
1434 printstat64(tcp, tcp->u_arg[2]);
1437 printstat(tcp, tcp->u_arg[2]);
1443 sys_fxstat(struct tcb *tcp)
1446 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1449 if (tcp->u_arg[0] == _STAT64_VER)
1450 printstat64(tcp, tcp->u_arg[2]);
1453 printstat(tcp, tcp->u_arg[2]);
1459 sys_lxstat(struct tcb *tcp)
1461 if (entering(tcp)) {
1462 tprintf("%ld, ", tcp->u_arg[0]);
1463 printpath(tcp, tcp->u_arg[1]);
1467 if (tcp->u_arg[0] == _STAT64_VER)
1468 printstat64(tcp, tcp->u_arg[2]);
1471 printstat(tcp, tcp->u_arg[2]);
1477 sys_xmknod(struct tcb *tcp)
1479 int mode = tcp->u_arg[2];
1481 if (entering(tcp)) {
1482 tprintf("%ld, ", tcp->u_arg[0]);
1483 printpath(tcp, tcp->u_arg[1]);
1484 tprintf(", %s", sprintmode(mode));
1485 switch (mode & S_IFMT) {
1486 case S_IFCHR: case S_IFBLK:
1487 tprintf(", makedev(%lu, %lu)",
1488 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1489 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1498 # ifdef HAVE_SYS_ACL_H
1500 # include <sys/acl.h>
1502 static const struct xlat aclcmds[] = {
1525 sys_acl(struct tcb *tcp)
1527 if (entering(tcp)) {
1528 printpath(tcp, tcp->u_arg[0]);
1530 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1531 tprintf(", %ld", tcp->u_arg[2]);
1533 * FIXME - dump out the list of aclent_t's pointed to
1534 * by "tcp->u_arg[3]" if it's not NULL.
1537 tprintf(", %#lx", tcp->u_arg[3]);
1545 sys_facl(struct tcb *tcp)
1547 if (entering(tcp)) {
1548 tprintf("%ld, ", tcp->u_arg[0]);
1549 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1550 tprintf(", %ld", tcp->u_arg[2]);
1552 * FIXME - dump out the list of aclent_t's pointed to
1553 * by "tcp->u_arg[3]" if it's not NULL.
1556 tprintf(", %#lx", tcp->u_arg[3]);
1563 static const struct xlat aclipc[] = {
1577 sys_aclipc(struct tcb *tcp)
1579 if (entering(tcp)) {
1580 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1581 tprintf(", %#lx, ", tcp->u_arg[1]);
1582 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1583 tprintf(", %ld", tcp->u_arg[3]);
1585 * FIXME - dump out the list of aclent_t's pointed to
1586 * by "tcp->u_arg[4]" if it's not NULL.
1589 tprintf(", %#lx", tcp->u_arg[4]);
1596 # endif /* HAVE_SYS_ACL_H */
1598 #endif /* SPARC[64] */
1600 static const struct xlat fsmagic[] = {
1601 { 0x73757245, "CODA_SUPER_MAGIC" },
1602 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1603 { 0x1373, "DEVFS_SUPER_MAGIC" },
1604 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1605 { 0x414A53, "EFS_SUPER_MAGIC" },
1606 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1607 { 0xef53, "EXT2_SUPER_MAGIC" },
1608 { 0x137d, "EXT_SUPER_MAGIC" },
1609 { 0xf995e849, "HPFS_SUPER_MAGIC" },
1610 { 0x9660, "ISOFS_SUPER_MAGIC" },
1611 { 0x137f, "MINIX_SUPER_MAGIC" },
1612 { 0x138f, "MINIX_SUPER_MAGIC2" },
1613 { 0x2468, "MINIX2_SUPER_MAGIC" },
1614 { 0x2478, "MINIX2_SUPER_MAGIC2" },
1615 { 0x4d44, "MSDOS_SUPER_MAGIC" },
1616 { 0x564c, "NCP_SUPER_MAGIC" },
1617 { 0x6969, "NFS_SUPER_MAGIC" },
1618 { 0x9fa0, "PROC_SUPER_MAGIC" },
1619 { 0x002f, "QNX4_SUPER_MAGIC" },
1620 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1621 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1622 { 0x517b, "SMB_SUPER_MAGIC" },
1623 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1624 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1625 { 0x00011954, "UFS_MAGIC" },
1626 { 0x54190100, "UFS_CIGAM" },
1627 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
1628 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
1629 { 0x62656572, "SYSFS_MAGIC" },
1634 sprintfstype(int magic)
1636 static char buf[32];
1639 s = xlookup(fsmagic, magic);
1641 sprintf(buf, "\"%s\"", s);
1644 sprintf(buf, "%#x", magic);
1649 printstatfs(struct tcb *tcp, long addr)
1651 struct statfs statbuf;
1653 if (syserror(tcp) || !verbose(tcp)) {
1654 tprintf("%#lx", addr);
1657 if (umove(tcp, addr, &statbuf) < 0) {
1663 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1664 sprintfstype(statbuf.f_type),
1665 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1666 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1667 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
1668 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1671 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1672 sprintfstype(statbuf.f_type),
1673 (unsigned long)statbuf.f_bsize,
1674 (unsigned long)statbuf.f_blocks,
1675 (unsigned long)statbuf.f_bfree);
1676 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1677 (unsigned long)statbuf.f_bavail,
1678 (unsigned long)statbuf.f_files,
1679 (unsigned long)statbuf.f_ffree,
1680 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1681 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1683 #ifdef _STATFS_F_FRSIZE
1684 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1690 sys_statfs(struct tcb *tcp)
1692 if (entering(tcp)) {
1693 printpath(tcp, tcp->u_arg[0]);
1696 printstatfs(tcp, tcp->u_arg[1]);
1702 sys_fstatfs(struct tcb *tcp)
1704 if (entering(tcp)) {
1705 printfd(tcp, tcp->u_arg[0]);
1708 printstatfs(tcp, tcp->u_arg[1]);
1713 #if defined HAVE_STATFS64
1715 printstatfs64(struct tcb *tcp, long addr)
1717 struct statfs64 statbuf;
1719 if (syserror(tcp) || !verbose(tcp)) {
1720 tprintf("%#lx", addr);
1723 if (umove(tcp, addr, &statbuf) < 0) {
1727 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
1728 sprintfstype(statbuf.f_type),
1729 (unsigned long long)statbuf.f_bsize,
1730 (unsigned long long)statbuf.f_blocks,
1731 (unsigned long long)statbuf.f_bfree);
1732 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1733 (unsigned long long)statbuf.f_bavail,
1734 (unsigned long long)statbuf.f_files,
1735 (unsigned long long)statbuf.f_ffree,
1736 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1737 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1738 #ifdef _STATFS_F_FRSIZE
1739 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
1741 #ifdef _STATFS_F_FLAGS
1742 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1747 struct compat_statfs64 {
1759 uint32_t f_spare[4];
1761 #if defined(X86_64) || defined(IA64)
1762 __attribute__ ((packed, aligned(4)))
1767 printcompat_statfs64(struct tcb *tcp, long addr)
1769 struct compat_statfs64 statbuf;
1771 if (syserror(tcp) || !verbose(tcp)) {
1772 tprintf("%#lx", addr);
1775 if (umove(tcp, addr, &statbuf) < 0) {
1779 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1780 sprintfstype(statbuf.f_type),
1781 (unsigned long)statbuf.f_bsize,
1782 (unsigned long long)statbuf.f_blocks,
1783 (unsigned long long)statbuf.f_bfree);
1784 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1785 (unsigned long long)statbuf.f_bavail,
1786 (unsigned long long)statbuf.f_files,
1787 (unsigned long long)statbuf.f_ffree,
1788 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1789 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1790 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1791 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
1795 sys_statfs64(struct tcb *tcp)
1797 if (entering(tcp)) {
1798 printpath(tcp, tcp->u_arg[0]);
1799 tprintf(", %lu, ", tcp->u_arg[1]);
1801 if (tcp->u_arg[1] == sizeof(struct statfs64))
1802 printstatfs64(tcp, tcp->u_arg[2]);
1803 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1804 printcompat_statfs64(tcp, tcp->u_arg[2]);
1812 sys_fstatfs64(struct tcb *tcp)
1814 if (entering(tcp)) {
1815 printfd(tcp, tcp->u_arg[0]);
1816 tprintf(", %lu, ", tcp->u_arg[1]);
1818 if (tcp->u_arg[1] == sizeof(struct statfs64))
1819 printstatfs64(tcp, tcp->u_arg[2]);
1820 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1821 printcompat_statfs64(tcp, tcp->u_arg[2]);
1831 osf_statfs(struct tcb *tcp)
1833 if (entering(tcp)) {
1834 printpath(tcp, tcp->u_arg[0]);
1837 printstatfs(tcp, tcp->u_arg[1]);
1838 tprintf(", %lu", tcp->u_arg[2]);
1844 osf_fstatfs(struct tcb *tcp)
1846 if (entering(tcp)) {
1847 tprintf("%lu, ", tcp->u_arg[0]);
1849 printstatfs(tcp, tcp->u_arg[1]);
1850 tprintf(", %lu", tcp->u_arg[2]);
1858 sys_chdir(struct tcb *tcp)
1860 if (entering(tcp)) {
1861 printpath(tcp, tcp->u_arg[0]);
1867 decode_mkdir(struct tcb *tcp, int offset)
1869 if (entering(tcp)) {
1870 printpath(tcp, tcp->u_arg[offset]);
1871 tprintf(", %#lo", tcp->u_arg[offset + 1]);
1877 sys_mkdir(struct tcb *tcp)
1879 return decode_mkdir(tcp, 0);
1883 sys_mkdirat(struct tcb *tcp)
1886 print_dirfd(tcp, tcp->u_arg[0]);
1887 return decode_mkdir(tcp, 1);
1891 sys_link(struct tcb *tcp)
1893 if (entering(tcp)) {
1894 printpath(tcp, tcp->u_arg[0]);
1896 printpath(tcp, tcp->u_arg[1]);
1902 sys_linkat(struct tcb *tcp)
1904 if (entering(tcp)) {
1905 print_dirfd(tcp, tcp->u_arg[0]);
1906 printpath(tcp, tcp->u_arg[1]);
1908 print_dirfd(tcp, tcp->u_arg[2]);
1909 printpath(tcp, tcp->u_arg[3]);
1911 printflags(at_flags, tcp->u_arg[4], "AT_???");
1917 sys_unlinkat(struct tcb *tcp)
1919 if (entering(tcp)) {
1920 print_dirfd(tcp, tcp->u_arg[0]);
1921 printpath(tcp, tcp->u_arg[1]);
1923 printflags(at_flags, tcp->u_arg[2], "AT_???");
1929 sys_symlinkat(struct tcb *tcp)
1931 if (entering(tcp)) {
1932 printpath(tcp, tcp->u_arg[0]);
1934 print_dirfd(tcp, tcp->u_arg[1]);
1935 printpath(tcp, tcp->u_arg[2]);
1941 decode_readlink(struct tcb *tcp, int offset)
1943 if (entering(tcp)) {
1944 printpath(tcp, tcp->u_arg[offset]);
1948 tprintf("%#lx", tcp->u_arg[offset + 1]);
1950 /* Used to use printpathn(), but readlink
1951 * neither includes NUL in the returned count,
1952 * nor actually writes it into memory.
1953 * printpathn() would decide on printing
1954 * "..." continuation based on garbage
1955 * past return buffer's end.
1957 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1958 tprintf(", %lu", tcp->u_arg[offset + 2]);
1964 sys_readlink(struct tcb *tcp)
1966 return decode_readlink(tcp, 0);
1970 sys_readlinkat(struct tcb *tcp)
1973 print_dirfd(tcp, tcp->u_arg[0]);
1974 return decode_readlink(tcp, 1);
1978 sys_renameat(struct tcb *tcp)
1980 if (entering(tcp)) {
1981 print_dirfd(tcp, tcp->u_arg[0]);
1982 printpath(tcp, tcp->u_arg[1]);
1984 print_dirfd(tcp, tcp->u_arg[2]);
1985 printpath(tcp, tcp->u_arg[3]);
1991 sys_chown(struct tcb *tcp)
1993 if (entering(tcp)) {
1994 printpath(tcp, tcp->u_arg[0]);
1995 printuid(", ", tcp->u_arg[1]);
1996 printuid(", ", tcp->u_arg[2]);
2002 sys_fchownat(struct tcb *tcp)
2004 if (entering(tcp)) {
2005 print_dirfd(tcp, tcp->u_arg[0]);
2006 printpath(tcp, tcp->u_arg[1]);
2007 printuid(", ", tcp->u_arg[2]);
2008 printuid(", ", tcp->u_arg[3]);
2010 printflags(at_flags, tcp->u_arg[4], "AT_???");
2016 sys_fchown(struct tcb *tcp)
2018 if (entering(tcp)) {
2019 printfd(tcp, tcp->u_arg[0]);
2020 printuid(", ", tcp->u_arg[1]);
2021 printuid(", ", tcp->u_arg[2]);
2027 decode_chmod(struct tcb *tcp, int offset)
2029 if (entering(tcp)) {
2030 printpath(tcp, tcp->u_arg[offset]);
2031 tprintf(", %#lo", tcp->u_arg[offset + 1]);
2037 sys_chmod(struct tcb *tcp)
2039 return decode_chmod(tcp, 0);
2043 sys_fchmodat(struct tcb *tcp)
2046 print_dirfd(tcp, tcp->u_arg[0]);
2047 return decode_chmod(tcp, 1);
2051 sys_fchmod(struct tcb *tcp)
2053 if (entering(tcp)) {
2054 printfd(tcp, tcp->u_arg[0]);
2055 tprintf(", %#lo", tcp->u_arg[1]);
2062 sys_osf_utimes(struct tcb *tcp)
2064 if (entering(tcp)) {
2065 printpath(tcp, tcp->u_arg[0]);
2067 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2074 decode_utimes(struct tcb *tcp, int offset, int special)
2076 if (entering(tcp)) {
2077 printpath(tcp, tcp->u_arg[offset]);
2079 if (tcp->u_arg[offset + 1] == 0)
2083 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2084 BITNESS_CURRENT, special);
2086 printtv_bitness(tcp, tcp->u_arg[offset + 1]
2087 + sizeof(struct timeval),
2088 BITNESS_CURRENT, special);
2096 sys_utimes(struct tcb *tcp)
2098 return decode_utimes(tcp, 0, 0);
2102 sys_futimesat(struct tcb *tcp)
2105 print_dirfd(tcp, tcp->u_arg[0]);
2106 return decode_utimes(tcp, 1, 0);
2110 sys_utimensat(struct tcb *tcp)
2112 if (entering(tcp)) {
2113 print_dirfd(tcp, tcp->u_arg[0]);
2114 decode_utimes(tcp, 1, 1);
2116 printflags(at_flags, tcp->u_arg[3], "AT_???");
2122 sys_utime(struct tcb *tcp)
2127 long paranoia_for_huge_wordsize[4];
2131 if (entering(tcp)) {
2132 printpath(tcp, tcp->u_arg[0]);
2135 wordsize = current_wordsize;
2138 else if (!verbose(tcp))
2139 tprintf("%#lx", tcp->u_arg[1]);
2140 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
2142 else if (wordsize == sizeof u.utl[0]) {
2143 tprintf("[%s,", sprinttime(u.utl[0]));
2144 tprintf(" %s]", sprinttime(u.utl[1]));
2146 else if (wordsize == sizeof u.uti[0]) {
2147 tprintf("[%s,", sprinttime(u.uti[0]));
2148 tprintf(" %s]", sprinttime(u.uti[1]));
2151 tprintf("<decode error: unsupported wordsize %d>",
2158 decode_mknod(struct tcb *tcp, int offset)
2160 int mode = tcp->u_arg[offset + 1];
2162 if (entering(tcp)) {
2163 printpath(tcp, tcp->u_arg[offset]);
2164 tprintf(", %s", sprintmode(mode));
2165 switch (mode & S_IFMT) {
2168 #if defined(SPARC) || defined(SPARC64)
2169 if (current_personality == 1)
2170 tprintf(", makedev(%lu, %lu)",
2171 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2172 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
2175 tprintf(", makedev(%lu, %lu)",
2176 (unsigned long) major(tcp->u_arg[offset + 2]),
2177 (unsigned long) minor(tcp->u_arg[offset + 2]));
2187 sys_mknod(struct tcb *tcp)
2189 return decode_mknod(tcp, 0);
2193 sys_mknodat(struct tcb *tcp)
2196 print_dirfd(tcp, tcp->u_arg[0]);
2197 return decode_mknod(tcp, 1);
2201 print_old_dirent(struct tcb *tcp, long addr)
2204 typedef struct kernel_dirent old_dirent_t;
2209 unsigned short d_reclen;
2215 if (!verbose(tcp) || umove(tcp, addr, &d) < 0) {
2216 tprintf("%#lx", addr);
2220 tprintf("{d_ino=%lu, d_off=%lu, d_reclen=%u, d_name=\"",
2221 (unsigned long) d.d_ino, (unsigned long) d.d_off, d.d_reclen);
2222 if (d.d_reclen > 256)
2224 printpathn(tcp, addr + offsetof(old_dirent_t, d_name), d.d_reclen);
2229 sys_readdir(struct tcb *tcp)
2231 if (entering(tcp)) {
2232 printfd(tcp, tcp->u_arg[0]);
2235 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2236 tprintf("%#lx", tcp->u_arg[1]);
2238 print_old_dirent(tcp, tcp->u_arg[1]);
2239 /* Not much point in printing this out, it is always 1. */
2240 if (tcp->u_arg[2] != 1)
2241 tprintf(", %lu", tcp->u_arg[2]);
2246 static const struct xlat direnttypes[] = {
2260 sys_getdents(struct tcb *tcp)
2262 int i, len, dents = 0;
2265 if (entering(tcp)) {
2266 printfd(tcp, tcp->u_arg[0]);
2270 if (syserror(tcp) || !verbose(tcp)) {
2271 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2275 /* Beware of insanely large or negative values in tcp->u_rval */
2276 if (tcp->u_rval > 1024*1024)
2278 if (tcp->u_rval < 0)
2280 buf = len ? malloc(len) : NULL;
2282 die_out_of_memory();
2283 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2284 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2290 for (i = 0; i < len;) {
2291 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2293 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2294 i ? " " : "", d->d_ino, d->d_off);
2295 tprintf("d_reclen=%u, d_name=\"%s\", d_type=",
2296 d->d_reclen, d->d_name);
2297 printxval(direnttypes, buf[i + d->d_reclen - 1], "DT_???");
2301 tprints("/* d_reclen == 0, problem here */");
2310 tprintf("/* %u entries */", dents);
2311 tprintf(", %lu", tcp->u_arg[2]);
2317 sys_getdents64(struct tcb *tcp)
2319 int i, len, dents = 0;
2322 if (entering(tcp)) {
2323 printfd(tcp, tcp->u_arg[0]);
2327 if (syserror(tcp) || !verbose(tcp)) {
2328 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2333 /* Beware of insanely large or negative tcp->u_rval */
2334 if (tcp->u_rval > 1024*1024)
2336 if (tcp->u_rval < 0)
2338 buf = len ? malloc(len) : NULL;
2340 die_out_of_memory();
2342 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2343 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2349 for (i = 0; i < len;) {
2350 struct dirent64 *d = (struct dirent64 *) &buf[i];
2352 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
2357 printxval(direnttypes, d->d_type, "DT_???");
2359 tprintf("d_reclen=%u, d_name=\"%s\"}",
2360 d->d_reclen, d->d_name);
2363 tprints("/* d_reclen == 0, problem here */");
2372 tprintf("/* %u entries */", dents);
2373 tprintf(", %lu", tcp->u_arg[2]);
2379 sys_getcwd(struct tcb *tcp)
2383 tprintf("%#lx", tcp->u_arg[0]);
2385 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2386 tprintf(", %lu", tcp->u_arg[1]);
2391 #ifdef HAVE_SYS_ASYNCH_H
2394 sys_aioread(struct tcb *tcp)
2396 struct aio_result_t res;
2398 if (entering(tcp)) {
2399 tprintf("%lu, ", tcp->u_arg[0]);
2402 tprintf("%#lx", tcp->u_arg[1]);
2404 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2405 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2406 printxval(whence, tcp->u_arg[4], "L_???");
2407 if (syserror(tcp) || tcp->u_arg[5] == 0
2408 || umove(tcp, tcp->u_arg[5], &res) < 0)
2409 tprintf(", %#lx", tcp->u_arg[5]);
2411 tprintf(", {aio_return %d aio_errno %d}",
2412 res.aio_return, res.aio_errno);
2418 sys_aiowrite(struct tcb *tcp)
2420 struct aio_result_t res;
2422 if (entering(tcp)) {
2423 tprintf("%lu, ", tcp->u_arg[0]);
2424 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2425 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2426 printxval(whence, tcp->u_arg[4], "L_???");
2429 if (tcp->u_arg[5] == 0)
2431 else if (syserror(tcp)
2432 || umove(tcp, tcp->u_arg[5], &res) < 0)
2433 tprintf(", %#lx", tcp->u_arg[5]);
2435 tprintf(", {aio_return %d aio_errno %d}",
2436 res.aio_return, res.aio_errno);
2442 sys_aiowait(struct tcb *tcp)
2445 printtv(tcp, tcp->u_arg[0]);
2450 sys_aiocancel(struct tcb *tcp)
2452 struct aio_result_t res;
2455 if (tcp->u_arg[0] == 0)
2457 else if (syserror(tcp)
2458 || umove(tcp, tcp->u_arg[0], &res) < 0)
2459 tprintf("%#lx", tcp->u_arg[0]);
2461 tprintf("{aio_return %d aio_errno %d}",
2462 res.aio_return, res.aio_errno);
2467 #endif /* HAVE_SYS_ASYNCH_H */
2469 static const struct xlat xattrflags[] = {
2472 XLAT(XATTR_REPLACE),
2478 print_xattr_val(struct tcb *tcp, int failed,
2480 unsigned long insize,
2486 unsigned long capacity = 4 * size + 1;
2487 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2488 if (buf == NULL || /* probably a bogus size argument */
2489 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2493 unsigned char *out = buf;
2494 unsigned char *in = &buf[3 * size];
2496 for (i = 0; i < size; ++i) {
2497 if (in[i] >= ' ' && in[i] <= 0x7e)
2500 #define tohex(n) "0123456789abcdef"[n]
2503 *out++ = tohex(in[i] / 16);
2504 *out++ = tohex(in[i] % 16);
2507 /* Don't print terminating NUL if there is one. */
2508 if (i > 0 && in[i - 1] == '\0')
2511 tprintf(", \"%s\", %ld", buf, insize);
2516 tprintf(", 0x%lx, %ld", arg, insize);
2520 sys_setxattr(struct tcb *tcp)
2522 if (entering(tcp)) {
2523 printpath(tcp, tcp->u_arg[0]);
2525 printstr(tcp, tcp->u_arg[1], -1);
2526 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2528 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2534 sys_fsetxattr(struct tcb *tcp)
2536 if (entering(tcp)) {
2537 printfd(tcp, tcp->u_arg[0]);
2539 printstr(tcp, tcp->u_arg[1], -1);
2540 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2542 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2548 sys_getxattr(struct tcb *tcp)
2550 if (entering(tcp)) {
2551 printpath(tcp, tcp->u_arg[0]);
2553 printstr(tcp, tcp->u_arg[1], -1);
2555 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2562 sys_fgetxattr(struct tcb *tcp)
2564 if (entering(tcp)) {
2565 printfd(tcp, tcp->u_arg[0]);
2567 printstr(tcp, tcp->u_arg[1], -1);
2569 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2576 print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2578 if (syserror(tcp)) {
2579 tprintf("%#lx", addr);
2585 (size < tcp->u_rval) ? size : tcp->u_rval;
2586 printstr(tcp, addr, len);
2589 tprintf(", %lu", size);
2593 sys_listxattr(struct tcb *tcp)
2595 if (entering(tcp)) {
2596 printpath(tcp, tcp->u_arg[0]);
2599 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2605 sys_flistxattr(struct tcb *tcp)
2607 if (entering(tcp)) {
2608 printfd(tcp, tcp->u_arg[0]);
2611 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2617 sys_removexattr(struct tcb *tcp)
2619 if (entering(tcp)) {
2620 printpath(tcp, tcp->u_arg[0]);
2622 printstr(tcp, tcp->u_arg[1], -1);
2628 sys_fremovexattr(struct tcb *tcp)
2630 if (entering(tcp)) {
2631 printfd(tcp, tcp->u_arg[0]);
2633 printstr(tcp, tcp->u_arg[1], -1);
2638 static const struct xlat advise[] = {
2639 XLAT(POSIX_FADV_NORMAL),
2640 XLAT(POSIX_FADV_RANDOM),
2641 XLAT(POSIX_FADV_SEQUENTIAL),
2642 XLAT(POSIX_FADV_WILLNEED),
2643 XLAT(POSIX_FADV_DONTNEED),
2644 XLAT(POSIX_FADV_NOREUSE),
2649 sys_fadvise64(struct tcb *tcp)
2651 if (entering(tcp)) {
2653 printfd(tcp, tcp->u_arg[0]);
2654 argn = printllval(tcp, ", %lld", 1);
2655 tprintf(", %ld, ", tcp->u_arg[argn++]);
2656 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2662 sys_fadvise64_64(struct tcb *tcp)
2664 if (entering(tcp)) {
2666 printfd(tcp, tcp->u_arg[0]);
2667 argn = printllval(tcp, ", %lld, ", 1);
2668 argn = printllval(tcp, "%lld, ", argn);
2669 #if defined __ARM_EABI__ || defined AARCH64 || defined POWERPC || defined XTENSA
2670 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
2672 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2678 static const struct xlat sync_file_range_flags[] = {
2679 XLAT(SYNC_FILE_RANGE_WAIT_BEFORE),
2680 XLAT(SYNC_FILE_RANGE_WRITE),
2681 XLAT(SYNC_FILE_RANGE_WAIT_AFTER),
2686 sys_sync_file_range(struct tcb *tcp)
2688 if (entering(tcp)) {
2690 printfd(tcp, tcp->u_arg[0]);
2691 argn = printllval(tcp, ", %lld, ", 1);
2692 argn = printllval(tcp, "%lld, ", argn);
2693 printflags(sync_file_range_flags, tcp->u_arg[argn],
2694 "SYNC_FILE_RANGE_???");
2700 sys_sync_file_range2(struct tcb *tcp)
2702 if (entering(tcp)) {
2704 printfd(tcp, tcp->u_arg[0]);
2705 printflags(sync_file_range_flags, 1,
2706 "SYNC_FILE_RANGE_???");
2707 argn = printllval(tcp, ", %lld, ", 2);
2708 argn = printllval(tcp, "%lld, ", argn);
2714 sys_fallocate(struct tcb *tcp)
2716 if (entering(tcp)) {
2718 printfd(tcp, tcp->u_arg[0]); /* fd */
2719 tprintf(", %#lo, ", tcp->u_arg[1]); /* mode */
2720 argn = printllval(tcp, "%llu, ", 2); /* offset */
2721 printllval(tcp, "%llu", argn); /* len */
2726 #ifndef SWAP_FLAG_PREFER
2727 # define SWAP_FLAG_PREFER 0x8000
2729 #ifndef SWAP_FLAG_DISCARD
2730 # define SWAP_FLAG_DISCARD 0x10000
2732 static const struct xlat swap_flags[] = {
2733 XLAT(SWAP_FLAG_PREFER),
2734 XLAT(SWAP_FLAG_DISCARD),
2739 sys_swapon(struct tcb *tcp)
2741 if (entering(tcp)) {
2742 int flags = tcp->u_arg[1];
2743 printpath(tcp, tcp->u_arg[0]);
2745 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2747 if (flags & SWAP_FLAG_PREFER)
2748 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);