master
1/*
2 * Copyright (c) 2004-2023 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#ifndef _COPYFILE_H_ /* version 0.1 */
24#define _COPYFILE_H_
25
26/*
27 * This API facilitates the copying of files and their associated
28 * metadata. There are several open source projects that need
29 * modifications to support preserving extended attributes and ACLs
30 * and this API collapses several hundred lines of modifications into
31 * one or two calls.
32 */
33
34/* private */
35#include <sys/cdefs.h>
36#include <stdint.h>
37
38__BEGIN_DECLS
39__ptrcheck_abi_assume_single()
40struct _copyfile_state;
41typedef struct _copyfile_state * copyfile_state_t;
42typedef uint32_t copyfile_flags_t;
43
44/* public */
45
46/* receives:
47 * from path to source file system object
48 * to path to destination file system object
49 * state opaque blob for future extensibility
50 * Must be NULL in current implementation
51 * flags (described below)
52 * returns:
53 * int negative for error
54 */
55
56int copyfile(const char *__unsafe_indexable from, const char *__unsafe_indexable to, copyfile_state_t state, copyfile_flags_t flags);
57int fcopyfile(int from_fd, int to_fd, copyfile_state_t, copyfile_flags_t flags);
58
59int copyfile_state_free(copyfile_state_t);
60copyfile_state_t copyfile_state_alloc(void);
61
62
63int copyfile_state_get(copyfile_state_t s, uint32_t flag, void * dst);
64int copyfile_state_set(copyfile_state_t s, uint32_t flag, const void * src);
65
66typedef int (*copyfile_callback_t)(int, int, copyfile_state_t, const char *__unsafe_indexable, const char *__unsafe_indexable, void *);
67
68#define COPYFILE_STATE_SRC_FD 1
69#define COPYFILE_STATE_SRC_FILENAME 2
70#define COPYFILE_STATE_DST_FD 3
71#define COPYFILE_STATE_DST_FILENAME 4
72#define COPYFILE_STATE_QUARANTINE 5
73#define COPYFILE_STATE_STATUS_CB 6
74#define COPYFILE_STATE_STATUS_CTX 7
75#define COPYFILE_STATE_COPIED 8
76#define COPYFILE_STATE_XATTRNAME 9
77#define COPYFILE_STATE_WAS_CLONED 10
78#define COPYFILE_STATE_SRC_BSIZE 11
79#define COPYFILE_STATE_DST_BSIZE 12
80#define COPYFILE_STATE_BSIZE 13
81#define COPYFILE_STATE_FORBID_CROSS_MOUNT 14
82#define COPYFILE_STATE_NOCPROTECT 15
83#define COPYFILE_STATE_PRESERVE_SUID 16
84#define COPYFILE_STATE_RECURSIVE_SRC_FTSENT 17
85#define COPYFILE_STATE_FORBID_DST_EXISTING_SYMLINKS 18
86
87
88#define COPYFILE_DISABLE_VAR "COPYFILE_DISABLE"
89
90/* flags for copyfile */
91
92#define COPYFILE_ACL (1<<0)
93#define COPYFILE_STAT (1<<1)
94#define COPYFILE_XATTR (1<<2)
95#define COPYFILE_DATA (1<<3)
96
97#define COPYFILE_SECURITY (COPYFILE_STAT | COPYFILE_ACL)
98#define COPYFILE_METADATA (COPYFILE_SECURITY | COPYFILE_XATTR)
99#define COPYFILE_ALL (COPYFILE_METADATA | COPYFILE_DATA)
100
101#define COPYFILE_RECURSIVE (1<<15) /* Descend into hierarchies */
102#define COPYFILE_CHECK (1<<16) /* return flags for xattr or acls if set */
103#define COPYFILE_EXCL (1<<17) /* fail if destination exists */
104#define COPYFILE_NOFOLLOW_SRC (1<<18) /* don't follow if source is a symlink */
105#define COPYFILE_NOFOLLOW_DST (1<<19) /* don't follow if dst is a symlink */
106#define COPYFILE_MOVE (1<<20) /* unlink src after copy */
107#define COPYFILE_UNLINK (1<<21) /* unlink dst before copy */
108#define COPYFILE_NOFOLLOW (COPYFILE_NOFOLLOW_SRC | COPYFILE_NOFOLLOW_DST)
109
110#define COPYFILE_PACK (1<<22)
111#define COPYFILE_UNPACK (1<<23)
112
113#define COPYFILE_CLONE (1<<24)
114#define COPYFILE_CLONE_FORCE (1<<25)
115
116#define COPYFILE_RUN_IN_PLACE (1<<26)
117
118#define COPYFILE_DATA_SPARSE (1<<27)
119
120#define COPYFILE_PRESERVE_DST_TRACKED (1<<28)
121
122#define COPYFILE_VERBOSE (1<<30)
123
124#define COPYFILE_RECURSE_ERROR 0
125#define COPYFILE_RECURSE_FILE 1
126#define COPYFILE_RECURSE_DIR 2
127#define COPYFILE_RECURSE_DIR_CLEANUP 3
128#define COPYFILE_COPY_DATA 4
129#define COPYFILE_COPY_XATTR 5
130
131#define COPYFILE_START 1
132#define COPYFILE_FINISH 2
133#define COPYFILE_ERR 3
134#define COPYFILE_PROGRESS 4
135
136#define COPYFILE_CONTINUE 0
137#define COPYFILE_SKIP 1
138#define COPYFILE_QUIT 2
139
140__END_DECLS
141
142#endif /* _COPYFILE_H_ */