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 <asm/div64.h>
19 #include <ubi_uboot.h>
22 #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
23 static void paranoid_check_volumes(struct ubi_device
*ubi
);
25 #define paranoid_check_volumes(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
);
129 * volume_sysfs_init - initialize sysfs for new volume.
130 * @ubi: UBI device description object
131 * @vol: volume description object
133 * This function returns zero in case of success and a negative error code in
136 * Note, this function does not free allocated resources in case of failure -
137 * the caller does it. This is because this would cause release() here and the
140 static int volume_sysfs_init(struct ubi_device
*ubi
, struct ubi_volume
*vol
)
144 err
= device_create_file(&vol
->dev
, &attr_vol_reserved_ebs
);
147 err
= device_create_file(&vol
->dev
, &attr_vol_type
);
150 err
= device_create_file(&vol
->dev
, &attr_vol_name
);
153 err
= device_create_file(&vol
->dev
, &attr_vol_corrupted
);
156 err
= device_create_file(&vol
->dev
, &attr_vol_alignment
);
159 err
= device_create_file(&vol
->dev
, &attr_vol_usable_eb_size
);
162 err
= device_create_file(&vol
->dev
, &attr_vol_data_bytes
);
165 err
= device_create_file(&vol
->dev
, &attr_vol_upd_marker
);
170 * volume_sysfs_close - close sysfs for a volume.
171 * @vol: volume description object
173 static void volume_sysfs_close(struct ubi_volume
*vol
)
175 device_remove_file(&vol
->dev
, &attr_vol_upd_marker
);
176 device_remove_file(&vol
->dev
, &attr_vol_data_bytes
);
177 device_remove_file(&vol
->dev
, &attr_vol_usable_eb_size
);
178 device_remove_file(&vol
->dev
, &attr_vol_alignment
);
179 device_remove_file(&vol
->dev
, &attr_vol_corrupted
);
180 device_remove_file(&vol
->dev
, &attr_vol_name
);
181 device_remove_file(&vol
->dev
, &attr_vol_type
);
182 device_remove_file(&vol
->dev
, &attr_vol_reserved_ebs
);
183 device_unregister(&vol
->dev
);
188 * ubi_create_volume - create volume.
189 * @ubi: UBI device description object
190 * @req: volume creation request
192 * This function creates volume described by @req. If @req->vol_id id
193 * %UBI_VOL_NUM_AUTO, this function automatically assign ID to the new volume
194 * and saves it in @req->vol_id. Returns zero in case of success and a negative
195 * error code in case of failure. Note, the caller has to have the
196 * @ubi->volumes_mutex locked.
198 int ubi_create_volume(struct ubi_device
*ubi
, struct ubi_mkvol_req
*req
)
200 int i
, err
, vol_id
= req
->vol_id
, dont_free
= 0;
201 struct ubi_volume
*vol
;
202 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_msg("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 dbg_err("out of volume IDs");
228 req
->vol_id
= vol_id
;
231 dbg_msg("volume ID %d, %llu bytes, type %d, name %s",
232 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 dbg_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 dbg_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
;
254 if (do_div(bytes
, vol
->usable_leb_size
))
255 vol
->reserved_pebs
= 1;
256 vol
->reserved_pebs
+= bytes
;
258 /* Reserve physical eraseblocks */
259 if (vol
->reserved_pebs
> ubi
->avail_pebs
) {
260 dbg_err("not enough PEBs, only %d available", ubi
->avail_pebs
);
264 ubi
->avail_pebs
-= vol
->reserved_pebs
;
265 ubi
->rsvd_pebs
+= vol
->reserved_pebs
;
266 spin_unlock(&ubi
->volumes_lock
);
268 vol
->vol_id
= vol_id
;
269 vol
->alignment
= req
->alignment
;
270 vol
->data_pad
= ubi
->leb_size
% vol
->alignment
;
271 vol
->vol_type
= req
->vol_type
;
272 vol
->name_len
= req
->name_len
;
273 memcpy(vol
->name
, req
->name
, vol
->name_len
+ 1);
277 * Finish all pending erases because there may be some LEBs belonging
278 * to the same volume ID.
280 err
= ubi_wl_flush(ubi
);
284 vol
->eba_tbl
= kmalloc(vol
->reserved_pebs
* sizeof(int), GFP_KERNEL
);
290 for (i
= 0; i
< vol
->reserved_pebs
; i
++)
291 vol
->eba_tbl
[i
] = UBI_LEB_UNMAPPED
;
293 if (vol
->vol_type
== UBI_DYNAMIC_VOLUME
) {
294 vol
->used_ebs
= vol
->reserved_pebs
;
295 vol
->last_eb_bytes
= vol
->usable_leb_size
;
297 (long long)vol
->used_ebs
* vol
->usable_leb_size
;
299 bytes
= vol
->used_bytes
;
300 vol
->last_eb_bytes
= do_div(bytes
, vol
->usable_leb_size
);
301 vol
->used_ebs
= bytes
;
302 if (vol
->last_eb_bytes
)
305 vol
->last_eb_bytes
= vol
->usable_leb_size
;
308 /* Register character device for the volume */
309 cdev_init(&vol
->cdev
, &ubi_vol_cdev_operations
);
310 vol
->cdev
.owner
= THIS_MODULE
;
311 dev
= MKDEV(MAJOR(ubi
->cdev
.dev
), vol_id
+ 1);
312 err
= cdev_add(&vol
->cdev
, dev
, 1);
314 ubi_err("cannot add character device");
318 err
= ubi_create_gluebi(ubi
, vol
);
322 vol
->dev
.release
= vol_release
;
323 vol
->dev
.parent
= &ubi
->dev
;
325 vol
->dev
.class = ubi_class
;
327 sprintf(&vol
->dev
.bus_id
[0], "%s_%d", ubi
->ubi_name
, vol
->vol_id
);
328 err
= device_register(&vol
->dev
);
330 ubi_err("cannot register device");
334 err
= volume_sysfs_init(ubi
, vol
);
338 /* Fill volume table record */
339 memset(&vtbl_rec
, 0, sizeof(struct ubi_vtbl_record
));
340 vtbl_rec
.reserved_pebs
= cpu_to_be32(vol
->reserved_pebs
);
341 vtbl_rec
.alignment
= cpu_to_be32(vol
->alignment
);
342 vtbl_rec
.data_pad
= cpu_to_be32(vol
->data_pad
);
343 vtbl_rec
.name_len
= cpu_to_be16(vol
->name_len
);
344 if (vol
->vol_type
== UBI_DYNAMIC_VOLUME
)
345 vtbl_rec
.vol_type
= UBI_VID_DYNAMIC
;
347 vtbl_rec
.vol_type
= UBI_VID_STATIC
;
348 memcpy(vtbl_rec
.name
, vol
->name
, vol
->name_len
+ 1);
350 err
= ubi_change_vtbl_record(ubi
, vol_id
, &vtbl_rec
);
354 spin_lock(&ubi
->volumes_lock
);
355 ubi
->volumes
[vol_id
] = vol
;
357 spin_unlock(&ubi
->volumes_lock
);
359 paranoid_check_volumes(ubi
);
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 if (ubi_destroy_gluebi(vol
))
376 dbg_err("cannot destroy gluebi for volume %d:%d",
377 ubi
->ubi_num
, vol_id
);
379 cdev_del(&vol
->cdev
);
383 spin_lock(&ubi
->volumes_lock
);
384 ubi
->rsvd_pebs
-= vol
->reserved_pebs
;
385 ubi
->avail_pebs
+= vol
->reserved_pebs
;
387 spin_unlock(&ubi
->volumes_lock
);
389 put_device(&vol
->dev
);
392 ubi_err("cannot create volume %d, error %d", vol_id
, err
);
397 * ubi_remove_volume - remove volume.
398 * @desc: volume descriptor
400 * This function removes volume described by @desc. The volume has to be opened
401 * in "exclusive" mode. Returns zero in case of success and a negative error
402 * code in case of failure. The caller has to have the @ubi->volumes_mutex
405 int ubi_remove_volume(struct ubi_volume_desc
*desc
)
407 struct ubi_volume
*vol
= desc
->vol
;
408 struct ubi_device
*ubi
= vol
->ubi
;
409 int i
, err
, vol_id
= vol
->vol_id
, reserved_pebs
= vol
->reserved_pebs
;
411 dbg_msg("remove UBI volume %d", vol_id
);
412 ubi_assert(desc
->mode
== UBI_EXCLUSIVE
);
413 ubi_assert(vol
== ubi
->volumes
[vol_id
]);
418 spin_lock(&ubi
->volumes_lock
);
419 if (vol
->ref_count
> 1) {
421 * The volume is busy, probably someone is reading one of its
427 ubi
->volumes
[vol_id
] = NULL
;
428 spin_unlock(&ubi
->volumes_lock
);
430 err
= ubi_destroy_gluebi(vol
);
434 err
= ubi_change_vtbl_record(ubi
, vol_id
, NULL
);
438 for (i
= 0; i
< vol
->reserved_pebs
; i
++) {
439 err
= ubi_eba_unmap_leb(ubi
, vol
, i
);
446 cdev_del(&vol
->cdev
);
447 volume_sysfs_close(vol
);
449 spin_lock(&ubi
->volumes_lock
);
450 ubi
->rsvd_pebs
-= reserved_pebs
;
451 ubi
->avail_pebs
+= reserved_pebs
;
452 i
= ubi
->beb_rsvd_level
- ubi
->beb_rsvd_pebs
;
454 i
= ubi
->avail_pebs
>= i
? i
: ubi
->avail_pebs
;
455 ubi
->avail_pebs
-= i
;
457 ubi
->beb_rsvd_pebs
+= i
;
459 ubi_msg("reserve more %d PEBs", i
);
462 spin_unlock(&ubi
->volumes_lock
);
464 paranoid_check_volumes(ubi
);
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
);
477 * ubi_resize_volume - re-size volume.
478 * @desc: volume descriptor
479 * @reserved_pebs: new size in physical eraseblocks
481 * This function re-sizes the volume and returns zero in case of success, and a
482 * negative error code in case of failure. The caller has to have the
483 * @ubi->volumes_mutex locked.
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
);
499 if (vol
->vol_type
== UBI_STATIC_VOLUME
&&
500 reserved_pebs
< vol
->used_ebs
) {
501 dbg_err("too small size %d, %d LEBs contain data",
502 reserved_pebs
, vol
->used_ebs
);
506 /* If the size is the same, we have nothing to do */
507 if (reserved_pebs
== vol
->reserved_pebs
)
510 new_mapping
= kmalloc(reserved_pebs
* sizeof(int), GFP_KERNEL
);
514 for (i
= 0; i
< reserved_pebs
; i
++)
515 new_mapping
[i
] = UBI_LEB_UNMAPPED
;
517 spin_lock(&ubi
->volumes_lock
);
518 if (vol
->ref_count
> 1) {
519 spin_unlock(&ubi
->volumes_lock
);
523 spin_unlock(&ubi
->volumes_lock
);
525 /* Reserve physical eraseblocks */
526 pebs
= reserved_pebs
- vol
->reserved_pebs
;
528 spin_lock(&ubi
->volumes_lock
);
529 if (pebs
> ubi
->avail_pebs
) {
530 dbg_err("not enough PEBs: requested %d, available %d",
531 pebs
, ubi
->avail_pebs
);
532 spin_unlock(&ubi
->volumes_lock
);
536 ubi
->avail_pebs
-= pebs
;
537 ubi
->rsvd_pebs
+= pebs
;
538 for (i
= 0; i
< vol
->reserved_pebs
; i
++)
539 new_mapping
[i
] = vol
->eba_tbl
[i
];
541 vol
->eba_tbl
= new_mapping
;
542 spin_unlock(&ubi
->volumes_lock
);
545 /* Change volume table record */
546 memcpy(&vtbl_rec
, &ubi
->vtbl
[vol_id
], sizeof(struct ubi_vtbl_record
));
547 vtbl_rec
.reserved_pebs
= cpu_to_be32(reserved_pebs
);
548 err
= ubi_change_vtbl_record(ubi
, vol_id
, &vtbl_rec
);
553 for (i
= 0; i
< -pebs
; i
++) {
554 err
= ubi_eba_unmap_leb(ubi
, vol
, reserved_pebs
+ i
);
558 spin_lock(&ubi
->volumes_lock
);
559 ubi
->rsvd_pebs
+= pebs
;
560 ubi
->avail_pebs
-= pebs
;
561 pebs
= ubi
->beb_rsvd_level
- ubi
->beb_rsvd_pebs
;
563 pebs
= ubi
->avail_pebs
>= pebs
? pebs
: ubi
->avail_pebs
;
564 ubi
->avail_pebs
-= pebs
;
565 ubi
->rsvd_pebs
+= pebs
;
566 ubi
->beb_rsvd_pebs
+= pebs
;
568 ubi_msg("reserve more %d PEBs", pebs
);
570 for (i
= 0; i
< reserved_pebs
; i
++)
571 new_mapping
[i
] = vol
->eba_tbl
[i
];
573 vol
->eba_tbl
= new_mapping
;
574 spin_unlock(&ubi
->volumes_lock
);
577 vol
->reserved_pebs
= reserved_pebs
;
578 if (vol
->vol_type
== UBI_DYNAMIC_VOLUME
) {
579 vol
->used_ebs
= reserved_pebs
;
580 vol
->last_eb_bytes
= vol
->usable_leb_size
;
582 (long long)vol
->used_ebs
* vol
->usable_leb_size
;
585 paranoid_check_volumes(ubi
);
590 spin_lock(&ubi
->volumes_lock
);
591 ubi
->rsvd_pebs
-= pebs
;
592 ubi
->avail_pebs
+= pebs
;
593 spin_unlock(&ubi
->volumes_lock
);
601 * ubi_add_volume - add volume.
602 * @ubi: UBI device description object
603 * @vol: volume description object
605 * This function adds an existing volume and initializes all its data
606 * structures. Returns zero in case of success and a negative error code in
609 int ubi_add_volume(struct ubi_device
*ubi
, struct ubi_volume
*vol
)
611 int err
, vol_id
= vol
->vol_id
;
614 dbg_msg("add volume %d", vol_id
);
615 ubi_dbg_dump_vol_info(vol
);
617 /* Register character device for the volume */
618 cdev_init(&vol
->cdev
, &ubi_vol_cdev_operations
);
619 vol
->cdev
.owner
= THIS_MODULE
;
620 dev
= MKDEV(MAJOR(ubi
->cdev
.dev
), vol
->vol_id
+ 1);
621 err
= cdev_add(&vol
->cdev
, dev
, 1);
623 ubi_err("cannot add character device for volume %d, error %d",
628 err
= ubi_create_gluebi(ubi
, vol
);
632 vol
->dev
.release
= vol_release
;
633 vol
->dev
.parent
= &ubi
->dev
;
635 vol
->dev
.class = ubi_class
;
636 sprintf(&vol
->dev
.bus_id
[0], "%s_%d", ubi
->ubi_name
, vol
->vol_id
);
637 err
= device_register(&vol
->dev
);
641 err
= volume_sysfs_init(ubi
, vol
);
643 cdev_del(&vol
->cdev
);
644 err
= ubi_destroy_gluebi(vol
);
645 volume_sysfs_close(vol
);
649 paranoid_check_volumes(ubi
);
653 err
= ubi_destroy_gluebi(vol
);
655 cdev_del(&vol
->cdev
);
660 * ubi_free_volume - free volume.
661 * @ubi: UBI device description object
662 * @vol: volume description object
664 * This function frees all resources for volume @vol but does not remove it.
665 * Used only when the UBI device is detached.
667 void ubi_free_volume(struct ubi_device
*ubi
, struct ubi_volume
*vol
)
669 dbg_msg("free volume %d", vol
->vol_id
);
671 ubi
->volumes
[vol
->vol_id
] = NULL
;
672 ubi_destroy_gluebi(vol
);
673 cdev_del(&vol
->cdev
);
674 volume_sysfs_close(vol
);
677 #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
680 * paranoid_check_volume - check volume information.
681 * @ubi: UBI device description object
684 static void paranoid_check_volume(struct ubi_device
*ubi
, int vol_id
)
686 int idx
= vol_id2idx(ubi
, vol_id
);
687 int reserved_pebs
, alignment
, data_pad
, vol_type
, name_len
, upd_marker
;
688 const struct ubi_volume
*vol
;
692 spin_lock(&ubi
->volumes_lock
);
693 reserved_pebs
= be32_to_cpu(ubi
->vtbl
[vol_id
].reserved_pebs
);
694 vol
= ubi
->volumes
[idx
];
698 ubi_err("no volume info, but volume exists");
701 spin_unlock(&ubi
->volumes_lock
);
705 if (vol
->exclusive
) {
707 * The volume may be being created at the moment, do not check
708 * it (e.g., it may be in the middle of ubi_create_volume().
710 spin_unlock(&ubi
->volumes_lock
);
714 if (vol
->reserved_pebs
< 0 || vol
->alignment
< 0 || vol
->data_pad
< 0 ||
716 ubi_err("negative values");
719 if (vol
->alignment
> ubi
->leb_size
|| vol
->alignment
== 0) {
720 ubi_err("bad alignment");
724 n
= vol
->alignment
& (ubi
->min_io_size
- 1);
725 if (vol
->alignment
!= 1 && n
) {
726 ubi_err("alignment is not multiple of min I/O unit");
730 n
= ubi
->leb_size
% vol
->alignment
;
731 if (vol
->data_pad
!= n
) {
732 ubi_err("bad data_pad, has to be %lld", n
);
736 if (vol
->vol_type
!= UBI_DYNAMIC_VOLUME
&&
737 vol
->vol_type
!= UBI_STATIC_VOLUME
) {
738 ubi_err("bad vol_type");
742 if (vol
->upd_marker
&& vol
->corrupted
) {
743 dbg_err("update marker and corrupted simultaneously");
747 if (vol
->reserved_pebs
> ubi
->good_peb_count
) {
748 ubi_err("too large reserved_pebs");
752 n
= ubi
->leb_size
- vol
->data_pad
;
753 if (vol
->usable_leb_size
!= ubi
->leb_size
- vol
->data_pad
) {
754 ubi_err("bad usable_leb_size, has to be %lld", n
);
758 if (vol
->name_len
> UBI_VOL_NAME_MAX
) {
759 ubi_err("too long volume name, max is %d", UBI_VOL_NAME_MAX
);
764 ubi_err("NULL volume name");
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("paranoid check failed for volume %d", vol_id
);
831 ubi_dbg_dump_vol_info(vol
);
832 ubi_dbg_dump_vtbl_record(&ubi
->vtbl
[vol_id
], vol_id
);
833 spin_unlock(&ubi
->volumes_lock
);
838 * paranoid_check_volumes - check information about all volumes.
839 * @ubi: UBI device description object
841 static void paranoid_check_volumes(struct ubi_device
*ubi
)
845 for (i
= 0; i
< ubi
->vtbl_slots
; i
++)
846 paranoid_check_volume(ubi
, i
);