XATTR_NAME_WITH_FLAGS(3) | Library Functions Manual | XATTR_NAME_WITH_FLAGS(3) |
xattr_preserve_for_intent
,
xattr_name_with_flags
,
xattr_name_without_flags
,
xattr_flags_from_name
,
xattr_intent_with_flags
—
obtain properties related to extended attributes, for use
in copying
Standard C Library (libc, -lc)
#include
<xattr_flags.h>
int
xattr_preserve_for_intent
(const
char *,
xattr_operation_intent_t);
char *
xattr_name_with_flags
(const
char *,
xattr_flags_t);
char *
xattr_name_without_flags
(const
char *);
xattr_flags_t
xattr_flags_from_name
(const
char *);
int
xattr_intent_with_flags
(xattr_operation_intent_t,
xattr_flags_t);
These functions are used in conjunction with copying extended attributes from one file to another. Various types of copying (an "intent") check flags to determine which is allowed or not.
The
xattr_name_with_flags
()
function returns an extended attribute name with the appropriate flags
encoded as a string; the
xattr_name_without_flags
()
undoes this, giving the name of the extended attribute without the flags
encoding. The slight inverse of that is
xattr_flags_from_name
(),
which will return the flags encoded in a name.
The values returned by
xattr_name_with_flags
()
and
xattr_name_without_flags
()
are allocated using malloc(3), and
should be released by the caller, using
free(3).
These functions also have an internal table of pre-defined names, maintained by the operating system.
The function
xattr_intent_with_flags
()
will return 0 if the flags argument indicates it
should not be preserved for the given intent, or 1 if it should.
The function
xattr_preserve_for_intent
()
combines the functions above, and will return zero if the named extended
attribute should be preserved during a copy for the given intent.
The type xattr_operation_intent_t is an integral type, which is used to indicate what the intent for the operation is. The following intent values are defined:
XATTR_OPERATION_INTENT_COPY
XATTR_OPERATION_INTENT_SAVE
XATTR_OPERATION_INTENT_SHARE
XATTR_OPERATION_INTENT_SYNC
XATTR_OPERATION_INTENT_BACKUP
Various flags are defined by the type xattr_flags_t; the currently-defined values for this are:
XATTR_FLAG_NO_EXPORT
XATTR_OPERATION_INTENT_SHARE
.XATTR_FLAG_CONTENT_DEPENDENT
XATTR_FLAG_NEVER_PRESERVE
XATTR_FLAG_SYNCABLE
XATTR_FLAG_CONTENT_DEPENDENT,
this may generate
conflicts when the file is synced.)XATTR_FLAG_ONLY_BACKUP
XATTR_FLAG_ONLY_SAVING
The following example is a simple function that, given an extended
attribute name and an operation intent, will return whether or not the
extended attribute should be copied. (This essentially does what
xattr_preserve_for_intent
() does.)
int ShouldCopyEA(const char *eaName, xattr_operation_intent_t intent) { xattr_flags_t flags = xattr_flags_from_name(eaName); return xattr_intent_with_flags(intent, flags); }
These functions first appeared in Mac OS in 2013.
December 19, 2023 | macOS 15.0 |