Blame libarchive/archive_entry_linkify.3

Packit Service 1d0348
.\" Copyright (c) 2010 Joerg Sonnenberger
Packit Service 1d0348
.\" All rights reserved.
Packit Service 1d0348
.\"
Packit Service 1d0348
.\" Redistribution and use in source and binary forms, with or without
Packit Service 1d0348
.\" modification, are permitted provided that the following conditions
Packit Service 1d0348
.\" are met:
Packit Service 1d0348
.\" 1. Redistributions of source code must retain the above copyright
Packit Service 1d0348
.\"    notice, this list of conditions and the following disclaimer.
Packit Service 1d0348
.\" 2. Redistributions in binary form must reproduce the above copyright
Packit Service 1d0348
.\"    notice, this list of conditions and the following disclaimer in the
Packit Service 1d0348
.\"    documentation and/or other materials provided with the distribution.
Packit Service 1d0348
.\"
Packit Service 1d0348
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
Packit Service 1d0348
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit Service 1d0348
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit Service 1d0348
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
Packit Service 1d0348
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Packit Service 1d0348
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
Packit Service 1d0348
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
Packit Service 1d0348
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
Packit Service 1d0348
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
Packit Service 1d0348
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
Packit Service 1d0348
.\" SUCH DAMAGE.
Packit Service 1d0348
.\"
Packit Service 1d0348
.Dd February 2, 2012
Packit Service 1d0348
.Dt ARCHIVE_ENTRY_LINKIFY 3
Packit Service 1d0348
.Os
Packit Service 1d0348
.Sh NAME
Packit Service 1d0348
.Nm archive_entry_linkresolver ,
Packit Service 1d0348
.Nm archive_entry_linkresolver_new ,
Packit Service 1d0348
.Nm archive_entry_linkresolver_set_strategy ,
Packit Service 1d0348
.Nm archive_entry_linkresolver_free ,
Packit Service 1d0348
.Nm archive_entry_linkify
Packit Service 1d0348
.Nd hardlink resolver functions
Packit Service 1d0348
.Sh LIBRARY
Packit Service 1d0348
Streaming Archive Library (libarchive, -larchive)
Packit Service 1d0348
.Sh SYNOPSIS
Packit Service 1d0348
.In archive_entry.h
Packit Service 1d0348
.Ft struct archive_entry_linkresolver *
Packit Service 1d0348
.Fn archive_entry_linkresolver_new void
Packit Service 1d0348
.Ft void
Packit Service 1d0348
.Fo archive_entry_linkresolver_set_strategy
Packit Service 1d0348
.Fa "struct archive_entry_linkresolver *resolver"
Packit Service 1d0348
.Fa "int format"
Packit Service 1d0348
.Fc
Packit Service 1d0348
.Ft void
Packit Service 1d0348
.Fo archive_entry_linkresolver_free
Packit Service 1d0348
.Fa "struct archive_entry_linkresolver *resolver"
Packit Service 1d0348
.Fc
Packit Service 1d0348
.Ft void
Packit Service 1d0348
.Fo archive_entry_linkify
Packit Service 1d0348
.Fa "struct archive_entry_linkresolver *resolver"
Packit Service 1d0348
.Fa "struct archive_entry **entry"
Packit Service 1d0348
.Fa "struct archive_entry **sparse"
Packit Service 1d0348
.Fc
Packit Service 1d0348
.Sh 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.
Packit Service 1d0348
The basic strategies are:
Packit Service 1d0348
.Bl -enum
Packit Service 1d0348
.It
Packit Service 1d0348
Ignore hardlinks and store the body for each reference (old cpio, zip).
Packit Service 1d0348
.It
Packit Service 1d0348
Store the body the first time an inode is seen (ustar, pax).
Packit Service 1d0348
.It
Packit Service 1d0348
Store the body the last time an inode is seen (new cpio).
Packit Service 1d0348
.El
Packit Service 1d0348
.Pp
Packit Service 1d0348
The
Packit Service 1d0348
.Nm
Packit Service 1d0348
functions help by providing a unified interface and handling the complexity
Packit Service 1d0348
behind the scene.
Packit Service 1d0348
.Pp
Packit Service 1d0348
The
Packit Service 1d0348
.Nm
Packit Service 1d0348
functions assume that
Packit Service 1d0348
.Vt archive_entry
Packit Service 1d0348
instances have valid nlinks, inode and device values.
Packit Service 1d0348
The inode and device value is used to match entries.
Packit Service 1d0348
The nlinks value is used to determined if all references have been found and
Packit Service 1d0348
if the internal references can be recycled.
Packit Service 1d0348
.Pp
Packit Service 1d0348
The
Packit Service 1d0348
.Fn archive_entry_linkresolver_new
Packit Service 1d0348
function allocates a new link resolver.
Packit Service 1d0348
The instance can be freed using
Packit Service 1d0348
.Fn archive_entry_linkresolver_free .
Packit Service 1d0348
All deferred entries are flushed and the internal storage is freed.
Packit Service 1d0348
.Pp
Packit Service 1d0348
The
Packit Service 1d0348
.Fn archive_entry_linkresolver_set_strategy
Packit Service 1d0348
function selects the optimal hardlink strategy for the given format.
Packit Service 1d0348
The format code can be obtained from
Packit Service 1d0348
.Xr archive_format 3 .
Packit Service 1d0348
The function can be called more than once, but it is recommended to
Packit Service 1d0348
flush all deferred entries first.
Packit Service 1d0348
.Pp
Packit Service 1d0348
The
Packit Service 1d0348
.Fn archive_entry_linkify
Packit Service 1d0348
function is the core of
Packit Service 1d0348
.Nm .
Packit Service 1d0348
The
Packit Service 1d0348
.Fn entry
Packit Service 1d0348
argument points to the
Packit Service 1d0348
.Vt archive_entry
Packit Service 1d0348
that should be written.
Packit Service 1d0348
Depending on the strategy one of the following actions is taken:
Packit Service 1d0348
.Bl -enum
Packit Service 1d0348
.It
Packit Service 1d0348
For the simple archive formats
Packit Service 1d0348
.Va *entry
Packit Service 1d0348
is left unmodified and
Packit Service 1d0348
.Va *sparse
Packit Service 1d0348
is set to
Packit Service 1d0348
.Dv NULL .
Packit Service 1d0348
.It
Packit Service 1d0348
For tar like archive formats,
Packit Service 1d0348
.Va *sparse
Packit Service 1d0348
is set to
Packit Service 1d0348
.Dv NULL .
Packit Service 1d0348
If
Packit Service 1d0348
.Va *entry
Packit Service 1d0348
is
Packit Service 1d0348
.Dv NULL ,
Packit Service 1d0348
no action is taken.
Packit Service 1d0348
If the hardlink count of
Packit Service 1d0348
.Va *entry
Packit Service 1d0348
is larger than 1 and the file type is a regular file or symbolic link,
Packit Service 1d0348
the internal list is searched for a matching inode.
Packit Service 1d0348
If such an inode is found, the link count is decremented and the file size
Packit Service 1d0348
of
Packit Service 1d0348
.Va *entry
Packit Service 1d0348
is set to 0 to notify that no body should be written.
Packit Service 1d0348
If no such inode is found, a copy of the entry is added to the internal cache
Packit Service 1d0348
with a link count reduced by one.
Packit Service 1d0348
.It
Packit Service 1d0348
For new cpio like archive formats a value for
Packit Service 1d0348
.Va *entry
Packit Service 1d0348
of
Packit Service 1d0348
.Dv NULL
Packit Service 1d0348
is used to flush deferred entries.
Packit Service 1d0348
In that case
Packit Service 1d0348
.Va *entry
Packit Service 1d0348
is set to an arbitrary deferred entry and the entry itself is removed from the
Packit Service 1d0348
internal list.
Packit Service 1d0348
If the internal list is empty,
Packit Service 1d0348
.Va *entry
Packit Service 1d0348
is set to
Packit Service 1d0348
.Dv NULL .
Packit Service 1d0348
In either case,
Packit Service 1d0348
.Va *sparse
Packit Service 1d0348
is set to
Packit Service 1d0348
.Dv NULL
Packit Service 1d0348
and the function returns.
Packit Service 1d0348
If the hardlink count of
Packit Service 1d0348
.Va *entry
Packit Service 1d0348
is one or the file type is a directory or device,
Packit Service 1d0348
.Va *sparse
Packit Service 1d0348
is set to
Packit Service 1d0348
.Dv NULL
Packit Service 1d0348
and no further action is taken.
Packit Service 1d0348
Otherwise, the internal list is searched for a matching inode.
Packit Service 1d0348
If such an inode is not found, the entry is added to the internal list,
Packit Service 1d0348
both
Packit Service 1d0348
.Va *entry
Packit Service 1d0348
and
Packit Service 1d0348
.Va *sparse
Packit Service 1d0348
are set to
Packit Service 1d0348
.Dv NULL
Packit Service 1d0348
and the function returns.
Packit Service 1d0348
If such an inode is found, the link count is decremented.
Packit Service 1d0348
If it remains larger than one, the existing entry on the internal list
Packit Service 1d0348
is swapped with
Packit Service 1d0348
.Va *entry
Packit Service 1d0348
after retaining the link count.
Packit Service 1d0348
The existing entry is returned in
Packit Service 1d0348
.Va *entry .
Packit Service 1d0348
If the link count reached one, the new entry is also removed from the
Packit Service 1d0348
internal list and returned in
Packit Service 1d0348
.Va *sparse .
Packit Service 1d0348
Otherwise
Packit Service 1d0348
.Va *sparse
Packit Service 1d0348
is set to
Packit Service 1d0348
.Dv NULL .
Packit Service 1d0348
.El
Packit Service 1d0348
.Pp
Packit Service 1d0348
The general usage is therefore:
Packit Service 1d0348
.Bl -enum
Packit Service 1d0348
.It
Packit Service 1d0348
For each new archive entry, call
Packit Service 1d0348
.Fn archive_entry_linkify .
Packit Service 1d0348
.It
Packit Service 1d0348
Keep in mind that the entries returned may have a size of 0 now.
Packit Service 1d0348
.It
Packit Service 1d0348
If
Packit Service 1d0348
.Va *entry
Packit Service 1d0348
is not
Packit Service 1d0348
.Dv NULL ,
Packit Service 1d0348
archive it.
Packit Service 1d0348
.It
Packit Service 1d0348
If
Packit Service 1d0348
.Va *sparse
Packit Service 1d0348
is not
Packit Service 1d0348
.Dv NULL ,
Packit Service 1d0348
archive it.
Packit Service 1d0348
.It
Packit Service 1d0348
After all entries have been written to disk, call
Packit Service 1d0348
.Fn archive_entry_linkify
Packit Service 1d0348
with
Packit Service 1d0348
.Va *entry
Packit Service 1d0348
set to
Packit Service 1d0348
.Dv NULL
Packit Service 1d0348
and archive the returned entry as long as it is not
Packit Service 1d0348
.Dv NULL .
Packit Service 1d0348
.El
Packit Service 1d0348
.Sh RETURN VALUES
Packit Service 1d0348
.Fn archive_entry_linkresolver_new
Packit Service 1d0348
returns
Packit Service 1d0348
.Dv NULL
Packit Service 1d0348
on
Packit Service 1d0348
.Xr malloc 3
Packit Service 1d0348
failures.
Packit Service 1d0348
.Sh SEE ALSO
Packit Service 1d0348
.Xr archive_entry 3