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
26 #include <linux/err.h>
27 #include <asm/div64.h>
30 #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
31 static void paranoid_check_volumes(struct ubi_device *ubi);
33 #define paranoid_check_volumes(ubi)
36 static ssize_t vol_attribute_show(struct device *dev,
37 struct device_attribute *attr, char *buf);
39 /* Device attributes corresponding to files in '/<sysfs>/class/ubi/ubiX_Y' */
40 static struct device_attribute attr_vol_reserved_ebs =
41 __ATTR(reserved_ebs, S_IRUGO, vol_attribute_show, NULL);
42 static struct device_attribute attr_vol_type =
43 __ATTR(type, S_IRUGO, vol_attribute_show, NULL);
44 static struct device_attribute attr_vol_name =
45 __ATTR(name, S_IRUGO, vol_attribute_show, NULL);
46 static struct device_attribute attr_vol_corrupted =
47 __ATTR(corrupted, S_IRUGO, vol_attribute_show, NULL);
48 static struct device_attribute attr_vol_alignment =
49 __ATTR(alignment, S_IRUGO, vol_attribute_show, NULL);
50 static struct device_attribute attr_vol_usable_eb_size =
51 __ATTR(usable_eb_size, S_IRUGO, vol_attribute_show, NULL);
52 static struct device_attribute attr_vol_data_bytes =
53 __ATTR(data_bytes, S_IRUGO, vol_attribute_show, NULL);
54 static struct device_attribute attr_vol_upd_marker =
55 __ATTR(upd_marker, S_IRUGO, vol_attribute_show, NULL);
58 * "Show" method for files in '/<sysfs>/class/ubi/ubiX_Y/'.
60 * Consider a situation:
61 * A. process 1 opens a sysfs file related to volume Y, say
62 * /<sysfs>/class/ubi/ubiX_Y/reserved_ebs;
63 * B. process 2 removes volume Y;
64 * C. process 1 starts reading the /<sysfs>/class/ubi/ubiX_Y/reserved_ebs file;
66 * In this situation, this function will return %-ENODEV because it will find
67 * out that the volume was removed from the @ubi->volumes array.
69 static ssize_t vol_attribute_show(struct device *dev,
70 struct device_attribute *attr, char *buf)
73 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev);
74 struct ubi_device *ubi = vol->ubi;
76 spin_lock(&ubi->volumes_lock);
77 if (!ubi->volumes[vol->vol_id]) {
78 spin_unlock(&ubi->volumes_lock);
81 /* Take a reference to prevent volume removal */
83 spin_unlock(&ubi->volumes_lock);
85 if (attr == &attr_vol_reserved_ebs)
86 ret = sprintf(buf, "%d\n", vol->reserved_pebs);
87 else if (attr == &attr_vol_type) {
90 if (vol->vol_type == UBI_DYNAMIC_VOLUME)
94 ret = sprintf(buf, "%s\n", tp);
95 } else if (attr == &attr_vol_name)
96 ret = sprintf(buf, "%s\n", vol->name);
97 else if (attr == &attr_vol_corrupted)
98 ret = sprintf(buf, "%d\n", vol->corrupted);
99 else if (attr == &attr_vol_alignment)
100 ret = sprintf(buf, "%d\n", vol->alignment);
101 else if (attr == &attr_vol_usable_eb_size)
102 ret = sprintf(buf, "%d\n", vol->usable_leb_size);
103 else if (attr == &attr_vol_data_bytes)
104 ret = sprintf(buf, "%lld\n", vol->used_bytes);
105 else if (attr == &attr_vol_upd_marker)
106 ret = sprintf(buf, "%d\n", vol->upd_marker);
108 /* This must be a bug */
111 spin_lock(&ubi->volumes_lock);
113 ubi_assert(vol->ref_count >= 0);
114 spin_unlock(&ubi->volumes_lock);
118 /* Release method for volume devices */
119 static void vol_release(struct device *dev)
121 struct ubi_volume *vol = container_of(dev, struct ubi_volume, dev);
127 * volume_sysfs_init - initialize sysfs for new volume.
128 * @ubi: UBI device description object
129 * @vol: volume description object
131 * This function returns zero in case of success and a negative error code in
134 * Note, this function does not free allocated resources in case of failure -
135 * the caller does it. This is because this would cause release() here and the
138 static int volume_sysfs_init(struct ubi_device *ubi, struct ubi_volume *vol)
142 err = device_create_file(&vol->dev, &attr_vol_reserved_ebs);
145 err = device_create_file(&vol->dev, &attr_vol_type);
148 err = device_create_file(&vol->dev, &attr_vol_name);
151 err = device_create_file(&vol->dev, &attr_vol_corrupted);
154 err = device_create_file(&vol->dev, &attr_vol_alignment);
157 err = device_create_file(&vol->dev, &attr_vol_usable_eb_size);
160 err = device_create_file(&vol->dev, &attr_vol_data_bytes);
163 err = device_create_file(&vol->dev, &attr_vol_upd_marker);
168 * volume_sysfs_close - close sysfs for a volume.
169 * @vol: volume description object
171 static void volume_sysfs_close(struct ubi_volume *vol)
173 device_remove_file(&vol->dev, &attr_vol_upd_marker);
174 device_remove_file(&vol->dev, &attr_vol_data_bytes);
175 device_remove_file(&vol->dev, &attr_vol_usable_eb_size);
176 device_remove_file(&vol->dev, &attr_vol_alignment);
177 device_remove_file(&vol->dev, &attr_vol_corrupted);
178 device_remove_file(&vol->dev, &attr_vol_name);
179 device_remove_file(&vol->dev, &attr_vol_type);
180 device_remove_file(&vol->dev, &attr_vol_reserved_ebs);
181 device_unregister(&vol->dev);
185 * ubi_create_volume - create volume.
186 * @ubi: UBI device description object
187 * @req: volume creation request
189 * This function creates volume described by @req. If @req->vol_id id
190 * %UBI_VOL_NUM_AUTO, this function automatically assign ID to the new volume
191 * and saves it in @req->vol_id. Returns zero in case of success and a negative
192 * error code in case of failure.
194 int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req)
196 int i, err, vol_id = req->vol_id, dont_free = 0;
197 struct ubi_volume *vol;
198 struct ubi_vtbl_record vtbl_rec;
205 vol = kzalloc(sizeof(struct ubi_volume), GFP_KERNEL);
209 mutex_lock(&ubi->volumes_mutex);
210 spin_lock(&ubi->volumes_lock);
211 if (vol_id == UBI_VOL_NUM_AUTO) {
212 /* Find unused volume ID */
213 dbg_msg("search for vacant volume ID");
214 for (i = 0; i < ubi->vtbl_slots; i++)
215 if (!ubi->volumes[i]) {
220 if (vol_id == UBI_VOL_NUM_AUTO) {
221 dbg_err("out of volume IDs");
225 req->vol_id = vol_id;
228 dbg_msg("volume ID %d, %llu bytes, type %d, name %s",
229 vol_id, (unsigned long long)req->bytes,
230 (int)req->vol_type, req->name);
232 /* Ensure that this volume does not exist */
234 if (ubi->volumes[vol_id]) {
235 dbg_err("volume %d already exists", vol_id);
239 /* Ensure that the name is unique */
240 for (i = 0; i < ubi->vtbl_slots; i++)
241 if (ubi->volumes[i] &&
242 ubi->volumes[i]->name_len == req->name_len &&
243 !strcmp(ubi->volumes[i]->name, req->name)) {
244 dbg_err("volume \"%s\" exists (ID %d)", req->name, i);
248 /* Calculate how many eraseblocks are requested */
249 vol->usable_leb_size = ubi->leb_size - ubi->leb_size % req->alignment;
251 if (do_div(bytes, vol->usable_leb_size))
252 vol->reserved_pebs = 1;
253 vol->reserved_pebs += bytes;
255 /* Reserve physical eraseblocks */
256 if (vol->reserved_pebs > ubi->avail_pebs) {
257 dbg_err("not enough PEBs, only %d available", ubi->avail_pebs);
261 ubi->avail_pebs -= vol->reserved_pebs;
262 ubi->rsvd_pebs += vol->reserved_pebs;
264 vol->vol_id = vol_id;
265 vol->alignment = req->alignment;
266 vol->data_pad = ubi->leb_size % vol->alignment;
267 vol->vol_type = req->vol_type;
268 vol->name_len = req->name_len;
269 memcpy(vol->name, req->name, vol->name_len + 1);
272 spin_unlock(&ubi->volumes_lock);
275 * Finish all pending erases because there may be some LEBs belonging
276 * to the same volume ID.
278 err = ubi_wl_flush(ubi);
282 vol->eba_tbl = kmalloc(vol->reserved_pebs * sizeof(int), GFP_KERNEL);
288 for (i = 0; i < vol->reserved_pebs; i++)
289 vol->eba_tbl[i] = UBI_LEB_UNMAPPED;
291 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
292 vol->used_ebs = vol->reserved_pebs;
293 vol->last_eb_bytes = vol->usable_leb_size;
295 (long long)vol->used_ebs * vol->usable_leb_size;
297 bytes = vol->used_bytes;
298 vol->last_eb_bytes = do_div(bytes, vol->usable_leb_size);
299 vol->used_ebs = bytes;
300 if (vol->last_eb_bytes)
303 vol->last_eb_bytes = vol->usable_leb_size;
306 /* Register character device for the volume */
307 cdev_init(&vol->cdev, &ubi_vol_cdev_operations);
308 vol->cdev.owner = THIS_MODULE;
309 dev = MKDEV(MAJOR(ubi->cdev.dev), vol_id + 1);
310 err = cdev_add(&vol->cdev, dev, 1);
312 ubi_err("cannot add character device");
316 err = ubi_create_gluebi(ubi, vol);
320 vol->dev.release = vol_release;
321 vol->dev.parent = &ubi->dev;
323 vol->dev.class = ubi_class;
325 sprintf(&vol->dev.bus_id[0], "%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 + 1);
348 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
352 spin_lock(&ubi->volumes_lock);
355 ubi->volumes[vol_id] = vol;
356 spin_unlock(&ubi->volumes_lock);
358 paranoid_check_volumes(ubi);
359 mutex_unlock(&ubi->volumes_mutex);
364 * We have registered our device, we should not free the volume*
365 * description object in this function in case of an error - it is
366 * freed by the release function.
368 * Get device reference to prevent the release function from being
369 * called just after sysfs has been closed.
372 get_device(&vol->dev);
373 volume_sysfs_close(vol);
375 ubi_destroy_gluebi(vol);
377 cdev_del(&vol->cdev);
381 spin_lock(&ubi->volumes_lock);
382 ubi->rsvd_pebs -= vol->reserved_pebs;
383 ubi->avail_pebs += vol->reserved_pebs;
385 spin_unlock(&ubi->volumes_lock);
386 mutex_unlock(&ubi->volumes_mutex);
388 put_device(&vol->dev);
391 ubi_err("cannot create volume %d, error %d", vol_id, err);
396 * ubi_remove_volume - remove volume.
397 * @desc: volume descriptor
399 * This function removes volume described by @desc. The volume has to be opened
400 * in "exclusive" mode. Returns zero in case of success and a negative error
401 * code in case of failure.
403 int ubi_remove_volume(struct ubi_volume_desc *desc)
405 struct ubi_volume *vol = desc->vol;
406 struct ubi_device *ubi = vol->ubi;
407 int i, err, vol_id = vol->vol_id, reserved_pebs = vol->reserved_pebs;
409 dbg_msg("remove UBI volume %d", vol_id);
410 ubi_assert(desc->mode == UBI_EXCLUSIVE);
411 ubi_assert(vol == ubi->volumes[vol_id]);
416 mutex_lock(&ubi->volumes_mutex);
417 spin_lock(&ubi->volumes_lock);
418 if (vol->ref_count > 1) {
420 * The volume is busy, probably someone is reading one of its
426 ubi->volumes[vol_id] = NULL;
427 spin_unlock(&ubi->volumes_lock);
429 err = ubi_destroy_gluebi(vol);
433 err = ubi_change_vtbl_record(ubi, vol_id, NULL);
437 for (i = 0; i < vol->reserved_pebs; i++) {
438 err = ubi_eba_unmap_leb(ubi, vol, i);
445 cdev_del(&vol->cdev);
446 volume_sysfs_close(vol);
448 spin_lock(&ubi->volumes_lock);
449 ubi->rsvd_pebs -= reserved_pebs;
450 ubi->avail_pebs += reserved_pebs;
451 i = ubi->beb_rsvd_level - ubi->beb_rsvd_pebs;
453 i = ubi->avail_pebs >= i ? i : ubi->avail_pebs;
454 ubi->avail_pebs -= i;
456 ubi->beb_rsvd_pebs += i;
458 ubi_msg("reserve more %d PEBs", i);
461 spin_unlock(&ubi->volumes_lock);
463 paranoid_check_volumes(ubi);
464 mutex_unlock(&ubi->volumes_mutex);
468 ubi_err("cannot remove volume %d, error %d", vol_id, err);
469 spin_lock(&ubi->volumes_lock);
470 ubi->volumes[vol_id] = vol;
472 spin_unlock(&ubi->volumes_lock);
473 mutex_unlock(&ubi->volumes_mutex);
478 * ubi_resize_volume - re-size volume.
479 * @desc: volume descriptor
480 * @reserved_pebs: new size in physical eraseblocks
482 * This function returns zero in case of success, and a negative error code in
485 int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs)
487 int i, err, pebs, *new_mapping;
488 struct ubi_volume *vol = desc->vol;
489 struct ubi_device *ubi = vol->ubi;
490 struct ubi_vtbl_record vtbl_rec;
491 int vol_id = vol->vol_id;
496 dbg_msg("re-size volume %d to from %d to %d PEBs",
497 vol_id, vol->reserved_pebs, reserved_pebs);
498 ubi_assert(desc->mode == UBI_EXCLUSIVE);
499 ubi_assert(vol == ubi->volumes[vol_id]);
501 if (vol->vol_type == UBI_STATIC_VOLUME &&
502 reserved_pebs < vol->used_ebs) {
503 dbg_err("too small size %d, %d LEBs contain data",
504 reserved_pebs, vol->used_ebs);
508 /* If the size is the same, we have nothing to do */
509 if (reserved_pebs == vol->reserved_pebs)
512 new_mapping = kmalloc(reserved_pebs * sizeof(int), GFP_KERNEL);
516 for (i = 0; i < reserved_pebs; i++)
517 new_mapping[i] = UBI_LEB_UNMAPPED;
519 mutex_lock(&ubi->volumes_mutex);
520 spin_lock(&ubi->volumes_lock);
521 if (vol->ref_count > 1) {
522 spin_unlock(&ubi->volumes_lock);
526 spin_unlock(&ubi->volumes_lock);
529 /* Reserve physical eraseblocks */
530 pebs = reserved_pebs - vol->reserved_pebs;
532 spin_lock(&ubi->volumes_lock);
533 if (pebs > ubi->avail_pebs) {
534 dbg_err("not enough PEBs: requested %d, available %d",
535 pebs, ubi->avail_pebs);
536 spin_unlock(&ubi->volumes_lock);
540 ubi->avail_pebs -= pebs;
541 ubi->rsvd_pebs += pebs;
542 for (i = 0; i < vol->reserved_pebs; i++)
543 new_mapping[i] = vol->eba_tbl[i];
545 vol->eba_tbl = new_mapping;
546 spin_unlock(&ubi->volumes_lock);
549 /* Change volume table record */
550 memcpy(&vtbl_rec, &ubi->vtbl[vol_id], sizeof(struct ubi_vtbl_record));
551 vtbl_rec.reserved_pebs = cpu_to_be32(reserved_pebs);
552 err = ubi_change_vtbl_record(ubi, vol_id, &vtbl_rec);
557 for (i = 0; i < -pebs; i++) {
558 err = ubi_eba_unmap_leb(ubi, vol, reserved_pebs + i);
562 spin_lock(&ubi->volumes_lock);
563 ubi->rsvd_pebs += pebs;
564 ubi->avail_pebs -= pebs;
565 pebs = ubi->beb_rsvd_level - ubi->beb_rsvd_pebs;
567 pebs = ubi->avail_pebs >= pebs ? pebs : ubi->avail_pebs;
568 ubi->avail_pebs -= pebs;
569 ubi->rsvd_pebs += pebs;
570 ubi->beb_rsvd_pebs += pebs;
572 ubi_msg("reserve more %d PEBs", pebs);
574 for (i = 0; i < reserved_pebs; i++)
575 new_mapping[i] = vol->eba_tbl[i];
577 vol->eba_tbl = new_mapping;
578 spin_unlock(&ubi->volumes_lock);
581 vol->reserved_pebs = reserved_pebs;
582 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
583 vol->used_ebs = reserved_pebs;
584 vol->last_eb_bytes = vol->usable_leb_size;
586 (long long)vol->used_ebs * vol->usable_leb_size;
589 paranoid_check_volumes(ubi);
590 mutex_unlock(&ubi->volumes_mutex);
595 spin_lock(&ubi->volumes_lock);
596 ubi->rsvd_pebs -= pebs;
597 ubi->avail_pebs += pebs;
598 spin_unlock(&ubi->volumes_lock);
602 mutex_unlock(&ubi->volumes_mutex);
607 * ubi_add_volume - add volume.
608 * @ubi: UBI device description object
609 * @vol: volume description object
611 * This function adds an existing volume and initializes all its data
612 * structures. Returns zero in case of success and a negative error code in
615 int ubi_add_volume(struct ubi_device *ubi, struct ubi_volume *vol)
617 int err, vol_id = vol->vol_id;
620 dbg_msg("add volume %d", vol_id);
621 ubi_dbg_dump_vol_info(vol);
623 /* Register character device for the volume */
624 cdev_init(&vol->cdev, &ubi_vol_cdev_operations);
625 vol->cdev.owner = THIS_MODULE;
626 dev = MKDEV(MAJOR(ubi->cdev.dev), vol->vol_id + 1);
627 err = cdev_add(&vol->cdev, dev, 1);
629 ubi_err("cannot add character device for volume %d, error %d",
634 err = ubi_create_gluebi(ubi, vol);
638 vol->dev.release = vol_release;
639 vol->dev.parent = &ubi->dev;
641 vol->dev.class = ubi_class;
642 sprintf(&vol->dev.bus_id[0], "%s_%d", ubi->ubi_name, vol->vol_id);
643 err = device_register(&vol->dev);
647 err = volume_sysfs_init(ubi, vol);
649 cdev_del(&vol->cdev);
650 err = ubi_destroy_gluebi(vol);
651 volume_sysfs_close(vol);
655 paranoid_check_volumes(ubi);
659 err = ubi_destroy_gluebi(vol);
661 cdev_del(&vol->cdev);
666 * ubi_free_volume - free volume.
667 * @ubi: UBI device description object
668 * @vol: volume description object
670 * This function frees all resources for volume @vol but does not remove it.
671 * Used only when the UBI device is detached.
673 void ubi_free_volume(struct ubi_device *ubi, struct ubi_volume *vol)
677 dbg_msg("free volume %d", vol->vol_id);
679 ubi->volumes[vol->vol_id] = NULL;
680 err = ubi_destroy_gluebi(vol);
681 cdev_del(&vol->cdev);
682 volume_sysfs_close(vol);
685 #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
688 * paranoid_check_volume - check volume information.
689 * @ubi: UBI device description object
692 static void paranoid_check_volume(struct ubi_device *ubi, int vol_id)
694 int idx = vol_id2idx(ubi, vol_id);
695 int reserved_pebs, alignment, data_pad, vol_type, name_len, upd_marker;
696 const struct ubi_volume *vol;
700 spin_lock(&ubi->volumes_lock);
701 reserved_pebs = be32_to_cpu(ubi->vtbl[vol_id].reserved_pebs);
702 vol = ubi->volumes[idx];
706 ubi_err("no volume info, but volume exists");
709 spin_unlock(&ubi->volumes_lock);
713 if (vol->exclusive) {
715 * The volume may be being created at the moment, do not check
716 * it (e.g., it may be in the middle of ubi_create_volume().
718 spin_unlock(&ubi->volumes_lock);
722 if (vol->reserved_pebs < 0 || vol->alignment < 0 || vol->data_pad < 0 ||
724 ubi_err("negative values");
727 if (vol->alignment > ubi->leb_size || vol->alignment == 0) {
728 ubi_err("bad alignment");
732 n = vol->alignment % ubi->min_io_size;
733 if (vol->alignment != 1 && n) {
734 ubi_err("alignment is not multiple of min I/O unit");
738 n = ubi->leb_size % vol->alignment;
739 if (vol->data_pad != n) {
740 ubi_err("bad data_pad, has to be %lld", n);
744 if (vol->vol_type != UBI_DYNAMIC_VOLUME &&
745 vol->vol_type != UBI_STATIC_VOLUME) {
746 ubi_err("bad vol_type");
750 if (vol->upd_marker != 0 && vol->upd_marker != 1) {
751 ubi_err("bad upd_marker");
755 if (vol->upd_marker && vol->corrupted) {
756 dbg_err("update marker and corrupted simultaneously");
760 if (vol->reserved_pebs > ubi->good_peb_count) {
761 ubi_err("too large reserved_pebs");
765 n = ubi->leb_size - vol->data_pad;
766 if (vol->usable_leb_size != ubi->leb_size - vol->data_pad) {
767 ubi_err("bad usable_leb_size, has to be %lld", n);
771 if (vol->name_len > UBI_VOL_NAME_MAX) {
772 ubi_err("too long volume name, max is %d", UBI_VOL_NAME_MAX);
777 ubi_err("NULL volume name");
781 n = strnlen(vol->name, vol->name_len + 1);
782 if (n != vol->name_len) {
783 ubi_err("bad name_len %lld", n);
787 n = (long long)vol->used_ebs * vol->usable_leb_size;
788 if (vol->vol_type == UBI_DYNAMIC_VOLUME) {
789 if (vol->corrupted != 0) {
790 ubi_err("corrupted dynamic volume");
793 if (vol->used_ebs != vol->reserved_pebs) {
794 ubi_err("bad used_ebs");
797 if (vol->last_eb_bytes != vol->usable_leb_size) {
798 ubi_err("bad last_eb_bytes");
801 if (vol->used_bytes != n) {
802 ubi_err("bad used_bytes");
806 if (vol->corrupted != 0 && vol->corrupted != 1) {
807 ubi_err("bad corrupted");
810 if (vol->used_ebs < 0 || vol->used_ebs > vol->reserved_pebs) {
811 ubi_err("bad used_ebs");
814 if (vol->last_eb_bytes < 0 ||
815 vol->last_eb_bytes > vol->usable_leb_size) {
816 ubi_err("bad last_eb_bytes");
819 if (vol->used_bytes < 0 || vol->used_bytes > n ||
820 vol->used_bytes < n - vol->usable_leb_size) {
821 ubi_err("bad used_bytes");
826 alignment = be32_to_cpu(ubi->vtbl[vol_id].alignment);
827 data_pad = be32_to_cpu(ubi->vtbl[vol_id].data_pad);
828 name_len = be16_to_cpu(ubi->vtbl[vol_id].name_len);
829 upd_marker = ubi->vtbl[vol_id].upd_marker;
830 name = &ubi->vtbl[vol_id].name[0];
831 if (ubi->vtbl[vol_id].vol_type == UBI_VID_DYNAMIC)
832 vol_type = UBI_DYNAMIC_VOLUME;
834 vol_type = UBI_STATIC_VOLUME;
836 if (alignment != vol->alignment || data_pad != vol->data_pad ||
837 upd_marker != vol->upd_marker || vol_type != vol->vol_type ||
838 name_len!= vol->name_len || strncmp(name, vol->name, name_len)) {
839 ubi_err("volume info is different");
843 spin_unlock(&ubi->volumes_lock);
847 ubi_err("paranoid check failed for volume %d", vol_id);
848 ubi_dbg_dump_vol_info(vol);
849 ubi_dbg_dump_vtbl_record(&ubi->vtbl[vol_id], vol_id);
850 spin_unlock(&ubi->volumes_lock);
855 * paranoid_check_volumes - check information about all volumes.
856 * @ubi: UBI device description object
858 static void paranoid_check_volumes(struct ubi_device *ubi)
862 for (i = 0; i < ubi->vtbl_slots; i++)
863 paranoid_check_volume(ubi, i);