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