2 * Copyright (c) International Business Machines Corp., 2006
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12 * the GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Author: Artem Bityutskiy (Битюцкий Артём)
22 * This file contains implementation of volume creation, deletion, updating and
27 #include <linux/err.h>
28 #include <asm/div64.h>
31 #include <ubi_uboot.h>
34 #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
35 static void paranoid_check_volumes(struct ubi_device *ubi);
37 #define paranoid_check_volumes(ubi)
41 static ssize_t vol_attribute_show(struct device *dev,
42 struct device_attribute *attr, char *buf);
44 /* Device attributes corresponding to files in '/<sysfs>/class/ubi/ubiX_Y' */
45 static struct device_attribute attr_vol_reserved_ebs =
46 __ATTR(reserved_ebs, S_IRUGO, vol_attribute_show, NULL);
47 static struct device_attribute attr_vol_type =
48 __ATTR(type, S_IRUGO, vol_attribute_show, NULL);
49 static struct device_attribute attr_vol_name =
50 __ATTR(name, S_IRUGO, vol_attribute_show, NULL);
51 static struct device_attribute attr_vol_corrupted =
52 __ATTR(corrupted, S_IRUGO, vol_attribute_show, NULL);
53 static struct device_attribute attr_vol_alignment =
54 __ATTR(alignment, S_IRUGO, vol_attribute_show, NULL);
55 static struct device_attribute attr_vol_usable_eb_size =
56 __ATTR(usable_eb_size, S_IRUGO, vol_attribute_show, NULL);
57 static struct device_attribute attr_vol_data_bytes =
58 __ATTR(data_bytes, S_IRUGO, vol_attribute_show, NULL);
59 static struct device_attribute attr_vol_upd_marker =
60 __ATTR(upd_marker, S_IRUGO, vol_attribute_show, NULL);
63 * "Show" method for files in '/<sysfs>/class/ubi/ubiX_Y/'.
65 * Consider a situation:
66 * A. process 1 opens a sysfs file related to volume Y, say
67 * /<sysfs>/class/ubi/ubiX_Y/reserved_ebs;
68 * B. process 2 removes volume Y;
69 * C. process 1 starts reading the /<sysfs>/class/ubi/ubiX_Y/reserved_ebs file;
71 * In this situation, this function will return %-ENODEV because it will find
72 * out that the volume was removed from the @ubi->volumes array.
74 static ssize_t vol_attribute_show(struct device *dev,
75 struct device_attribute *attr, char *buf)
78 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev);
79 struct ubi_device *ubi;
81 ubi = ubi_get_device(vol->ubi->ubi_num);
85 spin_lock(&ubi->volumes_lock);
86 if (!ubi->volumes[vol->vol_id]) {
87 spin_unlock(&ubi->volumes_lock);
91 /* Take a reference to prevent volume removal */
93 spin_unlock(&ubi->volumes_lock);
95 if (attr == &attr_vol_reserved_ebs)
96 ret = sprintf(buf, "%d\n", vol->reserved_pebs);
97 else if (attr == &attr_vol_type) {
100 if (vol->vol_type == UBI_DYNAMIC_VOLUME)
104 ret = sprintf(buf, "%s\n", tp);
105 } else if (attr == &attr_vol_name)
106 ret = sprintf(buf, "%s\n", vol->name);
107 else if (attr == &attr_vol_corrupted)
108 ret = sprintf(buf, "%d\n", vol->corrupted);
109 else if (attr == &attr_vol_alignment)
110 ret = sprintf(buf, "%d\n", vol->alignment);
111 else if (attr == &attr_vol_usable_eb_size)
112 ret = sprintf(buf, "%d\n", vol->usable_leb_size);
113 else if (attr == &attr_vol_data_bytes)
114 ret = sprintf(buf, "%lld\n", vol->used_bytes);
115 else if (attr == &attr_vol_upd_marker)
116 ret = sprintf(buf, "%d\n", vol->upd_marker);
118 /* This must be a bug */
121 /* We've done the operation, drop volume and UBI device references */
122 spin_lock(&ubi->volumes_lock);
124 ubi_assert(vol->ref_count >= 0);
125 spin_unlock(&ubi->volumes_lock);
131 /* Release method for volume devices */
132 static void vol_release(struct device *dev)
134 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev);
141 * volume_sysfs_init - initialize sysfs for new volume.
142 * @ubi: UBI device description object
143 * @vol: volume description object
145 * This function returns zero in case of success and a negative error code in
148 * Note, this function does not free allocated resources in case of failure -
149 * the caller does it. This is because this would cause release() here and the
152 static int volume_sysfs_init(struct ubi_device *ubi, struct ubi_volume *vol)
156 err = device_create_file(&vol->dev, &attr_vol_reserved_ebs);
159 err = device_create_file(&vol->dev, &attr_vol_type);
162 err = device_create_file(&vol->dev, &attr_vol_name);
165 err = device_create_file(&vol->dev, &attr_vol_corrupted);
168 err = device_create_file(&vol->dev, &attr_vol_alignment);
171 err = device_create_file(&vol->dev, &attr_vol_usable_eb_size);
174 err = device_create_file(&vol->dev, &attr_vol_data_bytes);
177 err = device_create_file(&vol->dev, &attr_vol_upd_marker);
182 * volume_sysfs_close - close sysfs for a volume.
183 * @vol: volume description object
185 static void volume_sysfs_close(struct ubi_volume *vol)
187 device_remove_file(&vol->dev, &attr_vol_upd_marker);
188 device_remove_file(&vol->dev, &attr_vol_data_bytes);
189 device_remove_file(&vol->dev, &attr_vol_usable_eb_size);
190 device_remove_file(&vol->dev, &attr_vol_alignment);
191 device_remove_file(&vol->dev, &attr_vol_corrupted);
192 device_remove_file(&vol->dev, &attr_vol_name);
193 device_remove_file(&vol->dev, &attr_vol_type);
194 device_remove_file(&vol->dev, &attr_vol_reserved_ebs);
195 device_unregister(&vol->dev);
200 * ubi_create_volume - create volume.
201 * @ubi: UBI device description object
202 * @req: volume creation request
204 * This function creates volume described by @req. If @req->vol_id id
205 * %UBI_VOL_NUM_AUTO, this function automatically assign ID to the new volume
206 * and saves it in @req->vol_id. Returns zero in case of success and a negative
207 * error code in case of failure. Note, the caller has to have the
208 * @ubi->volumes_mutex locked.
210 int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
212 int i, err, vol_id = req->vol_id, dont_free = 0;
213 struct ubi_volume *vol;
214 struct ubi_vtbl_record vtbl_rec;
221 vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL);
225 spin_lock(&ubi->volumes_lock);
226 if (vol_id == UBI_VOL_NUM_AUTO) {
227 /* Find unused volume ID */
228 dbg_msg("search for vacant volume ID");
229 for (i = 0; i < ubi->vtbl_slots; i++)
230 if (!ubi->volumes[i]) {
235 if (vol_id == UBI_VOL_NUM_AUTO) {
236 dbg_err("out of volume IDs");
240 req->vol_id = vol_id;
243 dbg_msg("volume ID %d, %llu bytes, type %d, name %s",
244 vol_id, (unsigned long long)req->bytes,
245 (int)req->vol_type, req->name);
247 /* Ensure that this volume does not exist */
249 if (ubi->volumes[vol_id]) {
250 dbg_err("volume %d already exists", vol_id);
254 /* Ensure that the name is unique */
255 for (i = 0; i < ubi->vtbl_slots; i++)
256 if (ubi->volumes[i] &&
257 ubi->volumes[i]->name_len == req->name_len &&
258 !strcmp(ubi->volumes[i]->name, req->name)) {
259 dbg_err("volume \"%s\" exists (ID %d)", req->name, i);
263 /* Calculate how many eraseblocks are requested */
264 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment;
266 if (do_div(bytes, vol->usable_leb_size))
267 vol->reserved_pebs = 1;
268 vol->reserved_pebs += bytes;
270 /* Reserve physical eraseblocks */
271 if (vol->reserved_pebs > ubi->avail_pebs) {
272 dbg_err("not enough PEBs, only %d available", ubi->avail_pebs);
276 ubi->avail_pebs -= vol->reserved_pebs;
277 ubi->rsvd_pebs += vol->reserved_pebs;
278 spin_unlock(&ubi->volumes_lock);
280 vol->vol_id = vol_id;
281 vol->alignment = req->alignment;
282 vol->data_pad = ubi->leb_size % vol->alignment;
283 vol->vol_type = req->vol_type;
284 vol->name_len = req->name_len;
285 memcpy(vol->name, req->name, vol->name_len + 1);
289 * Finish all pending erases because there may be some LEBs belonging
290 * to the same volume ID.
292 err = ubi_wl_flush(ubi);
296 vol->eba_tbl = kmalloc(vol->reserved_pebs * sizeof(int), GFP_KERNEL);
302 for (i = 0; i < vol->reserved_pebs; i++)
303 vol->eba_tbl[i] = UBI_LEB_UNMAPPED;
305 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
306 vol->used_ebs = vol->reserved_pebs;
307 vol->last_eb_bytes = vol->usable_leb_size;
309 (long long)vol->used_ebs * vol->usable_leb_size;
311 bytes = vol->used_bytes;
312 vol->last_eb_bytes = do_div(bytes, vol->usable_leb_size);
313 vol->used_ebs = bytes;
314 if (vol->last_eb_bytes)
317 vol->last_eb_bytes = vol->usable_leb_size;
320 /* Register character device for the volume */
321 cdev_init(&vol->cdev, &ubi_vol_cdev_operations);
322 vol->cdev.owner = THIS_MODULE;
323 dev = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1);
324 err = cdev_add(&vol->cdev, dev, 1);
326 ubi_err("cannot add character device");
330 err = ubi_create_gluebi(ubi, vol);
334 vol->dev.release = vol_release;
335 vol->dev.parent = &ubi->dev;
337 vol->dev.class = ubi_class;
339 sprintf(&vol->dev.bus_id[0], "%s_%d", ubi->ubi_name, vol->vol_id);
340 err = device_register(&vol->dev);
342 ubi_err("cannot register device");
346 err = volume_sysfs_init(ubi, vol);
350 /* Fill volume table record */
351 memset(&vtbl_rec, 0, sizeof(struct ubi_vtbl_record));
352 vtbl_rec.reserved_pebs = cpu_to_be32(vol->reserved_pebs);
353 vtbl_rec.alignment = cpu_to_be32(vol->alignment);
354 vtbl_rec.data_pad = cpu_to_be32(vol->data_pad);
355 vtbl_rec.name_len = cpu_to_be16(vol->name_len);
356 if (vol->vol_type == UBI_DYNAMIC_VOLUME)
357 vtbl_rec.vol_type = UBI_VID_DYNAMIC;
359 vtbl_rec.vol_type = UBI_VID_STATIC;
360 memcpy(vtbl_rec.name, vol->name, vol->name_len + 1);
362 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
366 spin_lock(&ubi->volumes_lock);
367 ubi->volumes[vol_id] = vol;
369 spin_unlock(&ubi->volumes_lock);
371 paranoid_check_volumes(ubi);
376 * We have registered our device, we should not free the volume*
377 * description object in this function in case of an error - it is
378 * freed by the release function.
380 * Get device reference to prevent the release function from being
381 * called just after sysfs has been closed.
384 get_device(&vol->dev);
385 volume_sysfs_close(vol);
387 if (ubi_destroy_gluebi(vol))
388 dbg_err("cannot destroy gluebi for volume %d:%d",
389 ubi->ubi_num, vol_id);
391 cdev_del(&vol->cdev);
395 spin_lock(&ubi->volumes_lock);
396 ubi->rsvd_pebs -= vol->reserved_pebs;
397 ubi->avail_pebs += vol->reserved_pebs;
399 spin_unlock(&ubi->volumes_lock);
401 put_device(&vol->dev);
404 ubi_err("cannot create volume %d, error %d", vol_id, err);
409 * ubi_remove_volume - remove volume.
410 * @desc: volume descriptor
412 * This function removes volume described by @desc. The volume has to be opened
413 * in "exclusive" mode. Returns zero in case of success and a negative error
414 * code in case of failure. The caller has to have the @ubi->volumes_mutex
417 int ubi_remove_volume(struct ubi_volume_desc *desc)
419 struct ubi_volume *vol = desc->vol;
420 struct ubi_device *ubi = vol->ubi;
421 int i, err, vol_id = vol->vol_id, reserved_pebs = vol->reserved_pebs;
423 dbg_msg("remove UBI volume %d", vol_id);
424 ubi_assert(desc->mode == UBI_EXCLUSIVE);
425 ubi_assert(vol == ubi->volumes[vol_id]);
430 spin_lock(&ubi->volumes_lock);
431 if (vol->ref_count > 1) {
433 * The volume is busy, probably someone is reading one of its
439 ubi->volumes[vol_id] = NULL;
440 spin_unlock(&ubi->volumes_lock);
442 err = ubi_destroy_gluebi(vol);
446 err = ubi_change_vtbl_record(ubi, vol_id, NULL);
450 for (i = 0; i < vol->reserved_pebs; i++) {
451 err = ubi_eba_unmap_leb(ubi, vol, i);
458 cdev_del(&vol->cdev);
459 volume_sysfs_close(vol);
461 spin_lock(&ubi->volumes_lock);
462 ubi->rsvd_pebs -= reserved_pebs;
463 ubi->avail_pebs += reserved_pebs;
464 i = ubi->beb_rsvd_level - ubi->beb_rsvd_pebs;
466 i = ubi->avail_pebs >= i ? i : ubi->avail_pebs;
467 ubi->avail_pebs -= i;
469 ubi->beb_rsvd_pebs += i;
471 ubi_msg("reserve more %d PEBs", i);
474 spin_unlock(&ubi->volumes_lock);
476 paranoid_check_volumes(ubi);
480 ubi_err("cannot remove volume %d, error %d", vol_id, err);
481 spin_lock(&ubi->volumes_lock);
482 ubi->volumes[vol_id] = vol;
484 spin_unlock(&ubi->volumes_lock);
489 * ubi_resize_volume - re-size volume.
490 * @desc: volume descriptor
491 * @reserved_pebs: new size in physical eraseblocks
493 * This function re-sizes the volume and returns zero in case of success, and a
494 * negative error code in case of failure. The caller has to have the
495 * @ubi->volumes_mutex locked.
497 int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
499 int i, err, pebs, *new_mapping;
500 struct ubi_volume *vol = desc->vol;
501 struct ubi_device *ubi = vol->ubi;
502 struct ubi_vtbl_record vtbl_rec;
503 int vol_id = vol->vol_id;
508 dbg_msg("re-size volume %d to from %d to %d PEBs",
509 vol_id, vol->reserved_pebs, reserved_pebs);
511 if (vol->vol_type == UBI_STATIC_VOLUME &&
512 reserved_pebs < vol->used_ebs) {
513 dbg_err("too small size %d, %d LEBs contain data",
514 reserved_pebs, vol->used_ebs);
518 /* If the size is the same, we have nothing to do */
519 if (reserved_pebs == vol->reserved_pebs)
522 new_mapping = kmalloc(reserved_pebs * sizeof(int), GFP_KERNEL);
526 for (i = 0; i < reserved_pebs; i++)
527 new_mapping[i] = UBI_LEB_UNMAPPED;
529 spin_lock(&ubi->volumes_lock);
530 if (vol->ref_count > 1) {
531 spin_unlock(&ubi->volumes_lock);
535 spin_unlock(&ubi->volumes_lock);
537 /* Reserve physical eraseblocks */
538 pebs = reserved_pebs - vol->reserved_pebs;
540 spin_lock(&ubi->volumes_lock);
541 if (pebs > ubi->avail_pebs) {
542 dbg_err("not enough PEBs: requested %d, available %d",
543 pebs, ubi->avail_pebs);
544 spin_unlock(&ubi->volumes_lock);
548 ubi->avail_pebs -= pebs;
549 ubi->rsvd_pebs += pebs;
550 for (i = 0; i < vol->reserved_pebs; i++)
551 new_mapping[i] = vol->eba_tbl[i];
553 vol->eba_tbl = new_mapping;
554 spin_unlock(&ubi->volumes_lock);
557 /* Change volume table record */
558 memcpy(&vtbl_rec, &ubi->vtbl[vol_id], sizeof(struct ubi_vtbl_record));
559 vtbl_rec.reserved_pebs = cpu_to_be32(reserved_pebs);
560 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
565 for (i = 0; i < -pebs; i++) {
566 err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i);
570 spin_lock(&ubi->volumes_lock);
571 ubi->rsvd_pebs += pebs;
572 ubi->avail_pebs -= pebs;
573 pebs = ubi->beb_rsvd_level - ubi->beb_rsvd_pebs;
575 pebs = ubi->avail_pebs >= pebs ? pebs : ubi->avail_pebs;
576 ubi->avail_pebs -= pebs;
577 ubi->rsvd_pebs += pebs;
578 ubi->beb_rsvd_pebs += pebs;
580 ubi_msg("reserve more %d PEBs", pebs);
582 for (i = 0; i < reserved_pebs; i++)
583 new_mapping[i] = vol->eba_tbl[i];
585 vol->eba_tbl = new_mapping;
586 spin_unlock(&ubi->volumes_lock);
589 vol->reserved_pebs = reserved_pebs;
590 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
591 vol->used_ebs = reserved_pebs;
592 vol->last_eb_bytes = vol->usable_leb_size;
594 (long long)vol->used_ebs * vol->usable_leb_size;
597 paranoid_check_volumes(ubi);
602 spin_lock(&ubi->volumes_lock);
603 ubi->rsvd_pebs -= pebs;
604 ubi->avail_pebs += pebs;
605 spin_unlock(&ubi->volumes_lock);
613 * ubi_add_volume - add volume.
614 * @ubi: UBI device description object
615 * @vol: volume description object
617 * This function adds an existing volume and initializes all its data
618 * structures. Returns zero in case of success and a negative error code in
621 int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol)
623 int err, vol_id = vol->vol_id;
626 dbg_msg("add volume %d", vol_id);
627 ubi_dbg_dump_vol_info(vol);
629 /* Register character device for the volume */
630 cdev_init(&vol->cdev, &ubi_vol_cdev_operations);
631 vol->cdev.owner = THIS_MODULE;
632 dev = MKDEV(MAJOR(ubi->cdev.dev), vol->vol_id + 1);
633 err = cdev_add(&vol->cdev, dev, 1);
635 ubi_err("cannot add character device for volume %d, error %d",
640 err = ubi_create_gluebi(ubi, vol);
644 vol->dev.release = vol_release;
645 vol->dev.parent = &ubi->dev;
647 vol->dev.class = ubi_class;
648 sprintf(&vol->dev.bus_id[0], "%s_%d", ubi->ubi_name, vol->vol_id);
649 err = device_register(&vol->dev);
653 err = volume_sysfs_init(ubi, vol);
655 cdev_del(&vol->cdev);
656 err = ubi_destroy_gluebi(vol);
657 volume_sysfs_close(vol);
661 paranoid_check_volumes(ubi);
665 err = ubi_destroy_gluebi(vol);
667 cdev_del(&vol->cdev);
672 * ubi_free_volume - free volume.
673 * @ubi: UBI device description object
674 * @vol: volume description object
676 * This function frees all resources for volume @vol but does not remove it.
677 * Used only when the UBI device is detached.
679 void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol)
681 dbg_msg("free volume %d", vol->vol_id);
683 ubi->volumes[vol->vol_id] = NULL;
684 ubi_destroy_gluebi(vol);
685 cdev_del(&vol->cdev);
686 volume_sysfs_close(vol);
689 #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
692 * paranoid_check_volume - check volume information.
693 * @ubi: UBI device description object
696 static void paranoid_check_volume(struct ubi_device *ubi, int vol_id)
698 int idx = vol_id2idx(ubi, vol_id);
699 int reserved_pebs, alignment, data_pad, vol_type, name_len, upd_marker;
700 const struct ubi_volume *vol;
704 spin_lock(&ubi->volumes_lock);
705 reserved_pebs = be32_to_cpu(ubi->vtbl[vol_id].reserved_pebs);
706 vol = ubi->volumes[idx];
710 ubi_err("no volume info, but volume exists");
713 spin_unlock(&ubi->volumes_lock);
717 if (vol->exclusive) {
719 * The volume may be being created at the moment, do not check
720 * it (e.g., it may be in the middle of ubi_create_volume().
722 spin_unlock(&ubi->volumes_lock);
726 if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 ||
728 ubi_err("negative values");
731 if (vol->alignment > ubi->leb_size || vol->alignment == 0) {
732 ubi_err("bad alignment");
736 n = vol->alignment & (ubi->min_io_size - 1);
737 if (vol->alignment != 1 && n) {
738 ubi_err("alignment is not multiple of min I/O unit");
742 n = ubi->leb_size % vol->alignment;
743 if (vol->data_pad != n) {
744 ubi_err("bad data_pad, has to be %lld", n);
748 if (vol->vol_type != UBI_DYNAMIC_VOLUME &&
749 vol->vol_type != UBI_STATIC_VOLUME) {
750 ubi_err("bad vol_type");
754 if (vol->upd_marker && vol->corrupted) {
755 dbg_err("update marker and corrupted simultaneously");
759 if (vol->reserved_pebs > ubi->good_peb_count) {
760 ubi_err("too large reserved_pebs");
764 n = ubi->leb_size - vol->data_pad;
765 if (vol->usable_leb_size != ubi->leb_size - vol->data_pad) {
766 ubi_err("bad usable_leb_size, has to be %lld", n);
770 if (vol->name_len > UBI_VOL_NAME_MAX) {
771 ubi_err("too long volume name, max is %d", UBI_VOL_NAME_MAX);
776 ubi_err("NULL volume name");
780 n = strnlen(vol->name, vol->name_len + 1);
781 if (n != vol->name_len) {
782 ubi_err("bad name_len %lld", n);
786 n = (long long)vol->used_ebs * vol->usable_leb_size;
787 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
788 if (vol->corrupted) {
789 ubi_err("corrupted dynamic volume");
792 if (vol->used_ebs != vol->reserved_pebs) {
793 ubi_err("bad used_ebs");
796 if (vol->last_eb_bytes != vol->usable_leb_size) {
797 ubi_err("bad last_eb_bytes");
800 if (vol->used_bytes != n) {
801 ubi_err("bad used_bytes");
805 if (vol->used_ebs < 0 || vol->used_ebs > vol->reserved_pebs) {
806 ubi_err("bad used_ebs");
809 if (vol->last_eb_bytes < 0 ||
810 vol->last_eb_bytes > vol->usable_leb_size) {
811 ubi_err("bad last_eb_bytes");
814 if (vol->used_bytes < 0 || vol->used_bytes > n ||
815 vol->used_bytes < n - vol->usable_leb_size) {
816 ubi_err("bad used_bytes");
821 alignment = be32_to_cpu(ubi->vtbl[vol_id].alignment);
822 data_pad = be32_to_cpu(ubi->vtbl[vol_id].data_pad);
823 name_len = be16_to_cpu(ubi->vtbl[vol_id].name_len);
824 upd_marker = ubi->vtbl[vol_id].upd_marker;
825 name = &ubi->vtbl[vol_id].name[0];
826 if (ubi->vtbl[vol_id].vol_type == UBI_VID_DYNAMIC)
827 vol_type = UBI_DYNAMIC_VOLUME;
829 vol_type = UBI_STATIC_VOLUME;
831 if (alignment != vol->alignment || data_pad != vol->data_pad ||
832 upd_marker != vol->upd_marker || vol_type != vol->vol_type ||
833 name_len!= vol->name_len || strncmp(name, vol->name, name_len)) {
834 ubi_err("volume info is different");
838 spin_unlock(&ubi->volumes_lock);
842 ubi_err("paranoid check failed for volume %d", vol_id);
843 ubi_dbg_dump_vol_info(vol);
844 ubi_dbg_dump_vtbl_record(&ubi->vtbl[vol_id], vol_id);
845 spin_unlock(&ubi->volumes_lock);
850 * paranoid_check_volumes - check information about all volumes.
851 * @ubi: UBI device description object
853 static void paranoid_check_volumes(struct ubi_device *ubi)
857 for (i = 0; i < ubi->vtbl_slots; i++)
858 paranoid_check_volume(ubi, i);