ATTR_GET(3)

πŸ“¦
version 2.6.0 Β· 4 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian bookworm, fedora 43, fedora 44, nixpkgs unstable, opensuse-leap 16.0, ubuntu jammy, ubuntu noble

πŸ’– ATTR_GET(3) πŸ’–

okay so bestie, this is a page from the XFS Compatibility API section of the manual, and it's all about peeking at the lil value hiding inside a user attribute on a filesystem object. yes. we're doing extended attributes today. slay.


✨ NAME ✨

attr_get, attr_getf β€” the iconic duo that gets the value of a user attribute of a filesystem object. no cap, that's literally their whole job. πŸŽ€


🌸 C SYNOPSIS 🌸

#include <attr/attributes.h>

int attr_get (const char *path, const char *attrname,
              char *attrvalue, int *valuelength, int flags);

int attr_getf (int fd, const char *attrname,
               char *attrvalue, int *valuelength, int flags);

πŸ¦‹ DESCRIPTION πŸ¦‹

So. attr_get and attr_getf are the way you retrieve the value of an attribute. that's it, that's the vibe. πŸ’…

Path points to a path name for a filesystem object, and fd refers to the file descriptor associated with a file. if the attribute attrname exists, the value associated with it gets copied into the attrvalue buffer. 🫢

The valuelength argument is giving input/output energy β€” on the call to attr_get, it should already contain the maximum size of attribute value the process is willing to accept. on return, valuelength will have been modified to show the actual size of the attribute value returned. she updates herself. main character behavior honestly. ✨

The flags argument can contain the following symbols bitwise OR'ed together:

  • ATTR_ROOT β€” look for attrname in the root address space, not in the user address space. (limited to use by super-user only β€” so like, know your lane unless you're root πŸ‘‘)
  • ATTR_DONTFOLLOW β€” do not follow symbolic links when resolving a path on an attr_get function call. the default is to follow symbolic links. so if you don't pass this, she's gonna chase those links down, no hesitation. 🧚

attr_get will fail if one or more of the following are true:

  • [ENOATTR] β€” the attribute name given is not associated with the indicated filesystem object. she looked. she found nothing. πŸ’€
  • [E2BIG] β€” the value of the given attribute is too large to fit into the buffer. the integer that the valuelength argument points to has been modified to show the actual number of bytes that would be required to store the value of that attribute. so like, she tells you how much room she'd need. helpful queen. 😭
  • [ENOENT] β€” the named file does not exist.
  • [EPERM] β€” the effective user ID does not match the owner of the file and the effective user ID is not super-user. not your file, not your business, fr fr.
  • [ENOTDIR] β€” a component of the path prefix is not a directory.
  • [EACCES] β€” search permission is denied on a component of the path prefix.
  • [EINVAL] β€” a bit was set in the flag argument that is not defined for this system call. you made up a flag bestie. that's not a thing.
  • [EFAULT] β€” Path, attrname, attrvalue, or valuelength points outside the allocated address space of the process. those pointers are off the map. πŸ™ˆ
  • [ELOOP] β€” a path name lookup involved too many symbolic links. the links got into a situationship. πŸ”₯
  • [ENAMETOOLONG] β€” the length of path exceeds {MAXPATHLEN}, or a pathname component is longer than {MAXNAMELEN}.

attr_getf will fail if:

  • [ENOATTR] β€” the attribute name given is not associated with the indicated filesystem object.
  • [E2BIG] β€” the value of the given attribute is too large to fit into the buffer. the integer that the valuelength argument points to has been modified to show the actual number of bytes that would be required to store the value of that attribute.
  • [EINVAL] β€” a bit was set in the flag argument that is not defined for this system call, or fd refers to a socket, not a file. sockets are NOT files, she does not do sockets, periodt. πŸ’…
  • [EFAULT] β€” Attrname, attrvalue, or valuelength points outside the allocated address space of the process.
  • [EBADF] β€” Fd does not refer to a valid descriptor. that fd is giving nothing. invalid. πŸ“

🌈 DIAGNOSTICS 🌈

On success, zero is returned. πŸŽ‰ on error, -1 is returned, and errno is set appropriately. so like, check your errno, she's always trying to tell you something. ⭐


πŸ‘‘ SEE ALSO πŸ‘‘


and that's the whole page bestie!! this one came from the Extended Attributes corner of the manual, dated Dec 2001 β€” a vintage icon, honestly, she's been serving since before most of us could read. go get those attributes. πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from