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 to getxattr(), only instead of a path you hand it an open file referred to by fd (as returned by open(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, NFSv4 for 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms