Merge from vendor branch LIBARCHIVE:
[dragonfly.git] / contrib / libarchive / libarchive.3
1 .\" Copyright (c) 2003-2004 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: src/lib/libarchive/libarchive.3,v 1.4 2004/07/04 21:15:37 ru Exp $
26 .\"
27 .Dd October 1, 2003
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
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 POSIX octet-oriented cpio archives.
63 .El
64 The library automatically detects archives compressed with
65 .Xr gzip 1 ,
66 .Xr bzip2 1 ,
67 or
68 .Xr compress 1
69 and decompresses them transparently.
70 .Pp
71 When writing an archive, you can specify the compression
72 to be used and the format to use.
73 The library can write
74 .Bl -bullet -compact
75 .It
76 POSIX-standard
77 .Dq ustar
78 archives,
79 .It
80 POSIX
81 .Dq pax interchange format
82 archives,
83 .It
84 POSIX octet-oriented cpio archives,
85 .It
86 two different variants of shar archives.
87 .El
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
91 by POSIX-compliant
92 .Xr pax 1
93 implementations on many systems as well as several newer implementations of
94 .Xr tar 1 .
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.
98 .Pp
99 The read and write APIs are accessed through the
100 .Fn archive_read_XXX
101 functions and the
102 .Fn archive_write_XXX
103 functions, respectively, and either can be used independently
104 of the other.
105 .Pp
106 The rest of this manual page provides an overview of the library
107 operation.
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
112 .Tn struct archive
113 object from
114 .Fn archive_read_new .
115 You can then modify this object for the desired operations with the
116 various
117 .Fn archive_read_set_XXX
118 and
119 .Fn archive_read_support_XXX
120 functions.
121 In particular, you will need to invoke appropriate
122 .Fn archive_read_support_XXX
123 functions to enable the corresponding compression and format
124 support.
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
129 to invoke
130 .Fn archive_read_support_compression_all
131 and
132 .Fn archive_read_support_format_all
133 to enable auto-detect for all formats and compression types
134 currently supported by the library.
135 .Pp
136 Once you have prepared the
137 .Tn struct archive
138 object, you call
139 .Fn archive_read_open
140 to actually open the archive and prepare it for reading.
141 .Pp
142 Each archive entry consists of a header followed by a certain
143 amount of data.
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
150 by the file data.
151 You can use
152 .Fn archive_read_data
153 (which works much like the
154 .Xr read 2
155 system call)
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
166 from the archive.
167 In particular, note that
168 .Fn archive_read_extract
169 uses the
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.
175 .Pp
176 Once you have finished reading data from the archive, you
177 should call
178 .Fn archive_read_finish
179 to release all resources.
180 In particular,
181 .Fn archive_read_finish
182 closes the archive and frees any memory that was allocated by the library.
183 .Pp
184 The
185 .Xr archive_read 3
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.
189 The
190 .Fn archive_write_new
191 function creates an archive object useful for writing,
192 the various
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.
197 .Pp
198 Individual archive entries are written in a three-step
199 process:
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
204 entry and provide a
205 .Va struct stat
206 with a valid
207 .Va st_mode
208 field, which specifies the type of object and
209 .Va st_size
210 field, which specifies the size of the data portion of the object.
211 The
212 .Fn archive_write_header
213 function actually writes the header data to the archive.
214 You can then use
215 .Fn archive_write_data
216 to write the actual data.
217 .Pp
218 After all entries have been written, use the
219 .Fn archive_write_finish
220 function to release all resources.
221 .Pp
222 The
223 .Xr archive_write 3
224 manual page provides more detailed calling information for this API.
225 .Sh DESCRIPTION
226 Detailed descriptions of each function are provided by the
227 corresponding manual pages.
228 .Pp
229 All of the functions utilize an opaque
230 .Tn struct archive
231 datatype that provides access to the archive contents.
232 .Pp
233 The
234 .Tn struct archive_entry
235 structure contains a complete description of a single archive
236 entry.
237 It uses an opaque interface that is fully documented in
238 .Xr archive_entry 3 .
239 .Pp
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
246 .Va PATH_MAX .
247 .Sh RETURN VALUES
248 Most functions return zero on success, non-zero on error.
249 The return value indicates the general severity of the error, ranging
250 from
251 .Cm ARCHIVE_WARNING ,
252 which indicates a minor problem that should probably be reported
253 to the user, to
254 .Cm ARCHIVE_FATAL ,
255 which indicates a serious problem that will prevent any further
256 operations on this archive.
257 On error, the
258 .Fn archive_errno
259 function can be used to retrieve a numeric error code (see
260 .Xr errno 2 ) .
261 The
262 .Fn archive_error_string
263 returns a textual error message suitable for display.
264 .Pp
265 .Fn archive_read_new
266 and
267 .Fn archive_write_new
268 return pointers to an allocated and initialized
269 .Tn struct archive
270 object.
271 .Pp
272 .Fn archive_read_data
273 and
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
278 .Fn archive_errno
279 and
280 .Fn archive_error_string
281 functions can be used to obtain more information.
282 .Sh ENVIRONMENT
283 There are character set conversions within the
284 .Xr archive_entry
285 functions that are impacted by the currently-selected locale.
286 .Sh SEE ALSO
287 .Xr tar 1 ,
288 .Xr archive_entry 3 ,
289 .Xr archive_read 3 ,
290 .Xr archive_util 3 ,
291 .Xr archive_write 3 ,
292 .Xr tar 5
293 .Sh HISTORY
294 The
295 .Nm libarchive
296 library first appeared in
297 .Fx 5.3 .
298 .Sh AUTHORS
299 .An -nosplit
300 The
301 .Nm libarchive
302 library was written by
303 .An Tim Kientzle Aq kientzle@acm.org .
304 .Sh BUGS
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, sparse
309 file information, or the arbitrary key/value pairs that can appear in
310 pax interchange format archives.
311 .Pp
312 Conversely, of course, not all of the information that can be
313 stored in an
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.
318 .Pp
319 The library cannot write pre-POSIX tar archives.
320 The support for GNU tar format is incomplete.