1178172Simp/*-
2178172Simp * Copyright (c) 2014 Juniper Networks, Inc.
3178172Simp * All rights reserved.
4178172Simp *
5178172Simp * Redistribution and use in source and binary forms, with or without
6178172Simp * modification, are permitted provided that the following conditions
7178172Simp * are met:
8178172Simp * 1. Redistributions of source code must retain the above copyright
9178172Simp *    notice, this list of conditions and the following disclaimer.
10178172Simp * 2. Redistributions in binary form must reproduce the above copyright
11178172Simp *    notice, this list of conditions and the following disclaimer in the
12178172Simp *    documentation and/or other materials provided with the distribution.
13178172Simp *
14178172Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15178172Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16178172Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17178172Simp * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18178172Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19178172Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20178172Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21178172Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22178172Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23178172Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24178172Simp * SUCH DAMAGE.
25178172Simp *
26178172Simp * $FreeBSD: releng/11.0/usr.bin/mkimg/mkimg.h 272485 2014-10-03 20:48:11Z marcel $
27178172Simp */
28178172Simp
29178172Simp#ifndef _MKIMG_MKIMG_H_
30178172Simp#define	_MKIMG_MKIMG_H_
31178172Simp
32178172Simp#include <sys/queue.h>
33178172Simp
34178172Simpstruct part {
35178172Simp	STAILQ_ENTRY(part) link;
36178172Simp	char	*alias;		/* Partition type alias. */
37178172Simp	char	*contents;	/* Contents/size specification. */
38178172Simp	u_int	kind;		/* Content kind. */
39178172Simp#define	PART_UNDEF	0
40178172Simp#define	PART_KIND_FILE	1
41178172Simp#define	PART_KIND_PIPE	2
42178172Simp#define	PART_KIND_SIZE	3
43178172Simp	u_int	index;		/* Partition index (0-based). */
44178172Simp	uintptr_t type;		/* Scheme-specific partition type. */
45178172Simp	lba_t	block;		/* Block-offset of partition in image. */
46178172Simp	lba_t	size;		/* Size in blocks of partition. */
47178172Simp	char	*label;		/* Partition label. */
48178172Simp};
49178172Simp
50178172Simpextern STAILQ_HEAD(partlisthead, part) partlist;
51178172Simpextern u_int nparts;
52178172Simp
53178172Simpextern u_int unit_testing;
54178172Simpextern u_int verbose;
55178172Simp
56178172Simpextern u_int ncyls;
57178172Simpextern u_int nheads;
58178172Simpextern u_int nsecs;
59178172Simpextern u_int secsz;	/* Logical block size. */
60178172Simpextern u_int blksz;	/* Physical block size. */
61178172Simp
62178172Simpstatic inline lba_t
63178172Simpround_block(lba_t n)
64178172Simp{
65178172Simp	lba_t b = blksz / secsz;
66178172Simp	return ((n + b - 1) & ~(b - 1));
67178172Simp}
68178172Simp
69178172Simpstatic inline lba_t
70178172Simpround_cylinder(lba_t n)
71178172Simp{
72178172Simp	u_int cyl = nsecs * nheads;
73178172Simp	u_int r = n % cyl;
74178172Simp	return ((r == 0) ? n : n + cyl - r);
75178172Simp}
76178172Simp
77178172Simpstatic inline lba_t
78178172Simpround_track(lba_t n)
79178172Simp{
80178172Simp	u_int r = n % nsecs;
81178172Simp	return ((r == 0) ? n : n + nsecs - r);
82178172Simp}
83178172Simp
84178172Simp#if !defined(SPARSE_WRITE)
85178172Simp#define	sparse_write	write
86178172Simp#else
87178172Simpssize_t sparse_write(int, const void *, size_t);
88178172Simp#endif
89178172Simp
90178172Simpvoid mkimg_chs(lba_t, u_int, u_int *, u_int *, u_int *);
91178172Simp
92178172Simpstruct uuid;
93178172Simpvoid mkimg_uuid(struct uuid *);
94178172Simp
95178172Simp#endif /* _MKIMG_MKIMG_H_ */
96178172Simp