blob: 30a8467ca390f21d130030de909e1c2b349fd9c0 [file] [log] [blame]
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00001/*
2 * Copyright (c) 2002-2005 Roland McGrath <roland@redhat.com>
3 * Copyright (c) 2004 Ulrich Drepper <drepper@redhat.com>
Dmitry V. Levinec9c3172016-05-10 18:52:06 +00004 * Copyright (c) 2005-2016 Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin38a34c92015-12-17 17:56:48 +00005 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000030#include "defs.h"
31
Dmitry V. Levin0c561952015-06-17 19:54:21 +000032#ifdef HAVE_SYS_XATTR_H
33# include <sys/xattr.h>
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000034#endif
35
36#include "xlat/xattrflags.h"
37
Dmitry V. Levinec9c3172016-05-10 18:52:06 +000038#ifndef XATTR_SIZE_MAX
39# define XATTR_SIZE_MAX 65536
40#endif
41
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000042static void
Dmitry V. Levind45548d2015-07-14 23:25:15 +000043print_xattr_val(struct tcb *tcp,
44 unsigned long addr,
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000045 unsigned long insize,
46 unsigned long size)
47{
Dmitry V. Levinec9c3172016-05-10 18:52:06 +000048 static char buf[XATTR_SIZE_MAX];
Dmitry V. Levin73e98802015-01-26 04:21:20 +000049
Dmitry V. Levin105c35b2015-07-14 23:34:06 +000050 tprints(", ");
51
Dmitry V. Levinec9c3172016-05-10 18:52:06 +000052 if (!addr || size > sizeof(buf))
Dmitry V. Levin105c35b2015-07-14 23:34:06 +000053 printaddr(addr);
Dmitry V. Levinec9c3172016-05-10 18:52:06 +000054 else if (!size || !umoven_or_printaddr(tcp, addr, size, buf)) {
55 /* Don't print terminating NUL if there is one. */
56 if (size && buf[size - 1] == '\0')
57 --size;
58
59 print_quoted_string(buf, size, 0);
Dmitry V. Levin105c35b2015-07-14 23:34:06 +000060 }
Dmitry V. Levinec9c3172016-05-10 18:52:06 +000061 tprintf(", %lu", insize);
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000062}
63
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000064SYS_FUNC(setxattr)
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000065{
Dmitry V. Levin6156d812015-07-14 23:38:58 +000066 printpath(tcp, tcp->u_arg[0]);
67 tprints(", ");
68 printstr(tcp, tcp->u_arg[1], -1);
69 print_xattr_val(tcp, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
70 tprints(", ");
71 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
72 return RVAL_DECODED;
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000073}
74
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000075SYS_FUNC(fsetxattr)
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000076{
Dmitry V. Levin6156d812015-07-14 23:38:58 +000077 printfd(tcp, tcp->u_arg[0]);
78 tprints(", ");
79 printstr(tcp, tcp->u_arg[1], -1);
80 print_xattr_val(tcp, tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[3]);
81 tprints(", ");
82 printflags(xattrflags, tcp->u_arg[4], "XATTR_???");
83 return RVAL_DECODED;
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000084}
85
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000086SYS_FUNC(getxattr)
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000087{
88 if (entering(tcp)) {
89 printpath(tcp, tcp->u_arg[0]);
90 tprints(", ");
91 printstr(tcp, tcp->u_arg[1], -1);
92 } else {
Dmitry V. Levind45548d2015-07-14 23:25:15 +000093 print_xattr_val(tcp, tcp->u_arg[2], tcp->u_arg[3], tcp->u_rval);
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000094 }
95 return 0;
96}
97
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000098SYS_FUNC(fgetxattr)
Dmitry V. Levin769ffe92014-12-06 03:53:16 +000099{
100 if (entering(tcp)) {
101 printfd(tcp, tcp->u_arg[0]);
102 tprints(", ");
103 printstr(tcp, tcp->u_arg[1], -1);
104 } else {
Dmitry V. Levind45548d2015-07-14 23:25:15 +0000105 print_xattr_val(tcp, tcp->u_arg[2], tcp->u_arg[3], tcp->u_rval);
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000106 }
107 return 0;
108}
109
110static void
111print_xattr_list(struct tcb *tcp, unsigned long addr, unsigned long size)
112{
Dmitry V. Levinec9c3172016-05-10 18:52:06 +0000113 if (!size || syserror(tcp)) {
Dmitry V. Levin8ae9c092015-07-14 23:31:35 +0000114 printaddr(addr);
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000115 } else {
Dmitry V. Levinec9c3172016-05-10 18:52:06 +0000116 printstr(tcp, addr, tcp->u_rval);
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000117 }
118 tprintf(", %lu", size);
119}
120
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000121SYS_FUNC(listxattr)
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000122{
123 if (entering(tcp)) {
124 printpath(tcp, tcp->u_arg[0]);
125 tprints(", ");
126 } else {
127 print_xattr_list(tcp, tcp->u_arg[1], tcp->u_arg[2]);
128 }
129 return 0;
130}
131
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000132SYS_FUNC(flistxattr)
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000133{
134 if (entering(tcp)) {
135 printfd(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
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000143SYS_FUNC(removexattr)
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000144{
Dmitry V. Levin6156d812015-07-14 23:38:58 +0000145 printpath(tcp, tcp->u_arg[0]);
146 tprints(", ");
147 printstr(tcp, tcp->u_arg[1], -1);
148 return RVAL_DECODED;
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000149}
150
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000151SYS_FUNC(fremovexattr)
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000152{
Dmitry V. Levin6156d812015-07-14 23:38:58 +0000153 printfd(tcp, tcp->u_arg[0]);
154 tprints(", ");
155 printstr(tcp, tcp->u_arg[1], -1);
156 return RVAL_DECODED;
Dmitry V. Levin769ffe92014-12-06 03:53:16 +0000157}