libarchive.3 8.2 KB

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