]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/libarchive/libarchive/archive_write_disk.3
MFC r314571:
[FreeBSD/stable/10.git] / contrib / libarchive / libarchive / archive_write_disk.3
1 .\" Copyright (c) 2003-2007 Tim Kientzle
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 .\" SUCH DAMAGE.
24 .\"
25 .\" $FreeBSD$
26 .\"
27 .Dd February 28, 2017
28 .Dt ARCHIVE_WRITE_DISK 3
29 .Os
30 .Sh NAME
31 .Nm archive_write_disk_new ,
32 .Nm archive_write_disk_set_options ,
33 .Nm archive_write_disk_set_skip_file ,
34 .Nm archive_write_disk_set_group_lookup ,
35 .Nm archive_write_disk_set_standard_lookup ,
36 .Nm archive_write_disk_set_user_lookup
37 .Nd functions for creating objects on disk
38 .Sh LIBRARY
39 Streaming Archive Library (libarchive, -larchive)
40 .Sh SYNOPSIS
41 .In archive.h
42 .Ft struct archive *
43 .Fn archive_write_disk_new "void"
44 .Ft int
45 .Fn archive_write_disk_set_options "struct archive *" "int flags"
46 .Ft int
47 .Fn archive_write_disk_set_skip_file "struct archive *" "dev_t" "ino_t"
48 .Ft int
49 .Fo archive_write_disk_set_group_lookup
50 .Fa "struct archive *"
51 .Fa "void *"
52 .Fa "gid_t (*)(void *, const char *gname, gid_t gid)"
53 .Fa "void (*cleanup)(void *)"
54 .Fc
55 .Ft int
56 .Fn archive_write_disk_set_standard_lookup "struct archive *"
57 .Ft int
58 .Fo archive_write_disk_set_user_lookup
59 .Fa "struct archive *"
60 .Fa "void *"
61 .Fa "uid_t (*)(void *, const char *uname, uid_t uid)"
62 .Fa "void (*cleanup)(void *)"
63 .Fc
64 .Sh DESCRIPTION
65 These functions provide a complete API for creating objects on
66 disk from
67 .Tn struct archive_entry
68 descriptions.
69 They are most naturally used when extracting objects from an archive
70 using the
71 .Fn archive_read
72 interface.
73 The general process is to read
74 .Tn struct archive_entry
75 objects from an archive, then write those objects to a
76 .Tn struct archive
77 object created using the
78 .Fn archive_write_disk
79 family functions.
80 This interface is deliberately very similar to the
81 .Fn archive_write
82 interface used to write objects to a streaming archive.
83 .Bl -tag -width indent
84 .It Fn archive_write_disk_new
85 Allocates and initializes a
86 .Tn struct archive
87 object suitable for writing objects to disk.
88 .It Fn archive_write_disk_set_skip_file
89 Records the device and inode numbers of a file that should not be
90 overwritten.
91 This is typically used to ensure that an extraction process does not
92 overwrite the archive from which objects are being read.
93 This capability is technically unnecessary but can be a significant
94 performance optimization in practice.
95 .It Fn archive_write_disk_set_options
96 The options field consists of a bitwise OR of one or more of the
97 following values:
98 .Bl -tag -compact -width "indent"
99 .It Cm ARCHIVE_EXTRACT_OWNER
100 The user and group IDs should be set on the restored file.
101 By default, the user and group IDs are not restored.
102 .It Cm ARCHIVE_EXTRACT_PERM
103 Full permissions (including SGID, SUID, and sticky bits) should
104 be restored exactly as specified, without obeying the
105 current umask.
106 Note that SUID and SGID bits can only be restored if the
107 user and group ID of the object on disk are correct.
108 If
109 .Cm ARCHIVE_EXTRACT_OWNER
110 is not specified, then SUID and SGID bits will only be restored
111 if the default user and group IDs of newly-created objects on disk
112 happen to match those specified in the archive entry.
113 By default, only basic permissions are restored, and umask is obeyed.
114 .It Cm ARCHIVE_EXTRACT_TIME
115 The timestamps (mtime, ctime, and atime) should be restored.
116 By default, they are ignored.
117 Note that restoring of atime is not currently supported.
118 .It Cm ARCHIVE_EXTRACT_NO_OVERWRITE
119 Existing files on disk will not be overwritten.
120 By default, existing regular files are truncated and overwritten;
121 existing directories will have their permissions updated;
122 other pre-existing objects are unlinked and recreated from scratch.
123 .It Cm ARCHIVE_EXTRACT_UNLINK
124 Existing files on disk will be unlinked before any attempt to
125 create them.
126 In some cases, this can prove to be a significant performance improvement.
127 By default, existing files are truncated and rewritten, but
128 the file is not recreated.
129 In particular, the default behavior does not break existing hard links.
130 .It Cm ARCHIVE_EXTRACT_ACL
131 Attempt to restore ACLs.
132 By default, extended ACLs are ignored.
133 .It Cm ARCHIVE_EXTRACT_FFLAGS
134 Attempt to restore extended file flags.
135 By default, file flags are ignored.
136 .It Cm ARCHIVE_EXTRACT_XATTR
137 Attempt to restore POSIX.1e extended attributes.
138 By default, they are ignored.
139 .It Cm ARCHIVE_EXTRACT_SECURE_SYMLINKS
140 Refuse to extract any object whose final location would be altered
141 by a symlink on disk.
142 This is intended to help guard against a variety of mischief
143 caused by archives that (deliberately or otherwise) extract
144 files outside of the current directory.
145 The default is not to perform this check.
146 If
147 .Cm ARCHIVE_EXTRACT_UNLINK
148 is specified together with this option, the library will
149 remove any intermediate symlinks it finds and return an
150 error only if such symlink could not be removed.
151 .It Cm ARCHIVE_EXTRACT_SECURE_NODOTDOT
152 Refuse to extract a path that contains a
153 .Pa ..
154 element anywhere within it.
155 The default is to not refuse such paths.
156 Note that paths ending in
157 .Pa ..
158 always cause an error, regardless of this flag.
159 .It Cm ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS
160 Refuse to extract an absolute path.
161 The default is to not refuse such paths.
162 .It Cm ARCHIVE_EXTRACT_SPARSE
163 Scan data for blocks of NUL bytes and try to recreate them with holes.
164 This results in sparse files, independent of whether the archive format
165 supports or uses them.
166 .It Cm ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS
167 Before removing a file system object prior to replacing it, clear
168 platform-specific file flags which might prevent its removal.
169 .El
170 .It Xo
171 .Fn archive_write_disk_set_group_lookup ,
172 .Fn archive_write_disk_set_user_lookup
173 .Xc
174 The
175 .Tn struct archive_entry
176 objects contain both names and ids that can be used to identify users
177 and groups.
178 These names and ids describe the ownership of the file itself and
179 also appear in ACL lists.
180 By default, the library uses the ids and ignores the names, but
181 this can be overridden by registering user and group lookup functions.
182 To register, you must provide a lookup function which
183 accepts both a name and id and returns a suitable id.
184 You may also provide a
185 .Tn void *
186 pointer to a private data structure and a cleanup function for
187 that data.
188 The cleanup function will be invoked when the
189 .Tn struct archive
190 object is destroyed.
191 .It Fn archive_write_disk_set_standard_lookup
192 This convenience function installs a standard set of user
193 and group lookup functions.
194 These functions use
195 .Xr getpwnam 3
196 and
197 .Xr getgrnam 3
198 to convert names to ids, defaulting to the ids if the names cannot
199 be looked up.
200 These functions also implement a simple memory cache to reduce
201 the number of calls to
202 .Xr getpwnam 3
203 and
204 .Xr getgrnam 3 .
205 .El
206 More information about the
207 .Va struct archive
208 object and the overall design of the library can be found in the
209 .Xr libarchive 3
210 overview.
211 Many of these functions are also documented under
212 .Xr archive_write 3 .
213 .Sh RETURN VALUES
214 Most functions return
215 .Cm ARCHIVE_OK
216 (zero) on success, or one of several non-zero
217 error codes for errors.
218 Specific error codes include:
219 .Cm ARCHIVE_RETRY
220 for operations that might succeed if retried,
221 .Cm ARCHIVE_WARN
222 for unusual conditions that do not prevent further operations, and
223 .Cm ARCHIVE_FATAL
224 for serious errors that make remaining operations impossible.
225 .Pp
226 .Fn archive_write_disk_new
227 returns a pointer to a newly-allocated
228 .Tn struct archive
229 object.
230 .Pp
231 .Fn archive_write_data
232 returns a count of the number of bytes actually written,
233 or
234 .Li -1
235 on error.
236 .\"
237 .Sh ERRORS
238 Detailed error codes and textual descriptions are available from the
239 .Fn archive_errno
240 and
241 .Fn archive_error_string
242 functions.
243 .\"
244 .Sh SEE ALSO
245 .Xr archive_read 3 ,
246 .Xr archive_write 3 ,
247 .Xr tar 1 ,
248 .Xr libarchive 3
249 .Sh HISTORY
250 The
251 .Nm libarchive
252 library first appeared in
253 .Fx 5.3 .
254 The
255 .Nm archive_write_disk
256 interface was added to
257 .Nm libarchive 2.0
258 and first appeared in
259 .Fx 6.3 .
260 .Sh AUTHORS
261 .An -nosplit
262 The
263 .Nm libarchive
264 library was written by
265 .An Tim Kientzle Aq kientzle@acm.org .
266 .Sh BUGS
267 Directories are actually extracted in two distinct phases.
268 Directories are created during
269 .Fn archive_write_header ,
270 but final permissions are not set until
271 .Fn archive_write_close .
272 This separation is necessary to correctly handle borderline
273 cases such as a non-writable directory containing
274 files, but can cause unexpected results.
275 In particular, directory permissions are not fully
276 restored until the archive is closed.
277 If you use
278 .Xr chdir 2
279 to change the current directory between calls to
280 .Fn archive_read_extract
281 or before calling
282 .Fn archive_read_close ,
283 you may confuse the permission-setting logic with
284 the result that directory permissions are restored
285 incorrectly.
286 .Pp
287 The library attempts to create objects with filenames longer than
288 .Cm PATH_MAX
289 by creating prefixes of the full path and changing the current directory.
290 Currently, this logic is limited in scope; the fixup pass does
291 not work correctly for such objects and the symlink security check
292 option disables the support for very long pathnames.
293 .Pp
294 Restoring the path
295 .Pa aa/../bb
296 does create each intermediate directory.
297 In particular, the directory
298 .Pa aa
299 is created as well as the final object
300 .Pa bb .
301 In theory, this can be exploited to create an entire directory hierarchy
302 with a single request.
303 Of course, this does not work if the
304 .Cm ARCHIVE_EXTRACT_NODOTDOT
305 option is specified.
306 .Pp
307 Implicit directories are always created obeying the current umask.
308 Explicit objects are created obeying the current umask unless
309 .Cm ARCHIVE_EXTRACT_PERM
310 is specified, in which case they current umask is ignored.
311 .Pp
312 SGID and SUID bits are restored only if the correct user and
313 group could be set.
314 If
315 .Cm ARCHIVE_EXTRACT_OWNER
316 is not specified, then no attempt is made to set the ownership.
317 In this case, SGID and SUID bits are restored only if the
318 user and group of the final object happen to match those specified
319 in the entry.
320 .Pp
321 The
322 .Dq standard
323 user-id and group-id lookup functions are not the defaults because
324 .Xr getgrnam 3
325 and
326 .Xr getpwnam 3
327 are sometimes too large for particular applications.
328 The current design allows the application author to use a more
329 compact implementation when appropriate.
330 .Pp
331 There should be a corresponding
332 .Nm archive_read_disk
333 interface that walks a directory hierarchy and returns archive
334 entry objects.