Import libarchive and bsdtar version 2.0.25
[dragonfly/port-amd64.git] / contrib / libarchive-2.0 / libarchive / archive_read_private.h
blobcca2fd86503472015530fc217f26b85694d258d6
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_read_private.h,v 1.1 2007/03/03 07:37:36 kientzle Exp $
28 #ifndef ARCHIVE_READ_PRIVATE_H_INCLUDED
29 #define ARCHIVE_READ_PRIVATE_H_INCLUDED
31 #include "archive.h"
32 #include "archive_string.h"
33 #include "archive_private.h"
35 struct archive_read {
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. */
85 /* File offset of beginning of most recently-read header. */
86 off_t header_position;
89 * Detection functions for decompression: bid functions are
90 * given a block of data from the beginning of the stream and
91 * can bid on whether or not they support the data stream.
92 * General guideline: bid the number of bits that you actually
93 * test, e.g., 16 if you test a 2-byte magic value. The
94 * highest bidder will have their init function invoked, which
95 * can set up pointers to specific handlers.
97 * On write, the client just invokes an archive_write_set function
98 * which sets up the data here directly.
100 struct {
101 int (*bid)(const void *buff, size_t);
102 int (*init)(struct archive_read *, const void *buff, size_t);
103 } decompressors[4];
104 /* Read/write data stream (with compression). */
105 void *compression_data; /* Data for (de)compressor. */
106 int (*compression_init)(struct archive_read *); /* Initialize. */
107 int (*compression_finish)(struct archive_read *);
108 int (*compression_write)(struct archive_read *, const void *, size_t);
110 * Read uses a peek/consume I/O model: the decompression code
111 * returns a pointer to the requested block and advances the
112 * file position only when requested by a consume call. This
113 * reduces copying and also simplifies look-ahead for format
114 * detection.
116 ssize_t (*compression_read_ahead)(struct archive_read *,
117 const void **, size_t request);
118 ssize_t (*compression_read_consume)(struct archive_read *, size_t);
119 off_t (*compression_skip)(struct archive_read *, off_t);
122 * Format detection is mostly the same as compression
123 * detection, with two significant differences: The bidders
124 * use the read_ahead calls above to examine the stream rather
125 * than having the supervisor hand them a block of data to
126 * examine, and the auction is repeated for every header.
127 * Winning bidders should set the archive_format and
128 * archive_format_name appropriately. Bid routines should
129 * check archive_format and decline to bid if the format of
130 * the last header was incompatible.
132 * Again, write support is considerably simpler because there's
133 * no need for an auction.
136 struct archive_format_descriptor {
137 int (*bid)(struct archive_read *);
138 int (*read_header)(struct archive_read *, struct archive_entry *);
139 int (*read_data)(struct archive_read *, const void **, size_t *, off_t *);
140 int (*read_data_skip)(struct archive_read *);
141 int (*cleanup)(struct archive_read *);
142 void *format_data; /* Format-specific data for readers. */
143 } formats[8];
144 struct archive_format_descriptor *format; /* Active format. */
147 * Storage for format-specific data. Note that there can be
148 * multiple format readers active at one time, so we need to
149 * allow for multiple format readers to have their data
150 * available. The pformat_data slot here is the solution: on
151 * read, it is guaranteed to always point to a void* variable
152 * that the format can use.
154 void **pformat_data; /* Pointer to current format_data. */
155 void *format_data; /* Used by writers. */
158 * Pointers to format-specific functions for writing. They're
159 * initialized by archive_write_set_format_XXX() calls.
161 int (*format_init)(struct archive *); /* Only used on write. */
162 int (*format_finish)(struct archive *);
163 int (*format_finish_entry)(struct archive *);
164 int (*format_write_header)(struct archive *,
165 struct archive_entry *);
166 ssize_t (*format_write_data)(struct archive *,
167 const void *buff, size_t);
170 * Various information needed by archive_extract.
172 struct extract *extract;
173 int (*cleanup_archive_extract)(struct archive_read *);
176 int __archive_read_register_format(struct archive_read *a,
177 void *format_data,
178 int (*bid)(struct archive_read *),
179 int (*read_header)(struct archive_read *, struct archive_entry *),
180 int (*read_data)(struct archive_read *, const void **, size_t *, off_t *),
181 int (*read_data_skip)(struct archive_read *),
182 int (*cleanup)(struct archive_read *));
184 int __archive_read_register_compression(struct archive_read *a,
185 int (*bid)(const void *, size_t),
186 int (*init)(struct archive_read *, const void *, size_t));
188 #endif