Lines Matching defs:ubi

52 #include "ubi.h"
54 static void self_vtbl_check(const struct ubi_device *ubi);
61 * @ubi: UBI device description object
63 static int ubi_update_layout_vol(struct ubi_device *ubi)
68 layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)];
70 err = ubi_eba_atomic_leb_change(ubi, layout_vol, i, ubi->vtbl,
71 ubi->vtbl_size);
81 * @ubi: UBI device description object
90 int ubi_change_vtbl_record(struct ubi_device *ubi, int idx,
96 ubi_assert(idx >= 0 && idx < ubi->vtbl_slots);
105 memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record));
106 err = ubi_update_layout_vol(ubi);
108 self_vtbl_check(ubi);
114 * @ubi: UBI device description object
121 int ubi_vtbl_rename_volumes(struct ubi_device *ubi,
129 struct ubi_vtbl_record *vtbl_rec = &ubi->vtbl[vol->vol_id];
146 return ubi_update_layout_vol(ubi);
151 * @ubi: UBI device description object
157 static int vtbl_check(const struct ubi_device *ubi,
165 for (i = 0; i < ubi->vtbl_slots; i++) {
178 ubi_err(ubi, "bad CRC at record %u: %#08x, not %#08x",
199 if (alignment > ubi->leb_size || alignment == 0) {
204 n = alignment & (ubi->min_io_size - 1);
210 n = ubi->leb_size % alignment;
212 ubi_err(ubi, "bad data_pad, has to be %d", n);
227 if (reserved_pebs > ubi->good_peb_count) {
228 ubi_err(ubi, "too large reserved_pebs %d, good PEBs %d",
229 reserved_pebs, ubi->good_peb_count);
251 for (i = 0; i < ubi->vtbl_slots - 1; i++) {
252 for (n = i + 1; n < ubi->vtbl_slots; n++) {
258 ubi_err(ubi, "volumes %d and %d have the same name \"%s\"",
270 ubi_err(ubi, "volume table check failed: record %d, error %d", i, err);
277 * @ubi: UBI device description object
285 static int create_vtbl(struct ubi_device *ubi, struct ubi_attach_info *ai,
295 vidb = ubi_alloc_vid_buf(ubi, GFP_KERNEL);
302 new_aeb = ubi_early_get_peb(ubi, ai);
317 err = ubi_io_write_vid_hdr(ubi, new_aeb->pnum, vidb);
322 err = ubi_io_write_data(ubi, vtbl, new_aeb->pnum, 0, ubi->vtbl_size);
330 err = ubi_add_to_av(ubi, ai, new_aeb->pnum, new_aeb->ec, vid_hdr, 0);
353 * @ubi: UBI device description object
361 static struct ubi_vtbl_record *process_lvol(struct ubi_device *ubi,
400 leb[aeb->lnum] = vzalloc(ubi->vtbl_size);
406 err = ubi_io_read_data(ubi, leb[aeb->lnum], aeb->pnum, 0,
407 ubi->vtbl_size);
426 leb_corrupted[0] = vtbl_check(ubi, leb[0]);
435 ubi->vtbl_size);
437 ubi_warn(ubi, "volume table copy #2 is corrupted");
438 err = create_vtbl(ubi, ai, 1, leb[0]);
441 ubi_msg(ubi, "volume table was restored");
450 leb_corrupted[1] = vtbl_check(ubi, leb[1]);
456 ubi_err(ubi, "both volume tables are corrupted");
460 ubi_warn(ubi, "volume table copy #1 is corrupted");
461 err = create_vtbl(ubi, ai, 0, leb[1]);
464 ubi_msg(ubi, "volume table was restored");
478 * @ubi: UBI device description object
484 static struct ubi_vtbl_record *create_empty_lvol(struct ubi_device *ubi,
490 vtbl = vzalloc(ubi->vtbl_size);
494 for (i = 0; i < ubi->vtbl_slots; i++)
500 err = create_vtbl(ubi, ai, i, vtbl);
512 * @ubi: UBI device description object
520 static int init_volumes(struct ubi_device *ubi,
528 for (i = 0; i < ubi->vtbl_slots; i++) {
545 vol->usable_leb_size = ubi->leb_size - vol->data_pad;
555 if (ubi->autoresize_vol_id != -1) {
556 ubi_err(ubi, "more than one auto-resize volume (%d and %d)",
557 ubi->autoresize_vol_id, i);
562 ubi->autoresize_vol_id = i;
565 ubi_assert(!ubi->volumes[i]);
566 ubi->volumes[i] = vol;
567 ubi->vol_count += 1;
568 vol->ubi = ubi;
572 * We use ubi->peb_count and not vol->reserved_pebs because
577 err = ubi_fastmap_init_checkmap(vol, ubi->peb_count);
612 ubi_warn(ubi, "static volume %d misses %d LEBs - corrupted",
635 vol->usable_leb_size = ubi->leb_size;
639 (long long)vol->used_ebs * (ubi->leb_size - vol->data_pad);
643 ubi_assert(!ubi->volumes[i]);
644 ubi->volumes[vol_id2idx(ubi, vol->vol_id)] = vol;
646 ubi->vol_count += 1;
647 vol->ubi = ubi;
652 if (reserved_pebs > ubi->avail_pebs) {
653 ubi_err(ubi, "not enough PEBs, required %d, available %d",
654 reserved_pebs, ubi->avail_pebs);
655 if (ubi->corr_peb_count)
656 ubi_err(ubi, "%d PEBs are corrupted and not used",
657 ubi->corr_peb_count);
660 ubi->rsvd_pebs += reserved_pebs;
661 ubi->avail_pebs -= reserved_pebs;
702 ubi_err(vol->ubi, "bad attaching information, error %d", err);
710 * @ubi: UBI device description object
718 static int check_attaching_info(const struct ubi_device *ubi,
725 if (ai->vols_found > UBI_INT_VOL_COUNT + ubi->vtbl_slots) {
726 ubi_err(ubi, "found %d volumes while attaching, maximum is %d + %d",
727 ai->vols_found, UBI_INT_VOL_COUNT, ubi->vtbl_slots);
731 if (ai->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT &&
733 ubi_err(ubi, "too large volume ID %d found",
738 for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
742 vol = ubi->volumes[i];
750 ubi_assert(i < ubi->vtbl_slots);
762 ubi_msg(ubi, "finish volume %d removal", av->vol_id);
776 * @ubi: UBI device description object
783 int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_attach_info *ai)
795 if (ubi->leb_size < UBI_VTBL_RECORD_SIZE) {
796 ubi_err(ubi, "LEB size too small for a volume record");
800 ubi->vtbl_slots = ubi->leb_size / UBI_VTBL_RECORD_SIZE;
801 if (ubi->vtbl_slots > UBI_MAX_VOLUMES)
802 ubi->vtbl_slots = UBI_MAX_VOLUMES;
804 ubi->vtbl_size = ubi->vtbl_slots * UBI_VTBL_RECORD_SIZE;
805 ubi->vtbl_size = ALIGN(ubi->vtbl_size, ubi->min_io_size);
818 ubi->vtbl = create_empty_lvol(ubi, ai);
819 if (IS_ERR(ubi->vtbl))
820 return PTR_ERR(ubi->vtbl);
822 ubi_err(ubi, "the layout volume was not found");
828 ubi_err(ubi, "too many LEBs (%d) in layout volume",
833 ubi->vtbl = process_lvol(ubi, ai, av);
834 if (IS_ERR(ubi->vtbl))
835 return PTR_ERR(ubi->vtbl);
838 ubi->avail_pebs = ubi->good_peb_count - ubi->corr_peb_count;
844 err = init_volumes(ubi, ai, ubi->vtbl);
852 err = check_attaching_info(ubi, ai);
859 vfree(ubi->vtbl);
860 ubi_free_all_volumes(ubi);
866 * @ubi: UBI device description object
868 static void self_vtbl_check(const struct ubi_device *ubi)
870 if (!ubi_dbg_chk_gen(ubi))
873 if (vtbl_check(ubi, ubi->vtbl)) {
874 ubi_err(ubi, "self-check failed");