Lines Matching refs:ubi
64 static void self_vtbl_check(const struct ubi_device *ubi);
80 int ubi_change_vtbl_record(struct ubi_device *ubi, int idx, in ubi_change_vtbl_record() argument
87 ubi_assert(idx >= 0 && idx < ubi->vtbl_slots); in ubi_change_vtbl_record()
88 layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)]; in ubi_change_vtbl_record()
97 memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record)); in ubi_change_vtbl_record()
99 err = ubi_eba_unmap_leb(ubi, layout_vol, i); in ubi_change_vtbl_record()
103 err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0, in ubi_change_vtbl_record()
104 ubi->vtbl_size); in ubi_change_vtbl_record()
109 self_vtbl_check(ubi); in ubi_change_vtbl_record()
122 int ubi_vtbl_rename_volumes(struct ubi_device *ubi, in ubi_vtbl_rename_volumes() argument
132 struct ubi_vtbl_record *vtbl_rec = &ubi->vtbl[vol->vol_id]; in ubi_vtbl_rename_volumes()
149 layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)]; in ubi_vtbl_rename_volumes()
151 err = ubi_eba_unmap_leb(ubi, layout_vol, i); in ubi_vtbl_rename_volumes()
155 err = ubi_eba_write_leb(ubi, layout_vol, i, ubi->vtbl, 0, in ubi_vtbl_rename_volumes()
156 ubi->vtbl_size); in ubi_vtbl_rename_volumes()
172 static int vtbl_check(const struct ubi_device *ubi, in vtbl_check() argument
180 for (i = 0; i < ubi->vtbl_slots; i++) { in vtbl_check()
214 if (alignment > ubi->leb_size || alignment == 0) { in vtbl_check()
219 n = alignment & (ubi->min_io_size - 1); in vtbl_check()
225 n = ubi->leb_size % alignment; in vtbl_check()
242 if (reserved_pebs > ubi->good_peb_count) { in vtbl_check()
244 reserved_pebs, ubi->good_peb_count); in vtbl_check()
266 for (i = 0; i < ubi->vtbl_slots - 1; i++) { in vtbl_check()
267 for (n = i + 1; n < ubi->vtbl_slots; n++) { in vtbl_check()
300 static int create_vtbl(struct ubi_device *ubi, struct ubi_attach_info *ai, in create_vtbl() argument
309 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL); in create_vtbl()
314 new_aeb = ubi_early_get_peb(ubi, ai); in create_vtbl()
329 err = ubi_io_write_vid_hdr(ubi, new_aeb->pnum, vid_hdr); in create_vtbl()
334 err = ubi_io_write_data(ubi, vtbl, new_aeb->pnum, 0, ubi->vtbl_size); in create_vtbl()
342 err = ubi_add_to_av(ubi, ai, new_aeb->pnum, new_aeb->ec, vid_hdr, 0); in create_vtbl()
344 ubi_free_vid_hdr(ubi, vid_hdr); in create_vtbl()
358 ubi_free_vid_hdr(ubi, vid_hdr); in create_vtbl()
373 static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi, in process_lvol() argument
412 leb[aeb->lnum] = vzalloc(ubi->vtbl_size); in process_lvol()
418 err = ubi_io_read_data(ubi, leb[aeb->lnum], aeb->pnum, 0, in process_lvol()
419 ubi->vtbl_size); in process_lvol()
438 leb_corrupted[0] = vtbl_check(ubi, leb[0]); in process_lvol()
447 ubi->vtbl_size); in process_lvol()
450 err = create_vtbl(ubi, ai, 1, leb[0]); in process_lvol()
462 leb_corrupted[1] = vtbl_check(ubi, leb[1]); in process_lvol()
473 err = create_vtbl(ubi, ai, 0, leb[1]); in process_lvol()
496 static struct ubi_vtbl_record *create_empty_lvol(struct ubi_device *ubi, in create_empty_lvol() argument
502 vtbl = vzalloc(ubi->vtbl_size); in create_empty_lvol()
506 for (i = 0; i < ubi->vtbl_slots; i++) in create_empty_lvol()
512 err = create_vtbl(ubi, ai, i, vtbl); in create_empty_lvol()
532 static int init_volumes(struct ubi_device *ubi, in init_volumes() argument
540 for (i = 0; i < ubi->vtbl_slots; i++) { in init_volumes()
557 vol->usable_leb_size = ubi->leb_size - vol->data_pad; in init_volumes()
564 if (ubi->autoresize_vol_id != -1) { in init_volumes()
566 ubi->autoresize_vol_id, i); in init_volumes()
571 ubi->autoresize_vol_id = i; in init_volumes()
574 ubi_assert(!ubi->volumes[i]); in init_volumes()
575 ubi->volumes[i] = vol; in init_volumes()
576 ubi->vol_count += 1; in init_volumes()
577 vol->ubi = ubi; in init_volumes()
634 vol->usable_leb_size = ubi->leb_size; in init_volumes()
638 (long long)vol->used_ebs * (ubi->leb_size - vol->data_pad); in init_volumes()
642 ubi_assert(!ubi->volumes[i]); in init_volumes()
643 ubi->volumes[vol_id2idx(ubi, vol->vol_id)] = vol; in init_volumes()
645 ubi->vol_count += 1; in init_volumes()
646 vol->ubi = ubi; in init_volumes()
648 if (reserved_pebs > ubi->avail_pebs) { in init_volumes()
650 reserved_pebs, ubi->avail_pebs); in init_volumes()
651 if (ubi->corr_peb_count) in init_volumes()
653 ubi->corr_peb_count); in init_volumes()
655 ubi->rsvd_pebs += reserved_pebs; in init_volumes()
656 ubi->avail_pebs -= reserved_pebs; in init_volumes()
713 static int check_attaching_info(const struct ubi_device *ubi, in check_attaching_info() argument
720 if (ai->vols_found > UBI_INT_VOL_COUNT + ubi->vtbl_slots) { in check_attaching_info()
722 ai->vols_found, UBI_INT_VOL_COUNT, ubi->vtbl_slots); in check_attaching_info()
726 if (ai->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT && 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()
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()
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()