Dmitry V. Levin | 769ffe9 | 2014-12-06 03:53:16 +0000 | [diff] [blame] | 1 | #include "defs.h" |
| 2 | |
| 3 | #ifdef HAVE_LINUX_XATTR_H |
| 4 | # include <linux/xattr.h> |
| 5 | #else |
| 6 | # define XATTR_CREATE 1 |
| 7 | # define XATTR_REPLACE 2 |
| 8 | #endif |
| 9 | |
| 10 | #include "xlat/xattrflags.h" |
| 11 | |
| 12 | static void |
| 13 | print_xattr_val(struct tcb *tcp, int failed, |
| 14 | unsigned long arg, |
| 15 | unsigned long insize, |
| 16 | unsigned long size) |
| 17 | { |
Dmitry V. Levin | 73e9880 | 2015-01-26 04:21:20 +0000 | [diff] [blame] | 18 | char *buf; |
| 19 | unsigned int len; |
| 20 | |
Dmitry V. Levin | 769ffe9 | 2014-12-06 03:53:16 +0000 | [diff] [blame] | 21 | if (insize == 0) |
Dmitry V. Levin | 73e9880 | 2015-01-26 04:21:20 +0000 | [diff] [blame] | 22 | goto failed; |
| 23 | |
| 24 | len = size; |
| 25 | if (size != (unsigned long) len) |
| 26 | goto failed; |
| 27 | |
| 28 | if (!len) { |
| 29 | tprintf(", \"\", %ld", insize); |
| 30 | return; |
Dmitry V. Levin | 769ffe9 | 2014-12-06 03:53:16 +0000 | [diff] [blame] | 31 | } |
Dmitry V. Levin | 73e9880 | 2015-01-26 04:21:20 +0000 | [diff] [blame] | 32 | |
| 33 | buf = malloc(len); |
| 34 | if (!buf) |
| 35 | goto failed; |
| 36 | |
| 37 | if (umoven(tcp, arg, len, buf) < 0) { |
| 38 | free(buf); |
| 39 | goto failed; |
| 40 | } |
| 41 | |
| 42 | /* Don't print terminating NUL if there is one. */ |
| 43 | if (buf[len - 1] == '\0') |
| 44 | --len; |
| 45 | |
| 46 | tprints(", "); |
| 47 | print_quoted_string(buf, len, 0); |
| 48 | tprintf(", %ld", insize); |
| 49 | |
| 50 | free(buf); |
| 51 | return; |
| 52 | |
| 53 | failed: |
| 54 | tprintf(", 0x%lx, %ld", arg, insize); |
Dmitry V. Levin | 769ffe9 | 2014-12-06 03:53:16 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 57 | SYS_FUNC(setxattr) |
Dmitry V. Levin | 769ffe9 | 2014-12-06 03:53:16 +0000 | [diff] [blame] | 58 | { |
| 59 | if (entering(tcp)) { |
| 60 | printpath(tcp, tcp->u_arg[0]); |
| 61 | tprints(", "); |
| 62 | printstr(tcp, tcp->u_arg[1], -1); |
| 63 | print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]); |
| 64 | tprints(", "); |
| 65 | printflags(xattrflags, tcp->u_arg[4], "XATTR_???"); |
| 66 | } |
| 67 | return 0; |
| 68 | } |
| 69 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 70 | SYS_FUNC(fsetxattr) |
Dmitry V. Levin | 769ffe9 | 2014-12-06 03:53:16 +0000 | [diff] [blame] | 71 | { |
| 72 | if (entering(tcp)) { |
| 73 | printfd(tcp, tcp->u_arg[0]); |
| 74 | tprints(", "); |
| 75 | printstr(tcp, tcp->u_arg[1], -1); |
| 76 | print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]); |
| 77 | tprints(", "); |
| 78 | printflags(xattrflags, tcp->u_arg[4], "XATTR_???"); |
| 79 | } |
| 80 | return 0; |
| 81 | } |
| 82 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 83 | SYS_FUNC(getxattr) |
Dmitry V. Levin | 769ffe9 | 2014-12-06 03:53:16 +0000 | [diff] [blame] | 84 | { |
| 85 | if (entering(tcp)) { |
| 86 | printpath(tcp, tcp->u_arg[0]); |
| 87 | tprints(", "); |
| 88 | printstr(tcp, tcp->u_arg[1], -1); |
| 89 | } else { |
| 90 | print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3], |
| 91 | tcp->u_rval); |
| 92 | } |
| 93 | return 0; |
| 94 | } |
| 95 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 96 | SYS_FUNC(fgetxattr) |
Dmitry V. Levin | 769ffe9 | 2014-12-06 03:53:16 +0000 | [diff] [blame] | 97 | { |
| 98 | if (entering(tcp)) { |
| 99 | printfd(tcp, tcp->u_arg[0]); |
| 100 | tprints(", "); |
| 101 | printstr(tcp, tcp->u_arg[1], -1); |
| 102 | } else { |
| 103 | print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3], |
| 104 | tcp->u_rval); |
| 105 | } |
| 106 | return 0; |
| 107 | } |
| 108 | |
| 109 | static void |
| 110 | print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size) |
| 111 | { |
| 112 | if (syserror(tcp)) { |
| 113 | tprintf("%#lx", addr); |
| 114 | } else { |
| 115 | if (!addr) { |
| 116 | tprints("NULL"); |
| 117 | } else { |
| 118 | unsigned long len = |
| 119 | (size < (unsigned long) tcp->u_rval) ? |
| 120 | size : (unsigned long) tcp->u_rval; |
| 121 | printstr(tcp, addr, len); |
| 122 | } |
| 123 | } |
| 124 | tprintf(", %lu", size); |
| 125 | } |
| 126 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 127 | SYS_FUNC(listxattr) |
Dmitry V. Levin | 769ffe9 | 2014-12-06 03:53:16 +0000 | [diff] [blame] | 128 | { |
| 129 | if (entering(tcp)) { |
| 130 | printpath(tcp, tcp->u_arg[0]); |
| 131 | tprints(", "); |
| 132 | } else { |
| 133 | print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 134 | } |
| 135 | return 0; |
| 136 | } |
| 137 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 138 | SYS_FUNC(flistxattr) |
Dmitry V. Levin | 769ffe9 | 2014-12-06 03:53:16 +0000 | [diff] [blame] | 139 | { |
| 140 | if (entering(tcp)) { |
| 141 | printfd(tcp, tcp->u_arg[0]); |
| 142 | tprints(", "); |
| 143 | } else { |
| 144 | print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 145 | } |
| 146 | return 0; |
| 147 | } |
| 148 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 149 | SYS_FUNC(removexattr) |
Dmitry V. Levin | 769ffe9 | 2014-12-06 03:53:16 +0000 | [diff] [blame] | 150 | { |
| 151 | if (entering(tcp)) { |
| 152 | printpath(tcp, tcp->u_arg[0]); |
| 153 | tprints(", "); |
| 154 | printstr(tcp, tcp->u_arg[1], -1); |
| 155 | } |
| 156 | return 0; |
| 157 | } |
| 158 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 159 | SYS_FUNC(fremovexattr) |
Dmitry V. Levin | 769ffe9 | 2014-12-06 03:53:16 +0000 | [diff] [blame] | 160 | { |
| 161 | if (entering(tcp)) { |
| 162 | printfd(tcp, tcp->u_arg[0]); |
| 163 | tprints(", "); |
| 164 | printstr(tcp, tcp->u_arg[1], -1); |
| 165 | } |
| 166 | return 0; |
| 167 | } |