-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.c
114 lines (92 loc) · 3.67 KB
/
system.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
dbench version 3
Copyright (c) Timur I. Bakeyev 2004
Copyright (C) Andrew Tridgell 1999-2004
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "dbench.h"
/**************************************************************************
Wrappers for extented attribute calls. Based on the Linux package with
support for IRIX also. Expand as other systems have them.
****************************************************************************/
ssize_t sys_getxattr (const char *path, const char *name, void *value, size_t size)
{
#if defined(HAVE_GETXATTR)
return getxattr(path, name, value, size);
#elif defined(HAVE_EXTATTR_GET_FILE)
char *s;
int attrnamespace = (strncmp(name, "system", 6) == 0) ?
EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
const char *attrname = ((s=strchr(name, '.')) == NULL) ? name : s + 1;
return extattr_get_file(path, attrnamespace, attrname, value, size);
#elif defined(HAVE_ATTR_GET)
int retval, flags = 0;
int valuelength = (int)size;
char *attrname = strchr(name,'.') +1;
if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
retval = attr_get(path, attrname, (char *)value, &valuelength, flags);
return retval ? retval : valuelength;
#else
errno = ENOSYS;
return -1;
#endif
}
ssize_t sys_fgetxattr (int filedes, const char *name, void *value, size_t size)
{
#if defined(HAVE_FGETXATTR)
return fgetxattr(filedes, name, value, size);
#elif defined(HAVE_EXTATTR_GET_FD)
char *s;
int attrnamespace = (strncmp(name, "system", 6) == 0) ?
EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
const char *attrname = ((s=strchr(name, '.')) == NULL) ? name : s + 1;
return extattr_get_fd(filedes, attrnamespace, attrname, value, size);
#elif defined(HAVE_ATTR_GETF)
int retval, flags = 0;
int valuelength = (int)size;
char *attrname = strchr(name,'.') +1;
if (strncmp(name, "system", 6) == 0) flags |= ATTR_ROOT;
retval = attr_getf(filedes, attrname, (char *)value, &valuelength, flags);
return retval ? retval : valuelength;
#else
errno = ENOSYS;
return -1;
#endif
}
#if !defined(HAVE_SETXATTR)
#define XATTR_CREATE 0x1 /* set value, fail if attr already exists */
#define XATTR_REPLACE 0x2 /* set value, fail if attr does not exist */
#endif
int sys_fsetxattr (int filedes, const char *name, const void *value, size_t size, int flags)
{
#if defined(HAVE_FSETXATTR)
return fsetxattr(filedes, name, value, size, flags);
#elif defined(HAVE_EXTATTR_SET_FD)
char *s;
int retval = 0;
int attrnamespace = (strncmp(name, "system", 6) == 0) ?
EXTATTR_NAMESPACE_SYSTEM : EXTATTR_NAMESPACE_USER;
const char *attrname = ((s=strchr(name, '.')) == NULL) ? name : s + 1;
retval = extattr_set_fd(filedes, attrnamespace, attrname, value, size);
return (retval < 0) ? -1 : 0;
#elif defined(HAVE_ATTR_SETF)
int myflags = 0;
char *attrname = strchr(name,'.') +1;
if (strncmp(name, "system", 6) == 0) myflags |= ATTR_ROOT;
if (flags & XATTR_CREATE) myflags |= ATTR_CREATE;
if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE;
return attr_setf(filedes, attrname, (const char *)value, size, myflags);
#else
errno = ENOSYS;
return -1;
#endif
}