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