com32/chain: comments, minor adjustment
[syslinux.git] / com32 / chain / partiter.c
blob092cca255ae64d244333a80c77dec9bcdedba9be
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2003-2009 H. Peter Anvin - All Rights Reserved
4 * Copyright 2009-2010 Intel Corporation; author: H. Peter Anvin
5 * Copyright 2010 Shao Miller
6 * Copyright 2010-2012 Michal Soltys
8 * Permission is hereby granted, free of charge, to any person
9 * obtaining a copy of this software and associated documentation
10 * files (the "Software"), to deal in the Software without
11 * restriction, including without limitation the rights to use,
12 * copy, modify, merge, publish, distribute, sublicense, and/or
13 * sell copies of the Software, and to permit persons to whom
14 * the Software is furnished to do so, subject to the following
15 * conditions:
17 * The above copyright notice and this permission notice shall
18 * be included in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
22 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
29 * ----------------------------------------------------------------------- */
32 * partiter.c
34 * Provides disk / partition iteration.
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <string.h>
40 #include <stdarg.h>
41 #include <zlib.h>
42 #include <syslinux/disk.h>
43 #include "common.h"
44 #include "partiter.h"
45 #include "utility.h"
47 #define ost_is_ext(type) ((type) == 0x05 || (type) == 0x0F || (type) == 0x85)
48 #define ost_is_nondata(type) (ost_is_ext(type) || (type) == 0x00)
49 #define sane(s,l) ((s)+(l) > (s))
51 /* forwards */
53 static int iter_ctor(struct part_iter *, va_list *);
54 static int iter_dos_ctor(struct part_iter *, va_list *);
55 static int iter_gpt_ctor(struct part_iter *, va_list *);
56 static void iter_dtor(struct part_iter *);
57 static struct part_iter *pi_dos_next(struct part_iter *);
58 static struct part_iter *pi_gpt_next(struct part_iter *);
59 static struct part_iter *pi_raw_next(struct part_iter *);
61 static struct itertype types[] = {
62 [0] = {
63 .ctor = &iter_dos_ctor,
64 .dtor = &iter_dtor,
65 .next = &pi_dos_next,
66 }, [1] = {
67 .ctor = &iter_gpt_ctor,
68 .dtor = &iter_dtor,
69 .next = &pi_gpt_next,
70 }, [2] = {
71 .ctor = &iter_ctor,
72 .dtor = &iter_dtor,
73 .next = &pi_raw_next,
74 }};
76 const struct itertype * const typedos = types;
77 const struct itertype * const typegpt = types+1;
78 const struct itertype * const typeraw = types+2;
80 #ifdef DEBUG
81 static int inv_type(const void *type)
83 int i, cnt = sizeof(types)/sizeof(types[0]);
84 for (i = 0; i < cnt; i++) {
85 if (type == types + i)
86 return 0;
88 return -1;
90 #endif
92 /**
93 * iter_ctor() - common iterator initialization
94 * @iter: iterator pointer
95 * @args(0): disk_info structure used for disk functions
96 * @args(1): stepall modifier
98 * Second and further arguments are passed as a pointer to va_list
99 **/
100 static int iter_ctor(struct part_iter *iter, va_list *args)
102 const struct disk_info *di = va_arg(*args, const struct disk_info *);
103 int stepall = va_arg(*args, int);
105 #ifdef DEBUG
106 if (!di)
107 return -1;
108 #endif
110 memcpy(&iter->di, di, sizeof(struct disk_info));
111 iter->stepall = stepall;
112 iter->index0 = -1;
113 iter->length = di->lbacnt;
115 return 0;
119 * iter_dtor() - common iterator cleanup
120 * @iter: iterator pointer
123 static void iter_dtor(struct part_iter *iter)
125 free(iter->data);
129 * iter_dos_ctor() - MBR/EBR iterator specific initialization
130 * @iter: iterator pointer
131 * @args(0): disk_info structure used for disk functions
132 * @args(1): pointer to buffer with loaded valid MBR
134 * Second and further arguments are passed as a pointer to va_list.
135 * This function only makes rudimentary checks. If user uses
136 * pi_new(), he/she is responsible for doing proper sanity checks.
138 static int iter_dos_ctor(struct part_iter *iter, va_list *args)
140 const struct disk_dos_mbr *mbr;
142 /* uses args(0) */
143 if (iter_ctor(iter, args))
144 return -1;
146 mbr = va_arg(*args, const struct disk_dos_mbr *);
148 #ifdef DEBUG
149 if (!mbr)
150 goto bail;
151 #endif
153 if (!(iter->data = malloc(sizeof(struct disk_dos_mbr))))
154 goto bail;
156 memcpy(iter->data, mbr, sizeof(struct disk_dos_mbr));
158 iter->sub.dos.bebr_index0 = -1;
159 iter->sub.dos.disk_sig = mbr->disk_sig;
161 return 0;
162 bail:
163 iter->type->dtor(iter);
164 return -1;
168 * iter_gpt_ctor() - GPT iterator specific initialization
169 * @iter: iterator pointer
170 * @args(0): ptr to disk_info structure
171 * @args(1): ptr to buffer with GPT header
172 * @args(2): ptr to buffer with GPT partition list
174 * Second and further arguments are passed as a pointer to va_list.
175 * This function only makes rudimentary checks. If user uses
176 * pi_new(), he/she is responsible for doing proper sanity checks.
178 static int iter_gpt_ctor(struct part_iter *iter, va_list *args)
180 uint64_t siz;
181 const struct disk_gpt_header *gpth;
182 const struct disk_gpt_part_entry *gptl;
184 /* uses args(0) */
185 if (iter_ctor(iter, args))
186 return -1;
188 gpth = va_arg(*args, const struct disk_gpt_header *);
189 gptl = va_arg(*args, const struct disk_gpt_part_entry *);
191 #ifdef DEBUG
192 if (!gpth || !gptl)
193 goto bail;
194 #endif
196 siz = (uint64_t)gpth->part_count * gpth->part_size;
198 #ifdef DEBUG
199 if (!siz || (siz + iter->di.bps - 1) / iter->di.bps > 255u ||
200 gpth->part_size < sizeof(struct disk_gpt_part_entry)) {
201 goto bail;
203 #endif
205 if (!(iter->data = malloc((size_t)siz)))
206 goto bail;
208 memcpy(iter->data, gptl, (size_t)siz);
210 iter->sub.gpt.pe_count = (int)gpth->part_count;
211 iter->sub.gpt.pe_size = (int)gpth->part_size;
212 iter->sub.gpt.ufirst = gpth->lba_first_usable;
213 iter->sub.gpt.ulast = gpth->lba_last_usable;
215 memcpy(&iter->sub.gpt.disk_guid, &gpth->disk_guid, sizeof(struct guid));
217 return 0;
218 bail:
219 iter->type->dtor(iter);
220 return -1;
223 /* Logical partition must be sane, meaning:
224 * - must be data or empty
225 * - must have non-0 start and length
226 * - values must not wrap around 32bit
227 * - must be inside current EBR frame
230 static int notsane_logical(const struct part_iter *iter)
232 const struct disk_dos_part_entry *dp;
233 uint32_t end_log;
235 dp = ((struct disk_dos_mbr *)iter->data)->table;
237 if (!dp[0].ostype)
238 return 0;
240 if (ost_is_ext(dp[0].ostype)) {
241 error("1st EBR entry must be data or empty.\n");
242 return -1;
245 end_log = dp[0].start_lba + dp[0].length;
247 if (!dp[0].start_lba ||
248 !dp[0].length ||
249 !sane(dp[0].start_lba, dp[0].length) ||
250 end_log > iter->sub.dos.ebr_size) {
252 error("Insane logical partition.\n");
253 return -1;
256 return 0;
259 /* Extended partition must be sane, meaning:
260 * - must be extended or empty
261 * - must have non-0 start and length
262 * - values must not wrap around 32bit
263 * - must be inside base EBR frame
266 static int notsane_extended(const struct part_iter *iter)
268 const struct disk_dos_part_entry *dp;
269 uint32_t end_ebr;
271 dp = ((struct disk_dos_mbr *)iter->data)->table;
273 if (!dp[1].ostype)
274 return 0;
276 if (!ost_is_nondata(dp[1].ostype)) {
277 error("2nd EBR entry must be extended or empty.\n");
278 return -1;
281 end_ebr = dp[1].start_lba + dp[1].length;
283 if (!dp[1].start_lba ||
284 !dp[1].length ||
285 !sane(dp[1].start_lba, dp[1].length) ||
286 end_ebr > iter->sub.dos.bebr_size) {
288 error("Insane extended partition.\n");
289 return -1;
292 return 0;
295 /* Primary partition must be sane, meaning:
296 * - must have non-0 start and length
297 * - values must not wrap around 32bit
300 static int notsane_primary(const struct part_iter *iter)
302 const struct disk_dos_part_entry *dp;
303 dp = ((struct disk_dos_mbr *)iter->data)->table + iter->index0;
305 if (!dp->ostype)
306 return 0;
308 if (!dp->start_lba ||
309 !dp->length ||
310 !sane(dp->start_lba, dp->length) ||
311 dp->start_lba + dp->length > iter->di.lbacnt) {
312 error("Insane primary (MBR) partition.\n");
313 return -1;
316 return 0;
319 static int notsane_gpt(const struct part_iter *iter)
321 const struct disk_gpt_part_entry *gp;
322 gp = (const struct disk_gpt_part_entry *)
323 (iter->data + iter->index0 * iter->sub.gpt.pe_size);
325 if (guid_is0(&gp->type))
326 return 0;
328 if (gp->lba_first < iter->sub.gpt.ufirst ||
329 gp->lba_last > iter->sub.gpt.ulast) {
330 error("Insane GPT partition.\n");
331 return -1;
334 return 0;
337 static int pi_dos_next_mbr(struct part_iter *iter, uint32_t *lba,
338 struct disk_dos_part_entry **_dp)
340 struct disk_dos_part_entry *dp;
342 while (++iter->index0 < 4) {
343 dp = ((struct disk_dos_mbr *)iter->data)->table + iter->index0;
345 if (notsane_primary(iter)) {
346 iter->status = PI_INSANE;
347 goto bail;
350 if (ost_is_ext(dp->ostype)) {
351 if (iter->sub.dos.bebr_index0 >= 0) {
352 error("You have more than 1 extended partition.\n");
353 iter->status = PI_INSANE;
354 goto bail;
356 /* record base EBR index */
357 iter->sub.dos.bebr_index0 = iter->index0;
359 if (!ost_is_nondata(dp->ostype) || iter->stepall) {
360 *lba = dp->start_lba;
361 *_dp = dp;
362 break;
366 return 0;
367 bail:
368 return -1;
371 static int prep_base_ebr(struct part_iter *iter)
373 struct disk_dos_part_entry *dp;
375 if (iter->sub.dos.bebr_index0 < 0) /* if we don't have base extended partition at all */
376 return -1;
377 else if (!iter->sub.dos.bebr_start) { /* if not initialized yet */
378 dp = ((struct disk_dos_mbr *)iter->data)->table + iter->sub.dos.bebr_index0;
380 iter->sub.dos.bebr_start = dp->start_lba;
381 iter->sub.dos.bebr_size = dp->length;
383 iter->sub.dos.ebr_start = 0;
384 iter->sub.dos.ebr_size = iter->sub.dos.bebr_size;
386 iter->sub.dos.cebr_lba = 0;
387 iter->sub.dos.nebr_lba = iter->sub.dos.bebr_start;
389 iter->index0--;
391 return 0;
394 static int pi_dos_next_ebr(struct part_iter *iter, uint32_t *lba,
395 struct disk_dos_part_entry **_dp)
397 struct disk_dos_part_entry *dp;
399 if (prep_base_ebr(iter)) {
400 iter->status = PI_DONE;
401 return -1;
404 while (++iter->index0 < 1024 && iter->sub.dos.nebr_lba) {
405 free(iter->data);
406 if (!(iter->data =
407 disk_read_sectors(&iter->di, iter->sub.dos.nebr_lba, 1))) {
408 error("Couldn't load EBR.\n");
409 iter->status = PI_ERRLOAD;
410 return -1;
413 if (notsane_logical(iter) || notsane_extended(iter)) {
414 iter->status = PI_INSANE;
415 return -1;
418 dp = ((struct disk_dos_mbr *)iter->data)->table;
420 iter->sub.dos.cebr_lba = iter->sub.dos.nebr_lba;
422 /* setup next frame values */
423 if (dp[1].ostype) {
424 iter->sub.dos.ebr_start = dp[1].start_lba;
425 iter->sub.dos.ebr_size = dp[1].length;
426 iter->sub.dos.nebr_lba = iter->sub.dos.bebr_start + dp[1].start_lba;
427 } else {
428 iter->sub.dos.ebr_start = 0;
429 iter->sub.dos.ebr_size = 0;
430 iter->sub.dos.nebr_lba = 0;
433 if (!dp[0].ostype)
434 iter->sub.dos.skipcnt++;
436 if (dp[0].ostype || iter->stepall) {
437 *lba = iter->sub.dos.cebr_lba + dp[0].start_lba;
438 *_dp = dp;
439 return 0;
442 * This way it's possible to continue, if some crazy soft left a "hole"
443 * - EBR with a valid extended partition without a logical one. In
444 * such case, linux will not reserve a number for such hole - so we
445 * don't increase index0. If stepall flag is set, we will never reach
446 * this place.
449 iter->status = PI_DONE;
450 return -1;
453 static struct part_iter *pi_dos_next(struct part_iter *iter)
455 uint32_t start_lba = 0;
456 struct disk_dos_part_entry *dos_part = NULL;
458 if (iter->status)
459 goto bail;
461 /* look for primary partitions */
462 if (iter->index0 < 4 &&
463 pi_dos_next_mbr(iter, &start_lba, &dos_part))
464 goto bail;
466 /* look for logical partitions */
467 if (iter->index0 >= 4 &&
468 pi_dos_next_ebr(iter, &start_lba, &dos_part))
469 goto bail;
472 * note special index handling, if we have stepall set -
473 * this is made to keep index consistent with non-stepall
474 * iterators
477 if (iter->index0 >= 4 && !dos_part->ostype)
478 iter->index = -1;
479 else
480 iter->index = iter->index0 - iter->sub.dos.skipcnt + 1;
481 iter->rawindex = iter->index0 + 1;
482 iter->start_lba = start_lba;
483 iter->length = dos_part->length;
484 iter->record = (char *)dos_part;
486 #ifdef DEBUG
487 disk_dos_part_dump(dos_part);
488 #endif
490 return iter;
491 bail:
492 return NULL;
495 static void gpt_conv_label(struct part_iter *iter)
497 const struct disk_gpt_part_entry *gp;
498 const int16_t *orig_lab;
500 gp = (const struct disk_gpt_part_entry *)
501 (iter->data + iter->index0 * iter->sub.gpt.pe_size);
502 orig_lab = (const int16_t *)gp->name;
504 /* caveat: this is very crude conversion */
505 for (int i = 0; i < PI_GPTLABSIZE/2; i++) {
506 iter->sub.gpt.part_label[i] = (char)orig_lab[i];
508 iter->sub.gpt.part_label[PI_GPTLABSIZE/2] = 0;
511 static struct part_iter *pi_gpt_next(struct part_iter *iter)
513 const struct disk_gpt_part_entry *gpt_part = NULL;
515 if (iter->status)
516 goto bail;
518 while (++iter->index0 < iter->sub.gpt.pe_count) {
519 gpt_part = (const struct disk_gpt_part_entry *)
520 (iter->data + iter->index0 * iter->sub.gpt.pe_size);
522 if (notsane_gpt(iter)) {
523 iter->status = PI_INSANE;
524 goto bail;
527 if (!guid_is0(&gpt_part->type) || iter->stepall)
528 break;
530 /* no more partitions ? */
531 if (iter->index0 == iter->sub.gpt.pe_count) {
532 iter->status = PI_DONE;
533 goto bail;
535 /* gpt_part is guaranteed to be valid here */
536 iter->index = iter->index0 + 1;
537 iter->rawindex = iter->index0 + 1;
538 iter->start_lba = gpt_part->lba_first;
539 iter->length = gpt_part->lba_last - gpt_part->lba_first + 1;
540 iter->record = (char *)gpt_part;
541 memcpy(&iter->sub.gpt.part_guid, &gpt_part->uid, sizeof(struct guid));
542 gpt_conv_label(iter);
544 #ifdef DEBUG
545 disk_gpt_part_dump(gpt_part);
546 #endif
548 return iter;
549 bail:
550 return NULL;
553 static struct part_iter *pi_raw_next(struct part_iter *iter)
555 iter->status = PI_DONE;
556 return NULL;
559 static int check_crc(uint32_t crc_match, const uint8_t *buf, unsigned int siz)
561 uint32_t crc;
563 crc = crc32(0, NULL, 0);
564 crc = crc32(crc, buf, siz);
566 return crc_match != crc;
569 static int gpt_check_hdr_crc(const struct disk_info * const diskinfo, struct disk_gpt_header **_gh)
571 struct disk_gpt_header *gh = *_gh;
572 uint64_t lba_alt;
573 uint32_t hold_crc32;
575 hold_crc32 = gh->chksum;
576 gh->chksum = 0;
577 if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) {
578 error("WARNING: Primary GPT header checksum invalid.\n");
579 /* retry with backup */
580 lba_alt = gh->lba_alt;
581 free(gh);
582 if (!(gh = *_gh = disk_read_sectors(diskinfo, lba_alt, 1))) {
583 error("Couldn't read backup GPT header.\n");
584 return -1;
586 hold_crc32 = gh->chksum;
587 gh->chksum = 0;
588 if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) {
589 error("Secondary GPT header checksum invalid.\n");
590 return -1;
593 /* restore old checksum */
594 gh->chksum = hold_crc32;
596 return 0;
600 * ----------------------------------------------------------------------------
601 * Following functions are for users to call.
602 * ----------------------------------------------------------------------------
606 int pi_next(struct part_iter **_iter)
608 struct part_iter *iter;
610 if(!_iter || !*_iter)
611 return 0;
612 iter = *_iter;
613 #ifdef DEBUG
614 if (inv_type(iter->type)) {
615 error("This is not a valid iterator.\n");
616 return 0;
618 #endif
619 if ((iter = iter->type->next(iter))) {
620 *_iter = iter;
622 return (*_iter)->status;
626 * pi_new() - get new iterator
627 * @itertype: iterator type
628 * @...: variable arguments passed to ctors
630 * Variable arguments depend on the type. Please see functions:
631 * iter_gpt_ctor() and iter_dos_ctor() for details.
633 struct part_iter *pi_new(const struct itertype *type, ...)
635 int badctor = 0;
636 struct part_iter *iter = NULL;
637 va_list ap;
639 va_start(ap, type);
641 #ifdef DEBUG
642 if (inv_type(type)) {
643 error("Unknown iterator requested.\n");
644 goto bail;
646 #endif
648 if (!(iter = malloc(sizeof(struct part_iter)))) {
649 error("Couldn't allocate memory for the iterator.\n");
650 goto bail;
653 memset(iter, 0, sizeof(struct part_iter));
654 iter->type = type;
656 if (type->ctor(iter, &ap)) {
657 badctor = -1;
658 error("Cannot initialize the iterator.\n");
659 goto bail;
662 bail:
663 va_end(ap);
664 if (badctor) {
665 free(iter);
666 iter = NULL;
668 return iter;
672 * pi_del() - delete iterator
673 * @iter: iterator double pointer
677 void pi_del(struct part_iter **_iter)
679 struct part_iter *iter;
681 if(!_iter || !*_iter)
682 return;
683 iter = *_iter;
685 #ifdef DEBUG
686 if (inv_type(iter->type)) {
687 error("This is not a valid iterator.\n");
688 return;
690 #endif
692 iter->type->dtor(iter);
693 free(iter);
694 *_iter = NULL;
698 * pi_begin() - check disk, validate, and get proper iterator
699 * @di: diskinfo struct pointer
701 * This function checks the disk for GPT or legacy partition table and allocates
702 * an appropriate iterator.
704 struct part_iter *pi_begin(const struct disk_info *di, int stepall)
706 int setraw = 0;
707 struct part_iter *iter = NULL;
708 struct disk_dos_mbr *mbr = NULL;
709 struct disk_gpt_header *gpth = NULL;
710 struct disk_gpt_part_entry *gptl = NULL;
712 /* Read MBR */
713 if (!(mbr = disk_read_sectors(di, 0, 1))) {
714 error("Couldn't read first disk sector.\n");
715 goto bail;
718 setraw = -1;
720 /* Check for MBR magic*/
721 if (mbr->sig != disk_mbr_sig_magic) {
722 error("No MBR magic.\n");
723 goto bail;
726 /* Check for GPT protective MBR */
727 if (mbr->table[0].ostype == 0xEE) {
728 if (!(gpth = disk_read_sectors(di, 1, 1))) {
729 error("Couldn't read potential GPT header.\n");
730 goto bail;
734 if (gpth && gpth->rev.uint32 == 0x00010000 &&
735 !memcmp(gpth->sig, disk_gpt_sig_magic, sizeof(disk_gpt_sig_magic))) {
736 /* looks like GPT v1.0 */
737 uint64_t gpt_loff; /* offset to GPT partition list in sectors */
738 uint64_t gpt_lsiz; /* size of GPT partition list in bytes */
739 uint64_t gpt_lcnt; /* size of GPT partition in sectors */
740 #ifdef DEBUG
741 puts("Looks like a GPT v1.0 disk.");
742 disk_gpt_header_dump(gpth);
743 #endif
744 /* Verify checksum, fallback to backup, then bail if invalid */
745 if (gpt_check_hdr_crc(di, &gpth))
746 goto bail;
748 gpt_loff = gpth->lba_table;
749 gpt_lsiz = (uint64_t)gpth->part_size * gpth->part_count;
750 gpt_lcnt = (gpt_lsiz + di->bps - 1) / di->bps;
753 * disk_read_sectors allows reading of max 255 sectors, so we use
754 * it as a sanity check base. EFI doesn't specify max (AFAIK).
755 * Apart from that, some extensive sanity checks.
757 if (!gpt_loff || !gpt_lsiz || gpt_lcnt > 255u ||
758 gpth->lba_first_usable > gpth->lba_last_usable ||
759 !sane(gpt_loff, gpt_lcnt) ||
760 gpt_loff + gpt_lcnt > gpth->lba_first_usable ||
761 !sane(gpth->lba_last_usable, gpt_lcnt) ||
762 gpth->lba_last_usable + gpt_lcnt >= gpth->lba_alt ||
763 gpth->lba_alt >= di->lbacnt ||
764 gpth->part_size < sizeof(struct disk_gpt_part_entry)) {
765 error("Invalid GPT header's values.\n");
766 goto bail;
768 if (!(gptl = disk_read_sectors(di, gpt_loff, gpt_lcnt))) {
769 error("Couldn't read GPT partition list.\n");
770 goto bail;
772 /* Check array checksum(s). */
773 if (check_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) {
774 error("WARNING: GPT partition list checksum invalid, trying backup.\n");
775 free(gptl);
776 /* secondary array directly precedes secondary header */
777 if (!(gptl = disk_read_sectors(di, gpth->lba_alt - gpt_lcnt, gpt_lcnt))) {
778 error("Couldn't read backup GPT partition list.\n");
779 goto bail;
781 if (check_crc(gpth->table_chksum, (const uint8_t *)gptl, gpt_lsiz)) {
782 error("Backup GPT partition list checksum invalid.\n");
783 goto bail;
786 /* allocate iterator and exit */
787 iter = pi_new(typegpt, di, stepall, gpth, gptl);
788 } else {
789 /* looks like MBR */
790 iter = pi_new(typedos, di, stepall, mbr);
793 setraw = 0;
794 bail:
795 if (setraw) {
796 error("WARNING: treating disk as raw.\n");
797 iter = pi_new(typeraw, di, stepall);
799 free(mbr);
800 free(gpth);
801 free(gptl);
803 return iter;
806 /* vim: set ts=8 sts=4 sw=4 noet: */