1 LIBARCHIVE(3) BSD Library Functions Manual LIBARCHIVE(3)
4 1mlibarchive 22m— functions for reading and writing streaming archives
7 The 1mlibarchive 22mlibrary provides a flexible interface for reading and
8 writing archives in various formats such as tar and cpio. 1mlibarchive0m
9 also supports reading and writing archives compressed using various com‐
10 pression filters such as gzip and bzip2. The library is inherently
11 stream-oriented; readers serially iterate through the archive, writers
12 serially add things to the archive. In particular, note that there is
13 currently no built-in support for random access nor for in-place modifi‐
16 When reading an archive, the library automatically detects the format and
17 the compression. The library currently has read support for:
18 1m· 22mold-style tar archives,
19 1m· 22mmost variants of the POSIX “ustar” format,
20 1m· 22mthe POSIX “pax interchange” format,
21 1m· 22mGNU-format tar archives,
22 1m· 22mmost common cpio archive formats,
23 1m· 22mISO9660 CD images (including RockRidge and Joliet extensions),
25 1m· 22mar archives (including GNU/SysV and BSD extensions),
26 1m· 22mMicrosoft CAB archives,
28 1m· 22mmtree file tree descriptions,
31 The library automatically detects archives compressed with gzip(1),
32 bzip2(1), xz(1), lzip(1), or compress(1) and decompresses them transpar‐
33 ently. It can similarly detect and decode archives processed with
34 uuencode(1) or which have an rpm(1) header.
36 When writing an archive, you can specify the compression to be used and
37 the format to use. The library can write
38 1m· 22mPOSIX-standard “ustar” archives,
39 1m· 22mPOSIX “pax interchange format” archives,
40 1m· 22mPOSIX octet-oriented cpio archives,
42 1m· 22mtwo different variants of shar archives,
43 1m· 22mISO9660 CD images,
44 1m· 22m7-Zip archives,
46 1m· 22mmtree file tree descriptions,
48 Pax interchange format is an extension of the tar archive format that
49 eliminates essentially all of the limitations of historic tar formats in
50 a standard fashion that is supported by POSIX-compliant pax(1) implemen‐
51 tations on many systems as well as several newer implementations of
52 tar(1). Note that the default write format will suppress the pax
53 extended attributes for most entries; explicitly requesting pax format
54 will enable those attributes for all entries.
56 The read and write APIs are accessed through the 1marchive_read_XXX22m() func‐
57 tions and the 1marchive_write_XXX22m() functions, respectively, and either can
58 be used independently of the other.
60 The rest of this manual page provides an overview of the library opera‐
61 tion. More detailed information can be found in the individual manual
62 pages for each API or utility function.
64 1mREADING AN ARCHIVE0m
67 1mWRITING AN ARCHIVE0m
70 1mWRITING ENTRIES TO DISK0m
71 The archive_write_disk(3) API allows you to write archive_entry(3)
72 objects to disk using the same API used by archive_write(3). The
73 archive_write_disk(3) API is used internally by 1marchive_read_extract22m();
74 using it directly can provide greater control over how entries get writ‐
75 ten to disk. This API also makes it possible to share code between ar‐
76 chive-to-archive copy and archive-to-disk extraction operations.
78 1mREADING ENTRIES FROM DISK0m
79 The archive_read_disk(3) supports for populating archive_entry(3) objects
80 from information in the filesystem. This includes the information acces‐
81 sible from the stat(2) system call as well as ACLs, extended attributes,
82 and other metadata. The archive_read_disk(3) API also supports iterating
83 over directory trees, which allows directories of files to be read using
84 an API compatible with the archive_read(3) API.
87 Detailed descriptions of each function are provided by the corresponding
90 All of the functions utilize an opaque struct archive datatype that pro‐
91 vides access to the archive contents.
93 The struct archive_entry structure contains a complete description of a
94 single archive entry. It uses an opaque interface that is fully docu‐
95 mented in archive_entry(3).
97 Users familiar with historic formats should be aware that the newer vari‐
98 ants have eliminated most restrictions on the length of textual fields.
99 Clients should not assume that filenames, link names, user names, or
100 group names are limited in length. In particular, pax interchange format
101 can easily accommodate pathnames in arbitrary character sets that exceed
105 Most functions return 1mARCHIVE_OK 22m(zero) on success, non-zero on error.
106 The return value indicates the general severity of the error, ranging
107 from 1mARCHIVE_WARN22m, which indicates a minor problem that should probably
108 be reported to the user, to 1mARCHIVE_FATAL22m, which indicates a serious
109 problem that will prevent any further operations on this archive. On
110 error, the 1marchive_errno22m() function can be used to retrieve a numeric
111 error code (see errno(2)). The 1marchive_error_string22m() returns a textual
112 error message suitable for display.
114 1marchive_read_new22m() and 1marchive_write_new22m() return pointers to an allo‐
115 cated and initialized struct archive object.
117 1marchive_read_data22m() and 1marchive_write_data22m() return a count of the number
118 of bytes actually read or written. A value of zero indicates the end of
119 the data for this entry. A negative value indicates an error, in which
120 case the 1marchive_errno22m() and 1marchive_error_string22m() functions can be used
121 to obtain more information.
124 There are character set conversions within the archive_entry(3) functions
125 that are impacted by the currently-selected locale.
128 tar(1), archive_entry(3), archive_read(3), archive_util(3),
129 archive_write(3), tar(5)
132 The 1mlibarchive 22mlibrary first appeared in FreeBSD 5.3.
135 The 1mlibarchive 22mlibrary was originally written by Tim Kientzle
139 Some archive formats support information that is not supported by struct
140 archive_entry. Such information cannot be fully archived or restored
141 using this library. This includes, for example, comments, character
142 sets, or the arbitrary key/value pairs that can appear in pax interchange
145 Conversely, of course, not all of the information that can be stored in
146 an struct archive_entry is supported by all formats. For example, cpio
147 formats do not support nanosecond timestamps; old tar formats do not sup‐
148 port large device numbers.
150 The ISO9660 reader cannot yet read all ISO9660 images; it should learn
153 The AR writer requires the client program to use two passes, unlike all
154 other libarchive writers.
156 BSD March 18, 2012 BSD