simple_xattr_set(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… simple_xattr_set(9) πŸ’…

okay so welcome to the Kernel API Manual bestie, today we're doing simple_xattr_set β€” the function that sets an xattr object. it's giving "small but powerful" energy ngl πŸŽ€


✨ NAME ✨

simple_xattr_set β€” set an xattr object πŸ¦‹


🌸 SYNOPSIS 🌸

struct simple_xattr * simple_xattr_set (struct simple_xattr_cache *cache
, struct list_head *xattrs , const char *name , const void *value ,
size_t size , int flags );

like, six whole arguments. she's high maintenance but she's iconic πŸ’…


πŸŽ€ ARGUMENTS πŸŽ€

  • cache β€” anchor for the hash table πŸ—‚οΈ
  • xattrs β€” the header of the xattr object
  • name β€” the name of the xattr to retrieve πŸ‘€
  • value β€” the value to store along the xattr πŸ’–
  • size β€” the size of value
  • flags β€” the flags determining how to set the xattr 🚩

πŸ’œ DESCRIPTION πŸ’œ

So we're setting a new xattr object. periodt.

If value is passed, a new xattr object will be allocated. ✨

Now the flags lore, because this is the main character of the whole function:

  • If XATTR_REPLACE is specified in flags, a matching xattr object for name must already exist. If it does, it gets replaced with the new xattr object. If it doesn't β€” we fail. 😭 no cap.
  • If XATTR_CREATE is specified and a matching xattr does already exist, we fail. If it doesn't exist, we create a new xattr. 🌱
  • If flags is zero, we simply insert the new xattr, replacing any existing one. easy slay 🫢

Also:

  • If value is empty and a matching xattr object is found, we delete it if XATTR_REPLACE is specified in flags or flags is zero. πŸ—‘οΈ
  • If value is empty and no matching xattr object for name is found, we do nothing if XATTR_CREATE is specified in flags or flags is zero. For XATTR_REPLACE we fail, as mentioned above. πŸ’€

πŸ”₯ NOTE πŸ”₯

bestie listen. Callers must externally serialize writes. All current callers hold the inode lock for write operations. The lookup->replace/remove sequence is not atomic with respect to the rhashtable's per-bucket locking, but it is safe because writes are serialized by the caller. like it looks sketchy but it's fine, iykyk 😌

⭐ RETURN ⭐

On success, the removed or replaced xattr is returned, to be freed by the caller; or NULL if none. On failure a negative error code is returned. πŸ™ˆ


🌈 SEE ALSO 🌈

Kernel file ./fs/xattr.c πŸ‘‘ and honestly the whole friend group:


that's the whole page bestie, from ./fs with love, October 2026 edition, simple_xattr_set(9) out πŸ’–βœ¨πŸ¦‹ go forth and set your xattrs 🫢

πŸ“¦ where this page comes from