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()
126 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev); in vol_release() local
128 kfree(vol->eba_tbl); in vol_release()
129 kfree(vol); in vol_release()
144 static int volume_sysfs_init(struct ubi_device *ubi, struct ubi_volume *vol) in volume_sysfs_init() argument
148 err = device_create_file(&vol->dev, &attr_vol_reserved_ebs); in volume_sysfs_init()
151 err = device_create_file(&vol->dev, &attr_vol_type); in volume_sysfs_init()
154 err = device_create_file(&vol->dev, &attr_vol_name); in volume_sysfs_init()
157 err = device_create_file(&vol->dev, &attr_vol_corrupted); in volume_sysfs_init()
160 err = device_create_file(&vol->dev, &attr_vol_alignment); in volume_sysfs_init()
163 err = device_create_file(&vol->dev, &attr_vol_usable_eb_size); in volume_sysfs_init()
166 err = device_create_file(&vol->dev, &attr_vol_data_bytes); in volume_sysfs_init()
169 err = device_create_file(&vol->dev, &attr_vol_upd_marker); in volume_sysfs_init()
177 static void volume_sysfs_close(struct ubi_volume *vol) in volume_sysfs_close() argument
179 device_remove_file(&vol->dev, &attr_vol_upd_marker); in volume_sysfs_close()
180 device_remove_file(&vol->dev, &attr_vol_data_bytes); in volume_sysfs_close()
181 device_remove_file(&vol->dev, &attr_vol_usable_eb_size); in volume_sysfs_close()
182 device_remove_file(&vol->dev, &attr_vol_alignment); in volume_sysfs_close()
183 device_remove_file(&vol->dev, &attr_vol_corrupted); in volume_sysfs_close()
184 device_remove_file(&vol->dev, &attr_vol_name); in volume_sysfs_close()
185 device_remove_file(&vol->dev, &attr_vol_type); in volume_sysfs_close()
186 device_remove_file(&vol->dev, &attr_vol_reserved_ebs); in volume_sysfs_close()
187 device_unregister(&vol->dev); in volume_sysfs_close()
204 struct ubi_volume *vol; in ubi_create_volume() local
211 vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL); in ubi_create_volume()
212 if (!vol) in ubi_create_volume()
255 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment; in ubi_create_volume()
256 vol->reserved_pebs += div_u64(req->bytes + vol->usable_leb_size - 1, in ubi_create_volume()
257 vol->usable_leb_size); in ubi_create_volume()
260 if (vol->reserved_pebs > ubi->avail_pebs) { in ubi_create_volume()
269 ubi->avail_pebs -= vol->reserved_pebs; in ubi_create_volume()
270 ubi->rsvd_pebs += vol->reserved_pebs; in ubi_create_volume()
273 vol->vol_id = vol_id; in ubi_create_volume()
274 vol->alignment = req->alignment; in ubi_create_volume()
275 vol->data_pad = ubi->leb_size % vol->alignment; in ubi_create_volume()
276 vol->vol_type = req->vol_type; in ubi_create_volume()
277 vol->name_len = req->name_len; in ubi_create_volume()
278 memcpy(vol->name, req->name, vol->name_len); in ubi_create_volume()
279 vol->ubi = ubi; in ubi_create_volume()
289 vol->eba_tbl = kmalloc(vol->reserved_pebs * sizeof(int), GFP_KERNEL); in ubi_create_volume()
290 if (!vol->eba_tbl) { in ubi_create_volume()
295 for (i = 0; i < vol->reserved_pebs; i++) in ubi_create_volume()
296 vol->eba_tbl[i] = UBI_LEB_UNMAPPED; in ubi_create_volume()
298 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in ubi_create_volume()
299 vol->used_ebs = vol->reserved_pebs; in ubi_create_volume()
300 vol->last_eb_bytes = vol->usable_leb_size; in ubi_create_volume()
301 vol->used_bytes = in ubi_create_volume()
302 (long long)vol->used_ebs * vol->usable_leb_size; in ubi_create_volume()
304 vol->used_ebs = div_u64_rem(vol->used_bytes, in ubi_create_volume()
305 vol->usable_leb_size, in ubi_create_volume()
306 &vol->last_eb_bytes); in ubi_create_volume()
307 if (vol->last_eb_bytes != 0) in ubi_create_volume()
308 vol->used_ebs += 1; in ubi_create_volume()
310 vol->last_eb_bytes = vol->usable_leb_size; in ubi_create_volume()
314 cdev_init(&vol->cdev, &ubi_vol_cdev_operations); in ubi_create_volume()
315 vol->cdev.owner = THIS_MODULE; in ubi_create_volume()
317 err = cdev_add(&vol->cdev, dev, 1); in ubi_create_volume()
323 vol->dev.release = vol_release; in ubi_create_volume()
324 vol->dev.parent = &ubi->dev; in ubi_create_volume()
325 vol->dev.devt = dev; in ubi_create_volume()
326 vol->dev.class = ubi_class; in ubi_create_volume()
328 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); in ubi_create_volume()
329 err = device_register(&vol->dev); in ubi_create_volume()
335 err = volume_sysfs_init(ubi, vol); in ubi_create_volume()
341 vtbl_rec.reserved_pebs = cpu_to_be32(vol->reserved_pebs); in ubi_create_volume()
342 vtbl_rec.alignment = cpu_to_be32(vol->alignment); in ubi_create_volume()
343 vtbl_rec.data_pad = cpu_to_be32(vol->data_pad); in ubi_create_volume()
344 vtbl_rec.name_len = cpu_to_be16(vol->name_len); in ubi_create_volume()
345 if (vol->vol_type == UBI_DYNAMIC_VOLUME) in ubi_create_volume()
349 memcpy(vtbl_rec.name, vol->name, vol->name_len); in ubi_create_volume()
356 ubi->volumes[vol_id] = vol; in ubi_create_volume()
360 ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED); in ubi_create_volume()
374 get_device(&vol->dev); in ubi_create_volume()
375 volume_sysfs_close(vol); in ubi_create_volume()
377 cdev_del(&vol->cdev); in ubi_create_volume()
380 kfree(vol->eba_tbl); in ubi_create_volume()
383 ubi->rsvd_pebs -= vol->reserved_pebs; in ubi_create_volume()
384 ubi->avail_pebs += vol->reserved_pebs; in ubi_create_volume()
388 kfree(vol); in ubi_create_volume()
390 put_device(&vol->dev); in ubi_create_volume()
407 struct ubi_volume *vol = desc->vol; in ubi_remove_volume() local
408 struct ubi_device *ubi = vol->ubi; in ubi_remove_volume()
409 int i, err, vol_id = vol->vol_id, reserved_pebs = vol->reserved_pebs; in ubi_remove_volume()
413 ubi_assert(vol == ubi->volumes[vol_id]); in ubi_remove_volume()
419 if (vol->ref_count > 1) { in ubi_remove_volume()
436 for (i = 0; i < vol->reserved_pebs; i++) { in ubi_remove_volume()
437 err = ubi_eba_unmap_leb(ubi, vol, i); in ubi_remove_volume()
442 cdev_del(&vol->cdev); in ubi_remove_volume()
443 volume_sysfs_close(vol); in ubi_remove_volume()
452 ubi_volume_notify(ubi, vol, UBI_VOLUME_REMOVED); in ubi_remove_volume()
461 ubi->volumes[vol_id] = vol; in ubi_remove_volume()
479 struct ubi_volume *vol = desc->vol; in ubi_resize_volume() local
480 struct ubi_device *ubi = vol->ubi; in ubi_resize_volume()
482 int vol_id = vol->vol_id; in ubi_resize_volume()
488 ubi->ubi_num, vol_id, vol->reserved_pebs, reserved_pebs); in ubi_resize_volume()
490 if (vol->vol_type == UBI_STATIC_VOLUME && in ubi_resize_volume()
491 reserved_pebs < vol->used_ebs) { in ubi_resize_volume()
493 reserved_pebs, vol->used_ebs); in ubi_resize_volume()
498 if (reserved_pebs == vol->reserved_pebs) in ubi_resize_volume()
509 if (vol->ref_count > 1) { in ubi_resize_volume()
517 pebs = reserved_pebs - vol->reserved_pebs; in ubi_resize_volume()
532 for (i = 0; i < vol->reserved_pebs; i++) in ubi_resize_volume()
533 new_mapping[i] = vol->eba_tbl[i]; in ubi_resize_volume()
534 kfree(vol->eba_tbl); in ubi_resize_volume()
535 vol->eba_tbl = new_mapping; in ubi_resize_volume()
548 err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i); in ubi_resize_volume()
557 new_mapping[i] = vol->eba_tbl[i]; in ubi_resize_volume()
558 kfree(vol->eba_tbl); in ubi_resize_volume()
559 vol->eba_tbl = new_mapping; in ubi_resize_volume()
563 vol->reserved_pebs = reserved_pebs; in ubi_resize_volume()
564 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in ubi_resize_volume()
565 vol->used_ebs = reserved_pebs; in ubi_resize_volume()
566 vol->last_eb_bytes = vol->usable_leb_size; in ubi_resize_volume()
567 vol->used_bytes = in ubi_resize_volume()
568 (long long)vol->used_ebs * vol->usable_leb_size; in ubi_resize_volume()
571 ubi_volume_notify(ubi, vol, UBI_VOLUME_RESIZED); in ubi_resize_volume()
611 struct ubi_volume *vol = re->desc->vol; in ubi_rename_volumes() local
614 vol->name_len = re->new_name_len; in ubi_rename_volumes()
615 memcpy(vol->name, re->new_name, re->new_name_len + 1); in ubi_rename_volumes()
617 ubi_volume_notify(ubi, vol, UBI_VOLUME_RENAMED); in ubi_rename_volumes()
635 int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol) in ubi_add_volume() argument
637 int err, vol_id = vol->vol_id; in ubi_add_volume()
643 cdev_init(&vol->cdev, &ubi_vol_cdev_operations); in ubi_add_volume()
644 vol->cdev.owner = THIS_MODULE; in ubi_add_volume()
645 dev = MKDEV(MAJOR(ubi->cdev.dev), vol->vol_id + 1); in ubi_add_volume()
646 err = cdev_add(&vol->cdev, dev, 1); in ubi_add_volume()
653 vol->dev.release = vol_release; in ubi_add_volume()
654 vol->dev.parent = &ubi->dev; in ubi_add_volume()
655 vol->dev.devt = dev; in ubi_add_volume()
656 vol->dev.class = ubi_class; in ubi_add_volume()
657 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); in ubi_add_volume()
658 err = device_register(&vol->dev); in ubi_add_volume()
662 err = volume_sysfs_init(ubi, vol); in ubi_add_volume()
664 cdev_del(&vol->cdev); in ubi_add_volume()
665 volume_sysfs_close(vol); in ubi_add_volume()
673 cdev_del(&vol->cdev); in ubi_add_volume()
685 void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol) in ubi_free_volume() argument
687 dbg_gen("free volume %d", vol->vol_id); in ubi_free_volume()
689 ubi->volumes[vol->vol_id] = NULL; in ubi_free_volume()
690 cdev_del(&vol->cdev); in ubi_free_volume()
691 volume_sysfs_close(vol); in ubi_free_volume()
705 const struct ubi_volume *vol; in self_check_volume() local
711 vol = ubi->volumes[idx]; in self_check_volume()
713 if (!vol) { in self_check_volume()
722 if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 || in self_check_volume()
723 vol->name_len < 0) { in self_check_volume()
727 if (vol->alignment > ubi->leb_size || vol->alignment == 0) { in self_check_volume()
732 n = vol->alignment & (ubi->min_io_size - 1); in self_check_volume()
733 if (vol->alignment != 1 && n) { in self_check_volume()
738 n = ubi->leb_size % vol->alignment; in self_check_volume()
739 if (vol->data_pad != n) { in self_check_volume()
744 if (vol->vol_type != UBI_DYNAMIC_VOLUME && in self_check_volume()
745 vol->vol_type != UBI_STATIC_VOLUME) { in self_check_volume()
750 if (vol->upd_marker && vol->corrupted) { in self_check_volume()
755 if (vol->reserved_pebs > ubi->good_peb_count) { in self_check_volume()
760 n = ubi->leb_size - vol->data_pad; in self_check_volume()
761 if (vol->usable_leb_size != ubi->leb_size - vol->data_pad) { in self_check_volume()
766 if (vol->name_len > UBI_VOL_NAME_MAX) { in self_check_volume()
772 n = strnlen(vol->name, vol->name_len + 1); in self_check_volume()
773 if (n != vol->name_len) { in self_check_volume()
778 n = (long long)vol->used_ebs * vol->usable_leb_size; in self_check_volume()
779 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in self_check_volume()
780 if (vol->corrupted) { in self_check_volume()
784 if (vol->used_ebs != vol->reserved_pebs) { in self_check_volume()
788 if (vol->last_eb_bytes != vol->usable_leb_size) { in self_check_volume()
792 if (vol->used_bytes != n) { in self_check_volume()
797 if (vol->used_ebs < 0 || vol->used_ebs > vol->reserved_pebs) { in self_check_volume()
801 if (vol->last_eb_bytes < 0 || in self_check_volume()
802 vol->last_eb_bytes > vol->usable_leb_size) { in self_check_volume()
806 if (vol->used_bytes < 0 || vol->used_bytes > n || in self_check_volume()
807 vol->used_bytes < n - vol->usable_leb_size) { in self_check_volume()
823 if (alignment != vol->alignment || data_pad != vol->data_pad || in self_check_volume()
824 upd_marker != vol->upd_marker || vol_type != vol->vol_type || in self_check_volume()
825 name_len != vol->name_len || strncmp(name, vol->name, name_len)) { in self_check_volume()
835 if (vol) in self_check_volume()
836 ubi_dump_vol_info(vol); in self_check_volume()