Blame doc/man/archive_write_disk.3

Packit Service 1d0348
.TH ARCHIVE_WRITE_DISK 3 "April 3, 2017" ""
Packit Service 1d0348
.SH NAME
Packit Service 1d0348
.ad l
Packit Service 1d0348
\fB\%archive_write_disk_new\fP,
Packit Service 1d0348
\fB\%archive_write_disk_set_options\fP,
Packit Service 1d0348
\fB\%archive_write_disk_set_skip_file\fP,
Packit Service 1d0348
\fB\%archive_write_disk_set_group_lookup\fP,
Packit Service 1d0348
\fB\%archive_write_disk_set_standard_lookup\fP,
Packit Service 1d0348
\fB\%archive_write_disk_set_user_lookup\fP
Packit Service 1d0348
\- functions for creating objects on disk
Packit Service 1d0348
.SH LIBRARY
Packit Service 1d0348
.ad l
Packit Service 1d0348
Streaming Archive Library (libarchive, -larchive)
Packit Service 1d0348
.SH SYNOPSIS
Packit Service 1d0348
.ad l
Packit Service 1d0348
\fB#include <archive.h>\fP
Packit Service 1d0348
.br
Packit Service 1d0348
\fIstruct archive *\fP
Packit Service 1d0348
.br
Packit Service 1d0348
\fB\%archive_write_disk_new\fP(\fI\%void\fP);
Packit Service 1d0348
.br
Packit Service 1d0348
\fIint\fP
Packit Service 1d0348
.br
Packit Service 1d0348
\fB\%archive_write_disk_set_options\fP(\fI\%struct\ archive\ *\fP, \fI\%int\ flags\fP);
Packit Service 1d0348
.br
Packit Service 1d0348
\fIint\fP
Packit Service 1d0348
.br
Packit Service 1d0348
\fB\%archive_write_disk_set_skip_file\fP(\fI\%struct\ archive\ *\fP, \fI\%dev_t\fP, \fI\%ino_t\fP);
Packit Service 1d0348
.br
Packit Service 1d0348
\fIint\fP
Packit Service 1d0348
.br
Packit Service 1d0348
\fB\%archive_write_disk_set_group_lookup\fP(\fI\%struct\ archive\ *\fP, \fI\%void\ *\fP, \fI\%gid_t\ (*)(void\ *,\ const\ char\ *gname,\ gid_t\ gid)\fP, \fI\%void\ (*cleanup)(void\ *)\fP);
Packit Service 1d0348
.br
Packit Service 1d0348
\fIint\fP
Packit Service 1d0348
.br
Packit Service 1d0348
\fB\%archive_write_disk_set_standard_lookup\fP(\fI\%struct\ archive\ *\fP);
Packit Service 1d0348
.br
Packit Service 1d0348
\fIint\fP
Packit Service 1d0348
.br
Packit Service 1d0348
\fB\%archive_write_disk_set_user_lookup\fP(\fI\%struct\ archive\ *\fP, \fI\%void\ *\fP, \fI\%uid_t\ (*)(void\ *,\ const\ char\ *uname,\ uid_t\ uid)\fP, \fI\%void\ (*cleanup)(void\ *)\fP);
Packit Service 1d0348
.SH DESCRIPTION
Packit Service 1d0348
.ad l
Packit Service 1d0348
These functions provide a complete API for creating objects on
Packit Service 1d0348
disk from
Packit Service 1d0348
Tn struct archive_entry
Packit Service 1d0348
descriptions.
Packit Service 1d0348
They are most naturally used when extracting objects from an archive
Packit Service 1d0348
using the
Packit Service 1d0348
\fB\%archive_read\fP()
Packit Service 1d0348
interface.
Packit Service 1d0348
The general process is to read
Packit Service 1d0348
Tn struct archive_entry
Packit Service 1d0348
objects from an archive, then write those objects to a
Packit Service 1d0348
Tn struct archive
Packit Service 1d0348
object created using the
Packit Service 1d0348
\fB\%archive_write_disk\fP()
Packit Service 1d0348
family functions.
Packit Service 1d0348
This interface is deliberately very similar to the
Packit Service 1d0348
\fB\%archive_write\fP()
Packit Service 1d0348
interface used to write objects to a streaming archive.
Packit Service 1d0348
.RS 5
Packit Service 1d0348
.TP
Packit Service 1d0348
\fB\%archive_write_disk_new\fP()
Packit Service 1d0348
Allocates and initializes a
Packit Service 1d0348
Tn struct archive
Packit Service 1d0348
object suitable for writing objects to disk.
Packit Service 1d0348
.TP
Packit Service 1d0348
\fB\%archive_write_disk_set_skip_file\fP()
Packit Service 1d0348
Records the device and inode numbers of a file that should not be
Packit Service 1d0348
overwritten.
Packit Service 1d0348
This is typically used to ensure that an extraction process does not
Packit Service 1d0348
overwrite the archive from which objects are being read.
Packit Service 1d0348
This capability is technically unnecessary but can be a significant
Packit Service 1d0348
performance optimization in practice.
Packit Service 1d0348
.TP
Packit Service 1d0348
\fB\%archive_write_disk_set_options\fP()
Packit Service 1d0348
The options field consists of a bitwise OR of one or more of the
Packit Service 1d0348
following values:
Packit Service 1d0348
.RS 5
Packit Service 1d0348
.TP
Packit Service 1d0348
\fBARCHIVE_EXTRACT_ACL\fP
Packit Service 1d0348
Attempt to restore Access Control Lists.
Packit Service 1d0348
By default, extended ACLs are ignored.
Packit Service 1d0348
.TP
Packit Service 1d0348
\fBARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS\fP
Packit Service 1d0348
Before removing a file system object prior to replacing it, clear
Packit Service 1d0348
platform-specific file flags which might prevent its removal.
Packit Service 1d0348
.TP
Packit Service 1d0348
\fBARCHIVE_EXTRACT_FFLAGS\fP
Packit Service 1d0348
Attempt to restore file attributes (file flags).
Packit Service 1d0348
By default, file attributes are ignored.
Packit Service 1d0348
See
Packit Service 1d0348
\fBchattr\fP(1)
Packit Service 1d0348
(Linux)
Packit Service 1d0348
or
Packit Service 1d0348
\fBchflags\fP(1)
Packit Service 1d0348
(FreeBSD, Mac OS X)
Packit Service 1d0348
for more information on file attributes.
Packit Service 1d0348
.TP
Packit Service 1d0348
\fBARCHIVE_EXTRACT_MAC_METADATA\fP
Packit Service 1d0348
Mac OS X specific. Restore metadata using
Packit Service 1d0348
\fBcopyfile\fP(3).
Packit Service 1d0348
By default,
Packit Service 1d0348
\fBcopyfile\fP(3)
Packit Service 1d0348
metadata is ignored.
Packit Service 1d0348
.TP
Packit Service 1d0348
\fBARCHIVE_EXTRACT_NO_OVERWRITE\fP
Packit Service 1d0348
Existing files on disk will not be overwritten.
Packit Service 1d0348
By default, existing regular files are truncated and overwritten;
Packit Service 1d0348
existing directories will have their permissions updated;
Packit Service 1d0348
other pre-existing objects are unlinked and recreated from scratch.
Packit Service 1d0348
.TP
Packit Service 1d0348
\fBARCHIVE_EXTRACT_OWNER\fP
Packit Service 1d0348
The user and group IDs should be set on the restored file.
Packit Service 1d0348
By default, the user and group IDs are not restored.
Packit Service 1d0348
.TP
Packit Service 1d0348
\fBARCHIVE_EXTRACT_PERM\fP
Packit Service 1d0348
Full permissions (including SGID, SUID, and sticky bits) should
Packit Service 1d0348
be restored exactly as specified, without obeying the
Packit Service 1d0348
current umask.
Packit Service 1d0348
Note that SUID and SGID bits can only be restored if the
Packit Service 1d0348
user and group ID of the object on disk are correct.
Packit Service 1d0348
If
Packit Service 1d0348
\fBARCHIVE_EXTRACT_OWNER\fP
Packit Service 1d0348
is not specified, then SUID and SGID bits will only be restored
Packit Service 1d0348
if the default user and group IDs of newly-created objects on disk
Packit Service 1d0348
happen to match those specified in the archive entry.
Packit Service 1d0348
By default, only basic permissions are restored, and umask is obeyed.
Packit Service 1d0348
.TP
Packit Service 1d0348
\fBARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS\fP
Packit Service 1d0348
Refuse to extract an absolute path.
Packit Service 1d0348
The default is to not refuse such paths.
Packit Service 1d0348
.TP
Packit Service 1d0348
\fBARCHIVE_EXTRACT_SECURE_NODOTDOT\fP
Packit Service 1d0348
Refuse to extract a path that contains a
Packit Service 1d0348
\fI\& ..\fP
Packit Service 1d0348
element anywhere within it.
Packit Service 1d0348
The default is to not refuse such paths.
Packit Service 1d0348
Note that paths ending in
Packit Service 1d0348
\fI\& ..\fP
Packit Service 1d0348
always cause an error, regardless of this flag.
Packit Service 1d0348
.TP
Packit Service 1d0348
\fBARCHIVE_EXTRACT_SECURE_SYMLINKS\fP
Packit Service 1d0348
Refuse to extract any object whose final location would be altered
Packit Service 1d0348
by a symlink on disk.
Packit Service 1d0348
This is intended to help guard against a variety of mischief
Packit Service 1d0348
caused by archives that (deliberately or otherwise) extract
Packit Service 1d0348
files outside of the current directory.
Packit Service 1d0348
The default is not to perform this check.
Packit Service 1d0348
If
Packit Service 1d0348
.TP
Packit Service 1d0348
\fBARCHIVE_EXTRACT_SPARSE\fP
Packit Service 1d0348
Scan data for blocks of NUL bytes and try to recreate them with holes.
Packit Service 1d0348
This results in sparse files, independent of whether the archive format
Packit Service 1d0348
supports or uses them.
Packit Service 1d0348
\fBARCHIVE_EXTRACT_UNLINK\fP
Packit Service 1d0348
is specified together with this option, the library will
Packit Service 1d0348
remove any intermediate symlinks it finds and return an
Packit Service 1d0348
error only if such symlink could not be removed.
Packit Service 1d0348
.TP
Packit Service 1d0348
\fBARCHIVE_EXTRACT_TIME\fP
Packit Service 1d0348
The timestamps (mtime, ctime, and atime) should be restored.
Packit Service 1d0348
By default, they are ignored.
Packit Service 1d0348
Note that restoring of atime is not currently supported.
Packit Service 1d0348
.TP
Packit Service 1d0348
\fBARCHIVE_EXTRACT_UNLINK\fP
Packit Service 1d0348
Existing files on disk will be unlinked before any attempt to
Packit Service 1d0348
create them.
Packit Service 1d0348
In some cases, this can prove to be a significant performance improvement.
Packit Service 1d0348
By default, existing files are truncated and rewritten, but
Packit Service 1d0348
the file is not recreated.
Packit Service 1d0348
In particular, the default behavior does not break existing hard links.
Packit Service 1d0348
.TP
Packit Service 1d0348
\fBARCHIVE_EXTRACT_XATTR\fP
Packit Service 1d0348
Attempt to restore extended file attributes.
Packit Service 1d0348
By default, they are ignored.
Packit Service 1d0348
See
Packit Service 1d0348
\fBxattr\fP(7)
Packit Service 1d0348
(Linux,)
Packit Service 1d0348
\fBxattr\fP(2)
Packit Service 1d0348
(Mac OS X,)
Packit Service 1d0348
or
Packit Service 1d0348
\fBgetextattr\fP(8)
Packit Service 1d0348
(FreeBSD)
Packit Service 1d0348
for more information on extended file attributes.
Packit Service 1d0348
.RE
Packit Service 1d0348
.TP
Packit Service 1d0348
\fB\%archive_write_disk_set_group_lookup\fP(),
Packit Service 1d0348
\fB\%archive_write_disk_set_user_lookup\fP()
Packit Service 1d0348
The
Packit Service 1d0348
Tn struct archive_entry
Packit Service 1d0348
objects contain both names and ids that can be used to identify users
Packit Service 1d0348
and groups.
Packit Service 1d0348
These names and ids describe the ownership of the file itself and
Packit Service 1d0348
also appear in ACL lists.
Packit Service 1d0348
By default, the library uses the ids and ignores the names, but
Packit Service 1d0348
this can be overridden by registering user and group lookup functions.
Packit Service 1d0348
To register, you must provide a lookup function which
Packit Service 1d0348
accepts both a name and id and returns a suitable id.
Packit Service 1d0348
You may also provide a
Packit Service 1d0348
Tn void *
Packit Service 1d0348
pointer to a private data structure and a cleanup function for
Packit Service 1d0348
that data.
Packit Service 1d0348
The cleanup function will be invoked when the
Packit Service 1d0348
Tn struct archive
Packit Service 1d0348
object is destroyed.
Packit Service 1d0348
.TP
Packit Service 1d0348
\fB\%archive_write_disk_set_standard_lookup\fP()
Packit Service 1d0348
This convenience function installs a standard set of user
Packit Service 1d0348
and group lookup functions.
Packit Service 1d0348
These functions use
Packit Service 1d0348
\fBgetpwnam\fP(3)
Packit Service 1d0348
and
Packit Service 1d0348
\fBgetgrnam\fP(3)
Packit Service 1d0348
to convert names to ids, defaulting to the ids if the names cannot
Packit Service 1d0348
be looked up.
Packit Service 1d0348
These functions also implement a simple memory cache to reduce
Packit Service 1d0348
the number of calls to
Packit Service 1d0348
\fBgetpwnam\fP(3)
Packit Service 1d0348
and
Packit Service 1d0348
\fBgetgrnam\fP(3).
Packit Service 1d0348
.RE
Packit Service 1d0348
More information about the
Packit Service 1d0348
\fIstruct\fP archive
Packit Service 1d0348
object and the overall design of the library can be found in the
Packit Service 1d0348
\fBlibarchive\fP(3)
Packit Service 1d0348
overview.
Packit Service 1d0348
Many of these functions are also documented under
Packit Service 1d0348
\fBarchive_write\fP(3).
Packit Service 1d0348
.SH RETURN VALUES
Packit Service 1d0348
.ad l
Packit Service 1d0348
Most functions return
Packit Service 1d0348
\fBARCHIVE_OK\fP
Packit Service 1d0348
(zero) on success, or one of several non-zero
Packit Service 1d0348
error codes for errors.
Packit Service 1d0348
Specific error codes include:
Packit Service 1d0348
\fBARCHIVE_RETRY\fP
Packit Service 1d0348
for operations that might succeed if retried,
Packit Service 1d0348
\fBARCHIVE_WARN\fP
Packit Service 1d0348
for unusual conditions that do not prevent further operations, and
Packit Service 1d0348
\fBARCHIVE_FATAL\fP
Packit Service 1d0348
for serious errors that make remaining operations impossible.
Packit Service 1d0348
.PP
Packit Service 1d0348
\fB\%archive_write_disk_new\fP()
Packit Service 1d0348
returns a pointer to a newly-allocated
Packit Service 1d0348
Tn struct archive
Packit Service 1d0348
object.
Packit Service 1d0348
.PP
Packit Service 1d0348
\fB\%archive_write_data\fP()
Packit Service 1d0348
returns a count of the number of bytes actually written,
Packit Service 1d0348
or
Packit Service 1d0348
.RS 4
Packit Service 1d0348
-1
Packit Service 1d0348
.RE
Packit Service 1d0348
on error.
Packit Service 1d0348
.SH ERRORS
Packit Service 1d0348
.ad l
Packit Service 1d0348
Detailed error codes and textual descriptions are available from the
Packit Service 1d0348
\fB\%archive_errno\fP()
Packit Service 1d0348
and
Packit Service 1d0348
\fB\%archive_error_string\fP()
Packit Service 1d0348
functions.
Packit Service 1d0348
.SH SEE ALSO
Packit Service 1d0348
.ad l
Packit Service 1d0348
\fBarchive_read\fP(3),
Packit Service 1d0348
\fBarchive_write\fP(3),
Packit Service 1d0348
\fBtar\fP(1),
Packit Service 1d0348
\fBlibarchive\fP(3)
Packit Service 1d0348
.SH HISTORY
Packit Service 1d0348
.ad l
Packit Service 1d0348
The
Packit Service 1d0348
\fB\%libarchive\fP
Packit Service 1d0348
library first appeared in
Packit Service 1d0348
FreeBSD 5.3.
Packit Service 1d0348
The
Packit Service 1d0348
\fB\%archive_write_disk\fP
Packit Service 1d0348
interface was added to
Packit Service 1d0348
\fB\%libarchive\fP 2.0
Packit Service 1d0348
and first appeared in
Packit Service 1d0348
FreeBSD 6.3.
Packit Service 1d0348
.SH AUTHORS
Packit Service 1d0348
.ad l
Packit Service 1d0348
-nosplit
Packit Service 1d0348
The
Packit Service 1d0348
\fB\%libarchive\fP
Packit Service 1d0348
library was written by
Packit Service 1d0348
Tim Kientzle \%<kientzle@acm.org.>
Packit Service 1d0348
.SH BUGS
Packit Service 1d0348
.ad l
Packit Service 1d0348
Directories are actually extracted in two distinct phases.
Packit Service 1d0348
Directories are created during
Packit Service 1d0348
\fB\%archive_write_header\fP(),
Packit Service 1d0348
but final permissions are not set until
Packit Service 1d0348
\fB\%archive_write_close\fP().
Packit Service 1d0348
This separation is necessary to correctly handle borderline
Packit Service 1d0348
cases such as a non-writable directory containing
Packit Service 1d0348
files, but can cause unexpected results.
Packit Service 1d0348
In particular, directory permissions are not fully
Packit Service 1d0348
restored until the archive is closed.
Packit Service 1d0348
If you use
Packit Service 1d0348
\fBchdir\fP(2)
Packit Service 1d0348
to change the current directory between calls to
Packit Service 1d0348
\fB\%archive_read_extract\fP()
Packit Service 1d0348
or before calling
Packit Service 1d0348
\fB\%archive_read_close\fP(),
Packit Service 1d0348
you may confuse the permission-setting logic with
Packit Service 1d0348
the result that directory permissions are restored
Packit Service 1d0348
incorrectly.
Packit Service 1d0348
.PP
Packit Service 1d0348
The library attempts to create objects with filenames longer than
Packit Service 1d0348
\fBPATH_MAX\fP
Packit Service 1d0348
by creating prefixes of the full path and changing the current directory.
Packit Service 1d0348
Currently, this logic is limited in scope; the fixup pass does
Packit Service 1d0348
not work correctly for such objects and the symlink security check
Packit Service 1d0348
option disables the support for very long pathnames.
Packit Service 1d0348
.PP
Packit Service 1d0348
Restoring the path
Packit Service 1d0348
\fIaa/../bb\fP
Packit Service 1d0348
does create each intermediate directory.
Packit Service 1d0348
In particular, the directory
Packit Service 1d0348
\fIaa\fP
Packit Service 1d0348
is created as well as the final object
Packit Service 1d0348
\fIbb\fP.
Packit Service 1d0348
In theory, this can be exploited to create an entire directory hierarchy
Packit Service 1d0348
with a single request.
Packit Service 1d0348
Of course, this does not work if the
Packit Service 1d0348
\fBARCHIVE_EXTRACT_NODOTDOT\fP
Packit Service 1d0348
option is specified.
Packit Service 1d0348
.PP
Packit Service 1d0348
Implicit directories are always created obeying the current umask.
Packit Service 1d0348
Explicit objects are created obeying the current umask unless
Packit Service 1d0348
\fBARCHIVE_EXTRACT_PERM\fP
Packit Service 1d0348
is specified, in which case they current umask is ignored.
Packit Service 1d0348
.PP
Packit Service 1d0348
SGID and SUID bits are restored only if the correct user and
Packit Service 1d0348
group could be set.
Packit Service 1d0348
If
Packit Service 1d0348
\fBARCHIVE_EXTRACT_OWNER\fP
Packit Service 1d0348
is not specified, then no attempt is made to set the ownership.
Packit Service 1d0348
In this case, SGID and SUID bits are restored only if the
Packit Service 1d0348
user and group of the final object happen to match those specified
Packit Service 1d0348
in the entry.
Packit Service 1d0348
.PP
Packit Service 1d0348
The
Packit Service 1d0348
``standard''
Packit Service 1d0348
user-id and group-id lookup functions are not the defaults because
Packit Service 1d0348
\fBgetgrnam\fP(3)
Packit Service 1d0348
and
Packit Service 1d0348
\fBgetpwnam\fP(3)
Packit Service 1d0348
are sometimes too large for particular applications.
Packit Service 1d0348
The current design allows the application author to use a more
Packit Service 1d0348
compact implementation when appropriate.
Packit Service 1d0348
.PP
Packit Service 1d0348
There should be a corresponding
Packit Service 1d0348
\fB\%archive_read_disk\fP
Packit Service 1d0348
interface that walks a directory hierarchy and returns archive
Packit Service 1d0348
entry objects.