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.
33 #if defined(SPARC) || defined(SPARC64)
35 unsigned short st_dev;
37 unsigned short st_mode;
39 unsigned short st_uid;
40 unsigned short st_gid;
41 unsigned short st_rdev;
44 unsigned int __unused1;
46 unsigned int __unused2;
48 unsigned int __unused3;
51 unsigned int __unused4[2];
58 unsigned int st_nlink;
68 unsigned long __unused4[2];
71 # define stat kernel_stat
72 # include <asm/stat.h>
76 unsigned long long st_dev;
77 unsigned long long st_ino;
78 unsigned long long st_nlink;
84 unsigned long long st_rdev;
89 unsigned long long st_atime;
90 unsigned long long st_atime_nsec;
91 unsigned long long st_mtime;
92 unsigned long long st_mtime_nsec;
93 unsigned long long st_ctime;
94 unsigned long long st_ctime_nsec;
95 long long __unused[3];
99 unsigned long long st_dev;
100 unsigned char __pad0[4];
101 unsigned long __st_ino;
102 unsigned int st_mode;
103 unsigned int st_nlink;
104 unsigned long st_uid;
105 unsigned long st_gid;
106 unsigned long long st_rdev;
107 unsigned char __pad3[4];
109 unsigned long st_blksize;
110 unsigned long long st_blocks;
111 unsigned long st_atime;
112 unsigned long st_atime_nsec;
113 unsigned long st_mtime;
114 unsigned int st_mtime_nsec;
115 unsigned long st_ctime;
116 unsigned long st_ctime_nsec;
117 unsigned long long st_ino;
118 } __attribute__((packed));
119 # define HAVE_STAT64 1
121 struct __old_kernel_stat {
122 unsigned short st_dev;
123 unsigned short st_ino;
124 unsigned short st_mode;
125 unsigned short st_nlink;
126 unsigned short st_uid;
127 unsigned short st_gid;
128 unsigned short st_rdev;
129 unsigned int st_size;
130 unsigned int st_atime;
131 unsigned int st_mtime;
132 unsigned int st_ctime;
143 # define dev_t __kernel_dev_t
144 # define ino_t __kernel_ino_t
145 # define mode_t __kernel_mode_t
146 # define nlink_t __kernel_nlink_t
147 # define uid_t __kernel_uid_t
148 # define gid_t __kernel_gid_t
149 # define off_t __kernel_off_t
150 # define loff_t __kernel_loff_t
152 # include <asm/stat.h>
164 # define mode_t mode_t
165 # define nlink_t nlink_t
169 # define loff_t loff_t
172 #define stat libc_stat
173 #define stat64 libc_stat64
174 #include <sys/stat.h>
177 /* These might be macros. */
183 #ifdef HAVE_LINUX_XATTR_H
184 # include <linux/xattr.h>
186 # define XATTR_CREATE 1
187 # define XATTR_REPLACE 2
190 #ifdef MAJOR_IN_SYSMACROS
191 # include <sys/sysmacros.h>
194 #ifdef MAJOR_IN_MKDEV
195 # include <sys/mkdev.h>
199 # if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
202 # define O_LARGEFILE 0x40000
203 # elif defined X86_64 || defined S390X
204 # define O_LARGEFILE 0100000
209 #include "xlat/open_access_modes.h"
210 #include "xlat/open_mode_flags.h"
213 # define AT_FDCWD -100
216 /* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
217 * extension to get the right value. We do this by declaring fd as int here.
220 print_dirfd(struct tcb *tcp, int fd)
223 tprints("AT_FDCWD, ");
231 * low bits of the open(2) flags define access mode,
232 * other bits are real flags.
235 sprint_open_modes(int flags)
237 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
241 const struct xlat *x;
244 p = stpcpy(outstr, "flags");
245 str = xlookup(open_access_modes, flags & 3);
255 for (x = open_mode_flags; x->str; x++) {
256 if ((flags & x->val) == x->val) {
258 p = stpcpy(p, x->str);
265 /* flags is still nonzero */
267 sprintf(p, "%#x", flags);
272 tprint_open_modes(int flags)
274 tprints(sprint_open_modes(flags) + sizeof("flags"));
278 decode_open(struct tcb *tcp, int offset)
281 printpath(tcp, tcp->u_arg[offset]);
284 tprint_open_modes(tcp->u_arg[offset + 1]);
285 if (tcp->u_arg[offset + 1] & O_CREAT) {
287 tprintf(", %#lo", tcp->u_arg[offset + 2]);
294 sys_open(struct tcb *tcp)
296 return decode_open(tcp, 0);
300 sys_openat(struct tcb *tcp)
303 print_dirfd(tcp, tcp->u_arg[0]);
304 return decode_open(tcp, 1);
307 #if defined(SPARC) || defined(SPARC64)
308 #include "xlat/openmodessol.h"
311 solaris_open(struct tcb *tcp)
314 printpath(tcp, tcp->u_arg[0]);
317 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
318 if (tcp->u_arg[1] & 0x100) {
320 tprintf(", %#lo", tcp->u_arg[2]);
329 sys_creat(struct tcb *tcp)
332 printpath(tcp, tcp->u_arg[0]);
333 tprintf(", %#lo", tcp->u_arg[1]);
338 #include "xlat/access_flags.h"
341 decode_access(struct tcb *tcp, int offset)
344 printpath(tcp, tcp->u_arg[offset]);
346 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
352 sys_access(struct tcb *tcp)
354 return decode_access(tcp, 0);
358 sys_faccessat(struct tcb *tcp)
361 print_dirfd(tcp, tcp->u_arg[0]);
362 return decode_access(tcp, 1);
366 sys_umask(struct tcb *tcp)
369 tprintf("%#lo", tcp->u_arg[0]);
374 #include "xlat/whence_codes.h"
376 /* Linux kernel has exactly one version of lseek:
377 * fs/read_write.c::SYSCALL_DEFINE3(lseek, unsigned, fd, off_t, offset, unsigned, origin)
378 * In kernel, off_t is always the same as (kernel's) long
379 * (see include/uapi/asm-generic/posix_types.h),
380 * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
381 * Use test/x32_lseek.c to test lseek decoding.
383 #if defined(LINUX_MIPSN32) || defined(X32)
385 sys_lseek(struct tcb *tcp)
391 printfd(tcp, tcp->u_arg[0]);
392 offset = tcp->ext_arg[1];
393 whence = tcp->u_arg[2];
394 if (whence == SEEK_SET)
395 tprintf(", %llu, ", offset);
397 tprintf(", %lld, ", offset);
398 printxval(whence_codes, whence, "SEEK_???");
400 return RVAL_LUDECIMAL;
404 sys_lseek(struct tcb *tcp)
410 printfd(tcp, tcp->u_arg[0]);
411 offset = tcp->u_arg[1];
412 whence = tcp->u_arg[2];
413 if (whence == SEEK_SET)
414 tprintf(", %lu, ", offset);
416 tprintf(", %ld, ", offset);
417 printxval(whence_codes, whence, "SEEK_???");
419 return RVAL_UDECIMAL;
423 /* llseek syscall takes explicitly two ulong arguments hi, lo,
424 * rather than one 64-bit argument for which LONG_LONG works
425 * appropriate for the native byte order.
427 * See kernel's fs/read_write.c::SYSCALL_DEFINE5(llseek, ...)
429 * hi,lo are "unsigned longs" and combined exactly this way in kernel:
430 * ((loff_t) hi << 32) | lo
431 * Note that for architectures with kernel's long wider than userspace long
432 * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
433 * for hi and lo. We would need to use tcp->ext_arg[N] on x32...
434 * ...however, x32 (and x86_64) does not _have_ llseek syscall as such.
437 sys_llseek(struct tcb *tcp)
440 printfd(tcp, tcp->u_arg[0]);
441 if (tcp->u_arg[4] == SEEK_SET)
443 ((long long) tcp->u_arg[1]) << 32 |
444 (unsigned long long) (unsigned) tcp->u_arg[2]);
447 ((long long) tcp->u_arg[1]) << 32 |
448 (unsigned long long) (unsigned) tcp->u_arg[2]);
452 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
453 tprintf("%#lx, ", tcp->u_arg[3]);
455 tprintf("[%llu], ", off);
456 printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
462 sys_readahead(struct tcb *tcp)
466 printfd(tcp, tcp->u_arg[0]);
467 argn = printllval(tcp, ", %lld", 1);
468 tprintf(", %ld", tcp->u_arg[argn]);
474 sys_truncate(struct tcb *tcp)
477 printpath(tcp, tcp->u_arg[0]);
478 tprintf(", %lu", tcp->u_arg[1]);
484 sys_truncate64(struct tcb *tcp)
487 printpath(tcp, tcp->u_arg[0]);
488 printllval(tcp, ", %llu", 1);
494 sys_ftruncate(struct tcb *tcp)
497 printfd(tcp, tcp->u_arg[0]);
498 tprintf(", %lu", tcp->u_arg[1]);
504 sys_ftruncate64(struct tcb *tcp)
507 printfd(tcp, tcp->u_arg[0]);
508 printllval(tcp, ", %llu", 1);
515 #include "xlat/modetypes.h"
520 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
525 if ((mode & S_IFMT) == 0)
527 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
528 sprintf(buf, "%#o", mode);
531 s = buf + sprintf(buf, "%s%s%s%s", s,
532 (mode & S_ISUID) ? "|S_ISUID" : "",
533 (mode & S_ISGID) ? "|S_ISGID" : "",
534 (mode & S_ISVTX) ? "|S_ISVTX" : "");
535 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
537 sprintf((char*)s, "|%#o", mode);
538 s = (*buf == '|') ? buf + 1 : buf;
546 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
554 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
555 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
556 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
558 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
563 #if defined(SPARC) || defined(SPARC64)
571 int st_pad1[3]; /* network id */
580 int st_pad3; /* st_size, off_t expansion */
581 timestruct_t st_atime;
582 timestruct_t st_mtime;
583 timestruct_t st_ctime;
587 int st_pad4[8]; /* expansion area */
591 printstatsol(struct tcb *tcp, long addr)
593 struct solstat statbuf;
595 if (umove(tcp, addr, &statbuf) < 0) {
600 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
601 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
602 (unsigned long) (statbuf.st_dev & 0x3ffff),
603 (unsigned long) statbuf.st_ino,
604 sprintmode(statbuf.st_mode));
605 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
606 (unsigned long) statbuf.st_nlink,
607 (unsigned long) statbuf.st_uid,
608 (unsigned long) statbuf.st_gid);
609 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
610 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
613 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
614 switch (statbuf.st_mode & S_IFMT) {
615 case S_IFCHR: case S_IFBLK:
616 tprintf("st_rdev=makedev(%lu, %lu), ",
617 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
618 (unsigned long) (statbuf.st_rdev & 0x3ffff));
621 tprintf("st_size=%u, ", statbuf.st_size);
625 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
626 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
627 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
633 # if defined(SPARC64)
635 printstat_sparc64(struct tcb *tcp, long addr)
637 struct stat_sparc64 statbuf;
639 if (umove(tcp, addr, &statbuf) < 0) {
645 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
646 (unsigned long) major(statbuf.st_dev),
647 (unsigned long) minor(statbuf.st_dev),
648 (unsigned long) statbuf.st_ino,
649 sprintmode(statbuf.st_mode));
650 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
651 (unsigned long) statbuf.st_nlink,
652 (unsigned long) statbuf.st_uid,
653 (unsigned long) statbuf.st_gid);
654 tprintf("st_blksize=%lu, ",
655 (unsigned long) statbuf.st_blksize);
656 tprintf("st_blocks=%lu, ",
657 (unsigned long) statbuf.st_blocks);
660 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
661 switch (statbuf.st_mode & S_IFMT) {
662 case S_IFCHR: case S_IFBLK:
663 tprintf("st_rdev=makedev(%lu, %lu), ",
664 (unsigned long) major(statbuf.st_rdev),
665 (unsigned long) minor(statbuf.st_rdev));
668 tprintf("st_size=%lu, ", statbuf.st_size);
672 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
673 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
674 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
679 # endif /* SPARC64 */
680 #endif /* SPARC[64] */
682 #if defined POWERPC64
683 struct stat_powerpc32 {
686 unsigned int st_mode;
687 unsigned short st_nlink;
690 unsigned int st_rdev;
691 unsigned int st_size;
692 unsigned int st_blksize;
693 unsigned int st_blocks;
694 unsigned int st_atime;
695 unsigned int st_atime_nsec;
696 unsigned int st_mtime;
697 unsigned int st_mtime_nsec;
698 unsigned int st_ctime;
699 unsigned int st_ctime_nsec;
700 unsigned int __unused4;
701 unsigned int __unused5;
705 printstat_powerpc32(struct tcb *tcp, long addr)
707 struct stat_powerpc32 statbuf;
709 if (umove(tcp, addr, &statbuf) < 0) {
715 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
716 major(statbuf.st_dev), minor(statbuf.st_dev),
718 sprintmode(statbuf.st_mode));
719 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
720 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
721 tprintf("st_blksize=%u, ", statbuf.st_blksize);
722 tprintf("st_blocks=%u, ", statbuf.st_blocks);
725 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
726 switch (statbuf.st_mode & S_IFMT) {
727 case S_IFCHR: case S_IFBLK:
728 tprintf("st_rdev=makedev(%lu, %lu), ",
729 (unsigned long) major(statbuf.st_rdev),
730 (unsigned long) minor(statbuf.st_rdev));
733 tprintf("st_size=%u, ", statbuf.st_size);
737 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
738 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
739 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
744 #endif /* POWERPC64 */
746 #include "xlat/fileflags.h"
749 realprintstat(struct tcb *tcp, struct stat *statbuf)
752 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
753 (unsigned long) major(statbuf->st_dev),
754 (unsigned long) minor(statbuf->st_dev),
755 (unsigned long) statbuf->st_ino,
756 sprintmode(statbuf->st_mode));
757 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
758 (unsigned long) statbuf->st_nlink,
759 (unsigned long) statbuf->st_uid,
760 (unsigned long) statbuf->st_gid);
761 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
762 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
764 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
765 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
769 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
770 switch (statbuf->st_mode & S_IFMT) {
771 case S_IFCHR: case S_IFBLK:
772 #ifdef HAVE_STRUCT_STAT_ST_RDEV
773 tprintf("st_rdev=makedev(%lu, %lu), ",
774 (unsigned long) major(statbuf->st_rdev),
775 (unsigned long) minor(statbuf->st_rdev));
776 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
777 tprintf("st_size=makedev(%lu, %lu), ",
778 (unsigned long) major(statbuf->st_size),
779 (unsigned long) minor(statbuf->st_size));
780 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
783 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
787 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
788 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
789 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
790 #if HAVE_STRUCT_STAT_ST_FLAGS
791 tprints(", st_flags=");
792 printflags(fileflags, statbuf->st_flags, "UF_???");
794 #if HAVE_STRUCT_STAT_ST_ACLCNT
795 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
797 #if HAVE_STRUCT_STAT_ST_LEVEL
798 tprintf(", st_level=%ld", statbuf->st_level);
800 #if HAVE_STRUCT_STAT_ST_FSTYPE
801 tprintf(", st_fstype=%.*s",
802 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
804 #if HAVE_STRUCT_STAT_ST_GEN
805 tprintf(", st_gen=%u", statbuf->st_gen);
815 printstat(struct tcb *tcp, long addr)
823 if (syserror(tcp) || !verbose(tcp)) {
824 tprintf("%#lx", addr);
828 #if defined(SPARC) || defined(SPARC64)
829 if (current_personality == 1) {
830 printstatsol(tcp, addr);
834 else if (current_personality == 2) {
835 printstat_sparc64(tcp, addr);
839 #endif /* SPARC[64] */
841 #if defined POWERPC64
842 if (current_personality == 1) {
843 printstat_powerpc32(tcp, addr);
848 if (umove(tcp, addr, &statbuf) < 0) {
853 realprintstat(tcp, &statbuf);
856 # define printstat printstat64
859 #if !defined HAVE_STAT64 && (defined AARCH64 || defined X86_64)
861 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
862 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
863 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
864 * __GNUC__ is needed for the required __attribute__ below.
866 * Similarly, aarch64 has a unified `struct stat' but its arm personality
867 * needs `struct stat64' (which also expects a 32-bit `long' but which
868 * shouldn't be packed).
871 unsigned long long st_dev;
872 unsigned char __pad0[4];
873 unsigned int __st_ino;
874 unsigned int st_mode;
875 unsigned int st_nlink;
878 unsigned long long st_rdev;
879 unsigned char __pad3[4];
881 unsigned int st_blksize;
882 unsigned long long st_blocks;
883 unsigned int st_atime;
884 unsigned int st_atime_nsec;
885 unsigned int st_mtime;
886 unsigned int st_mtime_nsec;
887 unsigned int st_ctime;
888 unsigned int st_ctime_nsec;
889 unsigned long long st_ino;
892 __attribute__((packed))
893 # define STAT64_SIZE 96
895 # define STAT64_SIZE 104
898 # define HAVE_STAT64 1
903 printstat64(struct tcb *tcp, long addr)
908 struct stat64 statbuf;
912 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
919 if (syserror(tcp) || !verbose(tcp)) {
920 tprintf("%#lx", addr);
924 #if defined(SPARC) || defined(SPARC64)
925 if (current_personality == 1) {
926 printstatsol(tcp, addr);
930 else if (current_personality == 2) {
931 printstat_sparc64(tcp, addr);
935 #endif /* SPARC[64] */
938 if (current_personality != 0) {
939 printstat(tcp, addr);
944 if (current_personality != 1) {
945 printstat(tcp, addr);
950 if (umove(tcp, addr, &statbuf) < 0) {
956 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
957 (unsigned long) major(statbuf.st_dev),
958 (unsigned long) minor(statbuf.st_dev),
959 (unsigned long long) statbuf.st_ino,
960 sprintmode(statbuf.st_mode));
961 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
962 (unsigned long) statbuf.st_nlink,
963 (unsigned long) statbuf.st_uid,
964 (unsigned long) statbuf.st_gid);
965 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
966 tprintf("st_blksize=%lu, ",
967 (unsigned long) statbuf.st_blksize);
968 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
969 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
970 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
971 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
974 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
975 switch (statbuf.st_mode & S_IFMT) {
976 case S_IFCHR: case S_IFBLK:
977 #ifdef HAVE_STRUCT_STAT_ST_RDEV
978 tprintf("st_rdev=makedev(%lu, %lu), ",
979 (unsigned long) major(statbuf.st_rdev),
980 (unsigned long) minor(statbuf.st_rdev));
981 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
982 tprintf("st_size=makedev(%lu, %lu), ",
983 (unsigned long) major(statbuf.st_size),
984 (unsigned long) minor(statbuf.st_size));
985 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
988 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
992 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
993 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
994 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
995 #if HAVE_STRUCT_STAT_ST_FLAGS
996 tprints(", st_flags=");
997 printflags(fileflags, statbuf.st_flags, "UF_???");
999 #if HAVE_STRUCT_STAT_ST_ACLCNT
1000 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1002 #if HAVE_STRUCT_STAT_ST_LEVEL
1003 tprintf(", st_level=%ld", statbuf.st_level);
1005 #if HAVE_STRUCT_STAT_ST_FSTYPE
1006 tprintf(", st_fstype=%.*s",
1007 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1009 #if HAVE_STRUCT_STAT_ST_GEN
1010 tprintf(", st_gen=%u", statbuf.st_gen);
1017 #endif /* HAVE_STAT64 */
1019 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1021 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
1023 newbuf->st_dev = oldbuf->st_dev;
1024 newbuf->st_ino = oldbuf->st_ino;
1025 newbuf->st_mode = oldbuf->st_mode;
1026 newbuf->st_nlink = oldbuf->st_nlink;
1027 newbuf->st_uid = oldbuf->st_uid;
1028 newbuf->st_gid = oldbuf->st_gid;
1029 newbuf->st_rdev = oldbuf->st_rdev;
1030 newbuf->st_size = oldbuf->st_size;
1031 newbuf->st_atime = oldbuf->st_atime;
1032 newbuf->st_mtime = oldbuf->st_mtime;
1033 newbuf->st_ctime = oldbuf->st_ctime;
1034 newbuf->st_blksize = 0; /* not supported in old_stat */
1035 newbuf->st_blocks = 0; /* not supported in old_stat */
1039 printoldstat(struct tcb *tcp, long addr)
1041 struct __old_kernel_stat statbuf;
1042 struct stat newstatbuf;
1048 if (syserror(tcp) || !verbose(tcp)) {
1049 tprintf("%#lx", addr);
1053 # if defined(SPARC) || defined(SPARC64)
1054 if (current_personality == 1) {
1055 printstatsol(tcp, addr);
1060 if (umove(tcp, addr, &statbuf) < 0) {
1065 convertoldstat(&statbuf, &newstatbuf);
1066 realprintstat(tcp, &newstatbuf);
1071 sys_stat(struct tcb *tcp)
1073 if (entering(tcp)) {
1074 printpath(tcp, tcp->u_arg[0]);
1077 printstat(tcp, tcp->u_arg[1]);
1084 printstat64_x32(struct tcb *tcp, long addr)
1086 struct stat64 statbuf;
1092 if (syserror(tcp) || !verbose(tcp)) {
1093 tprintf("%#lx", addr);
1097 if (umove(tcp, addr, &statbuf) < 0) {
1103 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1104 (unsigned long) major(statbuf.st_dev),
1105 (unsigned long) minor(statbuf.st_dev),
1106 (unsigned long long) statbuf.st_ino,
1107 sprintmode(statbuf.st_mode));
1108 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1109 (unsigned long) statbuf.st_nlink,
1110 (unsigned long) statbuf.st_uid,
1111 (unsigned long) statbuf.st_gid);
1112 tprintf("st_blksize=%lu, ",
1113 (unsigned long) statbuf.st_blksize);
1114 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1117 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1118 switch (statbuf.st_mode & S_IFMT) {
1119 case S_IFCHR: case S_IFBLK:
1120 tprintf("st_rdev=makedev(%lu, %lu), ",
1121 (unsigned long) major(statbuf.st_rdev),
1122 (unsigned long) minor(statbuf.st_rdev));
1125 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1129 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1130 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1131 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1140 sys_stat64(struct tcb *tcp)
1143 if (entering(tcp)) {
1144 printpath(tcp, tcp->u_arg[0]);
1148 printstat64_x32(tcp, tcp->u_arg[1]);
1150 printstat64(tcp, tcp->u_arg[1]);
1155 return printargs(tcp);
1159 #ifndef AT_SYMLINK_NOFOLLOW
1160 # define AT_SYMLINK_NOFOLLOW 0x100
1162 #ifndef AT_REMOVEDIR
1163 # define AT_REMOVEDIR 0x200
1165 #ifndef AT_SYMLINK_FOLLOW
1166 # define AT_SYMLINK_FOLLOW 0x400
1168 #ifndef AT_NO_AUTOMOUNT
1169 # define AT_NO_AUTOMOUNT 0x800
1171 #ifndef AT_EMPTY_PATH
1172 # define AT_EMPTY_PATH 0x1000
1175 #include "xlat/at_flags.h"
1178 sys_newfstatat(struct tcb *tcp)
1180 if (entering(tcp)) {
1181 print_dirfd(tcp, tcp->u_arg[0]);
1182 printpath(tcp, tcp->u_arg[1]);
1186 if (current_personality == 0)
1187 printstat(tcp, tcp->u_arg[2]);
1189 printstat64(tcp, tcp->u_arg[2]);
1190 #elif defined HAVE_STAT64
1191 printstat64(tcp, tcp->u_arg[2]);
1193 printstat(tcp, tcp->u_arg[2]);
1196 printflags(at_flags, tcp->u_arg[3], "AT_???");
1201 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1203 sys_oldstat(struct tcb *tcp)
1205 if (entering(tcp)) {
1206 printpath(tcp, tcp->u_arg[0]);
1209 printoldstat(tcp, tcp->u_arg[1]);
1216 sys_fstat(struct tcb *tcp)
1218 if (entering(tcp)) {
1219 printfd(tcp, tcp->u_arg[0]);
1222 printstat(tcp, tcp->u_arg[1]);
1228 sys_fstat64(struct tcb *tcp)
1231 if (entering(tcp)) {
1232 printfd(tcp, tcp->u_arg[0]);
1236 printstat64_x32(tcp, tcp->u_arg[1]);
1238 printstat64(tcp, tcp->u_arg[1]);
1243 return printargs(tcp);
1247 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1249 sys_oldfstat(struct tcb *tcp)
1251 if (entering(tcp)) {
1252 printfd(tcp, tcp->u_arg[0]);
1255 printoldstat(tcp, tcp->u_arg[1]);
1261 #if defined(SPARC) || defined(SPARC64)
1264 sys_xstat(struct tcb *tcp)
1266 if (entering(tcp)) {
1267 tprintf("%ld, ", tcp->u_arg[0]);
1268 printpath(tcp, tcp->u_arg[1]);
1272 if (tcp->u_arg[0] == _STAT64_VER)
1273 printstat64(tcp, tcp->u_arg[2]);
1276 printstat(tcp, tcp->u_arg[2]);
1282 sys_fxstat(struct tcb *tcp)
1285 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1288 if (tcp->u_arg[0] == _STAT64_VER)
1289 printstat64(tcp, tcp->u_arg[2]);
1292 printstat(tcp, tcp->u_arg[2]);
1298 sys_lxstat(struct tcb *tcp)
1300 if (entering(tcp)) {
1301 tprintf("%ld, ", tcp->u_arg[0]);
1302 printpath(tcp, tcp->u_arg[1]);
1306 if (tcp->u_arg[0] == _STAT64_VER)
1307 printstat64(tcp, tcp->u_arg[2]);
1310 printstat(tcp, tcp->u_arg[2]);
1316 sys_xmknod(struct tcb *tcp)
1318 int mode = tcp->u_arg[2];
1320 if (entering(tcp)) {
1321 tprintf("%ld, ", tcp->u_arg[0]);
1322 printpath(tcp, tcp->u_arg[1]);
1323 tprintf(", %s", sprintmode(mode));
1324 switch (mode & S_IFMT) {
1325 case S_IFCHR: case S_IFBLK:
1326 tprintf(", makedev(%lu, %lu)",
1327 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1328 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1337 #endif /* SPARC[64] */
1341 sys_chdir(struct tcb *tcp)
1343 if (entering(tcp)) {
1344 printpath(tcp, tcp->u_arg[0]);
1350 sys_link(struct tcb *tcp)
1352 if (entering(tcp)) {
1353 printpath(tcp, tcp->u_arg[0]);
1355 printpath(tcp, tcp->u_arg[1]);
1361 sys_linkat(struct tcb *tcp)
1363 if (entering(tcp)) {
1364 print_dirfd(tcp, tcp->u_arg[0]);
1365 printpath(tcp, tcp->u_arg[1]);
1367 print_dirfd(tcp, tcp->u_arg[2]);
1368 printpath(tcp, tcp->u_arg[3]);
1370 printflags(at_flags, tcp->u_arg[4], "AT_???");
1376 sys_unlinkat(struct tcb *tcp)
1378 if (entering(tcp)) {
1379 print_dirfd(tcp, tcp->u_arg[0]);
1380 printpath(tcp, tcp->u_arg[1]);
1382 printflags(at_flags, tcp->u_arg[2], "AT_???");
1388 sys_symlinkat(struct tcb *tcp)
1390 if (entering(tcp)) {
1391 printpath(tcp, tcp->u_arg[0]);
1393 print_dirfd(tcp, tcp->u_arg[1]);
1394 printpath(tcp, tcp->u_arg[2]);
1400 decode_readlink(struct tcb *tcp, int offset)
1402 if (entering(tcp)) {
1403 printpath(tcp, tcp->u_arg[offset]);
1407 tprintf("%#lx", tcp->u_arg[offset + 1]);
1409 /* Used to use printpathn(), but readlink
1410 * neither includes NUL in the returned count,
1411 * nor actually writes it into memory.
1412 * printpathn() would decide on printing
1413 * "..." continuation based on garbage
1414 * past return buffer's end.
1416 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1417 tprintf(", %lu", tcp->u_arg[offset + 2]);
1423 sys_readlink(struct tcb *tcp)
1425 return decode_readlink(tcp, 0);
1429 sys_readlinkat(struct tcb *tcp)
1432 print_dirfd(tcp, tcp->u_arg[0]);
1433 return decode_readlink(tcp, 1);
1437 decode_renameat(struct tcb *tcp)
1439 print_dirfd(tcp, tcp->u_arg[0]);
1440 printpath(tcp, tcp->u_arg[1]);
1442 print_dirfd(tcp, tcp->u_arg[2]);
1443 printpath(tcp, tcp->u_arg[3]);
1447 sys_renameat(struct tcb *tcp)
1449 if (entering(tcp)) {
1450 decode_renameat(tcp);
1455 #include "xlat/rename_flags.h"
1458 sys_renameat2(struct tcb *tcp)
1460 if (entering(tcp)) {
1461 decode_renameat(tcp);
1463 printflags(rename_flags, tcp->u_arg[4], "RENAME_??");
1469 sys_chown(struct tcb *tcp)
1471 if (entering(tcp)) {
1472 printpath(tcp, tcp->u_arg[0]);
1473 printuid(", ", tcp->u_arg[1]);
1474 printuid(", ", tcp->u_arg[2]);
1480 sys_fchownat(struct tcb *tcp)
1482 if (entering(tcp)) {
1483 print_dirfd(tcp, tcp->u_arg[0]);
1484 printpath(tcp, tcp->u_arg[1]);
1485 printuid(", ", tcp->u_arg[2]);
1486 printuid(", ", tcp->u_arg[3]);
1488 printflags(at_flags, tcp->u_arg[4], "AT_???");
1494 sys_fchown(struct tcb *tcp)
1496 if (entering(tcp)) {
1497 printfd(tcp, tcp->u_arg[0]);
1498 printuid(", ", tcp->u_arg[1]);
1499 printuid(", ", tcp->u_arg[2]);
1505 decode_chmod(struct tcb *tcp, int offset)
1507 if (entering(tcp)) {
1508 printpath(tcp, tcp->u_arg[offset]);
1509 tprintf(", %#lo", tcp->u_arg[offset + 1]);
1515 sys_chmod(struct tcb *tcp)
1517 return decode_chmod(tcp, 0);
1521 sys_fchmodat(struct tcb *tcp)
1524 print_dirfd(tcp, tcp->u_arg[0]);
1525 return decode_chmod(tcp, 1);
1529 sys_fchmod(struct tcb *tcp)
1531 if (entering(tcp)) {
1532 printfd(tcp, tcp->u_arg[0]);
1533 tprintf(", %#lo", tcp->u_arg[1]);
1540 sys_osf_utimes(struct tcb *tcp)
1542 if (entering(tcp)) {
1543 printpath(tcp, tcp->u_arg[0]);
1545 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
1552 decode_utimes(struct tcb *tcp, int offset, int special)
1554 if (entering(tcp)) {
1555 printpath(tcp, tcp->u_arg[offset]);
1557 if (tcp->u_arg[offset + 1] == 0)
1561 printtv_bitness(tcp, tcp->u_arg[offset + 1],
1562 BITNESS_CURRENT, special);
1564 printtv_bitness(tcp, tcp->u_arg[offset + 1]
1565 + sizeof(struct timeval),
1566 BITNESS_CURRENT, special);
1574 sys_utimes(struct tcb *tcp)
1576 return decode_utimes(tcp, 0, 0);
1580 sys_futimesat(struct tcb *tcp)
1583 print_dirfd(tcp, tcp->u_arg[0]);
1584 return decode_utimes(tcp, 1, 0);
1588 sys_utimensat(struct tcb *tcp)
1590 if (entering(tcp)) {
1591 print_dirfd(tcp, tcp->u_arg[0]);
1592 decode_utimes(tcp, 1, 1);
1594 printflags(at_flags, tcp->u_arg[3], "AT_???");
1600 sys_utime(struct tcb *tcp)
1605 long paranoia_for_huge_wordsize[4];
1609 if (entering(tcp)) {
1610 printpath(tcp, tcp->u_arg[0]);
1613 wordsize = current_wordsize;
1616 else if (!verbose(tcp))
1617 tprintf("%#lx", tcp->u_arg[1]);
1618 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
1620 else if (wordsize == sizeof u.utl[0]) {
1621 tprintf("[%s,", sprinttime(u.utl[0]));
1622 tprintf(" %s]", sprinttime(u.utl[1]));
1624 else if (wordsize == sizeof u.uti[0]) {
1625 tprintf("[%s,", sprinttime(u.uti[0]));
1626 tprintf(" %s]", sprinttime(u.uti[1]));
1629 tprintf("<decode error: unsupported wordsize %d>",
1636 decode_mknod(struct tcb *tcp, int offset)
1638 int mode = tcp->u_arg[offset + 1];
1640 if (entering(tcp)) {
1641 printpath(tcp, tcp->u_arg[offset]);
1642 tprintf(", %s", sprintmode(mode));
1643 switch (mode & S_IFMT) {
1646 #if defined(SPARC) || defined(SPARC64)
1647 if (current_personality == 1)
1648 tprintf(", makedev(%lu, %lu)",
1649 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
1650 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
1653 tprintf(", makedev(%lu, %lu)",
1654 (unsigned long) major(tcp->u_arg[offset + 2]),
1655 (unsigned long) minor(tcp->u_arg[offset + 2]));
1665 sys_mknod(struct tcb *tcp)
1667 return decode_mknod(tcp, 0);
1671 sys_mknodat(struct tcb *tcp)
1674 print_dirfd(tcp, tcp->u_arg[0]);
1675 return decode_mknod(tcp, 1);
1679 sys_getcwd(struct tcb *tcp)
1683 tprintf("%#lx", tcp->u_arg[0]);
1685 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
1686 tprintf(", %lu", tcp->u_arg[1]);
1691 #include "xlat/xattrflags.h"
1694 print_xattr_val(struct tcb *tcp, int failed,
1696 unsigned long insize,
1702 unsigned long capacity = 4 * size + 1;
1703 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
1704 if (buf == NULL || /* probably a bogus size argument */
1705 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
1709 unsigned char *out = buf;
1710 unsigned char *in = &buf[3 * size];
1712 for (i = 0; i < size; ++i) {
1713 if (in[i] >= ' ' && in[i] <= 0x7e)
1716 #define tohex(n) "0123456789abcdef"[n]
1719 *out++ = tohex(in[i] / 16);
1720 *out++ = tohex(in[i] % 16);
1723 /* Don't print terminating NUL if there is one. */
1724 if (i > 0 && in[i - 1] == '\0')
1727 tprintf(", \"%s\", %ld", buf, insize);
1732 tprintf(", 0x%lx, %ld", arg, insize);
1736 sys_setxattr(struct tcb *tcp)
1738 if (entering(tcp)) {
1739 printpath(tcp, tcp->u_arg[0]);
1741 printstr(tcp, tcp->u_arg[1], -1);
1742 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
1744 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
1750 sys_fsetxattr(struct tcb *tcp)
1752 if (entering(tcp)) {
1753 printfd(tcp, tcp->u_arg[0]);
1755 printstr(tcp, tcp->u_arg[1], -1);
1756 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
1758 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
1764 sys_getxattr(struct tcb *tcp)
1766 if (entering(tcp)) {
1767 printpath(tcp, tcp->u_arg[0]);
1769 printstr(tcp, tcp->u_arg[1], -1);
1771 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
1778 sys_fgetxattr(struct tcb *tcp)
1780 if (entering(tcp)) {
1781 printfd(tcp, tcp->u_arg[0]);
1783 printstr(tcp, tcp->u_arg[1], -1);
1785 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
1792 print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
1794 if (syserror(tcp)) {
1795 tprintf("%#lx", addr);
1801 (size < (unsigned long) tcp->u_rval) ?
1802 size : (unsigned long) tcp->u_rval;
1803 printstr(tcp, addr, len);
1806 tprintf(", %lu", size);
1810 sys_listxattr(struct tcb *tcp)
1812 if (entering(tcp)) {
1813 printpath(tcp, tcp->u_arg[0]);
1816 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1822 sys_flistxattr(struct tcb *tcp)
1824 if (entering(tcp)) {
1825 printfd(tcp, tcp->u_arg[0]);
1828 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
1834 sys_removexattr(struct tcb *tcp)
1836 if (entering(tcp)) {
1837 printpath(tcp, tcp->u_arg[0]);
1839 printstr(tcp, tcp->u_arg[1], -1);
1845 sys_fremovexattr(struct tcb *tcp)
1847 if (entering(tcp)) {
1848 printfd(tcp, tcp->u_arg[0]);
1850 printstr(tcp, tcp->u_arg[1], -1);