Lines Matching refs:vol
71 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev); in vol_attribute_show() local
74 ubi = ubi_get_device(vol->ubi->ubi_num); in vol_attribute_show()
79 if (!ubi->volumes[vol->vol_id]) { in vol_attribute_show()
85 vol->ref_count += 1; in vol_attribute_show()
89 ret = sprintf(buf, "%d\n", vol->reserved_pebs); in vol_attribute_show()
93 if (vol->vol_type == UBI_DYNAMIC_VOLUME) in vol_attribute_show()
99 ret = sprintf(buf, "%s\n", vol->name); in vol_attribute_show()
101 ret = sprintf(buf, "%d\n", vol->corrupted); in vol_attribute_show()
103 ret = sprintf(buf, "%d\n", vol->alignment); in vol_attribute_show()
105 ret = sprintf(buf, "%d\n", vol->usable_leb_size); in vol_attribute_show()
107 ret = sprintf(buf, "%lld\n", vol->used_bytes); in vol_attribute_show()
109 ret = sprintf(buf, "%d\n", vol->upd_marker); in vol_attribute_show()
116 vol->ref_count -= 1; in vol_attribute_show()
117 ubi_assert(vol->ref_count >= 0); in vol_attribute_show()
139 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev); in vol_release() local
141 ubi_eba_replace_table(vol, NULL); in vol_release()
142 ubi_fastmap_destroy_checkmap(vol); in vol_release()
143 kfree(vol); in vol_release()
160 struct ubi_volume *vol; in ubi_create_volume() local
167 vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL); in ubi_create_volume()
168 if (!vol) in ubi_create_volume()
171 device_initialize(&vol->dev); in ubi_create_volume()
172 vol->dev.release = vol_release; in ubi_create_volume()
173 vol->dev.parent = &ubi->dev; in ubi_create_volume()
174 vol->dev.class = &ubi_class; in ubi_create_volume()
175 vol->dev.groups = volume_dev_groups; in ubi_create_volume()
178 vol->skip_check = 1; in ubi_create_volume()
220 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment; in ubi_create_volume()
221 vol->reserved_pebs = div_u64(req->bytes + vol->usable_leb_size - 1, in ubi_create_volume()
222 vol->usable_leb_size); in ubi_create_volume()
225 if (vol->reserved_pebs > ubi->avail_pebs) { in ubi_create_volume()
234 ubi->avail_pebs -= vol->reserved_pebs; in ubi_create_volume()
235 ubi->rsvd_pebs += vol->reserved_pebs; in ubi_create_volume()
238 vol->vol_id = vol_id; in ubi_create_volume()
239 vol->alignment = req->alignment; in ubi_create_volume()
240 vol->data_pad = ubi->leb_size % vol->alignment; in ubi_create_volume()
241 vol->vol_type = req->vol_type; in ubi_create_volume()
242 vol->name_len = req->name_len; in ubi_create_volume()
243 memcpy(vol->name, req->name, vol->name_len); in ubi_create_volume()
244 vol->ubi = ubi; in ubi_create_volume()
254 eba_tbl = ubi_eba_create_table(vol, vol->reserved_pebs); in ubi_create_volume()
260 ubi_eba_replace_table(vol, eba_tbl); in ubi_create_volume()
262 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in ubi_create_volume()
263 vol->used_ebs = vol->reserved_pebs; in ubi_create_volume()
264 vol->last_eb_bytes = vol->usable_leb_size; in ubi_create_volume()
265 vol->used_bytes = in ubi_create_volume()
266 (long long)vol->used_ebs * vol->usable_leb_size; in ubi_create_volume()
268 vol->used_ebs = div_u64_rem(vol->used_bytes, in ubi_create_volume()
269 vol->usable_leb_size, in ubi_create_volume()
270 &vol->last_eb_bytes); in ubi_create_volume()
271 if (vol->last_eb_bytes != 0) in ubi_create_volume()
272 vol->used_ebs += 1; in ubi_create_volume()
274 vol->last_eb_bytes = vol->usable_leb_size; in ubi_create_volume()
279 ubi->volumes[vol_id] = vol; in ubi_create_volume()
284 cdev_init(&vol->cdev, &ubi_vol_cdev_operations); in ubi_create_volume()
285 vol->cdev.owner = THIS_MODULE; in ubi_create_volume()
287 vol->dev.devt = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1); in ubi_create_volume()
288 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); in ubi_create_volume()
289 err = cdev_device_add(&vol->cdev, &vol->dev); in ubi_create_volume()
297 vtbl_rec.reserved_pebs = cpu_to_be32(vol->reserved_pebs); in ubi_create_volume()
298 vtbl_rec.alignment = cpu_to_be32(vol->alignment); in ubi_create_volume()
299 vtbl_rec.data_pad = cpu_to_be32(vol->data_pad); in ubi_create_volume()
300 vtbl_rec.name_len = cpu_to_be16(vol->name_len); in ubi_create_volume()
301 if (vol->vol_type == UBI_DYNAMIC_VOLUME) in ubi_create_volume()
306 if (vol->skip_check) in ubi_create_volume()
309 memcpy(vtbl_rec.name, vol->name, vol->name_len); in ubi_create_volume()
315 ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED); in ubi_create_volume()
325 cdev_device_del(&vol->cdev, &vol->dev); in ubi_create_volume()
334 ubi->rsvd_pebs -= vol->reserved_pebs; in ubi_create_volume()
335 ubi->avail_pebs += vol->reserved_pebs; in ubi_create_volume()
338 put_device(&vol->dev); in ubi_create_volume()
355 struct ubi_volume *vol = desc->vol; in ubi_remove_volume() local
356 struct ubi_device *ubi = vol->ubi; in ubi_remove_volume()
357 int i, err, vol_id = vol->vol_id, reserved_pebs = vol->reserved_pebs; in ubi_remove_volume()
361 ubi_assert(vol == ubi->volumes[vol_id]); in ubi_remove_volume()
367 if (vol->ref_count > 1) { in ubi_remove_volume()
384 for (i = 0; i < vol->reserved_pebs; i++) { in ubi_remove_volume()
385 err = ubi_eba_unmap_leb(ubi, vol, i); in ubi_remove_volume()
390 cdev_device_del(&vol->cdev, &vol->dev); in ubi_remove_volume()
391 put_device(&vol->dev); in ubi_remove_volume()
400 ubi_volume_notify(ubi, vol, UBI_VOLUME_REMOVED); in ubi_remove_volume()
409 ubi->volumes[vol_id] = vol; in ubi_remove_volume()
427 struct ubi_volume *vol = desc->vol; in ubi_resize_volume() local
428 struct ubi_device *ubi = vol->ubi; in ubi_resize_volume()
431 int vol_id = vol->vol_id; in ubi_resize_volume()
437 ubi->ubi_num, vol_id, vol->reserved_pebs, reserved_pebs); in ubi_resize_volume()
439 if (vol->vol_type == UBI_STATIC_VOLUME && in ubi_resize_volume()
440 reserved_pebs < vol->used_ebs) { in ubi_resize_volume()
442 reserved_pebs, vol->used_ebs); in ubi_resize_volume()
447 if (reserved_pebs == vol->reserved_pebs) in ubi_resize_volume()
450 new_eba_tbl = ubi_eba_create_table(vol, reserved_pebs); in ubi_resize_volume()
455 if (vol->ref_count > 1) { in ubi_resize_volume()
463 pebs = reserved_pebs - vol->reserved_pebs; in ubi_resize_volume()
478 ubi_eba_copy_table(vol, new_eba_tbl, vol->reserved_pebs); in ubi_resize_volume()
479 ubi_eba_replace_table(vol, new_eba_tbl); in ubi_resize_volume()
485 err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i); in ubi_resize_volume()
493 ubi_eba_copy_table(vol, new_eba_tbl, reserved_pebs); in ubi_resize_volume()
494 ubi_eba_replace_table(vol, new_eba_tbl); in ubi_resize_volume()
516 vol->reserved_pebs = reserved_pebs; in ubi_resize_volume()
517 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in ubi_resize_volume()
518 vol->used_ebs = reserved_pebs; in ubi_resize_volume()
519 vol->last_eb_bytes = vol->usable_leb_size; in ubi_resize_volume()
520 vol->used_bytes = in ubi_resize_volume()
521 (long long)vol->used_ebs * vol->usable_leb_size; in ubi_resize_volume()
524 ubi_volume_notify(ubi, vol, UBI_VOLUME_RESIZED); in ubi_resize_volume()
564 struct ubi_volume *vol = re->desc->vol; in ubi_rename_volumes() local
567 vol->name_len = re->new_name_len; in ubi_rename_volumes()
568 memcpy(vol->name, re->new_name, re->new_name_len + 1); in ubi_rename_volumes()
570 ubi_volume_notify(ubi, vol, UBI_VOLUME_RENAMED); in ubi_rename_volumes()
588 int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol) in ubi_add_volume() argument
590 int err, vol_id = vol->vol_id; in ubi_add_volume()
596 cdev_init(&vol->cdev, &ubi_vol_cdev_operations); in ubi_add_volume()
597 vol->cdev.owner = THIS_MODULE; in ubi_add_volume()
598 dev = MKDEV(MAJOR(ubi->cdev.dev), vol->vol_id + 1); in ubi_add_volume()
599 err = cdev_add(&vol->cdev, dev, 1); in ubi_add_volume()
606 vol->dev.release = vol_release; in ubi_add_volume()
607 vol->dev.parent = &ubi->dev; in ubi_add_volume()
608 vol->dev.devt = dev; in ubi_add_volume()
609 vol->dev.class = &ubi_class; in ubi_add_volume()
610 vol->dev.groups = volume_dev_groups; in ubi_add_volume()
611 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); in ubi_add_volume()
612 err = device_register(&vol->dev); in ubi_add_volume()
620 cdev_del(&vol->cdev); in ubi_add_volume()
632 void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol) in ubi_free_volume() argument
634 dbg_gen("free volume %d", vol->vol_id); in ubi_free_volume()
636 ubi->volumes[vol->vol_id] = NULL; in ubi_free_volume()
637 cdev_del(&vol->cdev); in ubi_free_volume()
638 device_unregister(&vol->dev); in ubi_free_volume()
652 const struct ubi_volume *vol; in self_check_volume() local
658 vol = ubi->volumes[idx]; in self_check_volume()
660 if (!vol) { in self_check_volume()
669 if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 || in self_check_volume()
670 vol->name_len < 0) { in self_check_volume()
674 if (vol->alignment > ubi->leb_size || vol->alignment == 0) { in self_check_volume()
679 n = vol->alignment & (ubi->min_io_size - 1); in self_check_volume()
680 if (vol->alignment != 1 && n) { in self_check_volume()
685 n = ubi->leb_size % vol->alignment; in self_check_volume()
686 if (vol->data_pad != n) { in self_check_volume()
691 if (vol->vol_type != UBI_DYNAMIC_VOLUME && in self_check_volume()
692 vol->vol_type != UBI_STATIC_VOLUME) { in self_check_volume()
697 if (vol->upd_marker && vol->corrupted) { in self_check_volume()
702 if (vol->reserved_pebs > ubi->good_peb_count) { in self_check_volume()
707 n = ubi->leb_size - vol->data_pad; in self_check_volume()
708 if (vol->usable_leb_size != ubi->leb_size - vol->data_pad) { in self_check_volume()
713 if (vol->name_len > UBI_VOL_NAME_MAX) { in self_check_volume()
719 n = strnlen(vol->name, vol->name_len + 1); in self_check_volume()
720 if (n != vol->name_len) { in self_check_volume()
725 n = (long long)vol->used_ebs * vol->usable_leb_size; in self_check_volume()
726 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in self_check_volume()
727 if (vol->corrupted) { in self_check_volume()
731 if (vol->used_ebs != vol->reserved_pebs) { in self_check_volume()
735 if (vol->last_eb_bytes != vol->usable_leb_size) { in self_check_volume()
739 if (vol->used_bytes != n) { in self_check_volume()
744 if (vol->skip_check) { in self_check_volume()
749 if (vol->used_ebs < 0 || vol->used_ebs > vol->reserved_pebs) { in self_check_volume()
753 if (vol->last_eb_bytes < 0 || in self_check_volume()
754 vol->last_eb_bytes > vol->usable_leb_size) { in self_check_volume()
758 if (vol->used_bytes < 0 || vol->used_bytes > n || in self_check_volume()
759 vol->used_bytes < n - vol->usable_leb_size) { in self_check_volume()
775 if (alignment != vol->alignment || data_pad != vol->data_pad || in self_check_volume()
776 upd_marker != vol->upd_marker || vol_type != vol->vol_type || in self_check_volume()
777 name_len != vol->name_len || strncmp(name, vol->name, name_len)) { in self_check_volume()
787 if (vol) in self_check_volume()
788 ubi_dump_vol_info(vol); in self_check_volume()