2018-02-05 21:05:59 +00:00
|
|
|
package system // import "github.com/docker/docker/pkg/system"
|
2013-11-28 02:22:47 +00:00
|
|
|
|
2017-06-08 06:52:39 +00:00
|
|
|
import "golang.org/x/sys/unix"
|
2013-11-28 02:22:47 +00:00
|
|
|
|
2015-07-28 16:13:12 +00: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 13:24:37 +00:00
|
|
|
func Lgetxattr(path string, attr string) ([]byte, error) {
|
2019-12-04 13:25:58 +00:00
|
|
|
// Start with a 128 length byte array
|
2014-02-14 13:24:37 +00:00
|
|
|
dest := make([]byte, 128)
|
2017-06-08 06:52:39 +00:00
|
|
|
sz, errno := unix.Lgetxattr(path, attr, dest)
|
2019-12-04 13:25:58 +00:00
|
|
|
|
2020-02-26 14:44:25 +00:00
|
|
|
for errno == unix.ERANGE {
|
|
|
|
// Buffer too small, use zero-sized buffer to get the actual size
|
2019-12-04 13:25:58 +00:00
|
|
|
sz, errno = unix.Lgetxattr(path, attr, []byte{})
|
|
|
|
if errno != nil {
|
|
|
|
return nil, errno
|
|
|
|
}
|
2014-02-14 13:24:37 +00:00
|
|
|
dest = make([]byte, sz)
|
2017-06-08 06:52:39 +00:00
|
|
|
sz, errno = unix.Lgetxattr(path, attr, dest)
|
2020-02-26 14:44:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case errno == unix.ENODATA:
|
|
|
|
return nil, nil
|
2019-12-04 13:25:58 +00:00
|
|
|
case errno != nil:
|
2014-02-14 13:24:37 +00:00
|
|
|
return nil, errno
|
|
|
|
}
|
2020-02-26 14:44:25 +00:00
|
|
|
|
2014-02-14 13:24:37 +00:00
|
|
|
return dest[:sz], nil
|
|
|
|
}
|
|
|
|
|
2015-07-28 16:13:12 +00: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 13:24:37 +00:00
|
|
|
func Lsetxattr(path string, attr string, data []byte, flags int) error {
|
2017-06-08 06:52:39 +00:00
|
|
|
return unix.Lsetxattr(path, attr, data, flags)
|
2014-02-14 13:24:37 +00:00
|
|
|
}
|