+
+const struct xlat xattrflags[] = {
+#ifdef XATTR_CREATE
+ { XATTR_CREATE, "XATTR_CREATE" },
+ { XATTR_REPLACE, "XATTR_REPLACE" },
+#endif
+ { 0, NULL }
+};
+
+static void
+print_xattr_val(tcp, failed, arg, insize, size)
+struct tcb *tcp;
+int failed;
+unsigned long arg;
+unsigned long insize, size;
+{
+ if (!failed) {
+ unsigned long capacity = 4 * size + 1;
+ unsigned char *buf = (capacity < size) ? NULL : malloc(capacity);
+ if (buf == NULL || /* probably a bogus size argument */
+ umoven(tcp, arg, size, (char *) &buf[3 * size]) < 0) {
+ failed = 1;
+ }
+ else {
+ unsigned char *out = buf;
+ unsigned char *in = &buf[3 * size];
+ size_t i;
+ for (i = 0; i < size; ++i)
+ if (isprint(in[i]))
+ *out++ = in[i];
+ else {
+#define tohex(n) "0123456789abcdef"[n]
+ *out++ = '\\';
+ *out++ = 'x';
+ *out++ = tohex(in[i] / 16);
+ *out++ = tohex(in[i] % 16);
+ }
+ /* Don't print terminating NUL if there is one. */
+ if (in[i - 1] == '\0')
+ out -= 4;
+ *out = '\0';
+ tprintf(", \"%s\", %ld", buf, insize);
+ }
+ free(buf);
+ }
+ if (failed)
+ tprintf(", 0x%lx, %ld", arg, insize);
+}
+
+int
+sys_setxattr(tcp)
+struct tcb *tcp;
+{
+ if (entering(tcp)) {
+ printpath(tcp, tcp->u_arg[0]);
+ tprintf(", ");
+ 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(", ");
+ printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
+ }
+ return 0;
+}
+
+int
+sys_fsetxattr(tcp)
+struct tcb *tcp;
+{
+ if (entering(tcp)) {
+ tprintf("%ld, ", tcp->u_arg[0]);
+ 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(", ");
+ printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
+ }
+ return 0;
+}
+
+int
+sys_getxattr(tcp)
+struct tcb *tcp;
+{
+ if (entering(tcp)) {
+ printpath(tcp, tcp->u_arg[0]);
+ tprintf(", ");
+ printstr(tcp, tcp->u_arg[1], -1);
+ } else {
+ print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
+ tcp->u_rval);
+ }
+ return 0;
+}
+
+int
+sys_fgetxattr(tcp)
+struct tcb *tcp;
+{
+ if (entering(tcp)) {
+ tprintf("%ld, ", tcp->u_arg[0]);
+ printstr(tcp, tcp->u_arg[1], -1);
+ } else {
+ print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3],
+ tcp->u_rval);
+ }
+ return 0;
+}
+
+int
+sys_listxattr(tcp)
+struct tcb *tcp;
+{
+ if (entering(tcp)) {
+ printpath(tcp, tcp->u_arg[0]);
+ } else {
+ /* XXX Print value in format */
+ tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
+ }
+ return 0;
+}
+
+int
+sys_flistxattr(tcp)
+struct tcb *tcp;
+{
+ if (entering(tcp)) {
+ tprintf("%ld", tcp->u_arg[0]);
+ } else {
+ /* XXX Print value in format */
+ tprintf(", %p, %lu", (void *) tcp->u_arg[1], tcp->u_arg[2]);
+ }
+ return 0;
+}
+
+int
+sys_removexattr(tcp)
+struct tcb *tcp;
+{
+ if (entering(tcp)) {
+ printpath(tcp, tcp->u_arg[0]);
+ tprintf(", ");
+ printstr(tcp, tcp->u_arg[1], -1);
+ }
+ return 0;
+}
+
+int
+sys_fremovexattr(tcp)
+struct tcb *tcp;
+{
+ if (entering(tcp)) {
+ tprintf("%ld, ", tcp->u_arg[0]);
+ printstr(tcp, tcp->u_arg[1], -1);
+ }
+ return 0;
+}
+
+
+static const struct xlat advise[] = {
+ { POSIX_FADV_NORMAL, "POSIX_FADV_NORMAL" },
+ { POSIX_FADV_RANDOM, "POSIX_FADV_RANDOM" },
+ { POSIX_FADV_SEQUENTIAL, "POSIX_FADV_SEQUENTIAL" },
+ { POSIX_FADV_WILLNEED, "POSIX_FADV_WILLNEED" },
+ { POSIX_FADV_DONTNEED, "POSIX_FADV_DONTNEED" },
+ { POSIX_FADV_NOREUSE, "POSIX_FADV_NOREUSE" },
+ { 0, NULL }
+};
+
+
+#ifdef LINUX
+int
+sys_fadvise64(tcp)
+struct tcb *tcp;
+{
+ if (entering(tcp)) {
+ tprintf("%ld, %lld, %ld, ",
+ tcp->u_arg[0],
+# if defined IA64 || defined X86_64 || defined ALPHA
+ (long long int) tcp->u_arg[1], tcp->u_arg[2]);
+ printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
+#else
+ LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]), tcp->u_arg[3]);
+ printxval(advise, tcp->u_arg[4], "POSIX_FADV_???");
+#endif
+ }
+ return 0;
+}
+#endif
+
+
+int
+sys_fadvise64_64(tcp)
+struct tcb *tcp;
+{
+ if (entering(tcp)) {
+ tprintf("%ld, %lld, %lld, ",
+ tcp->u_arg[0],
+# if defined IA64 || defined X86_64 || defined ALPHA
+ (long long int) tcp->u_arg[1], (long long int) tcp->u_arg[2]);
+ printxval(advise, tcp->u_arg[3], "POSIX_FADV_???");
+#else
+ LONG_LONG(tcp->u_arg[1], tcp->u_arg[2]),
+ LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
+ printxval(advise, tcp->u_arg[5], "POSIX_FADV_???");
+#endif
+ }
+ return 0;
+}