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 March 18, 2012 28.Dt LIBARCHIVE 3 29.Os 30.Sh NAME 31.Nm libarchive 32.Nd functions for reading and writing streaming archives 33.Sh OVERVIEW 34The 35.Nm 36library provides a flexible interface for reading and writing 37archives in various formats such as tar and cpio. 38.Nm 39also supports reading and writing archives compressed using 40various compression filters such as gzip and bzip2. 41The library is inherently stream-oriented; readers serially iterate through 42the archive, writers serially add things to the archive. 43In particular, note that there is currently no built-in support for 44random access nor for in-place modification. 45.Pp 46When reading an archive, the library automatically detects the 47format and the compression. 48The library currently has read support for: 49.Bl -bullet -compact 50.It 51old-style tar archives, 52.It 53most variants of the POSIX 54.Dq ustar 55format, 56.It 57the POSIX 58.Dq pax interchange 59format, 60.It 61GNU-format tar archives, 62.It 63most common cpio archive formats, 64.It 65ISO9660 CD images (including RockRidge and Joliet extensions), 66.It 67Zip archives, 68.It 69ar archives (including GNU/SysV and BSD extensions), 70.It 71Microsoft CAB archives, 72.It 73LHA archives, 74.It 75mtree file tree descriptions, 76.It 77RAR archives, 78.It 79XAR archives. 80.El 81The library automatically detects archives compressed with 82.Xr gzip 1 , 83.Xr bzip2 1 , 84.Xr xz 1 , 85.Xr lzip 1 , 86or 87.Xr compress 1 88and decompresses them transparently. 89It can similarly detect and decode archives processed with 90.Xr uuencode 1 91or which have an 92.Xr rpm 1 93header. 94.Pp 95When writing an archive, you can specify the compression 96to be used and the format to use. 97The library can write 98.Bl -bullet -compact 99.It 100POSIX-standard 101.Dq ustar 102archives, 103.It 104POSIX 105.Dq pax interchange format 106archives, 107.It 108POSIX octet-oriented cpio archives, 109.It 110Zip archive, 111.It 112two different variants of shar archives, 113.It 114ISO9660 CD images, 115.It 1167-Zip archives, 117.It 118ar archives, 119.It 120mtree file tree descriptions, 121.It 122XAR archives. 123.El 124Pax interchange format is an extension of the tar archive format that 125eliminates essentially all of the limitations of historic tar formats 126in a standard fashion that is supported 127by POSIX-compliant 128.Xr pax 1 129implementations on many systems as well as several newer implementations of 130.Xr tar 1 . 131Note that the default write format will suppress the pax extended 132attributes for most entries; explicitly requesting pax format will 133enable those attributes for all entries. 134.Pp 135The read and write APIs are accessed through the 136.Fn archive_read_XXX 137functions and the 138.Fn archive_write_XXX 139functions, respectively, and either can be used independently 140of the other. 141.Pp 142The rest of this manual page provides an overview of the library 143operation. 144More detailed information can be found in the individual manual 145pages for each API or utility function. 146.\" 147.Sh READING AN ARCHIVE 148See 149.Xr archive_read 3 . 150.\" 151.Sh WRITING AN ARCHIVE 152See 153.Xr archive_write 3 . 154.\" 155.Sh WRITING ENTRIES TO DISK 156The 157.Xr archive_write_disk 3 158API allows you to write 159.Xr archive_entry 3 160objects to disk using the same API used by 161.Xr archive_write 3 . 162The 163.Xr archive_write_disk 3 164API is used internally by 165.Fn archive_read_extract ; 166using it directly can provide greater control over how entries 167get written to disk. 168This API also makes it possible to share code between 169archive-to-archive copy and archive-to-disk extraction 170operations. 171.Sh READING ENTRIES FROM DISK 172The 173.Xr archive_read_disk 3 174supports for populating 175.Xr archive_entry 3 176objects from information in the filesystem. 177This includes the information accessible from the 178.Xr stat 2 179system call as well as ACLs, extended attributes, 180and other metadata. 181The 182.Xr archive_read_disk 3 183API also supports iterating over directory trees, 184which allows directories of files to be read using 185an API compatible with 186the 187.Xr archive_read 3 188API. 189.Sh DESCRIPTION 190Detailed descriptions of each function are provided by the 191corresponding manual pages. 192.Pp 193All of the functions utilize an opaque 194.Tn struct archive 195datatype that provides access to the archive contents. 196.Pp 197The 198.Tn struct archive_entry 199structure contains a complete description of a single archive 200entry. 201It uses an opaque interface that is fully documented in 202.Xr archive_entry 3 . 203.Pp 204Users familiar with historic formats should be aware that the newer 205variants have eliminated most restrictions on the length of textual fields. 206Clients should not assume that filenames, link names, user names, or 207group names are limited in length. 208In particular, pax interchange format can easily accommodate pathnames 209in arbitrary character sets that exceed 210.Va PATH_MAX . 211.Sh RETURN VALUES 212Most functions return 213.Cm ARCHIVE_OK 214(zero) on success, non-zero on error. 215The return value indicates the general severity of the error, ranging 216from 217.Cm ARCHIVE_WARN , 218which indicates a minor problem that should probably be reported 219to the user, to 220.Cm ARCHIVE_FATAL , 221which indicates a serious problem that will prevent any further 222operations on this archive. 223On error, the 224.Fn archive_errno 225function can be used to retrieve a numeric error code (see 226.Xr errno 2 ) . 227The 228.Fn archive_error_string 229returns a textual error message suitable for display. 230.Pp 231.Fn archive_read_new 232and 233.Fn archive_write_new 234return pointers to an allocated and initialized 235.Tn struct archive 236object. 237.Pp 238.Fn archive_read_data 239and 240.Fn archive_write_data 241return a count of the number of bytes actually read or written. 242A value of zero indicates the end of the data for this entry. 243A negative value indicates an error, in which case the 244.Fn archive_errno 245and 246.Fn archive_error_string 247functions can be used to obtain more information. 248.Sh ENVIRONMENT 249There are character set conversions within the 250.Xr archive_entry 3 251functions that are impacted by the currently-selected locale. 252.Sh SEE ALSO 253.Xr tar 1 , 254.Xr archive_entry 3 , 255.Xr archive_read 3 , 256.Xr archive_util 3 , 257.Xr archive_write 3 , 258.Xr tar 5 259.Sh HISTORY 260The 261.Nm libarchive 262library first appeared in 263.Fx 5.3 . 264.Sh AUTHORS 265.An -nosplit 266The 267.Nm libarchive 268library was originally written by 269.An Tim Kientzle Aq kientzle@acm.org . 270.Sh BUGS 271Some archive formats support information that is not supported by 272.Tn struct archive_entry . 273Such information cannot be fully archived or restored using this library. 274This includes, for example, comments, character sets, 275or the arbitrary key/value pairs that can appear in 276pax interchange format archives. 277.Pp 278Conversely, of course, not all of the information that can be 279stored in an 280.Tn struct archive_entry 281is supported by all formats. 282For example, cpio formats do not support nanosecond timestamps; 283old tar formats do not support large device numbers. 284.Pp 285The ISO9660 reader cannot yet read all ISO9660 images; 286it should learn how to seek. 287.Pp 288The AR writer requires the client program to use 289two passes, unlike all other libarchive writers. 290