4 Copyright (c) Timur I. Bakeyev 2004
5 Copyright (C) Andrew Tridgell 1999-2004
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/>.
23 /**************************************************************************
24 Wrappers for extented attribute calls. Based on the Linux package with
25 support for IRIX also. Expand as other systems have them.
26 ****************************************************************************/
28 ssize_t sys_getxattr (const char *path, const char *name, void *value, size_t size)
30 #if defined(HAVE_GETXATTR)
31 return getxattr(path, name, value, size);
32 #elif defined(HAVE_EXTATTR_GET_FILE)
34 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
35 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
36 const char *attrname = ((s=strchr(name, '.')) == NULL) ? name : s + 1;
38 return extattr_get_file(path, attrnamespace, attrname, value, size);
39 #elif defined(HAVE_ATTR_GET)
40 int retval, flags = 0;
41 int valuelength = (int)size;
42 char *attrname = strchr(name,'.') +1;
44 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
46 retval = attr_get(path, attrname, (char *)value, &valuelength, flags);
48 return retval ? retval : valuelength;
55 ssize_t sys_fgetxattr (int filedes, const char *name, void *value, size_t size)
57 #if defined(HAVE_FGETXATTR)
58 return fgetxattr(filedes, name, value, size);
59 #elif defined(HAVE_EXTATTR_GET_FD)
61 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
62 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
63 const char *attrname = ((s=strchr(name, '.')) == NULL) ? name : s + 1;
65 return extattr_get_fd(filedes, attrnamespace, attrname, value, size);
66 #elif defined(HAVE_ATTR_GETF)
67 int retval, flags = 0;
68 int valuelength = (int)size;
69 char *attrname = strchr(name,'.') +1;
71 if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
73 retval = attr_getf(filedes, attrname, (char *)value, &valuelength, flags);
75 return retval ? retval : valuelength;
83 #if !defined(HAVE_SETXATTR)
84 #define XATTR_CREATE 0x1 /* set value, fail if attr already exists */
85 #define XATTR_REPLACE 0x2 /* set value, fail if attr does not exist */
88 int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size, int flags)
90 #if defined(HAVE_FSETXATTR)
91 return fsetxattr(filedes, name, value, size, flags);
92 #elif defined(HAVE_EXTATTR_SET_FD)
95 int attrnamespace = (strncmp(name, "system", 6) == 0) ?
96 EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
97 const char *attrname = ((s=strchr(name, '.')) == NULL) ? name : s + 1;
99 retval = extattr_set_fd(filedes, attrnamespace, attrname, value, size);
100 return (retval < 0) ? -1 : 0;
101 #elif defined(HAVE_ATTR_SETF)
103 char *attrname = strchr(name,'.') +1;
105 if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
106 if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
107 if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
109 return attr_setf(filedes, attrname, (const char *)value, size, myflags);