]> git.saurik.com Git - apple/xnu.git/blame - bsd/man/man2/setxattr.2
xnu-2782.30.5.tar.gz
[apple/xnu.git] / bsd / man / man2 / setxattr.2
CommitLineData
91447636
A
1.\"
2.\" Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
3.\"
6601e61a 4.\" @APPLE_LICENSE_HEADER_START@
91447636 5.\"
8f6c56a5
A
6.\" This file contains Original Code and/or Modifications of Original Code
7.\" as defined in and that are subject to the Apple Public Source License
8.\" Version 2.0 (the 'License'). You may not use this file except in
9.\" compliance with the License. Please obtain a copy of the License at
10.\" http://www.opensource.apple.com/apsl/ and read it before using this
91447636
A
11.\" file.
12.\"
8f6c56a5
A
13.\" The Original Code and all software distributed under the License are
14.\" distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15.\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16.\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17.\" FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18.\" Please see the License for the specific language governing rights and
91447636
A
19.\" limitations under the License.
20.\"
6601e61a 21.\" @APPLE_LICENSE_HEADER_END@
91447636
A
22.\"
23.Dd Oct 19, 2004
24.Dt SETXATTR 2
25.Os "Mac OS X"
26.Sh NAME
27.Nm setxattr,
28.Nm fsetxattr
29.Nd set an extended attribute value
30.Sh SYNOPSIS
31.Fd #include <sys/xattr.h>
32.Ft int
33.Fn setxattr "const char *path" "const char *name" "void *value" "size_t size" "u_int32_t position" "int options"
34.Ft int
35.Fn fsetxattr "int fd" "const char *name" "void *value" "size_t size" "u_int32_t position" "int options"
36.Sh DESCRIPTION
37Extended attributes extend the basic attributes associated with files and
38directories in the file system. They are stored as name:data pairs
39associated with file system objects (files, directories, symlinks, etc).
40.Pp
41.Fn setxattr
42associates
43.Fa name
44and
45.Fa data
46together as an attribute of
47.Fa path .
48.Pp
49An extended attribute's
50.Fa name
51is a simple NULL-terminated UTF-8 string.
52.Fa Value
53is a pointer to a data buffer of
54.Fa size
55bytes containing textual or binary data to be associated with the
56extended attribute.
57.Fa Position
58specifies the offset within the extended attribute. In the current
59implementation, only the resource fork extended attribute makes use of
60this argument. For all others,
61.Fa position
62is reserved and should be
63set to zero.
64.Pp
65.Fa options
66controls how the attribute is set:
67.Pp
68.Bl -tag -width XATTR_NOFOLLOW
69.It Dv XATTR_NOFOLLOW
70do not follow symbolic links.
71.Fn setxattr
72normally sets attributes on the target of
73.Fa path
74if it is a symbolic link.
75With this option,
76.Fn setxattr
77will act on the link itself.
78.It Dv XATTR_CREATE
79fail if the named attribute already exists.
80.It Dv XATTR_REPLACE
81fail if the named attribute does not exist. Failure to specify
82.Dv XATTR_REPLACE
83or
84.Dv XATTR_CREATE
85allows creation and replacement.
86.El
87.Pp
88.Fn fsetxattr
89is identical to
90.Fn setxattr ,
91except that it sets an extended attribute on an open file referenced by
92file descriptor
93.Fa fd .
39236c6e 94.Sh NOTES
6d2010ae
A
95On some filesystems, such as
96.Dv HFS+ ,
97setting the extended attribute
98.Dv com.apple.ResourceFork
99will update the modification time (``mtime'') of
100the file.
39236c6e
A
101.Pp
102Due to historical reasons, the
103.Dv XATTR_FINDERINFO_NAME
104(defined to be
105.Dq com.apple.FinderInfo )
106extended attribute must be 32 bytes; see the
107.Dv ATTR_CMN_FNDRINFO
108section in
109.Xr getattrlist 2 .
110.Pp
111The maximum supported size of extended attribute can be found out using
112.Xr pathconf 2
113with _PC_XATTR_SIZE_BITS option.
91447636
A
114.Sh RETURN VALUES
115On success, 0 is returned. On failure, -1 is returned and the global
116variable
117.Va errno
118is set as follows.
119.Sh ERRORS
120.Bl -tag -width Er
121.It Bq Er EEXIST
122.Fa options
123contains
124.Em XATTR_CREATE
125and the named attribute already exists.
126.It Bq Er ENOATTR
127.Fa options
128is set to
129.Em XATTR_REPLACE
130and the named attribute does not exist.
131.It Bq Er ENOTSUP
132The file system does not support extended attributes or has them disabled.
133.It Bq Er EROFS
134The file system is mounted read-only.
135.It Bq Er ERANGE
136The data size of the attribute is out of range (some attributes have size
137restrictions).
138.It Bq Er EPERM
139.\" EFTYPE could be more specific but isn't POSIX
140Attributes cannot be associated with this type of object. For example,
141attributes are not allowed for resource forks.
142.It Bq Er EINVAL
143.Fa name
144or
145.Fa options
146is invalid.
147.Fa name
148must be valid UTF-8 and
149.Fa options
150must make sense.
151.It Bq Er ENOTDIR
152A component of
153.Fa path
154is not a directory.
155.It Bq Er ENAMETOOLONG
156.Fa name
157exceeded
158.Dv XATTR_MAXNAMELEN
159UTF-8 bytes, or a component of
160.Fa path
161exceeded
162.Dv NAME_MAX
163characters, or the entire
164.Fa path
165exceeded
166.Dv PATH_MAX
167characters.
168.It Bq Er EACCES
169Search permission is denied for a component of
170.Fa path
171or permission to set the attribute is denied.
172.It Bq Er ELOOP
173Too many symbolic links were encountered resolving
174.Fa path .
175.It Bq Er EFAULT
176.Fa path
177or
178.Fa name
179points to an invalid address.
180.It Bq Er EIO
181An I/O error occurred while reading from or writing to the file system.
182.It Bq Er E2BIG
183The data size of the extended attribute is too large.
184.It Bq Er ENOSPC
185Not enough space left on the file system.
186.El
187.Sh SEE ALSO
188.Xr getxattr 2 ,
2d21ac55 189.Xr listxattr 2 ,
39236c6e
A
190.Xr removexattr 2 ,
191.Xr pathconf 2
91447636
A
192.Sh HISTORY
193.Fn setxattr
194and
195.Fn fsetxattr
196first appeared in Mac OS X 10.4.