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