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