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.
37 unsigned short st_dev;
39 unsigned short st_mode;
41 unsigned short st_uid;
42 unsigned short st_gid;
43 unsigned short st_rdev;
46 unsigned int __unused1;
48 unsigned int __unused2;
50 unsigned int __unused3;
53 unsigned int __unused4[2];
60 unsigned int st_nlink;
70 unsigned long __unused4[2];
73 # define stat kernel_stat
74 # include <asm/stat.h>
85 # define dev_t __kernel_dev_t
86 # define ino_t __kernel_ino_t
87 # define mode_t __kernel_mode_t
88 # define nlink_t __kernel_nlink_t
89 # define uid_t __kernel_uid_t
90 # define gid_t __kernel_gid_t
91 # define off_t __kernel_off_t
92 # define loff_t __kernel_loff_t
94 # include <asm/stat.h>
106 # define mode_t mode_t
107 # define nlink_t nlink_t
111 # define loff_t loff_t
114 #ifdef HPPA /* asm-parisc/stat.h defines stat64 */
117 #define stat libc_stat
118 #define stat64 libc_stat64
119 #include <sys/stat.h>
122 /* These might be macros. */
127 # define stat64 hpux_stat64
131 #ifdef HAVE_SYS_VFS_H
132 # include <sys/vfs.h>
134 #ifdef HAVE_LINUX_XATTR_H
135 # include <linux/xattr.h>
137 # define XATTR_CREATE 1
138 # define XATTR_REPLACE 2
141 #if HAVE_LONG_LONG_OFF_T
143 * Ugly hacks for systems that have typedef long long off_t
146 # define HAVE_STAT64 1 /* Ugly hack */
147 # define sys_stat64 sys_stat
148 # define sys_fstat64 sys_fstat
149 # define sys_lstat64 sys_lstat
150 # define sys_truncate64 sys_truncate
151 # define sys_ftruncate64 sys_ftruncate
154 #ifdef MAJOR_IN_SYSMACROS
155 # include <sys/sysmacros.h>
158 #ifdef MAJOR_IN_MKDEV
159 # include <sys/mkdev.h>
162 #ifdef HAVE_SYS_ASYNCH_H
163 # include <sys/asynch.h>
166 struct kernel_dirent {
169 unsigned short d_reclen;
173 const struct xlat open_access_modes[] = {
174 { O_RDONLY, "O_RDONLY" },
175 { O_WRONLY, "O_WRONLY" },
176 { O_RDWR, "O_RDWR" },
178 { O_ACCMODE, "O_ACCMODE" },
183 const struct xlat open_mode_flags[] = {
184 { O_CREAT, "O_CREAT" },
185 { O_EXCL, "O_EXCL" },
186 { O_NOCTTY, "O_NOCTTY" },
187 { O_TRUNC, "O_TRUNC" },
188 { O_APPEND, "O_APPEND" },
189 { O_NONBLOCK, "O_NONBLOCK" },
191 { O_SYNC, "O_SYNC" },
194 { O_ASYNC, "O_ASYNC" },
197 { O_DSYNC, "O_DSYNC" },
200 { O_RSYNC, "O_RSYNC" },
202 #if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
203 { O_NDELAY, "O_NDELAY" },
206 { O_PRIV, "O_PRIV" },
209 { O_DIRECT, "O_DIRECT" },
212 # if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
215 # define O_LARGEFILE 0x40000
216 # elif defined X86_64 || defined S390X
217 # define O_LARGEFILE 0100000
221 { O_LARGEFILE, "O_LARGEFILE" },
225 { O_DIRECTORY, "O_DIRECTORY" },
228 { O_NOFOLLOW, "O_NOFOLLOW" },
231 { O_NOATIME, "O_NOATIME" },
234 { O_CLOEXEC, "O_CLOEXEC" },
237 { FNDELAY, "FNDELAY" },
240 { FAPPEND, "FAPPEND" },
246 { FDEFER, "FDEFER" },
249 { FASYNC, "FASYNC" },
252 { FSHLOCK, "FSHLOCK" },
255 { FEXLOCK, "FEXLOCK" },
258 { FCREAT, "FCREAT" },
261 { FTRUNC, "FTRUNC" },
273 { FNOCTTY, "FNOCTTY" },
276 { O_SHLOCK, "O_SHLOCK" },
279 { O_EXLOCK, "O_EXLOCK" },
285 # define AT_FDCWD -100
288 /* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
289 * extension to get the right value. We do this by declaring fd as int here.
292 print_dirfd(struct tcb *tcp, int fd)
295 tprints("AT_FDCWD, ");
303 * low bits of the open(2) flags define access mode,
304 * other bits are real flags.
307 sprint_open_modes(mode_t flags)
309 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
313 const struct xlat *x;
316 p = stpcpy(outstr, "flags");
317 str = xlookup(open_access_modes, flags & 3);
327 for (x = open_mode_flags; x->str; x++) {
328 if ((flags & x->val) == x->val) {
330 p = stpcpy(p, x->str);
337 /* flags is still nonzero */
339 sprintf(p, "%#x", flags);
344 tprint_open_modes(mode_t flags)
346 tprints(sprint_open_modes(flags) + sizeof("flags"));
350 decode_open(struct tcb *tcp, int offset)
353 printpath(tcp, tcp->u_arg[offset]);
356 tprint_open_modes(tcp->u_arg[offset + 1]);
357 if (tcp->u_arg[offset + 1] & O_CREAT) {
359 tprintf(", %#lo", tcp->u_arg[offset + 2]);
366 sys_open(struct tcb *tcp)
368 return decode_open(tcp, 0);
372 sys_openat(struct tcb *tcp)
375 print_dirfd(tcp, tcp->u_arg[0]);
376 return decode_open(tcp, 1);
380 static const struct xlat openmodessol[] = {
384 { 0x80, "O_NONBLOCK" },
386 { 0x100, "O_CREAT" },
387 { 0x200, "O_TRUNC" },
389 { 0x800, "O_NOCTTY" },
392 { 0x8000, "O_RSYNC" },
394 { 0x1000, "O_PRIV" },
399 solaris_open(struct tcb *tcp)
402 printpath(tcp, tcp->u_arg[0]);
405 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
406 if (tcp->u_arg[1] & 0x100) {
408 tprintf(", %#lo", tcp->u_arg[2]);
417 sys_creat(struct tcb *tcp)
420 printpath(tcp, tcp->u_arg[0]);
421 tprintf(", %#lo", tcp->u_arg[1]);
426 static const struct xlat access_flags[] = {
432 { EFF_ONLY_OK, "EFF_ONLY_OK" },
441 decode_access(struct tcb *tcp, int offset)
444 printpath(tcp, tcp->u_arg[offset]);
446 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
452 sys_access(struct tcb *tcp)
454 return decode_access(tcp, 0);
458 sys_faccessat(struct tcb *tcp)
461 print_dirfd(tcp, tcp->u_arg[0]);
462 return decode_access(tcp, 1);
466 sys_umask(struct tcb *tcp)
469 tprintf("%#lo", tcp->u_arg[0]);
474 static const struct xlat whence[] = {
475 { SEEK_SET, "SEEK_SET" },
476 { SEEK_CUR, "SEEK_CUR" },
477 { SEEK_END, "SEEK_END" },
481 #if !defined(HAVE_LONG_LONG_OFF_T)
482 # if defined(LINUX_MIPSN32)
484 sys_lseek(struct tcb *tcp)
490 printfd(tcp, tcp->u_arg[0]);
492 offset = tcp->ext_arg[1];
493 _whence = tcp->u_arg[2];
494 if (_whence == SEEK_SET)
495 tprintf("%llu, ", offset);
497 tprintf("%lld, ", offset);
498 printxval(whence, _whence, "SEEK_???");
500 return RVAL_UDECIMAL;
502 # else /* !LINUX_MIPSN32 */
504 sys_lseek(struct tcb *tcp)
510 printfd(tcp, tcp->u_arg[0]);
512 offset = tcp->u_arg[1];
513 _whence = tcp->u_arg[2];
514 if (_whence == SEEK_SET)
515 tprintf("%lu, ", offset);
517 tprintf("%ld, ", offset);
518 printxval(whence, _whence, "SEEK_???");
520 return RVAL_UDECIMAL;
526 sys_llseek(struct tcb *tcp)
529 printfd(tcp, tcp->u_arg[0]);
531 * This one call takes explicitly two 32-bit arguments hi, lo,
532 * rather than one 64-bit argument for which LONG_LONG works
533 * appropriate for the native byte order.
535 if (tcp->u_arg[4] == SEEK_SET)
537 ((long long int) tcp->u_arg[1]) << 32 |
538 (unsigned long long) (unsigned) tcp->u_arg[2]);
541 ((long long int) tcp->u_arg[1]) << 32 |
542 (unsigned long long) (unsigned) tcp->u_arg[2]);
546 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
547 tprintf("%#lx, ", tcp->u_arg[3]);
549 tprintf("[%llu], ", off);
550 printxval(whence, tcp->u_arg[4], "SEEK_???");
556 sys_readahead(struct tcb *tcp)
560 printfd(tcp, tcp->u_arg[0]);
562 argn = printllval(tcp, "%lld", 1);
563 tprintf(", %ld", tcp->u_arg[argn]);
568 #ifndef HAVE_LONG_LONG_OFF_T
570 sys_truncate(struct tcb *tcp)
573 printpath(tcp, tcp->u_arg[0]);
574 tprintf(", %lu", tcp->u_arg[1]);
580 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
582 sys_truncate64(struct tcb *tcp)
585 printpath(tcp, tcp->u_arg[0]);
586 printllval(tcp, ", %llu", 1);
592 #ifndef HAVE_LONG_LONG_OFF_T
594 sys_ftruncate(struct tcb *tcp)
597 printfd(tcp, tcp->u_arg[0]);
598 tprintf(", %lu", tcp->u_arg[1]);
604 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
606 sys_ftruncate64(struct tcb *tcp)
609 printfd(tcp, tcp->u_arg[0]);
611 printllval(tcp, "%llu", 1);
619 static const struct xlat modetypes[] = {
620 { S_IFREG, "S_IFREG" },
621 { S_IFSOCK, "S_IFSOCK" },
622 { S_IFIFO, "S_IFIFO" },
623 { S_IFLNK, "S_IFLNK" },
624 { S_IFDIR, "S_IFDIR" },
625 { S_IFBLK, "S_IFBLK" },
626 { S_IFCHR, "S_IFCHR" },
633 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
638 if ((mode & S_IFMT) == 0)
640 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
641 sprintf(buf, "%#o", mode);
644 s = buf + sprintf(buf, "%s%s%s%s", s,
645 (mode & S_ISUID) ? "|S_ISUID" : "",
646 (mode & S_ISGID) ? "|S_ISGID" : "",
647 (mode & S_ISVTX) ? "|S_ISVTX" : "");
648 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
650 sprintf((char*)s, "|%#o", mode);
651 s = (*buf == '|') ? buf + 1 : buf;
659 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
667 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
668 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
669 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
671 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
684 int st_pad1[3]; /* network id */
693 int st_pad3; /* st_size, off_t expansion */
694 timestruct_t st_atime;
695 timestruct_t st_mtime;
696 timestruct_t st_ctime;
700 int st_pad4[8]; /* expansion area */
704 printstatsol(struct tcb *tcp, long addr)
706 struct solstat statbuf;
708 if (umove(tcp, addr, &statbuf) < 0) {
713 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
714 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
715 (unsigned long) (statbuf.st_dev & 0x3ffff),
716 (unsigned long) statbuf.st_ino,
717 sprintmode(statbuf.st_mode));
718 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
719 (unsigned long) statbuf.st_nlink,
720 (unsigned long) statbuf.st_uid,
721 (unsigned long) statbuf.st_gid);
722 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
723 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
726 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
727 switch (statbuf.st_mode & S_IFMT) {
728 case S_IFCHR: case S_IFBLK:
729 tprintf("st_rdev=makedev(%lu, %lu), ",
730 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
731 (unsigned long) (statbuf.st_rdev & 0x3ffff));
734 tprintf("st_size=%u, ", statbuf.st_size);
738 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
739 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
740 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
748 printstat_sparc64(struct tcb *tcp, long addr)
750 struct stat_sparc64 statbuf;
752 if (umove(tcp, addr, &statbuf) < 0) {
758 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
759 (unsigned long) major(statbuf.st_dev),
760 (unsigned long) minor(statbuf.st_dev),
761 (unsigned long) statbuf.st_ino,
762 sprintmode(statbuf.st_mode));
763 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
764 (unsigned long) statbuf.st_nlink,
765 (unsigned long) statbuf.st_uid,
766 (unsigned long) statbuf.st_gid);
767 tprintf("st_blksize=%lu, ",
768 (unsigned long) statbuf.st_blksize);
769 tprintf("st_blocks=%lu, ",
770 (unsigned long) statbuf.st_blocks);
773 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
774 switch (statbuf.st_mode & S_IFMT) {
775 case S_IFCHR: case S_IFBLK:
776 tprintf("st_rdev=makedev(%lu, %lu), ",
777 (unsigned long) major(statbuf.st_rdev),
778 (unsigned long) minor(statbuf.st_rdev));
781 tprintf("st_size=%lu, ", statbuf.st_size);
785 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
786 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
787 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
793 #endif /* LINUXSPARC */
795 #if defined POWERPC64
796 struct stat_powerpc32 {
799 unsigned int st_mode;
800 unsigned short st_nlink;
803 unsigned int st_rdev;
804 unsigned int st_size;
805 unsigned int st_blksize;
806 unsigned int st_blocks;
807 unsigned int st_atime;
808 unsigned int st_atime_nsec;
809 unsigned int st_mtime;
810 unsigned int st_mtime_nsec;
811 unsigned int st_ctime;
812 unsigned int st_ctime_nsec;
813 unsigned int __unused4;
814 unsigned int __unused5;
818 printstat_powerpc32(struct tcb *tcp, long addr)
820 struct stat_powerpc32 statbuf;
822 if (umove(tcp, addr, &statbuf) < 0) {
828 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
829 major(statbuf.st_dev), minor(statbuf.st_dev),
831 sprintmode(statbuf.st_mode));
832 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
833 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
834 tprintf("st_blksize=%u, ", statbuf.st_blksize);
835 tprintf("st_blocks=%u, ", statbuf.st_blocks);
838 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
839 switch (statbuf.st_mode & S_IFMT) {
840 case S_IFCHR: case S_IFBLK:
841 tprintf("st_rdev=makedev(%lu, %lu), ",
842 (unsigned long) major(statbuf.st_rdev),
843 (unsigned long) minor(statbuf.st_rdev));
846 tprintf("st_size=%u, ", statbuf.st_size);
850 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
851 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
852 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
857 #endif /* POWERPC64 */
859 static const struct xlat fileflags[] = {
863 #ifndef HAVE_LONG_LONG_OFF_T
865 realprintstat(struct tcb *tcp, struct stat *statbuf)
868 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
869 (unsigned long) major(statbuf->st_dev),
870 (unsigned long) minor(statbuf->st_dev),
871 (unsigned long) statbuf->st_ino,
872 sprintmode(statbuf->st_mode));
873 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
874 (unsigned long) statbuf->st_nlink,
875 (unsigned long) statbuf->st_uid,
876 (unsigned long) statbuf->st_gid);
877 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
878 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
880 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
881 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
885 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
886 switch (statbuf->st_mode & S_IFMT) {
887 case S_IFCHR: case S_IFBLK:
888 #ifdef HAVE_STRUCT_STAT_ST_RDEV
889 tprintf("st_rdev=makedev(%lu, %lu), ",
890 (unsigned long) major(statbuf->st_rdev),
891 (unsigned long) minor(statbuf->st_rdev));
892 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
893 tprintf("st_size=makedev(%lu, %lu), ",
894 (unsigned long) major(statbuf->st_size),
895 (unsigned long) minor(statbuf->st_size));
896 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
899 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
903 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
904 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
905 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
906 #if HAVE_STRUCT_STAT_ST_FLAGS
907 tprints(", st_flags=");
908 printflags(fileflags, statbuf->st_flags, "UF_???");
910 #if HAVE_STRUCT_STAT_ST_ACLCNT
911 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
913 #if HAVE_STRUCT_STAT_ST_LEVEL
914 tprintf(", st_level=%ld", statbuf->st_level);
916 #if HAVE_STRUCT_STAT_ST_FSTYPE
917 tprintf(", st_fstype=%.*s",
918 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
920 #if HAVE_STRUCT_STAT_ST_GEN
921 tprintf(", st_gen=%u", statbuf->st_gen);
930 printstat(struct tcb *tcp, long addr)
938 if (syserror(tcp) || !verbose(tcp)) {
939 tprintf("%#lx", addr);
944 if (current_personality == 1) {
945 printstatsol(tcp, addr);
949 else if (current_personality == 2) {
950 printstat_sparc64(tcp, addr);
954 #endif /* LINUXSPARC */
956 #if defined POWERPC64
957 if (current_personality == 1) {
958 printstat_powerpc32(tcp, addr);
963 if (umove(tcp, addr, &statbuf) < 0) {
968 realprintstat(tcp, &statbuf);
970 #endif /* !HAVE_LONG_LONG_OFF_T */
972 #if !defined HAVE_STAT64 && defined X86_64
974 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
975 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
976 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
977 * __GNUC__ is needed for the required __attribute__ below.
980 unsigned long long st_dev;
981 unsigned char __pad0[4];
982 unsigned int __st_ino;
983 unsigned int st_mode;
984 unsigned int st_nlink;
987 unsigned long long st_rdev;
988 unsigned char __pad3[4];
990 unsigned int st_blksize;
991 unsigned long long st_blocks;
992 unsigned int st_atime;
993 unsigned int st_atime_nsec;
994 unsigned int st_mtime;
995 unsigned int st_mtime_nsec;
996 unsigned int st_ctime;
997 unsigned int st_ctime_nsec;
998 unsigned long long st_ino;
999 } __attribute__((packed));
1000 # define HAVE_STAT64 1
1001 # define STAT64_SIZE 96
1006 printstat64(struct tcb *tcp, long addr)
1008 struct stat64 statbuf;
1011 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1018 if (syserror(tcp) || !verbose(tcp)) {
1019 tprintf("%#lx", addr);
1024 if (current_personality == 1) {
1025 printstatsol(tcp, addr);
1029 else if (current_personality == 2) {
1030 printstat_sparc64(tcp, addr);
1034 #endif /* LINUXSPARC */
1037 if (current_personality == 0) {
1038 printstat(tcp, addr);
1043 if (umove(tcp, addr, &statbuf) < 0) {
1049 #ifdef HAVE_LONG_LONG
1050 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1052 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
1054 (unsigned long) major(statbuf.st_dev),
1055 (unsigned long) minor(statbuf.st_dev),
1056 #ifdef HAVE_LONG_LONG
1057 (unsigned long long) statbuf.st_ino,
1059 (unsigned long) statbuf.st_ino,
1061 sprintmode(statbuf.st_mode));
1062 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1063 (unsigned long) statbuf.st_nlink,
1064 (unsigned long) statbuf.st_uid,
1065 (unsigned long) statbuf.st_gid);
1066 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1067 tprintf("st_blksize=%lu, ",
1068 (unsigned long) statbuf.st_blksize);
1069 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1070 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
1071 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1072 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
1075 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1076 switch (statbuf.st_mode & S_IFMT) {
1077 case S_IFCHR: case S_IFBLK:
1078 #ifdef HAVE_STRUCT_STAT_ST_RDEV
1079 tprintf("st_rdev=makedev(%lu, %lu), ",
1080 (unsigned long) major(statbuf.st_rdev),
1081 (unsigned long) minor(statbuf.st_rdev));
1082 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
1083 tprintf("st_size=makedev(%lu, %lu), ",
1084 (unsigned long) major(statbuf.st_size),
1085 (unsigned long) minor(statbuf.st_size));
1086 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
1089 #ifdef HAVE_LONG_LONG
1090 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1092 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1097 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1098 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1099 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1100 #if HAVE_STRUCT_STAT_ST_FLAGS
1101 tprints(", st_flags=");
1102 printflags(fileflags, statbuf.st_flags, "UF_???");
1104 #if HAVE_STRUCT_STAT_ST_ACLCNT
1105 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1107 #if HAVE_STRUCT_STAT_ST_LEVEL
1108 tprintf(", st_level=%ld", statbuf.st_level);
1110 #if HAVE_STRUCT_STAT_ST_FSTYPE
1111 tprintf(", st_fstype=%.*s",
1112 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1114 #if HAVE_STRUCT_STAT_ST_GEN
1115 tprintf(", st_gen=%u", statbuf.st_gen);
1122 #endif /* HAVE_STAT64 */
1124 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1126 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
1128 newbuf->st_dev = oldbuf->st_dev;
1129 newbuf->st_ino = oldbuf->st_ino;
1130 newbuf->st_mode = oldbuf->st_mode;
1131 newbuf->st_nlink = oldbuf->st_nlink;
1132 newbuf->st_uid = oldbuf->st_uid;
1133 newbuf->st_gid = oldbuf->st_gid;
1134 newbuf->st_rdev = oldbuf->st_rdev;
1135 newbuf->st_size = oldbuf->st_size;
1136 newbuf->st_atime = oldbuf->st_atime;
1137 newbuf->st_mtime = oldbuf->st_mtime;
1138 newbuf->st_ctime = oldbuf->st_ctime;
1139 newbuf->st_blksize = 0; /* not supported in old_stat */
1140 newbuf->st_blocks = 0; /* not supported in old_stat */
1144 printoldstat(struct tcb *tcp, long addr)
1146 struct __old_kernel_stat statbuf;
1147 struct stat newstatbuf;
1153 if (syserror(tcp) || !verbose(tcp)) {
1154 tprintf("%#lx", addr);
1159 if (current_personality == 1) {
1160 printstatsol(tcp, addr);
1165 if (umove(tcp, addr, &statbuf) < 0) {
1170 convertoldstat(&statbuf, &newstatbuf);
1171 realprintstat(tcp, &newstatbuf);
1175 #ifndef HAVE_LONG_LONG_OFF_T
1177 sys_stat(struct tcb *tcp)
1179 if (entering(tcp)) {
1180 printpath(tcp, tcp->u_arg[0]);
1183 printstat(tcp, tcp->u_arg[1]);
1190 sys_stat64(struct tcb *tcp)
1193 if (entering(tcp)) {
1194 printpath(tcp, tcp->u_arg[0]);
1197 printstat64(tcp, tcp->u_arg[1]);
1201 return printargs(tcp);
1205 #ifndef AT_SYMLINK_NOFOLLOW
1206 # define AT_SYMLINK_NOFOLLOW 0x100
1208 #ifndef AT_REMOVEDIR
1209 # define AT_REMOVEDIR 0x200
1211 #ifndef AT_SYMLINK_FOLLOW
1212 # define AT_SYMLINK_FOLLOW 0x400
1214 #ifndef AT_NO_AUTOMOUNT
1215 # define AT_NO_AUTOMOUNT 0x800
1217 #ifndef AT_EMPTY_PATH
1218 # define AT_EMPTY_PATH 0x1000
1221 static const struct xlat at_flags[] = {
1222 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1223 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1224 { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" },
1225 { AT_NO_AUTOMOUNT, "AT_NO_AUTOMOUNT" },
1226 { AT_EMPTY_PATH, "AT_EMPTY_PATH" },
1231 sys_newfstatat(struct tcb *tcp)
1233 if (entering(tcp)) {
1234 print_dirfd(tcp, tcp->u_arg[0]);
1235 printpath(tcp, tcp->u_arg[1]);
1239 if (current_personality == 0)
1240 printstat(tcp, tcp->u_arg[2]);
1242 printstat64(tcp, tcp->u_arg[2]);
1243 #elif defined HAVE_STAT64
1244 printstat64(tcp, tcp->u_arg[2]);
1246 printstat(tcp, tcp->u_arg[2]);
1249 printflags(at_flags, tcp->u_arg[3], "AT_???");
1254 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1256 sys_oldstat(struct tcb *tcp)
1258 if (entering(tcp)) {
1259 printpath(tcp, tcp->u_arg[0]);
1262 printoldstat(tcp, tcp->u_arg[1]);
1268 #ifndef HAVE_LONG_LONG_OFF_T
1270 sys_fstat(struct tcb *tcp)
1272 if (entering(tcp)) {
1273 printfd(tcp, tcp->u_arg[0]);
1276 printstat(tcp, tcp->u_arg[1]);
1283 sys_fstat64(struct tcb *tcp)
1286 if (entering(tcp)) {
1287 printfd(tcp, tcp->u_arg[0]);
1290 printstat64(tcp, tcp->u_arg[1]);
1294 return printargs(tcp);
1298 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1300 sys_oldfstat(struct tcb *tcp)
1302 if (entering(tcp)) {
1303 printfd(tcp, tcp->u_arg[0]);
1306 printoldstat(tcp, tcp->u_arg[1]);
1312 #ifndef HAVE_LONG_LONG_OFF_T
1314 sys_lstat(struct tcb *tcp)
1316 if (entering(tcp)) {
1317 printpath(tcp, tcp->u_arg[0]);
1320 printstat(tcp, tcp->u_arg[1]);
1327 sys_lstat64(struct tcb *tcp)
1330 if (entering(tcp)) {
1331 printpath(tcp, tcp->u_arg[0]);
1334 printstat64(tcp, tcp->u_arg[1]);
1338 return printargs(tcp);
1342 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1344 sys_oldlstat(struct tcb *tcp)
1346 if (entering(tcp)) {
1347 printpath(tcp, tcp->u_arg[0]);
1350 printoldstat(tcp, tcp->u_arg[1]);
1356 #if defined(LINUXSPARC)
1359 sys_xstat(struct tcb *tcp)
1361 if (entering(tcp)) {
1362 tprintf("%ld, ", tcp->u_arg[0]);
1363 printpath(tcp, tcp->u_arg[1]);
1367 if (tcp->u_arg[0] == _STAT64_VER)
1368 printstat64(tcp, tcp->u_arg[2]);
1371 printstat(tcp, tcp->u_arg[2]);
1377 sys_fxstat(struct tcb *tcp)
1380 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1383 if (tcp->u_arg[0] == _STAT64_VER)
1384 printstat64(tcp, tcp->u_arg[2]);
1387 printstat(tcp, tcp->u_arg[2]);
1393 sys_lxstat(struct tcb *tcp)
1395 if (entering(tcp)) {
1396 tprintf("%ld, ", tcp->u_arg[0]);
1397 printpath(tcp, 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_xmknod(struct tcb *tcp)
1413 int mode = tcp->u_arg[2];
1415 if (entering(tcp)) {
1416 tprintf("%ld, ", tcp->u_arg[0]);
1417 printpath(tcp, tcp->u_arg[1]);
1418 tprintf(", %s", sprintmode(mode));
1419 switch (mode & S_IFMT) {
1420 case S_IFCHR: case S_IFBLK:
1421 tprintf(", makedev(%lu, %lu)",
1422 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1423 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1432 # ifdef HAVE_SYS_ACL_H
1434 # include <sys/acl.h>
1436 static const struct xlat aclcmds[] = {
1438 { SETACL, "SETACL" },
1441 { GETACL, "GETACL" },
1444 { GETACLCNT, "GETACLCNT" },
1447 { ACL_GET, "ACL_GET" },
1450 { ACL_SET, "ACL_SET" },
1453 { ACL_CNT, "ACL_CNT" },
1459 sys_acl(struct tcb *tcp)
1461 if (entering(tcp)) {
1462 printpath(tcp, tcp->u_arg[0]);
1464 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1465 tprintf(", %ld", tcp->u_arg[2]);
1467 * FIXME - dump out the list of aclent_t's pointed to
1468 * by "tcp->u_arg[3]" if it's not NULL.
1471 tprintf(", %#lx", tcp->u_arg[3]);
1479 sys_facl(struct tcb *tcp)
1481 if (entering(tcp)) {
1482 tprintf("%ld, ", tcp->u_arg[0]);
1483 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1484 tprintf(", %ld", tcp->u_arg[2]);
1486 * FIXME - dump out the list of aclent_t's pointed to
1487 * by "tcp->u_arg[3]" if it's not NULL.
1490 tprintf(", %#lx", tcp->u_arg[3]);
1497 static const struct xlat aclipc[] = {
1499 { IPC_SHM, "IPC_SHM" },
1502 { IPC_SEM, "IPC_SEM" },
1505 { IPC_MSG, "IPC_MSG" },
1511 sys_aclipc(struct tcb *tcp)
1513 if (entering(tcp)) {
1514 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1515 tprintf(", %#lx, ", tcp->u_arg[1]);
1516 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1517 tprintf(", %ld", tcp->u_arg[3]);
1519 * FIXME - dump out the list of aclent_t's pointed to
1520 * by "tcp->u_arg[4]" if it's not NULL.
1523 tprintf(", %#lx", tcp->u_arg[4]);
1530 # endif /* HAVE_SYS_ACL_H */
1532 #endif /* LINUXSPARC */
1534 static const struct xlat fsmagic[] = {
1535 { 0x73757245, "CODA_SUPER_MAGIC" },
1536 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1537 { 0x1373, "DEVFS_SUPER_MAGIC" },
1538 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1539 { 0x414A53, "EFS_SUPER_MAGIC" },
1540 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1541 { 0xef53, "EXT2_SUPER_MAGIC" },
1542 { 0x137d, "EXT_SUPER_MAGIC" },
1543 { 0xf995e849, "HPFS_SUPER_MAGIC" },
1544 { 0x9660, "ISOFS_SUPER_MAGIC" },
1545 { 0x137f, "MINIX_SUPER_MAGIC" },
1546 { 0x138f, "MINIX_SUPER_MAGIC2" },
1547 { 0x2468, "MINIX2_SUPER_MAGIC" },
1548 { 0x2478, "MINIX2_SUPER_MAGIC2" },
1549 { 0x4d44, "MSDOS_SUPER_MAGIC" },
1550 { 0x564c, "NCP_SUPER_MAGIC" },
1551 { 0x6969, "NFS_SUPER_MAGIC" },
1552 { 0x9fa0, "PROC_SUPER_MAGIC" },
1553 { 0x002f, "QNX4_SUPER_MAGIC" },
1554 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1555 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1556 { 0x517b, "SMB_SUPER_MAGIC" },
1557 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1558 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1559 { 0x00011954, "UFS_MAGIC" },
1560 { 0x54190100, "UFS_CIGAM" },
1561 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
1562 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
1563 { 0x62656572, "SYSFS_MAGIC" },
1568 sprintfstype(int magic)
1570 static char buf[32];
1573 s = xlookup(fsmagic, magic);
1575 sprintf(buf, "\"%s\"", s);
1578 sprintf(buf, "%#x", magic);
1583 printstatfs(struct tcb *tcp, long addr)
1585 struct statfs statbuf;
1587 if (syserror(tcp) || !verbose(tcp)) {
1588 tprintf("%#lx", addr);
1591 if (umove(tcp, addr, &statbuf) < 0) {
1597 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1598 sprintfstype(statbuf.f_type),
1599 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1600 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1601 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
1602 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1605 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1606 sprintfstype(statbuf.f_type),
1607 (unsigned long)statbuf.f_bsize,
1608 (unsigned long)statbuf.f_blocks,
1609 (unsigned long)statbuf.f_bfree);
1610 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1611 (unsigned long)statbuf.f_bavail,
1612 (unsigned long)statbuf.f_files,
1613 (unsigned long)statbuf.f_ffree,
1614 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1615 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1617 #ifdef _STATFS_F_FRSIZE
1618 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1624 sys_statfs(struct tcb *tcp)
1626 if (entering(tcp)) {
1627 printpath(tcp, tcp->u_arg[0]);
1630 printstatfs(tcp, tcp->u_arg[1]);
1636 sys_fstatfs(struct tcb *tcp)
1638 if (entering(tcp)) {
1639 printfd(tcp, tcp->u_arg[0]);
1642 printstatfs(tcp, tcp->u_arg[1]);
1647 #if defined HAVE_STATFS64
1649 printstatfs64(struct tcb *tcp, long addr)
1651 struct statfs64 statbuf;
1653 if (syserror(tcp) || !verbose(tcp)) {
1654 tprintf("%#lx", addr);
1657 if (umove(tcp, addr, &statbuf) < 0) {
1661 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
1662 sprintfstype(statbuf.f_type),
1663 (unsigned long long)statbuf.f_bsize,
1664 (unsigned long long)statbuf.f_blocks,
1665 (unsigned long long)statbuf.f_bfree);
1666 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1667 (unsigned long long)statbuf.f_bavail,
1668 (unsigned long long)statbuf.f_files,
1669 (unsigned long long)statbuf.f_ffree,
1670 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1671 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1672 #ifdef _STATFS_F_FRSIZE
1673 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
1675 #ifdef _STATFS_F_FLAGS
1676 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1681 struct compat_statfs64 {
1693 uint32_t f_spare[4];
1695 #if defined(X86_64) || defined(IA64)
1696 __attribute__ ((packed, aligned(4)))
1701 printcompat_statfs64(struct tcb *tcp, long addr)
1703 struct compat_statfs64 statbuf;
1705 if (syserror(tcp) || !verbose(tcp)) {
1706 tprintf("%#lx", addr);
1709 if (umove(tcp, addr, &statbuf) < 0) {
1713 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1714 sprintfstype(statbuf.f_type),
1715 (unsigned long)statbuf.f_bsize,
1716 (unsigned long long)statbuf.f_blocks,
1717 (unsigned long long)statbuf.f_bfree);
1718 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1719 (unsigned long long)statbuf.f_bavail,
1720 (unsigned long long)statbuf.f_files,
1721 (unsigned long long)statbuf.f_ffree,
1722 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1723 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1724 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1725 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
1729 sys_statfs64(struct tcb *tcp)
1731 if (entering(tcp)) {
1732 printpath(tcp, tcp->u_arg[0]);
1733 tprintf(", %lu, ", tcp->u_arg[1]);
1735 if (tcp->u_arg[1] == sizeof(struct statfs64))
1736 printstatfs64(tcp, tcp->u_arg[2]);
1737 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1738 printcompat_statfs64(tcp, tcp->u_arg[2]);
1746 sys_fstatfs64(struct tcb *tcp)
1748 if (entering(tcp)) {
1749 printfd(tcp, tcp->u_arg[0]);
1750 tprintf(", %lu, ", tcp->u_arg[1]);
1752 if (tcp->u_arg[1] == sizeof(struct statfs64))
1753 printstatfs64(tcp, tcp->u_arg[2]);
1754 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1755 printcompat_statfs64(tcp, tcp->u_arg[2]);
1765 osf_statfs(struct tcb *tcp)
1767 if (entering(tcp)) {
1768 printpath(tcp, tcp->u_arg[0]);
1771 printstatfs(tcp, tcp->u_arg[1]);
1772 tprintf(", %lu", tcp->u_arg[2]);
1778 osf_fstatfs(struct tcb *tcp)
1780 if (entering(tcp)) {
1781 tprintf("%lu, ", tcp->u_arg[0]);
1783 printstatfs(tcp, tcp->u_arg[1]);
1784 tprintf(", %lu", tcp->u_arg[2]);
1792 sys_chdir(struct tcb *tcp)
1794 if (entering(tcp)) {
1795 printpath(tcp, tcp->u_arg[0]);
1801 decode_mkdir(struct tcb *tcp, int offset)
1803 if (entering(tcp)) {
1804 printpath(tcp, tcp->u_arg[offset]);
1805 tprintf(", %#lo", tcp->u_arg[offset + 1]);
1811 sys_mkdir(struct tcb *tcp)
1813 return decode_mkdir(tcp, 0);
1817 sys_mkdirat(struct tcb *tcp)
1820 print_dirfd(tcp, tcp->u_arg[0]);
1821 return decode_mkdir(tcp, 1);
1825 sys_link(struct tcb *tcp)
1827 if (entering(tcp)) {
1828 printpath(tcp, tcp->u_arg[0]);
1830 printpath(tcp, tcp->u_arg[1]);
1836 sys_linkat(struct tcb *tcp)
1838 if (entering(tcp)) {
1839 print_dirfd(tcp, tcp->u_arg[0]);
1840 printpath(tcp, tcp->u_arg[1]);
1842 print_dirfd(tcp, tcp->u_arg[2]);
1843 printpath(tcp, tcp->u_arg[3]);
1845 printflags(at_flags, tcp->u_arg[4], "AT_???");
1851 sys_unlinkat(struct tcb *tcp)
1853 if (entering(tcp)) {
1854 print_dirfd(tcp, tcp->u_arg[0]);
1855 printpath(tcp, tcp->u_arg[1]);
1857 printflags(at_flags, tcp->u_arg[2], "AT_???");
1863 sys_symlinkat(struct tcb *tcp)
1865 if (entering(tcp)) {
1866 printpath(tcp, tcp->u_arg[0]);
1868 print_dirfd(tcp, tcp->u_arg[1]);
1869 printpath(tcp, tcp->u_arg[2]);
1875 decode_readlink(struct tcb *tcp, int offset)
1877 if (entering(tcp)) {
1878 printpath(tcp, tcp->u_arg[offset]);
1882 tprintf("%#lx", tcp->u_arg[offset + 1]);
1884 /* Used to use printpathn(), but readlink
1885 * neither includes NUL in the returned count,
1886 * nor actually writes it into memory.
1887 * printpathn() would decide on printing
1888 * "..." continuation based on garbage
1889 * past return buffer's end.
1891 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1892 tprintf(", %lu", tcp->u_arg[offset + 2]);
1898 sys_readlink(struct tcb *tcp)
1900 return decode_readlink(tcp, 0);
1904 sys_readlinkat(struct tcb *tcp)
1907 print_dirfd(tcp, tcp->u_arg[0]);
1908 return decode_readlink(tcp, 1);
1912 sys_renameat(struct tcb *tcp)
1914 if (entering(tcp)) {
1915 print_dirfd(tcp, tcp->u_arg[0]);
1916 printpath(tcp, tcp->u_arg[1]);
1918 print_dirfd(tcp, tcp->u_arg[2]);
1919 printpath(tcp, tcp->u_arg[3]);
1925 sys_chown(struct tcb *tcp)
1927 if (entering(tcp)) {
1928 printpath(tcp, tcp->u_arg[0]);
1929 printuid(", ", tcp->u_arg[1]);
1930 printuid(", ", tcp->u_arg[2]);
1936 sys_fchownat(struct tcb *tcp)
1938 if (entering(tcp)) {
1939 print_dirfd(tcp, tcp->u_arg[0]);
1940 printpath(tcp, tcp->u_arg[1]);
1941 printuid(", ", tcp->u_arg[2]);
1942 printuid(", ", tcp->u_arg[3]);
1944 printflags(at_flags, tcp->u_arg[4], "AT_???");
1950 sys_fchown(struct tcb *tcp)
1952 if (entering(tcp)) {
1953 printfd(tcp, tcp->u_arg[0]);
1954 printuid(", ", tcp->u_arg[1]);
1955 printuid(", ", tcp->u_arg[2]);
1961 decode_chmod(struct tcb *tcp, int offset)
1963 if (entering(tcp)) {
1964 printpath(tcp, tcp->u_arg[offset]);
1965 tprintf(", %#lo", tcp->u_arg[offset + 1]);
1971 sys_chmod(struct tcb *tcp)
1973 return decode_chmod(tcp, 0);
1977 sys_fchmodat(struct tcb *tcp)
1980 print_dirfd(tcp, tcp->u_arg[0]);
1981 return decode_chmod(tcp, 1);
1985 sys_fchmod(struct tcb *tcp)
1987 if (entering(tcp)) {
1988 printfd(tcp, tcp->u_arg[0]);
1989 tprintf(", %#lo", tcp->u_arg[1]);
1996 sys_osf_utimes(struct tcb *tcp)
1998 if (entering(tcp)) {
1999 printpath(tcp, tcp->u_arg[0]);
2001 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2008 decode_utimes(struct tcb *tcp, int offset, int special)
2010 if (entering(tcp)) {
2011 printpath(tcp, tcp->u_arg[offset]);
2013 if (tcp->u_arg[offset + 1] == 0)
2017 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2018 BITNESS_CURRENT, special);
2020 printtv_bitness(tcp, tcp->u_arg[offset + 1]
2021 + sizeof(struct timeval),
2022 BITNESS_CURRENT, special);
2030 sys_utimes(struct tcb *tcp)
2032 return decode_utimes(tcp, 0, 0);
2036 sys_futimesat(struct tcb *tcp)
2039 print_dirfd(tcp, tcp->u_arg[0]);
2040 return decode_utimes(tcp, 1, 0);
2044 sys_utimensat(struct tcb *tcp)
2046 if (entering(tcp)) {
2047 print_dirfd(tcp, tcp->u_arg[0]);
2048 decode_utimes(tcp, 1, 1);
2050 printflags(at_flags, tcp->u_arg[3], "AT_???");
2056 sys_utime(struct tcb *tcp)
2062 unsigned wordsize = current_wordsize;
2064 if (entering(tcp)) {
2065 printpath(tcp, tcp->u_arg[0]);
2069 else if (!verbose(tcp))
2070 tprintf("%#lx", tcp->u_arg[1]);
2071 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
2073 else if (wordsize == sizeof u.utl[0]) {
2074 tprintf("[%s,", sprinttime(u.utl[0]));
2075 tprintf(" %s]", sprinttime(u.utl[1]));
2077 else if (wordsize == sizeof u.uti[0]) {
2078 tprintf("[%s,", sprinttime(u.uti[0]));
2079 tprintf(" %s]", sprinttime(u.uti[1]));
2088 decode_mknod(struct tcb *tcp, int offset)
2090 int mode = tcp->u_arg[offset + 1];
2092 if (entering(tcp)) {
2093 printpath(tcp, tcp->u_arg[offset]);
2094 tprintf(", %s", sprintmode(mode));
2095 switch (mode & S_IFMT) {
2099 if (current_personality == 1)
2100 tprintf(", makedev(%lu, %lu)",
2101 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2102 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
2105 tprintf(", makedev(%lu, %lu)",
2106 (unsigned long) major(tcp->u_arg[offset + 2]),
2107 (unsigned long) minor(tcp->u_arg[offset + 2]));
2117 sys_mknod(struct tcb *tcp)
2119 return decode_mknod(tcp, 0);
2123 sys_mknodat(struct tcb *tcp)
2126 print_dirfd(tcp, tcp->u_arg[0]);
2127 return decode_mknod(tcp, 1);
2131 printdir(struct tcb *tcp, long addr)
2135 if (!verbose(tcp)) {
2136 tprintf("%#lx", addr);
2139 if (umove(tcp, addr, &d) < 0) {
2143 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
2145 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2150 sys_readdir(struct tcb *tcp)
2152 if (entering(tcp)) {
2153 printfd(tcp, tcp->u_arg[0]);
2156 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2157 tprintf("%#lx", tcp->u_arg[1]);
2159 printdir(tcp, tcp->u_arg[1]);
2160 /* Not much point in printing this out, it is always 1. */
2161 if (tcp->u_arg[2] != 1)
2162 tprintf(", %lu", tcp->u_arg[2]);
2167 static const struct xlat direnttypes[] = {
2168 { DT_UNKNOWN, "DT_UNKNOWN" },
2169 { DT_FIFO, "DT_FIFO" },
2170 { DT_CHR, "DT_CHR" },
2171 { DT_DIR, "DT_DIR" },
2172 { DT_BLK, "DT_BLK" },
2173 { DT_REG, "DT_REG" },
2174 { DT_LNK, "DT_LNK" },
2175 { DT_SOCK, "DT_SOCK" },
2176 { DT_WHT, "DT_WHT" },
2181 sys_getdents(struct tcb *tcp)
2183 int i, len, dents = 0;
2186 if (entering(tcp)) {
2187 printfd(tcp, tcp->u_arg[0]);
2191 if (syserror(tcp) || !verbose(tcp)) {
2192 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2196 /* Beware of insanely large or negative values in tcp->u_rval */
2197 if (tcp->u_rval > 1024*1024)
2199 if (tcp->u_rval < 0)
2201 buf = len ? malloc(len) : NULL;
2203 die_out_of_memory();
2204 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2205 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2211 for (i = 0; i < len;) {
2212 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2214 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2215 i ? " " : "", d->d_ino, d->d_off);
2216 tprintf("d_reclen=%u, d_name=\"%s\"}",
2217 d->d_reclen, d->d_name);
2220 tprints("/* d_reclen == 0, problem here */");
2229 tprintf("/* %u entries */", dents);
2230 tprintf(", %lu", tcp->u_arg[2]);
2235 #if _LFS64_LARGEFILE
2237 sys_getdents64(struct tcb *tcp)
2239 int i, len, dents = 0;
2242 if (entering(tcp)) {
2243 printfd(tcp, tcp->u_arg[0]);
2247 if (syserror(tcp) || !verbose(tcp)) {
2248 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2253 /* Beware of insanely large or negative tcp->u_rval */
2254 if (tcp->u_rval > 1024*1024)
2256 if (tcp->u_rval < 0)
2258 buf = len ? malloc(len) : NULL;
2260 die_out_of_memory();
2262 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2263 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2269 for (i = 0; i < len;) {
2270 struct dirent64 *d = (struct dirent64 *) &buf[i];
2272 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
2277 printxval(direnttypes, d->d_type, "DT_???");
2279 tprintf("d_reclen=%u, d_name=\"%s\"}",
2280 d->d_reclen, d->d_name);
2283 tprints("/* d_reclen == 0, problem here */");
2292 tprintf("/* %u entries */", dents);
2293 tprintf(", %lu", tcp->u_arg[2]);
2300 sys_getcwd(struct tcb *tcp)
2304 tprintf("%#lx", tcp->u_arg[0]);
2306 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2307 tprintf(", %lu", tcp->u_arg[1]);
2312 #ifdef HAVE_SYS_ASYNCH_H
2315 sys_aioread(struct tcb *tcp)
2317 struct aio_result_t res;
2319 if (entering(tcp)) {
2320 tprintf("%lu, ", tcp->u_arg[0]);
2323 tprintf("%#lx", tcp->u_arg[1]);
2325 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2326 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2327 printxval(whence, tcp->u_arg[4], "L_???");
2328 if (syserror(tcp) || tcp->u_arg[5] == 0
2329 || umove(tcp, tcp->u_arg[5], &res) < 0)
2330 tprintf(", %#lx", tcp->u_arg[5]);
2332 tprintf(", {aio_return %d aio_errno %d}",
2333 res.aio_return, res.aio_errno);
2339 sys_aiowrite(struct tcb *tcp)
2341 struct aio_result_t res;
2343 if (entering(tcp)) {
2344 tprintf("%lu, ", tcp->u_arg[0]);
2345 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2346 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2347 printxval(whence, tcp->u_arg[4], "L_???");
2350 if (tcp->u_arg[5] == 0)
2352 else if (syserror(tcp)
2353 || umove(tcp, tcp->u_arg[5], &res) < 0)
2354 tprintf(", %#lx", tcp->u_arg[5]);
2356 tprintf(", {aio_return %d aio_errno %d}",
2357 res.aio_return, res.aio_errno);
2363 sys_aiowait(struct tcb *tcp)
2366 printtv(tcp, tcp->u_arg[0]);
2371 sys_aiocancel(struct tcb *tcp)
2373 struct aio_result_t res;
2376 if (tcp->u_arg[0] == 0)
2378 else if (syserror(tcp)
2379 || umove(tcp, tcp->u_arg[0], &res) < 0)
2380 tprintf("%#lx", tcp->u_arg[0]);
2382 tprintf("{aio_return %d aio_errno %d}",
2383 res.aio_return, res.aio_errno);
2388 #endif /* HAVE_SYS_ASYNCH_H */
2390 static const struct xlat xattrflags[] = {
2392 { XATTR_CREATE, "XATTR_CREATE" },
2393 { XATTR_REPLACE, "XATTR_REPLACE" },
2399 print_xattr_val(struct tcb *tcp, int failed,
2401 unsigned long insize,
2405 unsigned long capacity = 4 * size + 1;
2406 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2407 if (buf == NULL || /* probably a bogus size argument */
2408 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2412 unsigned char *out = buf;
2413 unsigned char *in = &buf[3 * size];
2415 for (i = 0; i < size; ++i) {
2419 #define tohex(n) "0123456789abcdef"[n]
2422 *out++ = tohex(in[i] / 16);
2423 *out++ = tohex(in[i] % 16);
2426 /* Don't print terminating NUL if there is one. */
2427 if (i > 0 && in[i - 1] == '\0')
2430 tprintf(", \"%s\", %ld", buf, insize);
2435 tprintf(", 0x%lx, %ld", arg, insize);
2439 sys_setxattr(struct tcb *tcp)
2441 if (entering(tcp)) {
2442 printpath(tcp, tcp->u_arg[0]);
2444 printstr(tcp, tcp->u_arg[1], -1);
2445 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2447 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2453 sys_fsetxattr(struct tcb *tcp)
2455 if (entering(tcp)) {
2456 printfd(tcp, tcp->u_arg[0]);
2458 printstr(tcp, tcp->u_arg[1], -1);
2459 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2461 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2467 sys_getxattr(struct tcb *tcp)
2469 if (entering(tcp)) {
2470 printpath(tcp, tcp->u_arg[0]);
2472 printstr(tcp, tcp->u_arg[1], -1);
2474 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2481 sys_fgetxattr(struct tcb *tcp)
2483 if (entering(tcp)) {
2484 printfd(tcp, tcp->u_arg[0]);
2486 printstr(tcp, tcp->u_arg[1], -1);
2488 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2495 print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2497 if (syserror(tcp)) {
2498 tprintf("%#lx", addr);
2504 (size < tcp->u_rval) ? size : tcp->u_rval;
2505 printstr(tcp, addr, len);
2508 tprintf(", %lu", size);
2512 sys_listxattr(struct tcb *tcp)
2514 if (entering(tcp)) {
2515 printpath(tcp, tcp->u_arg[0]);
2518 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2524 sys_flistxattr(struct tcb *tcp)
2526 if (entering(tcp)) {
2527 printfd(tcp, tcp->u_arg[0]);
2530 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2536 sys_removexattr(struct tcb *tcp)
2538 if (entering(tcp)) {
2539 printpath(tcp, tcp->u_arg[0]);
2541 printstr(tcp, tcp->u_arg[1], -1);
2547 sys_fremovexattr(struct tcb *tcp)
2549 if (entering(tcp)) {
2550 printfd(tcp, tcp->u_arg[0]);
2552 printstr(tcp, tcp->u_arg[1], -1);
2557 static const struct xlat advise[] = {
2558 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2559 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2560 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2561 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2562 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2563 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2568 sys_fadvise64(struct tcb *tcp)
2570 if (entering(tcp)) {
2572 printfd(tcp, tcp->u_arg[0]);
2574 argn = printllval(tcp, "%lld", 1);
2575 tprintf(", %ld, ", tcp->u_arg[argn++]);
2576 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2582 sys_fadvise64_64(struct tcb *tcp)
2584 if (entering(tcp)) {
2586 printfd(tcp, tcp->u_arg[0]);
2588 #if defined ARM || defined POWERPC
2589 argn = printllval(tcp, "%lld, ", 2);
2591 argn = printllval(tcp, "%lld, ", 1);
2593 argn = printllval(tcp, "%lld, ", argn);
2594 #if defined ARM || defined POWERPC
2595 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
2597 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2603 static const struct xlat inotify_modes[] = {
2604 { 0x00000001, "IN_ACCESS" },
2605 { 0x00000002, "IN_MODIFY" },
2606 { 0x00000004, "IN_ATTRIB" },
2607 { 0x00000008, "IN_CLOSE_WRITE"},
2608 { 0x00000010, "IN_CLOSE_NOWRITE"},
2609 { 0x00000020, "IN_OPEN" },
2610 { 0x00000040, "IN_MOVED_FROM" },
2611 { 0x00000080, "IN_MOVED_TO" },
2612 { 0x00000100, "IN_CREATE" },
2613 { 0x00000200, "IN_DELETE" },
2614 { 0x00000400, "IN_DELETE_SELF"},
2615 { 0x00000800, "IN_MOVE_SELF" },
2616 { 0x00002000, "IN_UNMOUNT" },
2617 { 0x00004000, "IN_Q_OVERFLOW" },
2618 { 0x00008000, "IN_IGNORED" },
2619 { 0x01000000, "IN_ONLYDIR" },
2620 { 0x02000000, "IN_DONT_FOLLOW"},
2621 { 0x20000000, "IN_MASK_ADD" },
2622 { 0x40000000, "IN_ISDIR" },
2623 { 0x80000000, "IN_ONESHOT" },
2627 static const struct xlat inotify_init_flags[] = {
2628 { 0x00000800, "IN_NONBLOCK" },
2629 { 0x00080000, "IN_CLOEXEC" },
2634 sys_inotify_add_watch(struct tcb *tcp)
2636 if (entering(tcp)) {
2637 printfd(tcp, tcp->u_arg[0]);
2639 printpath(tcp, tcp->u_arg[1]);
2641 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2647 sys_inotify_rm_watch(struct tcb *tcp)
2649 if (entering(tcp)) {
2650 printfd(tcp, tcp->u_arg[0]);
2651 tprintf(", %d", (int) tcp->u_arg[1]);
2657 sys_inotify_init1(struct tcb *tcp)
2660 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
2665 sys_fallocate(struct tcb *tcp)
2667 if (entering(tcp)) {
2669 printfd(tcp, tcp->u_arg[0]); /* fd */
2671 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
2672 argn = printllval(tcp, "%llu, ", 2); /* offset */
2673 printllval(tcp, "%llu", argn); /* len */
2678 #ifndef SWAP_FLAG_PREFER
2679 # define SWAP_FLAG_PREFER 0x8000
2681 #ifndef SWAP_FLAG_DISCARD
2682 # define SWAP_FLAG_DISCARD 0x10000
2684 static const struct xlat swap_flags[] = {
2685 { SWAP_FLAG_PREFER, "SWAP_FLAG_PREFER" },
2686 { SWAP_FLAG_DISCARD, "SWAP_FLAG_DISCARD" },
2691 sys_swapon(struct tcb *tcp)
2693 if (entering(tcp)) {
2694 int flags = tcp->u_arg[1];
2695 printpath(tcp, tcp->u_arg[0]);
2697 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2699 if (flags & SWAP_FLAG_PREFER)
2700 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);