• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef COMPRESSOR_H
2 #define COMPRESSOR_H
3 /*
4  *
5  * Copyright (c) 2009, 2010, 2011, 2012, 2013, 2014
6  * Phillip Lougher <phillip@squashfs.org.uk>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2,
11  * or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  * compressor.h
23  */
24 
25 struct compressor {
26 	int id;
27 	char *name;
28 	int supported;
29 	int (*init)(void **, int, int);
30 	int (*compress)(void *, void *, void *, int, int, int *);
31 	int (*uncompress)(void *, void *, int, int, int *);
32 	int (*options)(char **, int);
33 	int (*options_post)(int);
34 	void *(*dump_options)(int, int *);
35 	int (*extract_options)(int, void *, int);
36 	int (*check_options)(int, void *, int);
37 	void (*display_options)(void *, int);
38 	void (*usage)();
39 };
40 
41 extern struct compressor *lookup_compressor(char *);
42 extern struct compressor *lookup_compressor_id(int);
43 extern void display_compressors(char *, char *);
44 extern void display_compressor_usage(char *);
45 
compressor_init(struct compressor * comp,void ** stream,int block_size,int datablock)46 static inline int compressor_init(struct compressor *comp, void **stream,
47 	int block_size, int datablock)
48 {
49 	if(comp->init == NULL)
50 		return 0;
51 	return comp->init(stream, block_size, datablock);
52 }
53 
54 
compressor_compress(struct compressor * comp,void * strm,void * dest,void * src,int size,int block_size,int * error)55 static inline int compressor_compress(struct compressor *comp, void *strm,
56 	void *dest, void *src, int size, int block_size, int *error)
57 {
58 	return comp->compress(strm, dest, src, size, block_size, error);
59 }
60 
61 
compressor_uncompress(struct compressor * comp,void * dest,void * src,int size,int block_size,int * error)62 static inline int compressor_uncompress(struct compressor *comp, void *dest,
63 	void *src, int size, int block_size, int *error)
64 {
65 	return comp->uncompress(dest, src, size, block_size, error);
66 }
67 
68 
69 /*
70  * For the following functions please see the lzo, lz4 or xz
71  * compressors for commented examples of how they are used.
72  */
compressor_options(struct compressor * comp,char * argv[],int argc)73 static inline int compressor_options(struct compressor *comp, char *argv[],
74 	int argc)
75 {
76 	if(comp->options == NULL)
77 		return -1;
78 
79 	return comp->options(argv, argc);
80 }
81 
82 
compressor_options_post(struct compressor * comp,int block_size)83 static inline int compressor_options_post(struct compressor *comp, int block_size)
84 {
85 	if(comp->options_post == NULL)
86 		return 0;
87 	return comp->options_post(block_size);
88 }
89 
90 
compressor_dump_options(struct compressor * comp,int block_size,int * size)91 static inline void *compressor_dump_options(struct compressor *comp,
92 	int block_size, int *size)
93 {
94 	if(comp->dump_options == NULL)
95 		return NULL;
96 	return comp->dump_options(block_size, size);
97 }
98 
99 
compressor_extract_options(struct compressor * comp,int block_size,void * buffer,int size)100 static inline int compressor_extract_options(struct compressor *comp,
101 	int block_size, void *buffer, int size)
102 {
103 	if(comp->extract_options == NULL)
104 		return size ? -1 : 0;
105 	return comp->extract_options(block_size, buffer, size);
106 }
107 
108 
compressor_check_options(struct compressor * comp,int block_size,void * buffer,int size)109 static inline int compressor_check_options(struct compressor *comp,
110 	int block_size, void *buffer, int size)
111 {
112 	if(comp->check_options == NULL)
113 		return 0;
114 	return comp->check_options(block_size, buffer, size);
115 }
116 
117 
compressor_display_options(struct compressor * comp,void * buffer,int size)118 static inline void compressor_display_options(struct compressor *comp,
119 	void *buffer, int size)
120 {
121 	if(comp->display_options != NULL)
122 		comp->display_options(buffer, size);
123 }
124 #endif
125