1ARCHIVE_ENTRY_LINKIFY(3) BSD Library Functions Manual ARCHIVE_ENTRY_LINKIFY(3)
2

NAME

4     archive_entry_linkresolver, archive_entry_linkresolver_new,
5     archive_entry_linkresolver_set_strategy, archive_entry_linkresolver_free,
6     archive_entry_linkify — hardlink resolver functions
7

LIBRARY

9     Streaming Archive Library (libarchive, -larchive)
10

SYNOPSIS

12     #include <archive_entry.h>
13
14     struct archive_entry_linkresolver *
15     archive_entry_linkresolver_new(void);
16
17     void
18     archive_entry_linkresolver_set_strategy(struct archive_entry_linkresolver *resolver,
19         int format);
20
21     void
22     archive_entry_linkresolver_free(struct archive_entry_linkresolver *resolver);
23
24     void
25     archive_entry_linkify(struct archive_entry_linkresolver *resolver,
26         struct archive_entry **entry, struct archive_entry **sparse);
27

DESCRIPTION

29     Programs that want to create archives have to deal with hardlinks.
30     Hardlinks are handled in different ways by the archive formats.  The
31     basic strategies are:
32
33     1.   Ignore hardlinks and store the body for each reference (old cpio,
34          zip).
35
36     2.   Store the body the first time an inode is seen (ustar, pax).
37
38     3.   Store the body the last time an inode is seen (new cpio).
39
40     The archive_entry_linkresolver functions help by providing a unified
41     interface and handling the complexity behind the scene.
42
43     The archive_entry_linkresolver functions assume that archive_entry
44     instances have valid nlinks, inode and device values.  The inode and
45     device value is used to match entries.  The nlinks value is used to
46     determined if all references have been found and if the internal refer‐
47     ences can be recycled.
48
49     The archive_entry_linkresolver_new() function allocates a new link
50     resolver.  The instance can be freed using
51     archive_entry_linkresolver_free().  All deferred entries are flushed and
52     the internal storage is freed.
53
54     The archive_entry_linkresolver_set_strategy() function selects the opti‐
55     mal hardlink strategy for the given format.  The format code can be
56     obtained from archive_format(3).  The function can be called more than
57     once, but it is recommended to flush all deferred entries first.
58
59     The archive_entry_linkify() function is the core of
60     archive_entry_linkresolver.  The entry() argument points to the
61     archive_entry that should be written.  Depending on the strategy one of
62     the following actions is taken:
63
64     1.   For the simple archive formats *entry is left unmodified and *sparse
65          is set to NULL.
66
67     2.   For tar like archive formats, *sparse is set to NULL.  If *entry is
68          NULL, no action is taken.  If the hardlink count of *entry is larger
69          than 1 and the file type is a regular file or symbolic link, the
70          internal list is searched for a matching inode.  If such an inode is
71          found, the link count is decremented and the file size of *entry is
72          set to 0 to notify that no body should be written.  If no such inode
73          is found, a copy of the entry is added to the internal cache with a
74          link count reduced by one.
75
76     3.   For new cpio like archive formats a value for *entry of NULL is used
77          to flush deferred entries.  In that case *entry is set to an arbi‐
78          trary deferred entry and the entry itself is removed from the inter‐
79          nal list.  If the internal list is empty, *entry is set to NULL.  In
80          either case, *sparse is set to NULL and the function returns.  If
81          the hardlink count of *entry is one or the file type is a directory
82          or device, *sparse is set to NULL and no further action is taken.
83          Otherwise, the internal list is searched for a matching inode.  If
84          such an inode is not found, the entry is added to the internal list,
85          both *entry and *sparse are set to NULL and the function returns.
86          If such an inode is found, the link count is decremented.  If it
87          remains larger than one, the existing entry on the internal list is
88          swapped with *entry after retaining the link count.  The existing
89          entry is returned in *entry.  If the link count reached one, the new
90          entry is also removed from the internal list and returned in
91          *sparse.  Otherwise *sparse is set to NULL.
92
93     The general usage is therefore:
94
95     1.   For each new archive entry, call archive_entry_linkify().
96
97     2.   Keep in mind that the entries returned may have a size of 0 now.
98
99     3.   If *entry is not NULL, archive it.
100
101     4.   If *sparse is not NULL, archive it.
102
103     5.   After all entries have been written to disk, call
104          archive_entry_linkify() with *entry set to NULL and archive the
105          returned entry as long as it is not NULL.
106

RETURN VALUES

108     archive_entry_linkresolver_new() returns NULL on malloc(3) failures.
109

SEE ALSO

111     archive_entry(3)
112
113BSD                            February 2, 2012                            BSD
Impressum