Lines Matching +full:ubi +full:- +full:volume +full:-

1 // SPDX-License-Identifier: GPL-2.0-or-later
9 * This file contains implementation of volume creation, deletion, updating and
17 #include "ubi.h"
19 static int self_check_volumes(struct ubi_device *ubi);
24 /* Device attributes corresponding to files in '/<sysfs>/class/ubi/ubiX_Y' */
43 * "Show" method for files in '/<sysfs>/class/ubi/ubiX_Y/'.
46 * A. process 1 opens a sysfs file related to volume Y, say
47 * /<sysfs>/class/ubi/ubiX_Y/reserved_ebs;
48 * B. process 2 removes volume Y;
49 * C. process 1 starts reading the /<sysfs>/class/ubi/ubiX_Y/reserved_ebs file;
51 * In this situation, this function will return %-ENODEV because it will find
52 * out that the volume was removed from the @ubi->volumes array.
59 struct ubi_device *ubi = vol->ubi; in vol_attribute_show() local
61 spin_lock(&ubi->volumes_lock); in vol_attribute_show()
62 if (!ubi->volumes[vol->vol_id] || ubi->volumes[vol->vol_id]->is_dead) { in vol_attribute_show()
63 spin_unlock(&ubi->volumes_lock); in vol_attribute_show()
64 return -ENODEV; in vol_attribute_show()
66 /* Take a reference to prevent volume removal */ in vol_attribute_show()
67 vol->ref_count += 1; in vol_attribute_show()
68 spin_unlock(&ubi->volumes_lock); in vol_attribute_show()
71 ret = sprintf(buf, "%d\n", vol->reserved_pebs); in vol_attribute_show()
75 if (vol->vol_type == UBI_DYNAMIC_VOLUME) in vol_attribute_show()
81 ret = sprintf(buf, "%s\n", vol->name); in vol_attribute_show()
83 ret = sprintf(buf, "%d\n", vol->corrupted); in vol_attribute_show()
85 ret = sprintf(buf, "%d\n", vol->alignment); in vol_attribute_show()
87 ret = sprintf(buf, "%d\n", vol->usable_leb_size); in vol_attribute_show()
89 ret = sprintf(buf, "%lld\n", vol->used_bytes); in vol_attribute_show()
91 ret = sprintf(buf, "%d\n", vol->upd_marker); in vol_attribute_show()
94 ret = -EINVAL; in vol_attribute_show()
96 /* We've done the operation, drop volume and UBI device references */ in vol_attribute_show()
97 spin_lock(&ubi->volumes_lock); in vol_attribute_show()
98 vol->ref_count -= 1; in vol_attribute_show()
99 ubi_assert(vol->ref_count >= 0); in vol_attribute_show()
100 spin_unlock(&ubi->volumes_lock); in vol_attribute_show()
117 /* Release method for volume devices */
133 fw_vols = device_get_named_child_node(vol->dev.parent->parent, "volumes"); in find_volume_fwnode()
139 strncmp(volname, vol->name, vol->name_len)) in find_volume_fwnode()
143 vol->vol_id != volid) in find_volume_fwnode()
153 * ubi_create_volume - create volume.
154 * @ubi: UBI device description object
155 * @req: volume creation request
157 * This function creates volume described by @req. If @req->vol_id id
158 * %UBI_VOL_NUM_AUTO, this function automatically assign ID to the new volume
159 * and saves it in @req->vol_id. Returns zero in case of success and a negative
161 * @ubi->device_mutex locked.
163 int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) in ubi_create_volume() argument
165 int i, err, vol_id = req->vol_id; in ubi_create_volume()
170 if (ubi->ro_mode) in ubi_create_volume()
171 return -EROFS; in ubi_create_volume()
175 return -ENOMEM; in ubi_create_volume()
177 device_initialize(&vol->dev); in ubi_create_volume()
178 vol->dev.release = vol_release; in ubi_create_volume()
179 vol->dev.parent = &ubi->dev; in ubi_create_volume()
180 vol->dev.class = &ubi_class; in ubi_create_volume()
181 vol->dev.groups = volume_dev_groups; in ubi_create_volume()
183 if (req->flags & UBI_VOL_SKIP_CRC_CHECK_FLG) in ubi_create_volume()
184 vol->skip_check = 1; in ubi_create_volume()
186 spin_lock(&ubi->volumes_lock); in ubi_create_volume()
188 /* Find unused volume ID */ in ubi_create_volume()
189 dbg_gen("search for vacant volume ID"); in ubi_create_volume()
190 for (i = 0; i < ubi->vtbl_slots; i++) in ubi_create_volume()
191 if (!ubi->volumes[i]) { in ubi_create_volume()
197 ubi_err(ubi, "out of volume IDs"); in ubi_create_volume()
198 err = -ENFILE; in ubi_create_volume()
201 req->vol_id = vol_id; in ubi_create_volume()
204 dbg_gen("create device %d, volume %d, %llu bytes, type %d, name %s", in ubi_create_volume()
205 ubi->ubi_num, vol_id, (unsigned long long)req->bytes, in ubi_create_volume()
206 (int)req->vol_type, req->name); in ubi_create_volume()
208 /* Ensure that this volume does not exist */ in ubi_create_volume()
209 err = -EEXIST; in ubi_create_volume()
210 if (ubi->volumes[vol_id]) { in ubi_create_volume()
211 ubi_err(ubi, "volume %d already exists", vol_id); in ubi_create_volume()
216 for (i = 0; i < ubi->vtbl_slots; i++) in ubi_create_volume()
217 if (ubi->volumes[i] && !ubi->volumes[i]->is_dead && in ubi_create_volume()
218 ubi->volumes[i]->name_len == req->name_len && in ubi_create_volume()
219 !strcmp(ubi->volumes[i]->name, req->name)) { in ubi_create_volume()
220 ubi_err(ubi, "volume \"%s\" exists (ID %d)", in ubi_create_volume()
221 req->name, i); in ubi_create_volume()
226 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment; in ubi_create_volume()
227 vol->reserved_pebs = div_u64(req->bytes + vol->usable_leb_size - 1, in ubi_create_volume()
228 vol->usable_leb_size); in ubi_create_volume()
231 if (vol->reserved_pebs > ubi->avail_pebs) { in ubi_create_volume()
232 ubi_err(ubi, "not enough PEBs, only %d available", in ubi_create_volume()
233 ubi->avail_pebs); in ubi_create_volume()
234 if (ubi->corr_peb_count) in ubi_create_volume()
235 ubi_err(ubi, "%d PEBs are corrupted and not used", in ubi_create_volume()
236 ubi->corr_peb_count); in ubi_create_volume()
237 err = -ENOSPC; in ubi_create_volume()
240 ubi->avail_pebs -= vol->reserved_pebs; in ubi_create_volume()
241 ubi->rsvd_pebs += vol->reserved_pebs; in ubi_create_volume()
242 spin_unlock(&ubi->volumes_lock); in ubi_create_volume()
244 vol->vol_id = vol_id; in ubi_create_volume()
245 vol->alignment = req->alignment; in ubi_create_volume()
246 vol->data_pad = ubi->leb_size % vol->alignment; in ubi_create_volume()
247 vol->vol_type = req->vol_type; in ubi_create_volume()
248 vol->name_len = req->name_len; in ubi_create_volume()
249 memcpy(vol->name, req->name, vol->name_len); in ubi_create_volume()
250 vol->ubi = ubi; in ubi_create_volume()
251 device_set_node(&vol->dev, find_volume_fwnode(vol)); in ubi_create_volume()
255 * to the same volume ID. in ubi_create_volume()
257 err = ubi_wl_flush(ubi, vol_id, UBI_ALL); in ubi_create_volume()
261 eba_tbl = ubi_eba_create_table(vol, vol->reserved_pebs); in ubi_create_volume()
269 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in ubi_create_volume()
270 vol->used_ebs = vol->reserved_pebs; in ubi_create_volume()
271 vol->last_eb_bytes = vol->usable_leb_size; in ubi_create_volume()
272 vol->used_bytes = in ubi_create_volume()
273 (long long)vol->used_ebs * vol->usable_leb_size; in ubi_create_volume()
275 vol->used_ebs = div_u64_rem(vol->used_bytes, in ubi_create_volume()
276 vol->usable_leb_size, in ubi_create_volume()
277 &vol->last_eb_bytes); in ubi_create_volume()
278 if (vol->last_eb_bytes != 0) in ubi_create_volume()
279 vol->used_ebs += 1; in ubi_create_volume()
281 vol->last_eb_bytes = vol->usable_leb_size; in ubi_create_volume()
284 /* Make volume "available" before it becomes accessible via sysfs */ in ubi_create_volume()
285 spin_lock(&ubi->volumes_lock); in ubi_create_volume()
286 ubi->volumes[vol_id] = vol; in ubi_create_volume()
287 ubi->vol_count += 1; in ubi_create_volume()
288 spin_unlock(&ubi->volumes_lock); in ubi_create_volume()
290 /* Register character device for the volume */ in ubi_create_volume()
291 cdev_init(&vol->cdev, &ubi_vol_cdev_operations); in ubi_create_volume()
292 vol->cdev.owner = THIS_MODULE; in ubi_create_volume()
294 vol->dev.devt = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1); in ubi_create_volume()
295 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); in ubi_create_volume()
296 err = cdev_device_add(&vol->cdev, &vol->dev); in ubi_create_volume()
298 ubi_err(ubi, "cannot add device"); in ubi_create_volume()
302 /* Fill volume table record */ in ubi_create_volume()
304 vtbl_rec.reserved_pebs = cpu_to_be32(vol->reserved_pebs); in ubi_create_volume()
305 vtbl_rec.alignment = cpu_to_be32(vol->alignment); in ubi_create_volume()
306 vtbl_rec.data_pad = cpu_to_be32(vol->data_pad); in ubi_create_volume()
307 vtbl_rec.name_len = cpu_to_be16(vol->name_len); in ubi_create_volume()
308 if (vol->vol_type == UBI_DYNAMIC_VOLUME) in ubi_create_volume()
313 if (vol->skip_check) in ubi_create_volume()
316 memcpy(vtbl_rec.name, vol->name, vol->name_len); in ubi_create_volume()
318 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); in ubi_create_volume()
322 ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED); in ubi_create_volume()
323 self_check_volumes(ubi); in ubi_create_volume()
328 * We have registered our device, we should not free the volume in ubi_create_volume()
329 * description object in this function in case of an error - it is in ubi_create_volume()
332 cdev_device_del(&vol->cdev, &vol->dev); in ubi_create_volume()
334 spin_lock(&ubi->volumes_lock); in ubi_create_volume()
335 ubi->volumes[vol_id] = NULL; in ubi_create_volume()
336 ubi->vol_count -= 1; in ubi_create_volume()
337 spin_unlock(&ubi->volumes_lock); in ubi_create_volume()
339 spin_lock(&ubi->volumes_lock); in ubi_create_volume()
340 ubi->rsvd_pebs -= vol->reserved_pebs; in ubi_create_volume()
341 ubi->avail_pebs += vol->reserved_pebs; in ubi_create_volume()
343 spin_unlock(&ubi->volumes_lock); in ubi_create_volume()
344 put_device(&vol->dev); in ubi_create_volume()
345 ubi_err(ubi, "cannot create volume %d, error %d", vol_id, err); in ubi_create_volume()
350 * ubi_remove_volume - remove volume.
351 * @desc: volume descriptor
352 * @no_vtbl: do not change volume table if not zero
354 * This function removes volume described by @desc. The volume has to be opened
356 * code in case of failure. The caller has to have the @ubi->device_mutex
361 struct ubi_volume *vol = desc->vol; in ubi_remove_volume()
362 struct ubi_device *ubi = vol->ubi; in ubi_remove_volume() local
363 int i, err, vol_id = vol->vol_id, reserved_pebs = vol->reserved_pebs; in ubi_remove_volume()
365 dbg_gen("remove device %d, volume %d", ubi->ubi_num, vol_id); in ubi_remove_volume()
366 ubi_assert(desc->mode == UBI_EXCLUSIVE); in ubi_remove_volume()
367 ubi_assert(vol == ubi->volumes[vol_id]); in ubi_remove_volume()
369 if (ubi->ro_mode) in ubi_remove_volume()
370 return -EROFS; in ubi_remove_volume()
372 spin_lock(&ubi->volumes_lock); in ubi_remove_volume()
373 if (vol->ref_count > 1) { in ubi_remove_volume()
375 * The volume is busy, probably someone is reading one of its in ubi_remove_volume()
378 err = -EBUSY; in ubi_remove_volume()
383 * Mark volume as dead at this point to prevent that anyone in ubi_remove_volume()
384 * can take a reference to the volume from now on. in ubi_remove_volume()
388 vol->is_dead = true; in ubi_remove_volume()
389 spin_unlock(&ubi->volumes_lock); in ubi_remove_volume()
391 ubi_volume_notify(ubi, vol, UBI_VOLUME_SHUTDOWN); in ubi_remove_volume()
393 spin_lock(&ubi->volumes_lock); in ubi_remove_volume()
394 ubi->volumes[vol_id] = NULL; in ubi_remove_volume()
395 spin_unlock(&ubi->volumes_lock); in ubi_remove_volume()
398 err = ubi_change_vtbl_record(ubi, vol_id, NULL); in ubi_remove_volume()
403 for (i = 0; i < vol->reserved_pebs; i++) { in ubi_remove_volume()
404 err = ubi_eba_unmap_leb(ubi, vol, i); in ubi_remove_volume()
409 cdev_device_del(&vol->cdev, &vol->dev); in ubi_remove_volume()
410 put_device(&vol->dev); in ubi_remove_volume()
412 spin_lock(&ubi->volumes_lock); in ubi_remove_volume()
413 ubi->rsvd_pebs -= reserved_pebs; in ubi_remove_volume()
414 ubi->avail_pebs += reserved_pebs; in ubi_remove_volume()
415 ubi_update_reserved(ubi); in ubi_remove_volume()
416 ubi->vol_count -= 1; in ubi_remove_volume()
417 spin_unlock(&ubi->volumes_lock); in ubi_remove_volume()
419 ubi_volume_notify(ubi, vol, UBI_VOLUME_REMOVED); in ubi_remove_volume()
421 self_check_volumes(ubi); in ubi_remove_volume()
426 ubi_err(ubi, "cannot remove volume %d, error %d", vol_id, err); in ubi_remove_volume()
427 spin_lock(&ubi->volumes_lock); in ubi_remove_volume()
428 ubi->volumes[vol_id] = vol; in ubi_remove_volume()
430 spin_unlock(&ubi->volumes_lock); in ubi_remove_volume()
435 * ubi_resize_volume - re-size volume.
436 * @desc: volume descriptor
439 * This function re-sizes the volume and returns zero in case of success, and a
441 * @ubi->device_mutex locked.
446 struct ubi_volume *vol = desc->vol; in ubi_resize_volume()
447 struct ubi_device *ubi = vol->ubi; in ubi_resize_volume() local
451 int vol_id = vol->vol_id; in ubi_resize_volume()
453 if (ubi->ro_mode) in ubi_resize_volume()
454 return -EROFS; in ubi_resize_volume()
456 dbg_gen("re-size device %d, volume %d to from %d to %d PEBs", in ubi_resize_volume()
457 ubi->ubi_num, vol_id, vol->reserved_pebs, reserved_pebs); in ubi_resize_volume()
459 if (vol->vol_type == UBI_STATIC_VOLUME && in ubi_resize_volume()
460 reserved_pebs < vol->used_ebs) { in ubi_resize_volume()
461 ubi_err(ubi, "too small size %d, %d LEBs contain data", in ubi_resize_volume()
462 reserved_pebs, vol->used_ebs); in ubi_resize_volume()
463 return -EINVAL; in ubi_resize_volume()
467 if (reserved_pebs == vol->reserved_pebs) in ubi_resize_volume()
474 spin_lock(&ubi->volumes_lock); in ubi_resize_volume()
475 if (vol->ref_count > 1) { in ubi_resize_volume()
476 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
477 err = -EBUSY; in ubi_resize_volume()
480 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
483 pebs = reserved_pebs - vol->reserved_pebs; in ubi_resize_volume()
485 spin_lock(&ubi->volumes_lock); in ubi_resize_volume()
486 if (pebs > ubi->avail_pebs) { in ubi_resize_volume()
487 ubi_err(ubi, "not enough PEBs: requested %d, available %d", in ubi_resize_volume()
488 pebs, ubi->avail_pebs); in ubi_resize_volume()
489 if (ubi->corr_peb_count) in ubi_resize_volume()
490 ubi_err(ubi, "%d PEBs are corrupted and not used", in ubi_resize_volume()
491 ubi->corr_peb_count); in ubi_resize_volume()
492 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
493 err = -ENOSPC; in ubi_resize_volume()
497 ubi->avail_pebs -= pebs; in ubi_resize_volume()
498 ubi->rsvd_pebs += pebs; in ubi_resize_volume()
499 ubi_eba_copy_table(vol, new_eba_tbl, vol->reserved_pebs); in ubi_resize_volume()
500 old_eba_tbl = vol->eba_tbl; in ubi_resize_volume()
501 vol->eba_tbl = new_eba_tbl; in ubi_resize_volume()
502 vol->reserved_pebs = reserved_pebs; in ubi_resize_volume()
503 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
507 for (i = 0; i < -pebs; i++) { in ubi_resize_volume()
508 err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i); in ubi_resize_volume()
512 spin_lock(&ubi->volumes_lock); in ubi_resize_volume()
513 ubi->rsvd_pebs += pebs; in ubi_resize_volume()
514 ubi->avail_pebs -= pebs; in ubi_resize_volume()
515 ubi_update_reserved(ubi); in ubi_resize_volume()
517 old_eba_tbl = vol->eba_tbl; in ubi_resize_volume()
518 vol->eba_tbl = new_eba_tbl; in ubi_resize_volume()
519 vol->reserved_pebs = reserved_pebs; in ubi_resize_volume()
520 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
524 * When we shrink a volume we have to flush all pending (erase) work. in ubi_resize_volume()
525 * Otherwise it can happen that upon next attach UBI finds a LEB with in ubi_resize_volume()
529 err = ubi_wl_flush(ubi, vol_id, UBI_ALL); in ubi_resize_volume()
534 /* Change volume table record */ in ubi_resize_volume()
535 vtbl_rec = ubi->vtbl[vol_id]; in ubi_resize_volume()
537 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec); in ubi_resize_volume()
541 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in ubi_resize_volume()
542 vol->used_ebs = reserved_pebs; in ubi_resize_volume()
543 vol->last_eb_bytes = vol->usable_leb_size; in ubi_resize_volume()
544 vol->used_bytes = in ubi_resize_volume()
545 (long long)vol->used_ebs * vol->usable_leb_size; in ubi_resize_volume()
550 ubi_volume_notify(ubi, vol, UBI_VOLUME_RESIZED); in ubi_resize_volume()
551 self_check_volumes(ubi); in ubi_resize_volume()
555 spin_lock(&ubi->volumes_lock); in ubi_resize_volume()
556 vol->reserved_pebs = reserved_pebs - pebs; in ubi_resize_volume()
557 ubi->rsvd_pebs -= pebs; in ubi_resize_volume()
558 ubi->avail_pebs += pebs; in ubi_resize_volume()
560 ubi_eba_copy_table(vol, old_eba_tbl, vol->reserved_pebs); in ubi_resize_volume()
563 vol->eba_tbl = old_eba_tbl; in ubi_resize_volume()
564 spin_unlock(&ubi->volumes_lock); in ubi_resize_volume()
571 * ubi_rename_volumes - re-name UBI volumes.
572 * @ubi: UBI device description object
575 * This function re-names or removes volumes specified in the re-name list.
579 int ubi_rename_volumes(struct ubi_device *ubi, struct list_head *rename_list) in ubi_rename_volumes() argument
584 err = ubi_vtbl_rename_volumes(ubi, rename_list); in ubi_rename_volumes()
589 if (re->remove) { in ubi_rename_volumes()
590 err = ubi_remove_volume(re->desc, 1); in ubi_rename_volumes()
594 struct ubi_volume *vol = re->desc->vol; in ubi_rename_volumes()
596 spin_lock(&ubi->volumes_lock); in ubi_rename_volumes()
597 vol->name_len = re->new_name_len; in ubi_rename_volumes()
598 memcpy(vol->name, re->new_name, re->new_name_len + 1); in ubi_rename_volumes()
599 spin_unlock(&ubi->volumes_lock); in ubi_rename_volumes()
600 ubi_volume_notify(ubi, vol, UBI_VOLUME_RENAMED); in ubi_rename_volumes()
605 self_check_volumes(ubi); in ubi_rename_volumes()
610 * ubi_add_volume - add volume.
611 * @ubi: UBI device description object
612 * @vol: volume description object
614 * This function adds an existing volume and initializes all its data
618 int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol) in ubi_add_volume() argument
620 int err, vol_id = vol->vol_id; in ubi_add_volume()
623 dbg_gen("add volume %d", vol_id); in ubi_add_volume()
625 /* Register character device for the volume */ in ubi_add_volume()
626 cdev_init(&vol->cdev, &ubi_vol_cdev_operations); in ubi_add_volume()
627 vol->cdev.owner = THIS_MODULE; in ubi_add_volume()
628 dev = MKDEV(MAJOR(ubi->cdev.dev), vol->vol_id + 1); in ubi_add_volume()
629 err = cdev_add(&vol->cdev, dev, 1); in ubi_add_volume()
631 ubi_err(ubi, "cannot add character device for volume %d, error %d", in ubi_add_volume()
633 vol_release(&vol->dev); in ubi_add_volume()
637 vol->dev.release = vol_release; in ubi_add_volume()
638 vol->dev.parent = &ubi->dev; in ubi_add_volume()
639 vol->dev.devt = dev; in ubi_add_volume()
640 vol->dev.class = &ubi_class; in ubi_add_volume()
641 vol->dev.groups = volume_dev_groups; in ubi_add_volume()
642 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id); in ubi_add_volume()
643 device_set_node(&vol->dev, find_volume_fwnode(vol)); in ubi_add_volume()
644 err = device_register(&vol->dev); in ubi_add_volume()
646 cdev_del(&vol->cdev); in ubi_add_volume()
647 put_device(&vol->dev); in ubi_add_volume()
651 self_check_volumes(ubi); in ubi_add_volume()
656 * ubi_free_volume - free volume.
657 * @ubi: UBI device description object
658 * @vol: volume description object
660 * This function frees all resources for volume @vol but does not remove it.
661 * Used only when the UBI device is detached.
663 void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol) in ubi_free_volume() argument
665 dbg_gen("free volume %d", vol->vol_id); in ubi_free_volume()
667 ubi->volumes[vol->vol_id] = NULL; in ubi_free_volume()
668 cdev_del(&vol->cdev); in ubi_free_volume()
669 device_unregister(&vol->dev); in ubi_free_volume()
673 * self_check_volume - check volume information.
674 * @ubi: UBI device description object
675 * @vol_id: volume ID
677 * Returns zero if volume is all right and a negative error code if not.
679 static int self_check_volume(struct ubi_device *ubi, int vol_id) in self_check_volume() argument
681 int idx = vol_id2idx(ubi, vol_id); in self_check_volume()
687 spin_lock(&ubi->volumes_lock); in self_check_volume()
688 reserved_pebs = be32_to_cpu(ubi->vtbl[vol_id].reserved_pebs); in self_check_volume()
689 vol = ubi->volumes[idx]; in self_check_volume()
693 ubi_err(ubi, "no volume info, but volume exists"); in self_check_volume()
696 spin_unlock(&ubi->volumes_lock); in self_check_volume()
700 if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 || in self_check_volume()
701 vol->name_len < 0) { in self_check_volume()
702 ubi_err(ubi, "negative values"); in self_check_volume()
705 if (vol->alignment > ubi->leb_size || vol->alignment == 0) { in self_check_volume()
706 ubi_err(ubi, "bad alignment"); in self_check_volume()
710 n = vol->alignment & (ubi->min_io_size - 1); in self_check_volume()
711 if (vol->alignment != 1 && n) { in self_check_volume()
712 ubi_err(ubi, "alignment is not multiple of min I/O unit"); in self_check_volume()
716 n = ubi->leb_size % vol->alignment; in self_check_volume()
717 if (vol->data_pad != n) { in self_check_volume()
718 ubi_err(ubi, "bad data_pad, has to be %lld", n); in self_check_volume()
722 if (vol->vol_type != UBI_DYNAMIC_VOLUME && in self_check_volume()
723 vol->vol_type != UBI_STATIC_VOLUME) { in self_check_volume()
724 ubi_err(ubi, "bad vol_type"); in self_check_volume()
728 if (vol->upd_marker && vol->corrupted) { in self_check_volume()
729 ubi_err(ubi, "update marker and corrupted simultaneously"); in self_check_volume()
733 if (vol->reserved_pebs > ubi->good_peb_count) { in self_check_volume()
734 ubi_err(ubi, "too large reserved_pebs"); in self_check_volume()
738 n = ubi->leb_size - vol->data_pad; in self_check_volume()
739 if (vol->usable_leb_size != ubi->leb_size - vol->data_pad) { in self_check_volume()
740 ubi_err(ubi, "bad usable_leb_size, has to be %lld", n); in self_check_volume()
744 if (vol->name_len > UBI_VOL_NAME_MAX) { in self_check_volume()
745 ubi_err(ubi, "too long volume name, max is %d", in self_check_volume()
750 n = strnlen(vol->name, vol->name_len + 1); in self_check_volume()
751 if (n != vol->name_len) { in self_check_volume()
752 ubi_err(ubi, "bad name_len %lld", n); in self_check_volume()
756 n = (long long)vol->used_ebs * vol->usable_leb_size; in self_check_volume()
757 if (vol->vol_type == UBI_DYNAMIC_VOLUME) { in self_check_volume()
758 if (vol->corrupted) { in self_check_volume()
759 ubi_err(ubi, "corrupted dynamic volume"); in self_check_volume()
762 if (vol->used_ebs != vol->reserved_pebs) { in self_check_volume()
763 ubi_err(ubi, "bad used_ebs"); in self_check_volume()
766 if (vol->last_eb_bytes != vol->usable_leb_size) { in self_check_volume()
767 ubi_err(ubi, "bad last_eb_bytes"); in self_check_volume()
770 if (vol->used_bytes != n) { in self_check_volume()
771 ubi_err(ubi, "bad used_bytes"); in self_check_volume()
775 if (vol->skip_check) { in self_check_volume()
776 ubi_err(ubi, "bad skip_check"); in self_check_volume()
780 if (vol->used_ebs < 0 || vol->used_ebs > vol->reserved_pebs) { in self_check_volume()
781 ubi_err(ubi, "bad used_ebs"); in self_check_volume()
784 if (vol->last_eb_bytes < 0 || in self_check_volume()
785 vol->last_eb_bytes > vol->usable_leb_size) { in self_check_volume()
786 ubi_err(ubi, "bad last_eb_bytes"); in self_check_volume()
789 if (vol->used_bytes < 0 || vol->used_bytes > n || in self_check_volume()
790 vol->used_bytes < n - vol->usable_leb_size) { in self_check_volume()
791 ubi_err(ubi, "bad used_bytes"); in self_check_volume()
796 alignment = be32_to_cpu(ubi->vtbl[vol_id].alignment); in self_check_volume()
797 data_pad = be32_to_cpu(ubi->vtbl[vol_id].data_pad); in self_check_volume()
798 name_len = be16_to_cpu(ubi->vtbl[vol_id].name_len); in self_check_volume()
799 upd_marker = ubi->vtbl[vol_id].upd_marker; in self_check_volume()
800 name = &ubi->vtbl[vol_id].name[0]; in self_check_volume()
801 if (ubi->vtbl[vol_id].vol_type == UBI_VID_DYNAMIC) in self_check_volume()
806 if (alignment != vol->alignment || data_pad != vol->data_pad || in self_check_volume()
807 upd_marker != vol->upd_marker || vol_type != vol->vol_type || in self_check_volume()
808 name_len != vol->name_len || strncmp(name, vol->name, name_len)) { in self_check_volume()
809 ubi_err(ubi, "volume info is different"); in self_check_volume()
813 spin_unlock(&ubi->volumes_lock); in self_check_volume()
817 ubi_err(ubi, "self-check failed for volume %d", vol_id); in self_check_volume()
820 ubi_dump_vtbl_record(&ubi->vtbl[vol_id], vol_id); in self_check_volume()
822 spin_unlock(&ubi->volumes_lock); in self_check_volume()
823 return -EINVAL; in self_check_volume()
827 * self_check_volumes - check information about all volumes.
828 * @ubi: UBI device description object
832 static int self_check_volumes(struct ubi_device *ubi) in self_check_volumes() argument
836 if (!ubi_dbg_chk_gen(ubi)) in self_check_volumes()
839 for (i = 0; i < ubi->vtbl_slots; i++) { in self_check_volumes()
840 err = self_check_volume(ubi, i); in self_check_volumes()