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 | |
| 57 | int |
| 58 | sys_setxattr(struct tcb *tcp) |
| 59 | { |
| 60 | if (entering(tcp)) { |
| 61 | printpath(tcp, tcp->u_arg[0]); |
| 62 | tprints(", "); |
| 63 | printstr(tcp, tcp->u_arg[1], -1); |
| 64 | print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]); |
| 65 | tprints(", "); |
| 66 | printflags(xattrflags, tcp->u_arg[4], "XATTR_???"); |
| 67 | } |
| 68 | return 0; |
| 69 | } |
| 70 | |
| 71 | int |
| 72 | sys_fsetxattr(struct tcb *tcp) |
| 73 | { |
| 74 | if (entering(tcp)) { |
| 75 | printfd(tcp, tcp->u_arg[0]); |
| 76 | tprints(", "); |
| 77 | printstr(tcp, tcp->u_arg[1], -1); |
| 78 | print_xattr_val(tcp, 0, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]); |
| 79 | tprints(", "); |
| 80 | printflags(xattrflags, tcp->u_arg[4], "XATTR_???"); |
| 81 | } |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | int |
| 86 | sys_getxattr(struct tcb *tcp) |
| 87 | { |
| 88 | if (entering(tcp)) { |
| 89 | printpath(tcp, tcp->u_arg[0]); |
| 90 | tprints(", "); |
| 91 | printstr(tcp, tcp->u_arg[1], -1); |
| 92 | } else { |
| 93 | print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3], |
| 94 | tcp->u_rval); |
| 95 | } |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | int |
| 100 | sys_fgetxattr(struct tcb *tcp) |
| 101 | { |
| 102 | if (entering(tcp)) { |
| 103 | printfd(tcp, tcp->u_arg[0]); |
| 104 | tprints(", "); |
| 105 | printstr(tcp, tcp->u_arg[1], -1); |
| 106 | } else { |
| 107 | print_xattr_val(tcp, syserror(tcp), tcp->u_arg[2], tcp->u_arg[3], |
| 108 | tcp->u_rval); |
| 109 | } |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | static void |
| 114 | print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size) |
| 115 | { |
| 116 | if (syserror(tcp)) { |
| 117 | tprintf("%#lx", addr); |
| 118 | } else { |
| 119 | if (!addr) { |
| 120 | tprints("NULL"); |
| 121 | } else { |
| 122 | unsigned long len = |
| 123 | (size < (unsigned long) tcp->u_rval) ? |
| 124 | size : (unsigned long) tcp->u_rval; |
| 125 | printstr(tcp, addr, len); |
| 126 | } |
| 127 | } |
| 128 | tprintf(", %lu", size); |
| 129 | } |
| 130 | |
| 131 | int |
| 132 | sys_listxattr(struct tcb *tcp) |
| 133 | { |
| 134 | if (entering(tcp)) { |
| 135 | printpath(tcp, tcp->u_arg[0]); |
| 136 | tprints(", "); |
| 137 | } else { |
| 138 | print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 139 | } |
| 140 | return 0; |
| 141 | } |
| 142 | |
| 143 | int |
| 144 | sys_flistxattr(struct tcb *tcp) |
| 145 | { |
| 146 | if (entering(tcp)) { |
| 147 | printfd(tcp, tcp->u_arg[0]); |
| 148 | tprints(", "); |
| 149 | } else { |
| 150 | print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 151 | } |
| 152 | return 0; |
| 153 | } |
| 154 | |
| 155 | int |
| 156 | sys_removexattr(struct tcb *tcp) |
| 157 | { |
| 158 | if (entering(tcp)) { |
| 159 | printpath(tcp, tcp->u_arg[0]); |
| 160 | tprints(", "); |
| 161 | printstr(tcp, tcp->u_arg[1], -1); |
| 162 | } |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | int |
| 167 | sys_fremovexattr(struct tcb *tcp) |
| 168 | { |
| 169 | if (entering(tcp)) { |
| 170 | printfd(tcp, tcp->u_arg[0]); |
| 171 | tprints(", "); |
| 172 | printstr(tcp, tcp->u_arg[1], -1); |
| 173 | } |
| 174 | return 0; |
| 175 | } |