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