VOP_GETEXTATTR(9)

πŸ’– VOP_GETEXTATTR πŸ’–

okay so bestie, welcome to VOP_GETEXTATTR, section 9 of the Kernel Developer's Manual β€” aka the vnode call that retrieves a named extended attribute from a vnode. she's giving very much "get me that metadata, bestie" energy and honestly? we're obsessed. πŸŽ€


✨ SYNOPSIS ✨

first things first, you gotta pull in the headers, no cap:

#include <sys/param.h>
#include <sys/vnode.h>
#include <sys/extattr.h>

int
VOP_GETEXTATTR(struct vnode *vp, int attrnamespace, const char *name,
    struct uio *uio, size_t *size, struct ucred *cred,
    struct thread *td);

like, that's the whole vibe right there. seven arguments, all iconic, all necessary. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so this vnode call is literally the one you use to retrieve a specific named extended attribute from a file or a directory. file or directory, she doesn't discriminate, she just serves. ✨

now let's meet the arguments, one by one, because they ALL matter:

  • vp β€” the vnode of the file or directory. your main character, fr fr.
  • attrnamespace β€” an integer constant indicating which extended attribute namespace the attribute name is present in. she tells you where the name lives.
  • name β€” a pointer to a null-terminated character string containing the attribute name. yes, null-terminated, yes, that's important. 🫢
  • uio β€” the location of the data to be read. this is where the goods go.
  • size β€” if it's not NULL, then on return it will contain the number of bytes required to read all of the attribute data. and listen: in most cases uio will be NULL when size is not, and vice versa. they're giving mutually exclusive bestie energy, iykyk. πŸ’€
  • cred β€” the user credentials to use in authorizing the request. who's asking, basically.
  • td β€” the thread requesting the extended attribute. hi bestie, it's you. πŸ‘‘

and here's a lil detail that lowkey matters a lot: the cred pointer may be NULL to indicate that access control checks are not to be performed, if possible. this cred setting might be used to allow the kernel to authorize extended attribute retrieval that the active process might not be permitted to do. so like, the kernel gets to do things you don't get to do. iconic of her, honestly. πŸ‘‘

also, heads up: extended attribute semantics may vary by file system implementing the call. every FS does her own thing, and that's just the tea. β˜• more information on extended attributes may be found in extattr(9).


πŸ”’ LOCKS πŸ”’

the vnode will be locked on entry and should remain locked on return. don't you dare unlock her mid-flight, bestie, that's not the vibe. 🚫


πŸ’« RETURN VALUES πŸ’«

on success, zero will be returned, and the uio structure will be updated to reflect data read. slay. ✨

otherwise, an appropriate error code is returned. and by "appropriate" we mean "she'll tell you exactly what went wrong," so go read the next section. πŸ‘‡


😭 ERRORS 😭

  • [ENOATTR] β€” the requested attribute was not defined for this vnode. she doesn't have it. it's not there. it's giving empty shelf. πŸ’€
  • [EACCES] β€” the caller does not have the appropriate privilege. respectfully, who do you think you are? πŸ™ˆ
  • [ENXIO] β€” the request was not valid in this file system for the specified vnode and attribute name. wrong FS, wrong vnode, wrong name, wrong everything.
  • [ENOMEM] β€” sufficient memory is not available to fulfill the request. girl is broke. no memory. 😭
  • [EFAULT] β€” the uio structure refers to an invalid userspace address. that address is not real, bestie, stop pointing at it.
  • [EINVAL] β€” the name, namespace, or uio argument is invalid. one of the three, or maybe all three, we're not judging (we're a little judging).
  • [EOPNOTSUPP] β€” the file system does not support VOP_GETEXTATTR(). she literally cannot, and will not. periodt. πŸ’…

πŸ‘€ SEE ALSO πŸ‘€

go read these next, they're all part of the same friend group:


πŸ› BUGS πŸ›

okay so this is the messy part and we need to talk about it. by passing in the empty string as the attribute name, some file systems will return a list of defined names on the target vnode for the requested namespace.

and like... that's a bad API. straight up. the manpage said it, not me. it will be replaced by an explicit VOP. so yeah, it's deprecated behavior in spirit, it's a cursed little shortcut, and it's on its way out. don't build your whole personality around it. πŸ™ˆ


friendly reminder: this page is from the Debian distribution, dated December 23, 1999, and it's filed under VOP_GETEXTATTR(9) in the Kernel Developer's Manual. old but still serving. πŸ’œ

okay that's the whole page bestie, go read your extended attributes, stay locked, and slay πŸ¦‹βœ¨πŸŽ€πŸ’–

πŸ“¦ where this page comes from