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_CREATE was specified, and the attribute exists already. told you she was taken.
  • ENODATA โ€” XATTR_REPLACE was 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 of name is 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. (See FS_IOC_SETFLAGS(2const).) she is LOCKED, do not touch. ๐Ÿ”’

In addition, the errors documented in stat(2) can also occur.

  • ERANGE โ€” the size of name or value exceeds 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms