]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/libarchive/libarchive/libarchive.3
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / libarchive / libarchive / libarchive.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 July 17, 2010
28 .Dt LIBARCHIVE 3
29 .Os
30 .Sh NAME
31 .Nm libarchive
32 .Nd functions for reading and writing streaming archives
33 .Sh LIBRARY
34 .Lb libarchive
35 .Sh OVERVIEW
36 The
37 .Nm
38 library provides a flexible interface for reading and writing
39 streaming archive files such as tar and cpio.
40 The library is inherently stream-oriented; readers serially iterate through
41 the archive, writers serially add things to the archive.
42 In particular, note that there is no built-in support for
43 random access nor for in-place modification.
44 .Pp
45 When reading an archive, the library automatically detects the
46 format and the compression.
47 The library currently has read support for:
48 .Bl -bullet -compact
49 .It
50 old-style tar archives,
51 .It
52 most variants of the POSIX
53 .Dq ustar
54 format,
55 .It
56 the POSIX
57 .Dq pax interchange
58 format,
59 .It
60 GNU-format tar archives,
61 .It
62 most common cpio archive formats,
63 .It
64 ISO9660 CD images (including RockRidge and Joliet extensions),
65 .It
66 Zip archives.
67 .El
68 The library automatically detects archives compressed with
69 .Xr gzip 1 ,
70 .Xr bzip2 1 ,
71 .Xr xz 1 ,
72 or
73 .Xr compress 1
74 and decompresses them transparently.
75 .Pp
76 When writing an archive, you can specify the compression
77 to be used and the format to use.
78 The library can write
79 .Bl -bullet -compact
80 .It
81 POSIX-standard
82 .Dq ustar
83 archives,
84 .It
85 POSIX
86 .Dq pax interchange format
87 archives,
88 .It
89 POSIX octet-oriented cpio archives,
90 .It
91 Zip archive,
92 .It
93 two different variants of shar archives.
94 .El
95 Pax interchange format is an extension of the tar archive format that
96 eliminates essentially all of the limitations of historic tar formats
97 in a standard fashion that is supported
98 by POSIX-compliant
99 .Xr pax 1
100 implementations on many systems as well as several newer implementations of
101 .Xr tar 1 .
102 Note that the default write format will suppress the pax extended
103 attributes for most entries; explicitly requesting pax format will
104 enable those attributes for all entries.
105 .Pp
106 The read and write APIs are accessed through the
107 .Fn archive_read_XXX
108 functions and the
109 .Fn archive_write_XXX
110 functions, respectively, and either can be used independently
111 of the other.
112 .Pp
113 The rest of this manual page provides an overview of the library
114 operation.
115 More detailed information can be found in the individual manual
116 pages for each API or utility function.
117 .Sh READING AN ARCHIVE
118 To read an archive, you must first obtain an initialized
119 .Tn struct archive
120 object from
121 .Fn archive_read_new .
122 You can then modify this object for the desired operations with the
123 various
124 .Fn archive_read_set_XXX
125 and
126 .Fn archive_read_support_XXX
127 functions.
128 In particular, you will need to invoke appropriate
129 .Fn archive_read_support_XXX
130 functions to enable the corresponding compression and format
131 support.
132 Note that these latter functions perform two distinct operations:
133 they cause the corresponding support code to be linked into your
134 program, and they enable the corresponding auto-detect code.
135 Unless you have specific constraints, you will generally want
136 to invoke
137 .Fn archive_read_support_compression_all
138 and
139 .Fn archive_read_support_format_all
140 to enable auto-detect for all formats and compression types
141 currently supported by the library.
142 .Pp
143 Once you have prepared the
144 .Tn struct archive
145 object, you call
146 .Fn archive_read_open
147 to actually open the archive and prepare it for reading.
148 There are several variants of this function;
149 the most basic expects you to provide pointers to several
150 functions that can provide blocks of bytes from the archive.
151 There are convenience forms that allow you to
152 specify a filename, file descriptor,
153 .Ft "FILE *"
154 object, or a block of memory from which to read the archive data.
155 Note that the core library makes no assumptions about the
156 size of the blocks read;
157 callback functions are free to read whatever block size is
158 most appropriate for the medium.
159 .Pp
160 Each archive entry consists of a header followed by a certain
161 amount of data.
162 You can obtain the next header with
163 .Fn archive_read_next_header ,
164 which returns a pointer to an
165 .Tn struct archive_entry
166 structure with information about the current archive element.
167 If the entry is a regular file, then the header will be followed
168 by the file data.
169 You can use
170 .Fn archive_read_data
171 (which works much like the
172 .Xr read 2
173 system call)
174 to read this data from the archive, or
175 .Fn archive_read_data_block
176 which provides a slightly more efficient interface.
177 You may prefer to use the higher-level
178 .Fn archive_read_data_skip ,
179 which reads and discards the data for this entry,
180 .Fn archive_read_data_to_file ,
181 which copies the data to the provided file descriptor, or
182 .Fn archive_read_extract ,
183 which recreates the specified entry on disk and copies data
184 from the archive.
185 In particular, note that
186 .Fn archive_read_extract
187 uses the
188 .Tn struct archive_entry
189 structure that you provide it, which may differ from the
190 entry just read from the archive.
191 In particular, many applications will want to override the
192 pathname, file permissions, or ownership.
193 .Pp
194 Once you have finished reading data from the archive, you
195 should call
196 .Fn archive_read_close
197 to close the archive, then call
198 .Fn archive_read_free
199 to release all resources, including all memory allocated by the library.
200 .Pp
201 The
202 .Xr archive_read 3
203 manual page provides more detailed calling information for this API.
204 .Sh WRITING AN ARCHIVE
205 You use a similar process to write an archive.
206 The
207 .Fn archive_write_new
208 function creates an archive object useful for writing,
209 the various
210 .Fn archive_write_set_XXX
211 functions are used to set parameters for writing the archive, and
212 .Fn archive_write_open
213 completes the setup and opens the archive for writing.
214 .Pp
215 Individual archive entries are written in a three-step
216 process:
217 You first initialize a
218 .Tn struct archive_entry
219 structure with information about the new entry.
220 At a minimum, you should set the pathname of the
221 entry and provide a
222 .Va struct stat
223 with a valid
224 .Va st_mode
225 field, which specifies the type of object and
226 .Va st_size
227 field, which specifies the size of the data portion of the object.
228 The
229 .Fn archive_write_header
230 function actually writes the header data to the archive.
231 You can then use
232 .Fn archive_write_data
233 to write the actual data.
234 .Pp
235 After all entries have been written, use the
236 .Fn archive_write_free
237 function to release all resources.
238 .Pp
239 The
240 .Xr archive_write 3
241 manual page provides more detailed calling information for this API.
242 .Sh WRITING ENTRIES TO DISK
243 The
244 .Xr archive_write_disk 3
245 API allows you to write
246 .Xr archive_entry 3
247 objects to disk using the same API used by
248 .Xr archive_write 3 .
249 The
250 .Xr archive_write_disk 3
251 API is used internally by
252 .Fn archive_read_extract ;
253 using it directly can provide greater control over how entries
254 get written to disk.
255 This API also makes it possible to share code between
256 archive-to-archive copy and archive-to-disk extraction
257 operations.
258 .Sh READING ENTRIES FROM DISK
259 The
260 .Xr archive_read_disk 3
261 provides some support for populating
262 .Xr archive_entry 3
263 objects from information in the filesystem.
264 .Sh DESCRIPTION
265 Detailed descriptions of each function are provided by the
266 corresponding manual pages.
267 .Pp
268 All of the functions utilize an opaque
269 .Tn struct archive
270 datatype that provides access to the archive contents.
271 .Pp
272 The
273 .Tn struct archive_entry
274 structure contains a complete description of a single archive
275 entry.
276 It uses an opaque interface that is fully documented in
277 .Xr archive_entry 3 .
278 .Pp
279 Users familiar with historic formats should be aware that the newer
280 variants have eliminated most restrictions on the length of textual fields.
281 Clients should not assume that filenames, link names, user names, or
282 group names are limited in length.
283 In particular, pax interchange format can easily accommodate pathnames
284 in arbitrary character sets that exceed
285 .Va PATH_MAX .
286 .Sh RETURN VALUES
287 Most functions return
288 .Cm ARCHIVE_OK
289 (zero) on success, non-zero on error.
290 The return value indicates the general severity of the error, ranging
291 from
292 .Cm ARCHIVE_WARN ,
293 which indicates a minor problem that should probably be reported
294 to the user, to
295 .Cm ARCHIVE_FATAL ,
296 which indicates a serious problem that will prevent any further
297 operations on this archive.
298 On error, the
299 .Fn archive_errno
300 function can be used to retrieve a numeric error code (see
301 .Xr errno 2 ) .
302 The
303 .Fn archive_error_string
304 returns a textual error message suitable for display.
305 .Pp
306 .Fn archive_read_new
307 and
308 .Fn archive_write_new
309 return pointers to an allocated and initialized
310 .Tn struct archive
311 object.
312 .Pp
313 .Fn archive_read_data
314 and
315 .Fn archive_write_data
316 return a count of the number of bytes actually read or written.
317 A value of zero indicates the end of the data for this entry.
318 A negative value indicates an error, in which case the
319 .Fn archive_errno
320 and
321 .Fn archive_error_string
322 functions can be used to obtain more information.
323 .Sh ENVIRONMENT
324 There are character set conversions within the
325 .Xr archive_entry 3
326 functions that are impacted by the currently-selected locale.
327 .Sh SEE ALSO
328 .Xr tar 1 ,
329 .Xr archive_entry 3 ,
330 .Xr archive_read 3 ,
331 .Xr archive_util 3 ,
332 .Xr archive_write 3 ,
333 .Xr tar 5
334 .Sh HISTORY
335 The
336 .Nm libarchive
337 library first appeared in
338 .Fx 5.3 .
339 .Sh AUTHORS
340 .An -nosplit
341 The
342 .Nm libarchive
343 library was written by
344 .An Tim Kientzle Aq kientzle@acm.org .
345 .Sh BUGS
346 Some archive formats support information that is not supported by
347 .Tn struct archive_entry .
348 Such information cannot be fully archived or restored using this library.
349 This includes, for example, comments, character sets,
350 or the arbitrary key/value pairs that can appear in
351 pax interchange format archives.
352 .Pp
353 Conversely, of course, not all of the information that can be
354 stored in an
355 .Tn struct archive_entry
356 is supported by all formats.
357 For example, cpio formats do not support nanosecond timestamps;
358 old tar formats do not support large device numbers.
359 .Pp
360 The
361 .Xr archive_read_disk 3
362 API should support iterating over filesystems;
363 that would make it possible to share code among
364 disk-to-archive, archive-to-archive, archive-to-disk,
365 and disk-to-disk operations.
366 Currently, it only supports reading the
367 information for a single file.
368 (Which is still quite useful, as it hides a lot
369 of system-specific details.)