From 4d966409bc7033e3bebe7deb921d8be8249f8d18 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 8 Jun 2017 08:52:39 +0200 Subject: [PATCH] system: Use symlink xattr functions from x/sys/unix Use the symlink xattr syscall wrappers Lgetxattr and Lsetxattr from x/sys/unix (introduced in golang/sys@b90f89a) instead of providing own wrappers. Leave the functionality of system.Lgetxattr intact with respect to the retry with a larger buffer, but switch it to use unix.Lgetxattr. Also leave system.Lsetxattr intact (even though it's just a wrapper around the corresponding function from unix) in order to keep moby building for !linux. Signed-off-by: Tobias Klauser --- pkg/system/xattrs_linux.go | 45 +++++--------------------------------- 1 file changed, 5 insertions(+), 40 deletions(-) diff --git a/pkg/system/xattrs_linux.go b/pkg/system/xattrs_linux.go index 762bc3db1b..98b111be42 100644 --- a/pkg/system/xattrs_linux.go +++ b/pkg/system/xattrs_linux.go @@ -1,64 +1,29 @@ package system -import ( - "unsafe" - - "golang.org/x/sys/unix" -) +import "golang.org/x/sys/unix" // Lgetxattr retrieves the value of the extended attribute identified by attr // and associated with the given path in the file system. // It will returns a nil slice and nil error if the xattr is not set. func Lgetxattr(path string, attr string) ([]byte, error) { - pathBytes, err := unix.BytePtrFromString(path) - if err != nil { - return nil, err - } - attrBytes, err := unix.BytePtrFromString(attr) - if err != nil { - return nil, err - } - dest := make([]byte, 128) - destBytes := unsafe.Pointer(&dest[0]) - sz, _, errno := unix.Syscall6(unix.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0) + sz, errno := unix.Lgetxattr(path, attr, dest) if errno == unix.ENODATA { return nil, nil } if errno == unix.ERANGE { dest = make([]byte, sz) - destBytes := unsafe.Pointer(&dest[0]) - sz, _, errno = unix.Syscall6(unix.SYS_LGETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(destBytes), uintptr(len(dest)), 0, 0) + sz, errno = unix.Lgetxattr(path, attr, dest) } - if errno != 0 { + if errno != nil { return nil, errno } return dest[:sz], nil } -var _zero uintptr - // Lsetxattr sets the value of the extended attribute identified by attr // and associated with the given path in the file system. func Lsetxattr(path string, attr string, data []byte, flags int) error { - pathBytes, err := unix.BytePtrFromString(path) - if err != nil { - return err - } - attrBytes, err := unix.BytePtrFromString(attr) - if err != nil { - return err - } - var dataBytes unsafe.Pointer - if len(data) > 0 { - dataBytes = unsafe.Pointer(&data[0]) - } else { - dataBytes = unsafe.Pointer(&_zero) - } - _, _, errno := unix.Syscall6(unix.SYS_LSETXATTR, uintptr(unsafe.Pointer(pathBytes)), uintptr(unsafe.Pointer(attrBytes)), uintptr(dataBytes), uintptr(len(data)), uintptr(flags), 0) - if errno != 0 { - return errno - } - return nil + return unix.Lsetxattr(path, attr, data, flags) }