Skip to content

Commit

Permalink
pkg/system: fix EOPNOTSUPP to ENOTSUP for xattr syscalls
Browse files Browse the repository at this point in the history
The lgetxattr(2), lsetxattr(2), and llistxattr(2) syscalls on Linux
return ENOTSUP instead of EOPNOTSUPP. The same applies to getxattr(2),
setxattr(2), and listxattr(2) on macOS.

Note that EOPNOTSUPP and ENOTSUP have the same value in Linux (refer to
errno(3)).

Signed-off-by: Minseo Kim <[email protected]>
  • Loading branch information
kimminss0 committed Nov 29, 2024
1 parent be173a9 commit 5015968
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion drivers/chown_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (c *platformChowner) LChown(path string, info os.FileInfo, toHost, toContai
}
if uid != int(st.Uid) || gid != int(st.Gid) {
capability, err := system.Lgetxattr(path, "security.capability")
if err != nil && !errors.Is(err, system.EOPNOTSUPP) && err != system.ErrNotSupportedPlatform {
if err != nil && !errors.Is(err, system.ENOTSUP) && err != system.ErrNotSupportedPlatform {
return fmt.Errorf("%s: %w", os.Args[0], err)
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/chown_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (c *platformChowner) LChown(path string, info os.FileInfo, toHost, toContai
}
if uid != int(st.Uid) || gid != int(st.Gid) {
cap, err := system.Lgetxattr(path, "security.capability")
if err != nil && !errors.Is(err, system.EOPNOTSUPP) && !errors.Is(err, system.EOVERFLOW) && err != system.ErrNotSupportedPlatform {
if err != nil && !errors.Is(err, system.ENOTSUP) && !errors.Is(err, system.EOVERFLOW) && err != system.ErrNotSupportedPlatform {
return fmt.Errorf("%s: %w", os.Args[0], err)
}

Expand Down
4 changes: 2 additions & 2 deletions drivers/copy/copy_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func legacyCopy(srcFile io.Reader, dstFile io.Writer) error {

func copyXattr(srcPath, dstPath, attr string) error {
data, err := system.Lgetxattr(srcPath, attr)
if err != nil && !errors.Is(err, unix.EOPNOTSUPP) {
if err != nil && !errors.Is(err, system.ENOTSUP) {
return err
}
if data != nil {
Expand Down Expand Up @@ -279,7 +279,7 @@ func doCopyXattrs(srcPath, dstPath string) error {
}

xattrs, err := system.Llistxattr(srcPath)
if err != nil && !errors.Is(err, unix.EOPNOTSUPP) {
if err != nil && !errors.Is(err, system.ENOTSUP) {
return err
}

Expand Down
3 changes: 1 addition & 2 deletions drivers/overlay/check_116.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/containers/storage/pkg/archive"
"github.com/containers/storage/pkg/system"
"golang.org/x/sys/unix"
)

func scanForMountProgramIndicators(home string) (detected bool, err error) {
Expand All @@ -28,7 +27,7 @@ func scanForMountProgramIndicators(home string) (detected bool, err error) {
}
if d.IsDir() {
xattrs, err := system.Llistxattr(path)
if err != nil && !errors.Is(err, unix.EOPNOTSUPP) {
if err != nil && !errors.Is(err, system.ENOTSUP) {
return err
}
for _, xattr := range xattrs {
Expand Down
6 changes: 3 additions & 3 deletions pkg/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ func readSecurityXattrToTarHeader(path string, hdr *tar.Header) error {
}
for _, xattr := range []string{"security.capability", "security.ima"} {
capability, err := system.Lgetxattr(path, xattr)
if err != nil && !errors.Is(err, system.EOPNOTSUPP) && err != system.ErrNotSupportedPlatform {
if err != nil && !errors.Is(err, system.ENOTSUP) && err != system.ErrNotSupportedPlatform {
return fmt.Errorf("failed to read %q attribute from %q: %w", xattr, path, err)
}
if capability != nil {
Expand All @@ -440,7 +440,7 @@ func readSecurityXattrToTarHeader(path string, hdr *tar.Header) error {
// readUserXattrToTarHeader reads user.* xattr from filesystem to a tar header
func readUserXattrToTarHeader(path string, hdr *tar.Header) error {
xattrs, err := system.Llistxattr(path)
if err != nil && !errors.Is(err, system.EOPNOTSUPP) && err != system.ErrNotSupportedPlatform {
if err != nil && !errors.Is(err, system.ENOTSUP) && err != system.ErrNotSupportedPlatform {
return err
}
for _, key := range xattrs {
Expand Down Expand Up @@ -793,7 +793,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
continue
}
if err := system.Lsetxattr(path, xattrKey, []byte(value), 0); err != nil {
if errors.Is(err, syscall.ENOTSUP) || (inUserns && errors.Is(err, syscall.EPERM)) {
if errors.Is(err, system.ENOTSUP) || (inUserns && errors.Is(err, syscall.EPERM)) {
// Ignore specific error cases:
// - ENOTSUP: Expected for graphdrivers lacking extended attribute support:
// - Legacy AUFS versions
Expand Down
4 changes: 2 additions & 2 deletions pkg/archive/changes_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ func walkchunk(path string, fi os.FileInfo, dir string, root *FileInfo) error {
}
info.stat = stat
info.capability, err = system.Lgetxattr(cpath, "security.capability") // lgetxattr(2): fs access
if err != nil && !errors.Is(err, system.EOPNOTSUPP) {
if err != nil && !errors.Is(err, system.ENOTSUP) {
return err
}
xattrs, err := system.Llistxattr(cpath)
if err != nil && !errors.Is(err, system.EOPNOTSUPP) {
if err != nil && !errors.Is(err, system.ENOTSUP) {
return err
}
for _, key := range xattrs {
Expand Down
2 changes: 1 addition & 1 deletion pkg/system/xattrs_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
E2BIG unix.Errno = unix.E2BIG

// Operation not supported
EOPNOTSUPP unix.Errno = unix.EOPNOTSUPP
ENOTSUP unix.Errno = unix.ENOTSUP
)

// Lgetxattr retrieves the value of the extended attribute identified by attr
Expand Down
9 changes: 4 additions & 5 deletions pkg/system/xattrs_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package system

import (
"strings"
"syscall"

"golang.org/x/sys/unix"
)
Expand All @@ -12,7 +11,7 @@ const (
E2BIG unix.Errno = unix.E2BIG

// Operation not supported
EOPNOTSUPP unix.Errno = unix.EOPNOTSUPP
ENOTSUP unix.Errno = unix.ENOTSUP

// Value is too small or too large for maximum size allowed
EOVERFLOW unix.Errno = unix.EOVERFLOW
Expand All @@ -28,12 +27,12 @@ var (
func xattrToExtattr(xattr string) (namespace int, extattr string, err error) {
namespaceName, extattr, found := strings.Cut(xattr, ".")
if !found {
return -1, "", syscall.ENOTSUP
return -1, "", ENOTSUP
}

namespace, ok := namespaceMap[namespaceName]
if !ok {
return -1, "", syscall.ENOTSUP
return -1, "", ENOTSUP
}
return namespace, extattr, nil
}
Expand All @@ -56,7 +55,7 @@ func Lsetxattr(path string, attr string, value []byte, flags int) error {
// FIXME: Flags are not supported on FreeBSD, but we can implement
// them mimicking the behavior of the Linux implementation.
// See lsetxattr(2) on Linux for more information.
return syscall.ENOTSUP
return ENOTSUP
}

namespace, extattr, err := xattrToExtattr(attr)
Expand Down
2 changes: 1 addition & 1 deletion pkg/system/xattrs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
E2BIG unix.Errno = unix.E2BIG

// Operation not supported
EOPNOTSUPP unix.Errno = unix.EOPNOTSUPP
ENOTSUP unix.Errno = unix.ENOTSUP

// Value is too small or too large for maximum size allowed
EOVERFLOW unix.Errno = unix.EOVERFLOW
Expand Down
2 changes: 1 addition & 1 deletion pkg/system/xattrs_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const (
E2BIG syscall.Errno = syscall.Errno(0)

// Operation not supported
EOPNOTSUPP syscall.Errno = syscall.Errno(0)
ENOTSUP syscall.Errno = syscall.Errno(0)

// Value is too small or too large for maximum size allowed
EOVERFLOW syscall.Errno = syscall.Errno(0)
Expand Down

0 comments on commit 5015968

Please sign in to comment.