-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathop_xattr.c
128 lines (115 loc) · 2.76 KB
/
op_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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright (c) 2015, Kaho Ng, ngkaho1234@gmail.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. See README and COPYING for
* more details.
*/
#include <unistd.h>
#include <string.h>
#if defined(__FreeBSD__)
#include <sys/extattr.h>
#else
#include <sys/xattr.h>
#endif
#include <errno.h>
#include "ops.h"
#include "lwext4.h"
#include "acl.h"
int op_setxattr(const char *path, const char *name,
const char *value, size_t size, int flags)
{
int rc = 0;
#if !defined(__APPLE__)
int is_posix_acl = !strcmp(name, ACL_EA_ACCESS) ||
!strcmp(name, ACL_EA_DEFAULT);
if (!is_posix_acl)
#if !defined(__FreeBSD__)
rc = LWEXT4_CALL(ext4_setxattr, path, name, strlen(name),
(void *)value, size);
#else
rc = LWEXT4_CALL(ext4_setxattr, path, name, strlen(name),
(void *)value, size);
#endif
else {
size_t sz;
void *tmp = NULL;
rc = fuse_to_ext4_acl((acl_ea_header *)value, size,
(ext4_acl_header **)&tmp, &sz);
if (!rc)
#if !defined(__FreeBSD__)
rc = LWEXT4_CALL(ext4_setxattr, path, name, strlen(name),
(void *)tmp, sz);
#else
rc = LWEXT4_CALL(ext4_setxattr, path, name, strlen(name),
(void *)value, size);
#endif
if (tmp)
free(tmp);
}
#else /* __APPLE__ */
rc = LWEXT4_CALL(ext4_setxattr, path, name, strlen(name),
(void *)value, size);
#endif /* __APPLE__ */
return rc;
}
#if defined(__APPLE__)
int op_getxattr(const char *path, const char *name,
char *value, size_t size, uint32_t position)
#else
int op_getxattr(const char *path, const char *name,
char *value, size_t size)
#endif
{
int rc = 0;
size_t data_size = 0;
#if !defined(__APPLE__)
int is_posix_acl = !strcmp(name, ACL_EA_ACCESS) ||
!strcmp(name, ACL_EA_DEFAULT);
#else /* __APPLE__ */
if (position)
return -ENOSYS;
#endif /* __APPLE__ */
rc = LWEXT4_CALL(ext4_getxattr, path, name, strlen(name),
(void *)value, size, &data_size);
if (!rc) {
#if !defined(__APPLE__)
if (!is_posix_acl)
rc = (int)data_size;
else {
size_t sz;
void *tmp = NULL;
rc = ext4_to_fuse_acl((acl_ea_header **)&tmp, &sz,
(ext4_acl_header *)value, data_size);
if (!rc) {
if (sz > size)
rc = -EINVAL;
else {
memcpy(value, tmp, sz);
rc = (int)sz;
}
}
if (tmp)
free(tmp);
}
#else /* __APPLE__ */
rc = (int)data_size;
#endif /* __APPLE__ */
}
return rc;
}
int op_listxattr(const char *path, char *list, size_t size)
{
int rc = 0;
size_t ret_size = 0;
rc = LWEXT4_CALL(ext4_listxattr, path, list, size,
&ret_size);
if (!rc)
rc = (int)ret_size;
return rc;
}
int op_removexattr(const char *path, const char *name)
{
return LWEXT4_CALL(ext4_removexattr, path, name, strlen(name));
}