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 #ifndef HAVE_NBTOOL_CONFIG_H 33 #include <util.h> 34 #else 35 #include "opendisk.h" 36 #include "namespace.h" 37 #endif 38 39 #include "gpt_uuid.h" 40 41 struct mbr_part { 42 uint8_t part_flag; /* bootstrap flags */ 43 uint8_t part_shd; /* starting head */ 44 uint8_t part_ssect; /* starting sector */ 45 uint8_t part_scyl; /* starting cylinder */ 46 uint8_t part_typ; /* partition type */ 47 uint8_t part_ehd; /* end head */ 48 uint8_t part_esect; /* end sector */ 49 uint8_t part_ecyl; /* end cylinder */ 50 uint16_t part_start_lo; /* absolute starting ... */ 51 uint16_t part_start_hi; /* ... sector number */ 52 uint16_t part_size_lo; /* partition size ... */ 53 uint16_t part_size_hi; /* ... in sectors */ 54 }; 55 56 struct mbr { 57 uint8_t mbr_code[446]; 58 struct mbr_part mbr_part[4]; 59 uint16_t mbr_sig; 60 #define MBR_SIG 0xAA55 61 }; 62 63 typedef struct gpt *gpt_t; 64 typedef struct map *map_t; 65 66 struct gpt_cmd { 67 const char *name; 68 int (*fptr)(gpt_t, int, char *[]); 69 const char **help; 70 size_t hlen; 71 int flags; 72 }; 73 74 uint32_t crc32(const void *, size_t); 75 void gpt_close(gpt_t); 76 int gpt_gpt(gpt_t, off_t, int); 77 gpt_t gpt_open(const char *, int, int, off_t, u_int, time_t); 78 #define GPT_READONLY 0x01 79 #define GPT_MODIFIED 0x02 80 #define GPT_QUIET 0x04 81 #define GPT_NOSYNC 0x08 82 #define GPT_FILE 0x10 83 #define GPT_TIMESTAMP 0x20 84 #define GPT_SYNC 0x40 85 #define GPT_OPTDEV 0x8000 86 87 void* gpt_read(gpt_t, off_t, size_t); 88 off_t gpt_last(gpt_t); 89 off_t gpt_create(gpt_t, off_t, u_int, int); 90 int gpt_write(gpt_t, map_t); 91 int gpt_write_crc(gpt_t, map_t, map_t); 92 int gpt_write_primary(gpt_t); 93 int gpt_write_backup(gpt_t); 94 struct gpt_hdr *gpt_hdr(gpt_t); 95 void gpt_msg(gpt_t, const char *, ...) __printflike(2, 3); 96 void gpt_warn(gpt_t, const char *, ...) __printflike(2, 3); 97 void gpt_warnx(gpt_t, const char *, ...) __printflike(2, 3); 98 void gpt_create_pmbr_part(struct mbr_part *, off_t, int); 99 struct gpt_ent *gpt_ent(map_t, map_t, unsigned int); 100 struct gpt_ent *gpt_ent_primary(gpt_t, unsigned int); 101 struct gpt_ent *gpt_ent_backup(gpt_t, unsigned int); 102 int gpt_usage(const char *, const struct gpt_cmd *); 103 104 void utf16_to_utf8(const uint16_t *, size_t, uint8_t *, size_t); 105 void utf8_to_utf16(const uint8_t *, uint16_t *, size_t); 106 107 #define GPT_FIND "ab:i:L:s:t:" 108 109 struct gpt_find { 110 int all; 111 gpt_uuid_t type; 112 off_t block, size; 113 unsigned int entry; 114 uint8_t *name, *label; 115 const char *msg; 116 }; 117 int gpt_change_ent(gpt_t, const struct gpt_find *, 118 void (*)(struct gpt_ent *, void *), void *); 119 int gpt_add_find(gpt_t, struct gpt_find *, int); 120 121 #define GPT_AIS "a:i:s:" 122 int gpt_add_ais(gpt_t, off_t *, u_int *, off_t *, int); 123 off_t gpt_check_ais(gpt_t, off_t, u_int, off_t); 124 125 int gpt_attr_get(gpt_t, uint64_t *); 126 const char *gpt_attr_list(char *, size_t, uint64_t); 127 void gpt_attr_help(const char *); 128 int gpt_attr_update(gpt_t, u_int, uint64_t, uint64_t); 129 int gpt_uint_get(gpt_t, u_int *); 130 int gpt_human_get(gpt_t, off_t *); 131 int gpt_uuid_get(gpt_t, gpt_uuid_t *); 132 int gpt_name_get(gpt_t, void *); 133 int gpt_add_hdr(gpt_t, int, off_t); 134 void gpt_show_num(const char *, uintmax_t); 135 136 #endif /* _GPT_H_ */ 137