1/*
2 * Copyright (c) 2001-2002 Silicon Graphics, Inc.  All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2.1 of the GNU Lesser General Public License
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like.  Any license provided herein, whether implied or
15 * otherwise, applies only to this software file.  Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this program; if not, write the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307,
22 * USA.
23 *
24 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
25 * Mountain View, CA  94043, or:
26 *
27 * http://www.sgi.com
28 *
29 * For further information regarding this notice, see:
30 *
31 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
32 */
33
34/*
35 * The use of the syscall() function is an additional level of
36 * indirection.  This avoids the dependency on kernel sources.
37 */
38
39#include <errno.h>
40#include <unistd.h>
41#if 0
42#if defined (__i386__)
43# define HAVE_XATTR_SYSCALLS 1
44# define __NR_setxattr		226
45# define __NR_lsetxattr		227
46# define __NR_fsetxattr		228
47# define __NR_getxattr		229
48# define __NR_lgetxattr		230
49# define __NR_fgetxattr		231
50# define __NR_listxattr		232
51# define __NR_llistxattr	233
52# define __NR_flistxattr	234
53# define __NR_removexattr	235
54# define __NR_lremovexattr	236
55# define __NR_fremovexattr	237
56#elif defined (__sparc__)
57# define HAVE_XATTR_SYSCALLS 1
58# define __NR_setxattr		169
59# define __NR_lsetxattr		170
60# define __NR_fsetxattr		171
61# define __NR_getxattr		172
62# define __NR_lgetxattr		173
63# define __NR_fgetxattr		177
64# define __NR_listxattr		178
65# define __NR_llistxattr	179
66# define __NR_flistxattr	180
67# define __NR_removexattr	181
68# define __NR_lremovexattr	182
69# define __NR_fremovexattr	186
70#elif defined (__ia64__)
71# define HAVE_XATTR_SYSCALLS 1
72# define __NR_setxattr		1217
73# define __NR_lsetxattr		1218
74# define __NR_fsetxattr		1219
75# define __NR_getxattr		1220
76# define __NR_lgetxattr		1221
77# define __NR_fgetxattr		1222
78# define __NR_listxattr		1223
79# define __NR_llistxattr	1224
80# define __NR_flistxattr	1225
81# define __NR_removexattr	1226
82# define __NR_lremovexattr	1227
83# define __NR_fremovexattr	1228
84#elif defined (__powerpc__)
85# define HAVE_XATTR_SYSCALLS 1
86# define __NR_setxattr		209
87# define __NR_lsetxattr		210
88# define __NR_fsetxattr		211
89# define __NR_getxattr		212
90# define __NR_lgetxattr		213
91# define __NR_fgetxattr		214
92# define __NR_listxattr		215
93# define __NR_llistxattr	216
94# define __NR_flistxattr	217
95# define __NR_removexattr	218
96# define __NR_lremovexattr	219
97# define __NR_fremovexattr	220
98#elif defined (__x86_64__)
99# define HAVE_XATTR_SYSCALLS 1
100# define __NR_setxattr		188
101# define __NR_lsetxattr		189
102# define __NR_fsetxattr		190
103# define __NR_getxattr		191
104# define __NR_lgetxattr		192
105# define __NR_fgetxattr		193
106# define __NR_listxattr		194
107# define __NR_llistxattr	195
108# define __NR_flistxattr	196
109# define __NR_removexattr	197
110# define __NR_lremovexattr	198
111# define __NR_fremovexattr	199
112#elif defined (__s390__)
113# define HAVE_XATTR_SYSCALLS 1
114# define __NR_setxattr		224
115# define __NR_lsetxattr		225
116# define __NR_fsetxattr		226
117# define __NR_getxattr		227
118# define __NR_lgetxattr		228
119# define __NR_fgetxattr		229
120# define __NR_listxattr		230
121# define __NR_llistxattr	231
122# define __NR_flistxattr	232
123# define __NR_removexattr	233
124# define __NR_lremovexattr	234
125# define __NR_fremovexattr	235
126#elif defined (__arm__)
127# define HAVE_XATTR_SYSCALLS 1
128# define __NR_SYSCALL_BASE 0x900000
129# define __NR_setxattr		(__NR_SYSCALL_BASE+226)
130# define __NR_lsetxattr		(__NR_SYSCALL_BASE+227)
131# define __NR_fsetxattr		(__NR_SYSCALL_BASE+228)
132# define __NR_getxattr		(__NR_SYSCALL_BASE+229)
133# define __NR_lgetxattr		(__NR_SYSCALL_BASE+230)
134# define __NR_fgetxattr		(__NR_SYSCALL_BASE+231)
135# define __NR_listxattr		(__NR_SYSCALL_BASE+232)
136# define __NR_llistxattr	(__NR_SYSCALL_BASE+233)
137# define __NR_flistxattr	(__NR_SYSCALL_BASE+234)
138# define __NR_removexattr	(__NR_SYSCALL_BASE+235)
139# define __NR_lremovexattr	(__NR_SYSCALL_BASE+236)
140# define __NR_fremovexattr	(__NR_SYSCALL_BASE+237)
141#elif defined (__mips64__)
142# define HAVE_XATTR_SYSCALLS 1
143# define __NR_Linux 5000
144# define __NR_setxattr		(__NR_Linux + 217)
145# define __NR_lsetxattr		(__NR_Linux + 218)
146# define __NR_fsetxattr		(__NR_Linux + 219)
147# define __NR_getxattr		(__NR_Linux + 220)
148# define __NR_lgetxattr		(__NR_Linux + 221)
149# define __NR_fgetxattr		(__NR_Linux + 222)
150# define __NR_listxattr		(__NR_Linux + 223)
151# define __NR_llistxattr	(__NR_Linux + 224)
152# define __NR_flistxattr	(__NR_Linux + 225)
153# define __NR_removexattr	(__NR_Linux + 226)
154# define __NR_lremovexattr	(__NR_Linux + 227)
155# define __NR_fremovexattr	(__NR_Linux + 228)
156#elif defined (__mips__)
157#endif
158#endif
159# define HAVE_XATTR_SYSCALLS 1
160# define __NR_Linux 4000
161# define __NR_setxattr		(__NR_Linux + 224)
162# define __NR_lsetxattr		(__NR_Linux + 225)
163# define __NR_fsetxattr		(__NR_Linux + 226)
164# define __NR_getxattr		(__NR_Linux + 227)
165# define __NR_lgetxattr		(__NR_Linux + 228)
166# define __NR_fgetxattr		(__NR_Linux + 229)
167# define __NR_listxattr		(__NR_Linux + 230)
168# define __NR_llistxattr	(__NR_Linux + 231)
169# define __NR_flistxattr	(__NR_Linux + 232)
170# define __NR_removexattr	(__NR_Linux + 233)
171# define __NR_lremovexattr	(__NR_Linux + 234)
172# define __NR_fremovexattr	(__NR_Linux + 235)
173#if 0
174//#elif defined (__alpha__)
175# define HAVE_XATTR_SYSCALLS 1
176# define __NR_setxattr		382
177# define __NR_lsetxattr		383
178# define __NR_fsetxattr		384
179# define __NR_getxattr		385
180# define __NR_lgetxattr		386
181# define __NR_fgetxattr		387
182# define __NR_listxattr		388
183# define __NR_llistxattr	389
184# define __NR_flistxattr	390
185# define __NR_removexattr	391
186# define __NR_lremovexattr	392
187# define __NR_fremovexattr	393
188/#elif defined (__mc68000__)
189# define HAVE_XATTR_SYSCALLS 1
190# define __NR_setxattr		223
191# define __NR_lsetxattr		224
192# define __NR_fsetxattr		225
193# define __NR_getxattr		226
194# define __NR_lgetxattr		227
195# define __NR_fgetxattr		228
196# define __NR_listxattr		229
197# define __NR_llistxattr	230
198# define __NR_flistxattr	231
199# define __NR_removexattr	232
200# define __NR_lremovexattr	233
201# define __NR_fremovexattr	234
202/#else
203# warning "Extended attribute syscalls undefined for this architecture"
204# define HAVE_XATTR_SYSCALLS 0
205#endif
206//#endif
207
208#if HAVE_XATTR_SYSCALLS
209# define SYSCALL(args...)	syscall(args)
210#else
211# define SYSCALL(args...)	( errno = ENOSYS, -1 )
212#endif
213
214int setxattr (const char *path, const char *name,
215			void *value, size_t size, int flags)
216{
217	return SYSCALL(__NR_setxattr, path, name, value, size, flags);
218}
219
220int lsetxattr (const char *path, const char *name,
221			void *value, size_t size, int flags)
222{
223	return SYSCALL(__NR_lsetxattr, path, name, value, size, flags);
224}
225
226int fsetxattr (int filedes, const char *name,
227			void *value, size_t size, int flags)
228{
229	return SYSCALL(__NR_fsetxattr, filedes, name, value, size, flags);
230}
231
232ssize_t getxattr (const char *path, const char *name,
233				void *value, size_t size)
234{
235	return SYSCALL(__NR_getxattr, path, name, value, size);
236}
237
238ssize_t lgetxattr (const char *path, const char *name,
239				void *value, size_t size)
240{
241	return SYSCALL(__NR_lgetxattr, path, name, value, size);
242}
243
244ssize_t fgetxattr (int filedes, const char *name,
245				void *value, size_t size)
246{
247	return SYSCALL(__NR_fgetxattr, filedes, name, value, size);
248}
249
250ssize_t listxattr (const char *path, char *list, size_t size)
251{
252	return SYSCALL(__NR_listxattr, path, list, size);
253}
254
255ssize_t llistxattr (const char *path, char *list, size_t size)
256{
257	return SYSCALL(__NR_llistxattr, path, list, size);
258}
259
260ssize_t flistxattr (int filedes, char *list, size_t size)
261{
262	return SYSCALL(__NR_flistxattr, filedes, list, size);
263}
264
265int removexattr (const char *path, const char *name)
266{
267	return SYSCALL(__NR_removexattr, path, name);
268}
269
270int lremovexattr (const char *path, const char *name)
271{
272	return SYSCALL(__NR_lremovexattr, path, name);
273}
274
275int fremovexattr (int filedes, const char *name)
276{
277	return SYSCALL(__NR_fremovexattr, filedes, name);
278}
279