Home | History | Annotate | Line # | Download | only in gpt
gpt.h revision 1.23
      1   1.1  christos /*-
      2   1.1  christos  * Copyright (c) 2002 Marcel Moolenaar
      3   1.1  christos  * All rights reserved.
      4   1.1  christos  *
      5   1.1  christos  * Redistribution and use in source and binary forms, with or without
      6   1.1  christos  * modification, are permitted provided that the following conditions
      7   1.1  christos  * are met:
      8   1.1  christos  *
      9   1.1  christos  * 1. Redistributions of source code must retain the above copyright
     10   1.1  christos  *    notice, this list of conditions and the following disclaimer.
     11   1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     13   1.1  christos  *    documentation and/or other materials provided with the distribution.
     14   1.1  christos  *
     15   1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16   1.1  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17   1.1  christos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18   1.1  christos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19   1.1  christos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20   1.1  christos  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21   1.1  christos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22   1.1  christos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23   1.1  christos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24   1.1  christos  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25   1.1  christos  *
     26   1.1  christos  * $FreeBSD: src/sbin/gpt/gpt.h,v 1.11 2006/06/22 22:05:28 marcel Exp $
     27   1.1  christos  */
     28   1.1  christos 
     29   1.1  christos #ifndef _GPT_H_
     30   1.1  christos #define	_GPT_H_
     31   1.1  christos 
     32  1.14  christos #ifndef HAVE_NBTOOL_CONFIG_H
     33  1.16  christos #include <util.h>
     34  1.14  christos #else
     35  1.16  christos #include "opendisk.h"
     36  1.16  christos #include "namespace.h"
     37  1.14  christos #endif
     38   1.1  christos 
     39  1.16  christos #include "gpt_uuid.h"
     40   1.1  christos 
     41   1.1  christos struct mbr_part {
     42   1.1  christos 	uint8_t		part_flag;		/* bootstrap flags */
     43   1.1  christos 	uint8_t		part_shd;		/* starting head */
     44   1.1  christos 	uint8_t		part_ssect;		/* starting sector */
     45   1.1  christos 	uint8_t		part_scyl;		/* starting cylinder */
     46   1.1  christos 	uint8_t		part_typ;		/* partition type */
     47   1.1  christos 	uint8_t		part_ehd;		/* end head */
     48   1.1  christos 	uint8_t		part_esect;		/* end sector */
     49   1.1  christos 	uint8_t		part_ecyl;		/* end cylinder */
     50   1.1  christos 	uint16_t	part_start_lo;		/* absolute starting ... */
     51   1.1  christos 	uint16_t	part_start_hi;		/* ... sector number */
     52   1.1  christos 	uint16_t	part_size_lo;		/* partition size ... */
     53   1.1  christos 	uint16_t	part_size_hi;		/* ... in sectors */
     54   1.1  christos };
     55   1.1  christos 
     56   1.1  christos struct mbr {
     57   1.5  jakllsch 	uint8_t		mbr_code[446];
     58   1.1  christos 	struct mbr_part	mbr_part[4];
     59   1.1  christos 	uint16_t	mbr_sig;
     60   1.1  christos #define	MBR_SIG		0xAA55
     61   1.1  christos };
     62   1.1  christos 
     63  1.23  christos typedef struct gpt *gpt_t;
     64  1.23  christos typedef struct map *map_t;
     65   1.1  christos 
     66   1.1  christos uint32_t crc32(const void *, size_t);
     67  1.23  christos void	gpt_close(gpt_t);
     68  1.23  christos int	gpt_gpt(gpt_t, off_t, int);
     69  1.23  christos gpt_t	gpt_open(const char *, int, int, off_t, u_int);
     70  1.23  christos void*	gpt_read(gpt_t, off_t, size_t);
     71  1.23  christos int	gpt_write(gpt_t, map_t);
     72  1.23  christos int	gpt_write_crc(gpt_t, map_t, map_t);
     73  1.23  christos int	gpt_write_primary(gpt_t);
     74  1.23  christos int	gpt_write_backup(gpt_t);
     75  1.23  christos struct gpt_hdr *gpt_hdr(gpt_t);
     76  1.23  christos void	gpt_msg(gpt_t, const char *, ...) __printflike(2, 3);
     77  1.23  christos void	gpt_warn(gpt_t, const char *, ...) __printflike(2, 3);
     78  1.23  christos void	gpt_warnx(gpt_t, const char *, ...) __printflike(2, 3);
     79  1.23  christos void	gpt_create_pmbr_part(struct mbr_part *, off_t);
     80  1.23  christos off_t	gpt_check(gpt_t, off_t, off_t);
     81  1.23  christos struct gpt_ent *gpt_ent(map_t, map_t, unsigned int);
     82  1.23  christos struct gpt_ent *gpt_ent_primary(gpt_t, unsigned int);
     83  1.23  christos struct gpt_ent *gpt_ent_backup(gpt_t, unsigned int);
     84   1.1  christos 
     85   1.1  christos uint8_t *utf16_to_utf8(uint16_t *);
     86   1.1  christos void	utf8_to_utf16(const uint8_t *, uint16_t *, size_t);
     87   1.1  christos 
     88  1.23  christos int	cmd_add(gpt_t, int, char *[]);
     89  1.23  christos int	cmd_backup(gpt_t, int, char *[]);
     90  1.23  christos int	cmd_biosboot(gpt_t, int, char *[]);
     91  1.23  christos int	cmd_create(gpt_t, int, char *[]);
     92  1.23  christos int	cmd_destroy(gpt_t, int, char *[]);
     93  1.23  christos int	cmd_header(gpt_t, int, char *[]);
     94  1.23  christos int	cmd_label(gpt_t, int, char *[]);
     95  1.23  christos int	cmd_migrate(gpt_t, int, char *[]);
     96  1.23  christos int	cmd_recover(gpt_t, int, char *[]);
     97  1.23  christos int	cmd_remove(gpt_t, int, char *[]);
     98  1.23  christos int	cmd_resize(gpt_t, int, char *[]);
     99  1.23  christos int	cmd_resizedisk(gpt_t, int, char *[]);
    100  1.23  christos int	cmd_restore(gpt_t, int, char *[]);
    101  1.23  christos int	cmd_set(gpt_t, int, char *[]);
    102  1.23  christos int	cmd_show(gpt_t, int, char *[]);
    103  1.23  christos int	cmd_type(gpt_t, int, char *[]);
    104  1.23  christos int	cmd_unset(gpt_t, int, char *[]);
    105  1.23  christos 
    106  1.23  christos #define GPT_READONLY	1
    107  1.23  christos #define GPT_MODIFIED	2
    108  1.23  christos #define GPT_QUIET	4
    109  1.23  christos #define GPT_NOSYNC	8
    110   1.1  christos 
    111   1.1  christos #endif /* _GPT_H_ */
    112