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;
45 # define kernel_dirent dirent
51 unsigned short st_dev;
53 unsigned short st_mode;
55 unsigned short st_uid;
56 unsigned short st_gid;
57 unsigned short st_rdev;
60 unsigned int __unused1;
62 unsigned int __unused2;
64 unsigned int __unused3;
67 unsigned int __unused4[2];
74 unsigned int st_nlink;
84 unsigned long __unused4[2];
87 # define stat kernel_stat
88 # include <asm/stat.h>
100 # define dev_t __kernel_dev_t
101 # define ino_t __kernel_ino_t
102 # define mode_t __kernel_mode_t
103 # define nlink_t __kernel_nlink_t
104 # define uid_t __kernel_uid_t
105 # define gid_t __kernel_gid_t
106 # define off_t __kernel_off_t
107 # define loff_t __kernel_loff_t
109 # include <asm/stat.h>
122 # define mode_t mode_t
123 # define nlink_t nlink_t
127 # define loff_t loff_t
129 # ifdef HPPA /* asm-parisc/stat.h defines stat64 */
132 # define stat libc_stat
133 # define stat64 libc_stat64
134 # include <sys/stat.h>
137 /* These might be macros. */
142 # define stat64 hpux_stat64
145 # include <sys/stat.h>
151 # include <sys/cred.h>
154 #ifdef HAVE_SYS_VFS_H
158 #ifdef HAVE_LINUX_XATTR_H
159 #include <linux/xattr.h>
161 #define XATTR_CREATE 1
162 #define XATTR_REPLACE 2
166 #include <sys/param.h>
167 #include <sys/mount.h>
168 #include <sys/stat.h>
171 #if _LFS64_LARGEFILE && (defined(LINUX) || defined(SVR4))
172 # ifdef HAVE_INTTYPES_H
173 # include <inttypes.h>
175 # define PRId64 "lld"
176 # define PRIu64 "llu"
180 #if HAVE_LONG_LONG_OFF_T
182 * Ugly hacks for systems that have typedef long long off_t
186 #define HAVE_STAT64 1 /* Ugly hack */
188 #define sys_stat64 sys_stat
189 #define sys_fstat64 sys_fstat
190 #define sys_lstat64 sys_lstat
191 #define sys_lseek64 sys_lseek
192 #define sys_truncate64 sys_truncate
193 #define sys_ftruncate64 sys_ftruncate
196 #ifdef MAJOR_IN_SYSMACROS
197 #include <sys/sysmacros.h>
200 #ifdef MAJOR_IN_MKDEV
201 #include <sys/mkdev.h>
204 #ifdef HAVE_SYS_ASYNCH_H
205 #include <sys/asynch.h>
212 const struct xlat open_access_modes[] = {
213 { O_RDONLY, "O_RDONLY" },
214 { O_WRONLY, "O_WRONLY" },
215 { O_RDWR, "O_RDWR" },
217 { O_ACCMODE, "O_ACCMODE" },
222 const struct xlat open_mode_flags[] = {
223 { O_CREAT, "O_CREAT" },
224 { O_EXCL, "O_EXCL" },
225 { O_NOCTTY, "O_NOCTTY" },
226 { O_TRUNC, "O_TRUNC" },
227 { O_APPEND, "O_APPEND" },
228 { O_NONBLOCK, "O_NONBLOCK" },
230 { O_SYNC, "O_SYNC" },
233 { O_ASYNC, "O_ASYNC" },
236 { O_DSYNC, "O_DSYNC" },
239 { O_RSYNC, "O_RSYNC" },
241 #if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
242 { O_NDELAY, "O_NDELAY" },
245 { O_PRIV, "O_PRIV" },
248 { O_DIRECT, "O_DIRECT" },
251 # if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
254 # define O_LARGEFILE 0x40000
255 # elif defined X86_64 || defined S390X
256 # define O_LARGEFILE 0100000
260 { O_LARGEFILE, "O_LARGEFILE" },
264 { O_DIRECTORY, "O_DIRECTORY" },
267 { O_NOFOLLOW, "O_NOFOLLOW" },
270 { O_NOATIME, "O_NOATIME" },
273 { O_CLOEXEC, "O_CLOEXEC" },
277 { FNDELAY, "FNDELAY" },
280 { FAPPEND, "FAPPEND" },
286 { FDEFER, "FDEFER" },
289 { FASYNC, "FASYNC" },
292 { FSHLOCK, "FSHLOCK" },
295 { FEXLOCK, "FEXLOCK" },
298 { FCREAT, "FCREAT" },
301 { FTRUNC, "FTRUNC" },
313 { FNOCTTY, "FNOCTTY" },
316 { O_SHLOCK, "O_SHLOCK" },
319 { O_EXLOCK, "O_EXLOCK" },
327 # define AT_FDCWD -100
330 /* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
331 * extension to get the right value. We do this by declaring fd as int here.
337 tprintf("AT_FDCWD, ");
344 * Pity stpcpy() is not standardized...
347 str_append(char *dst, const char *src)
349 while ((*dst = *src++) != '\0')
355 * low bits of the open(2) flags define access mode,
356 * other bits are real flags.
359 sprint_open_modes(mode_t flags)
361 static char outstr[1024];
365 const struct xlat *x;
367 p = str_append(outstr, "flags ");
368 str = xlookup(open_access_modes, flags & 3);
370 p = str_append(p, str);
377 for (x = open_mode_flags; x->str; x++) {
378 if ((flags & x->val) == x->val) {
381 p = str_append(p, x->str);
388 /* flags is still nonzero */
391 sprintf(p, "%#x", flags);
396 tprint_open_modes(mode_t flags)
398 tprintf("%s", sprint_open_modes(flags) + sizeof("flags"));
402 decode_open(struct tcb *tcp, int offset)
405 printpath(tcp, tcp->u_arg[offset]);
408 tprint_open_modes(tcp->u_arg[offset + 1]);
409 if (tcp->u_arg[offset + 1] & O_CREAT) {
411 tprintf(", %#lo", tcp->u_arg[offset + 2]);
418 sys_open(struct tcb *tcp)
420 return decode_open(tcp, 0);
425 sys_openat(struct tcb *tcp)
428 print_dirfd(tcp->u_arg[0]);
429 return decode_open(tcp, 1);
434 static const struct xlat openmodessol[] = {
438 { 0x80, "O_NONBLOCK" },
440 { 0x100, "O_CREAT" },
441 { 0x200, "O_TRUNC" },
443 { 0x800, "O_NOCTTY" },
446 { 0x8000, "O_RSYNC" },
448 { 0x1000, "O_PRIV" },
453 solaris_open(struct tcb *tcp)
456 printpath(tcp, tcp->u_arg[0]);
459 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
460 if (tcp->u_arg[1] & 0x100) {
462 tprintf(", %#lo", tcp->u_arg[2]);
471 sys_creat(struct tcb *tcp)
474 printpath(tcp, tcp->u_arg[0]);
475 tprintf(", %#lo", tcp->u_arg[1]);
480 static const struct xlat access_flags[] = {
486 { EFF_ONLY_OK, "EFF_ONLY_OK" },
495 decode_access(struct tcb *tcp, int offset)
498 printpath(tcp, tcp->u_arg[offset]);
500 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
506 sys_access(struct tcb *tcp)
508 return decode_access(tcp, 0);
513 sys_faccessat(struct tcb *tcp)
516 print_dirfd(tcp->u_arg[0]);
517 return decode_access(tcp, 1);
522 sys_umask(struct tcb *tcp)
525 tprintf("%#lo", tcp->u_arg[0]);
530 static const struct xlat whence[] = {
531 { SEEK_SET, "SEEK_SET" },
532 { SEEK_CUR, "SEEK_CUR" },
533 { SEEK_END, "SEEK_END" },
537 #ifndef HAVE_LONG_LONG_OFF_T
538 #if defined (LINUX_MIPSN32)
540 sys_lseek(struct tcb *tcp)
546 tprintf("%ld, ", tcp->u_arg[0]);
547 offset = tcp->ext_arg[1];
548 _whence = tcp->u_arg[2];
549 if (_whence == SEEK_SET)
550 tprintf("%llu, ", offset);
552 tprintf("%lld, ", offset);
553 printxval(whence, _whence, "SEEK_???");
555 return RVAL_UDECIMAL;
557 #else /* !LINUX_MIPSN32 */
559 sys_lseek(struct tcb *tcp)
565 tprintf("%ld, ", tcp->u_arg[0]);
566 offset = tcp->u_arg[1];
567 _whence = tcp->u_arg[2];
568 if (_whence == SEEK_SET)
569 tprintf("%lu, ", offset);
571 tprintf("%ld, ", offset);
572 printxval(whence, _whence, "SEEK_???");
574 return RVAL_UDECIMAL;
576 #endif /* LINUX_MIPSN32 */
581 sys_llseek(struct tcb *tcp)
585 * This one call takes explicitly two 32-bit arguments hi, lo,
586 * rather than one 64-bit argument for which LONG_LONG works
587 * appropriate for the native byte order.
589 if (tcp->u_arg[4] == SEEK_SET)
590 tprintf("%ld, %llu, ", tcp->u_arg[0],
591 (((long long int) tcp->u_arg[1]) << 32
592 | (unsigned long long) (unsigned) tcp->u_arg[2]));
594 tprintf("%ld, %lld, ", tcp->u_arg[0],
595 (((long long int) tcp->u_arg[1]) << 32
596 | (unsigned long long) (unsigned) tcp->u_arg[2]));
600 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
601 tprintf("%#lx, ", tcp->u_arg[3]);
603 tprintf("[%llu], ", off);
604 printxval(whence, tcp->u_arg[4], "SEEK_???");
610 sys_readahead(struct tcb *tcp)
614 tprintf("%ld, ", tcp->u_arg[0]);
615 argn = printllval(tcp, "%lld", 1);
616 tprintf(", %ld", tcp->u_arg[argn]);
622 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
624 sys_lseek64(struct tcb *tcp)
628 tprintf("%ld, ", tcp->u_arg[0]);
629 if (tcp->u_arg[3] == SEEK_SET)
630 argn = printllval(tcp, "%llu, ", 1);
632 argn = printllval(tcp, "%lld, ", 1);
633 printxval(whence, tcp->u_arg[argn], "SEEK_???");
635 return RVAL_LUDECIMAL;
639 #ifndef HAVE_LONG_LONG_OFF_T
641 sys_truncate(struct tcb *tcp)
644 printpath(tcp, tcp->u_arg[0]);
645 tprintf(", %lu", tcp->u_arg[1]);
651 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
653 sys_truncate64(struct tcb *tcp)
656 printpath(tcp, tcp->u_arg[0]);
657 printllval(tcp, ", %llu", 1);
663 #ifndef HAVE_LONG_LONG_OFF_T
665 sys_ftruncate(struct tcb *tcp)
668 tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
674 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
676 sys_ftruncate64(struct tcb *tcp)
679 tprintf("%ld, ", tcp->u_arg[0]);
680 printllval(tcp, "%llu", 1);
688 static const struct xlat modetypes[] = {
689 { S_IFREG, "S_IFREG" },
690 { S_IFSOCK, "S_IFSOCK" },
691 { S_IFIFO, "S_IFIFO" },
692 { S_IFLNK, "S_IFLNK" },
693 { S_IFDIR, "S_IFDIR" },
694 { S_IFBLK, "S_IFBLK" },
695 { S_IFCHR, "S_IFCHR" },
705 if ((mode & S_IFMT) == 0)
707 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
708 sprintf(buf, "%#o", mode);
711 sprintf(buf, "%s%s%s%s", s,
712 (mode & S_ISUID) ? "|S_ISUID" : "",
713 (mode & S_ISGID) ? "|S_ISGID" : "",
714 (mode & S_ISVTX) ? "|S_ISVTX" : "");
715 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
717 sprintf(buf + strlen(buf), "|%#o", mode);
718 s = (*buf == '|') ? buf + 1 : buf;
732 if ((tmp = localtime(&t)))
733 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
734 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
735 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
737 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
750 int st_pad1[3]; /* network id */
759 int st_pad3; /* st_size, off_t expansion */
760 timestruct_t st_atime;
761 timestruct_t st_mtime;
762 timestruct_t st_ctime;
766 int st_pad4[8]; /* expansion area */
770 printstatsol(struct tcb *tcp, long addr)
772 struct solstat statbuf;
774 if (umove(tcp, addr, &statbuf) < 0) {
779 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
780 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
781 (unsigned long) (statbuf.st_dev & 0x3ffff),
782 (unsigned long) statbuf.st_ino,
783 sprintmode(statbuf.st_mode));
784 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
785 (unsigned long) statbuf.st_nlink,
786 (unsigned long) statbuf.st_uid,
787 (unsigned long) statbuf.st_gid);
788 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
789 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
792 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
793 switch (statbuf.st_mode & S_IFMT) {
794 case S_IFCHR: case S_IFBLK:
795 tprintf("st_rdev=makedev(%lu, %lu), ",
796 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
797 (unsigned long) (statbuf.st_rdev & 0x3ffff));
800 tprintf("st_size=%u, ", statbuf.st_size);
804 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
805 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
806 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
812 #if defined (SPARC64)
814 printstat_sparc64(struct tcb *tcp, long addr)
816 struct stat_sparc64 statbuf;
818 if (umove(tcp, addr, &statbuf) < 0) {
824 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
825 (unsigned long) major(statbuf.st_dev),
826 (unsigned long) minor(statbuf.st_dev),
827 (unsigned long) statbuf.st_ino,
828 sprintmode(statbuf.st_mode));
829 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
830 (unsigned long) statbuf.st_nlink,
831 (unsigned long) statbuf.st_uid,
832 (unsigned long) statbuf.st_gid);
833 tprintf("st_blksize=%lu, ",
834 (unsigned long) statbuf.st_blksize);
835 tprintf("st_blocks=%lu, ",
836 (unsigned long) statbuf.st_blocks);
839 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
840 switch (statbuf.st_mode & S_IFMT) {
841 case S_IFCHR: case S_IFBLK:
842 tprintf("st_rdev=makedev(%lu, %lu), ",
843 (unsigned long) major(statbuf.st_rdev),
844 (unsigned long) minor(statbuf.st_rdev));
847 tprintf("st_size=%lu, ", statbuf.st_size);
851 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
852 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
853 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
860 #endif /* LINUXSPARC */
862 static const struct xlat fileflags[] = {
864 { UF_NODUMP, "UF_NODUMP" },
865 { UF_IMMUTABLE, "UF_IMMUTABLE" },
866 { UF_APPEND, "UF_APPEND" },
867 { UF_OPAQUE, "UF_OPAQUE" },
868 { UF_NOUNLINK, "UF_NOUNLINK" },
869 { SF_ARCHIVED, "SF_ARCHIVED" },
870 { SF_IMMUTABLE, "SF_IMMUTABLE" },
871 { SF_APPEND, "SF_APPEND" },
872 { SF_NOUNLINK, "SF_NOUNLINK" },
875 { _S_ISMLD, "_S_ISMLD" },
878 { _S_ISMOUNTED, "_S_ISMOUNTED" },
886 sys_chflags(struct tcb *tcp)
889 printpath(tcp, tcp->u_arg[0]);
891 printflags(fileflags, tcp->u_arg[1], "UF_???");
897 sys_fchflags(struct tcb *tcp)
900 tprintf("%ld, ", tcp->u_arg[0]);
901 printflags(fileflags, tcp->u_arg[1], "UF_???");
907 #ifndef HAVE_LONG_LONG_OFF_T
909 realprintstat(struct tcb *tcp, struct stat *statbuf)
912 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
913 (unsigned long) major(statbuf->st_dev),
914 (unsigned long) minor(statbuf->st_dev),
915 (unsigned long) statbuf->st_ino,
916 sprintmode(statbuf->st_mode));
917 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
918 (unsigned long) statbuf->st_nlink,
919 (unsigned long) statbuf->st_uid,
920 (unsigned long) statbuf->st_gid);
921 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
922 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
924 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
925 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
929 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
930 switch (statbuf->st_mode & S_IFMT) {
931 case S_IFCHR: case S_IFBLK:
932 #ifdef HAVE_STRUCT_STAT_ST_RDEV
933 tprintf("st_rdev=makedev(%lu, %lu), ",
934 (unsigned long) major(statbuf->st_rdev),
935 (unsigned long) minor(statbuf->st_rdev));
936 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
937 tprintf("st_size=makedev(%lu, %lu), ",
938 (unsigned long) major(statbuf->st_size),
939 (unsigned long) minor(statbuf->st_size));
940 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
943 tprintf("st_size=%lu, ", statbuf->st_size);
947 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
948 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
949 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
950 #if HAVE_STRUCT_STAT_ST_FLAGS
951 tprintf(", st_flags=");
952 printflags(fileflags, statbuf->st_flags, "UF_???");
954 #if HAVE_STRUCT_STAT_ST_ACLCNT
955 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
957 #if HAVE_STRUCT_STAT_ST_LEVEL
958 tprintf(", st_level=%ld", statbuf->st_level);
960 #if HAVE_STRUCT_STAT_ST_FSTYPE
961 tprintf(", st_fstype=%.*s",
962 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
964 #if HAVE_STRUCT_STAT_ST_GEN
965 tprintf(", st_gen=%u", statbuf->st_gen);
975 printstat(struct tcb *tcp, long addr)
983 if (syserror(tcp) || !verbose(tcp)) {
984 tprintf("%#lx", addr);
989 if (current_personality == 1) {
990 printstatsol(tcp, addr);
994 else if (current_personality == 2) {
995 printstat_sparc64(tcp, addr);
999 #endif /* LINUXSPARC */
1001 if (umove(tcp, addr, &statbuf) < 0) {
1006 realprintstat(tcp, &statbuf);
1008 #endif /* !HAVE_LONG_LONG_OFF_T */
1010 #if !defined HAVE_STAT64 && defined LINUX && defined X86_64
1012 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1013 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1014 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1015 * __GNUC__ is needed for the required __attribute__ below.
1018 unsigned long long st_dev;
1019 unsigned char __pad0[4];
1020 unsigned int __st_ino;
1021 unsigned int st_mode;
1022 unsigned int st_nlink;
1023 unsigned int st_uid;
1024 unsigned int st_gid;
1025 unsigned long long st_rdev;
1026 unsigned char __pad3[4];
1028 unsigned int st_blksize;
1029 unsigned long long st_blocks;
1030 unsigned int st_atime;
1031 unsigned int st_atime_nsec;
1032 unsigned int st_mtime;
1033 unsigned int st_mtime_nsec;
1034 unsigned int st_ctime;
1035 unsigned int st_ctime_nsec;
1036 unsigned long long st_ino;
1037 } __attribute__((packed));
1038 # define HAVE_STAT64 1
1039 # define STAT64_SIZE 96
1044 printstat64(struct tcb *tcp, long addr)
1046 struct stat64 statbuf;
1049 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1056 if (syserror(tcp) || !verbose(tcp)) {
1057 tprintf("%#lx", addr);
1062 if (current_personality == 1) {
1063 printstatsol(tcp, addr);
1067 else if (current_personality == 2) {
1068 printstat_sparc64(tcp, addr);
1072 #endif /* LINUXSPARC */
1074 #if defined LINUX && defined X86_64
1075 if (current_personality == 0) {
1076 printstat(tcp, addr);
1081 if (umove(tcp, addr, &statbuf) < 0) {
1087 #ifdef HAVE_LONG_LONG
1088 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1090 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
1092 (unsigned long) major(statbuf.st_dev),
1093 (unsigned long) minor(statbuf.st_dev),
1094 #ifdef HAVE_LONG_LONG
1095 (unsigned long long) statbuf.st_ino,
1097 (unsigned long) statbuf.st_ino,
1099 sprintmode(statbuf.st_mode));
1100 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1101 (unsigned long) statbuf.st_nlink,
1102 (unsigned long) statbuf.st_uid,
1103 (unsigned long) statbuf.st_gid);
1104 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1105 tprintf("st_blksize=%lu, ",
1106 (unsigned long) statbuf.st_blksize);
1107 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1108 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
1109 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1110 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
1113 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1114 switch (statbuf.st_mode & S_IFMT) {
1115 case S_IFCHR: case S_IFBLK:
1116 #ifdef HAVE_STRUCT_STAT_ST_RDEV
1117 tprintf("st_rdev=makedev(%lu, %lu), ",
1118 (unsigned long) major(statbuf.st_rdev),
1119 (unsigned long) minor(statbuf.st_rdev));
1120 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
1121 tprintf("st_size=makedev(%lu, %lu), ",
1122 (unsigned long) major(statbuf.st_size),
1123 (unsigned long) minor(statbuf.st_size));
1124 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
1127 #ifdef HAVE_LONG_LONG
1128 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1130 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1135 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1136 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1137 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1138 #if HAVE_STRUCT_STAT_ST_FLAGS
1139 tprintf(", st_flags=");
1140 printflags(fileflags, statbuf.st_flags, "UF_???");
1142 #if HAVE_STRUCT_STAT_ST_ACLCNT
1143 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1145 #if HAVE_STRUCT_STAT_ST_LEVEL
1146 tprintf(", st_level=%ld", statbuf.st_level);
1148 #if HAVE_STRUCT_STAT_ST_FSTYPE
1149 tprintf(", st_fstype=%.*s",
1150 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1152 #if HAVE_STRUCT_STAT_ST_GEN
1153 tprintf(", st_gen=%u", statbuf.st_gen);
1160 #endif /* HAVE_STAT64 */
1162 #if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1164 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
1166 newbuf->st_dev = oldbuf->st_dev;
1167 newbuf->st_ino = oldbuf->st_ino;
1168 newbuf->st_mode = oldbuf->st_mode;
1169 newbuf->st_nlink = oldbuf->st_nlink;
1170 newbuf->st_uid = oldbuf->st_uid;
1171 newbuf->st_gid = oldbuf->st_gid;
1172 newbuf->st_rdev = oldbuf->st_rdev;
1173 newbuf->st_size = oldbuf->st_size;
1174 newbuf->st_atime = oldbuf->st_atime;
1175 newbuf->st_mtime = oldbuf->st_mtime;
1176 newbuf->st_ctime = oldbuf->st_ctime;
1177 newbuf->st_blksize = 0; /* not supported in old_stat */
1178 newbuf->st_blocks = 0; /* not supported in old_stat */
1183 printoldstat(struct tcb *tcp, long addr)
1185 struct __old_kernel_stat statbuf;
1186 struct stat newstatbuf;
1192 if (syserror(tcp) || !verbose(tcp)) {
1193 tprintf("%#lx", addr);
1198 if (current_personality == 1) {
1199 printstatsol(tcp, addr);
1202 #endif /* LINUXSPARC */
1204 if (umove(tcp, addr, &statbuf) < 0) {
1209 convertoldstat(&statbuf, &newstatbuf);
1210 realprintstat(tcp, &newstatbuf);
1212 #endif /* LINUX && !IA64 && !HPPA && !X86_64 && !S390 && !S390X */
1214 #ifndef HAVE_LONG_LONG_OFF_T
1216 sys_stat(struct tcb *tcp)
1218 if (entering(tcp)) {
1219 printpath(tcp, tcp->u_arg[0]);
1222 printstat(tcp, tcp->u_arg[1]);
1229 sys_stat64(struct tcb *tcp)
1232 if (entering(tcp)) {
1233 printpath(tcp, tcp->u_arg[0]);
1236 printstat64(tcp, tcp->u_arg[1]);
1240 return printargs(tcp);
1245 static const struct xlat fstatatflags[] = {
1246 #ifndef AT_SYMLINK_NOFOLLOW
1247 # define AT_SYMLINK_NOFOLLOW 0x100
1249 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1252 #define utimensatflags fstatatflags
1255 sys_newfstatat(struct tcb *tcp)
1257 if (entering(tcp)) {
1258 print_dirfd(tcp->u_arg[0]);
1259 printpath(tcp, tcp->u_arg[1]);
1262 #if defined HAVE_STAT64 && !(defined POWERPC && defined __powerpc64__)
1263 printstat64(tcp, tcp->u_arg[2]);
1265 printstat(tcp, tcp->u_arg[2]);
1268 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1274 #if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1276 sys_oldstat(struct tcb *tcp)
1278 if (entering(tcp)) {
1279 printpath(tcp, tcp->u_arg[0]);
1282 printoldstat(tcp, tcp->u_arg[1]);
1286 #endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
1288 #ifndef HAVE_LONG_LONG_OFF_T
1290 sys_fstat(struct tcb *tcp)
1293 tprintf("%ld, ", tcp->u_arg[0]);
1295 printstat(tcp, tcp->u_arg[1]);
1302 sys_fstat64(struct tcb *tcp)
1306 tprintf("%ld, ", tcp->u_arg[0]);
1308 printstat64(tcp, tcp->u_arg[1]);
1312 return printargs(tcp);
1316 #if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1318 sys_oldfstat(struct tcb *tcp)
1321 tprintf("%ld, ", tcp->u_arg[0]);
1323 printoldstat(tcp, tcp->u_arg[1]);
1327 #endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
1329 #ifndef HAVE_LONG_LONG_OFF_T
1331 sys_lstat(struct tcb *tcp)
1333 if (entering(tcp)) {
1334 printpath(tcp, tcp->u_arg[0]);
1337 printstat(tcp, tcp->u_arg[1]);
1344 sys_lstat64(struct tcb *tcp)
1347 if (entering(tcp)) {
1348 printpath(tcp, tcp->u_arg[0]);
1351 printstat64(tcp, tcp->u_arg[1]);
1355 return printargs(tcp);
1359 #if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1361 sys_oldlstat(struct tcb *tcp)
1363 if (entering(tcp)) {
1364 printpath(tcp, tcp->u_arg[0]);
1367 printoldstat(tcp, tcp->u_arg[1]);
1371 #endif /* LINUX && HAVE_STRUCT___OLD_KERNEL_STAT */
1374 #if defined(SVR4) || defined(LINUXSPARC)
1377 sys_xstat(struct tcb *tcp)
1379 if (entering(tcp)) {
1380 tprintf("%ld, ", tcp->u_arg[0]);
1381 printpath(tcp, tcp->u_arg[1]);
1385 if (tcp->u_arg[0] == _STAT64_VER)
1386 printstat64 (tcp, tcp->u_arg[2]);
1389 printstat(tcp, tcp->u_arg[2]);
1395 sys_fxstat(struct tcb *tcp)
1398 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1401 if (tcp->u_arg[0] == _STAT64_VER)
1402 printstat64 (tcp, tcp->u_arg[2]);
1405 printstat(tcp, tcp->u_arg[2]);
1411 sys_lxstat(struct tcb *tcp)
1413 if (entering(tcp)) {
1414 tprintf("%ld, ", tcp->u_arg[0]);
1415 printpath(tcp, tcp->u_arg[1]);
1419 if (tcp->u_arg[0] == _STAT64_VER)
1420 printstat64 (tcp, tcp->u_arg[2]);
1423 printstat(tcp, tcp->u_arg[2]);
1429 sys_xmknod(struct tcb *tcp)
1431 int mode = tcp->u_arg[2];
1433 if (entering(tcp)) {
1434 tprintf("%ld, ", tcp->u_arg[0]);
1435 printpath(tcp, tcp->u_arg[1]);
1436 tprintf(", %s", sprintmode(mode));
1437 switch (mode & S_IFMT) {
1438 case S_IFCHR: case S_IFBLK:
1440 tprintf(", makedev(%lu, %lu)",
1441 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1442 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1444 tprintf(", makedev(%lu, %lu)",
1445 (unsigned long) major(tcp->u_arg[3]),
1446 (unsigned long) minor(tcp->u_arg[3]));
1456 #ifdef HAVE_SYS_ACL_H
1458 #include <sys/acl.h>
1460 static const struct xlat aclcmds[] = {
1462 { SETACL, "SETACL" },
1465 { GETACL, "GETACL" },
1468 { GETACLCNT, "GETACLCNT" },
1471 { ACL_GET, "ACL_GET" },
1474 { ACL_SET, "ACL_SET" },
1477 { ACL_CNT, "ACL_CNT" },
1483 sys_acl(struct tcb *tcp)
1485 if (entering(tcp)) {
1486 printpath(tcp, tcp->u_arg[0]);
1488 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1489 tprintf(", %ld", tcp->u_arg[2]);
1491 * FIXME - dump out the list of aclent_t's pointed to
1492 * by "tcp->u_arg[3]" if it's not NULL.
1495 tprintf(", %#lx", tcp->u_arg[3]);
1504 sys_facl(struct tcb *tcp)
1506 if (entering(tcp)) {
1507 tprintf("%ld, ", tcp->u_arg[0]);
1508 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1509 tprintf(", %ld", tcp->u_arg[2]);
1511 * FIXME - dump out the list of aclent_t's pointed to
1512 * by "tcp->u_arg[3]" if it's not NULL.
1515 tprintf(", %#lx", tcp->u_arg[3]);
1523 static const struct xlat aclipc[] = {
1525 { IPC_SHM, "IPC_SHM" },
1528 { IPC_SEM, "IPC_SEM" },
1531 { IPC_MSG, "IPC_MSG" },
1538 sys_aclipc(struct tcb *tcp)
1540 if (entering(tcp)) {
1541 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1542 tprintf(", %#lx, ", tcp->u_arg[1]);
1543 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1544 tprintf(", %ld", tcp->u_arg[3]);
1546 * FIXME - dump out the list of aclent_t's pointed to
1547 * by "tcp->u_arg[4]" if it's not NULL.
1550 tprintf(", %#lx", tcp->u_arg[4]);
1557 #endif /* HAVE_SYS_ACL_H */
1559 #endif /* SVR4 || LINUXSPARC */
1563 static const struct xlat fsmagic[] = {
1564 { 0x73757245, "CODA_SUPER_MAGIC" },
1565 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1566 { 0x1373, "DEVFS_SUPER_MAGIC" },
1567 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1568 { 0x414A53, "EFS_SUPER_MAGIC" },
1569 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1570 { 0xef53, "EXT2_SUPER_MAGIC" },
1571 { 0x137d, "EXT_SUPER_MAGIC" },
1572 { 0xf995e849, "HPFS_SUPER_MAGIC" },
1573 { 0x9660, "ISOFS_SUPER_MAGIC" },
1574 { 0x137f, "MINIX_SUPER_MAGIC" },
1575 { 0x138f, "MINIX_SUPER_MAGIC2" },
1576 { 0x2468, "MINIX2_SUPER_MAGIC" },
1577 { 0x2478, "MINIX2_SUPER_MAGIC2" },
1578 { 0x4d44, "MSDOS_SUPER_MAGIC" },
1579 { 0x564c, "NCP_SUPER_MAGIC" },
1580 { 0x6969, "NFS_SUPER_MAGIC" },
1581 { 0x9fa0, "PROC_SUPER_MAGIC" },
1582 { 0x002f, "QNX4_SUPER_MAGIC" },
1583 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1584 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1585 { 0x517b, "SMB_SUPER_MAGIC" },
1586 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1587 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1588 { 0x00011954, "UFS_MAGIC" },
1589 { 0x54190100, "UFS_CIGAM" },
1590 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
1591 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
1592 { 0x62656572, "SYSFS_MAGIC" },
1601 sprintfstype(int magic)
1603 static char buf[32];
1607 s = xlookup(fsmagic, magic);
1609 sprintf(buf, "\"%s\"", s);
1613 sprintf(buf, "%#x", magic);
1618 printstatfs(struct tcb *tcp, long addr)
1620 struct statfs statbuf;
1622 if (syserror(tcp) || !verbose(tcp)) {
1623 tprintf("%#lx", addr);
1626 if (umove(tcp, addr, &statbuf) < 0) {
1632 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1633 sprintfstype(statbuf.f_type),
1634 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1635 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1636 statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
1637 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1640 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1641 sprintfstype(statbuf.f_type),
1642 (unsigned long)statbuf.f_bsize,
1643 (unsigned long)statbuf.f_blocks,
1644 (unsigned long)statbuf.f_bfree);
1645 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1646 (unsigned long)statbuf.f_bavail,
1647 (unsigned long)statbuf.f_files,
1648 (unsigned long)statbuf.f_ffree,
1649 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1651 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1654 #ifdef _STATFS_F_FRSIZE
1655 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1661 sys_statfs(struct tcb *tcp)
1663 if (entering(tcp)) {
1664 printpath(tcp, tcp->u_arg[0]);
1667 printstatfs(tcp, tcp->u_arg[1]);
1673 sys_fstatfs(struct tcb *tcp)
1675 if (entering(tcp)) {
1676 tprintf("%lu, ", tcp->u_arg[0]);
1678 printstatfs(tcp, tcp->u_arg[1]);
1683 #if defined LINUX && defined HAVE_STATFS64
1685 printstatfs64(struct tcb *tcp, long addr)
1687 struct statfs64 statbuf;
1689 if (syserror(tcp) || !verbose(tcp)) {
1690 tprintf("%#lx", addr);
1693 if (umove(tcp, addr, &statbuf) < 0) {
1697 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
1698 sprintfstype(statbuf.f_type),
1699 (unsigned long long)statbuf.f_bsize,
1700 (unsigned long long)statbuf.f_blocks,
1701 (unsigned long long)statbuf.f_bfree);
1702 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1703 (unsigned long long)statbuf.f_bavail,
1704 (unsigned long long)statbuf.f_files,
1705 (unsigned long long)statbuf.f_ffree,
1706 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1707 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1708 #ifdef _STATFS_F_FRSIZE
1709 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
1715 sys_statfs64(struct tcb *tcp)
1717 if (entering(tcp)) {
1718 printpath(tcp, tcp->u_arg[0]);
1719 tprintf(", %lu, ", tcp->u_arg[1]);
1721 if (tcp->u_arg[1] == sizeof (struct statfs64))
1722 printstatfs64(tcp, tcp->u_arg[2]);
1730 sys_fstatfs64(struct tcb *tcp)
1732 if (entering(tcp)) {
1733 tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
1735 if (tcp->u_arg[1] == sizeof (struct statfs64))
1736 printstatfs64(tcp, tcp->u_arg[2]);
1744 #if defined(LINUX) && defined(__alpha)
1747 osf_statfs(struct tcb *tcp)
1749 if (entering(tcp)) {
1750 printpath(tcp, tcp->u_arg[0]);
1753 printstatfs(tcp, tcp->u_arg[1]);
1754 tprintf(", %lu", tcp->u_arg[2]);
1760 osf_fstatfs(struct tcb *tcp)
1762 if (entering(tcp)) {
1763 tprintf("%lu, ", tcp->u_arg[0]);
1765 printstatfs(tcp, tcp->u_arg[1]);
1766 tprintf(", %lu", tcp->u_arg[2]);
1770 #endif /* LINUX && __alpha */
1776 sys_ustat(struct tcb *tcp)
1778 struct ustat statbuf;
1780 if (entering(tcp)) {
1781 tprintf("makedev(%lu, %lu), ",
1782 (long) major(tcp->u_arg[0]),
1783 (long) minor(tcp->u_arg[0]));
1786 if (syserror(tcp) || !verbose(tcp))
1787 tprintf("%#lx", tcp->u_arg[1]);
1788 else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
1791 tprintf("{f_tfree=%lu, f_tinode=%lu, ",
1792 statbuf.f_tfree, statbuf.f_tinode);
1793 tprintf("f_fname=\"%.*s\", ",
1794 (int) sizeof(statbuf.f_fname),
1796 tprintf("f_fpack=\"%.*s\"}",
1797 (int) sizeof(statbuf.f_fpack),
1806 sys_pivotroot(struct tcb *tcp)
1808 if (entering(tcp)) {
1809 printpath(tcp, tcp->u_arg[0]);
1811 printpath(tcp, tcp->u_arg[1]);
1819 sys_chdir(struct tcb *tcp)
1821 if (entering(tcp)) {
1822 printpath(tcp, tcp->u_arg[0]);
1828 decode_mkdir(struct tcb *tcp, int offset)
1830 if (entering(tcp)) {
1831 printpath(tcp, tcp->u_arg[offset]);
1832 tprintf(", %#lo", tcp->u_arg[offset + 1]);
1838 sys_mkdir(struct tcb *tcp)
1840 return decode_mkdir(tcp, 0);
1845 sys_mkdirat(struct tcb *tcp)
1848 print_dirfd(tcp->u_arg[0]);
1849 return decode_mkdir(tcp, 1);
1854 sys_rmdir(struct tcb *tcp)
1856 if (entering(tcp)) {
1857 printpath(tcp, tcp->u_arg[0]);
1863 sys_fchdir(struct tcb *tcp)
1865 if (entering(tcp)) {
1866 tprintf("%ld", tcp->u_arg[0]);
1872 sys_chroot(struct tcb *tcp)
1874 if (entering(tcp)) {
1875 printpath(tcp, tcp->u_arg[0]);
1880 #if defined(SUNOS4) || defined(SVR4)
1882 sys_fchroot(struct tcb *tcp)
1884 if (entering(tcp)) {
1885 tprintf("%ld", tcp->u_arg[0]);
1889 #endif /* SUNOS4 || SVR4 */
1892 sys_link(struct tcb *tcp)
1894 if (entering(tcp)) {
1895 printpath(tcp, tcp->u_arg[0]);
1897 printpath(tcp, tcp->u_arg[1]);
1904 sys_linkat(struct tcb *tcp)
1906 if (entering(tcp)) {
1907 print_dirfd(tcp->u_arg[0]);
1908 printpath(tcp, tcp->u_arg[1]);
1910 print_dirfd(tcp->u_arg[2]);
1911 printpath(tcp, tcp->u_arg[3]);
1912 tprintf(", %ld", tcp->u_arg[4]);
1919 sys_unlink(struct tcb *tcp)
1921 if (entering(tcp)) {
1922 printpath(tcp, tcp->u_arg[0]);
1928 static const struct xlat unlinkatflags[] = {
1929 #ifndef AT_REMOVEDIR
1930 # define AT_REMOVEDIR 0x200
1932 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1937 sys_unlinkat(struct tcb *tcp)
1939 if (entering(tcp)) {
1940 print_dirfd(tcp->u_arg[0]);
1941 printpath(tcp, tcp->u_arg[1]);
1943 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1950 sys_symlink(struct tcb *tcp)
1952 if (entering(tcp)) {
1953 printpath(tcp, tcp->u_arg[0]);
1955 printpath(tcp, tcp->u_arg[1]);
1962 sys_symlinkat(struct tcb *tcp)
1964 if (entering(tcp)) {
1965 printpath(tcp, tcp->u_arg[0]);
1967 print_dirfd(tcp->u_arg[1]);
1968 printpath(tcp, tcp->u_arg[2]);
1975 decode_readlink(struct tcb *tcp, int offset)
1977 if (entering(tcp)) {
1978 printpath(tcp, tcp->u_arg[offset]);
1982 tprintf("%#lx", tcp->u_arg[offset + 1]);
1984 printpathn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1985 tprintf(", %lu", tcp->u_arg[offset + 2]);
1991 sys_readlink(struct tcb *tcp)
1993 return decode_readlink(tcp, 0);
1998 sys_readlinkat(struct tcb *tcp)
2001 print_dirfd(tcp->u_arg[0]);
2002 return decode_readlink(tcp, 1);
2007 sys_rename(struct tcb *tcp)
2009 if (entering(tcp)) {
2010 printpath(tcp, tcp->u_arg[0]);
2012 printpath(tcp, tcp->u_arg[1]);
2019 sys_renameat(struct tcb *tcp)
2021 if (entering(tcp)) {
2022 print_dirfd(tcp->u_arg[0]);
2023 printpath(tcp, tcp->u_arg[1]);
2025 print_dirfd(tcp->u_arg[2]);
2026 printpath(tcp, tcp->u_arg[3]);
2033 sys_chown(struct tcb *tcp)
2035 if (entering(tcp)) {
2036 printpath(tcp, tcp->u_arg[0]);
2037 printuid(", ", tcp->u_arg[1]);
2038 printuid(", ", tcp->u_arg[2]);
2045 sys_fchownat(struct tcb *tcp)
2047 if (entering(tcp)) {
2048 print_dirfd(tcp->u_arg[0]);
2049 printpath(tcp, tcp->u_arg[1]);
2050 printuid(", ", tcp->u_arg[2]);
2051 printuid(", ", tcp->u_arg[3]);
2053 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
2060 sys_fchown(struct tcb *tcp)
2062 if (entering(tcp)) {
2063 tprintf("%ld", tcp->u_arg[0]);
2064 printuid(", ", tcp->u_arg[1]);
2065 printuid(", ", tcp->u_arg[2]);
2071 decode_chmod(struct tcb *tcp, int offset)
2073 if (entering(tcp)) {
2074 printpath(tcp, tcp->u_arg[offset]);
2075 tprintf(", %#lo", tcp->u_arg[offset + 1]);
2081 sys_chmod(struct tcb *tcp)
2083 return decode_chmod(tcp, 0);
2088 sys_fchmodat(struct tcb *tcp)
2091 print_dirfd(tcp->u_arg[0]);
2092 return decode_chmod(tcp, 1);
2097 sys_fchmod(struct tcb *tcp)
2099 if (entering(tcp)) {
2100 tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
2107 sys_osf_utimes(struct tcb *tcp)
2109 if (entering(tcp)) {
2110 printpath(tcp, tcp->u_arg[0]);
2112 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2119 decode_utimes(struct tcb *tcp, int offset, int special)
2121 if (entering(tcp)) {
2122 printpath(tcp, tcp->u_arg[offset]);
2124 if (tcp->u_arg[offset + 1] == 0)
2128 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2129 BITNESS_CURRENT, special);
2131 printtv_bitness(tcp, tcp->u_arg[offset + 1]
2132 + sizeof (struct timeval),
2133 BITNESS_CURRENT, special);
2141 sys_utimes(struct tcb *tcp)
2143 return decode_utimes(tcp, 0, 0);
2148 sys_futimesat(struct tcb *tcp)
2151 print_dirfd(tcp->u_arg[0]);
2152 return decode_utimes(tcp, 1, 0);
2156 sys_utimensat(struct tcb *tcp)
2158 if (entering(tcp)) {
2159 print_dirfd(tcp->u_arg[0]);
2160 decode_utimes(tcp, 1, 1);
2162 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2169 sys_utime(struct tcb *tcp)
2176 if (entering(tcp)) {
2177 printpath(tcp, tcp->u_arg[0]);
2181 else if (!verbose(tcp))
2182 tprintf("%#lx", tcp->u_arg[1]);
2183 else if (umoven(tcp, tcp->u_arg[1],
2184 2 * personality_wordsize[current_personality],
2187 else if (personality_wordsize[current_personality]
2188 == sizeof u.utl[0]) {
2189 tprintf("[%s,", sprinttime(u.utl[0]));
2190 tprintf(" %s]", sprinttime(u.utl[1]));
2192 else if (personality_wordsize[current_personality]
2193 == sizeof u.uti[0]) {
2194 tprintf("[%s,", sprinttime(u.uti[0]));
2195 tprintf(" %s]", sprinttime(u.uti[1]));
2204 decode_mknod(struct tcb *tcp, int offset)
2206 int mode = tcp->u_arg[offset + 1];
2208 if (entering(tcp)) {
2209 printpath(tcp, tcp->u_arg[offset]);
2210 tprintf(", %s", sprintmode(mode));
2211 switch (mode & S_IFMT) {
2212 case S_IFCHR: case S_IFBLK:
2214 if (current_personality == 1)
2215 tprintf(", makedev(%lu, %lu)",
2216 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2217 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
2220 tprintf(", makedev(%lu, %lu)",
2221 (unsigned long) major(tcp->u_arg[offset + 2]),
2222 (unsigned long) minor(tcp->u_arg[offset + 2]));
2232 sys_mknod(struct tcb *tcp)
2234 return decode_mknod(tcp, 0);
2239 sys_mknodat(struct tcb *tcp)
2242 print_dirfd(tcp->u_arg[0]);
2243 return decode_mknod(tcp, 1);
2249 sys_mkfifo(struct tcb *tcp)
2251 if (entering(tcp)) {
2252 printpath(tcp, tcp->u_arg[0]);
2253 tprintf(", %#lo", tcp->u_arg[1]);
2257 #endif /* FREEBSD */
2260 sys_fsync(struct tcb *tcp)
2262 if (entering(tcp)) {
2263 tprintf("%ld", tcp->u_arg[0]);
2271 printdir(struct tcb *tcp, long addr)
2275 if (!verbose(tcp)) {
2276 tprintf("%#lx", addr);
2279 if (umove(tcp, addr, &d) < 0) {
2283 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
2285 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2290 sys_readdir(struct tcb *tcp)
2292 if (entering(tcp)) {
2293 tprintf("%lu, ", tcp->u_arg[0]);
2295 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2296 tprintf("%#lx", tcp->u_arg[1]);
2298 printdir(tcp, tcp->u_arg[1]);
2299 /* Not much point in printing this out, it is always 1. */
2300 if (tcp->u_arg[2] != 1)
2301 tprintf(", %lu", tcp->u_arg[2]);
2308 #if defined FREEBSD || defined LINUX
2309 static const struct xlat direnttypes[] = {
2310 { DT_UNKNOWN, "DT_UNKNOWN" },
2311 { DT_FIFO, "DT_FIFO" },
2312 { DT_CHR, "DT_CHR" },
2313 { DT_DIR, "DT_DIR" },
2314 { DT_BLK, "DT_BLK" },
2315 { DT_REG, "DT_REG" },
2316 { DT_LNK, "DT_LNK" },
2317 { DT_SOCK, "DT_SOCK" },
2318 { DT_WHT, "DT_WHT" },
2325 sys_getdents(struct tcb *tcp)
2327 int i, len, dents = 0;
2330 if (entering(tcp)) {
2331 tprintf("%lu, ", tcp->u_arg[0]);
2334 if (syserror(tcp) || !verbose(tcp)) {
2335 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2339 buf = len ? malloc(len) : NULL;
2341 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2342 fprintf(stderr, "out of memory\n");
2345 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2346 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2352 for (i = 0; i < len;) {
2353 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2356 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2357 i ? " " : "", d->d_ino, d->d_off);
2358 tprintf("d_reclen=%u, d_name=\"%s\"}",
2359 d->d_reclen, d->d_name);
2364 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2366 (unsigned long) d->d_ino,
2367 (unsigned long) d->d_off);
2368 tprintf("d_reclen=%u, d_name=\"%s\"}",
2369 d->d_reclen, d->d_name);
2374 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2375 i ? " " : "", d->d_off, d->d_fileno,
2377 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2378 d->d_namlen, d->d_namlen, d->d_name);
2383 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2384 i ? " " : "", d->d_fileno, d->d_reclen);
2385 printxval(direnttypes, d->d_type, "DT_???");
2386 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2387 d->d_namlen, d->d_namlen, d->d_name);
2389 #endif /* FREEBSD */
2391 tprintf("/* d_reclen == 0, problem here */");
2400 tprintf("/* %u entries */", dents);
2401 tprintf(", %lu", tcp->u_arg[2]);
2407 #if _LFS64_LARGEFILE
2409 sys_getdents64(struct tcb *tcp)
2411 int i, len, dents = 0;
2414 if (entering(tcp)) {
2415 tprintf("%lu, ", tcp->u_arg[0]);
2418 if (syserror(tcp) || !verbose(tcp)) {
2419 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2423 buf = len ? malloc(len) : NULL;
2425 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2426 fprintf(stderr, "out of memory\n");
2429 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2430 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2436 for (i = 0; i < len;) {
2437 struct dirent64 *d = (struct dirent64 *) &buf[i];
2438 #if defined(LINUX) || defined(SVR4)
2440 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
2446 printxval(direnttypes, d->d_type, "DT_???");
2449 tprintf("d_reclen=%u, d_name=\"%s\"}",
2450 d->d_reclen, d->d_name);
2452 #endif /* LINUX || SVR4 */
2455 tprintf("%s{d_off=%lu, d_fileno=%lu, d_reclen=%u, ",
2456 i ? " " : "", d->d_off, d->d_fileno,
2458 tprintf("d_namlen=%u, d_name=\"%.*s\"}",
2459 d->d_namlen, d->d_namlen, d->d_name);
2463 tprintf("/* d_reclen == 0, problem here */");
2472 tprintf("/* %u entries */", dents);
2473 tprintf(", %lu", tcp->u_arg[2]);
2481 sys_getdirentries(struct tcb *tcp)
2483 int i, len, dents = 0;
2487 if (entering(tcp)) {
2488 tprintf("%lu, ", tcp->u_arg[0]);
2491 if (syserror(tcp) || !verbose(tcp)) {
2492 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2496 if ((buf = malloc(len)) == NULL) {
2497 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2498 fprintf(stderr, "out of memory\n");
2501 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2502 tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
2508 for (i = 0; i < len;) {
2509 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2511 tprintf("%s{d_fileno=%u, d_reclen=%u, d_type=",
2512 i ? " " : "", d->d_fileno, d->d_reclen);
2513 printxval(direnttypes, d->d_type, "DT_???");
2514 tprintf(", d_namlen=%u, d_name=\"%.*s\"}",
2515 d->d_namlen, d->d_namlen, d->d_name);
2518 tprintf("/* d_reclen == 0, problem here */");
2527 tprintf("/* %u entries */", dents);
2529 tprintf(", %lu", tcp->u_arg[2]);
2530 if (umove(tcp, tcp->u_arg[3], &basep) < 0)
2531 tprintf(", %#lx", tcp->u_arg[3]);
2533 tprintf(", [%lu]", basep);
2540 sys_getcwd(struct tcb *tcp)
2544 tprintf("%#lx", tcp->u_arg[0]);
2546 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2547 tprintf(", %lu", tcp->u_arg[1]);
2555 sys___getcwd(struct tcb *tcp)
2559 tprintf("%#lx", tcp->u_arg[0]);
2561 printpathn(tcp, tcp->u_arg[0], tcp->u_arg[1]);
2562 tprintf(", %lu", tcp->u_arg[1]);
2568 #ifdef HAVE_SYS_ASYNCH_H
2571 sys_aioread(struct tcb *tcp)
2573 struct aio_result_t res;
2575 if (entering(tcp)) {
2576 tprintf("%lu, ", tcp->u_arg[0]);
2579 tprintf("%#lx", tcp->u_arg[1]);
2581 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2582 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2583 printxval(whence, tcp->u_arg[4], "L_???");
2584 if (syserror(tcp) || tcp->u_arg[5] == 0
2585 || umove(tcp, tcp->u_arg[5], &res) < 0)
2586 tprintf(", %#lx", tcp->u_arg[5]);
2588 tprintf(", {aio_return %d aio_errno %d}",
2589 res.aio_return, res.aio_errno);
2595 sys_aiowrite(struct tcb *tcp)
2597 struct aio_result_t res;
2599 if (entering(tcp)) {
2600 tprintf("%lu, ", tcp->u_arg[0]);
2601 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2602 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2603 printxval(whence, tcp->u_arg[4], "L_???");
2606 if (tcp->u_arg[5] == 0)
2608 else if (syserror(tcp)
2609 || umove(tcp, tcp->u_arg[5], &res) < 0)
2610 tprintf(", %#lx", tcp->u_arg[5]);
2612 tprintf(", {aio_return %d aio_errno %d}",
2613 res.aio_return, res.aio_errno);
2619 sys_aiowait(struct tcb *tcp)
2622 printtv(tcp, tcp->u_arg[0]);
2627 sys_aiocancel(struct tcb *tcp)
2629 struct aio_result_t res;
2632 if (tcp->u_arg[0] == 0)
2634 else if (syserror(tcp)
2635 || umove(tcp, tcp->u_arg[0], &res) < 0)
2636 tprintf("%#lx", tcp->u_arg[0]);
2638 tprintf("{aio_return %d aio_errno %d}",
2639 res.aio_return, res.aio_errno);
2644 #endif /* HAVE_SYS_ASYNCH_H */
2646 static const struct xlat xattrflags[] = {
2648 { XATTR_CREATE, "XATTR_CREATE" },
2649 { XATTR_REPLACE, "XATTR_REPLACE" },
2655 print_xattr_val(struct tcb *tcp, int failed,
2657 unsigned long insize,
2661 unsigned long capacity = 4 * size + 1;
2662 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2663 if (buf == NULL || /* probably a bogus size argument */
2664 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2668 unsigned char *out = buf;
2669 unsigned char *in = &buf[3 * size];
2671 for (i = 0; i < size; ++i) {
2675 #define tohex(n) "0123456789abcdef"[n]
2678 *out++ = tohex(in[i] / 16);
2679 *out++ = tohex(in[i] % 16);
2682 /* Don't print terminating NUL if there is one. */
2683 if (i > 0 && in[i - 1] == '\0')
2686 tprintf(", \"%s\", %ld", buf, insize);
2691 tprintf(", 0x%lx, %ld", arg, insize);
2695 sys_setxattr(struct tcb *tcp)
2697 if (entering(tcp)) {
2698 printpath(tcp, tcp->u_arg[0]);
2700 printstr(tcp, tcp->u_arg[1], -1);
2701 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2703 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2709 sys_fsetxattr(struct tcb *tcp)
2711 if (entering(tcp)) {
2712 tprintf("%ld, ", tcp->u_arg[0]);
2713 printstr(tcp, tcp->u_arg[1], -1);
2714 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2716 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2722 sys_getxattr(struct tcb *tcp)
2724 if (entering(tcp)) {
2725 printpath(tcp, tcp->u_arg[0]);
2727 printstr(tcp, tcp->u_arg[1], -1);
2729 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2736 sys_fgetxattr(struct tcb *tcp)
2738 if (entering(tcp)) {
2739 tprintf("%ld, ", tcp->u_arg[0]);
2740 printstr(tcp, tcp->u_arg[1], -1);
2742 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2749 sys_listxattr(struct tcb *tcp)
2751 if (entering(tcp)) {
2752 printpath(tcp, tcp->u_arg[0]);
2754 /* XXX Print value in format */
2755 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2761 sys_flistxattr(struct tcb *tcp)
2763 if (entering(tcp)) {
2764 tprintf("%ld", tcp->u_arg[0]);
2766 /* XXX Print value in format */
2767 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2773 sys_removexattr(struct tcb *tcp)
2775 if (entering(tcp)) {
2776 printpath(tcp, tcp->u_arg[0]);
2778 printstr(tcp, tcp->u_arg[1], -1);
2784 sys_fremovexattr(struct tcb *tcp)
2786 if (entering(tcp)) {
2787 tprintf("%ld, ", tcp->u_arg[0]);
2788 printstr(tcp, tcp->u_arg[1], -1);
2794 static const struct xlat advise[] = {
2795 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2796 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2797 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2798 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2799 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2800 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2807 sys_fadvise64(struct tcb *tcp)
2809 if (entering(tcp)) {
2811 tprintf("%ld, ", tcp->u_arg[0]);
2812 argn = printllval(tcp, "%lld", 1);
2813 tprintf(", %ld, ", tcp->u_arg[argn++]);
2814 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2822 sys_fadvise64_64(struct tcb *tcp)
2824 if (entering(tcp)) {
2826 tprintf("%ld, ", tcp->u_arg[0]);
2827 #if defined ARM || defined POWERPC
2828 argn = printllval(tcp, "%lld, ", 2);
2830 argn = printllval(tcp, "%lld, ", 1);
2832 argn = printllval(tcp, "%lld, ", argn);
2833 #if defined ARM || defined POWERPC
2834 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
2836 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2843 static const struct xlat inotify_modes[] = {
2844 { 0x00000001, "IN_ACCESS" },
2845 { 0x00000002, "IN_MODIFY" },
2846 { 0x00000004, "IN_ATTRIB" },
2847 { 0x00000008, "IN_CLOSE_WRITE" },
2848 { 0x00000010, "IN_CLOSE_NOWRITE" },
2849 { 0x00000020, "IN_OPEN" },
2850 { 0x00000040, "IN_MOVED_FROM" },
2851 { 0x00000080, "IN_MOVED_TO" },
2852 { 0x00000100, "IN_CREATE" },
2853 { 0x00000200, "IN_DELETE" },
2854 { 0x00000400, "IN_DELETE_SELF" },
2855 { 0x00000800, "IN_MOVE_SELF" },
2856 { 0x00002000, "IN_UNMOUNT" },
2857 { 0x00004000, "IN_Q_OVERFLOW" },
2858 { 0x00008000, "IN_IGNORED" },
2859 { 0x01000000, "IN_ONLYDIR" },
2860 { 0x02000000, "IN_DONT_FOLLOW" },
2861 { 0x20000000, "IN_MASK_ADD" },
2862 { 0x40000000, "IN_ISDIR" },
2863 { 0x80000000, "IN_ONESHOT" }
2867 sys_inotify_add_watch(struct tcb *tcp)
2869 if (entering(tcp)) {
2870 tprintf("%ld, ", tcp->u_arg[0]);
2871 printpath(tcp, tcp->u_arg[1]);
2873 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2879 sys_inotify_rm_watch(struct tcb *tcp)
2881 if (entering(tcp)) {
2882 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
2888 sys_inotify_init1(struct tcb *tcp)
2891 printflags(open_mode_flags, tcp->u_arg[0], "O_???");
2896 sys_fallocate(struct tcb *tcp)
2898 if (entering(tcp)) {
2900 tprintf("%ld, ", tcp->u_arg[0]); /* fd */
2901 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
2902 argn = printllval(tcp, "%llu, ", 2); /* offset */
2903 printllval(tcp, "%llu", argn); /* len */