1 1.45 christos /* $NetBSD: gpt.h,v 1.45 2025/02/23 20:47:19 christos Exp $ */ 2 1.41 sevan 3 1.1 christos /*- 4 1.1 christos * Copyright (c) 2002 Marcel Moolenaar 5 1.1 christos * All rights reserved. 6 1.1 christos * 7 1.1 christos * Redistribution and use in source and binary forms, with or without 8 1.1 christos * modification, are permitted provided that the following conditions 9 1.1 christos * are met: 10 1.1 christos * 11 1.1 christos * 1. Redistributions of source code must retain the above copyright 12 1.1 christos * notice, this list of conditions and the following disclaimer. 13 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright 14 1.1 christos * notice, this list of conditions and the following disclaimer in the 15 1.1 christos * documentation and/or other materials provided with the distribution. 16 1.1 christos * 17 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 1.1 christos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 1.1 christos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 1.1 christos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 1.1 christos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 1.1 christos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 1.1 christos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 1.1 christos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 1.1 christos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 1.1 christos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 1.1 christos * 28 1.1 christos * $FreeBSD: src/sbin/gpt/gpt.h,v 1.11 2006/06/22 22:05:28 marcel Exp $ 29 1.1 christos */ 30 1.1 christos 31 1.1 christos #ifndef _GPT_H_ 32 1.1 christos #define _GPT_H_ 33 1.1 christos 34 1.14 christos #ifndef HAVE_NBTOOL_CONFIG_H 35 1.16 christos #include <util.h> 36 1.14 christos #else 37 1.16 christos #include "opendisk.h" 38 1.16 christos #include "namespace.h" 39 1.14 christos #endif 40 1.1 christos 41 1.16 christos #include "gpt_uuid.h" 42 1.1 christos 43 1.1 christos struct mbr_part { 44 1.1 christos uint8_t part_flag; /* bootstrap flags */ 45 1.1 christos uint8_t part_shd; /* starting head */ 46 1.1 christos uint8_t part_ssect; /* starting sector */ 47 1.1 christos uint8_t part_scyl; /* starting cylinder */ 48 1.1 christos uint8_t part_typ; /* partition type */ 49 1.1 christos uint8_t part_ehd; /* end head */ 50 1.1 christos uint8_t part_esect; /* end sector */ 51 1.1 christos uint8_t part_ecyl; /* end cylinder */ 52 1.1 christos uint16_t part_start_lo; /* absolute starting ... */ 53 1.1 christos uint16_t part_start_hi; /* ... sector number */ 54 1.1 christos uint16_t part_size_lo; /* partition size ... */ 55 1.1 christos uint16_t part_size_hi; /* ... in sectors */ 56 1.1 christos }; 57 1.1 christos 58 1.1 christos struct mbr { 59 1.5 jakllsch uint8_t mbr_code[446]; 60 1.1 christos struct mbr_part mbr_part[4]; 61 1.1 christos uint16_t mbr_sig; 62 1.1 christos #define MBR_SIG 0xAA55 63 1.1 christos }; 64 1.1 christos 65 1.23 christos typedef struct gpt *gpt_t; 66 1.23 christos typedef struct map *map_t; 67 1.1 christos 68 1.24 christos struct gpt_cmd { 69 1.24 christos const char *name; 70 1.24 christos int (*fptr)(gpt_t, int, char *[]); 71 1.24 christos const char **help; 72 1.24 christos size_t hlen; 73 1.24 christos int flags; 74 1.24 christos }; 75 1.24 christos 76 1.1 christos uint32_t crc32(const void *, size_t); 77 1.23 christos void gpt_close(gpt_t); 78 1.23 christos int gpt_gpt(gpt_t, off_t, int); 79 1.34 christos gpt_t gpt_open(const char *, int, int, off_t, u_int, time_t); 80 1.29 christos #define GPT_READONLY 0x01 81 1.29 christos #define GPT_MODIFIED 0x02 82 1.29 christos #define GPT_QUIET 0x04 83 1.29 christos #define GPT_NOSYNC 0x08 84 1.29 christos #define GPT_FILE 0x10 85 1.35 christos #define GPT_TIMESTAMP 0x20 86 1.38 jnemeth #define GPT_SYNC 0x40 87 1.42 jmcneill #define GPT_HYBRID 0x80 88 1.44 mlelstv #define GPT_OPTGPT 0x4000 89 1.43 mlelstv #define GPT_OPTDEV 0x8000 90 1.25 christos 91 1.23 christos void* gpt_read(gpt_t, off_t, size_t); 92 1.25 christos off_t gpt_last(gpt_t); 93 1.28 christos off_t gpt_create(gpt_t, off_t, u_int, int); 94 1.23 christos int gpt_write(gpt_t, map_t); 95 1.23 christos int gpt_write_crc(gpt_t, map_t, map_t); 96 1.23 christos int gpt_write_primary(gpt_t); 97 1.23 christos int gpt_write_backup(gpt_t); 98 1.23 christos struct gpt_hdr *gpt_hdr(gpt_t); 99 1.23 christos void gpt_msg(gpt_t, const char *, ...) __printflike(2, 3); 100 1.23 christos void gpt_warn(gpt_t, const char *, ...) __printflike(2, 3); 101 1.23 christos void gpt_warnx(gpt_t, const char *, ...) __printflike(2, 3); 102 1.33 christos void gpt_create_pmbr_part(struct mbr_part *, off_t, int); 103 1.23 christos struct gpt_ent *gpt_ent(map_t, map_t, unsigned int); 104 1.23 christos struct gpt_ent *gpt_ent_primary(gpt_t, unsigned int); 105 1.23 christos struct gpt_ent *gpt_ent_backup(gpt_t, unsigned int); 106 1.24 christos int gpt_usage(const char *, const struct gpt_cmd *); 107 1.1 christos 108 1.36 christos void utf16_to_utf8(const uint16_t *, size_t, uint8_t *, size_t); 109 1.1 christos void utf8_to_utf16(const uint8_t *, uint16_t *, size_t); 110 1.1 christos 111 1.25 christos #define GPT_FIND "ab:i:L:s:t:" 112 1.25 christos 113 1.25 christos struct gpt_find { 114 1.25 christos int all; 115 1.25 christos gpt_uuid_t type; 116 1.25 christos off_t block, size; 117 1.25 christos unsigned int entry; 118 1.25 christos uint8_t *name, *label; 119 1.25 christos const char *msg; 120 1.25 christos }; 121 1.25 christos int gpt_change_ent(gpt_t, const struct gpt_find *, 122 1.39 jnemeth void (*)(struct gpt_ent *, void *, int), void *); 123 1.40 jnemeth int gpt_change_hdr(gpt_t, const struct gpt_find *, 124 1.40 jnemeth void (*)(struct gpt_hdr *, void *, int), void *); 125 1.25 christos int gpt_add_find(gpt_t, struct gpt_find *, int); 126 1.25 christos 127 1.25 christos #define GPT_AIS "a:i:s:" 128 1.25 christos int gpt_add_ais(gpt_t, off_t *, u_int *, off_t *, int); 129 1.25 christos off_t gpt_check_ais(gpt_t, off_t, u_int, off_t); 130 1.25 christos 131 1.31 christos int gpt_attr_get(gpt_t, uint64_t *); 132 1.31 christos const char *gpt_attr_list(char *, size_t, uint64_t); 133 1.31 christos void gpt_attr_help(const char *); 134 1.25 christos int gpt_attr_update(gpt_t, u_int, uint64_t, uint64_t); 135 1.32 christos int gpt_uint_get(gpt_t, u_int *); 136 1.32 christos int gpt_human_get(gpt_t, off_t *); 137 1.26 christos int gpt_uuid_get(gpt_t, gpt_uuid_t *); 138 1.26 christos int gpt_name_get(gpt_t, void *); 139 1.30 christos int gpt_add_hdr(gpt_t, int, off_t); 140 1.28 christos void gpt_show_num(const char *, uintmax_t); 141 1.1 christos 142 1.45 christos extern const struct gpt_cmd 143 1.45 christos c_add, 144 1.45 christos #ifndef HAVE_NBTOOL_CONFIG_H 145 1.45 christos c_backup, 146 1.45 christos #endif 147 1.45 christos c_biosboot, 148 1.45 christos c_create, 149 1.45 christos c_destroy, 150 1.45 christos c_header, 151 1.45 christos c_label, 152 1.45 christos c_migrate, 153 1.45 christos c_recover, 154 1.45 christos c_remove, 155 1.45 christos c_resize, 156 1.45 christos c_resizedisk, 157 1.45 christos #ifndef HAVE_NBTOOL_CONFIG_H 158 1.45 christos c_restore, 159 1.45 christos #endif 160 1.45 christos c_set, 161 1.45 christos c_show, 162 1.45 christos c_type, 163 1.45 christos c_unset, 164 1.45 christos c_uuid; 165 1.45 christos 166 1.1 christos #endif /* _GPT_H_ */ 167