forked from someonegg/pathfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyscall.go
More file actions
45 lines (36 loc) · 902 Bytes
/
syscall.go
File metadata and controls
45 lines (36 loc) · 902 Bytes
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
package pathfs
import "bytes"
func listXAttr(path string) (attributes []string, err error) {
dest := make([]byte, 0)
sz, err := listXAttrSyscall(path, dest)
if err != nil {
return nil, err
}
for sz > cap(dest) && err == nil {
dest = make([]byte, sz)
sz, err = listXAttrSyscall(path, dest)
}
if sz == 0 {
return nil, err
}
// -1 to drop the final empty slice.
dest = dest[:sz-1]
attributesBytes := bytes.Split(dest, []byte{0})
attributes = make([]string, len(attributesBytes))
for i, v := range attributesBytes {
attributes[i] = string(v)
}
return attributes, nil
}
func getXAttr(path string, attr string) ([]byte, error) {
dest := make([]byte, 0)
sz, err := getXAttrSyscall(path, attr, dest)
for sz > cap(dest) && err == nil {
dest = make([]byte, sz)
sz, err = getXAttrSyscall(path, attr, dest)
}
if err != nil {
return nil, err
}
return dest[:sz], nil
}