Import libarchive and bsdtar version 2.0.25
[dragonfly/port-amd64.git] / contrib / libarchive-2.0 / libarchive / archive_write_private.h
blob817cca3218daeab9a1742d6f36396c2977a92d9b
1 /*-
2 * Copyright (c) 2003-2007 Tim Kientzle
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 * $FreeBSD: src/lib/libarchive/archive_write_private.h,v 1.1 2007/03/03 07:37:36 kientzle Exp $
28 #ifndef ARCHIVE_WRITE_PRIVATE_H_INCLUDED
29 #define ARCHIVE_WRITE_PRIVATE_H_INCLUDED
31 #include "archive.h"
32 #include "archive_string.h"
33 #include "archive_private.h"
35 struct archive_write {
36 struct archive archive;
38 struct archive_entry *entry;
40 /* Dev/ino of the archive being read/written. */
41 dev_t skip_file_dev;
42 ino_t skip_file_ino;
44 /* Utility: Pointer to a block of nulls. */
45 const unsigned char *nulls;
46 size_t null_length;
49 * Used by archive_read_data() to track blocks and copy
50 * data to client buffers, filling gaps with zero bytes.
52 const char *read_data_block;
53 off_t read_data_offset;
54 off_t read_data_output_offset;
55 size_t read_data_remaining;
57 /* Callbacks to open/read/write/close archive stream. */
58 archive_open_callback *client_opener;
59 archive_read_callback *client_reader;
60 archive_skip_callback *client_skipper;
61 archive_write_callback *client_writer;
62 archive_close_callback *client_closer;
63 void *client_data;
66 * Blocking information. Note that bytes_in_last_block is
67 * misleadingly named; I should find a better name. These
68 * control the final output from all compressors, including
69 * compression_none.
71 int bytes_per_block;
72 int bytes_in_last_block;
75 * These control whether data within a gzip/bzip2 compressed
76 * stream gets padded or not. If pad_uncompressed is set,
77 * the data will be padded to a full block before being
78 * compressed. The pad_uncompressed_byte determines the value
79 * that will be used for padding. Note that these have no
80 * effect on compression "none."
82 int pad_uncompressed;
83 int pad_uncompressed_byte; /* TODO: Support this. */
86 * On write, the client just invokes an archive_write_set function
87 * which sets up the data here directly.
89 void *compression_data; /* Data for (de)compressor. */
90 int (*compression_init)(struct archive_write *); /* Initialize. */
91 int (*compression_finish)(struct archive_write *);
92 int (*compression_write)(struct archive_write *, const void *, size_t);
94 * Read uses a peek/consume I/O model: the decompression code
95 * returns a pointer to the requested block and advances the
96 * file position only when requested by a consume call. This
97 * reduces copying and also simplifies look-ahead for format
98 * detection.
100 ssize_t (*compression_read_ahead)(struct archive *,
101 const void **, size_t request);
102 ssize_t (*compression_read_consume)(struct archive *, size_t);
103 off_t (*compression_skip)(struct archive *, off_t);
106 * Format detection is mostly the same as compression
107 * detection, with two significant differences: The bidders
108 * use the read_ahead calls above to examine the stream rather
109 * than having the supervisor hand them a block of data to
110 * examine, and the auction is repeated for every header.
111 * Winning bidders should set the archive_format and
112 * archive_format_name appropriately. Bid routines should
113 * check archive_format and decline to bid if the format of
114 * the last header was incompatible.
116 * Again, write support is considerably simpler because there's
117 * no need for an auction.
119 int archive_format;
120 const char *archive_format_name;
122 struct archive_format_descriptor {
123 int (*bid)(struct archive *);
124 int (*read_header)(struct archive *, struct archive_entry *);
125 int (*read_data)(struct archive *, const void **, size_t *, off_t *);
126 int (*read_data_skip)(struct archive *);
127 int (*cleanup)(struct archive *);
128 void *format_data; /* Format-specific data for readers. */
129 } formats[8];
130 struct archive_format_descriptor *format; /* Active format. */
133 * Storage for format-specific data. Note that there can be
134 * multiple format readers active at one time, so we need to
135 * allow for multiple format readers to have their data
136 * available. The pformat_data slot here is the solution: on
137 * read, it is guaranteed to always point to a void* variable
138 * that the format can use.
140 void **pformat_data; /* Pointer to current format_data. */
141 void *format_data; /* Used by writers. */
144 * Pointers to format-specific functions for writing. They're
145 * initialized by archive_write_set_format_XXX() calls.
147 int (*format_init)(struct archive_write *);
148 int (*format_finish)(struct archive_write *);
149 int (*format_destroy)(struct archive_write *);
150 int (*format_finish_entry)(struct archive_write *);
151 int (*format_write_header)(struct archive_write *,
152 struct archive_entry *);
153 ssize_t (*format_write_data)(struct archive_write *,
154 const void *buff, size_t);
157 * Various information needed by archive_extract.
159 struct extract *extract;
160 int (*cleanup_archive_extract)(struct archive *);
164 * Utility function to format a USTAR header into a buffer. If
165 * "strict" is set, this tries to create the absolutely most portable
166 * version of a ustar header. If "strict" is set to 0, then it will
167 * relax certain requirements.
169 * Generally, format-specific declarations don't belong in this
170 * header; this is a rare example of a function that is shared by
171 * two very similar formats (ustar and pax).
174 __archive_write_format_header_ustar(struct archive_write *, char buff[512],
175 struct archive_entry *, int tartype, int strict);
177 #endif