44package xattr
55
66import (
7+ "errors"
78 "os"
8- "syscall"
99
1010 "golang.org/x/sys/unix"
1111)
@@ -17,10 +17,11 @@ const (
1717 XATTR_CREATE = 0x1
1818 XATTR_REPLACE = 0x2
1919
20- // ENOATTR is not exported by the syscall package on Linux, because it is
21- // an alias for ENODATA. We export it here so it is available on all
22- // our supported platforms.
23- ENOATTR = syscall .ENODATA
20+ // ENOATTR is not defined on Solaris. When attempting to open an
21+ // extended attribute that doesn't exist, we'll get ENOENT. For
22+ // compatibility with other platforms, we make ENOATTR available as
23+ // an alias of unix.ENOENT.
24+ ENOATTR = unix .ENOENT
2425)
2526
2627func getxattr (path string , name string , data []byte ) (int , error ) {
@@ -132,7 +133,13 @@ func llistxattr(path string, data []byte) (int, error) {
132133func flistxattr (f * os.File , data []byte ) (int , error ) {
133134 fd , err := unix .Openat (int (f .Fd ()), "." , unix .O_RDONLY | unix .O_XATTR , 0 )
134135 if err != nil {
135- return 0 , unix .ENOTSUP
136+ // When attempting to list extended attributes on a filesystem
137+ // that doesn't support them (like as UFS and tmpfs), we'll get
138+ // EINVAL. Translate this error to the more conventional ENOTSUP.
139+ if errors .Is (err , unix .EINVAL ) {
140+ return 0 , unix .ENOTSUP
141+ }
142+ return 0 , err
136143 }
137144 xf := os .NewFile (uintptr (fd ), f .Name ())
138145 defer func () {
0 commit comments