Home | History | Annotate | Download | only in gpt

Lines Matching refs:gpt

33 __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp $");
51 #include "gpt.h"
71 * relocate the secondary GPT based on the following criteria:
82 resizedisk(gpt_t gpt, off_t sector, off_t size __unused, bool quiet)
91 last = gpt->mediasz / gpt->secsz - 1;
96 gpt_warnx(gpt, "specified number of sectors %jd"
102 mbrmap = map_find(gpt, MAP_TYPE_PMBR);
104 gpt_warnx(gpt, "No valid PMBR found");
109 gpt->gpt = map_find(gpt, MAP_TYPE_PRI_GPT_HDR);
110 if (gpt->gpt == NULL) {
111 gpt_warnx(gpt, "No primary GPT header; run create or recover");
115 gpt->tbl = map_find(gpt, MAP_TYPE_PRI_GPT_TBL);
116 if (gpt->tbl == NULL) {
117 gpt_warnx(gpt, "No primary GPT table; Run recover");
121 hdr = gpt->gpt->map_data;
124 gpt->tpg = map_find(gpt, MAP_TYPE_SEC_GPT_HDR);
125 gpt->lbt = map_find(gpt, MAP_TYPE_SEC_GPT_TBL);
127 if (gpt->tpg == NULL || gpt->lbt == NULL)
128 gpt_warnx(gpt, "No secondary GPT table");
130 gpt_size = gpt->tbl->map_size;
133 gpt_warnx(gpt, "Device is already the specified size");
139 gpt_warnx(gpt, "Device hasn't changed size");
140 if (gpt->tpg != NULL && gpt->lbt != NULL)
144 for (ent = gpt->tbl->map_data; ent <
145 (struct gpt_ent *)((char *)gpt->tbl->map_data +
154 gpt_warnx(gpt, "Not enough space at %" PRIu64
155 " for secondary GPT table", sector);
160 gpt_warnx(gpt, "Not enough space for new secondary GPT table");
171 if (newloc > 0 && gpt->tpg != NULL && gpt->lbt != NULL) {
173 gpt_msg(gpt, "Moving secondary GPT header");
174 gpt->tpg->map_start = newloc;
175 gpt->lbt->map_start = newloc - gpt_size;
178 gpt_msg(gpt, "Creating new secondary GPT header");
184 if (gpt_add_hdr(gpt, MAP_TYPE_SEC_GPT_HDR, newloc) == -1)
187 gpt->lbt = map_add(gpt, newloc - gpt_size, gpt_size,
188 MAP_TYPE_SEC_GPT_TBL, gpt->tbl->map_data, 0);
189 if (gpt->lbt == NULL) {
190 gpt_warn(gpt, "Error adding secondary GPT table");
193 memcpy(gpt->tpg->map_data, gpt->gpt->map_data, gpt->secsz);
196 hdr = gpt->gpt->map_data;
197 hdr->hdr_lba_alt = htole64((uint64_t)gpt->tpg->map_start);
199 hdr->hdr_lba_end = htole64((uint64_t)(gpt->lbt->map_start - 1));
201 htole32(crc32(gpt->gpt->map_data, GPT_HDR_SIZE));
202 gpt_write(gpt, gpt->gpt);
204 hdr = gpt->tpg->map_data;
205 hdr->hdr_lba_self = htole64((uint64_t)gpt->tpg->map_start);
206 hdr->hdr_lba_alt = htole64((uint64_t)gpt->gpt->map_start);
207 hdr->hdr_lba_end = htole64((uint64_t)(gpt->lbt->map_start - 1));
208 hdr->hdr_lba_table = htole64((uint64_t)gpt->lbt->map_start);
210 if (gpt_write_backup(gpt) == -1)
217 gpt_warnx(gpt, "No valid PMBR partition found");
227 if (gpt_write(gpt, mbrmap) == -1) {
228 gpt_warnx(gpt, "Error writing PMBR");
236 cmd_resizedisk(gpt_t gpt, int argc, char *argv[])
239 off_t sector, size = gpt->mediasz;
245 if (gpt_add_ais(gpt, NULL, NULL, &size, ch) == -1)
259 if ((sector = gpt_check_ais(gpt, 0, (u_int)~0, size)) == -1)
263 gpt_warnx(gpt, "New size %ju too small", (uintmax_t)size);
267 return resizedisk(gpt, sector, size, quiet);