Home | History | Annotate | Download | only in gpt

Lines Matching refs:gpt

33 __FBSDID("$FreeBSD: src/sbin/gpt/create.c,v 1.11 2005/08/31 01:47:19 marcel Exp $");
52 #include "gpt.h"
71 gpt_warnx(gpt, "proplib failure"); \
76 restore_mbr(gpt_t gpt, struct mbr *mbr, prop_dictionary_t mbr_dict, off_t last)
128 restore_ent(gpt_t gpt, prop_dictionary_t gpt_dict, void *secbuf,
138 gpt_warnx(gpt, "%s: not able to convert to an UUID", s);
143 gpt_warnx(gpt, "%s: not able to convert to an UUID", s);
162 gpt_warnx(gpt, "Entity index out of bounds %u > %u\n",
166 memcpy((char *)secbuf + gpt->secsz + ((i - 1) * sizeof(ent)),
172 restore(gpt_t gpt, const char *infile, int force)
190 last = gpt->mediasz / gpt->secsz - 1LL;
192 if (map_find(gpt, MAP_TYPE_PRI_GPT_HDR) != NULL ||
193 map_find(gpt, MAP_TYPE_SEC_GPT_HDR) != NULL) {
195 gpt_warnx(gpt, "Device contains a GPT");
199 map = map_find(gpt, MAP_TYPE_MBR);
202 gpt_warnx(gpt, "Device contains an MBR");
212 gpt_warnx(gpt, "Unable to read/parse backup file");
218 if (!prop_number_equals_signed(propnum, gpt->secsz)) {
219 gpt_warnx(gpt, "Sector size does not match backup");
230 gpt_warnx(gpt, "backup is not revision 1.0");
238 gpt_size = (u_int)(entries * sizeof(struct gpt_ent) / gpt->secsz);
239 if (gpt_size * sizeof(struct gpt_ent) % gpt->secsz)
244 gpt_warnx(gpt, "%s: not able to convert to an UUID", s);
247 firstdata = gpt_size + 2; /* PMBR and GPT header */
248 lastdata = last - gpt_size - 1; /* alt. GPT table and header */
259 gpt_warnx(gpt, "%s: not able to convert to an UUID", s);
269 gpt_warnx(gpt, "Backup GPT doesn't fit");
275 /* GPT TABLE + GPT HEADER */
276 if ((secbuf = calloc(gpt_size + 1, gpt->secsz)) == NULL) {
277 gpt_warn(gpt, "not enough memory to create a sector buffer");
281 if (lseek(gpt->fd, 0LL, SEEK_SET) == -1) {
282 gpt_warn(gpt, "Can't seek to beginning");
286 if (write(gpt->fd, secbuf, gpt->secsz) != (ssize_t)gpt->secsz) {
287 gpt_warn(gpt, "Error writing");
291 if (lseek(gpt->fd, (lastdata + 1) * gpt->secsz, SEEK_SET) == -1) {
292 gpt_warn(gpt, "Can't seek to end");
296 if (write(gpt->fd, secbuf, gpt->secsz) != (ssize_t)gpt->secsz) {
297 gpt_warn(gpt, "Error writing");
314 if (restore_mbr(gpt, mbr, mbr_dict, last) == -1)
320 if (lseek(gpt->fd, 0LL, SEEK_SET) == -1 ||
321 write(gpt->fd, mbr, gpt->secsz) != (ssize_t)gpt->secsz) {
322 gpt_warn(gpt, "Unable to seek/write MBR");
330 if (restore_ent(gpt, gpt_dict, secbuf, gpt_size, entries) == -1)
335 size_t len = gpt_size * gpt->secsz;
336 if (lseek(gpt->fd, 2 * gpt->secsz, SEEK_SET) == -1 ||
337 write(gpt->fd, (char *)secbuf + gpt->secsz, len) != (ssize_t) len) {
338 gpt_warn(gpt, "Unable to write primary GPT");
342 if (lseek(gpt->fd, (lastdata + 1) * gpt->secsz, SEEK_SET) == -1 ||
343 write(gpt->fd, (char *)secbuf + gpt->secsz, len) != (ssize_t) len) {
344 gpt_warn(gpt, "Unable to write secondary GPT");
348 memset(secbuf, 0, gpt->secsz);
361 hdr->hdr_crc_table = htole32(crc32((char *)secbuf + gpt->secsz, len));
363 if (lseek(gpt->fd, gpt->secsz, SEEK_SET) == -1 ||
364 write(gpt->fd, hdr, gpt->secsz) != (ssize_t)gpt->secsz) {
365 gpt_warn(gpt, "Unable to write primary header");
374 if (lseek(gpt->fd, last * gpt->secsz, SEEK_SET) == -1 ||
375 write(gpt->fd, hdr, gpt->secsz) != (ssize_t)gpt->secsz) {
376 gpt_warn(gpt, "Unable to write secondary header");
388 cmd_restore(gpt_t gpt, int argc, char *argv[])
410 return restore(gpt, infile, force);