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) {
|
|
|
|
dest := make([]byte, 128)
|
2017-06-08 02:52:39 -04:00
|
|
|
sz, errno := unix.Lgetxattr(path, attr, dest)
|
2017-05-23 10:22:32 -04:00
|
|
|
if errno == unix.ENODATA {
|
2014-02-14 08:24:37 -05:00
|
|
|
return nil, nil
|
|
|
|
}
|
2017-05-23 10:22:32 -04:00
|
|
|
if errno == unix.ERANGE {
|
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)
|
2014-02-14 08:24:37 -05:00
|
|
|
}
|
2017-06-08 02:52:39 -04:00
|
|
|
if 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
|
|
|
}
|