SETXATTR(2) | System Calls Manual | SETXATTR(2) |
setxattr,
fsetxattr
— set an extended
attribute value
#include
<sys/xattr.h>
int
setxattr
(const
char *path, const char
*name, void *value,
size_t size,
u_int32_t position,
int options);
int
fsetxattr
(int
fd, const char
*name, void *value,
size_t size,
u_int32_t position,
int options);
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).
setxattr
()
associates name and data
together as an attribute of path.
An extended attribute's name is a simple NULL-terminated UTF-8 string. Value is a pointer to a data buffer of size bytes containing textual or binary data to be associated with the extended attribute. 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, position is reserved and should be set to zero.
options controls how the attribute is set:
XATTR_NOFOLLOW
setxattr
()
normally sets attributes on the target of path if it
is a symbolic link. With this option, setxattr
()
will act on the link itself.XATTR_NOFOLLOW_ANY
XATTR_CREATE
XATTR_REPLACE
XATTR_REPLACE
or
XATTR_CREATE
allows creation and replacement.fsetxattr
()
is identical to setxattr
(), except that it sets an
extended attribute on an open file referenced by file descriptor
fd.
On some filesystems, such as HFS+
, setting
the extended attribute com.apple.ResourceFork
will
update the modification time (``mtime'') of the file.
Due to historical reasons, the
XATTR_FINDERINFO_NAME
(defined to be
“com.apple.FinderInfo”) extended attribute must be 32 bytes;
see the ATTR_CMN_FNDRINFO
section in
getattrlist(2).
The maximum supported size of extended attribute can be found out using pathconf(2) with _PC_XATTR_SIZE_BITS option.
On success, 0 is returned. On failure, -1 is returned and the global variable errno is set as follows.
EEXIST
]ENOATTR
]ENOTSUP
]EROFS
]ERANGE
]EPERM
]EINVAL
]EINVAL
]fsetxattr
().ENOTDIR
]ENAMETOOLONG
]XATTR_MAXNAMELEN
UTF-8 bytes, or a component of
path exceeded NAME_MAX
characters, or the entire path exceeded
PATH_MAX
characters.EACCES
]ELOOP
]ELOOP
]EFAULT
]EIO
]E2BIG
]ENOSPC
]setxattr
() and
fsetxattr
() first appeared in Mac OS X 10.4.
October 19, 2004 | Mac OS X |