1263382Smarcel/*- 2263382Smarcel * Copyright (c) 2014 Juniper Networks, Inc. 3263382Smarcel * All rights reserved. 4263382Smarcel * 5263382Smarcel * Redistribution and use in source and binary forms, with or without 6263382Smarcel * modification, are permitted provided that the following conditions 7263382Smarcel * are met: 8263382Smarcel * 1. Redistributions of source code must retain the above copyright 9263382Smarcel * notice, this list of conditions and the following disclaimer. 10263382Smarcel * 2. Redistributions in binary form must reproduce the above copyright 11263382Smarcel * notice, this list of conditions and the following disclaimer in the 12263382Smarcel * documentation and/or other materials provided with the distribution. 13263382Smarcel * 14263382Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15263382Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16263382Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17263382Smarcel * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18263382Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19263382Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20263382Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21263382Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22263382Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23263382Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24263382Smarcel * SUCH DAMAGE. 25263382Smarcel * 26263382Smarcel * $FreeBSD: releng/11.0/usr.bin/mkimg/mkimg.h 272485 2014-10-03 20:48:11Z marcel $ 27263382Smarcel */ 28263382Smarcel 29263382Smarcel#ifndef _MKIMG_MKIMG_H_ 30263382Smarcel#define _MKIMG_MKIMG_H_ 31263382Smarcel 32263442Smarcel#include <sys/queue.h> 33263442Smarcel 34263382Smarcelstruct part { 35263382Smarcel STAILQ_ENTRY(part) link; 36263414Smarcel char *alias; /* Partition type alias. */ 37263382Smarcel char *contents; /* Contents/size specification. */ 38263382Smarcel u_int kind; /* Content kind. */ 39263382Smarcel#define PART_UNDEF 0 40263382Smarcel#define PART_KIND_FILE 1 41263382Smarcel#define PART_KIND_PIPE 2 42263382Smarcel#define PART_KIND_SIZE 3 43263382Smarcel u_int index; /* Partition index (0-based). */ 44263461Smarcel uintptr_t type; /* Scheme-specific partition type. */ 45263653Smarcel lba_t block; /* Block-offset of partition in image. */ 46263653Smarcel lba_t size; /* Size in blocks of partition. */ 47263466Smarcel char *label; /* Partition label. */ 48263382Smarcel}; 49263382Smarcel 50263382Smarcelextern STAILQ_HEAD(partlisthead, part) partlist; 51263382Smarcelextern u_int nparts; 52263382Smarcel 53268236Smarcelextern u_int unit_testing; 54263831Smarcelextern u_int verbose; 55263831Smarcel 56263709Smarcelextern u_int ncyls; 57263709Smarcelextern u_int nheads; 58263709Smarcelextern u_int nsecs; 59263709Smarcelextern u_int secsz; /* Logical block size. */ 60263709Smarcelextern u_int blksz; /* Physical block size. */ 61263653Smarcel 62263844Smarcelstatic inline lba_t 63263844Smarcelround_block(lba_t n) 64263844Smarcel{ 65263844Smarcel lba_t b = blksz / secsz; 66263844Smarcel return ((n + b - 1) & ~(b - 1)); 67263844Smarcel} 68263844Smarcel 69271881Smarcelstatic inline lba_t 70271881Smarcelround_cylinder(lba_t n) 71271881Smarcel{ 72271881Smarcel u_int cyl = nsecs * nheads; 73271881Smarcel u_int r = n % cyl; 74271881Smarcel return ((r == 0) ? n : n + cyl - r); 75271881Smarcel} 76271881Smarcel 77271881Smarcelstatic inline lba_t 78271881Smarcelround_track(lba_t n) 79271881Smarcel{ 80271881Smarcel u_int r = n % nsecs; 81271881Smarcel return ((r == 0) ? n : n + nsecs - r); 82271881Smarcel} 83271881Smarcel 84266176Smarcel#if !defined(SPARSE_WRITE) 85266176Smarcel#define sparse_write write 86266176Smarcel#else 87266176Smarcelssize_t sparse_write(int, const void *, size_t); 88266176Smarcel#endif 89263653Smarcel 90272485Smarcelvoid mkimg_chs(lba_t, u_int, u_int *, u_int *, u_int *); 91272485Smarcel 92268236Smarcelstruct uuid; 93268236Smarcelvoid mkimg_uuid(struct uuid *); 94268236Smarcel 95263382Smarcel#endif /* _MKIMG_MKIMG_H_ */ 96