compr_zlib.c (c1b054d03f5b31c33eaa0b267c629b118eaf3790) | compr_zlib.c (182ec4eee397543101a6db8906ed88727d3f7e53) |
---|---|
1/* 2 * JFFS2 -- Journalling Flash File System, Version 2. 3 * 4 * Copyright (C) 2001-2003 Red Hat, Inc. 5 * 6 * Created by David Woodhouse <dwmw2@infradead.org> 7 * 8 * For licensing information, see the file 'LICENCE' in this directory. 9 * | 1/* 2 * JFFS2 -- Journalling Flash File System, Version 2. 3 * 4 * Copyright (C) 2001-2003 Red Hat, Inc. 5 * 6 * Created by David Woodhouse <dwmw2@infradead.org> 7 * 8 * For licensing information, see the file 'LICENCE' in this directory. 9 * |
10 * $Id: compr_zlib.c,v 1.31 2005/05/20 19:30:06 gleixner Exp $ | 10 * $Id: compr_zlib.c,v 1.32 2005/11/07 11:14:38 gleixner Exp $ |
11 * 12 */ 13 14#if !defined(__KERNEL__) && !defined(__ECOS) 15#error "The userspace support got too messy and was removed. Update your mkfs.jffs2" 16#endif 17 18#include <linux/config.h> 19#include <linux/kernel.h> 20#include <linux/sched.h> 21#include <linux/slab.h> 22#include <linux/zlib.h> 23#include <linux/zutil.h> 24#include "nodelist.h" 25#include "compr.h" 26 | 11 * 12 */ 13 14#if !defined(__KERNEL__) && !defined(__ECOS) 15#error "The userspace support got too messy and was removed. Update your mkfs.jffs2" 16#endif 17 18#include <linux/config.h> 19#include <linux/kernel.h> 20#include <linux/sched.h> 21#include <linux/slab.h> 22#include <linux/zlib.h> 23#include <linux/zutil.h> 24#include "nodelist.h" 25#include "compr.h" 26 |
27 /* Plan: call deflate() with avail_in == *sourcelen, 28 avail_out = *dstlen - 12 and flush == Z_FINISH. | 27 /* Plan: call deflate() with avail_in == *sourcelen, 28 avail_out = *dstlen - 12 and flush == Z_FINISH. |
29 If it doesn't manage to finish, call it again with 30 avail_in == 0 and avail_out set to the remaining 12 | 29 If it doesn't manage to finish, call it again with 30 avail_in == 0 and avail_out set to the remaining 12 |
31 bytes for it to clean up. | 31 bytes for it to clean up. |
32 Q: Is 12 bytes sufficient? 33 */ 34#define STREAM_END_SPACE 12 35 36static DECLARE_MUTEX(deflate_sem); 37static DECLARE_MUTEX(inflate_sem); 38static z_stream inf_strm, def_strm; 39 --- 44 unchanged lines hidden (view full) --- 84 if (Z_OK != zlib_deflateInit(&def_strm, 3)) { 85 printk(KERN_WARNING "deflateInit failed\n"); 86 up(&deflate_sem); 87 return -1; 88 } 89 90 def_strm.next_in = data_in; 91 def_strm.total_in = 0; | 32 Q: Is 12 bytes sufficient? 33 */ 34#define STREAM_END_SPACE 12 35 36static DECLARE_MUTEX(deflate_sem); 37static DECLARE_MUTEX(inflate_sem); 38static z_stream inf_strm, def_strm; 39 --- 44 unchanged lines hidden (view full) --- 84 if (Z_OK != zlib_deflateInit(&def_strm, 3)) { 85 printk(KERN_WARNING "deflateInit failed\n"); 86 up(&deflate_sem); 87 return -1; 88 } 89 90 def_strm.next_in = data_in; 91 def_strm.total_in = 0; |
92 | 92 |
93 def_strm.next_out = cpage_out; 94 def_strm.total_out = 0; 95 96 while (def_strm.total_out < *dstlen - STREAM_END_SPACE && def_strm.total_in < *sourcelen) { 97 def_strm.avail_out = *dstlen - (def_strm.total_out + STREAM_END_SPACE); 98 def_strm.avail_in = min((unsigned)(*sourcelen-def_strm.total_in), def_strm.avail_out); 99 D1(printk(KERN_DEBUG "calling deflate with avail_in %d, avail_out %d\n", 100 def_strm.avail_in, def_strm.avail_out)); 101 ret = zlib_deflate(&def_strm, Z_PARTIAL_FLUSH); | 93 def_strm.next_out = cpage_out; 94 def_strm.total_out = 0; 95 96 while (def_strm.total_out < *dstlen - STREAM_END_SPACE && def_strm.total_in < *sourcelen) { 97 def_strm.avail_out = *dstlen - (def_strm.total_out + STREAM_END_SPACE); 98 def_strm.avail_in = min((unsigned)(*sourcelen-def_strm.total_in), def_strm.avail_out); 99 D1(printk(KERN_DEBUG "calling deflate with avail_in %d, avail_out %d\n", 100 def_strm.avail_in, def_strm.avail_out)); 101 ret = zlib_deflate(&def_strm, Z_PARTIAL_FLUSH); |
102 D1(printk(KERN_DEBUG "deflate returned with avail_in %d, avail_out %d, total_in %ld, total_out %ld\n", | 102 D1(printk(KERN_DEBUG "deflate returned with avail_in %d, avail_out %d, total_in %ld, total_out %ld\n", |
103 def_strm.avail_in, def_strm.avail_out, def_strm.total_in, def_strm.total_out)); 104 if (ret != Z_OK) { 105 D1(printk(KERN_DEBUG "deflate in loop returned %d\n", ret)); 106 zlib_deflateEnd(&def_strm); 107 up(&deflate_sem); 108 return -1; 109 } 110 } --- 34 unchanged lines hidden (view full) --- 145 int ret; 146 int wbits = MAX_WBITS; 147 148 down(&inflate_sem); 149 150 inf_strm.next_in = data_in; 151 inf_strm.avail_in = srclen; 152 inf_strm.total_in = 0; | 103 def_strm.avail_in, def_strm.avail_out, def_strm.total_in, def_strm.total_out)); 104 if (ret != Z_OK) { 105 D1(printk(KERN_DEBUG "deflate in loop returned %d\n", ret)); 106 zlib_deflateEnd(&def_strm); 107 up(&deflate_sem); 108 return -1; 109 } 110 } --- 34 unchanged lines hidden (view full) --- 145 int ret; 146 int wbits = MAX_WBITS; 147 148 down(&inflate_sem); 149 150 inf_strm.next_in = data_in; 151 inf_strm.avail_in = srclen; 152 inf_strm.total_in = 0; |
153 | 153 |
154 inf_strm.next_out = cpage_out; 155 inf_strm.avail_out = destlen; 156 inf_strm.total_out = 0; 157 158 /* If it's deflate, and it's got no preset dictionary, then 159 we can tell zlib to skip the adler32 check. */ 160 if (srclen > 2 && !(data_in[1] & PRESET_DICT) && 161 ((data_in[0] & 0x0f) == Z_DEFLATED) && --- 61 unchanged lines hidden --- | 154 inf_strm.next_out = cpage_out; 155 inf_strm.avail_out = destlen; 156 inf_strm.total_out = 0; 157 158 /* If it's deflate, and it's got no preset dictionary, then 159 we can tell zlib to skip the adler32 check. */ 160 if (srclen > 2 && !(data_in[1] & PRESET_DICT) && 161 ((data_in[0] & 0x0f) == Z_DEFLATED) && --- 61 unchanged lines hidden --- |