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_aligned(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_aligned(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_aligned(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 AARCH64 || 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.
1032 * Similarly, aarch64 has a unified `struct stat' but its arm personality
1033 * needs `struct stat64' (which also expects a 32-bit `long' but which
1034 * shouldn't be packed).
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;
1058 __attribute__((packed))
1059 # define STAT64_SIZE 96
1061 # define STAT64_SIZE 104
1064 # define HAVE_STAT64 1
1069 printstat64(struct tcb *tcp, long addr)
1072 struct stat statbuf;
1074 struct stat64 statbuf;
1078 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1085 if (syserror(tcp) || !verbose(tcp)) {
1086 tprintf("%#lx", addr);
1090 #if defined(SPARC) || defined(SPARC64)
1091 if (current_personality == 1) {
1092 printstatsol(tcp, addr);
1096 else if (current_personality == 2) {
1097 printstat_sparc64(tcp, addr);
1101 #endif /* SPARC[64] */
1104 if (current_personality != 0) {
1105 printstat(tcp, addr);
1110 if (current_personality != 1) {
1111 printstat(tcp, addr);
1116 if (umove(tcp, addr, &statbuf) < 0) {
1122 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1123 (unsigned long) major(statbuf.st_dev),
1124 (unsigned long) minor(statbuf.st_dev),
1125 (unsigned long long) statbuf.st_ino,
1126 sprintmode(statbuf.st_mode));
1127 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1128 (unsigned long) statbuf.st_nlink,
1129 (unsigned long) statbuf.st_uid,
1130 (unsigned long) statbuf.st_gid);
1131 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1132 tprintf("st_blksize=%lu, ",
1133 (unsigned long) statbuf.st_blksize);
1134 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1135 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
1136 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1137 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
1140 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1141 switch (statbuf.st_mode & S_IFMT) {
1142 case S_IFCHR: case S_IFBLK:
1143 #ifdef HAVE_STRUCT_STAT_ST_RDEV
1144 tprintf("st_rdev=makedev(%lu, %lu), ",
1145 (unsigned long) major(statbuf.st_rdev),
1146 (unsigned long) minor(statbuf.st_rdev));
1147 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
1148 tprintf("st_size=makedev(%lu, %lu), ",
1149 (unsigned long) major(statbuf.st_size),
1150 (unsigned long) minor(statbuf.st_size));
1151 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
1154 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1158 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1159 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1160 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1161 #if HAVE_STRUCT_STAT_ST_FLAGS
1162 tprints(", st_flags=");
1163 printflags(fileflags, statbuf.st_flags, "UF_???");
1165 #if HAVE_STRUCT_STAT_ST_ACLCNT
1166 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1168 #if HAVE_STRUCT_STAT_ST_LEVEL
1169 tprintf(", st_level=%ld", statbuf.st_level);
1171 #if HAVE_STRUCT_STAT_ST_FSTYPE
1172 tprintf(", st_fstype=%.*s",
1173 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1175 #if HAVE_STRUCT_STAT_ST_GEN
1176 tprintf(", st_gen=%u", statbuf.st_gen);
1183 #endif /* HAVE_STAT64 */
1185 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1187 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
1189 newbuf->st_dev = oldbuf->st_dev;
1190 newbuf->st_ino = oldbuf->st_ino;
1191 newbuf->st_mode = oldbuf->st_mode;
1192 newbuf->st_nlink = oldbuf->st_nlink;
1193 newbuf->st_uid = oldbuf->st_uid;
1194 newbuf->st_gid = oldbuf->st_gid;
1195 newbuf->st_rdev = oldbuf->st_rdev;
1196 newbuf->st_size = oldbuf->st_size;
1197 newbuf->st_atime = oldbuf->st_atime;
1198 newbuf->st_mtime = oldbuf->st_mtime;
1199 newbuf->st_ctime = oldbuf->st_ctime;
1200 newbuf->st_blksize = 0; /* not supported in old_stat */
1201 newbuf->st_blocks = 0; /* not supported in old_stat */
1205 printoldstat(struct tcb *tcp, long addr)
1207 struct __old_kernel_stat statbuf;
1208 struct stat newstatbuf;
1214 if (syserror(tcp) || !verbose(tcp)) {
1215 tprintf("%#lx", addr);
1219 # if defined(SPARC) || defined(SPARC64)
1220 if (current_personality == 1) {
1221 printstatsol(tcp, addr);
1226 if (umove(tcp, addr, &statbuf) < 0) {
1231 convertoldstat(&statbuf, &newstatbuf);
1232 realprintstat(tcp, &newstatbuf);
1237 sys_stat(struct tcb *tcp)
1239 if (entering(tcp)) {
1240 printpath(tcp, tcp->u_arg[0]);
1243 printstat(tcp, tcp->u_arg[1]);
1250 printstat64_x32(struct tcb *tcp, long addr)
1252 struct stat64 statbuf;
1258 if (syserror(tcp) || !verbose(tcp)) {
1259 tprintf("%#lx", addr);
1263 if (umove(tcp, addr, &statbuf) < 0) {
1269 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1270 (unsigned long) major(statbuf.st_dev),
1271 (unsigned long) minor(statbuf.st_dev),
1272 (unsigned long long) statbuf.st_ino,
1273 sprintmode(statbuf.st_mode));
1274 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1275 (unsigned long) statbuf.st_nlink,
1276 (unsigned long) statbuf.st_uid,
1277 (unsigned long) statbuf.st_gid);
1278 tprintf("st_blksize=%lu, ",
1279 (unsigned long) statbuf.st_blksize);
1280 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1283 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1284 switch (statbuf.st_mode & S_IFMT) {
1285 case S_IFCHR: case S_IFBLK:
1286 tprintf("st_rdev=makedev(%lu, %lu), ",
1287 (unsigned long) major(statbuf.st_rdev),
1288 (unsigned long) minor(statbuf.st_rdev));
1291 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1295 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1296 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1297 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1306 sys_stat64(struct tcb *tcp)
1309 if (entering(tcp)) {
1310 printpath(tcp, tcp->u_arg[0]);
1314 printstat64_x32(tcp, tcp->u_arg[1]);
1316 printstat64(tcp, tcp->u_arg[1]);
1321 return printargs(tcp);
1325 #ifndef AT_SYMLINK_NOFOLLOW
1326 # define AT_SYMLINK_NOFOLLOW 0x100
1328 #ifndef AT_REMOVEDIR
1329 # define AT_REMOVEDIR 0x200
1331 #ifndef AT_SYMLINK_FOLLOW
1332 # define AT_SYMLINK_FOLLOW 0x400
1334 #ifndef AT_NO_AUTOMOUNT
1335 # define AT_NO_AUTOMOUNT 0x800
1337 #ifndef AT_EMPTY_PATH
1338 # define AT_EMPTY_PATH 0x1000
1341 static const struct xlat at_flags[] = {
1342 XLAT(AT_SYMLINK_NOFOLLOW),
1344 XLAT(AT_SYMLINK_FOLLOW),
1345 XLAT(AT_NO_AUTOMOUNT),
1346 XLAT(AT_EMPTY_PATH),
1351 sys_newfstatat(struct tcb *tcp)
1353 if (entering(tcp)) {
1354 print_dirfd(tcp, tcp->u_arg[0]);
1355 printpath(tcp, tcp->u_arg[1]);
1359 if (current_personality == 0)
1360 printstat(tcp, tcp->u_arg[2]);
1362 printstat64(tcp, tcp->u_arg[2]);
1363 #elif defined HAVE_STAT64
1364 printstat64(tcp, tcp->u_arg[2]);
1366 printstat(tcp, tcp->u_arg[2]);
1369 printflags(at_flags, tcp->u_arg[3], "AT_???");
1374 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1376 sys_oldstat(struct tcb *tcp)
1378 if (entering(tcp)) {
1379 printpath(tcp, tcp->u_arg[0]);
1382 printoldstat(tcp, tcp->u_arg[1]);
1389 sys_fstat(struct tcb *tcp)
1391 if (entering(tcp)) {
1392 printfd(tcp, tcp->u_arg[0]);
1395 printstat(tcp, tcp->u_arg[1]);
1401 sys_fstat64(struct tcb *tcp)
1404 if (entering(tcp)) {
1405 printfd(tcp, tcp->u_arg[0]);
1409 printstat64_x32(tcp, tcp->u_arg[1]);
1411 printstat64(tcp, tcp->u_arg[1]);
1416 return printargs(tcp);
1420 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1422 sys_oldfstat(struct tcb *tcp)
1424 if (entering(tcp)) {
1425 printfd(tcp, tcp->u_arg[0]);
1428 printoldstat(tcp, tcp->u_arg[1]);
1434 #if defined(SPARC) || defined(SPARC64)
1437 sys_xstat(struct tcb *tcp)
1439 if (entering(tcp)) {
1440 tprintf("%ld, ", tcp->u_arg[0]);
1441 printpath(tcp, 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_fxstat(struct tcb *tcp)
1458 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1461 if (tcp->u_arg[0] == _STAT64_VER)
1462 printstat64(tcp, tcp->u_arg[2]);
1465 printstat(tcp, tcp->u_arg[2]);
1471 sys_lxstat(struct tcb *tcp)
1473 if (entering(tcp)) {
1474 tprintf("%ld, ", tcp->u_arg[0]);
1475 printpath(tcp, tcp->u_arg[1]);
1479 if (tcp->u_arg[0] == _STAT64_VER)
1480 printstat64(tcp, tcp->u_arg[2]);
1483 printstat(tcp, tcp->u_arg[2]);
1489 sys_xmknod(struct tcb *tcp)
1491 int mode = tcp->u_arg[2];
1493 if (entering(tcp)) {
1494 tprintf("%ld, ", tcp->u_arg[0]);
1495 printpath(tcp, tcp->u_arg[1]);
1496 tprintf(", %s", sprintmode(mode));
1497 switch (mode & S_IFMT) {
1498 case S_IFCHR: case S_IFBLK:
1499 tprintf(", makedev(%lu, %lu)",
1500 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1501 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1510 # ifdef HAVE_SYS_ACL_H
1512 # include <sys/acl.h>
1514 static const struct xlat aclcmds[] = {
1537 sys_acl(struct tcb *tcp)
1539 if (entering(tcp)) {
1540 printpath(tcp, tcp->u_arg[0]);
1542 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1543 tprintf(", %ld", tcp->u_arg[2]);
1545 * FIXME - dump out the list of aclent_t's pointed to
1546 * by "tcp->u_arg[3]" if it's not NULL.
1549 tprintf(", %#lx", tcp->u_arg[3]);
1557 sys_facl(struct tcb *tcp)
1559 if (entering(tcp)) {
1560 tprintf("%ld, ", tcp->u_arg[0]);
1561 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1562 tprintf(", %ld", tcp->u_arg[2]);
1564 * FIXME - dump out the list of aclent_t's pointed to
1565 * by "tcp->u_arg[3]" if it's not NULL.
1568 tprintf(", %#lx", tcp->u_arg[3]);
1575 static const struct xlat aclipc[] = {
1589 sys_aclipc(struct tcb *tcp)
1591 if (entering(tcp)) {
1592 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1593 tprintf(", %#lx, ", tcp->u_arg[1]);
1594 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1595 tprintf(", %ld", tcp->u_arg[3]);
1597 * FIXME - dump out the list of aclent_t's pointed to
1598 * by "tcp->u_arg[4]" if it's not NULL.
1601 tprintf(", %#lx", tcp->u_arg[4]);
1608 # endif /* HAVE_SYS_ACL_H */
1610 #endif /* SPARC[64] */
1612 static const struct xlat fsmagic[] = {
1613 { 0x73757245, "CODA_SUPER_MAGIC" },
1614 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1615 { 0x1373, "DEVFS_SUPER_MAGIC" },
1616 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1617 { 0x414A53, "EFS_SUPER_MAGIC" },
1618 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1619 { 0xef53, "EXT2_SUPER_MAGIC" },
1620 { 0x137d, "EXT_SUPER_MAGIC" },
1621 { 0xf995e849, "HPFS_SUPER_MAGIC" },
1622 { 0x9660, "ISOFS_SUPER_MAGIC" },
1623 { 0x137f, "MINIX_SUPER_MAGIC" },
1624 { 0x138f, "MINIX_SUPER_MAGIC2" },
1625 { 0x2468, "MINIX2_SUPER_MAGIC" },
1626 { 0x2478, "MINIX2_SUPER_MAGIC2" },
1627 { 0x4d44, "MSDOS_SUPER_MAGIC" },
1628 { 0x564c, "NCP_SUPER_MAGIC" },
1629 { 0x6969, "NFS_SUPER_MAGIC" },
1630 { 0x9fa0, "PROC_SUPER_MAGIC" },
1631 { 0x002f, "QNX4_SUPER_MAGIC" },
1632 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1633 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1634 { 0x517b, "SMB_SUPER_MAGIC" },
1635 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1636 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1637 { 0x00011954, "UFS_MAGIC" },
1638 { 0x54190100, "UFS_CIGAM" },
1639 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
1640 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
1641 { 0x62656572, "SYSFS_MAGIC" },
1646 sprintfstype(int magic)
1648 static char buf[32];
1651 s = xlookup(fsmagic, magic);
1653 sprintf(buf, "\"%s\"", s);
1656 sprintf(buf, "%#x", magic);
1661 printstatfs(struct tcb *tcp, long addr)
1663 struct statfs statbuf;
1665 if (syserror(tcp) || !verbose(tcp)) {
1666 tprintf("%#lx", addr);
1669 if (umove(tcp, addr, &statbuf) < 0) {
1675 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1676 sprintfstype(statbuf.f_type),
1677 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1678 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1679 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
1680 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1683 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1684 sprintfstype(statbuf.f_type),
1685 (unsigned long)statbuf.f_bsize,
1686 (unsigned long)statbuf.f_blocks,
1687 (unsigned long)statbuf.f_bfree);
1688 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1689 (unsigned long)statbuf.f_bavail,
1690 (unsigned long)statbuf.f_files,
1691 (unsigned long)statbuf.f_ffree,
1692 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1693 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1695 #ifdef _STATFS_F_FRSIZE
1696 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1702 sys_statfs(struct tcb *tcp)
1704 if (entering(tcp)) {
1705 printpath(tcp, tcp->u_arg[0]);
1708 printstatfs(tcp, tcp->u_arg[1]);
1714 sys_fstatfs(struct tcb *tcp)
1716 if (entering(tcp)) {
1717 printfd(tcp, tcp->u_arg[0]);
1720 printstatfs(tcp, tcp->u_arg[1]);
1725 #if defined HAVE_STATFS64
1727 printstatfs64(struct tcb *tcp, long addr)
1729 struct statfs64 statbuf;
1731 if (syserror(tcp) || !verbose(tcp)) {
1732 tprintf("%#lx", addr);
1735 if (umove(tcp, addr, &statbuf) < 0) {
1739 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
1740 sprintfstype(statbuf.f_type),
1741 (unsigned long long)statbuf.f_bsize,
1742 (unsigned long long)statbuf.f_blocks,
1743 (unsigned long long)statbuf.f_bfree);
1744 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1745 (unsigned long long)statbuf.f_bavail,
1746 (unsigned long long)statbuf.f_files,
1747 (unsigned long long)statbuf.f_ffree,
1748 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1749 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1750 #ifdef _STATFS_F_FRSIZE
1751 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
1753 #ifdef _STATFS_F_FLAGS
1754 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1759 struct compat_statfs64 {
1771 uint32_t f_spare[4];
1773 #if defined(X86_64) || defined(IA64)
1774 __attribute__ ((packed, aligned(4)))
1779 printcompat_statfs64(struct tcb *tcp, long addr)
1781 struct compat_statfs64 statbuf;
1783 if (syserror(tcp) || !verbose(tcp)) {
1784 tprintf("%#lx", addr);
1787 if (umove(tcp, addr, &statbuf) < 0) {
1791 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1792 sprintfstype(statbuf.f_type),
1793 (unsigned long)statbuf.f_bsize,
1794 (unsigned long long)statbuf.f_blocks,
1795 (unsigned long long)statbuf.f_bfree);
1796 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1797 (unsigned long long)statbuf.f_bavail,
1798 (unsigned long long)statbuf.f_files,
1799 (unsigned long long)statbuf.f_ffree,
1800 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1801 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1802 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1803 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
1807 sys_statfs64(struct tcb *tcp)
1809 if (entering(tcp)) {
1810 printpath(tcp, tcp->u_arg[0]);
1811 tprintf(", %lu, ", tcp->u_arg[1]);
1813 if (tcp->u_arg[1] == sizeof(struct statfs64))
1814 printstatfs64(tcp, tcp->u_arg[2]);
1815 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1816 printcompat_statfs64(tcp, tcp->u_arg[2]);
1824 sys_fstatfs64(struct tcb *tcp)
1826 if (entering(tcp)) {
1827 printfd(tcp, tcp->u_arg[0]);
1828 tprintf(", %lu, ", tcp->u_arg[1]);
1830 if (tcp->u_arg[1] == sizeof(struct statfs64))
1831 printstatfs64(tcp, tcp->u_arg[2]);
1832 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1833 printcompat_statfs64(tcp, tcp->u_arg[2]);
1843 osf_statfs(struct tcb *tcp)
1845 if (entering(tcp)) {
1846 printpath(tcp, tcp->u_arg[0]);
1849 printstatfs(tcp, tcp->u_arg[1]);
1850 tprintf(", %lu", tcp->u_arg[2]);
1856 osf_fstatfs(struct tcb *tcp)
1858 if (entering(tcp)) {
1859 tprintf("%lu, ", tcp->u_arg[0]);
1861 printstatfs(tcp, tcp->u_arg[1]);
1862 tprintf(", %lu", tcp->u_arg[2]);
1870 sys_chdir(struct tcb *tcp)
1872 if (entering(tcp)) {
1873 printpath(tcp, tcp->u_arg[0]);
1879 decode_mkdir(struct tcb *tcp, int offset)
1881 if (entering(tcp)) {
1882 printpath(tcp, tcp->u_arg[offset]);
1883 tprintf(", %#lo", tcp->u_arg[offset + 1]);
1889 sys_mkdir(struct tcb *tcp)
1891 return decode_mkdir(tcp, 0);
1895 sys_mkdirat(struct tcb *tcp)
1898 print_dirfd(tcp, tcp->u_arg[0]);
1899 return decode_mkdir(tcp, 1);
1903 sys_link(struct tcb *tcp)
1905 if (entering(tcp)) {
1906 printpath(tcp, tcp->u_arg[0]);
1908 printpath(tcp, tcp->u_arg[1]);
1914 sys_linkat(struct tcb *tcp)
1916 if (entering(tcp)) {
1917 print_dirfd(tcp, tcp->u_arg[0]);
1918 printpath(tcp, tcp->u_arg[1]);
1920 print_dirfd(tcp, tcp->u_arg[2]);
1921 printpath(tcp, tcp->u_arg[3]);
1923 printflags(at_flags, tcp->u_arg[4], "AT_???");
1929 sys_unlinkat(struct tcb *tcp)
1931 if (entering(tcp)) {
1932 print_dirfd(tcp, tcp->u_arg[0]);
1933 printpath(tcp, tcp->u_arg[1]);
1935 printflags(at_flags, tcp->u_arg[2], "AT_???");
1941 sys_symlinkat(struct tcb *tcp)
1943 if (entering(tcp)) {
1944 printpath(tcp, tcp->u_arg[0]);
1946 print_dirfd(tcp, tcp->u_arg[1]);
1947 printpath(tcp, tcp->u_arg[2]);
1953 decode_readlink(struct tcb *tcp, int offset)
1955 if (entering(tcp)) {
1956 printpath(tcp, tcp->u_arg[offset]);
1960 tprintf("%#lx", tcp->u_arg[offset + 1]);
1962 /* Used to use printpathn(), but readlink
1963 * neither includes NUL in the returned count,
1964 * nor actually writes it into memory.
1965 * printpathn() would decide on printing
1966 * "..." continuation based on garbage
1967 * past return buffer's end.
1969 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1970 tprintf(", %lu", tcp->u_arg[offset + 2]);
1976 sys_readlink(struct tcb *tcp)
1978 return decode_readlink(tcp, 0);
1982 sys_readlinkat(struct tcb *tcp)
1985 print_dirfd(tcp, tcp->u_arg[0]);
1986 return decode_readlink(tcp, 1);
1990 sys_renameat(struct tcb *tcp)
1992 if (entering(tcp)) {
1993 print_dirfd(tcp, tcp->u_arg[0]);
1994 printpath(tcp, tcp->u_arg[1]);
1996 print_dirfd(tcp, tcp->u_arg[2]);
1997 printpath(tcp, tcp->u_arg[3]);
2003 sys_chown(struct tcb *tcp)
2005 if (entering(tcp)) {
2006 printpath(tcp, tcp->u_arg[0]);
2007 printuid(", ", tcp->u_arg[1]);
2008 printuid(", ", tcp->u_arg[2]);
2014 sys_fchownat(struct tcb *tcp)
2016 if (entering(tcp)) {
2017 print_dirfd(tcp, tcp->u_arg[0]);
2018 printpath(tcp, tcp->u_arg[1]);
2019 printuid(", ", tcp->u_arg[2]);
2020 printuid(", ", tcp->u_arg[3]);
2022 printflags(at_flags, tcp->u_arg[4], "AT_???");
2028 sys_fchown(struct tcb *tcp)
2030 if (entering(tcp)) {
2031 printfd(tcp, tcp->u_arg[0]);
2032 printuid(", ", tcp->u_arg[1]);
2033 printuid(", ", tcp->u_arg[2]);
2039 decode_chmod(struct tcb *tcp, int offset)
2041 if (entering(tcp)) {
2042 printpath(tcp, tcp->u_arg[offset]);
2043 tprintf(", %#lo", tcp->u_arg[offset + 1]);
2049 sys_chmod(struct tcb *tcp)
2051 return decode_chmod(tcp, 0);
2055 sys_fchmodat(struct tcb *tcp)
2058 print_dirfd(tcp, tcp->u_arg[0]);
2059 return decode_chmod(tcp, 1);
2063 sys_fchmod(struct tcb *tcp)
2065 if (entering(tcp)) {
2066 printfd(tcp, tcp->u_arg[0]);
2067 tprintf(", %#lo", tcp->u_arg[1]);
2074 sys_osf_utimes(struct tcb *tcp)
2076 if (entering(tcp)) {
2077 printpath(tcp, tcp->u_arg[0]);
2079 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2086 decode_utimes(struct tcb *tcp, int offset, int special)
2088 if (entering(tcp)) {
2089 printpath(tcp, tcp->u_arg[offset]);
2091 if (tcp->u_arg[offset + 1] == 0)
2095 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2096 BITNESS_CURRENT, special);
2098 printtv_bitness(tcp, tcp->u_arg[offset + 1]
2099 + sizeof(struct timeval),
2100 BITNESS_CURRENT, special);
2108 sys_utimes(struct tcb *tcp)
2110 return decode_utimes(tcp, 0, 0);
2114 sys_futimesat(struct tcb *tcp)
2117 print_dirfd(tcp, tcp->u_arg[0]);
2118 return decode_utimes(tcp, 1, 0);
2122 sys_utimensat(struct tcb *tcp)
2124 if (entering(tcp)) {
2125 print_dirfd(tcp, tcp->u_arg[0]);
2126 decode_utimes(tcp, 1, 1);
2128 printflags(at_flags, tcp->u_arg[3], "AT_???");
2134 sys_utime(struct tcb *tcp)
2139 long paranoia_for_huge_wordsize[4];
2143 if (entering(tcp)) {
2144 printpath(tcp, tcp->u_arg[0]);
2147 wordsize = current_wordsize;
2150 else if (!verbose(tcp))
2151 tprintf("%#lx", tcp->u_arg[1]);
2152 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
2154 else if (wordsize == sizeof u.utl[0]) {
2155 tprintf("[%s,", sprinttime(u.utl[0]));
2156 tprintf(" %s]", sprinttime(u.utl[1]));
2158 else if (wordsize == sizeof u.uti[0]) {
2159 tprintf("[%s,", sprinttime(u.uti[0]));
2160 tprintf(" %s]", sprinttime(u.uti[1]));
2163 tprintf("<decode error: unsupported wordsize %d>",
2170 decode_mknod(struct tcb *tcp, int offset)
2172 int mode = tcp->u_arg[offset + 1];
2174 if (entering(tcp)) {
2175 printpath(tcp, tcp->u_arg[offset]);
2176 tprintf(", %s", sprintmode(mode));
2177 switch (mode & S_IFMT) {
2180 #if defined(SPARC) || defined(SPARC64)
2181 if (current_personality == 1)
2182 tprintf(", makedev(%lu, %lu)",
2183 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2184 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
2187 tprintf(", makedev(%lu, %lu)",
2188 (unsigned long) major(tcp->u_arg[offset + 2]),
2189 (unsigned long) minor(tcp->u_arg[offset + 2]));
2199 sys_mknod(struct tcb *tcp)
2201 return decode_mknod(tcp, 0);
2205 sys_mknodat(struct tcb *tcp)
2208 print_dirfd(tcp, tcp->u_arg[0]);
2209 return decode_mknod(tcp, 1);
2213 print_old_dirent(struct tcb *tcp, long addr)
2216 typedef struct kernel_dirent old_dirent_t;
2221 unsigned short d_reclen;
2227 if (!verbose(tcp) || umove(tcp, addr, &d) < 0) {
2228 tprintf("%#lx", addr);
2232 tprintf("{d_ino=%lu, d_off=%lu, d_reclen=%u, d_name=\"",
2233 (unsigned long) d.d_ino, (unsigned long) d.d_off, d.d_reclen);
2234 if (d.d_reclen > 256)
2236 printpathn(tcp, addr + offsetof(old_dirent_t, d_name), d.d_reclen);
2241 sys_readdir(struct tcb *tcp)
2243 if (entering(tcp)) {
2244 printfd(tcp, tcp->u_arg[0]);
2247 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2248 tprintf("%#lx", tcp->u_arg[1]);
2250 print_old_dirent(tcp, tcp->u_arg[1]);
2251 /* Not much point in printing this out, it is always 1. */
2252 if (tcp->u_arg[2] != 1)
2253 tprintf(", %lu", tcp->u_arg[2]);
2258 static const struct xlat direnttypes[] = {
2272 sys_getdents(struct tcb *tcp)
2274 int i, len, dents = 0;
2277 if (entering(tcp)) {
2278 printfd(tcp, tcp->u_arg[0]);
2282 if (syserror(tcp) || !verbose(tcp)) {
2283 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2287 /* Beware of insanely large or negative values in tcp->u_rval */
2288 if (tcp->u_rval > 1024*1024)
2290 if (tcp->u_rval < 0)
2292 buf = len ? malloc(len) : NULL;
2294 die_out_of_memory();
2295 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2296 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2302 for (i = 0; i < len;) {
2303 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2305 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2306 i ? " " : "", d->d_ino, d->d_off);
2307 tprintf("d_reclen=%u, d_name=\"%s\", d_type=",
2308 d->d_reclen, d->d_name);
2309 printxval(direnttypes, buf[i + d->d_reclen - 1], "DT_???");
2313 tprints("/* d_reclen == 0, problem here */");
2322 tprintf("/* %u entries */", dents);
2323 tprintf(", %lu", tcp->u_arg[2]);
2329 sys_getdents64(struct tcb *tcp)
2331 int i, len, dents = 0;
2334 if (entering(tcp)) {
2335 printfd(tcp, tcp->u_arg[0]);
2339 if (syserror(tcp) || !verbose(tcp)) {
2340 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2345 /* Beware of insanely large or negative tcp->u_rval */
2346 if (tcp->u_rval > 1024*1024)
2348 if (tcp->u_rval < 0)
2350 buf = len ? malloc(len) : NULL;
2352 die_out_of_memory();
2354 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2355 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2361 for (i = 0; i < len;) {
2362 struct dirent64 *d = (struct dirent64 *) &buf[i];
2364 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
2369 printxval(direnttypes, d->d_type, "DT_???");
2371 tprintf("d_reclen=%u, d_name=\"%s\"}",
2372 d->d_reclen, d->d_name);
2375 tprints("/* d_reclen == 0, problem here */");
2384 tprintf("/* %u entries */", dents);
2385 tprintf(", %lu", tcp->u_arg[2]);
2391 sys_getcwd(struct tcb *tcp)
2395 tprintf("%#lx", tcp->u_arg[0]);
2397 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2398 tprintf(", %lu", tcp->u_arg[1]);
2403 #ifdef HAVE_SYS_ASYNCH_H
2406 sys_aioread(struct tcb *tcp)
2408 struct aio_result_t res;
2410 if (entering(tcp)) {
2411 tprintf("%lu, ", tcp->u_arg[0]);
2414 tprintf("%#lx", tcp->u_arg[1]);
2416 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2417 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2418 printxval(whence, tcp->u_arg[4], "L_???");
2419 if (syserror(tcp) || tcp->u_arg[5] == 0
2420 || umove(tcp, tcp->u_arg[5], &res) < 0)
2421 tprintf(", %#lx", tcp->u_arg[5]);
2423 tprintf(", {aio_return %d aio_errno %d}",
2424 res.aio_return, res.aio_errno);
2430 sys_aiowrite(struct tcb *tcp)
2432 struct aio_result_t res;
2434 if (entering(tcp)) {
2435 tprintf("%lu, ", tcp->u_arg[0]);
2436 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2437 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2438 printxval(whence, tcp->u_arg[4], "L_???");
2441 if (tcp->u_arg[5] == 0)
2443 else if (syserror(tcp)
2444 || umove(tcp, tcp->u_arg[5], &res) < 0)
2445 tprintf(", %#lx", tcp->u_arg[5]);
2447 tprintf(", {aio_return %d aio_errno %d}",
2448 res.aio_return, res.aio_errno);
2454 sys_aiowait(struct tcb *tcp)
2457 printtv(tcp, tcp->u_arg[0]);
2462 sys_aiocancel(struct tcb *tcp)
2464 struct aio_result_t res;
2467 if (tcp->u_arg[0] == 0)
2469 else if (syserror(tcp)
2470 || umove(tcp, tcp->u_arg[0], &res) < 0)
2471 tprintf("%#lx", tcp->u_arg[0]);
2473 tprintf("{aio_return %d aio_errno %d}",
2474 res.aio_return, res.aio_errno);
2479 #endif /* HAVE_SYS_ASYNCH_H */
2481 static const struct xlat xattrflags[] = {
2484 XLAT(XATTR_REPLACE),
2490 print_xattr_val(struct tcb *tcp, int failed,
2492 unsigned long insize,
2498 unsigned long capacity = 4 * size + 1;
2499 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2500 if (buf == NULL || /* probably a bogus size argument */
2501 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2505 unsigned char *out = buf;
2506 unsigned char *in = &buf[3 * size];
2508 for (i = 0; i < size; ++i) {
2509 if (in[i] >= ' ' && in[i] <= 0x7e)
2512 #define tohex(n) "0123456789abcdef"[n]
2515 *out++ = tohex(in[i] / 16);
2516 *out++ = tohex(in[i] % 16);
2519 /* Don't print terminating NUL if there is one. */
2520 if (i > 0 && in[i - 1] == '\0')
2523 tprintf(", \"%s\", %ld", buf, insize);
2528 tprintf(", 0x%lx, %ld", arg, insize);
2532 sys_setxattr(struct tcb *tcp)
2534 if (entering(tcp)) {
2535 printpath(tcp, tcp->u_arg[0]);
2537 printstr(tcp, tcp->u_arg[1], -1);
2538 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2540 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2546 sys_fsetxattr(struct tcb *tcp)
2548 if (entering(tcp)) {
2549 printfd(tcp, tcp->u_arg[0]);
2551 printstr(tcp, tcp->u_arg[1], -1);
2552 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2554 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2560 sys_getxattr(struct tcb *tcp)
2562 if (entering(tcp)) {
2563 printpath(tcp, tcp->u_arg[0]);
2565 printstr(tcp, tcp->u_arg[1], -1);
2567 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2574 sys_fgetxattr(struct tcb *tcp)
2576 if (entering(tcp)) {
2577 printfd(tcp, tcp->u_arg[0]);
2579 printstr(tcp, tcp->u_arg[1], -1);
2581 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2588 print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2590 if (syserror(tcp)) {
2591 tprintf("%#lx", addr);
2597 (size < tcp->u_rval) ? size : tcp->u_rval;
2598 printstr(tcp, addr, len);
2601 tprintf(", %lu", size);
2605 sys_listxattr(struct tcb *tcp)
2607 if (entering(tcp)) {
2608 printpath(tcp, tcp->u_arg[0]);
2611 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2617 sys_flistxattr(struct tcb *tcp)
2619 if (entering(tcp)) {
2620 printfd(tcp, tcp->u_arg[0]);
2623 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2629 sys_removexattr(struct tcb *tcp)
2631 if (entering(tcp)) {
2632 printpath(tcp, tcp->u_arg[0]);
2634 printstr(tcp, tcp->u_arg[1], -1);
2640 sys_fremovexattr(struct tcb *tcp)
2642 if (entering(tcp)) {
2643 printfd(tcp, tcp->u_arg[0]);
2645 printstr(tcp, tcp->u_arg[1], -1);
2650 static const struct xlat advise[] = {
2651 XLAT(POSIX_FADV_NORMAL),
2652 XLAT(POSIX_FADV_RANDOM),
2653 XLAT(POSIX_FADV_SEQUENTIAL),
2654 XLAT(POSIX_FADV_WILLNEED),
2655 XLAT(POSIX_FADV_DONTNEED),
2656 XLAT(POSIX_FADV_NOREUSE),
2661 sys_fadvise64(struct tcb *tcp)
2663 if (entering(tcp)) {
2665 printfd(tcp, tcp->u_arg[0]);
2666 argn = printllval_aligned(tcp, ", %lld", 1);
2667 tprintf(", %ld, ", tcp->u_arg[argn++]);
2668 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2674 sys_fadvise64_64(struct tcb *tcp)
2676 if (entering(tcp)) {
2678 printfd(tcp, tcp->u_arg[0]);
2679 argn = printllval_aligned(tcp, ", %lld, ", 1);
2680 argn = printllval_aligned(tcp, "%lld, ", argn);
2681 #if defined __ARM_EABI__ || defined AARCH64 || defined POWERPC || defined XTENSA
2682 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
2684 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2690 static const struct xlat sync_file_range_flags[] = {
2691 XLAT(SYNC_FILE_RANGE_WAIT_BEFORE),
2692 XLAT(SYNC_FILE_RANGE_WRITE),
2693 XLAT(SYNC_FILE_RANGE_WAIT_AFTER),
2698 sys_sync_file_range(struct tcb *tcp)
2700 if (entering(tcp)) {
2702 printfd(tcp, tcp->u_arg[0]);
2703 argn = printllval_aligned(tcp, ", %lld, ", 1);
2704 argn = printllval_aligned(tcp, "%lld, ", argn);
2705 printflags(sync_file_range_flags, tcp->u_arg[argn],
2706 "SYNC_FILE_RANGE_???");
2712 sys_sync_file_range2(struct tcb *tcp)
2714 if (entering(tcp)) {
2716 printfd(tcp, tcp->u_arg[0]);
2717 printflags(sync_file_range_flags, 1,
2718 "SYNC_FILE_RANGE_???");
2719 argn = printllval_aligned(tcp, ", %lld, ", 2);
2720 argn = printllval_aligned(tcp, "%lld, ", argn);
2726 sys_fallocate(struct tcb *tcp)
2728 if (entering(tcp)) {
2730 printfd(tcp, tcp->u_arg[0]); /* fd */
2731 tprintf(", %#lo, ", tcp->u_arg[1]); /* mode */
2732 argn = printllval_aligned(tcp, "%llu, ", 2); /* offset */
2733 printllval_aligned(tcp, "%llu", argn); /* len */
2738 #ifndef SWAP_FLAG_PREFER
2739 # define SWAP_FLAG_PREFER 0x8000
2741 #ifndef SWAP_FLAG_DISCARD
2742 # define SWAP_FLAG_DISCARD 0x10000
2744 static const struct xlat swap_flags[] = {
2745 XLAT(SWAP_FLAG_PREFER),
2746 XLAT(SWAP_FLAG_DISCARD),
2751 sys_swapon(struct tcb *tcp)
2753 if (entering(tcp)) {
2754 int flags = tcp->u_arg[1];
2755 printpath(tcp, tcp->u_arg[0]);
2757 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2759 if (flags & SWAP_FLAG_PREFER)
2760 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);