mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00

Changes most references of syscall to golang.org/x/sys/
Ones aren't changes include, Errno, Signal and SysProcAttr
as they haven't been implemented in /x/sys/.
Signed-off-by: Christopher Jones <tophj@linux.vnet.ibm.com>
[s390x] switch utsname from unsigned to signed
per 33267e036f
char in s390x in the /x/sys/unix package is now signed, so
change the buildtags
Signed-off-by: Christopher Jones <tophj@linux.vnet.ibm.com>
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package system
|
|
|
|
import (
|
|
"unsafe"
|
|
|
|
"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)
|
|
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)
|
|
}
|
|
if errno != 0 {
|
|
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
|
|
}
|