com32/chain: add generic length field to partition iterators
[syslinux.git] / com32 / chain / partiter.c
blob1acd1958689ca94261576cf31b777ca6f1ce8e44
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2003-2010 H. Peter Anvin - All Rights Reserved
4 * Copyright 2010 Shao Miller
5 * Copyright 2010 Michal Soltys
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use,
11 * copy, modify, merge, publish, distribute, sublicense, and/or
12 * sell copies of the Software, and to permit persons to whom
13 * the Software is furnished to do so, subject to the following
14 * conditions:
16 * The above copyright notice and this permission notice shall
17 * be included in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
28 * ----------------------------------------------------------------------- */
31 * partiter.c
33 * Provides disk / partition iteration.
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <string.h>
39 #include <stdarg.h>
40 #include <zlib.h>
41 #include <syslinux/disk.h>
42 #include "common.h"
43 #include "partiter.h"
44 #include "utility.h"
46 #define ost_is_ext(type) ((type) == 0x05 || (type) == 0x0F || (type) == 0x85)
47 #define ost_is_nondata(type) (ost_is_ext(type) || (type) == 0x00)
48 #define sane(s,l) ((s)+(l) > (s))
50 /* forwards */
52 static int iter_ctor(struct part_iter *, va_list *);
53 static int iter_dos_ctor(struct part_iter *, va_list *);
54 static int iter_gpt_ctor(struct part_iter *, va_list *);
55 static void iter_dtor(struct part_iter *);
56 static struct part_iter *pi_dos_next(struct part_iter *);
57 static struct part_iter *pi_gpt_next(struct part_iter *);
58 static struct part_iter *pi_raw_next(struct part_iter *);
60 static struct itertype types[] = {
61 [0] = {
62 .ctor = &iter_dos_ctor,
63 .dtor = &iter_dtor,
64 .next = &pi_dos_next,
65 }, [1] = {
66 .ctor = &iter_gpt_ctor,
67 .dtor = &iter_dtor,
68 .next = &pi_gpt_next,
69 }, [2] = {
70 .ctor = &iter_ctor,
71 .dtor = &iter_dtor,
72 .next = &pi_raw_next,
73 }};
75 const struct itertype * const typedos = types;
76 const struct itertype * const typegpt = types+1;
77 const struct itertype * const typeraw = types+2;
79 #ifdef DEBUG
80 static int inv_type(const void *type)
82 int i, cnt = sizeof(types)/sizeof(types[0]);
83 for (i = 0; i < cnt; i++) {
84 if (type == types + i)
85 return 0;
87 return -1;
89 #endif
91 /**
92 * iter_ctor() - common iterator initialization
93 * @iter: iterator pointer
94 * @args(0): disk_info structure used for disk functions
95 * @args(1): stepall modifier
97 * Second and further arguments are passed as a pointer to va_list
98 **/
99 static int iter_ctor(struct part_iter *iter, va_list *args)
101 const struct disk_info *di = va_arg(*args, const struct disk_info *);
102 int stepall = va_arg(*args, int);
104 #ifdef DEBUG
105 if (!di)
106 return -1;
107 #endif
109 memcpy(&iter->di, di, sizeof(struct disk_info));
110 iter->stepall = stepall;
111 iter->index0 = -1;
112 iter->length = di->lbacnt;
114 return 0;
118 * iter_dtor() - common iterator cleanup
119 * @iter: iterator pointer
122 static void iter_dtor(struct part_iter *iter)
124 free(iter->data);
128 * iter_dos_ctor() - MBR/EBR iterator specific initialization
129 * @iter: iterator pointer
130 * @args(0): disk_info structure used for disk functions
131 * @args(1): pointer to buffer with loaded valid MBR
133 * Second and further arguments are passed as a pointer to va_list.
134 * This function only makes rudimentary checks. If user uses
135 * pi_new(), he/she is responsible for doing proper sanity checks.
137 static int iter_dos_ctor(struct part_iter *iter, va_list *args)
139 const struct disk_dos_mbr *mbr;
141 /* uses args(0) */
142 if (iter_ctor(iter, args))
143 return -1;
145 mbr = va_arg(*args, const struct disk_dos_mbr *);
147 #ifdef DEBUG
148 if (!mbr)
149 goto bail;
150 #endif
152 if (!(iter->data = malloc(sizeof(struct disk_dos_mbr))))
153 goto bail;
155 memcpy(iter->data, mbr, sizeof(struct disk_dos_mbr));
157 iter->sub.dos.bebr_index0 = -1;
158 iter->sub.dos.disk_sig = mbr->disk_sig;
160 return 0;
161 bail:
162 iter->type->dtor(iter);
163 return -1;
167 * iter_gpt_ctor() - GPT iterator specific initialization
168 * @iter: iterator pointer
169 * @args(0): ptr to disk_info structure
170 * @args(1): ptr to buffer with GPT header
171 * @args(2): ptr to buffer with GPT partition list
173 * Second and further arguments are passed as a pointer to va_list.
174 * This function only makes rudimentary checks. If user uses
175 * pi_new(), he/she is responsible for doing proper sanity checks.
177 static int iter_gpt_ctor(struct part_iter *iter, va_list *args)
179 uint64_t siz;
180 const struct disk_gpt_header *gpth;
181 const struct disk_gpt_part_entry *gptl;
183 /* uses args(0) */
184 if (iter_ctor(iter, args))
185 return -1;
187 gpth = va_arg(*args, const struct disk_gpt_header *);
188 gptl = va_arg(*args, const struct disk_gpt_part_entry *);
190 #ifdef DEBUG
191 if (!gpth || !gptl)
192 goto bail;
193 #endif
195 siz = (uint64_t)gpth->part_count * gpth->part_size;
197 #ifdef DEBUG
198 if (!siz || (siz + iter->di.bps - 1) / iter->di.bps > 255u ||
199 gpth->part_size < sizeof(struct disk_gpt_part_entry)) {
200 goto bail;
202 #endif
204 if (!(iter->data = malloc((size_t)siz)))
205 goto bail;
207 memcpy(iter->data, gptl, (size_t)siz);
209 iter->sub.gpt.pe_count = (int)gpth->part_count;
210 iter->sub.gpt.pe_size = (int)gpth->part_size;
211 iter->sub.gpt.ufirst = gpth->lba_first_usable;
212 iter->sub.gpt.ulast = gpth->lba_last_usable;
214 memcpy(&iter->sub.gpt.disk_guid, &gpth->disk_guid, sizeof(struct guid));
216 return 0;
217 bail:
218 iter->type->dtor(iter);
219 return -1;
222 /* Logical partition must be sane, meaning:
223 * - must be data or empty
224 * - must have non-0 start and length
225 * - values must not wrap around 32bit
226 * - must be inside current EBR frame
229 static int notsane_logical(const struct part_iter *iter)
231 const struct disk_dos_part_entry *dp;
232 uint32_t end_log;
234 dp = ((struct disk_dos_mbr *)iter->data)->table;
236 if (!dp[0].ostype)
237 return 0;
239 if (ost_is_ext(dp[0].ostype)) {
240 error("1st EBR entry must be data or empty.\n");
241 return -1;
244 end_log = dp[0].start_lba + dp[0].length;
246 if (!dp[0].start_lba ||
247 !dp[0].length ||
248 !sane(dp[0].start_lba, dp[0].length) ||
249 end_log > iter->sub.dos.ebr_size) {
251 error("Insane logical partition.\n");
252 return -1;
255 return 0;
258 /* Extended partition must be sane, meaning:
259 * - must be extended or empty
260 * - must have non-0 start and length
261 * - values must not wrap around 32bit
262 * - must be inside base EBR frame
265 static int notsane_extended(const struct part_iter *iter)
267 const struct disk_dos_part_entry *dp;
268 uint32_t end_ebr;
270 dp = ((struct disk_dos_mbr *)iter->data)->table;
272 if (!dp[1].ostype)
273 return 0;
275 if (!ost_is_nondata(dp[1].ostype)) {
276 error("2nd EBR entry must be extended or empty.\n");
277 return -1;
280 end_ebr = dp[1].start_lba + dp[1].length;
282 if (!dp[1].start_lba ||
283 !dp[1].length ||
284 !sane(dp[1].start_lba, dp[1].length) ||
285 end_ebr > iter->sub.dos.bebr_size) {
287 error("Insane extended partition.\n");
288 return -1;
291 return 0;
294 /* Primary partition must be sane, meaning:
295 * - must have non-0 start and length
296 * - values must not wrap around 32bit
299 static int notsane_primary(const struct part_iter *iter)
301 const struct disk_dos_part_entry *dp;
302 dp = ((struct disk_dos_mbr *)iter->data)->table + iter->index0;
304 if (!dp->ostype)
305 return 0;
307 if (!dp->start_lba ||
308 !dp->length ||
309 !sane(dp->start_lba, dp->length) ||
310 dp->start_lba + dp->length > iter->di.lbacnt) {
311 error("Insane primary (MBR) partition.\n");
312 return -1;
315 return 0;
318 static int notsane_gpt(const struct part_iter *iter)
320 const struct disk_gpt_part_entry *gp;
321 gp = (const struct disk_gpt_part_entry *)
322 (iter->data + iter->index0 * iter->sub.gpt.pe_size);
324 if (guid_is0(&gp->type))
325 return 0;
327 if (gp->lba_first < iter->sub.gpt.ufirst ||
328 gp->lba_last > iter->sub.gpt.ulast) {
329 error("Insane GPT partition.\n");
330 return -1;
333 return 0;
336 static int pi_dos_next_mbr(struct part_iter *iter, uint32_t *lba,
337 struct disk_dos_part_entry **_dp)
339 struct disk_dos_part_entry *dp;
341 while (++iter->index0 < 4) {
342 dp = ((struct disk_dos_mbr *)iter->data)->table + iter->index0;
344 if (notsane_primary(iter)) {
345 iter->status = PI_INSANE;
346 goto bail;
349 if (ost_is_ext(dp->ostype)) {
350 if (iter->sub.dos.bebr_index0 >= 0) {
351 error("You have more than 1 extended partition.\n");
352 iter->status = PI_INSANE;
353 goto bail;
355 /* record base EBR index */
356 iter->sub.dos.bebr_index0 = iter->index0;
358 if (!ost_is_nondata(dp->ostype) || iter->stepall) {
359 *lba = dp->start_lba;
360 *_dp = dp;
361 break;
365 return 0;
366 bail:
367 return -1;
370 static int prep_base_ebr(struct part_iter *iter)
372 struct disk_dos_part_entry *dp;
374 if (iter->sub.dos.bebr_index0 < 0) /* if we don't have base extended partition at all */
375 return -1;
376 else if (!iter->sub.dos.bebr_start) { /* if not initialized yet */
377 dp = ((struct disk_dos_mbr *)iter->data)->table + iter->sub.dos.bebr_index0;
379 iter->sub.dos.bebr_start = dp->start_lba;
380 iter->sub.dos.bebr_size = dp->length;
382 iter->sub.dos.ebr_start = 0;
383 iter->sub.dos.ebr_size = iter->sub.dos.bebr_size;
385 iter->sub.dos.cebr_lba = 0;
386 iter->sub.dos.nebr_lba = iter->sub.dos.bebr_start;
388 iter->index0--;
390 return 0;
393 static int pi_dos_next_ebr(struct part_iter *iter, uint32_t *lba,
394 struct disk_dos_part_entry **_dp)
396 struct disk_dos_part_entry *dp;
398 if (prep_base_ebr(iter)) {
399 iter->status = PI_DONE;
400 return -1;
403 while (++iter->index0 < 1024 && iter->sub.dos.nebr_lba) {
404 free(iter->data);
405 if (!(iter->data =
406 disk_read_sectors(&iter->di, iter->sub.dos.nebr_lba, 1))) {
407 error("Couldn't load EBR.\n");
408 iter->status = PI_ERRLOAD;
409 return -1;
412 if (notsane_logical(iter) || notsane_extended(iter)) {
413 iter->status = PI_INSANE;
414 return -1;
417 dp = ((struct disk_dos_mbr *)iter->data)->table;
419 iter->sub.dos.cebr_lba = iter->sub.dos.nebr_lba;
421 /* setup next frame values */
422 if (dp[1].ostype) {
423 iter->sub.dos.ebr_start = dp[1].start_lba;
424 iter->sub.dos.ebr_size = dp[1].length;
425 iter->sub.dos.nebr_lba = iter->sub.dos.bebr_start + dp[1].start_lba;
426 } else {
427 iter->sub.dos.ebr_start = 0;
428 iter->sub.dos.ebr_size = 0;
429 iter->sub.dos.nebr_lba = 0;
432 if (!dp[0].ostype)
433 iter->sub.dos.skipcnt++;
435 if (dp[0].ostype || iter->stepall) {
436 *lba = iter->sub.dos.cebr_lba + dp[0].start_lba;
437 *_dp = dp;
438 return 0;
441 * This way it's possible to continue, if some crazy soft left a "hole"
442 * - EBR with a valid extended partition without a logical one. In
443 * such case, linux will not reserve a number for such hole - so we
444 * don't increase index0. If stepall flag is set, we will never reach
445 * this place.
448 iter->status = PI_DONE;
449 return -1;
452 static struct part_iter *pi_dos_next(struct part_iter *iter)
454 uint32_t start_lba = 0;
455 struct disk_dos_part_entry *dos_part = NULL;
457 if (iter->status)
458 goto bail;
460 /* look for primary partitions */
461 if (iter->index0 < 4 &&
462 pi_dos_next_mbr(iter, &start_lba, &dos_part))
463 goto bail;
465 /* look for logical partitions */
466 if (iter->index0 >= 4 &&
467 pi_dos_next_ebr(iter, &start_lba, &dos_part))
468 goto bail;
471 * note special index handling, if we have stepall set -
472 * this is made to keep index consistent with non-stepall
473 * iterators
476 if (iter->index0 >= 4 && !dos_part->ostype)
477 iter->index = -1;
478 else
479 iter->index = iter->index0 - iter->sub.dos.skipcnt + 1;
480 iter->rawindex = iter->index0 + 1;
481 iter->start_lba = start_lba;
482 iter->length = dos_part->length;
483 iter->record = (char *)dos_part;
485 #ifdef DEBUG
486 disk_dos_part_dump(dos_part);
487 #endif
489 return iter;
490 bail:
491 return NULL;
494 static void gpt_conv_label(struct part_iter *iter)
496 const struct disk_gpt_part_entry *gp;
497 const int16_t *orig_lab;
499 gp = (const struct disk_gpt_part_entry *)
500 (iter->data + iter->index0 * iter->sub.gpt.pe_size);
501 orig_lab = (const int16_t *)gp->name;
503 /* caveat: this is very crude conversion */
504 for (int i = 0; i < PI_GPTLABSIZE/2; i++) {
505 iter->sub.gpt.part_label[i] = (char)orig_lab[i];
507 iter->sub.gpt.part_label[PI_GPTLABSIZE/2] = 0;
510 static struct part_iter *pi_gpt_next(struct part_iter *iter)
512 const struct disk_gpt_part_entry *gpt_part = NULL;
514 if (iter->status)
515 goto bail;
517 while (++iter->index0 < iter->sub.gpt.pe_count) {
518 gpt_part = (const struct disk_gpt_part_entry *)
519 (iter->data + iter->index0 * iter->sub.gpt.pe_size);
521 if (notsane_gpt(iter)) {
522 iter->status = PI_INSANE;
523 goto bail;
526 if (!guid_is0(&gpt_part->type) || iter->stepall)
527 break;
529 /* no more partitions ? */
530 if (iter->index0 == iter->sub.gpt.pe_count) {
531 iter->status = PI_DONE;
532 goto bail;
534 /* gpt_part is guaranteed to be valid here */
535 iter->index = iter->index0 + 1;
536 iter->rawindex = iter->index0 + 1;
537 iter->start_lba = gpt_part->lba_first;
538 iter->length = gpt_part->lba_last - gpt_part->lba_first + 1;
539 iter->record = (char *)gpt_part;
540 memcpy(&iter->sub.gpt.part_guid, &gpt_part->uid, sizeof(struct guid));
541 gpt_conv_label(iter);
543 #ifdef DEBUG
544 disk_gpt_part_dump(gpt_part);
545 #endif
547 return iter;
548 bail:
549 return NULL;
552 static struct part_iter *pi_raw_next(struct part_iter *iter)
554 iter->status = PI_DONE;
555 return NULL;
558 static int check_crc(uint32_t crc_match, const uint8_t *buf, unsigned int siz)
560 uint32_t crc;
562 crc = crc32(0, NULL, 0);
563 crc = crc32(crc, buf, siz);
565 return crc_match != crc;
568 static int gpt_check_hdr_crc(const struct disk_info * const diskinfo, struct disk_gpt_header **_gh)
570 struct disk_gpt_header *gh = *_gh;
571 uint64_t lba_alt;
572 uint32_t hold_crc32;
574 hold_crc32 = gh->chksum;
575 gh->chksum = 0;
576 if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) {
577 error("WARNING: Primary GPT header checksum invalid.\n");
578 /* retry with backup */
579 lba_alt = gh->lba_alt;
580 free(gh);
581 if (!(gh = *_gh = disk_read_sectors(diskinfo, lba_alt, 1))) {
582 error("Couldn't read backup GPT header.\n");
583 return -1;
585 hold_crc32 = gh->chksum;
586 gh->chksum = 0;
587 if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) {
588 error("Secondary GPT header checksum invalid.\n");
589 return -1;
592 /* restore old checksum */
593 gh->chksum = hold_crc32;
595 return 0;
599 * ----------------------------------------------------------------------------
600 * Following functions are for users to call.
601 * ----------------------------------------------------------------------------
605 int pi_next(struct part_iter **_iter)
607 struct part_iter *iter;
609 if(!_iter || !*_iter)
610 return 0;
611 iter = *_iter;
612 #ifdef DEBUG
613 if (inv_type(iter->type)) {
614 error("This is not a valid iterator.\n");
615 return 0;
617 #endif
618 if ((iter = iter->type->next(iter))) {
619 *_iter = iter;
621 return (*_iter)->status;
625 * pi_new() - get new iterator
626 * @itertype: iterator type
627 * @...: variable arguments passed to ctors
629 * Variable arguments depend on the type. Please see functions:
630 * iter_gpt_ctor() and iter_dos_ctor() for details.
632 struct part_iter *pi_new(const struct itertype *type, ...)
634 int badctor = 0;
635 struct part_iter *iter = NULL;
636 va_list ap;
638 va_start(ap, type);
640 #ifdef DEBUG
641 if (inv_type(type)) {
642 error("Unknown iterator requested.\n");
643 goto bail;
645 #endif
647 if (!(iter = malloc(sizeof(struct part_iter)))) {
648 error("Couldn't allocate memory for the iterator.\n");
649 goto bail;
652 memset(iter, 0, sizeof(struct part_iter));
653 iter->type = type;
655 if (type->ctor(iter, &ap)) {
656 badctor = -1;
657 error("Cannot initialize the iterator.\n");
658 goto bail;
661 bail:
662 va_end(ap);
663 if (badctor) {
664 free(iter);
665 iter = NULL;
667 return iter;
671 * pi_del() - delete iterator
672 * @iter: iterator double pointer
676 void pi_del(struct part_iter **_iter)
678 struct part_iter *iter;
680 if(!_iter || !*_iter)
681 return;
682 iter = *_iter;
684 #ifdef DEBUG
685 if (inv_type(iter->type)) {
686 error("This is not a valid iterator.\n");
687 return;
689 #endif
691 iter->type->dtor(iter);
692 free(iter);
693 *_iter = NULL;
697 * pi_begin() - check disk, validate, and get proper iterator
698 * @di: diskinfo struct pointer
700 * This function checks the disk for GPT or legacy partition table and allocates
701 * an appropriate iterator.
703 struct part_iter *pi_begin(const struct disk_info *di, int stepall)
705 int setraw = 0;
706 struct part_iter *iter = NULL;
707 struct disk_dos_mbr *mbr = NULL;
708 struct disk_gpt_header *gpth = NULL;
709 struct disk_gpt_part_entry *gptl = NULL;
711 /* Read MBR */
712 if (!(mbr = disk_read_sectors(di, 0, 1))) {
713 error("Couldn't read first disk sector.\n");
714 goto bail;
717 setraw = -1;
719 /* Check for MBR magic*/
720 if (mbr->sig != disk_mbr_sig_magic) {
721 error("No MBR magic.\n");
722 goto bail;
725 /* Check for GPT protective MBR */
726 if (mbr->table[0].ostype == 0xEE) {
727 if (!(gpth = disk_read_sectors(di, 1, 1))) {
728 error("Couldn't read potential GPT header.\n");
729 goto bail;
733 if (gpth && gpth->rev.uint32 == 0x00010000 &&
734 !memcmp(gpth->sig, disk_gpt_sig_magic, sizeof(disk_gpt_sig_magic))) {
735 /* looks like GPT v1.0 */
736 uint64_t gpt_loff; /* offset to GPT partition list in sectors */
737 uint64_t gpt_lsiz; /* size of GPT partition list in bytes */
738 uint64_t gpt_lcnt; /* size of GPT partition in sectors */
739 #ifdef DEBUG
740 puts("Looks like a GPT v1.0 disk.");
741 disk_gpt_header_dump(gpth);
742 #endif
743 /* Verify checksum, fallback to backup, then bail if invalid */
744 if (gpt_check_hdr_crc(di, &gpth))
745 goto bail;
747 gpt_loff = gpth->lba_table;
748 gpt_lsiz = (uint64_t)gpth->part_size * gpth->part_count;
749 gpt_lcnt = (gpt_lsiz + di->bps - 1) / di->bps;
752 * disk_read_sectors allows reading of max 255 sectors, so we use
753 * it as a sanity check base. EFI doesn't specify max (AFAIK).
754 * Apart from that, some extensive sanity checks.
756 if (!gpt_loff || !gpt_lsiz || gpt_lcnt > 255u ||
757 gpth->lba_first_usable > gpth->lba_last_usable ||
758 !sane(gpt_loff, gpt_lcnt) ||
759 gpt_loff + gpt_lcnt > gpth->lba_first_usable ||
760 !sane(gpth->lba_last_usable, gpt_lcnt) ||
761 gpth->lba_last_usable + gpt_lcnt >= gpth->lba_alt ||
762 gpth->lba_alt >= di->lbacnt ||
763 gpth->part_size < sizeof(struct disk_gpt_part_entry)) {
764 error("Invalid GPT header's values.\n");
765 goto bail;
767 if (!(gptl = disk_read_sectors(di, gpt_loff, (uint8_t)gpt_lcnt))) {
768 error("Couldn't read GPT partition list.\n");
769 goto bail;
771 /* Check array checksum(s). */
772 if (check_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) {
773 error("WARNING: GPT partition list checksum invalid, trying backup.\n");
774 free(gptl);
775 /* secondary array directly precedes secondary header */
776 if (!(gptl = disk_read_sectors(di, gpth->lba_alt - gpt_lcnt, (uint8_t)gpt_lcnt))) {
777 error("Couldn't read backup GPT partition list.\n");
778 goto bail;
780 if (check_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) {
781 error("Backup GPT partition list checksum invalid.\n");
782 goto bail;
785 /* allocate iterator and exit */
786 iter = pi_new(typegpt, di, stepall, gpth, gptl);
787 } else {
788 /* looks like MBR */
789 iter = pi_new(typedos, di, stepall, mbr);
792 setraw = 0;
793 bail:
794 if (setraw) {
795 error("WARNING: treating disk as raw.\n");
796 iter = pi_new(typeraw, di, stepall);
798 free(mbr);
799 free(gpth);
800 free(gptl);
802 return iter;
805 /* vim: set ts=8 sts=4 sw=4 noet: */