decompress.c (9e6e15042fe8eed186bfa123fa6d79d7728f0ade) | decompress.c (c9431fa1e59a88c2f0abf611f25b97af964449e5) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 125 unchanged lines hidden (view full) --- 134 } else { 135 filep->fi_dcscrbuf = bkmem_alloc(DECOMP_BUFSIZE); 136 decomp_bufcnt++; 137 } 138 filep->fi_dcscrused = 0; 139 zsp = bkmem_alloc(sizeof (*zsp)); 140 filep->fi_dcstream = zsp; 141 /* | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 125 unchanged lines hidden (view full) --- 134 } else { 135 filep->fi_dcscrbuf = bkmem_alloc(DECOMP_BUFSIZE); 136 decomp_bufcnt++; 137 } 138 filep->fi_dcscrused = 0; 139 zsp = bkmem_alloc(sizeof (*zsp)); 140 filep->fi_dcstream = zsp; 141 /* |
142 * Initialize the decompression stream | 142 * Initialize the decompression stream. Adding 16 to the window size 143 * indicates that zlib should expect a gzip header. |
143 */ 144 bzero(zsp, sizeof (*zsp)); 145 zsp->opaque = filep; 146 zsp->zalloc = cf_alloc; 147 zsp->zfree = cf_free; 148 zsp->avail_in = 0; 149 zsp->next_in = NULL; 150 zsp->avail_out = 0; 151 zsp->next_out = NULL; | 144 */ 145 bzero(zsp, sizeof (*zsp)); 146 zsp->opaque = filep; 147 zsp->zalloc = cf_alloc; 148 zsp->zfree = cf_free; 149 zsp->avail_in = 0; 150 zsp->next_in = NULL; 151 zsp->avail_out = 0; 152 zsp->next_out = NULL; |
152 if (inflateInit2(zsp, -MAX_WBITS) != Z_OK) | 153 if (inflateInit2(zsp, MAX_WBITS + 16) != Z_OK) { 154 dprintf("inflateInit2() failed\n"); |
153 return (-1); | 155 return (-1); |
156 } |
|
154 return (0); 155} 156 157/* 158 * If the file described by fileid_t struct at *filep is compressed 159 * free any resources associated with the decompression. (decompression 160 * buffer, etc.). 161 */ --- 26 unchanged lines hidden (view full) --- 188} 189 190#define FLG_FHCRC 0x02 /* crc field present */ 191#define FLG_FEXTRA 0x04 /* "extra" field present */ 192#define FLG_FNAME 0x08 /* file name field present */ 193#define FLG_FCOMMENT 0x10 /* comment field present */ 194 195/* | 157 return (0); 158} 159 160/* 161 * If the file described by fileid_t struct at *filep is compressed 162 * free any resources associated with the decompression. (decompression 163 * buffer, etc.). 164 */ --- 26 unchanged lines hidden (view full) --- 191} 192 193#define FLG_FHCRC 0x02 /* crc field present */ 194#define FLG_FEXTRA 0x04 /* "extra" field present */ 195#define FLG_FNAME 0x08 /* file name field present */ 196#define FLG_FCOMMENT 0x10 /* comment field present */ 197 198/* |
196 * Calculate the header length of a gzip compressed file 197 */ 198static int 199cf_headerlen(unsigned char *hp) 200{ 201 unsigned char flag; 202 int xlen, hlen = 0; 203 204 hlen += 3; /* skip ID bytes and compression method */ 205 flag = hp[hlen]; 206 hlen += 7; /* skip flag, mtime(4 bytes), xfl, and os */ 207 if (flag & FLG_FEXTRA) { 208 xlen = hp[hlen++]; 209 xlen += hp[hlen++] << 8; 210 hlen += xlen; /* skip extra field */ 211 } 212 if (flag & FLG_FNAME) 213 hlen += strlen((char *)&hp[hlen]) + 1; /* skip file name */ 214 if (flag & FLG_FCOMMENT) 215 hlen += strlen((char *)&hp[hlen]) + 1; /* skip comment */ 216 if (flag & FLG_FHCRC) 217 hlen += 2; /* skip crc */ 218 return (hlen); 219} 220 221/* | |
222 * Read at the current uncompressed offset from the compressed file described 223 * by *filep. Will return decompressed data. 224 */ 225int 226cf_read(fileid_t *filep, caddr_t buf, size_t count) 227{ 228 z_stream *zsp; 229 struct inode *ip; 230 int err = Z_OK; | 199 * Read at the current uncompressed offset from the compressed file described 200 * by *filep. Will return decompressed data. 201 */ 202int 203cf_read(fileid_t *filep, caddr_t buf, size_t count) 204{ 205 z_stream *zsp; 206 struct inode *ip; 207 int err = Z_OK; |
231 int hlen, infbytes; | 208 int infbytes; |
232 off_t soff; 233 caddr_t smemp; 234 235 dprintf("cf_read: %s ", filep->fi_path); 236 dprintf("%lx bytes\n", count); 237 zsp = filep->fi_dcstream; 238 ip = filep->fi_inode; 239 dprintf(" reading at offset %lx\n", zsp->total_out); --- 10 unchanged lines hidden (view full) --- 250 filep->fi_offset = filep->fi_cfoff; 251 filep->fi_count = 0; 252 if ((*filep->fi_getblock)(filep) == -1) 253 return (-1); 254 filep->fi_offset = soff; 255 zsp->next_in = (unsigned char *)filep->fi_memp; 256 zsp->avail_in = filep->fi_count; 257 filep->fi_memp = smemp; | 209 off_t soff; 210 caddr_t smemp; 211 212 dprintf("cf_read: %s ", filep->fi_path); 213 dprintf("%lx bytes\n", count); 214 zsp = filep->fi_dcstream; 215 ip = filep->fi_inode; 216 dprintf(" reading at offset %lx\n", zsp->total_out); --- 10 unchanged lines hidden (view full) --- 227 filep->fi_offset = filep->fi_cfoff; 228 filep->fi_count = 0; 229 if ((*filep->fi_getblock)(filep) == -1) 230 return (-1); 231 filep->fi_offset = soff; 232 zsp->next_in = (unsigned char *)filep->fi_memp; 233 zsp->avail_in = filep->fi_count; 234 filep->fi_memp = smemp; |
258 /* 259 * If we are reading the first block of the file, we 260 * need to skip over the header bytes before inflating 261 */ 262 if (filep->fi_cfoff == 0) { 263 hlen = cf_headerlen(zsp->next_in); 264 zsp->next_in += hlen; 265 zsp->avail_in -= hlen; 266 } | |
267 filep->fi_cfoff += filep->fi_count; 268 } 269 infbytes = zsp->avail_out; 270 dprintf("attempting inflate of %x bytes to buf at: %lx\n", 271 zsp->avail_out, (unsigned long)zsp->next_out); 272 err = inflate(zsp, Z_NO_FLUSH); 273 infbytes -= zsp->avail_out; 274 dprintf("inflated %x bytes, errcode=%d\n", infbytes, err); --- 40 unchanged lines hidden --- | 235 filep->fi_cfoff += filep->fi_count; 236 } 237 infbytes = zsp->avail_out; 238 dprintf("attempting inflate of %x bytes to buf at: %lx\n", 239 zsp->avail_out, (unsigned long)zsp->next_out); 240 err = inflate(zsp, Z_NO_FLUSH); 241 infbytes -= zsp->avail_out; 242 dprintf("inflated %x bytes, errcode=%d\n", infbytes, err); --- 40 unchanged lines hidden --- |