2 * Copyright (c) International Business Machines Corp., 2006
4 * SPDX-License-Identifier: GPL-2.0+
6 * Author: Artem Bityutskiy (Битюцкий Артём)
10 * This file contains implementation of volume creation, deletion, updating and
16 #include <linux/err.h>
17 #include <linux/slab.h>
18 #include <linux/export.h>
21 #include <ubi_uboot.h>
23 #include <linux/math64.h>
27 static int self_check_volumes(struct ubi_device *ubi);
30 static ssize_t vol_attribute_show(struct device *dev,
31 struct device_attribute *attr, char *buf);
33 /* Device attributes corresponding to files in '/<sysfs>/class/ubi/ubiX_Y' */
34 static struct device_attribute attr_vol_reserved_ebs =
35 __ATTR(reserved_ebs, S_IRUGO, vol_attribute_show, NULL);
36 static struct device_attribute attr_vol_type =
37 __ATTR(type, S_IRUGO, vol_attribute_show, NULL);
38 static struct device_attribute attr_vol_name =
39 __ATTR(name, S_IRUGO, vol_attribute_show, NULL);
40 static struct device_attribute attr_vol_corrupted =
41 __ATTR(corrupted, S_IRUGO, vol_attribute_show, NULL);
42 static struct device_attribute attr_vol_alignment =
43 __ATTR(alignment, S_IRUGO, vol_attribute_show, NULL);
44 static struct device_attribute attr_vol_usable_eb_size =
45 __ATTR(usable_eb_size, S_IRUGO, vol_attribute_show, NULL);
46 static struct device_attribute attr_vol_data_bytes =
47 __ATTR(data_bytes, S_IRUGO, vol_attribute_show, NULL);
48 static struct device_attribute attr_vol_upd_marker =
49 __ATTR(upd_marker, S_IRUGO, vol_attribute_show, NULL);
52 * "Show" method for files in '/<sysfs>/class/ubi/ubiX_Y/'.
54 * Consider a situation:
55 * A. process 1 opens a sysfs file related to volume Y, say
56 * /<sysfs>/class/ubi/ubiX_Y/reserved_ebs;
57 * B. process 2 removes volume Y;
58 * C. process 1 starts reading the /<sysfs>/class/ubi/ubiX_Y/reserved_ebs file;
60 * In this situation, this function will return %-ENODEV because it will find
61 * out that the volume was removed from the @ubi->volumes array.
63 static ssize_t vol_attribute_show(struct device *dev,
64 struct device_attribute *attr, char *buf)
67 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev);
68 struct ubi_device *ubi;
70 ubi = ubi_get_device(vol->ubi->ubi_num);
74 spin_lock(&ubi->volumes_lock);
75 if (!ubi->volumes[vol->vol_id]) {
76 spin_unlock(&ubi->volumes_lock);
80 /* Take a reference to prevent volume removal */
82 spin_unlock(&ubi->volumes_lock);
84 if (attr == &attr_vol_reserved_ebs)
85 ret = sprintf(buf, "%d\n", vol->reserved_pebs);
86 else if (attr == &attr_vol_type) {
89 if (vol->vol_type == UBI_DYNAMIC_VOLUME)
93 ret = sprintf(buf, "%s\n", tp);
94 } else if (attr == &attr_vol_name)
95 ret = sprintf(buf, "%s\n", vol->name);
96 else if (attr == &attr_vol_corrupted)
97 ret = sprintf(buf, "%d\n", vol->corrupted);
98 else if (attr == &attr_vol_alignment)
99 ret = sprintf(buf, "%d\n", vol->alignment);
100 else if (attr == &attr_vol_usable_eb_size)
101 ret = sprintf(buf, "%d\n", vol->usable_leb_size);
102 else if (attr == &attr_vol_data_bytes)
103 ret = sprintf(buf, "%lld\n", vol->used_bytes);
104 else if (attr == &attr_vol_upd_marker)
105 ret = sprintf(buf, "%d\n", vol->upd_marker);
107 /* This must be a bug */
110 /* We've done the operation, drop volume and UBI device references */
111 spin_lock(&ubi->volumes_lock);
113 ubi_assert(vol->ref_count >= 0);
114 spin_unlock(&ubi->volumes_lock);
120 /* Release method for volume devices */
121 static void vol_release(struct device *dev)
123 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev);
131 * volume_sysfs_init - initialize sysfs for new volume.
132 * @ubi: UBI device description object
133 * @vol: volume description object
135 * This function returns zero in case of success and a negative error code in
138 * Note, this function does not free allocated resources in case of failure -
139 * the caller does it. This is because this would cause release() here and the
142 static int volume_sysfs_init(struct ubi_device *ubi, struct ubi_volume *vol)
146 err = device_create_file(&vol->dev, &attr_vol_reserved_ebs);
149 err = device_create_file(&vol->dev, &attr_vol_type);
152 err = device_create_file(&vol->dev, &attr_vol_name);
155 err = device_create_file(&vol->dev, &attr_vol_corrupted);
158 err = device_create_file(&vol->dev, &attr_vol_alignment);
161 err = device_create_file(&vol->dev, &attr_vol_usable_eb_size);
164 err = device_create_file(&vol->dev, &attr_vol_data_bytes);
167 err = device_create_file(&vol->dev, &attr_vol_upd_marker);
172 * volume_sysfs_close - close sysfs for a volume.
173 * @vol: volume description object
175 static void volume_sysfs_close(struct ubi_volume *vol)
177 device_remove_file(&vol->dev, &attr_vol_upd_marker);
178 device_remove_file(&vol->dev, &attr_vol_data_bytes);
179 device_remove_file(&vol->dev, &attr_vol_usable_eb_size);
180 device_remove_file(&vol->dev, &attr_vol_alignment);
181 device_remove_file(&vol->dev, &attr_vol_corrupted);
182 device_remove_file(&vol->dev, &attr_vol_name);
183 device_remove_file(&vol->dev, &attr_vol_type);
184 device_remove_file(&vol->dev, &attr_vol_reserved_ebs);
185 device_unregister(&vol->dev);
190 * ubi_create_volume - create volume.
191 * @ubi: UBI device description object
192 * @req: volume creation request
194 * This function creates volume described by @req. If @req->vol_id id
195 * %UBI_VOL_NUM_AUTO, this function automatically assign ID to the new volume
196 * and saves it in @req->vol_id. Returns zero in case of success and a negative
197 * error code in case of failure. Note, the caller has to have the
198 * @ubi->device_mutex locked.
200 int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
202 int i, err, vol_id = req->vol_id, do_free = 1;
203 struct ubi_volume *vol;
204 struct ubi_vtbl_record vtbl_rec;
210 vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL);
214 spin_lock(&ubi->volumes_lock);
215 if (vol_id == UBI_VOL_NUM_AUTO) {
216 /* Find unused volume ID */
217 dbg_gen("search for vacant volume ID");
218 for (i = 0; i < ubi->vtbl_slots; i++)
219 if (!ubi->volumes[i]) {
224 if (vol_id == UBI_VOL_NUM_AUTO) {
225 ubi_err("out of volume IDs");
229 req->vol_id = vol_id;
232 dbg_gen("create device %d, volume %d, %llu bytes, type %d, name %s",
233 ubi->ubi_num, vol_id, (unsigned long long)req->bytes,
234 (int)req->vol_type, req->name);
236 /* Ensure that this volume does not exist */
238 if (ubi->volumes[vol_id]) {
239 ubi_err("volume %d already exists", vol_id);
243 /* Ensure that the name is unique */
244 for (i = 0; i < ubi->vtbl_slots; i++)
245 if (ubi->volumes[i] &&
246 ubi->volumes[i]->name_len == req->name_len &&
247 !strcmp(ubi->volumes[i]->name, req->name)) {
248 ubi_err("volume \"%s\" exists (ID %d)", req->name, i);
252 /* Calculate how many eraseblocks are requested */
253 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment;
254 vol->reserved_pebs += div_u64(req->bytes + vol->usable_leb_size - 1,
255 vol->usable_leb_size);
257 /* Reserve physical eraseblocks */
258 if (vol->reserved_pebs > ubi->avail_pebs) {
259 ubi_err("not enough PEBs, only %d available", ubi->avail_pebs);
260 if (ubi->corr_peb_count)
261 ubi_err("%d PEBs are corrupted and not used",
262 ubi->corr_peb_count);
266 ubi->avail_pebs -= vol->reserved_pebs;
267 ubi->rsvd_pebs += vol->reserved_pebs;
268 spin_unlock(&ubi->volumes_lock);
270 vol->vol_id = vol_id;
271 vol->alignment = req->alignment;
272 vol->data_pad = ubi->leb_size % vol->alignment;
273 vol->vol_type = req->vol_type;
274 vol->name_len = req->name_len;
275 memcpy(vol->name, req->name, vol->name_len);
279 * Finish all pending erases because there may be some LEBs belonging
280 * to the same volume ID.
282 err = ubi_wl_flush(ubi, vol_id, UBI_ALL);
286 vol->eba_tbl = kmalloc(vol->reserved_pebs * sizeof(int), GFP_KERNEL);
292 for (i = 0; i < vol->reserved_pebs; i++)
293 vol->eba_tbl[i] = UBI_LEB_UNMAPPED;
295 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
296 vol->used_ebs = vol->reserved_pebs;
297 vol->last_eb_bytes = vol->usable_leb_size;
299 (long long)vol->used_ebs * vol->usable_leb_size;
301 vol->used_ebs = div_u64_rem(vol->used_bytes,
302 vol->usable_leb_size,
303 &vol->last_eb_bytes);
304 if (vol->last_eb_bytes != 0)
307 vol->last_eb_bytes = vol->usable_leb_size;
310 /* Register character device for the volume */
311 cdev_init(&vol->cdev, &ubi_vol_cdev_operations);
312 vol->cdev.owner = THIS_MODULE;
313 dev = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1);
314 err = cdev_add(&vol->cdev, dev, 1);
316 ubi_err("cannot add character device");
320 vol->dev.release = vol_release;
321 vol->dev.parent = &ubi->dev;
323 vol->dev.class = ubi_class;
325 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id);
326 err = device_register(&vol->dev);
328 ubi_err("cannot register device");
332 err = volume_sysfs_init(ubi, vol);
336 /* Fill volume table record */
337 memset(&vtbl_rec, 0, sizeof(struct ubi_vtbl_record));
338 vtbl_rec.reserved_pebs = cpu_to_be32(vol->reserved_pebs);
339 vtbl_rec.alignment = cpu_to_be32(vol->alignment);
340 vtbl_rec.data_pad = cpu_to_be32(vol->data_pad);
341 vtbl_rec.name_len = cpu_to_be16(vol->name_len);
342 if (vol->vol_type == UBI_DYNAMIC_VOLUME)
343 vtbl_rec.vol_type = UBI_VID_DYNAMIC;
345 vtbl_rec.vol_type = UBI_VID_STATIC;
346 memcpy(vtbl_rec.name, vol->name, vol->name_len);
348 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
352 spin_lock(&ubi->volumes_lock);
353 ubi->volumes[vol_id] = vol;
355 spin_unlock(&ubi->volumes_lock);
357 ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED);
358 self_check_volumes(ubi);
363 * We have registered our device, we should not free the volume
364 * description object in this function in case of an error - it is
365 * freed by the release function.
367 * Get device reference to prevent the release function from being
368 * called just after sysfs has been closed.
371 get_device(&vol->dev);
372 volume_sysfs_close(vol);
374 cdev_del(&vol->cdev);
379 spin_lock(&ubi->volumes_lock);
380 ubi->rsvd_pebs -= vol->reserved_pebs;
381 ubi->avail_pebs += vol->reserved_pebs;
383 spin_unlock(&ubi->volumes_lock);
387 put_device(&vol->dev);
388 ubi_err("cannot create volume %d, error %d", vol_id, err);
393 * ubi_remove_volume - remove volume.
394 * @desc: volume descriptor
395 * @no_vtbl: do not change volume table if not zero
397 * This function removes volume described by @desc. The volume has to be opened
398 * in "exclusive" mode. Returns zero in case of success and a negative error
399 * code in case of failure. The caller has to have the @ubi->device_mutex
402 int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl)
404 struct ubi_volume *vol = desc->vol;
405 struct ubi_device *ubi = vol->ubi;
406 int i, err, vol_id = vol->vol_id, reserved_pebs = vol->reserved_pebs;
408 dbg_gen("remove device %d, volume %d", ubi->ubi_num, vol_id);
409 ubi_assert(desc->mode == UBI_EXCLUSIVE);
410 ubi_assert(vol == ubi->volumes[vol_id]);
415 spin_lock(&ubi->volumes_lock);
416 if (vol->ref_count > 1) {
418 * The volume is busy, probably someone is reading one of its
424 ubi->volumes[vol_id] = NULL;
425 spin_unlock(&ubi->volumes_lock);
428 err = ubi_change_vtbl_record(ubi, vol_id, NULL);
433 for (i = 0; i < vol->reserved_pebs; i++) {
434 err = ubi_eba_unmap_leb(ubi, vol, i);
439 cdev_del(&vol->cdev);
440 volume_sysfs_close(vol);
442 spin_lock(&ubi->volumes_lock);
443 ubi->rsvd_pebs -= reserved_pebs;
444 ubi->avail_pebs += reserved_pebs;
445 ubi_update_reserved(ubi);
447 spin_unlock(&ubi->volumes_lock);
449 ubi_volume_notify(ubi, vol, UBI_VOLUME_REMOVED);
451 self_check_volumes(ubi);
456 ubi_err("cannot remove volume %d, error %d", vol_id, err);
457 spin_lock(&ubi->volumes_lock);
458 ubi->volumes[vol_id] = vol;
460 spin_unlock(&ubi->volumes_lock);
465 * ubi_resize_volume - re-size volume.
466 * @desc: volume descriptor
467 * @reserved_pebs: new size in physical eraseblocks
469 * This function re-sizes the volume and returns zero in case of success, and a
470 * negative error code in case of failure. The caller has to have the
471 * @ubi->device_mutex locked.
473 int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
475 int i, err, pebs, *new_mapping;
476 struct ubi_volume *vol = desc->vol;
477 struct ubi_device *ubi = vol->ubi;
478 struct ubi_vtbl_record vtbl_rec;
479 int vol_id = vol->vol_id;
484 dbg_gen("re-size device %d, volume %d to from %d to %d PEBs",
485 ubi->ubi_num, vol_id, vol->reserved_pebs, reserved_pebs);
487 if (vol->vol_type == UBI_STATIC_VOLUME &&
488 reserved_pebs < vol->used_ebs) {
489 ubi_err("too small size %d, %d LEBs contain data",
490 reserved_pebs, vol->used_ebs);
494 /* If the size is the same, we have nothing to do */
495 if (reserved_pebs == vol->reserved_pebs)
498 new_mapping = kmalloc(reserved_pebs * sizeof(int), GFP_KERNEL);
502 for (i = 0; i < reserved_pebs; i++)
503 new_mapping[i] = UBI_LEB_UNMAPPED;
505 spin_lock(&ubi->volumes_lock);
506 if (vol->ref_count > 1) {
507 spin_unlock(&ubi->volumes_lock);
511 spin_unlock(&ubi->volumes_lock);
513 /* Reserve physical eraseblocks */
514 pebs = reserved_pebs - vol->reserved_pebs;
516 spin_lock(&ubi->volumes_lock);
517 if (pebs > ubi->avail_pebs) {
518 ubi_err("not enough PEBs: requested %d, available %d",
519 pebs, ubi->avail_pebs);
520 if (ubi->corr_peb_count)
521 ubi_err("%d PEBs are corrupted and not used",
522 ubi->corr_peb_count);
523 spin_unlock(&ubi->volumes_lock);
527 ubi->avail_pebs -= pebs;
528 ubi->rsvd_pebs += pebs;
529 for (i = 0; i < vol->reserved_pebs; i++)
530 new_mapping[i] = vol->eba_tbl[i];
532 vol->eba_tbl = new_mapping;
533 spin_unlock(&ubi->volumes_lock);
536 /* Change volume table record */
537 vtbl_rec = ubi->vtbl[vol_id];
538 vtbl_rec.reserved_pebs = cpu_to_be32(reserved_pebs);
539 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
544 for (i = 0; i < -pebs; i++) {
545 err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i);
549 spin_lock(&ubi->volumes_lock);
550 ubi->rsvd_pebs += pebs;
551 ubi->avail_pebs -= pebs;
552 ubi_update_reserved(ubi);
553 for (i = 0; i < reserved_pebs; i++)
554 new_mapping[i] = vol->eba_tbl[i];
556 vol->eba_tbl = new_mapping;
557 spin_unlock(&ubi->volumes_lock);
560 vol->reserved_pebs = reserved_pebs;
561 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
562 vol->used_ebs = reserved_pebs;
563 vol->last_eb_bytes = vol->usable_leb_size;
565 (long long)vol->used_ebs * vol->usable_leb_size;
568 ubi_volume_notify(ubi, vol, UBI_VOLUME_RESIZED);
569 self_check_volumes(ubi);
574 spin_lock(&ubi->volumes_lock);
575 ubi->rsvd_pebs -= pebs;
576 ubi->avail_pebs += pebs;
577 spin_unlock(&ubi->volumes_lock);
585 * ubi_rename_volumes - re-name UBI volumes.
586 * @ubi: UBI device description object
587 * @rename_list: list of &struct ubi_rename_entry objects
589 * This function re-names or removes volumes specified in the re-name list.
590 * Returns zero in case of success and a negative error code in case of
593 int ubi_rename_volumes(struct ubi_device *ubi, struct list_head *rename_list)
596 struct ubi_rename_entry *re;
598 err = ubi_vtbl_rename_volumes(ubi, rename_list);
602 list_for_each_entry(re, rename_list, list) {
604 err = ubi_remove_volume(re->desc, 1);
608 struct ubi_volume *vol = re->desc->vol;
610 spin_lock(&ubi->volumes_lock);
611 vol->name_len = re->new_name_len;
612 memcpy(vol->name, re->new_name, re->new_name_len + 1);
613 spin_unlock(&ubi->volumes_lock);
614 ubi_volume_notify(ubi, vol, UBI_VOLUME_RENAMED);
619 self_check_volumes(ubi);
624 * ubi_add_volume - add volume.
625 * @ubi: UBI device description object
626 * @vol: volume description object
628 * This function adds an existing volume and initializes all its data
629 * structures. Returns zero in case of success and a negative error code in
632 int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol)
634 int err, vol_id = vol->vol_id;
637 dbg_gen("add volume %d", vol_id);
639 /* Register character device for the volume */
640 cdev_init(&vol->cdev, &ubi_vol_cdev_operations);
641 vol->cdev.owner = THIS_MODULE;
642 dev = MKDEV(MAJOR(ubi->cdev.dev), vol->vol_id + 1);
643 err = cdev_add(&vol->cdev, dev, 1);
645 ubi_err("cannot add character device for volume %d, error %d",
650 vol->dev.release = vol_release;
651 vol->dev.parent = &ubi->dev;
653 vol->dev.class = ubi_class;
654 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id);
655 err = device_register(&vol->dev);
659 err = volume_sysfs_init(ubi, vol);
661 cdev_del(&vol->cdev);
662 volume_sysfs_close(vol);
666 self_check_volumes(ubi);
670 cdev_del(&vol->cdev);
675 * ubi_free_volume - free volume.
676 * @ubi: UBI device description object
677 * @vol: volume description object
679 * This function frees all resources for volume @vol but does not remove it.
680 * Used only when the UBI device is detached.
682 void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol)
684 dbg_gen("free volume %d", vol->vol_id);
686 ubi->volumes[vol->vol_id] = NULL;
687 cdev_del(&vol->cdev);
688 volume_sysfs_close(vol);
692 * self_check_volume - check volume information.
693 * @ubi: UBI device description object
696 * Returns zero if volume is all right and a a negative error code if not.
698 static int self_check_volume(struct ubi_device *ubi, int vol_id)
700 int idx = vol_id2idx(ubi, vol_id);
701 int reserved_pebs, alignment, data_pad, vol_type, name_len, upd_marker;
702 const struct ubi_volume *vol;
706 spin_lock(&ubi->volumes_lock);
707 reserved_pebs = be32_to_cpu(ubi->vtbl[vol_id].reserved_pebs);
708 vol = ubi->volumes[idx];
712 ubi_err("no volume info, but volume exists");
715 spin_unlock(&ubi->volumes_lock);
719 if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 ||
721 ubi_err("negative values");
724 if (vol->alignment > ubi->leb_size || vol->alignment == 0) {
725 ubi_err("bad alignment");
729 n = vol->alignment & (ubi->min_io_size - 1);
730 if (vol->alignment != 1 && n) {
731 ubi_err("alignment is not multiple of min I/O unit");
735 n = ubi->leb_size % vol->alignment;
736 if (vol->data_pad != n) {
737 ubi_err("bad data_pad, has to be %lld", n);
741 if (vol->vol_type != UBI_DYNAMIC_VOLUME &&
742 vol->vol_type != UBI_STATIC_VOLUME) {
743 ubi_err("bad vol_type");
747 if (vol->upd_marker && vol->corrupted) {
748 ubi_err("update marker and corrupted simultaneously");
752 if (vol->reserved_pebs > ubi->good_peb_count) {
753 ubi_err("too large reserved_pebs");
757 n = ubi->leb_size - vol->data_pad;
758 if (vol->usable_leb_size != ubi->leb_size - vol->data_pad) {
759 ubi_err("bad usable_leb_size, has to be %lld", n);
763 if (vol->name_len > UBI_VOL_NAME_MAX) {
764 ubi_err("too long volume name, max is %d", UBI_VOL_NAME_MAX);
768 n = strnlen(vol->name, vol->name_len + 1);
769 if (n != vol->name_len) {
770 ubi_err("bad name_len %lld", n);
774 n = (long long)vol->used_ebs * vol->usable_leb_size;
775 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
776 if (vol->corrupted) {
777 ubi_err("corrupted dynamic volume");
780 if (vol->used_ebs != vol->reserved_pebs) {
781 ubi_err("bad used_ebs");
784 if (vol->last_eb_bytes != vol->usable_leb_size) {
785 ubi_err("bad last_eb_bytes");
788 if (vol->used_bytes != n) {
789 ubi_err("bad used_bytes");
793 if (vol->used_ebs < 0 || vol->used_ebs > vol->reserved_pebs) {
794 ubi_err("bad used_ebs");
797 if (vol->last_eb_bytes < 0 ||
798 vol->last_eb_bytes > vol->usable_leb_size) {
799 ubi_err("bad last_eb_bytes");
802 if (vol->used_bytes < 0 || vol->used_bytes > n ||
803 vol->used_bytes < n - vol->usable_leb_size) {
804 ubi_err("bad used_bytes");
809 alignment = be32_to_cpu(ubi->vtbl[vol_id].alignment);
810 data_pad = be32_to_cpu(ubi->vtbl[vol_id].data_pad);
811 name_len = be16_to_cpu(ubi->vtbl[vol_id].name_len);
812 upd_marker = ubi->vtbl[vol_id].upd_marker;
813 name = &ubi->vtbl[vol_id].name[0];
814 if (ubi->vtbl[vol_id].vol_type == UBI_VID_DYNAMIC)
815 vol_type = UBI_DYNAMIC_VOLUME;
817 vol_type = UBI_STATIC_VOLUME;
819 if (alignment != vol->alignment || data_pad != vol->data_pad ||
820 upd_marker != vol->upd_marker || vol_type != vol->vol_type ||
821 name_len != vol->name_len || strncmp(name, vol->name, name_len)) {
822 ubi_err("volume info is different");
826 spin_unlock(&ubi->volumes_lock);
830 ubi_err("self-check failed for volume %d", vol_id);
832 ubi_dump_vol_info(vol);
833 ubi_dump_vtbl_record(&ubi->vtbl[vol_id], vol_id);
835 spin_unlock(&ubi->volumes_lock);
840 * self_check_volumes - check information about all volumes.
841 * @ubi: UBI device description object
843 * Returns zero if volumes are all right and a a negative error code if not.
845 static int self_check_volumes(struct ubi_device *ubi)
849 if (!ubi_dbg_chk_gen(ubi))
852 for (i = 0; i < ubi->vtbl_slots; i++) {
853 err = self_check_volume(ubi, i);