Blame libarchive/archive_read_disk.3

Packit Service 1d0348
.\" Copyright (c) 2003-2009 Tim Kientzle
Packit Service 1d0348
.\" All rights reserved.
Packit Service 1d0348
.\"
Packit Service 1d0348
.\" Redistribution and use in source and binary forms, with or without
Packit Service 1d0348
.\" modification, are permitted provided that the following conditions
Packit Service 1d0348
.\" are met:
Packit Service 1d0348
.\" 1. Redistributions of source code must retain the above copyright
Packit Service 1d0348
.\"    notice, this list of conditions and the following disclaimer.
Packit Service 1d0348
.\" 2. Redistributions in binary form must reproduce the above copyright
Packit Service 1d0348
.\"    notice, this list of conditions and the following disclaimer in the
Packit Service 1d0348
.\"    documentation and/or other materials provided with the distribution.
Packit Service 1d0348
.\"
Packit Service 1d0348
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
Packit Service 1d0348
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit Service 1d0348
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit Service 1d0348
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
Packit Service 1d0348
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit Service 1d0348
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit Service 1d0348
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit Service 1d0348
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit Service 1d0348
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit Service 1d0348
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit Service 1d0348
.\" SUCH DAMAGE.
Packit Service 1d0348
.\"
Packit Service 1d0348
.\" $FreeBSD$
Packit Service 1d0348
.\"
Packit Service 1d0348
.Dd April 3, 2017
Packit Service 1d0348
.Dt ARCHIVE_READ_DISK 3
Packit Service 1d0348
.Os
Packit Service 1d0348
.Sh NAME
Packit Service 1d0348
.Nm archive_read_disk_new ,
Packit Service 1d0348
.Nm archive_read_disk_set_behavior ,
Packit Service 1d0348
.Nm archive_read_disk_set_symlink_logical ,
Packit Service 1d0348
.Nm archive_read_disk_set_symlink_physical ,
Packit Service 1d0348
.Nm archive_read_disk_set_symlink_hybrid ,
Packit Service 1d0348
.Nm archive_read_disk_entry_from_file ,
Packit Service 1d0348
.Nm archive_read_disk_gname ,
Packit Service 1d0348
.Nm archive_read_disk_uname ,
Packit Service 1d0348
.Nm archive_read_disk_set_uname_lookup ,
Packit Service 1d0348
.Nm archive_read_disk_set_gname_lookup ,
Packit Service 1d0348
.Nm archive_read_disk_set_standard_lookup
Packit Service 1d0348
.Nd functions for reading objects from disk
Packit Service 1d0348
.Sh LIBRARY
Packit Service 1d0348
Streaming Archive Library (libarchive, -larchive)
Packit Service 1d0348
.Sh SYNOPSIS
Packit Service 1d0348
.In archive.h
Packit Service 1d0348
.Ft struct archive *
Packit Service 1d0348
.Fn archive_read_disk_new "void"
Packit Service 1d0348
.Ft int
Packit Service 1d0348
.Fn archive_read_disk_set_behavior "struct archive *" "int"
Packit Service 1d0348
.Ft int
Packit Service 1d0348
.Fn archive_read_disk_set_symlink_logical "struct archive *"
Packit Service 1d0348
.Ft int
Packit Service 1d0348
.Fn archive_read_disk_set_symlink_physical "struct archive *"
Packit Service 1d0348
.Ft int
Packit Service 1d0348
.Fn archive_read_disk_set_symlink_hybrid "struct archive *"
Packit Service 1d0348
.Ft const char *
Packit Service 1d0348
.Fn archive_read_disk_gname "struct archive *" "gid_t"
Packit Service 1d0348
.Ft const char *
Packit Service 1d0348
.Fn archive_read_disk_uname "struct archive *" "uid_t"
Packit Service 1d0348
.Ft int
Packit Service 1d0348
.Fo archive_read_disk_set_gname_lookup
Packit Service 1d0348
.Fa "struct archive *"
Packit Service 1d0348
.Fa "void *"
Packit Service 1d0348
.Fa "const char *(*lookup)(void *, gid_t)"
Packit Service 1d0348
.Fa "void (*cleanup)(void *)"
Packit Service 1d0348
.Fc
Packit Service 1d0348
.Ft int
Packit Service 1d0348
.Fo archive_read_disk_set_uname_lookup
Packit Service 1d0348
.Fa "struct archive *"
Packit Service 1d0348
.Fa "void *"
Packit Service 1d0348
.Fa "const char *(*lookup)(void *, uid_t)"
Packit Service 1d0348
.Fa "void (*cleanup)(void *)"
Packit Service 1d0348
.Fc
Packit Service 1d0348
.Ft int
Packit Service 1d0348
.Fn archive_read_disk_set_standard_lookup "struct archive *"
Packit Service 1d0348
.Ft int
Packit Service 1d0348
.Fo archive_read_disk_entry_from_file
Packit Service 1d0348
.Fa "struct archive *"
Packit Service 1d0348
.Fa "struct archive_entry *"
Packit Service 1d0348
.Fa "int fd"
Packit Service 1d0348
.Fa "const struct stat *"
Packit Service 1d0348
.Fc
Packit Service 1d0348
.Sh DESCRIPTION
Packit Service 1d0348
These functions provide an API for reading information about
Packit Service 1d0348
objects on disk.
Packit Service 1d0348
In particular, they provide an interface for populating
Packit Service 1d0348
.Tn struct archive_entry
Packit Service 1d0348
objects.
Packit Service 1d0348
.Bl -tag -width indent
Packit Service 1d0348
.It Fn archive_read_disk_new
Packit Service 1d0348
Allocates and initializes a
Packit Service 1d0348
.Tn struct archive
Packit Service 1d0348
object suitable for reading object information from disk.
Packit Service 1d0348
.It Fn archive_read_disk_set_behavior
Packit Service 1d0348
Configures various behavior options when reading entries from disk.
Packit Service 1d0348
The flags field consists of a bitwise OR of one or more of the
Packit Service 1d0348
following values:
Packit Service 1d0348
.Bl -tag -compact -width "indent"
Packit Service 1d0348
.It Cm ARCHIVE_READDISK_HONOR_NODUMP
Packit Service 1d0348
Skip files and directories with the nodump file attribute (file flag) set.
Packit Service 1d0348
By default, the nodump file atrribute is ignored.
Packit Service 1d0348
.It Cm ARCHIVE_READDISK_MAC_COPYFILE
Packit Service 1d0348
Mac OS X specific. Read metadata (ACLs and extended attributes) with
Packit Service 1d0348
.Xr copyfile 3 .
Packit Service 1d0348
By default, metadata is read using
Packit Service 1d0348
.Xr copyfile 3 .
Packit Service 1d0348
.It Cm ARCHIVE_READDISK_NO_ACL
Packit Service 1d0348
Do not read Access Control Lists.
Packit Service 1d0348
By default, ACLs are read from disk.
Packit Service 1d0348
.It Cm ARCHIVE_READDISK_NO_FFLAGS
Packit Service 1d0348
Do not read file attributes (file flags).
Packit Service 1d0348
By default, file attributes are read from disk.
Packit Service 1d0348
See
Packit Service 1d0348
.Xr chattr 1
Packit Service 1d0348
.Pq Linux
Packit Service 1d0348
or
Packit Service 1d0348
.Xr chflags 1
Packit Service 1d0348
.Pq FreeBSD, Mac OS X
Packit Service 1d0348
for more information on file attributes.
Packit Service 1d0348
.It Cm ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS
Packit Service 1d0348
Do not traverse mount points.
Packit Service 1d0348
By defaut, moint points are traversed.
Packit Service 1d0348
.It Cm ARCHIVE_READDISK_NO_XATTR
Packit Service 1d0348
Do not read extended file attributes (xattrs).
Packit Service 1d0348
By default, extended file attributes are read from disk.
Packit Service 1d0348
See
Packit Service 1d0348
.Xr xattr 7
Packit Service 1d0348
.Pq Linux ,
Packit Service 1d0348
.Xr xattr 2
Packit Service 1d0348
.Pq Mac OS X ,
Packit Service 1d0348
or
Packit Service 1d0348
.Xr getextattr 8
Packit Service 1d0348
.Pq FreeBSD
Packit Service 1d0348
for more information on extended file attributes.
Packit Service 1d0348
.It Cm ARCHIVE_READDISK_RESTORE_ATIME
Packit Service 1d0348
Restore access time of traversed files.
Packit Service 1d0348
By default, access time of traversed files is not restored.
Packit Service 1d0348
.El
Packit Service 1d0348
.It Xo
Packit Service 1d0348
.Fn archive_read_disk_set_symlink_logical ,
Packit Service 1d0348
.Fn archive_read_disk_set_symlink_physical ,
Packit Service 1d0348
.Fn archive_read_disk_set_symlink_hybrid
Packit Service 1d0348
.Xc
Packit Service 1d0348
This sets the mode used for handling symbolic links.
Packit Service 1d0348
The
Packit Service 1d0348
.Dq logical
Packit Service 1d0348
mode follows all symbolic links.
Packit Service 1d0348
The
Packit Service 1d0348
.Dq physical
Packit Service 1d0348
mode does not follow any symbolic links.
Packit Service 1d0348
The
Packit Service 1d0348
.Dq hybrid
Packit Service 1d0348
mode currently behaves identically to the
Packit Service 1d0348
.Dq logical
Packit Service 1d0348
mode.
Packit Service 1d0348
.It Xo
Packit Service 1d0348
.Fn archive_read_disk_gname ,
Packit Service 1d0348
.Fn archive_read_disk_uname
Packit Service 1d0348
.Xc
Packit Service 1d0348
Returns a user or group name given a gid or uid value.
Packit Service 1d0348
By default, these always return a NULL string.
Packit Service 1d0348
.It Xo
Packit Service 1d0348
.Fn archive_read_disk_set_gname_lookup ,
Packit Service 1d0348
.Fn archive_read_disk_set_uname_lookup
Packit Service 1d0348
.Xc
Packit Service 1d0348
These allow you to override the functions used for
Packit Service 1d0348
user and group name lookups.
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 or when new lookup functions are registered.
Packit Service 1d0348
.It Fn archive_read_disk_set_standard_lookup
Packit Service 1d0348
This convenience function installs a standard set of user
Packit Service 1d0348
and group name lookup functions.
Packit Service 1d0348
These functions use
Packit Service 1d0348
.Xr getpwuid 3
Packit Service 1d0348
and
Packit Service 1d0348
.Xr getgrgid 3
Packit Service 1d0348
to convert ids to names, defaulting to NULL 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
.Xr getpwuid 3
Packit Service 1d0348
and
Packit Service 1d0348
.Xr getgrgid 3 .
Packit Service 1d0348
.It Fn archive_read_disk_entry_from_file
Packit Service 1d0348
Populates a
Packit Service 1d0348
.Tn struct archive_entry
Packit Service 1d0348
object with information about a particular file.
Packit Service 1d0348
The
Packit Service 1d0348
.Tn archive_entry
Packit Service 1d0348
object must have already been created with
Packit Service 1d0348
.Xr archive_entry_new 3
Packit Service 1d0348
and at least one of the source path or path fields must already be set.
Packit Service 1d0348
(If both are set, the source path will be used.)
Packit Service 1d0348
.Pp
Packit Service 1d0348
Information is read from disk using the path name from the
Packit Service 1d0348
.Tn struct archive_entry
Packit Service 1d0348
object.
Packit Service 1d0348
If a file descriptor is provided, some information will be obtained using
Packit Service 1d0348
that file descriptor, on platforms that support the appropriate
Packit Service 1d0348
system calls.
Packit Service 1d0348
.Pp
Packit Service 1d0348
If a pointer to a
Packit Service 1d0348
.Tn struct stat
Packit Service 1d0348
is provided, information from that structure will be used instead
Packit Service 1d0348
of reading from the disk where appropriate.
Packit Service 1d0348
This can provide performance benefits in scenarios where
Packit Service 1d0348
.Tn struct stat
Packit Service 1d0348
information has already been read from the disk as a side effect
Packit Service 1d0348
of some other operation.
Packit Service 1d0348
(For example, directory traversal libraries often provide this information.)
Packit Service 1d0348
.Pp
Packit Service 1d0348
Where necessary, user and group ids are converted to user and group names
Packit Service 1d0348
using the currently registered lookup functions above.
Packit Service 1d0348
This affects the file ownership fields and ACL values in the
Packit Service 1d0348
.Tn struct archive_entry
Packit Service 1d0348
object.
Packit Service 1d0348
.El
Packit Service 1d0348
More information about the
Packit Service 1d0348
.Va struct archive
Packit Service 1d0348
object and the overall design of the library can be found in the
Packit Service 1d0348
.Xr libarchive 3
Packit Service 1d0348
overview.
Packit Service 1d0348
.Sh EXAMPLE
Packit Service 1d0348
The following illustrates basic usage of the library by
Packit Service 1d0348
showing how to use it to copy an item on disk into an archive.
Packit Service 1d0348
.Bd -literal -offset indent
Packit Service 1d0348
void
Packit Service 1d0348
file_to_archive(struct archive *a, const char *name)
Packit Service 1d0348
{
Packit Service 1d0348
  char buff[8192];
Packit Service 1d0348
  size_t bytes_read;
Packit Service 1d0348
  struct archive *ard;
Packit Service 1d0348
  struct archive_entry *entry;
Packit Service 1d0348
  int fd;
Packit Service 1d0348
Packit Service 1d0348
  ard = archive_read_disk_new();
Packit Service 1d0348
  archive_read_disk_set_standard_lookup(ard);
Packit Service 1d0348
  entry = archive_entry_new();
Packit Service 1d0348
  fd = open(name, O_RDONLY);
Packit Service 1d0348
  if (fd < 0)
Packit Service 1d0348
     return;
Packit Service 1d0348
  archive_entry_copy_pathname(entry, name);
Packit Service 1d0348
  archive_read_disk_entry_from_file(ard, entry, fd, NULL);
Packit Service 1d0348
  archive_write_header(a, entry);
Packit Service 1d0348
  while ((bytes_read = read(fd, buff, sizeof(buff))) > 0)
Packit Service 1d0348
    archive_write_data(a, buff, bytes_read);
Packit Service 1d0348
  archive_write_finish_entry(a);
Packit Service 1d0348
  archive_read_free(ard);
Packit Service 1d0348
  archive_entry_free(entry);
Packit Service 1d0348
}
Packit Service 1d0348
.Ed
Packit Service 1d0348
.Sh RETURN VALUES
Packit Service 1d0348
Most functions return
Packit Service 1d0348
.Cm ARCHIVE_OK
Packit Service 1d0348
(zero) on success, or one of several negative
Packit Service 1d0348
error codes for errors.
Packit Service 1d0348
Specific error codes include:
Packit Service 1d0348
.Cm ARCHIVE_RETRY
Packit Service 1d0348
for operations that might succeed if retried,
Packit Service 1d0348
.Cm ARCHIVE_WARN
Packit Service 1d0348
for unusual conditions that do not prevent further operations, and
Packit Service 1d0348
.Cm ARCHIVE_FATAL
Packit Service 1d0348
for serious errors that make remaining operations impossible.
Packit Service 1d0348
.Pp
Packit Service 1d0348
.Fn archive_read_disk_new
Packit Service 1d0348
returns a pointer to a newly-allocated
Packit Service 1d0348
.Tn struct archive
Packit Service 1d0348
object or NULL if the allocation failed for any reason.
Packit Service 1d0348
.Pp
Packit Service 1d0348
.Fn archive_read_disk_gname
Packit Service 1d0348
and
Packit Service 1d0348
.Fn archive_read_disk_uname
Packit Service 1d0348
return
Packit Service 1d0348
.Tn const char *
Packit Service 1d0348
pointers to the textual name or NULL if the lookup failed for any reason.
Packit Service 1d0348
The returned pointer points to internal storage that
Packit Service 1d0348
may be reused on the next call to either of these functions;
Packit Service 1d0348
callers should copy the string if they need to continue accessing it.
Packit Service 1d0348
.\"
Packit Service 1d0348
.Sh ERRORS
Packit Service 1d0348
Detailed error codes and textual descriptions are available from the
Packit Service 1d0348
.Fn archive_errno
Packit Service 1d0348
and
Packit Service 1d0348
.Fn archive_error_string
Packit Service 1d0348
functions.
Packit Service 1d0348
.\"
Packit Service 1d0348
.Sh SEE ALSO
Packit Service 1d0348
.Xr archive_read 3 ,
Packit Service 1d0348
.Xr archive_util 3 ,
Packit Service 1d0348
.Xr archive_write 3 ,
Packit Service 1d0348
.Xr archive_write_disk 3 ,
Packit Service 1d0348
.Xr tar 1 ,
Packit Service 1d0348
.Xr libarchive 3
Packit Service 1d0348
.Sh HISTORY
Packit Service 1d0348
The
Packit Service 1d0348
.Nm libarchive
Packit Service 1d0348
library first appeared in
Packit Service 1d0348
.Fx 5.3 .
Packit Service 1d0348
The
Packit Service 1d0348
.Nm archive_read_disk
Packit Service 1d0348
interface was added to
Packit Service 1d0348
.Nm libarchive 2.6
Packit Service 1d0348
and first appeared in
Packit Service 1d0348
.Fx 8.0 .
Packit Service 1d0348
.Sh AUTHORS
Packit Service 1d0348
.An -nosplit
Packit Service 1d0348
The
Packit Service 1d0348
.Nm libarchive
Packit Service 1d0348
library was written by
Packit Service 1d0348
.An Tim Kientzle Aq kientzle@FreeBSD.org .
Packit Service 1d0348
.Sh BUGS
Packit Service 1d0348
The
Packit Service 1d0348
.Dq standard
Packit Service 1d0348
user name and group name lookup functions are not the defaults because
Packit Service 1d0348
.Xr getgrgid 3
Packit Service 1d0348
and
Packit Service 1d0348
.Xr getpwuid 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
The full list of metadata read from disk by
Packit Service 1d0348
.Fn archive_read_disk_entry_from_file
Packit Service 1d0348
is necessarily system-dependent.
Packit Service 1d0348
.Pp
Packit Service 1d0348
The
Packit Service 1d0348
.Fn archive_read_disk_entry_from_file
Packit Service 1d0348
function reads as much information as it can from disk.
Packit Service 1d0348
Some method should be provided to limit this so that clients who
Packit Service 1d0348
do not need ACLs, for instance, can avoid the extra work needed
Packit Service 1d0348
to look up such information.
Packit Service 1d0348
.Pp
Packit Service 1d0348
This API should provide a set of methods for walking a directory tree.
Packit Service 1d0348
That would make it a direct parallel of the
Packit Service 1d0348
.Xr archive_read 3
Packit Service 1d0348
API.
Packit Service 1d0348
When such methods are implemented, the
Packit Service 1d0348
.Dq hybrid
Packit Service 1d0348
symbolic link mode will make sense.