Lines Matching defs:vol

58 	struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev);
59 struct ubi_device *ubi = vol->ubi;
62 if (!ubi->volumes[vol->vol_id] || ubi->volumes[vol->vol_id]->is_dead) {
67 vol->ref_count += 1;
71 ret = sprintf(buf, "%d\n", vol->reserved_pebs);
75 if (vol->vol_type == UBI_DYNAMIC_VOLUME)
81 ret = sprintf(buf, "%s\n", vol->name);
83 ret = sprintf(buf, "%d\n", vol->corrupted);
85 ret = sprintf(buf, "%d\n", vol->alignment);
87 ret = sprintf(buf, "%d\n", vol->usable_leb_size);
89 ret = sprintf(buf, "%lld\n", vol->used_bytes);
91 ret = sprintf(buf, "%d\n", vol->upd_marker);
98 vol->ref_count -= 1;
99 ubi_assert(vol->ref_count >= 0);
120 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev);
122 ubi_eba_replace_table(vol, NULL);
123 ubi_fastmap_destroy_checkmap(vol);
124 kfree(vol);
127 static struct fwnode_handle *find_volume_fwnode(struct ubi_volume *vol)
133 fw_vols = device_get_named_child_node(vol->dev.parent->parent, "volumes");
139 strncmp(volname, vol->name, vol->name_len))
143 vol->vol_id != volid)
166 struct ubi_volume *vol;
173 vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL);
174 if (!vol)
177 device_initialize(&vol->dev);
178 vol->dev.release = vol_release;
179 vol->dev.parent = &ubi->dev;
180 vol->dev.class = &ubi_class;
181 vol->dev.groups = volume_dev_groups;
184 vol->skip_check = 1;
226 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment;
227 vol->reserved_pebs = div_u64(req->bytes + vol->usable_leb_size - 1,
228 vol->usable_leb_size);
231 if (vol->reserved_pebs > ubi->avail_pebs) {
240 ubi->avail_pebs -= vol->reserved_pebs;
241 ubi->rsvd_pebs += vol->reserved_pebs;
244 vol->vol_id = vol_id;
245 vol->alignment = req->alignment;
246 vol->data_pad = ubi->leb_size % vol->alignment;
247 vol->vol_type = req->vol_type;
248 vol->name_len = req->name_len;
249 memcpy(vol->name, req->name, vol->name_len);
250 vol->ubi = ubi;
251 device_set_node(&vol->dev, find_volume_fwnode(vol));
261 eba_tbl = ubi_eba_create_table(vol, vol->reserved_pebs);
267 ubi_eba_replace_table(vol, eba_tbl);
269 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
270 vol->used_ebs = vol->reserved_pebs;
271 vol->last_eb_bytes = vol->usable_leb_size;
272 vol->used_bytes =
273 (long long)vol->used_ebs * vol->usable_leb_size;
275 vol->used_ebs = div_u64_rem(vol->used_bytes,
276 vol->usable_leb_size,
277 &vol->last_eb_bytes);
278 if (vol->last_eb_bytes != 0)
279 vol->used_ebs += 1;
281 vol->last_eb_bytes = vol->usable_leb_size;
286 ubi->volumes[vol_id] = vol;
291 cdev_init(&vol->cdev, &ubi_vol_cdev_operations);
292 vol->cdev.owner = THIS_MODULE;
294 vol->dev.devt = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1);
295 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id);
296 err = cdev_device_add(&vol->cdev, &vol->dev);
304 vtbl_rec.reserved_pebs = cpu_to_be32(vol->reserved_pebs);
305 vtbl_rec.alignment = cpu_to_be32(vol->alignment);
306 vtbl_rec.data_pad = cpu_to_be32(vol->data_pad);
307 vtbl_rec.name_len = cpu_to_be16(vol->name_len);
308 if (vol->vol_type == UBI_DYNAMIC_VOLUME)
313 if (vol->skip_check)
316 memcpy(vtbl_rec.name, vol->name, vol->name_len);
322 ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED);
332 cdev_device_del(&vol->cdev, &vol->dev);
340 ubi->rsvd_pebs -= vol->reserved_pebs;
341 ubi->avail_pebs += vol->reserved_pebs;
344 put_device(&vol->dev);
361 struct ubi_volume *vol = desc->vol;
362 struct ubi_device *ubi = vol->ubi;
363 int i, err, vol_id = vol->vol_id, reserved_pebs = vol->reserved_pebs;
367 ubi_assert(vol == ubi->volumes[vol_id]);
373 if (vol->ref_count > 1) {
388 vol->is_dead = true;
391 ubi_volume_notify(ubi, vol, UBI_VOLUME_SHUTDOWN);
403 for (i = 0; i < vol->reserved_pebs; i++) {
404 err = ubi_eba_unmap_leb(ubi, vol, i);
409 cdev_device_del(&vol->cdev, &vol->dev);
410 put_device(&vol->dev);
419 ubi_volume_notify(ubi, vol, UBI_VOLUME_REMOVED);
428 ubi->volumes[vol_id] = vol;
446 struct ubi_volume *vol = desc->vol;
447 struct ubi_device *ubi = vol->ubi;
451 int vol_id = vol->vol_id;
457 ubi->ubi_num, vol_id, vol->reserved_pebs, reserved_pebs);
459 if (vol->vol_type == UBI_STATIC_VOLUME &&
460 reserved_pebs < vol->used_ebs) {
462 reserved_pebs, vol->used_ebs);
467 if (reserved_pebs == vol->reserved_pebs)
470 new_eba_tbl = ubi_eba_create_table(vol, reserved_pebs);
475 if (vol->ref_count > 1) {
483 pebs = reserved_pebs - vol->reserved_pebs;
499 ubi_eba_copy_table(vol, new_eba_tbl, vol->reserved_pebs);
500 old_eba_tbl = vol->eba_tbl;
501 vol->eba_tbl = new_eba_tbl;
502 vol->reserved_pebs = reserved_pebs;
508 err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i);
516 ubi_eba_copy_table(vol, new_eba_tbl, reserved_pebs);
517 old_eba_tbl = vol->eba_tbl;
518 vol->eba_tbl = new_eba_tbl;
519 vol->reserved_pebs = reserved_pebs;
541 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
542 vol->used_ebs = reserved_pebs;
543 vol->last_eb_bytes = vol->usable_leb_size;
544 vol->used_bytes =
545 (long long)vol->used_ebs * vol->usable_leb_size;
550 ubi_volume_notify(ubi, vol, UBI_VOLUME_RESIZED);
556 vol->reserved_pebs = reserved_pebs - pebs;
560 ubi_eba_copy_table(vol, old_eba_tbl, vol->reserved_pebs);
562 ubi_eba_copy_table(vol, old_eba_tbl, reserved_pebs);
563 vol->eba_tbl = old_eba_tbl;
594 struct ubi_volume *vol = re->desc->vol;
597 vol->name_len = re->new_name_len;
598 memcpy(vol->name, re->new_name, re->new_name_len + 1);
600 ubi_volume_notify(ubi, vol, UBI_VOLUME_RENAMED);
612 * @vol: volume description object
618 int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol)
620 int err, vol_id = vol->vol_id;
626 cdev_init(&vol->cdev, &ubi_vol_cdev_operations);
627 vol->cdev.owner = THIS_MODULE;
628 dev = MKDEV(MAJOR(ubi->cdev.dev), vol->vol_id + 1);
629 err = cdev_add(&vol->cdev, dev, 1);
633 vol_release(&vol->dev);
637 vol->dev.release = vol_release;
638 vol->dev.parent = &ubi->dev;
639 vol->dev.devt = dev;
640 vol->dev.class = &ubi_class;
641 vol->dev.groups = volume_dev_groups;
642 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id);
643 device_set_node(&vol->dev, find_volume_fwnode(vol));
644 err = device_register(&vol->dev);
646 cdev_del(&vol->cdev);
647 put_device(&vol->dev);
658 * @vol: volume description object
660 * This function frees all resources for volume @vol but does not remove it.
663 void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol)
665 dbg_gen("free volume %d", vol->vol_id);
667 ubi->volumes[vol->vol_id] = NULL;
668 cdev_del(&vol->cdev);
669 device_unregister(&vol->dev);
683 const struct ubi_volume *vol;
689 vol = ubi->volumes[idx];
691 if (!vol) {
700 if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 ||
701 vol->name_len < 0) {
705 if (vol->alignment > ubi->leb_size || vol->alignment == 0) {
710 n = vol->alignment & (ubi->min_io_size - 1);
711 if (vol->alignment != 1 && n) {
716 n = ubi->leb_size % vol->alignment;
717 if (vol->data_pad != n) {
722 if (vol->vol_type != UBI_DYNAMIC_VOLUME &&
723 vol->vol_type != UBI_STATIC_VOLUME) {
728 if (vol->upd_marker && vol->corrupted) {
733 if (vol->reserved_pebs > ubi->good_peb_count) {
738 n = ubi->leb_size - vol->data_pad;
739 if (vol->usable_leb_size != ubi->leb_size - vol->data_pad) {
744 if (vol->name_len > UBI_VOL_NAME_MAX) {
750 n = strnlen(vol->name, vol->name_len + 1);
751 if (n != vol->name_len) {
756 n = (long long)vol->used_ebs * vol->usable_leb_size;
757 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
758 if (vol->corrupted) {
762 if (vol->used_ebs != vol->reserved_pebs) {
766 if (vol->last_eb_bytes != vol->usable_leb_size) {
770 if (vol->used_bytes != n) {
775 if (vol->skip_check) {
780 if (vol->used_ebs < 0 || vol->used_ebs > vol->reserved_pebs) {
784 if (vol->last_eb_bytes < 0 ||
785 vol->last_eb_bytes > vol->usable_leb_size) {
789 if (vol->used_bytes < 0 || vol->used_bytes > n ||
790 vol->used_bytes < n - vol->usable_leb_size) {
806 if (alignment != vol->alignment || data_pad != vol->data_pad ||
807 upd_marker != vol->upd_marker || vol_type != vol->vol_type ||
808 name_len != vol->name_len || strncmp(name, vol->name, name_len)) {
818 if (vol)
819 ubi_dump_vol_info(vol);