Lines Matching +full:- +full:av
5 * SPDX-License-Identifier: GPL-2.0+
12 * on-flash table containing volume meta-data like name, number of reserved
13 * physical eraseblocks, type, etc. The volume table is stored in the so-called
17 * consists of two logical eraseblocks - LEB 0 and LEB 1. Each logical
30 * In this UBI implementation the on-flash volume table does not contain any
41 * The volume table also stores so-called "update marker", which is used for
44 * the update operation was interrupted (e.g. by an unclean reboot) - the
67 * ubi_update_layout_vol - helper for updatting layout volumes on flash
75 layout_vol = ubi->volumes[vol_id2idx(ubi, UBI_LAYOUT_VOLUME_ID)]; in ubi_update_layout_vol()
77 err = ubi_eba_atomic_leb_change(ubi, layout_vol, i, ubi->vtbl, in ubi_update_layout_vol()
78 ubi->vtbl_size); in ubi_update_layout_vol()
87 * ubi_change_vtbl_record - change volume table record.
103 ubi_assert(idx >= 0 && idx < ubi->vtbl_slots); in ubi_change_vtbl_record()
109 vtbl_rec->crc = cpu_to_be32(crc); in ubi_change_vtbl_record()
112 memcpy(&ubi->vtbl[idx], vtbl_rec, sizeof(struct ubi_vtbl_record)); in ubi_change_vtbl_record()
120 * ubi_vtbl_rename_volumes - rename UBI volumes in the volume table.
124 * This function re-names multiple volumes specified in @req in the volume
135 struct ubi_volume *vol = re->desc->vol; in ubi_vtbl_rename_volumes()
136 struct ubi_vtbl_record *vtbl_rec = &ubi->vtbl[vol->vol_id]; in ubi_vtbl_rename_volumes()
138 if (re->remove) { in ubi_vtbl_rename_volumes()
144 vtbl_rec->name_len = cpu_to_be16(re->new_name_len); in ubi_vtbl_rename_volumes()
145 memcpy(vtbl_rec->name, re->new_name, re->new_name_len); in ubi_vtbl_rename_volumes()
146 memset(vtbl_rec->name + re->new_name_len, 0, in ubi_vtbl_rename_volumes()
147 UBI_VOL_NAME_MAX + 1 - re->new_name_len); in ubi_vtbl_rename_volumes()
150 vtbl_rec->crc = cpu_to_be32(crc); in ubi_vtbl_rename_volumes()
157 * vtbl_check - check if volume table is not corrupted and sensible.
162 * and %-EINVAL if it contains inconsistent data.
172 for (i = 0; i < ubi->vtbl_slots; i++) {
206 if (alignment > ubi->leb_size || alignment == 0) {
211 n = alignment & (ubi->min_io_size - 1);
217 n = ubi->leb_size % alignment;
234 if (reserved_pebs > ubi->good_peb_count) {
236 reserved_pebs, ubi->good_peb_count);
258 for (i = 0; i < ubi->vtbl_slots - 1; i++) {
259 for (n = i + 1; n < ubi->vtbl_slots; n++) {
273 return -EINVAL;
283 return -EINVAL;
287 * create_vtbl - create a copy of volume table.
307 return -ENOMEM;
316 vid_hdr->vol_type = UBI_LAYOUT_VOLUME_TYPE;
317 vid_hdr->vol_id = cpu_to_be32(UBI_LAYOUT_VOLUME_ID);
318 vid_hdr->compat = UBI_LAYOUT_VOLUME_COMPAT;
319 vid_hdr->data_size = vid_hdr->used_ebs =
320 vid_hdr->data_pad = cpu_to_be32(0);
321 vid_hdr->lnum = cpu_to_be32(copy);
322 vid_hdr->sqnum = cpu_to_be64(++ai->max_sqnum);
325 err = ubi_io_write_vid_hdr(ubi, new_aeb->pnum, vid_hdr);
330 err = ubi_io_write_data(ubi, vtbl, new_aeb->pnum, 0, ubi->vtbl_size);
338 err = ubi_add_to_av(ubi, ai, new_aeb->pnum, new_aeb->ec, vid_hdr, 0);
339 kmem_cache_free(ai->aeb_slab_cache, new_aeb);
344 if (err == -EIO && ++tries <= 5) {
349 list_add(&new_aeb->u.list, &ai->erase);
352 kmem_cache_free(ai->aeb_slab_cache, new_aeb);
360 * process_lvol - process the layout volume.
363 * @av: layout volume attaching information
371 struct ubi_ainf_volume *av) argument
407 ubi_rb_for_each_entry(rb, aeb, &av->root, u.rb) {
408 leb[aeb->lnum] = vzalloc(ubi->vtbl_size);
409 if (!leb[aeb->lnum]) {
410 err = -ENOMEM;
414 err = ubi_io_read_data(ubi, leb[aeb->lnum], aeb->pnum, 0,
415 ubi->vtbl_size);
418 * Scrub the PEB later. Note, -EBADMSG indicates an
422 * aeb->scrub). If the data is not OK, the contents of
424 * aeb->scrub will be cleared in
427 aeb->scrub = 1;
432 err = -EINVAL;
443 ubi->vtbl_size);
485 * create_empty_lvol - create empty layout volume.
498 vtbl = vzalloc(ubi->vtbl_size);
500 return ERR_PTR(-ENOMEM);
502 for (i = 0; i < ubi->vtbl_slots; i++)
519 * init_volumes - initialize volume information for existing volumes.
533 struct ubi_ainf_volume *av; local
536 for (i = 0; i < ubi->vtbl_slots; i++) {
544 return -ENOMEM;
546 vol->reserved_pebs = be32_to_cpu(vtbl[i].reserved_pebs);
547 vol->alignment = be32_to_cpu(vtbl[i].alignment);
548 vol->data_pad = be32_to_cpu(vtbl[i].data_pad);
549 vol->upd_marker = vtbl[i].upd_marker;
550 vol->vol_type = vtbl[i].vol_type == UBI_VID_DYNAMIC ?
552 vol->name_len = be16_to_cpu(vtbl[i].name_len);
553 vol->usable_leb_size = ubi->leb_size - vol->data_pad;
554 memcpy(vol->name, vtbl[i].name, vol->name_len);
555 vol->name[vol->name_len] = '\0';
556 vol->vol_id = i;
559 /* Auto re-size flag may be set only for one volume */
560 if (ubi->autoresize_vol_id != -1) {
561 ubi_err(ubi, "more than one auto-resize volume (%d and %d)",
562 ubi->autoresize_vol_id, i);
564 return -EINVAL;
567 ubi->autoresize_vol_id = i;
570 ubi_assert(!ubi->volumes[i]);
571 ubi->volumes[i] = vol;
572 ubi->vol_count += 1;
573 vol->ubi = ubi;
574 reserved_pebs += vol->reserved_pebs;
580 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
581 vol->used_ebs = vol->reserved_pebs;
582 vol->last_eb_bytes = vol->usable_leb_size;
583 vol->used_bytes =
584 (long long)vol->used_ebs * vol->usable_leb_size;
589 av = ubi_find_av(ai, i);
590 if (!av || !av->leb_count) {
602 if (av->leb_count != av->used_ebs) {
607 ubi_warn(ubi, "static volume %d misses %d LEBs - corrupted",
608 av->vol_id, av->used_ebs - av->leb_count);
609 vol->corrupted = 1;
613 vol->used_ebs = av->used_ebs;
614 vol->used_bytes =
615 (long long)(vol->used_ebs - 1) * vol->usable_leb_size;
616 vol->used_bytes += av->last_data_size;
617 vol->last_eb_bytes = av->last_data_size;
623 return -ENOMEM;
625 vol->reserved_pebs = UBI_LAYOUT_VOLUME_EBS;
626 vol->alignment = UBI_LAYOUT_VOLUME_ALIGN;
627 vol->vol_type = UBI_DYNAMIC_VOLUME;
628 vol->name_len = sizeof(UBI_LAYOUT_VOLUME_NAME) - 1;
629 memcpy(vol->name, UBI_LAYOUT_VOLUME_NAME, vol->name_len + 1);
630 vol->usable_leb_size = ubi->leb_size;
631 vol->used_ebs = vol->reserved_pebs;
632 vol->last_eb_bytes = vol->reserved_pebs;
633 vol->used_bytes =
634 (long long)vol->used_ebs * (ubi->leb_size - vol->data_pad);
635 vol->vol_id = UBI_LAYOUT_VOLUME_ID;
636 vol->ref_count = 1;
638 ubi_assert(!ubi->volumes[i]);
639 ubi->volumes[vol_id2idx(ubi, vol->vol_id)] = vol;
640 reserved_pebs += vol->reserved_pebs;
641 ubi->vol_count += 1;
642 vol->ubi = ubi;
644 if (reserved_pebs > ubi->avail_pebs) {
646 reserved_pebs, ubi->avail_pebs);
647 if (ubi->corr_peb_count)
649 ubi->corr_peb_count);
651 ubi->rsvd_pebs += reserved_pebs;
652 ubi->avail_pebs -= reserved_pebs;
658 * check_av - check volume attaching information.
660 * @av: volume attaching information
663 * to the data read from the volume tabla, and %-EINVAL if not.
666 const struct ubi_ainf_volume *av) argument
670 if (av->highest_lnum >= vol->reserved_pebs) {
674 if (av->leb_count > vol->reserved_pebs) {
678 if (av->vol_type != vol->vol_type) {
682 if (av->used_ebs > vol->reserved_pebs) {
686 if (av->data_pad != vol->data_pad) {
693 ubi_err(vol->ubi, "bad attaching information, error %d", err);
694 ubi_dump_av(av);
696 return -EINVAL;
700 * check_attaching_info - check that attaching information.
704 * Even though we protect on-flash data by CRC checksums, we still don't trust
707 * information is OK and %-EINVAL if it is not.
713 struct ubi_ainf_volume *av; local
716 if (ai->vols_found > UBI_INT_VOL_COUNT + ubi->vtbl_slots) {
718 ai->vols_found, UBI_INT_VOL_COUNT, ubi->vtbl_slots);
719 return -EINVAL;
722 if (ai->highest_vol_id >= ubi->vtbl_slots + UBI_INT_VOL_COUNT &&
723 ai->highest_vol_id < UBI_INTERNAL_VOL_START) {
725 ai->highest_vol_id);
726 return -EINVAL;
729 for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
732 av = ubi_find_av(ai, i);
733 vol = ubi->volumes[i];
735 if (av)
736 ubi_remove_av(ai, av);
740 if (vol->reserved_pebs == 0) {
741 ubi_assert(i < ubi->vtbl_slots);
743 if (!av)
753 ubi_msg(ubi, "finish volume %d removal", av->vol_id);
754 ubi_remove_av(ai, av);
755 } else if (av) {
756 err = check_av(vol, av);
766 * ubi_read_volume_table - read the volume table.
777 struct ubi_ainf_volume *av; local
785 ubi->vtbl_slots = ubi->leb_size / UBI_VTBL_RECORD_SIZE;
786 if (ubi->vtbl_slots > UBI_MAX_VOLUMES)
787 ubi->vtbl_slots = UBI_MAX_VOLUMES;
789 ubi->vtbl_size = ubi->vtbl_slots * UBI_VTBL_RECORD_SIZE;
790 ubi->vtbl_size = ALIGN(ubi->vtbl_size, ubi->min_io_size);
792 av = ubi_find_av(ai, UBI_LAYOUT_VOLUME_ID);
793 if (!av) {
802 if (ai->is_empty) {
803 ubi->vtbl = create_empty_lvol(ubi, ai);
804 if (IS_ERR(ubi->vtbl))
805 return PTR_ERR(ubi->vtbl);
808 return -EINVAL;
811 if (av->leb_count > UBI_LAYOUT_VOLUME_EBS) {
814 av->leb_count);
815 return -EINVAL;
818 ubi->vtbl = process_lvol(ubi, ai, av);
819 if (IS_ERR(ubi->vtbl))
820 return PTR_ERR(ubi->vtbl);
823 ubi->avail_pebs = ubi->good_peb_count - ubi->corr_peb_count;
826 * The layout volume is OK, initialize the corresponding in-RAM data
829 err = init_volumes(ubi, ai, ubi->vtbl);
844 vfree(ubi->vtbl);
845 for (i = 0; i < ubi->vtbl_slots + UBI_INT_VOL_COUNT; i++) {
846 kfree(ubi->volumes[i]);
847 ubi->volumes[i] = NULL;
853 * self_vtbl_check - check volume table.
861 if (vtbl_check(ubi, ubi->vtbl)) {
862 ubi_err(ubi, "self-check failed");