]> git.saurik.com Git - apple/copyfile.git/blame - xattr_name_with_flags.3
copyfile-138.tar.gz
[apple/copyfile.git] / xattr_name_with_flags.3
CommitLineData
618b37c8
A
1.\"
2.\" Copyright (c) 2013 Apple Computer, Inc. All rights reserved.
3.\"
4.Dd October 7, 2013
5.Dt XATTR_NAME_WITH_FLAGS 3
6.Os
7.Sh NAME
8.Nm xattr_preserve_for_intent , xattr_name_with_flags , xattr_name_without_flags ,
9.Nm xattr_flags_from_name , xattr_intent_with_flags
10.Sh LIBRARY
11.Lb libc
12.Sh SYNOPSIS
913df16a 13.In xattr_flags.h
618b37c8
A
14.Ft int
15.Fn xattr_preserve_for_intent "const char *" "xattr_operation_intent_t"
16.Ft char *
17.Fn xattr_name_with_flags "const char *" "xattr_flags_t"
18.Ft char *
19.Fn xattr_name_without_flags "const char *"
20.Ft xattr_flags_t
21.Fn xattr_flags_from_name "const char *"
22.Ft int
23.Fn xattr_intent_with_flags "xattr_operation_intent_t" "xattr_flags_t"
24.Sh DESCRIPTION
25These functions are used in conjunction with copying extended attributes from
26one file to another. Various types of copying (an "intent") check flags to
27determine which is allowed or not.
28.Pp
29The
30.Fn xattr_name_with_flags
31function returns an extended attribute name with the appropriate flags encoded
32as a string; the
33.Fn xattr_name_without_flags
34undoes this, giving the name of the extended attribute without the flags
35encoding. The slight inverse of that is
36.Fn xattr_flags_from_name ,
37which will return the flags encoded in a name.
38.Pp
39The values returned by
40.Fn xattr_name_with_flags
41and
42.Fn xattr_name_without_flags
43are allocated using
44.Xr malloc 3 ,
45and should be released by the caller, using
46.Xr free 3 .
47.Pp
48These functions also have an internal table of pre-defined names, maintained
49by the operating system.
50.Pp
51The function
52.Fn xattr_intent_with_flags
53will return 0 if the
54.Ar flags
55argument indicates it should not be preserved for the given
56intent, or 1 if it should.
57.Pp
58The function
59.Fn xattr_presere_for_intent
60combines the functions above, and will return zero if the
61named extended attribute should be preserved during a copy for
62the given intent.
63.Sh INTENT
64The type
65.Dt xattr_operation_intent_t
66is an integral type, which is used to indicate what the intent for the operation
67is. The following intent values are defined:
68.Bl -tag -width XATTR_OPERATION_INTENT_SHARE
69.It Dv XATTR_OPERATION_INTENT_COPY
70Indicates that the intent is to simply copy from the source to the destination.
71E.g., with cp. Most extended attributes should generally be preserved in this
72case.
73.It Dv XATTR_OPERATION_INTENT_SAVE
74Indicates that intent is to perform a save (perhaps as in a "safe save").
75This differs from a copy in that the content may be changing; the destination
76may be over-writing or replacing the source, and som extended attributes should
77not be preserved during this process.
78.It Dv XATTR_OPERATION_INTENT_SHARE
79Indicates that the intent is to share, or export, the object. For example,
80saving as an attachment in an email message, or placing in a public folder.
81Sensitive information should probably not be preserved in this case.
82.It Dv XATTR_OPERATION_INTENT_SYNC
83Indicates that the intent is to sync the object to a service like iCloud.
84.El
85.Sh FLAGS
86Various flags are defined by the type
87.Dt xattr_flags_t ;
88the currently-defined values for this are
89.Bl -tag -width XATTR_FLAG_CONTENT_DEPENDENT
90.It Dv XATTR_FLAG_NO_EXPORT
91This indicates that the extended attribute should not be exported, or shared.
92This is used with
93.Dv XATTR_OPERATION_INTENT_SHARE .
94.It Dv XATTR_FLAG_CONTENT_DEPENDENT
95This indicates that the extended attribute is tied to the contents of the
96file (or vice versa), such that it should be re-created when the contents
97are changed. A checksum, for example, should not be copied, and would thus
98be marked with this flag.
99.It Dv XATTR_FLAG_NEVER_PRESERVE
100This indicates that the extended attribute should never be copied from a
101source object to a destination, no matter what the given intent is.
102.It Dv XATTR_FLAG_SYNCABLE
103This indicates that the extended attribute should be copied when the file
104is synced on services like iCloud. Sync services tends to want the metadata
105synced to be kept to a bare minimum, and may enforce additional restrictions
106on the acceptable size and number of extended attributes.
107.El
108.Sh EXAMPLE
109The following example is a simple function that, given an extended attribute
110name and an operation intent, will return whether or not the extended attribute
111should be copied. (This essentially does what
112.Fn xattr_preserve_for_intent
113does.)
114.Bd -literal -offset indent
115int
116ShouldCopyEA(const char *eaName, xattr_operation_intent_t intent)
117{
118 xattr_flags_t flags = xattr_flags_from_name(eaName);
119 return xattr_intent_with_flags(intent, flags);
120}
121.Ed
122.Sh HISTORY
123These functions first appeared in Mac OS in 2013.