1 .\" Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 .\" The contents of this file constitute Original Code as defined in and
4 .\" are subject to the Apple Public Source License Version 1.1 (the
5 .\" "License"). You may not use this file except in compliance with the
6 .\" License. Please obtain a copy of the License at
7 .\" http://www.apple.com/publicsource and read it before using this file.
9 .\" This Original Code and all software distributed under the License are
10 .\" distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
11 .\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
12 .\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
13 .\" FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
14 .\" License for the specific language governing rights and limitations
15 .\" under the License.
17 .\" @(#)exchangedata.2
24 .Nd atomically exchange data between two files
26 .Fd #include <unistd.h>
27 .Fd #include <sys/attr.h>
29 .Fn exchangedata "const char * path1" "const char * path2" "unsigned int options"
34 function swaps the contents of the files referenced by
39 That is, all concurrent processes will either see the pre-exchanged state or the
40 post-exchanged state; they can never see the files in an inconsistent state.
41 The data in all forks is swapped in this way.
44 parameter lets you control specific aspects of the function's behaviour.
47 Open file descriptors follow the swapped data.
48 Thus, a descriptor that previously referenced
50 will now reference the data that's accessible via
55 In general, the file attributes (metadata) are not exchanged.
56 Specifically, the object identifier attributes (that is, the
59 .Dv ATTR_CMN_OBJPERMANENTID
60 attributes as defined by the
62 function) are not swapped.
63 An exception to this general rule is that the modification time attribute (
68 When combined, these features allow you to implement a 'safe save' function that
69 does not break references to the file (for example, aliases).
70 You first save the new contents to a temporary file and then
71 exchange the data of the original file and the temporary.
72 Programs that reference the file via an object identifier will continue to
73 reference the original file, but now it has the new data.
76 WARNING: This system call is largely supported only by HFS and AFP file systems. Many other
77 file systems, including APFS, do not support it. Further, it is not supported on iOS, tvOS, or watchOS.
78 It is recommended that callers refer
83 to conduct safe-save operations instead.
86 .\" path1 and path2 parameters
92 parameters must both reference valid files.
93 All directories listed in the path names leading to these files must be
95 You must have write access to the files.
102 parameter is a bit set that controls the behaviour of
104 The following option bits are defined.
106 .Bl -tag -width FSOPT_NOFOLLOW
111 will not follow a symlink if it occurs as
112 the last component of
120 Upon successful completion a value of 0 is returned.
121 Otherwise, a value of -1 is returned and
123 is set to indicate the error.
126 Not all volumes support
128 This includes APFS volumes.
129 You can test whether a volume supports
133 to get the volume capabilities attribute
134 .Dv ATTR_VOL_CAPABILITIES ,
136 .Dv VOL_CAP_INT_EXCHANGEDATA
146 The volume does not support
150 A component of the path prefix is not a directory.
152 .It Bq Er ENAMETOOLONG
153 A component of a path name exceeded
155 characters, or an entire path name exceeded
160 Either file does not exist.
163 Search permission is denied for a component of the path prefix.
166 Too many symbolic links were encountered in translating the pathname.
172 points to an invalid address.
178 are on different volumes (mounted file systems).
184 reference the same file.
187 You try to exchange something other than a regular file (for example, a directory).
190 An I/O error occurred while reading from or writing to the file system.
202 function call appeared in Darwin 1.3.1 (Mac OS X version 10.0).
204 It was deprecated in macOS 10.13.