Blame doc/text/archive_write_disk.3.txt

Packit Service 1d0348
ARCHIVE_WRITE_DISK(3)	 BSD Library Functions Manual	 ARCHIVE_WRITE_DISK(3)
Packit Service 1d0348
Packit Service 1d0348
NAME
Packit Service 1d0348
     archive_write_disk_new, archive_write_disk_set_options,
Packit Service 1d0348
     archive_write_disk_set_skip_file, archive_write_disk_set_group_lookup,
Packit Service 1d0348
     archive_write_disk_set_standard_lookup,
Packit Service 1d0348
     archive_write_disk_set_user_lookup — functions for creating objects on
Packit Service 1d0348
     disk
Packit Service 1d0348
Packit Service 1d0348
LIBRARY
Packit Service 1d0348
     Streaming Archive Library (libarchive, -larchive)
Packit Service 1d0348
Packit Service 1d0348
SYNOPSIS
Packit Service 1d0348
     #include <archive.h>
Packit Service 1d0348
Packit Service 1d0348
     struct archive *
Packit Service 1d0348
     archive_write_disk_new(void);
Packit Service 1d0348
Packit Service 1d0348
     int
Packit Service 1d0348
     archive_write_disk_set_options(struct archive *, int flags);
Packit Service 1d0348
Packit Service 1d0348
     int
Packit Service 1d0348
     archive_write_disk_set_skip_file(struct archive *, dev_t, ino_t);
Packit Service 1d0348
Packit Service 1d0348
     int
Packit Service 1d0348
     archive_write_disk_set_group_lookup(struct archive *, void *,
Packit Service 1d0348
	 gid_t (*)(void *, const char *gname, gid_t gid),
Packit Service 1d0348
	 void (*cleanup)(void *));
Packit Service 1d0348
Packit Service 1d0348
     int
Packit Service 1d0348
     archive_write_disk_set_standard_lookup(struct archive *);
Packit Service 1d0348
Packit Service 1d0348
     int
Packit Service 1d0348
     archive_write_disk_set_user_lookup(struct archive *, void *,
Packit Service 1d0348
	 uid_t (*)(void *, const char *uname, uid_t uid),
Packit Service 1d0348
	 void (*cleanup)(void *));
Packit Service 1d0348
Packit Service 1d0348
DESCRIPTION
Packit Service 1d0348
     These functions provide a complete API for creating objects on disk from
Packit Service 1d0348
     struct archive_entry descriptions.  They are most naturally used when
Packit Service 1d0348
     extracting objects from an archive using the archive_read() interface.
Packit Service 1d0348
     The general process is to read struct archive_entry objects from an ar‐
Packit Service 1d0348
     chive, then write those objects to a struct archive object created using
Packit Service 1d0348
     the archive_write_disk() family functions.  This interface is deliber‐
Packit Service 1d0348
     ately very similar to the archive_write() interface used to write objects
Packit Service 1d0348
     to a streaming archive.
Packit Service 1d0348
Packit Service 1d0348
     archive_write_disk_new()
Packit Service 1d0348
	     Allocates and initializes a struct archive object suitable for
Packit Service 1d0348
	     writing objects to disk.
Packit Service 1d0348
Packit Service 1d0348
     archive_write_disk_set_skip_file()
Packit Service 1d0348
	     Records the device and inode numbers of a file that should not be
Packit Service 1d0348
	     overwritten.  This is typically used to ensure that an extraction
Packit Service 1d0348
	     process does not overwrite the archive from which objects are
Packit Service 1d0348
	     being read.  This capability is technically unnecessary but can
Packit Service 1d0348
	     be a significant performance optimization in practice.
Packit Service 1d0348
Packit Service 1d0348
     archive_write_disk_set_options()
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
	     ARCHIVE_EXTRACT_ACL
Packit Service 1d0348
		     Attempt to restore Access Control Lists.  By default,
Packit Service 1d0348
		     extended ACLs are ignored.
Packit Service 1d0348
	     ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS
Packit Service 1d0348
		     Before removing a file system object prior to replacing
Packit Service 1d0348
		     it, clear platform-specific file flags which might pre‐
Packit Service 1d0348
		     vent its removal.
Packit Service 1d0348
	     ARCHIVE_EXTRACT_FFLAGS
Packit Service 1d0348
		     Attempt to restore file attributes (file flags).  By
Packit Service 1d0348
		     default, file attributes are ignored.  See chattr(1)
Packit Service 1d0348
		     (Linux) or chflags(1) (FreeBSD, Mac OS X) for more infor‐
Packit Service 1d0348
		     mation on file attributes.
Packit Service 1d0348
	     ARCHIVE_EXTRACT_MAC_METADATA
Packit Service 1d0348
		     Mac OS X specific. Restore metadata using copyfile(3).
Packit Service 1d0348
		     By default, copyfile(3) metadata is ignored.
Packit Service 1d0348
	     ARCHIVE_EXTRACT_NO_OVERWRITE
Packit Service 1d0348
		     Existing files on disk will not be overwritten.  By
Packit Service 1d0348
		     default, existing regular files are truncated and over‐
Packit Service 1d0348
		     written; existing directories will have their permissions
Packit Service 1d0348
		     updated; other pre-existing objects are unlinked and
Packit Service 1d0348
		     recreated from scratch.
Packit Service 1d0348
	     ARCHIVE_EXTRACT_OWNER
Packit Service 1d0348
		     The user and group IDs should be set on the restored
Packit Service 1d0348
		     file.  By default, the user and group IDs are not
Packit Service 1d0348
		     restored.
Packit Service 1d0348
	     ARCHIVE_EXTRACT_PERM
Packit Service 1d0348
		     Full permissions (including SGID, SUID, and sticky bits)
Packit Service 1d0348
		     should be restored exactly as specified, without obeying
Packit Service 1d0348
		     the current umask.  Note that SUID and SGID bits can only
Packit Service 1d0348
		     be restored if the user and group ID of the object on
Packit Service 1d0348
		     disk are correct.	If ARCHIVE_EXTRACT_OWNER is not speci‐
Packit Service 1d0348
		     fied, then SUID and SGID bits will only be restored if
Packit Service 1d0348
		     the default user and group IDs of newly-created objects
Packit Service 1d0348
		     on disk happen to match those specified in the archive
Packit Service 1d0348
		     entry.  By default, only basic permissions are restored,
Packit Service 1d0348
		     and umask is obeyed.
Packit Service 1d0348
	     ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS
Packit Service 1d0348
		     Refuse to extract an absolute path.  The default is to
Packit Service 1d0348
		     not refuse such paths.
Packit Service 1d0348
	     ARCHIVE_EXTRACT_SECURE_NODOTDOT
Packit Service 1d0348
		     Refuse to extract a path that contains a .. element any‐
Packit Service 1d0348
		     where within it.  The default is to not refuse such
Packit Service 1d0348
		     paths.  Note that paths ending in .. always cause an
Packit Service 1d0348
		     error, regardless of this flag.
Packit Service 1d0348
	     ARCHIVE_EXTRACT_SECURE_SYMLINKS
Packit Service 1d0348
		     Refuse to extract any object whose final location would
Packit Service 1d0348
		     be altered by a symlink on disk.  This is intended to
Packit Service 1d0348
		     help guard against a variety of mischief caused by ar‐
Packit Service 1d0348
		     chives that (deliberately or otherwise) extract files
Packit Service 1d0348
		     outside of the current directory.	The default is not to
Packit Service 1d0348
		     perform this check.  If
Packit Service 1d0348
	     ARCHIVE_EXTRACT_SPARSE
Packit Service 1d0348
		     Scan data for blocks of NUL bytes and try to recreate
Packit Service 1d0348
		     them with holes.  This results in sparse files, indepen‐
Packit Service 1d0348
		     dent of whether the archive format supports or uses them.
Packit Service 1d0348
		     ARCHIVE_EXTRACT_UNLINK is specified together with this
Packit Service 1d0348
		     option, the library will remove any intermediate symlinks
Packit Service 1d0348
		     it finds and return an error only if such symlink could
Packit Service 1d0348
		     not be removed.
Packit Service 1d0348
	     ARCHIVE_EXTRACT_TIME
Packit Service 1d0348
		     The timestamps (mtime, ctime, and atime) should be
Packit Service 1d0348
		     restored.	By default, they are ignored.  Note that
Packit Service 1d0348
		     restoring of atime is not currently supported.
Packit Service 1d0348
	     ARCHIVE_EXTRACT_UNLINK
Packit Service 1d0348
		     Existing files on disk will be unlinked before any
Packit Service 1d0348
		     attempt to create them.  In some cases, this can prove to
Packit Service 1d0348
		     be a significant performance improvement.	By default,
Packit Service 1d0348
		     existing files are truncated and rewritten, but the file
Packit Service 1d0348
		     is not recreated.	In particular, the default behavior
Packit Service 1d0348
		     does not break existing hard links.
Packit Service 1d0348
	     ARCHIVE_EXTRACT_XATTR
Packit Service 1d0348
		     Attempt to restore extended file attributes.  By default,
Packit Service 1d0348
		     they are ignored.	See xattr(7) (Linux), xattr(2) (Mac OS
Packit Service 1d0348
		     X), or getextattr(8) (FreeBSD) for more information on
Packit Service 1d0348
		     extended file attributes.
Packit Service 1d0348
Packit Service 1d0348
     archive_write_disk_set_group_lookup(),
Packit Service 1d0348
	     archive_write_disk_set_user_lookup()
Packit Service 1d0348
	     The struct archive_entry objects contain both names and ids that
Packit Service 1d0348
	     can be used to identify users and groups.	These names and ids
Packit Service 1d0348
	     describe the ownership of the file itself and also appear in ACL
Packit Service 1d0348
	     lists.  By default, the library uses the ids and ignores the
Packit Service 1d0348
	     names, but this can be overridden by registering user and group
Packit Service 1d0348
	     lookup functions.	To register, you must provide a lookup func‐
Packit Service 1d0348
	     tion which accepts both a name and id and returns a suitable id.
Packit Service 1d0348
	     You may also provide a void * pointer to a private data structure
Packit Service 1d0348
	     and a cleanup function for that data.  The cleanup function will
Packit Service 1d0348
	     be invoked when the struct archive object is destroyed.
Packit Service 1d0348
Packit Service 1d0348
     archive_write_disk_set_standard_lookup()
Packit Service 1d0348
	     This convenience function installs a standard set of user and
Packit Service 1d0348
	     group lookup functions.  These functions use getpwnam(3) and
Packit Service 1d0348
	     getgrnam(3) to convert names to ids, defaulting to the ids if the
Packit Service 1d0348
	     names cannot be looked up.  These functions also implement a sim‐
Packit Service 1d0348
	     ple memory cache to reduce the number of calls to getpwnam(3) and
Packit Service 1d0348
	     getgrnam(3).
Packit Service 1d0348
     More information about the struct archive object and the overall design
Packit Service 1d0348
     of the library can be found in the libarchive(3) overview.  Many of these
Packit Service 1d0348
     functions are also documented under archive_write(3).
Packit Service 1d0348
Packit Service 1d0348
RETURN VALUES
Packit Service 1d0348
     Most functions return ARCHIVE_OK (zero) on success, or one of several
Packit Service 1d0348
     non-zero error codes for errors.  Specific error codes include:
Packit Service 1d0348
     ARCHIVE_RETRY for operations that might succeed if retried, ARCHIVE_WARN
Packit Service 1d0348
     for unusual conditions that do not prevent further operations, and
Packit Service 1d0348
     ARCHIVE_FATAL for serious errors that make remaining operations impossi‐
Packit Service 1d0348
     ble.
Packit Service 1d0348
Packit Service 1d0348
     archive_write_disk_new() returns a pointer to a newly-allocated struct
Packit Service 1d0348
     archive object.
Packit Service 1d0348
Packit Service 1d0348
     archive_write_data() returns a count of the number of bytes actually
Packit Service 1d0348
     written, or -1 on error.
Packit Service 1d0348
Packit Service 1d0348
ERRORS
Packit Service 1d0348
     Detailed error codes and textual descriptions are available from the
Packit Service 1d0348
     archive_errno() and archive_error_string() functions.
Packit Service 1d0348
Packit Service 1d0348
SEE ALSO
Packit Service 1d0348
     archive_read(3), archive_write(3), tar(1), libarchive(3)
Packit Service 1d0348
Packit Service 1d0348
HISTORY
Packit Service 1d0348
     The libarchive library first appeared in FreeBSD 5.3.  The
Packit Service 1d0348
     archive_write_disk interface was added to libarchive 2.0 and first
Packit Service 1d0348
     appeared in FreeBSD 6.3.
Packit Service 1d0348
Packit Service 1d0348
AUTHORS
Packit Service 1d0348
     The libarchive library was written by Tim Kientzle <kientzle@acm.org>.
Packit Service 1d0348
Packit Service 1d0348
BUGS
Packit Service 1d0348
     Directories are actually extracted in two distinct phases.  Directories
Packit Service 1d0348
     are created during archive_write_header(), but final permissions are not
Packit Service 1d0348
     set until archive_write_close().  This separation is necessary to cor‐
Packit Service 1d0348
     rectly handle borderline cases such as a non-writable directory contain‐
Packit Service 1d0348
     ing files, but can cause unexpected results.  In particular, directory
Packit Service 1d0348
     permissions are not fully restored until the archive is closed.  If you
Packit Service 1d0348
     use chdir(2) to change the current directory between calls to
Packit Service 1d0348
     archive_read_extract() or before calling archive_read_close(), you may
Packit Service 1d0348
     confuse the permission-setting logic with the result that directory per‐
Packit Service 1d0348
     missions are restored incorrectly.
Packit Service 1d0348
Packit Service 1d0348
     The library attempts to create objects with filenames longer than
Packit Service 1d0348
     PATH_MAX by creating prefixes of the full path and changing the current
Packit Service 1d0348
     directory.  Currently, this logic is limited in scope; the fixup pass
Packit Service 1d0348
     does 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
Packit Service 1d0348
     Restoring the path aa/../bb does create each intermediate directory.  In
Packit Service 1d0348
     particular, the directory aa is created as well as the final object bb.
Packit Service 1d0348
     In theory, this can be exploited to create an entire directory hierarchy
Packit Service 1d0348
     with a single request.  Of course, this does not work if the
Packit Service 1d0348
     ARCHIVE_EXTRACT_NODOTDOT option is specified.
Packit Service 1d0348
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
     ARCHIVE_EXTRACT_PERM is specified, in which case they current umask is
Packit Service 1d0348
     ignored.
Packit Service 1d0348
Packit Service 1d0348
     SGID and SUID bits are restored only if the correct user and group could
Packit Service 1d0348
     be set.  If ARCHIVE_EXTRACT_OWNER is not specified, then no attempt is
Packit Service 1d0348
     made to set the ownership.  In this case, SGID and SUID bits are restored
Packit Service 1d0348
     only if the user and group of the final object happen to match those
Packit Service 1d0348
     specified in the entry.
Packit Service 1d0348
Packit Service 1d0348
     The “standard” user-id and group-id lookup functions are not the defaults
Packit Service 1d0348
     because getgrnam(3) and getpwnam(3) are sometimes too large for particu‐
Packit Service 1d0348
     lar applications.	The current design allows the application author to
Packit Service 1d0348
     use a more compact implementation when appropriate.
Packit Service 1d0348
Packit Service 1d0348
     There should be a corresponding archive_read_disk interface that walks a
Packit Service 1d0348
     directory hierarchy and returns archive entry objects.
Packit Service 1d0348
Packit Service 1d0348
BSD				 April 3, 2017				   BSD