]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - lib/libarchive/libarchive.3
MFC contrib/libarchive:
[FreeBSD/stable/9.git] / lib / 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 February 6, 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 a
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_buffer ,
181 which reads the data into an in-memory buffer,
182 .Fn archive_read_data_to_file ,
183 which copies the data to the provided file descriptor, or
184 .Fn archive_read_extract ,
185 which recreates the specified entry on disk and copies data
186 from the archive.
187 In particular, note that
188 .Fn archive_read_extract
189 uses the
190 .Tn struct archive_entry
191 structure that you provide it, which may differ from the
192 entry just read from the archive.
193 In particular, many applications will want to override the
194 pathname, file permissions, or ownership.
195 .Pp
196 Once you have finished reading data from the archive, you
197 should call
198 .Fn archive_read_close
199 to close the archive, then call
200 .Fn archive_read_free
201 to release all resources, including all memory allocated by the library.
202 .Pp
203 The
204 .Xr archive_read 3
205 manual page provides more detailed calling information for this API.
206 .Sh WRITING AN ARCHIVE
207 You use a similar process to write an archive.
208 The
209 .Fn archive_write_new
210 function creates an archive object useful for writing,
211 the various
212 .Fn archive_write_set_XXX
213 functions are used to set parameters for writing the archive, and
214 .Fn archive_write_open
215 completes the setup and opens the archive for writing.
216 .Pp
217 Individual archive entries are written in a three-step
218 process:
219 You first initialize a
220 .Tn struct archive_entry
221 structure with information about the new entry.
222 At a minimum, you should set the pathname of the
223 entry and provide a
224 .Va struct stat
225 with a valid
226 .Va st_mode
227 field, which specifies the type of object and
228 .Va st_size
229 field, which specifies the size of the data portion of the object.
230 The
231 .Fn archive_write_header
232 function actually writes the header data to the archive.
233 You can then use
234 .Fn archive_write_data
235 to write the actual data.
236 .Pp
237 After all entries have been written, use the
238 .Fn archive_write_free
239 function to release all resources.
240 .Pp
241 The
242 .Xr archive_write 3
243 manual page provides more detailed calling information for this API.
244 .Sh WRITING ENTRIES TO DISK
245 The
246 .Xr archive_write_disk 3
247 API allows you to write
248 .Xr archive_entry 3
249 objects to disk using the same API used by
250 .Xr archive_write 3 .
251 The
252 .Xr archive_write_disk 3
253 API is used internally by
254 .Fn archive_read_extract ;
255 using it directly can provide greater control over how entries
256 get written to disk.
257 This API also makes it possible to share code between
258 archive-to-archive copy and archive-to-disk extraction
259 operations.
260 .Sh READING ENTRIES FROM DISK
261 The
262 .Xr archive_read_disk 3
263 provides some support for populating
264 .Xr archive_entry 3
265 objects from information in the filesystem.
266 .Sh DESCRIPTION
267 Detailed descriptions of each function are provided by the
268 corresponding manual pages.
269 .Pp
270 All of the functions utilize an opaque
271 .Tn struct archive
272 datatype that provides access to the archive contents.
273 .Pp
274 The
275 .Tn struct archive_entry
276 structure contains a complete description of a single archive
277 entry.
278 It uses an opaque interface that is fully documented in
279 .Xr archive_entry 3 .
280 .Pp
281 Users familiar with historic formats should be aware that the newer
282 variants have eliminated most restrictions on the length of textual fields.
283 Clients should not assume that filenames, link names, user names, or
284 group names are limited in length.
285 In particular, pax interchange format can easily accommodate pathnames
286 in arbitrary character sets that exceed
287 .Va PATH_MAX .
288 .Sh RETURN VALUES
289 Most functions return
290 .Cm ARCHIVE_OK
291 (zero) on success, non-zero on error.
292 The return value indicates the general severity of the error, ranging
293 from
294 .Cm ARCHIVE_WARN ,
295 which indicates a minor problem that should probably be reported
296 to the user, to
297 .Cm ARCHIVE_FATAL ,
298 which indicates a serious problem that will prevent any further
299 operations on this archive.
300 On error, the
301 .Fn archive_errno
302 function can be used to retrieve a numeric error code (see
303 .Xr errno 2 ) .
304 The
305 .Fn archive_error_string
306 returns a textual error message suitable for display.
307 .Pp
308 .Fn archive_read_new
309 and
310 .Fn archive_write_new
311 return pointers to an allocated and initialized
312 .Tn struct archive
313 object.
314 .Pp
315 .Fn archive_read_data
316 and
317 .Fn archive_write_data
318 return a count of the number of bytes actually read or written.
319 A value of zero indicates the end of the data for this entry.
320 A negative value indicates an error, in which case the
321 .Fn archive_errno
322 and
323 .Fn archive_error_string
324 functions can be used to obtain more information.
325 .Sh ENVIRONMENT
326 There are character set conversions within the
327 .Xr archive_entry 3
328 functions that are impacted by the currently-selected locale.
329 .Sh SEE ALSO
330 .Xr tar 1 ,
331 .Xr archive_entry 3 ,
332 .Xr archive_read 3 ,
333 .Xr archive_util 3 ,
334 .Xr archive_write 3 ,
335 .Xr tar 5
336 .Sh HISTORY
337 The
338 .Nm libarchive
339 library first appeared in
340 .Fx 5.3 .
341 .Sh AUTHORS
342 .An -nosplit
343 The
344 .Nm libarchive
345 library was written by
346 .An Tim Kientzle Aq kientzle@acm.org .
347 .Sh BUGS
348 Some archive formats support information that is not supported by
349 .Tn struct archive_entry .
350 Such information cannot be fully archived or restored using this library.
351 This includes, for example, comments, character sets,
352 or the arbitrary key/value pairs that can appear in
353 pax interchange format archives.
354 .Pp
355 Conversely, of course, not all of the information that can be
356 stored in a
357 .Tn struct archive_entry
358 is supported by all formats.
359 For example, cpio formats do not support nanosecond timestamps;
360 old tar formats do not support large device numbers.
361 .Pp
362 The
363 .Xr archive_read_disk 3
364 API should support iterating over filesystems;
365 that would make it possible to share code among
366 disk-to-archive, archive-to-archive, archive-to-disk,
367 and disk-to-disk operations.
368 Currently, it only supports reading the
369 information for a single file.
370 (Which is still quite useful, as it hides a lot
371 of system-specific details.)