1/*
2 * Copyright (c) 2013 Apple, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#ifndef _XATTR_PROPERTIES_H
25#define _XATTR_PROPERTIES_H
26
27#include <stdint.h>
28
29#include <sys/cdefs.h>
30
31
32__BEGIN_DECLS
33
34/*
35 * CopyOperationIntent_t is used to declare what the intent of the copy is.
36 * Not a bit-field (for now, at least).
37 *
38 * CopyOperationIntentCopy indicates that the EA is attached to an object
39 * that is simply being copied.  E.g., cp src dst
40 *
41 * CopyOperationIntentSave indicates that the EA is attached to an object
42 * being saved; as in a "safe save," the destination is being replaced by
43 * the source, so the question is whether the EA should be applied to the
44 * destination, or generated anew.
45 *
46 * CopyOperationIntentShare indicates that the EA is attached to an object that
47 * is being given out to other people.  For example, saving to a public folder,
48 * or attaching to an email message.
49 */
50
51typedef enum {
52	CopyOperationIntentCopy = 1,
53	CopyOperationIntentSave,
54	CopyOperationIntentShare,
55} CopyOperationIntent_t;
56
57typedef uint64_t CopyOperationProperties_t;
58
59/*
60 * Various properties used to determine how to handle the xattr during
61 * copying.  The intent is that the default is reasonable for most xattrs.
62 */
63
64/*
65 * kCopyOperationPropertyNoExport
66 * Declare that the extended property should not be exported; this is
67 * deliberately a bit vague, but this is used by CopyOperationIntentShare
68 * to indicate not to preserve the xattr.
69 */
70#define kCopyOperationPropertyNoExport	((CopyOperationProperties_t)0x0001)
71
72/*
73 * kCopyOperationPropertyContentDependent
74 * Declares the extended attribute to be tied to the contents of the file (or
75 * vice versa), such that it should be re-created when the contents of the
76 * file change.  Examples might include cryptographic keys, checksums, saved
77 * position or search information, and text encoding.
78 *
79 * This property causes the EA to be preserved for copy and share, but not for
80 * safe save.  (In a safe save, the EA exists on the original, and will not
81 * be copied to the new version.)
82 */
83#define	kCopyOperationPropertyContentDependent	((CopyOperationProperties_t)0x0002)
84
85/*
86 * kCopyOperationPropertyNeverPreserve
87 * Declares that the extended attribute is never to be copied, for any
88 * intention type.
89 */
90#define kCopyOperationPropertyNeverPreserve	((CopyOperationProperties_t)0x0004)
91
92// Given a named extended attribute, and a copy intent, should the EA be preserved?
93extern int _PreserveEA(const char *, CopyOperationIntent_t);
94
95/*
96 * Given an extended attribute name, and a set of properties, return an
97 *  allocated C string with the name.  This will return NULL on error;
98 * errno may be set to ENOMEM if the new name cannot be allocated, or
99 * ENAMETOOLONG if the new name is longer than the maximum for EAs (127 UTF8
100 * characters).  The caller must deallocate the return value otherwise.
101 *
102 * If no properties are set, it returns a copy of the EA name.
103 *
104 * If the EA name is in the internal list, and the properties are the same as
105 * defined there, then it will also return an unmodified copy of the EA name.
106 */
107extern char *_xattrNameWithProperties(const char *, CopyOperationProperties_t);
108
109/*
110 * Given an extended attribute name, which may or may not have properties encoded
111 * as a suffix, return just the name of the attribute.  E.g., com.example.mine#P
112 * would return "com.example.mine".  The return value will be NULL on error;
113 * errno will be set to ENOMEM if it cannot be allocated.  The caller must deallocate
114 * the return value.
115 */
116extern char *_xattrNameWithoutProperties(const char *);
117
118/*
119 * Given an EA name, return the properties.  If the name is in the internal list,
120 * those properties will be returned.  Unknown property encodings are ignored.
121 */
122extern CopyOperationProperties_t _xattrPropertiesFromName(const char *);
123
124__END_DECLS
125
126#endif /* _XATTR_PROPERTIES_H */
127