getxattr(2)
๐ getxattr(2) โ the extended attribute value getter ๐
okay bestie so this is the manual page for getxattr, lgetxattr, and fgetxattr from section 2 of the Linux man-pages (system calls, the real ones) ๐ฆ
โจ NAME โจ
getxattr, lgetxattr, fgetxattr โ retrieve an extended attribute value ๐
๐ LIBRARY ๐
Standard C library (libc, -lc)
๐ SYNOPSIS ๐
#include <sys/xattr.h>
ssize_t getxattr(size_t size;
const char *path, const char *name,
void value[size], size_t size);
ssize_t lgetxattr(size_t size;
const char *path, const char *name,
void value[size], size_t size);
ssize_t fgetxattr(size_t size;
int fd, const char *name,
void value[size], size_t size);
๐ธ DESCRIPTION ๐ธ
so like. extended attributes are these little name:value pairs that live on inodes (files, directories, symbolic links, literally all of them). they're like the extra extra โ extensions to the normal attributes that every inode in the system already has (you know, the stat(2) data). the whole big-picture lore is in xattr(7), go read it, it's giving encyclopedia ๐ง
getxattr() fetches the value of the extended attribute identified by name that's chillin' with the given path in the filesystem. the value gets dropped into the buffer that value points at, and size tells it how big that buffer is. what it returns? the number of bytes it placed into value. periodt. ๐
lgetxattr() is literally getxattr() twin except for one lil' plot twist: if path is a symbolic link, it interrogates the link itself, not the file the link is pointing at. don't get it twisted ๐
fgetxattr() is also identical togetxattr(), only instead of a path you hand it an open file referred to by fd (as returned byopen(2)). main character energy, same vibes ๐
an extended attribute name is a null-terminated string. it includes a namespace prefix โ and a single inode can have several, disjoint namespaces hanging out on it, no drama. the value of an extended attribute is just a chunk of arbitrary textual or binary data that somebody assigned using setxattr(2). ๐
and here's the iconic lil' trick: if you set size to zero, these calls return the current size of the named extended attribute and leave value unchanged. perfect for figuring out how big your buffer needs to be before the next call. ๐
BUT. bear in mind there's a real possibility the attribute value changes between those two calls โ so you still have to check the return status from the second call. no skipping that, bestie, fr fr. ๐ญ
โญ RETURN VALUE โญ
slay: on success these calls return a nonnegative value, which is the size in bytes of the extended attribute value.
flop: on failure, -1 is returned and errno gets set to tell you what went wrong. ๐
๐ฅ ERRORS ๐ฅ
E2BIGโ the attribute value is bigger than the max size allowed, so the attribute just cannot be retrieved. this can happen on filesystems that support very large attribute values,NFSv4for example. it's giving too much ๐ซถENODATAโ the named attribute does not exist, OR the process has no access to this attribute. either way: nothing there for you.ENOTSUPโ extended attributes aren't supported by the filesystem, or they're disabled. ๐ERANGEโ your value buffer is too small to hold the result. buffer said "not today."
plus, the errors documented in stat(2) can also occur. so yeah, check those too. โจ
๐ STANDARDS ๐
Linux. that's it, that's the standard. ๐
๐ HISTORY ๐
Linux 2.4, glibc 2.3. old money, honestly. ๐
๐ EXAMPLES ๐
See listxattr(2). not me making you go read another page, but it's worth it i promise ๐ฆ
๐ SEE ALSO ๐
getfattr(1), setfattr(1), listxattr(2), open(2), removexattr(2), setxattr(2), stat(2), symlink(7), xattr(7)
okay that's the whole page bestie, you're so ready ๐ this was Linux man-pages 6.20, dated 2026-02-08, and yes the page is literally called getxattr(2) โ go forth and retrieve those attribute values, you absolute icon, mwah ๐โจ๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: GPL-2.0-or-later
- Copyright 2001, Andreas Grรผnbacher <agruen@gnu.org>
- Copyright 2001, Silicon Graphics, Inc
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms