• Home
  • Raw
  • Download

Lines Matching refs:iter

76 static void pi_dtor_(struct part_iter *iter)  in pi_dtor_()  argument
79 free(iter->data); in pi_dtor_()
83 static int pi_ctor(struct part_iter *iter, in pi_ctor() argument
87 memcpy(&iter->di, di, sizeof *di); in pi_ctor()
88 iter->flags = flags; in pi_ctor()
89 iter->index0 = -1; in pi_ctor()
90 iter->length = di->lbacnt; in pi_ctor()
92 iter->type = typeraw; in pi_ctor()
97 static int pi_dos_ctor(struct part_iter *iter, in pi_dos_ctor() argument
102 if (pi_ctor(iter, di, flags)) in pi_dos_ctor()
105 if (!(iter->data = malloc(sizeof *mbr))) { in pi_dos_ctor()
110 memcpy(iter->data, mbr, sizeof *mbr); in pi_dos_ctor()
112 iter->dos.bebr_index0 = -1; in pi_dos_ctor()
113 iter->dos.disk_sig = mbr->disk_sig; in pi_dos_ctor()
115 iter->type = typedos; in pi_dos_ctor()
118 pi_dtor_(iter); in pi_dos_ctor()
123 static int pi_gpt_ctor(struct part_iter *iter, in pi_gpt_ctor() argument
130 if (pi_ctor(iter, di, flags)) in pi_gpt_ctor()
135 if (!(iter->data = malloc((size_t)siz))) { in pi_gpt_ctor()
140 memcpy(iter->data, gptl, (size_t)siz); in pi_gpt_ctor()
142 iter->gpt.pe_count = (int)gpth->part_count; in pi_gpt_ctor()
143 iter->gpt.pe_size = (int)gpth->part_size; in pi_gpt_ctor()
144 iter->gpt.ufirst = gpth->lba_first_usable; in pi_gpt_ctor()
145 iter->gpt.ulast = gpth->lba_last_usable; in pi_gpt_ctor()
147 memcpy(&iter->gpt.disk_guid, &gpth->disk_guid, sizeof gpth->disk_guid); in pi_gpt_ctor()
148 memcpy(&iter->gpt.part_guid, &gpth->disk_guid, sizeof gpth->disk_guid); in pi_gpt_ctor()
150 iter->type = typegpt; in pi_gpt_ctor()
153 pi_dtor_(iter); in pi_gpt_ctor()
164 static int notsane_logical(const struct part_iter *iter) in notsane_logical() argument
169 dp = ((struct disk_dos_mbr *)iter->data)->table; in notsane_logical()
179 if (!(iter->flags & PIF_STRICT)) in notsane_logical()
187 end_log > iter->dos.nebr_siz) { in notsane_logical()
203 static int notsane_extended(const struct part_iter *iter) in notsane_extended() argument
208 dp = ((struct disk_dos_mbr *)iter->data)->table; in notsane_extended()
218 if (!(iter->flags & PIF_STRICT)) in notsane_extended()
226 end_ebr > iter->dos.bebr_siz) { in notsane_extended()
240 static int notsane_primary(const struct part_iter *iter) in notsane_primary() argument
243 dp = ((struct disk_dos_mbr *)iter->data)->table + iter->index0; in notsane_primary()
248 if (!(iter->flags & PIF_STRICT)) in notsane_primary()
254 ((iter->flags & PIF_STRICTER) && (dp->start_lba + dp->length > iter->di.lbacnt))) { in notsane_primary()
262 static int notsane_gpt(const struct part_iter *iter) in notsane_gpt() argument
266 (iter->data + iter->index0 * iter->gpt.pe_size); in notsane_gpt()
271 if (!(iter->flags & PIF_STRICT)) in notsane_gpt()
274 if (gp->lba_first < iter->gpt.ufirst || in notsane_gpt()
275 gp->lba_last > iter->gpt.ulast) { in notsane_gpt()
283 static int dos_next_mbr(struct part_iter *iter, uint32_t *lba, in dos_next_mbr() argument
288 while (++iter->index0 < 4) { in dos_next_mbr()
289 dp = ((struct disk_dos_mbr *)iter->data)->table + iter->index0; in dos_next_mbr()
291 if (notsane_primary(iter)) { in dos_next_mbr()
292 iter->status = PI_INSANE; in dos_next_mbr()
297 if (iter->dos.bebr_index0 >= 0) { in dos_next_mbr()
299 iter->status = PI_INSANE; in dos_next_mbr()
303 iter->dos.bebr_index0 = iter->index0; in dos_next_mbr()
305 if (!ost_is_nondata(dp->ostype) || (iter->flags & PIF_STEPALL)) { in dos_next_mbr()
315 static int prep_base_ebr(struct part_iter *iter) in prep_base_ebr() argument
319 if (iter->dos.bebr_index0 < 0) /* if we don't have base extended partition at all */ in prep_base_ebr()
321 else if (!iter->dos.bebr_lba) { /* if not initialized yet */ in prep_base_ebr()
322 dp = ((struct disk_dos_mbr *)iter->data)->table + iter->dos.bebr_index0; in prep_base_ebr()
324 iter->dos.bebr_lba = dp->start_lba; in prep_base_ebr()
325 iter->dos.bebr_siz = dp->length; in prep_base_ebr()
327 iter->dos.nebr_lba = dp->start_lba; in prep_base_ebr()
328 iter->dos.nebr_siz = dp->length; in prep_base_ebr()
330 iter->index0--; in prep_base_ebr()
335 static int dos_next_ebr(struct part_iter *iter, uint32_t *lba, in dos_next_ebr() argument
340 if (prep_base_ebr(iter) < 0) { in dos_next_ebr()
341 iter->status = PI_DONE; in dos_next_ebr()
345 while (++iter->index0 < 1024 && iter->dos.nebr_lba) { in dos_next_ebr()
346 free(iter->data); in dos_next_ebr()
347 if (!(iter->data = in dos_next_ebr()
348 disk_read_sectors(&iter->di, iter->dos.nebr_lba, 1))) { in dos_next_ebr()
350 iter->status = PI_ERRLOAD; in dos_next_ebr()
355 if (notsane_logical(iter) || notsane_extended(iter)) { in dos_next_ebr()
356 iter->status = PI_INSANE; in dos_next_ebr()
360 dp = ((struct disk_dos_mbr *)iter->data)->table; in dos_next_ebr()
362 iter->dos.cebr_lba = iter->dos.nebr_lba; in dos_next_ebr()
363 iter->dos.cebr_siz = iter->dos.nebr_siz; in dos_next_ebr()
367 iter->dos.nebr_lba = iter->dos.bebr_lba + dp[1].start_lba; in dos_next_ebr()
368 iter->dos.nebr_siz = dp[1].length; in dos_next_ebr()
370 iter->dos.nebr_lba = 0; in dos_next_ebr()
371 iter->dos.nebr_siz = 0; in dos_next_ebr()
375 iter->dos.logskipcnt++; in dos_next_ebr()
377 if (dp[0].ostype || (iter->flags & PIF_STEPALL)) { in dos_next_ebr()
378 *lba = dp[0].start_lba ? iter->dos.cebr_lba + dp[0].start_lba : 0; in dos_next_ebr()
390 iter->status = PI_DONE; in dos_next_ebr()
394 static void gpt_conv_label(struct part_iter *iter) in gpt_conv_label() argument
400 (iter->data + iter->index0 * iter->gpt.pe_size); in gpt_conv_label()
405 iter->gpt.part_label[i] = (char)orig_lab[i]; in gpt_conv_label()
407 iter->gpt.part_label[PI_GPTLABSIZE/2] = 0; in gpt_conv_label()
427 static int pi_next_(struct part_iter *iter) in pi_next_() argument
429 iter->status = PI_DONE; in pi_next_()
430 return iter->status; in pi_next_()
433 static int pi_dos_next(struct part_iter *iter) in pi_dos_next() argument
438 if (iter->status) in pi_dos_next()
439 return iter->status; in pi_dos_next()
442 if (iter->index0 < 4 && in pi_dos_next()
443 dos_next_mbr(iter, &abs_lba, &dos_part) < 0) in pi_dos_next()
444 return iter->status; in pi_dos_next()
447 if (iter->index0 >= 4 && in pi_dos_next()
448 dos_next_ebr(iter, &abs_lba, &dos_part) < 0) in pi_dos_next()
449 return iter->status; in pi_dos_next()
458 iter->index = -1; in pi_dos_next()
460 iter->index = iter->index0 + 1 - iter->dos.logskipcnt; in pi_dos_next()
461 iter->abs_lba = abs_lba; in pi_dos_next()
462 iter->length = dos_part->length; in pi_dos_next()
463 iter->record = (char *)dos_part; in pi_dos_next()
469 return iter->status; in pi_dos_next()
472 static int pi_gpt_next(struct part_iter *iter) in pi_gpt_next() argument
476 if (iter->status) in pi_gpt_next()
477 return iter->status; in pi_gpt_next()
479 while (++iter->index0 < iter->gpt.pe_count) { in pi_gpt_next()
481 (iter->data + iter->index0 * iter->gpt.pe_size); in pi_gpt_next()
483 if (notsane_gpt(iter)) { in pi_gpt_next()
484 iter->status = PI_INSANE; in pi_gpt_next()
485 return iter->status; in pi_gpt_next()
488 if (!guid_is0(&gpt_part->type) || (iter->flags & PIF_STEPALL)) in pi_gpt_next()
492 if (iter->index0 == iter->gpt.pe_count) { in pi_gpt_next()
493 iter->status = PI_DONE; in pi_gpt_next()
494 return iter->status; in pi_gpt_next()
497 iter->index = iter->index0 + 1; in pi_gpt_next()
498 iter->abs_lba = gpt_part->lba_first; in pi_gpt_next()
499 iter->length = gpt_part->lba_last - gpt_part->lba_first + 1; in pi_gpt_next()
500 iter->record = (char *)gpt_part; in pi_gpt_next()
501 memcpy(&iter->gpt.part_guid, &gpt_part->uid, sizeof(struct guid)); in pi_gpt_next()
502 gpt_conv_label(iter); in pi_gpt_next()
508 return iter->status; in pi_gpt_next()
513 struct part_iter *iter; in pi_alloc() local
514 if (!(iter = malloc(sizeof *iter))) in pi_alloc()
517 memset(iter, 0, sizeof *iter); in pi_alloc()
518 return iter; in pi_alloc()
637 struct part_iter *iter; in pi_begin() local
643 if (!(iter = pi_alloc())) in pi_begin()
656 ret = pi_ctor(iter, di, flags); in pi_begin()
697 ret = pi_gpt_ctor(iter, di, flags, gpth, gptl); in pi_begin()
700 ret = pi_dos_ctor(iter, di, flags, mbr); in pi_begin()
704 free(iter); in pi_begin()
705 iter = NULL; in pi_begin()
711 return iter; in pi_begin()