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. */
185 #ifdef HAVE_SYS_VFS_H
186 # include <sys/vfs.h>
188 #ifdef HAVE_LINUX_XATTR_H
189 # include <linux/xattr.h>
191 # define XATTR_CREATE 1
192 # define XATTR_REPLACE 2
195 #ifdef MAJOR_IN_SYSMACROS
196 # include <sys/sysmacros.h>
199 #ifdef MAJOR_IN_MKDEV
200 # include <sys/mkdev.h>
203 #ifdef HAVE_SYS_ASYNCH_H
204 # include <sys/asynch.h>
207 struct kernel_dirent {
210 unsigned short d_reclen;
214 const struct xlat open_access_modes[] = {
224 const struct xlat open_mode_flags[] = {
243 #if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
253 # if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
256 # define O_LARGEFILE 0x40000
257 # elif defined X86_64 || defined S390X
258 # define O_LARGEFILE 0100000
329 # define AT_FDCWD -100
332 /* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
333 * extension to get the right value. We do this by declaring fd as int here.
336 print_dirfd(struct tcb *tcp, int fd)
339 tprints("AT_FDCWD, ");
347 * low bits of the open(2) flags define access mode,
348 * other bits are real flags.
351 sprint_open_modes(mode_t flags)
353 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
357 const struct xlat *x;
360 p = stpcpy(outstr, "flags");
361 str = xlookup(open_access_modes, flags & 3);
371 for (x = open_mode_flags; x->str; x++) {
372 if ((flags & x->val) == x->val) {
374 p = stpcpy(p, x->str);
381 /* flags is still nonzero */
383 sprintf(p, "%#x", flags);
388 tprint_open_modes(mode_t flags)
390 tprints(sprint_open_modes(flags) + sizeof("flags"));
394 decode_open(struct tcb *tcp, int offset)
397 printpath(tcp, tcp->u_arg[offset]);
400 tprint_open_modes(tcp->u_arg[offset + 1]);
401 if (tcp->u_arg[offset + 1] & O_CREAT) {
403 tprintf(", %#lo", tcp->u_arg[offset + 2]);
410 sys_open(struct tcb *tcp)
412 return decode_open(tcp, 0);
416 sys_openat(struct tcb *tcp)
419 print_dirfd(tcp, tcp->u_arg[0]);
420 return decode_open(tcp, 1);
423 #if defined(SPARC) || defined(SPARC64)
424 static const struct xlat openmodessol[] = {
428 { 0x80, "O_NONBLOCK" },
430 { 0x100, "O_CREAT" },
431 { 0x200, "O_TRUNC" },
433 { 0x800, "O_NOCTTY" },
436 { 0x8000, "O_RSYNC" },
438 { 0x1000, "O_PRIV" },
443 solaris_open(struct tcb *tcp)
446 printpath(tcp, tcp->u_arg[0]);
449 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
450 if (tcp->u_arg[1] & 0x100) {
452 tprintf(", %#lo", tcp->u_arg[2]);
461 sys_creat(struct tcb *tcp)
464 printpath(tcp, tcp->u_arg[0]);
465 tprintf(", %#lo", tcp->u_arg[1]);
470 static const struct xlat access_flags[] = {
485 decode_access(struct tcb *tcp, int offset)
488 printpath(tcp, tcp->u_arg[offset]);
490 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
496 sys_access(struct tcb *tcp)
498 return decode_access(tcp, 0);
502 sys_faccessat(struct tcb *tcp)
505 print_dirfd(tcp, tcp->u_arg[0]);
506 return decode_access(tcp, 1);
510 sys_umask(struct tcb *tcp)
513 tprintf("%#lo", tcp->u_arg[0]);
518 const struct xlat whence_codes[] = {
531 /* Linux kernel has exactly one version of lseek:
532 * fs/read_write.c::SYSCALL_DEFINE3(lseek, unsigned, fd, off_t, offset, unsigned, origin)
533 * In kernel, off_t is always the same as (kernel's) long
534 * (see include/uapi/asm-generic/posix_types.h),
535 * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
536 * Use test/x32_lseek.c to test lseek decoding.
538 #if defined(LINUX_MIPSN32) || defined(X32)
540 sys_lseek(struct tcb *tcp)
546 printfd(tcp, tcp->u_arg[0]);
547 offset = tcp->ext_arg[1];
548 whence = tcp->u_arg[2];
549 if (whence == SEEK_SET)
550 tprintf(", %llu, ", offset);
552 tprintf(", %lld, ", offset);
553 printxval(whence_codes, whence, "SEEK_???");
555 return RVAL_LUDECIMAL;
559 sys_lseek(struct tcb *tcp)
565 printfd(tcp, tcp->u_arg[0]);
566 offset = tcp->u_arg[1];
567 whence = tcp->u_arg[2];
568 if (whence == SEEK_SET)
569 tprintf(", %lu, ", offset);
571 tprintf(", %ld, ", offset);
572 printxval(whence_codes, whence, "SEEK_???");
574 return RVAL_UDECIMAL;
578 /* llseek syscall takes explicitly two ulong arguments hi, lo,
579 * rather than one 64-bit argument for which LONG_LONG works
580 * appropriate for the native byte order.
582 * See kernel's fs/read_write.c::SYSCALL_DEFINE5(llseek, ...)
584 * hi,lo are "unsigned longs" and combined exactly this way in kernel:
585 * ((loff_t) hi << 32) | lo
586 * Note that for architectures with kernel's long wider than userspace long
587 * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
588 * for hi and lo. We would need to use tcp->ext_arg[N] on x32...
589 * ...however, x32 (and x86_64) does not _have_ llseek syscall as such.
592 sys_llseek(struct tcb *tcp)
595 printfd(tcp, tcp->u_arg[0]);
596 if (tcp->u_arg[4] == SEEK_SET)
598 ((long long) tcp->u_arg[1]) << 32 |
599 (unsigned long long) (unsigned) tcp->u_arg[2]);
602 ((long long) tcp->u_arg[1]) << 32 |
603 (unsigned long long) (unsigned) tcp->u_arg[2]);
607 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
608 tprintf("%#lx, ", tcp->u_arg[3]);
610 tprintf("[%llu], ", off);
611 printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
617 sys_readahead(struct tcb *tcp)
621 printfd(tcp, tcp->u_arg[0]);
622 argn = printllval(tcp, ", %lld", 1);
623 tprintf(", %ld", tcp->u_arg[argn]);
629 sys_truncate(struct tcb *tcp)
632 printpath(tcp, tcp->u_arg[0]);
633 tprintf(", %lu", tcp->u_arg[1]);
639 sys_truncate64(struct tcb *tcp)
642 printpath(tcp, tcp->u_arg[0]);
643 printllval(tcp, ", %llu", 1);
649 sys_ftruncate(struct tcb *tcp)
652 printfd(tcp, tcp->u_arg[0]);
653 tprintf(", %lu", tcp->u_arg[1]);
659 sys_ftruncate64(struct tcb *tcp)
662 printfd(tcp, tcp->u_arg[0]);
663 printllval(tcp, ", %llu", 1);
670 static const struct xlat modetypes[] = {
684 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
689 if ((mode & S_IFMT) == 0)
691 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
692 sprintf(buf, "%#o", mode);
695 s = buf + sprintf(buf, "%s%s%s%s", s,
696 (mode & S_ISUID) ? "|S_ISUID" : "",
697 (mode & S_ISGID) ? "|S_ISGID" : "",
698 (mode & S_ISVTX) ? "|S_ISVTX" : "");
699 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
701 sprintf((char*)s, "|%#o", mode);
702 s = (*buf == '|') ? buf + 1 : buf;
710 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
718 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
719 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
720 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
722 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
727 #if defined(SPARC) || defined(SPARC64)
735 int st_pad1[3]; /* network id */
744 int st_pad3; /* st_size, off_t expansion */
745 timestruct_t st_atime;
746 timestruct_t st_mtime;
747 timestruct_t st_ctime;
751 int st_pad4[8]; /* expansion area */
755 printstatsol(struct tcb *tcp, long addr)
757 struct solstat statbuf;
759 if (umove(tcp, addr, &statbuf) < 0) {
764 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
765 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
766 (unsigned long) (statbuf.st_dev & 0x3ffff),
767 (unsigned long) statbuf.st_ino,
768 sprintmode(statbuf.st_mode));
769 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
770 (unsigned long) statbuf.st_nlink,
771 (unsigned long) statbuf.st_uid,
772 (unsigned long) statbuf.st_gid);
773 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
774 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
777 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
778 switch (statbuf.st_mode & S_IFMT) {
779 case S_IFCHR: case S_IFBLK:
780 tprintf("st_rdev=makedev(%lu, %lu), ",
781 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
782 (unsigned long) (statbuf.st_rdev & 0x3ffff));
785 tprintf("st_size=%u, ", statbuf.st_size);
789 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
790 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
791 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
797 # if defined(SPARC64)
799 printstat_sparc64(struct tcb *tcp, long addr)
801 struct stat_sparc64 statbuf;
803 if (umove(tcp, addr, &statbuf) < 0) {
809 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
810 (unsigned long) major(statbuf.st_dev),
811 (unsigned long) minor(statbuf.st_dev),
812 (unsigned long) statbuf.st_ino,
813 sprintmode(statbuf.st_mode));
814 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
815 (unsigned long) statbuf.st_nlink,
816 (unsigned long) statbuf.st_uid,
817 (unsigned long) statbuf.st_gid);
818 tprintf("st_blksize=%lu, ",
819 (unsigned long) statbuf.st_blksize);
820 tprintf("st_blocks=%lu, ",
821 (unsigned long) statbuf.st_blocks);
824 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
825 switch (statbuf.st_mode & S_IFMT) {
826 case S_IFCHR: case S_IFBLK:
827 tprintf("st_rdev=makedev(%lu, %lu), ",
828 (unsigned long) major(statbuf.st_rdev),
829 (unsigned long) minor(statbuf.st_rdev));
832 tprintf("st_size=%lu, ", statbuf.st_size);
836 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
837 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
838 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
843 # endif /* SPARC64 */
844 #endif /* SPARC[64] */
846 #if defined POWERPC64
847 struct stat_powerpc32 {
850 unsigned int st_mode;
851 unsigned short st_nlink;
854 unsigned int st_rdev;
855 unsigned int st_size;
856 unsigned int st_blksize;
857 unsigned int st_blocks;
858 unsigned int st_atime;
859 unsigned int st_atime_nsec;
860 unsigned int st_mtime;
861 unsigned int st_mtime_nsec;
862 unsigned int st_ctime;
863 unsigned int st_ctime_nsec;
864 unsigned int __unused4;
865 unsigned int __unused5;
869 printstat_powerpc32(struct tcb *tcp, long addr)
871 struct stat_powerpc32 statbuf;
873 if (umove(tcp, addr, &statbuf) < 0) {
879 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
880 major(statbuf.st_dev), minor(statbuf.st_dev),
882 sprintmode(statbuf.st_mode));
883 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
884 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
885 tprintf("st_blksize=%u, ", statbuf.st_blksize);
886 tprintf("st_blocks=%u, ", statbuf.st_blocks);
889 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
890 switch (statbuf.st_mode & S_IFMT) {
891 case S_IFCHR: case S_IFBLK:
892 tprintf("st_rdev=makedev(%lu, %lu), ",
893 (unsigned long) major(statbuf.st_rdev),
894 (unsigned long) minor(statbuf.st_rdev));
897 tprintf("st_size=%u, ", statbuf.st_size);
901 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
902 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
903 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
908 #endif /* POWERPC64 */
910 static const struct xlat fileflags[] = {
915 realprintstat(struct tcb *tcp, struct stat *statbuf)
918 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
919 (unsigned long) major(statbuf->st_dev),
920 (unsigned long) minor(statbuf->st_dev),
921 (unsigned long) statbuf->st_ino,
922 sprintmode(statbuf->st_mode));
923 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
924 (unsigned long) statbuf->st_nlink,
925 (unsigned long) statbuf->st_uid,
926 (unsigned long) statbuf->st_gid);
927 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
928 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
930 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
931 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
935 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
936 switch (statbuf->st_mode & S_IFMT) {
937 case S_IFCHR: case S_IFBLK:
938 #ifdef HAVE_STRUCT_STAT_ST_RDEV
939 tprintf("st_rdev=makedev(%lu, %lu), ",
940 (unsigned long) major(statbuf->st_rdev),
941 (unsigned long) minor(statbuf->st_rdev));
942 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
943 tprintf("st_size=makedev(%lu, %lu), ",
944 (unsigned long) major(statbuf->st_size),
945 (unsigned long) minor(statbuf->st_size));
946 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
949 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
953 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
954 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
955 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
956 #if HAVE_STRUCT_STAT_ST_FLAGS
957 tprints(", st_flags=");
958 printflags(fileflags, statbuf->st_flags, "UF_???");
960 #if HAVE_STRUCT_STAT_ST_ACLCNT
961 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
963 #if HAVE_STRUCT_STAT_ST_LEVEL
964 tprintf(", st_level=%ld", statbuf->st_level);
966 #if HAVE_STRUCT_STAT_ST_FSTYPE
967 tprintf(", st_fstype=%.*s",
968 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
970 #if HAVE_STRUCT_STAT_ST_GEN
971 tprintf(", st_gen=%u", statbuf->st_gen);
981 printstat(struct tcb *tcp, long addr)
989 if (syserror(tcp) || !verbose(tcp)) {
990 tprintf("%#lx", addr);
994 #if defined(SPARC) || defined(SPARC64)
995 if (current_personality == 1) {
996 printstatsol(tcp, addr);
1000 else if (current_personality == 2) {
1001 printstat_sparc64(tcp, addr);
1005 #endif /* SPARC[64] */
1007 #if defined POWERPC64
1008 if (current_personality == 1) {
1009 printstat_powerpc32(tcp, addr);
1014 if (umove(tcp, addr, &statbuf) < 0) {
1019 realprintstat(tcp, &statbuf);
1022 # define printstat printstat64
1025 #if !defined HAVE_STAT64 && defined X86_64
1027 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1028 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1029 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1030 * __GNUC__ is needed for the required __attribute__ below.
1033 unsigned long long st_dev;
1034 unsigned char __pad0[4];
1035 unsigned int __st_ino;
1036 unsigned int st_mode;
1037 unsigned int st_nlink;
1038 unsigned int st_uid;
1039 unsigned int st_gid;
1040 unsigned long long st_rdev;
1041 unsigned char __pad3[4];
1043 unsigned int st_blksize;
1044 unsigned long long st_blocks;
1045 unsigned int st_atime;
1046 unsigned int st_atime_nsec;
1047 unsigned int st_mtime;
1048 unsigned int st_mtime_nsec;
1049 unsigned int st_ctime;
1050 unsigned int st_ctime_nsec;
1051 unsigned long long st_ino;
1052 } __attribute__((packed));
1053 # define HAVE_STAT64 1
1054 # define STAT64_SIZE 96
1059 printstat64(struct tcb *tcp, long addr)
1062 struct stat statbuf;
1064 struct stat64 statbuf;
1068 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1075 if (syserror(tcp) || !verbose(tcp)) {
1076 tprintf("%#lx", addr);
1080 #if defined(SPARC) || defined(SPARC64)
1081 if (current_personality == 1) {
1082 printstatsol(tcp, addr);
1086 else if (current_personality == 2) {
1087 printstat_sparc64(tcp, addr);
1091 #endif /* SPARC[64] */
1094 if (current_personality != 1) {
1095 printstat(tcp, addr);
1100 if (umove(tcp, addr, &statbuf) < 0) {
1106 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1107 (unsigned long) major(statbuf.st_dev),
1108 (unsigned long) minor(statbuf.st_dev),
1109 (unsigned long long) statbuf.st_ino,
1110 sprintmode(statbuf.st_mode));
1111 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1112 (unsigned long) statbuf.st_nlink,
1113 (unsigned long) statbuf.st_uid,
1114 (unsigned long) statbuf.st_gid);
1115 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1116 tprintf("st_blksize=%lu, ",
1117 (unsigned long) statbuf.st_blksize);
1118 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1119 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
1120 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1121 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
1124 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1125 switch (statbuf.st_mode & S_IFMT) {
1126 case S_IFCHR: case S_IFBLK:
1127 #ifdef HAVE_STRUCT_STAT_ST_RDEV
1128 tprintf("st_rdev=makedev(%lu, %lu), ",
1129 (unsigned long) major(statbuf.st_rdev),
1130 (unsigned long) minor(statbuf.st_rdev));
1131 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
1132 tprintf("st_size=makedev(%lu, %lu), ",
1133 (unsigned long) major(statbuf.st_size),
1134 (unsigned long) minor(statbuf.st_size));
1135 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
1138 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1142 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1143 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1144 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1145 #if HAVE_STRUCT_STAT_ST_FLAGS
1146 tprints(", st_flags=");
1147 printflags(fileflags, statbuf.st_flags, "UF_???");
1149 #if HAVE_STRUCT_STAT_ST_ACLCNT
1150 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1152 #if HAVE_STRUCT_STAT_ST_LEVEL
1153 tprintf(", st_level=%ld", statbuf.st_level);
1155 #if HAVE_STRUCT_STAT_ST_FSTYPE
1156 tprintf(", st_fstype=%.*s",
1157 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1159 #if HAVE_STRUCT_STAT_ST_GEN
1160 tprintf(", st_gen=%u", statbuf.st_gen);
1167 #endif /* HAVE_STAT64 */
1169 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1171 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
1173 newbuf->st_dev = oldbuf->st_dev;
1174 newbuf->st_ino = oldbuf->st_ino;
1175 newbuf->st_mode = oldbuf->st_mode;
1176 newbuf->st_nlink = oldbuf->st_nlink;
1177 newbuf->st_uid = oldbuf->st_uid;
1178 newbuf->st_gid = oldbuf->st_gid;
1179 newbuf->st_rdev = oldbuf->st_rdev;
1180 newbuf->st_size = oldbuf->st_size;
1181 newbuf->st_atime = oldbuf->st_atime;
1182 newbuf->st_mtime = oldbuf->st_mtime;
1183 newbuf->st_ctime = oldbuf->st_ctime;
1184 newbuf->st_blksize = 0; /* not supported in old_stat */
1185 newbuf->st_blocks = 0; /* not supported in old_stat */
1189 printoldstat(struct tcb *tcp, long addr)
1191 struct __old_kernel_stat statbuf;
1192 struct stat newstatbuf;
1198 if (syserror(tcp) || !verbose(tcp)) {
1199 tprintf("%#lx", addr);
1203 # if defined(SPARC) || defined(SPARC64)
1204 if (current_personality == 1) {
1205 printstatsol(tcp, addr);
1210 if (umove(tcp, addr, &statbuf) < 0) {
1215 convertoldstat(&statbuf, &newstatbuf);
1216 realprintstat(tcp, &newstatbuf);
1221 sys_stat(struct tcb *tcp)
1223 if (entering(tcp)) {
1224 printpath(tcp, tcp->u_arg[0]);
1227 printstat(tcp, tcp->u_arg[1]);
1234 printstat64_x32(struct tcb *tcp, long addr)
1236 struct stat64 statbuf;
1242 if (syserror(tcp) || !verbose(tcp)) {
1243 tprintf("%#lx", addr);
1247 if (umove(tcp, addr, &statbuf) < 0) {
1253 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1254 (unsigned long) major(statbuf.st_dev),
1255 (unsigned long) minor(statbuf.st_dev),
1256 (unsigned long long) statbuf.st_ino,
1257 sprintmode(statbuf.st_mode));
1258 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1259 (unsigned long) statbuf.st_nlink,
1260 (unsigned long) statbuf.st_uid,
1261 (unsigned long) statbuf.st_gid);
1262 tprintf("st_blksize=%lu, ",
1263 (unsigned long) statbuf.st_blksize);
1264 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1267 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1268 switch (statbuf.st_mode & S_IFMT) {
1269 case S_IFCHR: case S_IFBLK:
1270 tprintf("st_rdev=makedev(%lu, %lu), ",
1271 (unsigned long) major(statbuf.st_rdev),
1272 (unsigned long) minor(statbuf.st_rdev));
1275 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1279 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1280 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1281 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1290 sys_stat64(struct tcb *tcp)
1293 if (entering(tcp)) {
1294 printpath(tcp, tcp->u_arg[0]);
1298 printstat64_x32(tcp, tcp->u_arg[1]);
1300 printstat64(tcp, tcp->u_arg[1]);
1305 return printargs(tcp);
1309 #ifndef AT_SYMLINK_NOFOLLOW
1310 # define AT_SYMLINK_NOFOLLOW 0x100
1312 #ifndef AT_REMOVEDIR
1313 # define AT_REMOVEDIR 0x200
1315 #ifndef AT_SYMLINK_FOLLOW
1316 # define AT_SYMLINK_FOLLOW 0x400
1318 #ifndef AT_NO_AUTOMOUNT
1319 # define AT_NO_AUTOMOUNT 0x800
1321 #ifndef AT_EMPTY_PATH
1322 # define AT_EMPTY_PATH 0x1000
1325 static const struct xlat at_flags[] = {
1326 XLAT(AT_SYMLINK_NOFOLLOW),
1328 XLAT(AT_SYMLINK_FOLLOW),
1329 XLAT(AT_NO_AUTOMOUNT),
1330 XLAT(AT_EMPTY_PATH),
1335 sys_newfstatat(struct tcb *tcp)
1337 if (entering(tcp)) {
1338 print_dirfd(tcp, tcp->u_arg[0]);
1339 printpath(tcp, tcp->u_arg[1]);
1343 if (current_personality == 0)
1344 printstat(tcp, tcp->u_arg[2]);
1346 printstat64(tcp, tcp->u_arg[2]);
1347 #elif defined HAVE_STAT64
1348 printstat64(tcp, tcp->u_arg[2]);
1350 printstat(tcp, tcp->u_arg[2]);
1353 printflags(at_flags, tcp->u_arg[3], "AT_???");
1358 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1360 sys_oldstat(struct tcb *tcp)
1362 if (entering(tcp)) {
1363 printpath(tcp, tcp->u_arg[0]);
1366 printoldstat(tcp, tcp->u_arg[1]);
1373 sys_fstat(struct tcb *tcp)
1375 if (entering(tcp)) {
1376 printfd(tcp, tcp->u_arg[0]);
1379 printstat(tcp, tcp->u_arg[1]);
1385 sys_fstat64(struct tcb *tcp)
1388 if (entering(tcp)) {
1389 printfd(tcp, tcp->u_arg[0]);
1393 printstat64_x32(tcp, tcp->u_arg[1]);
1395 printstat64(tcp, tcp->u_arg[1]);
1400 return printargs(tcp);
1404 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1406 sys_oldfstat(struct tcb *tcp)
1408 if (entering(tcp)) {
1409 printfd(tcp, tcp->u_arg[0]);
1412 printoldstat(tcp, tcp->u_arg[1]);
1418 #if defined(SPARC) || defined(SPARC64)
1421 sys_xstat(struct tcb *tcp)
1423 if (entering(tcp)) {
1424 tprintf("%ld, ", tcp->u_arg[0]);
1425 printpath(tcp, tcp->u_arg[1]);
1429 if (tcp->u_arg[0] == _STAT64_VER)
1430 printstat64(tcp, tcp->u_arg[2]);
1433 printstat(tcp, tcp->u_arg[2]);
1439 sys_fxstat(struct tcb *tcp)
1442 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1445 if (tcp->u_arg[0] == _STAT64_VER)
1446 printstat64(tcp, tcp->u_arg[2]);
1449 printstat(tcp, tcp->u_arg[2]);
1455 sys_lxstat(struct tcb *tcp)
1457 if (entering(tcp)) {
1458 tprintf("%ld, ", tcp->u_arg[0]);
1459 printpath(tcp, tcp->u_arg[1]);
1463 if (tcp->u_arg[0] == _STAT64_VER)
1464 printstat64(tcp, tcp->u_arg[2]);
1467 printstat(tcp, tcp->u_arg[2]);
1473 sys_xmknod(struct tcb *tcp)
1475 int mode = tcp->u_arg[2];
1477 if (entering(tcp)) {
1478 tprintf("%ld, ", tcp->u_arg[0]);
1479 printpath(tcp, tcp->u_arg[1]);
1480 tprintf(", %s", sprintmode(mode));
1481 switch (mode & S_IFMT) {
1482 case S_IFCHR: case S_IFBLK:
1483 tprintf(", makedev(%lu, %lu)",
1484 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1485 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1494 # ifdef HAVE_SYS_ACL_H
1496 # include <sys/acl.h>
1498 static const struct xlat aclcmds[] = {
1521 sys_acl(struct tcb *tcp)
1523 if (entering(tcp)) {
1524 printpath(tcp, tcp->u_arg[0]);
1526 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1527 tprintf(", %ld", tcp->u_arg[2]);
1529 * FIXME - dump out the list of aclent_t's pointed to
1530 * by "tcp->u_arg[3]" if it's not NULL.
1533 tprintf(", %#lx", tcp->u_arg[3]);
1541 sys_facl(struct tcb *tcp)
1543 if (entering(tcp)) {
1544 tprintf("%ld, ", tcp->u_arg[0]);
1545 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1546 tprintf(", %ld", tcp->u_arg[2]);
1548 * FIXME - dump out the list of aclent_t's pointed to
1549 * by "tcp->u_arg[3]" if it's not NULL.
1552 tprintf(", %#lx", tcp->u_arg[3]);
1559 static const struct xlat aclipc[] = {
1573 sys_aclipc(struct tcb *tcp)
1575 if (entering(tcp)) {
1576 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1577 tprintf(", %#lx, ", tcp->u_arg[1]);
1578 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1579 tprintf(", %ld", tcp->u_arg[3]);
1581 * FIXME - dump out the list of aclent_t's pointed to
1582 * by "tcp->u_arg[4]" if it's not NULL.
1585 tprintf(", %#lx", tcp->u_arg[4]);
1592 # endif /* HAVE_SYS_ACL_H */
1594 #endif /* SPARC[64] */
1596 static const struct xlat fsmagic[] = {
1597 { 0x73757245, "CODA_SUPER_MAGIC" },
1598 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1599 { 0x1373, "DEVFS_SUPER_MAGIC" },
1600 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1601 { 0x414A53, "EFS_SUPER_MAGIC" },
1602 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1603 { 0xef53, "EXT2_SUPER_MAGIC" },
1604 { 0x137d, "EXT_SUPER_MAGIC" },
1605 { 0xf995e849, "HPFS_SUPER_MAGIC" },
1606 { 0x9660, "ISOFS_SUPER_MAGIC" },
1607 { 0x137f, "MINIX_SUPER_MAGIC" },
1608 { 0x138f, "MINIX_SUPER_MAGIC2" },
1609 { 0x2468, "MINIX2_SUPER_MAGIC" },
1610 { 0x2478, "MINIX2_SUPER_MAGIC2" },
1611 { 0x4d44, "MSDOS_SUPER_MAGIC" },
1612 { 0x564c, "NCP_SUPER_MAGIC" },
1613 { 0x6969, "NFS_SUPER_MAGIC" },
1614 { 0x9fa0, "PROC_SUPER_MAGIC" },
1615 { 0x002f, "QNX4_SUPER_MAGIC" },
1616 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1617 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1618 { 0x517b, "SMB_SUPER_MAGIC" },
1619 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1620 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1621 { 0x00011954, "UFS_MAGIC" },
1622 { 0x54190100, "UFS_CIGAM" },
1623 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
1624 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
1625 { 0x62656572, "SYSFS_MAGIC" },
1630 sprintfstype(int magic)
1632 static char buf[32];
1635 s = xlookup(fsmagic, magic);
1637 sprintf(buf, "\"%s\"", s);
1640 sprintf(buf, "%#x", magic);
1645 printstatfs(struct tcb *tcp, long addr)
1647 struct statfs statbuf;
1649 if (syserror(tcp) || !verbose(tcp)) {
1650 tprintf("%#lx", addr);
1653 if (umove(tcp, addr, &statbuf) < 0) {
1659 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1660 sprintfstype(statbuf.f_type),
1661 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1662 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1663 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
1664 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1667 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1668 sprintfstype(statbuf.f_type),
1669 (unsigned long)statbuf.f_bsize,
1670 (unsigned long)statbuf.f_blocks,
1671 (unsigned long)statbuf.f_bfree);
1672 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1673 (unsigned long)statbuf.f_bavail,
1674 (unsigned long)statbuf.f_files,
1675 (unsigned long)statbuf.f_ffree,
1676 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1677 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1679 #ifdef _STATFS_F_FRSIZE
1680 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1686 sys_statfs(struct tcb *tcp)
1688 if (entering(tcp)) {
1689 printpath(tcp, tcp->u_arg[0]);
1692 printstatfs(tcp, tcp->u_arg[1]);
1698 sys_fstatfs(struct tcb *tcp)
1700 if (entering(tcp)) {
1701 printfd(tcp, tcp->u_arg[0]);
1704 printstatfs(tcp, tcp->u_arg[1]);
1709 #if defined HAVE_STATFS64
1711 printstatfs64(struct tcb *tcp, long addr)
1713 struct statfs64 statbuf;
1715 if (syserror(tcp) || !verbose(tcp)) {
1716 tprintf("%#lx", addr);
1719 if (umove(tcp, addr, &statbuf) < 0) {
1723 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
1724 sprintfstype(statbuf.f_type),
1725 (unsigned long long)statbuf.f_bsize,
1726 (unsigned long long)statbuf.f_blocks,
1727 (unsigned long long)statbuf.f_bfree);
1728 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1729 (unsigned long long)statbuf.f_bavail,
1730 (unsigned long long)statbuf.f_files,
1731 (unsigned long long)statbuf.f_ffree,
1732 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1733 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1734 #ifdef _STATFS_F_FRSIZE
1735 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
1737 #ifdef _STATFS_F_FLAGS
1738 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1743 struct compat_statfs64 {
1755 uint32_t f_spare[4];
1757 #if defined(X86_64) || defined(IA64)
1758 __attribute__ ((packed, aligned(4)))
1763 printcompat_statfs64(struct tcb *tcp, long addr)
1765 struct compat_statfs64 statbuf;
1767 if (syserror(tcp) || !verbose(tcp)) {
1768 tprintf("%#lx", addr);
1771 if (umove(tcp, addr, &statbuf) < 0) {
1775 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1776 sprintfstype(statbuf.f_type),
1777 (unsigned long)statbuf.f_bsize,
1778 (unsigned long long)statbuf.f_blocks,
1779 (unsigned long long)statbuf.f_bfree);
1780 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1781 (unsigned long long)statbuf.f_bavail,
1782 (unsigned long long)statbuf.f_files,
1783 (unsigned long long)statbuf.f_ffree,
1784 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1785 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1786 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1787 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
1791 sys_statfs64(struct tcb *tcp)
1793 if (entering(tcp)) {
1794 printpath(tcp, tcp->u_arg[0]);
1795 tprintf(", %lu, ", tcp->u_arg[1]);
1797 if (tcp->u_arg[1] == sizeof(struct statfs64))
1798 printstatfs64(tcp, tcp->u_arg[2]);
1799 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1800 printcompat_statfs64(tcp, tcp->u_arg[2]);
1808 sys_fstatfs64(struct tcb *tcp)
1810 if (entering(tcp)) {
1811 printfd(tcp, tcp->u_arg[0]);
1812 tprintf(", %lu, ", tcp->u_arg[1]);
1814 if (tcp->u_arg[1] == sizeof(struct statfs64))
1815 printstatfs64(tcp, tcp->u_arg[2]);
1816 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1817 printcompat_statfs64(tcp, tcp->u_arg[2]);
1827 osf_statfs(struct tcb *tcp)
1829 if (entering(tcp)) {
1830 printpath(tcp, tcp->u_arg[0]);
1833 printstatfs(tcp, tcp->u_arg[1]);
1834 tprintf(", %lu", tcp->u_arg[2]);
1840 osf_fstatfs(struct tcb *tcp)
1842 if (entering(tcp)) {
1843 tprintf("%lu, ", tcp->u_arg[0]);
1845 printstatfs(tcp, tcp->u_arg[1]);
1846 tprintf(", %lu", tcp->u_arg[2]);
1854 sys_chdir(struct tcb *tcp)
1856 if (entering(tcp)) {
1857 printpath(tcp, tcp->u_arg[0]);
1863 decode_mkdir(struct tcb *tcp, int offset)
1865 if (entering(tcp)) {
1866 printpath(tcp, tcp->u_arg[offset]);
1867 tprintf(", %#lo", tcp->u_arg[offset + 1]);
1873 sys_mkdir(struct tcb *tcp)
1875 return decode_mkdir(tcp, 0);
1879 sys_mkdirat(struct tcb *tcp)
1882 print_dirfd(tcp, tcp->u_arg[0]);
1883 return decode_mkdir(tcp, 1);
1887 sys_link(struct tcb *tcp)
1889 if (entering(tcp)) {
1890 printpath(tcp, tcp->u_arg[0]);
1892 printpath(tcp, tcp->u_arg[1]);
1898 sys_linkat(struct tcb *tcp)
1900 if (entering(tcp)) {
1901 print_dirfd(tcp, tcp->u_arg[0]);
1902 printpath(tcp, tcp->u_arg[1]);
1904 print_dirfd(tcp, tcp->u_arg[2]);
1905 printpath(tcp, tcp->u_arg[3]);
1907 printflags(at_flags, tcp->u_arg[4], "AT_???");
1913 sys_unlinkat(struct tcb *tcp)
1915 if (entering(tcp)) {
1916 print_dirfd(tcp, tcp->u_arg[0]);
1917 printpath(tcp, tcp->u_arg[1]);
1919 printflags(at_flags, tcp->u_arg[2], "AT_???");
1925 sys_symlinkat(struct tcb *tcp)
1927 if (entering(tcp)) {
1928 printpath(tcp, tcp->u_arg[0]);
1930 print_dirfd(tcp, tcp->u_arg[1]);
1931 printpath(tcp, tcp->u_arg[2]);
1937 decode_readlink(struct tcb *tcp, int offset)
1939 if (entering(tcp)) {
1940 printpath(tcp, tcp->u_arg[offset]);
1944 tprintf("%#lx", tcp->u_arg[offset + 1]);
1946 /* Used to use printpathn(), but readlink
1947 * neither includes NUL in the returned count,
1948 * nor actually writes it into memory.
1949 * printpathn() would decide on printing
1950 * "..." continuation based on garbage
1951 * past return buffer's end.
1953 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1954 tprintf(", %lu", tcp->u_arg[offset + 2]);
1960 sys_readlink(struct tcb *tcp)
1962 return decode_readlink(tcp, 0);
1966 sys_readlinkat(struct tcb *tcp)
1969 print_dirfd(tcp, tcp->u_arg[0]);
1970 return decode_readlink(tcp, 1);
1974 sys_renameat(struct tcb *tcp)
1976 if (entering(tcp)) {
1977 print_dirfd(tcp, tcp->u_arg[0]);
1978 printpath(tcp, tcp->u_arg[1]);
1980 print_dirfd(tcp, tcp->u_arg[2]);
1981 printpath(tcp, tcp->u_arg[3]);
1987 sys_chown(struct tcb *tcp)
1989 if (entering(tcp)) {
1990 printpath(tcp, tcp->u_arg[0]);
1991 printuid(", ", tcp->u_arg[1]);
1992 printuid(", ", tcp->u_arg[2]);
1998 sys_fchownat(struct tcb *tcp)
2000 if (entering(tcp)) {
2001 print_dirfd(tcp, tcp->u_arg[0]);
2002 printpath(tcp, tcp->u_arg[1]);
2003 printuid(", ", tcp->u_arg[2]);
2004 printuid(", ", tcp->u_arg[3]);
2006 printflags(at_flags, tcp->u_arg[4], "AT_???");
2012 sys_fchown(struct tcb *tcp)
2014 if (entering(tcp)) {
2015 printfd(tcp, tcp->u_arg[0]);
2016 printuid(", ", tcp->u_arg[1]);
2017 printuid(", ", tcp->u_arg[2]);
2023 decode_chmod(struct tcb *tcp, int offset)
2025 if (entering(tcp)) {
2026 printpath(tcp, tcp->u_arg[offset]);
2027 tprintf(", %#lo", tcp->u_arg[offset + 1]);
2033 sys_chmod(struct tcb *tcp)
2035 return decode_chmod(tcp, 0);
2039 sys_fchmodat(struct tcb *tcp)
2042 print_dirfd(tcp, tcp->u_arg[0]);
2043 return decode_chmod(tcp, 1);
2047 sys_fchmod(struct tcb *tcp)
2049 if (entering(tcp)) {
2050 printfd(tcp, tcp->u_arg[0]);
2051 tprintf(", %#lo", tcp->u_arg[1]);
2058 sys_osf_utimes(struct tcb *tcp)
2060 if (entering(tcp)) {
2061 printpath(tcp, tcp->u_arg[0]);
2063 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2070 decode_utimes(struct tcb *tcp, int offset, int special)
2072 if (entering(tcp)) {
2073 printpath(tcp, tcp->u_arg[offset]);
2075 if (tcp->u_arg[offset + 1] == 0)
2079 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2080 BITNESS_CURRENT, special);
2082 printtv_bitness(tcp, tcp->u_arg[offset + 1]
2083 + sizeof(struct timeval),
2084 BITNESS_CURRENT, special);
2092 sys_utimes(struct tcb *tcp)
2094 return decode_utimes(tcp, 0, 0);
2098 sys_futimesat(struct tcb *tcp)
2101 print_dirfd(tcp, tcp->u_arg[0]);
2102 return decode_utimes(tcp, 1, 0);
2106 sys_utimensat(struct tcb *tcp)
2108 if (entering(tcp)) {
2109 print_dirfd(tcp, tcp->u_arg[0]);
2110 decode_utimes(tcp, 1, 1);
2112 printflags(at_flags, tcp->u_arg[3], "AT_???");
2118 sys_utime(struct tcb *tcp)
2123 long paranoia_for_huge_wordsize[4];
2127 if (entering(tcp)) {
2128 printpath(tcp, tcp->u_arg[0]);
2131 wordsize = current_wordsize;
2134 else if (!verbose(tcp))
2135 tprintf("%#lx", tcp->u_arg[1]);
2136 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
2138 else if (wordsize == sizeof u.utl[0]) {
2139 tprintf("[%s,", sprinttime(u.utl[0]));
2140 tprintf(" %s]", sprinttime(u.utl[1]));
2142 else if (wordsize == sizeof u.uti[0]) {
2143 tprintf("[%s,", sprinttime(u.uti[0]));
2144 tprintf(" %s]", sprinttime(u.uti[1]));
2147 tprintf("<decode error: unsupported wordsize %d>",
2154 decode_mknod(struct tcb *tcp, int offset)
2156 int mode = tcp->u_arg[offset + 1];
2158 if (entering(tcp)) {
2159 printpath(tcp, tcp->u_arg[offset]);
2160 tprintf(", %s", sprintmode(mode));
2161 switch (mode & S_IFMT) {
2164 #if defined(SPARC) || defined(SPARC64)
2165 if (current_personality == 1)
2166 tprintf(", makedev(%lu, %lu)",
2167 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2168 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
2171 tprintf(", makedev(%lu, %lu)",
2172 (unsigned long) major(tcp->u_arg[offset + 2]),
2173 (unsigned long) minor(tcp->u_arg[offset + 2]));
2183 sys_mknod(struct tcb *tcp)
2185 return decode_mknod(tcp, 0);
2189 sys_mknodat(struct tcb *tcp)
2192 print_dirfd(tcp, tcp->u_arg[0]);
2193 return decode_mknod(tcp, 1);
2197 print_old_dirent(struct tcb *tcp, long addr)
2200 typedef struct kernel_dirent old_dirent_t;
2205 unsigned short d_reclen;
2211 if (!verbose(tcp) || umove(tcp, addr, &d) < 0) {
2212 tprintf("%#lx", addr);
2216 tprintf("{d_ino=%lu, d_off=%lu, d_reclen=%u, d_name=\"",
2217 (unsigned long) d.d_ino, (unsigned long) d.d_off, d.d_reclen);
2218 if (d.d_reclen > 256)
2220 printpathn(tcp, addr + offsetof(old_dirent_t, d_name), d.d_reclen);
2225 sys_readdir(struct tcb *tcp)
2227 if (entering(tcp)) {
2228 printfd(tcp, tcp->u_arg[0]);
2231 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2232 tprintf("%#lx", tcp->u_arg[1]);
2234 print_old_dirent(tcp, tcp->u_arg[1]);
2235 /* Not much point in printing this out, it is always 1. */
2236 if (tcp->u_arg[2] != 1)
2237 tprintf(", %lu", tcp->u_arg[2]);
2242 static const struct xlat direnttypes[] = {
2256 sys_getdents(struct tcb *tcp)
2258 int i, len, dents = 0;
2261 if (entering(tcp)) {
2262 printfd(tcp, tcp->u_arg[0]);
2266 if (syserror(tcp) || !verbose(tcp)) {
2267 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2271 /* Beware of insanely large or negative values in tcp->u_rval */
2272 if (tcp->u_rval > 1024*1024)
2274 if (tcp->u_rval < 0)
2276 buf = len ? malloc(len) : NULL;
2278 die_out_of_memory();
2279 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2280 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2286 for (i = 0; i < len;) {
2287 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2289 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2290 i ? " " : "", d->d_ino, d->d_off);
2291 tprintf("d_reclen=%u, d_name=\"%s\", d_type=",
2292 d->d_reclen, d->d_name);
2293 printxval(direnttypes, buf[i + d->d_reclen - 1], "DT_???");
2297 tprints("/* d_reclen == 0, problem here */");
2306 tprintf("/* %u entries */", dents);
2307 tprintf(", %lu", tcp->u_arg[2]);
2313 sys_getdents64(struct tcb *tcp)
2315 int i, len, dents = 0;
2318 if (entering(tcp)) {
2319 printfd(tcp, tcp->u_arg[0]);
2323 if (syserror(tcp) || !verbose(tcp)) {
2324 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2329 /* Beware of insanely large or negative tcp->u_rval */
2330 if (tcp->u_rval > 1024*1024)
2332 if (tcp->u_rval < 0)
2334 buf = len ? malloc(len) : NULL;
2336 die_out_of_memory();
2338 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2339 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2345 for (i = 0; i < len;) {
2346 struct dirent64 *d = (struct dirent64 *) &buf[i];
2348 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
2353 printxval(direnttypes, d->d_type, "DT_???");
2355 tprintf("d_reclen=%u, d_name=\"%s\"}",
2356 d->d_reclen, d->d_name);
2359 tprints("/* d_reclen == 0, problem here */");
2368 tprintf("/* %u entries */", dents);
2369 tprintf(", %lu", tcp->u_arg[2]);
2375 sys_getcwd(struct tcb *tcp)
2379 tprintf("%#lx", tcp->u_arg[0]);
2381 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2382 tprintf(", %lu", tcp->u_arg[1]);
2387 #ifdef HAVE_SYS_ASYNCH_H
2390 sys_aioread(struct tcb *tcp)
2392 struct aio_result_t res;
2394 if (entering(tcp)) {
2395 tprintf("%lu, ", tcp->u_arg[0]);
2398 tprintf("%#lx", tcp->u_arg[1]);
2400 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2401 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2402 printxval(whence, tcp->u_arg[4], "L_???");
2403 if (syserror(tcp) || tcp->u_arg[5] == 0
2404 || umove(tcp, tcp->u_arg[5], &res) < 0)
2405 tprintf(", %#lx", tcp->u_arg[5]);
2407 tprintf(", {aio_return %d aio_errno %d}",
2408 res.aio_return, res.aio_errno);
2414 sys_aiowrite(struct tcb *tcp)
2416 struct aio_result_t res;
2418 if (entering(tcp)) {
2419 tprintf("%lu, ", tcp->u_arg[0]);
2420 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2421 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2422 printxval(whence, tcp->u_arg[4], "L_???");
2425 if (tcp->u_arg[5] == 0)
2427 else if (syserror(tcp)
2428 || umove(tcp, tcp->u_arg[5], &res) < 0)
2429 tprintf(", %#lx", tcp->u_arg[5]);
2431 tprintf(", {aio_return %d aio_errno %d}",
2432 res.aio_return, res.aio_errno);
2438 sys_aiowait(struct tcb *tcp)
2441 printtv(tcp, tcp->u_arg[0]);
2446 sys_aiocancel(struct tcb *tcp)
2448 struct aio_result_t res;
2451 if (tcp->u_arg[0] == 0)
2453 else if (syserror(tcp)
2454 || umove(tcp, tcp->u_arg[0], &res) < 0)
2455 tprintf("%#lx", tcp->u_arg[0]);
2457 tprintf("{aio_return %d aio_errno %d}",
2458 res.aio_return, res.aio_errno);
2463 #endif /* HAVE_SYS_ASYNCH_H */
2465 static const struct xlat xattrflags[] = {
2468 XLAT(XATTR_REPLACE),
2474 print_xattr_val(struct tcb *tcp, int failed,
2476 unsigned long insize,
2482 unsigned long capacity = 4 * size + 1;
2483 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2484 if (buf == NULL || /* probably a bogus size argument */
2485 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2489 unsigned char *out = buf;
2490 unsigned char *in = &buf[3 * size];
2492 for (i = 0; i < size; ++i) {
2493 if (in[i] >= ' ' && in[i] <= 0x7e)
2496 #define tohex(n) "0123456789abcdef"[n]
2499 *out++ = tohex(in[i] / 16);
2500 *out++ = tohex(in[i] % 16);
2503 /* Don't print terminating NUL if there is one. */
2504 if (i > 0 && in[i - 1] == '\0')
2507 tprintf(", \"%s\", %ld", buf, insize);
2512 tprintf(", 0x%lx, %ld", arg, insize);
2516 sys_setxattr(struct tcb *tcp)
2518 if (entering(tcp)) {
2519 printpath(tcp, tcp->u_arg[0]);
2521 printstr(tcp, tcp->u_arg[1], -1);
2522 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2524 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2530 sys_fsetxattr(struct tcb *tcp)
2532 if (entering(tcp)) {
2533 printfd(tcp, tcp->u_arg[0]);
2535 printstr(tcp, tcp->u_arg[1], -1);
2536 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2538 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2544 sys_getxattr(struct tcb *tcp)
2546 if (entering(tcp)) {
2547 printpath(tcp, tcp->u_arg[0]);
2549 printstr(tcp, tcp->u_arg[1], -1);
2551 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2558 sys_fgetxattr(struct tcb *tcp)
2560 if (entering(tcp)) {
2561 printfd(tcp, tcp->u_arg[0]);
2563 printstr(tcp, tcp->u_arg[1], -1);
2565 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2572 print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2574 if (syserror(tcp)) {
2575 tprintf("%#lx", addr);
2581 (size < tcp->u_rval) ? size : tcp->u_rval;
2582 printstr(tcp, addr, len);
2585 tprintf(", %lu", size);
2589 sys_listxattr(struct tcb *tcp)
2591 if (entering(tcp)) {
2592 printpath(tcp, tcp->u_arg[0]);
2595 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2601 sys_flistxattr(struct tcb *tcp)
2603 if (entering(tcp)) {
2604 printfd(tcp, tcp->u_arg[0]);
2607 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2613 sys_removexattr(struct tcb *tcp)
2615 if (entering(tcp)) {
2616 printpath(tcp, tcp->u_arg[0]);
2618 printstr(tcp, tcp->u_arg[1], -1);
2624 sys_fremovexattr(struct tcb *tcp)
2626 if (entering(tcp)) {
2627 printfd(tcp, tcp->u_arg[0]);
2629 printstr(tcp, tcp->u_arg[1], -1);
2634 static const struct xlat advise[] = {
2635 XLAT(POSIX_FADV_NORMAL),
2636 XLAT(POSIX_FADV_RANDOM),
2637 XLAT(POSIX_FADV_SEQUENTIAL),
2638 XLAT(POSIX_FADV_WILLNEED),
2639 XLAT(POSIX_FADV_DONTNEED),
2640 XLAT(POSIX_FADV_NOREUSE),
2645 sys_fadvise64(struct tcb *tcp)
2647 if (entering(tcp)) {
2649 printfd(tcp, tcp->u_arg[0]);
2650 argn = printllval(tcp, ", %lld", 1);
2651 tprintf(", %ld, ", tcp->u_arg[argn++]);
2652 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2658 sys_fadvise64_64(struct tcb *tcp)
2660 if (entering(tcp)) {
2662 printfd(tcp, tcp->u_arg[0]);
2663 argn = printllval(tcp, ", %lld, ", 1);
2664 argn = printllval(tcp, "%lld, ", argn);
2665 #if defined __ARM_EABI__ || defined AARCH64 || defined POWERPC || defined XTENSA
2666 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
2668 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2674 static const struct xlat sync_file_range_flags[] = {
2675 XLAT(SYNC_FILE_RANGE_WAIT_BEFORE),
2676 XLAT(SYNC_FILE_RANGE_WRITE),
2677 XLAT(SYNC_FILE_RANGE_WAIT_AFTER),
2682 sys_sync_file_range(struct tcb *tcp)
2684 if (entering(tcp)) {
2686 printfd(tcp, tcp->u_arg[0]);
2687 argn = printllval(tcp, ", %lld, ", 1);
2688 argn = printllval(tcp, "%lld, ", argn);
2689 printflags(sync_file_range_flags, tcp->u_arg[argn],
2690 "SYNC_FILE_RANGE_???");
2696 sys_sync_file_range2(struct tcb *tcp)
2698 if (entering(tcp)) {
2700 printfd(tcp, tcp->u_arg[0]);
2701 printflags(sync_file_range_flags, 1,
2702 "SYNC_FILE_RANGE_???");
2703 argn = printllval(tcp, ", %lld, ", 2);
2704 argn = printllval(tcp, "%lld, ", argn);
2710 sys_fallocate(struct tcb *tcp)
2712 if (entering(tcp)) {
2714 printfd(tcp, tcp->u_arg[0]); /* fd */
2715 tprintf(", %#lo, ", tcp->u_arg[1]); /* mode */
2716 argn = printllval(tcp, "%llu, ", 2); /* offset */
2717 printllval(tcp, "%llu", argn); /* len */
2722 #ifndef SWAP_FLAG_PREFER
2723 # define SWAP_FLAG_PREFER 0x8000
2725 #ifndef SWAP_FLAG_DISCARD
2726 # define SWAP_FLAG_DISCARD 0x10000
2728 static const struct xlat swap_flags[] = {
2729 XLAT(SWAP_FLAG_PREFER),
2730 XLAT(SWAP_FLAG_DISCARD),
2735 sys_swapon(struct tcb *tcp)
2737 if (entering(tcp)) {
2738 int flags = tcp->u_arg[1];
2739 printpath(tcp, tcp->u_arg[0]);
2741 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2743 if (flags & SWAP_FLAG_PREFER)
2744 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);