Blame doc/html/archive_entry_linkify.3.html

Packit 08bd4c
Packit 08bd4c
Packit 08bd4c
Packit 08bd4c
"http://www.w3.org/TR/html4/loose.dtd">
Packit 08bd4c
<html>
Packit 08bd4c
<head>
Packit 08bd4c
<meta name="generator" content="groff -Thtml, see www.gnu.org">
Packit 08bd4c
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
Packit 08bd4c
<meta name="Content-Style" content="text/css">
Packit 08bd4c
<style type="text/css">
Packit 08bd4c
       p       { margin-top: 0; margin-bottom: 0; vertical-align: top }
Packit 08bd4c
       pre     { margin-top: 0; margin-bottom: 0; vertical-align: top }
Packit 08bd4c
       table   { margin-top: 0; margin-bottom: 0; vertical-align: top }
Packit 08bd4c
       h1      { text-align: center }
Packit 08bd4c
</style>
Packit 08bd4c
<title></title>
Packit 08bd4c
</head>
Packit 08bd4c
<body>
Packit 08bd4c
Packit 08bd4c

Packit 08bd4c
Packit 08bd4c
Packit 08bd4c

ARCHIVE_ENTRY_LINKIFY(3) BSD Library Functions Manual

Packit 08bd4c
ARCHIVE_ENTRY_LINKIFY(3)

Packit 08bd4c
Packit 08bd4c

NAME

Packit 08bd4c
Packit 08bd4c
Packit 08bd4c

archive_entry_linkresolver,

Packit 08bd4c
archive_entry_linkresolver_new,
Packit 08bd4c
archive_entry_linkresolver_set_strategy,
Packit 08bd4c
archive_entry_linkresolver_free,
Packit 08bd4c
archive_entry_linkify — hardlink resolver
Packit 08bd4c
functions

Packit 08bd4c
Packit 08bd4c

LIBRARY

Packit 08bd4c
Packit 08bd4c

Streaming Archive Library

Packit 08bd4c
(libarchive, -larchive)

Packit 08bd4c
Packit 08bd4c

SYNOPSIS

Packit 08bd4c
Packit 08bd4c

#include

Packit 08bd4c
<archive_entry.h>

Packit 08bd4c
Packit 08bd4c

struct

Packit 08bd4c
archive_entry_linkresolver *

Packit 08bd4c
Packit 08bd4c
Packit 08bd4c

archive_entry_linkresolver_new(void);

Packit 08bd4c
Packit 08bd4c

void

Packit 08bd4c
Packit 08bd4c
Packit 08bd4c

archive_entry_linkresolver_set_strategy(struct archive_entry_linkresolver *resolver,

Packit 08bd4c
int format);

Packit 08bd4c
Packit 08bd4c

void

Packit 08bd4c
Packit 08bd4c
Packit 08bd4c

archive_entry_linkresolver_free(struct archive_entry_linkresolver *resolver);

Packit 08bd4c
Packit 08bd4c

void

Packit 08bd4c
Packit 08bd4c
Packit 08bd4c

archive_entry_linkify(struct archive_entry_linkresolver *resolver,

Packit 08bd4c
struct archive_entry **entry,
Packit 08bd4c
struct archive_entry **sparse);

Packit 08bd4c
Packit 08bd4c

DESCRIPTION

Packit 08bd4c
Packit 08bd4c

Programs that want to create

Packit 08bd4c
archives have to deal with hardlinks. Hardlinks are handled
Packit 08bd4c
in different ways by the archive formats. The basic
Packit 08bd4c
strategies are:

Packit 08bd4c
Packit 08bd4c

1.

Packit 08bd4c
Packit 08bd4c

Ignore hardlinks and store the

Packit 08bd4c
body for each reference (old cpio, zip).

Packit 08bd4c
Packit 08bd4c

2.

Packit 08bd4c
Packit 08bd4c

Store the body the first time

Packit 08bd4c
an inode is seen (ustar, pax).

Packit 08bd4c
Packit 08bd4c

3.

Packit 08bd4c
Packit 08bd4c

Store the body the last time an

Packit 08bd4c
inode is seen (new cpio).

Packit 08bd4c
Packit 08bd4c

The

Packit 08bd4c
archive_entry_linkresolver functions help by
Packit 08bd4c
providing a unified interface and handling the complexity
Packit 08bd4c
behind the scene.

Packit 08bd4c
Packit 08bd4c

The

Packit 08bd4c
archive_entry_linkresolver functions assume that
Packit 08bd4c
archive_entry instances have valid nlinks, inode and
Packit 08bd4c
device values. The inode and device value is used to match
Packit 08bd4c
entries. The nlinks value is used to determined if all
Packit 08bd4c
references have been found and if the internal references
Packit 08bd4c
can be recycled.

Packit 08bd4c
Packit 08bd4c

The

Packit 08bd4c
archive_entry_linkresolver_new() function allocates a
Packit 08bd4c
new link resolver. The instance can be freed using
Packit 08bd4c
archive_entry_linkresolver_free(). All deferred
Packit 08bd4c
entries are flushed and the internal storage is freed.

Packit 08bd4c
Packit 08bd4c

The

Packit 08bd4c
archive_entry_linkresolver_set_strategy() function
Packit 08bd4c
selects the optimal hardlink strategy for the given format.
Packit 08bd4c
The format code can be obtained from archive_format(3). The
Packit 08bd4c
function can be called more than once, but it is recommended
Packit 08bd4c
to flush all deferred entries first.

Packit 08bd4c
Packit 08bd4c

The

Packit 08bd4c
archive_entry_linkify() function is the core of
Packit 08bd4c
archive_entry_linkresolver. The entry()
Packit 08bd4c
argument points to the archive_entry that should be
Packit 08bd4c
written. Depending on the strategy one of the following
Packit 08bd4c
actions is taken:

Packit 08bd4c
Packit 08bd4c

1.

Packit 08bd4c
Packit 08bd4c

For the simple archive formats

Packit 08bd4c
*entry is left unmodified and *sparse is set
Packit 08bd4c
to NULL.

Packit 08bd4c
Packit 08bd4c

2.

Packit 08bd4c
Packit 08bd4c

For tar like archive formats,

Packit 08bd4c
*sparse is set to NULL. If *entry is NULL, no
Packit 08bd4c
action is taken. If the hardlink count of *entry is
Packit 08bd4c
larger than 1 and the file type is a regular file or
Packit 08bd4c
symbolic link, the internal list is searched for a matching
Packit 08bd4c
inode. If such an inode is found, the link count is
Packit 08bd4c
decremented and the file size of *entry is set to 0
Packit 08bd4c
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
Packit 08bd4c
with a link count reduced by one.

Packit 08bd4c
Packit 08bd4c

3.

Packit 08bd4c
Packit 08bd4c

For new cpio like archive

Packit 08bd4c
formats a value for *entry of NULL is used to flush
Packit 08bd4c
deferred entries. In that case *entry is set to an
Packit 08bd4c
arbitrary deferred entry and the entry itself is removed
Packit 08bd4c
from the internal list. If the internal list is empty,
Packit 08bd4c
*entry is set to NULL. In either case, *sparse
Packit 08bd4c
is set to NULL and the function returns. If the hardlink
Packit 08bd4c
count of *entry is one or the file type is a
Packit 08bd4c
directory or device, *sparse is set to NULL and no
Packit 08bd4c
further action is taken. Otherwise, the internal list is
Packit 08bd4c
searched for a matching inode. If such an inode is not
Packit 08bd4c
found, the entry is added to the internal list, both
Packit 08bd4c
*entry and *sparse are set to NULL and the
Packit 08bd4c
function returns. If such an inode is found, the link count
Packit 08bd4c
is decremented. If it remains larger than one, the existing
Packit 08bd4c
entry on the internal list is swapped with *entry
Packit 08bd4c
after retaining the link count. The existing entry is
Packit 08bd4c
returned in *entry. If the link count reached one,
Packit 08bd4c
the new entry is also removed from the internal list and
Packit 08bd4c
returned in *sparse. Otherwise *sparse is set
Packit 08bd4c
to NULL.

Packit 08bd4c
Packit 08bd4c

The general

Packit 08bd4c
usage is therefore:

Packit 08bd4c
Packit 08bd4c

1.

Packit 08bd4c
Packit 08bd4c

For each new archive entry,

Packit 08bd4c
call archive_entry_linkify().

Packit 08bd4c
Packit 08bd4c

2.

Packit 08bd4c
Packit 08bd4c

Keep in mind that the entries

Packit 08bd4c
returned may have a size of 0 now.

Packit 08bd4c
Packit 08bd4c

3.

Packit 08bd4c
Packit 08bd4c

If *entry is not NULL,

Packit 08bd4c
archive it.

Packit 08bd4c
Packit 08bd4c

4.

Packit 08bd4c
Packit 08bd4c

If *sparse is not NULL,

Packit 08bd4c
archive it.

Packit 08bd4c
Packit 08bd4c

5.

Packit 08bd4c
Packit 08bd4c

After all entries have been

Packit 08bd4c
written to disk, call archive_entry_linkify() with
Packit 08bd4c
*entry set to NULL and archive the returned entry as
Packit 08bd4c
long as it is not NULL.

Packit 08bd4c
Packit 08bd4c

RETURN VALUES

Packit 08bd4c
Packit 08bd4c
Packit 08bd4c

archive_entry_linkresolver_new()

Packit 08bd4c
returns NULL on malloc(3) failures.

Packit 08bd4c
Packit 08bd4c

SEE ALSO

Packit 08bd4c
Packit 08bd4c

archive_entry(3)

Packit 08bd4c
Packit 08bd4c

BSD

Packit 08bd4c
February 2, 2012 BSD

Packit 08bd4c

Packit 08bd4c
</body>
Packit 08bd4c
</html>