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
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 (including RockRidge and Joliet extensions),
68 The library automatically detects archives compressed with
74 and decompresses them transparently.
76 When writing an archive, you can specify the compression
77 to be used and the format to use.
86 .Dq pax interchange format
89 POSIX octet-oriented cpio archives,
93 two different variants of shar archives.
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
100 implementations on many systems as well as several newer implementations of
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.
106 The read and write APIs are accessed through the
109 .Fn archive_write_XXX
110 functions, respectively, and either can be used independently
113 The rest of this manual page provides an overview of the library
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
121 .Fn archive_read_new .
122 You can then modify this object for the desired operations with the
124 .Fn archive_read_set_XXX
126 .Fn archive_read_support_XXX
128 In particular, you will need to invoke appropriate
129 .Fn archive_read_support_XXX
130 functions to enable the corresponding compression and format
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
137 .Fn archive_read_support_compression_all
139 .Fn archive_read_support_format_all
140 to enable auto-detect for all formats and compression types
141 currently supported by the library.
143 Once you have prepared the
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,
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.
160 Each archive entry consists of a header followed by a certain
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
170 .Fn archive_read_data
171 (which works much like the
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
187 In particular, note that
188 .Fn archive_read_extract
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.
196 Once you have finished reading data from the archive, you
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.
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.
209 .Fn archive_write_new
210 function creates an archive object useful for writing,
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.
217 Individual archive entries are written in a three-step
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
227 field, which specifies the type of object and
229 field, which specifies the size of the data portion of the object.
231 .Fn archive_write_header
232 function actually writes the header data to the archive.
234 .Fn archive_write_data
235 to write the actual data.
237 After all entries have been written, use the
238 .Fn archive_write_free
239 function to release all resources.
243 manual page provides more detailed calling information for this API.
244 .Sh WRITING ENTRIES TO DISK
246 .Xr archive_write_disk 3
247 API allows you to write
249 objects to disk using the same API used by
250 .Xr archive_write 3 .
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
257 This API also makes it possible to share code between
258 archive-to-archive copy and archive-to-disk extraction
260 .Sh READING ENTRIES FROM DISK
262 .Xr archive_read_disk 3
263 provides some support for populating
265 objects from information in the filesystem.
267 Detailed descriptions of each function are provided by the
268 corresponding manual pages.
270 All of the functions utilize an opaque
272 datatype that provides access to the archive contents.
275 .Tn struct archive_entry
276 structure contains a complete description of a single archive
278 It uses an opaque interface that is fully documented in
279 .Xr archive_entry 3 .
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
289 Most functions return
291 (zero) on success, non-zero on error.
292 The return value indicates the general severity of the error, ranging
295 which indicates a minor problem that should probably be reported
298 which indicates a serious problem that will prevent any further
299 operations on this archive.
302 function can be used to retrieve a numeric error code (see
305 .Fn archive_error_string
306 returns a textual error message suitable for display.
310 .Fn archive_write_new
311 return pointers to an allocated and initialized
315 .Fn archive_read_data
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
323 .Fn archive_error_string
324 functions can be used to obtain more information.
326 There are character set conversions within the
328 functions that are impacted by the currently-selected locale.
331 .Xr archive_entry 3 ,
334 .Xr archive_write 3 ,
339 library first appeared in
345 library was written by
346 .An Tim Kientzle Aq kientzle@acm.org .
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.
355 Conversely, of course, not all of the information that can be
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.
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.)