Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: utility/bmpblk_util.c

Issue 6523019: Enable LZMA compression in bmpbklk_utility. (Closed) Base URL: http://git.chromium.org/git/vboot_reference.git@master
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utility/Makefile ('k') | utility/bmpblk_utility.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <errno.h> 5 #include <errno.h>
6 #include <fcntl.h> 6 #include <fcntl.h>
7 #include <limits.h> 7 #include <limits.h>
8 #include <lzma.h>
8 #include <stdio.h> 9 #include <stdio.h>
9 #include <string.h> 10 #include <string.h>
10 #include <sys/mman.h> 11 #include <sys/mman.h>
11 #include <sys/stat.h> 12 #include <sys/stat.h>
12 #include <sys/types.h> 13 #include <sys/types.h>
13 #include <unistd.h> 14 #include <unistd.h>
14 15
15 #include "bmpblk_util.h" 16 #include "bmpblk_util.h"
16 #include "eficompress.h" 17 #include "eficompress.h"
17 18
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 free(obuf); 133 free(obuf);
133 free(sbuf); 134 free(sbuf);
134 return 0; 135 return 0;
135 } 136 }
136 137
137 free(sbuf); 138 free(sbuf);
138 return obuf; 139 return obuf;
139 } 140 }
140 141
141 142
143
144 static void *do_lzma_decompress(ImageInfo *img) {
145 void *ibuf;
146 void *obuf;
147 uint32_t isize;
148 uint32_t osize;
149 lzma_stream stream = LZMA_STREAM_INIT;
150 lzma_ret result;
151
152 ibuf = ((void *)img) + sizeof(ImageInfo);
Hung-Te 2011/02/15 07:55:10 We should not perform arithmetic operation to void
Tom Wai-Hong Tam 2011/02/16 10:58:03 Done.
153 isize = img->compressed_size;
154 osize = img->original_size;
155 obuf = malloc(osize);
Hung-Te 2011/02/15 07:55:10 Why not lzma_stream_buffer_bound?
Tom Wai-Hong Tam 2011/02/16 10:58:03 Since the exact uncompressed size is filled in whe
156 if (!obuf) {
157 fprintf(stderr, "Can't allocate %d bytes: %s\n",
158 osize,
159 strerror(errno));
160 return 0;
161 }
162
163 result = lzma_auto_decoder(&stream, -1, 0);
164 if (result != LZMA_OK) {
165 fprintf(stderr, "Unalbe to initialize auto decoder (error: %d)!\n", result);
Hung-Te 2011/02/15 07:55:10 Unable, typo
Tom Wai-Hong Tam 2011/02/16 10:58:03 Done.
166 free(obuf);
167 return 0;
168 }
169
170 stream.next_in = ibuf;
171 stream.avail_in = isize;
172 do {
173 stream.next_out = obuf;
174 stream.avail_out = osize;
175 result = lzma_code(&stream, LZMA_FINISH);
176 if (result != LZMA_OK && result != LZMA_STREAM_END) {
177 fprintf(stderr, "Unalbe to decode data (error: %d)!\n", result);
178 free(obuf);
179 return 0;
180 }
181 } while (result == LZMA_OK);
182 lzma_end(&stream);
183 return obuf;
184 }
185
186
187
142 // Show what's inside. If todir is NULL, just print. Otherwise unpack. 188 // Show what's inside. If todir is NULL, just print. Otherwise unpack.
143 int dump_bmpblock(const char *infile, int show_as_yaml, 189 int dump_bmpblock(const char *infile, int show_as_yaml,
144 const char *todir, int overwrite) { 190 const char *todir, int overwrite) {
145 void *ptr, *data_ptr; 191 void *ptr, *data_ptr;
146 size_t length = 0; 192 size_t length = 0;
147 BmpBlockHeader *hdr; 193 BmpBlockHeader *hdr;
148 ImageInfo *img; 194 ImageInfo *img;
149 ScreenLayout *scr; 195 ScreenLayout *scr;
150 int loc_num; 196 int loc_num;
151 int screen_num; 197 int screen_num;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 case COMPRESS_EFIv1: 305 case COMPRESS_EFIv1:
260 data_ptr = do_efi_decompress(img); 306 data_ptr = do_efi_decompress(img);
261 if (!data_ptr) { 307 if (!data_ptr) {
262 fclose(bfp); 308 fclose(bfp);
263 fclose(yfp); 309 fclose(yfp);
264 discard_file(ptr, length); 310 discard_file(ptr, length);
265 return 1; 311 return 1;
266 } 312 }
267 free_data = 1; 313 free_data = 1;
268 break; 314 break;
315 case COMPRESS_LZMA:
316 data_ptr = do_lzma_decompress(img);
317 if (!data_ptr) {
318 fclose(bfp);
319 fclose(yfp);
320 discard_file(ptr, length);
321 return 1;
322 }
323 free_data = 1;
324 break;
269 default: 325 default:
270 fprintf(stderr, "Unsupported compression method encountered.\n"); 326 fprintf(stderr, "Unsupported compression method encountered.\n");
271 fclose(bfp); 327 fclose(bfp);
272 fclose(yfp); 328 fclose(yfp);
273 discard_file(ptr, length); 329 discard_file(ptr, length);
274 return 1; 330 return 1;
275 } 331 }
276 if (1 != fwrite(data_ptr, img->original_size, 1, bfp)) { 332 if (1 != fwrite(data_ptr, img->original_size, 1, bfp)) {
277 fprintf(stderr, "Unable to write %s: %s\n", full_path_name, 333 fprintf(stderr, "Unable to write %s: %s\n", full_path_name,
278 strerror(errno)); 334 strerror(errno));
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 383 }
328 384
329 if (todir) 385 if (todir)
330 fclose(yfp); 386 fclose(yfp);
331 387
332 discard_file(ptr, length); 388 discard_file(ptr, length);
333 389
334 return 0; 390 return 0;
335 } 391 }
336 392
OLDNEW
« no previous file with comments | « utility/Makefile ('k') | utility/bmpblk_utility.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698