blob: 7a6e2c2d58d427c22a5c87dc45cc43546748ddef [file] [log] [blame]
Patrick Georgib7b56dd82009-09-14 13:29:27 +00001/*
2 * common utility functions for cbfstool
3 *
4 * Copyright (C) 2009 coresystems GmbH
5 * written by Patrick Georgi <patrick.georgi@coresystems.de>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
19 */
20
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
Uwe Hermann942a40d2010-02-10 19:52:35 +000024#include <libgen.h>
Patrick Georgib7b56dd82009-09-14 13:29:27 +000025#include "common.h"
26#include "cbfs.h"
27#include "elf.h"
28
Stefan Reinauera1e48242011-10-21 14:24:57 -070029#define dprintf(x...)
Patrick Georgib7b56dd82009-09-14 13:29:27 +000030
Patrick Georgi0da38dd2009-11-09 17:18:02 +000031uint32_t getfilesize(const char *filename)
32{
33 uint32_t size;
34 FILE *file = fopen(filename, "rb");
35 fseek(file, 0, SEEK_END);
36 size = ftell(file);
37 fclose(file);
38 return size;
39}
40
Patrick Georgib7b56dd82009-09-14 13:29:27 +000041void *loadfile(const char *filename, uint32_t * romsize_p, void *content,
42 int place)
43{
44 FILE *file = fopen(filename, "rb");
Patrick Georgi45d8a832009-09-15 08:21:46 +000045 if (file == NULL)
46 return NULL;
Patrick Georgib7b56dd82009-09-14 13:29:27 +000047 fseek(file, 0, SEEK_END);
48 *romsize_p = ftell(file);
49 fseek(file, 0, SEEK_SET);
Stefan Reinauer853270a2009-09-22 15:55:01 +000050 if (!content) {
Patrick Georgib7b56dd82009-09-14 13:29:27 +000051 content = malloc(*romsize_p);
Stefan Reinauer853270a2009-09-22 15:55:01 +000052 if (!content) {
53 printf("Could not get %d bytes for file %s\n",
Patrick Georgi56f5fb72009-09-30 11:21:18 +000054 *romsize_p, filename);
Stefan Reinauer853270a2009-09-22 15:55:01 +000055 exit(1);
56 }
57 } else if (place == SEEK_END)
Patrick Georgib7b56dd82009-09-14 13:29:27 +000058 content -= *romsize_p;
Stefan Reinauer853270a2009-09-22 15:55:01 +000059
Patrick Georgib7b56dd82009-09-14 13:29:27 +000060 if (!fread(content, *romsize_p, 1, file)) {
61 printf("failed to read %s\n", filename);
62 return NULL;
63 }
64 fclose(file);
65 return content;
66}
67
68struct cbfs_header *master_header;
69uint32_t phys_start, phys_end, align, romsize;
70void *offset;
71
72void recalculate_rom_geometry(void *romarea)
73{
74 offset = romarea + romsize - 0x100000000ULL;
75 master_header = (struct cbfs_header *)
76 phys_to_virt(*((uint32_t *) phys_to_virt(0xfffffffc)));
77 phys_start = (0 - romsize + ntohl(master_header->offset)) & 0xffffffff;
78 phys_end =
79 (0 - ntohl(master_header->bootblocksize) -
80 sizeof(struct cbfs_header)) & 0xffffffff;
81 align = ntohl(master_header->align);
82}
83
84void *loadrom(const char *filename)
85{
86 void *romarea = loadfile(filename, &romsize, 0, SEEK_SET);
Patrick Georgi45d8a832009-09-15 08:21:46 +000087 if (romarea == NULL)
88 return NULL;
Patrick Georgib7b56dd82009-09-14 13:29:27 +000089 recalculate_rom_geometry(romarea);
90 return romarea;
91}
92
Stefan Reinauer9bb043852010-06-24 13:37:59 +000093int writerom(const char *filename, void *start, uint32_t size)
Patrick Georgib7b56dd82009-09-14 13:29:27 +000094{
95 FILE *file = fopen(filename, "wb");
Stefan Reinauer9bb043852010-06-24 13:37:59 +000096 if (!file) {
97 fprintf(stderr, "Could not open '%s' for writing: ", filename);
98 perror("");
99 return 1;
100 }
101
102 if (fwrite(start, size, 1, file) != 1) {
103 fprintf(stderr, "Could not write to '%s': ", filename);
104 perror("");
105 return 1;
106 }
107
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000108 fclose(file);
Stefan Reinauer9bb043852010-06-24 13:37:59 +0000109 return 0;
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000110}
111
112int cbfs_file_header(uint32_t physaddr)
113{
114 /* maybe improve this test */
115 return (strncmp(phys_to_virt(physaddr), "LARCHIVE", 8) == 0);
116}
117
118struct cbfs_file *cbfs_create_empty_file(uint32_t physaddr, uint32_t size)
119{
120 struct cbfs_file *nextfile = (struct cbfs_file *)phys_to_virt(physaddr);
Stefan Reinauera1e48242011-10-21 14:24:57 -0700121 strncpy((char *)(nextfile->magic), "LARCHIVE", 8);
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000122 nextfile->len = htonl(size);
123 nextfile->type = htonl(0xffffffff);
124 nextfile->checksum = 0; // FIXME?
125 nextfile->offset = htonl(sizeof(struct cbfs_file) + 16);
126 memset(((void *)nextfile) + sizeof(struct cbfs_file), 0, 16);
127 return nextfile;
128}
129
130int iself(unsigned char *input)
131{
132 Elf32_Ehdr *ehdr = (Elf32_Ehdr *) input;
133 return !memcmp(ehdr->e_ident, ELFMAG, 4);
134}
135
Mathias Krause941158f2012-04-12 21:36:23 +0200136static struct filetypes_t {
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000137 uint32_t type;
138 const char *name;
139} filetypes[] = {
140 {CBFS_COMPONENT_STAGE, "stage"},
141 {CBFS_COMPONENT_PAYLOAD, "payload"},
142 {CBFS_COMPONENT_OPTIONROM, "optionrom"},
Stefan Reinauer800379f2010-03-01 08:34:19 +0000143 {CBFS_COMPONENT_BOOTSPLASH, "bootsplash"},
144 {CBFS_COMPONENT_RAW, "raw"},
145 {CBFS_COMPONENT_VSA, "vsa"},
146 {CBFS_COMPONENT_MBI, "mbi"},
147 {CBFS_COMPONENT_MICROCODE, "microcode"},
Patrick Georgia865b172011-01-14 07:40:24 +0000148 {CBFS_COMPONENT_CMOS_DEFAULT, "cmos default"},
Mathias Krause941158f2012-04-12 21:36:23 +0200149 {CBFS_COMPONENT_CMOS_LAYOUT, "cmos layout"},
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000150 {CBFS_COMPONENT_DELETED, "deleted"},
151 {CBFS_COMPONENT_NULL, "null"}
152};
153
Stefan Reinauer07040582010-04-24 21:24:06 +0000154void print_supported_filetypes(void)
155{
156 int i, number = ARRAY_SIZE(filetypes);
157
158 for (i=0; i<number; i++) {
159 printf(" %s%c", filetypes[i].name, (i==(number-1))?'\n':',');
160 if ((i%8) == 7)
161 printf("\n");
162 }
163}
164
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000165const char *strfiletype(uint32_t number)
166{
167 int i;
168 for (i = 0; i < (sizeof(filetypes) / sizeof(struct filetypes_t)); i++)
169 if (filetypes[i].type == number)
170 return filetypes[i].name;
171 return "unknown";
172}
173
174uint64_t intfiletype(const char *name)
175{
176 int i;
177 for (i = 0; i < (sizeof(filetypes) / sizeof(struct filetypes_t)); i++)
178 if (strcmp(filetypes[i].name, name) == 0)
179 return filetypes[i].type;
180 return -1;
181}
182
183void print_cbfs_directory(const char *filename)
184{
185 printf
186 ("%s: %d kB, bootblocksize %d, romsize %d, offset 0x%x\nAlignment: %d bytes\n\n",
Uwe Hermann942a40d2010-02-10 19:52:35 +0000187 basename((char *)filename), romsize / 1024, ntohl(master_header->bootblocksize),
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000188 romsize, ntohl(master_header->offset), align);
189 printf("%-30s %-10s %-12s Size\n", "Name", "Offset", "Type");
190 uint32_t current = phys_start;
191 while (current < phys_end) {
192 if (!cbfs_file_header(current)) {
193 current += align;
194 continue;
195 }
196 struct cbfs_file *thisfile =
197 (struct cbfs_file *)phys_to_virt(current);
198 uint32_t length = ntohl(thisfile->len);
Maciej Pijankaf44eb782010-01-07 21:37:18 +0000199 char *fname = (char *)(phys_to_virt(current) + sizeof(struct cbfs_file));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000200 if (strlen(fname) == 0)
Maciej Pijankaf44eb782010-01-07 21:37:18 +0000201 fname = "(empty)";
202
Stefan Reinauer14e22772010-04-27 06:56:47 +0000203 printf("%-30s 0x%-8x %-12s %d\n", fname,
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000204 current - phys_start, strfiletype(ntohl(thisfile->type)),
205 length);
206 current =
207 ALIGN(current + ntohl(thisfile->len) +
208 ntohl(thisfile->offset), align);
209 }
210}
211
Aurelien Guillaumefe7d6b92011-01-13 09:09:21 +0000212int extract_file_from_cbfs(const char *filename, const char *payloadname, const char *outpath)
213{
214 // Identify the coreboot image.
215 printf(
216 "%s: %d kB, bootblocksize %d, romsize %d, offset 0x%x\nAlignment: %d bytes\n\n",
217 basename((char *)filename), romsize / 1024, ntohl(master_header->bootblocksize),
218 romsize, ntohl(master_header->offset), align);
219
220 FILE *outfile = NULL;
221 uint32_t current = phys_start;
222 while (current < phys_end) {
223 if (!cbfs_file_header(current)) {
224 current += align;
225 continue;
226 }
227
228 // Locate the file start struct
229 struct cbfs_file *thisfile =
230 (struct cbfs_file *)phys_to_virt(current);
231 // And its length
232 uint32_t length = ntohl(thisfile->len);
233 // Locate the file name
234 char *fname = (char *)(phys_to_virt(current) + sizeof(struct cbfs_file));
Stefan Reinauera1e48242011-10-21 14:24:57 -0700235
Aurelien Guillaumefe7d6b92011-01-13 09:09:21 +0000236 // It's not the file we are looking for..
237 if (strcmp(fname, payloadname) != 0)
238 {
239 current =
240 ALIGN(current + ntohl(thisfile->len) +
241 ntohl(thisfile->offset), align);
242 continue;
243 }
244
245 // Else, it's our file.
Peter Stuge441426b2011-01-17 05:08:32 +0000246 printf("Found file %.30s at 0x%x, type %.12s, size %d\n", fname,
Aurelien Guillaumefe7d6b92011-01-13 09:09:21 +0000247 current - phys_start, strfiletype(ntohl(thisfile->type)),
248 length);
249
250 // If we are not dumping to stdout, open the out file.
251 outfile = fopen(outpath, "wb");
252 if (!outfile)
253 {
254 printf("Could not open the file %s for writing. Aborting.\n", outpath);
255 return 1;
256 }
257
258 if (ntohl(thisfile->type) != CBFS_COMPONENT_RAW)
259 {
260 printf("Warning: only 'raw' files are safe to extract.\n");
261 }
262
263 fwrite(((char *)thisfile)
264 + ntohl(thisfile->offset), length, 1, outfile);
265
266 fclose(outfile);
Peter Stuge441426b2011-01-17 05:08:32 +0000267 printf("Successfully dumped the file.\n");
Aurelien Guillaumefe7d6b92011-01-13 09:09:21 +0000268
269 // We'll only dump one file.
270 return 0;
271 }
Stefan Reinauera1e48242011-10-21 14:24:57 -0700272 printf("File %s not found.\n", payloadname);
273 return 1;
Aurelien Guillaumefe7d6b92011-01-13 09:09:21 +0000274}
275
276
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000277int add_file_to_cbfs(void *content, uint32_t contentsize, uint32_t location)
278{
279 uint32_t current = phys_start;
280 while (current < phys_end) {
281 if (!cbfs_file_header(current)) {
282 current += align;
283 continue;
284 }
285 struct cbfs_file *thisfile =
286 (struct cbfs_file *)phys_to_virt(current);
287 uint32_t length = ntohl(thisfile->len);
288
289 dprintf("at %x, %x bytes\n", current, length);
290 /* Is this a free chunk? */
291 if ((thisfile->type == CBFS_COMPONENT_DELETED)
292 || (thisfile->type == CBFS_COMPONENT_NULL)) {
293 dprintf("null||deleted at %x, %x bytes\n", current,
294 length);
295 /* if this is the right size, and if specified, the right location, use it */
296 if ((contentsize <= length)
297 && ((location == 0) || (current == location))) {
298 if (contentsize < length) {
299 dprintf
300 ("this chunk is %x bytes, we need %x. create a new chunk at %x with %x bytes\n",
301 length, contentsize,
302 ALIGN(current + contentsize,
303 align),
304 length - contentsize);
305 uint32_t start =
306 ALIGN(current + contentsize, align);
307 uint32_t size =
308 current + ntohl(thisfile->offset)
309 + length - start - 16 -
310 sizeof(struct cbfs_file);
311 cbfs_create_empty_file(start, size);
312 }
313 dprintf("copying data\n");
314 memcpy(phys_to_virt(current), content,
315 contentsize);
Patrick Georgi56f5fb72009-09-30 11:21:18 +0000316 return 0;
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000317 }
Patrick Georgi56f5fb72009-09-30 11:21:18 +0000318 if (location != 0) {
319 /* CBFS has the constraint that the chain always moves up in memory. so once
320 we're past the place we seek, we don't need to look any further */
321 if (current > location) {
322 printf
323 ("the requested space is not available\n");
324 return 1;
325 }
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000326
Patrick Georgi56f5fb72009-09-30 11:21:18 +0000327 /* Is the requested location inside the current chunk? */
328 if ((current < location)
329 && ((location + contentsize) <=
330 (current + length))) {
331 /* Split it up. In the next iteration the code will be at the right place. */
332 dprintf("split up. new length: %x\n",
333 location - current -
334 ntohl(thisfile->offset));
335 thisfile->len =
336 htonl(location - current -
337 ntohl(thisfile->offset));
Stefan Reinauera1e48242011-10-21 14:24:57 -0700338 cbfs_create_empty_file(location,
Patrick Georgi56f5fb72009-09-30 11:21:18 +0000339 length -
340 (location -
341 current));
342 }
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000343 }
344 }
345 current =
346 ALIGN(current + ntohl(thisfile->len) +
347 ntohl(thisfile->offset), align);
348 }
Patrick Georgi56f5fb72009-09-30 11:21:18 +0000349 printf("Could not add the file to CBFS, it's probably too big.\n");
Uwe Hermann6a3ca4e2009-11-12 20:06:32 +0000350 printf("File size: %d bytes (%d KB).\n", contentsize, contentsize/1024);
Patrick Georgi56f5fb72009-09-30 11:21:18 +0000351 return 1;
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000352}
353
Gabe Blacke1bb49e2012-01-27 00:33:47 -0800354
355static struct cbfs_file *merge_adjacent_files(struct cbfs_file *first,
356 struct cbfs_file *second)
357{
358 uint32_t new_length =
359 ntohl(first->len) + ntohl(second->len) + ntohl(second->offset);
360 first->len = htonl(new_length);
361 first->checksum = 0; // FIXME?
362 return first;
363}
364
365static struct cbfs_file *next_file(struct cbfs_file *prev)
366{
367 uint32_t pos = (prev == NULL) ? phys_start :
368 ALIGN(virt_to_phys(prev) + ntohl(prev->len) + ntohl(prev->offset),
369 align);
370
371 for (; pos < phys_end; pos += align) {
372 if (cbfs_file_header(pos))
373 return (struct cbfs_file *)phys_to_virt(pos);
374 }
375 return NULL;
376}
377
378
379int remove_file_from_cbfs(const char *filename)
380{
381 struct cbfs_file *prev = NULL;
382 struct cbfs_file *cur = next_file(prev);
383 struct cbfs_file *next = next_file(cur);
384 for (; cur; prev = cur, cur = next, next = next_file(next)) {
385
386 /* Check if this is the file to remove. */
387 char *name = (char *)cur + sizeof(*cur);
388 if (strcmp(name, filename))
389 continue;
390
391 /* Mark the file as free space and erase its name. */
392 cur->type = CBFS_COMPONENT_NULL;
393 name[0] = '\0';
394
395 /* Merge it with the previous file if possible. */
396 if (prev && prev->type == CBFS_COMPONENT_NULL)
397 cur = merge_adjacent_files(prev, cur);
398
399 /* Merge it with the next file if possible. */
400 if (next && next->type == CBFS_COMPONENT_NULL)
401 merge_adjacent_files(cur, next);
402
403 return 0;
404 }
405 printf("CBFS file %s not found.\n", filename);
406 return 1;
407}
408
409
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000410/* returns new data block with cbfs_file header, suitable to dump into the ROM. location returns
411 the new location that points to the cbfs_file header */
412void *create_cbfs_file(const char *filename, void *data, uint32_t * datasize,
413 uint32_t type, uint32_t * location)
414{
415 uint32_t filename_len = ALIGN(strlen(filename) + 1, 16);
416 uint32_t headersize = sizeof(struct cbfs_file) + filename_len;
417 if ((location != 0) && (*location != 0)) {
418 uint32_t offset = *location % align;
419 /* If offset >= (headersize % align), we can stuff the header into the offset.
420 Otherwise the header has to be aligned itself, and put before the offset data */
421 if (offset >= (headersize % align)) {
422 offset -= (headersize % align);
423 } else {
424 offset += align - (headersize % align);
425 }
426 headersize += offset;
427 *location -= headersize;
428 }
429 void *newdata = malloc(*datasize + headersize);
Stefan Reinauer853270a2009-09-22 15:55:01 +0000430 if (!newdata) {
431 printf("Could not get %d bytes for CBFS file.\n", *datasize +
Patrick Georgi56f5fb72009-09-30 11:21:18 +0000432 headersize);
Stefan Reinauer853270a2009-09-22 15:55:01 +0000433 exit(1);
434 }
Peter Stugef4aca1d2009-12-06 12:14:39 +0000435 memset(newdata, 0xff, *datasize + headersize);
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000436 struct cbfs_file *nextfile = (struct cbfs_file *)newdata;
Stefan Reinauera1e48242011-10-21 14:24:57 -0700437 strncpy((char *)(nextfile->magic), "LARCHIVE", 8);
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000438 nextfile->len = htonl(*datasize);
439 nextfile->type = htonl(type);
440 nextfile->checksum = 0; // FIXME?
441 nextfile->offset = htonl(headersize);
442 strcpy(newdata + sizeof(struct cbfs_file), filename);
443 memcpy(newdata + headersize, data, *datasize);
444 *datasize += headersize;
445 return newdata;
446}
447
448int create_cbfs_image(const char *romfile, uint32_t _romsize,
449 const char *bootblock, uint32_t align)
450{
451 romsize = _romsize;
452 unsigned char *romarea = malloc(romsize);
Stefan Reinauer853270a2009-09-22 15:55:01 +0000453 if (!romarea) {
454 printf("Could not get %d bytes of memory for CBFS image.\n",
Patrick Georgi56f5fb72009-09-30 11:21:18 +0000455 romsize);
Stefan Reinauer853270a2009-09-22 15:55:01 +0000456 exit(1);
457 }
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000458 memset(romarea, 0xff, romsize);
Stefan Reinauer853270a2009-09-22 15:55:01 +0000459
460 // Set up physical/virtual mapping
461 offset = romarea + romsize - 0x100000000ULL;
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000462
463 if (align == 0)
464 align = 64;
465
466 uint32_t bootblocksize = 0;
467 loadfile(bootblock, &bootblocksize, romarea + romsize, SEEK_END);
468 struct cbfs_header *master_header =
469 (struct cbfs_header *)(romarea + romsize - bootblocksize -
470 sizeof(struct cbfs_header));
471 master_header->magic = ntohl(0x4f524243);
472 master_header->version = ntohl(0x31313131);
473 master_header->romsize = htonl(romsize);
474 master_header->bootblocksize = htonl(bootblocksize);
475 master_header->align = htonl(align);
476 master_header->offset = htonl(0);
477 ((uint32_t *) phys_to_virt(0xfffffffc))[0] =
478 virt_to_phys(master_header);
Stefan Reinauer853270a2009-09-22 15:55:01 +0000479
480 recalculate_rom_geometry(romarea);
481
Stefan Reinauera1e48242011-10-21 14:24:57 -0700482 cbfs_create_empty_file((0 - romsize) & 0xffffffff,
Patrick Georgib7b56dd82009-09-14 13:29:27 +0000483 romsize - bootblocksize -
484 sizeof(struct cbfs_header) -
485 sizeof(struct cbfs_file) - 16);
486
487 writerom(romfile, romarea, romsize);
488 return 0;
489}
Patrick Georgi0da38dd2009-11-09 17:18:02 +0000490
491static int in_segment(int addr, int size, int gran)
492{
493 return ((addr & ~(gran - 1)) == ((addr + size) & ~(gran - 1)));
494}
495
496uint32_t cbfs_find_location(const char *romfile, uint32_t filesize,
497 const char *filename, uint32_t alignment)
498{
Stefan Reinauera1e48242011-10-21 14:24:57 -0700499 loadrom(romfile);
Patrick Georgi0da38dd2009-11-09 17:18:02 +0000500 int filename_size = strlen(filename);
501
502 int headersize =
503 sizeof(struct cbfs_file) + ALIGN(filename_size + 1,
504 16) + sizeof(struct cbfs_stage);
505 int totalsize = headersize + filesize;
506
507 uint32_t current = phys_start;
508 while (current < phys_end) {
509 if (!cbfs_file_header(current)) {
510 current += align;
511 continue;
512 }
513 struct cbfs_file *thisfile =
514 (struct cbfs_file *)phys_to_virt(current);
515
516 uint32_t top =
517 current + ntohl(thisfile->len) + ntohl(thisfile->offset);
518 if (((ntohl(thisfile->type) == 0x0)
519 || (ntohl(thisfile->type) == 0xffffffff))
520 && (ntohl(thisfile->len) + ntohl(thisfile->offset) >=
521 totalsize)) {
522 if (in_segment
523 (current + headersize, filesize, alignment))
524 return current + headersize;
525 if ((ALIGN(current, alignment) + filesize < top)
526 && (ALIGN(current, alignment) - headersize >
527 current)
528 && in_segment(ALIGN(current, alignment), filesize,
529 alignment))
530 return ALIGN(current, alignment);
531 if ((ALIGN(current, alignment) + alignment + filesize <
532 top)
533 && (ALIGN(current, alignment) + alignment -
534 headersize > current)
535 && in_segment(ALIGN(current, alignment) + alignment,
536 filesize, alignment))
537 return ALIGN(current, alignment) + alignment;
538 }
539 current =
540 ALIGN(current + ntohl(thisfile->len) +
541 ntohl(thisfile->offset), align);
542 }
543 return 0;
544}