160b4ad09SPeter Avalos /*- 260b4ad09SPeter Avalos * Copyright (c) 2003-2007 Tim Kientzle 360b4ad09SPeter Avalos * All rights reserved. 460b4ad09SPeter Avalos * 560b4ad09SPeter Avalos * Redistribution and use in source and binary forms, with or without 660b4ad09SPeter Avalos * modification, are permitted provided that the following conditions 760b4ad09SPeter Avalos * are met: 860b4ad09SPeter Avalos * 1. Redistributions of source code must retain the above copyright 960b4ad09SPeter Avalos * notice, this list of conditions and the following disclaimer. 1060b4ad09SPeter Avalos * 2. Redistributions in binary form must reproduce the above copyright 1160b4ad09SPeter Avalos * notice, this list of conditions and the following disclaimer in the 1260b4ad09SPeter Avalos * documentation and/or other materials provided with the distribution. 1360b4ad09SPeter Avalos * 1460b4ad09SPeter Avalos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 1560b4ad09SPeter Avalos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1660b4ad09SPeter Avalos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1760b4ad09SPeter Avalos * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 1860b4ad09SPeter Avalos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1960b4ad09SPeter Avalos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2060b4ad09SPeter Avalos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2160b4ad09SPeter Avalos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2260b4ad09SPeter Avalos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2360b4ad09SPeter Avalos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2460b4ad09SPeter Avalos * 259c82a63eSPeter Avalos * $FreeBSD: head/lib/libarchive/archive_write_private.h 201155 2009-12-29 05:20:12Z kientzle $ 2660b4ad09SPeter Avalos */ 2760b4ad09SPeter Avalos 28085658deSDaniel Fojt #ifndef ARCHIVE_WRITE_PRIVATE_H_INCLUDED 29085658deSDaniel Fojt #define ARCHIVE_WRITE_PRIVATE_H_INCLUDED 30085658deSDaniel Fojt 319c82a63eSPeter Avalos #ifndef __LIBARCHIVE_BUILD 326b384f39SPeter Avalos #ifndef __LIBARCHIVE_TEST 339c82a63eSPeter Avalos #error This header is only to be used internally to libarchive. 349c82a63eSPeter Avalos #endif 356b384f39SPeter Avalos #endif 369c82a63eSPeter Avalos 3760b4ad09SPeter Avalos #include "archive.h" 3860b4ad09SPeter Avalos #include "archive_string.h" 3960b4ad09SPeter Avalos #include "archive_private.h" 4060b4ad09SPeter Avalos 41085658deSDaniel Fojt #define ARCHIVE_WRITE_FILTER_STATE_NEW 1U 42085658deSDaniel Fojt #define ARCHIVE_WRITE_FILTER_STATE_OPEN 2U 43085658deSDaniel Fojt #define ARCHIVE_WRITE_FILTER_STATE_CLOSED 4U 44085658deSDaniel Fojt #define ARCHIVE_WRITE_FILTER_STATE_FATAL 0x8000U 45085658deSDaniel Fojt 46c09f92d2SPeter Avalos struct archive_write; 47c09f92d2SPeter Avalos 48c09f92d2SPeter Avalos struct archive_write_filter { 49c09f92d2SPeter Avalos int64_t bytes_written; 50c09f92d2SPeter Avalos struct archive *archive; /* Associated archive. */ 51c09f92d2SPeter Avalos struct archive_write_filter *next_filter; /* Who I write to. */ 52c09f92d2SPeter Avalos int (*options)(struct archive_write_filter *, 53c09f92d2SPeter Avalos const char *key, const char *value); 54c09f92d2SPeter Avalos int (*open)(struct archive_write_filter *); 55c09f92d2SPeter Avalos int (*write)(struct archive_write_filter *, const void *, size_t); 56c09f92d2SPeter Avalos int (*close)(struct archive_write_filter *); 57c09f92d2SPeter Avalos int (*free)(struct archive_write_filter *); 58c09f92d2SPeter Avalos void *data; 59c09f92d2SPeter Avalos const char *name; 60c09f92d2SPeter Avalos int code; 61c09f92d2SPeter Avalos int bytes_per_block; 62c09f92d2SPeter Avalos int bytes_in_last_block; 63085658deSDaniel Fojt int state; 64c09f92d2SPeter Avalos }; 65c09f92d2SPeter Avalos 66c09f92d2SPeter Avalos #if ARCHIVE_VERSION < 4000000 67c09f92d2SPeter Avalos void __archive_write_filters_free(struct archive *); 68c09f92d2SPeter Avalos #endif 69c09f92d2SPeter Avalos 70c09f92d2SPeter Avalos struct archive_write_filter *__archive_write_allocate_filter(struct archive *); 71c09f92d2SPeter Avalos 72c09f92d2SPeter Avalos int __archive_write_output(struct archive_write *, const void *, size_t); 73c09f92d2SPeter Avalos int __archive_write_nulls(struct archive_write *, size_t); 74c09f92d2SPeter Avalos int __archive_write_filter(struct archive_write_filter *, const void *, size_t); 75c09f92d2SPeter Avalos 7660b4ad09SPeter Avalos struct archive_write { 7760b4ad09SPeter Avalos struct archive archive; 7860b4ad09SPeter Avalos 7960b4ad09SPeter Avalos /* Dev/ino of the archive being written. */ 80c09f92d2SPeter Avalos int skip_file_set; 8159bf7050SPeter Avalos int64_t skip_file_dev; 829c82a63eSPeter Avalos int64_t skip_file_ino; 8360b4ad09SPeter Avalos 8460b4ad09SPeter Avalos /* Utility: Pointer to a block of nulls. */ 8560b4ad09SPeter Avalos const unsigned char *nulls; 8660b4ad09SPeter Avalos size_t null_length; 8760b4ad09SPeter Avalos 8860b4ad09SPeter Avalos /* Callbacks to open/read/write/close archive stream. */ 8960b4ad09SPeter Avalos archive_open_callback *client_opener; 9060b4ad09SPeter Avalos archive_write_callback *client_writer; 9160b4ad09SPeter Avalos archive_close_callback *client_closer; 92*50f8aa9cSAntonio Huete Jimenez archive_free_callback *client_freer; 9360b4ad09SPeter Avalos void *client_data; 9460b4ad09SPeter Avalos 9560b4ad09SPeter Avalos /* 9660b4ad09SPeter Avalos * Blocking information. Note that bytes_in_last_block is 9760b4ad09SPeter Avalos * misleadingly named; I should find a better name. These 9860b4ad09SPeter Avalos * control the final output from all compressors, including 9960b4ad09SPeter Avalos * compression_none. 10060b4ad09SPeter Avalos */ 10160b4ad09SPeter Avalos int bytes_per_block; 10260b4ad09SPeter Avalos int bytes_in_last_block; 10360b4ad09SPeter Avalos 10460b4ad09SPeter Avalos /* 105c09f92d2SPeter Avalos * First and last write filters in the pipeline. 10660b4ad09SPeter Avalos */ 107c09f92d2SPeter Avalos struct archive_write_filter *filter_first; 108c09f92d2SPeter Avalos struct archive_write_filter *filter_last; 10960b4ad09SPeter Avalos 11060b4ad09SPeter Avalos /* 11160b4ad09SPeter Avalos * Pointers to format-specific functions for writing. They're 11260b4ad09SPeter Avalos * initialized by archive_write_set_format_XXX() calls. 11360b4ad09SPeter Avalos */ 11460b4ad09SPeter Avalos void *format_data; 1158029ab02SPeter Avalos const char *format_name; 11660b4ad09SPeter Avalos int (*format_init)(struct archive_write *); 1178029ab02SPeter Avalos int (*format_options)(struct archive_write *, 1188029ab02SPeter Avalos const char *key, const char *value); 11960b4ad09SPeter Avalos int (*format_finish_entry)(struct archive_write *); 12060b4ad09SPeter Avalos int (*format_write_header)(struct archive_write *, 12160b4ad09SPeter Avalos struct archive_entry *); 12260b4ad09SPeter Avalos ssize_t (*format_write_data)(struct archive_write *, 12360b4ad09SPeter Avalos const void *buff, size_t); 124c09f92d2SPeter Avalos int (*format_close)(struct archive_write *); 125c09f92d2SPeter Avalos int (*format_free)(struct archive_write *); 1266b384f39SPeter Avalos 1276b384f39SPeter Avalos 1286b384f39SPeter Avalos /* 1296b384f39SPeter Avalos * Encryption passphrase. 1306b384f39SPeter Avalos */ 1316b384f39SPeter Avalos char *passphrase; 1326b384f39SPeter Avalos archive_passphrase_callback *passphrase_callback; 1336b384f39SPeter Avalos void *passphrase_client_data; 13460b4ad09SPeter Avalos }; 13560b4ad09SPeter Avalos 13660b4ad09SPeter Avalos /* 13760b4ad09SPeter Avalos * Utility function to format a USTAR header into a buffer. If 13860b4ad09SPeter Avalos * "strict" is set, this tries to create the absolutely most portable 13960b4ad09SPeter Avalos * version of a ustar header. If "strict" is set to 0, then it will 14060b4ad09SPeter Avalos * relax certain requirements. 14160b4ad09SPeter Avalos * 14260b4ad09SPeter Avalos * Generally, format-specific declarations don't belong in this 14360b4ad09SPeter Avalos * header; this is a rare example of a function that is shared by 14460b4ad09SPeter Avalos * two very similar formats (ustar and pax). 14560b4ad09SPeter Avalos */ 14660b4ad09SPeter Avalos int 14760b4ad09SPeter Avalos __archive_write_format_header_ustar(struct archive_write *, char buff[512], 148c09f92d2SPeter Avalos struct archive_entry *, int tartype, int strict, 149c09f92d2SPeter Avalos struct archive_string_conv *); 15060b4ad09SPeter Avalos 151d4d8193eSPeter Avalos struct archive_write_program_data; 1526b384f39SPeter Avalos struct archive_write_program_data * __archive_write_program_allocate(const char *program_name); 153d4d8193eSPeter Avalos int __archive_write_program_free(struct archive_write_program_data *); 154d4d8193eSPeter Avalos int __archive_write_program_open(struct archive_write_filter *, 155d4d8193eSPeter Avalos struct archive_write_program_data *, const char *); 156d4d8193eSPeter Avalos int __archive_write_program_close(struct archive_write_filter *, 157d4d8193eSPeter Avalos struct archive_write_program_data *); 158d4d8193eSPeter Avalos int __archive_write_program_write(struct archive_write_filter *, 159d4d8193eSPeter Avalos struct archive_write_program_data *, const void *, size_t); 1606b384f39SPeter Avalos 1616b384f39SPeter Avalos /* 1626b384f39SPeter Avalos * Get a encryption passphrase. 1636b384f39SPeter Avalos */ 1646b384f39SPeter Avalos const char * __archive_write_get_passphrase(struct archive_write *a); 16560b4ad09SPeter Avalos #endif 166