1218912Slstewart/*- 2218912Slstewart * Copyright (c) 2012 Andrey V. Elsukov <ae@FreeBSD.org> 3218912Slstewart * All rights reserved. 4218912Slstewart * 5218912Slstewart * Redistribution and use in source and binary forms, with or without 6220560Slstewart * modification, are permitted provided that the following conditions 7220560Slstewart * are met: 8218912Slstewart * 1. Redistributions of source code must retain the above copyright 9218912Slstewart * notice, this list of conditions and the following disclaimer. 10218912Slstewart * 2. Redistributions in binary form must reproduce the above copyright 11218912Slstewart * notice, this list of conditions and the following disclaimer in the 12218912Slstewart * documentation and/or other materials provided with the distribution. 13218912Slstewart * 14218912Slstewart * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 15218912Slstewart * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16218912Slstewart * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17218912Slstewart * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 18218912Slstewart * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19218912Slstewart * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20218912Slstewart * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21218912Slstewart * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22218912Slstewart * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23218912Slstewart * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24218912Slstewart * SUCH DAMAGE. 25218912Slstewart * 26218912Slstewart * $FreeBSD: stable/11/stand/common/part.h 332956 2018-04-24 18:19:30Z benno $ 27218912Slstewart */ 28218912Slstewart 29218912Slstewart#ifndef _PART_H_ 30218912Slstewart#define _PART_H_ 31218912Slstewart 32225583Slstewartstruct ptable; 33218912Slstewart 34218912Slstewartenum ptable_type { 35218912Slstewart PTABLE_NONE, 36218912Slstewart PTABLE_BSD, 37218912Slstewart PTABLE_MBR, 38218912Slstewart PTABLE_GPT, 39218912Slstewart PTABLE_VTOC8, 40218912Slstewart PTABLE_ISO9660 41218912Slstewart}; 42218912Slstewart 43218912Slstewartenum partition_type { 44218912Slstewart PART_UNKNOWN, 45218912Slstewart PART_EFI, 46218912Slstewart PART_FREEBSD, 47218912Slstewart PART_FREEBSD_BOOT, 48218912Slstewart PART_FREEBSD_NANDFS, 49218912Slstewart PART_FREEBSD_UFS, 50218912Slstewart PART_FREEBSD_ZFS, 51218912Slstewart PART_FREEBSD_SWAP, 52218912Slstewart PART_FREEBSD_VINUM, 53218912Slstewart PART_LINUX, 54218912Slstewart PART_LINUX_SWAP, 55218912Slstewart PART_DOS, 56218912Slstewart PART_ISO9660 57218912Slstewart}; 58218912Slstewart 59218912Slstewartstruct ptable_entry { 60218912Slstewart uint64_t start; 61218912Slstewart uint64_t end; 62218912Slstewart int index; 63218912Slstewart enum partition_type type; 64218912Slstewart}; 65218912Slstewart 66218912Slstewart/* The offset and size are in sectors */ 67218912Slstewarttypedef int (diskread_t)(void *arg, void *buf, size_t blocks, uint64_t offset); 68218912Slstewarttypedef int (ptable_iterate_t)(void *arg, const char *partname, 69218912Slstewart const struct ptable_entry *part); 70218912Slstewart 71218912Slstewartstruct ptable *ptable_open(void *dev, uint64_t sectors, uint16_t sectorsize, 72218912Slstewart diskread_t *dread); 73218912Slstewartvoid ptable_close(struct ptable *table); 74218912Slstewartenum ptable_type ptable_gettype(const struct ptable *table); 75218912Slstewartint ptable_getsize(const struct ptable *table, uint64_t *sizep); 76218912Slstewart 77218912Slstewartint ptable_getpart(const struct ptable *table, struct ptable_entry *part, 78225583Slstewart int index); 79218912Slstewartint ptable_getbestpart(const struct ptable *table, struct ptable_entry *part); 80225583Slstewart 81225583Slstewartint ptable_iterate(const struct ptable *table, void *arg, 82218912Slstewart ptable_iterate_t *iter); 83218912Slstewartconst char *parttype2str(enum partition_type type); 84218912Slstewart 85218912Slstewart#endif /* !_PART_H_ */ 86218912Slstewart