1239054Sae/*-
2239054Sae * Copyright (c) 2012 Andrey V. Elsukov <ae@FreeBSD.org>
3239054Sae * All rights reserved.
4239054Sae *
5239054Sae * Redistribution and use in source and binary forms, with or without
6239054Sae * modification, are permitted provided that the following conditions
7239054Sae * are met:
8239054Sae * 1. Redistributions of source code must retain the above copyright
9239054Sae *    notice, this list of conditions and the following disclaimer.
10239054Sae * 2. Redistributions in binary form must reproduce the above copyright
11239054Sae *    notice, this list of conditions and the following disclaimer in the
12239054Sae *    documentation and/or other materials provided with the distribution.
13239054Sae *
14239054Sae * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15239054Sae * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16239054Sae * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17239054Sae * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18239054Sae * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19239054Sae * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20239054Sae * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21239054Sae * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22239054Sae * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23239054Sae * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24239054Sae * SUCH DAMAGE.
25239054Sae *
26239054Sae * $FreeBSD$
27239054Sae */
28239054Sae
29239054Sae#ifndef _PART_H_
30239054Sae#define	_PART_H_
31239054Sae
32239054Saestruct ptable;
33239054Sae
34239054Saeenum ptable_type {
35239054Sae	PTABLE_NONE,
36239054Sae	PTABLE_BSD,
37239054Sae	PTABLE_MBR,
38239054Sae	PTABLE_GPT,
39239054Sae	PTABLE_VTOC8
40239054Sae};
41239054Sae
42239054Saeenum partition_type {
43239054Sae	PART_UNKNOWN,
44239054Sae	PART_EFI,
45239054Sae	PART_FREEBSD,
46239054Sae	PART_FREEBSD_BOOT,
47239054Sae	PART_FREEBSD_NANDFS,
48239054Sae	PART_FREEBSD_UFS,
49239054Sae	PART_FREEBSD_ZFS,
50239054Sae	PART_FREEBSD_SWAP,
51239054Sae	PART_FREEBSD_VINUM,
52239054Sae	PART_LINUX,
53239054Sae	PART_LINUX_SWAP,
54239054Sae	PART_DOS,
55239054Sae};
56239054Sae
57239054Saestruct ptable_entry {
58239054Sae	uint64_t		start;
59239054Sae	uint64_t		end;
60239054Sae	int			index;
61239054Sae	enum partition_type	type;
62239054Sae};
63239054Sae
64239054Sae/* The offset and size are in sectors */
65239054Saetypedef int (diskread_t)(void *arg, void *buf, size_t blocks, off_t offset);
66239054Saetypedef void (ptable_iterate_t)(void *arg, const char *partname,
67239054Sae    const struct ptable_entry *part);
68239054Sae
69239054Saestruct ptable *ptable_open(void *dev, off_t sectors, uint16_t sectorsize,
70239054Sae    diskread_t *dread);
71239054Saevoid ptable_close(struct ptable *table);
72239054Saeenum ptable_type ptable_gettype(const struct ptable *table);
73239054Sae
74239054Saeint ptable_getpart(const struct ptable *table, struct ptable_entry *part,
75239054Sae    int index);
76239054Saeint ptable_getbestpart(const struct ptable *table, struct ptable_entry *part);
77239054Sae
78239054Saevoid ptable_iterate(const struct ptable *table, void *arg,
79239054Sae    ptable_iterate_t *iter);
80239054Saeconst char *parttype2str(enum partition_type type);
81239054Sae
82239054Sae#endif	/* !_PART_H_ */
83