github.com/devdivbcp/moby@v17.12.0-ce-rc1.0.20200726071732-2d4bfdc789ad+incompatible/pkg/system/xattrs_linux.go (about) 1 package system // import "github.com/docker/docker/pkg/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 // Start with a 128 length byte array 10 dest := make([]byte, 128) 11 sz, errno := unix.Lgetxattr(path, attr, dest) 12 13 switch { 14 case errno == unix.ENODATA: 15 return nil, nil 16 case errno == unix.ERANGE: 17 // 128 byte array might just not be good enough. A dummy buffer is used 18 // to get the real size of the xattrs on disk 19 sz, errno = unix.Lgetxattr(path, attr, []byte{}) 20 if errno != nil { 21 return nil, errno 22 } 23 dest = make([]byte, sz) 24 sz, errno = unix.Lgetxattr(path, attr, dest) 25 if errno != nil { 26 return nil, errno 27 } 28 case errno != nil: 29 return nil, errno 30 } 31 return dest[:sz], nil 32 } 33 34 // Lsetxattr sets the value of the extended attribute identified by attr 35 // and associated with the given path in the file system. 36 func Lsetxattr(path string, attr string, data []byte, flags int) error { 37 return unix.Lsetxattr(path, attr, data, flags) 38 }