compile fixes
[freebsd-src/fkvm-freebsd.git] / lib / libarchive / archive_read_private.h
blob43539831cedfbd6faf9961cb603979f4a8bb7c0d
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$
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;
45 * Used by archive_read_data() to track blocks and copy
46 * data to client buffers, filling gaps with zero bytes.
48 const char *read_data_block;
49 off_t read_data_offset;
50 off_t read_data_output_offset;
51 size_t read_data_remaining;
53 /* Callbacks to open/read/write/close archive stream. */
54 archive_open_callback *client_opener;
55 archive_read_callback *client_reader;
56 archive_skip_callback *client_skipper;
57 archive_close_callback *client_closer;
58 void *client_data;
60 /* File offset of beginning of most recently-read header. */
61 off_t header_position;
64 * Decompressors have a very specific lifecycle:
65 * public setup function initializes a slot in this table
66 * 'config' holds minimal configuration data
67 * bid() examines a block of data and returns a bid [1]
68 * init() is called for successful bidder
69 * 'data' is initialized by init()
70 * read() returns a pointer to the next block of data
71 * consume() indicates how much data is used
72 * skip() ignores bytes of data
73 * finish() cleans up and frees 'data' and 'config'
75 * [1] General guideline: bid the number of bits that you actually
76 * test, e.g., 16 if you test a 2-byte magic value.
78 struct decompressor_t {
79 void *config;
80 void *data;
81 int (*bid)(const void *buff, size_t);
82 int (*init)(struct archive_read *,
83 const void *buff, size_t);
84 int (*finish)(struct archive_read *);
85 ssize_t (*read_ahead)(struct archive_read *,
86 const void **, size_t);
87 ssize_t (*consume)(struct archive_read *, size_t);
88 off_t (*skip)(struct archive_read *, off_t);
89 } decompressors[4];
91 /* Pointer to current decompressor. */
92 struct decompressor_t *decompressor;
95 * Format detection is mostly the same as compression
96 * detection, with one significant difference: The bidders
97 * use the read_ahead calls above to examine the stream rather
98 * than having the supervisor hand them a block of data to
99 * examine.
102 struct archive_format_descriptor {
103 void *data;
104 int (*bid)(struct archive_read *);
105 int (*read_header)(struct archive_read *, struct archive_entry *);
106 int (*read_data)(struct archive_read *, const void **, size_t *, off_t *);
107 int (*read_data_skip)(struct archive_read *);
108 int (*cleanup)(struct archive_read *);
109 } formats[8];
110 struct archive_format_descriptor *format; /* Active format. */
113 * Various information needed by archive_extract.
115 struct extract *extract;
116 int (*cleanup_archive_extract)(struct archive_read *);
119 int __archive_read_register_format(struct archive_read *a,
120 void *format_data,
121 int (*bid)(struct archive_read *),
122 int (*read_header)(struct archive_read *, struct archive_entry *),
123 int (*read_data)(struct archive_read *, const void **, size_t *, off_t *),
124 int (*read_data_skip)(struct archive_read *),
125 int (*cleanup)(struct archive_read *));
127 struct decompressor_t
128 *__archive_read_register_compression(struct archive_read *a,
129 int (*bid)(const void *, size_t),
130 int (*init)(struct archive_read *, const void *, size_t));
132 const void
133 *__archive_read_ahead(struct archive_read *, size_t);
135 #endif