2018-02-05 16:05:59 -05:00
|
|
|
package system // import "github.com/docker/docker/pkg/system"
|
2013-11-27 21:22:47 -05:00
|
|
|
|
2017-06-08 02:52:39 -04:00
|
|
|
import "golang.org/x/sys/unix"
|
2013-11-27 21:22:47 -05:00
|
|
|
|
2015-07-28 12:13:12 -04:00
|
|
|
// Lgetxattr retrieves the value of the extended attribute identified by attr
|
|
|
|
// and associated with the given path in the file system.
|
|
|
|
// It will returns a nil slice and nil error if the xattr is not set.
|
2014-02-14 08:24:37 -05:00
|
|
|
func Lgetxattr(path string, attr string) ([]byte, error) {
|
2019-12-04 08:25:58 -05:00
|
|
|
// Start with a 128 length byte array
|
2014-02-14 08:24:37 -05:00
|
|
|
dest := make([]byte, 128)
|
2017-06-08 02:52:39 -04:00
|
|
|
sz, errno := unix.Lgetxattr(path, attr, dest)
|
2019-12-04 08:25:58 -05:00
|
|
|
|
|
|
|
switch {
|
|
|
|
case errno == unix.ENODATA:
|
2014-02-14 08:24:37 -05:00
|
|
|
return nil, nil
|
2019-12-04 08:25:58 -05:00
|
|
|
case errno == unix.ERANGE:
|
|
|
|
// 128 byte array might just not be good enough. A dummy buffer is used
|
|
|
|
// to get the real size of the xattrs on disk
|
|
|
|
sz, errno = unix.Lgetxattr(path, attr, []byte{})
|
|
|
|
if errno != nil {
|
|
|
|
return nil, errno
|
|
|
|
}
|
2014-02-14 08:24:37 -05:00
|
|
|
dest = make([]byte, sz)
|
2017-06-08 02:52:39 -04:00
|
|
|
sz, errno = unix.Lgetxattr(path, attr, dest)
|
2019-12-04 08:25:58 -05:00
|
|
|
if errno != nil {
|
|
|
|
return nil, errno
|
|
|
|
}
|
|
|
|
case errno != nil:
|
2014-02-14 08:24:37 -05:00
|
|
|
return nil, errno
|
|
|
|
}
|
|
|
|
return dest[:sz], nil
|
|
|
|
}
|
|
|
|
|
2015-07-28 12:13:12 -04:00
|
|
|
// Lsetxattr sets the value of the extended attribute identified by attr
|
|
|
|
// and associated with the given path in the file system.
|
2014-02-14 08:24:37 -05:00
|
|
|
func Lsetxattr(path string, attr string, data []byte, flags int) error {
|
2017-06-08 02:52:39 -04:00
|
|
|
return unix.Lsetxattr(path, attr, data, flags)
|
2014-02-14 08:24:37 -05:00
|
|
|
}
|