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.
35 #if defined(SPARC) || defined(SPARC64)
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>
78 unsigned long long st_dev;
79 unsigned long long st_ino;
80 unsigned long long st_nlink;
86 unsigned long long st_rdev;
91 unsigned long long st_atime;
92 unsigned long long st_atime_nsec;
93 unsigned long long st_mtime;
94 unsigned long long st_mtime_nsec;
95 unsigned long long st_ctime;
96 unsigned long long st_ctime_nsec;
97 long long __unused[3];
101 unsigned long long st_dev;
102 unsigned char __pad0[4];
103 unsigned long __st_ino;
104 unsigned int st_mode;
105 unsigned int st_nlink;
106 unsigned long st_uid;
107 unsigned long st_gid;
108 unsigned long long st_rdev;
109 unsigned char __pad3[4];
111 unsigned long st_blksize;
112 unsigned long long st_blocks;
113 unsigned long st_atime;
114 unsigned long st_atime_nsec;
115 unsigned long st_mtime;
116 unsigned int st_mtime_nsec;
117 unsigned long st_ctime;
118 unsigned long st_ctime_nsec;
119 unsigned long long st_ino;
120 } __attribute__((packed));
121 # define HAVE_STAT64 1
123 struct __old_kernel_stat {
124 unsigned short st_dev;
125 unsigned short st_ino;
126 unsigned short st_mode;
127 unsigned short st_nlink;
128 unsigned short st_uid;
129 unsigned short st_gid;
130 unsigned short st_rdev;
131 unsigned int st_size;
132 unsigned int st_atime;
133 unsigned int st_mtime;
134 unsigned int st_ctime;
145 # define dev_t __kernel_dev_t
146 # define ino_t __kernel_ino_t
147 # define mode_t __kernel_mode_t
148 # define nlink_t __kernel_nlink_t
149 # define uid_t __kernel_uid_t
150 # define gid_t __kernel_gid_t
151 # define off_t __kernel_off_t
152 # define loff_t __kernel_loff_t
154 # include <asm/stat.h>
166 # define mode_t mode_t
167 # define nlink_t nlink_t
171 # define loff_t loff_t
174 #define stat libc_stat
175 #define stat64 libc_stat64
176 #include <sys/stat.h>
179 /* These might be macros. */
185 #ifdef HAVE_SYS_VFS_H
186 # include <sys/vfs.h>
188 #ifdef HAVE_LINUX_XATTR_H
189 # include <linux/xattr.h>
191 # define XATTR_CREATE 1
192 # define XATTR_REPLACE 2
195 #ifdef MAJOR_IN_SYSMACROS
196 # include <sys/sysmacros.h>
199 #ifdef MAJOR_IN_MKDEV
200 # include <sys/mkdev.h>
203 #ifdef HAVE_SYS_ASYNCH_H
204 # include <sys/asynch.h>
207 struct kernel_dirent {
210 unsigned short d_reclen;
214 const struct xlat open_access_modes[] = {
215 { O_RDONLY, "O_RDONLY" },
216 { O_WRONLY, "O_WRONLY" },
217 { O_RDWR, "O_RDWR" },
219 { O_ACCMODE, "O_ACCMODE" },
224 const struct xlat open_mode_flags[] = {
225 { O_CREAT, "O_CREAT" },
226 { O_EXCL, "O_EXCL" },
227 { O_NOCTTY, "O_NOCTTY" },
228 { O_TRUNC, "O_TRUNC" },
229 { O_APPEND, "O_APPEND" },
230 { O_NONBLOCK, "O_NONBLOCK" },
232 { O_SYNC, "O_SYNC" },
235 { O_ASYNC, "O_ASYNC" },
238 { O_DSYNC, "O_DSYNC" },
241 { O_RSYNC, "O_RSYNC" },
243 #if defined(O_NDELAY) && (O_NDELAY != O_NONBLOCK)
244 { O_NDELAY, "O_NDELAY" },
247 { O_PRIV, "O_PRIV" },
250 { O_DIRECT, "O_DIRECT" },
253 # if O_LARGEFILE == 0 /* biarch platforms in 64-bit mode */
256 # define O_LARGEFILE 0x40000
257 # elif defined X86_64 || defined S390X
258 # define O_LARGEFILE 0100000
262 { O_LARGEFILE, "O_LARGEFILE" },
266 { O_DIRECTORY, "O_DIRECTORY" },
269 { O_NOFOLLOW, "O_NOFOLLOW" },
272 { O_NOATIME, "O_NOATIME" },
275 { O_CLOEXEC, "O_CLOEXEC" },
278 { FNDELAY, "FNDELAY" },
281 { FAPPEND, "FAPPEND" },
287 { FDEFER, "FDEFER" },
290 { FASYNC, "FASYNC" },
293 { FSHLOCK, "FSHLOCK" },
296 { FEXLOCK, "FEXLOCK" },
299 { FCREAT, "FCREAT" },
302 { FTRUNC, "FTRUNC" },
314 { FNOCTTY, "FNOCTTY" },
317 { O_SHLOCK, "O_SHLOCK" },
320 { O_EXLOCK, "O_EXLOCK" },
326 # define AT_FDCWD -100
329 /* The fd is an "int", so when decoding x86 on x86_64, we need to force sign
330 * extension to get the right value. We do this by declaring fd as int here.
333 print_dirfd(struct tcb *tcp, int fd)
336 tprints("AT_FDCWD, ");
344 * low bits of the open(2) flags define access mode,
345 * other bits are real flags.
348 sprint_open_modes(mode_t flags)
350 static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
354 const struct xlat *x;
357 p = stpcpy(outstr, "flags");
358 str = xlookup(open_access_modes, flags & 3);
368 for (x = open_mode_flags; x->str; x++) {
369 if ((flags & x->val) == x->val) {
371 p = stpcpy(p, x->str);
378 /* flags is still nonzero */
380 sprintf(p, "%#x", flags);
385 tprint_open_modes(mode_t flags)
387 tprints(sprint_open_modes(flags) + sizeof("flags"));
391 decode_open(struct tcb *tcp, int offset)
394 printpath(tcp, tcp->u_arg[offset]);
397 tprint_open_modes(tcp->u_arg[offset + 1]);
398 if (tcp->u_arg[offset + 1] & O_CREAT) {
400 tprintf(", %#lo", tcp->u_arg[offset + 2]);
407 sys_open(struct tcb *tcp)
409 return decode_open(tcp, 0);
413 sys_openat(struct tcb *tcp)
416 print_dirfd(tcp, tcp->u_arg[0]);
417 return decode_open(tcp, 1);
420 #if defined(SPARC) || defined(SPARC64)
421 static const struct xlat openmodessol[] = {
425 { 0x80, "O_NONBLOCK" },
427 { 0x100, "O_CREAT" },
428 { 0x200, "O_TRUNC" },
430 { 0x800, "O_NOCTTY" },
433 { 0x8000, "O_RSYNC" },
435 { 0x1000, "O_PRIV" },
440 solaris_open(struct tcb *tcp)
443 printpath(tcp, tcp->u_arg[0]);
446 printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
447 if (tcp->u_arg[1] & 0x100) {
449 tprintf(", %#lo", tcp->u_arg[2]);
458 sys_creat(struct tcb *tcp)
461 printpath(tcp, tcp->u_arg[0]);
462 tprintf(", %#lo", tcp->u_arg[1]);
467 static const struct xlat access_flags[] = {
473 { EFF_ONLY_OK, "EFF_ONLY_OK" },
482 decode_access(struct tcb *tcp, int offset)
485 printpath(tcp, tcp->u_arg[offset]);
487 printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
493 sys_access(struct tcb *tcp)
495 return decode_access(tcp, 0);
499 sys_faccessat(struct tcb *tcp)
502 print_dirfd(tcp, tcp->u_arg[0]);
503 return decode_access(tcp, 1);
507 sys_umask(struct tcb *tcp)
510 tprintf("%#lo", tcp->u_arg[0]);
515 const struct xlat whence_codes[] = {
516 { SEEK_SET, "SEEK_SET" },
517 { SEEK_CUR, "SEEK_CUR" },
518 { SEEK_END, "SEEK_END" },
520 { SEEK_DATA, "SEEK_DATA" },
523 { SEEK_HOLE, "SEEK_HOLE" },
528 /* Linux kernel has exactly one version of lseek:
529 * fs/read_write.c::SYSCALL_DEFINE3(lseek, unsigned, fd, off_t, offset, unsigned, origin)
530 * In kernel, off_t is always the same as (kernel's) long
531 * (see include/uapi/asm-generic/posix_types.h),
532 * which means that on x32 we need to use tcp->ext_arg[N] to get offset argument.
533 * Use test/x32_lseek.c to test lseek decoding.
535 #if defined(LINUX_MIPSN32) || defined(X32)
537 sys_lseek(struct tcb *tcp)
543 printfd(tcp, tcp->u_arg[0]);
544 offset = tcp->ext_arg[1];
545 whence = tcp->u_arg[2];
546 if (whence == SEEK_SET)
547 tprintf(", %llu, ", offset);
549 tprintf(", %lld, ", offset);
550 printxval(whence_codes, whence, "SEEK_???");
552 return RVAL_LUDECIMAL;
556 sys_lseek(struct tcb *tcp)
562 printfd(tcp, tcp->u_arg[0]);
563 offset = tcp->u_arg[1];
564 whence = tcp->u_arg[2];
565 if (whence == SEEK_SET)
566 tprintf(", %lu, ", offset);
568 tprintf(", %ld, ", offset);
569 printxval(whence_codes, whence, "SEEK_???");
571 return RVAL_UDECIMAL;
575 /* llseek syscall takes explicitly two ulong arguments hi, lo,
576 * rather than one 64-bit argument for which LONG_LONG works
577 * appropriate for the native byte order.
579 * See kernel's fs/read_write.c::SYSCALL_DEFINE5(llseek, ...)
581 * hi,lo are "unsigned longs" and combined exactly this way in kernel:
582 * ((loff_t) hi << 32) | lo
583 * Note that for architectures with kernel's long wider than userspace long
584 * (such as x32), combining code will use *kernel's*, i.e. *wide* longs
585 * for hi and lo. We would need to use tcp->ext_arg[N] on x32...
586 * ...however, x32 (and x86_64) does not _have_ llseek syscall as such.
589 sys_llseek(struct tcb *tcp)
592 printfd(tcp, tcp->u_arg[0]);
593 if (tcp->u_arg[4] == SEEK_SET)
595 ((long long) tcp->u_arg[1]) << 32 |
596 (unsigned long long) (unsigned) tcp->u_arg[2]);
599 ((long long) tcp->u_arg[1]) << 32 |
600 (unsigned long long) (unsigned) tcp->u_arg[2]);
604 if (syserror(tcp) || umove(tcp, tcp->u_arg[3], &off) < 0)
605 tprintf("%#lx, ", tcp->u_arg[3]);
607 tprintf("[%llu], ", off);
608 printxval(whence_codes, tcp->u_arg[4], "SEEK_???");
614 sys_readahead(struct tcb *tcp)
618 printfd(tcp, tcp->u_arg[0]);
619 argn = printllval(tcp, ", %lld", 1);
620 tprintf(", %ld", tcp->u_arg[argn]);
626 sys_truncate(struct tcb *tcp)
629 printpath(tcp, tcp->u_arg[0]);
630 tprintf(", %lu", tcp->u_arg[1]);
637 sys_truncate64(struct tcb *tcp)
640 printpath(tcp, tcp->u_arg[0]);
641 printllval(tcp, ", %llu", 1);
648 sys_ftruncate(struct tcb *tcp)
651 printfd(tcp, tcp->u_arg[0]);
652 tprintf(", %lu", tcp->u_arg[1]);
659 sys_ftruncate64(struct tcb *tcp)
662 printfd(tcp, tcp->u_arg[0]);
663 printllval(tcp, ", %llu", 1);
671 static const struct xlat modetypes[] = {
672 { S_IFREG, "S_IFREG" },
673 { S_IFSOCK, "S_IFSOCK" },
674 { S_IFIFO, "S_IFIFO" },
675 { S_IFLNK, "S_IFLNK" },
676 { S_IFDIR, "S_IFDIR" },
677 { S_IFBLK, "S_IFBLK" },
678 { S_IFCHR, "S_IFCHR" },
685 static char buf[sizeof("S_IFSOCK|S_ISUID|S_ISGID|S_ISVTX|%o")
690 if ((mode & S_IFMT) == 0)
692 else if ((s = xlookup(modetypes, mode & S_IFMT)) == NULL) {
693 sprintf(buf, "%#o", mode);
696 s = buf + sprintf(buf, "%s%s%s%s", s,
697 (mode & S_ISUID) ? "|S_ISUID" : "",
698 (mode & S_ISGID) ? "|S_ISGID" : "",
699 (mode & S_ISVTX) ? "|S_ISVTX" : "");
700 mode &= ~(S_IFMT|S_ISUID|S_ISGID|S_ISVTX);
702 sprintf((char*)s, "|%#o", mode);
703 s = (*buf == '|') ? buf + 1 : buf;
711 static char buf[sizeof("yyyy/mm/dd-hh:mm:ss")];
719 snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
720 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
721 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
723 snprintf(buf, sizeof buf, "%lu", (unsigned long) t);
728 #if defined(SPARC) || defined(SPARC64)
736 int st_pad1[3]; /* network id */
745 int st_pad3; /* st_size, off_t expansion */
746 timestruct_t st_atime;
747 timestruct_t st_mtime;
748 timestruct_t st_ctime;
752 int st_pad4[8]; /* expansion area */
756 printstatsol(struct tcb *tcp, long addr)
758 struct solstat statbuf;
760 if (umove(tcp, addr, &statbuf) < 0) {
765 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
766 (unsigned long) ((statbuf.st_dev >> 18) & 0x3fff),
767 (unsigned long) (statbuf.st_dev & 0x3ffff),
768 (unsigned long) statbuf.st_ino,
769 sprintmode(statbuf.st_mode));
770 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
771 (unsigned long) statbuf.st_nlink,
772 (unsigned long) statbuf.st_uid,
773 (unsigned long) statbuf.st_gid);
774 tprintf("st_blksize=%lu, ", (unsigned long) statbuf.st_blksize);
775 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
778 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
779 switch (statbuf.st_mode & S_IFMT) {
780 case S_IFCHR: case S_IFBLK:
781 tprintf("st_rdev=makedev(%lu, %lu), ",
782 (unsigned long) ((statbuf.st_rdev >> 18) & 0x3fff),
783 (unsigned long) (statbuf.st_rdev & 0x3ffff));
786 tprintf("st_size=%u, ", statbuf.st_size);
790 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime.tv_sec));
791 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime.tv_sec));
792 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
798 # if defined(SPARC64)
800 printstat_sparc64(struct tcb *tcp, long addr)
802 struct stat_sparc64 statbuf;
804 if (umove(tcp, addr, &statbuf) < 0) {
810 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
811 (unsigned long) major(statbuf.st_dev),
812 (unsigned long) minor(statbuf.st_dev),
813 (unsigned long) statbuf.st_ino,
814 sprintmode(statbuf.st_mode));
815 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
816 (unsigned long) statbuf.st_nlink,
817 (unsigned long) statbuf.st_uid,
818 (unsigned long) statbuf.st_gid);
819 tprintf("st_blksize=%lu, ",
820 (unsigned long) statbuf.st_blksize);
821 tprintf("st_blocks=%lu, ",
822 (unsigned long) statbuf.st_blocks);
825 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
826 switch (statbuf.st_mode & S_IFMT) {
827 case S_IFCHR: case S_IFBLK:
828 tprintf("st_rdev=makedev(%lu, %lu), ",
829 (unsigned long) major(statbuf.st_rdev),
830 (unsigned long) minor(statbuf.st_rdev));
833 tprintf("st_size=%lu, ", statbuf.st_size);
837 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
838 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
839 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
844 # endif /* SPARC64 */
845 #endif /* SPARC[64] */
847 #if defined POWERPC64
848 struct stat_powerpc32 {
851 unsigned int st_mode;
852 unsigned short st_nlink;
855 unsigned int st_rdev;
856 unsigned int st_size;
857 unsigned int st_blksize;
858 unsigned int st_blocks;
859 unsigned int st_atime;
860 unsigned int st_atime_nsec;
861 unsigned int st_mtime;
862 unsigned int st_mtime_nsec;
863 unsigned int st_ctime;
864 unsigned int st_ctime_nsec;
865 unsigned int __unused4;
866 unsigned int __unused5;
870 printstat_powerpc32(struct tcb *tcp, long addr)
872 struct stat_powerpc32 statbuf;
874 if (umove(tcp, addr, &statbuf) < 0) {
880 tprintf("{st_dev=makedev(%u, %u), st_ino=%u, st_mode=%s, ",
881 major(statbuf.st_dev), minor(statbuf.st_dev),
883 sprintmode(statbuf.st_mode));
884 tprintf("st_nlink=%u, st_uid=%u, st_gid=%u, ",
885 statbuf.st_nlink, statbuf.st_uid, statbuf.st_gid);
886 tprintf("st_blksize=%u, ", statbuf.st_blksize);
887 tprintf("st_blocks=%u, ", statbuf.st_blocks);
890 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
891 switch (statbuf.st_mode & S_IFMT) {
892 case S_IFCHR: case S_IFBLK:
893 tprintf("st_rdev=makedev(%lu, %lu), ",
894 (unsigned long) major(statbuf.st_rdev),
895 (unsigned long) minor(statbuf.st_rdev));
898 tprintf("st_size=%u, ", statbuf.st_size);
902 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
903 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
904 tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime));
909 #endif /* POWERPC64 */
911 static const struct xlat fileflags[] = {
916 realprintstat(struct tcb *tcp, struct stat *statbuf)
919 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
920 (unsigned long) major(statbuf->st_dev),
921 (unsigned long) minor(statbuf->st_dev),
922 (unsigned long) statbuf->st_ino,
923 sprintmode(statbuf->st_mode));
924 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
925 (unsigned long) statbuf->st_nlink,
926 (unsigned long) statbuf->st_uid,
927 (unsigned long) statbuf->st_gid);
928 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
929 tprintf("st_blksize=%lu, ", (unsigned long) statbuf->st_blksize);
931 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
932 tprintf("st_blocks=%lu, ", (unsigned long) statbuf->st_blocks);
936 tprintf("{st_mode=%s, ", sprintmode(statbuf->st_mode));
937 switch (statbuf->st_mode & S_IFMT) {
938 case S_IFCHR: case S_IFBLK:
939 #ifdef HAVE_STRUCT_STAT_ST_RDEV
940 tprintf("st_rdev=makedev(%lu, %lu), ",
941 (unsigned long) major(statbuf->st_rdev),
942 (unsigned long) minor(statbuf->st_rdev));
943 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
944 tprintf("st_size=makedev(%lu, %lu), ",
945 (unsigned long) major(statbuf->st_size),
946 (unsigned long) minor(statbuf->st_size));
947 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
950 tprintf("st_size=%lu, ", (unsigned long) statbuf->st_size);
954 tprintf("st_atime=%s, ", sprinttime(statbuf->st_atime));
955 tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
956 tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
957 #if HAVE_STRUCT_STAT_ST_FLAGS
958 tprints(", st_flags=");
959 printflags(fileflags, statbuf->st_flags, "UF_???");
961 #if HAVE_STRUCT_STAT_ST_ACLCNT
962 tprintf(", st_aclcnt=%d", statbuf->st_aclcnt);
964 #if HAVE_STRUCT_STAT_ST_LEVEL
965 tprintf(", st_level=%ld", statbuf->st_level);
967 #if HAVE_STRUCT_STAT_ST_FSTYPE
968 tprintf(", st_fstype=%.*s",
969 (int) sizeof statbuf->st_fstype, statbuf->st_fstype);
971 #if HAVE_STRUCT_STAT_ST_GEN
972 tprintf(", st_gen=%u", statbuf->st_gen);
982 printstat(struct tcb *tcp, long addr)
990 if (syserror(tcp) || !verbose(tcp)) {
991 tprintf("%#lx", addr);
995 #if defined(SPARC) || defined(SPARC64)
996 if (current_personality == 1) {
997 printstatsol(tcp, addr);
1001 else if (current_personality == 2) {
1002 printstat_sparc64(tcp, addr);
1006 #endif /* SPARC[64] */
1008 #if defined POWERPC64
1009 if (current_personality == 1) {
1010 printstat_powerpc32(tcp, addr);
1015 if (umove(tcp, addr, &statbuf) < 0) {
1020 realprintstat(tcp, &statbuf);
1023 # define printstat printstat64
1026 #if !defined HAVE_STAT64 && defined X86_64
1028 * Linux x86_64 has unified `struct stat' but its i386 biarch needs
1029 * `struct stat64'. Its <asm-i386/stat.h> definition expects 32-bit `long'.
1030 * <linux/include/asm-x86_64/ia32.h> is not in the public includes set.
1031 * __GNUC__ is needed for the required __attribute__ below.
1034 unsigned long long st_dev;
1035 unsigned char __pad0[4];
1036 unsigned int __st_ino;
1037 unsigned int st_mode;
1038 unsigned int st_nlink;
1039 unsigned int st_uid;
1040 unsigned int st_gid;
1041 unsigned long long st_rdev;
1042 unsigned char __pad3[4];
1044 unsigned int st_blksize;
1045 unsigned long long st_blocks;
1046 unsigned int st_atime;
1047 unsigned int st_atime_nsec;
1048 unsigned int st_mtime;
1049 unsigned int st_mtime_nsec;
1050 unsigned int st_ctime;
1051 unsigned int st_ctime_nsec;
1052 unsigned long long st_ino;
1053 } __attribute__((packed));
1054 # define HAVE_STAT64 1
1055 # define STAT64_SIZE 96
1060 printstat64(struct tcb *tcp, long addr)
1063 struct stat statbuf;
1065 struct stat64 statbuf;
1069 (void) sizeof(char[sizeof statbuf == STAT64_SIZE ? 1 : -1]);
1076 if (syserror(tcp) || !verbose(tcp)) {
1077 tprintf("%#lx", addr);
1081 #if defined(SPARC) || defined(SPARC64)
1082 if (current_personality == 1) {
1083 printstatsol(tcp, addr);
1087 else if (current_personality == 2) {
1088 printstat_sparc64(tcp, addr);
1092 #endif /* SPARC[64] */
1095 if (current_personality != 1) {
1096 printstat(tcp, addr);
1101 if (umove(tcp, addr, &statbuf) < 0) {
1107 #ifdef HAVE_LONG_LONG
1108 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1110 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%lu, st_mode=%s, ",
1112 (unsigned long) major(statbuf.st_dev),
1113 (unsigned long) minor(statbuf.st_dev),
1114 #ifdef HAVE_LONG_LONG
1115 (unsigned long long) statbuf.st_ino,
1117 (unsigned long) statbuf.st_ino,
1119 sprintmode(statbuf.st_mode));
1120 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1121 (unsigned long) statbuf.st_nlink,
1122 (unsigned long) statbuf.st_uid,
1123 (unsigned long) statbuf.st_gid);
1124 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1125 tprintf("st_blksize=%lu, ",
1126 (unsigned long) statbuf.st_blksize);
1127 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1128 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
1129 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1130 #endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
1133 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1134 switch (statbuf.st_mode & S_IFMT) {
1135 case S_IFCHR: case S_IFBLK:
1136 #ifdef HAVE_STRUCT_STAT_ST_RDEV
1137 tprintf("st_rdev=makedev(%lu, %lu), ",
1138 (unsigned long) major(statbuf.st_rdev),
1139 (unsigned long) minor(statbuf.st_rdev));
1140 #else /* !HAVE_STRUCT_STAT_ST_RDEV */
1141 tprintf("st_size=makedev(%lu, %lu), ",
1142 (unsigned long) major(statbuf.st_size),
1143 (unsigned long) minor(statbuf.st_size));
1144 #endif /* !HAVE_STRUCT_STAT_ST_RDEV */
1147 #ifdef HAVE_LONG_LONG
1148 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1150 tprintf("st_size=%lu, ", (unsigned long) statbuf.st_size);
1155 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1156 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1157 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1158 #if HAVE_STRUCT_STAT_ST_FLAGS
1159 tprints(", st_flags=");
1160 printflags(fileflags, statbuf.st_flags, "UF_???");
1162 #if HAVE_STRUCT_STAT_ST_ACLCNT
1163 tprintf(", st_aclcnt=%d", statbuf.st_aclcnt);
1165 #if HAVE_STRUCT_STAT_ST_LEVEL
1166 tprintf(", st_level=%ld", statbuf.st_level);
1168 #if HAVE_STRUCT_STAT_ST_FSTYPE
1169 tprintf(", st_fstype=%.*s",
1170 (int) sizeof statbuf.st_fstype, statbuf.st_fstype);
1172 #if HAVE_STRUCT_STAT_ST_GEN
1173 tprintf(", st_gen=%u", statbuf.st_gen);
1180 #endif /* HAVE_STAT64 */
1182 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1184 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
1186 newbuf->st_dev = oldbuf->st_dev;
1187 newbuf->st_ino = oldbuf->st_ino;
1188 newbuf->st_mode = oldbuf->st_mode;
1189 newbuf->st_nlink = oldbuf->st_nlink;
1190 newbuf->st_uid = oldbuf->st_uid;
1191 newbuf->st_gid = oldbuf->st_gid;
1192 newbuf->st_rdev = oldbuf->st_rdev;
1193 newbuf->st_size = oldbuf->st_size;
1194 newbuf->st_atime = oldbuf->st_atime;
1195 newbuf->st_mtime = oldbuf->st_mtime;
1196 newbuf->st_ctime = oldbuf->st_ctime;
1197 newbuf->st_blksize = 0; /* not supported in old_stat */
1198 newbuf->st_blocks = 0; /* not supported in old_stat */
1202 printoldstat(struct tcb *tcp, long addr)
1204 struct __old_kernel_stat statbuf;
1205 struct stat newstatbuf;
1211 if (syserror(tcp) || !verbose(tcp)) {
1212 tprintf("%#lx", addr);
1216 # if defined(SPARC) || defined(SPARC64)
1217 if (current_personality == 1) {
1218 printstatsol(tcp, addr);
1223 if (umove(tcp, addr, &statbuf) < 0) {
1228 convertoldstat(&statbuf, &newstatbuf);
1229 realprintstat(tcp, &newstatbuf);
1234 sys_stat(struct tcb *tcp)
1236 if (entering(tcp)) {
1237 printpath(tcp, tcp->u_arg[0]);
1240 printstat(tcp, tcp->u_arg[1]);
1247 printstat64_x32(struct tcb *tcp, long addr)
1249 struct stat64 statbuf;
1255 if (syserror(tcp) || !verbose(tcp)) {
1256 tprintf("%#lx", addr);
1260 if (umove(tcp, addr, &statbuf) < 0) {
1266 tprintf("{st_dev=makedev(%lu, %lu), st_ino=%llu, st_mode=%s, ",
1267 (unsigned long) major(statbuf.st_dev),
1268 (unsigned long) minor(statbuf.st_dev),
1269 (unsigned long long) statbuf.st_ino,
1270 sprintmode(statbuf.st_mode));
1271 tprintf("st_nlink=%lu, st_uid=%lu, st_gid=%lu, ",
1272 (unsigned long) statbuf.st_nlink,
1273 (unsigned long) statbuf.st_uid,
1274 (unsigned long) statbuf.st_gid);
1275 tprintf("st_blksize=%lu, ",
1276 (unsigned long) statbuf.st_blksize);
1277 tprintf("st_blocks=%lu, ", (unsigned long) statbuf.st_blocks);
1280 tprintf("{st_mode=%s, ", sprintmode(statbuf.st_mode));
1281 switch (statbuf.st_mode & S_IFMT) {
1282 case S_IFCHR: case S_IFBLK:
1283 tprintf("st_rdev=makedev(%lu, %lu), ",
1284 (unsigned long) major(statbuf.st_rdev),
1285 (unsigned long) minor(statbuf.st_rdev));
1288 tprintf("st_size=%llu, ", (unsigned long long) statbuf.st_size);
1292 tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
1293 tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
1294 tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
1303 sys_stat64(struct tcb *tcp)
1306 if (entering(tcp)) {
1307 printpath(tcp, tcp->u_arg[0]);
1311 printstat64_x32(tcp, tcp->u_arg[1]);
1313 printstat64(tcp, tcp->u_arg[1]);
1318 return printargs(tcp);
1322 #ifndef AT_SYMLINK_NOFOLLOW
1323 # define AT_SYMLINK_NOFOLLOW 0x100
1325 #ifndef AT_REMOVEDIR
1326 # define AT_REMOVEDIR 0x200
1328 #ifndef AT_SYMLINK_FOLLOW
1329 # define AT_SYMLINK_FOLLOW 0x400
1331 #ifndef AT_NO_AUTOMOUNT
1332 # define AT_NO_AUTOMOUNT 0x800
1334 #ifndef AT_EMPTY_PATH
1335 # define AT_EMPTY_PATH 0x1000
1338 static const struct xlat at_flags[] = {
1339 { AT_SYMLINK_NOFOLLOW, "AT_SYMLINK_NOFOLLOW" },
1340 { AT_REMOVEDIR, "AT_REMOVEDIR" },
1341 { AT_SYMLINK_FOLLOW, "AT_SYMLINK_FOLLOW" },
1342 { AT_NO_AUTOMOUNT, "AT_NO_AUTOMOUNT" },
1343 { AT_EMPTY_PATH, "AT_EMPTY_PATH" },
1348 sys_newfstatat(struct tcb *tcp)
1350 if (entering(tcp)) {
1351 print_dirfd(tcp, tcp->u_arg[0]);
1352 printpath(tcp, tcp->u_arg[1]);
1356 if (current_personality == 0)
1357 printstat(tcp, tcp->u_arg[2]);
1359 printstat64(tcp, tcp->u_arg[2]);
1360 #elif defined HAVE_STAT64
1361 printstat64(tcp, tcp->u_arg[2]);
1363 printstat(tcp, tcp->u_arg[2]);
1366 printflags(at_flags, tcp->u_arg[3], "AT_???");
1371 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1373 sys_oldstat(struct tcb *tcp)
1375 if (entering(tcp)) {
1376 printpath(tcp, tcp->u_arg[0]);
1379 printoldstat(tcp, tcp->u_arg[1]);
1386 sys_fstat(struct tcb *tcp)
1388 if (entering(tcp)) {
1389 printfd(tcp, tcp->u_arg[0]);
1392 printstat(tcp, tcp->u_arg[1]);
1398 sys_fstat64(struct tcb *tcp)
1401 if (entering(tcp)) {
1402 printfd(tcp, tcp->u_arg[0]);
1406 printstat64_x32(tcp, tcp->u_arg[1]);
1408 printstat64(tcp, tcp->u_arg[1]);
1413 return printargs(tcp);
1417 #if defined(HAVE_STRUCT___OLD_KERNEL_STAT)
1419 sys_oldfstat(struct tcb *tcp)
1421 if (entering(tcp)) {
1422 printfd(tcp, tcp->u_arg[0]);
1425 printoldstat(tcp, tcp->u_arg[1]);
1431 #if defined(SPARC) || defined(SPARC64)
1434 sys_xstat(struct tcb *tcp)
1436 if (entering(tcp)) {
1437 tprintf("%ld, ", tcp->u_arg[0]);
1438 printpath(tcp, tcp->u_arg[1]);
1442 if (tcp->u_arg[0] == _STAT64_VER)
1443 printstat64(tcp, tcp->u_arg[2]);
1446 printstat(tcp, tcp->u_arg[2]);
1452 sys_fxstat(struct tcb *tcp)
1455 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
1458 if (tcp->u_arg[0] == _STAT64_VER)
1459 printstat64(tcp, tcp->u_arg[2]);
1462 printstat(tcp, tcp->u_arg[2]);
1468 sys_lxstat(struct tcb *tcp)
1470 if (entering(tcp)) {
1471 tprintf("%ld, ", tcp->u_arg[0]);
1472 printpath(tcp, tcp->u_arg[1]);
1476 if (tcp->u_arg[0] == _STAT64_VER)
1477 printstat64(tcp, tcp->u_arg[2]);
1480 printstat(tcp, tcp->u_arg[2]);
1486 sys_xmknod(struct tcb *tcp)
1488 int mode = tcp->u_arg[2];
1490 if (entering(tcp)) {
1491 tprintf("%ld, ", tcp->u_arg[0]);
1492 printpath(tcp, tcp->u_arg[1]);
1493 tprintf(", %s", sprintmode(mode));
1494 switch (mode & S_IFMT) {
1495 case S_IFCHR: case S_IFBLK:
1496 tprintf(", makedev(%lu, %lu)",
1497 (unsigned long) ((tcp->u_arg[3] >> 18) & 0x3fff),
1498 (unsigned long) (tcp->u_arg[3] & 0x3ffff));
1507 # ifdef HAVE_SYS_ACL_H
1509 # include <sys/acl.h>
1511 static const struct xlat aclcmds[] = {
1513 { SETACL, "SETACL" },
1516 { GETACL, "GETACL" },
1519 { GETACLCNT, "GETACLCNT" },
1522 { ACL_GET, "ACL_GET" },
1525 { ACL_SET, "ACL_SET" },
1528 { ACL_CNT, "ACL_CNT" },
1534 sys_acl(struct tcb *tcp)
1536 if (entering(tcp)) {
1537 printpath(tcp, tcp->u_arg[0]);
1539 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1540 tprintf(", %ld", tcp->u_arg[2]);
1542 * FIXME - dump out the list of aclent_t's pointed to
1543 * by "tcp->u_arg[3]" if it's not NULL.
1546 tprintf(", %#lx", tcp->u_arg[3]);
1554 sys_facl(struct tcb *tcp)
1556 if (entering(tcp)) {
1557 tprintf("%ld, ", tcp->u_arg[0]);
1558 printxval(aclcmds, tcp->u_arg[1], "???ACL???");
1559 tprintf(", %ld", tcp->u_arg[2]);
1561 * FIXME - dump out the list of aclent_t's pointed to
1562 * by "tcp->u_arg[3]" if it's not NULL.
1565 tprintf(", %#lx", tcp->u_arg[3]);
1572 static const struct xlat aclipc[] = {
1574 { IPC_SHM, "IPC_SHM" },
1577 { IPC_SEM, "IPC_SEM" },
1580 { IPC_MSG, "IPC_MSG" },
1586 sys_aclipc(struct tcb *tcp)
1588 if (entering(tcp)) {
1589 printxval(aclipc, tcp->u_arg[0], "???IPC???");
1590 tprintf(", %#lx, ", tcp->u_arg[1]);
1591 printxval(aclcmds, tcp->u_arg[2], "???ACL???");
1592 tprintf(", %ld", tcp->u_arg[3]);
1594 * FIXME - dump out the list of aclent_t's pointed to
1595 * by "tcp->u_arg[4]" if it's not NULL.
1598 tprintf(", %#lx", tcp->u_arg[4]);
1605 # endif /* HAVE_SYS_ACL_H */
1607 #endif /* SPARC[64] */
1609 static const struct xlat fsmagic[] = {
1610 { 0x73757245, "CODA_SUPER_MAGIC" },
1611 { 0x012ff7b7, "COH_SUPER_MAGIC" },
1612 { 0x1373, "DEVFS_SUPER_MAGIC" },
1613 { 0x1cd1, "DEVPTS_SUPER_MAGIC" },
1614 { 0x414A53, "EFS_SUPER_MAGIC" },
1615 { 0xef51, "EXT2_OLD_SUPER_MAGIC" },
1616 { 0xef53, "EXT2_SUPER_MAGIC" },
1617 { 0x137d, "EXT_SUPER_MAGIC" },
1618 { 0xf995e849, "HPFS_SUPER_MAGIC" },
1619 { 0x9660, "ISOFS_SUPER_MAGIC" },
1620 { 0x137f, "MINIX_SUPER_MAGIC" },
1621 { 0x138f, "MINIX_SUPER_MAGIC2" },
1622 { 0x2468, "MINIX2_SUPER_MAGIC" },
1623 { 0x2478, "MINIX2_SUPER_MAGIC2" },
1624 { 0x4d44, "MSDOS_SUPER_MAGIC" },
1625 { 0x564c, "NCP_SUPER_MAGIC" },
1626 { 0x6969, "NFS_SUPER_MAGIC" },
1627 { 0x9fa0, "PROC_SUPER_MAGIC" },
1628 { 0x002f, "QNX4_SUPER_MAGIC" },
1629 { 0x52654973, "REISERFS_SUPER_MAGIC" },
1630 { 0x02011994, "SHMFS_SUPER_MAGIC" },
1631 { 0x517b, "SMB_SUPER_MAGIC" },
1632 { 0x012ff7b6, "SYSV2_SUPER_MAGIC" },
1633 { 0x012ff7b5, "SYSV4_SUPER_MAGIC" },
1634 { 0x00011954, "UFS_MAGIC" },
1635 { 0x54190100, "UFS_CIGAM" },
1636 { 0x012ff7b4, "XENIX_SUPER_MAGIC" },
1637 { 0x012fd16d, "XIAFS_SUPER_MAGIC" },
1638 { 0x62656572, "SYSFS_MAGIC" },
1643 sprintfstype(int magic)
1645 static char buf[32];
1648 s = xlookup(fsmagic, magic);
1650 sprintf(buf, "\"%s\"", s);
1653 sprintf(buf, "%#x", magic);
1658 printstatfs(struct tcb *tcp, long addr)
1660 struct statfs statbuf;
1662 if (syserror(tcp) || !verbose(tcp)) {
1663 tprintf("%#lx", addr);
1666 if (umove(tcp, addr, &statbuf) < 0) {
1672 tprintf("{f_type=%s, f_fbsize=%u, f_blocks=%u, f_bfree=%u, ",
1673 sprintfstype(statbuf.f_type),
1674 statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
1675 tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
1676 statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
1677 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
1680 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%lu, f_bfree=%lu, ",
1681 sprintfstype(statbuf.f_type),
1682 (unsigned long)statbuf.f_bsize,
1683 (unsigned long)statbuf.f_blocks,
1684 (unsigned long)statbuf.f_bfree);
1685 tprintf("f_bavail=%lu, f_files=%lu, f_ffree=%lu, f_fsid={%d, %d}",
1686 (unsigned long)statbuf.f_bavail,
1687 (unsigned long)statbuf.f_files,
1688 (unsigned long)statbuf.f_ffree,
1689 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1690 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1692 #ifdef _STATFS_F_FRSIZE
1693 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1699 sys_statfs(struct tcb *tcp)
1701 if (entering(tcp)) {
1702 printpath(tcp, tcp->u_arg[0]);
1705 printstatfs(tcp, tcp->u_arg[1]);
1711 sys_fstatfs(struct tcb *tcp)
1713 if (entering(tcp)) {
1714 printfd(tcp, tcp->u_arg[0]);
1717 printstatfs(tcp, tcp->u_arg[1]);
1722 #if defined HAVE_STATFS64
1724 printstatfs64(struct tcb *tcp, long addr)
1726 struct statfs64 statbuf;
1728 if (syserror(tcp) || !verbose(tcp)) {
1729 tprintf("%#lx", addr);
1732 if (umove(tcp, addr, &statbuf) < 0) {
1736 tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
1737 sprintfstype(statbuf.f_type),
1738 (unsigned long long)statbuf.f_bsize,
1739 (unsigned long long)statbuf.f_blocks,
1740 (unsigned long long)statbuf.f_bfree);
1741 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1742 (unsigned long long)statbuf.f_bavail,
1743 (unsigned long long)statbuf.f_files,
1744 (unsigned long long)statbuf.f_ffree,
1745 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1746 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1747 #ifdef _STATFS_F_FRSIZE
1748 tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
1750 #ifdef _STATFS_F_FLAGS
1751 tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
1756 struct compat_statfs64 {
1768 uint32_t f_spare[4];
1770 #if defined(X86_64) || defined(IA64)
1771 __attribute__ ((packed, aligned(4)))
1776 printcompat_statfs64(struct tcb *tcp, long addr)
1778 struct compat_statfs64 statbuf;
1780 if (syserror(tcp) || !verbose(tcp)) {
1781 tprintf("%#lx", addr);
1784 if (umove(tcp, addr, &statbuf) < 0) {
1788 tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
1789 sprintfstype(statbuf.f_type),
1790 (unsigned long)statbuf.f_bsize,
1791 (unsigned long long)statbuf.f_blocks,
1792 (unsigned long long)statbuf.f_bfree);
1793 tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
1794 (unsigned long long)statbuf.f_bavail,
1795 (unsigned long long)statbuf.f_files,
1796 (unsigned long long)statbuf.f_ffree,
1797 statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
1798 tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
1799 tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
1800 tprintf(", f_flags=%lu}", (unsigned long)statbuf.f_frsize);
1804 sys_statfs64(struct tcb *tcp)
1806 if (entering(tcp)) {
1807 printpath(tcp, tcp->u_arg[0]);
1808 tprintf(", %lu, ", tcp->u_arg[1]);
1810 if (tcp->u_arg[1] == sizeof(struct statfs64))
1811 printstatfs64(tcp, tcp->u_arg[2]);
1812 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1813 printcompat_statfs64(tcp, tcp->u_arg[2]);
1821 sys_fstatfs64(struct tcb *tcp)
1823 if (entering(tcp)) {
1824 printfd(tcp, tcp->u_arg[0]);
1825 tprintf(", %lu, ", tcp->u_arg[1]);
1827 if (tcp->u_arg[1] == sizeof(struct statfs64))
1828 printstatfs64(tcp, tcp->u_arg[2]);
1829 else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
1830 printcompat_statfs64(tcp, tcp->u_arg[2]);
1840 osf_statfs(struct tcb *tcp)
1842 if (entering(tcp)) {
1843 printpath(tcp, tcp->u_arg[0]);
1846 printstatfs(tcp, tcp->u_arg[1]);
1847 tprintf(", %lu", tcp->u_arg[2]);
1853 osf_fstatfs(struct tcb *tcp)
1855 if (entering(tcp)) {
1856 tprintf("%lu, ", tcp->u_arg[0]);
1858 printstatfs(tcp, tcp->u_arg[1]);
1859 tprintf(", %lu", tcp->u_arg[2]);
1867 sys_chdir(struct tcb *tcp)
1869 if (entering(tcp)) {
1870 printpath(tcp, tcp->u_arg[0]);
1876 decode_mkdir(struct tcb *tcp, int offset)
1878 if (entering(tcp)) {
1879 printpath(tcp, tcp->u_arg[offset]);
1880 tprintf(", %#lo", tcp->u_arg[offset + 1]);
1886 sys_mkdir(struct tcb *tcp)
1888 return decode_mkdir(tcp, 0);
1892 sys_mkdirat(struct tcb *tcp)
1895 print_dirfd(tcp, tcp->u_arg[0]);
1896 return decode_mkdir(tcp, 1);
1900 sys_link(struct tcb *tcp)
1902 if (entering(tcp)) {
1903 printpath(tcp, tcp->u_arg[0]);
1905 printpath(tcp, tcp->u_arg[1]);
1911 sys_linkat(struct tcb *tcp)
1913 if (entering(tcp)) {
1914 print_dirfd(tcp, tcp->u_arg[0]);
1915 printpath(tcp, tcp->u_arg[1]);
1917 print_dirfd(tcp, tcp->u_arg[2]);
1918 printpath(tcp, tcp->u_arg[3]);
1920 printflags(at_flags, tcp->u_arg[4], "AT_???");
1926 sys_unlinkat(struct tcb *tcp)
1928 if (entering(tcp)) {
1929 print_dirfd(tcp, tcp->u_arg[0]);
1930 printpath(tcp, tcp->u_arg[1]);
1932 printflags(at_flags, tcp->u_arg[2], "AT_???");
1938 sys_symlinkat(struct tcb *tcp)
1940 if (entering(tcp)) {
1941 printpath(tcp, tcp->u_arg[0]);
1943 print_dirfd(tcp, tcp->u_arg[1]);
1944 printpath(tcp, tcp->u_arg[2]);
1950 decode_readlink(struct tcb *tcp, int offset)
1952 if (entering(tcp)) {
1953 printpath(tcp, tcp->u_arg[offset]);
1957 tprintf("%#lx", tcp->u_arg[offset + 1]);
1959 /* Used to use printpathn(), but readlink
1960 * neither includes NUL in the returned count,
1961 * nor actually writes it into memory.
1962 * printpathn() would decide on printing
1963 * "..." continuation based on garbage
1964 * past return buffer's end.
1966 printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
1967 tprintf(", %lu", tcp->u_arg[offset + 2]);
1973 sys_readlink(struct tcb *tcp)
1975 return decode_readlink(tcp, 0);
1979 sys_readlinkat(struct tcb *tcp)
1982 print_dirfd(tcp, tcp->u_arg[0]);
1983 return decode_readlink(tcp, 1);
1987 sys_renameat(struct tcb *tcp)
1989 if (entering(tcp)) {
1990 print_dirfd(tcp, tcp->u_arg[0]);
1991 printpath(tcp, tcp->u_arg[1]);
1993 print_dirfd(tcp, tcp->u_arg[2]);
1994 printpath(tcp, tcp->u_arg[3]);
2000 sys_chown(struct tcb *tcp)
2002 if (entering(tcp)) {
2003 printpath(tcp, tcp->u_arg[0]);
2004 printuid(", ", tcp->u_arg[1]);
2005 printuid(", ", tcp->u_arg[2]);
2011 sys_fchownat(struct tcb *tcp)
2013 if (entering(tcp)) {
2014 print_dirfd(tcp, tcp->u_arg[0]);
2015 printpath(tcp, tcp->u_arg[1]);
2016 printuid(", ", tcp->u_arg[2]);
2017 printuid(", ", tcp->u_arg[3]);
2019 printflags(at_flags, tcp->u_arg[4], "AT_???");
2025 sys_fchown(struct tcb *tcp)
2027 if (entering(tcp)) {
2028 printfd(tcp, tcp->u_arg[0]);
2029 printuid(", ", tcp->u_arg[1]);
2030 printuid(", ", tcp->u_arg[2]);
2036 decode_chmod(struct tcb *tcp, int offset)
2038 if (entering(tcp)) {
2039 printpath(tcp, tcp->u_arg[offset]);
2040 tprintf(", %#lo", tcp->u_arg[offset + 1]);
2046 sys_chmod(struct tcb *tcp)
2048 return decode_chmod(tcp, 0);
2052 sys_fchmodat(struct tcb *tcp)
2055 print_dirfd(tcp, tcp->u_arg[0]);
2056 return decode_chmod(tcp, 1);
2060 sys_fchmod(struct tcb *tcp)
2062 if (entering(tcp)) {
2063 printfd(tcp, tcp->u_arg[0]);
2064 tprintf(", %#lo", tcp->u_arg[1]);
2071 sys_osf_utimes(struct tcb *tcp)
2073 if (entering(tcp)) {
2074 printpath(tcp, tcp->u_arg[0]);
2076 printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32, 0);
2083 decode_utimes(struct tcb *tcp, int offset, int special)
2085 if (entering(tcp)) {
2086 printpath(tcp, tcp->u_arg[offset]);
2088 if (tcp->u_arg[offset + 1] == 0)
2092 printtv_bitness(tcp, tcp->u_arg[offset + 1],
2093 BITNESS_CURRENT, special);
2095 printtv_bitness(tcp, tcp->u_arg[offset + 1]
2096 + sizeof(struct timeval),
2097 BITNESS_CURRENT, special);
2105 sys_utimes(struct tcb *tcp)
2107 return decode_utimes(tcp, 0, 0);
2111 sys_futimesat(struct tcb *tcp)
2114 print_dirfd(tcp, tcp->u_arg[0]);
2115 return decode_utimes(tcp, 1, 0);
2119 sys_utimensat(struct tcb *tcp)
2121 if (entering(tcp)) {
2122 print_dirfd(tcp, tcp->u_arg[0]);
2123 decode_utimes(tcp, 1, 1);
2125 printflags(at_flags, tcp->u_arg[3], "AT_???");
2131 sys_utime(struct tcb *tcp)
2136 long paranoia_for_huge_wordsize[4];
2140 if (entering(tcp)) {
2141 printpath(tcp, tcp->u_arg[0]);
2144 wordsize = current_wordsize;
2147 else if (!verbose(tcp))
2148 tprintf("%#lx", tcp->u_arg[1]);
2149 else if (umoven(tcp, tcp->u_arg[1], 2 * wordsize, (char *) &u) < 0)
2151 else if (wordsize == sizeof u.utl[0]) {
2152 tprintf("[%s,", sprinttime(u.utl[0]));
2153 tprintf(" %s]", sprinttime(u.utl[1]));
2155 else if (wordsize == sizeof u.uti[0]) {
2156 tprintf("[%s,", sprinttime(u.uti[0]));
2157 tprintf(" %s]", sprinttime(u.uti[1]));
2160 tprintf("<decode error: unsupported wordsize %d>",
2167 decode_mknod(struct tcb *tcp, int offset)
2169 int mode = tcp->u_arg[offset + 1];
2171 if (entering(tcp)) {
2172 printpath(tcp, tcp->u_arg[offset]);
2173 tprintf(", %s", sprintmode(mode));
2174 switch (mode & S_IFMT) {
2177 #if defined(SPARC) || defined(SPARC64)
2178 if (current_personality == 1)
2179 tprintf(", makedev(%lu, %lu)",
2180 (unsigned long) ((tcp->u_arg[offset + 2] >> 18) & 0x3fff),
2181 (unsigned long) (tcp->u_arg[offset + 2] & 0x3ffff));
2184 tprintf(", makedev(%lu, %lu)",
2185 (unsigned long) major(tcp->u_arg[offset + 2]),
2186 (unsigned long) minor(tcp->u_arg[offset + 2]));
2196 sys_mknod(struct tcb *tcp)
2198 return decode_mknod(tcp, 0);
2202 sys_mknodat(struct tcb *tcp)
2205 print_dirfd(tcp, tcp->u_arg[0]);
2206 return decode_mknod(tcp, 1);
2210 print_old_dirent(struct tcb *tcp, long addr)
2213 typedef struct kernel_dirent old_dirent_t;
2218 unsigned short d_reclen;
2224 if (!verbose(tcp) || umove(tcp, addr, &d) < 0) {
2225 tprintf("%#lx", addr);
2229 tprintf("{d_ino=%lu, d_off=%lu, d_reclen=%u, d_name=\"",
2230 (unsigned long) d.d_ino, (unsigned long) d.d_off, d.d_reclen);
2231 if (d.d_reclen > 256)
2233 printpathn(tcp, addr + offsetof(old_dirent_t, d_name), d.d_reclen);
2238 sys_readdir(struct tcb *tcp)
2240 if (entering(tcp)) {
2241 printfd(tcp, tcp->u_arg[0]);
2244 if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
2245 tprintf("%#lx", tcp->u_arg[1]);
2247 print_old_dirent(tcp, tcp->u_arg[1]);
2248 /* Not much point in printing this out, it is always 1. */
2249 if (tcp->u_arg[2] != 1)
2250 tprintf(", %lu", tcp->u_arg[2]);
2255 static const struct xlat direnttypes[] = {
2256 { DT_UNKNOWN, "DT_UNKNOWN" },
2257 { DT_FIFO, "DT_FIFO" },
2258 { DT_CHR, "DT_CHR" },
2259 { DT_DIR, "DT_DIR" },
2260 { DT_BLK, "DT_BLK" },
2261 { DT_REG, "DT_REG" },
2262 { DT_LNK, "DT_LNK" },
2263 { DT_SOCK, "DT_SOCK" },
2264 { DT_WHT, "DT_WHT" },
2269 sys_getdents(struct tcb *tcp)
2271 int i, len, dents = 0;
2274 if (entering(tcp)) {
2275 printfd(tcp, tcp->u_arg[0]);
2279 if (syserror(tcp) || !verbose(tcp)) {
2280 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2284 /* Beware of insanely large or negative values in tcp->u_rval */
2285 if (tcp->u_rval > 1024*1024)
2287 if (tcp->u_rval < 0)
2289 buf = len ? malloc(len) : NULL;
2291 die_out_of_memory();
2292 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2293 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2299 for (i = 0; i < len;) {
2300 struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
2302 tprintf("%s{d_ino=%lu, d_off=%lu, ",
2303 i ? " " : "", d->d_ino, d->d_off);
2304 tprintf("d_reclen=%u, d_name=\"%s\", d_type=",
2305 d->d_reclen, d->d_name);
2306 printxval(direnttypes, buf[i + d->d_reclen - 1], "DT_???");
2310 tprints("/* d_reclen == 0, problem here */");
2319 tprintf("/* %u entries */", dents);
2320 tprintf(", %lu", tcp->u_arg[2]);
2325 #if _LFS64_LARGEFILE
2327 sys_getdents64(struct tcb *tcp)
2329 int i, len, dents = 0;
2332 if (entering(tcp)) {
2333 printfd(tcp, tcp->u_arg[0]);
2337 if (syserror(tcp) || !verbose(tcp)) {
2338 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2343 /* Beware of insanely large or negative tcp->u_rval */
2344 if (tcp->u_rval > 1024*1024)
2346 if (tcp->u_rval < 0)
2348 buf = len ? malloc(len) : NULL;
2350 die_out_of_memory();
2352 if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
2353 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
2359 for (i = 0; i < len;) {
2360 struct dirent64 *d = (struct dirent64 *) &buf[i];
2362 tprintf("%s{d_ino=%" PRIu64 ", d_off=%" PRId64 ", ",
2367 printxval(direnttypes, d->d_type, "DT_???");
2369 tprintf("d_reclen=%u, d_name=\"%s\"}",
2370 d->d_reclen, d->d_name);
2373 tprints("/* d_reclen == 0, problem here */");
2382 tprintf("/* %u entries */", dents);
2383 tprintf(", %lu", tcp->u_arg[2]);
2390 sys_getcwd(struct tcb *tcp)
2394 tprintf("%#lx", tcp->u_arg[0]);
2396 printpathn(tcp, tcp->u_arg[0], tcp->u_rval - 1);
2397 tprintf(", %lu", tcp->u_arg[1]);
2402 #ifdef HAVE_SYS_ASYNCH_H
2405 sys_aioread(struct tcb *tcp)
2407 struct aio_result_t res;
2409 if (entering(tcp)) {
2410 tprintf("%lu, ", tcp->u_arg[0]);
2413 tprintf("%#lx", tcp->u_arg[1]);
2415 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2416 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2417 printxval(whence, tcp->u_arg[4], "L_???");
2418 if (syserror(tcp) || tcp->u_arg[5] == 0
2419 || umove(tcp, tcp->u_arg[5], &res) < 0)
2420 tprintf(", %#lx", tcp->u_arg[5]);
2422 tprintf(", {aio_return %d aio_errno %d}",
2423 res.aio_return, res.aio_errno);
2429 sys_aiowrite(struct tcb *tcp)
2431 struct aio_result_t res;
2433 if (entering(tcp)) {
2434 tprintf("%lu, ", tcp->u_arg[0]);
2435 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2436 tprintf(", %lu, %lu, ", tcp->u_arg[2], tcp->u_arg[3]);
2437 printxval(whence, tcp->u_arg[4], "L_???");
2440 if (tcp->u_arg[5] == 0)
2442 else if (syserror(tcp)
2443 || umove(tcp, tcp->u_arg[5], &res) < 0)
2444 tprintf(", %#lx", tcp->u_arg[5]);
2446 tprintf(", {aio_return %d aio_errno %d}",
2447 res.aio_return, res.aio_errno);
2453 sys_aiowait(struct tcb *tcp)
2456 printtv(tcp, tcp->u_arg[0]);
2461 sys_aiocancel(struct tcb *tcp)
2463 struct aio_result_t res;
2466 if (tcp->u_arg[0] == 0)
2468 else if (syserror(tcp)
2469 || umove(tcp, tcp->u_arg[0], &res) < 0)
2470 tprintf("%#lx", tcp->u_arg[0]);
2472 tprintf("{aio_return %d aio_errno %d}",
2473 res.aio_return, res.aio_errno);
2478 #endif /* HAVE_SYS_ASYNCH_H */
2480 static const struct xlat xattrflags[] = {
2482 { XATTR_CREATE, "XATTR_CREATE" },
2483 { XATTR_REPLACE, "XATTR_REPLACE" },
2489 print_xattr_val(struct tcb *tcp, int failed,
2491 unsigned long insize,
2497 unsigned long capacity = 4 * size + 1;
2498 unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
2499 if (buf == NULL || /* probably a bogus size argument */
2500 umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
2504 unsigned char *out = buf;
2505 unsigned char *in = &buf[3 * size];
2507 for (i = 0; i < size; ++i) {
2508 if (in[i] >= ' ' && in[i] <= 0x7e)
2511 #define tohex(n) "0123456789abcdef"[n]
2514 *out++ = tohex(in[i] / 16);
2515 *out++ = tohex(in[i] % 16);
2518 /* Don't print terminating NUL if there is one. */
2519 if (i > 0 && in[i - 1] == '\0')
2522 tprintf(", \"%s\", %ld", buf, insize);
2527 tprintf(", 0x%lx, %ld", arg, insize);
2531 sys_setxattr(struct tcb *tcp)
2533 if (entering(tcp)) {
2534 printpath(tcp, tcp->u_arg[0]);
2536 printstr(tcp, tcp->u_arg[1], -1);
2537 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2539 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2545 sys_fsetxattr(struct tcb *tcp)
2547 if (entering(tcp)) {
2548 printfd(tcp, tcp->u_arg[0]);
2550 printstr(tcp, tcp->u_arg[1], -1);
2551 print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
2553 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
2559 sys_getxattr(struct tcb *tcp)
2561 if (entering(tcp)) {
2562 printpath(tcp, tcp->u_arg[0]);
2564 printstr(tcp, tcp->u_arg[1], -1);
2566 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2573 sys_fgetxattr(struct tcb *tcp)
2575 if (entering(tcp)) {
2576 printfd(tcp, tcp->u_arg[0]);
2578 printstr(tcp, tcp->u_arg[1], -1);
2580 print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
2587 print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
2589 if (syserror(tcp)) {
2590 tprintf("%#lx", addr);
2596 (size < tcp->u_rval) ? size : tcp->u_rval;
2597 printstr(tcp, addr, len);
2600 tprintf(", %lu", size);
2604 sys_listxattr(struct tcb *tcp)
2606 if (entering(tcp)) {
2607 printpath(tcp, tcp->u_arg[0]);
2610 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2616 sys_flistxattr(struct tcb *tcp)
2618 if (entering(tcp)) {
2619 printfd(tcp, tcp->u_arg[0]);
2622 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
2628 sys_removexattr(struct tcb *tcp)
2630 if (entering(tcp)) {
2631 printpath(tcp, tcp->u_arg[0]);
2633 printstr(tcp, tcp->u_arg[1], -1);
2639 sys_fremovexattr(struct tcb *tcp)
2641 if (entering(tcp)) {
2642 printfd(tcp, tcp->u_arg[0]);
2644 printstr(tcp, tcp->u_arg[1], -1);
2649 static const struct xlat advise[] = {
2650 { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
2651 { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
2652 { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
2653 { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
2654 { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
2655 { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
2660 sys_fadvise64(struct tcb *tcp)
2662 if (entering(tcp)) {
2664 printfd(tcp, tcp->u_arg[0]);
2665 argn = printllval(tcp, ", %lld", 1);
2666 tprintf(", %ld, ", tcp->u_arg[argn++]);
2667 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2673 sys_fadvise64_64(struct tcb *tcp)
2675 if (entering(tcp)) {
2677 printfd(tcp, tcp->u_arg[0]);
2678 argn = printllval(tcp, ", %lld, ", 1);
2679 argn = printllval(tcp, "%lld, ", argn);
2680 #if defined ARM || defined AARCH64 || defined POWERPC
2681 printxval(advise, tcp->u_arg[1], "POSIX_FADV_???");
2683 printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
2689 static const struct xlat inotify_modes[] = {
2690 { 0x00000001, "IN_ACCESS" },
2691 { 0x00000002, "IN_MODIFY" },
2692 { 0x00000004, "IN_ATTRIB" },
2693 { 0x00000008, "IN_CLOSE_WRITE"},
2694 { 0x00000010, "IN_CLOSE_NOWRITE"},
2695 { 0x00000020, "IN_OPEN" },
2696 { 0x00000040, "IN_MOVED_FROM" },
2697 { 0x00000080, "IN_MOVED_TO" },
2698 { 0x00000100, "IN_CREATE" },
2699 { 0x00000200, "IN_DELETE" },
2700 { 0x00000400, "IN_DELETE_SELF"},
2701 { 0x00000800, "IN_MOVE_SELF" },
2702 { 0x00002000, "IN_UNMOUNT" },
2703 { 0x00004000, "IN_Q_OVERFLOW" },
2704 { 0x00008000, "IN_IGNORED" },
2705 { 0x01000000, "IN_ONLYDIR" },
2706 { 0x02000000, "IN_DONT_FOLLOW"},
2707 { 0x20000000, "IN_MASK_ADD" },
2708 { 0x40000000, "IN_ISDIR" },
2709 { 0x80000000, "IN_ONESHOT" },
2713 static const struct xlat inotify_init_flags[] = {
2714 { 0x00000800, "IN_NONBLOCK" },
2715 { 0x00080000, "IN_CLOEXEC" },
2720 sys_inotify_add_watch(struct tcb *tcp)
2722 if (entering(tcp)) {
2723 printfd(tcp, tcp->u_arg[0]);
2725 printpath(tcp, tcp->u_arg[1]);
2727 printflags(inotify_modes, tcp->u_arg[2], "IN_???");
2733 sys_inotify_rm_watch(struct tcb *tcp)
2735 if (entering(tcp)) {
2736 printfd(tcp, tcp->u_arg[0]);
2737 tprintf(", %d", (int) tcp->u_arg[1]);
2743 sys_inotify_init1(struct tcb *tcp)
2746 printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
2751 sys_fallocate(struct tcb *tcp)
2753 if (entering(tcp)) {
2755 printfd(tcp, tcp->u_arg[0]); /* fd */
2756 tprintf(", %#lo, ", tcp->u_arg[1]); /* mode */
2757 argn = printllval(tcp, "%llu, ", 2); /* offset */
2758 printllval(tcp, "%llu", argn); /* len */
2763 #ifndef SWAP_FLAG_PREFER
2764 # define SWAP_FLAG_PREFER 0x8000
2766 #ifndef SWAP_FLAG_DISCARD
2767 # define SWAP_FLAG_DISCARD 0x10000
2769 static const struct xlat swap_flags[] = {
2770 { SWAP_FLAG_PREFER, "SWAP_FLAG_PREFER" },
2771 { SWAP_FLAG_DISCARD, "SWAP_FLAG_DISCARD" },
2776 sys_swapon(struct tcb *tcp)
2778 if (entering(tcp)) {
2779 int flags = tcp->u_arg[1];
2780 printpath(tcp, tcp->u_arg[0]);
2782 printflags(swap_flags, flags & ~SWAP_FLAG_PRIO_MASK,
2784 if (flags & SWAP_FLAG_PREFER)
2785 tprintf("|%d", flags & SWAP_FLAG_PRIO_MASK);