1SETXATTR(2) Linux Programmer's Manual SETXATTR(2)
2
3
4
6 setxattr, lsetxattr, fsetxattr - set an extended attribute value
7
9 #include <sys/types.h>
10 #include <sys/xattr.h>
11
12 int setxattr(const char *path, const char *name,
13 const void *value, size_t size, int flags);
14 int lsetxattr(const char *path, const char *name,
15 const void *value, size_t size, int flags);
16 int fsetxattr(int fd, const char *name,
17 const void *value, size_t size, int flags);
18
20 Extended attributes are name:value pairs associated with inodes (files,
21 directories, symbolic links, etc.). They are extensions to the normal
22 attributes which are associated with all inodes in the system (i.e.,
23 the stat(2) data). A complete overview of extended attributes concepts
24 can be found in xattr(7).
25
26 setxattr() sets the value of the extended attribute identified by name
27 and associated with the given path in the filesystem. The size argu‐
28 ment specifies the size (in bytes) of value; a zero-length value is
29 permitted.
30
31 lsetxattr() is identical to setxattr(), except in the case of a sym‐
32 bolic link, where the extended attribute is set on the link itself, not
33 the file that it refers to.
34
35 fsetxattr() is identical to setxattr(), only the extended attribute is
36 set on the open file referred to by fd (as returned by open(2)) in
37 place of path.
38
39 An extended attribute name is a null-terminated string. The name
40 includes a namespace prefix; there may be several, disjoint namespaces
41 associated with an individual inode. The value of an extended
42 attribute is a chunk of arbitrary textual or binary data of specified
43 length.
44
45 By default (i.e., flags is zero), the extended attribute will be cre‐
46 ated if it does not exist, or the value will be replaced if the
47 attribute already exists. To modify these semantics, one of the fol‐
48 lowing values can be specified in flags:
49
50 XATTR_CREATE
51 Perform a pure create, which fails if the named attribute exists
52 already.
53
54 XATTR_REPLACE
55 Perform a pure replace operation, which fails if the named
56 attribute does not already exist.
57
59 On success, zero is returned. On failure, -1 is returned and errno is
60 set appropriately.
61
63 EDQUOT Disk quota limits meant that there is insufficient space remain‐
64 ing to store the extended attribute.
65
66 EEXIST XATTR_CREATE was specified, and the attribute exists already.
67
68 ENOATTR
69 XATTR_REPLACE was specified, and the attribute does not exist.
70 (ENOATTR is defined to be a synonym for ENODATA in
71 <attr/xattr.h>.)
72
73 ENOSPC There is insufficient space remaining to store the extended
74 attribute.
75
76 ENOTSUP
77 The namespace prefix of name is not valid.
78
79 ENOTSUP
80 Extended attributes are not supported by the filesystem, or are
81 disabled,
82
83 EPERM The file is marked immutable or append-only. (See
84 ioctl_iflags(2).)
85
86 In addition, the errors documented in stat(2) can also occur.
87
89 These system calls have been available on Linux since kernel 2.4; glibc
90 support is provided since version 2.3.
91
93 These system calls are Linux-specific.
94
96 getfattr(1), setfattr(1), getxattr(2), listxattr(2), open(2), removex‐
97 attr(2), stat(2), symlink(7), xattr(7)
98
100 This page is part of release 4.15 of the Linux man-pages project. A
101 description of the project, information about reporting bugs, and the
102 latest version of this page, can be found at
103 https://www.kernel.org/doc/man-pages/.
104
105
106
107Linux 2017-03-13 SETXATTR(2)