aboutsummaryrefslogtreecommitdiffstats
path: root/init/initramfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'init/initramfs.c')
-rw-r--r--init/initramfs.c101
1 files changed, 21 insertions, 80 deletions
diff --git a/init/initramfs.c b/init/initramfs.c
index d9c941c0c3ca..f8241e832aa3 100644
--- a/init/initramfs.c
+++ b/init/initramfs.c
@@ -390,11 +390,14 @@ static int __init write_buffer(char *buf, unsigned len)
390 return len - count; 390 return len - count;
391} 391}
392 392
393static void __init flush_buffer(char *buf, unsigned len) 393#if defined CONFIG_RD_GZIP || defined CONFIG_RD_BZIP2 || defined CONFIG_RD_LZMA
394static int __init flush_buffer(void *bufv, unsigned len)
394{ 395{
396 char *buf = (char *) bufv;
395 int written; 397 int written;
398 int origLen = len;
396 if (message) 399 if (message)
397 return; 400 return -1;
398 while ((written = write_buffer(buf, len)) < len && !message) { 401 while ((written = write_buffer(buf, len)) < len && !message) {
399 char c = buf[written]; 402 char c = buf[written];
400 if (c == '0') { 403 if (c == '0') {
@@ -408,84 +411,27 @@ static void __init flush_buffer(char *buf, unsigned len)
408 } else 411 } else
409 error("junk in compressed archive"); 412 error("junk in compressed archive");
410 } 413 }
414 return origLen;
411} 415}
412
413/*
414 * gzip declarations
415 */
416
417#define OF(args) args
418
419#ifndef memzero
420#define memzero(s, n) memset ((s), 0, (n))
421#endif 416#endif
422 417
423typedef unsigned char uch; 418static unsigned my_inptr; /* index of next byte to be processed in inbuf */
424typedef unsigned short ush;
425typedef unsigned long ulg;
426
427#define WSIZE 0x8000 /* window size--must be a power of two, and */
428 /* at least 32K for zip's deflate method */
429
430static uch *inbuf;
431static uch *window;
432
433static unsigned insize; /* valid bytes in inbuf */
434static unsigned inptr; /* index of next byte to be processed in inbuf */
435static unsigned outcnt; /* bytes in output buffer */
436static long bytes_out;
437
438#define get_byte() (inptr < insize ? inbuf[inptr++] : -1)
439
440/* Diagnostic functions (stubbed out) */
441#define Assert(cond,msg)
442#define Trace(x)
443#define Tracev(x)
444#define Tracevv(x)
445#define Tracec(c,x)
446#define Tracecv(c,x)
447
448#define STATIC static
449#define INIT __init
450
451static void __init flush_window(void);
452static void __init error(char *m);
453 419
454#define NO_INFLATE_MALLOC 420#include <linux/decompress/generic.h>
455
456#include "../lib/inflate.c"
457
458/* ===========================================================================
459 * Write the output window window[0..outcnt-1] and update crc and bytes_out.
460 * (Used for the decompressed data only.)
461 */
462static void __init flush_window(void)
463{
464 ulg c = crc; /* temporary variable */
465 unsigned n;
466 uch *in, ch;
467
468 flush_buffer(window, outcnt);
469 in = window;
470 for (n = 0; n < outcnt; n++) {
471 ch = *in++;
472 c = crc_32_tab[((int)c ^ ch) & 0xff] ^ (c >> 8);
473 }
474 crc = c;
475 bytes_out += (ulg)outcnt;
476 outcnt = 0;
477}
478 421
479static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only) 422static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
480{ 423{
481 int written; 424 int written;
425 decompress_fn decompress;
426
482 dry_run = check_only; 427 dry_run = check_only;
483 header_buf = kmalloc(110, GFP_KERNEL); 428 header_buf = kmalloc(110, GFP_KERNEL);
484 symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL); 429 symlink_buf = kmalloc(PATH_MAX + N_ALIGN(PATH_MAX) + 1, GFP_KERNEL);
485 name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL); 430 name_buf = kmalloc(N_ALIGN(PATH_MAX), GFP_KERNEL);
486 window = kmalloc(WSIZE, GFP_KERNEL); 431
487 if (!window || !header_buf || !symlink_buf || !name_buf) 432 if (!header_buf || !symlink_buf || !name_buf)
488 panic("can't allocate buffers"); 433 panic("can't allocate buffers");
434
489 state = Start; 435 state = Start;
490 this_header = 0; 436 this_header = 0;
491 message = NULL; 437 message = NULL;
@@ -505,22 +451,17 @@ static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
505 continue; 451 continue;
506 } 452 }
507 this_header = 0; 453 this_header = 0;
508 insize = len; 454 decompress = decompress_method(buf, len, NULL);
509 inbuf = buf; 455 if (decompress)
510 inptr = 0; 456 decompress(buf, len, NULL, flush_buffer, NULL,
511 outcnt = 0; /* bytes in output buffer */ 457 &my_inptr, error);
512 bytes_out = 0;
513 crc = (ulg)0xffffffffL; /* shift register contents */
514 makecrc();
515 gunzip();
516 if (state != Reset) 458 if (state != Reset)
517 error("junk in gzipped archive"); 459 error("junk in compressed archive");
518 this_header = saved_offset + inptr; 460 this_header = saved_offset + my_inptr;
519 buf += inptr; 461 buf += my_inptr;
520 len -= inptr; 462 len -= my_inptr;
521 } 463 }
522 dir_utime(); 464 dir_utime();
523 kfree(window);
524 kfree(name_buf); 465 kfree(name_buf);
525 kfree(symlink_buf); 466 kfree(symlink_buf);
526 kfree(header_buf); 467 kfree(header_buf);