Imported Upstream version 2.4.46
[platform/upstream/attr.git] / man / man2 / setxattr.2
1 .\"
2 .\" Extended attributes system calls manual pages
3 .\"
4 .\" (C) Andreas Gruenbacher, February 2001
5 .\" (C) Silicon Graphics Inc, September 2001
6 .\"
7 .\" This is free documentation; you can redistribute it and/or
8 .\" modify it under the terms of the GNU General Public License as
9 .\" published by the Free Software Foundation; either version 2 of
10 .\" the License, or (at your option) any later version.
11 .\"
12 .\" The GNU General Public License's references to "object code"
13 .\" and "executables" are to be interpreted as the output of any
14 .\" document formatting or typesetting system, including
15 .\" intermediate and printed output.
16 .\"
17 .\" This manual is distributed in the hope that it will be useful,
18 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
19 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 .\" GNU General Public License for more details.
21 .\"
22 .\" You should have received a copy of the GNU General Public
23 .\" License along with this manual.  If not, see
24 .\" <http://www.gnu.org/licenses/>.
25 .\"
26 .TH SETXATTR 2 "Extended Attributes" "Dec 2001" "System calls"
27 .SH NAME
28 setxattr, lsetxattr, fsetxattr \- set an extended attribute value
29 .SH SYNOPSIS
30 .fam C
31 .nf
32 .B #include <sys/types.h>
33 .B #include <attr/xattr.h>
34 .sp
35 .BI "int setxattr (const char\ *" path ", const char\ *" name ",
36 .BI "\t\t\t const void\ *" value ", size_t " size ", int " flags );
37 .BI "int lsetxattr (const char\ *" path ", const char\ *" name ",
38 .BI "\t\t\t const void\ *" value ", size_t " size ", int " flags );
39 .BI "int fsetxattr (int " filedes ", const char\ *" name ",
40 .BI "\t\t\t const void\ *" value ", size_t " size ", int " flags );
41 .fi
42 .fam T
43 .SH DESCRIPTION
44 Extended attributes are
45 .IR name :\c
46 .I value
47 pairs associated with inodes (files, directories, symlinks, etc).
48 They are extensions to the normal attributes which are associated
49 with all inodes in the system (i.e. the
50 .BR stat (2)
51 data).
52 A complete overview of extended attributes concepts can be found in
53 .BR attr (5).
54 .PP
55 .B setxattr
56 sets the
57 .I value
58 of the extended attribute identified by
59 .I name
60 and associated with the given
61 .I path
62 in the filesystem.
63 The
64 .I size
65 of the
66 .I value
67 must be specified.
68 .PP
69 .B lsetxattr
70 is identical to 
71 .BR setxattr ,
72 except in the case of a symbolic link, where the extended attribute is
73 set on the link itself, not the file that it refers to.
74 .PP
75 .B fsetxattr
76 is identical to
77 .BR setxattr ,
78 only the extended attribute is set on the open file pointed to by
79 .I filedes
80 (as returned by
81 .BR open (2))
82 in place of
83 .IR path .
84 .PP
85 An extended attribute name is a simple NULL-terminated string.
86 The
87 .I name
88 includes a namespace prefix \- there may be several, disjoint
89 namespaces associated with an individual inode.
90 The
91 .I value
92 of an extended attribute is a chunk of arbitrary textual or
93 binary data of specified length.
94 .PP
95 The
96 .I flags
97 parameter can be used to refine the semantics of the operation.
98 XATTR_CREATE specifies a pure create, which fails if the named
99 attribute exists already.
100 XATTR_REPLACE specifies a pure replace operation, which fails if the
101 named attribute does not already exist.
102 By default (no flags), the extended attribute will be created if
103 need be, or will simply replace the value if the attribute exists.
104 .SH RETURN VALUE
105 On success, zero is returned.
106 On failure, \-1 is returned and
107 .I errno
108 is set appropriately.
109 .PP
110 If XATTR_CREATE is specified, and the attribute exists already,
111 .I errno
112 is set to EEXIST.
113 If XATTR_REPLACE is specified, and the attribute does not exist,
114 .I errno
115 is set to ENOATTR.
116 .PP
117 If there is insufficient space remaining to store the extended attribute,
118 .I errno
119 is set to either ENOSPC, or EDQUOT if quota enforcement was the cause.
120 .PP
121 If extended attributes are not supported by the filesystem, or are disabled,
122 .I errno
123 is set to ENOTSUP.
124 .PP
125 The errors documented for the
126 .BR stat (2)
127 system call are also applicable here.
128 .SH AUTHORS
129 Andreas Gruenbacher,
130 .RI < a.gruenbacher@bestbits.at >
131 and the SGI XFS development team,
132 .RI < linux-xfs@oss.sgi.com >.
133 Please send any bug reports or comments to these addresses.
134 .SH SEE ALSO
135 .BR getfattr (1),
136 .BR setfattr (1),
137 .BR open (2),
138 .BR stat (2),
139 .BR getxattr (2),
140 .BR listxattr (2),
141 .BR removexattr (2),
142 and
143 .BR attr (5).