archive_write_private.h revision 228759
1290375Srodrigc/*-
2290375Srodrigc * Copyright (c) 2003-2007 Tim Kientzle
3290375Srodrigc * All rights reserved.
4290375Srodrigc *
5290375Srodrigc * Redistribution and use in source and binary forms, with or without
6290375Srodrigc * modification, are permitted provided that the following conditions
7290375Srodrigc * are met:
8290375Srodrigc * 1. Redistributions of source code must retain the above copyright
9290375Srodrigc *    notice, this list of conditions and the following disclaimer.
10290375Srodrigc * 2. Redistributions in binary form must reproduce the above copyright
11290375Srodrigc *    notice, this list of conditions and the following disclaimer in the
12290375Srodrigc *    documentation and/or other materials provided with the distribution.
13290375Srodrigc *
14290375Srodrigc * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15290375Srodrigc * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16290375Srodrigc * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17290375Srodrigc * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18290375Srodrigc * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19290375Srodrigc * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20290375Srodrigc * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21290375Srodrigc * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22290375Srodrigc * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23290375Srodrigc * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24290375Srodrigc *
25290375Srodrigc * $FreeBSD: head/lib/libarchive/archive_write_private.h 201155 2009-12-29 05:20:12Z kientzle $
26290375Srodrigc */
27290375Srodrigc
28290375Srodrigc#ifndef __LIBARCHIVE_BUILD
29290375Srodrigc#error This header is only to be used internally to libarchive.
30290375Srodrigc#endif
31290375Srodrigc
32290375Srodrigc#ifndef ARCHIVE_WRITE_PRIVATE_H_INCLUDED
33290375Srodrigc#define	ARCHIVE_WRITE_PRIVATE_H_INCLUDED
34290375Srodrigc
35290375Srodrigc#include "archive.h"
36290375Srodrigc#include "archive_string.h"
37290375Srodrigc#include "archive_private.h"
38290375Srodrigc
39290375Srodrigcstruct archive_write {
40290375Srodrigc	struct archive	archive;
41290375Srodrigc
42290375Srodrigc	/* Dev/ino of the archive being written. */
43290375Srodrigc	dev_t		  skip_file_dev;
44290375Srodrigc	int64_t		  skip_file_ino;
45290375Srodrigc
46290375Srodrigc	/* Utility:  Pointer to a block of nulls. */
47290375Srodrigc	const unsigned char	*nulls;
48290375Srodrigc	size_t			 null_length;
49290375Srodrigc
50290375Srodrigc	/* Callbacks to open/read/write/close archive stream. */
51290375Srodrigc	archive_open_callback	*client_opener;
52290375Srodrigc	archive_write_callback	*client_writer;
53290375Srodrigc	archive_close_callback	*client_closer;
54290375Srodrigc	void			*client_data;
55290375Srodrigc
56290375Srodrigc	/*
57290375Srodrigc	 * Blocking information.  Note that bytes_in_last_block is
58290375Srodrigc	 * misleadingly named; I should find a better name.  These
59290375Srodrigc	 * control the final output from all compressors, including
60290375Srodrigc	 * compression_none.
61290375Srodrigc	 */
62290375Srodrigc	int		  bytes_per_block;
63290375Srodrigc	int		  bytes_in_last_block;
64290375Srodrigc
65290375Srodrigc	/*
66290375Srodrigc	 * These control whether data within a gzip/bzip2 compressed
67290375Srodrigc	 * stream gets padded or not.  If pad_uncompressed is set,
68290375Srodrigc	 * the data will be padded to a full block before being
69290375Srodrigc	 * compressed.  The pad_uncompressed_byte determines the value
70290375Srodrigc	 * that will be used for padding.  Note that these have no
71290375Srodrigc	 * effect on compression "none."
72290375Srodrigc	 */
73290375Srodrigc	int		  pad_uncompressed;
74290375Srodrigc	int		  pad_uncompressed_byte; /* TODO: Support this. */
75290375Srodrigc
76290375Srodrigc	/*
77290375Srodrigc	 * On write, the client just invokes an archive_write_set function
78290375Srodrigc	 * which sets up the data here directly.
79290375Srodrigc	 */
80290375Srodrigc	struct {
81290375Srodrigc		void	 *data;
82290375Srodrigc		void	 *config;
83290375Srodrigc		int	(*init)(struct archive_write *);
84290375Srodrigc		int	(*options)(struct archive_write *,
85290375Srodrigc			    const char *key, const char *value);
86290375Srodrigc		int	(*finish)(struct archive_write *);
87290375Srodrigc		int	(*write)(struct archive_write *, const void *, size_t);
88290375Srodrigc	} compressor;
89290375Srodrigc
90290375Srodrigc	/*
91290375Srodrigc	 * Pointers to format-specific functions for writing.  They're
92290375Srodrigc	 * initialized by archive_write_set_format_XXX() calls.
93290375Srodrigc	 */
94290375Srodrigc	void	 *format_data;
95290375Srodrigc	const char *format_name;
96290375Srodrigc	int	(*format_init)(struct archive_write *);
97290375Srodrigc	int	(*format_options)(struct archive_write *,
98290375Srodrigc		    const char *key, const char *value);
99290375Srodrigc	int	(*format_finish)(struct archive_write *);
100290375Srodrigc	int	(*format_destroy)(struct archive_write *);
101290375Srodrigc	int	(*format_finish_entry)(struct archive_write *);
102290375Srodrigc	int 	(*format_write_header)(struct archive_write *,
103290375Srodrigc		    struct archive_entry *);
104290375Srodrigc	ssize_t	(*format_write_data)(struct archive_write *,
105290375Srodrigc		    const void *buff, size_t);
106290375Srodrigc};
107290375Srodrigc
108290375Srodrigc/*
109290375Srodrigc * Utility function to format a USTAR header into a buffer.  If
110290375Srodrigc * "strict" is set, this tries to create the absolutely most portable
111290375Srodrigc * version of a ustar header.  If "strict" is set to 0, then it will
112290375Srodrigc * relax certain requirements.
113290375Srodrigc *
114290375Srodrigc * Generally, format-specific declarations don't belong in this
115290375Srodrigc * header; this is a rare example of a function that is shared by
116290375Srodrigc * two very similar formats (ustar and pax).
117290375Srodrigc */
118290375Srodrigcint
119290375Srodrigc__archive_write_format_header_ustar(struct archive_write *, char buff[512],
120290375Srodrigc    struct archive_entry *, int tartype, int strict);
121290375Srodrigc
122290375Srodrigc#endif
123290375Srodrigc