1/*- 2 * Copyright (c) 2013 Juniper Networks, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 26 unchanged lines hidden (view full) --- 35#include <fcntl.h> 36#include <libutil.h> 37#include <stdio.h> 38#include <stdlib.h> 39#include <string.h> 40#include <sysexits.h> 41#include <unistd.h> 42 |
43#include "mkimg.h" |
44#include "scheme.h" 45 46#define BUFFER_SIZE (1024*1024) 47 |
48struct partlisthead partlist = STAILQ_HEAD_INITIALIZER(partlist); 49u_int nparts = 0; |
50 |
51static int bcfd = 0; 52static int outfd = 0; 53static int tmpfd = -1; 54 55static char tmpfname[] = "/tmp/mkimg-XXXXXX"; 56 57static void 58cleanup(void) --- 78 unchanged lines hidden (view full) --- 137 138 part->contents = strdup(spec); 139 if (part->contents == NULL) { 140 error = ENOMEM; 141 goto errout; 142 } 143 144 part->index = nparts; |
145 STAILQ_INSERT_TAIL(&partlist, part, link); |
146 nparts++; 147 return (0); 148 149 errout: 150 if (part->type != NULL) 151 free(part->type); 152 free(part); 153 return (error); --- 36 unchanged lines hidden (view full) --- 190 uint64_t size; 191 int error, fd; 192 193 if (nparts > scheme_max_parts()) 194 errc(EX_DATAERR, ENOSPC, "only %d partitions are supported", 195 scheme_max_parts()); 196 197 offset = scheme_first_offset(nparts); |
198 STAILQ_FOREACH(part, &partlist, link) { |
199 part->offset = offset; 200 lseek(tmpfd, offset, SEEK_SET); 201 /* XXX check error */ 202 203 error = 0; 204 switch (part->kind) { 205 case PART_KIND_SIZE: 206 if (expand_number(part->contents, &size) == -1) --- 12 unchanged lines hidden (view full) --- 219 if (fp != NULL) { 220 error = fdcopy(fileno(fp), tmpfd, &size); 221 pclose(fp); 222 } else 223 error = errno; 224 break; 225 } 226 part->size = size; |
227 scheme_check_part(part); |
228 offset = scheme_next_offset(offset, size); 229 } 230 231 scheme_write(tmpfd, offset); 232} 233 234int 235main(int argc, char *argv[]) --- 71 unchanged lines hidden --- |