Manpages - archive_entry_linkify.3

Streaming Archive Library (libarchive, -larchive)

Programs that want to create archives have to deal with hardlinks. Hardlinks are handled in different ways by the archive formats. The basic strategies are:

Ignore hardlinks and store the body for each reference (old cpio, zip).

Store the body the first time an inode is seen (ustar, pax).

Store the body the last time an inode is seen (new cpio).

The

functions help by providing a unified interface and handling the complexity behind the scene.

The

functions assume that

instances have valid nlinks, inode and device values. The inode and device value is used to match entries. The nlinks value is used to determined if all references have been found and if the internal references can be recycled.

The

function allocates a new link resolver. The instance can be freed using

All deferred entries are flushed and the internal storage is freed.

The

function selects the optimal hardlink strategy for the given format. The format code can be obtained from

The function can be called more than once, but it is recommended to flush all deferred entries first.

The

function is the core of

The

argument points to the

that should be written. Depending on the strategy one of the following actions is taken:

For the simple archive formats

is left unmodified and

is set to

For tar like archive formats,

is set to

If

is

no action is taken. If the hardlink count of

is larger than 1 and the file type is a regular file or symbolic link, the internal list is searched for a matching inode. If such an inode is found, the link count is decremented and the file size of

is set to 0 to notify that no body should be written. If no such inode is found, a copy of the entry is added to the internal cache with a link count reduced by one.

For new cpio like archive formats a value for

of

is used to flush deferred entries. In that case

is set to an arbitrary deferred entry and the entry itself is removed from the internal list. If the internal list is empty,

is set to

In either case,

is set to

and the function returns. If the hardlink count of

is one or the file type is a directory or device,

is set to

and no further action is taken. Otherwise, the internal list is searched for a matching inode. If such an inode is not found, the entry is added to the internal list, both

and

are set to

and the function returns. If such an inode is found, the link count is decremented. If it remains larger than one, the existing entry on the internal list is swapped with

after retaining the link count. The existing entry is returned in

If the link count reached one, the new entry is also removed from the internal list and returned in

Otherwise

is set to

The general usage is therefore:

For each new archive entry, call

Keep in mind that the entries returned may have a size of 0 now.

If

is not

archive it.

If

is not

archive it.

After all entries have been written to disk, call

with

set to

and archive the returned entry as long as it is not

returns

on

failures.

Author: dt

Created: 2022-02-20 Sun 15:02