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. */
184 #ifdef MAJOR_IN_SYSMACROS
185 # include <sys/sysmacros.h>
188 #ifdef MAJOR_IN_MKDEV
189 # include <sys/mkdev.h>
193 # if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
196 # define O_LARGEFILE 0x40000
197 # elif defined X86_64 || defined S390X
198 # define O_LARGEFILE 0100000
203 #include "xlat/open_access_modes.h"
204 #include "xlat/open_mode_flags.h"
207 # define AT_FDCWD -100
210 /* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
211 * extension to get the right value. We do this by declaring fd as int here.
214 print_dirfd(struct tcb *tcp, int fd)
217 tprints("AT_FDCWD, ");
225 * low bits of the open(2) flags define access mode,
226 * other bits are real flags.
229 sprint_open_modes(int flags)
231 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
235 const struct xlat *x;
238 p = stpcpy(outstr, "flags");
239 str = xlookup(open_access_modes, flags & 3);
249 for (x = open_mode_flags; x->str; x++) {
250 if ((flags & x->val) == x->val) {
252 p = stpcpy(p, x->str);
259 /* flags is still nonzero */
261 sprintf(p, "%#x", flags);
266 tprint_open_modes(int flags)
268 tprints(sprint_open_modes(flags) + sizeof("flags"));
272 decode_open(struct tcb *tcp, int offset)
275 printpath(tcp, tcp->u_arg[offset]);
278 tprint_open_modes(tcp->u_arg[offset + 1]);
279 if (tcp->u_arg[offset + 1] & O_CREAT) {
281 tprintf(", %#lo", tcp->u_arg[offset + 2]);
288 sys_open(struct tcb *tcp)
290 return decode_open(tcp, 0);
294 sys_openat(struct tcb *tcp)
297 print_dirfd(tcp, tcp->u_arg[0]);
298 return decode_open(tcp, 1);
301 #if defined(SPARC) || defined(SPARC64)
302 #include "xlat/openmodessol.h"
305 solaris_open(struct tcb *tcp)
308 printpath(tcp, tcp->u_arg[0]);
311 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
312 if (tcp->u_arg[1] & 0x100) {
314 tprintf(", %#lo", tcp->u_arg[2]);
323 sys_creat(struct tcb *tcp)
326 printpath(tcp, tcp->u_arg[0]);
327 tprintf(", %#lo", tcp->u_arg[1]);
332 #include "xlat/access_flags.h"
335 decode_access(struct tcb *tcp, int offset)
338 printpath(tcp, tcp->u_arg[offset]);
340 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
346 sys_access(struct tcb *tcp)
348 return decode_access(tcp, 0);
352 sys_faccessat(struct tcb *tcp)
355 print_dirfd(tcp, tcp->u_arg[0]);
356 return decode_access(tcp, 1);
360 sys_umask(struct tcb *tcp)
363 tprintf("%#lo", tcp->u_arg[0]);
368 #include "xlat/whence_codes.h"
370 /* Linux kernel has exactly one version of lseek:
371 * fs/read_write.c::SYSCALL_DEFINE3(lseek, unsigned, fd, off_t, offset, unsigned, origin)
372 * In kernel, off_t is always the same as (kernel's) long
373 * (see include/uapi/asm-generic/posix_types.h),
374 * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
375 * Use test/x32_lseek.c to test lseek decoding.
377 #if defined(LINUX_MIPSN32) || defined(X32)
379 sys_lseek(struct tcb *tcp)
385 printfd(tcp, tcp->u_arg[0]);
386 offset = tcp->ext_arg[1];
387 whence = tcp->u_arg[2];
388 if (whence == SEEK_SET)
389 tprintf(", %llu, ", offset);
391 tprintf(", %lld, ", offset);
392 printxval(whence_codes, whence, "SEEK_???");
394 return RVAL_LUDECIMAL;
398 sys_lseek(struct tcb *tcp)
404 printfd(tcp, tcp->u_arg[0]);
405 offset = tcp->u_arg[1];
406 whence = tcp->u_arg[2];
407 if (whence == SEEK_SET)
408 tprintf(", %lu, ", offset);
410 tprintf(", %ld, ", offset);
411 printxval(whence_codes, whence, "SEEK_???");
413 return RVAL_UDECIMAL;
417 /* llseek syscall takes explicitly two ulong arguments hi, lo,
418 * rather than one 64-bit argument for which LONG_LONG works
419 * appropriate for the native byte order.
421 * See kernel's fs/read_write.c::SYSCALL_DEFINE5(llseek, ...)
423 * hi,lo are "unsigned longs" and combined exactly this way in kernel:
424 * ((loff_t) hi << 32) | lo
425 * Note that for architectures with kernel's long wider than userspace long
426 * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
427 * for hi and lo. We would need to use tcp->ext_arg[N] on x32...
428 * ...however, x32 (and x86_64) does not _have_ llseek syscall as such.
431 sys_llseek(struct tcb *tcp)
434 printfd(tcp, tcp->u_arg[0]);
435 if (tcp->u_arg[4] == SEEK_SET)
437 ((long long) tcp->u_arg[1]) << 32 |
438 (unsigned long long) (unsigned) tcp->u_arg[2]);
441 ((long long) tcp->u_arg[1]) << 32 |
442 (unsigned long long) (unsigned) tcp->u_arg[2]);
446 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
447 tprintf("%#lx, ", tcp->u_arg[3]);
449 tprintf("[%llu], ", off);
450 printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
456 sys_readahead(struct tcb *tcp)
460 printfd(tcp, tcp->u_arg[0]);
461 argn = printllval(tcp, ", %lld", 1);
462 tprintf(", %ld", tcp->u_arg[argn]);
468 sys_truncate(struct tcb *tcp)
471 printpath(tcp, tcp->u_arg[0]);
472 tprintf(", %lu", tcp->u_arg[1]);
478 sys_truncate64(struct tcb *tcp)
481 printpath(tcp, tcp->u_arg[0]);
482 printllval(tcp, ", %llu", 1);
488 sys_ftruncate(struct tcb *tcp)
491 printfd(tcp, tcp->u_arg[0]);
492 tprintf(", %lu", tcp->u_arg[1]);
498 sys_ftruncate64(struct tcb *tcp)
501 printfd(tcp, tcp->u_arg[0]);
502 printllval(tcp, ", %llu", 1);
513 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
521 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
522 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
523 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
525 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
530 #if defined(SPARC) || defined(SPARC64)
538 int st_pad1[3]; /* network id */
547 int st_pad3; /* st_size, off_t expansion */
548 timestruct_t st_atime;
549 timestruct_t st_mtime;
550 timestruct_t st_ctime;
554 int st_pad4[8]; /* expansion area */
558 printstatsol(struct tcb *tcp, long addr)
560 struct solstat statbuf;
562 if (umove(tcp, addr, &statbuf) < 0) {
567 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
568 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
569 (unsigned long) (statbuf.st_dev & 0x3ffff),
570 (unsigned long) statbuf.st_ino,
571 sprintmode(statbuf.st_mode));
572 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
573 (unsigned long) statbuf.st_nlink,
574 (unsigned long) statbuf.st_uid,
575 (unsigned long) statbuf.st_gid);
576 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
577 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
580 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
581 switch (statbuf.st_mode & S_IFMT) {
582 case S_IFCHR: case S_IFBLK:
583 tprintf("st_rdev=makedev(%lu, %lu), ",
584 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
585 (unsigned long) (statbuf.st_rdev & 0x3ffff));
588 tprintf("st_size=%u, ", statbuf.st_size);
592 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
593 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
594 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
600 # if defined(SPARC64)
602 printstat_sparc64(struct tcb *tcp, long addr)
604 struct stat_sparc64 statbuf;
606 if (umove(tcp, addr, &statbuf) < 0) {
612 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
613 (unsigned long) major(statbuf.st_dev),
614 (unsigned long) minor(statbuf.st_dev),
615 (unsigned long) statbuf.st_ino,
616 sprintmode(statbuf.st_mode));
617 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
618 (unsigned long) statbuf.st_nlink,
619 (unsigned long) statbuf.st_uid,
620 (unsigned long) statbuf.st_gid);
621 tprintf("st_blksize=%lu, ",
622 (unsigned long) statbuf.st_blksize);
623 tprintf("st_blocks=%lu, ",
624 (unsigned long) statbuf.st_blocks);
627 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
628 switch (statbuf.st_mode & S_IFMT) {
629 case S_IFCHR: case S_IFBLK:
630 tprintf("st_rdev=makedev(%lu, %lu), ",
631 (unsigned long) major(statbuf.st_rdev),
632 (unsigned long) minor(statbuf.st_rdev));
635 tprintf("st_size=%lu, ", statbuf.st_size);
639 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
640 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
641 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
646 # endif /* SPARC64 */
647 #endif /* SPARC[64] */
649 #if defined POWERPC64
650 struct stat_powerpc32 {
653 unsigned int st_mode;
654 unsigned short st_nlink;
657 unsigned int st_rdev;
658 unsigned int st_size;
659 unsigned int st_blksize;
660 unsigned int st_blocks;
661 unsigned int st_atime;
662 unsigned int st_atime_nsec;
663 unsigned int st_mtime;
664 unsigned int st_mtime_nsec;
665 unsigned int st_ctime;
666 unsigned int st_ctime_nsec;
667 unsigned int __unused4;
668 unsigned int __unused5;
672 printstat_powerpc32(struct tcb *tcp, long addr)
674 struct stat_powerpc32 statbuf;
676 if (umove(tcp, addr, &statbuf) < 0) {
682 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
683 major(statbuf.st_dev), minor(statbuf.st_dev),
685 sprintmode(statbuf.st_mode));
686 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
687 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
688 tprintf("st_blksize=%u, ", statbuf.st_blksize);
689 tprintf("st_blocks=%u, ", statbuf.st_blocks);
692 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
693 switch (statbuf.st_mode & S_IFMT) {
694 case S_IFCHR: case S_IFBLK:
695 tprintf("st_rdev=makedev(%lu, %lu), ",
696 (unsigned long) major(statbuf.st_rdev),
697 (unsigned long) minor(statbuf.st_rdev));
700 tprintf("st_size=%u, ", statbuf.st_size);
704 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
705 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
706 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
711 #endif /* POWERPC64 */
713 #include "xlat/fileflags.h"
716 realprintstat(struct tcb *tcp, struct stat *statbuf)
719 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
720 (unsigned long) major(statbuf->st_dev),
721 (unsigned long) minor(statbuf->st_dev),
722 (unsigned long) statbuf->st_ino,
723 sprintmode(statbuf->st_mode));
724 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
725 (unsigned long) statbuf->st_nlink,
726 (unsigned long) statbuf->st_uid,
727 (unsigned long) statbuf->st_gid);
728 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
729 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
731 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
732 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
736 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
737 switch (statbuf->st_mode & S_IFMT) {
738 case S_IFCHR: case S_IFBLK:
739 #ifdef HAVE_STRUCT_STAT_ST_RDEV
740 tprintf("st_rdev=makedev(%lu, %lu), ",
741 (unsigned long) major(statbuf->st_rdev),
742 (unsigned long) minor(statbuf->st_rdev));
743 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
744 tprintf("st_size=makedev(%lu, %lu), ",
745 (unsigned long) major(statbuf->st_size),
746 (unsigned long) minor(statbuf->st_size));
747 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
750 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
754 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
755 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
756 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
757 #if HAVE_STRUCT_STAT_ST_FLAGS
758 tprints(", st_flags=");
759 printflags(fileflags, statbuf->st_flags, "UF_???");
761 #if HAVE_STRUCT_STAT_ST_ACLCNT
762 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
764 #if HAVE_STRUCT_STAT_ST_LEVEL
765 tprintf(", st_level=%ld", statbuf->st_level);
767 #if HAVE_STRUCT_STAT_ST_FSTYPE
768 tprintf(", st_fstype=%.*s",
769 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
771 #if HAVE_STRUCT_STAT_ST_GEN
772 tprintf(", st_gen=%u", statbuf->st_gen);
782 printstat(struct tcb *tcp, long addr)
790 if (syserror(tcp) || !verbose(tcp)) {
791 tprintf("%#lx", addr);
795 #if defined(SPARC) || defined(SPARC64)
796 if (current_personality == 1) {
797 printstatsol(tcp, addr);
801 else if (current_personality == 2) {
802 printstat_sparc64(tcp, addr);
806 #endif /* SPARC[64] */
808 #if defined POWERPC64
809 if (current_personality == 1) {
810 printstat_powerpc32(tcp, addr);
815 if (umove(tcp, addr, &statbuf) < 0) {
820 realprintstat(tcp, &statbuf);
823 # define printstat printstat64
826 #if !defined HAVE_STAT64 && (defined AARCH64 || defined X86_64)
828 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
829 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
830 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
831 * __GNUC__ is needed for the required __attribute__ below.
833 * Similarly, aarch64 has a unified `struct stat' but its arm personality
834 * needs `struct stat64' (which also expects a 32-bit `long' but which
835 * shouldn't be packed).
838 unsigned long long st_dev;
839 unsigned char __pad0[4];
840 unsigned int __st_ino;
841 unsigned int st_mode;
842 unsigned int st_nlink;
845 unsigned long long st_rdev;
846 unsigned char __pad3[4];
848 unsigned int st_blksize;
849 unsigned long long st_blocks;
850 unsigned int st_atime;
851 unsigned int st_atime_nsec;
852 unsigned int st_mtime;
853 unsigned int st_mtime_nsec;
854 unsigned int st_ctime;
855 unsigned int st_ctime_nsec;
856 unsigned long long st_ino;
859 __attribute__((packed))
860 # define STAT64_SIZE 96
862 # define STAT64_SIZE 104
865 # define HAVE_STAT64 1
870 printstat64(struct tcb *tcp, long addr)
875 struct stat64 statbuf;
879 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
886 if (syserror(tcp) || !verbose(tcp)) {
887 tprintf("%#lx", addr);
891 #if defined(SPARC) || defined(SPARC64)
892 if (current_personality == 1) {
893 printstatsol(tcp, addr);
897 else if (current_personality == 2) {
898 printstat_sparc64(tcp, addr);
902 #endif /* SPARC[64] */
905 if (current_personality != 0) {
906 printstat(tcp, addr);
911 if (current_personality != 1) {
912 printstat(tcp, addr);
917 if (umove(tcp, addr, &statbuf) < 0) {
923 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
924 (unsigned long) major(statbuf.st_dev),
925 (unsigned long) minor(statbuf.st_dev),
926 (unsigned long long) statbuf.st_ino,
927 sprintmode(statbuf.st_mode));
928 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
929 (unsigned long) statbuf.st_nlink,
930 (unsigned long) statbuf.st_uid,
931 (unsigned long) statbuf.st_gid);
932 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
933 tprintf("st_blksize=%lu, ",
934 (unsigned long) statbuf.st_blksize);
935 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
936 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
937 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
938 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
941 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
942 switch (statbuf.st_mode & S_IFMT) {
943 case S_IFCHR: case S_IFBLK:
944 #ifdef HAVE_STRUCT_STAT_ST_RDEV
945 tprintf("st_rdev=makedev(%lu, %lu), ",
946 (unsigned long) major(statbuf.st_rdev),
947 (unsigned long) minor(statbuf.st_rdev));
948 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
949 tprintf("st_size=makedev(%lu, %lu), ",
950 (unsigned long) major(statbuf.st_size),
951 (unsigned long) minor(statbuf.st_size));
952 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
955 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
959 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
960 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
961 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
962 #if HAVE_STRUCT_STAT_ST_FLAGS
963 tprints(", st_flags=");
964 printflags(fileflags, statbuf.st_flags, "UF_???");
966 #if HAVE_STRUCT_STAT_ST_ACLCNT
967 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
969 #if HAVE_STRUCT_STAT_ST_LEVEL
970 tprintf(", st_level=%ld", statbuf.st_level);
972 #if HAVE_STRUCT_STAT_ST_FSTYPE
973 tprintf(", st_fstype=%.*s",
974 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
976 #if HAVE_STRUCT_STAT_ST_GEN
977 tprintf(", st_gen=%u", statbuf.st_gen);
984 #endif /* HAVE_STAT64 */
986 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
988 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
990 newbuf->st_dev = oldbuf->st_dev;
991 newbuf->st_ino = oldbuf->st_ino;
992 newbuf->st_mode = oldbuf->st_mode;
993 newbuf->st_nlink = oldbuf->st_nlink;
994 newbuf->st_uid = oldbuf->st_uid;
995 newbuf->st_gid = oldbuf->st_gid;
996 newbuf->st_rdev = oldbuf->st_rdev;
997 newbuf->st_size = oldbuf->st_size;
998 newbuf->st_atime = oldbuf->st_atime;
999 newbuf->st_mtime = oldbuf->st_mtime;
1000 newbuf->st_ctime = oldbuf->st_ctime;
1001 newbuf->st_blksize = 0; /* not supported in old_stat */
1002 newbuf->st_blocks = 0; /* not supported in old_stat */
1006 printoldstat(struct tcb *tcp, long addr)
1008 struct __old_kernel_stat statbuf;
1009 struct stat newstatbuf;
1015 if (syserror(tcp) || !verbose(tcp)) {
1016 tprintf("%#lx", addr);
1020 # if defined(SPARC) || defined(SPARC64)
1021 if (current_personality == 1) {
1022 printstatsol(tcp, addr);
1027 if (umove(tcp, addr, &statbuf) < 0) {
1032 convertoldstat(&statbuf, &newstatbuf);
1033 realprintstat(tcp, &newstatbuf);
1038 sys_stat(struct tcb *tcp)
1040 if (entering(tcp)) {
1041 printpath(tcp, tcp->u_arg[0]);
1044 printstat(tcp, tcp->u_arg[1]);
1051 printstat64_x32(struct tcb *tcp, long addr)
1053 struct stat64 statbuf;
1059 if (syserror(tcp) || !verbose(tcp)) {
1060 tprintf("%#lx", addr);
1064 if (umove(tcp, addr, &statbuf) < 0) {
1070 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1071 (unsigned long) major(statbuf.st_dev),
1072 (unsigned long) minor(statbuf.st_dev),
1073 (unsigned long long) statbuf.st_ino,
1074 sprintmode(statbuf.st_mode));
1075 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1076 (unsigned long) statbuf.st_nlink,
1077 (unsigned long) statbuf.st_uid,
1078 (unsigned long) statbuf.st_gid);
1079 tprintf("st_blksize=%lu, ",
1080 (unsigned long) statbuf.st_blksize);
1081 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1084 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1085 switch (statbuf.st_mode & S_IFMT) {
1086 case S_IFCHR: case S_IFBLK:
1087 tprintf("st_rdev=makedev(%lu, %lu), ",
1088 (unsigned long) major(statbuf.st_rdev),
1089 (unsigned long) minor(statbuf.st_rdev));
1092 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1096 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1097 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1098 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1107 sys_stat64(struct tcb *tcp)
1110 if (entering(tcp)) {
1111 printpath(tcp, tcp->u_arg[0]);
1115 printstat64_x32(tcp, tcp->u_arg[1]);
1117 printstat64(tcp, tcp->u_arg[1]);
1122 return printargs(tcp);
1126 #ifndef AT_SYMLINK_NOFOLLOW
1127 # define AT_SYMLINK_NOFOLLOW 0x100
1129 #ifndef AT_REMOVEDIR
1130 # define AT_REMOVEDIR 0x200
1132 #ifndef AT_SYMLINK_FOLLOW
1133 # define AT_SYMLINK_FOLLOW 0x400
1135 #ifndef AT_NO_AUTOMOUNT
1136 # define AT_NO_AUTOMOUNT 0x800
1138 #ifndef AT_EMPTY_PATH
1139 # define AT_EMPTY_PATH 0x1000
1142 #include "xlat/at_flags.h"
1145 sys_newfstatat(struct tcb *tcp)
1147 if (entering(tcp)) {
1148 print_dirfd(tcp, tcp->u_arg[0]);
1149 printpath(tcp, tcp->u_arg[1]);
1153 if (current_personality == 0)
1154 printstat(tcp, tcp->u_arg[2]);
1156 printstat64(tcp, tcp->u_arg[2]);
1157 #elif defined HAVE_STAT64
1158 printstat64(tcp, tcp->u_arg[2]);
1160 printstat(tcp, tcp->u_arg[2]);
1163 printflags(at_flags, tcp->u_arg[3], "AT_???");
1168 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1170 sys_oldstat(struct tcb *tcp)
1172 if (entering(tcp)) {
1173 printpath(tcp, tcp->u_arg[0]);
1176 printoldstat(tcp, tcp->u_arg[1]);
1183 sys_fstat(struct tcb *tcp)
1185 if (entering(tcp)) {
1186 printfd(tcp, tcp->u_arg[0]);
1189 printstat(tcp, tcp->u_arg[1]);
1195 sys_fstat64(struct tcb *tcp)
1198 if (entering(tcp)) {
1199 printfd(tcp, tcp->u_arg[0]);
1203 printstat64_x32(tcp, tcp->u_arg[1]);
1205 printstat64(tcp, tcp->u_arg[1]);
1210 return printargs(tcp);
1214 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1216 sys_oldfstat(struct tcb *tcp)
1218 if (entering(tcp)) {
1219 printfd(tcp, tcp->u_arg[0]);
1222 printoldstat(tcp, tcp->u_arg[1]);
1228 #if defined(SPARC) || defined(SPARC64)
1231 sys_xstat(struct tcb *tcp)
1233 if (entering(tcp)) {
1234 tprintf("%ld, ", tcp->u_arg[0]);
1235 printpath(tcp, tcp->u_arg[1]);
1239 if (tcp->u_arg[0] == _STAT64_VER)
1240 printstat64(tcp, tcp->u_arg[2]);
1243 printstat(tcp, tcp->u_arg[2]);
1249 sys_fxstat(struct tcb *tcp)
1252 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1255 if (tcp->u_arg[0] == _STAT64_VER)
1256 printstat64(tcp, tcp->u_arg[2]);
1259 printstat(tcp, tcp->u_arg[2]);
1265 sys_lxstat(struct tcb *tcp)
1267 if (entering(tcp)) {
1268 tprintf("%ld, ", tcp->u_arg[0]);
1269 printpath(tcp, tcp->u_arg[1]);
1273 if (tcp->u_arg[0] == _STAT64_VER)
1274 printstat64(tcp, tcp->u_arg[2]);
1277 printstat(tcp, tcp->u_arg[2]);
1283 sys_xmknod(struct tcb *tcp)
1285 int mode = tcp->u_arg[2];
1287 if (entering(tcp)) {
1288 tprintf("%ld, ", tcp->u_arg[0]);
1289 printpath(tcp, tcp->u_arg[1]);
1290 tprintf(", %s", sprintmode(mode));
1291 switch (mode & S_IFMT) {
1292 case S_IFCHR: case S_IFBLK:
1293 tprintf(", makedev(%lu, %lu)",
1294 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1295 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1304 #endif /* SPARC[64] */
1308 sys_chdir(struct tcb *tcp)
1310 if (entering(tcp)) {
1311 printpath(tcp, tcp->u_arg[0]);
1317 sys_link(struct tcb *tcp)
1319 if (entering(tcp)) {
1320 printpath(tcp, tcp->u_arg[0]);
1322 printpath(tcp, tcp->u_arg[1]);
1328 sys_linkat(struct tcb *tcp)
1330 if (entering(tcp)) {
1331 print_dirfd(tcp, tcp->u_arg[0]);
1332 printpath(tcp, tcp->u_arg[1]);
1334 print_dirfd(tcp, tcp->u_arg[2]);
1335 printpath(tcp, tcp->u_arg[3]);
1337 printflags(at_flags, tcp->u_arg[4], "AT_???");
1343 sys_unlinkat(struct tcb *tcp)
1345 if (entering(tcp)) {
1346 print_dirfd(tcp, tcp->u_arg[0]);
1347 printpath(tcp, tcp->u_arg[1]);
1349 printflags(at_flags, tcp->u_arg[2], "AT_???");
1355 sys_symlinkat(struct tcb *tcp)
1357 if (entering(tcp)) {
1358 printpath(tcp, tcp->u_arg[0]);
1360 print_dirfd(tcp, tcp->u_arg[1]);
1361 printpath(tcp, tcp->u_arg[2]);
1367 decode_readlink(struct tcb *tcp, int offset)
1369 if (entering(tcp)) {
1370 printpath(tcp, tcp->u_arg[offset]);
1374 tprintf("%#lx", tcp->u_arg[offset + 1]);
1376 /* Used to use printpathn(), but readlink
1377 * neither includes NUL in the returned count,
1378 * nor actually writes it into memory.
1379 * printpathn() would decide on printing
1380 * "..." continuation based on garbage
1381 * past return buffer's end.
1383 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1384 tprintf(", %lu", tcp->u_arg[offset + 2]);
1390 sys_readlink(struct tcb *tcp)
1392 return decode_readlink(tcp, 0);
1396 sys_readlinkat(struct tcb *tcp)
1399 print_dirfd(tcp, tcp->u_arg[0]);
1400 return decode_readlink(tcp, 1);
1404 decode_renameat(struct tcb *tcp)
1406 print_dirfd(tcp, tcp->u_arg[0]);
1407 printpath(tcp, tcp->u_arg[1]);
1409 print_dirfd(tcp, tcp->u_arg[2]);
1410 printpath(tcp, tcp->u_arg[3]);
1414 sys_renameat(struct tcb *tcp)
1416 if (entering(tcp)) {
1417 decode_renameat(tcp);
1422 #include "xlat/rename_flags.h"
1425 sys_renameat2(struct tcb *tcp)
1427 if (entering(tcp)) {
1428 decode_renameat(tcp);
1430 printflags(rename_flags, tcp->u_arg[4], "RENAME_??");
1436 sys_chown(struct tcb *tcp)
1438 if (entering(tcp)) {
1439 printpath(tcp, tcp->u_arg[0]);
1440 printuid(", ", tcp->u_arg[1]);
1441 printuid(", ", tcp->u_arg[2]);
1447 sys_fchownat(struct tcb *tcp)
1449 if (entering(tcp)) {
1450 print_dirfd(tcp, tcp->u_arg[0]);
1451 printpath(tcp, tcp->u_arg[1]);
1452 printuid(", ", tcp->u_arg[2]);
1453 printuid(", ", tcp->u_arg[3]);
1455 printflags(at_flags, tcp->u_arg[4], "AT_???");
1461 sys_fchown(struct tcb *tcp)
1463 if (entering(tcp)) {
1464 printfd(tcp, tcp->u_arg[0]);
1465 printuid(", ", tcp->u_arg[1]);
1466 printuid(", ", tcp->u_arg[2]);
1472 decode_chmod(struct tcb *tcp, int offset)
1474 if (entering(tcp)) {
1475 printpath(tcp, tcp->u_arg[offset]);
1476 tprintf(", %#lo", tcp->u_arg[offset + 1]);
1482 sys_chmod(struct tcb *tcp)
1484 return decode_chmod(tcp, 0);
1488 sys_fchmodat(struct tcb *tcp)
1491 print_dirfd(tcp, tcp->u_arg[0]);
1492 return decode_chmod(tcp, 1);
1496 sys_fchmod(struct tcb *tcp)
1498 if (entering(tcp)) {
1499 printfd(tcp, tcp->u_arg[0]);
1500 tprintf(", %#lo", tcp->u_arg[1]);
1507 sys_osf_utimes(struct tcb *tcp)
1509 if (entering(tcp)) {
1510 printpath(tcp, tcp->u_arg[0]);
1512 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
1519 decode_utimes(struct tcb *tcp, int offset, int special)
1521 if (entering(tcp)) {
1522 printpath(tcp, tcp->u_arg[offset]);
1524 if (tcp->u_arg[offset + 1] == 0)
1528 printtv_bitness(tcp, tcp->u_arg[offset + 1],
1529 BITNESS_CURRENT, special);
1531 printtv_bitness(tcp, tcp->u_arg[offset + 1]
1532 + sizeof(struct timeval),
1533 BITNESS_CURRENT, special);
1541 sys_utimes(struct tcb *tcp)
1543 return decode_utimes(tcp, 0, 0);
1547 sys_futimesat(struct tcb *tcp)
1550 print_dirfd(tcp, tcp->u_arg[0]);
1551 return decode_utimes(tcp, 1, 0);
1555 sys_utimensat(struct tcb *tcp)
1557 if (entering(tcp)) {
1558 print_dirfd(tcp, tcp->u_arg[0]);
1559 decode_utimes(tcp, 1, 1);
1561 printflags(at_flags, tcp->u_arg[3], "AT_???");
1567 sys_utime(struct tcb *tcp)
1572 long paranoia_for_huge_wordsize[4];
1576 if (entering(tcp)) {
1577 printpath(tcp, tcp->u_arg[0]);
1580 wordsize = current_wordsize;
1583 else if (!verbose(tcp))
1584 tprintf("%#lx", tcp->u_arg[1]);
1585 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
1587 else if (wordsize == sizeof u.utl[0]) {
1588 tprintf("[%s,", sprinttime(u.utl[0]));
1589 tprintf(" %s]", sprinttime(u.utl[1]));
1591 else if (wordsize == sizeof u.uti[0]) {
1592 tprintf("[%s,", sprinttime(u.uti[0]));
1593 tprintf(" %s]", sprinttime(u.uti[1]));
1596 tprintf("<decode error: unsupported wordsize %d>",
1603 decode_mknod(struct tcb *tcp, int offset)
1605 int mode = tcp->u_arg[offset + 1];
1607 if (entering(tcp)) {
1608 printpath(tcp, tcp->u_arg[offset]);
1609 tprintf(", %s", sprintmode(mode));
1610 switch (mode & S_IFMT) {
1613 #if defined(SPARC) || defined(SPARC64)
1614 if (current_personality == 1)
1615 tprintf(", makedev(%lu, %lu)",
1616 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
1617 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
1620 tprintf(", makedev(%lu, %lu)",
1621 (unsigned long) major(tcp->u_arg[offset + 2]),
1622 (unsigned long) minor(tcp->u_arg[offset + 2]));
1632 sys_mknod(struct tcb *tcp)
1634 return decode_mknod(tcp, 0);
1638 sys_mknodat(struct tcb *tcp)
1641 print_dirfd(tcp, tcp->u_arg[0]);
1642 return decode_mknod(tcp, 1);