12 // Returns a []byte slice if the xattr is set and nil otherwise
13 // Requires path and its attribute as arguments
14 func lgetxattr(path string, attr string) ([]byte, error) {
16 pathBytes, err := syscall.BytePtrFromString(path)
20 attrBytes, err := syscall.BytePtrFromString(attr)
25 // Start with a 128 length byte array
27 dest := make([]byte, sz)
28 destBytes := unsafe.Pointer(&dest[0])
29 _sz, _, errno := syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0)
32 case errno == syscall.ENODATA:
34 case errno == syscall.ENOTSUP:
36 case errno == syscall.ERANGE:
37 // 128 byte array might just not be good enough,
38 // A dummy buffer is used ``uintptr(0)`` to get real size
39 // of the xattrs on disk
40 _sz, _, errno = syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(unsafe.Pointer(nil)), uintptr(0), 0, 0)
45 dest = make([]byte, sz)
46 destBytes := unsafe.Pointer(&dest[0])
47 _sz, _, errno = syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0)
58 func lsetxattr(path string, attr string, data []byte, flags int) error {
59 pathBytes, err := syscall.BytePtrFromString(path)
63 attrBytes, err := syscall.BytePtrFromString(attr)
67 var dataBytes unsafe.Pointer
69 dataBytes = unsafe.Pointer(&data[0])
71 dataBytes = unsafe.Pointer(&_zero)
73 _, _, errno := syscall.Syscall6(syscall.SYS_LSETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(dataBytes), uintptr(len(data)), uintptr(flags), 0)