2 .\" Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
8 .Nm copyfile , fcopyfile ,
9 .Nm copyfile_state_alloc , copyfile_state_free ,
10 .Nm copyfile_state_get , copyfile_state_set
17 .Fn copyfile "const char *from" "const char *to" "copyfile_state_t state" "copyfile_flags_t flags"
19 .Fn fcopyfile "int from" "int to" "copyfile_state_t state" "copyfile_flags_t flags"
21 .Fn copyfile_state_alloc "void"
23 .Fn copyfile_state_free "copyfile_state_t state"
25 .Fn copyfile_state_get "copyfile_state_t state" "uint32_t flag" "void * dst"
27 .Fn copyfile_state_set "copyfile_state_t state" "uint32_t flag" "const void * src"
29 These functions are used to copy a file's data and/or metadata. (Metadata
30 consists of permissions, extended attributes, access control lists, and so
34 .Fn copyfile_state_alloc
35 function initializes a
37 object (which is an opaque data type).
38 This object can be passed to
42 .Fn copyfile_state_get
44 .Fn copyfile_state_set
45 can be used to manipulate the state (see below).
47 .Fn copyfile_state_free
48 function is used to deallocate the object and its contents.
52 function can copy the named
58 function does the same, but using the file descriptors of already-opened
62 parameter is the return value from
63 .Fn copyfile_state_alloc ,
68 will use the information from the state object; if it is
70 then both functions will work normally, but less control will be available to the caller.
73 parameter controls which contents are copied:
74 .Bl -tag -width COPYFILE_XATTR
76 Copy the source file's access control lists.
78 Copy the source file's POSIX information (mode, modification time, etc.).
80 Copy the source file's extended attributes.
82 Copy the source file's data.
85 These values may be or'd together; several convenience macros are provided:
86 .Bl -tag -width COPYFILE_SECURITY
87 .It Dv COPYFILE_SECURITY
88 Copy the source file's POSIX and ACL information; equivalent to
89 .Dv (COPYFILE_STAT|COPYFILE_ACL) .
90 .It Dv COPYFILE_METADATA
91 Copy the metadata; equivalent to
92 .Dv (COPYFILE_SECURITY|COPYFILE_XATTR) .
94 Copy the entire file; equivalent to
95 .Dv (COPYFILE_METADATA|COPYFILE_DATA) .
102 functions can also have their behavior modified by the following flags:
103 .Bl -tag -width COPYFILE_NOFOLLOW_SRC
104 .It Dv COPYFILE_CHECK
105 Return a bitmask (corresponding to the
107 argument) indicating which contents would be copied; no data are actually
111 .Dv COPYFILE_CHECK|COPYFILE_METADATA ,
114 file had extended attributes but no ACLs, the return value would be
115 .Dv COPYFILE_XATTR .)
121 file is an AppleDouble-format file.
122 .It Dv COPYFILE_UNPACK
127 file is an AppleDouble-format file; the
129 file will have the extended attributes, ACLs, resource fork, and
130 FinderInfo data from the
132 file, regardless of the
138 file already exists. (This is only applicable for the
141 .It Dv COPYFILE_NOFOLLOW_SRC
144 file, if it is a symbolic link. (This is only applicable for the
147 .It Dv COPYFILE_NOFOLLOW_DST
150 file, if it is a symbolic link. (This is only applicable for the
156 file. (This is only applicable for the
159 .It Dv COPYFILE_UNLINK
162 file before starting. (This is only applicable for the
165 .It Dv COPYFILE_NOFOLLOW
166 This is a convenience macro, equivalent to
167 .Dv (COPYFILE_NOFOLLOW_DST|COPYFILE_NOFOLLOW_SRC) .
171 .Fn copyfile_state_get
173 .Fn copyfile_state_set
174 functions can be used to manipulate the
177 .Fn copyfile_state_alloc .
178 In both functions, the
180 parameter's type depends on the
182 parameter that is passed in.
183 .Bl -tag -width COPYFILE_STATE_DST_FILENAME
184 .It Dv COPYFILE_STATE_SRC_FD
185 .It Dv COPYFILE_STATE_DST_FD
186 Get or set the file descriptor associated with the source (or destination)
188 If this has not been initialized yet, the value will be -2.
192 .Fn copyfile_state_get )
196 .Fn copyfile_state_set )
197 parameters are pointers to
199 .It Dv COPYFILE_STATE_SRC_FILENAME
200 .It Dv COPYFILE_STATE_DST_FILENAME
201 Get or set the filename associated with the source (or destination)
202 file. If it has not been initialized yet, the value will be
205 .Fn copyfile_state_set ,
208 parameter is a pointer to a C string
211 .Fn copyfile_state_set
212 makes a private copy of this string.
214 .Fn copyfile_state_get
217 parameter is a pointer to a pointer to a C string
220 the returned value is a pointer to the
222 copy, and must not be modified or released.
223 .It Dv COPYFILE_STATE_QUARANTINE
224 Get or set the quarantine information with the source file.
227 parameter is a pointer to a
230 .Pa <quarantine.h> ).
232 .Dv COPYFILE_STATE_SET ,
233 the object is cloned; in the case of
234 .Dv COPYFILE_STATE_GET ,
235 the object is simply returned, and it is up to the
236 caller to clone it if desired.
239 Except when given the
245 return less than 0 on error, and 0 on success.
246 All of the other functions return 0 on success, and less than 0
263 or a negative number (
266 A memory allocation failed.
268 The source file was not a directory, symbolic link, or regular file.
270 In addition, both functions may set
272 via an underlying library or system call.
274 .Bd -literal -offset indent
275 /* Initialize a state variable */
277 s = copyfile_state_alloc();
278 /* Copy the data and extended attributes of one file to another */
279 copyfile("/tmp/f1", "/tmp/f2", s, COPYFILE_DATA | COPYFILE_XATTR);
280 /* Convert a file to an AppleDouble file for serialization */
281 copyfile("/tmp/f2", "/tmp/tmpfile", NULL, COPYFILE_ALL | COPYFILE_PACK);
282 /* Release the state variable */
283 copyfile_state_free(s);
284 /* A more complex way to call copyfile() */
285 s = copyfile_state_alloc();
286 copyfile_state_set(s, COPYFILE_STATE_SRC_FILENAME, "/tmp/foo");
287 /* One of src or dst must be set... rest can come from the state */
288 copyfile(NULL, "/tmp/bar", s, COPYFILE_ALL);
289 /* Now copy the same source file to another destination file */
290 copyfile(NULL, "/tmp/car", s, COPYFILE_ALL);
291 copyfile_state_free(s);
296 functions lack a way to set the input or output block size.
300 API was introduced in Mac OS X 10.5.