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(LINUX_MIPSN32)
483 sys_lseek(struct tcb *tcp)
489 printfd(tcp, tcp->u_arg[0]);
491 offset = tcp->ext_arg[1];
492 _whence = tcp->u_arg[2];
493 if (_whence == SEEK_SET)
494 tprintf("%llu, ", offset);
496 tprintf("%lld, ", offset);
497 printxval(whence, _whence, "SEEK_???");
499 return RVAL_LUDECIMAL;
503 sys_lseek(struct tcb *tcp)
509 printfd(tcp, tcp->u_arg[0]);
511 offset = tcp->u_arg[1];
512 _whence = tcp->u_arg[2];
513 if (_whence == SEEK_SET)
514 tprintf("%lu, ", offset);
516 tprintf("%ld, ", offset);
517 printxval(whence, _whence, "SEEK_???");
519 return RVAL_UDECIMAL;
524 sys_llseek(struct tcb *tcp)
527 printfd(tcp, tcp->u_arg[0]);
529 * This one call takes explicitly two 32-bit arguments hi, lo,
530 * rather than one 64-bit argument for which LONG_LONG works
531 * appropriate for the native byte order.
533 if (tcp->u_arg[4] == SEEK_SET)
535 ((long long int) tcp->u_arg[1]) << 32 |
536 (unsigned long long) (unsigned) tcp->u_arg[2]);
539 ((long long int) tcp->u_arg[1]) << 32 |
540 (unsigned long long) (unsigned) tcp->u_arg[2]);
544 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
545 tprintf("%#lx, ", tcp->u_arg[3]);
547 tprintf("[%llu], ", off);
548 printxval(whence, tcp->u_arg[4], "SEEK_???");
554 sys_readahead(struct tcb *tcp)
558 printfd(tcp, tcp->u_arg[0]);
560 argn = printllval(tcp, "%lld", 1);
561 tprintf(", %ld", tcp->u_arg[argn]);
566 #ifndef HAVE_LONG_LONG_OFF_T
568 sys_truncate(struct tcb *tcp)
571 printpath(tcp, tcp->u_arg[0]);
572 tprintf(", %lu", tcp->u_arg[1]);
578 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
580 sys_truncate64(struct tcb *tcp)
583 printpath(tcp, tcp->u_arg[0]);
584 printllval(tcp, ", %llu", 1);
590 #ifndef HAVE_LONG_LONG_OFF_T
592 sys_ftruncate(struct tcb *tcp)
595 printfd(tcp, tcp->u_arg[0]);
596 tprintf(", %lu", tcp->u_arg[1]);
602 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
604 sys_ftruncate64(struct tcb *tcp)
607 printfd(tcp, tcp->u_arg[0]);
609 printllval(tcp, "%llu", 1);
617 static const struct xlat modetypes[] = {
618 { S_IFREG, "S_IFREG" },
619 { S_IFSOCK, "S_IFSOCK" },
620 { S_IFIFO, "S_IFIFO" },
621 { S_IFLNK, "S_IFLNK" },
622 { S_IFDIR, "S_IFDIR" },
623 { S_IFBLK, "S_IFBLK" },
624 { S_IFCHR, "S_IFCHR" },
631 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
636 if ((mode & S_IFMT) == 0)
638 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
639 sprintf(buf, "%#o", mode);
642 s = buf + sprintf(buf, "%s%s%s%s", s,
643 (mode & S_ISUID) ? "|S_ISUID" : "",
644 (mode & S_ISGID) ? "|S_ISGID" : "",
645 (mode & S_ISVTX) ? "|S_ISVTX" : "");
646 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
648 sprintf((char*)s, "|%#o", mode);
649 s = (*buf == '|') ? buf + 1 : buf;
657 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
665 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
666 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
667 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
669 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
682 int st_pad1[3]; /* network id */
691 int st_pad3; /* st_size, off_t expansion */
692 timestruct_t st_atime;
693 timestruct_t st_mtime;
694 timestruct_t st_ctime;
698 int st_pad4[8]; /* expansion area */
702 printstatsol(struct tcb *tcp, long addr)
704 struct solstat statbuf;
706 if (umove(tcp, addr, &statbuf) < 0) {
711 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
712 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
713 (unsigned long) (statbuf.st_dev & 0x3ffff),
714 (unsigned long) statbuf.st_ino,
715 sprintmode(statbuf.st_mode));
716 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
717 (unsigned long) statbuf.st_nlink,
718 (unsigned long) statbuf.st_uid,
719 (unsigned long) statbuf.st_gid);
720 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
721 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
724 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
725 switch (statbuf.st_mode & S_IFMT) {
726 case S_IFCHR: case S_IFBLK:
727 tprintf("st_rdev=makedev(%lu, %lu), ",
728 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
729 (unsigned long) (statbuf.st_rdev & 0x3ffff));
732 tprintf("st_size=%u, ", statbuf.st_size);
736 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
737 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
738 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
746 printstat_sparc64(struct tcb *tcp, long addr)
748 struct stat_sparc64 statbuf;
750 if (umove(tcp, addr, &statbuf) < 0) {
756 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
757 (unsigned long) major(statbuf.st_dev),
758 (unsigned long) minor(statbuf.st_dev),
759 (unsigned long) statbuf.st_ino,
760 sprintmode(statbuf.st_mode));
761 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
762 (unsigned long) statbuf.st_nlink,
763 (unsigned long) statbuf.st_uid,
764 (unsigned long) statbuf.st_gid);
765 tprintf("st_blksize=%lu, ",
766 (unsigned long) statbuf.st_blksize);
767 tprintf("st_blocks=%lu, ",
768 (unsigned long) statbuf.st_blocks);
771 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
772 switch (statbuf.st_mode & S_IFMT) {
773 case S_IFCHR: case S_IFBLK:
774 tprintf("st_rdev=makedev(%lu, %lu), ",
775 (unsigned long) major(statbuf.st_rdev),
776 (unsigned long) minor(statbuf.st_rdev));
779 tprintf("st_size=%lu, ", statbuf.st_size);
783 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
784 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
785 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
791 #endif /* LINUXSPARC */
793 #if defined POWERPC64
794 struct stat_powerpc32 {
797 unsigned int st_mode;
798 unsigned short st_nlink;
801 unsigned int st_rdev;
802 unsigned int st_size;
803 unsigned int st_blksize;
804 unsigned int st_blocks;
805 unsigned int st_atime;
806 unsigned int st_atime_nsec;
807 unsigned int st_mtime;
808 unsigned int st_mtime_nsec;
809 unsigned int st_ctime;
810 unsigned int st_ctime_nsec;
811 unsigned int __unused4;
812 unsigned int __unused5;
816 printstat_powerpc32(struct tcb *tcp, long addr)
818 struct stat_powerpc32 statbuf;
820 if (umove(tcp, addr, &statbuf) < 0) {
826 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
827 major(statbuf.st_dev), minor(statbuf.st_dev),
829 sprintmode(statbuf.st_mode));
830 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
831 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
832 tprintf("st_blksize=%u, ", statbuf.st_blksize);
833 tprintf("st_blocks=%u, ", statbuf.st_blocks);
836 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
837 switch (statbuf.st_mode & S_IFMT) {
838 case S_IFCHR: case S_IFBLK:
839 tprintf("st_rdev=makedev(%lu, %lu), ",
840 (unsigned long) major(statbuf.st_rdev),
841 (unsigned long) minor(statbuf.st_rdev));
844 tprintf("st_size=%u, ", statbuf.st_size);
848 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
849 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
850 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
855 #endif /* POWERPC64 */
857 static const struct xlat fileflags[] = {
861 #ifndef HAVE_LONG_LONG_OFF_T
863 realprintstat(struct tcb *tcp, struct stat *statbuf)
866 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
867 (unsigned long) major(statbuf->st_dev),
868 (unsigned long) minor(statbuf->st_dev),
869 (unsigned long) statbuf->st_ino,
870 sprintmode(statbuf->st_mode));
871 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
872 (unsigned long) statbuf->st_nlink,
873 (unsigned long) statbuf->st_uid,
874 (unsigned long) statbuf->st_gid);
875 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
876 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
878 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
879 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
883 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
884 switch (statbuf->st_mode & S_IFMT) {
885 case S_IFCHR: case S_IFBLK:
886 #ifdef HAVE_STRUCT_STAT_ST_RDEV
887 tprintf("st_rdev=makedev(%lu, %lu), ",
888 (unsigned long) major(statbuf->st_rdev),
889 (unsigned long) minor(statbuf->st_rdev));
890 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
891 tprintf("st_size=makedev(%lu, %lu), ",
892 (unsigned long) major(statbuf->st_size),
893 (unsigned long) minor(statbuf->st_size));
894 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
897 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
901 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
902 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
903 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
904 #if HAVE_STRUCT_STAT_ST_FLAGS
905 tprints(", st_flags=");
906 printflags(fileflags, statbuf->st_flags, "UF_???");
908 #if HAVE_STRUCT_STAT_ST_ACLCNT
909 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
911 #if HAVE_STRUCT_STAT_ST_LEVEL
912 tprintf(", st_level=%ld", statbuf->st_level);
914 #if HAVE_STRUCT_STAT_ST_FSTYPE
915 tprintf(", st_fstype=%.*s",
916 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
918 #if HAVE_STRUCT_STAT_ST_GEN
919 tprintf(", st_gen=%u", statbuf->st_gen);
928 printstat(struct tcb *tcp, long addr)
936 if (syserror(tcp) || !verbose(tcp)) {
937 tprintf("%#lx", addr);
942 if (current_personality == 1) {
943 printstatsol(tcp, addr);
947 else if (current_personality == 2) {
948 printstat_sparc64(tcp, addr);
952 #endif /* LINUXSPARC */
954 #if defined POWERPC64
955 if (current_personality == 1) {
956 printstat_powerpc32(tcp, addr);
961 if (umove(tcp, addr, &statbuf) < 0) {
966 realprintstat(tcp, &statbuf);
968 #endif /* !HAVE_LONG_LONG_OFF_T */
970 #if !defined HAVE_STAT64 && defined X86_64
972 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
973 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
974 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
975 * __GNUC__ is needed for the required __attribute__ below.
978 unsigned long long st_dev;
979 unsigned char __pad0[4];
980 unsigned int __st_ino;
981 unsigned int st_mode;
982 unsigned int st_nlink;
985 unsigned long long st_rdev;
986 unsigned char __pad3[4];
988 unsigned int st_blksize;
989 unsigned long long st_blocks;
990 unsigned int st_atime;
991 unsigned int st_atime_nsec;
992 unsigned int st_mtime;
993 unsigned int st_mtime_nsec;
994 unsigned int st_ctime;
995 unsigned int st_ctime_nsec;
996 unsigned long long st_ino;
997 } __attribute__((packed));
998 # define HAVE_STAT64 1
999 # define STAT64_SIZE 96
1004 printstat64(struct tcb *tcp, long addr)
1006 struct stat64 statbuf;
1009 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1016 if (syserror(tcp) || !verbose(tcp)) {
1017 tprintf("%#lx", addr);
1022 if (current_personality == 1) {
1023 printstatsol(tcp, addr);
1027 else if (current_personality == 2) {
1028 printstat_sparc64(tcp, addr);
1032 #endif /* LINUXSPARC */
1035 if (current_personality == 0) {
1036 printstat(tcp, addr);
1041 if (umove(tcp, addr, &statbuf) < 0) {
1047 #ifdef HAVE_LONG_LONG
1048 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1050 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
1052 (unsigned long) major(statbuf.st_dev),
1053 (unsigned long) minor(statbuf.st_dev),
1054 #ifdef HAVE_LONG_LONG
1055 (unsigned long long) statbuf.st_ino,
1057 (unsigned long) statbuf.st_ino,
1059 sprintmode(statbuf.st_mode));
1060 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1061 (unsigned long) statbuf.st_nlink,
1062 (unsigned long) statbuf.st_uid,
1063 (unsigned long) statbuf.st_gid);
1064 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1065 tprintf("st_blksize=%lu, ",
1066 (unsigned long) statbuf.st_blksize);
1067 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1068 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
1069 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1070 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
1073 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1074 switch (statbuf.st_mode & S_IFMT) {
1075 case S_IFCHR: case S_IFBLK:
1076 #ifdef HAVE_STRUCT_STAT_ST_RDEV
1077 tprintf("st_rdev=makedev(%lu, %lu), ",
1078 (unsigned long) major(statbuf.st_rdev),
1079 (unsigned long) minor(statbuf.st_rdev));
1080 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
1081 tprintf("st_size=makedev(%lu, %lu), ",
1082 (unsigned long) major(statbuf.st_size),
1083 (unsigned long) minor(statbuf.st_size));
1084 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
1087 #ifdef HAVE_LONG_LONG
1088 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1090 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1095 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1096 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1097 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1098 #if HAVE_STRUCT_STAT_ST_FLAGS
1099 tprints(", st_flags=");
1100 printflags(fileflags, statbuf.st_flags, "UF_???");
1102 #if HAVE_STRUCT_STAT_ST_ACLCNT
1103 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1105 #if HAVE_STRUCT_STAT_ST_LEVEL
1106 tprintf(", st_level=%ld", statbuf.st_level);
1108 #if HAVE_STRUCT_STAT_ST_FSTYPE
1109 tprintf(", st_fstype=%.*s",
1110 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1112 #if HAVE_STRUCT_STAT_ST_GEN
1113 tprintf(", st_gen=%u", statbuf.st_gen);
1120 #endif /* HAVE_STAT64 */
1122 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1124 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
1126 newbuf->st_dev = oldbuf->st_dev;
1127 newbuf->st_ino = oldbuf->st_ino;
1128 newbuf->st_mode = oldbuf->st_mode;
1129 newbuf->st_nlink = oldbuf->st_nlink;
1130 newbuf->st_uid = oldbuf->st_uid;
1131 newbuf->st_gid = oldbuf->st_gid;
1132 newbuf->st_rdev = oldbuf->st_rdev;
1133 newbuf->st_size = oldbuf->st_size;
1134 newbuf->st_atime = oldbuf->st_atime;
1135 newbuf->st_mtime = oldbuf->st_mtime;
1136 newbuf->st_ctime = oldbuf->st_ctime;
1137 newbuf->st_blksize = 0; /* not supported in old_stat */
1138 newbuf->st_blocks = 0; /* not supported in old_stat */
1142 printoldstat(struct tcb *tcp, long addr)
1144 struct __old_kernel_stat statbuf;
1145 struct stat newstatbuf;
1151 if (syserror(tcp) || !verbose(tcp)) {
1152 tprintf("%#lx", addr);
1157 if (current_personality == 1) {
1158 printstatsol(tcp, addr);
1163 if (umove(tcp, addr, &statbuf) < 0) {
1168 convertoldstat(&statbuf, &newstatbuf);
1169 realprintstat(tcp, &newstatbuf);
1173 #ifndef HAVE_LONG_LONG_OFF_T
1175 sys_stat(struct tcb *tcp)
1177 if (entering(tcp)) {
1178 printpath(tcp, tcp->u_arg[0]);
1181 printstat(tcp, tcp->u_arg[1]);
1188 sys_stat64(struct tcb *tcp)
1191 if (entering(tcp)) {
1192 printpath(tcp, tcp->u_arg[0]);
1195 printstat64(tcp, tcp->u_arg[1]);
1199 return printargs(tcp);
1203 #ifndef AT_SYMLINK_NOFOLLOW
1204 # define AT_SYMLINK_NOFOLLOW 0x100
1206 #ifndef AT_REMOVEDIR
1207 # define AT_REMOVEDIR 0x200
1209 #ifndef AT_SYMLINK_FOLLOW
1210 # define AT_SYMLINK_FOLLOW 0x400
1212 #ifndef AT_NO_AUTOMOUNT
1213 # define AT_NO_AUTOMOUNT 0x800
1215 #ifndef AT_EMPTY_PATH
1216 # define AT_EMPTY_PATH 0x1000
1219 static const struct xlat at_flags[] = {
1220 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1221 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1222 { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" },
1223 { AT_NO_AUTOMOUNT, "AT_NO_AUTOMOUNT" },
1224 { AT_EMPTY_PATH, "AT_EMPTY_PATH" },
1229 sys_newfstatat(struct tcb *tcp)
1231 if (entering(tcp)) {
1232 print_dirfd(tcp, tcp->u_arg[0]);
1233 printpath(tcp, tcp->u_arg[1]);
1237 if (current_personality == 0)
1238 printstat(tcp, tcp->u_arg[2]);
1240 printstat64(tcp, tcp->u_arg[2]);
1241 #elif defined HAVE_STAT64
1242 printstat64(tcp, tcp->u_arg[2]);
1244 printstat(tcp, tcp->u_arg[2]);
1247 printflags(at_flags, tcp->u_arg[3], "AT_???");
1252 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1254 sys_oldstat(struct tcb *tcp)
1256 if (entering(tcp)) {
1257 printpath(tcp, tcp->u_arg[0]);
1260 printoldstat(tcp, tcp->u_arg[1]);
1266 #ifndef HAVE_LONG_LONG_OFF_T
1268 sys_fstat(struct tcb *tcp)
1270 if (entering(tcp)) {
1271 printfd(tcp, tcp->u_arg[0]);
1274 printstat(tcp, tcp->u_arg[1]);
1281 sys_fstat64(struct tcb *tcp)
1284 if (entering(tcp)) {
1285 printfd(tcp, tcp->u_arg[0]);
1288 printstat64(tcp, tcp->u_arg[1]);
1292 return printargs(tcp);
1296 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1298 sys_oldfstat(struct tcb *tcp)
1300 if (entering(tcp)) {
1301 printfd(tcp, tcp->u_arg[0]);
1304 printoldstat(tcp, tcp->u_arg[1]);
1310 #ifndef HAVE_LONG_LONG_OFF_T
1312 sys_lstat(struct tcb *tcp)
1314 if (entering(tcp)) {
1315 printpath(tcp, tcp->u_arg[0]);
1318 printstat(tcp, tcp->u_arg[1]);
1325 sys_lstat64(struct tcb *tcp)
1328 if (entering(tcp)) {
1329 printpath(tcp, tcp->u_arg[0]);
1332 printstat64(tcp, tcp->u_arg[1]);
1336 return printargs(tcp);
1340 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1342 sys_oldlstat(struct tcb *tcp)
1344 if (entering(tcp)) {
1345 printpath(tcp, tcp->u_arg[0]);
1348 printoldstat(tcp, tcp->u_arg[1]);
1354 #if defined(LINUXSPARC)
1357 sys_xstat(struct tcb *tcp)
1359 if (entering(tcp)) {
1360 tprintf("%ld, ", tcp->u_arg[0]);
1361 printpath(tcp, tcp->u_arg[1]);
1365 if (tcp->u_arg[0] == _STAT64_VER)
1366 printstat64(tcp, tcp->u_arg[2]);
1369 printstat(tcp, tcp->u_arg[2]);
1375 sys_fxstat(struct tcb *tcp)
1378 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1381 if (tcp->u_arg[0] == _STAT64_VER)
1382 printstat64(tcp, tcp->u_arg[2]);
1385 printstat(tcp, tcp->u_arg[2]);
1391 sys_lxstat(struct tcb *tcp)
1393 if (entering(tcp)) {
1394 tprintf("%ld, ", tcp->u_arg[0]);
1395 printpath(tcp, tcp->u_arg[1]);
1399 if (tcp->u_arg[0] == _STAT64_VER)
1400 printstat64(tcp, tcp->u_arg[2]);
1403 printstat(tcp, tcp->u_arg[2]);
1409 sys_xmknod(struct tcb *tcp)
1411 int mode = tcp->u_arg[2];
1413 if (entering(tcp)) {
1414 tprintf("%ld, ", tcp->u_arg[0]);
1415 printpath(tcp, tcp->u_arg[1]);
1416 tprintf(", %s", sprintmode(mode));
1417 switch (mode & S_IFMT) {
1418 case S_IFCHR: case S_IFBLK:
1419 tprintf(", makedev(%lu, %lu)",
1420 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1421 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1430 # ifdef HAVE_SYS_ACL_H
1432 # include <sys/acl.h>
1434 static const struct xlat aclcmds[] = {
1436 { SETACL, "SETACL" },
1439 { GETACL, "GETACL" },
1442 { GETACLCNT, "GETACLCNT" },
1445 { ACL_GET, "ACL_GET" },
1448 { ACL_SET, "ACL_SET" },
1451 { ACL_CNT, "ACL_CNT" },
1457 sys_acl(struct tcb *tcp)
1459 if (entering(tcp)) {
1460 printpath(tcp, tcp->u_arg[0]);
1462 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1463 tprintf(", %ld", tcp->u_arg[2]);
1465 * FIXME - dump out the list of aclent_t's pointed to
1466 * by "tcp->u_arg[3]" if it's not NULL.
1469 tprintf(", %#lx", tcp->u_arg[3]);
1477 sys_facl(struct tcb *tcp)
1479 if (entering(tcp)) {
1480 tprintf("%ld, ", tcp->u_arg[0]);
1481 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1482 tprintf(", %ld", tcp->u_arg[2]);
1484 * FIXME - dump out the list of aclent_t's pointed to
1485 * by "tcp->u_arg[3]" if it's not NULL.
1488 tprintf(", %#lx", tcp->u_arg[3]);
1495 static const struct xlat aclipc[] = {
1497 { IPC_SHM, "IPC_SHM" },
1500 { IPC_SEM, "IPC_SEM" },
1503 { IPC_MSG, "IPC_MSG" },
1509 sys_aclipc(struct tcb *tcp)
1511 if (entering(tcp)) {
1512 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1513 tprintf(", %#lx, ", tcp->u_arg[1]);
1514 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1515 tprintf(", %ld", tcp->u_arg[3]);
1517 * FIXME - dump out the list of aclent_t's pointed to
1518 * by "tcp->u_arg[4]" if it's not NULL.
1521 tprintf(", %#lx", tcp->u_arg[4]);
1528 # endif /* HAVE_SYS_ACL_H */
1530 #endif /* LINUXSPARC */
1532 static const struct xlat fsmagic[] = {
1533 { 0x73757245, "CODA_SUPER_MAGIC" },
1534 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1535 { 0x1373, "DEVFS_SUPER_MAGIC" },
1536 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1537 { 0x414A53, "EFS_SUPER_MAGIC" },
1538 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1539 { 0xef53, "EXT2_SUPER_MAGIC" },
1540 { 0x137d, "EXT_SUPER_MAGIC" },
1541 { 0xf995e849, "HPFS_SUPER_MAGIC" },
1542 { 0x9660, "ISOFS_SUPER_MAGIC" },
1543 { 0x137f, "MINIX_SUPER_MAGIC" },
1544 { 0x138f, "MINIX_SUPER_MAGIC2" },
1545 { 0x2468, "MINIX2_SUPER_MAGIC" },
1546 { 0x2478, "MINIX2_SUPER_MAGIC2" },
1547 { 0x4d44, "MSDOS_SUPER_MAGIC" },
1548 { 0x564c, "NCP_SUPER_MAGIC" },
1549 { 0x6969, "NFS_SUPER_MAGIC" },
1550 { 0x9fa0, "PROC_SUPER_MAGIC" },
1551 { 0x002f, "QNX4_SUPER_MAGIC" },
1552 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1553 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1554 { 0x517b, "SMB_SUPER_MAGIC" },
1555 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1556 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1557 { 0x00011954, "UFS_MAGIC" },
1558 { 0x54190100, "UFS_CIGAM" },
1559 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
1560 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
1561 { 0x62656572, "SYSFS_MAGIC" },
1566 sprintfstype(int magic)
1568 static char buf[32];
1571 s = xlookup(fsmagic, magic);
1573 sprintf(buf, "\"%s\"", s);
1576 sprintf(buf, "%#x", magic);
1581 printstatfs(struct tcb *tcp, long addr)
1583 struct statfs statbuf;
1585 if (syserror(tcp) || !verbose(tcp)) {
1586 tprintf("%#lx", addr);
1589 if (umove(tcp, addr, &statbuf) < 0) {
1595 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1596 sprintfstype(statbuf.f_type),
1597 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1598 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1599 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
1600 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1603 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1604 sprintfstype(statbuf.f_type),
1605 (unsigned long)statbuf.f_bsize,
1606 (unsigned long)statbuf.f_blocks,
1607 (unsigned long)statbuf.f_bfree);
1608 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1609 (unsigned long)statbuf.f_bavail,
1610 (unsigned long)statbuf.f_files,
1611 (unsigned long)statbuf.f_ffree,
1612 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1613 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1615 #ifdef _STATFS_F_FRSIZE
1616 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1622 sys_statfs(struct tcb *tcp)
1624 if (entering(tcp)) {
1625 printpath(tcp, tcp->u_arg[0]);
1628 printstatfs(tcp, tcp->u_arg[1]);
1634 sys_fstatfs(struct tcb *tcp)
1636 if (entering(tcp)) {
1637 printfd(tcp, tcp->u_arg[0]);
1640 printstatfs(tcp, tcp->u_arg[1]);
1645 #if defined HAVE_STATFS64
1647 printstatfs64(struct tcb *tcp, long addr)
1649 struct statfs64 statbuf;
1651 if (syserror(tcp) || !verbose(tcp)) {
1652 tprintf("%#lx", addr);
1655 if (umove(tcp, addr, &statbuf) < 0) {
1659 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
1660 sprintfstype(statbuf.f_type),
1661 (unsigned long long)statbuf.f_bsize,
1662 (unsigned long long)statbuf.f_blocks,
1663 (unsigned long long)statbuf.f_bfree);
1664 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1665 (unsigned long long)statbuf.f_bavail,
1666 (unsigned long long)statbuf.f_files,
1667 (unsigned long long)statbuf.f_ffree,
1668 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1669 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1670 #ifdef _STATFS_F_FRSIZE
1671 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
1673 #ifdef _STATFS_F_FLAGS
1674 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1679 struct compat_statfs64 {
1691 uint32_t f_spare[4];
1693 #if defined(X86_64) || defined(IA64)
1694 __attribute__ ((packed, aligned(4)))
1699 printcompat_statfs64(struct tcb *tcp, long addr)
1701 struct compat_statfs64 statbuf;
1703 if (syserror(tcp) || !verbose(tcp)) {
1704 tprintf("%#lx", addr);
1707 if (umove(tcp, addr, &statbuf) < 0) {
1711 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1712 sprintfstype(statbuf.f_type),
1713 (unsigned long)statbuf.f_bsize,
1714 (unsigned long long)statbuf.f_blocks,
1715 (unsigned long long)statbuf.f_bfree);
1716 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1717 (unsigned long long)statbuf.f_bavail,
1718 (unsigned long long)statbuf.f_files,
1719 (unsigned long long)statbuf.f_ffree,
1720 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1721 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1722 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1723 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
1727 sys_statfs64(struct tcb *tcp)
1729 if (entering(tcp)) {
1730 printpath(tcp, tcp->u_arg[0]);
1731 tprintf(", %lu, ", tcp->u_arg[1]);
1733 if (tcp->u_arg[1] == sizeof(struct statfs64))
1734 printstatfs64(tcp, tcp->u_arg[2]);
1735 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1736 printcompat_statfs64(tcp, tcp->u_arg[2]);
1744 sys_fstatfs64(struct tcb *tcp)
1746 if (entering(tcp)) {
1747 printfd(tcp, tcp->u_arg[0]);
1748 tprintf(", %lu, ", tcp->u_arg[1]);
1750 if (tcp->u_arg[1] == sizeof(struct statfs64))
1751 printstatfs64(tcp, tcp->u_arg[2]);
1752 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1753 printcompat_statfs64(tcp, tcp->u_arg[2]);
1763 osf_statfs(struct tcb *tcp)
1765 if (entering(tcp)) {
1766 printpath(tcp, tcp->u_arg[0]);
1769 printstatfs(tcp, tcp->u_arg[1]);
1770 tprintf(", %lu", tcp->u_arg[2]);
1776 osf_fstatfs(struct tcb *tcp)
1778 if (entering(tcp)) {
1779 tprintf("%lu, ", tcp->u_arg[0]);
1781 printstatfs(tcp, tcp->u_arg[1]);
1782 tprintf(", %lu", tcp->u_arg[2]);
1790 sys_chdir(struct tcb *tcp)
1792 if (entering(tcp)) {
1793 printpath(tcp, tcp->u_arg[0]);
1799 decode_mkdir(struct tcb *tcp, int offset)
1801 if (entering(tcp)) {
1802 printpath(tcp, tcp->u_arg[offset]);
1803 tprintf(", %#lo", tcp->u_arg[offset + 1]);
1809 sys_mkdir(struct tcb *tcp)
1811 return decode_mkdir(tcp, 0);
1815 sys_mkdirat(struct tcb *tcp)
1818 print_dirfd(tcp, tcp->u_arg[0]);
1819 return decode_mkdir(tcp, 1);
1823 sys_link(struct tcb *tcp)
1825 if (entering(tcp)) {
1826 printpath(tcp, tcp->u_arg[0]);
1828 printpath(tcp, tcp->u_arg[1]);
1834 sys_linkat(struct tcb *tcp)
1836 if (entering(tcp)) {
1837 print_dirfd(tcp, tcp->u_arg[0]);
1838 printpath(tcp, tcp->u_arg[1]);
1840 print_dirfd(tcp, tcp->u_arg[2]);
1841 printpath(tcp, tcp->u_arg[3]);
1843 printflags(at_flags, tcp->u_arg[4], "AT_???");
1849 sys_unlinkat(struct tcb *tcp)
1851 if (entering(tcp)) {
1852 print_dirfd(tcp, tcp->u_arg[0]);
1853 printpath(tcp, tcp->u_arg[1]);
1855 printflags(at_flags, tcp->u_arg[2], "AT_???");
1861 sys_symlinkat(struct tcb *tcp)
1863 if (entering(tcp)) {
1864 printpath(tcp, tcp->u_arg[0]);
1866 print_dirfd(tcp, tcp->u_arg[1]);
1867 printpath(tcp, tcp->u_arg[2]);
1873 decode_readlink(struct tcb *tcp, int offset)
1875 if (entering(tcp)) {
1876 printpath(tcp, tcp->u_arg[offset]);
1880 tprintf("%#lx", tcp->u_arg[offset + 1]);
1882 /* Used to use printpathn(), but readlink
1883 * neither includes NUL in the returned count,
1884 * nor actually writes it into memory.
1885 * printpathn() would decide on printing
1886 * "..." continuation based on garbage
1887 * past return buffer's end.
1889 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1890 tprintf(", %lu", tcp->u_arg[offset + 2]);
1896 sys_readlink(struct tcb *tcp)
1898 return decode_readlink(tcp, 0);
1902 sys_readlinkat(struct tcb *tcp)
1905 print_dirfd(tcp, tcp->u_arg[0]);
1906 return decode_readlink(tcp, 1);
1910 sys_renameat(struct tcb *tcp)
1912 if (entering(tcp)) {
1913 print_dirfd(tcp, tcp->u_arg[0]);
1914 printpath(tcp, tcp->u_arg[1]);
1916 print_dirfd(tcp, tcp->u_arg[2]);
1917 printpath(tcp, tcp->u_arg[3]);
1923 sys_chown(struct tcb *tcp)
1925 if (entering(tcp)) {
1926 printpath(tcp, tcp->u_arg[0]);
1927 printuid(", ", tcp->u_arg[1]);
1928 printuid(", ", tcp->u_arg[2]);
1934 sys_fchownat(struct tcb *tcp)
1936 if (entering(tcp)) {
1937 print_dirfd(tcp, tcp->u_arg[0]);
1938 printpath(tcp, tcp->u_arg[1]);
1939 printuid(", ", tcp->u_arg[2]);
1940 printuid(", ", tcp->u_arg[3]);
1942 printflags(at_flags, tcp->u_arg[4], "AT_???");
1948 sys_fchown(struct tcb *tcp)
1950 if (entering(tcp)) {
1951 printfd(tcp, tcp->u_arg[0]);
1952 printuid(", ", tcp->u_arg[1]);
1953 printuid(", ", tcp->u_arg[2]);
1959 decode_chmod(struct tcb *tcp, int offset)
1961 if (entering(tcp)) {
1962 printpath(tcp, tcp->u_arg[offset]);
1963 tprintf(", %#lo", tcp->u_arg[offset + 1]);
1969 sys_chmod(struct tcb *tcp)
1971 return decode_chmod(tcp, 0);
1975 sys_fchmodat(struct tcb *tcp)
1978 print_dirfd(tcp, tcp->u_arg[0]);
1979 return decode_chmod(tcp, 1);
1983 sys_fchmod(struct tcb *tcp)
1985 if (entering(tcp)) {
1986 printfd(tcp, tcp->u_arg[0]);
1987 tprintf(", %#lo", tcp->u_arg[1]);
1994 sys_osf_utimes(struct tcb *tcp)
1996 if (entering(tcp)) {
1997 printpath(tcp, tcp->u_arg[0]);
1999 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2006 decode_utimes(struct tcb *tcp, int offset, int special)
2008 if (entering(tcp)) {
2009 printpath(tcp, tcp->u_arg[offset]);
2011 if (tcp->u_arg[offset + 1] == 0)
2015 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2016 BITNESS_CURRENT, special);
2018 printtv_bitness(tcp, tcp->u_arg[offset + 1]
2019 + sizeof(struct timeval),
2020 BITNESS_CURRENT, special);
2028 sys_utimes(struct tcb *tcp)
2030 return decode_utimes(tcp, 0, 0);
2034 sys_futimesat(struct tcb *tcp)
2037 print_dirfd(tcp, tcp->u_arg[0]);
2038 return decode_utimes(tcp, 1, 0);
2042 sys_utimensat(struct tcb *tcp)
2044 if (entering(tcp)) {
2045 print_dirfd(tcp, tcp->u_arg[0]);
2046 decode_utimes(tcp, 1, 1);
2048 printflags(at_flags, tcp->u_arg[3], "AT_???");
2054 sys_utime(struct tcb *tcp)
2060 unsigned wordsize = current_wordsize;
2062 if (entering(tcp)) {
2063 printpath(tcp, tcp->u_arg[0]);
2067 else if (!verbose(tcp))
2068 tprintf("%#lx", tcp->u_arg[1]);
2069 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
2071 else if (wordsize == sizeof u.utl[0]) {
2072 tprintf("[%s,", sprinttime(u.utl[0]));
2073 tprintf(" %s]", sprinttime(u.utl[1]));
2075 else if (wordsize == sizeof u.uti[0]) {
2076 tprintf("[%s,", sprinttime(u.uti[0]));
2077 tprintf(" %s]", sprinttime(u.uti[1]));
2086 decode_mknod(struct tcb *tcp, int offset)
2088 int mode = tcp->u_arg[offset + 1];
2090 if (entering(tcp)) {
2091 printpath(tcp, tcp->u_arg[offset]);
2092 tprintf(", %s", sprintmode(mode));
2093 switch (mode & S_IFMT) {
2097 if (current_personality == 1)
2098 tprintf(", makedev(%lu, %lu)",
2099 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2100 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
2103 tprintf(", makedev(%lu, %lu)",
2104 (unsigned long) major(tcp->u_arg[offset + 2]),
2105 (unsigned long) minor(tcp->u_arg[offset + 2]));
2115 sys_mknod(struct tcb *tcp)
2117 return decode_mknod(tcp, 0);
2121 sys_mknodat(struct tcb *tcp)
2124 print_dirfd(tcp, tcp->u_arg[0]);
2125 return decode_mknod(tcp, 1);
2129 printdir(struct tcb *tcp, long addr)
2133 if (!verbose(tcp)) {
2134 tprintf("%#lx", addr);
2137 if (umove(tcp, addr, &d) < 0) {
2141 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
2143 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2148 sys_readdir(struct tcb *tcp)
2150 if (entering(tcp)) {
2151 printfd(tcp, tcp->u_arg[0]);
2154 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2155 tprintf("%#lx", tcp->u_arg[1]);
2157 printdir(tcp, tcp->u_arg[1]);
2158 /* Not much point in printing this out, it is always 1. */
2159 if (tcp->u_arg[2] != 1)
2160 tprintf(", %lu", tcp->u_arg[2]);
2165 static const struct xlat direnttypes[] = {
2166 { DT_UNKNOWN, "DT_UNKNOWN" },
2167 { DT_FIFO, "DT_FIFO" },
2168 { DT_CHR, "DT_CHR" },
2169 { DT_DIR, "DT_DIR" },
2170 { DT_BLK, "DT_BLK" },
2171 { DT_REG, "DT_REG" },
2172 { DT_LNK, "DT_LNK" },
2173 { DT_SOCK, "DT_SOCK" },
2174 { DT_WHT, "DT_WHT" },
2179 sys_getdents(struct tcb *tcp)
2181 int i, len, dents = 0;
2184 if (entering(tcp)) {
2185 printfd(tcp, tcp->u_arg[0]);
2189 if (syserror(tcp) || !verbose(tcp)) {
2190 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2194 /* Beware of insanely large or negative values in tcp->u_rval */
2195 if (tcp->u_rval > 1024*1024)
2197 if (tcp->u_rval < 0)
2199 buf = len ? malloc(len) : NULL;
2201 die_out_of_memory();
2202 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2203 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2209 for (i = 0; i < len;) {
2210 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2212 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2213 i ? " " : "", d->d_ino, d->d_off);
2214 tprintf("d_reclen=%u, d_name=\"%s\"}",
2215 d->d_reclen, d->d_name);
2218 tprints("/* d_reclen == 0, problem here */");
2227 tprintf("/* %u entries */", dents);
2228 tprintf(", %lu", tcp->u_arg[2]);
2233 #if _LFS64_LARGEFILE
2235 sys_getdents64(struct tcb *tcp)
2237 int i, len, dents = 0;
2240 if (entering(tcp)) {
2241 printfd(tcp, tcp->u_arg[0]);
2245 if (syserror(tcp) || !verbose(tcp)) {
2246 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2251 /* Beware of insanely large or negative tcp->u_rval */
2252 if (tcp->u_rval > 1024*1024)
2254 if (tcp->u_rval < 0)
2256 buf = len ? malloc(len) : NULL;
2258 die_out_of_memory();
2260 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2261 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2267 for (i = 0; i < len;) {
2268 struct dirent64 *d = (struct dirent64 *) &buf[i];
2270 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
2275 printxval(direnttypes, d->d_type, "DT_???");
2277 tprintf("d_reclen=%u, d_name=\"%s\"}",
2278 d->d_reclen, d->d_name);
2281 tprints("/* d_reclen == 0, problem here */");
2290 tprintf("/* %u entries */", dents);
2291 tprintf(", %lu", tcp->u_arg[2]);
2298 sys_getcwd(struct tcb *tcp)
2302 tprintf("%#lx", tcp->u_arg[0]);
2304 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2305 tprintf(", %lu", tcp->u_arg[1]);
2310 #ifdef HAVE_SYS_ASYNCH_H
2313 sys_aioread(struct tcb *tcp)
2315 struct aio_result_t res;
2317 if (entering(tcp)) {
2318 tprintf("%lu, ", tcp->u_arg[0]);
2321 tprintf("%#lx", tcp->u_arg[1]);
2323 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2324 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2325 printxval(whence, tcp->u_arg[4], "L_???");
2326 if (syserror(tcp) || tcp->u_arg[5] == 0
2327 || umove(tcp, tcp->u_arg[5], &res) < 0)
2328 tprintf(", %#lx", tcp->u_arg[5]);
2330 tprintf(", {aio_return %d aio_errno %d}",
2331 res.aio_return, res.aio_errno);
2337 sys_aiowrite(struct tcb *tcp)
2339 struct aio_result_t res;
2341 if (entering(tcp)) {
2342 tprintf("%lu, ", tcp->u_arg[0]);
2343 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2344 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2345 printxval(whence, tcp->u_arg[4], "L_???");
2348 if (tcp->u_arg[5] == 0)
2350 else if (syserror(tcp)
2351 || umove(tcp, tcp->u_arg[5], &res) < 0)
2352 tprintf(", %#lx", tcp->u_arg[5]);
2354 tprintf(", {aio_return %d aio_errno %d}",
2355 res.aio_return, res.aio_errno);
2361 sys_aiowait(struct tcb *tcp)
2364 printtv(tcp, tcp->u_arg[0]);
2369 sys_aiocancel(struct tcb *tcp)
2371 struct aio_result_t res;
2374 if (tcp->u_arg[0] == 0)
2376 else if (syserror(tcp)
2377 || umove(tcp, tcp->u_arg[0], &res) < 0)
2378 tprintf("%#lx", tcp->u_arg[0]);
2380 tprintf("{aio_return %d aio_errno %d}",
2381 res.aio_return, res.aio_errno);
2386 #endif /* HAVE_SYS_ASYNCH_H */
2388 static const struct xlat xattrflags[] = {
2390 { XATTR_CREATE, "XATTR_CREATE" },
2391 { XATTR_REPLACE, "XATTR_REPLACE" },
2397 print_xattr_val(struct tcb *tcp, int failed,
2399 unsigned long insize,
2403 unsigned long capacity = 4 * size + 1;
2404 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2405 if (buf == NULL || /* probably a bogus size argument */
2406 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2410 unsigned char *out = buf;
2411 unsigned char *in = &buf[3 * size];
2413 for (i = 0; i < size; ++i) {
2417 #define tohex(n) "0123456789abcdef"[n]
2420 *out++ = tohex(in[i] / 16);
2421 *out++ = tohex(in[i] % 16);
2424 /* Don't print terminating NUL if there is one. */
2425 if (i > 0 && in[i - 1] == '\0')
2428 tprintf(", \"%s\", %ld", buf, insize);
2433 tprintf(", 0x%lx, %ld", arg, insize);
2437 sys_setxattr(struct tcb *tcp)
2439 if (entering(tcp)) {
2440 printpath(tcp, tcp->u_arg[0]);
2442 printstr(tcp, tcp->u_arg[1], -1);
2443 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2445 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2451 sys_fsetxattr(struct tcb *tcp)
2453 if (entering(tcp)) {
2454 printfd(tcp, tcp->u_arg[0]);
2456 printstr(tcp, tcp->u_arg[1], -1);
2457 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2459 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2465 sys_getxattr(struct tcb *tcp)
2467 if (entering(tcp)) {
2468 printpath(tcp, tcp->u_arg[0]);
2470 printstr(tcp, tcp->u_arg[1], -1);
2472 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2479 sys_fgetxattr(struct tcb *tcp)
2481 if (entering(tcp)) {
2482 printfd(tcp, tcp->u_arg[0]);
2484 printstr(tcp, tcp->u_arg[1], -1);
2486 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2493 print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2495 if (syserror(tcp)) {
2496 tprintf("%#lx", addr);
2502 (size < tcp->u_rval) ? size : tcp->u_rval;
2503 printstr(tcp, addr, len);
2506 tprintf(", %lu", size);
2510 sys_listxattr(struct tcb *tcp)
2512 if (entering(tcp)) {
2513 printpath(tcp, tcp->u_arg[0]);
2516 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2522 sys_flistxattr(struct tcb *tcp)
2524 if (entering(tcp)) {
2525 printfd(tcp, tcp->u_arg[0]);
2528 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2534 sys_removexattr(struct tcb *tcp)
2536 if (entering(tcp)) {
2537 printpath(tcp, tcp->u_arg[0]);
2539 printstr(tcp, tcp->u_arg[1], -1);
2545 sys_fremovexattr(struct tcb *tcp)
2547 if (entering(tcp)) {
2548 printfd(tcp, tcp->u_arg[0]);
2550 printstr(tcp, tcp->u_arg[1], -1);
2555 static const struct xlat advise[] = {
2556 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2557 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2558 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2559 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2560 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2561 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2566 sys_fadvise64(struct tcb *tcp)
2568 if (entering(tcp)) {
2570 printfd(tcp, tcp->u_arg[0]);
2572 argn = printllval(tcp, "%lld", 1);
2573 tprintf(", %ld, ", tcp->u_arg[argn++]);
2574 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2580 sys_fadvise64_64(struct tcb *tcp)
2582 if (entering(tcp)) {
2584 printfd(tcp, tcp->u_arg[0]);
2586 #if defined ARM || defined POWERPC
2587 argn = printllval(tcp, "%lld, ", 2);
2589 argn = printllval(tcp, "%lld, ", 1);
2591 argn = printllval(tcp, "%lld, ", argn);
2592 #if defined ARM || defined POWERPC
2593 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
2595 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2601 static const struct xlat inotify_modes[] = {
2602 { 0x00000001, "IN_ACCESS" },
2603 { 0x00000002, "IN_MODIFY" },
2604 { 0x00000004, "IN_ATTRIB" },
2605 { 0x00000008, "IN_CLOSE_WRITE"},
2606 { 0x00000010, "IN_CLOSE_NOWRITE"},
2607 { 0x00000020, "IN_OPEN" },
2608 { 0x00000040, "IN_MOVED_FROM" },
2609 { 0x00000080, "IN_MOVED_TO" },
2610 { 0x00000100, "IN_CREATE" },
2611 { 0x00000200, "IN_DELETE" },
2612 { 0x00000400, "IN_DELETE_SELF"},
2613 { 0x00000800, "IN_MOVE_SELF" },
2614 { 0x00002000, "IN_UNMOUNT" },
2615 { 0x00004000, "IN_Q_OVERFLOW" },
2616 { 0x00008000, "IN_IGNORED" },
2617 { 0x01000000, "IN_ONLYDIR" },
2618 { 0x02000000, "IN_DONT_FOLLOW"},
2619 { 0x20000000, "IN_MASK_ADD" },
2620 { 0x40000000, "IN_ISDIR" },
2621 { 0x80000000, "IN_ONESHOT" },
2625 static const struct xlat inotify_init_flags[] = {
2626 { 0x00000800, "IN_NONBLOCK" },
2627 { 0x00080000, "IN_CLOEXEC" },
2632 sys_inotify_add_watch(struct tcb *tcp)
2634 if (entering(tcp)) {
2635 printfd(tcp, tcp->u_arg[0]);
2637 printpath(tcp, tcp->u_arg[1]);
2639 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2645 sys_inotify_rm_watch(struct tcb *tcp)
2647 if (entering(tcp)) {
2648 printfd(tcp, tcp->u_arg[0]);
2649 tprintf(", %d", (int) tcp->u_arg[1]);
2655 sys_inotify_init1(struct tcb *tcp)
2658 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
2663 sys_fallocate(struct tcb *tcp)
2665 if (entering(tcp)) {
2667 printfd(tcp, tcp->u_arg[0]); /* fd */
2669 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
2670 argn = printllval(tcp, "%llu, ", 2); /* offset */
2671 printllval(tcp, "%llu", argn); /* len */
2676 #ifndef SWAP_FLAG_PREFER
2677 # define SWAP_FLAG_PREFER 0x8000
2679 #ifndef SWAP_FLAG_DISCARD
2680 # define SWAP_FLAG_DISCARD 0x10000
2682 static const struct xlat swap_flags[] = {
2683 { SWAP_FLAG_PREFER, "SWAP_FLAG_PREFER" },
2684 { SWAP_FLAG_DISCARD, "SWAP_FLAG_DISCARD" },
2689 sys_swapon(struct tcb *tcp)
2691 if (entering(tcp)) {
2692 int flags = tcp->u_arg[1];
2693 printpath(tcp, tcp->u_arg[0]);
2695 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2697 if (flags & SWAP_FLAG_PREFER)
2698 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);