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