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.
38 struct kernel_dirent {
41 unsigned short d_reclen;
47 unsigned short st_dev;
49 unsigned short st_mode;
51 unsigned short st_uid;
52 unsigned short st_gid;
53 unsigned short st_rdev;
56 unsigned int __unused1;
58 unsigned int __unused2;
60 unsigned int __unused3;
63 unsigned int __unused4[2];
70 unsigned int st_nlink;
80 unsigned long __unused4[2];
83 # define stat kernel_stat
84 # include <asm/stat.h>
96 # define dev_t __kernel_dev_t
97 # define ino_t __kernel_ino_t
98 # define mode_t __kernel_mode_t
99 # define nlink_t __kernel_nlink_t
100 # define uid_t __kernel_uid_t
101 # define gid_t __kernel_gid_t
102 # define off_t __kernel_off_t
103 # define loff_t __kernel_loff_t
105 # include <asm/stat.h>
118 # define mode_t mode_t
119 # define nlink_t nlink_t
123 # define loff_t loff_t
126 #ifdef HPPA /* asm-parisc/stat.h defines stat64 */
129 #define stat libc_stat
130 #define stat64 libc_stat64
131 #include <sys/stat.h>
134 /* These might be macros. */
139 # define stat64 hpux_stat64
144 #ifdef HAVE_SYS_VFS_H
145 # include <sys/vfs.h>
148 #ifdef HAVE_LINUX_XATTR_H
149 # include <linux/xattr.h>
151 # define XATTR_CREATE 1
152 # define XATTR_REPLACE 2
156 # ifdef HAVE_INTTYPES_H
157 # include <inttypes.h>
159 # define PRId64 "lld"
160 # define PRIu64 "llu"
164 #if HAVE_LONG_LONG_OFF_T
166 * Ugly hacks for systems that have typedef long long off_t
170 # define HAVE_STAT64 1 /* Ugly hack */
172 # define sys_stat64 sys_stat
173 # define sys_fstat64 sys_fstat
174 # define sys_lstat64 sys_lstat
175 # define sys_lseek64 sys_lseek
176 # define sys_truncate64 sys_truncate
177 # define sys_ftruncate64 sys_ftruncate
180 #ifdef MAJOR_IN_SYSMACROS
181 # include <sys/sysmacros.h>
184 #ifdef MAJOR_IN_MKDEV
185 # include <sys/mkdev.h>
188 #ifdef HAVE_SYS_ASYNCH_H
189 # include <sys/asynch.h>
192 const struct xlat open_access_modes[] = {
193 { O_RDONLY, "O_RDONLY" },
194 { O_WRONLY, "O_WRONLY" },
195 { O_RDWR, "O_RDWR" },
197 { O_ACCMODE, "O_ACCMODE" },
202 const struct xlat open_mode_flags[] = {
203 { O_CREAT, "O_CREAT" },
204 { O_EXCL, "O_EXCL" },
205 { O_NOCTTY, "O_NOCTTY" },
206 { O_TRUNC, "O_TRUNC" },
207 { O_APPEND, "O_APPEND" },
208 { O_NONBLOCK, "O_NONBLOCK" },
210 { O_SYNC, "O_SYNC" },
213 { O_ASYNC, "O_ASYNC" },
216 { O_DSYNC, "O_DSYNC" },
219 { O_RSYNC, "O_RSYNC" },
221 #if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
222 { O_NDELAY, "O_NDELAY" },
225 { O_PRIV, "O_PRIV" },
228 { O_DIRECT, "O_DIRECT" },
231 # if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
234 # define O_LARGEFILE 0x40000
235 # elif defined X86_64 || defined S390X
236 # define O_LARGEFILE 0100000
240 { O_LARGEFILE, "O_LARGEFILE" },
244 { O_DIRECTORY, "O_DIRECTORY" },
247 { O_NOFOLLOW, "O_NOFOLLOW" },
250 { O_NOATIME, "O_NOATIME" },
253 { O_CLOEXEC, "O_CLOEXEC" },
256 { FNDELAY, "FNDELAY" },
259 { FAPPEND, "FAPPEND" },
265 { FDEFER, "FDEFER" },
268 { FASYNC, "FASYNC" },
271 { FSHLOCK, "FSHLOCK" },
274 { FEXLOCK, "FEXLOCK" },
277 { FCREAT, "FCREAT" },
280 { FTRUNC, "FTRUNC" },
292 { FNOCTTY, "FNOCTTY" },
295 { O_SHLOCK, "O_SHLOCK" },
298 { O_EXLOCK, "O_EXLOCK" },
304 # define AT_FDCWD -100
307 /* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
308 * extension to get the right value. We do this by declaring fd as int here.
311 print_dirfd(struct tcb *tcp, int fd)
314 tprints("AT_FDCWD, ");
322 * low bits of the open(2) flags define access mode,
323 * other bits are real flags.
326 sprint_open_modes(mode_t flags)
328 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
332 const struct xlat *x;
335 p = stpcpy(outstr, "flags");
336 str = xlookup(open_access_modes, flags & 3);
346 for (x = open_mode_flags; x->str; x++) {
347 if ((flags & x->val) == x->val) {
349 p = stpcpy(p, x->str);
356 /* flags is still nonzero */
358 sprintf(p, "%#x", flags);
363 tprint_open_modes(mode_t flags)
365 tprints(sprint_open_modes(flags) + sizeof("flags"));
369 decode_open(struct tcb *tcp, int offset)
372 printpath(tcp, tcp->u_arg[offset]);
375 tprint_open_modes(tcp->u_arg[offset + 1]);
376 if (tcp->u_arg[offset + 1] & O_CREAT) {
378 tprintf(", %#lo", tcp->u_arg[offset + 2]);
385 sys_open(struct tcb *tcp)
387 return decode_open(tcp, 0);
391 sys_openat(struct tcb *tcp)
394 print_dirfd(tcp, tcp->u_arg[0]);
395 return decode_open(tcp, 1);
399 static const struct xlat openmodessol[] = {
403 { 0x80, "O_NONBLOCK" },
405 { 0x100, "O_CREAT" },
406 { 0x200, "O_TRUNC" },
408 { 0x800, "O_NOCTTY" },
411 { 0x8000, "O_RSYNC" },
413 { 0x1000, "O_PRIV" },
418 solaris_open(struct tcb *tcp)
421 printpath(tcp, tcp->u_arg[0]);
424 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
425 if (tcp->u_arg[1] & 0x100) {
427 tprintf(", %#lo", tcp->u_arg[2]);
436 sys_creat(struct tcb *tcp)
439 printpath(tcp, tcp->u_arg[0]);
440 tprintf(", %#lo", tcp->u_arg[1]);
445 static const struct xlat access_flags[] = {
451 { EFF_ONLY_OK, "EFF_ONLY_OK" },
460 decode_access(struct tcb *tcp, int offset)
463 printpath(tcp, tcp->u_arg[offset]);
465 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
471 sys_access(struct tcb *tcp)
473 return decode_access(tcp, 0);
477 sys_faccessat(struct tcb *tcp)
480 print_dirfd(tcp, tcp->u_arg[0]);
481 return decode_access(tcp, 1);
485 sys_umask(struct tcb *tcp)
488 tprintf("%#lo", tcp->u_arg[0]);
493 static const struct xlat whence[] = {
494 { SEEK_SET, "SEEK_SET" },
495 { SEEK_CUR, "SEEK_CUR" },
496 { SEEK_END, "SEEK_END" },
500 #ifndef HAVE_LONG_LONG_OFF_T
501 #if defined(LINUX_MIPSN32)
503 sys_lseek(struct tcb *tcp)
509 printfd(tcp, tcp->u_arg[0]);
511 offset = tcp->ext_arg[1];
512 _whence = tcp->u_arg[2];
513 if (_whence == SEEK_SET)
514 tprintf("%llu, ", offset);
516 tprintf("%lld, ", offset);
517 printxval(whence, _whence, "SEEK_???");
519 return RVAL_UDECIMAL;
521 #else /* !LINUX_MIPSN32 */
523 sys_lseek(struct tcb *tcp)
529 printfd(tcp, tcp->u_arg[0]);
531 offset = tcp->u_arg[1];
532 _whence = tcp->u_arg[2];
533 if (_whence == SEEK_SET)
534 tprintf("%lu, ", offset);
536 tprintf("%ld, ", offset);
537 printxval(whence, _whence, "SEEK_???");
539 return RVAL_UDECIMAL;
541 #endif /* LINUX_MIPSN32 */
545 sys_llseek(struct tcb *tcp)
548 printfd(tcp, tcp->u_arg[0]);
550 * This one call takes explicitly two 32-bit arguments hi, lo,
551 * rather than one 64-bit argument for which LONG_LONG works
552 * appropriate for the native byte order.
554 if (tcp->u_arg[4] == SEEK_SET)
556 ((long long int) tcp->u_arg[1]) << 32 |
557 (unsigned long long) (unsigned) tcp->u_arg[2]);
560 ((long long int) tcp->u_arg[1]) << 32 |
561 (unsigned long long) (unsigned) tcp->u_arg[2]);
565 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
566 tprintf("%#lx, ", tcp->u_arg[3]);
568 tprintf("[%llu], ", off);
569 printxval(whence, tcp->u_arg[4], "SEEK_???");
575 sys_readahead(struct tcb *tcp)
579 printfd(tcp, tcp->u_arg[0]);
581 argn = printllval(tcp, "%lld", 1);
582 tprintf(", %ld", tcp->u_arg[argn]);
587 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
589 sys_lseek64(struct tcb *tcp)
593 printfd(tcp, tcp->u_arg[0]);
595 if (tcp->u_arg[3] == SEEK_SET)
596 argn = printllval(tcp, "%llu, ", 1);
598 argn = printllval(tcp, "%lld, ", 1);
599 printxval(whence, tcp->u_arg[argn], "SEEK_???");
601 return RVAL_LUDECIMAL;
605 #ifndef HAVE_LONG_LONG_OFF_T
607 sys_truncate(struct tcb *tcp)
610 printpath(tcp, tcp->u_arg[0]);
611 tprintf(", %lu", tcp->u_arg[1]);
617 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
619 sys_truncate64(struct tcb *tcp)
622 printpath(tcp, tcp->u_arg[0]);
623 printllval(tcp, ", %llu", 1);
629 #ifndef HAVE_LONG_LONG_OFF_T
631 sys_ftruncate(struct tcb *tcp)
634 printfd(tcp, tcp->u_arg[0]);
635 tprintf(", %lu", tcp->u_arg[1]);
641 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
643 sys_ftruncate64(struct tcb *tcp)
646 printfd(tcp, tcp->u_arg[0]);
648 printllval(tcp, "%llu", 1);
656 static const struct xlat modetypes[] = {
657 { S_IFREG, "S_IFREG" },
658 { S_IFSOCK, "S_IFSOCK" },
659 { S_IFIFO, "S_IFIFO" },
660 { S_IFLNK, "S_IFLNK" },
661 { S_IFDIR, "S_IFDIR" },
662 { S_IFBLK, "S_IFBLK" },
663 { S_IFCHR, "S_IFCHR" },
670 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
675 if ((mode & S_IFMT) == 0)
677 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
678 sprintf(buf, "%#o", mode);
681 s = buf + sprintf(buf, "%s%s%s%s", s,
682 (mode & S_ISUID) ? "|S_ISUID" : "",
683 (mode & S_ISGID) ? "|S_ISGID" : "",
684 (mode & S_ISVTX) ? "|S_ISVTX" : "");
685 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
687 sprintf((char*)s, "|%#o", mode);
688 s = (*buf == '|') ? buf + 1 : buf;
696 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
704 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
705 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
706 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
708 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
721 int st_pad1[3]; /* network id */
730 int st_pad3; /* st_size, off_t expansion */
731 timestruct_t st_atime;
732 timestruct_t st_mtime;
733 timestruct_t st_ctime;
737 int st_pad4[8]; /* expansion area */
741 printstatsol(struct tcb *tcp, long addr)
743 struct solstat statbuf;
745 if (umove(tcp, addr, &statbuf) < 0) {
750 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
751 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
752 (unsigned long) (statbuf.st_dev & 0x3ffff),
753 (unsigned long) statbuf.st_ino,
754 sprintmode(statbuf.st_mode));
755 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
756 (unsigned long) statbuf.st_nlink,
757 (unsigned long) statbuf.st_uid,
758 (unsigned long) statbuf.st_gid);
759 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
760 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
763 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
764 switch (statbuf.st_mode & S_IFMT) {
765 case S_IFCHR: case S_IFBLK:
766 tprintf("st_rdev=makedev(%lu, %lu), ",
767 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
768 (unsigned long) (statbuf.st_rdev & 0x3ffff));
771 tprintf("st_size=%u, ", statbuf.st_size);
775 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
776 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
777 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
785 printstat_sparc64(struct tcb *tcp, long addr)
787 struct stat_sparc64 statbuf;
789 if (umove(tcp, addr, &statbuf) < 0) {
795 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
796 (unsigned long) major(statbuf.st_dev),
797 (unsigned long) minor(statbuf.st_dev),
798 (unsigned long) statbuf.st_ino,
799 sprintmode(statbuf.st_mode));
800 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
801 (unsigned long) statbuf.st_nlink,
802 (unsigned long) statbuf.st_uid,
803 (unsigned long) statbuf.st_gid);
804 tprintf("st_blksize=%lu, ",
805 (unsigned long) statbuf.st_blksize);
806 tprintf("st_blocks=%lu, ",
807 (unsigned long) statbuf.st_blocks);
810 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
811 switch (statbuf.st_mode & S_IFMT) {
812 case S_IFCHR: case S_IFBLK:
813 tprintf("st_rdev=makedev(%lu, %lu), ",
814 (unsigned long) major(statbuf.st_rdev),
815 (unsigned long) minor(statbuf.st_rdev));
818 tprintf("st_size=%lu, ", statbuf.st_size);
822 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
823 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
824 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
830 #endif /* LINUXSPARC */
832 #if defined POWERPC64
833 struct stat_powerpc32 {
836 unsigned int st_mode;
837 unsigned short st_nlink;
840 unsigned int st_rdev;
841 unsigned int st_size;
842 unsigned int st_blksize;
843 unsigned int st_blocks;
844 unsigned int st_atime;
845 unsigned int st_atime_nsec;
846 unsigned int st_mtime;
847 unsigned int st_mtime_nsec;
848 unsigned int st_ctime;
849 unsigned int st_ctime_nsec;
850 unsigned int __unused4;
851 unsigned int __unused5;
855 printstat_powerpc32(struct tcb *tcp, long addr)
857 struct stat_powerpc32 statbuf;
859 if (umove(tcp, addr, &statbuf) < 0) {
865 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
866 major(statbuf.st_dev), minor(statbuf.st_dev),
868 sprintmode(statbuf.st_mode));
869 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
870 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
871 tprintf("st_blksize=%u, ", statbuf.st_blksize);
872 tprintf("st_blocks=%u, ", statbuf.st_blocks);
875 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
876 switch (statbuf.st_mode & S_IFMT) {
877 case S_IFCHR: case S_IFBLK:
878 tprintf("st_rdev=makedev(%lu, %lu), ",
879 (unsigned long) major(statbuf.st_rdev),
880 (unsigned long) minor(statbuf.st_rdev));
883 tprintf("st_size=%u, ", statbuf.st_size);
887 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
888 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
889 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
894 #endif /* POWERPC64 */
896 static const struct xlat fileflags[] = {
900 #ifndef HAVE_LONG_LONG_OFF_T
902 realprintstat(struct tcb *tcp, struct stat *statbuf)
905 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
906 (unsigned long) major(statbuf->st_dev),
907 (unsigned long) minor(statbuf->st_dev),
908 (unsigned long) statbuf->st_ino,
909 sprintmode(statbuf->st_mode));
910 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
911 (unsigned long) statbuf->st_nlink,
912 (unsigned long) statbuf->st_uid,
913 (unsigned long) statbuf->st_gid);
914 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
915 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
917 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
918 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
922 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
923 switch (statbuf->st_mode & S_IFMT) {
924 case S_IFCHR: case S_IFBLK:
925 #ifdef HAVE_STRUCT_STAT_ST_RDEV
926 tprintf("st_rdev=makedev(%lu, %lu), ",
927 (unsigned long) major(statbuf->st_rdev),
928 (unsigned long) minor(statbuf->st_rdev));
929 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
930 tprintf("st_size=makedev(%lu, %lu), ",
931 (unsigned long) major(statbuf->st_size),
932 (unsigned long) minor(statbuf->st_size));
933 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
936 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
940 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
941 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
942 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
943 #if HAVE_STRUCT_STAT_ST_FLAGS
944 tprints(", st_flags=");
945 printflags(fileflags, statbuf->st_flags, "UF_???");
947 #if HAVE_STRUCT_STAT_ST_ACLCNT
948 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
950 #if HAVE_STRUCT_STAT_ST_LEVEL
951 tprintf(", st_level=%ld", statbuf->st_level);
953 #if HAVE_STRUCT_STAT_ST_FSTYPE
954 tprintf(", st_fstype=%.*s",
955 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
957 #if HAVE_STRUCT_STAT_ST_GEN
958 tprintf(", st_gen=%u", statbuf->st_gen);
967 printstat(struct tcb *tcp, long addr)
975 if (syserror(tcp) || !verbose(tcp)) {
976 tprintf("%#lx", addr);
981 if (current_personality == 1) {
982 printstatsol(tcp, addr);
986 else if (current_personality == 2) {
987 printstat_sparc64(tcp, addr);
991 #endif /* LINUXSPARC */
993 #if defined POWERPC64
994 if (current_personality == 1) {
995 printstat_powerpc32(tcp, addr);
1000 if (umove(tcp, addr, &statbuf) < 0) {
1005 realprintstat(tcp, &statbuf);
1007 #endif /* !HAVE_LONG_LONG_OFF_T */
1009 #if !defined HAVE_STAT64 && defined X86_64
1011 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1012 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1013 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1014 * __GNUC__ is needed for the required __attribute__ below.
1017 unsigned long long st_dev;
1018 unsigned char __pad0[4];
1019 unsigned int __st_ino;
1020 unsigned int st_mode;
1021 unsigned int st_nlink;
1022 unsigned int st_uid;
1023 unsigned int st_gid;
1024 unsigned long long st_rdev;
1025 unsigned char __pad3[4];
1027 unsigned int st_blksize;
1028 unsigned long long st_blocks;
1029 unsigned int st_atime;
1030 unsigned int st_atime_nsec;
1031 unsigned int st_mtime;
1032 unsigned int st_mtime_nsec;
1033 unsigned int st_ctime;
1034 unsigned int st_ctime_nsec;
1035 unsigned long long st_ino;
1036 } __attribute__((packed));
1037 # define HAVE_STAT64 1
1038 # define STAT64_SIZE 96
1043 printstat64(struct tcb *tcp, long addr)
1045 struct stat64 statbuf;
1048 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1055 if (syserror(tcp) || !verbose(tcp)) {
1056 tprintf("%#lx", addr);
1061 if (current_personality == 1) {
1062 printstatsol(tcp, addr);
1066 else if (current_personality == 2) {
1067 printstat_sparc64(tcp, addr);
1071 #endif /* LINUXSPARC */
1074 if (current_personality == 0) {
1075 printstat(tcp, addr);
1080 if (umove(tcp, addr, &statbuf) < 0) {
1086 #ifdef HAVE_LONG_LONG
1087 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1089 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
1091 (unsigned long) major(statbuf.st_dev),
1092 (unsigned long) minor(statbuf.st_dev),
1093 #ifdef HAVE_LONG_LONG
1094 (unsigned long long) statbuf.st_ino,
1096 (unsigned long) statbuf.st_ino,
1098 sprintmode(statbuf.st_mode));
1099 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1100 (unsigned long) statbuf.st_nlink,
1101 (unsigned long) statbuf.st_uid,
1102 (unsigned long) statbuf.st_gid);
1103 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1104 tprintf("st_blksize=%lu, ",
1105 (unsigned long) statbuf.st_blksize);
1106 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1107 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
1108 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1109 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
1112 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1113 switch (statbuf.st_mode & S_IFMT) {
1114 case S_IFCHR: case S_IFBLK:
1115 #ifdef HAVE_STRUCT_STAT_ST_RDEV
1116 tprintf("st_rdev=makedev(%lu, %lu), ",
1117 (unsigned long) major(statbuf.st_rdev),
1118 (unsigned long) minor(statbuf.st_rdev));
1119 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
1120 tprintf("st_size=makedev(%lu, %lu), ",
1121 (unsigned long) major(statbuf.st_size),
1122 (unsigned long) minor(statbuf.st_size));
1123 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
1126 #ifdef HAVE_LONG_LONG
1127 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1129 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1134 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1135 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1136 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1137 #if HAVE_STRUCT_STAT_ST_FLAGS
1138 tprints(", st_flags=");
1139 printflags(fileflags, statbuf.st_flags, "UF_???");
1141 #if HAVE_STRUCT_STAT_ST_ACLCNT
1142 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1144 #if HAVE_STRUCT_STAT_ST_LEVEL
1145 tprintf(", st_level=%ld", statbuf.st_level);
1147 #if HAVE_STRUCT_STAT_ST_FSTYPE
1148 tprintf(", st_fstype=%.*s",
1149 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1151 #if HAVE_STRUCT_STAT_ST_GEN
1152 tprintf(", st_gen=%u", statbuf.st_gen);
1159 #endif /* HAVE_STAT64 */
1161 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1163 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
1165 newbuf->st_dev = oldbuf->st_dev;
1166 newbuf->st_ino = oldbuf->st_ino;
1167 newbuf->st_mode = oldbuf->st_mode;
1168 newbuf->st_nlink = oldbuf->st_nlink;
1169 newbuf->st_uid = oldbuf->st_uid;
1170 newbuf->st_gid = oldbuf->st_gid;
1171 newbuf->st_rdev = oldbuf->st_rdev;
1172 newbuf->st_size = oldbuf->st_size;
1173 newbuf->st_atime = oldbuf->st_atime;
1174 newbuf->st_mtime = oldbuf->st_mtime;
1175 newbuf->st_ctime = oldbuf->st_ctime;
1176 newbuf->st_blksize = 0; /* not supported in old_stat */
1177 newbuf->st_blocks = 0; /* not supported in old_stat */
1181 printoldstat(struct tcb *tcp, long addr)
1183 struct __old_kernel_stat statbuf;
1184 struct stat newstatbuf;
1190 if (syserror(tcp) || !verbose(tcp)) {
1191 tprintf("%#lx", addr);
1196 if (current_personality == 1) {
1197 printstatsol(tcp, addr);
1202 if (umove(tcp, addr, &statbuf) < 0) {
1207 convertoldstat(&statbuf, &newstatbuf);
1208 realprintstat(tcp, &newstatbuf);
1212 #ifndef HAVE_LONG_LONG_OFF_T
1214 sys_stat(struct tcb *tcp)
1216 if (entering(tcp)) {
1217 printpath(tcp, tcp->u_arg[0]);
1220 printstat(tcp, tcp->u_arg[1]);
1227 sys_stat64(struct tcb *tcp)
1230 if (entering(tcp)) {
1231 printpath(tcp, tcp->u_arg[0]);
1234 printstat64(tcp, tcp->u_arg[1]);
1238 return printargs(tcp);
1242 static const struct xlat fstatatflags[] = {
1243 #ifndef AT_SYMLINK_NOFOLLOW
1244 # define AT_SYMLINK_NOFOLLOW 0x100
1246 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1249 #define utimensatflags fstatatflags
1252 sys_newfstatat(struct tcb *tcp)
1254 if (entering(tcp)) {
1255 print_dirfd(tcp, tcp->u_arg[0]);
1256 printpath(tcp, tcp->u_arg[1]);
1260 if (current_personality == 0)
1261 printstat(tcp, tcp->u_arg[2]);
1263 printstat64(tcp, tcp->u_arg[2]);
1264 #elif defined HAVE_STAT64
1265 printstat64(tcp, tcp->u_arg[2]);
1267 printstat(tcp, tcp->u_arg[2]);
1270 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1275 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1277 sys_oldstat(struct tcb *tcp)
1279 if (entering(tcp)) {
1280 printpath(tcp, tcp->u_arg[0]);
1283 printoldstat(tcp, tcp->u_arg[1]);
1289 #ifndef HAVE_LONG_LONG_OFF_T
1291 sys_fstat(struct tcb *tcp)
1293 if (entering(tcp)) {
1294 printfd(tcp, tcp->u_arg[0]);
1297 printstat(tcp, tcp->u_arg[1]);
1304 sys_fstat64(struct tcb *tcp)
1307 if (entering(tcp)) {
1308 printfd(tcp, tcp->u_arg[0]);
1311 printstat64(tcp, tcp->u_arg[1]);
1315 return printargs(tcp);
1319 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1321 sys_oldfstat(struct tcb *tcp)
1323 if (entering(tcp)) {
1324 printfd(tcp, tcp->u_arg[0]);
1327 printoldstat(tcp, tcp->u_arg[1]);
1333 #ifndef HAVE_LONG_LONG_OFF_T
1335 sys_lstat(struct tcb *tcp)
1337 if (entering(tcp)) {
1338 printpath(tcp, tcp->u_arg[0]);
1341 printstat(tcp, tcp->u_arg[1]);
1348 sys_lstat64(struct tcb *tcp)
1351 if (entering(tcp)) {
1352 printpath(tcp, tcp->u_arg[0]);
1355 printstat64(tcp, tcp->u_arg[1]);
1359 return printargs(tcp);
1363 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1365 sys_oldlstat(struct tcb *tcp)
1367 if (entering(tcp)) {
1368 printpath(tcp, tcp->u_arg[0]);
1371 printoldstat(tcp, tcp->u_arg[1]);
1377 #if defined(LINUXSPARC)
1380 sys_xstat(struct tcb *tcp)
1382 if (entering(tcp)) {
1383 tprintf("%ld, ", tcp->u_arg[0]);
1384 printpath(tcp, tcp->u_arg[1]);
1388 if (tcp->u_arg[0] == _STAT64_VER)
1389 printstat64(tcp, tcp->u_arg[2]);
1392 printstat(tcp, tcp->u_arg[2]);
1398 sys_fxstat(struct tcb *tcp)
1401 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1404 if (tcp->u_arg[0] == _STAT64_VER)
1405 printstat64(tcp, tcp->u_arg[2]);
1408 printstat(tcp, tcp->u_arg[2]);
1414 sys_lxstat(struct tcb *tcp)
1416 if (entering(tcp)) {
1417 tprintf("%ld, ", tcp->u_arg[0]);
1418 printpath(tcp, tcp->u_arg[1]);
1422 if (tcp->u_arg[0] == _STAT64_VER)
1423 printstat64(tcp, tcp->u_arg[2]);
1426 printstat(tcp, tcp->u_arg[2]);
1432 sys_xmknod(struct tcb *tcp)
1434 int mode = tcp->u_arg[2];
1436 if (entering(tcp)) {
1437 tprintf("%ld, ", tcp->u_arg[0]);
1438 printpath(tcp, tcp->u_arg[1]);
1439 tprintf(", %s", sprintmode(mode));
1440 switch (mode & S_IFMT) {
1441 case S_IFCHR: case S_IFBLK:
1442 tprintf(", makedev(%lu, %lu)",
1443 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1444 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1453 # ifdef HAVE_SYS_ACL_H
1455 # include <sys/acl.h>
1457 static const struct xlat aclcmds[] = {
1459 { SETACL, "SETACL" },
1462 { GETACL, "GETACL" },
1465 { GETACLCNT, "GETACLCNT" },
1468 { ACL_GET, "ACL_GET" },
1471 { ACL_SET, "ACL_SET" },
1474 { ACL_CNT, "ACL_CNT" },
1480 sys_acl(struct tcb *tcp)
1482 if (entering(tcp)) {
1483 printpath(tcp, tcp->u_arg[0]);
1485 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1486 tprintf(", %ld", tcp->u_arg[2]);
1488 * FIXME - dump out the list of aclent_t's pointed to
1489 * by "tcp->u_arg[3]" if it's not NULL.
1492 tprintf(", %#lx", tcp->u_arg[3]);
1500 sys_facl(struct tcb *tcp)
1502 if (entering(tcp)) {
1503 tprintf("%ld, ", tcp->u_arg[0]);
1504 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1505 tprintf(", %ld", tcp->u_arg[2]);
1507 * FIXME - dump out the list of aclent_t's pointed to
1508 * by "tcp->u_arg[3]" if it's not NULL.
1511 tprintf(", %#lx", tcp->u_arg[3]);
1518 static const struct xlat aclipc[] = {
1520 { IPC_SHM, "IPC_SHM" },
1523 { IPC_SEM, "IPC_SEM" },
1526 { IPC_MSG, "IPC_MSG" },
1532 sys_aclipc(struct tcb *tcp)
1534 if (entering(tcp)) {
1535 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1536 tprintf(", %#lx, ", tcp->u_arg[1]);
1537 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1538 tprintf(", %ld", tcp->u_arg[3]);
1540 * FIXME - dump out the list of aclent_t's pointed to
1541 * by "tcp->u_arg[4]" if it's not NULL.
1544 tprintf(", %#lx", tcp->u_arg[4]);
1551 # endif /* HAVE_SYS_ACL_H */
1553 #endif /* LINUXSPARC */
1555 static const struct xlat fsmagic[] = {
1556 { 0x73757245, "CODA_SUPER_MAGIC" },
1557 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1558 { 0x1373, "DEVFS_SUPER_MAGIC" },
1559 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1560 { 0x414A53, "EFS_SUPER_MAGIC" },
1561 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1562 { 0xef53, "EXT2_SUPER_MAGIC" },
1563 { 0x137d, "EXT_SUPER_MAGIC" },
1564 { 0xf995e849, "HPFS_SUPER_MAGIC" },
1565 { 0x9660, "ISOFS_SUPER_MAGIC" },
1566 { 0x137f, "MINIX_SUPER_MAGIC" },
1567 { 0x138f, "MINIX_SUPER_MAGIC2" },
1568 { 0x2468, "MINIX2_SUPER_MAGIC" },
1569 { 0x2478, "MINIX2_SUPER_MAGIC2" },
1570 { 0x4d44, "MSDOS_SUPER_MAGIC" },
1571 { 0x564c, "NCP_SUPER_MAGIC" },
1572 { 0x6969, "NFS_SUPER_MAGIC" },
1573 { 0x9fa0, "PROC_SUPER_MAGIC" },
1574 { 0x002f, "QNX4_SUPER_MAGIC" },
1575 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1576 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1577 { 0x517b, "SMB_SUPER_MAGIC" },
1578 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1579 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1580 { 0x00011954, "UFS_MAGIC" },
1581 { 0x54190100, "UFS_CIGAM" },
1582 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
1583 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
1584 { 0x62656572, "SYSFS_MAGIC" },
1589 sprintfstype(int magic)
1591 static char buf[32];
1594 s = xlookup(fsmagic, magic);
1596 sprintf(buf, "\"%s\"", s);
1599 sprintf(buf, "%#x", magic);
1604 printstatfs(struct tcb *tcp, long addr)
1606 struct statfs statbuf;
1608 if (syserror(tcp) || !verbose(tcp)) {
1609 tprintf("%#lx", addr);
1612 if (umove(tcp, addr, &statbuf) < 0) {
1618 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1619 sprintfstype(statbuf.f_type),
1620 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1621 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1622 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
1623 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1626 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1627 sprintfstype(statbuf.f_type),
1628 (unsigned long)statbuf.f_bsize,
1629 (unsigned long)statbuf.f_blocks,
1630 (unsigned long)statbuf.f_bfree);
1631 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1632 (unsigned long)statbuf.f_bavail,
1633 (unsigned long)statbuf.f_files,
1634 (unsigned long)statbuf.f_ffree,
1635 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1636 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1638 #ifdef _STATFS_F_FRSIZE
1639 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1645 sys_statfs(struct tcb *tcp)
1647 if (entering(tcp)) {
1648 printpath(tcp, tcp->u_arg[0]);
1651 printstatfs(tcp, tcp->u_arg[1]);
1657 sys_fstatfs(struct tcb *tcp)
1659 if (entering(tcp)) {
1660 printfd(tcp, tcp->u_arg[0]);
1663 printstatfs(tcp, tcp->u_arg[1]);
1668 #if defined HAVE_STATFS64
1670 printstatfs64(struct tcb *tcp, long addr)
1672 struct statfs64 statbuf;
1674 if (syserror(tcp) || !verbose(tcp)) {
1675 tprintf("%#lx", addr);
1678 if (umove(tcp, addr, &statbuf) < 0) {
1682 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
1683 sprintfstype(statbuf.f_type),
1684 (unsigned long long)statbuf.f_bsize,
1685 (unsigned long long)statbuf.f_blocks,
1686 (unsigned long long)statbuf.f_bfree);
1687 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1688 (unsigned long long)statbuf.f_bavail,
1689 (unsigned long long)statbuf.f_files,
1690 (unsigned long long)statbuf.f_ffree,
1691 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1692 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1693 #ifdef _STATFS_F_FRSIZE
1694 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
1696 #ifdef _STATFS_F_FLAGS
1697 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1702 struct compat_statfs64 {
1714 uint32_t f_spare[4];
1716 #if defined(X86_64) || defined(IA64)
1717 __attribute__ ((packed, aligned(4)))
1722 printcompat_statfs64(struct tcb *tcp, long addr)
1724 struct compat_statfs64 statbuf;
1726 if (syserror(tcp) || !verbose(tcp)) {
1727 tprintf("%#lx", addr);
1730 if (umove(tcp, addr, &statbuf) < 0) {
1734 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1735 sprintfstype(statbuf.f_type),
1736 (unsigned long)statbuf.f_bsize,
1737 (unsigned long long)statbuf.f_blocks,
1738 (unsigned long long)statbuf.f_bfree);
1739 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1740 (unsigned long long)statbuf.f_bavail,
1741 (unsigned long long)statbuf.f_files,
1742 (unsigned long long)statbuf.f_ffree,
1743 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1744 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1745 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1746 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
1750 sys_statfs64(struct tcb *tcp)
1752 if (entering(tcp)) {
1753 printpath(tcp, tcp->u_arg[0]);
1754 tprintf(", %lu, ", tcp->u_arg[1]);
1756 if (tcp->u_arg[1] == sizeof(struct statfs64))
1757 printstatfs64(tcp, tcp->u_arg[2]);
1758 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1759 printcompat_statfs64(tcp, tcp->u_arg[2]);
1767 sys_fstatfs64(struct tcb *tcp)
1769 if (entering(tcp)) {
1770 printfd(tcp, tcp->u_arg[0]);
1771 tprintf(", %lu, ", tcp->u_arg[1]);
1773 if (tcp->u_arg[1] == sizeof(struct statfs64))
1774 printstatfs64(tcp, tcp->u_arg[2]);
1775 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1776 printcompat_statfs64(tcp, tcp->u_arg[2]);
1786 osf_statfs(struct tcb *tcp)
1788 if (entering(tcp)) {
1789 printpath(tcp, tcp->u_arg[0]);
1792 printstatfs(tcp, tcp->u_arg[1]);
1793 tprintf(", %lu", tcp->u_arg[2]);
1799 osf_fstatfs(struct tcb *tcp)
1801 if (entering(tcp)) {
1802 tprintf("%lu, ", tcp->u_arg[0]);
1804 printstatfs(tcp, tcp->u_arg[1]);
1805 tprintf(", %lu", tcp->u_arg[2]);
1813 sys_chdir(struct tcb *tcp)
1815 if (entering(tcp)) {
1816 printpath(tcp, tcp->u_arg[0]);
1822 decode_mkdir(struct tcb *tcp, int offset)
1824 if (entering(tcp)) {
1825 printpath(tcp, tcp->u_arg[offset]);
1826 tprintf(", %#lo", tcp->u_arg[offset + 1]);
1832 sys_mkdir(struct tcb *tcp)
1834 return decode_mkdir(tcp, 0);
1838 sys_mkdirat(struct tcb *tcp)
1841 print_dirfd(tcp, tcp->u_arg[0]);
1842 return decode_mkdir(tcp, 1);
1846 sys_link(struct tcb *tcp)
1848 if (entering(tcp)) {
1849 printpath(tcp, tcp->u_arg[0]);
1851 printpath(tcp, tcp->u_arg[1]);
1857 sys_linkat(struct tcb *tcp)
1859 if (entering(tcp)) {
1860 print_dirfd(tcp, tcp->u_arg[0]);
1861 printpath(tcp, tcp->u_arg[1]);
1863 print_dirfd(tcp, tcp->u_arg[2]);
1864 printpath(tcp, tcp->u_arg[3]);
1866 printfd(tcp, tcp->u_arg[4]);
1871 static const struct xlat unlinkatflags[] = {
1872 #ifndef AT_REMOVEDIR
1873 # define AT_REMOVEDIR 0x200
1875 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1880 sys_unlinkat(struct tcb *tcp)
1882 if (entering(tcp)) {
1883 print_dirfd(tcp, tcp->u_arg[0]);
1884 printpath(tcp, tcp->u_arg[1]);
1886 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1892 sys_symlinkat(struct tcb *tcp)
1894 if (entering(tcp)) {
1895 printpath(tcp, tcp->u_arg[0]);
1897 print_dirfd(tcp, tcp->u_arg[1]);
1898 printpath(tcp, tcp->u_arg[2]);
1904 decode_readlink(struct tcb *tcp, int offset)
1906 if (entering(tcp)) {
1907 printpath(tcp, tcp->u_arg[offset]);
1911 tprintf("%#lx", tcp->u_arg[offset + 1]);
1913 /* Used to use printpathn(), but readlink
1914 * neither includes NUL in the returned count,
1915 * nor actually writes it into memory.
1916 * printpathn() would decide on printing
1917 * "..." continuation based on garbage
1918 * past return buffer's end.
1920 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1921 tprintf(", %lu", tcp->u_arg[offset + 2]);
1927 sys_readlink(struct tcb *tcp)
1929 return decode_readlink(tcp, 0);
1933 sys_readlinkat(struct tcb *tcp)
1936 print_dirfd(tcp, tcp->u_arg[0]);
1937 return decode_readlink(tcp, 1);
1941 sys_renameat(struct tcb *tcp)
1943 if (entering(tcp)) {
1944 print_dirfd(tcp, tcp->u_arg[0]);
1945 printpath(tcp, tcp->u_arg[1]);
1947 print_dirfd(tcp, tcp->u_arg[2]);
1948 printpath(tcp, tcp->u_arg[3]);
1954 sys_chown(struct tcb *tcp)
1956 if (entering(tcp)) {
1957 printpath(tcp, tcp->u_arg[0]);
1958 printuid(", ", tcp->u_arg[1]);
1959 printuid(", ", tcp->u_arg[2]);
1965 sys_fchownat(struct tcb *tcp)
1967 if (entering(tcp)) {
1968 print_dirfd(tcp, tcp->u_arg[0]);
1969 printpath(tcp, tcp->u_arg[1]);
1970 printuid(", ", tcp->u_arg[2]);
1971 printuid(", ", tcp->u_arg[3]);
1973 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
1979 sys_fchown(struct tcb *tcp)
1981 if (entering(tcp)) {
1982 printfd(tcp, tcp->u_arg[0]);
1983 printuid(", ", tcp->u_arg[1]);
1984 printuid(", ", tcp->u_arg[2]);
1990 decode_chmod(struct tcb *tcp, int offset)
1992 if (entering(tcp)) {
1993 printpath(tcp, tcp->u_arg[offset]);
1994 tprintf(", %#lo", tcp->u_arg[offset + 1]);
2000 sys_chmod(struct tcb *tcp)
2002 return decode_chmod(tcp, 0);
2006 sys_fchmodat(struct tcb *tcp)
2009 print_dirfd(tcp, tcp->u_arg[0]);
2010 return decode_chmod(tcp, 1);
2014 sys_fchmod(struct tcb *tcp)
2016 if (entering(tcp)) {
2017 printfd(tcp, tcp->u_arg[0]);
2018 tprintf(", %#lo", tcp->u_arg[1]);
2025 sys_osf_utimes(struct tcb *tcp)
2027 if (entering(tcp)) {
2028 printpath(tcp, tcp->u_arg[0]);
2030 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2037 decode_utimes(struct tcb *tcp, int offset, int special)
2039 if (entering(tcp)) {
2040 printpath(tcp, tcp->u_arg[offset]);
2042 if (tcp->u_arg[offset + 1] == 0)
2046 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2047 BITNESS_CURRENT, special);
2049 printtv_bitness(tcp, tcp->u_arg[offset + 1]
2050 + sizeof(struct timeval),
2051 BITNESS_CURRENT, special);
2059 sys_utimes(struct tcb *tcp)
2061 return decode_utimes(tcp, 0, 0);
2065 sys_futimesat(struct tcb *tcp)
2068 print_dirfd(tcp, tcp->u_arg[0]);
2069 return decode_utimes(tcp, 1, 0);
2073 sys_utimensat(struct tcb *tcp)
2075 if (entering(tcp)) {
2076 print_dirfd(tcp, tcp->u_arg[0]);
2077 decode_utimes(tcp, 1, 1);
2079 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2085 sys_utime(struct tcb *tcp)
2091 unsigned wordsize = personality_wordsize[current_personality];
2093 if (entering(tcp)) {
2094 printpath(tcp, tcp->u_arg[0]);
2098 else if (!verbose(tcp))
2099 tprintf("%#lx", tcp->u_arg[1]);
2100 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
2102 else if (wordsize == sizeof u.utl[0]) {
2103 tprintf("[%s,", sprinttime(u.utl[0]));
2104 tprintf(" %s]", sprinttime(u.utl[1]));
2106 else if (wordsize == sizeof u.uti[0]) {
2107 tprintf("[%s,", sprinttime(u.uti[0]));
2108 tprintf(" %s]", sprinttime(u.uti[1]));
2117 decode_mknod(struct tcb *tcp, int offset)
2119 int mode = tcp->u_arg[offset + 1];
2121 if (entering(tcp)) {
2122 printpath(tcp, tcp->u_arg[offset]);
2123 tprintf(", %s", sprintmode(mode));
2124 switch (mode & S_IFMT) {
2128 if (current_personality == 1)
2129 tprintf(", makedev(%lu, %lu)",
2130 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2131 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
2134 tprintf(", makedev(%lu, %lu)",
2135 (unsigned long) major(tcp->u_arg[offset + 2]),
2136 (unsigned long) minor(tcp->u_arg[offset + 2]));
2146 sys_mknod(struct tcb *tcp)
2148 return decode_mknod(tcp, 0);
2152 sys_mknodat(struct tcb *tcp)
2155 print_dirfd(tcp, tcp->u_arg[0]);
2156 return decode_mknod(tcp, 1);
2160 printdir(struct tcb *tcp, long addr)
2164 if (!verbose(tcp)) {
2165 tprintf("%#lx", addr);
2168 if (umove(tcp, addr, &d) < 0) {
2172 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
2174 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2179 sys_readdir(struct tcb *tcp)
2181 if (entering(tcp)) {
2182 printfd(tcp, tcp->u_arg[0]);
2185 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2186 tprintf("%#lx", tcp->u_arg[1]);
2188 printdir(tcp, tcp->u_arg[1]);
2189 /* Not much point in printing this out, it is always 1. */
2190 if (tcp->u_arg[2] != 1)
2191 tprintf(", %lu", tcp->u_arg[2]);
2196 static const struct xlat direnttypes[] = {
2197 { DT_UNKNOWN, "DT_UNKNOWN" },
2198 { DT_FIFO, "DT_FIFO" },
2199 { DT_CHR, "DT_CHR" },
2200 { DT_DIR, "DT_DIR" },
2201 { DT_BLK, "DT_BLK" },
2202 { DT_REG, "DT_REG" },
2203 { DT_LNK, "DT_LNK" },
2204 { DT_SOCK, "DT_SOCK" },
2205 { DT_WHT, "DT_WHT" },
2210 sys_getdents(struct tcb *tcp)
2212 int i, len, dents = 0;
2215 if (entering(tcp)) {
2216 printfd(tcp, tcp->u_arg[0]);
2220 if (syserror(tcp) || !verbose(tcp)) {
2221 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2225 /* Beware of insanely large or negative values in tcp->u_rval */
2226 if (tcp->u_rval > 1024*1024)
2228 if (tcp->u_rval < 0)
2230 buf = len ? malloc(len) : NULL;
2232 die_out_of_memory();
2233 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2234 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2240 for (i = 0; i < len;) {
2241 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2243 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2244 i ? " " : "", d->d_ino, d->d_off);
2245 tprintf("d_reclen=%u, d_name=\"%s\"}",
2246 d->d_reclen, d->d_name);
2249 tprints("/* d_reclen == 0, problem here */");
2258 tprintf("/* %u entries */", dents);
2259 tprintf(", %lu", tcp->u_arg[2]);
2264 #if _LFS64_LARGEFILE
2266 sys_getdents64(struct tcb *tcp)
2268 int i, len, dents = 0;
2271 if (entering(tcp)) {
2272 printfd(tcp, tcp->u_arg[0]);
2276 if (syserror(tcp) || !verbose(tcp)) {
2277 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2282 /* Beware of insanely large or negative tcp->u_rval */
2283 if (tcp->u_rval > 1024*1024)
2285 if (tcp->u_rval < 0)
2287 buf = len ? malloc(len) : NULL;
2289 die_out_of_memory();
2291 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2292 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2298 for (i = 0; i < len;) {
2299 struct dirent64 *d = (struct dirent64 *) &buf[i];
2301 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
2306 printxval(direnttypes, d->d_type, "DT_???");
2308 tprintf("d_reclen=%u, d_name=\"%s\"}",
2309 d->d_reclen, d->d_name);
2312 tprints("/* d_reclen == 0, problem here */");
2321 tprintf("/* %u entries */", dents);
2322 tprintf(", %lu", tcp->u_arg[2]);
2329 sys_getcwd(struct tcb *tcp)
2333 tprintf("%#lx", tcp->u_arg[0]);
2335 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2336 tprintf(", %lu", tcp->u_arg[1]);
2341 #ifdef HAVE_SYS_ASYNCH_H
2344 sys_aioread(struct tcb *tcp)
2346 struct aio_result_t res;
2348 if (entering(tcp)) {
2349 tprintf("%lu, ", tcp->u_arg[0]);
2352 tprintf("%#lx", tcp->u_arg[1]);
2354 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2355 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2356 printxval(whence, tcp->u_arg[4], "L_???");
2357 if (syserror(tcp) || tcp->u_arg[5] == 0
2358 || umove(tcp, tcp->u_arg[5], &res) < 0)
2359 tprintf(", %#lx", tcp->u_arg[5]);
2361 tprintf(", {aio_return %d aio_errno %d}",
2362 res.aio_return, res.aio_errno);
2368 sys_aiowrite(struct tcb *tcp)
2370 struct aio_result_t res;
2372 if (entering(tcp)) {
2373 tprintf("%lu, ", tcp->u_arg[0]);
2374 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2375 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2376 printxval(whence, tcp->u_arg[4], "L_???");
2379 if (tcp->u_arg[5] == 0)
2381 else if (syserror(tcp)
2382 || umove(tcp, tcp->u_arg[5], &res) < 0)
2383 tprintf(", %#lx", tcp->u_arg[5]);
2385 tprintf(", {aio_return %d aio_errno %d}",
2386 res.aio_return, res.aio_errno);
2392 sys_aiowait(struct tcb *tcp)
2395 printtv(tcp, tcp->u_arg[0]);
2400 sys_aiocancel(struct tcb *tcp)
2402 struct aio_result_t res;
2405 if (tcp->u_arg[0] == 0)
2407 else if (syserror(tcp)
2408 || umove(tcp, tcp->u_arg[0], &res) < 0)
2409 tprintf("%#lx", tcp->u_arg[0]);
2411 tprintf("{aio_return %d aio_errno %d}",
2412 res.aio_return, res.aio_errno);
2417 #endif /* HAVE_SYS_ASYNCH_H */
2419 static const struct xlat xattrflags[] = {
2421 { XATTR_CREATE, "XATTR_CREATE" },
2422 { XATTR_REPLACE, "XATTR_REPLACE" },
2428 print_xattr_val(struct tcb *tcp, int failed,
2430 unsigned long insize,
2434 unsigned long capacity = 4 * size + 1;
2435 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2436 if (buf == NULL || /* probably a bogus size argument */
2437 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2441 unsigned char *out = buf;
2442 unsigned char *in = &buf[3 * size];
2444 for (i = 0; i < size; ++i) {
2448 #define tohex(n) "0123456789abcdef"[n]
2451 *out++ = tohex(in[i] / 16);
2452 *out++ = tohex(in[i] % 16);
2455 /* Don't print terminating NUL if there is one. */
2456 if (i > 0 && in[i - 1] == '\0')
2459 tprintf(", \"%s\", %ld", buf, insize);
2464 tprintf(", 0x%lx, %ld", arg, insize);
2468 sys_setxattr(struct tcb *tcp)
2470 if (entering(tcp)) {
2471 printpath(tcp, tcp->u_arg[0]);
2473 printstr(tcp, tcp->u_arg[1], -1);
2474 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2476 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2482 sys_fsetxattr(struct tcb *tcp)
2484 if (entering(tcp)) {
2485 printfd(tcp, tcp->u_arg[0]);
2487 printstr(tcp, tcp->u_arg[1], -1);
2488 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2490 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2496 sys_getxattr(struct tcb *tcp)
2498 if (entering(tcp)) {
2499 printpath(tcp, tcp->u_arg[0]);
2501 printstr(tcp, tcp->u_arg[1], -1);
2503 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2510 sys_fgetxattr(struct tcb *tcp)
2512 if (entering(tcp)) {
2513 printfd(tcp, tcp->u_arg[0]);
2515 printstr(tcp, tcp->u_arg[1], -1);
2517 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2524 sys_listxattr(struct tcb *tcp)
2526 if (entering(tcp)) {
2527 printpath(tcp, tcp->u_arg[0]);
2529 /* XXX Print value in format */
2530 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2536 sys_flistxattr(struct tcb *tcp)
2538 if (entering(tcp)) {
2539 printfd(tcp, tcp->u_arg[0]);
2541 /* XXX Print value in format */
2542 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2548 sys_removexattr(struct tcb *tcp)
2550 if (entering(tcp)) {
2551 printpath(tcp, tcp->u_arg[0]);
2553 printstr(tcp, tcp->u_arg[1], -1);
2559 sys_fremovexattr(struct tcb *tcp)
2561 if (entering(tcp)) {
2562 printfd(tcp, tcp->u_arg[0]);
2564 printstr(tcp, tcp->u_arg[1], -1);
2569 static const struct xlat advise[] = {
2570 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2571 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2572 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2573 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2574 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2575 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2580 sys_fadvise64(struct tcb *tcp)
2582 if (entering(tcp)) {
2584 printfd(tcp, tcp->u_arg[0]);
2586 argn = printllval(tcp, "%lld", 1);
2587 tprintf(", %ld, ", tcp->u_arg[argn++]);
2588 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2594 sys_fadvise64_64(struct tcb *tcp)
2596 if (entering(tcp)) {
2598 printfd(tcp, tcp->u_arg[0]);
2600 #if defined ARM || defined POWERPC
2601 argn = printllval(tcp, "%lld, ", 2);
2603 argn = printllval(tcp, "%lld, ", 1);
2605 argn = printllval(tcp, "%lld, ", argn);
2606 #if defined ARM || defined POWERPC
2607 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
2609 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2615 static const struct xlat inotify_modes[] = {
2616 { 0x00000001, "IN_ACCESS" },
2617 { 0x00000002, "IN_MODIFY" },
2618 { 0x00000004, "IN_ATTRIB" },
2619 { 0x00000008, "IN_CLOSE_WRITE"},
2620 { 0x00000010, "IN_CLOSE_NOWRITE"},
2621 { 0x00000020, "IN_OPEN" },
2622 { 0x00000040, "IN_MOVED_FROM" },
2623 { 0x00000080, "IN_MOVED_TO" },
2624 { 0x00000100, "IN_CREATE" },
2625 { 0x00000200, "IN_DELETE" },
2626 { 0x00000400, "IN_DELETE_SELF"},
2627 { 0x00000800, "IN_MOVE_SELF" },
2628 { 0x00002000, "IN_UNMOUNT" },
2629 { 0x00004000, "IN_Q_OVERFLOW" },
2630 { 0x00008000, "IN_IGNORED" },
2631 { 0x01000000, "IN_ONLYDIR" },
2632 { 0x02000000, "IN_DONT_FOLLOW"},
2633 { 0x20000000, "IN_MASK_ADD" },
2634 { 0x40000000, "IN_ISDIR" },
2635 { 0x80000000, "IN_ONESHOT" },
2639 static const struct xlat inotify_init_flags[] = {
2640 { 0x00000800, "IN_NONBLOCK" },
2641 { 0x00080000, "IN_CLOEXEC" },
2646 sys_inotify_add_watch(struct tcb *tcp)
2648 if (entering(tcp)) {
2649 printfd(tcp, tcp->u_arg[0]);
2651 printpath(tcp, tcp->u_arg[1]);
2653 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2659 sys_inotify_rm_watch(struct tcb *tcp)
2661 if (entering(tcp)) {
2662 printfd(tcp, tcp->u_arg[0]);
2663 tprintf(", %d", (int) tcp->u_arg[1]);
2669 sys_inotify_init1(struct tcb *tcp)
2672 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
2677 sys_fallocate(struct tcb *tcp)
2679 if (entering(tcp)) {
2681 printfd(tcp, tcp->u_arg[0]); /* fd */
2683 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
2684 argn = printllval(tcp, "%llu, ", 2); /* offset */
2685 printllval(tcp, "%llu", argn); /* len */
2690 static const struct xlat swap_flags[] = {
2691 { SWAP_FLAG_PREFER, "SWAP_FLAG_PREFER" },
2692 { SWAP_FLAG_DISCARD, "SWAP_FLAG_DISCARD" },
2697 sys_swapon(struct tcb *tcp)
2699 if (entering(tcp)) {
2700 int flags = tcp->u_arg[1];
2701 printpath(tcp, tcp->u_arg[0]);
2703 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2705 if (flags & SWAP_FLAG_PREFER)
2706 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);