2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-25 20:11:06 +00:00
restic/vendor/github.com/pkg/xattr/xattr_linux.go

82 lines
2.0 KiB
Go
Raw Normal View History

2017-07-23 12:24:45 +00:00
// +build linux
package xattr
import (
2019-01-27 20:07:57 +00:00
"os"
"syscall"
2017-07-23 12:24:45 +00:00
"golang.org/x/sys/unix"
)
const (
XATTR_CREATE = unix.XATTR_CREATE
XATTR_REPLACE = unix.XATTR_REPLACE
// ENOATTR is not exported by the syscall package on Linux, because it is
// an alias for ENODATA. We export it here so it is available on all
// our supported platforms.
ENOATTR = syscall.ENODATA
)
func getxattr(path string, name string, data []byte) (int, error) {
return unix.Getxattr(path, name, data)
2017-07-23 12:24:45 +00:00
}
func lgetxattr(path string, name string, data []byte) (int, error) {
return unix.Lgetxattr(path, name, data)
2017-07-23 12:24:45 +00:00
}
2019-01-27 20:07:57 +00:00
func fgetxattr(f *os.File, name string, data []byte) (int, error) {
return unix.Fgetxattr(int(f.Fd()), name, data)
}
func setxattr(path string, name string, data []byte, flags int) error {
return unix.Setxattr(path, name, data, flags)
2017-07-23 12:24:45 +00:00
}
func lsetxattr(path string, name string, data []byte, flags int) error {
return unix.Lsetxattr(path, name, data, flags)
}
2019-01-27 20:07:57 +00:00
func fsetxattr(f *os.File, name string, data []byte, flags int) error {
return unix.Fsetxattr(int(f.Fd()), name, data, flags)
}
func removexattr(path string, name string) error {
return unix.Removexattr(path, name)
}
func lremovexattr(path string, name string) error {
return unix.Lremovexattr(path, name)
2017-07-23 12:24:45 +00:00
}
2019-01-27 20:07:57 +00:00
func fremovexattr(f *os.File, name string) error {
return unix.Fremovexattr(int(f.Fd()), name)
}
func listxattr(path string, data []byte) (int, error) {
return unix.Listxattr(path, data)
}
func llistxattr(path string, data []byte) (int, error) {
return unix.Llistxattr(path, data)
}
2019-01-27 20:07:57 +00:00
func flistxattr(f *os.File, data []byte) (int, error) {
return unix.Flistxattr(int(f.Fd()), data)
}
// stringsFromByteSlice converts a sequence of attributes to a []string.
// On Darwin and Linux, each entry is a NULL-terminated string.
func stringsFromByteSlice(buf []byte) (result []string) {
offset := 0
for index, b := range buf {
if b == 0 {
result = append(result, string(buf[offset:index]))
offset = index + 1
}
}
return
}