summaryrefslogtreecommitdiff
path: root/archivers/libarchive/files/doc/html/archive_write_disk.3.html
blob: 2b909b008c2f7d88d981f4fc24400269cd863b65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
<!-- Creator     : groff version 1.22.3 -->
<!-- CreationDate: Sat Feb 25 11:22:05 2017 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta name="generator" content="groff -Thtml, see www.gnu.org">
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="Content-Style" content="text/css">
<style type="text/css">
       p       { margin-top: 0; margin-bottom: 0; vertical-align: top }
       pre     { margin-top: 0; margin-bottom: 0; vertical-align: top }
       table   { margin-top: 0; margin-bottom: 0; vertical-align: top }
       h1      { text-align: center }
</style>
<title></title>
</head>
<body>

<hr>


<p>ARCHIVE_WRITE_DISK(3) BSD Library Functions Manual
ARCHIVE_WRITE_DISK(3)</p>

<p style="margin-top: 1em"><b>NAME</b></p>

<p style="margin-left:6%;"><b>archive_write_disk_new</b>,
<b>archive_write_disk_set_options</b>,
<b>archive_write_disk_set_skip_file</b>,
<b>archive_write_disk_set_group_lookup</b>,
<b>archive_write_disk_set_standard_lookup</b>,
<b>archive_write_disk_set_user_lookup</b>,
<b>archive_write_header</b>, <b>archive_write_data</b>,
<b>archive_write_data_block</b>,
<b>archive_write_finish_entry</b>,
<b>archive_write_close</b>, <b>archive_write_finish
archive_write_free</b> &mdash; functions for creating
objects on disk</p>

<p style="margin-top: 1em"><b>LIBRARY</b></p>

<p style="margin-left:6%;">Streaming Archive Library
(libarchive, -larchive)</p>

<p style="margin-top: 1em"><b>SYNOPSIS</b></p>

<p style="margin-left:6%;"><b>#include
&lt;archive.h&gt;</b></p>

<p style="margin-left:6%; margin-top: 1em"><i>struct
archive *</i></p>


<p style="margin-left:12%;"><b>archive_write_disk_new</b>(<i>void</i>);</p>

<p style="margin-left:6%; margin-top: 1em"><i>int</i></p>


<p style="margin-left:12%;"><b>archive_write_disk_set_options</b>(<i>struct&nbsp;archive&nbsp;*</i>,
<i>int&nbsp;flags</i>);</p>

<p style="margin-left:6%; margin-top: 1em"><i>int</i></p>


<p style="margin-left:12%;"><b>archive_write_disk_set_skip_file</b>(<i>struct&nbsp;archive&nbsp;*</i>,
<i>dev_t</i>, <i>ino_t</i>);</p>

<p style="margin-left:6%; margin-top: 1em"><i>int</i></p>


<p><b>archive_write_disk_set_group_lookup</b>(<i>struct&nbsp;archive&nbsp;*</i>,
<i>void&nbsp;*</i>,
<i>gid_t&nbsp;(*)(void&nbsp;*,&nbsp;const&nbsp;char&nbsp;*gname,&nbsp;gid_t&nbsp;gid)</i>,
<i>void&nbsp;(*cleanup)(void&nbsp;*)</i>);</p>

<p style="margin-left:6%; margin-top: 1em"><i>int</i></p>


<p style="margin-left:12%;"><b>archive_write_disk_set_standard_lookup</b>(<i>struct&nbsp;archive&nbsp;*</i>);</p>

<p style="margin-left:6%; margin-top: 1em"><i>int</i></p>


<p><b>archive_write_disk_set_user_lookup</b>(<i>struct&nbsp;archive&nbsp;*</i>,
<i>void&nbsp;*</i>,
<i>uid_t&nbsp;(*)(void&nbsp;*,&nbsp;const&nbsp;char&nbsp;*uname,&nbsp;uid_t&nbsp;uid)</i>,
<i>void&nbsp;(*cleanup)(void&nbsp;*)</i>);</p>

<p style="margin-left:6%; margin-top: 1em"><i>int</i></p>


<p style="margin-left:12%;"><b>archive_write_header</b>(<i>struct&nbsp;archive&nbsp;*</i>,
<i>struct&nbsp;archive_entry&nbsp;*</i>);</p>


<p style="margin-left:6%; margin-top: 1em"><i>la_ssize_t</i></p>


<p style="margin-left:12%;"><b>archive_write_data</b>(<i>struct&nbsp;archive&nbsp;*</i>,
<i>const&nbsp;void&nbsp;*</i>, <i>size_t</i>);</p>


<p style="margin-left:6%; margin-top: 1em"><i>la_ssize_t</i></p>


<p style="margin-left:12%;"><b>archive_write_data_block</b>(<i>struct&nbsp;archive&nbsp;*</i>,
<i>const&nbsp;void&nbsp;*</i>, <i>size_t&nbsp;size</i>,
<i>int64_t&nbsp;offset</i>);</p>

<p style="margin-left:6%; margin-top: 1em"><i>int</i></p>


<p style="margin-left:12%;"><b>archive_write_finish_entry</b>(<i>struct&nbsp;archive&nbsp;*</i>);</p>

<p style="margin-left:6%; margin-top: 1em"><i>int</i></p>


<p style="margin-left:12%;"><b>archive_write_close</b>(<i>struct&nbsp;archive&nbsp;*</i>);</p>

<p style="margin-left:6%; margin-top: 1em"><i>int</i></p>


<p style="margin-left:12%;"><b>archive_write_finish</b>(<i>struct&nbsp;archive&nbsp;*</i>);</p>

<p style="margin-left:6%; margin-top: 1em"><i>int</i></p>


<p style="margin-left:12%;"><b>archive_write_free</b>(<i>struct&nbsp;archive&nbsp;*</i>);</p>

<p style="margin-top: 1em"><b>DESCRIPTION</b></p>

<p style="margin-left:6%;">These functions provide a
complete API for creating objects on disk from struct
archive_entry descriptions. They are most naturally used
when extracting objects from an archive using the
<b>archive_read</b>() interface. The general process is to
read struct archive_entry objects from an archive, then
write those objects to a struct archive object created using
the <b>archive_write_disk</b>() family functions. This
interface is deliberately very similar to the
<b>archive_write</b>() interface used to write objects to a
streaming archive.</p>


<p style="margin-top: 1em"><b>archive_write_disk_new</b>()</p>

<p style="margin-left:17%;">Allocates and initializes a
struct archive object suitable for writing objects to
disk.</p>


<p style="margin-top: 1em"><b>archive_write_disk_set_skip_file</b>()</p>

<p style="margin-left:17%;">Records the device and inode
numbers of a file that should not be overwritten. This is
typically used to ensure that an extraction process does not
overwrite the archive from which objects are being read.
This capability is technically unnecessary but can be a
significant performance optimization in practice.</p>


<p style="margin-top: 1em"><b>archive_write_disk_set_options</b>()</p>

<p style="margin-left:17%;">The options field consists of a
bitwise OR of one or more of the following values:</p>

<p><b>ARCHIVE_EXTRACT_OWNER</b></p>

<p style="margin-left:27%;">The user and group IDs should
be set on the restored file. By default, the user and group
IDs are not restored.</p>

<p><b>ARCHIVE_EXTRACT_PERM</b></p>

<p style="margin-left:27%;">Full permissions (including
SGID, SUID, and sticky bits) should be restored exactly as
specified, without obeying the current umask. Note that SUID
and SGID bits can only be restored if the user and group ID
of the object on disk are correct. If
<b>ARCHIVE_EXTRACT_OWNER</b> is not specified, then SUID and
SGID bits will only be restored if the default user and
group IDs of newly-created objects on disk happen to match
those specified in the archive entry. By default, only basic
permissions are restored, and umask is obeyed.</p>

<p><b>ARCHIVE_EXTRACT_TIME</b></p>

<p style="margin-left:27%;">The timestamps (mtime, ctime,
and atime) should be restored. By default, they are ignored.
Note that restoring of atime is not currently supported.</p>

<p><b>ARCHIVE_EXTRACT_NO_OVERWRITE</b></p>

<p style="margin-left:27%;">Existing files on disk will not
be overwritten. By default, existing regular files are
truncated and overwritten; existing directories will have
their permissions updated; other pre-existing objects are
unlinked and recreated from scratch.</p>

<p><b>ARCHIVE_EXTRACT_UNLINK</b></p>

<p style="margin-left:27%;">Existing files on disk will be
unlinked before any attempt to create them. In some cases,
this can prove to be a significant performance improvement.
By default, existing files are truncated and rewritten, but
the file is not recreated. In particular, the default
behavior does not break existing hard links.</p>

<p><b>ARCHIVE_EXTRACT_ACL</b></p>

<p style="margin-left:27%;">Attempt to restore ACLs. By
default, extended ACLs are ignored.</p>

<p><b>ARCHIVE_EXTRACT_FFLAGS</b></p>

<p style="margin-left:27%;">Attempt to restore extended
file flags. By default, file flags are ignored.</p>

<p><b>ARCHIVE_EXTRACT_XATTR</b></p>

<p style="margin-left:27%;">Attempt to restore POSIX.1e
extended attributes. By default, they are ignored.</p>

<p><b>ARCHIVE_EXTRACT_SECURE_SYMLINKS</b></p>

<p style="margin-left:27%;">Refuse to extract any object
whose final location would be altered by a symlink on disk.
This is intended to help guard against a variety of mischief
caused by archives that (deliberately or otherwise) extract
files outside of the current directory. The default is not
to perform this check. If <b>ARCHIVE_EXTRACT_UNLINK</b> is
specified together with this option, the library will remove
any intermediate symlinks it finds and return an error only
if such symlink could not be removed.</p>

<p><b>ARCHIVE_EXTRACT_SECURE_NODOTDOT</b></p>

<p style="margin-left:27%;">Refuse to extract a path that
contains a <i>..</i> element anywhere within it. The default
is to not refuse such paths. Note that paths ending in
<i>..</i> always cause an error, regardless of this
flag.</p>

<p><b>ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS</b></p>

<p style="margin-left:27%;">Refuse to extract an absolute
path. The default is to not refuse such paths.</p>

<p><b>ARCHIVE_EXTRACT_SPARSE</b></p>

<p style="margin-left:27%;">Scan data for blocks of NUL
bytes and try to recreate them with holes. This results in
sparse files, independent of whether the archive format
supports or uses them.</p>

<p><b>ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS</b></p>

<p style="margin-left:27%;">Before removing a file system
object prior to replacing it, clear platform-specific file
flags which might prevent its removal.</p>


<p style="margin-top: 1em"><b>archive_write_disk_set_group_lookup</b>(),
<b>archive_write_disk_set_user_lookup</b>()</p>

<p style="margin-left:17%;">The struct archive_entry
objects contain both names and ids that can be used to
identify users and groups. These names and ids describe the
ownership of the file itself and also appear in ACL lists.
By default, the library uses the ids and ignores the names,
but this can be overridden by registering user and group
lookup functions. To register, you must provide a lookup
function which accepts both a name and id and returns a
suitable id. You may also provide a void * pointer to a
private data structure and a cleanup function for that data.
The cleanup function will be invoked when the struct archive
object is destroyed.</p>


<p style="margin-top: 1em"><b>archive_write_disk_set_standard_lookup</b>()</p>

<p style="margin-left:17%;">This convenience function
installs a standard set of user and group lookup functions.
These functions use getpwnam(3) and getgrnam(3) to convert
names to ids, defaulting to the ids if the names cannot be
looked up. These functions also implement a simple memory
cache to reduce the number of calls to getpwnam(3) and
getgrnam(3).</p>


<p style="margin-top: 1em"><b>archive_write_header</b>()</p>

<p style="margin-left:17%;">Build and write a header using
the data in the provided struct archive_entry structure. See
archive_entry(3) for information on creating and populating
struct archive_entry objects.</p>

<p style="margin-top: 1em"><b>archive_write_data</b>()</p>

<p style="margin-left:17%;">Write data corresponding to the
header just written. Returns number of bytes written or -1
on error.</p>


<p style="margin-top: 1em"><b>archive_write_data_block</b>()</p>

<p style="margin-left:17%;">Write data corresponding to the
header just written. This is like
<b>archive_write_data</b>() except that it performs a seek
on the file being written to the specified offset before
writing the data. This is useful when restoring sparse files
from archive formats that support sparse files. Returns
number of bytes written or -1 on error. (Note: This is
currently not supported for archive_write handles, only for
archive_write_disk handles.)</p>


<p style="margin-top: 1em"><b>archive_write_finish_entry</b>()</p>

<p style="margin-left:17%;">Close out the entry just
written. Ordinarily, clients never need to call this, as it
is called automatically by
<b>archive_write_next_header</b>() and
<b>archive_write_close</b>() as needed. However, some file
attributes are written to disk only after the file is
closed, so this can be necessary if you need to work with
the file on disk right away.</p>


<p style="margin-top: 1em"><b>archive_write_close</b>()</p>

<p style="margin-left:17%;">Set any attributes that could
not be set during the initial restore. For example,
directory timestamps are not restored initially because
restoring a subsequent file would alter that timestamp.
Similarly, non-writable directories are initially created
with write permissions (so that their contents can be
restored). The <b>archive_write_disk_new</b> library
maintains a list of all such deferred attributes and sets
them when this function is invoked.</p>


<p style="margin-top: 1em"><b>archive_write_finish</b>()</p>

<p style="margin-left:17%;">This is a deprecated synonym
for <b>archive_write_free</b>().</p>

<p style="margin-top: 1em"><b>archive_write_free</b>()</p>

<p style="margin-left:17%;">Invokes
<b>archive_write_close</b>() if it was not invoked manually,
then releases all resources.</p>

<p style="margin-left:6%;">More information about the
<i>struct archive</i> object and the overall design of the
library can be found in the libarchive(3) overview. Many of
these functions are also documented under
archive_write(3).</p>

<p style="margin-top: 1em"><b>RETURN VALUES</b></p>

<p style="margin-left:6%;">Most functions return
<b>ARCHIVE_OK</b> (zero) on success, or one of several
non-zero error codes for errors. Specific error codes
include: <b>ARCHIVE_RETRY</b> for operations that might
succeed if retried, <b>ARCHIVE_WARN</b> for unusual
conditions that do not prevent further operations, and
<b>ARCHIVE_FATAL</b> for serious errors that make remaining
operations impossible.</p>


<p style="margin-left:6%; margin-top: 1em"><b>archive_write_disk_new</b>()
returns a pointer to a newly-allocated struct archive
object.</p>


<p style="margin-left:6%; margin-top: 1em"><b>archive_write_data</b>()
returns a count of the number of bytes actually written, or
-1 on error.</p>

<p style="margin-top: 1em"><b>ERRORS</b></p>

<p style="margin-left:6%;">Detailed error codes and textual
descriptions are available from the <b>archive_errno</b>()
and <b>archive_error_string</b>() functions.</p>

<p style="margin-top: 1em"><b>SEE ALSO</b></p>

<p style="margin-left:6%;">archive_read(3),
archive_write(3), tar(1), libarchive(3)</p>

<p style="margin-top: 1em"><b>HISTORY</b></p>

<p style="margin-left:6%;">The <b>libarchive</b> library
first appeared in FreeBSD&nbsp;5.3. The
<b>archive_write_disk</b> interface was added to
<b>libarchive 2.0</b> and first appeared in
FreeBSD&nbsp;6.3.</p>

<p style="margin-top: 1em"><b>AUTHORS</b></p>

<p style="margin-left:6%;">The <b>libarchive</b> library
was written by Tim Kientzle &lt;kientzle@acm.org&gt;.</p>

<p style="margin-top: 1em"><b>BUGS</b></p>

<p style="margin-left:6%;">Directories are actually
extracted in two distinct phases. Directories are created
during <b>archive_write_header</b>(), but final permissions
are not set until <b>archive_write_close</b>(). This
separation is necessary to correctly handle borderline cases
such as a non-writable directory containing files, but can
cause unexpected results. In particular, directory
permissions are not fully restored until the archive is
closed. If you use chdir(2) to change the current directory
between calls to <b>archive_read_extract</b>() or before
calling <b>archive_read_close</b>(), you may confuse the
permission-setting logic with the result that directory
permissions are restored incorrectly.</p>

<p style="margin-left:6%; margin-top: 1em">The library
attempts to create objects with filenames longer than
<b>PATH_MAX</b> by creating prefixes of the full path and
changing the current directory. Currently, this logic is
limited in scope; the fixup pass does not work correctly for
such objects and the symlink security check option disables
the support for very long pathnames.</p>

<p style="margin-left:6%; margin-top: 1em">Restoring the
path <i>aa/../bb</i> does create each intermediate
directory. In particular, the directory <i>aa</i> is created
as well as the final object <i>bb</i>. In theory, this can
be exploited to create an entire directory hierarchy with a
single request. Of course, this does not work if the
<b>ARCHIVE_EXTRACT_NODOTDOT</b> option is specified.</p>

<p style="margin-left:6%; margin-top: 1em">Implicit
directories are always created obeying the current umask.
Explicit objects are created obeying the current umask
unless <b>ARCHIVE_EXTRACT_PERM</b> is specified, in which
case they current umask is ignored.</p>

<p style="margin-left:6%; margin-top: 1em">SGID and SUID
bits are restored only if the correct user and group could
be set. If <b>ARCHIVE_EXTRACT_OWNER</b> is not specified,
then no attempt is made to set the ownership. In this case,
SGID and SUID bits are restored only if the user and group
of the final object happen to match those specified in the
entry.</p>

<p style="margin-left:6%; margin-top: 1em">The
&lsquo;&lsquo;standard&rsquo;&rsquo; user-id and group-id
lookup functions are not the defaults because getgrnam(3)
and getpwnam(3) are sometimes too large for particular
applications. The current design allows the application
author to use a more compact implementation when
appropriate.</p>

<p style="margin-left:6%; margin-top: 1em">There should be
a corresponding <b>archive_read_disk</b> interface that
walks a directory hierarchy and returns archive entry
objects.</p>

<p style="margin-left:6%; margin-top: 1em">BSD
February&nbsp;2, 2012 BSD</p>
<hr>
</body>
</html>