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