-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathxattr.c
64 lines (53 loc) · 1.58 KB
/
xattr.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
// Instead of hard-coding 'F' for the ATTR field at all times,
// store the actual attr byte from the client in xattr.
// dl.c always sets attr first (default or from client) then calls one of these.
// If !USE_XATTR, then these are all no-op and attr simply left unchanged.
// If USE_XATTR, then these may or may not copy xattr to attr, or attr to xattr,
// depending on get vs set and depending on if the xattr exists.
#ifdef USE_XATTR
#if defined(__FreeBSD__)
#include <sys/extattr.h>
#else
#include <sys/xattr.h>
#endif
#include "xattr.h"
#ifndef XATTR_NAME
#define XATTR_NAME "pdd.attr"
#endif
const char* xattr_name =
#if defined(__linux__)
"user." XATTR_NAME
#elif defined(__APPLE__)
XATTR_NAME "#S"
#else
XATTR_NAME
#endif
;
void dl_getxattr(const char* path, uint8_t* value) {
#if defined(__linux__)
getxattr(path, xattr_name, value, 1);
#elif defined(__APPLE__)
getxattr(path, xattr_name, value, 1, 0, 0);
#elif defined(__FreeBSD__)
extattr_get_file(path, EXTATTR_NAMESPACE_USER, xattr_name, value, 1);
#endif
}
void dl_fgetxattr(int fd, uint8_t* value) {
#if defined(__linux__)
fgetxattr(fd, xattr_name, value, 1);
#elif defined(__APPLE__)
fgetxattr(fd, xattr_name, value, 1, 0, 0);
#elif defined(__FreeBSD__)
extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, xattr_name, value, 1);
#endif
}
void dl_fsetxattr(int fd, const uint8_t* value) {
#if defined(__linux__)
fsetxattr(fd, xattr_name, value, 1, 0);
#elif defined(__APPLE__)
fsetxattr(fd, xattr_name, value, 1, 0, 0);
#elif defined(__FreeBSD__)
extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, xattr_name, value, 1);
#endif
}
#endif // USE_XATTR