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_write_private.h,v 1.3 2008/03/15 11:04:45 kientzle Exp $
26  */
27 
28 #ifndef ARCHIVE_WRITE_PRIVATE_H_INCLUDED
29 #define	ARCHIVE_WRITE_PRIVATE_H_INCLUDED
30 
31 #include "archive.h"
32 #include "archive_string.h"
33 #include "archive_private.h"
34 
35 struct archive_write {
36 	struct archive	archive;
37 
38 	/* Dev/ino of the archive being written. */
39 	dev_t		  skip_file_dev;
40 	ino_t		  skip_file_ino;
41 
42 	/* Utility:  Pointer to a block of nulls. */
43 	const unsigned char	*nulls;
44 	size_t			 null_length;
45 
46 	/* Callbacks to open/read/write/close archive stream. */
47 	archive_open_callback	*client_opener;
48 	archive_write_callback	*client_writer;
49 	archive_close_callback	*client_closer;
50 	void			*client_data;
51 
52 	/*
53 	 * Blocking information.  Note that bytes_in_last_block is
54 	 * misleadingly named; I should find a better name.  These
55 	 * control the final output from all compressors, including
56 	 * compression_none.
57 	 */
58 	int		  bytes_per_block;
59 	int		  bytes_in_last_block;
60 
61 	/*
62 	 * These control whether data within a gzip/bzip2 compressed
63 	 * stream gets padded or not.  If pad_uncompressed is set,
64 	 * the data will be padded to a full block before being
65 	 * compressed.  The pad_uncompressed_byte determines the value
66 	 * that will be used for padding.  Note that these have no
67 	 * effect on compression "none."
68 	 */
69 	int		  pad_uncompressed;
70 	int		  pad_uncompressed_byte; /* TODO: Support this. */
71 
72 	/*
73 	 * On write, the client just invokes an archive_write_set function
74 	 * which sets up the data here directly.
75 	 */
76 	struct {
77 		void	 *data;
78 		void	 *config;
79 		int	(*init)(struct archive_write *);
80 		int	(*options)(struct archive_write *,
81 			    const char *key, const char *value);
82 		int	(*finish)(struct archive_write *);
83 		int	(*write)(struct archive_write *, const void *, size_t);
84 	} compressor;
85 
86 	/*
87 	 * Pointers to format-specific functions for writing.  They're
88 	 * initialized by archive_write_set_format_XXX() calls.
89 	 */
90 	void	 *format_data;
91 	const char *format_name;
92 	int	(*format_init)(struct archive_write *);
93 	int	(*format_options)(struct archive_write *,
94 		    const char *key, const char *value);
95 	int	(*format_finish)(struct archive_write *);
96 	int	(*format_destroy)(struct archive_write *);
97 	int	(*format_finish_entry)(struct archive_write *);
98 	int 	(*format_write_header)(struct archive_write *,
99 		    struct archive_entry *);
100 	ssize_t	(*format_write_data)(struct archive_write *,
101 		    const void *buff, size_t);
102 };
103 
104 /*
105  * Utility function to format a USTAR header into a buffer.  If
106  * "strict" is set, this tries to create the absolutely most portable
107  * version of a ustar header.  If "strict" is set to 0, then it will
108  * relax certain requirements.
109  *
110  * Generally, format-specific declarations don't belong in this
111  * header; this is a rare example of a function that is shared by
112  * two very similar formats (ustar and pax).
113  */
114 int
115 __archive_write_format_header_ustar(struct archive_write *, char buff[512],
116     struct archive_entry *, int tartype, int strict);
117 
118 #endif
119