Add our READMEs.
[dragonfly/vkernel-mp.git] / contrib / libarchive-2.1 / libarchive / archive_read_private.h
blobd8cfa75386ccad854806e4c4acd9bc52a6a9aca5
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.2 2007/04/02 00:11:54 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 * Decompressors have a very specific lifecycle:
90 * public setup function initializes a slot in this table
91 * 'config' holds minimal configuration data
92 * bid() examines a block of data and returns a bid [1]
93 * init() is called for successful bidder
94 * 'data' is initialized by init()
95 * read() returns a pointer to the next block of data
96 * consume() indicates how much data is used
97 * skip() ignores bytes of data
98 * finish() cleans up and frees 'data' and 'config'
100 * [1] General guideline: bid the number of bits that you actually
101 * test, e.g., 16 if you test a 2-byte magic value.
103 struct decompressor_t {
104 void *config;
105 void *data;
106 int (*bid)(const void *buff, size_t);
107 int (*init)(struct archive_read *,
108 const void *buff, size_t);
109 int (*finish)(struct archive_read *);
110 ssize_t (*read_ahead)(struct archive_read *,
111 const void **, size_t);
112 ssize_t (*consume)(struct archive_read *, size_t);
113 off_t (*skip)(struct archive_read *, off_t);
114 } decompressors[4];
116 /* Pointer to current decompressor. */
117 struct decompressor_t *decompressor;
120 * Format detection is mostly the same as compression
121 * detection, with two significant differences: The bidders
122 * use the read_ahead calls above to examine the stream rather
123 * than having the supervisor hand them a block of data to
124 * examine, and the auction is repeated for every header.
125 * Winning bidders should set the archive_format and
126 * archive_format_name appropriately. Bid routines should
127 * check archive_format and decline to bid if the format of
128 * the last header was incompatible.
130 * Again, write support is considerably simpler because there's
131 * no need for an auction.
134 struct archive_format_descriptor {
135 void *data;
136 int (*bid)(struct archive_read *);
137 int (*read_header)(struct archive_read *, struct archive_entry *);
138 int (*read_data)(struct archive_read *, const void **, size_t *, off_t *);
139 int (*read_data_skip)(struct archive_read *);
140 int (*cleanup)(struct archive_read *);
141 } formats[8];
142 struct archive_format_descriptor *format; /* Active format. */
145 * Pointers to format-specific functions for writing. They're
146 * initialized by archive_write_set_format_XXX() calls.
148 int (*format_init)(struct archive *); /* Only used on write. */
149 int (*format_finish)(struct archive *);
150 int (*format_finish_entry)(struct archive *);
151 int (*format_write_header)(struct archive *,
152 struct archive_entry *);
153 ssize_t (*format_write_data)(struct archive *,
154 const void *buff, size_t);
157 * Various information needed by archive_extract.
159 struct extract *extract;
160 int (*cleanup_archive_extract)(struct archive_read *);
163 int __archive_read_register_format(struct archive_read *a,
164 void *format_data,
165 int (*bid)(struct archive_read *),
166 int (*read_header)(struct archive_read *, struct archive_entry *),
167 int (*read_data)(struct archive_read *, const void **, size_t *, off_t *),
168 int (*read_data_skip)(struct archive_read *),
169 int (*cleanup)(struct archive_read *));
171 struct decompressor_t
172 *__archive_read_register_compression(struct archive_read *a,
173 int (*bid)(const void *, size_t),
174 int (*init)(struct archive_read *, const void *, size_t));
176 #endif