ARCHIVE_READ_DISK(3)
β¨ ARCHIVE_READ_DISK(3) β¨
okay bestie, so this is the manual page for ARCHIVE_READ_DISK(3) from the Library Functions Manual. it's literally all about reading objects from disk and it's giving very useful library energy π
. no cap, if you're populating struct archive_entry objects from disk, this is your main character moment.
π NAME π
Here's the whole squad of functions, all together:
archive_read_disk_newarchive_read_disk_openarchive_read_disk_open_warchive_read_disk_set_behaviorarchive_read_disk_set_symlink_logicalarchive_read_disk_set_symlink_physicalarchive_read_disk_set_symlink_hybridarchive_read_disk_entry_from_filearchive_read_disk_gnamearchive_read_disk_unamearchive_read_disk_set_uname_lookuparchive_read_disk_set_gname_lookuparchive_read_disk_set_standard_lookuparchive_read_disk_descendarchive_read_disk_can_descendarchive_read_disk_current_filesystemarchive_read_disk_current_filesystem_is_syntheticarchive_read_disk_current_filesystem_is_remotearchive_read_disk_set_matchingarchive_read_disk_set_metadata_filter_callback
β functions for reading objects from disk πΈ
π LIBRARY π
Streaming Archive Library (libarchive, -larchive) β so you link with -larchive, bestie π
π¦ SYNOPSIS π¦
#include <archive.h>
struct archive *
archive_read_disk_new(void);
int
archive_read_disk_open(struct archive *, const char *);
int
archive_read_disk_open_w(struct archive *, const wchar_t *);
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 *);
int
archive_read_disk_descend(struct archive *);
int
archive_read_disk_can_descend(struct archive *);
int
archive_read_disk_current_filesystem(struct archive *);
int
archive_read_disk_current_filesystem_is_synthetic(struct archive *);
int
archive_read_disk_current_filesystem_is_remote(struct archive *);
int
archive_read_disk_set_matching(struct archive *, struct archive *,
void (*excluded_func)(struct archive *, void *, struct archive entry *),
void *);
int
archive_read_disk_set_metadata_filter_callback(struct archive *,
int (*metadata_filter_func)(struct archive *, void*, struct archive_entry *),
void *);
β¨ DESCRIPTION β¨
These functions provide an API for reading information about objects on disk. In particular, they provide an interface for populating struct archive_entry objects. periodt.
archive_read_disk_new()β Allocates and initializes astruct archiveobject suitable for reading object information from disk. it's giving new beginnings β¨archive_read_disk_open()β Opens the file or directory from the given path and prepares thestruct archiveto read it from disk. open sesame π«Άarchive_read_disk_open_w()β Opens the file or directory from the given path as a wide character string and prepares thestruct archiveto read it from disk. wchar_t bestie πarchive_read_disk_set_behavior()β Configures various behavior options when reading entries from disk. The flags field consists of a bitwise OR of one or more of the following values:ARCHIVE_READDISK_HONOR_NODUMPβ Skip files and directories with the nodump file attribute (file flag) set. By default, the nodump file attribute is ignored.ARCHIVE_READDISK_MAC_COPYFILEβ Mac OS X specific. Read metadata (ACLs and extended attributes) withcopyfile(3). By default, metadata is read usingcopyfile(3).ARCHIVE_READDISK_NO_ACLβ Do not read Access Control Lists. By default, ACLs are read from disk.ARCHIVE_READDISK_NO_FFLAGSβ Do not read file attributes (file flags). By default, file attributes are read from disk. Seechattr(1)(Linux) orchflags(1)(FreeBSD, Mac OS X) for more information on file attributes.ARCHIVE_READDISK_NO_TRAVERSE_MOUNTSβ Do not traverse mount points. By default, mount points are traversed.ARCHIVE_READDISK_NO_XATTRβ Do not read extended file attributes (xattrs). By default, extended file attributes are read from disk. Seexattr(7)(Linux),xattr(2)(Mac OS X), orgetextattr(8)(FreeBSD) for more information on extended file attributes.ARCHIVE_READDISK_RESTORE_ATIMEβ Restore access time of traversed files. By default, access time of traversed files is not restored.ARCHIVE_READDISK_NO_SPARSEβ Do not read sparse file information. By default, sparse file information is read from disk.
no cap, you combine these with | because it's a bitwise OR situation. iykyk π
archive_read_disk_set_symlink_logical(),archive_read_disk_set_symlink_physical(),archive_read_disk_set_symlink_hybrid()β This sets the mode used for handling symbolic links. The βlogicalβ mode follows all symbolic links. The βphysicalβ mode does not follow any symbolic links. The βhybridβ mode currently behaves identically to the βlogicalβ mode. symlink vibes π¦archive_read_disk_gname(),archive_read_disk_uname()β Returns a user or group name given a gid or uid value. By default, these always return a NULL string. null string energy πarchive_read_disk_set_gname_lookup(),archive_read_disk_set_uname_lookup()β These allow you to override the functions used for user and group name lookups. You may also provide avoid *pointer to a private data structure and a cleanup function for that data. The cleanup function will be invoked when thestruct archiveobject is destroyed or when new lookup functions are registered. custom lookup slay πarchive_read_disk_set_standard_lookup()β This convenience function installs a standard set of user and group name lookup functions. These functions usegetpwuid(3)andgetgrgid(3)to convert ids to names, defaulting to NULL if the names cannot be looked up. These functions also implement a simple memory cache to reduce the number of calls togetpwuid(3)andgetgrgid(3). cache it and slay β¨archive_read_disk_entry_from_file()β Populates astruct archive_entryobject with information about a particular file. Thearchive_entryobject must have already been created witharchive_entry_new(3)and at least one of the source path or path fields must already be set. (If both are set, the source path will be used.)
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. metadata glow-up π
archive_read_disk_descend()β If the current entry can be descended, this function will mark the directory as the next entry forarchive_read_header(3)to visit. go deeper bestie π§archive_read_disk_can_descend()β Returns 1 if the current entry is an unvisited directory and 0 otherwise. 1 or 0, no in-between πarchive_read_disk_current_filesystem()β Returns the index of the most recent filesystem entry that has been visited througharchive_read_diskindex realness π₯archive_read_disk_current_filesystem_is_synthetic()β Returns 1 if the current filesystem is a virtual filesystem. Returns 0 if the current filesystem is not a virtual filesystem. Returns -1 if it is unknown. synthetic or not, we don't judge πarchive_read_disk_current_filesystem_is_remote()β Returns 1 if the current filesystem is a remote filesystem. Returns 0 if the current filesystem is not a remote filesystem. Returns -1 if it is unknown. remote work vibes πarchive_read_disk_set_matching()β Allows the caller to setstruct archive *_mato compare each entry duringarchive_read_header(3)calls. If matched based on calls toarchive_match_path_excluded,archive_match_time_excluded, orarchive_match_owner_excluded, then the callback function specified by the_excluded_funcparameter will execute. This function will receive data provided to the fourth parameter,void *_client_data. match made in archive heaven πarchive_read_disk_set_metadata_filter_callback()β Allows the caller to set a callback function during calls toarchive_read_header(3)to filter out metadata for each entry. The callback function receives thestruct archiveobject,void*custom filter data, and thestruct archive_entry. If the callback function returns an error,ARCHIVE_RETRYwill be returned and the entry will not be further processed. filter it and flip it β¨
More information about the struct archive object and the overall design of the library can be found in the libarchive(3) overview.
β¨ EXAMPLES β¨
Okay bestie, here's the vibe β this lil snippet shows you the basic usage of the library, specifically how to copy an item sitting on disk into an archive. It's giving "starter pack" π
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);
}
π RETURN VALUES π
Most functions come back with ARCHIVE_OK (that's zero, bestie π) when everything slays. Otherwise you get one of several negative error codes. The specific ones you might see:
ARCHIVE_RETRYβ for operations that might actually succeed if you just retry them. It's giving "try again, babe" πARCHIVE_WARNβ for unusual conditions that do not prevent further operations. Weird, but we move πARCHIVE_FATALβ for serious errors that make remaining operations impossible. Like, dead. Done. No coming back π
Now the specific functions, one by one:
archive_read_disk_new()β returns a pointer to a newly-allocatedstruct archiveobject, orNULLif the allocation failed for any reason π«Άarchive_read_disk_gname()andarchive_read_disk_uname()β these returnconst char *pointers to the textual name, orNULLif the lookup failed for any reason.
β οΈ Okay important, no cap: that returned pointer points to internal storage that may be reused on the very next call to either of those functions. So if you need to keep accessing that string? Copy it. Do not hold onto it. Periodt. π
π ERRORS π
Detailed error codes and textual descriptions are available from the archive_errno() and archive_error_string() functions. That's your receipts, bestie β go read them π§Ύβ¨
π SEE ALSO π
tar(1), archive_read(3), archive_util(3), archive_write(3), archive_write_disk(3), libarchive(3)
π¦ HISTORY π¦
The 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. Little glow-up moment, honestly πΈ
π AUTHORS π
The libarchive library was written by Tim Kientzle <kientzle@FreeBSD.org>. Legend behaviour, fr fr π
π BUGS π
Okay so here's the messy part, and we're gonna be honest about it:
- The "standard" user name and group name lookup functions are not the defaults, because
getgrgid(3)andgetpwuid(3)are sometimes too large for particular applications. The current design lets the application author use a more compact implementation when that's the move. It's giving β¨flexibilityβ¨ - The full list of metadata read from disk by
archive_read_disk_entry_from_file()is necessarily system-dependent. So yeah, it varies, and that's just how it is π« - 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 don't need ACLs, for instance, can avoid the extra work needed to look up such information. Right now? No such limiter. π - 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. And when such methods get implemented, the "hybrid" symbolic link mode will make sense. Until then... it's just sitting there, waiting π
and that's the whole page, bestie!! π this one came from Debian, dated April 3, 2017, and it's page ARCHIVE_READ_DISK(3) of the manual. go forth and archive responsibly πβ¨π¦
π¦ where this page comes from
- arch rolling: libarchive 3.8.9-1
- centos-stream 10: libarchive-devel 3.7.7-11.el10 Β· BSD-2-Clause AND FSFULLR AND GPL-2.0-or-later WITH Libtool-exception AND BSD-3-Clause AND FSFUL
- debian trixie: libarchive-dev 3.7.4-4+deb13u1 Β· BSD-2-Clause
- fedora 43: libarchive-devel 3.8.1-3.fc43 Β· BSD-2-Clause AND FSFULLR AND GPL-2.0-or-later WITH Libtool-exception AND BSD-3-Clause AND FSFUL
- fedora 43: libarchive-devel 3.8.1-3.fc43 Β· BSD-2-Clause AND FSFULLR AND GPL-2.0-or-later WITH Libtool-exception AND BSD-3-Clause AND FSFUL
- fedora 43: libarchive-devel 3.8.4-1.fc43 Β· BSD-2-Clause AND FSFULLR AND GPL-2.0-or-later WITH Libtool-exception AND BSD-3-Clause AND FSFUL
- fedora 43: libarchive-devel 3.8.4-1.fc43 Β· BSD-2-Clause AND FSFULLR AND GPL-2.0-or-later WITH Libtool-exception AND BSD-3-Clause AND FSFUL
- fedora 44: libarchive-devel 3.8.4-2.fc44 Β· BSD-2-Clause AND FSFULLR AND GPL-2.0-or-later WITH Libtool-exception AND BSD-3-Clause AND FSFUL
- fedora 44: libarchive-devel 3.8.4-2.fc44 Β· BSD-2-Clause AND FSFULLR AND GPL-2.0-or-later WITH Libtool-exception AND BSD-3-Clause AND FSFUL
- fedora 44: libarchive-devel 3.8.7-1.fc44 Β· BSD-2-Clause AND FSFULLR AND GPL-2.0-or-later WITH Libtool-exception AND BSD-3-Clause AND FSFUL
- fedora 44: libarchive-devel 3.8.7-1.fc44 Β· BSD-2-Clause AND FSFULLR AND GPL-2.0-or-later WITH Libtool-exception AND BSD-3-Clause AND FSFUL
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixos 26.05: libarchive 3.8.9
- nixpkgs unstable: libarchive 3.8.9
- opensuse-leap 16.0: libarchive-devel 3.8.1-160000.4.1 Β· BSD-2-Clause
- opensuse-leap 16.0: libarchive-devel 3.8.1-160000.4.1 Β· BSD-2-Clause
- opensuse-leap 16.0: libarchive-devel 3.8.1-160000.4.1 Β· BSD-2-Clause
- opensuse-leap 16.0: libarchive-devel 3.8.1-160000.4.1 Β· BSD-2-Clause
- ubuntu questing: libarchive-dev 3.7.7-0ubuntu3
- ubuntu questing: libarchive-dev 3.7.7-0ubuntu3.2
- ubuntu resolute: libarchive-dev 3.8.5-1ubuntu2 Β· BSD-2-Clause
- ubuntu resolute: libarchive-dev 3.8.5-1ubuntu2.3 Β· BSD-2-Clause
- ubuntu stonking: libarchive-dev 3.8.9-1 Β· BSD-2-Clause
- Copyright (c) 2003-2009 Tim Kientzle
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms