aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jffs2/compr.c
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@infradead.org>2007-07-10 05:01:22 -0400
committerDavid Woodhouse <dwmw2@infradead.org>2007-07-10 05:01:22 -0400
commitef53cb02ffee8ceb44ea75f778f77eace6b9c89a (patch)
tree3e41f74e33ca8b995f5aeb914074ac980b10e56a /fs/jffs2/compr.c
parent16adce7b6f4dab015d0b93274b41f8aae6fe07a5 (diff)
[JFFS2] Whitespace cleanups.
Convert many spaces to tabs; one or two other minor cosmetic fixes. Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Diffstat (limited to 'fs/jffs2/compr.c')
-rw-r--r--fs/jffs2/compr.c381
1 files changed, 191 insertions, 190 deletions
diff --git a/fs/jffs2/compr.c b/fs/jffs2/compr.c
index 485d065de41f..d90ca05e4992 100644
--- a/fs/jffs2/compr.c
+++ b/fs/jffs2/compr.c
@@ -5,7 +5,7 @@
5 * Created by Arjan van de Ven <arjanv@redhat.com> 5 * Created by Arjan van de Ven <arjanv@redhat.com>
6 * 6 *
7 * Copyright © 2004 Ferenc Havasi <havasi@inf.u-szeged.hu>, 7 * Copyright © 2004 Ferenc Havasi <havasi@inf.u-szeged.hu>,
8 * University of Szeged, Hungary 8 * University of Szeged, Hungary
9 * 9 *
10 * For licensing information, see the file 'LICENCE' in this directory. 10 * For licensing information, see the file 'LICENCE' in this directory.
11 * 11 *
@@ -43,121 +43,122 @@ static uint32_t none_stat_compr_blocks=0,none_stat_decompr_blocks=0,none_stat_co
43 * *datalen accordingly to show the amount of data which were compressed. 43 * *datalen accordingly to show the amount of data which were compressed.
44 */ 44 */
45uint16_t jffs2_compress(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 45uint16_t jffs2_compress(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
46 unsigned char *data_in, unsigned char **cpage_out, 46 unsigned char *data_in, unsigned char **cpage_out,
47 uint32_t *datalen, uint32_t *cdatalen) 47 uint32_t *datalen, uint32_t *cdatalen)
48{ 48{
49 int ret = JFFS2_COMPR_NONE; 49 int ret = JFFS2_COMPR_NONE;
50 int compr_ret; 50 int compr_ret;
51 struct jffs2_compressor *this, *best=NULL; 51 struct jffs2_compressor *this, *best=NULL;
52 unsigned char *output_buf = NULL, *tmp_buf; 52 unsigned char *output_buf = NULL, *tmp_buf;
53 uint32_t orig_slen, orig_dlen; 53 uint32_t orig_slen, orig_dlen;
54 uint32_t best_slen=0, best_dlen=0; 54 uint32_t best_slen=0, best_dlen=0;
55 55
56 switch (jffs2_compression_mode) { 56 switch (jffs2_compression_mode) {
57 case JFFS2_COMPR_MODE_NONE: 57 case JFFS2_COMPR_MODE_NONE:
58 break; 58 break;
59 case JFFS2_COMPR_MODE_PRIORITY: 59 case JFFS2_COMPR_MODE_PRIORITY:
60 output_buf = kmalloc(*cdatalen,GFP_KERNEL); 60 output_buf = kmalloc(*cdatalen,GFP_KERNEL);
61 if (!output_buf) { 61 if (!output_buf) {
62 printk(KERN_WARNING "JFFS2: No memory for compressor allocation. Compression failed.\n"); 62 printk(KERN_WARNING "JFFS2: No memory for compressor allocation. Compression failed.\n");
63 goto out; 63 goto out;
64 } 64 }
65 orig_slen = *datalen; 65 orig_slen = *datalen;
66 orig_dlen = *cdatalen; 66 orig_dlen = *cdatalen;
67 spin_lock(&jffs2_compressor_list_lock); 67 spin_lock(&jffs2_compressor_list_lock);
68 list_for_each_entry(this, &jffs2_compressor_list, list) { 68 list_for_each_entry(this, &jffs2_compressor_list, list) {
69 /* Skip decompress-only backwards-compatibility and disabled modules */ 69 /* Skip decompress-only backwards-compatibility and disabled modules */
70 if ((!this->compress)||(this->disabled)) 70 if ((!this->compress)||(this->disabled))
71 continue; 71 continue;
72 72
73 this->usecount++; 73 this->usecount++;
74 spin_unlock(&jffs2_compressor_list_lock); 74 spin_unlock(&jffs2_compressor_list_lock);
75 *datalen = orig_slen; 75 *datalen = orig_slen;
76 *cdatalen = orig_dlen; 76 *cdatalen = orig_dlen;
77 compr_ret = this->compress(data_in, output_buf, datalen, cdatalen, NULL); 77 compr_ret = this->compress(data_in, output_buf, datalen, cdatalen, NULL);
78 spin_lock(&jffs2_compressor_list_lock); 78 spin_lock(&jffs2_compressor_list_lock);
79 this->usecount--; 79 this->usecount--;
80 if (!compr_ret) { 80 if (!compr_ret) {
81 ret = this->compr; 81 ret = this->compr;
82 this->stat_compr_blocks++; 82 this->stat_compr_blocks++;
83 this->stat_compr_orig_size += *datalen; 83 this->stat_compr_orig_size += *datalen;
84 this->stat_compr_new_size += *cdatalen; 84 this->stat_compr_new_size += *cdatalen;
85 break; 85 break;
86 } 86 }
87 } 87 }
88 spin_unlock(&jffs2_compressor_list_lock); 88 spin_unlock(&jffs2_compressor_list_lock);
89 if (ret == JFFS2_COMPR_NONE) kfree(output_buf); 89 if (ret == JFFS2_COMPR_NONE)
90 break; 90 kfree(output_buf);
91 case JFFS2_COMPR_MODE_SIZE: 91 break;
92 orig_slen = *datalen; 92 case JFFS2_COMPR_MODE_SIZE:
93 orig_dlen = *cdatalen; 93 orig_slen = *datalen;
94 spin_lock(&jffs2_compressor_list_lock); 94 orig_dlen = *cdatalen;
95 list_for_each_entry(this, &jffs2_compressor_list, list) { 95 spin_lock(&jffs2_compressor_list_lock);
96 /* Skip decompress-only backwards-compatibility and disabled modules */ 96 list_for_each_entry(this, &jffs2_compressor_list, list) {
97 if ((!this->compress)||(this->disabled)) 97 /* Skip decompress-only backwards-compatibility and disabled modules */
98 continue; 98 if ((!this->compress)||(this->disabled))
99 /* Allocating memory for output buffer if necessary */ 99 continue;
100 if ((this->compr_buf_size<orig_dlen)&&(this->compr_buf)) { 100 /* Allocating memory for output buffer if necessary */
101 spin_unlock(&jffs2_compressor_list_lock); 101 if ((this->compr_buf_size<orig_dlen)&&(this->compr_buf)) {
102 kfree(this->compr_buf); 102 spin_unlock(&jffs2_compressor_list_lock);
103 spin_lock(&jffs2_compressor_list_lock); 103 kfree(this->compr_buf);
104 this->compr_buf_size=0; 104 spin_lock(&jffs2_compressor_list_lock);
105 this->compr_buf=NULL; 105 this->compr_buf_size=0;
106 } 106 this->compr_buf=NULL;
107 if (!this->compr_buf) { 107 }
108 spin_unlock(&jffs2_compressor_list_lock); 108 if (!this->compr_buf) {
109 tmp_buf = kmalloc(orig_dlen,GFP_KERNEL); 109 spin_unlock(&jffs2_compressor_list_lock);
110 spin_lock(&jffs2_compressor_list_lock); 110 tmp_buf = kmalloc(orig_dlen,GFP_KERNEL);
111 if (!tmp_buf) { 111 spin_lock(&jffs2_compressor_list_lock);
112 printk(KERN_WARNING "JFFS2: No memory for compressor allocation. (%d bytes)\n",orig_dlen); 112 if (!tmp_buf) {
113 continue; 113 printk(KERN_WARNING "JFFS2: No memory for compressor allocation. (%d bytes)\n",orig_dlen);
114 } 114 continue;
115 else { 115 }
116 this->compr_buf = tmp_buf; 116 else {
117 this->compr_buf_size = orig_dlen; 117 this->compr_buf = tmp_buf;
118 } 118 this->compr_buf_size = orig_dlen;
119 } 119 }
120 this->usecount++; 120 }
121 spin_unlock(&jffs2_compressor_list_lock); 121 this->usecount++;
122 *datalen = orig_slen; 122 spin_unlock(&jffs2_compressor_list_lock);
123 *cdatalen = orig_dlen; 123 *datalen = orig_slen;
124 compr_ret = this->compress(data_in, this->compr_buf, datalen, cdatalen, NULL); 124 *cdatalen = orig_dlen;
125 spin_lock(&jffs2_compressor_list_lock); 125 compr_ret = this->compress(data_in, this->compr_buf, datalen, cdatalen, NULL);
126 this->usecount--; 126 spin_lock(&jffs2_compressor_list_lock);
127 if (!compr_ret) { 127 this->usecount--;
128 if ((!best_dlen)||(best_dlen>*cdatalen)) { 128 if (!compr_ret) {
129 best_dlen = *cdatalen; 129 if ((!best_dlen)||(best_dlen>*cdatalen)) {
130 best_slen = *datalen; 130 best_dlen = *cdatalen;
131 best = this; 131 best_slen = *datalen;
132 } 132 best = this;
133 } 133 }
134 } 134 }
135 if (best_dlen) { 135 }
136 *cdatalen = best_dlen; 136 if (best_dlen) {
137 *datalen = best_slen; 137 *cdatalen = best_dlen;
138 output_buf = best->compr_buf; 138 *datalen = best_slen;
139 best->compr_buf = NULL; 139 output_buf = best->compr_buf;
140 best->compr_buf_size = 0; 140 best->compr_buf = NULL;
141 best->stat_compr_blocks++; 141 best->compr_buf_size = 0;
142 best->stat_compr_orig_size += best_slen; 142 best->stat_compr_blocks++;
143 best->stat_compr_new_size += best_dlen; 143 best->stat_compr_orig_size += best_slen;
144 ret = best->compr; 144 best->stat_compr_new_size += best_dlen;
145 } 145 ret = best->compr;
146 spin_unlock(&jffs2_compressor_list_lock); 146 }
147 break; 147 spin_unlock(&jffs2_compressor_list_lock);
148 default: 148 break;
149 printk(KERN_ERR "JFFS2: unknow compression mode.\n"); 149 default:
150 } 150 printk(KERN_ERR "JFFS2: unknow compression mode.\n");
151 }
151 out: 152 out:
152 if (ret == JFFS2_COMPR_NONE) { 153 if (ret == JFFS2_COMPR_NONE) {
153 *cpage_out = data_in; 154 *cpage_out = data_in;
154 *datalen = *cdatalen; 155 *datalen = *cdatalen;
155 none_stat_compr_blocks++; 156 none_stat_compr_blocks++;
156 none_stat_compr_size += *datalen; 157 none_stat_compr_size += *datalen;
157 } 158 }
158 else { 159 else {
159 *cpage_out = output_buf; 160 *cpage_out = output_buf;
160 } 161 }
161 return ret; 162 return ret;
162} 163}
163 164
@@ -165,8 +166,8 @@ int jffs2_decompress(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
165 uint16_t comprtype, unsigned char *cdata_in, 166 uint16_t comprtype, unsigned char *cdata_in,
166 unsigned char *data_out, uint32_t cdatalen, uint32_t datalen) 167 unsigned char *data_out, uint32_t cdatalen, uint32_t datalen)
167{ 168{
168 struct jffs2_compressor *this; 169 struct jffs2_compressor *this;
169 int ret; 170 int ret;
170 171
171 /* Older code had a bug where it would write non-zero 'usercompr' 172 /* Older code had a bug where it would write non-zero 'usercompr'
172 fields. Deal with it. */ 173 fields. Deal with it. */
@@ -177,32 +178,32 @@ int jffs2_decompress(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
177 case JFFS2_COMPR_NONE: 178 case JFFS2_COMPR_NONE:
178 /* This should be special-cased elsewhere, but we might as well deal with it */ 179 /* This should be special-cased elsewhere, but we might as well deal with it */
179 memcpy(data_out, cdata_in, datalen); 180 memcpy(data_out, cdata_in, datalen);
180 none_stat_decompr_blocks++; 181 none_stat_decompr_blocks++;
181 break; 182 break;
182 case JFFS2_COMPR_ZERO: 183 case JFFS2_COMPR_ZERO:
183 memset(data_out, 0, datalen); 184 memset(data_out, 0, datalen);
184 break; 185 break;
185 default: 186 default:
186 spin_lock(&jffs2_compressor_list_lock); 187 spin_lock(&jffs2_compressor_list_lock);
187 list_for_each_entry(this, &jffs2_compressor_list, list) { 188 list_for_each_entry(this, &jffs2_compressor_list, list) {
188 if (comprtype == this->compr) { 189 if (comprtype == this->compr) {
189 this->usecount++; 190 this->usecount++;
190 spin_unlock(&jffs2_compressor_list_lock); 191 spin_unlock(&jffs2_compressor_list_lock);
191 ret = this->decompress(cdata_in, data_out, cdatalen, datalen, NULL); 192 ret = this->decompress(cdata_in, data_out, cdatalen, datalen, NULL);
192 spin_lock(&jffs2_compressor_list_lock); 193 spin_lock(&jffs2_compressor_list_lock);
193 if (ret) { 194 if (ret) {
194 printk(KERN_WARNING "Decompressor \"%s\" returned %d\n", this->name, ret); 195 printk(KERN_WARNING "Decompressor \"%s\" returned %d\n", this->name, ret);
195 } 196 }
196 else { 197 else {
197 this->stat_decompr_blocks++; 198 this->stat_decompr_blocks++;
198 } 199 }
199 this->usecount--; 200 this->usecount--;
200 spin_unlock(&jffs2_compressor_list_lock); 201 spin_unlock(&jffs2_compressor_list_lock);
201 return ret; 202 return ret;
202 } 203 }
203 } 204 }
204 printk(KERN_WARNING "JFFS2 compression type 0x%02x not available.\n", comprtype); 205 printk(KERN_WARNING "JFFS2 compression type 0x%02x not available.\n", comprtype);
205 spin_unlock(&jffs2_compressor_list_lock); 206 spin_unlock(&jffs2_compressor_list_lock);
206 return -EIO; 207 return -EIO;
207 } 208 }
208 return 0; 209 return 0;
@@ -210,108 +211,108 @@ int jffs2_decompress(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
210 211
211int jffs2_register_compressor(struct jffs2_compressor *comp) 212int jffs2_register_compressor(struct jffs2_compressor *comp)
212{ 213{
213 struct jffs2_compressor *this; 214 struct jffs2_compressor *this;
214 215
215 if (!comp->name) { 216 if (!comp->name) {
216 printk(KERN_WARNING "NULL compressor name at registering JFFS2 compressor. Failed.\n"); 217 printk(KERN_WARNING "NULL compressor name at registering JFFS2 compressor. Failed.\n");
217 return -1; 218 return -1;
218 } 219 }
219 comp->compr_buf_size=0; 220 comp->compr_buf_size=0;
220 comp->compr_buf=NULL; 221 comp->compr_buf=NULL;
221 comp->usecount=0; 222 comp->usecount=0;
222 comp->stat_compr_orig_size=0; 223 comp->stat_compr_orig_size=0;
223 comp->stat_compr_new_size=0; 224 comp->stat_compr_new_size=0;
224 comp->stat_compr_blocks=0; 225 comp->stat_compr_blocks=0;
225 comp->stat_decompr_blocks=0; 226 comp->stat_decompr_blocks=0;
226 D1(printk(KERN_DEBUG "Registering JFFS2 compressor \"%s\"\n", comp->name)); 227 D1(printk(KERN_DEBUG "Registering JFFS2 compressor \"%s\"\n", comp->name));
227 228
228 spin_lock(&jffs2_compressor_list_lock); 229 spin_lock(&jffs2_compressor_list_lock);
229 230
230 list_for_each_entry(this, &jffs2_compressor_list, list) { 231 list_for_each_entry(this, &jffs2_compressor_list, list) {
231 if (this->priority < comp->priority) { 232 if (this->priority < comp->priority) {
232 list_add(&comp->list, this->list.prev); 233 list_add(&comp->list, this->list.prev);
233 goto out; 234 goto out;
234 } 235 }
235 } 236 }
236 list_add_tail(&comp->list, &jffs2_compressor_list); 237 list_add_tail(&comp->list, &jffs2_compressor_list);
237out: 238out:
238 D2(list_for_each_entry(this, &jffs2_compressor_list, list) { 239 D2(list_for_each_entry(this, &jffs2_compressor_list, list) {
239 printk(KERN_DEBUG "Compressor \"%s\", prio %d\n", this->name, this->priority); 240 printk(KERN_DEBUG "Compressor \"%s\", prio %d\n", this->name, this->priority);
240 }) 241 })
241 242
242 spin_unlock(&jffs2_compressor_list_lock); 243 spin_unlock(&jffs2_compressor_list_lock);
243 244
244 return 0; 245 return 0;
245} 246}
246 247
247int jffs2_unregister_compressor(struct jffs2_compressor *comp) 248int jffs2_unregister_compressor(struct jffs2_compressor *comp)
248{ 249{
249 D2(struct jffs2_compressor *this;) 250 D2(struct jffs2_compressor *this;)
250 251
251 D1(printk(KERN_DEBUG "Unregistering JFFS2 compressor \"%s\"\n", comp->name)); 252 D1(printk(KERN_DEBUG "Unregistering JFFS2 compressor \"%s\"\n", comp->name));
252 253
253 spin_lock(&jffs2_compressor_list_lock); 254 spin_lock(&jffs2_compressor_list_lock);
254 255
255 if (comp->usecount) { 256 if (comp->usecount) {
256 spin_unlock(&jffs2_compressor_list_lock); 257 spin_unlock(&jffs2_compressor_list_lock);
257 printk(KERN_WARNING "JFFS2: Compressor modul is in use. Unregister failed.\n"); 258 printk(KERN_WARNING "JFFS2: Compressor modul is in use. Unregister failed.\n");
258 return -1; 259 return -1;
259 } 260 }
260 list_del(&comp->list); 261 list_del(&comp->list);
261 262
262 D2(list_for_each_entry(this, &jffs2_compressor_list, list) { 263 D2(list_for_each_entry(this, &jffs2_compressor_list, list) {
263 printk(KERN_DEBUG "Compressor \"%s\", prio %d\n", this->name, this->priority); 264 printk(KERN_DEBUG "Compressor \"%s\", prio %d\n", this->name, this->priority);
264 }) 265 })
265 spin_unlock(&jffs2_compressor_list_lock); 266 spin_unlock(&jffs2_compressor_list_lock);
266 return 0; 267 return 0;
267} 268}
268 269
269void jffs2_free_comprbuf(unsigned char *comprbuf, unsigned char *orig) 270void jffs2_free_comprbuf(unsigned char *comprbuf, unsigned char *orig)
270{ 271{
271 if (orig != comprbuf) 272 if (orig != comprbuf)
272 kfree(comprbuf); 273 kfree(comprbuf);
273} 274}
274 275
275int __init jffs2_compressors_init(void) 276int __init jffs2_compressors_init(void)
276{ 277{
277/* Registering compressors */ 278/* Registering compressors */
278#ifdef CONFIG_JFFS2_ZLIB 279#ifdef CONFIG_JFFS2_ZLIB
279 jffs2_zlib_init(); 280 jffs2_zlib_init();
280#endif 281#endif
281#ifdef CONFIG_JFFS2_RTIME 282#ifdef CONFIG_JFFS2_RTIME
282 jffs2_rtime_init(); 283 jffs2_rtime_init();
283#endif 284#endif
284#ifdef CONFIG_JFFS2_RUBIN 285#ifdef CONFIG_JFFS2_RUBIN
285 jffs2_rubinmips_init(); 286 jffs2_rubinmips_init();
286 jffs2_dynrubin_init(); 287 jffs2_dynrubin_init();
287#endif 288#endif
288/* Setting default compression mode */ 289/* Setting default compression mode */
289#ifdef CONFIG_JFFS2_CMODE_NONE 290#ifdef CONFIG_JFFS2_CMODE_NONE
290 jffs2_compression_mode = JFFS2_COMPR_MODE_NONE; 291 jffs2_compression_mode = JFFS2_COMPR_MODE_NONE;
291 D1(printk(KERN_INFO "JFFS2: default compression mode: none\n");) 292 D1(printk(KERN_INFO "JFFS2: default compression mode: none\n");)
292#else 293#else
293#ifdef CONFIG_JFFS2_CMODE_SIZE 294#ifdef CONFIG_JFFS2_CMODE_SIZE
294 jffs2_compression_mode = JFFS2_COMPR_MODE_SIZE; 295 jffs2_compression_mode = JFFS2_COMPR_MODE_SIZE;
295 D1(printk(KERN_INFO "JFFS2: default compression mode: size\n");) 296 D1(printk(KERN_INFO "JFFS2: default compression mode: size\n");)
296#else 297#else
297 D1(printk(KERN_INFO "JFFS2: default compression mode: priority\n");) 298 D1(printk(KERN_INFO "JFFS2: default compression mode: priority\n");)
298#endif 299#endif
299#endif 300#endif
300 return 0; 301 return 0;
301} 302}
302 303
303int jffs2_compressors_exit(void) 304int jffs2_compressors_exit(void)
304{ 305{
305/* Unregistering compressors */ 306/* Unregistering compressors */
306#ifdef CONFIG_JFFS2_RUBIN 307#ifdef CONFIG_JFFS2_RUBIN
307 jffs2_dynrubin_exit(); 308 jffs2_dynrubin_exit();
308 jffs2_rubinmips_exit(); 309 jffs2_rubinmips_exit();
309#endif 310#endif
310#ifdef CONFIG_JFFS2_RTIME 311#ifdef CONFIG_JFFS2_RTIME
311 jffs2_rtime_exit(); 312 jffs2_rtime_exit();
312#endif 313#endif
313#ifdef CONFIG_JFFS2_ZLIB 314#ifdef CONFIG_JFFS2_ZLIB
314 jffs2_zlib_exit(); 315 jffs2_zlib_exit();
315#endif 316#endif
316 return 0; 317 return 0;
317} 318}