1cf8b12emarcel/*-
2cf8b12emarcel * Copyright (c) 2014 Juniper Networks, Inc.
3cf8b12emarcel * All rights reserved.
4cf8b12emarcel *
5cf8b12emarcel * Redistribution and use in source and binary forms, with or without
6cf8b12emarcel * modification, are permitted provided that the following conditions
7cf8b12emarcel * are met:
8cf8b12emarcel * 1. Redistributions of source code must retain the above copyright
9cf8b12emarcel *    notice, this list of conditions and the following disclaimer.
10cf8b12emarcel * 2. Redistributions in binary form must reproduce the above copyright
11cf8b12emarcel *    notice, this list of conditions and the following disclaimer in the
12cf8b12emarcel *    documentation and/or other materials provided with the distribution.
13cf8b12emarcel *
14cf8b12emarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15cf8b12emarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16cf8b12emarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17cf8b12emarcel * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18cf8b12emarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19cf8b12emarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20cf8b12emarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21cf8b12emarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22cf8b12emarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23cf8b12emarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24cf8b12emarcel * SUCH DAMAGE.
25cf8b12emarcel *
26cf8b12emarcel * $FreeBSD$
27cf8b12emarcel */
28cf8b12emarcel
29cf8b12emarcel#ifndef _MKIMG_MKIMG_H_
30cf8b12emarcel#define	_MKIMG_MKIMG_H_
31cf8b12emarcel
320dddaf6marcel#include <sys/queue.h>
33a31300amarcel#include <sys/types.h>
340dddaf6marcel
35cf8b12emarcelstruct part {
36f258aa5marcel	TAILQ_ENTRY(part) link;
375f39eb9marcel	char	*alias;		/* Partition type alias. */
38cf8b12emarcel	char	*contents;	/* Contents/size specification. */
39cf8b12emarcel	u_int	kind;		/* Content kind. */
40cf8b12emarcel#define	PART_UNDEF	0
41cf8b12emarcel#define	PART_KIND_FILE	1
42cf8b12emarcel#define	PART_KIND_PIPE	2
43cf8b12emarcel#define	PART_KIND_SIZE	3
44cf8b12emarcel	u_int	index;		/* Partition index (0-based). */
45edfa576marcel	uintptr_t type;		/* Scheme-specific partition type. */
463cd8745marcel	lba_t	block;		/* Block-offset of partition in image. */
473cd8745marcel	lba_t	size;		/* Size in blocks of partition. */
48ee34aedmarcel	char	*label;		/* Partition label. */
49cf8b12emarcel};
50cf8b12emarcel
51f258aa5marcelextern TAILQ_HEAD(partlisthead, part) partlist;
52cf8b12emarcelextern u_int nparts;
53cf8b12emarcel
54787496fmarcelextern u_int unit_testing;
556084642marcelextern u_int verbose;
566084642marcel
570a26345marcelextern u_int ncyls;
580a26345marcelextern u_int nheads;
590a26345marcelextern u_int nsecs;
600a26345marcelextern u_int secsz;	/* Logical block size. */
610a26345marcelextern u_int blksz;	/* Physical block size. */
625f1361aimpextern uint32_t active_partition;
633cd8745marcel
64bfd31b9marcelstatic inline lba_t
65bfd31b9marcelround_block(lba_t n)
66bfd31b9marcel{
67bfd31b9marcel	lba_t b = blksz / secsz;
68bfd31b9marcel	return ((n + b - 1) & ~(b - 1));
69bfd31b9marcel}
70bfd31b9marcel
719dc0698marcelstatic inline lba_t
729dc0698marcelround_cylinder(lba_t n)
739dc0698marcel{
749dc0698marcel	u_int cyl = nsecs * nheads;
759dc0698marcel	u_int r = n % cyl;
769dc0698marcel	return ((r == 0) ? n : n + cyl - r);
779dc0698marcel}
789dc0698marcel
799dc0698marcelstatic inline lba_t
809dc0698marcelround_track(lba_t n)
819dc0698marcel{
829dc0698marcel	u_int r = n % nsecs;
839dc0698marcel	return ((r == 0) ? n : n + nsecs - r);
849dc0698marcel}
859dc0698marcel
868e16ce1marcel#if !defined(SPARSE_WRITE)
878e16ce1marcel#define	sparse_write	write
888e16ce1marcel#else
89bea02c4marcelssize_t sparse_write(int, const void *, size_t);
908e16ce1marcel#endif
918e16ce1marcel
92ad936aamarcelvoid mkimg_chs(lba_t, u_int, u_int *, u_int *, u_int *);
93ad936aamarcel
94a31300amarcelstruct mkimg_uuid {
95a31300amarcel	uint32_t	time_low;
96a31300amarcel	uint16_t	time_mid;
97a31300amarcel	uint16_t	time_hi_and_version;
98a31300amarcel	uint8_t		clock_seq_hi_and_reserved;
99a31300amarcel	uint8_t		clock_seq_low;
100a31300amarcel	uint8_t		node[6];
101a31300amarcel};
102a31300amarceltypedef struct mkimg_uuid mkimg_uuid_t;
103a31300amarcel
104a31300amarcelvoid mkimg_uuid(mkimg_uuid_t *);
105a31300amarcelvoid mkimg_uuid_enc(void *, const mkimg_uuid_t *);
106787496fmarcel
1076b4d12csjg#ifdef __linux__
1086b4d12csjg# if !defined(__unused)
1096b4d12csjg#   define __unused __attribute__ ((__unused__))
1106b4d12csjg# endif
1116b4d12csjg#endif
1126b4d12csjg
113cf8b12emarcel#endif /* _MKIMG_MKIMG_H_ */
114