Basic system calls:
Each of the above accepts a pathname argument.
There are alternate forms for working on symbolic links or open file descriptors, e.g., lsetxattr(), fsetxattr() (cf. stat(), lstat(), fstat()).
int setxattr(const char *pathname, const char *name,
const void *value, size_t size, int flags)
Set an EA for pathname, using name and value.
- name is a null-terminated string.
- size is length of value.
- By default (i.e., flags == 0), setfxattr() creates new name or overwrites existing name as required.
- flags can be:
0;
XATTR_CREATE, give an error if name is already defined; or
XATTR_REPLACE, give an error if name is not already defined.
- Example:
char *value; value = "The past is not dead."; setxattr(pathname, "user.x", value, strlen(value), 0);
ssize_t getxattr(const char *pathname, const char *name,
void *value, size_t size)
Retrieves current value of name for pathname, and places it in value.
- size specifies space available in value.
- Returns number of bytes copied into value.
int removexattr(const char *pathname, const char *name)
Remove EA name from pathname.
ssize_t listxattr(const char *pathname, char *list, size_t size)
Returns a list containing names of all EAs associated with pathname.
- List is returned as a series of null-separated strings in list.
- size specifies space available in list.
- Returns the number of bytes copied into list.
- Call fails if size is too small; making a call with size == 0 can be used to obtain size required for list.
- Obtain corresponding values by calling getxattr() for each name in list.
(C) 2006, Michael Kerrisk