Lines Matching full:ubi

17 #include "ubi.h"
19 static int self_check_volumes(struct ubi_device *ubi);
24 /* Device attributes corresponding to files in '/<sysfs>/class/ubi/ubiX_Y' */
43 * "Show" method for files in '/<sysfs>/class/ubi/ubiX_Y/'.
47 * /<sysfs>/class/ubi/ubiX_Y/reserved_ebs;
49 * C. process 1 starts reading the /<sysfs>/class/ubi/ubiX_Y/reserved_ebs file;
52 * out that the volume was removed from the @ubi->volumes array.
59 struct ubi_device *ubi = vol->ubi; in vol_attribute_show() local
61 spin_lock(&ubi->volumes_lock); in vol_attribute_show()
62 if (!ubi->volumes[vol->vol_id] || ubi->volumes[vol->vol_id]->is_dead) { in vol_attribute_show()
63 spin_unlock(&ubi->volumes_lock); in vol_attribute_show()
68 spin_unlock(&ubi->volumes_lock); in vol_attribute_show()
96 /* We've done the operation, drop volume and UBI device references */ in vol_attribute_show()
97 spin_lock(&ubi->volumes_lock); in vol_attribute_show()
100 spin_unlock(&ubi->volumes_lock); in vol_attribute_show()
154 * @ubi: UBI device description object
161 * @ubi->device_mutex locked.
163 int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) in ubi_create_volume() argument
170 if (ubi->ro_mode) in ubi_create_volume()
179 vol->dev.parent = &ubi->dev; in ubi_create_volume()
186 spin_lock(&ubi->volumes_lock); in ubi_create_volume()
190 for (i = 0; i < ubi->vtbl_slots; i++) in ubi_create_volume()
191 if (!ubi->volumes[i]) { in ubi_create_volume()
197 ubi_err(ubi, "out of volume IDs"); in ubi_create_volume()
205 ubi->ubi_num, vol_id, (unsigned long long)req->bytes, in ubi_create_volume()
210 if (ubi->volumes[vol_id]) { in ubi_create_volume()
211 ubi_err(ubi, "volume %d already exists", vol_id); in ubi_create_volume()
216 for (i = 0; i < ubi->vtbl_slots; i++) in ubi_create_volume()
217 if (ubi->volumes[i] && !ubi->volumes[i]->is_dead && in ubi_create_volume()
218 ubi->volumes[i]->name_len == req->name_len && in ubi_create_volume()
219 !strcmp(ubi->volumes[i]->name, req->name)) { in ubi_create_volume()
220 ubi_err(ubi, "volume \"%s\" exists (ID %d)", in ubi_create_volume()
226 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment; in ubi_create_volume()
231 if (vol->reserved_pebs > ubi->avail_pebs) { in ubi_create_volume()
232 ubi_err(ubi, "not enough PEBs, only %d available", in ubi_create_volume()
233 ubi->avail_pebs); in ubi_create_volume()
234 if (ubi->corr_peb_count) in ubi_create_volume()
235 ubi_err(ubi, "%d PEBs are corrupted and not used", in ubi_create_volume()
236 ubi->corr_peb_count); in ubi_create_volume()
240 ubi->avail_pebs -= vol->reserved_pebs; in ubi_create_volume()
241 ubi->rsvd_pebs += vol->reserved_pebs; in ubi_create_volume()
242 spin_unlock(&ubi->volumes_lock); in ubi_create_volume()
246 vol->data_pad = ubi->leb_size % vol->alignment; in ubi_create_volume()
250 vol->ubi = ubi; in ubi_create_volume()
257 err = ubi_wl_flush(ubi, vol_id, UBI_ALL); in ubi_create_volume()
285 spin_lock(&ubi->volumes_lock); in ubi_create_volume()
286 ubi->volumes[vol_id] = vol; in ubi_create_volume()
287 ubi->vol_count += 1; in ubi_create_volume()
288 spin_unlock(&ubi->volumes_lock); in ubi_create_volume()
294 vol->dev.devt = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1); in ubi_create_volume()
295 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); in ubi_create_volume()
298 ubi_err(ubi, "cannot add device"); in ubi_create_volume()
318 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); in ubi_create_volume()
322 ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED); in ubi_create_volume()
323 self_check_volumes(ubi); in ubi_create_volume()
334 spin_lock(&ubi->volumes_lock); in ubi_create_volume()
335 ubi->volumes[vol_id] = NULL; in ubi_create_volume()
336 ubi->vol_count -= 1; in ubi_create_volume()
337 spin_unlock(&ubi->volumes_lock); in ubi_create_volume()
339 spin_lock(&ubi->volumes_lock); in ubi_create_volume()
340 ubi->rsvd_pebs -= vol->reserved_pebs; in ubi_create_volume()
341 ubi->avail_pebs += vol->reserved_pebs; in ubi_create_volume()
343 spin_unlock(&ubi->volumes_lock); in ubi_create_volume()
345 ubi_err(ubi, "cannot create volume %d, error %d", vol_id, err); in ubi_create_volume()
356 * code in case of failure. The caller has to have the @ubi->device_mutex
362 struct ubi_device *ubi = vol->ubi; in ubi_remove_volume() local
365 dbg_gen("remove device %d, volume %d", ubi->ubi_num, vol_id); in ubi_remove_volume()
367 ubi_assert(vol == ubi->volumes[vol_id]); in ubi_remove_volume()
369 if (ubi->ro_mode) in ubi_remove_volume()
372 spin_lock(&ubi->volumes_lock); in ubi_remove_volume()
389 spin_unlock(&ubi->volumes_lock); in ubi_remove_volume()
391 ubi_volume_notify(ubi, vol, UBI_VOLUME_SHUTDOWN); in ubi_remove_volume()
393 spin_lock(&ubi->volumes_lock); in ubi_remove_volume()
394 ubi->volumes[vol_id] = NULL; in ubi_remove_volume()
395 spin_unlock(&ubi->volumes_lock); in ubi_remove_volume()
398 err = ubi_change_vtbl_record(ubi, vol_id, NULL); in ubi_remove_volume()
404 err = ubi_eba_unmap_leb(ubi, vol, i); in ubi_remove_volume()
412 spin_lock(&ubi->volumes_lock); in ubi_remove_volume()
413 ubi->rsvd_pebs -= reserved_pebs; in ubi_remove_volume()
414 ubi->avail_pebs += reserved_pebs; in ubi_remove_volume()
415 ubi_update_reserved(ubi); in ubi_remove_volume()
416 ubi->vol_count -= 1; in ubi_remove_volume()
417 spin_unlock(&ubi->volumes_lock); in ubi_remove_volume()
419 ubi_volume_notify(ubi, vol, UBI_VOLUME_REMOVED); in ubi_remove_volume()
421 self_check_volumes(ubi); in ubi_remove_volume()
426 ubi_err(ubi, "cannot remove volume %d, error %d", vol_id, err); in ubi_remove_volume()
427 spin_lock(&ubi->volumes_lock); in ubi_remove_volume()
428 ubi->volumes[vol_id] = vol; in ubi_remove_volume()
430 spin_unlock(&ubi->volumes_lock); in ubi_remove_volume()
441 * @ubi->device_mutex locked.
447 struct ubi_device *ubi = vol->ubi; in ubi_resize_volume() local
453 if (ubi->ro_mode) in ubi_resize_volume()
457 ubi->ubi_num, vol_id, vol->reserved_pebs, reserved_pebs); in ubi_resize_volume()
461 ubi_err(ubi, "too small size %d, %d LEBs contain data", in ubi_resize_volume()
474 spin_lock(&ubi->volumes_lock); in ubi_resize_volume()
476 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
480 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
485 spin_lock(&ubi->volumes_lock); in ubi_resize_volume()
486 if (pebs > ubi->avail_pebs) { in ubi_resize_volume()
487 ubi_err(ubi, "not enough PEBs: requested %d, available %d", in ubi_resize_volume()
488 pebs, ubi->avail_pebs); in ubi_resize_volume()
489 if (ubi->corr_peb_count) in ubi_resize_volume()
490 ubi_err(ubi, "%d PEBs are corrupted and not used", in ubi_resize_volume()
491 ubi->corr_peb_count); in ubi_resize_volume()
492 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
497 ubi->avail_pebs -= pebs; in ubi_resize_volume()
498 ubi->rsvd_pebs += pebs; in ubi_resize_volume()
503 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
508 err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i); in ubi_resize_volume()
512 spin_lock(&ubi->volumes_lock); in ubi_resize_volume()
513 ubi->rsvd_pebs += pebs; in ubi_resize_volume()
514 ubi->avail_pebs -= pebs; in ubi_resize_volume()
515 ubi_update_reserved(ubi); in ubi_resize_volume()
520 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
525 * Otherwise it can happen that upon next attach UBI finds a LEB with in ubi_resize_volume()
529 err = ubi_wl_flush(ubi, vol_id, UBI_ALL); in ubi_resize_volume()
535 vtbl_rec = ubi->vtbl[vol_id]; in ubi_resize_volume()
537 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); in ubi_resize_volume()
550 ubi_volume_notify(ubi, vol, UBI_VOLUME_RESIZED); in ubi_resize_volume()
551 self_check_volumes(ubi); in ubi_resize_volume()
555 spin_lock(&ubi->volumes_lock); in ubi_resize_volume()
557 ubi->rsvd_pebs -= pebs; in ubi_resize_volume()
558 ubi->avail_pebs += pebs; in ubi_resize_volume()
564 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
571 * ubi_rename_volumes - re-name UBI volumes.
572 * @ubi: UBI device description object
579 int ubi_rename_volumes(struct ubi_device *ubi, struct list_head *rename_list) in ubi_rename_volumes() argument
584 err = ubi_vtbl_rename_volumes(ubi, rename_list); in ubi_rename_volumes()
596 spin_lock(&ubi->volumes_lock); in ubi_rename_volumes()
599 spin_unlock(&ubi->volumes_lock); in ubi_rename_volumes()
600 ubi_volume_notify(ubi, vol, UBI_VOLUME_RENAMED); in ubi_rename_volumes()
605 self_check_volumes(ubi); in ubi_rename_volumes()
611 * @ubi: UBI device description object
618 int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol) in ubi_add_volume() argument
628 dev = MKDEV(MAJOR(ubi->cdev.dev), vol->vol_id + 1); in ubi_add_volume()
631 ubi_err(ubi, "cannot add character device for volume %d, error %d", in ubi_add_volume()
638 vol->dev.parent = &ubi->dev; in ubi_add_volume()
642 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); in ubi_add_volume()
651 self_check_volumes(ubi); in ubi_add_volume()
657 * @ubi: UBI device description object
661 * Used only when the UBI device is detached.
663 void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol) in ubi_free_volume() argument
667 ubi->volumes[vol->vol_id] = NULL; in ubi_free_volume()
674 * @ubi: UBI device description object
679 static int self_check_volume(struct ubi_device *ubi, int vol_id) in self_check_volume() argument
681 int idx = vol_id2idx(ubi, vol_id); in self_check_volume()
687 spin_lock(&ubi->volumes_lock); in self_check_volume()
688 reserved_pebs = be32_to_cpu(ubi->vtbl[vol_id].reserved_pebs); in self_check_volume()
689 vol = ubi->volumes[idx]; in self_check_volume()
693 ubi_err(ubi, "no volume info, but volume exists"); in self_check_volume()
696 spin_unlock(&ubi->volumes_lock); in self_check_volume()
702 ubi_err(ubi, "negative values"); in self_check_volume()
705 if (vol->alignment > ubi->leb_size || vol->alignment == 0) { in self_check_volume()
706 ubi_err(ubi, "bad alignment"); in self_check_volume()
710 n = vol->alignment & (ubi->min_io_size - 1); in self_check_volume()
712 ubi_err(ubi, "alignment is not multiple of min I/O unit"); in self_check_volume()
716 n = ubi->leb_size % vol->alignment; in self_check_volume()
718 ubi_err(ubi, "bad data_pad, has to be %lld", n); in self_check_volume()
724 ubi_err(ubi, "bad vol_type"); in self_check_volume()
729 ubi_err(ubi, "update marker and corrupted simultaneously"); in self_check_volume()
733 if (vol->reserved_pebs > ubi->good_peb_count) { in self_check_volume()
734 ubi_err(ubi, "too large reserved_pebs"); in self_check_volume()
738 n = ubi->leb_size - vol->data_pad; in self_check_volume()
739 if (vol->usable_leb_size != ubi->leb_size - vol->data_pad) { in self_check_volume()
740 ubi_err(ubi, "bad usable_leb_size, has to be %lld", n); in self_check_volume()
745 ubi_err(ubi, "too long volume name, max is %d", in self_check_volume()
752 ubi_err(ubi, "bad name_len %lld", n); in self_check_volume()
759 ubi_err(ubi, "corrupted dynamic volume"); in self_check_volume()
763 ubi_err(ubi, "bad used_ebs"); in self_check_volume()
767 ubi_err(ubi, "bad last_eb_bytes"); in self_check_volume()
771 ubi_err(ubi, "bad used_bytes"); in self_check_volume()
776 ubi_err(ubi, "bad skip_check"); in self_check_volume()
781 ubi_err(ubi, "bad used_ebs"); in self_check_volume()
786 ubi_err(ubi, "bad last_eb_bytes"); in self_check_volume()
791 ubi_err(ubi, "bad used_bytes"); in self_check_volume()
796 alignment = be32_to_cpu(ubi->vtbl[vol_id].alignment); in self_check_volume()
797 data_pad = be32_to_cpu(ubi->vtbl[vol_id].data_pad); in self_check_volume()
798 name_len = be16_to_cpu(ubi->vtbl[vol_id].name_len); in self_check_volume()
799 upd_marker = ubi->vtbl[vol_id].upd_marker; in self_check_volume()
800 name = &ubi->vtbl[vol_id].name[0]; in self_check_volume()
801 if (ubi->vtbl[vol_id].vol_type == UBI_VID_DYNAMIC) in self_check_volume()
809 ubi_err(ubi, "volume info is different"); in self_check_volume()
813 spin_unlock(&ubi->volumes_lock); in self_check_volume()
817 ubi_err(ubi, "self-check failed for volume %d", vol_id); in self_check_volume()
820 ubi_dump_vtbl_record(&ubi->vtbl[vol_id], vol_id); in self_check_volume()
822 spin_unlock(&ubi->volumes_lock); in self_check_volume()
828 * @ubi: UBI device description object
832 static int self_check_volumes(struct ubi_device *ubi) in self_check_volumes() argument
836 if (!ubi_dbg_chk_gen(ubi)) in self_check_volumes()
839 for (i = 0; i < ubi->vtbl_slots; i++) { in self_check_volumes()
840 err = self_check_volume(ubi, i); in self_check_volumes()