Blame doc/text/archive_read_disk.3.txt

Packit Service 1d0348
ARCHIVE_READ_DISK(3)	 BSD Library Functions Manual	  ARCHIVE_READ_DISK(3)
Packit Service 1d0348
Packit Service 1d0348
NAME
Packit Service 1d0348
     archive_read_disk_new, archive_read_disk_set_behavior,
Packit Service 1d0348
     archive_read_disk_set_symlink_logical,
Packit Service 1d0348
     archive_read_disk_set_symlink_physical,
Packit Service 1d0348
     archive_read_disk_set_symlink_hybrid, archive_read_disk_entry_from_file,
Packit Service 1d0348
     archive_read_disk_gname, archive_read_disk_uname,
Packit Service 1d0348
     archive_read_disk_set_uname_lookup, archive_read_disk_set_gname_lookup,
Packit Service 1d0348
     archive_read_disk_set_standard_lookup — functions for reading objects
Packit Service 1d0348
     from 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_read_disk_new(void);
Packit Service 1d0348
Packit Service 1d0348
     int
Packit Service 1d0348
     archive_read_disk_set_behavior(struct archive *, int);
Packit Service 1d0348
Packit Service 1d0348
     int
Packit Service 1d0348
     archive_read_disk_set_symlink_logical(struct archive *);
Packit Service 1d0348
Packit Service 1d0348
     int
Packit Service 1d0348
     archive_read_disk_set_symlink_physical(struct archive *);
Packit Service 1d0348
Packit Service 1d0348
     int
Packit Service 1d0348
     archive_read_disk_set_symlink_hybrid(struct archive *);
Packit Service 1d0348
Packit Service 1d0348
     const char *
Packit Service 1d0348
     archive_read_disk_gname(struct archive *, gid_t);
Packit Service 1d0348
Packit Service 1d0348
     const char *
Packit Service 1d0348
     archive_read_disk_uname(struct archive *, uid_t);
Packit Service 1d0348
Packit Service 1d0348
     int
Packit Service 1d0348
     archive_read_disk_set_gname_lookup(struct archive *, void *,
Packit Service 1d0348
	 const char *(*lookup)(void *, gid_t), void (*cleanup)(void *));
Packit Service 1d0348
Packit Service 1d0348
     int
Packit Service 1d0348
     archive_read_disk_set_uname_lookup(struct archive *, void *,
Packit Service 1d0348
	 const char *(*lookup)(void *, uid_t), void (*cleanup)(void *));
Packit Service 1d0348
Packit Service 1d0348
     int
Packit Service 1d0348
     archive_read_disk_set_standard_lookup(struct archive *);
Packit Service 1d0348
Packit Service 1d0348
     int
Packit Service 1d0348
     archive_read_disk_entry_from_file(struct archive *,
Packit Service 1d0348
	 struct archive_entry *, int fd, const struct stat *);
Packit Service 1d0348
Packit Service 1d0348
DESCRIPTION
Packit Service 1d0348
     These functions provide an API for reading information about objects on
Packit Service 1d0348
     disk.  In particular, they provide an interface for populating struct
Packit Service 1d0348
     archive_entry objects.
Packit Service 1d0348
Packit Service 1d0348
     archive_read_disk_new()
Packit Service 1d0348
	     Allocates and initializes a struct archive object suitable for
Packit Service 1d0348
	     reading object information from disk.
Packit Service 1d0348
Packit Service 1d0348
     archive_read_disk_set_behavior()
Packit Service 1d0348
	     Configures various behavior options when reading entries from
Packit Service 1d0348
	     disk.  The flags field consists of a bitwise OR of one or more of
Packit Service 1d0348
	     the following values:
Packit Service 1d0348
	     ARCHIVE_READDISK_HONOR_NODUMP
Packit Service 1d0348
		     Skip files and directories with the nodump file attribute
Packit Service 1d0348
		     (file flag) set.  By default, the nodump file atrribute
Packit Service 1d0348
		     is ignored.
Packit Service 1d0348
	     ARCHIVE_READDISK_MAC_COPYFILE
Packit Service 1d0348
		     Mac OS X specific. Read metadata (ACLs and extended
Packit Service 1d0348
		     attributes) with copyfile(3).  By default, metadata is
Packit Service 1d0348
		     read using copyfile(3).
Packit Service 1d0348
	     ARCHIVE_READDISK_NO_ACL
Packit Service 1d0348
		     Do not read Access Control Lists.	By default, ACLs are
Packit Service 1d0348
		     read from disk.
Packit Service 1d0348
	     ARCHIVE_READDISK_NO_FFLAGS
Packit Service 1d0348
		     Do not read file attributes (file flags).	By default,
Packit Service 1d0348
		     file attributes are read from disk.  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_READDISK_NO_TRAVERSE_MOUNTS
Packit Service 1d0348
		     Do not traverse mount points.  By defaut, moint points
Packit Service 1d0348
		     are traversed.
Packit Service 1d0348
	     ARCHIVE_READDISK_NO_XATTR
Packit Service 1d0348
		     Do not read extended file attributes (xattrs).  By
Packit Service 1d0348
		     default, extended file attributes are read from disk.
Packit Service 1d0348
		     See xattr(7) (Linux), xattr(2) (Mac OS X), or
Packit Service 1d0348
		     getextattr(8) (FreeBSD) for more information on extended
Packit Service 1d0348
		     file attributes.
Packit Service 1d0348
	     ARCHIVE_READDISK_RESTORE_ATIME
Packit Service 1d0348
		     Restore access time of traversed files.  By default,
Packit Service 1d0348
		     access time of traversed files is not restored.
Packit Service 1d0348
Packit Service 1d0348
     archive_read_disk_set_symlink_logical(),
Packit Service 1d0348
	     archive_read_disk_set_symlink_physical(),
Packit Service 1d0348
	     archive_read_disk_set_symlink_hybrid()
Packit Service 1d0348
	     This sets the mode used for handling symbolic links.  The
Packit Service 1d0348
	     “logical” mode follows all symbolic links.  The “physical” mode
Packit Service 1d0348
	     does not follow any symbolic links.  The “hybrid” mode currently
Packit Service 1d0348
	     behaves identically to the “logical” mode.
Packit Service 1d0348
Packit Service 1d0348
     archive_read_disk_gname(), archive_read_disk_uname()
Packit Service 1d0348
	     Returns a user or group name given a gid or uid value.  By
Packit Service 1d0348
	     default, these always return a NULL string.
Packit Service 1d0348
Packit Service 1d0348
     archive_read_disk_set_gname_lookup(),
Packit Service 1d0348
	     archive_read_disk_set_uname_lookup()
Packit Service 1d0348
	     These allow you to override the functions used for user and group
Packit Service 1d0348
	     name lookups.  You may also provide a void * pointer to a private
Packit Service 1d0348
	     data structure and a cleanup function for that data.  The cleanup
Packit Service 1d0348
	     function will be invoked when the struct archive object is
Packit Service 1d0348
	     destroyed or when new lookup functions are registered.
Packit Service 1d0348
Packit Service 1d0348
     archive_read_disk_set_standard_lookup()
Packit Service 1d0348
	     This convenience function installs a standard set of user and
Packit Service 1d0348
	     group name lookup functions.  These functions use getpwuid(3) and
Packit Service 1d0348
	     getgrgid(3) to convert ids to names, defaulting to NULL 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 getpwuid(3) and
Packit Service 1d0348
	     getgrgid(3).
Packit Service 1d0348
Packit Service 1d0348
     archive_read_disk_entry_from_file()
Packit Service 1d0348
	     Populates a struct archive_entry object with information about a
Packit Service 1d0348
	     particular file.  The archive_entry object must have already been
Packit Service 1d0348
	     created with archive_entry_new(3) and at least one of the source
Packit Service 1d0348
	     path or path fields must already be set.  (If both are set, the
Packit Service 1d0348
	     source path will be used.)
Packit Service 1d0348
Packit Service 1d0348
	     Information is read from disk using the path name from the struct
Packit Service 1d0348
	     archive_entry object.  If a file descriptor is provided, some
Packit Service 1d0348
	     information will be obtained using that file descriptor, on plat‐
Packit Service 1d0348
	     forms that support the appropriate system calls.
Packit Service 1d0348
Packit Service 1d0348
	     If a pointer to a struct stat is provided, information from that
Packit Service 1d0348
	     structure will be used instead of reading from the disk where
Packit Service 1d0348
	     appropriate.  This can provide performance benefits in scenarios
Packit Service 1d0348
	     where struct stat information has already been read from the disk
Packit Service 1d0348
	     as a side effect of some other operation.	(For example, direc‐
Packit Service 1d0348
	     tory traversal libraries often provide this information.)
Packit Service 1d0348
Packit Service 1d0348
	     Where necessary, user and group ids are converted to user and
Packit Service 1d0348
	     group names using the currently registered lookup functions
Packit Service 1d0348
	     above.  This affects the file ownership fields and ACL values in
Packit Service 1d0348
	     the struct archive_entry object.
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.
Packit Service 1d0348
Packit Service 1d0348
EXAMPLE
Packit Service 1d0348
     The following illustrates basic usage of the library by showing how to
Packit Service 1d0348
     use it to copy an item on disk into an archive.
Packit Service 1d0348
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
Packit Service 1d0348
RETURN VALUES
Packit Service 1d0348
     Most functions return ARCHIVE_OK (zero) on success, or one of several
Packit Service 1d0348
     negative 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_read_disk_new() returns a pointer to a newly-allocated struct
Packit Service 1d0348
     archive object or NULL if the allocation failed for any reason.
Packit Service 1d0348
Packit Service 1d0348
     archive_read_disk_gname() and archive_read_disk_uname() return const char
Packit Service 1d0348
     * pointers to the textual name or NULL if the lookup failed for any rea‐
Packit Service 1d0348
     son.  The returned pointer points to internal storage that may be reused
Packit Service 1d0348
     on the next call to either of these functions; callers should copy the
Packit Service 1d0348
     string if they need to continue accessing it.
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_util(3), archive_write(3),
Packit Service 1d0348
     archive_write_disk(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_read_disk interface was added to libarchive 2.6 and first
Packit Service 1d0348
     appeared in FreeBSD 8.0.
Packit Service 1d0348
Packit Service 1d0348
AUTHORS
Packit Service 1d0348
     The libarchive library was written by Tim Kientzle
Packit Service 1d0348
     <kientzle@FreeBSD.org>.
Packit Service 1d0348
Packit Service 1d0348
BUGS
Packit Service 1d0348
     The “standard” user name and group name lookup functions are not the
Packit Service 1d0348
     defaults because getgrgid(3) and getpwuid(3) are sometimes too large for
Packit Service 1d0348
     particular applications.  The current design allows the application
Packit Service 1d0348
     author to use a more compact implementation when appropriate.
Packit Service 1d0348
Packit Service 1d0348
     The full list of metadata read from disk by
Packit Service 1d0348
     archive_read_disk_entry_from_file() is necessarily system-dependent.
Packit Service 1d0348
Packit Service 1d0348
     The archive_read_disk_entry_from_file() function reads as much informa‐
Packit Service 1d0348
     tion as it can from disk.	Some method should be provided to limit this
Packit Service 1d0348
     so that clients who do not need ACLs, for instance, can avoid the extra
Packit Service 1d0348
     work needed to look up such information.
Packit Service 1d0348
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 archive_read(3) API.  When
Packit Service 1d0348
     such methods are implemented, the “hybrid” symbolic link mode will make
Packit Service 1d0348
     sense.
Packit Service 1d0348
Packit Service 1d0348
BSD				 April 3, 2017				   BSD