wok-current rev 1897
linux/initramfs: early desallocate input buffer for none and gzip compression too
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sat Dec 20 14:23:46 2008 +0000 (2008-12-20) |
parents | 2eaab2a3a962 |
children | 09747329b5d0 |
files | linux/stuff/linux-lzma-2.6.25.5.u |
line diff
1.1 --- a/linux/stuff/linux-lzma-2.6.25.5.u Sat Dec 20 00:17:52 2008 +0100 1.2 +++ b/linux/stuff/linux-lzma-2.6.25.5.u Sat Dec 20 14:23:46 2008 +0000 1.3 @@ -2134,3 +2134,92 @@ 1.4 + free_init_pages(NULL, start, end); 1.5 } 1.6 #endif 1.7 + 1.8 +--- linux-2.6.25.5/init/initramfs.c 1.9 ++++ linux-2.6.25.5/init/initramfs.c 1.10 +@@ -404,7 +404,32 @@ 1.11 + static unsigned outcnt; /* bytes in output buffer */ 1.12 + static long bytes_out; 1.13 + 1.14 +-#define get_byte() (inptr < insize ? inbuf[inptr++] : -1) 1.15 ++#define INITRD_PAGE ((PAGE_SIZE > 1024*1024) ? PAGE_SIZE : 1024*1024) 1.16 ++static int fill_offset, fill_total; 1.17 ++#include <linux/initrd.h> 1.18 ++static void release_inbuf(int count) 1.19 ++{ 1.20 ++ if (fill_total < 0) return; 1.21 ++ fill_offset += count; 1.22 ++ fill_total += count; 1.23 ++ if (fill_offset >= INITRD_PAGE) { 1.24 ++ unsigned rem = fill_offset % INITRD_PAGE; 1.25 ++ unsigned end = initrd_start + fill_offset - rem; 1.26 ++ free_initrd_mem(initrd_start, end); 1.27 ++ printk("."); 1.28 ++ initrd_start = end; 1.29 ++ fill_offset = rem; 1.30 ++ } 1.31 ++} 1.32 ++ 1.33 ++static uch get_byte(void) 1.34 ++{ 1.35 ++ uch c; 1.36 ++ if (inptr > insize) return -1; 1.37 ++ c = inbuf[inptr++]; 1.38 ++ release_inbuf(1); 1.39 ++ return c; 1.40 ++} 1.41 + 1.42 + /* Diagnostic functions (stubbed out) */ 1.43 + #define Assert(cond,msg) 1.44 +@@ -453,25 +478,13 @@ 1.45 + outcnt = 0; 1.46 + } 1.47 + 1.48 +-#include <linux/initrd.h> 1.49 + #ifdef CONFIG_RD_LZMA 1.50 +-#define INITRD_PAGE ((PAGE_SIZE > 1024*1024) ? PAGE_SIZE : 1024*1024) 1.51 +-static int fill_offset, fill_total; 1.52 + static int fill_buffer(void *buffer, unsigned size) 1.53 + { 1.54 + int max = initrd_end - initrd_start - fill_offset; 1.55 + if (size < max) max = size; 1.56 + memcpy(buffer, (void *)(initrd_start + fill_offset), max); 1.57 +- fill_offset += max; 1.58 +- fill_total += max; 1.59 +- if (fill_offset >= INITRD_PAGE) { 1.60 +- unsigned rem = fill_offset % INITRD_PAGE; 1.61 +- unsigned end = initrd_start + fill_offset - rem; 1.62 +- free_initrd_mem(initrd_start, end); 1.63 +- printk("."); 1.64 +- initrd_start = end; 1.65 +- fill_offset = rem; 1.66 +- } 1.67 ++ release_inbuf(max); 1.68 + return max; 1.69 + } 1.70 + #endif 1.71 +@@ -489,6 +502,8 @@ 1.72 + state = Start; 1.73 + this_header = 0; 1.74 + message = NULL; 1.75 ++ fill_total = fill_offset = 0; 1.76 ++ if(buf != (char *) initrd_start) fill_total = -1; 1.77 + while (!message && len) { 1.78 + #ifdef CONFIG_RD_LZMA 1.79 + int status; 1.80 +@@ -497,6 +512,7 @@ 1.81 + if (*buf == '0' && !(this_header & 3)) { 1.82 + state = Start; 1.83 + written = write_buffer(buf, len); 1.84 ++ release_inbuf(written); 1.85 + buf += written; 1.86 + len -= written; 1.87 + continue; 1.88 +@@ -534,7 +550,6 @@ 1.89 + if(buf == (char *) initrd_start) { 1.90 + char *work_buffer = malloc(LZMA_IOBUF_SIZE); 1.91 + if (work_buffer) { 1.92 +- fill_total = fill_offset = 0; 1.93 + fill_buffer(work_buffer, LZMA_IOBUF_SIZE); 1.94 + status = unlzma(work_buffer, LZMA_IOBUF_SIZE, 1.95 + fill_buffer, flush_buffer, NULL);