.examples
.github
alerting
client
config
controller
core
docs
jsonpath
metric
pattern
security
storage
test
util
vendor
github.com
go.etcd.io
golang.org
x
crypto
image
mod
net
oauth2
sync
sys
execabs
internal
unix
.gitignore
README.md
affinity_linux.go
aliases.go
asm_aix_ppc64.s
asm_bsd_386.s
asm_bsd_amd64.s
asm_bsd_arm.s
asm_bsd_arm64.s
asm_linux_386.s
asm_linux_amd64.s
asm_linux_arm.s
asm_linux_arm64.s
asm_linux_mips64x.s
asm_linux_mipsx.s
asm_linux_ppc64x.s
asm_linux_riscv64.s
asm_linux_s390x.s
asm_openbsd_mips64.s
asm_solaris_amd64.s
asm_zos_s390x.s
bluetooth_linux.go
cap_freebsd.go
constants.go
dev_aix_ppc.go
dev_aix_ppc64.go
dev_darwin.go
dev_dragonfly.go
dev_freebsd.go
dev_linux.go
dev_netbsd.go
dev_openbsd.go
dev_zos.go
dirent.go
endian_big.go
endian_little.go
env_unix.go
epoll_zos.go
errors_freebsd_386.go
errors_freebsd_amd64.go
errors_freebsd_arm.go
errors_freebsd_arm64.go
fcntl.go
fcntl_darwin.go
fcntl_linux_32bit.go
fdset.go
fstatfs_zos.go
gccgo.go
gccgo_c.c
gccgo_linux_amd64.go
ifreq_linux.go
ioctl.go
ioctl_linux.go
ioctl_zos.go
mkall.sh
mkerrors.sh
pagesize_unix.go
pledge_openbsd.go
ptrace_darwin.go
ptrace_ios.go
race.go
race0.go
readdirent_getdents.go
readdirent_getdirentries.go
sockcmsg_dragonfly.go
sockcmsg_linux.go
sockcmsg_unix.go
sockcmsg_unix_other.go
str.go
syscall.go
syscall_aix.go
syscall_aix_ppc.go
syscall_aix_ppc64.go
syscall_bsd.go
syscall_darwin.1_12.go
syscall_darwin.1_13.go
syscall_darwin.go
syscall_darwin_amd64.go
syscall_darwin_arm64.go
syscall_darwin_libSystem.go
syscall_dragonfly.go
syscall_dragonfly_amd64.go
syscall_freebsd.go
syscall_freebsd_386.go
syscall_freebsd_amd64.go
syscall_freebsd_arm.go
syscall_freebsd_arm64.go
syscall_illumos.go
syscall_linux.go
syscall_linux_386.go
syscall_linux_amd64.go
syscall_linux_amd64_gc.go
syscall_linux_arm.go
syscall_linux_arm64.go
syscall_linux_gc.go
syscall_linux_gc_386.go
syscall_linux_gc_arm.go
syscall_linux_gccgo_386.go
syscall_linux_gccgo_arm.go
syscall_linux_mips64x.go
syscall_linux_mipsx.go
syscall_linux_ppc.go
syscall_linux_ppc64x.go
syscall_linux_riscv64.go
syscall_linux_s390x.go
syscall_linux_sparc64.go
syscall_netbsd.go
syscall_netbsd_386.go
syscall_netbsd_amd64.go
syscall_netbsd_arm.go
syscall_netbsd_arm64.go
syscall_openbsd.go
syscall_openbsd_386.go
syscall_openbsd_amd64.go
syscall_openbsd_arm.go
syscall_openbsd_arm64.go
syscall_openbsd_mips64.go
syscall_solaris.go
syscall_solaris_amd64.go
syscall_unix.go
syscall_unix_gc.go
syscall_unix_gc_ppc64x.go
syscall_zos_s390x.go
sysvshm_linux.go
sysvshm_unix.go
sysvshm_unix_other.go
timestruct.go
unveil_openbsd.go
xattr_bsd.go
zerrors_aix_ppc.go
zerrors_aix_ppc64.go
zerrors_darwin_amd64.go
zerrors_darwin_arm64.go
zerrors_dragonfly_amd64.go
zerrors_freebsd_386.go
zerrors_freebsd_amd64.go
zerrors_freebsd_arm.go
zerrors_freebsd_arm64.go
zerrors_linux.go
zerrors_linux_386.go
zerrors_linux_amd64.go
zerrors_linux_arm.go
zerrors_linux_arm64.go
zerrors_linux_mips.go
zerrors_linux_mips64.go
zerrors_linux_mips64le.go
zerrors_linux_mipsle.go
zerrors_linux_ppc.go
zerrors_linux_ppc64.go
zerrors_linux_ppc64le.go
zerrors_linux_riscv64.go
zerrors_linux_s390x.go
zerrors_linux_sparc64.go
zerrors_netbsd_386.go
zerrors_netbsd_amd64.go
zerrors_netbsd_arm.go
zerrors_netbsd_arm64.go
zerrors_openbsd_386.go
zerrors_openbsd_amd64.go
zerrors_openbsd_arm.go
zerrors_openbsd_arm64.go
zerrors_openbsd_mips64.go
zerrors_solaris_amd64.go
zerrors_zos_s390x.go
zptrace_armnn_linux.go
zptrace_linux_arm64.go
zptrace_mipsnn_linux.go
zptrace_mipsnnle_linux.go
zptrace_x86_linux.go
zsyscall_aix_ppc.go
zsyscall_aix_ppc64.go
zsyscall_aix_ppc64_gc.go
zsyscall_aix_ppc64_gccgo.go
zsyscall_darwin_amd64.1_13.go
zsyscall_darwin_amd64.1_13.s
zsyscall_darwin_amd64.go
zsyscall_darwin_amd64.s
zsyscall_darwin_arm64.1_13.go
zsyscall_darwin_arm64.1_13.s
zsyscall_darwin_arm64.go
zsyscall_darwin_arm64.s
zsyscall_dragonfly_amd64.go
zsyscall_freebsd_386.go
zsyscall_freebsd_amd64.go
zsyscall_freebsd_arm.go
zsyscall_freebsd_arm64.go
zsyscall_illumos_amd64.go
zsyscall_linux.go
zsyscall_linux_386.go
zsyscall_linux_amd64.go
zsyscall_linux_arm.go
zsyscall_linux_arm64.go
zsyscall_linux_mips.go
zsyscall_linux_mips64.go
zsyscall_linux_mips64le.go
zsyscall_linux_mipsle.go
zsyscall_linux_ppc.go
zsyscall_linux_ppc64.go
zsyscall_linux_ppc64le.go
zsyscall_linux_riscv64.go
zsyscall_linux_s390x.go
zsyscall_linux_sparc64.go
zsyscall_netbsd_386.go
zsyscall_netbsd_amd64.go
zsyscall_netbsd_arm.go
zsyscall_netbsd_arm64.go
zsyscall_openbsd_386.go
zsyscall_openbsd_amd64.go
zsyscall_openbsd_arm.go
zsyscall_openbsd_arm64.go
zsyscall_openbsd_mips64.go
zsyscall_solaris_amd64.go
zsyscall_zos_s390x.go
zsysctl_openbsd_386.go
zsysctl_openbsd_amd64.go
zsysctl_openbsd_arm.go
zsysctl_openbsd_arm64.go
zsysctl_openbsd_mips64.go
zsysnum_darwin_amd64.go
zsysnum_darwin_arm64.go
zsysnum_dragonfly_amd64.go
zsysnum_freebsd_386.go
zsysnum_freebsd_amd64.go
zsysnum_freebsd_arm.go
zsysnum_freebsd_arm64.go
zsysnum_linux_386.go
zsysnum_linux_amd64.go
zsysnum_linux_arm.go
zsysnum_linux_arm64.go
zsysnum_linux_mips.go
zsysnum_linux_mips64.go
zsysnum_linux_mips64le.go
zsysnum_linux_mipsle.go
zsysnum_linux_ppc.go
zsysnum_linux_ppc64.go
zsysnum_linux_ppc64le.go
zsysnum_linux_riscv64.go
zsysnum_linux_s390x.go
zsysnum_linux_sparc64.go
zsysnum_netbsd_386.go
zsysnum_netbsd_amd64.go
zsysnum_netbsd_arm.go
zsysnum_netbsd_arm64.go
zsysnum_openbsd_386.go
zsysnum_openbsd_amd64.go
zsysnum_openbsd_arm.go
zsysnum_openbsd_arm64.go
zsysnum_openbsd_mips64.go
zsysnum_zos_s390x.go
ztypes_aix_ppc.go
ztypes_aix_ppc64.go
ztypes_darwin_amd64.go
ztypes_darwin_arm64.go
ztypes_dragonfly_amd64.go
ztypes_freebsd_386.go
ztypes_freebsd_amd64.go
ztypes_freebsd_arm.go
ztypes_freebsd_arm64.go
ztypes_illumos_amd64.go
ztypes_linux.go
ztypes_linux_386.go
ztypes_linux_amd64.go
ztypes_linux_arm.go
ztypes_linux_arm64.go
ztypes_linux_mips.go
ztypes_linux_mips64.go
ztypes_linux_mips64le.go
ztypes_linux_mipsle.go
ztypes_linux_ppc.go
ztypes_linux_ppc64.go
ztypes_linux_ppc64le.go
ztypes_linux_riscv64.go
ztypes_linux_s390x.go
ztypes_linux_sparc64.go
ztypes_netbsd_386.go
ztypes_netbsd_amd64.go
ztypes_netbsd_arm.go
ztypes_netbsd_arm64.go
ztypes_openbsd_386.go
ztypes_openbsd_amd64.go
ztypes_openbsd_arm.go
ztypes_openbsd_arm64.go
ztypes_openbsd_mips64.go
ztypes_solaris_amd64.go
ztypes_zos_s390x.go
windows
AUTHORS
CONTRIBUTORS
LICENSE
PATENTS
tools
xerrors
google.golang.org
gopkg.in
lukechampine.com
modernc.org
modules.txt
watchdog
web
.dockerignore
.gitattributes
.gitignore
Dockerfile
LICENSE
Makefile
README.md
config.yaml
go.mod
go.sum
main.go
242 lines
5.0 KiB
Go
242 lines
5.0 KiB
Go
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
//go:build freebsd || netbsd
|
|
// +build freebsd netbsd
|
|
|
|
package unix
|
|
|
|
import (
|
|
"strings"
|
|
"unsafe"
|
|
)
|
|
|
|
// Derive extattr namespace and attribute name
|
|
|
|
func xattrnamespace(fullattr string) (ns int, attr string, err error) {
|
|
s := strings.IndexByte(fullattr, '.')
|
|
if s == -1 {
|
|
return -1, "", ENOATTR
|
|
}
|
|
|
|
namespace := fullattr[0:s]
|
|
attr = fullattr[s+1:]
|
|
|
|
switch namespace {
|
|
case "user":
|
|
return EXTATTR_NAMESPACE_USER, attr, nil
|
|
case "system":
|
|
return EXTATTR_NAMESPACE_SYSTEM, attr, nil
|
|
default:
|
|
return -1, "", ENOATTR
|
|
}
|
|
}
|
|
|
|
func initxattrdest(dest []byte, idx int) (d unsafe.Pointer) {
|
|
if len(dest) > idx {
|
|
return unsafe.Pointer(&dest[idx])
|
|
} else {
|
|
return unsafe.Pointer(_zero)
|
|
}
|
|
}
|
|
|
|
// FreeBSD and NetBSD implement their own syscalls to handle extended attributes
|
|
|
|
func Getxattr(file string, attr string, dest []byte) (sz int, err error) {
|
|
d := initxattrdest(dest, 0)
|
|
destsize := len(dest)
|
|
|
|
nsid, a, err := xattrnamespace(attr)
|
|
if err != nil {
|
|
return -1, err
|
|
}
|
|
|
|
return ExtattrGetFile(file, nsid, a, uintptr(d), destsize)
|
|
}
|
|
|
|
func Fgetxattr(fd int, attr string, dest []byte) (sz int, err error) {
|
|
d := initxattrdest(dest, 0)
|
|
destsize := len(dest)
|
|
|
|
nsid, a, err := xattrnamespace(attr)
|
|
if err != nil {
|
|
return -1, err
|
|
}
|
|
|
|
return ExtattrGetFd(fd, nsid, a, uintptr(d), destsize)
|
|
}
|
|
|
|
func Lgetxattr(link string, attr string, dest []byte) (sz int, err error) {
|
|
d := initxattrdest(dest, 0)
|
|
destsize := len(dest)
|
|
|
|
nsid, a, err := xattrnamespace(attr)
|
|
if err != nil {
|
|
return -1, err
|
|
}
|
|
|
|
return ExtattrGetLink(link, nsid, a, uintptr(d), destsize)
|
|
}
|
|
|
|
// flags are unused on FreeBSD
|
|
|
|
func Fsetxattr(fd int, attr string, data []byte, flags int) (err error) {
|
|
var d unsafe.Pointer
|
|
if len(data) > 0 {
|
|
d = unsafe.Pointer(&data[0])
|
|
}
|
|
datasiz := len(data)
|
|
|
|
nsid, a, err := xattrnamespace(attr)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
_, err = ExtattrSetFd(fd, nsid, a, uintptr(d), datasiz)
|
|
return
|
|
}
|
|
|
|
func Setxattr(file string, attr string, data []byte, flags int) (err error) {
|
|
var d unsafe.Pointer
|
|
if len(data) > 0 {
|
|
d = unsafe.Pointer(&data[0])
|
|
}
|
|
datasiz := len(data)
|
|
|
|
nsid, a, err := xattrnamespace(attr)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
_, err = ExtattrSetFile(file, nsid, a, uintptr(d), datasiz)
|
|
return
|
|
}
|
|
|
|
func Lsetxattr(link string, attr string, data []byte, flags int) (err error) {
|
|
var d unsafe.Pointer
|
|
if len(data) > 0 {
|
|
d = unsafe.Pointer(&data[0])
|
|
}
|
|
datasiz := len(data)
|
|
|
|
nsid, a, err := xattrnamespace(attr)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
_, err = ExtattrSetLink(link, nsid, a, uintptr(d), datasiz)
|
|
return
|
|
}
|
|
|
|
func Removexattr(file string, attr string) (err error) {
|
|
nsid, a, err := xattrnamespace(attr)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = ExtattrDeleteFile(file, nsid, a)
|
|
return
|
|
}
|
|
|
|
func Fremovexattr(fd int, attr string) (err error) {
|
|
nsid, a, err := xattrnamespace(attr)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = ExtattrDeleteFd(fd, nsid, a)
|
|
return
|
|
}
|
|
|
|
func Lremovexattr(link string, attr string) (err error) {
|
|
nsid, a, err := xattrnamespace(attr)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = ExtattrDeleteLink(link, nsid, a)
|
|
return
|
|
}
|
|
|
|
func Listxattr(file string, dest []byte) (sz int, err error) {
|
|
d := initxattrdest(dest, 0)
|
|
destsiz := len(dest)
|
|
|
|
// FreeBSD won't allow you to list xattrs from multiple namespaces
|
|
s := 0
|
|
for _, nsid := range [...]int{EXTATTR_NAMESPACE_USER, EXTATTR_NAMESPACE_SYSTEM} {
|
|
stmp, e := ExtattrListFile(file, nsid, uintptr(d), destsiz)
|
|
|
|
/* Errors accessing system attrs are ignored so that
|
|
* we can implement the Linux-like behavior of omitting errors that
|
|
* we don't have read permissions on
|
|
*
|
|
* Linux will still error if we ask for user attributes on a file that
|
|
* we don't have read permissions on, so don't ignore those errors
|
|
*/
|
|
if e != nil && e == EPERM && nsid != EXTATTR_NAMESPACE_USER {
|
|
continue
|
|
} else if e != nil {
|
|
return s, e
|
|
}
|
|
|
|
s += stmp
|
|
destsiz -= s
|
|
if destsiz < 0 {
|
|
destsiz = 0
|
|
}
|
|
d = initxattrdest(dest, s)
|
|
}
|
|
|
|
return s, nil
|
|
}
|
|
|
|
func Flistxattr(fd int, dest []byte) (sz int, err error) {
|
|
d := initxattrdest(dest, 0)
|
|
destsiz := len(dest)
|
|
|
|
s := 0
|
|
for _, nsid := range [...]int{EXTATTR_NAMESPACE_USER, EXTATTR_NAMESPACE_SYSTEM} {
|
|
stmp, e := ExtattrListFd(fd, nsid, uintptr(d), destsiz)
|
|
if e != nil && e == EPERM && nsid != EXTATTR_NAMESPACE_USER {
|
|
continue
|
|
} else if e != nil {
|
|
return s, e
|
|
}
|
|
|
|
s += stmp
|
|
destsiz -= s
|
|
if destsiz < 0 {
|
|
destsiz = 0
|
|
}
|
|
d = initxattrdest(dest, s)
|
|
}
|
|
|
|
return s, nil
|
|
}
|
|
|
|
func Llistxattr(link string, dest []byte) (sz int, err error) {
|
|
d := initxattrdest(dest, 0)
|
|
destsiz := len(dest)
|
|
|
|
s := 0
|
|
for _, nsid := range [...]int{EXTATTR_NAMESPACE_USER, EXTATTR_NAMESPACE_SYSTEM} {
|
|
stmp, e := ExtattrListLink(link, nsid, uintptr(d), destsiz)
|
|
if e != nil && e == EPERM && nsid != EXTATTR_NAMESPACE_USER {
|
|
continue
|
|
} else if e != nil {
|
|
return s, e
|
|
}
|
|
|
|
s += stmp
|
|
destsiz -= s
|
|
if destsiz < 0 {
|
|
destsiz = 0
|
|
}
|
|
d = initxattrdest(dest, s)
|
|
}
|
|
|
|
return s, nil
|
|
}
|