Lines Matching refs:vol
58 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev); in vol_attribute_show() local
59 struct ubi_device *ubi = vol->ubi; in vol_attribute_show()
62 if (!ubi->volumes[vol->vol_id]) { in vol_attribute_show()
67 vol->ref_count += 1; in vol_attribute_show()
71 ret = sprintf(buf, "%d\n", vol->reserved_pebs); in vol_attribute_show()
75 if (vol->vol_type == UBI_DYNAMIC_VOLUME) in vol_attribute_show()
81 ret = sprintf(buf, "%s\n", vol->name); in vol_attribute_show()
83 ret = sprintf(buf, "%d\n", vol->corrupted); in vol_attribute_show()
85 ret = sprintf(buf, "%d\n", vol->alignment); in vol_attribute_show()
87 ret = sprintf(buf, "%d\n", vol->usable_leb_size); in vol_attribute_show()
89 ret = sprintf(buf, "%lld\n", vol->used_bytes); in vol_attribute_show()
91 ret = sprintf(buf, "%d\n", vol->upd_marker); in vol_attribute_show()
98 vol->ref_count -= 1; in vol_attribute_show()
99 ubi_assert(vol->ref_count >= 0); in vol_attribute_show()
120 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev); in vol_release() local
122 ubi_eba_replace_table(vol, NULL); in vol_release()
123 ubi_fastmap_destroy_checkmap(vol); in vol_release()
124 kfree(vol); in vol_release()
141 struct ubi_volume *vol; in ubi_create_volume() local
148 vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL); in ubi_create_volume()
149 if (!vol) in ubi_create_volume()
152 device_initialize(&vol->dev); in ubi_create_volume()
153 vol->dev.release = vol_release; in ubi_create_volume()
154 vol->dev.parent = &ubi->dev; in ubi_create_volume()
155 vol->dev.class = &ubi_class; in ubi_create_volume()
156 vol->dev.groups = volume_dev_groups; in ubi_create_volume()
159 vol->skip_check = 1; in ubi_create_volume()
201 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment; in ubi_create_volume()
202 vol->reserved_pebs = div_u64(req->bytes + vol->usable_leb_size - 1, in ubi_create_volume()
203 vol->usable_leb_size); in ubi_create_volume()
206 if (vol->reserved_pebs > ubi->avail_pebs) { in ubi_create_volume()
215 ubi->avail_pebs -= vol->reserved_pebs; in ubi_create_volume()
216 ubi->rsvd_pebs += vol->reserved_pebs; in ubi_create_volume()
219 vol->vol_id = vol_id; in ubi_create_volume()
220 vol->alignment = req->alignment; in ubi_create_volume()
221 vol->data_pad = ubi->leb_size % vol->alignment; in ubi_create_volume()
222 vol->vol_type = req->vol_type; in ubi_create_volume()
223 vol->name_len = req->name_len; in ubi_create_volume()
224 memcpy(vol->name, req->name, vol->name_len); in ubi_create_volume()
225 vol->ubi = ubi; in ubi_create_volume()
235 eba_tbl = ubi_eba_create_table(vol, vol->reserved_pebs); in ubi_create_volume()
241 ubi_eba_replace_table(vol, eba_tbl); in ubi_create_volume()
243 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in ubi_create_volume()
244 vol->used_ebs = vol->reserved_pebs; in ubi_create_volume()
245 vol->last_eb_bytes = vol->usable_leb_size; in ubi_create_volume()
246 vol->used_bytes = in ubi_create_volume()
247 (long long)vol->used_ebs * vol->usable_leb_size; in ubi_create_volume()
249 vol->used_ebs = div_u64_rem(vol->used_bytes, in ubi_create_volume()
250 vol->usable_leb_size, in ubi_create_volume()
251 &vol->last_eb_bytes); in ubi_create_volume()
252 if (vol->last_eb_bytes != 0) in ubi_create_volume()
253 vol->used_ebs += 1; in ubi_create_volume()
255 vol->last_eb_bytes = vol->usable_leb_size; in ubi_create_volume()
260 ubi->volumes[vol_id] = vol; in ubi_create_volume()
265 cdev_init(&vol->cdev, &ubi_vol_cdev_operations); in ubi_create_volume()
266 vol->cdev.owner = THIS_MODULE; in ubi_create_volume()
268 vol->dev.devt = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1); in ubi_create_volume()
269 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); in ubi_create_volume()
270 err = cdev_device_add(&vol->cdev, &vol->dev); in ubi_create_volume()
278 vtbl_rec.reserved_pebs = cpu_to_be32(vol->reserved_pebs); in ubi_create_volume()
279 vtbl_rec.alignment = cpu_to_be32(vol->alignment); in ubi_create_volume()
280 vtbl_rec.data_pad = cpu_to_be32(vol->data_pad); in ubi_create_volume()
281 vtbl_rec.name_len = cpu_to_be16(vol->name_len); in ubi_create_volume()
282 if (vol->vol_type == UBI_DYNAMIC_VOLUME) in ubi_create_volume()
287 if (vol->skip_check) in ubi_create_volume()
290 memcpy(vtbl_rec.name, vol->name, vol->name_len); in ubi_create_volume()
296 ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED); in ubi_create_volume()
306 cdev_device_del(&vol->cdev, &vol->dev); in ubi_create_volume()
314 ubi->rsvd_pebs -= vol->reserved_pebs; in ubi_create_volume()
315 ubi->avail_pebs += vol->reserved_pebs; in ubi_create_volume()
318 put_device(&vol->dev); in ubi_create_volume()
335 struct ubi_volume *vol = desc->vol; in ubi_remove_volume() local
336 struct ubi_device *ubi = vol->ubi; in ubi_remove_volume()
337 int i, err, vol_id = vol->vol_id, reserved_pebs = vol->reserved_pebs; in ubi_remove_volume()
341 ubi_assert(vol == ubi->volumes[vol_id]); in ubi_remove_volume()
347 if (vol->ref_count > 1) { in ubi_remove_volume()
364 for (i = 0; i < vol->reserved_pebs; i++) { in ubi_remove_volume()
365 err = ubi_eba_unmap_leb(ubi, vol, i); in ubi_remove_volume()
370 cdev_device_del(&vol->cdev, &vol->dev); in ubi_remove_volume()
371 put_device(&vol->dev); in ubi_remove_volume()
380 ubi_volume_notify(ubi, vol, UBI_VOLUME_REMOVED); in ubi_remove_volume()
389 ubi->volumes[vol_id] = vol; in ubi_remove_volume()
407 struct ubi_volume *vol = desc->vol; in ubi_resize_volume() local
408 struct ubi_device *ubi = vol->ubi; in ubi_resize_volume()
411 int vol_id = vol->vol_id; in ubi_resize_volume()
417 ubi->ubi_num, vol_id, vol->reserved_pebs, reserved_pebs); in ubi_resize_volume()
419 if (vol->vol_type == UBI_STATIC_VOLUME && in ubi_resize_volume()
420 reserved_pebs < vol->used_ebs) { in ubi_resize_volume()
422 reserved_pebs, vol->used_ebs); in ubi_resize_volume()
427 if (reserved_pebs == vol->reserved_pebs) in ubi_resize_volume()
430 new_eba_tbl = ubi_eba_create_table(vol, reserved_pebs); in ubi_resize_volume()
435 if (vol->ref_count > 1) { in ubi_resize_volume()
443 pebs = reserved_pebs - vol->reserved_pebs; in ubi_resize_volume()
458 ubi_eba_copy_table(vol, new_eba_tbl, vol->reserved_pebs); in ubi_resize_volume()
459 ubi_eba_replace_table(vol, new_eba_tbl); in ubi_resize_volume()
465 err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i); in ubi_resize_volume()
473 ubi_eba_copy_table(vol, new_eba_tbl, reserved_pebs); in ubi_resize_volume()
474 ubi_eba_replace_table(vol, new_eba_tbl); in ubi_resize_volume()
496 vol->reserved_pebs = reserved_pebs; in ubi_resize_volume()
497 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in ubi_resize_volume()
498 vol->used_ebs = reserved_pebs; in ubi_resize_volume()
499 vol->last_eb_bytes = vol->usable_leb_size; in ubi_resize_volume()
500 vol->used_bytes = in ubi_resize_volume()
501 (long long)vol->used_ebs * vol->usable_leb_size; in ubi_resize_volume()
504 ubi_volume_notify(ubi, vol, UBI_VOLUME_RESIZED); in ubi_resize_volume()
546 struct ubi_volume *vol = re->desc->vol; in ubi_rename_volumes() local
549 vol->name_len = re->new_name_len; in ubi_rename_volumes()
550 memcpy(vol->name, re->new_name, re->new_name_len + 1); in ubi_rename_volumes()
552 ubi_volume_notify(ubi, vol, UBI_VOLUME_RENAMED); in ubi_rename_volumes()
570 int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol) in ubi_add_volume() argument
572 int err, vol_id = vol->vol_id; in ubi_add_volume()
578 cdev_init(&vol->cdev, &ubi_vol_cdev_operations); in ubi_add_volume()
579 vol->cdev.owner = THIS_MODULE; in ubi_add_volume()
580 dev = MKDEV(MAJOR(ubi->cdev.dev), vol->vol_id + 1); in ubi_add_volume()
581 err = cdev_add(&vol->cdev, dev, 1); in ubi_add_volume()
585 vol_release(&vol->dev); in ubi_add_volume()
589 vol->dev.release = vol_release; in ubi_add_volume()
590 vol->dev.parent = &ubi->dev; in ubi_add_volume()
591 vol->dev.devt = dev; in ubi_add_volume()
592 vol->dev.class = &ubi_class; in ubi_add_volume()
593 vol->dev.groups = volume_dev_groups; in ubi_add_volume()
594 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); in ubi_add_volume()
595 err = device_register(&vol->dev); in ubi_add_volume()
597 cdev_del(&vol->cdev); in ubi_add_volume()
598 put_device(&vol->dev); in ubi_add_volume()
614 void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol) in ubi_free_volume() argument
616 dbg_gen("free volume %d", vol->vol_id); in ubi_free_volume()
618 ubi->volumes[vol->vol_id] = NULL; in ubi_free_volume()
619 cdev_del(&vol->cdev); in ubi_free_volume()
620 device_unregister(&vol->dev); in ubi_free_volume()
634 const struct ubi_volume *vol; in self_check_volume() local
640 vol = ubi->volumes[idx]; in self_check_volume()
642 if (!vol) { in self_check_volume()
651 if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 || in self_check_volume()
652 vol->name_len < 0) { in self_check_volume()
656 if (vol->alignment > ubi->leb_size || vol->alignment == 0) { in self_check_volume()
661 n = vol->alignment & (ubi->min_io_size - 1); in self_check_volume()
662 if (vol->alignment != 1 && n) { in self_check_volume()
667 n = ubi->leb_size % vol->alignment; in self_check_volume()
668 if (vol->data_pad != n) { in self_check_volume()
673 if (vol->vol_type != UBI_DYNAMIC_VOLUME && in self_check_volume()
674 vol->vol_type != UBI_STATIC_VOLUME) { in self_check_volume()
679 if (vol->upd_marker && vol->corrupted) { in self_check_volume()
684 if (vol->reserved_pebs > ubi->good_peb_count) { in self_check_volume()
689 n = ubi->leb_size - vol->data_pad; in self_check_volume()
690 if (vol->usable_leb_size != ubi->leb_size - vol->data_pad) { in self_check_volume()
695 if (vol->name_len > UBI_VOL_NAME_MAX) { in self_check_volume()
701 n = strnlen(vol->name, vol->name_len + 1); in self_check_volume()
702 if (n != vol->name_len) { in self_check_volume()
707 n = (long long)vol->used_ebs * vol->usable_leb_size; in self_check_volume()
708 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in self_check_volume()
709 if (vol->corrupted) { in self_check_volume()
713 if (vol->used_ebs != vol->reserved_pebs) { in self_check_volume()
717 if (vol->last_eb_bytes != vol->usable_leb_size) { in self_check_volume()
721 if (vol->used_bytes != n) { in self_check_volume()
726 if (vol->skip_check) { in self_check_volume()
731 if (vol->used_ebs < 0 || vol->used_ebs > vol->reserved_pebs) { in self_check_volume()
735 if (vol->last_eb_bytes < 0 || in self_check_volume()
736 vol->last_eb_bytes > vol->usable_leb_size) { in self_check_volume()
740 if (vol->used_bytes < 0 || vol->used_bytes > n || in self_check_volume()
741 vol->used_bytes < n - vol->usable_leb_size) { in self_check_volume()
757 if (alignment != vol->alignment || data_pad != vol->data_pad || in self_check_volume()
758 upd_marker != vol->upd_marker || vol_type != vol->vol_type || in self_check_volume()
759 name_len != vol->name_len || strncmp(name, vol->name, name_len)) { in self_check_volume()
769 if (vol) in self_check_volume()
770 ubi_dump_vol_info(vol); in self_check_volume()