blob: 0f8533e3a131e6f8057736be92088c6468391018 [file] [log] [blame]
Dmitry V. Levin769ffe92014-12-06 03:53:16 +00001#include "defs.h"
2
Dmitry V. Levin0c561952015-06-17 19:54:21 +00003#ifdef HAVE_SYS_XATTR_H
4# include <sys/xattr.h>
Dmitry V. Levin769ffe92014-12-06 03:53:16 +00005#endif
6
7#include "xlat/xattrflags.h"
8
9static void
Dmitry V. Levind45548d2015-07-14 23:25:15 +000010print_xattr_val(struct tcb *tcp,
11 unsigned long addr,
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000012 unsigned long insize,
13 unsigned long size)
14{
Dmitry V. Levin105c35b2015-07-14 23:34:06 +000015 char *buf = NULL;
Dmitry V. Levin73e98802015-01-26 04:21:20 +000016 unsigned int len;
17
Dmitry V. Levin105c35b2015-07-14 23:34:06 +000018 tprints(", ");
19
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000020 if (insize == 0)
Dmitry V. Levin105c35b2015-07-14 23:34:06 +000021 goto done;
Dmitry V. Levin73e98802015-01-26 04:21:20 +000022
23 len = size;
24 if (size != (unsigned long) len)
Dmitry V. Levin105c35b2015-07-14 23:34:06 +000025 goto done;
Dmitry V. Levin73e98802015-01-26 04:21:20 +000026
27 if (!len) {
Dmitry V. Levin105c35b2015-07-14 23:34:06 +000028 tprintf("\"\", %ld", insize);
Dmitry V. Levin73e98802015-01-26 04:21:20 +000029 return;
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000030 }
Dmitry V. Levin73e98802015-01-26 04:21:20 +000031
Dmitry V. Levin105c35b2015-07-14 23:34:06 +000032 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)))
33 goto done;
34
Dmitry V. Levin73e98802015-01-26 04:21:20 +000035 buf = malloc(len);
36 if (!buf)
Dmitry V. Levin105c35b2015-07-14 23:34:06 +000037 goto done;
Dmitry V. Levin73e98802015-01-26 04:21:20 +000038
Dmitry V. Levin105c35b2015-07-14 23:34:06 +000039 if (umoven(tcp, addr, len, buf) < 0) {
Dmitry V. Levin73e98802015-01-26 04:21:20 +000040 free(buf);
Dmitry V. Levin105c35b2015-07-14 23:34:06 +000041 buf = NULL;
42 goto done;
Dmitry V. Levin73e98802015-01-26 04:21:20 +000043 }
44
45 /* Don't print terminating NUL if there is one. */
46 if (buf[len - 1] == '\0')
47 --len;
48
Dmitry V. Levin105c35b2015-07-14 23:34:06 +000049done:
50 if (buf) {
51 print_quoted_string(buf, len, 0);
52 free(buf);
53 } else {
54 printaddr(addr);
55 }
Dmitry V. Levin73e98802015-01-26 04:21:20 +000056 tprintf(", %ld", insize);
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000057}
58
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000059SYS_FUNC(setxattr)
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000060{
Dmitry V. Levin6156d812015-07-14 23:38:58 +000061 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. Levin769ffe92014-12-06 03:53:16 +000068}
69
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000070SYS_FUNC(fsetxattr)
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000071{
Dmitry V. Levin6156d812015-07-14 23:38:58 +000072 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. Levin769ffe92014-12-06 03:53:16 +000079}
80
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000081SYS_FUNC(getxattr)
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000082{
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. Levind45548d2015-07-14 23:25:15 +000088 print_xattr_val(tcp, tcp->u_arg[2], tcp->u_arg[3], tcp->u_rval);
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000089 }
90 return 0;
91}
92
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000093SYS_FUNC(fgetxattr)
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000094{
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. Levind45548d2015-07-14 23:25:15 +0000100 print_xattr_val(tcp, tcp->u_arg[2], tcp->u_arg[3], tcp->u_rval);
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000101 }
102 return 0;
103}
104
105static void
106print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
107{
108 if (syserror(tcp)) {
Dmitry V. Levin8ae9c092015-07-14 23:31:35 +0000109 printaddr(addr);
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000110 } else {
Dmitry V. Levin7a9ec122015-07-14 23:27:21 +0000111 unsigned long len =
112 (size < (unsigned long) tcp->u_rval) ?
113 size : (unsigned long) tcp->u_rval;
114 printstr(tcp, addr, len);
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000115 }
116 tprintf(", %lu", size);
117}
118
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000119SYS_FUNC(listxattr)
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000120{
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. Levina0bd3742015-04-07 01:36:50 +0000130SYS_FUNC(flistxattr)
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000131{
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. Levina0bd3742015-04-07 01:36:50 +0000141SYS_FUNC(removexattr)
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000142{
Dmitry V. Levin6156d812015-07-14 23:38:58 +0000143 printpath(tcp, tcp->u_arg[0]);
144 tprints(", ");
145 printstr(tcp, tcp->u_arg[1], -1);
146 return RVAL_DECODED;
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000147}
148
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000149SYS_FUNC(fremovexattr)
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000150{
Dmitry V. Levin6156d812015-07-14 23:38:58 +0000151 printfd(tcp, tcp->u_arg[0]);
152 tprints(", ");
153 printstr(tcp, tcp->u_arg[1], -1);
154 return RVAL_DECODED;
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000155}