setxattr(2)
๐ setxattr, lsetxattr, fsetxattr โ setting extended attribute values โจ
okay bestie, so we're in setxattr(2) territory, the System Calls Manual corner of the universe, and this is literally the page where you learn how to WRITE an extended attribute value onto an inode. eating, no crumbs. let's go ๐ฆ
๐ธ LIBRARY
Standard C library (libc, -lc) โ yeah she's just a normal libc girlie, nothing exotic. ๐
โจ SYNOPSIS โจ
#include <sys/xattr.h>
int setxattr(size_t size;
const char *path, const char *name,
const void value[size], size_t size, int flags);
int lsetxattr(size_t size;
const char *path, const char *name,
const void value[size], size_t size, int flags);
int fsetxattr(size_t size;
int fd, const char *name,
const void value[size], size_t size, int flags);
yes the prototypes look like that, don't come for me, I'm just the messenger ๐ซถ
๐ DESCRIPTION
Extended attributes are name:value pairs that get associated with inodes โ so like files, directories, symbolic links, all of it. They're basically extensions to the normal attributes that every inode in the system already has (you know, the stat(2) data ๐). And if you want the full โจconceptualโจ overview of extended attributes, that lives in xattr(7). slay.
setxattr() sets the value of the extended attribute identified by name and associated with the given path in the filesystem. The size argument says how big (in bytes) value is โ and heads up bestie, a zero-length value is permitted. iconic.
lsetxattr() is identical to setxattr(), EXCEPT in the case of a symbolic link โ there the extended attribute is set on the link itself, not the file that it refers to. yes. the link. herself. ๐
fsetxattr() is identical to setxattr() too, except the extended attribute gets set on the open file referred to by fd (as returned by open(2)) instead of path. different portal, same vibe. ๐
An extended attribute name is a null-terminated string. The name includes a namespace prefix, and there may be several, disjoint namespaces associated with one individual inode. Meanwhile, the extended attribute value is just a chunk of arbitrary textual or binary data of a specified length. no judgement, binary is valid. ๐
By default โ that's when flags is zero โ the extended attribute will be created if it does not exist, or the value will be replaced if the attribute already exists. If you want to change those semantics, you can specify one of these in flags:
XATTR_CREATEโ perform a pure create, which fails if the named attribute exists already. it's giving "I said NEW, not pre-owned" ๐ญXATTR_REPLACEโ perform a pure replace operation, which fails if the named attribute does not already exist. if she's not there, we're not manifesting her, we're erroring. periodt.
๐ RETURN VALUE
On success, zero is returned. On failure, -1 is returned and errno is set to indicate the error. that's the whole deal, no surprises. ๐
๐ฆ ERRORS ๐ฆ
EDQUOTโ disk quota limits meant that there is insufficient space remaining to store the extended attribute. the quota said no ๐EEXISTโXATTR_CREATEwas specified, and the attribute exists already. told you she was taken.ENODATAโXATTR_REPLACEwas specified, and the attribute does not exist. ghosted fr fr ๐ปENOSPCโ there is insufficient space remaining to store the extended attribute. no room bestie, we're full up.ENOTSUPโ the namespace prefix ofnameis not valid. wrong prefix, wrong party.ENOTSUPโ extended attributes are not supported by the filesystem, or are disabled. yes, same errno, different situation, keep both in your notes ๐EPERMโ the file is marked immutable or append-only. (SeeFS_IOC_SETFLAGS(2const).) she is LOCKED, do not touch. ๐
In addition, the errors documented in stat(2) can also occur.
ERANGEโ the size ofnameorvalueexceeds a filesystem-specific limit. too much. too big. the filesystem is overwhelmed. ๐
โญ STANDARDS
Linux. that's it, that's the standard. ๐ง
๐ธ HISTORY
Linux 2.4, glibc 2.3. vintage but still thriving. ๐
๐ SEE ALSO
getfattr(1), setfattr(1), getxattr(2), listxattr(2), open(2), removexattr(2), stat(2), symlink(7), xattr(7)
and that's the whole page bestie, you ate it ๐ this was Linux man-pages 6.20, dated 2026-02-08, and she's still the setxattr(2) page she's always been. 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