1253923Smarcel/*-
2263409Smarcel * Copyright (c) 2013,2014 Juniper Networks, Inc.
3253923Smarcel * All rights reserved.
4253923Smarcel *
5253923Smarcel * Redistribution and use in source and binary forms, with or without
6253923Smarcel * modification, are permitted provided that the following conditions
7253923Smarcel * are met:
8253923Smarcel * 1. Redistributions of source code must retain the above copyright
9253923Smarcel *    notice, this list of conditions and the following disclaimer.
10253923Smarcel * 2. Redistributions in binary form must reproduce the above copyright
11253923Smarcel *    notice, this list of conditions and the following disclaimer in the
12253923Smarcel *    documentation and/or other materials provided with the distribution.
13253923Smarcel *
14253923Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15253923Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16253923Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17253923Smarcel * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18253923Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19253923Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20253923Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21253923Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22253923Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23253923Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24253923Smarcel * SUCH DAMAGE.
25253923Smarcel *
26253923Smarcel * $FreeBSD: releng/11.0/usr.bin/mkimg/scheme.h 292082 2015-12-11 05:39:42Z imp $
27253923Smarcel */
28253923Smarcel
29253923Smarcel#ifndef _MKIMG_SCHEME_H_
30253923Smarcel#define	_MKIMG_SCHEME_H_
31253923Smarcel
32263442Smarcel#include <sys/linker_set.h>
33263442Smarcel
34263487Smarcelenum alias {
35263487Smarcel	ALIAS_NONE,		/* Keep first! */
36263487Smarcel	/* start */
37263672Smarcel	ALIAS_EBR,
38263487Smarcel	ALIAS_EFI,
39289349Semaste	ALIAS_FAT16B,
40263672Smarcel	ALIAS_FAT32,
41263487Smarcel	ALIAS_FREEBSD,
42263487Smarcel	ALIAS_FREEBSD_BOOT,
43263487Smarcel	ALIAS_FREEBSD_NANDFS,
44263487Smarcel	ALIAS_FREEBSD_SWAP,
45263487Smarcel	ALIAS_FREEBSD_UFS,
46263487Smarcel	ALIAS_FREEBSD_VINUM,
47263487Smarcel	ALIAS_FREEBSD_ZFS,
48263487Smarcel	ALIAS_MBR,
49284883Smarcel	ALIAS_NTFS,
50292082Simp	ALIAS_PPCBOOT,
51263487Smarcel	/* end */
52263487Smarcel	ALIAS_COUNT		/* Keep last! */
53263487Smarcel};
54263487Smarcel
55263409Smarcelstruct mkimg_alias {
56263487Smarcel	u_int		alias;
57263461Smarcel	uintptr_t	type;
58263461Smarcel#define	ALIAS_PTR2TYPE(p)	(uintptr_t)(p)
59263461Smarcel#define	ALIAS_INT2TYPE(i)	(i)
60263461Smarcel#define	ALIAS_TYPE2PTR(p)	(void *)(p)
61263461Smarcel#define	ALIAS_TYPE2INT(i)	(i)
62263409Smarcel};
63253923Smarcel
64263409Smarcelstruct mkimg_scheme {
65263440Smarcel	const char	*name;
66263440Smarcel	const char	*description;
67263409Smarcel	struct mkimg_alias *aliases;
68271881Smarcel	lba_t		(*metadata)(u_int, lba_t);
69263440Smarcel#define	SCHEME_META_IMG_START	1
70263440Smarcel#define	SCHEME_META_IMG_END	2
71263440Smarcel#define	SCHEME_META_PART_BEFORE	3
72263440Smarcel#define	SCHEME_META_PART_AFTER	4
73266176Smarcel	int		(*write)(lba_t, void *);
74263466Smarcel	u_int		nparts;
75263466Smarcel	u_int		labellen;
76263537Smarcel	u_int		bootcode;
77263700Smarcel	u_int		maxsecsz;
78263409Smarcel};
79263409Smarcel
80263409SmarcelSET_DECLARE(schemes, struct mkimg_scheme);
81263409Smarcel#define	SCHEME_DEFINE(nm)	DATA_SET(schemes, nm)
82263409Smarcel
83253923Smarcelint	scheme_select(const char *);
84263409Smarcelstruct mkimg_scheme *scheme_selected(void);
85253923Smarcel
86263537Smarcelint scheme_bootcode(int fd);
87263382Smarcelint scheme_check_part(struct part *);
88253923Smarcelu_int scheme_max_parts(void);
89263829Smarcelu_int scheme_max_secsz(void);
90263844Smarcellba_t scheme_metadata(u_int, lba_t);
91266176Smarcelint scheme_write(lba_t);
92253923Smarcel
93253923Smarcel#endif /* _MKIMG_SCHEME_H_ */
94