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
15 #include <linux/err.h>
16 #include <linux/slab.h>
17 #include <linux/export.h>
20 #include <ubi_uboot.h>
22 #include <linux/math64.h>
26 static int self_check_volumes(struct ubi_device *ubi);
29 static ssize_t vol_attribute_show(struct device *dev,
30 struct device_attribute *attr, char *buf);
32 /* Device attributes corresponding to files in '/<sysfs>/class/ubi/ubiX_Y' */
33 static struct device_attribute attr_vol_reserved_ebs =
34 __ATTR(reserved_ebs, S_IRUGO, vol_attribute_show, NULL);
35 static struct device_attribute attr_vol_type =
36 __ATTR(type, S_IRUGO, vol_attribute_show, NULL);
37 static struct device_attribute attr_vol_name =
38 __ATTR(name, S_IRUGO, vol_attribute_show, NULL);
39 static struct device_attribute attr_vol_corrupted =
40 __ATTR(corrupted, S_IRUGO, vol_attribute_show, NULL);
41 static struct device_attribute attr_vol_alignment =
42 __ATTR(alignment, S_IRUGO, vol_attribute_show, NULL);
43 static struct device_attribute attr_vol_usable_eb_size =
44 __ATTR(usable_eb_size, S_IRUGO, vol_attribute_show, NULL);
45 static struct device_attribute attr_vol_data_bytes =
46 __ATTR(data_bytes, S_IRUGO, vol_attribute_show, NULL);
47 static struct device_attribute attr_vol_upd_marker =
48 __ATTR(upd_marker, S_IRUGO, vol_attribute_show, NULL);
51 * "Show" method for files in '/<sysfs>/class/ubi/ubiX_Y/'.
53 * Consider a situation:
54 * A. process 1 opens a sysfs file related to volume Y, say
55 * /<sysfs>/class/ubi/ubiX_Y/reserved_ebs;
56 * B. process 2 removes volume Y;
57 * C. process 1 starts reading the /<sysfs>/class/ubi/ubiX_Y/reserved_ebs file;
59 * In this situation, this function will return %-ENODEV because it will find
60 * out that the volume was removed from the @ubi->volumes array.
62 static ssize_t vol_attribute_show(struct device *dev,
63 struct device_attribute *attr, char *buf)
66 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev);
67 struct ubi_device *ubi;
69 ubi = ubi_get_device(vol->ubi->ubi_num);
73 spin_lock(&ubi->volumes_lock);
74 if (!ubi->volumes[vol->vol_id]) {
75 spin_unlock(&ubi->volumes_lock);
79 /* Take a reference to prevent volume removal */
81 spin_unlock(&ubi->volumes_lock);
83 if (attr == &attr_vol_reserved_ebs)
84 ret = sprintf(buf, "%d\n", vol->reserved_pebs);
85 else if (attr == &attr_vol_type) {
88 if (vol->vol_type == UBI_DYNAMIC_VOLUME)
92 ret = sprintf(buf, "%s\n", tp);
93 } else if (attr == &attr_vol_name)
94 ret = sprintf(buf, "%s\n", vol->name);
95 else if (attr == &attr_vol_corrupted)
96 ret = sprintf(buf, "%d\n", vol->corrupted);
97 else if (attr == &attr_vol_alignment)
98 ret = sprintf(buf, "%d\n", vol->alignment);
99 else if (attr == &attr_vol_usable_eb_size)
100 ret = sprintf(buf, "%d\n", vol->usable_leb_size);
101 else if (attr == &attr_vol_data_bytes)
102 ret = sprintf(buf, "%lld\n", vol->used_bytes);
103 else if (attr == &attr_vol_upd_marker)
104 ret = sprintf(buf, "%d\n", vol->upd_marker);
106 /* This must be a bug */
109 /* We've done the operation, drop volume and UBI device references */
110 spin_lock(&ubi->volumes_lock);
112 ubi_assert(vol->ref_count >= 0);
113 spin_unlock(&ubi->volumes_lock);
119 /* Release method for volume devices */
120 static void vol_release(struct device *dev)
122 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev);
130 * volume_sysfs_init - initialize sysfs for new volume.
131 * @ubi: UBI device description object
132 * @vol: volume description object
134 * This function returns zero in case of success and a negative error code in
137 * Note, this function does not free allocated resources in case of failure -
138 * the caller does it. This is because this would cause release() here and the
141 static int volume_sysfs_init(struct ubi_device *ubi, struct ubi_volume *vol)
145 err = device_create_file(&vol->dev, &attr_vol_reserved_ebs);
148 err = device_create_file(&vol->dev, &attr_vol_type);
151 err = device_create_file(&vol->dev, &attr_vol_name);
154 err = device_create_file(&vol->dev, &attr_vol_corrupted);
157 err = device_create_file(&vol->dev, &attr_vol_alignment);
160 err = device_create_file(&vol->dev, &attr_vol_usable_eb_size);
163 err = device_create_file(&vol->dev, &attr_vol_data_bytes);
166 err = device_create_file(&vol->dev, &attr_vol_upd_marker);
171 * volume_sysfs_close - close sysfs for a volume.
172 * @vol: volume description object
174 static void volume_sysfs_close(struct ubi_volume *vol)
176 device_remove_file(&vol->dev, &attr_vol_upd_marker);
177 device_remove_file(&vol->dev, &attr_vol_data_bytes);
178 device_remove_file(&vol->dev, &attr_vol_usable_eb_size);
179 device_remove_file(&vol->dev, &attr_vol_alignment);
180 device_remove_file(&vol->dev, &attr_vol_corrupted);
181 device_remove_file(&vol->dev, &attr_vol_name);
182 device_remove_file(&vol->dev, &attr_vol_type);
183 device_remove_file(&vol->dev, &attr_vol_reserved_ebs);
184 device_unregister(&vol->dev);
189 * ubi_create_volume - create volume.
190 * @ubi: UBI device description object
191 * @req: volume creation request
193 * This function creates volume described by @req. If @req->vol_id id
194 * %UBI_VOL_NUM_AUTO, this function automatically assign ID to the new volume
195 * and saves it in @req->vol_id. Returns zero in case of success and a negative
196 * error code in case of failure. Note, the caller has to have the
197 * @ubi->device_mutex locked.
199 int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
201 int i, err, vol_id = req->vol_id, do_free = 1;
202 struct ubi_volume *vol;
203 struct ubi_vtbl_record vtbl_rec;
209 vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL);
213 spin_lock(&ubi->volumes_lock);
214 if (vol_id == UBI_VOL_NUM_AUTO) {
215 /* Find unused volume ID */
216 dbg_gen("search for vacant volume ID");
217 for (i = 0; i < ubi->vtbl_slots; i++)
218 if (!ubi->volumes[i]) {
223 if (vol_id == UBI_VOL_NUM_AUTO) {
224 ubi_err("out of volume IDs");
228 req->vol_id = vol_id;
231 dbg_gen("create device %d, volume %d, %llu bytes, type %d, name %s",
232 ubi->ubi_num, vol_id, (unsigned long long)req->bytes,
233 (int)req->vol_type, req->name);
235 /* Ensure that this volume does not exist */
237 if (ubi->volumes[vol_id]) {
238 ubi_err("volume %d already exists", vol_id);
242 /* Ensure that the name is unique */
243 for (i = 0; i < ubi->vtbl_slots; i++)
244 if (ubi->volumes[i] &&
245 ubi->volumes[i]->name_len == req->name_len &&
246 !strcmp(ubi->volumes[i]->name, req->name)) {
247 ubi_err("volume \"%s\" exists (ID %d)", req->name, i);
251 /* Calculate how many eraseblocks are requested */
252 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment;
253 vol->reserved_pebs += div_u64(req->bytes + vol->usable_leb_size - 1,
254 vol->usable_leb_size);
256 /* Reserve physical eraseblocks */
257 if (vol->reserved_pebs > ubi->avail_pebs) {
258 ubi_err("not enough PEBs, only %d available", ubi->avail_pebs);
259 if (ubi->corr_peb_count)
260 ubi_err("%d PEBs are corrupted and not used",
261 ubi->corr_peb_count);
265 ubi->avail_pebs -= vol->reserved_pebs;
266 ubi->rsvd_pebs += vol->reserved_pebs;
267 spin_unlock(&ubi->volumes_lock);
269 vol->vol_id = vol_id;
270 vol->alignment = req->alignment;
271 vol->data_pad = ubi->leb_size % vol->alignment;
272 vol->vol_type = req->vol_type;
273 vol->name_len = req->name_len;
274 memcpy(vol->name, req->name, vol->name_len);
278 * Finish all pending erases because there may be some LEBs belonging
279 * to the same volume ID.
281 err = ubi_wl_flush(ubi, vol_id, UBI_ALL);
285 vol->eba_tbl = kmalloc(vol->reserved_pebs * sizeof(int), GFP_KERNEL);
291 for (i = 0; i < vol->reserved_pebs; i++)
292 vol->eba_tbl[i] = UBI_LEB_UNMAPPED;
294 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
295 vol->used_ebs = vol->reserved_pebs;
296 vol->last_eb_bytes = vol->usable_leb_size;
298 (long long)vol->used_ebs * vol->usable_leb_size;
300 vol->used_ebs = div_u64_rem(vol->used_bytes,
301 vol->usable_leb_size,
302 &vol->last_eb_bytes);
303 if (vol->last_eb_bytes != 0)
306 vol->last_eb_bytes = vol->usable_leb_size;
309 /* Register character device for the volume */
310 cdev_init(&vol->cdev, &ubi_vol_cdev_operations);
311 vol->cdev.owner = THIS_MODULE;
312 dev = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1);
313 err = cdev_add(&vol->cdev, dev, 1);
315 ubi_err("cannot add character device");
319 vol->dev.release = vol_release;
320 vol->dev.parent = &ubi->dev;
322 vol->dev.class = ubi_class;
324 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id);
325 err = device_register(&vol->dev);
327 ubi_err("cannot register device");
331 err = volume_sysfs_init(ubi, vol);
335 /* Fill volume table record */
336 memset(&vtbl_rec, 0, sizeof(struct ubi_vtbl_record));
337 vtbl_rec.reserved_pebs = cpu_to_be32(vol->reserved_pebs);
338 vtbl_rec.alignment = cpu_to_be32(vol->alignment);
339 vtbl_rec.data_pad = cpu_to_be32(vol->data_pad);
340 vtbl_rec.name_len = cpu_to_be16(vol->name_len);
341 if (vol->vol_type == UBI_DYNAMIC_VOLUME)
342 vtbl_rec.vol_type = UBI_VID_DYNAMIC;
344 vtbl_rec.vol_type = UBI_VID_STATIC;
345 memcpy(vtbl_rec.name, vol->name, vol->name_len);
347 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
351 spin_lock(&ubi->volumes_lock);
352 ubi->volumes[vol_id] = vol;
354 spin_unlock(&ubi->volumes_lock);
356 ubi_volume_notify(ubi, vol, UBI_VOLUME_ADDED);
357 self_check_volumes(ubi);
362 * We have registered our device, we should not free the volume
363 * description object in this function in case of an error - it is
364 * freed by the release function.
366 * Get device reference to prevent the release function from being
367 * called just after sysfs has been closed.
370 get_device(&vol->dev);
371 volume_sysfs_close(vol);
373 cdev_del(&vol->cdev);
378 spin_lock(&ubi->volumes_lock);
379 ubi->rsvd_pebs -= vol->reserved_pebs;
380 ubi->avail_pebs += vol->reserved_pebs;
382 spin_unlock(&ubi->volumes_lock);
386 put_device(&vol->dev);
387 ubi_err("cannot create volume %d, error %d", vol_id, err);
392 * ubi_remove_volume - remove volume.
393 * @desc: volume descriptor
394 * @no_vtbl: do not change volume table if not zero
396 * This function removes volume described by @desc. The volume has to be opened
397 * in "exclusive" mode. Returns zero in case of success and a negative error
398 * code in case of failure. The caller has to have the @ubi->device_mutex
401 int ubi_remove_volume(struct ubi_volume_desc *desc, int no_vtbl)
403 struct ubi_volume *vol = desc->vol;
404 struct ubi_device *ubi = vol->ubi;
405 int i, err, vol_id = vol->vol_id, reserved_pebs = vol->reserved_pebs;
407 dbg_gen("remove device %d, volume %d", ubi->ubi_num, vol_id);
408 ubi_assert(desc->mode == UBI_EXCLUSIVE);
409 ubi_assert(vol == ubi->volumes[vol_id]);
414 spin_lock(&ubi->volumes_lock);
415 if (vol->ref_count > 1) {
417 * The volume is busy, probably someone is reading one of its
423 ubi->volumes[vol_id] = NULL;
424 spin_unlock(&ubi->volumes_lock);
427 err = ubi_change_vtbl_record(ubi, vol_id, NULL);
432 for (i = 0; i < vol->reserved_pebs; i++) {
433 err = ubi_eba_unmap_leb(ubi, vol, i);
438 cdev_del(&vol->cdev);
439 volume_sysfs_close(vol);
441 spin_lock(&ubi->volumes_lock);
442 ubi->rsvd_pebs -= reserved_pebs;
443 ubi->avail_pebs += reserved_pebs;
444 ubi_update_reserved(ubi);
446 spin_unlock(&ubi->volumes_lock);
448 ubi_volume_notify(ubi, vol, UBI_VOLUME_REMOVED);
450 self_check_volumes(ubi);
455 ubi_err("cannot remove volume %d, error %d", vol_id, err);
456 spin_lock(&ubi->volumes_lock);
457 ubi->volumes[vol_id] = vol;
459 spin_unlock(&ubi->volumes_lock);
464 * ubi_resize_volume - re-size volume.
465 * @desc: volume descriptor
466 * @reserved_pebs: new size in physical eraseblocks
468 * This function re-sizes the volume and returns zero in case of success, and a
469 * negative error code in case of failure. The caller has to have the
470 * @ubi->device_mutex locked.
472 int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
474 int i, err, pebs, *new_mapping;
475 struct ubi_volume *vol = desc->vol;
476 struct ubi_device *ubi = vol->ubi;
477 struct ubi_vtbl_record vtbl_rec;
478 int vol_id = vol->vol_id;
483 dbg_gen("re-size device %d, volume %d to from %d to %d PEBs",
484 ubi->ubi_num, vol_id, vol->reserved_pebs, reserved_pebs);
486 if (vol->vol_type == UBI_STATIC_VOLUME &&
487 reserved_pebs < vol->used_ebs) {
488 ubi_err("too small size %d, %d LEBs contain data",
489 reserved_pebs, vol->used_ebs);
493 /* If the size is the same, we have nothing to do */
494 if (reserved_pebs == vol->reserved_pebs)
497 new_mapping = kmalloc(reserved_pebs * sizeof(int), GFP_KERNEL);
501 for (i = 0; i < reserved_pebs; i++)
502 new_mapping[i] = UBI_LEB_UNMAPPED;
504 spin_lock(&ubi->volumes_lock);
505 if (vol->ref_count > 1) {
506 spin_unlock(&ubi->volumes_lock);
510 spin_unlock(&ubi->volumes_lock);
512 /* Reserve physical eraseblocks */
513 pebs = reserved_pebs - vol->reserved_pebs;
515 spin_lock(&ubi->volumes_lock);
516 if (pebs > ubi->avail_pebs) {
517 ubi_err("not enough PEBs: requested %d, available %d",
518 pebs, ubi->avail_pebs);
519 if (ubi->corr_peb_count)
520 ubi_err("%d PEBs are corrupted and not used",
521 ubi->corr_peb_count);
522 spin_unlock(&ubi->volumes_lock);
526 ubi->avail_pebs -= pebs;
527 ubi->rsvd_pebs += pebs;
528 for (i = 0; i < vol->reserved_pebs; i++)
529 new_mapping[i] = vol->eba_tbl[i];
531 vol->eba_tbl = new_mapping;
532 spin_unlock(&ubi->volumes_lock);
535 /* Change volume table record */
536 vtbl_rec = ubi->vtbl[vol_id];
537 vtbl_rec.reserved_pebs = cpu_to_be32(reserved_pebs);
538 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
543 for (i = 0; i < -pebs; i++) {
544 err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i);
548 spin_lock(&ubi->volumes_lock);
549 ubi->rsvd_pebs += pebs;
550 ubi->avail_pebs -= pebs;
551 ubi_update_reserved(ubi);
552 for (i = 0; i < reserved_pebs; i++)
553 new_mapping[i] = vol->eba_tbl[i];
555 vol->eba_tbl = new_mapping;
556 spin_unlock(&ubi->volumes_lock);
559 vol->reserved_pebs = reserved_pebs;
560 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
561 vol->used_ebs = reserved_pebs;
562 vol->last_eb_bytes = vol->usable_leb_size;
564 (long long)vol->used_ebs * vol->usable_leb_size;
567 ubi_volume_notify(ubi, vol, UBI_VOLUME_RESIZED);
568 self_check_volumes(ubi);
573 spin_lock(&ubi->volumes_lock);
574 ubi->rsvd_pebs -= pebs;
575 ubi->avail_pebs += pebs;
576 spin_unlock(&ubi->volumes_lock);
584 * ubi_rename_volumes - re-name UBI volumes.
585 * @ubi: UBI device description object
586 * @rename_list: list of &struct ubi_rename_entry objects
588 * This function re-names or removes volumes specified in the re-name list.
589 * Returns zero in case of success and a negative error code in case of
592 int ubi_rename_volumes(struct ubi_device *ubi, struct list_head *rename_list)
595 struct ubi_rename_entry *re;
597 err = ubi_vtbl_rename_volumes(ubi, rename_list);
601 list_for_each_entry(re, rename_list, list) {
603 err = ubi_remove_volume(re->desc, 1);
607 struct ubi_volume *vol = re->desc->vol;
609 spin_lock(&ubi->volumes_lock);
610 vol->name_len = re->new_name_len;
611 memcpy(vol->name, re->new_name, re->new_name_len + 1);
612 spin_unlock(&ubi->volumes_lock);
613 ubi_volume_notify(ubi, vol, UBI_VOLUME_RENAMED);
618 self_check_volumes(ubi);
623 * ubi_add_volume - add volume.
624 * @ubi: UBI device description object
625 * @vol: volume description object
627 * This function adds an existing volume and initializes all its data
628 * structures. Returns zero in case of success and a negative error code in
631 int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol)
633 int err, vol_id = vol->vol_id;
636 dbg_gen("add volume %d", vol_id);
638 /* Register character device for the volume */
639 cdev_init(&vol->cdev, &ubi_vol_cdev_operations);
640 vol->cdev.owner = THIS_MODULE;
641 dev = MKDEV(MAJOR(ubi->cdev.dev), vol->vol_id + 1);
642 err = cdev_add(&vol->cdev, dev, 1);
644 ubi_err("cannot add character device for volume %d, error %d",
649 vol->dev.release = vol_release;
650 vol->dev.parent = &ubi->dev;
652 vol->dev.class = ubi_class;
653 dev_set_name(&vol->dev, "%s_%d", ubi->ubi_name, vol->vol_id);
654 err = device_register(&vol->dev);
658 err = volume_sysfs_init(ubi, vol);
660 cdev_del(&vol->cdev);
661 volume_sysfs_close(vol);
665 self_check_volumes(ubi);
669 cdev_del(&vol->cdev);
674 * ubi_free_volume - free volume.
675 * @ubi: UBI device description object
676 * @vol: volume description object
678 * This function frees all resources for volume @vol but does not remove it.
679 * Used only when the UBI device is detached.
681 void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol)
683 dbg_gen("free volume %d", vol->vol_id);
685 ubi->volumes[vol->vol_id] = NULL;
686 cdev_del(&vol->cdev);
687 volume_sysfs_close(vol);
691 * self_check_volume - check volume information.
692 * @ubi: UBI device description object
695 * Returns zero if volume is all right and a a negative error code if not.
697 static int self_check_volume(struct ubi_device *ubi, int vol_id)
699 int idx = vol_id2idx(ubi, vol_id);
700 int reserved_pebs, alignment, data_pad, vol_type, name_len, upd_marker;
701 const struct ubi_volume *vol;
705 spin_lock(&ubi->volumes_lock);
706 reserved_pebs = be32_to_cpu(ubi->vtbl[vol_id].reserved_pebs);
707 vol = ubi->volumes[idx];
711 ubi_err("no volume info, but volume exists");
714 spin_unlock(&ubi->volumes_lock);
718 if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 ||
720 ubi_err("negative values");
723 if (vol->alignment > ubi->leb_size || vol->alignment == 0) {
724 ubi_err("bad alignment");
728 n = vol->alignment & (ubi->min_io_size - 1);
729 if (vol->alignment != 1 && n) {
730 ubi_err("alignment is not multiple of min I/O unit");
734 n = ubi->leb_size % vol->alignment;
735 if (vol->data_pad != n) {
736 ubi_err("bad data_pad, has to be %lld", n);
740 if (vol->vol_type != UBI_DYNAMIC_VOLUME &&
741 vol->vol_type != UBI_STATIC_VOLUME) {
742 ubi_err("bad vol_type");
746 if (vol->upd_marker && vol->corrupted) {
747 ubi_err("update marker and corrupted simultaneously");
751 if (vol->reserved_pebs > ubi->good_peb_count) {
752 ubi_err("too large reserved_pebs");
756 n = ubi->leb_size - vol->data_pad;
757 if (vol->usable_leb_size != ubi->leb_size - vol->data_pad) {
758 ubi_err("bad usable_leb_size, has to be %lld", n);
762 if (vol->name_len > UBI_VOL_NAME_MAX) {
763 ubi_err("too long volume name, max is %d", UBI_VOL_NAME_MAX);
767 n = strnlen(vol->name, vol->name_len + 1);
768 if (n != vol->name_len) {
769 ubi_err("bad name_len %lld", n);
773 n = (long long)vol->used_ebs * vol->usable_leb_size;
774 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
775 if (vol->corrupted) {
776 ubi_err("corrupted dynamic volume");
779 if (vol->used_ebs != vol->reserved_pebs) {
780 ubi_err("bad used_ebs");
783 if (vol->last_eb_bytes != vol->usable_leb_size) {
784 ubi_err("bad last_eb_bytes");
787 if (vol->used_bytes != n) {
788 ubi_err("bad used_bytes");
792 if (vol->used_ebs < 0 || vol->used_ebs > vol->reserved_pebs) {
793 ubi_err("bad used_ebs");
796 if (vol->last_eb_bytes < 0 ||
797 vol->last_eb_bytes > vol->usable_leb_size) {
798 ubi_err("bad last_eb_bytes");
801 if (vol->used_bytes < 0 || vol->used_bytes > n ||
802 vol->used_bytes < n - vol->usable_leb_size) {
803 ubi_err("bad used_bytes");
808 alignment = be32_to_cpu(ubi->vtbl[vol_id].alignment);
809 data_pad = be32_to_cpu(ubi->vtbl[vol_id].data_pad);
810 name_len = be16_to_cpu(ubi->vtbl[vol_id].name_len);
811 upd_marker = ubi->vtbl[vol_id].upd_marker;
812 name = &ubi->vtbl[vol_id].name[0];
813 if (ubi->vtbl[vol_id].vol_type == UBI_VID_DYNAMIC)
814 vol_type = UBI_DYNAMIC_VOLUME;
816 vol_type = UBI_STATIC_VOLUME;
818 if (alignment != vol->alignment || data_pad != vol->data_pad ||
819 upd_marker != vol->upd_marker || vol_type != vol->vol_type ||
820 name_len != vol->name_len || strncmp(name, vol->name, name_len)) {
821 ubi_err("volume info is different");
825 spin_unlock(&ubi->volumes_lock);
829 ubi_err("self-check failed for volume %d", vol_id);
831 ubi_dump_vol_info(vol);
832 ubi_dump_vtbl_record(&ubi->vtbl[vol_id], vol_id);
834 spin_unlock(&ubi->volumes_lock);
839 * self_check_volumes - check information about all volumes.
840 * @ubi: UBI device description object
842 * Returns zero if volumes are all right and a a negative error code if not.
844 static int self_check_volumes(struct ubi_device *ubi)
848 if (!ubi_dbg_chk_gen(ubi))
851 for (i = 0; i < ubi->vtbl_slots; i++) {
852 err = self_check_volume(ubi, i);