Lines Matching refs:ubi
60 static void self_vtbl_check(const struct ubi_device *ubi);
69 static int ubi_update_layout_vol(struct ubi_device *ubi) in ubi_update_layout_vol() argument
74 layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)]; in ubi_update_layout_vol()
76 err = ubi_eba_atomic_leb_change(ubi, layout_vol, i, ubi->vtbl, in ubi_update_layout_vol()
77 ubi->vtbl_size); in ubi_update_layout_vol()
96 int ubi_change_vtbl_record(struct ubi_device *ubi, int idx, in ubi_change_vtbl_record() argument
102 ubi_assert(idx >= 0 && idx < ubi->vtbl_slots); in ubi_change_vtbl_record()
111 memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record)); in ubi_change_vtbl_record()
112 err = ubi_update_layout_vol(ubi); in ubi_change_vtbl_record()
114 self_vtbl_check(ubi); in ubi_change_vtbl_record()
127 int ubi_vtbl_rename_volumes(struct ubi_device *ubi, in ubi_vtbl_rename_volumes() argument
135 struct ubi_vtbl_record *vtbl_rec = &ubi->vtbl[vol->vol_id]; in ubi_vtbl_rename_volumes()
152 return ubi_update_layout_vol(ubi); in ubi_vtbl_rename_volumes()
163 static int vtbl_check(const struct ubi_device *ubi, argument
171 for (i = 0; i < ubi->vtbl_slots; i++) {
184 ubi_err(ubi, "bad CRC at record %u: %#08x, not %#08x",
205 if (alignment > ubi->leb_size || alignment == 0) {
210 n = alignment & (ubi->min_io_size - 1);
216 n = ubi->leb_size % alignment;
218 ubi_err(ubi, "bad data_pad, has to be %d", n);
233 if (reserved_pebs > ubi->good_peb_count) {
234 ubi_err(ubi, "too large reserved_pebs %d, good PEBs %d",
235 reserved_pebs, ubi->good_peb_count);
257 for (i = 0; i < ubi->vtbl_slots - 1; i++) {
258 for (n = i + 1; n < ubi->vtbl_slots; n++) {
268 ubi_err(ubi, "volumes %d and %d have the same name \"%s\"",
280 ubi_err(ubi, "volume table check failed: record %d, error %d", i, err);
295 static int create_vtbl(struct ubi_device *ubi, struct ubi_attach_info *ai, argument
304 vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL);
309 new_aeb = ubi_early_get_peb(ubi, ai);
324 err = ubi_io_write_vid_hdr(ubi, new_aeb->pnum, vid_hdr);
329 err = ubi_io_write_data(ubi, vtbl, new_aeb->pnum, 0, ubi->vtbl_size);
337 err = ubi_add_to_av(ubi, ai, new_aeb->pnum, new_aeb->ec, vid_hdr, 0);
339 ubi_free_vid_hdr(ubi, vid_hdr);
353 ubi_free_vid_hdr(ubi, vid_hdr);
368 static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi, argument
407 leb[aeb->lnum] = vzalloc(ubi->vtbl_size);
413 err = ubi_io_read_data(ubi, leb[aeb->lnum], aeb->pnum, 0,
414 ubi->vtbl_size);
433 leb_corrupted[0] = vtbl_check(ubi, leb[0]);
442 ubi->vtbl_size);
444 ubi_warn(ubi, "volume table copy #2 is corrupted");
445 err = create_vtbl(ubi, ai, 1, leb[0]);
448 ubi_msg(ubi, "volume table was restored");
457 leb_corrupted[1] = vtbl_check(ubi, leb[1]);
463 ubi_err(ubi, "both volume tables are corrupted");
467 ubi_warn(ubi, "volume table copy #1 is corrupted");
468 err = create_vtbl(ubi, ai, 0, leb[1]);
471 ubi_msg(ubi, "volume table was restored");
491 static struct ubi_vtbl_record *create_empty_lvol(struct ubi_device *ubi, argument
497 vtbl = vzalloc(ubi->vtbl_size);
501 for (i = 0; i < ubi->vtbl_slots; i++)
507 err = create_vtbl(ubi, ai, i, vtbl);
527 static int init_volumes(struct ubi_device *ubi, argument
535 for (i = 0; i < ubi->vtbl_slots; i++) {
552 vol->usable_leb_size = ubi->leb_size - vol->data_pad;
559 if (ubi->autoresize_vol_id != -1) {
560 ubi_err(ubi, "more than one auto-resize volume (%d and %d)",
561 ubi->autoresize_vol_id, i);
566 ubi->autoresize_vol_id = i;
569 ubi_assert(!ubi->volumes[i]);
570 ubi->volumes[i] = vol;
571 ubi->vol_count += 1;
572 vol->ubi = ubi;
606 ubi_warn(ubi, "static volume %d misses %d LEBs - corrupted",
629 vol->usable_leb_size = ubi->leb_size;
633 (long long)vol->used_ebs * (ubi->leb_size - vol->data_pad);
637 ubi_assert(!ubi->volumes[i]);
638 ubi->volumes[vol_id2idx(ubi, vol->vol_id)] = vol;
640 ubi->vol_count += 1;
641 vol->ubi = ubi;
643 if (reserved_pebs > ubi->avail_pebs) {
644 ubi_err(ubi, "not enough PEBs, required %d, available %d",
645 reserved_pebs, ubi->avail_pebs);
646 if (ubi->corr_peb_count)
647 ubi_err(ubi, "%d PEBs are corrupted and not used",
648 ubi->corr_peb_count);
650 ubi->rsvd_pebs += reserved_pebs;
651 ubi->avail_pebs -= reserved_pebs;
692 ubi_err(vol->ubi, "bad attaching information, error %d", err);
708 static int check_attaching_info(const struct ubi_device *ubi, argument
715 if (ai->vols_found > UBI_INT_VOL_COUNT + ubi->vtbl_slots) {
716 ubi_err(ubi, "found %d volumes while attaching, maximum is %d + %d",
717 ai->vols_found, UBI_INT_VOL_COUNT, ubi->vtbl_slots);
721 if (ai->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT &&
723 ubi_err(ubi, "too large volume ID %d found",
728 for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
732 vol = ubi->volumes[i];
740 ubi_assert(i < ubi->vtbl_slots);
752 ubi_msg(ubi, "finish volume %d removal", av->vol_id);
773 int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_attach_info *ai) argument
784 ubi->vtbl_slots = ubi->leb_size / UBI_VTBL_RECORD_SIZE;
785 if (ubi->vtbl_slots > UBI_MAX_VOLUMES)
786 ubi->vtbl_slots = UBI_MAX_VOLUMES;
788 ubi->vtbl_size = ubi->vtbl_slots * UBI_VTBL_RECORD_SIZE;
789 ubi->vtbl_size = ALIGN(ubi->vtbl_size, ubi->min_io_size);
802 ubi->vtbl = create_empty_lvol(ubi, ai);
803 if (IS_ERR(ubi->vtbl))
804 return PTR_ERR(ubi->vtbl);
806 ubi_err(ubi, "the layout volume was not found");
812 ubi_err(ubi, "too many LEBs (%d) in layout volume",
817 ubi->vtbl = process_lvol(ubi, ai, av);
818 if (IS_ERR(ubi->vtbl))
819 return PTR_ERR(ubi->vtbl);
822 ubi->avail_pebs = ubi->good_peb_count - ubi->corr_peb_count;
828 err = init_volumes(ubi, ai, ubi->vtbl);
836 err = check_attaching_info(ubi, ai);
843 vfree(ubi->vtbl);
844 for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
845 kfree(ubi->volumes[i]);
846 ubi->volumes[i] = NULL;
855 static void self_vtbl_check(const struct ubi_device *ubi) argument
857 if (!ubi_dbg_chk_gen(ubi))
860 if (vtbl_check(ubi, ubi->vtbl)) {
861 ubi_err(ubi, "self-check failed");