mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 18:53:35 +00:00
Bumps the github-dependencies group with 3 updates: [github.com/aws/aws-sdk-go-v2/service/sts](https://github.com/aws/aws-sdk-go-v2), [github.com/hashicorp/vault/api](https://github.com/hashicorp/vault) and [github.com/pkg/xattr](https://github.com/pkg/xattr). Updates `github.com/aws/aws-sdk-go-v2/service/sts` from 1.33.19 to 1.33.20 - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/main/changelog-template.json) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/sns/v1.33.19...service/sns/v1.33.20) Updates `github.com/hashicorp/vault/api` from 1.16.0 to 1.20.0 - [Release notes](https://github.com/hashicorp/vault/releases) - [Changelog](https://github.com/hashicorp/vault/blob/main/CHANGELOG.md) - [Commits](https://github.com/hashicorp/vault/compare/v1.16.0...api/v1.20.0) Updates `github.com/pkg/xattr` from 0.4.10 to 0.4.11 - [Release notes](https://github.com/pkg/xattr/releases) - [Commits](https://github.com/pkg/xattr/compare/v0.4.10...v0.4.11) --- updated-dependencies: - dependency-name: github.com/aws/aws-sdk-go-v2/service/sts dependency-version: 1.33.20 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: github-dependencies - dependency-name: github.com/hashicorp/vault/api dependency-version: 1.20.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: github-dependencies - dependency-name: github.com/pkg/xattr dependency-version: 0.4.11 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: github-dependencies ... Signed-off-by: dependabot[bot] <support@github.com>
183 lines
4.1 KiB
Go
183 lines
4.1 KiB
Go
//go:build solaris
|
|
// +build solaris
|
|
|
|
package xattr
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
const (
|
|
// XATTR_SUPPORTED will be true if the current platform is supported
|
|
XATTR_SUPPORTED = true
|
|
|
|
XATTR_CREATE = 0x1
|
|
XATTR_REPLACE = 0x2
|
|
|
|
// ENOATTR is not defined on Solaris. When attempting to open an
|
|
// extended attribute that doesn't exist, we'll get ENOENT. For
|
|
// compatibility with other platforms, we make ENOATTR available as
|
|
// an alias of unix.ENOENT.
|
|
ENOATTR = unix.ENOENT
|
|
)
|
|
|
|
func getxattr(path string, name string, data []byte) (int, error) {
|
|
f, err := openNonblock(path)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
defer func() {
|
|
_ = f.Close()
|
|
}()
|
|
return fgetxattr(f, name, data)
|
|
}
|
|
|
|
func lgetxattr(path string, name string, data []byte) (int, error) {
|
|
return 0, unix.ENOTSUP
|
|
}
|
|
|
|
func fgetxattr(f *os.File, name string, data []byte) (int, error) {
|
|
fd, err := unix.Openat(int(f.Fd()), name, unix.O_RDONLY|unix.O_XATTR, 0)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
defer func() {
|
|
_ = unix.Close(fd)
|
|
}()
|
|
return unix.Read(fd, data)
|
|
}
|
|
|
|
func setxattr(path string, name string, data []byte, flags int) error {
|
|
f, err := openNonblock(path)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = fsetxattr(f, name, data, flags)
|
|
if err != nil {
|
|
_ = f.Close()
|
|
return err
|
|
}
|
|
return f.Close()
|
|
}
|
|
|
|
func lsetxattr(path string, name string, data []byte, flags int) error {
|
|
return unix.ENOTSUP
|
|
}
|
|
|
|
func fsetxattr(f *os.File, name string, data []byte, flags int) error {
|
|
mode := unix.O_WRONLY | unix.O_XATTR
|
|
if flags&XATTR_REPLACE != 0 {
|
|
mode |= unix.O_TRUNC
|
|
} else if flags&XATTR_CREATE != 0 {
|
|
mode |= unix.O_CREAT | unix.O_EXCL
|
|
} else {
|
|
mode |= unix.O_CREAT | unix.O_TRUNC
|
|
}
|
|
fd, err := unix.Openat(int(f.Fd()), name, mode, 0666)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if _, err = unix.Write(fd, data); err != nil {
|
|
_ = unix.Close(fd)
|
|
return err
|
|
}
|
|
return unix.Close(fd)
|
|
}
|
|
|
|
func removexattr(path string, name string) error {
|
|
mode := unix.O_RDONLY | unix.O_XATTR | unix.O_NONBLOCK | unix.O_CLOEXEC
|
|
fd, err := unix.Open(path, mode, 0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
f := os.NewFile(uintptr(fd), path)
|
|
defer func() {
|
|
_ = f.Close()
|
|
}()
|
|
return fremovexattr(f, name)
|
|
}
|
|
|
|
func lremovexattr(path string, name string) error {
|
|
return unix.ENOTSUP
|
|
}
|
|
|
|
func fremovexattr(f *os.File, name string) error {
|
|
fd, err := unix.Openat(int(f.Fd()), ".", unix.O_XATTR, 0)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer func() {
|
|
_ = unix.Close(fd)
|
|
}()
|
|
return unix.Unlinkat(fd, name, 0)
|
|
}
|
|
|
|
func listxattr(path string, data []byte) (int, error) {
|
|
f, err := openNonblock(path)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
defer func() {
|
|
_ = f.Close()
|
|
}()
|
|
return flistxattr(f, data)
|
|
}
|
|
|
|
func llistxattr(path string, data []byte) (int, error) {
|
|
return 0, unix.ENOTSUP
|
|
}
|
|
|
|
func flistxattr(f *os.File, data []byte) (int, error) {
|
|
fd, err := unix.Openat(int(f.Fd()), ".", unix.O_RDONLY|unix.O_XATTR, 0)
|
|
if err != nil {
|
|
// When attempting to list extended attributes on a filesystem
|
|
// that doesn't support them (like as UFS and tmpfs), we'll get
|
|
// EINVAL. Translate this error to the more conventional ENOTSUP.
|
|
if errors.Is(err, unix.EINVAL) {
|
|
return 0, unix.ENOTSUP
|
|
}
|
|
return 0, err
|
|
}
|
|
xf := os.NewFile(uintptr(fd), f.Name())
|
|
defer func() {
|
|
_ = xf.Close()
|
|
}()
|
|
names, err := xf.Readdirnames(-1)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
var buf []byte
|
|
for _, name := range names {
|
|
buf = append(buf, append([]byte(name), '\000')...)
|
|
}
|
|
if data == nil {
|
|
return len(buf), nil
|
|
}
|
|
return copy(data, buf), nil
|
|
}
|
|
|
|
// Like os.Open, but passes O_NONBLOCK to the open(2) syscall.
|
|
func openNonblock(path string) (*os.File, error) {
|
|
fd, err := unix.Open(path, unix.O_RDONLY|unix.O_CLOEXEC|unix.O_NONBLOCK, 0)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return os.NewFile(uintptr(fd), path), err
|
|
}
|
|
|
|
// stringsFromByteSlice converts a sequence of attributes to a []string.
|
|
// We simulate Linux/Darwin, where 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
|
|
}
|