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