]> git.saurik.com Git - apple/xnu.git/blob - bsd/man/man2/exchangedata.2
xnu-792.22.5.tar.gz
[apple/xnu.git] / bsd / man / man2 / exchangedata.2
1 .\" Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
2 .\"
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.
8 .\"
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.
16 .\"
17 .\" @(#)exchangedata.2
18 .
19 .Dd December 15, 2003
20 .Dt EXCHANGEDATA 2
21 .Os Darwin
22 .Sh NAME
23 .Nm exchangedata
24 .Nd atomically exchange data between two files
25 .Sh SYNOPSIS
26 .Fd #include <unistd.h>
27 .Ft int
28 .Fn exchangedata "const char * path1" "const char * path2" "unsigned long options"
29 .
30 .Sh DESCRIPTION
31 The
32 .Fn exchangedata
33 function swaps the contents of the files referenced by
34 .Fa path1
35 and
36 .Fa path2
37 in an atomic fashion.
38 That is, all concurrent processes will either see the pre-exchanged state or the
39 post-exchanged state; they can never see the files in an inconsistent state.
40 The data in all forks is swapped in this way.
41 The
42 .Fa options
43 parameter lets you control specific aspects of the function's behaviour.
44 .Pp
45 .
46 Open file descriptors follow the swapped data.
47 Thus, a descriptor that previously referenced
48 .Fa path1
49 will now reference the data that's accessible via
50 .Fa path2 ,
51 and vice versa.
52 .Pp
53 .
54 In general, the file attributes (metadata) are not exchanged.
55 Specifically, the object identifier attributes (that is, the
56 .Dv ATTR_CMN_OBJID
57 and
58 .Dv ATTR_CMN_OBJPERMANENTID
59 attributes as defined by the
60 .Xr getattrlist 2
61 function) are not swapped.
62 An exception to this general rule is that the modification time attribute (
63 .Dv ATTR_CMN_MODTIME
64 ) is swapped.
65 .Pp
66 .
67 When combined, these features allow you to implement a 'safe save' function that
68 does not break references to the file (for example, aliases).
69 You first save the new contents to a temporary file and then
70 exchange the data of the original file and the temporary.
71 Programs that reference the file via an object identifier will continue to
72 reference the original file, but now it has the new data.
73 .Pp
74 .
75 .\" path1 and path2 parameters
76 .
77 The
78 .Fa path1
79 and
80 .Fa path2
81 parameters must both reference valid files.
82 All directories listed in the path names leading to these files must be
83 searchable.
84 You must have write access to the files.
85 .Pp
86 .
87 .\" options parameter
88 .
89 The
90 .Fa options
91 parameter is a bit set that controls the behaviour of
92 .Fn exchangedata .
93 The following option bits are defined.
94 .
95 .Bl -tag -width FSOPT_NOFOLLOW
96 .
97 .It FSOPT_NOFOLLOW
98 If this bit is set,
99 .Fn exchangedata
100 will not follow a symlink if it occurs as
101 the last component of
102 .Fa path1
103 or
104 .Fa path2 .
105 .
106 .El
107 .
108 .Sh RETURN VALUES
109 Upon successful completion a value of 0 is returned.
110 Otherwise, a value of -1 is returned and
111 .Va errno
112 is set to indicate the error.
113 .
114 .Sh COMPATIBILITY
115 Not all volumes support
116 .Fn exchangedata .
117 You can test whether a volume supports
118 .Fn exchangedata
119 by using
120 .Xr getattrlist 2
121 to get the volume capabilities attribute
122 .Dv ATTR_VOL_CAPABILITIES ,
123 and then testing the
124 .Dv VOL_CAP_INT_EXCHANGEDATA
125 flag.
126 .Pp
127 .
128 .Sh ERRORS
129 .Fn exchangedata
130 will fail if:
131 .Bl -tag -width Er
132 .
133 .It Bq Er ENOTSUP
134 The volume does not support
135 .Fn exchangedata .
136 .
137 .It Bq Er ENOTDIR
138 A component of the path prefix is not a directory.
139 .
140 .It Bq Er ENAMETOOLONG
141 A component of a path name exceeded
142 .Dv NAME_MAX
143 characters, or an entire path name exceeded
144 .Dv PATH_MAX
145 characters.
146 .
147 .It Bq Er ENOENT
148 Either file does not exist.
149 .
150 .It Bq Er EACCES
151 Search permission is denied for a component of the path prefix.
152 .
153 .It Bq Er ELOOP
154 Too many symbolic links were encountered in translating the pathname.
155 .
156 .It Bq Er EFAULT
157 .Fa path1
158 or
159 .Em path2
160 points to an invalid address.
161 .
162 .It Bq Er EXDEV
163 .Fa path1
164 and
165 .Em path2
166 are on different volumes (mounted file systems).
167 .
168 .It Bq Er EINVAL
169 .Fa path1
170 or
171 .Em path2
172 reference the same file.
173 .
174 .It Bq Er EINVAL
175 You try to exchange something other than a regular file (for example, a directory).
176 .
177 .It Bq Er EIO
178 An I/O error occurred while reading from or writing to the file system.
179 .El
180 .Pp
181 .
182 .Sh SEE ALSO
183 .
184 .Xr getattrlist 2
185 .
186 .Sh HISTORY
187 A
188 .Fn exchangedata
189 function call appeared in Darwin 1.3.1 (Mac OS X version 10.0).
190 .