---
name: "xattr_name_with_flags"
section: "3"
platform: "macos"
package: "copyfile"
version: "240"
release: "macOS 26.5"
platforms: ["macos"]
url: "https://new.carta.tech/xattr_name_with_flags"
---

# xattr\_name\_with\_flags(3)

obtain properties related to extended attributes, for use in copying

## NAME

**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

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#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*);

## DESCRIPTION

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)](/malloc/3.md), and should be released by the caller, using [free(3)](/free/3.md).

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 non zero if the named extended attribute should be preserved during a copy for the given intent.

## 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

  Indicates that the intent is to simply copy from the source to the destination. E.g., with cp. Most extended attributes should generally be preserved in this case.

- XATTR\_OPERATION\_INTENT\_SAVE

  Indicates that intent is to perform a save (perhaps as in a "safe save"). This differs from a copy in that the content may be changing; the destination may be over-writing or replacing the source, and some extended attributes should not be preserved during this process.

- XATTR\_OPERATION\_INTENT\_SHARE

  Indicates that the intent is to share, or export, the object. For example, saving as an attachment in an email message, or placing in a public folder. Sensitive information should probably not be preserved in this case.

- XATTR\_OPERATION\_INTENT\_SYNC

  Indicates that the intent is to sync the object to a service like iCloud Drive.

- XATTR\_OPERATION\_INTENT\_BACKUP

  Indicates that the intent is to backup the object to a service like Time Machine.

## FLAGS

Various flags are defined by the type *xattr\_flags\_t*; the currently-defined values for this are:

- XATTR\_FLAG\_NO\_EXPORT

  This indicates that the extended attribute should not be exported, or shared. This is used with XATTR\_OPERATION\_INTENT\_SHARE.

- XATTR\_FLAG\_CONTENT\_DEPENDENT

  This indicates that the extended attribute is tied to the contents of the file (or vice versa), such that it should be re-created when the contents are changed. A checksum, for example, should not be copied, and would thus be marked with this flag.

- XATTR\_FLAG\_NEVER\_PRESERVE

  This indicates that the extended attribute should never be copied from a source object to a destination, no matter what the given intent is.

- XATTR\_FLAG\_SYNCABLE

  This indicates that the extended attribute should be copied when the file is synced on services like iCloud Drive. Sync services may enforce additional restrictions on the acceptable size and number of extended attributes. (Note that when used with XATTR\_FLAG\_CONTENT\_DEPENDENT, this may generate conflicts when the file is synced.)

- XATTR\_FLAG\_ONLY\_BACKUP

  This indicates that the extended attribute should only be copied during backup on services like Time Machine.

- XATTR\_FLAG\_ONLY\_SAVING

  This indicates that the extended attribute should only be copied during save/backup.

## EXAMPLE

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);
}
```

## HISTORY

These functions first appeared in Mac OS in 2013.
