2007-01-09 08:05:56 +00:00
|
|
|
.\" Copyright (c) 2003-2007 Tim Kientzle
|
2004-02-09 23:22:54 +00:00
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
2009-04-27 20:13:13 +00:00
|
|
|
.Dd April 13, 2009
|
2010-06-11 06:03:47 +00:00
|
|
|
.Dt ARCHIVE_READ 3
|
2004-02-09 23:22:54 +00:00
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm archive_read_new ,
|
2009-04-17 01:02:12 +00:00
|
|
|
.Nm archive_read_set_filter_options ,
|
|
|
|
.Nm archive_read_set_format_options ,
|
|
|
|
.Nm archive_read_set_options ,
|
2004-02-09 23:22:54 +00:00
|
|
|
.Nm archive_read_support_compression_all ,
|
2004-05-27 04:21:52 +00:00
|
|
|
.Nm archive_read_support_compression_bzip2 ,
|
|
|
|
.Nm archive_read_support_compression_compress ,
|
|
|
|
.Nm archive_read_support_compression_gzip ,
|
2009-04-27 20:13:13 +00:00
|
|
|
.Nm archive_read_support_compression_lzma ,
|
2004-05-27 04:21:52 +00:00
|
|
|
.Nm archive_read_support_compression_none ,
|
2009-04-27 20:13:13 +00:00
|
|
|
.Nm archive_read_support_compression_xz ,
|
2007-05-29 01:00:21 +00:00
|
|
|
.Nm archive_read_support_compression_program ,
|
2009-04-27 20:13:13 +00:00
|
|
|
.Nm archive_read_support_compression_program_signature ,
|
2004-02-09 23:22:54 +00:00
|
|
|
.Nm archive_read_support_format_all ,
|
2009-04-27 20:13:13 +00:00
|
|
|
.Nm archive_read_support_format_ar ,
|
2005-01-08 19:51:04 +00:00
|
|
|
.Nm archive_read_support_format_cpio ,
|
2007-02-01 06:18:17 +00:00
|
|
|
.Nm archive_read_support_format_empty ,
|
2005-01-08 19:51:04 +00:00
|
|
|
.Nm archive_read_support_format_iso9660 ,
|
2009-04-27 20:13:13 +00:00
|
|
|
.Nm archive_read_support_format_mtree,
|
|
|
|
.Nm archive_read_support_format_raw,
|
2005-01-08 19:51:04 +00:00
|
|
|
.Nm archive_read_support_format_tar ,
|
2005-01-25 06:07:28 +00:00
|
|
|
.Nm archive_read_support_format_zip ,
|
2004-02-09 23:22:54 +00:00
|
|
|
.Nm archive_read_open ,
|
2006-09-05 05:59:46 +00:00
|
|
|
.Nm archive_read_open2 ,
|
2004-04-05 21:12:29 +00:00
|
|
|
.Nm archive_read_open_fd ,
|
2006-11-24 05:34:23 +00:00
|
|
|
.Nm archive_read_open_FILE ,
|
2006-11-20 16:48:04 +00:00
|
|
|
.Nm archive_read_open_filename ,
|
2006-11-24 05:34:23 +00:00
|
|
|
.Nm archive_read_open_memory ,
|
2004-02-09 23:22:54 +00:00
|
|
|
.Nm archive_read_next_header ,
|
2009-04-17 01:02:12 +00:00
|
|
|
.Nm archive_read_next_header2 ,
|
2004-02-09 23:22:54 +00:00
|
|
|
.Nm archive_read_data ,
|
2004-06-02 08:14:43 +00:00
|
|
|
.Nm archive_read_data_block ,
|
2004-02-09 23:22:54 +00:00
|
|
|
.Nm archive_read_data_skip ,
|
2007-04-05 15:51:19 +00:00
|
|
|
.\" #if ARCHIVE_API_VERSION < 3
|
2004-02-09 23:22:54 +00:00
|
|
|
.Nm archive_read_data_into_buffer ,
|
2007-04-05 15:51:19 +00:00
|
|
|
.\" #endif
|
2004-06-02 08:14:43 +00:00
|
|
|
.Nm archive_read_data_into_fd ,
|
2004-02-09 23:22:54 +00:00
|
|
|
.Nm archive_read_extract ,
|
2008-05-26 17:00:24 +00:00
|
|
|
.Nm archive_read_extract2 ,
|
2004-05-13 06:01:14 +00:00
|
|
|
.Nm archive_read_extract_set_progress_callback ,
|
2005-01-11 20:50:51 +00:00
|
|
|
.Nm archive_read_close ,
|
2004-02-09 23:22:54 +00:00
|
|
|
.Nm archive_read_finish
|
2005-01-10 05:11:15 +00:00
|
|
|
.Nd functions for reading streaming archives
|
2004-02-09 23:22:54 +00:00
|
|
|
.Sh SYNOPSIS
|
|
|
|
.In archive.h
|
|
|
|
.Ft struct archive *
|
|
|
|
.Fn archive_read_new "void"
|
|
|
|
.Ft int
|
2004-05-27 04:21:52 +00:00
|
|
|
.Fn archive_read_support_compression_all "struct archive *"
|
2004-02-09 23:22:54 +00:00
|
|
|
.Ft int
|
|
|
|
.Fn archive_read_support_compression_bzip2 "struct archive *"
|
|
|
|
.Ft int
|
2004-05-27 04:21:52 +00:00
|
|
|
.Fn archive_read_support_compression_compress "struct archive *"
|
2004-02-09 23:22:54 +00:00
|
|
|
.Ft int
|
2004-05-27 04:21:52 +00:00
|
|
|
.Fn archive_read_support_compression_gzip "struct archive *"
|
|
|
|
.Ft int
|
2009-04-27 20:13:13 +00:00
|
|
|
.Fn archive_read_support_compression_lzma "struct archive *"
|
|
|
|
.Ft int
|
2004-05-27 04:21:52 +00:00
|
|
|
.Fn archive_read_support_compression_none "struct archive *"
|
2004-02-09 23:22:54 +00:00
|
|
|
.Ft int
|
2009-04-27 20:13:13 +00:00
|
|
|
.Fn archive_read_support_compression_xz "struct archive *"
|
|
|
|
.Ft int
|
2008-03-10 14:45:29 +00:00
|
|
|
.Fo archive_read_support_compression_program
|
|
|
|
.Fa "struct archive *"
|
|
|
|
.Fa "const char *cmd"
|
|
|
|
.Fc
|
2007-05-29 01:00:21 +00:00
|
|
|
.Ft int
|
2009-04-27 20:13:13 +00:00
|
|
|
.Fo archive_read_support_compression_program_signature
|
|
|
|
.Fa "struct archive *"
|
|
|
|
.Fa "const char *cmd"
|
|
|
|
.Fa "const void *signature"
|
|
|
|
.Fa "size_t signature_length"
|
|
|
|
.Fc
|
|
|
|
.Ft int
|
2005-01-08 19:51:04 +00:00
|
|
|
.Fn archive_read_support_format_all "struct archive *"
|
2004-02-09 23:22:54 +00:00
|
|
|
.Ft int
|
2009-04-27 20:13:13 +00:00
|
|
|
.Fn archive_read_support_format_ar "struct archive *"
|
|
|
|
.Ft int
|
2004-02-09 23:22:54 +00:00
|
|
|
.Fn archive_read_support_format_cpio "struct archive *"
|
|
|
|
.Ft int
|
2007-02-01 06:18:17 +00:00
|
|
|
.Fn archive_read_support_format_empty "struct archive *"
|
|
|
|
.Ft int
|
2005-01-08 19:51:04 +00:00
|
|
|
.Fn archive_read_support_format_iso9660 "struct archive *"
|
|
|
|
.Ft int
|
2009-04-27 20:13:13 +00:00
|
|
|
.Fn archive_read_support_format_mtree "struct archive *"
|
|
|
|
.Ft int
|
|
|
|
.Fn archive_read_support_format_raw "struct archive *"
|
|
|
|
.Ft int
|
2005-01-08 19:51:04 +00:00
|
|
|
.Fn archive_read_support_format_tar "struct archive *"
|
2004-02-09 23:22:54 +00:00
|
|
|
.Ft int
|
2005-01-25 06:07:28 +00:00
|
|
|
.Fn archive_read_support_format_zip "struct archive *"
|
|
|
|
.Ft int
|
2009-04-17 01:02:12 +00:00
|
|
|
.Fn archive_read_set_filter_options "struct archive *" "const char *"
|
|
|
|
.Ft int
|
|
|
|
.Fn archive_read_set_format_options "struct archive *" "const char *"
|
|
|
|
.Ft int
|
|
|
|
.Fn archive_read_set_options "struct archive *" "const char *"
|
|
|
|
.Ft int
|
2008-03-10 14:45:29 +00:00
|
|
|
.Fo archive_read_open
|
|
|
|
.Fa "struct archive *"
|
|
|
|
.Fa "void *client_data"
|
|
|
|
.Fa "archive_open_callback *"
|
|
|
|
.Fa "archive_read_callback *"
|
|
|
|
.Fa "archive_close_callback *"
|
|
|
|
.Fc
|
2004-02-09 23:22:54 +00:00
|
|
|
.Ft int
|
2008-03-10 14:45:29 +00:00
|
|
|
.Fo archive_read_open2
|
|
|
|
.Fa "struct archive *"
|
|
|
|
.Fa "void *client_data"
|
|
|
|
.Fa "archive_open_callback *"
|
|
|
|
.Fa "archive_read_callback *"
|
|
|
|
.Fa "archive_skip_callback *"
|
|
|
|
.Fa "archive_close_callback *"
|
|
|
|
.Fc
|
2006-09-05 05:59:46 +00:00
|
|
|
.Ft int
|
2006-11-24 05:34:23 +00:00
|
|
|
.Fn archive_read_open_FILE "struct archive *" "FILE *file"
|
|
|
|
.Ft int
|
2005-01-12 05:56:49 +00:00
|
|
|
.Fn archive_read_open_fd "struct archive *" "int fd" "size_t block_size"
|
2004-04-05 21:12:29 +00:00
|
|
|
.Ft int
|
2008-03-10 14:45:29 +00:00
|
|
|
.Fo archive_read_open_filename
|
|
|
|
.Fa "struct archive *"
|
|
|
|
.Fa "const char *filename"
|
|
|
|
.Fa "size_t block_size"
|
|
|
|
.Fc
|
2004-02-09 23:22:54 +00:00
|
|
|
.Ft int
|
2006-11-24 05:34:23 +00:00
|
|
|
.Fn archive_read_open_memory "struct archive *" "void *buff" "size_t size"
|
|
|
|
.Ft int
|
2004-02-09 23:22:54 +00:00
|
|
|
.Fn archive_read_next_header "struct archive *" "struct archive_entry **"
|
2009-04-17 01:02:12 +00:00
|
|
|
.Ft int
|
|
|
|
.Fn archive_read_next_header2 "struct archive *" "struct archive_entry *"
|
2004-02-09 23:22:54 +00:00
|
|
|
.Ft ssize_t
|
|
|
|
.Fn archive_read_data "struct archive *" "void *buff" "size_t len"
|
|
|
|
.Ft int
|
2008-03-10 14:45:29 +00:00
|
|
|
.Fo archive_read_data_block
|
|
|
|
.Fa "struct archive *"
|
|
|
|
.Fa "const void **buff"
|
|
|
|
.Fa "size_t *len"
|
|
|
|
.Fa "off_t *offset"
|
|
|
|
.Fc
|
2004-06-02 08:14:43 +00:00
|
|
|
.Ft int
|
2004-02-09 23:22:54 +00:00
|
|
|
.Fn archive_read_data_skip "struct archive *"
|
2007-04-05 15:51:19 +00:00
|
|
|
.\" #if ARCHIVE_API_VERSION < 3
|
2004-02-09 23:22:54 +00:00
|
|
|
.Ft int
|
2005-11-24 10:06:05 +00:00
|
|
|
.Fn archive_read_data_into_buffer "struct archive *" "void *" "ssize_t len"
|
2007-04-05 15:51:19 +00:00
|
|
|
.\" #endif
|
2004-02-09 23:22:54 +00:00
|
|
|
.Ft int
|
2004-06-02 08:14:43 +00:00
|
|
|
.Fn archive_read_data_into_fd "struct archive *" "int fd"
|
2004-02-09 23:22:54 +00:00
|
|
|
.Ft int
|
2008-03-10 14:45:29 +00:00
|
|
|
.Fo archive_read_extract
|
|
|
|
.Fa "struct archive *"
|
|
|
|
.Fa "struct archive_entry *"
|
|
|
|
.Fa "int flags"
|
|
|
|
.Fc
|
2008-05-26 17:00:24 +00:00
|
|
|
.Ft int
|
|
|
|
.Fo archive_read_extract2
|
|
|
|
.Fa "struct archive *src"
|
|
|
|
.Fa "struct archive_entry *"
|
|
|
|
.Fa "struct archive *dest"
|
|
|
|
.Fc
|
2004-02-09 23:22:54 +00:00
|
|
|
.Ft void
|
2008-03-10 14:45:29 +00:00
|
|
|
.Fo archive_read_extract_set_progress_callback
|
|
|
|
.Fa "struct archive *"
|
|
|
|
.Fa "void (*func)(void *)"
|
|
|
|
.Fa "void *user_data"
|
|
|
|
.Fc
|
2004-08-07 19:22:50 +00:00
|
|
|
.Ft int
|
|
|
|
.Fn archive_read_close "struct archive *"
|
2007-03-03 07:37:37 +00:00
|
|
|
.Ft int
|
2004-02-09 23:22:54 +00:00
|
|
|
.Fn archive_read_finish "struct archive *"
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
These functions provide a complete API for reading streaming archives.
|
|
|
|
The general process is to first create the
|
|
|
|
.Tn struct archive
|
|
|
|
object, set options, initialize the reader, iterate over the archive
|
|
|
|
headers and associated data, then close the archive and release all
|
|
|
|
resources.
|
|
|
|
The following summary describes the functions in approximately the
|
|
|
|
order they would be used:
|
|
|
|
.Bl -tag -compact -width indent
|
|
|
|
.It Fn archive_read_new
|
|
|
|
Allocates and initializes a
|
|
|
|
.Tn struct archive
|
|
|
|
object suitable for reading from an archive.
|
2008-03-10 14:45:29 +00:00
|
|
|
.It Xo
|
|
|
|
.Fn archive_read_support_compression_bzip2 ,
|
|
|
|
.Fn archive_read_support_compression_compress ,
|
|
|
|
.Fn archive_read_support_compression_gzip ,
|
2009-04-27 20:13:13 +00:00
|
|
|
.Fn archive_read_support_compression_lzma ,
|
|
|
|
.Fn archive_read_support_compression_none ,
|
|
|
|
.Fn archive_read_support_compression_xz
|
2008-03-10 14:45:29 +00:00
|
|
|
.Xc
|
2004-02-09 23:22:54 +00:00
|
|
|
Enables auto-detection code and decompression support for the
|
|
|
|
specified compression.
|
2009-04-27 20:13:13 +00:00
|
|
|
Returns
|
|
|
|
.Cm ARCHIVE_OK
|
|
|
|
if the compression is fully supported, or
|
|
|
|
.Cm ARCHIVE_WARN
|
|
|
|
if the compression is supported only through an external program.
|
|
|
|
Note that decompression using an external program is usually slower than
|
|
|
|
decompression through built-in libraries.
|
2004-02-09 23:22:54 +00:00
|
|
|
Note that
|
|
|
|
.Dq none
|
|
|
|
is always enabled by default.
|
2009-04-27 20:13:13 +00:00
|
|
|
.It Fn archive_read_support_compression_all
|
|
|
|
Enables all available decompression filters.
|
2007-05-29 01:00:21 +00:00
|
|
|
.It Fn archive_read_support_compression_program
|
|
|
|
Data is fed through the specified external program before being dearchived.
|
|
|
|
Note that this disables automatic detection of the compression format,
|
|
|
|
so it makes no sense to specify this in conjunction with any other
|
|
|
|
decompression option.
|
2009-04-27 20:13:13 +00:00
|
|
|
.It Fn archive_read_support_compression_program_signature
|
|
|
|
This feeds data through the specified external program
|
|
|
|
but only if the initial bytes of the data match the specified
|
|
|
|
signature value.
|
2008-03-10 14:45:29 +00:00
|
|
|
.It Xo
|
|
|
|
.Fn archive_read_support_format_all ,
|
2009-04-27 20:13:13 +00:00
|
|
|
.Fn archive_read_support_format_ar ,
|
2008-03-10 14:45:29 +00:00
|
|
|
.Fn archive_read_support_format_cpio ,
|
|
|
|
.Fn archive_read_support_format_empty ,
|
|
|
|
.Fn archive_read_support_format_iso9660 ,
|
2009-04-27 20:13:13 +00:00
|
|
|
.Fn archive_read_support_format_mtree ,
|
2008-03-10 14:45:29 +00:00
|
|
|
.Fn archive_read_support_format_tar ,
|
|
|
|
.Fn archive_read_support_format_zip
|
|
|
|
.Xc
|
2004-02-09 23:22:54 +00:00
|
|
|
Enables support---including auto-detection code---for the
|
|
|
|
specified archive format.
|
2005-01-08 19:51:04 +00:00
|
|
|
For example,
|
2004-02-09 23:22:54 +00:00
|
|
|
.Fn archive_read_support_format_tar
|
|
|
|
enables support for a variety of standard tar formats, old-style tar,
|
|
|
|
ustar, pax interchange format, and many common variants.
|
|
|
|
For convenience,
|
|
|
|
.Fn archive_read_support_format_all
|
|
|
|
enables support for all available formats.
|
2007-03-03 07:37:37 +00:00
|
|
|
Only empty archives are supported by default.
|
2009-04-27 20:13:13 +00:00
|
|
|
.It Fn archive_read_support_format_raw
|
|
|
|
The
|
|
|
|
.Dq raw
|
|
|
|
format handler allows libarchive to be used to read arbitrary data.
|
|
|
|
It treats any data stream as an archive with a single entry.
|
|
|
|
The pathname of this entry is
|
|
|
|
.Dq data ;
|
|
|
|
all other entry fields are unset.
|
|
|
|
This is not enabled by
|
|
|
|
.Fn archive_read_support_format_all
|
|
|
|
in order to avoid erroneous handling of damaged archives.
|
2009-04-17 01:02:12 +00:00
|
|
|
.It Xo
|
|
|
|
.Fn archive_read_set_filter_options ,
|
|
|
|
.Fn archive_read_set_format_options ,
|
|
|
|
.Fn archive_read_set_options
|
|
|
|
.Xc
|
|
|
|
Specifies options that will be passed to currently-registered
|
|
|
|
filters (including decompression filters) and/or format readers.
|
|
|
|
The argument is a comma-separated list of individual options.
|
|
|
|
Individual options have one of the following forms:
|
|
|
|
.Bl -tag -compact -width indent
|
|
|
|
.It Ar option=value
|
|
|
|
The option/value pair will be provided to every module.
|
|
|
|
Modules that do not accept an option with this name will ignore it.
|
|
|
|
.It Ar option
|
|
|
|
The option will be provided to every module with a value of
|
|
|
|
.Dq 1 .
|
|
|
|
.It Ar !option
|
|
|
|
The option will be provided to every module with a NULL value.
|
|
|
|
.It Ar module:option=value , Ar module:option , Ar module:!option
|
|
|
|
As above, but the corresponding option and value will be provided
|
|
|
|
only to modules whose name matches
|
|
|
|
.Ar module .
|
|
|
|
.El
|
|
|
|
The return value will be
|
|
|
|
.Cm ARCHIVE_OK
|
|
|
|
if any module accepts the option, or
|
|
|
|
.Cm ARCHIVE_WARN
|
|
|
|
if no module accepted the option, or
|
|
|
|
.Cm ARCHIVE_FATAL
|
|
|
|
if there was a fatal error while attempting to process the option.
|
|
|
|
.Pp
|
|
|
|
The currently supported options are:
|
|
|
|
.Bl -tag -compact -width indent
|
|
|
|
.It Format iso9660
|
|
|
|
.Bl -tag -compact -width indent
|
|
|
|
.It Cm joliet
|
|
|
|
Support Joliet extensions.
|
|
|
|
Defaults to enabled, use
|
|
|
|
.Cm !joliet
|
|
|
|
to disable.
|
|
|
|
.El
|
|
|
|
.El
|
2004-02-09 23:22:54 +00:00
|
|
|
.It Fn archive_read_open
|
2006-09-05 05:59:46 +00:00
|
|
|
The same as
|
|
|
|
.Fn archive_read_open2 ,
|
|
|
|
except that the skip callback is assumed to be
|
|
|
|
.Dv NULL .
|
|
|
|
.It Fn archive_read_open2
|
2004-02-09 23:22:54 +00:00
|
|
|
Freeze the settings, open the archive, and prepare for reading entries.
|
|
|
|
This is the most generic version of this call, which accepts
|
2006-09-05 05:59:46 +00:00
|
|
|
four callback functions.
|
2005-01-12 05:56:49 +00:00
|
|
|
Most clients will want to use
|
2006-11-24 05:34:23 +00:00
|
|
|
.Fn archive_read_open_filename ,
|
|
|
|
.Fn archive_read_open_FILE ,
|
|
|
|
.Fn archive_read_open_fd ,
|
2005-01-12 05:56:49 +00:00
|
|
|
or
|
2006-11-24 05:34:23 +00:00
|
|
|
.Fn archive_read_open_memory
|
2005-01-12 05:56:49 +00:00
|
|
|
instead.
|
|
|
|
The library invokes the client-provided functions to obtain
|
2004-02-09 23:22:54 +00:00
|
|
|
raw bytes from the archive.
|
2006-11-24 05:34:23 +00:00
|
|
|
.It Fn archive_read_open_FILE
|
|
|
|
Like
|
|
|
|
.Fn archive_read_open ,
|
|
|
|
except that it accepts a
|
|
|
|
.Ft "FILE *"
|
|
|
|
pointer.
|
|
|
|
This function should not be used with tape drives or other devices
|
|
|
|
that require strict I/O blocking.
|
2004-04-05 21:12:29 +00:00
|
|
|
.It Fn archive_read_open_fd
|
|
|
|
Like
|
|
|
|
.Fn archive_read_open ,
|
2005-01-12 05:56:49 +00:00
|
|
|
except that it accepts a file descriptor and block size rather than
|
2006-09-05 05:59:46 +00:00
|
|
|
a set of function pointers.
|
2004-04-05 21:12:29 +00:00
|
|
|
Note that the file descriptor will not be automatically closed at
|
|
|
|
end-of-archive.
|
2006-09-05 05:59:46 +00:00
|
|
|
This function is safe for use with tape drives or other blocked devices.
|
2004-02-09 23:22:54 +00:00
|
|
|
.It Fn archive_read_open_file
|
2006-11-20 16:48:04 +00:00
|
|
|
This is a deprecated synonym for
|
|
|
|
.Fn archive_read_open_filename .
|
|
|
|
.It Fn archive_read_open_filename
|
2004-02-09 23:22:54 +00:00
|
|
|
Like
|
|
|
|
.Fn archive_read_open ,
|
2005-01-12 05:56:49 +00:00
|
|
|
except that it accepts a simple filename and a block size.
|
2004-02-09 23:22:54 +00:00
|
|
|
A NULL filename represents standard input.
|
2006-09-05 05:59:46 +00:00
|
|
|
This function is safe for use with tape drives or other blocked devices.
|
2006-11-24 05:34:23 +00:00
|
|
|
.It Fn archive_read_open_memory
|
|
|
|
Like
|
|
|
|
.Fn archive_read_open ,
|
|
|
|
except that it accepts a pointer and size of a block of
|
|
|
|
memory containing the archive data.
|
2004-02-09 23:22:54 +00:00
|
|
|
.It Fn archive_read_next_header
|
|
|
|
Read the header for the next entry and return a pointer to
|
|
|
|
a
|
|
|
|
.Tn struct archive_entry .
|
2009-04-17 01:02:12 +00:00
|
|
|
This is a convenience wrapper around
|
|
|
|
.Fn archive_read_next_header2
|
2009-04-27 20:13:13 +00:00
|
|
|
that reuses an internal
|
2009-04-17 01:02:12 +00:00
|
|
|
.Tn struct archive_entry
|
2009-04-27 20:13:13 +00:00
|
|
|
object for each request.
|
2009-04-17 01:02:12 +00:00
|
|
|
.It Fn archive_read_next_header2
|
|
|
|
Read the header for the next entry and populate the provided
|
|
|
|
.Tn struct archive_entry .
|
2004-02-09 23:22:54 +00:00
|
|
|
.It Fn archive_read_data
|
|
|
|
Read data associated with the header just read.
|
2004-06-27 01:15:31 +00:00
|
|
|
Internally, this is a convenience function that calls
|
|
|
|
.Fn archive_read_data_block
|
|
|
|
and fills any gaps with nulls so that callers see a single
|
|
|
|
continuous stream of data.
|
2004-06-02 08:14:43 +00:00
|
|
|
.It Fn archive_read_data_block
|
|
|
|
Return the next available block of data for this entry.
|
|
|
|
Unlike
|
|
|
|
.Fn archive_read_data ,
|
|
|
|
the
|
|
|
|
.Fn archive_read_data_block
|
|
|
|
function avoids copying data and allows you to correctly handle
|
|
|
|
sparse files, as supported by some archive formats.
|
2005-07-31 03:30:48 +00:00
|
|
|
The library guarantees that offsets will increase and that blocks
|
2004-06-02 08:14:43 +00:00
|
|
|
will not overlap.
|
2005-01-12 05:56:49 +00:00
|
|
|
Note that the blocks returned from this function can be much larger
|
|
|
|
than the block size read from disk, due to compression
|
|
|
|
and internal buffer optimizations.
|
2004-02-09 23:22:54 +00:00
|
|
|
.It Fn archive_read_data_skip
|
|
|
|
A convenience function that repeatedly calls
|
2004-06-02 08:14:43 +00:00
|
|
|
.Fn archive_read_data_block
|
2004-02-09 23:22:54 +00:00
|
|
|
to skip all of the data for this archive entry.
|
2007-04-05 15:51:19 +00:00
|
|
|
.\" #if ARCHIVE_API_VERSION < 3
|
2004-02-09 23:22:54 +00:00
|
|
|
.It Fn archive_read_data_into_buffer
|
2007-04-07 05:53:11 +00:00
|
|
|
This function is deprecated and will be removed.
|
|
|
|
Use
|
|
|
|
.Fn archive_read_data
|
|
|
|
instead.
|
2007-04-05 15:51:19 +00:00
|
|
|
.\" #endif
|
2004-06-02 08:14:43 +00:00
|
|
|
.It Fn archive_read_data_into_fd
|
2004-02-09 23:22:54 +00:00
|
|
|
A convenience function that repeatedly calls
|
2004-06-02 08:14:43 +00:00
|
|
|
.Fn archive_read_data_block
|
2004-02-09 23:22:54 +00:00
|
|
|
to copy the entire entry to the provided file descriptor.
|
2007-03-03 07:37:37 +00:00
|
|
|
.It Fn archive_read_extract , Fn archive_read_extract_set_skip_file
|
|
|
|
A convenience function that wraps the corresponding
|
|
|
|
.Xr archive_write_disk 3
|
|
|
|
interfaces.
|
|
|
|
The first call to
|
2006-09-05 05:59:46 +00:00
|
|
|
.Fn archive_read_extract
|
2007-03-03 07:37:37 +00:00
|
|
|
creates a restore object using
|
|
|
|
.Xr archive_write_disk_new 3
|
|
|
|
and
|
|
|
|
.Xr archive_write_disk_set_standard_lookup 3 ,
|
|
|
|
then transparently invokes
|
|
|
|
.Xr archive_write_disk_set_options 3 ,
|
|
|
|
.Xr archive_write_header 3 ,
|
|
|
|
.Xr archive_write_data 3 ,
|
|
|
|
and
|
|
|
|
.Xr archive_write_finish_entry 3
|
|
|
|
to create the entry on disk and copy data into it.
|
2004-02-09 23:22:54 +00:00
|
|
|
The
|
|
|
|
.Va flags
|
2007-03-03 07:37:37 +00:00
|
|
|
argument is passed unmodified to
|
2007-09-19 16:37:45 +00:00
|
|
|
.Xr archive_write_disk_set_options 3 .
|
2008-05-26 17:00:24 +00:00
|
|
|
.It Fn archive_read_extract2
|
|
|
|
This is another version of
|
|
|
|
.Fn archive_read_extract
|
|
|
|
that allows you to provide your own restore object.
|
|
|
|
In particular, this allows you to override the standard lookup functions
|
|
|
|
using
|
|
|
|
.Xr archive_write_disk_set_group_lookup 3 ,
|
|
|
|
and
|
|
|
|
.Xr archive_write_disk_set_user_lookup 3 .
|
|
|
|
Note that
|
|
|
|
.Fn archive_read_extract2
|
|
|
|
does not accept a
|
|
|
|
.Va flags
|
|
|
|
argument; you should use
|
|
|
|
.Fn archive_write_disk_set_options
|
|
|
|
to set the restore options yourself.
|
2004-05-13 06:01:14 +00:00
|
|
|
.It Fn archive_read_extract_set_progress_callback
|
|
|
|
Sets a pointer to a user-defined callback that can be used
|
|
|
|
for updating progress displays during extraction.
|
|
|
|
The progress function will be invoked during the extraction of large
|
|
|
|
regular files.
|
|
|
|
The progress function will be invoked with the pointer provided to this call.
|
|
|
|
Generally, the data pointed to should include a reference to the archive
|
|
|
|
object and the archive_entry object so that various statistics
|
|
|
|
can be retrieved for the progress display.
|
2004-08-07 19:22:50 +00:00
|
|
|
.It Fn archive_read_close
|
|
|
|
Complete the archive and invoke the close callback.
|
2004-02-09 23:22:54 +00:00
|
|
|
.It Fn archive_read_finish
|
2004-08-07 19:22:50 +00:00
|
|
|
Invokes
|
|
|
|
.Fn archive_read_close
|
2005-07-31 03:30:48 +00:00
|
|
|
if it was not invoked manually, then release all resources.
|
2007-03-03 07:37:37 +00:00
|
|
|
Note: In libarchive 1.x, this function was declared to return
|
|
|
|
.Ft void ,
|
|
|
|
which made it impossible to detect certain errors when
|
|
|
|
.Fn archive_read_close
|
|
|
|
was invoked implicitly from this function.
|
|
|
|
The declaration is corrected beginning with libarchive 2.0.
|
2004-02-09 23:22:54 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
Note that the library determines most of the relevant information about
|
|
|
|
the archive by inspection.
|
|
|
|
In particular, it automatically detects
|
|
|
|
.Xr gzip 1
|
|
|
|
or
|
|
|
|
.Xr bzip2 1
|
|
|
|
compression and transparently performs the appropriate decompression.
|
|
|
|
It also automatically detects the archive format.
|
|
|
|
.Pp
|
2005-01-08 19:51:04 +00:00
|
|
|
A complete description of the
|
|
|
|
.Tn struct archive
|
|
|
|
and
|
|
|
|
.Tn struct archive_entry
|
|
|
|
objects can be found in the overview manual page for
|
|
|
|
.Xr libarchive 3 .
|
|
|
|
.Sh CLIENT CALLBACKS
|
2004-02-09 23:22:54 +00:00
|
|
|
The callback functions must match the following prototypes:
|
|
|
|
.Bl -item -offset indent
|
|
|
|
.It
|
|
|
|
.Ft typedef ssize_t
|
2008-03-10 14:45:29 +00:00
|
|
|
.Fo archive_read_callback
|
|
|
|
.Fa "struct archive *"
|
|
|
|
.Fa "void *client_data"
|
|
|
|
.Fa "const void **buffer"
|
|
|
|
.Fc
|
2004-02-09 23:22:54 +00:00
|
|
|
.It
|
2007-01-05 10:48:18 +00:00
|
|
|
.\" #if ARCHIVE_API_VERSION < 2
|
2004-02-09 23:22:54 +00:00
|
|
|
.Ft typedef int
|
2008-03-10 14:45:29 +00:00
|
|
|
.Fo archive_skip_callback
|
|
|
|
.Fa "struct archive *"
|
|
|
|
.Fa "void *client_data"
|
|
|
|
.Fa "size_t request"
|
|
|
|
.Fc
|
2007-01-05 10:48:18 +00:00
|
|
|
.\" #else
|
|
|
|
.\" .Ft typedef off_t
|
2008-03-10 14:45:29 +00:00
|
|
|
.\" .Fo archive_skip_callback
|
|
|
|
.\" .Fa "struct archive *"
|
|
|
|
.\" .Fa "void *client_data"
|
|
|
|
.\" .Fa "off_t request"
|
|
|
|
.\" .Fc
|
2007-01-05 10:48:18 +00:00
|
|
|
.\" #endif
|
2006-09-05 05:59:46 +00:00
|
|
|
.It
|
|
|
|
.Ft typedef int
|
2004-02-09 23:22:54 +00:00
|
|
|
.Fn archive_open_callback "struct archive *" "void *client_data"
|
|
|
|
.It
|
|
|
|
.Ft typedef int
|
|
|
|
.Fn archive_close_callback "struct archive *" "void *client_data"
|
|
|
|
.El
|
|
|
|
.Pp
|
2005-01-08 19:51:04 +00:00
|
|
|
The open callback is invoked by
|
|
|
|
.Fn archive_open .
|
|
|
|
It should return
|
|
|
|
.Cm ARCHIVE_OK
|
|
|
|
if the underlying file or data source is successfully
|
|
|
|
opened.
|
|
|
|
If the open fails, it should call
|
|
|
|
.Fn archive_set_error
|
|
|
|
to register an error code and message and return
|
|
|
|
.Cm ARCHIVE_FATAL .
|
|
|
|
.Pp
|
|
|
|
The read callback is invoked whenever the library
|
|
|
|
requires raw bytes from the archive.
|
|
|
|
The read callback should read data into a buffer,
|
|
|
|
set the
|
|
|
|
.Li const void **buffer
|
|
|
|
argument to point to the available data, and
|
|
|
|
return a count of the number of bytes available.
|
|
|
|
The library will invoke the read callback again
|
|
|
|
only after it has consumed this data.
|
|
|
|
The library imposes no constraints on the size
|
|
|
|
of the data blocks returned.
|
|
|
|
On end-of-file, the read callback should
|
|
|
|
return zero.
|
|
|
|
On error, the read callback should invoke
|
|
|
|
.Fn archive_set_error
|
|
|
|
to register an error code and message and
|
|
|
|
return -1.
|
|
|
|
.Pp
|
2006-09-05 05:59:46 +00:00
|
|
|
The skip callback is invoked when the
|
|
|
|
library wants to ignore a block of data.
|
|
|
|
The return value is the number of bytes actually
|
|
|
|
skipped, which may differ from the request.
|
|
|
|
If the callback cannot skip data, it should return
|
|
|
|
zero.
|
|
|
|
If the skip callback is not provided (the
|
|
|
|
function pointer is
|
|
|
|
.Dv NULL ),
|
|
|
|
the library will invoke the read function
|
|
|
|
instead and simply discard the result.
|
|
|
|
A skip callback can provide significant
|
|
|
|
performance gains when reading uncompressed
|
|
|
|
archives from slow disk drives or other media
|
|
|
|
that can skip quickly.
|
|
|
|
.Pp
|
2005-01-08 19:51:04 +00:00
|
|
|
The close callback is invoked by archive_close when
|
|
|
|
the archive processing is complete.
|
|
|
|
The callback should return
|
|
|
|
.Cm ARCHIVE_OK
|
|
|
|
on success.
|
|
|
|
On failure, the callback should invoke
|
|
|
|
.Fn archive_set_error
|
|
|
|
to register an error code and message and
|
2005-07-31 03:30:48 +00:00
|
|
|
return
|
2005-01-08 19:51:04 +00:00
|
|
|
.Cm ARCHIVE_FATAL.
|
2004-02-09 23:22:54 +00:00
|
|
|
.Sh EXAMPLE
|
2004-07-02 23:52:20 +00:00
|
|
|
The following illustrates basic usage of the library.
|
|
|
|
In this example,
|
2004-02-09 23:22:54 +00:00
|
|
|
the callback functions are simply wrappers around the standard
|
|
|
|
.Xr open 2 ,
|
|
|
|
.Xr read 2 ,
|
|
|
|
and
|
|
|
|
.Xr close 2
|
|
|
|
system calls.
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
void
|
|
|
|
list_archive(const char *name)
|
|
|
|
{
|
|
|
|
struct mydata *mydata;
|
|
|
|
struct archive *a;
|
|
|
|
struct archive_entry *entry;
|
|
|
|
|
|
|
|
mydata = malloc(sizeof(struct mydata));
|
|
|
|
a = archive_read_new();
|
|
|
|
mydata->name = name;
|
|
|
|
archive_read_support_compression_all(a);
|
|
|
|
archive_read_support_format_all(a);
|
|
|
|
archive_read_open(a, mydata, myopen, myread, myclose);
|
2004-06-08 00:23:27 +00:00
|
|
|
while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
|
2004-02-09 23:22:54 +00:00
|
|
|
printf("%s\\n",archive_entry_pathname(entry));
|
|
|
|
archive_read_data_skip(a);
|
|
|
|
}
|
|
|
|
archive_read_finish(a);
|
|
|
|
free(mydata);
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
myread(struct archive *a, void *client_data, const void **buff)
|
|
|
|
{
|
|
|
|
struct mydata *mydata = client_data;
|
|
|
|
|
|
|
|
*buff = mydata->buff;
|
|
|
|
return (read(mydata->fd, mydata->buff, 10240));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
myopen(struct archive *a, void *client_data)
|
|
|
|
{
|
|
|
|
struct mydata *mydata = client_data;
|
|
|
|
|
|
|
|
mydata->fd = open(mydata->name, O_RDONLY);
|
2005-05-21 19:38:19 +00:00
|
|
|
return (mydata->fd >= 0 ? ARCHIVE_OK : ARCHIVE_FATAL);
|
2004-02-09 23:22:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
myclose(struct archive *a, void *client_data)
|
|
|
|
{
|
|
|
|
struct mydata *mydata = client_data;
|
|
|
|
|
|
|
|
if (mydata->fd > 0)
|
|
|
|
close(mydata->fd);
|
2005-05-21 19:38:19 +00:00
|
|
|
return (ARCHIVE_OK);
|
2004-02-09 23:22:54 +00:00
|
|
|
}
|
|
|
|
.Ed
|
|
|
|
.Sh RETURN VALUES
|
|
|
|
Most functions return zero on success, non-zero on error.
|
|
|
|
The possible return codes include:
|
2004-06-08 00:23:27 +00:00
|
|
|
.Cm ARCHIVE_OK
|
2005-01-25 06:07:28 +00:00
|
|
|
(the operation succeeded),
|
2004-06-08 00:23:27 +00:00
|
|
|
.Cm ARCHIVE_WARN
|
2005-01-25 06:07:28 +00:00
|
|
|
(the operation succeeded but a non-critical error was encountered),
|
2004-06-08 00:23:27 +00:00
|
|
|
.Cm ARCHIVE_EOF
|
2004-05-27 04:21:52 +00:00
|
|
|
(end-of-archive was encountered),
|
2004-06-08 00:23:27 +00:00
|
|
|
.Cm ARCHIVE_RETRY
|
2004-02-09 23:22:54 +00:00
|
|
|
(the operation failed but can be retried),
|
|
|
|
and
|
2004-06-08 00:23:27 +00:00
|
|
|
.Cm ARCHIVE_FATAL
|
2004-02-09 23:22:54 +00:00
|
|
|
(there was a fatal error; the archive should be closed immediately).
|
|
|
|
Detailed error codes and textual descriptions are available from the
|
|
|
|
.Fn archive_errno
|
|
|
|
and
|
|
|
|
.Fn archive_error_string
|
|
|
|
functions.
|
|
|
|
.Pp
|
|
|
|
.Fn archive_read_new
|
|
|
|
returns a pointer to a freshly allocated
|
|
|
|
.Tn struct archive
|
|
|
|
object.
|
|
|
|
It returns
|
|
|
|
.Dv NULL
|
|
|
|
on error.
|
|
|
|
.Pp
|
|
|
|
.Fn archive_read_data
|
|
|
|
returns a count of bytes actually read or zero at the end of the entry.
|
|
|
|
On error, a value of
|
|
|
|
.Cm ARCHIVE_FATAL ,
|
|
|
|
.Cm ARCHIVE_WARN ,
|
|
|
|
or
|
|
|
|
.Cm ARCHIVE_RETRY
|
|
|
|
is returned and an error code and textual description can be retrieved from the
|
|
|
|
.Fn archive_errno
|
|
|
|
and
|
|
|
|
.Fn archive_error_string
|
|
|
|
functions.
|
|
|
|
.Pp
|
|
|
|
The library expects the client callbacks to behave similarly.
|
|
|
|
If there is an error, you can use
|
|
|
|
.Fn archive_set_error
|
|
|
|
to set an appropriate error code and description,
|
|
|
|
then return one of the non-zero values above.
|
|
|
|
(Note that the value eventually returned to the client may
|
|
|
|
not be the same; many errors that are not critical at the level
|
|
|
|
of basic I/O can prevent the archive from being properly read,
|
2004-05-27 04:21:52 +00:00
|
|
|
thus most I/O errors eventually cause
|
2004-02-09 23:22:54 +00:00
|
|
|
.Cm ARCHIVE_FATAL
|
|
|
|
to be returned.)
|
|
|
|
.\" .Sh ERRORS
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr tar 1 ,
|
|
|
|
.Xr archive 3 ,
|
2005-01-08 19:51:04 +00:00
|
|
|
.Xr archive_util 3 ,
|
2004-07-04 21:15:37 +00:00
|
|
|
.Xr tar 5
|
2004-02-09 23:22:54 +00:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Nm libarchive
|
|
|
|
library first appeared in
|
|
|
|
.Fx 5.3 .
|
|
|
|
.Sh AUTHORS
|
|
|
|
.An -nosplit
|
|
|
|
The
|
|
|
|
.Nm libarchive
|
|
|
|
library was written by
|
|
|
|
.An Tim Kientzle Aq kientzle@acm.org .
|
|
|
|
.Sh BUGS
|
2007-02-01 06:18:17 +00:00
|
|
|
Many traditional archiver programs treat
|
|
|
|
empty files as valid empty archives.
|
|
|
|
For example, many implementations of
|
|
|
|
.Xr tar 1
|
|
|
|
allow you to append entries to an empty file.
|
|
|
|
Of course, it is impossible to determine the format of an empty file
|
|
|
|
by inspecting the contents, so this library treats empty files as
|
|
|
|
having a special
|
|
|
|
.Dq empty
|
|
|
|
format.
|