archive_private.h revision 1.1.1.1.4.2
1/*- 2 * Copyright (c) 2003-2007 Tim Kientzle 3 * All rights reserved. 4 * 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. 13 * 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. 24 * 25 * $FreeBSD: src/lib/libarchive/archive_private.h,v 1.29 2007/04/02 00:15:45 kientzle Exp $ 26 */ 27 28#ifndef ARCHIVE_PRIVATE_H_INCLUDED 29#define ARCHIVE_PRIVATE_H_INCLUDED 30 31#include "archive.h" 32#include "archive_string.h" 33 34#define ARCHIVE_WRITE_MAGIC (0xb0c5c0deU) 35#define ARCHIVE_READ_MAGIC (0xdeb0c5U) 36#define ARCHIVE_WRITE_DISK_MAGIC (0xc001b0c5U) 37 38#define ARCHIVE_STATE_ANY 0xFFFFU 39#define ARCHIVE_STATE_NEW 1U 40#define ARCHIVE_STATE_HEADER 2U 41#define ARCHIVE_STATE_DATA 4U 42#define ARCHIVE_STATE_DATA_END 8U 43#define ARCHIVE_STATE_EOF 0x10U 44#define ARCHIVE_STATE_CLOSED 0x20U 45#define ARCHIVE_STATE_FATAL 0x8000U 46 47struct archive_vtable { 48 int (*archive_write_close)(struct archive *); 49 int (*archive_write_finish)(struct archive *); 50 int (*archive_write_header)(struct archive *, 51 struct archive_entry *); 52 int (*archive_write_finish_entry)(struct archive *); 53 ssize_t (*archive_write_data)(struct archive *, 54 const void *, size_t); 55 ssize_t (*archive_write_data_block)(struct archive *, 56 const void *, size_t, off_t); 57}; 58 59struct archive { 60 /* 61 * The magic/state values are used to sanity-check the 62 * client's usage. If an API function is called at a 63 * ridiculous time, or the client passes us an invalid 64 * pointer, these values allow me to catch that. 65 */ 66 unsigned int magic; 67 unsigned int state; 68 69 /* 70 * Some public API functions depend on the "real" type of the 71 * archive object. 72 */ 73 struct archive_vtable *vtable; 74 75 int archive_format; 76 const char *archive_format_name; 77 78 int compression_code; /* Currently active compression. */ 79 const char *compression_name; 80 81 /* Position in UNCOMPRESSED data stream. */ 82 off_t file_position; 83 /* Position in COMPRESSED data stream. */ 84 off_t raw_position; 85 86 int archive_error_number; 87 const char *error; 88 struct archive_string error_string; 89}; 90 91/* Check magic value and state; exit if it isn't valid. */ 92void __archive_check_magic(struct archive *, unsigned int magic, 93 unsigned int state, const char *func); 94 95void __archive_errx(int retvalue, const char *msg); 96 97#define err_combine(a,b) ((a) < (b) ? (a) : (b)) 98 99#endif 100