60 #include <linux/slab.h>
61 #include <asm/div64.h>
91 vtbl_rec = &empty_vtbl_record;
109 self_vtbl_check(ubi);
135 memcpy(vtbl_rec, &empty_vtbl_record,
172 static int vtbl_check(
const struct ubi_device *ubi,
183 reserved_pebs =
be32_to_cpu(vtbl[i].reserved_pebs);
189 name = &vtbl[
i].
name[0];
193 ubi_err(
"bad CRC at record %u: %#08x, not %#08x",
199 if (reserved_pebs == 0) {
200 if (
memcmp(&vtbl[i], &empty_vtbl_record,
208 if (reserved_pebs < 0 || alignment < 0 || data_pad < 0 ||
214 if (alignment > ubi->
leb_size || alignment == 0) {
220 if (alignment != 1 && n) {
227 ubi_err(
"bad data_pad, has to be %d", n);
237 if (upd_marker != 0 && upd_marker != 1) {
243 ubi_err(
"too large reserved_pebs %d, good PEBs %d",
254 if (name[0] ==
'\0') {
259 if (name_len !=
strnlen(name, name_len + 1)) {
271 if (len1 > 0 && len1 == len2 &&
272 !
strncmp(vtbl[i].name, vtbl[n].name, len1)) {
273 ubi_err(
"volumes %d and %d have the same name \"%s\"",
285 ubi_err(
"volume table check failed: record %d, error %d", i, err);
301 int copy,
void *vtbl)
307 dbg_gen(
"create volume table (copy #%d)", copy + 1);
309 vid_hdr = ubi_zalloc_vid_hdr(ubi,
GFP_KERNEL);
315 if (IS_ERR(new_aeb)) {
316 err = PTR_ERR(new_aeb);
334 err = ubi_io_write_data(ubi, vtbl, new_aeb->
pnum, 0, ubi->
vtbl_size);
344 ubi_free_vid_hdr(ubi, vid_hdr);
348 if (err == -
EIO && ++tries <= 5) {
358 ubi_free_vid_hdr(ubi, vid_hdr);
408 dbg_gen(
"check layout volume");
413 if (!leb[aeb->
lnum]) {
418 err = ubi_io_read_data(ubi, leb[aeb->
lnum], aeb->
pnum, 0,
438 leb_corrupted[0] = vtbl_check(ubi, leb[0]);
439 if (leb_corrupted[0] < 0)
443 if (!leb_corrupted[0]) {
446 leb_corrupted[1] =
memcmp(leb[0], leb[1],
448 if (leb_corrupted[1]) {
449 ubi_warn(
"volume table copy #2 is corrupted");
450 err = create_vtbl(ubi, ai, 1, leb[0]);
453 ubi_msg(
"volume table was restored");
462 leb_corrupted[1] = vtbl_check(ubi, leb[1]);
463 if (leb_corrupted[1] < 0)
466 if (leb_corrupted[1]) {
468 ubi_err(
"both volume tables are corrupted");
472 ubi_warn(
"volume table copy #1 is corrupted");
473 err = create_vtbl(ubi, ai, 0, leb[1]);
476 ubi_msg(
"volume table was restored");
512 err = create_vtbl(ubi, ai, i, vtbl);
532 static int init_volumes(
struct ubi_device *ubi,
536 int i, reserved_pebs = 0;
565 ubi_err(
"more than one auto-resize volume (%d and %d)",
611 ubi_warn(
"static volume %d misses %d LEBs - corrupted",
649 ubi_err(
"not enough PEBs, required %d, available %d",
652 ubi_err(
"%d PEBs are corrupted and not used",
669 static int check_av(
const struct ubi_volume *vol,
697 ubi_err(
"bad attaching information, error %d", err);
713 static int check_attaching_info(
const struct ubi_device *ubi,
721 ubi_err(
"found %d volumes while attaching, maximum is %d + %d",
759 err = check_av(vol, av);
806 ubi->
vtbl = create_empty_lvol(ubi, ai);
807 if (IS_ERR(ubi->
vtbl))
808 return PTR_ERR(ubi->
vtbl);
810 ubi_err(
"the layout volume was not found");
814 if (av->
leb_count > UBI_LAYOUT_VOLUME_EBS) {
816 ubi_err(
"too many LEBs (%d) in layout volume",
821 ubi->
vtbl = process_lvol(ubi, ai, av);
822 if (IS_ERR(ubi->
vtbl))
823 return PTR_ERR(ubi->
vtbl);
832 err = init_volumes(ubi, ai, ubi->
vtbl);
840 err = check_attaching_info(ubi, ai);
859 static void self_vtbl_check(
const struct ubi_device *ubi)
861 if (!ubi->
dbg->chk_gen)
864 if (vtbl_check(ubi, ubi->
vtbl)) {