1 .\" Copyright (c) 2003-2005 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.7 2005/01/21 20:50:38 ru 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:
52 most variants of the POSIX
60 GNU-format tar archives,
62 POSIX octet-oriented cpio archives.
64 The library automatically detects archives compressed with
69 and decompresses them transparently.
71 When writing an archive, you can specify the compression
72 to be used and the format to use.
81 .Dq pax interchange format
84 POSIX octet-oriented cpio archives,
86 two different variants of shar archives.
88 Pax interchange format is an extension of the tar archive format that
89 eliminates essentially all of the limitations of historic tar formats
90 in a standard fashion that is supported
93 implementations on many systems as well as several newer implementations of
95 Note that the default write format will suppress the pax extended
96 attributes for most entries; explicitly requesting pax format will
97 enable those attributes for all entries.
99 The read and write APIs are accessed through the
102 .Fn archive_write_XXX
103 functions, respectively, and either can be used independently
106 The rest of this manual page provides an overview of the library
108 More detailed information can be found in the individual manual
109 pages for each API or utility function.
110 .Sh READING AN ARCHIVE
111 To read an archive, you must first obtain an initialized
114 .Fn archive_read_new .
115 You can then modify this object for the desired operations with the
117 .Fn archive_read_set_XXX
119 .Fn archive_read_support_XXX
121 In particular, you will need to invoke appropriate
122 .Fn archive_read_support_XXX
123 functions to enable the corresponding compression and format
125 Note that these latter functions perform two distinct operations:
126 they cause the corresponding support code to be linked into your
127 program, and they enable the corresponding auto-detect code.
128 Unless you have specific constraints, you will generally want
130 .Fn archive_read_support_compression_all
132 .Fn archive_read_support_format_all
133 to enable auto-detect for all formats and compression types
134 currently supported by the library.
136 Once you have prepared the
139 .Fn archive_read_open
140 to actually open the archive and prepare it for reading.
142 Each archive entry consists of a header followed by a certain
144 You can obtain the next header with
145 .Fn archive_read_next_header ,
146 which returns a pointer to an
147 .Tn struct archive_entry
148 structure with information about the current archive element.
149 If the entry is a regular file, then the header will be followed
152 .Fn archive_read_data
153 (which works much like the
156 to read this data from the archive.
157 You may prefer to use the higher-level
158 .Fn archive_read_data_skip ,
159 which reads and discards the data for this entry,
160 .Fn archive_read_data_to_buffer ,
161 which reads the data into an in-memory buffer,
162 .Fn archive_read_data_to_file ,
163 which copies the data to the provided file descriptor, or
164 .Fn archive_read_extract ,
165 which recreates the specified entry on disk and copies data
167 In particular, note that
168 .Fn archive_read_extract
170 .Tn struct archive_entry
171 structure that you provide it, which may differ from the
172 entry just read from the archive.
173 In particular, many applications will want to override the
174 pathname, file permissions, or ownership.
176 Once you have finished reading data from the archive, you
178 .Fn archive_read_finish
179 to release all resources.
181 .Fn archive_read_finish
182 closes the archive and frees any memory that was allocated by the library.
186 manual page provides more detailed calling information for this API.
187 .Sh WRITING AN ARCHIVE
188 You use a similar process to write an archive.
190 .Fn archive_write_new
191 function creates an archive object useful for writing,
193 .Fn archive_write_set_XXX
194 functions are used to set parameters for writing the archive, and
195 .Fn archive_write_open
196 completes the setup and opens the archive for writing.
198 Individual archive entries are written in a three-step
200 You first initialize a
201 .Tn struct archive_entry
202 structure with information about the new entry.
203 At a minimum, you should set the pathname of the
208 field, which specifies the type of object and
210 field, which specifies the size of the data portion of the object.
212 .Fn archive_write_header
213 function actually writes the header data to the archive.
215 .Fn archive_write_data
216 to write the actual data.
218 After all entries have been written, use the
219 .Fn archive_write_finish
220 function to release all resources.
224 manual page provides more detailed calling information for this API.
226 Detailed descriptions of each function are provided by the
227 corresponding manual pages.
229 All of the functions utilize an opaque
231 datatype that provides access to the archive contents.
234 .Tn struct archive_entry
235 structure contains a complete description of a single archive
237 It uses an opaque interface that is fully documented in
238 .Xr archive_entry 3 .
240 Users familiar with historic formats should be aware that the newer
241 variants have eliminated most restrictions on the length of textual fields.
242 Clients should not assume that filenames, link names, user names, or
243 group names are limited in length.
244 In particular, pax interchange format can easily accomodate pathnames
245 in arbitrary character sets that exceed
248 Most functions return zero on success, non-zero on error.
249 The return value indicates the general severity of the error, ranging
251 .Cm ARCHIVE_WARNING ,
252 which indicates a minor problem that should probably be reported
255 which indicates a serious problem that will prevent any further
256 operations on this archive.
259 function can be used to retrieve a numeric error code (see
262 .Fn archive_error_string
263 returns a textual error message suitable for display.
267 .Fn archive_write_new
268 return pointers to an allocated and initialized
272 .Fn archive_read_data
274 .Fn archive_write_data
275 return a count of the number of bytes actually read or written.
276 A value of zero indicates the end of the data for this entry.
277 A negative value indicates an error, in which case the
280 .Fn archive_error_string
281 functions can be used to obtain more information.
283 There are character set conversions within the
285 functions that are impacted by the currently-selected locale.
288 .Xr archive_entry 3 ,
291 .Xr archive_write 3 ,
296 library first appeared in
302 library was written by
303 .An Tim Kientzle Aq kientzle@acm.org .
305 Some archive formats support information that is not supported by
306 .Tn struct archive_entry .
307 Such information cannot be fully archived or restored using this library.
308 This includes, for example, comments, character sets,
309 or the arbitrary key/value pairs that can appear in
310 pax interchange format archives.
312 Conversely, of course, not all of the information that can be
314 .Tn struct archive_entry
315 is supported by all formats.
316 For example, cpio formats do not support nanosecond timestamps;
317 old tar formats do not support large device numbers.