Blame doc/text/archive_entry_linkify.3.txt

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