extattr 0.1 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/HISTORY.ja.md +49 -0
- data/{LICENSE.txt → LICENSE.md} +5 -0
- data/QUICKREF.ja.md +112 -0
- data/README.md +84 -0
- data/Rakefile +212 -0
- data/ext/extattr-extattr.h +192 -0
- data/ext/extattr-windows.h +724 -0
- data/ext/extattr-xattr.h +229 -0
- data/ext/extattr.c +393 -206
- data/ext/extconf.rb +16 -12
- data/gemstub.rb +22 -0
- data/lib/extattr.rb +274 -0
- data/test/test_extattr.rb +75 -0
- metadata +70 -37
- data/README.txt +0 -53
- data/ext/extattr.bsd +0 -186
- data/ext/extattr.linux +0 -209
- data/ext/extattr.windows +0 -407
- data/rspecs/extattr.rb +0 -53
data/ext/extattr.bsd
DELETED
@@ -1,186 +0,0 @@
|
|
1
|
-
#include <sys/types.h>
|
2
|
-
#include <sys/extattr.h>
|
3
|
-
|
4
|
-
|
5
|
-
static void
|
6
|
-
split_name(const char list[], size_t size, void (*func)(void *, VALUE), void *userdata)
|
7
|
-
{
|
8
|
-
// Each list entry consists of a single byte containing the length of
|
9
|
-
// the attribute name, followed by the attribute name.
|
10
|
-
// The attribute name is not terminated by ASCII 0 (nul).
|
11
|
-
const char *ptr = list;
|
12
|
-
const char *end = list + size;
|
13
|
-
|
14
|
-
while (ptr < end) {
|
15
|
-
size_t len = (uint8_t)*ptr ++;
|
16
|
-
if (ptr + len > end) { return; }
|
17
|
-
func(userdata, rb_str_new(ptr, len));
|
18
|
-
ptr += len;
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
static int
|
23
|
-
get_extattr_list_size(int (*extattr_list)(), intptr_t d, int namespace)
|
24
|
-
{
|
25
|
-
int size = extattr_list(d, namespace, NULL, 0);
|
26
|
-
if (size < 0) { rb_sys_fail("extattr_list call error"); }
|
27
|
-
return size;
|
28
|
-
}
|
29
|
-
|
30
|
-
static VALUE
|
31
|
-
extattr_list0(int (*extattr_list)(), intptr_t d, int namespace)
|
32
|
-
{
|
33
|
-
size_t size = get_extattr_list_size(extattr_list, d, namespace);
|
34
|
-
VALUE buf = rb_str_buf_new(size);
|
35
|
-
char *ptr = RSTRING_PTR(buf);
|
36
|
-
|
37
|
-
ssize_t size1 = extattr_list(d, namespace, ptr, size);
|
38
|
-
if (size1 < 0) { rb_sys_fail("extattr_list call error"); }
|
39
|
-
|
40
|
-
VALUE list = Qnil;
|
41
|
-
if (rb_block_given_p()) {
|
42
|
-
split_name(ptr, size1, (void (*)(void *, VALUE))rb_yield_values, (void *)(1));
|
43
|
-
} else {
|
44
|
-
list = rb_ary_new();
|
45
|
-
split_name(ptr, size1, (void (*)(void *, VALUE))rb_ary_push, (void *)list);
|
46
|
-
}
|
47
|
-
rb_free_tmp_buffer(&buf);
|
48
|
-
|
49
|
-
return list;
|
50
|
-
}
|
51
|
-
|
52
|
-
static VALUE
|
53
|
-
file_extattr_list0(VALUE file, int fd, int namespace)
|
54
|
-
{
|
55
|
-
return extattr_list0(extattr_list_fd, fd, namespace);
|
56
|
-
}
|
57
|
-
|
58
|
-
static VALUE
|
59
|
-
file_s_extattr_list0(VALUE path, int namespace)
|
60
|
-
{
|
61
|
-
return extattr_list0(extattr_list_file, (intptr_t)StringValueCStr(path), namespace);
|
62
|
-
}
|
63
|
-
|
64
|
-
static VALUE
|
65
|
-
file_s_extattr_list_link0(VALUE path, int namespace)
|
66
|
-
{
|
67
|
-
return extattr_list0(extattr_list_link, (intptr_t)StringValueCStr(path), namespace);
|
68
|
-
}
|
69
|
-
|
70
|
-
|
71
|
-
static VALUE
|
72
|
-
extattr_size0(int (*extattr_get)(), intptr_t d, int namespace, VALUE name)
|
73
|
-
{
|
74
|
-
ssize_t size = extattr_get(d, namespace, RSTRING_PTR(name), NULL, 0);
|
75
|
-
if (size < 0) { rb_sys_fail("extattr_get call error"); }
|
76
|
-
return SIZET2NUM(size);
|
77
|
-
}
|
78
|
-
|
79
|
-
static VALUE
|
80
|
-
file_extattr_size0(VALUE file, int fd, int namespace, VALUE name)
|
81
|
-
{
|
82
|
-
return extattr_size0(extattr_get_fd, fd, namespace, name);
|
83
|
-
}
|
84
|
-
|
85
|
-
static VALUE
|
86
|
-
file_s_extattr_size0(VALUE path, int namespace, VALUE name)
|
87
|
-
{
|
88
|
-
return extattr_size0(extattr_get_file, (intptr_t)StringValueCStr(path), namespace, name);
|
89
|
-
}
|
90
|
-
|
91
|
-
static VALUE
|
92
|
-
file_s_extattr_size_link0(VALUE path, int namespace, VALUE name)
|
93
|
-
{
|
94
|
-
return extattr_size0(extattr_get_link, (intptr_t)StringValueCStr(path), namespace, name);
|
95
|
-
}
|
96
|
-
|
97
|
-
|
98
|
-
static VALUE
|
99
|
-
extattr_get0(int (*extattr_get)(), intptr_t d, VALUE path, int namespace, VALUE name)
|
100
|
-
{
|
101
|
-
ssize_t size = extattr_get(d, namespace, RSTRING_PTR(name), NULL, 0);
|
102
|
-
if (size < 0) { rb_sys_fail(StringValueCStr(path)); }
|
103
|
-
VALUE buf = rb_str_buf_new(size);
|
104
|
-
size = extattr_get(d, namespace, RSTRING_PTR(name), RSTRING_PTR(buf), size);
|
105
|
-
if (size < 0) { rb_sys_fail(StringValueCStr(path)); }
|
106
|
-
rb_str_set_len(buf, size);
|
107
|
-
return buf;
|
108
|
-
}
|
109
|
-
|
110
|
-
static VALUE
|
111
|
-
file_extattr_get0(VALUE file, int fd, int namespace, VALUE name)
|
112
|
-
{
|
113
|
-
return extattr_get0(extattr_get_fd, fd, RFILE(file)->fptr->pathv, namespace, name);
|
114
|
-
}
|
115
|
-
|
116
|
-
static VALUE
|
117
|
-
file_s_extattr_get0(VALUE path, int namespace, VALUE name)
|
118
|
-
{
|
119
|
-
return extattr_get0(extattr_get_file, (intptr_t)StringValueCStr(path), path, namespace, name);
|
120
|
-
}
|
121
|
-
|
122
|
-
static VALUE
|
123
|
-
file_s_extattr_get_link0(VALUE path, int namespace, VALUE name)
|
124
|
-
{
|
125
|
-
return extattr_get0(extattr_get_link, (intptr_t)StringValueCStr(path), path, namespace, name);
|
126
|
-
}
|
127
|
-
|
128
|
-
|
129
|
-
static VALUE
|
130
|
-
extattr_set0(int (*extattr_set)(), intptr_t d, int namespace, VALUE name, VALUE data)
|
131
|
-
{
|
132
|
-
int status = extattr_set(d, namespace, RSTRING_PTR(name), RSTRING_PTR(data), RSTRING_LEN(data));
|
133
|
-
if (status < 0) { rb_sys_fail("extattr_set call error"); }
|
134
|
-
return Qnil;
|
135
|
-
}
|
136
|
-
|
137
|
-
static VALUE
|
138
|
-
file_extattr_set0(VALUE file, int fd, int namespace, VALUE name, VALUE data)
|
139
|
-
{
|
140
|
-
return extattr_set0(extattr_set_fd, fd, namespace, name, data);
|
141
|
-
}
|
142
|
-
|
143
|
-
static VALUE
|
144
|
-
file_s_extattr_set0(VALUE path, int namespace, VALUE name, VALUE data)
|
145
|
-
{
|
146
|
-
return extattr_set0(extattr_set_file, (intptr_t)StringValueCStr(path), namespace, name, data);
|
147
|
-
}
|
148
|
-
|
149
|
-
static VALUE
|
150
|
-
file_s_extattr_set_link0(VALUE path, int namespace, VALUE name, VALUE data)
|
151
|
-
{
|
152
|
-
return extattr_set0(extattr_set_link, (intptr_t)StringValueCStr(path), namespace, name, data);
|
153
|
-
}
|
154
|
-
|
155
|
-
|
156
|
-
static VALUE
|
157
|
-
extattr_delete0(int (*extattr_delete)(), intptr_t d, int namespace, VALUE name)
|
158
|
-
{
|
159
|
-
int status = extattr_delete(d, namespace, RSTRING_PTR(name), NULL, 0);
|
160
|
-
if (status < 0) { rb_sys_fail("extattr_delete call error"); }
|
161
|
-
return Qnil;
|
162
|
-
}
|
163
|
-
|
164
|
-
static VALUE
|
165
|
-
file_extattr_delete0(VALUE file, int fd, int namespace, VALUE name)
|
166
|
-
{
|
167
|
-
return extattr_delete0(extattr_delete_fd, fd, namespace, name);
|
168
|
-
}
|
169
|
-
|
170
|
-
static VALUE
|
171
|
-
file_s_extattr_delete0(VALUE path, int namespace, VALUE name)
|
172
|
-
{
|
173
|
-
return extattr_delete0(extattr_delete_file, (intptr_t)StringValueCStr(path), namespace, name);
|
174
|
-
}
|
175
|
-
|
176
|
-
static VALUE
|
177
|
-
file_s_extattr_delete_link0(VALUE path, int namespace, VALUE name)
|
178
|
-
{
|
179
|
-
return extattr_delete0(extattr_delete_link, (intptr_t)StringValueCStr(path), namespace, name);
|
180
|
-
}
|
181
|
-
|
182
|
-
|
183
|
-
static void
|
184
|
-
setup(void)
|
185
|
-
{
|
186
|
-
}
|
data/ext/extattr.linux
DELETED
@@ -1,209 +0,0 @@
|
|
1
|
-
#include <sys/types.h>
|
2
|
-
#include <attr/xattr.h>
|
3
|
-
|
4
|
-
#define EXTATTR_NAMESPACE_USER 0
|
5
|
-
#define EXTATTR_NAMESPACE_SYSTEM 1
|
6
|
-
|
7
|
-
static VALUE NAMESPACE_USER_PREFIX, NAMESPACE_SYSTEM_PREFIX;
|
8
|
-
|
9
|
-
|
10
|
-
static VALUE
|
11
|
-
extattr_list0(ssize_t (*func)(), void *d, int namespace)
|
12
|
-
{
|
13
|
-
ssize_t size = 65536;
|
14
|
-
VALUE buf = rb_str_buf_new(size);
|
15
|
-
char *ptr = RSTRING_PTR(buf);
|
16
|
-
size = func(d, ptr, size);
|
17
|
-
if (size < 0) { rb_sys_fail("listxattr call error"); }
|
18
|
-
|
19
|
-
VALUE (*reduce)(void *, VALUE);
|
20
|
-
void *first;
|
21
|
-
VALUE list;
|
22
|
-
if (rb_block_given_p()) {
|
23
|
-
reduce = (VALUE (*)(void *, VALUE))rb_yield_values;
|
24
|
-
first = (void *)1;
|
25
|
-
list = Qnil;
|
26
|
-
} else {
|
27
|
-
reduce = (VALUE (*)(void *, VALUE))rb_ary_push;
|
28
|
-
first = (void *)(list = rb_ary_new());
|
29
|
-
}
|
30
|
-
|
31
|
-
const char *end = ptr + size;
|
32
|
-
while (ptr < end) {
|
33
|
-
int len = strlen(ptr);
|
34
|
-
VALUE name;
|
35
|
-
if (namespace == EXTATTR_NAMESPACE_USER && len > 5 && strncmp(ptr, "user.", 5) == 0) {
|
36
|
-
ptr += 5;
|
37
|
-
} else if (namespace == EXTATTR_NAMESPACE_SYSTEM && len > 7 && strncmp(ptr, "system.", 7) == 0) {
|
38
|
-
ptr += 7;
|
39
|
-
} else {
|
40
|
-
ptr += len + 1;
|
41
|
-
continue;
|
42
|
-
}
|
43
|
-
|
44
|
-
name = rb_str_new_cstr(ptr);
|
45
|
-
reduce(first, name);
|
46
|
-
ptr += RSTRING_LEN(name) + 1; // 最後の『+1』は、ヌルバイトの分。
|
47
|
-
}
|
48
|
-
|
49
|
-
return list;
|
50
|
-
}
|
51
|
-
|
52
|
-
static VALUE
|
53
|
-
file_extattr_list0(VALUE file, int fd, int namespace)
|
54
|
-
{
|
55
|
-
return extattr_list0(flistxattr, (void *)fd, namespace);
|
56
|
-
}
|
57
|
-
|
58
|
-
static VALUE
|
59
|
-
file_s_extattr_list0(VALUE path, int namespace)
|
60
|
-
{
|
61
|
-
return extattr_list0(listxattr, StringValueCStr(path), namespace);
|
62
|
-
}
|
63
|
-
|
64
|
-
static VALUE
|
65
|
-
file_s_extattr_list_link0(VALUE path, int namespace)
|
66
|
-
{
|
67
|
-
return extattr_list0(llistxattr, StringValueCStr(path), namespace);
|
68
|
-
}
|
69
|
-
|
70
|
-
|
71
|
-
static VALUE
|
72
|
-
xattr_name(int namespace, VALUE name)
|
73
|
-
{
|
74
|
-
switch (namespace) {
|
75
|
-
case EXTATTR_NAMESPACE_USER:
|
76
|
-
return rb_str_plus(NAMESPACE_USER_PREFIX, name);
|
77
|
-
case EXTATTR_NAMESPACE_SYSTEM:
|
78
|
-
return rb_str_plus(NAMESPACE_SYSTEM_PREFIX, name);
|
79
|
-
default:
|
80
|
-
rb_raise(rb_eRuntimeError, "namespace error");
|
81
|
-
return Qnil;
|
82
|
-
}
|
83
|
-
}
|
84
|
-
|
85
|
-
static VALUE
|
86
|
-
extattr_size0(ssize_t (*func)(), void *d, int namespace, VALUE name)
|
87
|
-
{
|
88
|
-
name = xattr_name(namespace, name);
|
89
|
-
ssize_t size = func(d, StringValueCStr(name), NULL, 0);
|
90
|
-
if (size < 0) { rb_sys_fail("getxattr call error"); }
|
91
|
-
return SSIZET2NUM(size);
|
92
|
-
}
|
93
|
-
|
94
|
-
static VALUE
|
95
|
-
file_extattr_size0(VALUE file, int fd, int namespace, VALUE name)
|
96
|
-
{
|
97
|
-
return extattr_size0(fgetxattr, (void *)fd, namespace, name);
|
98
|
-
}
|
99
|
-
|
100
|
-
static VALUE
|
101
|
-
file_s_extattr_size0(VALUE path, int namespace, VALUE name)
|
102
|
-
{
|
103
|
-
return extattr_size0(getxattr, StringValueCStr(path), namespace, name);
|
104
|
-
}
|
105
|
-
|
106
|
-
static VALUE
|
107
|
-
file_s_extattr_size_link0(VALUE path, int namespace, VALUE name)
|
108
|
-
{
|
109
|
-
return extattr_size0(lgetxattr, StringValueCStr(path), namespace, name);
|
110
|
-
}
|
111
|
-
|
112
|
-
|
113
|
-
static VALUE
|
114
|
-
extattr_get0(ssize_t (*func)(), void *d, int namespace, VALUE name)
|
115
|
-
{
|
116
|
-
name = xattr_name(namespace, name);
|
117
|
-
ssize_t size = 65536;
|
118
|
-
VALUE buf = rb_str_buf_new(size);
|
119
|
-
char *ptr = RSTRING_PTR(buf);
|
120
|
-
size = func(d, StringValueCStr(name), ptr, size);
|
121
|
-
if (size < 0) { rb_sys_fail("getxattr call error"); }
|
122
|
-
rb_str_set_len(buf, size);
|
123
|
-
return buf;
|
124
|
-
}
|
125
|
-
|
126
|
-
static VALUE
|
127
|
-
file_extattr_get0(VALUE file, int fd, int namespace, VALUE name)
|
128
|
-
{
|
129
|
-
return extattr_get0(fgetxattr, (void *)fd, namespace, name);
|
130
|
-
}
|
131
|
-
|
132
|
-
static VALUE
|
133
|
-
file_s_extattr_get0(VALUE path, int namespace, VALUE name)
|
134
|
-
{
|
135
|
-
return extattr_get0(getxattr, StringValueCStr(path), namespace, name);
|
136
|
-
}
|
137
|
-
|
138
|
-
static VALUE
|
139
|
-
file_s_extattr_get_link0(VALUE path, int namespace, VALUE name)
|
140
|
-
{
|
141
|
-
return extattr_get0(lgetxattr, StringValueCStr(path), namespace, name);
|
142
|
-
}
|
143
|
-
|
144
|
-
|
145
|
-
static VALUE
|
146
|
-
extattr_set0(int (*func)(), void *d, int namespace, VALUE name, VALUE data)
|
147
|
-
{
|
148
|
-
name = xattr_name(namespace, name);
|
149
|
-
int status = func(d, StringValueCStr(name), RSTRING_PTR(data), RSTRING_LEN(data));
|
150
|
-
if (status < 0) { rb_sys_fail("getxattr call error"); }
|
151
|
-
return Qnil;
|
152
|
-
}
|
153
|
-
|
154
|
-
static VALUE
|
155
|
-
file_extattr_set0(VALUE file, int fd, int namespace, VALUE name, VALUE data)
|
156
|
-
{
|
157
|
-
return extattr_set0(fsetxattr, (void *)fd, namespace, name, data);
|
158
|
-
}
|
159
|
-
|
160
|
-
static VALUE
|
161
|
-
file_s_extattr_set0(VALUE path, int namespace, VALUE name, VALUE data)
|
162
|
-
{
|
163
|
-
return extattr_set0(setxattr, StringValueCStr(path), namespace, name, data);
|
164
|
-
}
|
165
|
-
|
166
|
-
static VALUE
|
167
|
-
file_s_extattr_set_link0(VALUE path, int namespace, VALUE name, VALUE data)
|
168
|
-
{
|
169
|
-
return extattr_set0(lsetxattr, StringValueCStr(path), namespace, name, data);
|
170
|
-
}
|
171
|
-
|
172
|
-
|
173
|
-
static VALUE
|
174
|
-
extattr_delete0(int (*func)(), void *d, int namespace, VALUE name)
|
175
|
-
{
|
176
|
-
name = xattr_name(namespace, name);
|
177
|
-
int status = func(d, StringValueCStr(name));
|
178
|
-
if (status < 0) { rb_sys_fail("removexattr call error"); }
|
179
|
-
return Qnil;
|
180
|
-
}
|
181
|
-
|
182
|
-
static VALUE
|
183
|
-
file_extattr_delete0(VALUE file, int fd, int namespace, VALUE name)
|
184
|
-
{
|
185
|
-
return extattr_delete0(fremovexattr, (void *)fd, namespace, name);
|
186
|
-
}
|
187
|
-
|
188
|
-
static VALUE
|
189
|
-
file_s_extattr_delete0(VALUE path, int namespace, VALUE name)
|
190
|
-
{
|
191
|
-
return extattr_delete0(removexattr, StringValueCStr(path), namespace, name);
|
192
|
-
}
|
193
|
-
|
194
|
-
static VALUE
|
195
|
-
file_s_extattr_delete_link0(VALUE path, int namespace, VALUE name)
|
196
|
-
{
|
197
|
-
return extattr_delete0(lremovexattr, StringValueCStr(path), namespace, name);
|
198
|
-
}
|
199
|
-
|
200
|
-
|
201
|
-
static void
|
202
|
-
setup(void)
|
203
|
-
{
|
204
|
-
NAMESPACE_USER_PREFIX = rb_str_new_cstr("user.");
|
205
|
-
NAMESPACE_SYSTEM_PREFIX = rb_str_new_cstr("system.");
|
206
|
-
|
207
|
-
rb_gc_register_mark_object(NAMESPACE_USER_PREFIX);
|
208
|
-
rb_gc_register_mark_object(NAMESPACE_SYSTEM_PREFIX);
|
209
|
-
}
|