Blame doc/text/archive_entry_linkify.3.txt

Packit Service 1d0348
ARCHIVE_ENTRY_LINKIFY(3) BSD Library Functions Manual ARCHIVE_ENTRY_LINKIFY(3)
Packit Service 1d0348
Packit Service 1d0348
NAME
Packit Service 1d0348
     archive_entry_linkresolver, archive_entry_linkresolver_new,
Packit Service 1d0348
     archive_entry_linkresolver_set_strategy, archive_entry_linkresolver_free,
Packit Service 1d0348
     archive_entry_linkify — hardlink resolver functions
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_entry.h>
Packit Service 1d0348
Packit Service 1d0348
     struct archive_entry_linkresolver *
Packit Service 1d0348
     archive_entry_linkresolver_new(void);
Packit Service 1d0348
Packit Service 1d0348
     void
Packit Service 1d0348
     archive_entry_linkresolver_set_strategy(struct archive_entry_linkresolver *resolver,
Packit Service 1d0348
	 int format);
Packit Service 1d0348
Packit Service 1d0348
     void
Packit Service 1d0348
     archive_entry_linkresolver_free(struct archive_entry_linkresolver *resolver);
Packit Service 1d0348
Packit Service 1d0348
     void
Packit Service 1d0348
     archive_entry_linkify(struct archive_entry_linkresolver *resolver,
Packit Service 1d0348
	 struct archive_entry **entry, struct archive_entry **sparse);
Packit Service 1d0348
Packit Service 1d0348
DESCRIPTION
Packit Service 1d0348
     Programs that want to create archives have to deal with hardlinks.
Packit Service 1d0348
     Hardlinks are handled in different ways by the archive formats.  The
Packit Service 1d0348
     basic strategies are:
Packit Service 1d0348
Packit Service 1d0348
     1.   Ignore hardlinks and store the body for each reference (old cpio,
Packit Service 1d0348
	  zip).
Packit Service 1d0348
Packit Service 1d0348
     2.   Store the body the first time an inode is seen (ustar, pax).
Packit Service 1d0348
Packit Service 1d0348
     3.   Store the body the last time an inode is seen (new cpio).
Packit Service 1d0348
Packit Service 1d0348
     The archive_entry_linkresolver functions help by providing a unified
Packit Service 1d0348
     interface and handling the complexity behind the scene.
Packit Service 1d0348
Packit Service 1d0348
     The archive_entry_linkresolver functions assume that archive_entry
Packit Service 1d0348
     instances have valid nlinks, inode and device values.  The inode and
Packit Service 1d0348
     device value is used to match entries.  The nlinks value is used to
Packit Service 1d0348
     determined if all references have been found and if the internal refer‐
Packit Service 1d0348
     ences can be recycled.
Packit Service 1d0348
Packit Service 1d0348
     The archive_entry_linkresolver_new() function allocates a new link
Packit Service 1d0348
     resolver.	The instance can be freed using
Packit Service 1d0348
     archive_entry_linkresolver_free().  All deferred entries are flushed and
Packit Service 1d0348
     the internal storage is freed.
Packit Service 1d0348
Packit Service 1d0348
     The archive_entry_linkresolver_set_strategy() function selects the opti‐
Packit Service 1d0348
     mal hardlink strategy for the given format.  The format code can be
Packit Service 1d0348
     obtained from archive_format(3).  The function can be called more than
Packit Service 1d0348
     once, but it is recommended to flush all deferred entries first.
Packit Service 1d0348
Packit Service 1d0348
     The archive_entry_linkify() function is the core of
Packit Service 1d0348
     archive_entry_linkresolver.  The entry() argument points to the
Packit Service 1d0348
     archive_entry that should be written.  Depending on the strategy one of
Packit Service 1d0348
     the following actions is taken:
Packit Service 1d0348
Packit Service 1d0348
     1.   For the simple archive formats *entry is left unmodified and *sparse
Packit Service 1d0348
	  is set to NULL.
Packit Service 1d0348
Packit Service 1d0348
     2.   For tar like archive formats, *sparse is set to NULL.  If *entry is
Packit Service 1d0348
	  NULL, no action is taken.  If the hardlink count of *entry is larger
Packit Service 1d0348
	  than 1 and the file type is a regular file or symbolic link, the
Packit Service 1d0348
	  internal list is searched for a matching inode.  If such an inode is
Packit Service 1d0348
	  found, the link count is decremented and the file size of *entry is
Packit Service 1d0348
	  set to 0 to notify that no body should be written.  If no such inode
Packit Service 1d0348
	  is found, a copy of the entry is added to the internal cache with a
Packit Service 1d0348
	  link count reduced by one.
Packit Service 1d0348
Packit Service 1d0348
     3.   For new cpio like archive formats a value for *entry of NULL is used
Packit Service 1d0348
	  to flush deferred entries.  In that case *entry is set to an arbi‐
Packit Service 1d0348
	  trary deferred entry and the entry itself is removed from the inter‐
Packit Service 1d0348
	  nal list.  If the internal list is empty, *entry is set to NULL.  In
Packit Service 1d0348
	  either case, *sparse is set to NULL and the function returns.  If
Packit Service 1d0348
	  the hardlink count of *entry is one or the file type is a directory
Packit Service 1d0348
	  or device, *sparse is set to NULL and no further action is taken.
Packit Service 1d0348
	  Otherwise, the internal list is searched for a matching inode.  If
Packit Service 1d0348
	  such an inode is not found, the entry is added to the internal list,
Packit Service 1d0348
	  both *entry and *sparse are set to NULL and the function returns.
Packit Service 1d0348
	  If such an inode is found, the link count is decremented.  If it
Packit Service 1d0348
	  remains larger than one, the existing entry on the internal list is
Packit Service 1d0348
	  swapped with *entry after retaining the link count.  The existing
Packit Service 1d0348
	  entry is returned in *entry.	If the link count reached one, the new
Packit Service 1d0348
	  entry is also removed from the internal list and returned in
Packit Service 1d0348
	  *sparse.  Otherwise *sparse is set to NULL.
Packit Service 1d0348
Packit Service 1d0348
     The general usage is therefore:
Packit Service 1d0348
Packit Service 1d0348
     1.   For each new archive entry, call archive_entry_linkify().
Packit Service 1d0348
Packit Service 1d0348
     2.   Keep in mind that the entries returned may have a size of 0 now.
Packit Service 1d0348
Packit Service 1d0348
     3.   If *entry is not NULL, archive it.
Packit Service 1d0348
Packit Service 1d0348
     4.   If *sparse is not NULL, archive it.
Packit Service 1d0348
Packit Service 1d0348
     5.   After all entries have been written to disk, call
Packit Service 1d0348
	  archive_entry_linkify() with *entry set to NULL and archive the
Packit Service 1d0348
	  returned entry as long as it is not NULL.
Packit Service 1d0348
Packit Service 1d0348
RETURN VALUES
Packit Service 1d0348
     archive_entry_linkresolver_new() returns NULL on malloc(3) failures.
Packit Service 1d0348
Packit Service 1d0348
SEE ALSO
Packit Service 1d0348
     archive_entry(3)
Packit Service 1d0348
Packit Service 1d0348
BSD			       February 2, 2012 			   BSD