com32/chain/partiter.c,h: updates
[syslinux.git] / com32 / chain / partiter.c
blob05443bb17f076780c7de9ebee35f516e003d9db2
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;
113 return 0;
117 * iter_dtor() - common iterator cleanup
118 * @iter: iterator pointer
121 static void iter_dtor(struct part_iter *iter)
123 free(iter->data);
127 * iter_dos_ctor() - MBR/EBR iterator specific initialization
128 * @iter: iterator pointer
129 * @args(0): disk_info structure used for disk functions
130 * @args(1): pointer to buffer with loaded valid MBR
132 * Second and further arguments are passed as a pointer to va_list.
133 * This function only makes rudimentary checks. If user uses
134 * pi_new(), he/she is responsible for doing proper sanity checks.
136 static int iter_dos_ctor(struct part_iter *iter, va_list *args)
138 const struct disk_dos_mbr *mbr;
140 /* uses args(0) */
141 if (iter_ctor(iter, args))
142 return -1;
144 mbr = va_arg(*args, const struct disk_dos_mbr *);
146 #ifdef DEBUG
147 if (!mbr)
148 goto bail;
149 #endif
151 if (!(iter->data = malloc(sizeof(struct disk_dos_mbr))))
152 goto bail;
154 memcpy(iter->data, mbr, sizeof(struct disk_dos_mbr));
156 iter->sub.dos.bebr_index0 = -1;
157 iter->sub.dos.disk_sig = mbr->disk_sig;
159 return 0;
160 bail:
161 iter->type->dtor(iter);
162 return -1;
166 * iter_gpt_ctor() - GPT iterator specific initialization
167 * @iter: iterator pointer
168 * @args(0): ptr to disk_info structure
169 * @args(1): ptr to buffer with GPT header
170 * @args(2): ptr to buffer with GPT partition list
172 * Second and further arguments are passed as a pointer to va_list.
173 * This function only makes rudimentary checks. If user uses
174 * pi_new(), he/she is responsible for doing proper sanity checks.
176 static int iter_gpt_ctor(struct part_iter *iter, va_list *args)
178 uint64_t siz;
179 const struct disk_gpt_header *gpth;
180 const struct disk_gpt_part_entry *gptl;
182 /* uses args(0) */
183 if (iter_ctor(iter, args))
184 return -1;
186 gpth = va_arg(*args, const struct disk_gpt_header *);
187 gptl = va_arg(*args, const struct disk_gpt_part_entry *);
189 #ifdef DEBUG
190 if (!gpth || !gptl)
191 goto bail;
192 #endif
194 siz = (uint64_t)gpth->part_count * gpth->part_size;
196 #ifdef DEBUG
197 if (!siz || (siz + iter->di.bps - 1) / iter->di.bps > 255u ||
198 gpth->part_size < sizeof(struct disk_gpt_part_entry)) {
199 goto bail;
201 #endif
203 if (!(iter->data = malloc((size_t)siz)))
204 goto bail;
206 memcpy(iter->data, gptl, (size_t)siz);
208 iter->sub.gpt.pe_count = (int)gpth->part_count;
209 iter->sub.gpt.pe_size = (int)gpth->part_size;
210 iter->sub.gpt.ufirst = gpth->lba_first_usable;
211 iter->sub.gpt.ulast = gpth->lba_last_usable;
213 memcpy(&iter->sub.gpt.disk_guid, &gpth->disk_guid, sizeof(struct guid));
215 return 0;
216 bail:
217 iter->type->dtor(iter);
218 return -1;
221 /* Logical partition must be sane, meaning:
222 * - must be data or empty
223 * - must have non-0 start and length
224 * - values must not wrap around 32bit
225 * - must be inside current EBR frame
228 static int notsane_logical(const struct part_iter *iter)
230 const struct disk_dos_part_entry *dp;
231 uint32_t end_log;
233 dp = ((struct disk_dos_mbr *)iter->data)->table;
235 if (!dp[0].ostype)
236 return 0;
238 if (ost_is_ext(dp[0].ostype)) {
239 error("1st EBR entry must be data or empty.\n");
240 return -1;
243 end_log = dp[0].start_lba + dp[0].length;
245 if (!dp[0].start_lba ||
246 !dp[0].length ||
247 !sane(dp[0].start_lba, dp[0].length) ||
248 end_log > iter->sub.dos.ebr_size) {
250 error("Insane logical partition.\n");
251 return -1;
254 return 0;
257 /* Extended partition must be sane, meaning:
258 * - must be extended or empty
259 * - must have non-0 start and length
260 * - values must not wrap around 32bit
261 * - must be inside base EBR frame
264 static int notsane_extended(const struct part_iter *iter)
266 const struct disk_dos_part_entry *dp;
267 uint32_t end_ebr;
269 dp = ((struct disk_dos_mbr *)iter->data)->table;
271 if (!dp[1].ostype)
272 return 0;
274 if (!ost_is_nondata(dp[1].ostype)) {
275 error("2nd EBR entry must be extended or empty.\n");
276 return -1;
279 end_ebr = dp[1].start_lba + dp[1].length;
281 if (!dp[1].start_lba ||
282 !dp[1].length ||
283 !sane(dp[1].start_lba, dp[1].length) ||
284 end_ebr > iter->sub.dos.bebr_size) {
286 error("Insane extended partition.\n");
287 return -1;
290 return 0;
293 /* Primary partition must be sane, meaning:
294 * - must have non-0 start and length
295 * - values must not wrap around 32bit
298 static int notsane_primary(const struct part_iter *iter)
300 const struct disk_dos_part_entry *dp;
301 dp = ((struct disk_dos_mbr *)iter->data)->table + iter->index0;
303 if (!dp->ostype)
304 return 0;
306 if (!dp->start_lba ||
307 !dp->length ||
308 !sane(dp->start_lba, dp->length) ||
309 dp->start_lba + dp->length > iter->di.lbacnt) {
310 error("Insane primary (MBR) partition.\n");
311 return -1;
314 return 0;
317 static int notsane_gpt(const struct part_iter *iter)
319 const struct disk_gpt_part_entry *gp;
320 gp = (const struct disk_gpt_part_entry *)
321 (iter->data + iter->index0 * iter->sub.gpt.pe_size);
323 if (guid_is0(&gp->type))
324 return 0;
326 if (gp->lba_first < iter->sub.gpt.ufirst ||
327 gp->lba_last > iter->sub.gpt.ulast) {
328 error("Insane GPT partition.\n");
329 return -1;
332 return 0;
335 static int pi_dos_next_mbr(struct part_iter *iter, uint32_t *lba,
336 struct disk_dos_part_entry **_dp)
338 struct disk_dos_part_entry *dp;
340 while (++iter->index0 < 4) {
341 dp = ((struct disk_dos_mbr *)iter->data)->table + iter->index0;
343 if (notsane_primary(iter)) {
344 iter->status = PI_INSANE;
345 goto bail;
348 if (ost_is_ext(dp->ostype)) {
349 if (iter->sub.dos.bebr_index0 >= 0) {
350 error("You have more than 1 extended partition.\n");
351 iter->status = PI_INSANE;
352 goto bail;
354 /* record base EBR index */
355 iter->sub.dos.bebr_index0 = iter->index0;
357 if (!ost_is_nondata(dp->ostype) || iter->stepall) {
358 *lba = dp->start_lba;
359 *_dp = dp;
360 break;
364 return 0;
365 bail:
366 return -1;
369 static int prep_base_ebr(struct part_iter *iter)
371 struct disk_dos_part_entry *dp;
373 if (iter->sub.dos.bebr_index0 < 0) /* if we don't have base extended partition at all */
374 return -1;
375 else if (!iter->sub.dos.bebr_start) { /* if not initialized yet */
376 dp = ((struct disk_dos_mbr *)iter->data)->table + iter->sub.dos.bebr_index0;
378 iter->sub.dos.bebr_start = dp->start_lba;
379 iter->sub.dos.bebr_size = dp->length;
381 iter->sub.dos.ebr_start = 0;
382 iter->sub.dos.ebr_size = iter->sub.dos.bebr_size;
384 iter->sub.dos.cebr_lba = 0;
385 iter->sub.dos.nebr_lba = iter->sub.dos.bebr_start;
387 iter->index0--;
389 return 0;
392 static int pi_dos_next_ebr(struct part_iter *iter, uint32_t *lba,
393 struct disk_dos_part_entry **_dp)
395 struct disk_dos_part_entry *dp;
397 if (prep_base_ebr(iter)) {
398 iter->status = PI_DONE;
399 return -1;
402 while (++iter->index0 < 1024 && iter->sub.dos.nebr_lba) {
403 free(iter->data);
404 if (!(iter->data =
405 disk_read_sectors(&iter->di, iter->sub.dos.nebr_lba, 1))) {
406 error("Couldn't load EBR.\n");
407 iter->status = PI_ERRLOAD;
408 return -1;
411 if (notsane_logical(iter) || notsane_extended(iter)) {
412 iter->status = PI_INSANE;
413 return -1;
416 dp = ((struct disk_dos_mbr *)iter->data)->table;
418 iter->sub.dos.cebr_lba = iter->sub.dos.nebr_lba;
420 /* setup next frame values */
421 if (dp[1].ostype) {
422 iter->sub.dos.ebr_start = dp[1].start_lba;
423 iter->sub.dos.ebr_size = dp[1].length;
424 iter->sub.dos.nebr_lba = iter->sub.dos.bebr_start + dp[1].start_lba;
425 } else {
426 iter->sub.dos.ebr_start = 0;
427 iter->sub.dos.ebr_size = 0;
428 iter->sub.dos.nebr_lba = 0;
431 if (!dp[0].ostype)
432 iter->sub.dos.skipcnt++;
434 if (dp[0].ostype || iter->stepall) {
435 *lba = iter->sub.dos.cebr_lba + dp[0].start_lba;
436 *_dp = dp;
437 return 0;
440 * This way it's possible to continue, if some crazy soft left a "hole"
441 * - EBR with a valid extended partition without a logical one. In
442 * such case, linux will not reserve a number for such hole - so we
443 * don't increase index0. If stepall flag is set, we will never reach
444 * this place.
447 iter->status = PI_DONE;
448 return -1;
451 static struct part_iter *pi_dos_next(struct part_iter *iter)
453 uint32_t start_lba = 0;
454 struct disk_dos_part_entry *dos_part = NULL;
456 if (iter->status)
457 goto bail;
459 /* look for primary partitions */
460 if (iter->index0 < 4 &&
461 pi_dos_next_mbr(iter, &start_lba, &dos_part))
462 goto bail;
464 /* look for logical partitions */
465 if (iter->index0 >= 4 &&
466 pi_dos_next_ebr(iter, &start_lba, &dos_part))
467 goto bail;
470 * note special index handling, if we have stepall set -
471 * this is made to keep index consistent with non-stepall
472 * iterators
475 if (iter->index0 >= 4 && !dos_part->ostype)
476 iter->index = -1;
477 else
478 iter->index = iter->index0 - iter->sub.dos.skipcnt + 1;
479 iter->rawindex = iter->index0 + 1;
480 iter->start_lba = start_lba;
481 iter->record = (char *)dos_part;
483 #ifdef DEBUG
484 disk_dos_part_dump(dos_part);
485 #endif
487 return iter;
488 bail:
489 return NULL;
492 static void gpt_conv_label(struct part_iter *iter)
494 const struct disk_gpt_part_entry *gp;
495 const int16_t *orig_lab;
497 gp = (const struct disk_gpt_part_entry *)
498 (iter->data + iter->index0 * iter->sub.gpt.pe_size);
499 orig_lab = (const int16_t *)gp->name;
501 /* caveat: this is very crude conversion */
502 for (int i = 0; i < PI_GPTLABSIZE/2; i++) {
503 iter->sub.gpt.part_label[i] = (char)orig_lab[i];
505 iter->sub.gpt.part_label[PI_GPTLABSIZE/2] = 0;
508 static struct part_iter *pi_gpt_next(struct part_iter *iter)
510 const struct disk_gpt_part_entry *gpt_part = NULL;
512 if (iter->status)
513 goto bail;
515 while (++iter->index0 < iter->sub.gpt.pe_count) {
516 gpt_part = (const struct disk_gpt_part_entry *)
517 (iter->data + iter->index0 * iter->sub.gpt.pe_size);
519 if (notsane_gpt(iter)) {
520 iter->status = PI_INSANE;
521 goto bail;
524 if (!guid_is0(&gpt_part->type) || iter->stepall)
525 break;
527 /* no more partitions ? */
528 if (iter->index0 == iter->sub.gpt.pe_count) {
529 iter->status = PI_DONE;
530 goto bail;
532 /* gpt_part is guaranteed to be valid here */
533 iter->index = iter->index0 + 1;
534 iter->rawindex = iter->index0 + 1;
535 iter->start_lba = gpt_part->lba_first;
536 iter->record = (char *)gpt_part;
537 memcpy(&iter->sub.gpt.part_guid, &gpt_part->uid, sizeof(struct guid));
538 gpt_conv_label(iter);
540 #ifdef DEBUG
541 disk_gpt_part_dump(gpt_part);
542 #endif
544 return iter;
545 bail:
546 return NULL;
549 static struct part_iter *pi_raw_next(struct part_iter *iter)
551 iter->status = PI_DONE;
552 return NULL;
555 static int check_crc(uint32_t crc_match, const uint8_t *buf, unsigned int siz)
557 uint32_t crc;
559 crc = crc32(0, NULL, 0);
560 crc = crc32(crc, buf, siz);
562 return crc_match != crc;
565 static int gpt_check_hdr_crc(const struct disk_info * const diskinfo, struct disk_gpt_header **_gh)
567 struct disk_gpt_header *gh = *_gh;
568 uint64_t lba_alt;
569 uint32_t hold_crc32;
571 hold_crc32 = gh->chksum;
572 gh->chksum = 0;
573 if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) {
574 error("WARNING: Primary GPT header checksum invalid.\n");
575 /* retry with backup */
576 lba_alt = gh->lba_alt;
577 free(gh);
578 if (!(gh = *_gh = disk_read_sectors(diskinfo, lba_alt, 1))) {
579 error("Couldn't read backup GPT header.\n");
580 return -1;
582 hold_crc32 = gh->chksum;
583 gh->chksum = 0;
584 if (check_crc(hold_crc32, (const uint8_t *)gh, gh->hdr_size)) {
585 error("Secondary GPT header checksum invalid.\n");
586 return -1;
589 /* restore old checksum */
590 gh->chksum = hold_crc32;
592 return 0;
596 * ----------------------------------------------------------------------------
597 * Following functions are for users to call.
598 * ----------------------------------------------------------------------------
602 int pi_next(struct part_iter **_iter)
604 struct part_iter *iter;
606 if(!_iter || !*_iter)
607 return 0;
608 iter = *_iter;
609 #ifdef DEBUG
610 if (inv_type(iter->type)) {
611 error("This is not a valid iterator.\n");
612 return 0;
614 #endif
615 if ((iter = iter->type->next(iter))) {
616 *_iter = iter;
618 return (*_iter)->status;
622 * pi_new() - get new iterator
623 * @itertype: iterator type
624 * @...: variable arguments passed to ctors
626 * Variable arguments depend on the type. Please see functions:
627 * iter_gpt_ctor() and iter_dos_ctor() for details.
629 struct part_iter *pi_new(const struct itertype *type, ...)
631 int badctor = 0;
632 struct part_iter *iter = NULL;
633 va_list ap;
635 va_start(ap, type);
637 #ifdef DEBUG
638 if (inv_type(type)) {
639 error("Unknown iterator requested.\n");
640 goto bail;
642 #endif
644 if (!(iter = malloc(sizeof(struct part_iter)))) {
645 error("Couldn't allocate memory for the iterator.\n");
646 goto bail;
649 memset(iter, 0, sizeof(struct part_iter));
650 iter->type = type;
652 if (type->ctor(iter, &ap)) {
653 badctor = -1;
654 error("Cannot initialize the iterator.\n");
655 goto bail;
658 bail:
659 va_end(ap);
660 if (badctor) {
661 free(iter);
662 iter = NULL;
664 return iter;
668 * pi_del() - delete iterator
669 * @iter: iterator double pointer
673 void pi_del(struct part_iter **_iter)
675 struct part_iter *iter;
677 if(!_iter || !*_iter)
678 return;
679 iter = *_iter;
681 #ifdef DEBUG
682 if (inv_type(iter->type)) {
683 error("This is not a valid iterator.\n");
684 return;
686 #endif
688 iter->type->dtor(iter);
689 free(iter);
690 *_iter = NULL;
694 * pi_begin() - check disk, validate, and get proper iterator
695 * @di: diskinfo struct pointer
697 * This function checks the disk for GPT or legacy partition table and allocates
698 * an appropriate iterator.
700 struct part_iter *pi_begin(const struct disk_info *di, int stepall)
702 int setraw = 0;
703 struct part_iter *iter = NULL;
704 struct disk_dos_mbr *mbr = NULL;
705 struct disk_gpt_header *gpth = NULL;
706 struct disk_gpt_part_entry *gptl = NULL;
708 /* Read MBR */
709 if (!(mbr = disk_read_sectors(di, 0, 1))) {
710 error("Couldn't read first disk sector.\n");
711 goto bail;
714 setraw = -1;
716 /* Check for MBR magic*/
717 if (mbr->sig != disk_mbr_sig_magic) {
718 error("No MBR magic.\n");
719 goto bail;
722 /* Check for GPT protective MBR */
723 if (mbr->table[0].ostype == 0xEE) {
724 if (!(gpth = disk_read_sectors(di, 1, 1))) {
725 error("Couldn't read potential GPT header.\n");
726 goto bail;
730 if (gpth && gpth->rev.uint32 == 0x00010000 &&
731 !memcmp(gpth->sig, disk_gpt_sig_magic, sizeof(disk_gpt_sig_magic))) {
732 /* looks like GPT v1.0 */
733 uint64_t gpt_loff; /* offset to GPT partition list in sectors */
734 uint64_t gpt_lsiz; /* size of GPT partition list in bytes */
735 uint64_t gpt_lcnt; /* size of GPT partition in sectors */
736 #ifdef DEBUG
737 puts("Looks like a GPT v1.0 disk.");
738 disk_gpt_header_dump(gpth);
739 #endif
740 /* Verify checksum, fallback to backup, then bail if invalid */
741 if (gpt_check_hdr_crc(di, &gpth))
742 goto bail;
744 gpt_loff = gpth->lba_table;
745 gpt_lsiz = (uint64_t)gpth->part_size * gpth->part_count;
746 gpt_lcnt = (gpt_lsiz + di->bps - 1) / di->bps;
749 * disk_read_sectors allows reading of max 255 sectors, so we use
750 * it as a sanity check base. EFI doesn't specify max (AFAIK).
751 * Apart from that, some extensive sanity checks.
753 if (!gpt_loff || !gpt_lsiz || gpt_lcnt > 255u ||
754 gpth->lba_first_usable > gpth->lba_last_usable ||
755 !sane(gpt_loff, gpt_lcnt) ||
756 gpt_loff + gpt_lcnt > gpth->lba_first_usable ||
757 !sane(gpth->lba_last_usable, gpt_lcnt) ||
758 gpth->lba_last_usable + gpt_lcnt >= gpth->lba_alt ||
759 gpth->lba_alt >= di->lbacnt ||
760 gpth->part_size < sizeof(struct disk_gpt_part_entry)) {
761 error("Invalid GPT header's values.\n");
762 goto bail;
764 if (!(gptl = disk_read_sectors(di, gpt_loff, (uint8_t)gpt_lcnt))) {
765 error("Couldn't read GPT partition list.\n");
766 goto bail;
768 /* Check array checksum(s). */
769 if (check_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) {
770 error("WARNING: GPT partition list checksum invalid, trying backup.\n");
771 free(gptl);
772 /* secondary array directly precedes secondary header */
773 if (!(gptl = disk_read_sectors(di, gpth->lba_alt - gpt_lcnt, (uint8_t)gpt_lcnt))) {
774 error("Couldn't read backup GPT partition list.\n");
775 goto bail;
777 if (check_crc(gpth->table_chksum, (const uint8_t *)gptl, (unsigned int)gpt_lsiz)) {
778 error("Backup GPT partition list checksum invalid.\n");
779 goto bail;
782 /* allocate iterator and exit */
783 iter = pi_new(typegpt, di, stepall, gpth, gptl);
784 } else {
785 /* looks like MBR */
786 iter = pi_new(typedos, di, stepall, mbr);
789 setraw = 0;
790 bail:
791 if (setraw) {
792 error("WARNING: treating disk as raw.\n");
793 iter = pi_new(typeraw, di, stepall);
795 free(mbr);
796 free(gpth);
797 free(gptl);
799 return iter;
802 /* vim: set ts=8 sts=4 sw=4 noet: */