| ARCHIVE_READ_DISK(3) | Library Functions Manual | ARCHIVE_READ_DISK(3) | 
archive_read_disk_new,
  archive_read_disk_set_behavior,
  archive_read_disk_set_symlink_logical,
  archive_read_disk_set_symlink_physical,
  archive_read_disk_set_symlink_hybrid,
  archive_read_disk_entry_from_file,
  archive_read_disk_gname,
  archive_read_disk_uname,
  archive_read_disk_set_uname_lookup,
  archive_read_disk_set_gname_lookup,
  archive_read_disk_set_standard_lookup —
#include <archive.h>
struct archive *
  
  archive_read_disk_new(void);
int
  
  archive_read_disk_set_behavior(struct
    archive *,
  int);
int
  
  archive_read_disk_set_symlink_logical(struct
    archive *);
int
  
  archive_read_disk_set_symlink_physical(struct
    archive *);
int
  
  archive_read_disk_set_symlink_hybrid(struct
    archive *);
const char *
  
  archive_read_disk_gname(struct
    archive *,
  gid_t);
const char *
  
  archive_read_disk_uname(struct
    archive *,
  uid_t);
int
  
  archive_read_disk_set_gname_lookup(struct
    archive *, void *, const char
    *(*lookup)(void *, gid_t), void (*cleanup)(void
    *));
int
  
  archive_read_disk_set_uname_lookup(struct
    archive *, void *, const char
    *(*lookup)(void *, uid_t), void (*cleanup)(void
    *));
int
  
  archive_read_disk_set_standard_lookup(struct
    archive *);
int
  
  archive_read_disk_entry_from_file(struct
    archive *, struct archive_entry *,
    int fd, const struct stat
  *);
archive_read_disk_new()archive_read_disk_set_behavior()ARCHIVE_READDISK_HONOR_NODUMPARCHIVE_READDISK_MAC_COPYFILEARCHIVE_READDISK_NO_ACLARCHIVE_READDISK_NO_FFLAGSARCHIVE_READDISK_NO_TRAVERSE_MOUNTSARCHIVE_READDISK_NO_XATTRARCHIVE_READDISK_RESTORE_ATIMEarchive_read_disk_set_symlink_logical(),
    archive_read_disk_set_symlink_physical(),
    archive_read_disk_set_symlink_hybrid()archive_read_disk_gname(),
    archive_read_disk_uname()archive_read_disk_set_gname_lookup(),
    archive_read_disk_set_uname_lookup()archive_read_disk_set_standard_lookup()archive_read_disk_entry_from_file()Information is read from disk using the path name from the struct archive_entry object. If a file descriptor is provided, some information will be obtained using that file descriptor, on platforms that support the appropriate system calls.
If a pointer to a struct stat is provided, information from that structure will be used instead of reading from the disk where appropriate. This can provide performance benefits in scenarios where struct stat information has already been read from the disk as a side effect of some other operation. (For example, directory traversal libraries often provide this information.)
Where necessary, user and group ids are converted to user and group names using the currently registered lookup functions above. This affects the file ownership fields and ACL values in the struct archive_entry object.
void
file_to_archive(struct archive *a, const char *name)
{
  char buff[8192];
  size_t bytes_read;
  struct archive *ard;
  struct archive_entry *entry;
  int fd;
  ard = archive_read_disk_new();
  archive_read_disk_set_standard_lookup(ard);
  entry = archive_entry_new();
  fd = open(name, O_RDONLY);
  if (fd < 0)
     return;
  archive_entry_copy_pathname(entry, name);
  archive_read_disk_entry_from_file(ard, entry, fd, NULL);
  archive_write_header(a, entry);
  while ((bytes_read = read(fd, buff, sizeof(buff))) > 0)
    archive_write_data(a, buff, bytes_read);
  archive_write_finish_entry(a);
  archive_read_free(ard);
  archive_entry_free(entry);
}
ARCHIVE_OK (zero) on success, or
  one of several negative error codes for errors. Specific error codes include:
  ARCHIVE_RETRY for operations that might succeed if
  retried, ARCHIVE_WARN for unusual conditions that do
  not prevent further operations, and ARCHIVE_FATAL for
  serious errors that make remaining operations impossible.
archive_read_disk_new() returns a pointer
    to a newly-allocated struct archive object or NULL if the allocation failed
    for any reason.
archive_read_disk_gname() and
    archive_read_disk_uname() return const char *
    pointers to the textual name or NULL if the lookup failed for any reason.
    The returned pointer points to internal storage that may be reused on the
    next call to either of these functions; callers should copy the string if
    they need to continue accessing it.
archive_errno() and
  archive_error_string() functions.
libarchive library first appeared in
  FreeBSD 5.3. The
  archive_read_disk interface was added to
  libarchive 2.6 and first appeared in
  FreeBSD 8.0.
libarchive library was written by
  Tim Kientzle ⟨kientzle@FreeBSD.org⟩.
The full list of metadata read from disk by
    archive_read_disk_entry_from_file() is necessarily
    system-dependent.
The archive_read_disk_entry_from_file()
    function reads as much information as it can from disk. Some method should
    be provided to limit this so that clients who do not need ACLs, for
    instance, can avoid the extra work needed to look up such information.
This API should provide a set of methods for walking a directory tree. That would make it a direct parallel of the archive_read(3) API. When such methods are implemented, the “hybrid” symbolic link mode will make sense.
| April 3, 2017 | NetBSD 10.0 |