8 // Lgetxattr retrieves the value of the extended attribute identified by attr
9 // and associated with the given path in the file system.
10 // It will returns a nil slice and nil error if the xattr is not set.
11 func Lgetxattr(path string, attr string) ([]byte, error) {
12 pathBytes, err := syscall.BytePtrFromString(path)
16 attrBytes, err := syscall.BytePtrFromString(attr)
21 dest := make([]byte, 128)
22 destBytes := unsafe.Pointer(&dest[0])
23 sz, _, errno := syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0)
24 if errno == syscall.ENODATA {
27 if errno == syscall.ERANGE {
28 dest = make([]byte, sz)
29 destBytes := unsafe.Pointer(&dest[0])
30 sz, _, errno = syscall.Syscall6(syscall.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0)
41 // Lsetxattr sets the value of the extended attribute identified by attr
42 // and associated with the given path in the file system.
43 func Lsetxattr(path string, attr string, data []byte, flags int) error {
44 pathBytes, err := syscall.BytePtrFromString(path)
48 attrBytes, err := syscall.BytePtrFromString(attr)
52 var dataBytes unsafe.Pointer
54 dataBytes = unsafe.Pointer(&data[0])
56 dataBytes = unsafe.Pointer(&_zero)
58 _, _, errno := syscall.Syscall6(syscall.SYS_LSETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(dataBytes), uintptr(len(data)), uintptr(flags), 0)