Copyright (c) 2004 Apple Computer, Inc. All rights reserved.

@APPLE_LICENSE_HEADER_START@

This file contains Original Code and/or Modifications of Original Code
as defined in and that are subject to the Apple Public Source License
Version 2.0 (the 'License'). You may not use this file except in
compliance with the License. Please obtain a copy of the License at
http://www.opensource.apple.com/apsl/ and read it before using this
file.

The Original Code and all software distributed under the License are
distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
Please see the License for the specific language governing rights and
limitations under the License.

@APPLE_LICENSE_HEADER_END@

.Dd Oct 19, 2004 .Dt SETXATTR 2 .Os "Mac OS X" .Sh NAME .Nm setxattr, .Nm fsetxattr .Nd set an extended attribute value .Sh SYNOPSIS .Fd #include <sys/xattr.h> .Ft int .Fn setxattr "const char *path" "const char *name" "void *value" "size_t size" "u_int32_t position" "int options" .Ft int .Fn fsetxattr "int fd" "const char *name" "void *value" "size_t size" "u_int32_t position" "int options" .Sh DESCRIPTION Extended attributes extend the basic attributes associated with files and directories in the file system. They are stored as name:data pairs associated with file system objects (files, directories, symlinks, etc).

p .Fn setxattr associates .Fa name and .Fa data together as an attribute of .Fa path .

p An extended attribute's .Fa name is a simple NULL-terminated UTF-8 string. .Fa Value is a pointer to a data buffer of .Fa size bytes containing textual or binary data to be associated with the extended attribute. .Fa Position specifies the offset within the extended attribute. In the current implementation, only the resource fork extended attribute makes use of this argument. For all others, .Fa position is reserved and should be set to zero.

p .Fa options controls how the attribute is set:

p l -tag -width XATTR_NOFOLLOW t Dv XATTR_NOFOLLOW do not follow symbolic links. .Fn setxattr normally sets attributes on the target of .Fa path if it is a symbolic link. With this option, .Fn setxattr will act on the link itself. t Dv XATTR_CREATE fail if the named attribute already exists. t Dv XATTR_REPLACE fail if the named attribute does not exist. Failure to specify .Dv XATTR_REPLACE or .Dv XATTR_CREATE allows creation and replacement. .El

p .Fn fsetxattr is identical to .Fn setxattr , except that it sets an extended attribute on an open file referenced by file descriptor .Fa fd . .Sh NOTES On some filesystems, such as .Dv HFS+ , setting the extended attribute .Dv com.apple.ResourceFork will update the modification time (``mtime'') of the file.

p Due to historical reasons, the .Dv XATTR_FINDERINFO_NAME (defined to be .Dq com.apple.FinderInfo ) extended attribute must be 32 bytes; see the .Dv ATTR_CMN_FNDRINFO section in .Xr getattrlist 2 .

p The maximum supported size of extended attribute can be found out using .Xr pathconf 2 with _PC_XATTR_SIZE_BITS option. .Sh RETURN VALUES On success, 0 is returned. On failure, -1 is returned and the global variable .Va errno is set as follows. .Sh ERRORS l -tag -width Er t Bq Er EEXIST .Fa options contains .Em XATTR_CREATE and the named attribute already exists. t Bq Er ENOATTR .Fa options is set to .Em XATTR_REPLACE and the named attribute does not exist. t Bq Er ENOTSUP The file system does not support extended attributes or has them disabled. t Bq Er EROFS The file system is mounted read-only. t Bq Er ERANGE The data size of the attribute is out of range (some attributes have size restrictions). t Bq Er EPERM EFTYPE could be more specific but isn't POSIX
Attributes cannot be associated with this type of object. For example, attributes are not allowed for resource forks. t Bq Er EINVAL .Fa name or .Fa options is invalid. .Fa name must be valid UTF-8 and .Fa options must make sense. t Bq Er ENOTDIR A component of .Fa path is not a directory. t Bq Er ENAMETOOLONG .Fa name exceeded .Dv XATTR_MAXNAMELEN UTF-8 bytes, or a component of .Fa path exceeded .Dv NAME_MAX characters, or the entire .Fa path exceeded .Dv PATH_MAX characters. t Bq Er EACCES Search permission is denied for a component of .Fa path or permission to set the attribute is denied. t Bq Er ELOOP Too many symbolic links were encountered resolving .Fa path . t Bq Er EFAULT .Fa path or .Fa name points to an invalid address. t Bq Er EIO An I/O error occurred while reading from or writing to the file system. t Bq Er E2BIG The data size of the extended attribute is too large. t Bq Er ENOSPC Not enough space left on the file system. .El .Sh SEE ALSO .Xr getxattr 2 , .Xr listxattr 2 , .Xr removexattr 2 , .Xr pathconf 2 .Sh HISTORY .Fn setxattr and .Fn fsetxattr first appeared in Mac OS X 10.4.