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$ 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 53269177Smarcelextern 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 69272030Smarcelstatic inline lba_t 70272030Smarcelround_cylinder(lba_t n) 71272030Smarcel{ 72272030Smarcel u_int cyl = nsecs * nheads; 73272030Smarcel u_int r = n % cyl; 74272030Smarcel return ((r == 0) ? n : n + cyl - r); 75272030Smarcel} 76272030Smarcel 77272030Smarcelstatic inline lba_t 78272030Smarcelround_track(lba_t n) 79272030Smarcel{ 80272030Smarcel u_int r = n % nsecs; 81272030Smarcel return ((r == 0) ? n : n + nsecs - r); 82272030Smarcel} 83272030Smarcel 84268161Smarcel#if !defined(SPARSE_WRITE) 85268161Smarcel#define sparse_write write 86268161Smarcel#else 87268161Smarcelssize_t sparse_write(int, const void *, size_t); 88268161Smarcel#endif 89263653Smarcel 90269177Smarcelstruct uuid; 91269177Smarcelvoid mkimg_uuid(struct uuid *); 92269177Smarcel 93263382Smarcel#endif /* _MKIMG_MKIMG_H_ */ 94