1 .\" Copyright (c) 2003-2007 Tim Kientzle
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
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
25 .\" $FreeBSD: src/lib/libarchive/libarchive.3,v 1.11 2007/01/09 08:05:56 kientzle Exp $
32 .Nd functions for reading and writing streaming archives
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.
45 When reading an archive, the library automatically detects the
46 format and the compression.
47 The library currently has read support for:
50 old-style tar archives,
52 most variants of the POSIX
60 GNU-format tar archives,
62 most common cpio archive formats,
64 ISO9660 CD images (with or without RockRidge extensions),
68 The library automatically detects archives compressed with
73 and decompresses them transparently.
75 When writing an archive, you can specify the compression
76 to be used and the format to use.
85 .Dq pax interchange format
88 POSIX octet-oriented cpio archives,
90 two different variants of shar archives.
92 Pax interchange format is an extension of the tar archive format that
93 eliminates essentially all of the limitations of historic tar formats
94 in a standard fashion that is supported
97 implementations on many systems as well as several newer implementations of
99 Note that the default write format will suppress the pax extended
100 attributes for most entries; explicitly requesting pax format will
101 enable those attributes for all entries.
103 The read and write APIs are accessed through the
106 .Fn archive_write_XXX
107 functions, respectively, and either can be used independently
110 The rest of this manual page provides an overview of the library
112 More detailed information can be found in the individual manual
113 pages for each API or utility function.
114 .Sh READING AN ARCHIVE
115 To read an archive, you must first obtain an initialized
118 .Fn archive_read_new .
119 You can then modify this object for the desired operations with the
121 .Fn archive_read_set_XXX
123 .Fn archive_read_support_XXX
125 In particular, you will need to invoke appropriate
126 .Fn archive_read_support_XXX
127 functions to enable the corresponding compression and format
129 Note that these latter functions perform two distinct operations:
130 they cause the corresponding support code to be linked into your
131 program, and they enable the corresponding auto-detect code.
132 Unless you have specific constraints, you will generally want
134 .Fn archive_read_support_compression_all
136 .Fn archive_read_support_format_all
137 to enable auto-detect for all formats and compression types
138 currently supported by the library.
140 Once you have prepared the
143 .Fn archive_read_open
144 to actually open the archive and prepare it for reading.
145 There are several variants of this function;
146 the most basic expects you to provide pointers to several
147 functions that can provide blocks of bytes from the archive.
148 There are convenience forms that allow you to
149 specify a filename, file descriptor,
151 object, or a block of memory from which to read the archive data.
152 Note that the core library makes no assumptions about the
153 size of the blocks read;
154 callback functions are free to read whatever block size is
155 most appropriate for the medium.
157 Each archive entry consists of a header followed by a certain
159 You can obtain the next header with
160 .Fn archive_read_next_header ,
161 which returns a pointer to an
162 .Tn struct archive_entry
163 structure with information about the current archive element.
164 If the entry is a regular file, then the header will be followed
167 .Fn archive_read_data
168 (which works much like the
171 to read this data from the archive.
172 You may prefer to use the higher-level
173 .Fn archive_read_data_skip ,
174 which reads and discards the data for this entry,
175 .Fn archive_read_data_to_buffer ,
176 which reads the data into an in-memory buffer,
177 .Fn archive_read_data_to_file ,
178 which copies the data to the provided file descriptor, or
179 .Fn archive_read_extract ,
180 which recreates the specified entry on disk and copies data
182 In particular, note that
183 .Fn archive_read_extract
185 .Tn struct archive_entry
186 structure that you provide it, which may differ from the
187 entry just read from the archive.
188 In particular, many applications will want to override the
189 pathname, file permissions, or ownership.
191 Once you have finished reading data from the archive, you
193 .Fn archive_read_close
194 to close the archive, then call
195 .Fn archive_read_finish
196 to release all resources, including all memory allocated by the library.
200 manual page provides more detailed calling information for this API.
201 .Sh WRITING AN ARCHIVE
202 You use a similar process to write an archive.
204 .Fn archive_write_new
205 function creates an archive object useful for writing,
207 .Fn archive_write_set_XXX
208 functions are used to set parameters for writing the archive, and
209 .Fn archive_write_open
210 completes the setup and opens the archive for writing.
212 Individual archive entries are written in a three-step
214 You first initialize a
215 .Tn struct archive_entry
216 structure with information about the new entry.
217 At a minimum, you should set the pathname of the
222 field, which specifies the type of object and
224 field, which specifies the size of the data portion of the object.
226 .Fn archive_write_header
227 function actually writes the header data to the archive.
229 .Fn archive_write_data
230 to write the actual data.
232 After all entries have been written, use the
233 .Fn archive_write_finish
234 function to release all resources.
238 manual page provides more detailed calling information for this API.
240 Detailed descriptions of each function are provided by the
241 corresponding manual pages.
243 All of the functions utilize an opaque
245 datatype that provides access to the archive contents.
248 .Tn struct archive_entry
249 structure contains a complete description of a single archive
251 It uses an opaque interface that is fully documented in
252 .Xr archive_entry 3 .
254 Users familiar with historic formats should be aware that the newer
255 variants have eliminated most restrictions on the length of textual fields.
256 Clients should not assume that filenames, link names, user names, or
257 group names are limited in length.
258 In particular, pax interchange format can easily accommodate pathnames
259 in arbitrary character sets that exceed
262 Most functions return zero on success, non-zero on error.
263 The return value indicates the general severity of the error, ranging
266 which indicates a minor problem that should probably be reported
269 which indicates a serious problem that will prevent any further
270 operations on this archive.
273 function can be used to retrieve a numeric error code (see
276 .Fn archive_error_string
277 returns a textual error message suitable for display.
281 .Fn archive_write_new
282 return pointers to an allocated and initialized
286 .Fn archive_read_data
288 .Fn archive_write_data
289 return a count of the number of bytes actually read or written.
290 A value of zero indicates the end of the data for this entry.
291 A negative value indicates an error, in which case the
294 .Fn archive_error_string
295 functions can be used to obtain more information.
297 There are character set conversions within the
299 functions that are impacted by the currently-selected locale.
302 .Xr archive_entry 3 ,
305 .Xr archive_write 3 ,
310 library first appeared in
316 library was written by
317 .An Tim Kientzle Aq kientzle@acm.org .
319 Some archive formats support information that is not supported by
320 .Tn struct archive_entry .
321 Such information cannot be fully archived or restored using this library.
322 This includes, for example, comments, character sets,
323 or the arbitrary key/value pairs that can appear in
324 pax interchange format archives.
326 Conversely, of course, not all of the information that can be
328 .Tn struct archive_entry
329 is supported by all formats.
330 For example, cpio formats do not support nanosecond timestamps;
331 old tar formats do not support large device numbers.