]>
git.ipfire.org Git - people/ms/u-boot.git/blob - fs/cramfs/uncompress.c
4 * Copyright (C) 1999 Linus Torvalds
5 * Copyright (C) 2000-2002 Transmeta Corporation
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License (Version 2) as
9 * published by the Free Software Foundation.
11 * cramfs interfaces to the uncompression library. There's really just
14 * - cramfs_uncompress_init() - called to initialize the thing.
15 * - cramfs_uncompress_exit() - tell me when you're done
16 * - cramfs_uncompress_block() - uncompress a block.
18 * NOTE NOTE NOTE! The uncompression is entirely single-threaded. We
19 * only have one stream, and we'll initialize it only once even if it
20 * then is used by multiple filesystems.
28 #if (CONFIG_COMMANDS & CFG_CMD_JFFS2)
30 static z_stream stream
;
32 #define ZALLOC_ALIGNMENT 16
34 static void *zalloc (void *x
, unsigned items
, unsigned size
)
39 size
= (size
+ ZALLOC_ALIGNMENT
- 1) & ~(ZALLOC_ALIGNMENT
- 1);
46 static void zfree (void *x
, void *addr
, unsigned nb
)
51 /* Returns length of decompressed data. */
52 int cramfs_uncompress_block (void *dst
, void *src
, int srclen
)
56 inflateReset (&stream
);
59 stream
.avail_in
= srclen
;
61 stream
.next_out
= dst
;
62 stream
.avail_out
= 4096 * 2;
64 err
= inflate (&stream
, Z_FINISH
);
66 if (err
!= Z_STREAM_END
)
68 return stream
.total_out
;
71 /*printf ("Error %d while decompressing!\n", err); */
72 /*printf ("%p(%d)->%p\n", src, srclen, dst); */
76 int cramfs_uncompress_init (void)
80 stream
.zalloc
= zalloc
;
85 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
86 stream
.outcb
= (cb_func
) WATCHDOG_RESET
;
88 stream
.outcb
= Z_NULL
;
89 #endif /* CONFIG_HW_WATCHDOG */
91 err
= inflateInit (&stream
);
93 printf ("Error: inflateInit2() returned %d\n", err
);
100 int cramfs_uncompress_exit (void)
102 inflateEnd (&stream
);
106 #endif /* CFG_FS_CRAMFS */