From 14045511d3d91f36845a138359718c0fe7dff21c Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Mon, 2 Feb 2026 22:18:25 +0100 Subject: Use user-provided Listxattr buffer size This huge buffer showed up big time in ./profiling/ls.bash and caused a 2x LS benchmark slowdown. Instead of the fixed-size buffer, use the buffer size hint the user has provided us. We return inaccurate (larger than actual, which should be safe) numbers when the user has provided no buffer (size probe). --- internal/syscallcompat/sys_common.go | 43 +----------------------------------- 1 file changed, 1 insertion(+), 42 deletions(-) (limited to 'internal/syscallcompat/sys_common.go') diff --git a/internal/syscallcompat/sys_common.go b/internal/syscallcompat/sys_common.go index 1aa6a6e..1f08246 100644 --- a/internal/syscallcompat/sys_common.go +++ b/internal/syscallcompat/sys_common.go @@ -179,48 +179,7 @@ out: return val, nil } -// Flistxattr is a wrapper for unix.Flistxattr that handles buffer sizing and -// parsing the returned blob to a string slice. -func Flistxattr(fd int) (attrs []string, err error) { - // See the buffer sizing comments in getxattrSmartBuf. - // TODO: smarter buffer sizing? - buf := make([]byte, XATTR_BUFSZ) - sz, err := unix.Flistxattr(fd, buf) - if err == syscall.ERANGE { - // Do NOT return ERANGE - the user might retry ad inifinitum! - return nil, syscall.EOVERFLOW - } - if err != nil { - return nil, err - } - if sz >= XATTR_SIZE_MAX { - return nil, syscall.EOVERFLOW - } - attrs = parseListxattrBlob(buf[:sz]) - return attrs, nil -} - -// Llistxattr is a wrapper for unix.Llistxattr that handles buffer sizing and -// parsing the returned blob to a string slice. -func Llistxattr(path string) (attrs []string, err error) { - // TODO: smarter buffer sizing? - buf := make([]byte, XATTR_BUFSZ) - sz, err := unix.Llistxattr(path, buf) - if err == syscall.ERANGE { - // Do NOT return ERANGE - the user might retry ad inifinitum! - return nil, syscall.EOVERFLOW - } - if err != nil { - return nil, err - } - if sz >= XATTR_SIZE_MAX { - return nil, syscall.EOVERFLOW - } - attrs = parseListxattrBlob(buf[:sz]) - return attrs, nil -} - -func parseListxattrBlob(buf []byte) (attrs []string) { +func ParseListxattrBlob(buf []byte) (attrs []string) { parts := bytes.Split(buf, []byte{0}) for _, part := range parts { if len(part) == 0 { -- cgit v1.2.3