]> granicus.if.org Git - strace/blobdiff - file.c
Check HAVE_LONG_LONG_OFF_T when printing offset
[strace] / file.c
diff --git a/file.c b/file.c
index dc17854f21a55da92d51512da5a8d1ca68dbff07..db024ef83891d3ffde0784f7e9ec13eb22fe0895 100644 (file)
--- a/file.c
+++ b/file.c
@@ -257,22 +257,21 @@ const struct xlat open_mode_flags[] = {
 #  endif
 # endif
 # ifdef O_LARGEFILE
-       { O_LARGEFILE,  "O_LARGEFILE"   },
+       { O_LARGEFILE,  "O_LARGEFILE"   },
 # endif
 #endif
 #ifdef O_DIRECTORY
-       { O_DIRECTORY,  "O_DIRECTORY"   },
+       { O_DIRECTORY,  "O_DIRECTORY"   },
 #endif
 #ifdef O_NOFOLLOW
-       { O_NOFOLLOW,   "O_NOFOLLOW"    },
+       { O_NOFOLLOW,   "O_NOFOLLOW"    },
 #endif
 #ifdef O_NOATIME
-       { O_NOATIME,    "O_NOATIME"     },
+       { O_NOATIME,    "O_NOATIME"     },
 #endif
 #ifdef O_CLOEXEC
        { O_CLOEXEC,    "O_CLOEXEC"     },
 #endif
-
 #ifdef FNDELAY
        { FNDELAY,      "FNDELAY"       },
 #endif
@@ -331,26 +330,17 @@ const struct xlat open_mode_flags[] = {
  * extension to get the right value.  We do this by declaring fd as int here.
  */
 static void
-print_dirfd(int fd)
+print_dirfd(struct tcb *tcp, int fd)
 {
        if (fd == AT_FDCWD)
-               tprintf("AT_FDCWD, ");
-       else
-               tprintf("%d, ", fd);
+               tprints("AT_FDCWD, ");
+       else {
+               printfd(tcp, fd);
+               tprints(", ");
+       }
 }
 #endif
 
-/*
- * Pity stpcpy() is not standardized...
- */
-static char *
-str_append(char *dst, const char *src)
-{
-       while ((*dst = *src++) != '\0')
-               dst++;
-       return dst;
-}
-
 /*
  * low bits of the open(2) flags define access mode,
  * other bits are real flags.
@@ -358,16 +348,18 @@ str_append(char *dst, const char *src)
 const char *
 sprint_open_modes(mode_t flags)
 {
-       static char outstr[1024];
+       static char outstr[(1 + ARRAY_SIZE(open_mode_flags)) * sizeof("O_LARGEFILE")];
        char *p;
-       char sep = 0;
+       char sep;
        const char *str;
        const struct xlat *x;
 
-       p = str_append(outstr, "flags ");
+       sep = ' ';
+       p = stpcpy(outstr, "flags");
        str = xlookup(open_access_modes, flags & 3);
        if (str) {
-               p = str_append(p, str);
+               *p++ = sep;
+               p = stpcpy(p, str);
                flags &= ~3;
                if (!flags)
                        return outstr;
@@ -376,9 +368,8 @@ sprint_open_modes(mode_t flags)
 
        for (x = open_mode_flags; x->str; x++) {
                if ((flags & x->val) == x->val) {
-                       if (sep)
-                               *p++ = sep;
-                       p = str_append(p, x->str);
+                       *p++ = sep;
+                       p = stpcpy(p, x->str);
                        flags &= ~x->val;
                        if (!flags)
                                return outstr;
@@ -386,8 +377,7 @@ sprint_open_modes(mode_t flags)
                }
        }
        /* flags is still nonzero */
-       if (sep)
-               *p++ = sep;
+       *p++ = sep;
        sprintf(p, "%#x", flags);
        return outstr;
 }
@@ -395,7 +385,7 @@ sprint_open_modes(mode_t flags)
 void
 tprint_open_modes(mode_t flags)
 {
-       tprintf("%s", sprint_open_modes(flags) + sizeof("flags"));
+       tprints(sprint_open_modes(flags) + sizeof("flags"));
 }
 
 static int
@@ -403,7 +393,7 @@ decode_open(struct tcb *tcp, int offset)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[offset]);
-               tprintf(", ");
+               tprints(", ");
                /* flags */
                tprint_open_modes(tcp->u_arg[offset + 1]);
                if (tcp->u_arg[offset + 1] & O_CREAT) {
@@ -425,7 +415,7 @@ int
 sys_openat(struct tcb *tcp)
 {
        if (entering(tcp))
-               print_dirfd(tcp->u_arg[0]);
+               print_dirfd(tcp, tcp->u_arg[0]);
        return decode_open(tcp, 1);
 }
 #endif
@@ -454,7 +444,7 @@ solaris_open(struct tcb *tcp)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
+               tprints(", ");
                /* flags */
                printflags(openmodessol, tcp->u_arg[1] + 1, "O_???");
                if (tcp->u_arg[1] & 0x100) {
@@ -496,7 +486,7 @@ decode_access(struct tcb *tcp, int offset)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[offset]);
-               tprintf(", ");
+               tprints(", ");
                printflags(access_flags, tcp->u_arg[offset + 1], "?_OK");
        }
        return 0;
@@ -513,7 +503,7 @@ int
 sys_faccessat(struct tcb *tcp)
 {
        if (entering(tcp))
-               print_dirfd(tcp->u_arg[0]);
+               print_dirfd(tcp, tcp->u_arg[0]);
        return decode_access(tcp, 1);
 }
 #endif
@@ -543,7 +533,8 @@ sys_lseek(struct tcb *tcp)
        int _whence;
 
        if (entering(tcp)) {
-               tprintf("%ld, ", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
                offset = tcp->ext_arg[1];
                _whence = tcp->u_arg[2];
                if (_whence == SEEK_SET)
@@ -562,7 +553,8 @@ sys_lseek(struct tcb *tcp)
        int _whence;
 
        if (entering(tcp)) {
-               tprintf("%ld, ", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
                offset = tcp->u_arg[1];
                _whence = tcp->u_arg[2];
                if (_whence == SEEK_SET)
@@ -581,19 +573,20 @@ int
 sys_llseek(struct tcb *tcp)
 {
        if (entering(tcp)) {
+               printfd(tcp, tcp->u_arg[0]);
                /*
                 * This one call takes explicitly two 32-bit arguments hi, lo,
                 * rather than one 64-bit argument for which LONG_LONG works
                 * appropriate for the native byte order.
                 */
                if (tcp->u_arg[4] == SEEK_SET)
-                       tprintf("%ld, %llu, ", tcp->u_arg[0],
-                               (((long long int) tcp->u_arg[1]) << 32
-                                | (unsigned long long) (unsigned) tcp->u_arg[2]));
+                       tprintf(", %llu, ",
+                               ((long long int) tcp->u_arg[1]) << 32 |
+                               (unsigned long long) (unsigned) tcp->u_arg[2]);
                else
-                       tprintf("%ld, %lld, ", tcp->u_arg[0],
-                               (((long long int) tcp->u_arg[1]) << 32
-                                | (unsigned long long) (unsigned) tcp->u_arg[2]));
+                       tprintf(", %lld, ",
+                               ((long long int) tcp->u_arg[1]) << 32 |
+                               (unsigned long long) (unsigned) tcp->u_arg[2]);
        }
        else {
                long long int off;
@@ -611,7 +604,8 @@ sys_readahead(struct tcb *tcp)
 {
        if (entering(tcp)) {
                int argn;
-               tprintf("%ld, ", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
                argn = printllval(tcp, "%lld", 1);
                tprintf(", %ld", tcp->u_arg[argn]);
        }
@@ -625,7 +619,8 @@ sys_lseek64(struct tcb *tcp)
 {
        if (entering(tcp)) {
                int argn;
-               tprintf("%ld, ", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
                if (tcp->u_arg[3] == SEEK_SET)
                        argn = printllval(tcp, "%llu, ", 1);
                else
@@ -665,7 +660,8 @@ int
 sys_ftruncate(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               tprintf("%ld, %lu", tcp->u_arg[0], tcp->u_arg[1]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprintf(", %lu", tcp->u_arg[1]);
        }
        return 0;
 }
@@ -676,7 +672,8 @@ int
 sys_ftruncate64(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               tprintf("%ld, ", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
                printllval(tcp, "%llu", 1);
        }
        return 0;
@@ -729,7 +726,8 @@ sprinttime(time_t t)
                strcpy(buf, "0");
                return buf;
        }
-       if ((tmp = localtime(&t)))
+       tmp = localtime(&t);
+       if (tmp)
                snprintf(buf, sizeof buf, "%02d/%02d/%02d-%02d:%02d:%02d",
                        tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
                        tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
@@ -772,7 +770,7 @@ printstatsol(struct tcb *tcp, long addr)
        struct solstat statbuf;
 
        if (umove(tcp, addr, &statbuf) < 0) {
-               tprintf("{...}");
+               tprints("{...}");
                return;
        }
        if (!abbrev(tcp)) {
@@ -806,7 +804,7 @@ printstatsol(struct tcb *tcp, long addr)
                tprintf("st_ctime=%s}", sprinttime(statbuf.st_ctime.tv_sec));
        }
        else
-               tprintf("...}");
+               tprints("...}");
 }
 
 #if defined (SPARC64)
@@ -816,7 +814,7 @@ printstat_sparc64(struct tcb *tcp, long addr)
        struct stat_sparc64 statbuf;
 
        if (umove(tcp, addr, &statbuf) < 0) {
-               tprintf("{...}");
+               tprints("{...}");
                return;
        }
 
@@ -851,10 +849,10 @@ printstat_sparc64(struct tcb *tcp, long addr)
                tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
                tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
                tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
-               tprintf("}");
+               tprints("}");
        }
        else
-               tprintf("...}");
+               tprints("...}");
 }
 #endif /* SPARC64 */
 #endif /* LINUXSPARC */
@@ -887,7 +885,7 @@ printstat_powerpc32(struct tcb *tcp, long addr)
        struct stat_powerpc32 statbuf;
 
        if (umove(tcp, addr, &statbuf) < 0) {
-               tprintf("{...}");
+               tprints("{...}");
                return;
        }
 
@@ -917,10 +915,10 @@ printstat_powerpc32(struct tcb *tcp, long addr)
                tprintf("st_atime=%s, ", sprinttime(statbuf.st_atime));
                tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
                tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
-               tprintf("}");
+               tprints("}");
        }
        else
-               tprintf("...}");
+               tprints("...}");
 }
 #endif /* LINUX && POWERPC64 */
 
@@ -936,11 +934,11 @@ static const struct xlat fileflags[] = {
        { SF_APPEND,    "SF_APPEND"     },
        { SF_NOUNLINK,  "SF_NOUNLINK"   },
 #elif UNIXWARE >= 2
-#ifdef         _S_ISMLD
-       { _S_ISMLD,     "_S_ISMLD"      },
+#ifdef _S_ISMLD
+       { _S_ISMLD,     "_S_ISMLD"      },
 #endif
-#ifdef         _S_ISMOUNTED
-       { _S_ISMOUNTED, "_S_ISMOUNTED"  },
+#ifdef _S_ISMOUNTED
+       { _S_ISMOUNTED, "_S_ISMOUNTED"  },
 #endif
 #endif
        { 0,            NULL            },
@@ -952,7 +950,7 @@ sys_chflags(struct tcb *tcp)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
+               tprints(", ");
                printflags(fileflags, tcp->u_arg[1], "UF_???");
        }
        return 0;
@@ -1013,7 +1011,7 @@ realprintstat(struct tcb *tcp, struct stat *statbuf)
                tprintf("st_mtime=%s, ", sprinttime(statbuf->st_mtime));
                tprintf("st_ctime=%s", sprinttime(statbuf->st_ctime));
 #if HAVE_STRUCT_STAT_ST_FLAGS
-               tprintf(", st_flags=");
+               tprints(", st_flags=");
                printflags(fileflags, statbuf->st_flags, "UF_???");
 #endif
 #if HAVE_STRUCT_STAT_ST_ACLCNT
@@ -1029,10 +1027,10 @@ realprintstat(struct tcb *tcp, struct stat *statbuf)
 #if HAVE_STRUCT_STAT_ST_GEN
                tprintf(", st_gen=%u", statbuf->st_gen);
 #endif
-               tprintf("}");
+               tprints("}");
        }
        else
-               tprintf("...}");
+               tprints("...}");
 }
 
 
@@ -1042,7 +1040,7 @@ printstat(struct tcb *tcp, long addr)
        struct stat statbuf;
 
        if (!addr) {
-               tprintf("NULL");
+               tprints("NULL");
                return;
        }
        if (syserror(tcp) || !verbose(tcp)) {
@@ -1071,7 +1069,7 @@ printstat(struct tcb *tcp, long addr)
 #endif
 
        if (umove(tcp, addr, &statbuf) < 0) {
-               tprintf("{...}");
+               tprints("{...}");
                return;
        }
 
@@ -1122,7 +1120,7 @@ printstat64(struct tcb *tcp, long addr)
 #endif
 
        if (!addr) {
-               tprintf("NULL");
+               tprints("NULL");
                return;
        }
        if (syserror(tcp) || !verbose(tcp)) {
@@ -1151,7 +1149,7 @@ printstat64(struct tcb *tcp, long addr)
 #endif
 
        if (umove(tcp, addr, &statbuf) < 0) {
-               tprintf("{...}");
+               tprints("{...}");
                return;
        }
 
@@ -1208,7 +1206,7 @@ printstat64(struct tcb *tcp, long addr)
                tprintf("st_mtime=%s, ", sprinttime(statbuf.st_mtime));
                tprintf("st_ctime=%s", sprinttime(statbuf.st_ctime));
 #if HAVE_STRUCT_STAT_ST_FLAGS
-               tprintf(", st_flags=");
+               tprints(", st_flags=");
                printflags(fileflags, statbuf.st_flags, "UF_???");
 #endif
 #if HAVE_STRUCT_STAT_ST_ACLCNT
@@ -1224,14 +1222,15 @@ printstat64(struct tcb *tcp, long addr)
 #if HAVE_STRUCT_STAT_ST_GEN
                tprintf(", st_gen=%u", statbuf.st_gen);
 #endif
-               tprintf("}");
+               tprints("}");
        }
        else
-               tprintf("...}");
+               tprints("...}");
 }
 #endif /* HAVE_STAT64 */
 
-#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
+#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT) \
+    && !defined(HAVE_LONG_LONG_OFF_T)
 static void
 convertoldstat(const struct __old_kernel_stat *oldbuf, struct stat *newbuf)
 {
@@ -1258,7 +1257,7 @@ printoldstat(struct tcb *tcp, long addr)
        struct stat newstatbuf;
 
        if (!addr) {
-               tprintf("NULL");
+               tprints("NULL");
                return;
        }
        if (syserror(tcp) || !verbose(tcp)) {
@@ -1274,7 +1273,7 @@ printoldstat(struct tcb *tcp, long addr)
 #endif /* LINUXSPARC */
 
        if (umove(tcp, addr, &statbuf) < 0) {
-               tprintf("{...}");
+               tprints("{...}");
                return;
        }
 
@@ -1289,7 +1288,7 @@ sys_stat(struct tcb *tcp)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
+               tprints(", ");
        } else {
                printstat(tcp, tcp->u_arg[1]);
        }
@@ -1303,7 +1302,7 @@ sys_stat64(struct tcb *tcp)
 #ifdef HAVE_STAT64
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
+               tprints(", ");
        } else {
                printstat64(tcp, tcp->u_arg[1]);
        }
@@ -1327,9 +1326,9 @@ int
 sys_newfstatat(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               print_dirfd(tcp->u_arg[0]);
+               print_dirfd(tcp, tcp->u_arg[0]);
                printpath(tcp, tcp->u_arg[1]);
-               tprintf(", ");
+               tprints(", ");
        } else {
 #ifdef POWERPC64
                if (current_personality == 0)
@@ -1341,20 +1340,21 @@ sys_newfstatat(struct tcb *tcp)
 #else
                printstat(tcp, tcp->u_arg[2]);
 #endif
-               tprintf(", ");
+               tprints(", ");
                printflags(fstatatflags, tcp->u_arg[3], "AT_???");
        }
        return 0;
 }
 #endif
 
-#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
+#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT) \
+    && !defined(HAVE_LONG_LONG_OFF_T)
 int
 sys_oldstat(struct tcb *tcp)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
+               tprints(", ");
        } else {
                printoldstat(tcp, tcp->u_arg[1]);
        }
@@ -1366,9 +1366,10 @@ sys_oldstat(struct tcb *tcp)
 int
 sys_fstat(struct tcb *tcp)
 {
-       if (entering(tcp))
-               tprintf("%ld, ", tcp->u_arg[0]);
-       else {
+       if (entering(tcp)) {
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
+       } else {
                printstat(tcp, tcp->u_arg[1]);
        }
        return 0;
@@ -1379,9 +1380,10 @@ int
 sys_fstat64(struct tcb *tcp)
 {
 #ifdef HAVE_STAT64
-       if (entering(tcp))
-               tprintf("%ld, ", tcp->u_arg[0]);
-       else {
+       if (entering(tcp)) {
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
+       } else {
                printstat64(tcp, tcp->u_arg[1]);
        }
        return 0;
@@ -1390,13 +1392,15 @@ sys_fstat64(struct tcb *tcp)
 #endif
 }
 
-#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
+#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT) \
+    && !defined(HAVE_LONG_LONG_OFF_T)
 int
 sys_oldfstat(struct tcb *tcp)
 {
-       if (entering(tcp))
-               tprintf("%ld, ", tcp->u_arg[0]);
-       else {
+       if (entering(tcp)) {
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
+       } else {
                printoldstat(tcp, tcp->u_arg[1]);
        }
        return 0;
@@ -1409,7 +1413,7 @@ sys_lstat(struct tcb *tcp)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
+               tprints(", ");
        } else {
                printstat(tcp, tcp->u_arg[1]);
        }
@@ -1423,7 +1427,7 @@ sys_lstat64(struct tcb *tcp)
 #ifdef HAVE_STAT64
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
+               tprints(", ");
        } else {
                printstat64(tcp, tcp->u_arg[1]);
        }
@@ -1433,13 +1437,14 @@ sys_lstat64(struct tcb *tcp)
 #endif
 }
 
-#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT)
+#if defined(LINUX) && defined(HAVE_STRUCT___OLD_KERNEL_STAT) \
+    && !defined(HAVE_LONG_LONG_OFF_T)
 int
 sys_oldlstat(struct tcb *tcp)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
+               tprints(", ");
        } else {
                printoldstat(tcp, tcp->u_arg[1]);
        }
@@ -1456,7 +1461,7 @@ sys_xstat(struct tcb *tcp)
        if (entering(tcp)) {
                tprintf("%ld, ", tcp->u_arg[0]);
                printpath(tcp, tcp->u_arg[1]);
-               tprintf(", ");
+               tprints(", ");
        } else {
 #ifdef _STAT64_VER
                if (tcp->u_arg[0] == _STAT64_VER)
@@ -1490,7 +1495,7 @@ sys_lxstat(struct tcb *tcp)
        if (entering(tcp)) {
                tprintf("%ld, ", tcp->u_arg[0]);
                printpath(tcp, tcp->u_arg[1]);
-               tprintf(", ");
+               tprints(", ");
        } else {
 #ifdef _STAT64_VER
                if (tcp->u_arg[0] == _STAT64_VER)
@@ -1561,7 +1566,7 @@ sys_acl(struct tcb *tcp)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
+               tprints(", ");
                printxval(aclcmds, tcp->u_arg[1], "???ACL???");
                tprintf(", %ld", tcp->u_arg[2]);
                /*
@@ -1571,7 +1576,7 @@ sys_acl(struct tcb *tcp)
                if (tcp->u_arg[3])
                        tprintf(", %#lx", tcp->u_arg[3]);
                else
-                       tprintf(", NULL");
+                       tprints(", NULL");
        }
        return 0;
 }
@@ -1591,7 +1596,7 @@ sys_facl(struct tcb *tcp)
                if (tcp->u_arg[3])
                        tprintf(", %#lx", tcp->u_arg[3]);
                else
-                       tprintf(", NULL");
+                       tprints(", NULL");
        }
        return 0;
 }
@@ -1626,7 +1631,7 @@ sys_aclipc(struct tcb *tcp)
                if (tcp->u_arg[4])
                        tprintf(", %#lx", tcp->u_arg[4]);
                else
-                       tprintf(", NULL");
+                       tprints(", NULL");
        }
        return 0;
 }
@@ -1701,7 +1706,7 @@ printstatfs(struct tcb *tcp, long addr)
                return;
        }
        if (umove(tcp, addr, &statbuf) < 0) {
-               tprintf("{...}");
+               tprints("{...}");
                return;
        }
 #ifdef ALPHA
@@ -1710,7 +1715,7 @@ printstatfs(struct tcb *tcp, long addr)
                sprintfstype(statbuf.f_type),
                statbuf.f_bsize, statbuf.f_blocks, statbuf.f_bfree);
        tprintf("f_bavail=%u, f_files=%u, f_ffree=%u, f_fsid={%d, %d}, f_namelen=%u",
-               statbuf.f_bavail,statbuf.f_files, statbuf.f_ffree,
+               statbuf.f_bavail, statbuf.f_files, statbuf.f_ffree,
                statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1],
                statbuf.f_namelen);
 #else /* !ALPHA */
@@ -1731,7 +1736,7 @@ printstatfs(struct tcb *tcp, long addr)
 #ifdef _STATFS_F_FRSIZE
        tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
 #endif
-       tprintf("}");
+       tprints("}");
 }
 
 int
@@ -1739,7 +1744,7 @@ sys_statfs(struct tcb *tcp)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
+               tprints(", ");
        } else {
                printstatfs(tcp, tcp->u_arg[1]);
        }
@@ -1750,7 +1755,8 @@ int
 sys_fstatfs(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               tprintf("%lu, ", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
        } else {
                printstatfs(tcp, tcp->u_arg[1]);
        }
@@ -1768,7 +1774,7 @@ printstatfs64(struct tcb *tcp, long addr)
                return;
        }
        if (umove(tcp, addr, &statbuf) < 0) {
-               tprintf("{...}");
+               tprints("{...}");
                return;
        }
        tprintf("{f_type=%s, f_bsize=%llu, f_blocks=%llu, f_bfree=%llu, ",
@@ -1785,7 +1791,58 @@ printstatfs64(struct tcb *tcp, long addr)
 #ifdef _STATFS_F_FRSIZE
        tprintf(", f_frsize=%llu", (unsigned long long)statbuf.f_frsize);
 #endif
-       tprintf("}");
+#ifdef _STATFS_F_FLAGS
+       tprintf(", f_flags=%llu", (unsigned long long)statbuf.f_flags);
+#endif
+       tprints("}");
+}
+
+struct compat_statfs64 {
+       uint32_t f_type;
+       uint32_t f_bsize;
+       uint64_t f_blocks;
+       uint64_t f_bfree;
+       uint64_t f_bavail;
+       uint64_t f_files;
+       uint64_t f_ffree;
+       fsid_t f_fsid;
+       uint32_t f_namelen;
+       uint32_t f_frsize;
+       uint32_t f_flags;
+       uint32_t f_spare[4];
+}
+#if defined(X86_64) || defined(IA64)
+  __attribute__ ((packed, aligned(4)))
+#endif
+;
+
+static void
+printcompat_statfs64(struct tcb *tcp, long addr)
+{
+       struct compat_statfs64 statbuf;
+
+       if (syserror(tcp) || !verbose(tcp)) {
+               tprintf("%#lx", addr);
+               return;
+       }
+       if (umove(tcp, addr, &statbuf) < 0) {
+               tprints("{...}");
+               return;
+       }
+       tprintf("{f_type=%s, f_bsize=%lu, f_blocks=%llu, f_bfree=%llu, ",
+               sprintfstype(statbuf.f_type),
+               (unsigned long)statbuf.f_bsize,
+               (unsigned long long)statbuf.f_blocks,
+               (unsigned long long)statbuf.f_bfree);
+       tprintf("f_bavail=%llu, f_files=%llu, f_ffree=%llu, f_fsid={%d, %d}",
+               (unsigned long long)statbuf.f_bavail,
+               (unsigned long long)statbuf.f_files,
+               (unsigned long long)statbuf.f_ffree,
+               statbuf.f_fsid.__val[0], statbuf.f_fsid.__val[1]);
+       tprintf(", f_namelen=%lu", (unsigned long)statbuf.f_namelen);
+       tprintf(", f_frsize=%lu", (unsigned long)statbuf.f_frsize);
+       tprintf(", f_flags=%lu", (unsigned long)statbuf.f_frsize);
+       tprints("}");
 }
 
 int
@@ -1795,10 +1852,12 @@ sys_statfs64(struct tcb *tcp)
                printpath(tcp, tcp->u_arg[0]);
                tprintf(", %lu, ", tcp->u_arg[1]);
        } else {
-               if (tcp->u_arg[1] == sizeof (struct statfs64))
+               if (tcp->u_arg[1] == sizeof(struct statfs64))
                        printstatfs64(tcp, tcp->u_arg[2]);
+               else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
+                       printcompat_statfs64(tcp, tcp->u_arg[2]);
                else
-                       tprintf("{???}");
+                       tprints("{???}");
        }
        return 0;
 }
@@ -1807,12 +1866,15 @@ int
 sys_fstatfs64(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               tprintf("%lu, %lu, ", tcp->u_arg[0], tcp->u_arg[1]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprintf(", %lu, ", tcp->u_arg[1]);
        } else {
-               if (tcp->u_arg[1] == sizeof (struct statfs64))
+               if (tcp->u_arg[1] == sizeof(struct statfs64))
                        printstatfs64(tcp, tcp->u_arg[2]);
+               else if (tcp->u_arg[1] == sizeof(struct compat_statfs64))
+                       printcompat_statfs64(tcp, tcp->u_arg[2]);
                else
-                       tprintf("{???}");
+                       tprints("{???}");
        }
        return 0;
 }
@@ -1825,7 +1887,7 @@ osf_statfs(struct tcb *tcp)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
+               tprints(", ");
        } else {
                printstatfs(tcp, tcp->u_arg[1]);
                tprintf(", %lu", tcp->u_arg[2]);
@@ -1863,7 +1925,7 @@ sys_ustat(struct tcb *tcp)
                if (syserror(tcp) || !verbose(tcp))
                        tprintf("%#lx", tcp->u_arg[1]);
                else if (umove(tcp, tcp->u_arg[1], &statbuf) < 0)
-                       tprintf("{...}");
+                       tprints("{...}");
                else {
                        tprintf("{f_tfree=%lu, f_tinode=%lu, ",
                                statbuf.f_tfree, statbuf.f_tinode);
@@ -1879,18 +1941,6 @@ sys_ustat(struct tcb *tcp)
 }
 #endif /* SUNOS4 */
 
-int
-sys_pivotroot(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
-               printpath(tcp, tcp->u_arg[1]);
-       }
-       return 0;
-}
-
-
 /* directory */
 int
 sys_chdir(struct tcb *tcp)
@@ -1922,55 +1972,17 @@ int
 sys_mkdirat(struct tcb *tcp)
 {
        if (entering(tcp))
-               print_dirfd(tcp->u_arg[0]);
+               print_dirfd(tcp, tcp->u_arg[0]);
        return decode_mkdir(tcp, 1);
 }
 #endif
 
-int
-sys_rmdir(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               printpath(tcp, tcp->u_arg[0]);
-       }
-       return 0;
-}
-
-int
-sys_fchdir(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               tprintf("%ld", tcp->u_arg[0]);
-       }
-       return 0;
-}
-
-int
-sys_chroot(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               printpath(tcp, tcp->u_arg[0]);
-       }
-       return 0;
-}
-
-#if defined(SUNOS4) || defined(SVR4)
-int
-sys_fchroot(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               tprintf("%ld", tcp->u_arg[0]);
-       }
-       return 0;
-}
-#endif /* SUNOS4 || SVR4 */
-
 int
 sys_link(struct tcb *tcp)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
+               tprints(", ");
                printpath(tcp, tcp->u_arg[1]);
        }
        return 0;
@@ -1981,26 +1993,18 @@ int
 sys_linkat(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               print_dirfd(tcp->u_arg[0]);
+               print_dirfd(tcp, tcp->u_arg[0]);
                printpath(tcp, tcp->u_arg[1]);
-               tprintf(", ");
-               print_dirfd(tcp->u_arg[2]);
+               tprints(", ");
+               print_dirfd(tcp, tcp->u_arg[2]);
                printpath(tcp, tcp->u_arg[3]);
-               tprintf(", %ld", tcp->u_arg[4]);
+               tprints(", ");
+               printfd(tcp, tcp->u_arg[4]);
        }
        return 0;
 }
 #endif
 
-int
-sys_unlink(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               printpath(tcp, tcp->u_arg[0]);
-       }
-       return 0;
-}
-
 #ifdef LINUX
 static const struct xlat unlinkatflags[] = {
 #ifndef AT_REMOVEDIR
@@ -2014,34 +2018,23 @@ int
 sys_unlinkat(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               print_dirfd(tcp->u_arg[0]);
+               print_dirfd(tcp, tcp->u_arg[0]);
                printpath(tcp, tcp->u_arg[1]);
-               tprintf(", ");
+               tprints(", ");
                printflags(unlinkatflags, tcp->u_arg[2], "AT_???");
        }
        return 0;
 }
 #endif
 
-int
-sys_symlink(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
-               printpath(tcp, tcp->u_arg[1]);
-       }
-       return 0;
-}
-
 #ifdef LINUX
 int
 sys_symlinkat(struct tcb *tcp)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
-               print_dirfd(tcp->u_arg[1]);
+               tprints(", ");
+               print_dirfd(tcp, tcp->u_arg[1]);
                printpath(tcp, tcp->u_arg[2]);
        }
        return 0;
@@ -2053,12 +2046,19 @@ decode_readlink(struct tcb *tcp, int offset)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[offset]);
-               tprintf(", ");
+               tprints(", ");
        } else {
                if (syserror(tcp))
                        tprintf("%#lx", tcp->u_arg[offset + 1]);
                else
-                       printpathn(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
+                       /* Used to use printpathn(), but readlink
+                        * neither includes NUL in the returned count,
+                        * nor actually writes it into memory.
+                        * printpathn() would decide on printing
+                        * "..." continuation based on garbage
+                        * past return buffer's end.
+                        */
+                       printstr(tcp, tcp->u_arg[offset + 1], tcp->u_rval);
                tprintf(", %lu", tcp->u_arg[offset + 2]);
        }
        return 0;
@@ -2075,31 +2075,20 @@ int
 sys_readlinkat(struct tcb *tcp)
 {
        if (entering(tcp))
-               print_dirfd(tcp->u_arg[0]);
+               print_dirfd(tcp, tcp->u_arg[0]);
        return decode_readlink(tcp, 1);
 }
 #endif
 
-int
-sys_rename(struct tcb *tcp)
-{
-       if (entering(tcp)) {
-               printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
-               printpath(tcp, tcp->u_arg[1]);
-       }
-       return 0;
-}
-
 #ifdef LINUX
 int
 sys_renameat(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               print_dirfd(tcp->u_arg[0]);
+               print_dirfd(tcp, tcp->u_arg[0]);
                printpath(tcp, tcp->u_arg[1]);
-               tprintf(", ");
-               print_dirfd(tcp->u_arg[2]);
+               tprints(", ");
+               print_dirfd(tcp, tcp->u_arg[2]);
                printpath(tcp, tcp->u_arg[3]);
        }
        return 0;
@@ -2122,11 +2111,11 @@ int
 sys_fchownat(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               print_dirfd(tcp->u_arg[0]);
+               print_dirfd(tcp, tcp->u_arg[0]);
                printpath(tcp, tcp->u_arg[1]);
                printuid(", ", tcp->u_arg[2]);
                printuid(", ", tcp->u_arg[3]);
-               tprintf(", ");
+               tprints(", ");
                printflags(fstatatflags, tcp->u_arg[4], "AT_???");
        }
        return 0;
@@ -2137,7 +2126,7 @@ int
 sys_fchown(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               tprintf("%ld", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
                printuid(", ", tcp->u_arg[1]);
                printuid(", ", tcp->u_arg[2]);
        }
@@ -2165,7 +2154,7 @@ int
 sys_fchmodat(struct tcb *tcp)
 {
        if (entering(tcp))
-               print_dirfd(tcp->u_arg[0]);
+               print_dirfd(tcp, tcp->u_arg[0]);
        return decode_chmod(tcp, 1);
 }
 #endif
@@ -2174,7 +2163,8 @@ int
 sys_fchmod(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               tprintf("%ld, %#lo", tcp->u_arg[0], tcp->u_arg[1]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprintf(", %#lo", tcp->u_arg[1]);
        }
        return 0;
 }
@@ -2185,7 +2175,7 @@ sys_osf_utimes(struct tcb *tcp)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
+               tprints(", ");
                printtv_bitness(tcp, tcp->u_arg[1], BITNESS_32,  0);
        }
        return 0;
@@ -2197,18 +2187,18 @@ decode_utimes(struct tcb *tcp, int offset, int special)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[offset]);
-               tprintf(", ");
+               tprints(", ");
                if (tcp->u_arg[offset + 1] == 0)
-                       tprintf("NULL");
+                       tprints("NULL");
                else {
-                       tprintf("{");
+                       tprints("{");
                        printtv_bitness(tcp, tcp->u_arg[offset + 1],
                                        BITNESS_CURRENT, special);
-                       tprintf(", ");
+                       tprints(", ");
                        printtv_bitness(tcp, tcp->u_arg[offset + 1]
-                                       + sizeof (struct timeval),
+                                       + sizeof(struct timeval),
                                        BITNESS_CURRENT, special);
-                       tprintf("}");
+                       tprints("}");
                }
        }
        return 0;
@@ -2225,7 +2215,7 @@ int
 sys_futimesat(struct tcb *tcp)
 {
        if (entering(tcp))
-               print_dirfd(tcp->u_arg[0]);
+               print_dirfd(tcp, tcp->u_arg[0]);
        return decode_utimes(tcp, 1, 0);
 }
 
@@ -2233,9 +2223,9 @@ int
 sys_utimensat(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               print_dirfd(tcp->u_arg[0]);
+               print_dirfd(tcp, tcp->u_arg[0]);
                decode_utimes(tcp, 1, 1);
-               tprintf(", ");
+               tprints(", ");
                printflags(utimensatflags, tcp->u_arg[3], "AT_???");
        }
        return 0;
@@ -2252,15 +2242,15 @@ sys_utime(struct tcb *tcp)
 
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
+               tprints(", ");
                if (!tcp->u_arg[1])
-                       tprintf("NULL");
+                       tprints("NULL");
                else if (!verbose(tcp))
                        tprintf("%#lx", tcp->u_arg[1]);
                else if (umoven(tcp, tcp->u_arg[1],
                                2 * personality_wordsize[current_personality],
                                (char *) &u) < 0)
-                       tprintf("[?, ?]");
+                       tprints("[?, ?]");
                else if (personality_wordsize[current_personality]
                         == sizeof u.utl[0]) {
                        tprintf("[%s,", sprinttime(u.utl[0]));
@@ -2316,7 +2306,7 @@ int
 sys_mknodat(struct tcb *tcp)
 {
        if (entering(tcp))
-               print_dirfd(tcp->u_arg[0]);
+               print_dirfd(tcp, tcp->u_arg[0]);
        return decode_mknod(tcp, 1);
 }
 #endif
@@ -2337,7 +2327,7 @@ int
 sys_fsync(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               tprintf("%ld", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
        }
        return 0;
 }
@@ -2354,20 +2344,21 @@ printdir(struct tcb *tcp, long addr)
                return;
        }
        if (umove(tcp, addr, &d) < 0) {
-               tprintf("{...}");
+               tprints("{...}");
                return;
        }
        tprintf("{d_ino=%ld, ", (unsigned long) d.d_ino);
-       tprintf("d_name=");
+       tprints("d_name=");
        printpathn(tcp, (long) ((struct dirent *) addr)->d_name, d.d_reclen);
-       tprintf("}");
+       tprints("}");
 }
 
 int
 sys_readdir(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               tprintf("%lu, ", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
        } else {
                if (syserror(tcp) || tcp->u_rval == 0 || !verbose(tcp))
                        tprintf("%#lx", tcp->u_arg[1]);
@@ -2384,15 +2375,15 @@ sys_readdir(struct tcb *tcp)
 
 #if defined FREEBSD || defined LINUX
 static const struct xlat direnttypes[] = {
-       { DT_UNKNOWN,   "DT_UNKNOWN"    },
-       { DT_FIFO,      "DT_FIFO"       },
-       { DT_CHR,       "DT_CHR"        },
-       { DT_DIR,       "DT_DIR"        },
-       { DT_BLK,       "DT_BLK"        },
-       { DT_REG,       "DT_REG"        },
-       { DT_LNK,       "DT_LNK"        },
-       { DT_SOCK,      "DT_SOCK"       },
-       { DT_WHT,       "DT_WHT"        },
+       { DT_UNKNOWN,   "DT_UNKNOWN"    },
+       { DT_FIFO,      "DT_FIFO"       },
+       { DT_CHR,       "DT_CHR"        },
+       { DT_DIR,       "DT_DIR"        },
+       { DT_BLK,       "DT_BLK"        },
+       { DT_REG,       "DT_REG"        },
+       { DT_LNK,       "DT_LNK"        },
+       { DT_SOCK,      "DT_SOCK"       },
+       { DT_WHT,       "DT_WHT"        },
        { 0,            NULL            },
 };
 
@@ -2405,7 +2396,8 @@ sys_getdents(struct tcb *tcp)
        char *buf;
 
        if (entering(tcp)) {
-               tprintf("%lu, ", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
                return 0;
        }
        if (syserror(tcp) || !verbose(tcp)) {
@@ -2413,19 +2405,21 @@ sys_getdents(struct tcb *tcp)
                return 0;
        }
        len = tcp->u_rval;
+       /* Beware of insanely large or negative values in tcp->u_rval */
+       if (tcp->u_rval > 1024*1024)
+               len = 1024*1024;
+       if (tcp->u_rval < 0)
+               len = 0;
        buf = len ? malloc(len) : NULL;
-       if (len && !buf) {
-               tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
-               fprintf(stderr, "out of memory\n");
-               return 0;
-       }
+       if (len && !buf)
+               die_out_of_memory();
        if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
                tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
                free(buf);
                return 0;
        }
        if (!abbrev(tcp))
-               tprintf("{");
+               tprints("{");
        for (i = 0; i < len;) {
                struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
 #ifdef LINUX
@@ -2465,14 +2459,14 @@ sys_getdents(struct tcb *tcp)
                }
 #endif /* FREEBSD */
                if (!d->d_reclen) {
-                       tprintf("/* d_reclen == 0, problem here */");
+                       tprints("/* d_reclen == 0, problem here */");
                        break;
                }
                i += d->d_reclen;
                dents++;
        }
        if (!abbrev(tcp))
-               tprintf("}");
+               tprints("}");
        else
                tprintf("/* %u entries */", dents);
        tprintf(", %lu", tcp->u_arg[2]);
@@ -2489,27 +2483,32 @@ sys_getdents64(struct tcb *tcp)
        char *buf;
 
        if (entering(tcp)) {
-               tprintf("%lu, ", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
                return 0;
        }
        if (syserror(tcp) || !verbose(tcp)) {
                tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
                return 0;
        }
+
        len = tcp->u_rval;
+       /* Beware of insanely large or negative tcp->u_rval */
+       if (tcp->u_rval > 1024*1024)
+               len = 1024*1024;
+       if (tcp->u_rval < 0)
+               len = 0;
        buf = len ? malloc(len) : NULL;
-       if (len && !buf) {
-               tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
-               fprintf(stderr, "out of memory\n");
-               return 0;
-       }
+       if (len && !buf)
+               die_out_of_memory();
+
        if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
                tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
                free(buf);
                return 0;
        }
        if (!abbrev(tcp))
-               tprintf("{");
+               tprints("{");
        for (i = 0; i < len;) {
                struct dirent64 *d = (struct dirent64 *) &buf[i];
 #if defined(LINUX) || defined(SVR4)
@@ -2519,9 +2518,9 @@ sys_getdents64(struct tcb *tcp)
                                d->d_ino,
                                d->d_off);
 #ifdef LINUX
-                       tprintf("d_type=");
+                       tprints("d_type=");
                        printxval(direnttypes, d->d_type, "DT_???");
-                       tprintf(", ");
+                       tprints(", ");
 #endif
                        tprintf("d_reclen=%u, d_name=\"%s\"}",
                                d->d_reclen, d->d_name);
@@ -2537,14 +2536,14 @@ sys_getdents64(struct tcb *tcp)
                }
 #endif /* SUNOS4 */
                if (!d->d_reclen) {
-                       tprintf("/* d_reclen == 0, problem here */");
+                       tprints("/* d_reclen == 0, problem here */");
                        break;
                }
                i += d->d_reclen;
                dents++;
        }
        if (!abbrev(tcp))
-               tprintf("}");
+               tprints("}");
        else
                tprintf("/* %u entries */", dents);
        tprintf(", %lu", tcp->u_arg[2]);
@@ -2562,26 +2561,32 @@ sys_getdirentries(struct tcb *tcp)
        char *buf;
 
        if (entering(tcp)) {
-               tprintf("%lu, ", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
                return 0;
        }
        if (syserror(tcp) || !verbose(tcp)) {
                tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
                return 0;
        }
+
        len = tcp->u_rval;
-       if ((buf = malloc(len)) == NULL) {
-               tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
-               fprintf(stderr, "out of memory\n");
-               return 0;
-       }
+       /* Beware of insanely large or negative tcp->u_rval */
+       if (tcp->u_rval > 1024*1024)
+               len = 1024*1024;
+       if (tcp->u_rval < 0)
+               len = 0;
+       buf = malloc(len);
+       if (!buf)
+               die_out_of_memory();
+
        if (umoven(tcp, tcp->u_arg[1], len, buf) < 0) {
                tprintf("%#lx, %lu, %#lx", tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
                free(buf);
                return 0;
        }
        if (!abbrev(tcp))
-               tprintf("{");
+               tprints("{");
        for (i = 0; i < len;) {
                struct kernel_dirent *d = (struct kernel_dirent *) &buf[i];
                if (!abbrev(tcp)) {
@@ -2592,14 +2597,14 @@ sys_getdirentries(struct tcb *tcp)
                                d->d_namlen, d->d_namlen, d->d_name);
                }
                if (!d->d_reclen) {
-                       tprintf("/* d_reclen == 0, problem here */");
+                       tprints("/* d_reclen == 0, problem here */");
                        break;
                }
                i += d->d_reclen;
                dents++;
        }
        if (!abbrev(tcp))
-               tprintf("}");
+               tprints("}");
        else
                tprintf("/* %u entries */", dents);
        free(buf);
@@ -2681,7 +2686,7 @@ sys_aiowrite(struct tcb *tcp)
        }
        else {
                if (tcp->u_arg[5] == 0)
-                       tprintf(", NULL");
+                       tprints(", NULL");
                else if (syserror(tcp)
                    || umove(tcp, tcp->u_arg[5], &res) < 0)
                        tprintf(", %#lx", tcp->u_arg[5]);
@@ -2707,7 +2712,7 @@ sys_aiocancel(struct tcb *tcp)
 
        if (exiting(tcp)) {
                if (tcp->u_arg[0] == 0)
-                       tprintf("NULL");
+                       tprints("NULL");
                else if (syserror(tcp)
                    || umove(tcp, tcp->u_arg[0], &res) < 0)
                        tprintf("%#lx", tcp->u_arg[0]);
@@ -2773,10 +2778,10 @@ sys_setxattr(struct tcb *tcp)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
+               tprints(", ");
                printstr(tcp, tcp->u_arg[1], -1);
                print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
-               tprintf(", ");
+               tprints(", ");
                printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
        }
        return 0;
@@ -2786,10 +2791,11 @@ int
 sys_fsetxattr(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               tprintf("%ld, ", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
                printstr(tcp, tcp->u_arg[1], -1);
                print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
-               tprintf(", ");
+               tprints(", ");
                printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
        }
        return 0;
@@ -2800,7 +2806,7 @@ sys_getxattr(struct tcb *tcp)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
+               tprints(", ");
                printstr(tcp, tcp->u_arg[1], -1);
        } else {
                print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
@@ -2813,7 +2819,8 @@ int
 sys_fgetxattr(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               tprintf("%ld, ", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
                printstr(tcp, tcp->u_arg[1], -1);
        } else {
                print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
@@ -2838,7 +2845,7 @@ int
 sys_flistxattr(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               tprintf("%ld", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
        } else {
                /* XXX Print value in format */
                tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
@@ -2851,7 +2858,7 @@ sys_removexattr(struct tcb *tcp)
 {
        if (entering(tcp)) {
                printpath(tcp, tcp->u_arg[0]);
-               tprintf(", ");
+               tprints(", ");
                printstr(tcp, tcp->u_arg[1], -1);
        }
        return 0;
@@ -2861,7 +2868,8 @@ int
 sys_fremovexattr(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               tprintf("%ld, ", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
                printstr(tcp, tcp->u_arg[1], -1);
        }
        return 0;
@@ -2885,7 +2893,8 @@ sys_fadvise64(struct tcb *tcp)
 {
        if (entering(tcp)) {
                int argn;
-               tprintf("%ld, ", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
                argn = printllval(tcp, "%lld", 1);
                tprintf(", %ld, ", tcp->u_arg[argn++]);
                printxval(advise, tcp->u_arg[argn], "POSIX_FADV_???");
@@ -2900,7 +2909,8 @@ sys_fadvise64_64(struct tcb *tcp)
 {
        if (entering(tcp)) {
                int argn;
-               tprintf("%ld, ", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
 #if defined ARM || defined POWERPC
                argn = printllval(tcp, "%lld, ", 2);
 #else
@@ -2918,35 +2928,43 @@ sys_fadvise64_64(struct tcb *tcp)
 
 #ifdef LINUX
 static const struct xlat inotify_modes[] = {
-       { 0x00000001, "IN_ACCESS" },
-       { 0x00000002, "IN_MODIFY" },
-       { 0x00000004, "IN_ATTRIB" },
-       { 0x00000008, "IN_CLOSE_WRITE" },
-       { 0x00000010, "IN_CLOSE_NOWRITE" },
-       { 0x00000020, "IN_OPEN" },
-       { 0x00000040, "IN_MOVED_FROM" },
-       { 0x00000080, "IN_MOVED_TO" },
-       { 0x00000100, "IN_CREATE" },
-       { 0x00000200, "IN_DELETE" },
-       { 0x00000400, "IN_DELETE_SELF" },
-       { 0x00000800, "IN_MOVE_SELF" },
-       { 0x00002000, "IN_UNMOUNT" },
-       { 0x00004000, "IN_Q_OVERFLOW" },
-       { 0x00008000, "IN_IGNORED" },
-       { 0x01000000, "IN_ONLYDIR" },
-       { 0x02000000, "IN_DONT_FOLLOW" },
-       { 0x20000000, "IN_MASK_ADD" },
-       { 0x40000000, "IN_ISDIR" },
-       { 0x80000000, "IN_ONESHOT" }
+       { 0x00000001,   "IN_ACCESS"     },
+       { 0x00000002,   "IN_MODIFY"     },
+       { 0x00000004,   "IN_ATTRIB"     },
+       { 0x00000008,   "IN_CLOSE_WRITE"},
+       { 0x00000010,   "IN_CLOSE_NOWRITE"},
+       { 0x00000020,   "IN_OPEN"       },
+       { 0x00000040,   "IN_MOVED_FROM" },
+       { 0x00000080,   "IN_MOVED_TO"   },
+       { 0x00000100,   "IN_CREATE"     },
+       { 0x00000200,   "IN_DELETE"     },
+       { 0x00000400,   "IN_DELETE_SELF"},
+       { 0x00000800,   "IN_MOVE_SELF"  },
+       { 0x00002000,   "IN_UNMOUNT"    },
+       { 0x00004000,   "IN_Q_OVERFLOW" },
+       { 0x00008000,   "IN_IGNORED"    },
+       { 0x01000000,   "IN_ONLYDIR"    },
+       { 0x02000000,   "IN_DONT_FOLLOW"},
+       { 0x20000000,   "IN_MASK_ADD"   },
+       { 0x40000000,   "IN_ISDIR"      },
+       { 0x80000000,   "IN_ONESHOT"    },
+       { 0,            NULL            }
+};
+
+static const struct xlat inotify_init_flags[] = {
+       { 0x00000800,   "IN_NONBLOCK"   },
+       { 0x00080000,   "IN_CLOEXEC"    },
+       { 0,            NULL            }
 };
 
 int
 sys_inotify_add_watch(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               tprintf("%ld, ", tcp->u_arg[0]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprints(", ");
                printpath(tcp, tcp->u_arg[1]);
-               tprintf(", ");
+               tprints(", ");
                printflags(inotify_modes, tcp->u_arg[2], "IN_???");
        }
        return 0;
@@ -2956,7 +2974,8 @@ int
 sys_inotify_rm_watch(struct tcb *tcp)
 {
        if (entering(tcp)) {
-               tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
+               printfd(tcp, tcp->u_arg[0]);
+               tprintf(", %ld", tcp->u_arg[1]);
        }
        return 0;
 }
@@ -2965,7 +2984,7 @@ int
 sys_inotify_init1(struct tcb *tcp)
 {
        if (entering(tcp))
-               printflags(open_mode_flags, tcp->u_arg[0], "O_???");
+               printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
        return 0;
 }
 
@@ -2974,7 +2993,8 @@ sys_fallocate(struct tcb *tcp)
 {
        if (entering(tcp)) {
                int argn;
-               tprintf("%ld, ", tcp->u_arg[0]);        /* fd */
+               printfd(tcp, tcp->u_arg[0]);            /* fd */
+               tprints(", ");
                tprintf("%#lo, ", tcp->u_arg[1]);       /* mode */
                argn = printllval(tcp, "%llu, ", 2);    /* offset */
                printllval(tcp, "%llu", argn);          /* len */