diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2007-03-14 01:32:17 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2007-03-16 01:38:19 -0400 |
commit | 7850ad5c39a40ae14ab37e030357e2ae8252af2b (patch) | |
tree | c384344139d0153ed54de2e051a7023437b856b2 | |
parent | 0e0293c898c424c52e5d4e7f6923a203d06b9c4b (diff) |
[POWERPC] Add documentation for the zImage's gunzip convenience functions
This patch adds documenting comments to the gunzip convenience
functions added in commit ad9d2716cfc1cda5a7e0d7bc0db45e3af8a4adbb.
It also removes a stray newline, and an unused global variable.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
-rw-r--r-- | arch/powerpc/boot/gunzip_util.c | 81 | ||||
-rw-r--r-- | arch/powerpc/boot/gunzip_util.h | 17 |
2 files changed, 95 insertions, 3 deletions
diff --git a/arch/powerpc/boot/gunzip_util.c b/arch/powerpc/boot/gunzip_util.c index 3d9ff8f081c6..f7c95f24fcdd 100644 --- a/arch/powerpc/boot/gunzip_util.c +++ b/arch/powerpc/boot/gunzip_util.c | |||
@@ -14,14 +14,31 @@ | |||
14 | #include "ops.h" | 14 | #include "ops.h" |
15 | #include "gunzip_util.h" | 15 | #include "gunzip_util.h" |
16 | 16 | ||
17 | struct gunzip_state state; | ||
18 | |||
19 | #define HEAD_CRC 2 | 17 | #define HEAD_CRC 2 |
20 | #define EXTRA_FIELD 4 | 18 | #define EXTRA_FIELD 4 |
21 | #define ORIG_NAME 8 | 19 | #define ORIG_NAME 8 |
22 | #define COMMENT 0x10 | 20 | #define COMMENT 0x10 |
23 | #define RESERVED 0xe0 | 21 | #define RESERVED 0xe0 |
24 | 22 | ||
23 | /** | ||
24 | * gunzip_start - prepare to decompress gzip data | ||
25 | * @state: decompressor state structure to be initialized | ||
26 | * @src: buffer containing gzip compressed or uncompressed data | ||
27 | * @srclen: size in bytes of the buffer at src | ||
28 | * | ||
29 | * If the buffer at @src contains a gzip header, this function | ||
30 | * initializes zlib to decompress the data, storing the decompression | ||
31 | * state in @state. The other functions in this file can then be used | ||
32 | * to decompress data from the gzipped stream. | ||
33 | * | ||
34 | * If the buffer at @src does not contain a gzip header, it is assumed | ||
35 | * to contain uncompressed data. The buffer information is recorded | ||
36 | * in @state and the other functions in this file will simply copy | ||
37 | * data from the uncompressed data stream at @src. | ||
38 | * | ||
39 | * Any errors, such as bad compressed data, cause an error to be | ||
40 | * printed an the platform's exit() function to be called. | ||
41 | */ | ||
25 | void gunzip_start(struct gunzip_state *state, void *src, int srclen) | 42 | void gunzip_start(struct gunzip_state *state, void *src, int srclen) |
26 | { | 43 | { |
27 | char *hdr = src; | 44 | char *hdr = src; |
@@ -73,6 +90,22 @@ void gunzip_start(struct gunzip_state *state, void *src, int srclen) | |||
73 | state->s.avail_in = srclen - hdrlen; | 90 | state->s.avail_in = srclen - hdrlen; |
74 | } | 91 | } |
75 | 92 | ||
93 | /** | ||
94 | * gunzip_partial - extract bytes from a gzip data stream | ||
95 | * @state: gzip state structure previously initialized by gunzip_start() | ||
96 | * @dst: buffer to store extracted data | ||
97 | * @dstlen: maximum number of bytes to extract | ||
98 | * | ||
99 | * This function extracts at most @dstlen bytes from the data stream | ||
100 | * previously associated with @state by gunzip_start(), decompressing | ||
101 | * if necessary. Exactly @dstlen bytes are extracted unless the data | ||
102 | * stream doesn't contain enough bytes, in which case the entire | ||
103 | * remainder of the stream is decompressed. | ||
104 | * | ||
105 | * Returns the actual number of bytes extracted. If any errors occur, | ||
106 | * such as a corrupted compressed stream, an error is printed an the | ||
107 | * platform's exit() function is called. | ||
108 | */ | ||
76 | int gunzip_partial(struct gunzip_state *state, void *dst, int dstlen) | 109 | int gunzip_partial(struct gunzip_state *state, void *dst, int dstlen) |
77 | { | 110 | { |
78 | int len; | 111 | int len; |
@@ -99,6 +132,20 @@ int gunzip_partial(struct gunzip_state *state, void *dst, int dstlen) | |||
99 | return len; | 132 | return len; |
100 | } | 133 | } |
101 | 134 | ||
135 | /** | ||
136 | * gunzip_exactly - extract a fixed number of bytes from a gzip data stream | ||
137 | * @state: gzip state structure previously initialized by gunzip_start() | ||
138 | * @dst: buffer to store extracted data | ||
139 | * @dstlen: number of bytes to extract | ||
140 | * | ||
141 | * This function extracts exactly @dstlen bytes from the data stream | ||
142 | * previously associated with @state by gunzip_start(), decompressing | ||
143 | * if necessary. | ||
144 | * | ||
145 | * If there are less @dstlen bytes available in the data stream, or if | ||
146 | * any other errors occur, such as a corrupted compressed stream, an | ||
147 | * error is printed an the platform's exit() function is called. | ||
148 | */ | ||
102 | void gunzip_exactly(struct gunzip_state *state, void *dst, int dstlen) | 149 | void gunzip_exactly(struct gunzip_state *state, void *dst, int dstlen) |
103 | { | 150 | { |
104 | int len; | 151 | int len; |
@@ -110,6 +157,21 @@ void gunzip_exactly(struct gunzip_state *state, void *dst, int dstlen) | |||
110 | } | 157 | } |
111 | } | 158 | } |
112 | 159 | ||
160 | /** | ||
161 | * gunzip_discard - discard bytes from a gzip data stream | ||
162 | * @state: gzip state structure previously initialized by gunzip_start() | ||
163 | * @len: number of bytes to discard | ||
164 | * | ||
165 | * This function extracts, then discards exactly @len bytes from the | ||
166 | * data stream previously associated with @state by gunzip_start(). | ||
167 | * Subsequent gunzip_partial(), gunzip_exactly() or gunzip_finish() | ||
168 | * calls will extract the data following the discarded bytes in the | ||
169 | * data stream. | ||
170 | * | ||
171 | * If there are less @len bytes available in the data stream, or if | ||
172 | * any other errors occur, such as a corrupted compressed stream, an | ||
173 | * error is printed an the platform's exit() function is called. | ||
174 | */ | ||
113 | void gunzip_discard(struct gunzip_state *state, int len) | 175 | void gunzip_discard(struct gunzip_state *state, int len) |
114 | { | 176 | { |
115 | static char discard_buf[128]; | 177 | static char discard_buf[128]; |
@@ -123,6 +185,21 @@ void gunzip_discard(struct gunzip_state *state, int len) | |||
123 | gunzip_exactly(state, discard_buf, len); | 185 | gunzip_exactly(state, discard_buf, len); |
124 | } | 186 | } |
125 | 187 | ||
188 | /** | ||
189 | * gunzip_finish - extract all remaining bytes from a gzip data stream | ||
190 | * @state: gzip state structure previously initialized by gunzip_start() | ||
191 | * @dst: buffer to store extracted data | ||
192 | * @dstlen: maximum number of bytes to extract | ||
193 | * | ||
194 | * This function extracts all remaining data, or at most @dstlen | ||
195 | * bytes, from the stream previously associated with @state by | ||
196 | * gunzip_start(). zlib is then shut down, so it is an error to use | ||
197 | * any of the functions in this file on @state until it is | ||
198 | * re-initialized with another call to gunzip_start(). | ||
199 | * | ||
200 | * If any errors occur, such as a corrupted compressed stream, an | ||
201 | * error is printed an the platform's exit() function is called. | ||
202 | */ | ||
126 | int gunzip_finish(struct gunzip_state *state, void *dst, int dstlen) | 203 | int gunzip_finish(struct gunzip_state *state, void *dst, int dstlen) |
127 | { | 204 | { |
128 | int len; | 205 | int len; |
diff --git a/arch/powerpc/boot/gunzip_util.h b/arch/powerpc/boot/gunzip_util.h index 950f62fe0a6d..b3dfa6e87b3a 100644 --- a/arch/powerpc/boot/gunzip_util.h +++ b/arch/powerpc/boot/gunzip_util.h | |||
@@ -12,6 +12,22 @@ | |||
12 | 12 | ||
13 | #include "zlib.h" | 13 | #include "zlib.h" |
14 | 14 | ||
15 | /* | ||
16 | * These functions are designed to make life easy for decompressing | ||
17 | * kernel images, initrd images or any other gzip compressed image, | ||
18 | * particularly if its useful to decompress part of the image (e.g. to | ||
19 | * examine headers) before decompressing the remainder. | ||
20 | * | ||
21 | * To use: | ||
22 | * - declare a gunzip_state structure | ||
23 | * - use gunzip_start() to initialize the state, associating it | ||
24 | * with a stream of compressed data | ||
25 | * - use gunzip_partial(), gunzip_exactly() and gunzip_discard() | ||
26 | * in any combination to extract pieces of data from the stream | ||
27 | * - Finally use gunzip_finish() to extract the tail of the | ||
28 | * compressed stream and wind up zlib | ||
29 | */ | ||
30 | |||
15 | /* scratch space for gunzip; 46912 is from zlib_inflate_workspacesize() */ | 31 | /* scratch space for gunzip; 46912 is from zlib_inflate_workspacesize() */ |
16 | #define GUNZIP_SCRATCH_SIZE 46912 | 32 | #define GUNZIP_SCRATCH_SIZE 46912 |
17 | 33 | ||
@@ -27,4 +43,3 @@ void gunzip_discard(struct gunzip_state *state, int len); | |||
27 | int gunzip_finish(struct gunzip_state *state, void *dst, int len); | 43 | int gunzip_finish(struct gunzip_state *state, void *dst, int len); |
28 | 44 | ||
29 | #endif /* _PPC_BOOT_GUNZIP_UTIL_H_ */ | 45 | #endif /* _PPC_BOOT_GUNZIP_UTIL_H_ */ |
30 | |||