Lines Matching refs:vol
58 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev); in vol_attribute_show() local
61 ubi = ubi_get_device(vol->ubi->ubi_num); in vol_attribute_show()
66 if (!ubi->volumes[vol->vol_id]) { in vol_attribute_show()
72 vol->ref_count += 1; in vol_attribute_show()
76 ret = sprintf(buf, "%d\n", vol->reserved_pebs); in vol_attribute_show()
80 if (vol->vol_type == UBI_DYNAMIC_VOLUME) in vol_attribute_show()
86 ret = sprintf(buf, "%s\n", vol->name); in vol_attribute_show()
88 ret = sprintf(buf, "%d\n", vol->corrupted); in vol_attribute_show()
90 ret = sprintf(buf, "%d\n", vol->alignment); in vol_attribute_show()
92 ret = sprintf(buf, "%d\n", vol->usable_leb_size); in vol_attribute_show()
94 ret = sprintf(buf, "%lld\n", vol->used_bytes); in vol_attribute_show()
96 ret = sprintf(buf, "%d\n", vol->upd_marker); in vol_attribute_show()
103 vol->ref_count -= 1; in vol_attribute_show()
104 ubi_assert(vol->ref_count >= 0); in vol_attribute_show()
126 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev); in vol_release() local
128 ubi_eba_replace_table(vol, NULL); in vol_release()
129 ubi_fastmap_destroy_checkmap(vol); in vol_release()
130 kfree(vol); in vol_release()
147 struct ubi_volume *vol; in ubi_create_volume() local
154 vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL); in ubi_create_volume()
155 if (!vol) in ubi_create_volume()
158 device_initialize(&vol->dev); in ubi_create_volume()
159 vol->dev.release = vol_release; in ubi_create_volume()
160 vol->dev.parent = &ubi->dev; in ubi_create_volume()
161 vol->dev.class = &ubi_class; in ubi_create_volume()
162 vol->dev.groups = volume_dev_groups; in ubi_create_volume()
165 vol->skip_check = 1; in ubi_create_volume()
207 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment; in ubi_create_volume()
208 vol->reserved_pebs = div_u64(req->bytes + vol->usable_leb_size - 1, in ubi_create_volume()
209 vol->usable_leb_size); in ubi_create_volume()
212 if (vol->reserved_pebs > ubi->avail_pebs) { in ubi_create_volume()
221 ubi->avail_pebs -= vol->reserved_pebs; in ubi_create_volume()
222 ubi->rsvd_pebs += vol->reserved_pebs; in ubi_create_volume()
225 vol->vol_id = vol_id; in ubi_create_volume()
226 vol->alignment = req->alignment; in ubi_create_volume()
227 vol->data_pad = ubi->leb_size % vol->alignment; in ubi_create_volume()
228 vol->vol_type = req->vol_type; in ubi_create_volume()
229 vol->name_len = req->name_len; in ubi_create_volume()
230 memcpy(vol->name, req->name, vol->name_len); in ubi_create_volume()
231 vol->ubi = ubi; in ubi_create_volume()
241 eba_tbl = ubi_eba_create_table(vol, vol->reserved_pebs); in ubi_create_volume()
247 ubi_eba_replace_table(vol, eba_tbl); in ubi_create_volume()
249 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in ubi_create_volume()
250 vol->used_ebs = vol->reserved_pebs; in ubi_create_volume()
251 vol->last_eb_bytes = vol->usable_leb_size; in ubi_create_volume()
252 vol->used_bytes = in ubi_create_volume()
253 (long long)vol->used_ebs * vol->usable_leb_size; in ubi_create_volume()
255 vol->used_ebs = div_u64_rem(vol->used_bytes, in ubi_create_volume()
256 vol->usable_leb_size, in ubi_create_volume()
257 &vol->last_eb_bytes); in ubi_create_volume()
258 if (vol->last_eb_bytes != 0) in ubi_create_volume()
259 vol->used_ebs += 1; in ubi_create_volume()
261 vol->last_eb_bytes = vol->usable_leb_size; in ubi_create_volume()
266 ubi->volumes[vol_id] = vol; in ubi_create_volume()
271 cdev_init(&vol->cdev, &ubi_vol_cdev_operations); in ubi_create_volume()
272 vol->cdev.owner = THIS_MODULE; in ubi_create_volume()
274 vol->dev.devt = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1); in ubi_create_volume()
275 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); in ubi_create_volume()
276 err = cdev_device_add(&vol->cdev, &vol->dev); in ubi_create_volume()
284 vtbl_rec.reserved_pebs = cpu_to_be32(vol->reserved_pebs); in ubi_create_volume()
285 vtbl_rec.alignment = cpu_to_be32(vol->alignment); in ubi_create_volume()
286 vtbl_rec.data_pad = cpu_to_be32(vol->data_pad); in ubi_create_volume()
287 vtbl_rec.name_len = cpu_to_be16(vol->name_len); in ubi_create_volume()
288 if (vol->vol_type == UBI_DYNAMIC_VOLUME) in ubi_create_volume()
293 if (vol->skip_check) in ubi_create_volume()
296 memcpy(vtbl_rec.name, vol->name, vol->name_len); in ubi_create_volume()
302 ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED); in ubi_create_volume()
312 cdev_device_del(&vol->cdev, &vol->dev); in ubi_create_volume()
321 ubi->rsvd_pebs -= vol->reserved_pebs; in ubi_create_volume()
322 ubi->avail_pebs += vol->reserved_pebs; in ubi_create_volume()
325 put_device(&vol->dev); in ubi_create_volume()
342 struct ubi_volume *vol = desc->vol; in ubi_remove_volume() local
343 struct ubi_device *ubi = vol->ubi; in ubi_remove_volume()
344 int i, err, vol_id = vol->vol_id, reserved_pebs = vol->reserved_pebs; in ubi_remove_volume()
348 ubi_assert(vol == ubi->volumes[vol_id]); in ubi_remove_volume()
354 if (vol->ref_count > 1) { in ubi_remove_volume()
371 for (i = 0; i < vol->reserved_pebs; i++) { in ubi_remove_volume()
372 err = ubi_eba_unmap_leb(ubi, vol, i); in ubi_remove_volume()
377 cdev_device_del(&vol->cdev, &vol->dev); in ubi_remove_volume()
378 put_device(&vol->dev); in ubi_remove_volume()
387 ubi_volume_notify(ubi, vol, UBI_VOLUME_REMOVED); in ubi_remove_volume()
396 ubi->volumes[vol_id] = vol; in ubi_remove_volume()
414 struct ubi_volume *vol = desc->vol; in ubi_resize_volume() local
415 struct ubi_device *ubi = vol->ubi; in ubi_resize_volume()
418 int vol_id = vol->vol_id; in ubi_resize_volume()
424 ubi->ubi_num, vol_id, vol->reserved_pebs, reserved_pebs); in ubi_resize_volume()
426 if (vol->vol_type == UBI_STATIC_VOLUME && in ubi_resize_volume()
427 reserved_pebs < vol->used_ebs) { in ubi_resize_volume()
429 reserved_pebs, vol->used_ebs); in ubi_resize_volume()
434 if (reserved_pebs == vol->reserved_pebs) in ubi_resize_volume()
437 new_eba_tbl = ubi_eba_create_table(vol, reserved_pebs); in ubi_resize_volume()
442 if (vol->ref_count > 1) { in ubi_resize_volume()
450 pebs = reserved_pebs - vol->reserved_pebs; in ubi_resize_volume()
465 ubi_eba_copy_table(vol, new_eba_tbl, vol->reserved_pebs); in ubi_resize_volume()
466 ubi_eba_replace_table(vol, new_eba_tbl); in ubi_resize_volume()
472 err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i); in ubi_resize_volume()
480 ubi_eba_copy_table(vol, new_eba_tbl, reserved_pebs); in ubi_resize_volume()
481 ubi_eba_replace_table(vol, new_eba_tbl); in ubi_resize_volume()
503 vol->reserved_pebs = reserved_pebs; in ubi_resize_volume()
504 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in ubi_resize_volume()
505 vol->used_ebs = reserved_pebs; in ubi_resize_volume()
506 vol->last_eb_bytes = vol->usable_leb_size; in ubi_resize_volume()
507 vol->used_bytes = in ubi_resize_volume()
508 (long long)vol->used_ebs * vol->usable_leb_size; in ubi_resize_volume()
511 ubi_volume_notify(ubi, vol, UBI_VOLUME_RESIZED); in ubi_resize_volume()
551 struct ubi_volume *vol = re->desc->vol; in ubi_rename_volumes() local
554 vol->name_len = re->new_name_len; in ubi_rename_volumes()
555 memcpy(vol->name, re->new_name, re->new_name_len + 1); in ubi_rename_volumes()
557 ubi_volume_notify(ubi, vol, UBI_VOLUME_RENAMED); in ubi_rename_volumes()
575 int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol) in ubi_add_volume() argument
577 int err, vol_id = vol->vol_id; in ubi_add_volume()
583 cdev_init(&vol->cdev, &ubi_vol_cdev_operations); in ubi_add_volume()
584 vol->cdev.owner = THIS_MODULE; in ubi_add_volume()
585 dev = MKDEV(MAJOR(ubi->cdev.dev), vol->vol_id + 1); in ubi_add_volume()
586 err = cdev_add(&vol->cdev, dev, 1); in ubi_add_volume()
593 vol->dev.release = vol_release; in ubi_add_volume()
594 vol->dev.parent = &ubi->dev; in ubi_add_volume()
595 vol->dev.devt = dev; in ubi_add_volume()
596 vol->dev.class = &ubi_class; in ubi_add_volume()
597 vol->dev.groups = volume_dev_groups; in ubi_add_volume()
598 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); in ubi_add_volume()
599 err = device_register(&vol->dev); in ubi_add_volume()
607 cdev_del(&vol->cdev); in ubi_add_volume()
619 void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol) in ubi_free_volume() argument
621 dbg_gen("free volume %d", vol->vol_id); in ubi_free_volume()
623 ubi->volumes[vol->vol_id] = NULL; in ubi_free_volume()
624 cdev_del(&vol->cdev); in ubi_free_volume()
625 device_unregister(&vol->dev); in ubi_free_volume()
639 const struct ubi_volume *vol; in self_check_volume() local
645 vol = ubi->volumes[idx]; in self_check_volume()
647 if (!vol) { in self_check_volume()
656 if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 || in self_check_volume()
657 vol->name_len < 0) { in self_check_volume()
661 if (vol->alignment > ubi->leb_size || vol->alignment == 0) { in self_check_volume()
666 n = vol->alignment & (ubi->min_io_size - 1); in self_check_volume()
667 if (vol->alignment != 1 && n) { in self_check_volume()
672 n = ubi->leb_size % vol->alignment; in self_check_volume()
673 if (vol->data_pad != n) { in self_check_volume()
678 if (vol->vol_type != UBI_DYNAMIC_VOLUME && in self_check_volume()
679 vol->vol_type != UBI_STATIC_VOLUME) { in self_check_volume()
684 if (vol->upd_marker && vol->corrupted) { in self_check_volume()
689 if (vol->reserved_pebs > ubi->good_peb_count) { in self_check_volume()
694 n = ubi->leb_size - vol->data_pad; in self_check_volume()
695 if (vol->usable_leb_size != ubi->leb_size - vol->data_pad) { in self_check_volume()
700 if (vol->name_len > UBI_VOL_NAME_MAX) { in self_check_volume()
706 n = strnlen(vol->name, vol->name_len + 1); in self_check_volume()
707 if (n != vol->name_len) { in self_check_volume()
712 n = (long long)vol->used_ebs * vol->usable_leb_size; in self_check_volume()
713 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in self_check_volume()
714 if (vol->corrupted) { in self_check_volume()
718 if (vol->used_ebs != vol->reserved_pebs) { in self_check_volume()
722 if (vol->last_eb_bytes != vol->usable_leb_size) { in self_check_volume()
726 if (vol->used_bytes != n) { in self_check_volume()
731 if (vol->skip_check) { in self_check_volume()
736 if (vol->used_ebs < 0 || vol->used_ebs > vol->reserved_pebs) { in self_check_volume()
740 if (vol->last_eb_bytes < 0 || in self_check_volume()
741 vol->last_eb_bytes > vol->usable_leb_size) { in self_check_volume()
745 if (vol->used_bytes < 0 || vol->used_bytes > n || in self_check_volume()
746 vol->used_bytes < n - vol->usable_leb_size) { in self_check_volume()
762 if (alignment != vol->alignment || data_pad != vol->data_pad || in self_check_volume()
763 upd_marker != vol->upd_marker || vol_type != vol->vol_type || in self_check_volume()
764 name_len != vol->name_len || strncmp(name, vol->name, name_len)) { in self_check_volume()
774 if (vol) in self_check_volume()
775 ubi_dump_vol_info(vol); in self_check_volume()