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 struct kernel_dirent {
40 unsigned short d_reclen;
46 unsigned short st_dev;
48 unsigned short st_mode;
50 unsigned short st_uid;
51 unsigned short st_gid;
52 unsigned short st_rdev;
55 unsigned int __unused1;
57 unsigned int __unused2;
59 unsigned int __unused3;
62 unsigned int __unused4[2];
69 unsigned int st_nlink;
79 unsigned long __unused4[2];
82 # define stat kernel_stat
83 # include <asm/stat.h>
95 # define dev_t __kernel_dev_t
96 # define ino_t __kernel_ino_t
97 # define mode_t __kernel_mode_t
98 # define nlink_t __kernel_nlink_t
99 # define uid_t __kernel_uid_t
100 # define gid_t __kernel_gid_t
101 # define off_t __kernel_off_t
102 # define loff_t __kernel_loff_t
104 # include <asm/stat.h>
117 # define mode_t mode_t
118 # define nlink_t nlink_t
122 # define loff_t loff_t
125 #ifdef HPPA /* asm-parisc/stat.h defines stat64 */
128 #define stat libc_stat
129 #define stat64 libc_stat64
130 #include <sys/stat.h>
133 /* These might be macros. */
138 # define stat64 hpux_stat64
144 #ifdef HAVE_SYS_VFS_H
145 # include <sys/vfs.h>
148 #ifdef HAVE_LINUX_XATTR_H
149 # include <linux/xattr.h>
151 # define XATTR_CREATE 1
152 # define XATTR_REPLACE 2
157 # ifdef HAVE_INTTYPES_H
158 # include <inttypes.h>
160 # define PRId64 "lld"
161 # define PRIu64 "llu"
165 #if HAVE_LONG_LONG_OFF_T
167 * Ugly hacks for systems that have typedef long long off_t
171 # define HAVE_STAT64 1 /* Ugly hack */
173 # define sys_stat64 sys_stat
174 # define sys_fstat64 sys_fstat
175 # define sys_lstat64 sys_lstat
176 # define sys_lseek64 sys_lseek
177 # define sys_truncate64 sys_truncate
178 # define sys_ftruncate64 sys_ftruncate
181 #ifdef MAJOR_IN_SYSMACROS
182 # include <sys/sysmacros.h>
185 #ifdef MAJOR_IN_MKDEV
186 # include <sys/mkdev.h>
189 #ifdef HAVE_SYS_ASYNCH_H
190 # include <sys/asynch.h>
194 const struct xlat open_access_modes[] = {
195 { O_RDONLY, "O_RDONLY" },
196 { O_WRONLY, "O_WRONLY" },
197 { O_RDWR, "O_RDWR" },
199 { O_ACCMODE, "O_ACCMODE" },
204 const struct xlat open_mode_flags[] = {
205 { O_CREAT, "O_CREAT" },
206 { O_EXCL, "O_EXCL" },
207 { O_NOCTTY, "O_NOCTTY" },
208 { O_TRUNC, "O_TRUNC" },
209 { O_APPEND, "O_APPEND" },
210 { O_NONBLOCK, "O_NONBLOCK" },
212 { O_SYNC, "O_SYNC" },
215 { O_ASYNC, "O_ASYNC" },
218 { O_DSYNC, "O_DSYNC" },
221 { O_RSYNC, "O_RSYNC" },
223 #if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
224 { O_NDELAY, "O_NDELAY" },
227 { O_PRIV, "O_PRIV" },
230 { O_DIRECT, "O_DIRECT" },
233 # if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
236 # define O_LARGEFILE 0x40000
237 # elif defined X86_64 || defined S390X
238 # define O_LARGEFILE 0100000
242 { O_LARGEFILE, "O_LARGEFILE" },
246 { O_DIRECTORY, "O_DIRECTORY" },
249 { O_NOFOLLOW, "O_NOFOLLOW" },
252 { O_NOATIME, "O_NOATIME" },
255 { O_CLOEXEC, "O_CLOEXEC" },
258 { FNDELAY, "FNDELAY" },
261 { FAPPEND, "FAPPEND" },
267 { FDEFER, "FDEFER" },
270 { FASYNC, "FASYNC" },
273 { FSHLOCK, "FSHLOCK" },
276 { FEXLOCK, "FEXLOCK" },
279 { FCREAT, "FCREAT" },
282 { FTRUNC, "FTRUNC" },
294 { FNOCTTY, "FNOCTTY" },
297 { O_SHLOCK, "O_SHLOCK" },
300 { O_EXLOCK, "O_EXLOCK" },
307 # define AT_FDCWD -100
310 /* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
311 * extension to get the right value. We do this by declaring fd as int here.
314 print_dirfd(struct tcb *tcp, int fd)
317 tprints("AT_FDCWD, ");
325 * low bits of the open(2) flags define access mode,
326 * other bits are real flags.
329 sprint_open_modes(mode_t flags)
331 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
335 const struct xlat *x;
338 p = stpcpy(outstr, "flags");
339 str = xlookup(open_access_modes, flags & 3);
349 for (x = open_mode_flags; x->str; x++) {
350 if ((flags & x->val) == x->val) {
352 p = stpcpy(p, x->str);
359 /* flags is still nonzero */
361 sprintf(p, "%#x", flags);
366 tprint_open_modes(mode_t flags)
368 tprints(sprint_open_modes(flags) + sizeof("flags"));
372 decode_open(struct tcb *tcp, int offset)
375 printpath(tcp, tcp->u_arg[offset]);
378 tprint_open_modes(tcp->u_arg[offset + 1]);
379 if (tcp->u_arg[offset + 1] & O_CREAT) {
381 tprintf(", %#lo", tcp->u_arg[offset + 2]);
388 sys_open(struct tcb *tcp)
390 return decode_open(tcp, 0);
394 sys_openat(struct tcb *tcp)
397 print_dirfd(tcp, tcp->u_arg[0]);
398 return decode_open(tcp, 1);
402 static const struct xlat openmodessol[] = {
406 { 0x80, "O_NONBLOCK" },
408 { 0x100, "O_CREAT" },
409 { 0x200, "O_TRUNC" },
411 { 0x800, "O_NOCTTY" },
414 { 0x8000, "O_RSYNC" },
416 { 0x1000, "O_PRIV" },
421 solaris_open(struct tcb *tcp)
424 printpath(tcp, tcp->u_arg[0]);
427 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
428 if (tcp->u_arg[1] & 0x100) {
430 tprintf(", %#lo", tcp->u_arg[2]);
439 sys_creat(struct tcb *tcp)
442 printpath(tcp, tcp->u_arg[0]);
443 tprintf(", %#lo", tcp->u_arg[1]);
448 static const struct xlat access_flags[] = {
454 { EFF_ONLY_OK, "EFF_ONLY_OK" },
463 decode_access(struct tcb *tcp, int offset)
466 printpath(tcp, tcp->u_arg[offset]);
468 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
474 sys_access(struct tcb *tcp)
476 return decode_access(tcp, 0);
480 sys_faccessat(struct tcb *tcp)
483 print_dirfd(tcp, tcp->u_arg[0]);
484 return decode_access(tcp, 1);
488 sys_umask(struct tcb *tcp)
491 tprintf("%#lo", tcp->u_arg[0]);
496 static const struct xlat whence[] = {
497 { SEEK_SET, "SEEK_SET" },
498 { SEEK_CUR, "SEEK_CUR" },
499 { SEEK_END, "SEEK_END" },
503 #ifndef HAVE_LONG_LONG_OFF_T
504 #if defined (LINUX_MIPSN32)
506 sys_lseek(struct tcb *tcp)
512 printfd(tcp, tcp->u_arg[0]);
514 offset = tcp->ext_arg[1];
515 _whence = tcp->u_arg[2];
516 if (_whence == SEEK_SET)
517 tprintf("%llu, ", offset);
519 tprintf("%lld, ", offset);
520 printxval(whence, _whence, "SEEK_???");
522 return RVAL_UDECIMAL;
524 #else /* !LINUX_MIPSN32 */
526 sys_lseek(struct tcb *tcp)
532 printfd(tcp, tcp->u_arg[0]);
534 offset = tcp->u_arg[1];
535 _whence = tcp->u_arg[2];
536 if (_whence == SEEK_SET)
537 tprintf("%lu, ", offset);
539 tprintf("%ld, ", offset);
540 printxval(whence, _whence, "SEEK_???");
542 return RVAL_UDECIMAL;
544 #endif /* LINUX_MIPSN32 */
548 sys_llseek(struct tcb *tcp)
551 printfd(tcp, tcp->u_arg[0]);
553 * This one call takes explicitly two 32-bit arguments hi, lo,
554 * rather than one 64-bit argument for which LONG_LONG works
555 * appropriate for the native byte order.
557 if (tcp->u_arg[4] == SEEK_SET)
559 ((long long int) tcp->u_arg[1]) << 32 |
560 (unsigned long long) (unsigned) tcp->u_arg[2]);
563 ((long long int) tcp->u_arg[1]) << 32 |
564 (unsigned long long) (unsigned) tcp->u_arg[2]);
568 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
569 tprintf("%#lx, ", tcp->u_arg[3]);
571 tprintf("[%llu], ", off);
572 printxval(whence, tcp->u_arg[4], "SEEK_???");
578 sys_readahead(struct tcb *tcp)
582 printfd(tcp, tcp->u_arg[0]);
584 argn = printllval(tcp, "%lld", 1);
585 tprintf(", %ld", tcp->u_arg[argn]);
590 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
592 sys_lseek64(struct tcb *tcp)
596 printfd(tcp, tcp->u_arg[0]);
598 if (tcp->u_arg[3] == SEEK_SET)
599 argn = printllval(tcp, "%llu, ", 1);
601 argn = printllval(tcp, "%lld, ", 1);
602 printxval(whence, tcp->u_arg[argn], "SEEK_???");
604 return RVAL_LUDECIMAL;
608 #ifndef HAVE_LONG_LONG_OFF_T
610 sys_truncate(struct tcb *tcp)
613 printpath(tcp, tcp->u_arg[0]);
614 tprintf(", %lu", tcp->u_arg[1]);
620 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
622 sys_truncate64(struct tcb *tcp)
625 printpath(tcp, tcp->u_arg[0]);
626 printllval(tcp, ", %llu", 1);
632 #ifndef HAVE_LONG_LONG_OFF_T
634 sys_ftruncate(struct tcb *tcp)
637 printfd(tcp, tcp->u_arg[0]);
638 tprintf(", %lu", tcp->u_arg[1]);
644 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
646 sys_ftruncate64(struct tcb *tcp)
649 printfd(tcp, tcp->u_arg[0]);
651 printllval(tcp, "%llu", 1);
659 static const struct xlat modetypes[] = {
660 { S_IFREG, "S_IFREG" },
661 { S_IFSOCK, "S_IFSOCK" },
662 { S_IFIFO, "S_IFIFO" },
663 { S_IFLNK, "S_IFLNK" },
664 { S_IFDIR, "S_IFDIR" },
665 { S_IFBLK, "S_IFBLK" },
666 { S_IFCHR, "S_IFCHR" },
676 if ((mode & S_IFMT) == 0)
678 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
679 sprintf(buf, "%#o", mode);
682 sprintf(buf, "%s%s%s%s", s,
683 (mode & S_ISUID) ? "|S_ISUID" : "",
684 (mode & S_ISGID) ? "|S_ISGID" : "",
685 (mode & S_ISVTX) ? "|S_ISVTX" : "");
686 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
688 sprintf(buf + strlen(buf), "|%#o", mode);
689 s = (*buf == '|') ? buf + 1 : buf;
705 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
706 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
707 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
709 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
722 int st_pad1[3]; /* network id */
731 int st_pad3; /* st_size, off_t expansion */
732 timestruct_t st_atime;
733 timestruct_t st_mtime;
734 timestruct_t st_ctime;
738 int st_pad4[8]; /* expansion area */
742 printstatsol(struct tcb *tcp, long addr)
744 struct solstat statbuf;
746 if (umove(tcp, addr, &statbuf) < 0) {
751 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
752 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
753 (unsigned long) (statbuf.st_dev & 0x3ffff),
754 (unsigned long) statbuf.st_ino,
755 sprintmode(statbuf.st_mode));
756 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
757 (unsigned long) statbuf.st_nlink,
758 (unsigned long) statbuf.st_uid,
759 (unsigned long) statbuf.st_gid);
760 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
761 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
764 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
765 switch (statbuf.st_mode & S_IFMT) {
766 case S_IFCHR: case S_IFBLK:
767 tprintf("st_rdev=makedev(%lu, %lu), ",
768 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
769 (unsigned long) (statbuf.st_rdev & 0x3ffff));
772 tprintf("st_size=%u, ", statbuf.st_size);
776 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
777 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
778 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
784 #if defined (SPARC64)
786 printstat_sparc64(struct tcb *tcp, long addr)
788 struct stat_sparc64 statbuf;
790 if (umove(tcp, addr, &statbuf) < 0) {
796 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
797 (unsigned long) major(statbuf.st_dev),
798 (unsigned long) minor(statbuf.st_dev),
799 (unsigned long) statbuf.st_ino,
800 sprintmode(statbuf.st_mode));
801 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
802 (unsigned long) statbuf.st_nlink,
803 (unsigned long) statbuf.st_uid,
804 (unsigned long) statbuf.st_gid);
805 tprintf("st_blksize=%lu, ",
806 (unsigned long) statbuf.st_blksize);
807 tprintf("st_blocks=%lu, ",
808 (unsigned long) statbuf.st_blocks);
811 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
812 switch (statbuf.st_mode & S_IFMT) {
813 case S_IFCHR: case S_IFBLK:
814 tprintf("st_rdev=makedev(%lu, %lu), ",
815 (unsigned long) major(statbuf.st_rdev),
816 (unsigned long) minor(statbuf.st_rdev));
819 tprintf("st_size=%lu, ", statbuf.st_size);
823 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
824 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
825 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
832 #endif /* LINUXSPARC */
834 #if defined POWERPC64
835 struct stat_powerpc32 {
838 unsigned int st_mode;
839 unsigned short st_nlink;
842 unsigned int st_rdev;
843 unsigned int st_size;
844 unsigned int st_blksize;
845 unsigned int st_blocks;
846 unsigned int st_atime;
847 unsigned int st_atime_nsec;
848 unsigned int st_mtime;
849 unsigned int st_mtime_nsec;
850 unsigned int st_ctime;
851 unsigned int st_ctime_nsec;
852 unsigned int __unused4;
853 unsigned int __unused5;
857 printstat_powerpc32(struct tcb *tcp, long addr)
859 struct stat_powerpc32 statbuf;
861 if (umove(tcp, addr, &statbuf) < 0) {
867 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
868 major(statbuf.st_dev), minor(statbuf.st_dev),
870 sprintmode(statbuf.st_mode));
871 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
872 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
873 tprintf("st_blksize=%u, ", statbuf.st_blksize);
874 tprintf("st_blocks=%u, ", statbuf.st_blocks);
877 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
878 switch (statbuf.st_mode & S_IFMT) {
879 case S_IFCHR: case S_IFBLK:
880 tprintf("st_rdev=makedev(%lu, %lu), ",
881 (unsigned long) major(statbuf.st_rdev),
882 (unsigned long) minor(statbuf.st_rdev));
885 tprintf("st_size=%u, ", statbuf.st_size);
889 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
890 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
891 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
897 #endif /* POWERPC64 */
899 static const struct xlat fileflags[] = {
904 #ifndef HAVE_LONG_LONG_OFF_T
906 realprintstat(struct tcb *tcp, struct stat *statbuf)
909 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
910 (unsigned long) major(statbuf->st_dev),
911 (unsigned long) minor(statbuf->st_dev),
912 (unsigned long) statbuf->st_ino,
913 sprintmode(statbuf->st_mode));
914 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
915 (unsigned long) statbuf->st_nlink,
916 (unsigned long) statbuf->st_uid,
917 (unsigned long) statbuf->st_gid);
918 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
919 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
921 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
922 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
926 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
927 switch (statbuf->st_mode & S_IFMT) {
928 case S_IFCHR: case S_IFBLK:
929 #ifdef HAVE_STRUCT_STAT_ST_RDEV
930 tprintf("st_rdev=makedev(%lu, %lu), ",
931 (unsigned long) major(statbuf->st_rdev),
932 (unsigned long) minor(statbuf->st_rdev));
933 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
934 tprintf("st_size=makedev(%lu, %lu), ",
935 (unsigned long) major(statbuf->st_size),
936 (unsigned long) minor(statbuf->st_size));
937 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
940 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
944 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
945 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
946 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
947 #if HAVE_STRUCT_STAT_ST_FLAGS
948 tprints(", st_flags=");
949 printflags(fileflags, statbuf->st_flags, "UF_???");
951 #if HAVE_STRUCT_STAT_ST_ACLCNT
952 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
954 #if HAVE_STRUCT_STAT_ST_LEVEL
955 tprintf(", st_level=%ld", statbuf->st_level);
957 #if HAVE_STRUCT_STAT_ST_FSTYPE
958 tprintf(", st_fstype=%.*s",
959 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
961 #if HAVE_STRUCT_STAT_ST_GEN
962 tprintf(", st_gen=%u", statbuf->st_gen);
972 printstat(struct tcb *tcp, long addr)
980 if (syserror(tcp) || !verbose(tcp)) {
981 tprintf("%#lx", addr);
986 if (current_personality == 1) {
987 printstatsol(tcp, addr);
991 else if (current_personality == 2) {
992 printstat_sparc64(tcp, addr);
996 #endif /* LINUXSPARC */
998 #if defined POWERPC64
999 if (current_personality == 1) {
1000 printstat_powerpc32(tcp, addr);
1005 if (umove(tcp, addr, &statbuf) < 0) {
1010 realprintstat(tcp, &statbuf);
1012 #endif /* !HAVE_LONG_LONG_OFF_T */
1014 #if !defined HAVE_STAT64 && defined X86_64
1016 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1017 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1018 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1019 * __GNUC__ is needed for the required __attribute__ below.
1022 unsigned long long st_dev;
1023 unsigned char __pad0[4];
1024 unsigned int __st_ino;
1025 unsigned int st_mode;
1026 unsigned int st_nlink;
1027 unsigned int st_uid;
1028 unsigned int st_gid;
1029 unsigned long long st_rdev;
1030 unsigned char __pad3[4];
1032 unsigned int st_blksize;
1033 unsigned long long st_blocks;
1034 unsigned int st_atime;
1035 unsigned int st_atime_nsec;
1036 unsigned int st_mtime;
1037 unsigned int st_mtime_nsec;
1038 unsigned int st_ctime;
1039 unsigned int st_ctime_nsec;
1040 unsigned long long st_ino;
1041 } __attribute__((packed));
1042 # define HAVE_STAT64 1
1043 # define STAT64_SIZE 96
1048 printstat64(struct tcb *tcp, long addr)
1050 struct stat64 statbuf;
1053 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1060 if (syserror(tcp) || !verbose(tcp)) {
1061 tprintf("%#lx", addr);
1066 if (current_personality == 1) {
1067 printstatsol(tcp, addr);
1071 else if (current_personality == 2) {
1072 printstat_sparc64(tcp, addr);
1076 #endif /* LINUXSPARC */
1079 if (current_personality == 0) {
1080 printstat(tcp, addr);
1085 if (umove(tcp, addr, &statbuf) < 0) {
1091 #ifdef HAVE_LONG_LONG
1092 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1094 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
1096 (unsigned long) major(statbuf.st_dev),
1097 (unsigned long) minor(statbuf.st_dev),
1098 #ifdef HAVE_LONG_LONG
1099 (unsigned long long) statbuf.st_ino,
1101 (unsigned long) statbuf.st_ino,
1103 sprintmode(statbuf.st_mode));
1104 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1105 (unsigned long) statbuf.st_nlink,
1106 (unsigned long) statbuf.st_uid,
1107 (unsigned long) statbuf.st_gid);
1108 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1109 tprintf("st_blksize=%lu, ",
1110 (unsigned long) statbuf.st_blksize);
1111 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1112 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
1113 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1114 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
1117 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1118 switch (statbuf.st_mode & S_IFMT) {
1119 case S_IFCHR: case S_IFBLK:
1120 #ifdef HAVE_STRUCT_STAT_ST_RDEV
1121 tprintf("st_rdev=makedev(%lu, %lu), ",
1122 (unsigned long) major(statbuf.st_rdev),
1123 (unsigned long) minor(statbuf.st_rdev));
1124 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
1125 tprintf("st_size=makedev(%lu, %lu), ",
1126 (unsigned long) major(statbuf.st_size),
1127 (unsigned long) minor(statbuf.st_size));
1128 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
1131 #ifdef HAVE_LONG_LONG
1132 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1134 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1139 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1140 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1141 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1142 #if HAVE_STRUCT_STAT_ST_FLAGS
1143 tprints(", st_flags=");
1144 printflags(fileflags, statbuf.st_flags, "UF_???");
1146 #if HAVE_STRUCT_STAT_ST_ACLCNT
1147 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1149 #if HAVE_STRUCT_STAT_ST_LEVEL
1150 tprintf(", st_level=%ld", statbuf.st_level);
1152 #if HAVE_STRUCT_STAT_ST_FSTYPE
1153 tprintf(", st_fstype=%.*s",
1154 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1156 #if HAVE_STRUCT_STAT_ST_GEN
1157 tprintf(", st_gen=%u", statbuf.st_gen);
1164 #endif /* HAVE_STAT64 */
1166 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1168 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
1170 newbuf->st_dev = oldbuf->st_dev;
1171 newbuf->st_ino = oldbuf->st_ino;
1172 newbuf->st_mode = oldbuf->st_mode;
1173 newbuf->st_nlink = oldbuf->st_nlink;
1174 newbuf->st_uid = oldbuf->st_uid;
1175 newbuf->st_gid = oldbuf->st_gid;
1176 newbuf->st_rdev = oldbuf->st_rdev;
1177 newbuf->st_size = oldbuf->st_size;
1178 newbuf->st_atime = oldbuf->st_atime;
1179 newbuf->st_mtime = oldbuf->st_mtime;
1180 newbuf->st_ctime = oldbuf->st_ctime;
1181 newbuf->st_blksize = 0; /* not supported in old_stat */
1182 newbuf->st_blocks = 0; /* not supported in old_stat */
1187 printoldstat(struct tcb *tcp, long addr)
1189 struct __old_kernel_stat statbuf;
1190 struct stat newstatbuf;
1196 if (syserror(tcp) || !verbose(tcp)) {
1197 tprintf("%#lx", addr);
1202 if (current_personality == 1) {
1203 printstatsol(tcp, addr);
1208 if (umove(tcp, addr, &statbuf) < 0) {
1213 convertoldstat(&statbuf, &newstatbuf);
1214 realprintstat(tcp, &newstatbuf);
1218 #ifndef HAVE_LONG_LONG_OFF_T
1220 sys_stat(struct tcb *tcp)
1222 if (entering(tcp)) {
1223 printpath(tcp, tcp->u_arg[0]);
1226 printstat(tcp, tcp->u_arg[1]);
1233 sys_stat64(struct tcb *tcp)
1236 if (entering(tcp)) {
1237 printpath(tcp, tcp->u_arg[0]);
1240 printstat64(tcp, tcp->u_arg[1]);
1244 return printargs(tcp);
1248 static const struct xlat fstatatflags[] = {
1249 #ifndef AT_SYMLINK_NOFOLLOW
1250 # define AT_SYMLINK_NOFOLLOW 0x100
1252 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1255 #define utimensatflags fstatatflags
1258 sys_newfstatat(struct tcb *tcp)
1260 if (entering(tcp)) {
1261 print_dirfd(tcp, tcp->u_arg[0]);
1262 printpath(tcp, tcp->u_arg[1]);
1266 if (current_personality == 0)
1267 printstat(tcp, tcp->u_arg[2]);
1269 printstat64(tcp, tcp->u_arg[2]);
1270 #elif defined HAVE_STAT64
1271 printstat64(tcp, tcp->u_arg[2]);
1273 printstat(tcp, tcp->u_arg[2]);
1276 printflags(fstatatflags, tcp->u_arg[3], "AT_???");
1281 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1283 sys_oldstat(struct tcb *tcp)
1285 if (entering(tcp)) {
1286 printpath(tcp, tcp->u_arg[0]);
1289 printoldstat(tcp, tcp->u_arg[1]);
1295 #ifndef HAVE_LONG_LONG_OFF_T
1297 sys_fstat(struct tcb *tcp)
1299 if (entering(tcp)) {
1300 printfd(tcp, tcp->u_arg[0]);
1303 printstat(tcp, tcp->u_arg[1]);
1310 sys_fstat64(struct tcb *tcp)
1313 if (entering(tcp)) {
1314 printfd(tcp, tcp->u_arg[0]);
1317 printstat64(tcp, tcp->u_arg[1]);
1321 return printargs(tcp);
1325 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1327 sys_oldfstat(struct tcb *tcp)
1329 if (entering(tcp)) {
1330 printfd(tcp, tcp->u_arg[0]);
1333 printoldstat(tcp, tcp->u_arg[1]);
1339 #ifndef HAVE_LONG_LONG_OFF_T
1341 sys_lstat(struct tcb *tcp)
1343 if (entering(tcp)) {
1344 printpath(tcp, tcp->u_arg[0]);
1347 printstat(tcp, tcp->u_arg[1]);
1354 sys_lstat64(struct tcb *tcp)
1357 if (entering(tcp)) {
1358 printpath(tcp, tcp->u_arg[0]);
1361 printstat64(tcp, tcp->u_arg[1]);
1365 return printargs(tcp);
1369 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT) && !defined(HAVE_LONG_LONG_OFF_T)
1371 sys_oldlstat(struct tcb *tcp)
1373 if (entering(tcp)) {
1374 printpath(tcp, tcp->u_arg[0]);
1377 printoldstat(tcp, tcp->u_arg[1]);
1384 #if defined(LINUXSPARC)
1387 sys_xstat(struct tcb *tcp)
1389 if (entering(tcp)) {
1390 tprintf("%ld, ", tcp->u_arg[0]);
1391 printpath(tcp, tcp->u_arg[1]);
1395 if (tcp->u_arg[0] == _STAT64_VER)
1396 printstat64 (tcp, tcp->u_arg[2]);
1399 printstat(tcp, tcp->u_arg[2]);
1405 sys_fxstat(struct tcb *tcp)
1408 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1411 if (tcp->u_arg[0] == _STAT64_VER)
1412 printstat64 (tcp, tcp->u_arg[2]);
1415 printstat(tcp, tcp->u_arg[2]);
1421 sys_lxstat(struct tcb *tcp)
1423 if (entering(tcp)) {
1424 tprintf("%ld, ", tcp->u_arg[0]);
1425 printpath(tcp, tcp->u_arg[1]);
1429 if (tcp->u_arg[0] == _STAT64_VER)
1430 printstat64 (tcp, tcp->u_arg[2]);
1433 printstat(tcp, tcp->u_arg[2]);
1439 sys_xmknod(struct tcb *tcp)
1441 int mode = tcp->u_arg[2];
1443 if (entering(tcp)) {
1444 tprintf("%ld, ", tcp->u_arg[0]);
1445 printpath(tcp, tcp->u_arg[1]);
1446 tprintf(", %s", sprintmode(mode));
1447 switch (mode & S_IFMT) {
1448 case S_IFCHR: case S_IFBLK:
1449 tprintf(", makedev(%lu, %lu)",
1450 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1451 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1460 # ifdef HAVE_SYS_ACL_H
1462 # include <sys/acl.h>
1464 static const struct xlat aclcmds[] = {
1466 { SETACL, "SETACL" },
1469 { GETACL, "GETACL" },
1472 { GETACLCNT, "GETACLCNT" },
1475 { ACL_GET, "ACL_GET" },
1478 { ACL_SET, "ACL_SET" },
1481 { ACL_CNT, "ACL_CNT" },
1487 sys_acl(struct tcb *tcp)
1489 if (entering(tcp)) {
1490 printpath(tcp, tcp->u_arg[0]);
1492 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1493 tprintf(", %ld", tcp->u_arg[2]);
1495 * FIXME - dump out the list of aclent_t's pointed to
1496 * by "tcp->u_arg[3]" if it's not NULL.
1499 tprintf(", %#lx", tcp->u_arg[3]);
1508 sys_facl(struct tcb *tcp)
1510 if (entering(tcp)) {
1511 tprintf("%ld, ", tcp->u_arg[0]);
1512 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1513 tprintf(", %ld", tcp->u_arg[2]);
1515 * FIXME - dump out the list of aclent_t's pointed to
1516 * by "tcp->u_arg[3]" if it's not NULL.
1519 tprintf(", %#lx", tcp->u_arg[3]);
1527 static const struct xlat aclipc[] = {
1529 { IPC_SHM, "IPC_SHM" },
1532 { IPC_SEM, "IPC_SEM" },
1535 { IPC_MSG, "IPC_MSG" },
1542 sys_aclipc(struct tcb *tcp)
1544 if (entering(tcp)) {
1545 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1546 tprintf(", %#lx, ", tcp->u_arg[1]);
1547 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1548 tprintf(", %ld", tcp->u_arg[3]);
1550 * FIXME - dump out the list of aclent_t's pointed to
1551 * by "tcp->u_arg[4]" if it's not NULL.
1554 tprintf(", %#lx", tcp->u_arg[4]);
1561 # endif /* HAVE_SYS_ACL_H */
1563 #endif /* LINUXSPARC */
1566 static const struct xlat fsmagic[] = {
1567 { 0x73757245, "CODA_SUPER_MAGIC" },
1568 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1569 { 0x1373, "DEVFS_SUPER_MAGIC" },
1570 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1571 { 0x414A53, "EFS_SUPER_MAGIC" },
1572 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1573 { 0xef53, "EXT2_SUPER_MAGIC" },
1574 { 0x137d, "EXT_SUPER_MAGIC" },
1575 { 0xf995e849, "HPFS_SUPER_MAGIC" },
1576 { 0x9660, "ISOFS_SUPER_MAGIC" },
1577 { 0x137f, "MINIX_SUPER_MAGIC" },
1578 { 0x138f, "MINIX_SUPER_MAGIC2" },
1579 { 0x2468, "MINIX2_SUPER_MAGIC" },
1580 { 0x2478, "MINIX2_SUPER_MAGIC2" },
1581 { 0x4d44, "MSDOS_SUPER_MAGIC" },
1582 { 0x564c, "NCP_SUPER_MAGIC" },
1583 { 0x6969, "NFS_SUPER_MAGIC" },
1584 { 0x9fa0, "PROC_SUPER_MAGIC" },
1585 { 0x002f, "QNX4_SUPER_MAGIC" },
1586 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1587 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1588 { 0x517b, "SMB_SUPER_MAGIC" },
1589 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1590 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1591 { 0x00011954, "UFS_MAGIC" },
1592 { 0x54190100, "UFS_CIGAM" },
1593 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
1594 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
1595 { 0x62656572, "SYSFS_MAGIC" },
1602 sprintfstype(int magic)
1604 static char buf[32];
1607 s = xlookup(fsmagic, magic);
1609 sprintf(buf, "\"%s\"", s);
1612 sprintf(buf, "%#x", magic);
1617 printstatfs(struct tcb *tcp, long addr)
1619 struct statfs statbuf;
1621 if (syserror(tcp) || !verbose(tcp)) {
1622 tprintf("%#lx", addr);
1625 if (umove(tcp, addr, &statbuf) < 0) {
1631 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1632 sprintfstype(statbuf.f_type),
1633 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1634 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1635 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
1636 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1639 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1640 sprintfstype(statbuf.f_type),
1641 (unsigned long)statbuf.f_bsize,
1642 (unsigned long)statbuf.f_blocks,
1643 (unsigned long)statbuf.f_bfree);
1644 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1645 (unsigned long)statbuf.f_bavail,
1646 (unsigned long)statbuf.f_files,
1647 (unsigned long)statbuf.f_ffree,
1648 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1649 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1651 #ifdef _STATFS_F_FRSIZE
1652 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1658 sys_statfs(struct tcb *tcp)
1660 if (entering(tcp)) {
1661 printpath(tcp, tcp->u_arg[0]);
1664 printstatfs(tcp, tcp->u_arg[1]);
1670 sys_fstatfs(struct tcb *tcp)
1672 if (entering(tcp)) {
1673 printfd(tcp, tcp->u_arg[0]);
1676 printstatfs(tcp, tcp->u_arg[1]);
1681 #if defined HAVE_STATFS64
1683 printstatfs64(struct tcb *tcp, long addr)
1685 struct statfs64 statbuf;
1687 if (syserror(tcp) || !verbose(tcp)) {
1688 tprintf("%#lx", addr);
1691 if (umove(tcp, addr, &statbuf) < 0) {
1695 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
1696 sprintfstype(statbuf.f_type),
1697 (unsigned long long)statbuf.f_bsize,
1698 (unsigned long long)statbuf.f_blocks,
1699 (unsigned long long)statbuf.f_bfree);
1700 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1701 (unsigned long long)statbuf.f_bavail,
1702 (unsigned long long)statbuf.f_files,
1703 (unsigned long long)statbuf.f_ffree,
1704 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1705 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1706 #ifdef _STATFS_F_FRSIZE
1707 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
1709 #ifdef _STATFS_F_FLAGS
1710 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1715 struct compat_statfs64 {
1727 uint32_t f_spare[4];
1729 #if defined(X86_64) || defined(IA64)
1730 __attribute__ ((packed, aligned(4)))
1735 printcompat_statfs64(struct tcb *tcp, long addr)
1737 struct compat_statfs64 statbuf;
1739 if (syserror(tcp) || !verbose(tcp)) {
1740 tprintf("%#lx", addr);
1743 if (umove(tcp, addr, &statbuf) < 0) {
1747 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1748 sprintfstype(statbuf.f_type),
1749 (unsigned long)statbuf.f_bsize,
1750 (unsigned long long)statbuf.f_blocks,
1751 (unsigned long long)statbuf.f_bfree);
1752 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1753 (unsigned long long)statbuf.f_bavail,
1754 (unsigned long long)statbuf.f_files,
1755 (unsigned long long)statbuf.f_ffree,
1756 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1757 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1758 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1759 tprintf(", f_flags=%lu", (unsigned long)statbuf.f_frsize);
1764 sys_statfs64(struct tcb *tcp)
1766 if (entering(tcp)) {
1767 printpath(tcp, tcp->u_arg[0]);
1768 tprintf(", %lu, ", tcp->u_arg[1]);
1770 if (tcp->u_arg[1] == sizeof(struct statfs64))
1771 printstatfs64(tcp, tcp->u_arg[2]);
1772 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1773 printcompat_statfs64(tcp, tcp->u_arg[2]);
1781 sys_fstatfs64(struct tcb *tcp)
1783 if (entering(tcp)) {
1784 printfd(tcp, tcp->u_arg[0]);
1785 tprintf(", %lu, ", tcp->u_arg[1]);
1787 if (tcp->u_arg[1] == sizeof(struct statfs64))
1788 printstatfs64(tcp, tcp->u_arg[2]);
1789 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1790 printcompat_statfs64(tcp, tcp->u_arg[2]);
1798 #if defined(__alpha)
1800 osf_statfs(struct tcb *tcp)
1802 if (entering(tcp)) {
1803 printpath(tcp, tcp->u_arg[0]);
1806 printstatfs(tcp, tcp->u_arg[1]);
1807 tprintf(", %lu", tcp->u_arg[2]);
1813 osf_fstatfs(struct tcb *tcp)
1815 if (entering(tcp)) {
1816 tprintf("%lu, ", tcp->u_arg[0]);
1818 printstatfs(tcp, tcp->u_arg[1]);
1819 tprintf(", %lu", tcp->u_arg[2]);
1828 sys_chdir(struct tcb *tcp)
1830 if (entering(tcp)) {
1831 printpath(tcp, tcp->u_arg[0]);
1837 decode_mkdir(struct tcb *tcp, int offset)
1839 if (entering(tcp)) {
1840 printpath(tcp, tcp->u_arg[offset]);
1841 tprintf(", %#lo", tcp->u_arg[offset + 1]);
1847 sys_mkdir(struct tcb *tcp)
1849 return decode_mkdir(tcp, 0);
1853 sys_mkdirat(struct tcb *tcp)
1856 print_dirfd(tcp, tcp->u_arg[0]);
1857 return decode_mkdir(tcp, 1);
1861 sys_link(struct tcb *tcp)
1863 if (entering(tcp)) {
1864 printpath(tcp, tcp->u_arg[0]);
1866 printpath(tcp, tcp->u_arg[1]);
1872 sys_linkat(struct tcb *tcp)
1874 if (entering(tcp)) {
1875 print_dirfd(tcp, tcp->u_arg[0]);
1876 printpath(tcp, tcp->u_arg[1]);
1878 print_dirfd(tcp, tcp->u_arg[2]);
1879 printpath(tcp, tcp->u_arg[3]);
1881 printfd(tcp, tcp->u_arg[4]);
1886 static const struct xlat unlinkatflags[] = {
1887 #ifndef AT_REMOVEDIR
1888 # define AT_REMOVEDIR 0x200
1890 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1895 sys_unlinkat(struct tcb *tcp)
1897 if (entering(tcp)) {
1898 print_dirfd(tcp, tcp->u_arg[0]);
1899 printpath(tcp, tcp->u_arg[1]);
1901 printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
1907 sys_symlinkat(struct tcb *tcp)
1909 if (entering(tcp)) {
1910 printpath(tcp, tcp->u_arg[0]);
1912 print_dirfd(tcp, tcp->u_arg[1]);
1913 printpath(tcp, tcp->u_arg[2]);
1919 decode_readlink(struct tcb *tcp, int offset)
1921 if (entering(tcp)) {
1922 printpath(tcp, tcp->u_arg[offset]);
1926 tprintf("%#lx", tcp->u_arg[offset + 1]);
1928 /* Used to use printpathn(), but readlink
1929 * neither includes NUL in the returned count,
1930 * nor actually writes it into memory.
1931 * printpathn() would decide on printing
1932 * "..." continuation based on garbage
1933 * past return buffer's end.
1935 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1936 tprintf(", %lu", tcp->u_arg[offset + 2]);
1942 sys_readlink(struct tcb *tcp)
1944 return decode_readlink(tcp, 0);
1948 sys_readlinkat(struct tcb *tcp)
1951 print_dirfd(tcp, tcp->u_arg[0]);
1952 return decode_readlink(tcp, 1);
1956 sys_renameat(struct tcb *tcp)
1958 if (entering(tcp)) {
1959 print_dirfd(tcp, tcp->u_arg[0]);
1960 printpath(tcp, tcp->u_arg[1]);
1962 print_dirfd(tcp, tcp->u_arg[2]);
1963 printpath(tcp, tcp->u_arg[3]);
1969 sys_chown(struct tcb *tcp)
1971 if (entering(tcp)) {
1972 printpath(tcp, tcp->u_arg[0]);
1973 printuid(", ", tcp->u_arg[1]);
1974 printuid(", ", tcp->u_arg[2]);
1980 sys_fchownat(struct tcb *tcp)
1982 if (entering(tcp)) {
1983 print_dirfd(tcp, tcp->u_arg[0]);
1984 printpath(tcp, tcp->u_arg[1]);
1985 printuid(", ", tcp->u_arg[2]);
1986 printuid(", ", tcp->u_arg[3]);
1988 printflags(fstatatflags, tcp->u_arg[4], "AT_???");
1994 sys_fchown(struct tcb *tcp)
1996 if (entering(tcp)) {
1997 printfd(tcp, tcp->u_arg[0]);
1998 printuid(", ", tcp->u_arg[1]);
1999 printuid(", ", tcp->u_arg[2]);
2005 decode_chmod(struct tcb *tcp, int offset)
2007 if (entering(tcp)) {
2008 printpath(tcp, tcp->u_arg[offset]);
2009 tprintf(", %#lo", tcp->u_arg[offset + 1]);
2015 sys_chmod(struct tcb *tcp)
2017 return decode_chmod(tcp, 0);
2021 sys_fchmodat(struct tcb *tcp)
2024 print_dirfd(tcp, tcp->u_arg[0]);
2025 return decode_chmod(tcp, 1);
2029 sys_fchmod(struct tcb *tcp)
2031 if (entering(tcp)) {
2032 printfd(tcp, tcp->u_arg[0]);
2033 tprintf(", %#lo", tcp->u_arg[1]);
2040 sys_osf_utimes(struct tcb *tcp)
2042 if (entering(tcp)) {
2043 printpath(tcp, tcp->u_arg[0]);
2045 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2052 decode_utimes(struct tcb *tcp, int offset, int special)
2054 if (entering(tcp)) {
2055 printpath(tcp, tcp->u_arg[offset]);
2057 if (tcp->u_arg[offset + 1] == 0)
2061 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2062 BITNESS_CURRENT, special);
2064 printtv_bitness(tcp, tcp->u_arg[offset + 1]
2065 + sizeof(struct timeval),
2066 BITNESS_CURRENT, special);
2074 sys_utimes(struct tcb *tcp)
2076 return decode_utimes(tcp, 0, 0);
2080 sys_futimesat(struct tcb *tcp)
2083 print_dirfd(tcp, tcp->u_arg[0]);
2084 return decode_utimes(tcp, 1, 0);
2088 sys_utimensat(struct tcb *tcp)
2090 if (entering(tcp)) {
2091 print_dirfd(tcp, tcp->u_arg[0]);
2092 decode_utimes(tcp, 1, 1);
2094 printflags(utimensatflags, tcp->u_arg[3], "AT_???");
2100 sys_utime(struct tcb *tcp)
2107 if (entering(tcp)) {
2108 printpath(tcp, tcp->u_arg[0]);
2112 else if (!verbose(tcp))
2113 tprintf("%#lx", tcp->u_arg[1]);
2114 else if (umoven(tcp, tcp->u_arg[1],
2115 2 * personality_wordsize[current_personality],
2118 else if (personality_wordsize[current_personality]
2119 == sizeof u.utl[0]) {
2120 tprintf("[%s,", sprinttime(u.utl[0]));
2121 tprintf(" %s]", sprinttime(u.utl[1]));
2123 else if (personality_wordsize[current_personality]
2124 == sizeof u.uti[0]) {
2125 tprintf("[%s,", sprinttime(u.uti[0]));
2126 tprintf(" %s]", sprinttime(u.uti[1]));
2135 decode_mknod(struct tcb *tcp, int offset)
2137 int mode = tcp->u_arg[offset + 1];
2139 if (entering(tcp)) {
2140 printpath(tcp, tcp->u_arg[offset]);
2141 tprintf(", %s", sprintmode(mode));
2142 switch (mode & S_IFMT) {
2143 case S_IFCHR: case S_IFBLK:
2145 if (current_personality == 1)
2146 tprintf(", makedev(%lu, %lu)",
2147 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2148 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
2151 tprintf(", makedev(%lu, %lu)",
2152 (unsigned long) major(tcp->u_arg[offset + 2]),
2153 (unsigned long) minor(tcp->u_arg[offset + 2]));
2163 sys_mknod(struct tcb *tcp)
2165 return decode_mknod(tcp, 0);
2169 sys_mknodat(struct tcb *tcp)
2172 print_dirfd(tcp, tcp->u_arg[0]);
2173 return decode_mknod(tcp, 1);
2178 sys_fsync(struct tcb *tcp)
2180 if (entering(tcp)) {
2181 printfd(tcp, tcp->u_arg[0]);
2188 printdir(struct tcb *tcp, long addr)
2192 if (!verbose(tcp)) {
2193 tprintf("%#lx", addr);
2196 if (umove(tcp, addr, &d) < 0) {
2200 tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
2202 printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
2207 sys_readdir(struct tcb *tcp)
2209 if (entering(tcp)) {
2210 printfd(tcp, tcp->u_arg[0]);
2213 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2214 tprintf("%#lx", tcp->u_arg[1]);
2216 printdir(tcp, tcp->u_arg[1]);
2217 /* Not much point in printing this out, it is always 1. */
2218 if (tcp->u_arg[2] != 1)
2219 tprintf(", %lu", tcp->u_arg[2]);
2225 static const struct xlat direnttypes[] = {
2226 { DT_UNKNOWN, "DT_UNKNOWN" },
2227 { DT_FIFO, "DT_FIFO" },
2228 { DT_CHR, "DT_CHR" },
2229 { DT_DIR, "DT_DIR" },
2230 { DT_BLK, "DT_BLK" },
2231 { DT_REG, "DT_REG" },
2232 { DT_LNK, "DT_LNK" },
2233 { DT_SOCK, "DT_SOCK" },
2234 { DT_WHT, "DT_WHT" },
2240 sys_getdents(struct tcb *tcp)
2242 int i, len, dents = 0;
2245 if (entering(tcp)) {
2246 printfd(tcp, tcp->u_arg[0]);
2250 if (syserror(tcp) || !verbose(tcp)) {
2251 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2255 /* Beware of insanely large or negative values in tcp->u_rval */
2256 if (tcp->u_rval > 1024*1024)
2258 if (tcp->u_rval < 0)
2260 buf = len ? malloc(len) : NULL;
2262 die_out_of_memory();
2263 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2264 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2270 for (i = 0; i < len;) {
2271 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2273 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2274 i ? " " : "", d->d_ino, d->d_off);
2275 tprintf("d_reclen=%u, d_name=\"%s\"}",
2276 d->d_reclen, d->d_name);
2279 tprints("/* d_reclen == 0, problem here */");
2288 tprintf("/* %u entries */", dents);
2289 tprintf(", %lu", tcp->u_arg[2]);
2295 #if _LFS64_LARGEFILE
2297 sys_getdents64(struct tcb *tcp)
2299 int i, len, dents = 0;
2302 if (entering(tcp)) {
2303 printfd(tcp, tcp->u_arg[0]);
2307 if (syserror(tcp) || !verbose(tcp)) {
2308 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2313 /* Beware of insanely large or negative tcp->u_rval */
2314 if (tcp->u_rval > 1024*1024)
2316 if (tcp->u_rval < 0)
2318 buf = len ? malloc(len) : NULL;
2320 die_out_of_memory();
2322 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2323 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2329 for (i = 0; i < len;) {
2330 struct dirent64 *d = (struct dirent64 *) &buf[i];
2332 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
2337 printxval(direnttypes, d->d_type, "DT_???");
2339 tprintf("d_reclen=%u, d_name=\"%s\"}",
2340 d->d_reclen, d->d_name);
2343 tprints("/* d_reclen == 0, problem here */");
2352 tprintf("/* %u entries */", dents);
2353 tprintf(", %lu", tcp->u_arg[2]);
2361 sys_getcwd(struct tcb *tcp)
2365 tprintf("%#lx", tcp->u_arg[0]);
2367 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2368 tprintf(", %lu", tcp->u_arg[1]);
2374 #ifdef HAVE_SYS_ASYNCH_H
2377 sys_aioread(struct tcb *tcp)
2379 struct aio_result_t res;
2381 if (entering(tcp)) {
2382 tprintf("%lu, ", tcp->u_arg[0]);
2385 tprintf("%#lx", tcp->u_arg[1]);
2387 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2388 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2389 printxval(whence, tcp->u_arg[4], "L_???");
2390 if (syserror(tcp) || tcp->u_arg[5] == 0
2391 || umove(tcp, tcp->u_arg[5], &res) < 0)
2392 tprintf(", %#lx", tcp->u_arg[5]);
2394 tprintf(", {aio_return %d aio_errno %d}",
2395 res.aio_return, res.aio_errno);
2401 sys_aiowrite(struct tcb *tcp)
2403 struct aio_result_t res;
2405 if (entering(tcp)) {
2406 tprintf("%lu, ", tcp->u_arg[0]);
2407 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2408 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2409 printxval(whence, tcp->u_arg[4], "L_???");
2412 if (tcp->u_arg[5] == 0)
2414 else if (syserror(tcp)
2415 || umove(tcp, tcp->u_arg[5], &res) < 0)
2416 tprintf(", %#lx", tcp->u_arg[5]);
2418 tprintf(", {aio_return %d aio_errno %d}",
2419 res.aio_return, res.aio_errno);
2425 sys_aiowait(struct tcb *tcp)
2428 printtv(tcp, tcp->u_arg[0]);
2433 sys_aiocancel(struct tcb *tcp)
2435 struct aio_result_t res;
2438 if (tcp->u_arg[0] == 0)
2440 else if (syserror(tcp)
2441 || umove(tcp, tcp->u_arg[0], &res) < 0)
2442 tprintf("%#lx", tcp->u_arg[0]);
2444 tprintf("{aio_return %d aio_errno %d}",
2445 res.aio_return, res.aio_errno);
2450 #endif /* HAVE_SYS_ASYNCH_H */
2452 static const struct xlat xattrflags[] = {
2454 { XATTR_CREATE, "XATTR_CREATE" },
2455 { XATTR_REPLACE, "XATTR_REPLACE" },
2461 print_xattr_val(struct tcb *tcp, int failed,
2463 unsigned long insize,
2467 unsigned long capacity = 4 * size + 1;
2468 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2469 if (buf == NULL || /* probably a bogus size argument */
2470 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2474 unsigned char *out = buf;
2475 unsigned char *in = &buf[3 * size];
2477 for (i = 0; i < size; ++i) {
2481 #define tohex(n) "0123456789abcdef"[n]
2484 *out++ = tohex(in[i] / 16);
2485 *out++ = tohex(in[i] % 16);
2488 /* Don't print terminating NUL if there is one. */
2489 if (i > 0 && in[i - 1] == '\0')
2492 tprintf(", \"%s\", %ld", buf, insize);
2497 tprintf(", 0x%lx, %ld", arg, insize);
2501 sys_setxattr(struct tcb *tcp)
2503 if (entering(tcp)) {
2504 printpath(tcp, tcp->u_arg[0]);
2506 printstr(tcp, tcp->u_arg[1], -1);
2507 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2509 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2515 sys_fsetxattr(struct tcb *tcp)
2517 if (entering(tcp)) {
2518 printfd(tcp, tcp->u_arg[0]);
2520 printstr(tcp, tcp->u_arg[1], -1);
2521 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2523 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2529 sys_getxattr(struct tcb *tcp)
2531 if (entering(tcp)) {
2532 printpath(tcp, tcp->u_arg[0]);
2534 printstr(tcp, tcp->u_arg[1], -1);
2536 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2543 sys_fgetxattr(struct tcb *tcp)
2545 if (entering(tcp)) {
2546 printfd(tcp, tcp->u_arg[0]);
2548 printstr(tcp, tcp->u_arg[1], -1);
2550 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2557 sys_listxattr(struct tcb *tcp)
2559 if (entering(tcp)) {
2560 printpath(tcp, tcp->u_arg[0]);
2562 /* XXX Print value in format */
2563 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2569 sys_flistxattr(struct tcb *tcp)
2571 if (entering(tcp)) {
2572 printfd(tcp, tcp->u_arg[0]);
2574 /* XXX Print value in format */
2575 tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
2581 sys_removexattr(struct tcb *tcp)
2583 if (entering(tcp)) {
2584 printpath(tcp, tcp->u_arg[0]);
2586 printstr(tcp, tcp->u_arg[1], -1);
2592 sys_fremovexattr(struct tcb *tcp)
2594 if (entering(tcp)) {
2595 printfd(tcp, tcp->u_arg[0]);
2597 printstr(tcp, tcp->u_arg[1], -1);
2603 static const struct xlat advise[] = {
2604 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2605 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2606 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2607 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2608 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2609 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2615 sys_fadvise64(struct tcb *tcp)
2617 if (entering(tcp)) {
2619 printfd(tcp, tcp->u_arg[0]);
2621 argn = printllval(tcp, "%lld", 1);
2622 tprintf(", %ld, ", tcp->u_arg[argn++]);
2623 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2630 sys_fadvise64_64(struct tcb *tcp)
2632 if (entering(tcp)) {
2634 printfd(tcp, tcp->u_arg[0]);
2636 #if defined ARM || defined POWERPC
2637 argn = printllval(tcp, "%lld, ", 2);
2639 argn = printllval(tcp, "%lld, ", 1);
2641 argn = printllval(tcp, "%lld, ", argn);
2642 #if defined ARM || defined POWERPC
2643 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
2645 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2651 static const struct xlat inotify_modes[] = {
2652 { 0x00000001, "IN_ACCESS" },
2653 { 0x00000002, "IN_MODIFY" },
2654 { 0x00000004, "IN_ATTRIB" },
2655 { 0x00000008, "IN_CLOSE_WRITE"},
2656 { 0x00000010, "IN_CLOSE_NOWRITE"},
2657 { 0x00000020, "IN_OPEN" },
2658 { 0x00000040, "IN_MOVED_FROM" },
2659 { 0x00000080, "IN_MOVED_TO" },
2660 { 0x00000100, "IN_CREATE" },
2661 { 0x00000200, "IN_DELETE" },
2662 { 0x00000400, "IN_DELETE_SELF"},
2663 { 0x00000800, "IN_MOVE_SELF" },
2664 { 0x00002000, "IN_UNMOUNT" },
2665 { 0x00004000, "IN_Q_OVERFLOW" },
2666 { 0x00008000, "IN_IGNORED" },
2667 { 0x01000000, "IN_ONLYDIR" },
2668 { 0x02000000, "IN_DONT_FOLLOW"},
2669 { 0x20000000, "IN_MASK_ADD" },
2670 { 0x40000000, "IN_ISDIR" },
2671 { 0x80000000, "IN_ONESHOT" },
2675 static const struct xlat inotify_init_flags[] = {
2676 { 0x00000800, "IN_NONBLOCK" },
2677 { 0x00080000, "IN_CLOEXEC" },
2682 sys_inotify_add_watch(struct tcb *tcp)
2684 if (entering(tcp)) {
2685 printfd(tcp, tcp->u_arg[0]);
2687 printpath(tcp, tcp->u_arg[1]);
2689 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2695 sys_inotify_rm_watch(struct tcb *tcp)
2697 if (entering(tcp)) {
2698 printfd(tcp, tcp->u_arg[0]);
2699 tprintf(", %ld", tcp->u_arg[1]);
2705 sys_inotify_init1(struct tcb *tcp)
2708 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
2713 sys_fallocate(struct tcb *tcp)
2715 if (entering(tcp)) {
2717 printfd(tcp, tcp->u_arg[0]); /* fd */
2719 tprintf("%#lo, ", tcp->u_arg[1]); /* mode */
2720 argn = printllval(tcp, "%llu, ", 2); /* offset */
2721 printllval(tcp, "%llu", argn); /* len */