github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/pkg/system/xattrs_linux.go (about)

     1  package system
     2  
     3  import "golang.org/x/sys/unix"
     4  
     5  // Lgetxattr retrieves the value of the extended attribute identified by attr
     6  // and associated with the given path in the file system.
     7  // It will returns a nil slice and nil error if the xattr is not set.
     8  func Lgetxattr(path string, attr string) ([]byte, error) {
     9  	dest := make([]byte, 128)
    10  	sz, errno := unix.Lgetxattr(path, attr, dest)
    11  	if errno == unix.ENODATA {
    12  		return nil, nil
    13  	}
    14  	if errno == unix.ERANGE {
    15  		dest = make([]byte, sz)
    16  		sz, errno = unix.Lgetxattr(path, attr, dest)
    17  	}
    18  	if errno != nil {
    19  		return nil, errno
    20  	}
    21  
    22  	return dest[:sz], nil
    23  }
    24  
    25  // Lsetxattr sets the value of the extended attribute identified by attr
    26  // and associated with the given path in the file system.
    27  func Lsetxattr(path string, attr string, data []byte, flags int) error {
    28  	return unix.Lsetxattr(path, attr, data, flags)
    29  }