Lines Matching refs:ubi
67 static void self_vtbl_check(const struct ubi_device *ubi);
76 static int ubi_update_layout_vol(struct ubi_device *ubi) in ubi_update_layout_vol() argument
81 layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)]; in ubi_update_layout_vol()
83 err = ubi_eba_atomic_leb_change(ubi, layout_vol, i, ubi->vtbl, in ubi_update_layout_vol()
84 ubi->vtbl_size); in ubi_update_layout_vol()
103 int ubi_change_vtbl_record(struct ubi_device *ubi, int idx, in ubi_change_vtbl_record() argument
109 ubi_assert(idx >= 0 && idx < ubi->vtbl_slots); in ubi_change_vtbl_record()
118 memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record)); in ubi_change_vtbl_record()
119 err = ubi_update_layout_vol(ubi); in ubi_change_vtbl_record()
121 self_vtbl_check(ubi); in ubi_change_vtbl_record()
134 int ubi_vtbl_rename_volumes(struct ubi_device *ubi, in ubi_vtbl_rename_volumes() argument
142 struct ubi_vtbl_record *vtbl_rec = &ubi->vtbl[vol->vol_id]; in ubi_vtbl_rename_volumes()
159 return ubi_update_layout_vol(ubi); in ubi_vtbl_rename_volumes()
170 static int vtbl_check(const struct ubi_device *ubi, in vtbl_check() argument
178 for (i = 0; i < ubi->vtbl_slots; i++) { in vtbl_check()
191 ubi_err(ubi, "bad CRC at record %u: %#08x, not %#08x", in vtbl_check()
212 if (alignment > ubi->leb_size || alignment == 0) { in vtbl_check()
217 n = alignment & (ubi->min_io_size - 1); in vtbl_check()
223 n = ubi->leb_size % alignment; in vtbl_check()
225 ubi_err(ubi, "bad data_pad, has to be %d", n); in vtbl_check()
240 if (reserved_pebs > ubi->good_peb_count) { in vtbl_check()
241 ubi_err(ubi, "too large reserved_pebs %d, good PEBs %d", in vtbl_check()
242 reserved_pebs, ubi->good_peb_count); in vtbl_check()
264 for (i = 0; i < ubi->vtbl_slots - 1; i++) { in vtbl_check()
265 for (n = i + 1; n < ubi->vtbl_slots; n++) { in vtbl_check()
271 ubi_err(ubi, "volumes %d and %d have the same name \"%s\"", in vtbl_check()
283 ubi_err(ubi, "volume table check failed: record %d, error %d", i, err); in vtbl_check()
298 static int create_vtbl(struct ubi_device *ubi, struct ubi_attach_info *ai, in create_vtbl() argument
307 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL); in create_vtbl()
312 new_aeb = ubi_early_get_peb(ubi, ai); in create_vtbl()
327 err = ubi_io_write_vid_hdr(ubi, new_aeb->pnum, vid_hdr); in create_vtbl()
332 err = ubi_io_write_data(ubi, vtbl, new_aeb->pnum, 0, ubi->vtbl_size); in create_vtbl()
340 err = ubi_add_to_av(ubi, ai, new_aeb->pnum, new_aeb->ec, vid_hdr, 0); in create_vtbl()
342 ubi_free_vid_hdr(ubi, vid_hdr); in create_vtbl()
356 ubi_free_vid_hdr(ubi, vid_hdr); in create_vtbl()
371 static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi, in process_lvol() argument
410 leb[aeb->lnum] = vzalloc(ubi->vtbl_size); in process_lvol()
416 err = ubi_io_read_data(ubi, leb[aeb->lnum], aeb->pnum, 0, in process_lvol()
417 ubi->vtbl_size); in process_lvol()
436 leb_corrupted[0] = vtbl_check(ubi, leb[0]); in process_lvol()
445 ubi->vtbl_size); in process_lvol()
447 ubi_warn(ubi, "volume table copy #2 is corrupted"); in process_lvol()
448 err = create_vtbl(ubi, ai, 1, leb[0]); in process_lvol()
451 ubi_msg(ubi, "volume table was restored"); in process_lvol()
460 leb_corrupted[1] = vtbl_check(ubi, leb[1]); in process_lvol()
466 ubi_err(ubi, "both volume tables are corrupted"); in process_lvol()
470 ubi_warn(ubi, "volume table copy #1 is corrupted"); in process_lvol()
471 err = create_vtbl(ubi, ai, 0, leb[1]); in process_lvol()
474 ubi_msg(ubi, "volume table was restored"); in process_lvol()
494 static struct ubi_vtbl_record *create_empty_lvol(struct ubi_device *ubi, in create_empty_lvol() argument
500 vtbl = vzalloc(ubi->vtbl_size); in create_empty_lvol()
504 for (i = 0; i < ubi->vtbl_slots; i++) in create_empty_lvol()
510 err = create_vtbl(ubi, ai, i, vtbl); in create_empty_lvol()
530 static int init_volumes(struct ubi_device *ubi, in init_volumes() argument
538 for (i = 0; i < ubi->vtbl_slots; i++) { in init_volumes()
555 vol->usable_leb_size = ubi->leb_size - vol->data_pad; in init_volumes()
562 if (ubi->autoresize_vol_id != -1) { in init_volumes()
563 ubi_err(ubi, "more than one auto-resize volume (%d and %d)", in init_volumes()
564 ubi->autoresize_vol_id, i); in init_volumes()
569 ubi->autoresize_vol_id = i; in init_volumes()
572 ubi_assert(!ubi->volumes[i]); in init_volumes()
573 ubi->volumes[i] = vol; in init_volumes()
574 ubi->vol_count += 1; in init_volumes()
575 vol->ubi = ubi; in init_volumes()
609 ubi_warn(ubi, "static volume %d misses %d LEBs - corrupted", in init_volumes()
632 vol->usable_leb_size = ubi->leb_size; in init_volumes()
636 (long long)vol->used_ebs * (ubi->leb_size - vol->data_pad); in init_volumes()
640 ubi_assert(!ubi->volumes[i]); in init_volumes()
641 ubi->volumes[vol_id2idx(ubi, vol->vol_id)] = vol; in init_volumes()
643 ubi->vol_count += 1; in init_volumes()
644 vol->ubi = ubi; in init_volumes()
646 if (reserved_pebs > ubi->avail_pebs) { in init_volumes()
647 ubi_err(ubi, "not enough PEBs, required %d, available %d", in init_volumes()
648 reserved_pebs, ubi->avail_pebs); in init_volumes()
649 if (ubi->corr_peb_count) in init_volumes()
650 ubi_err(ubi, "%d PEBs are corrupted and not used", in init_volumes()
651 ubi->corr_peb_count); in init_volumes()
654 ubi->rsvd_pebs += reserved_pebs; in init_volumes()
655 ubi->avail_pebs -= reserved_pebs; in init_volumes()
696 ubi_err(vol->ubi, "bad attaching information, error %d", err); in check_av()
712 static int check_attaching_info(const struct ubi_device *ubi, in check_attaching_info() argument
719 if (ai->vols_found > UBI_INT_VOL_COUNT + ubi->vtbl_slots) { in check_attaching_info()
720 ubi_err(ubi, "found %d volumes while attaching, maximum is %d + %d", in check_attaching_info()
721 ai->vols_found, UBI_INT_VOL_COUNT, ubi->vtbl_slots); in check_attaching_info()
725 if (ai->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT && in check_attaching_info()
727 ubi_err(ubi, "too large volume ID %d found", in check_attaching_info()
732 for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) { in check_attaching_info()
736 vol = ubi->volumes[i]; in check_attaching_info()
744 ubi_assert(i < ubi->vtbl_slots); in check_attaching_info()
756 ubi_msg(ubi, "finish volume %d removal", av->vol_id); in check_attaching_info()
777 int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_attach_info *ai) in ubi_read_volume_table() argument
788 ubi->vtbl_slots = ubi->leb_size / UBI_VTBL_RECORD_SIZE; in ubi_read_volume_table()
789 if (ubi->vtbl_slots > UBI_MAX_VOLUMES) in ubi_read_volume_table()
790 ubi->vtbl_slots = UBI_MAX_VOLUMES; in ubi_read_volume_table()
792 ubi->vtbl_size = ubi->vtbl_slots * UBI_VTBL_RECORD_SIZE; in ubi_read_volume_table()
793 ubi->vtbl_size = ALIGN(ubi->vtbl_size, ubi->min_io_size); in ubi_read_volume_table()
806 ubi->vtbl = create_empty_lvol(ubi, ai); in ubi_read_volume_table()
807 if (IS_ERR(ubi->vtbl)) in ubi_read_volume_table()
808 return PTR_ERR(ubi->vtbl); in ubi_read_volume_table()
810 ubi_err(ubi, "the layout volume was not found"); in ubi_read_volume_table()
816 ubi_err(ubi, "too many LEBs (%d) in layout volume", in ubi_read_volume_table()
821 ubi->vtbl = process_lvol(ubi, ai, av); in ubi_read_volume_table()
822 if (IS_ERR(ubi->vtbl)) in ubi_read_volume_table()
823 return PTR_ERR(ubi->vtbl); in ubi_read_volume_table()
826 ubi->avail_pebs = ubi->good_peb_count - ubi->corr_peb_count; in ubi_read_volume_table()
832 err = init_volumes(ubi, ai, ubi->vtbl); in ubi_read_volume_table()
840 err = check_attaching_info(ubi, ai); in ubi_read_volume_table()
847 vfree(ubi->vtbl); in ubi_read_volume_table()
848 for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) { in ubi_read_volume_table()
849 kfree(ubi->volumes[i]); in ubi_read_volume_table()
850 ubi->volumes[i] = NULL; in ubi_read_volume_table()
859 static void self_vtbl_check(const struct ubi_device *ubi) in self_vtbl_check() argument
861 if (!ubi_dbg_chk_gen(ubi)) in self_vtbl_check()
864 if (vtbl_check(ubi, ubi->vtbl)) { in self_vtbl_check()
865 ubi_err(ubi, "self-check failed"); in self_vtbl_check()