Commit 979c9296 authored by Artem Bityutskiy's avatar Artem Bityutskiy

UBI: print error code

Print error code if checking failed which is very useful
to identify problems.
Signed-off-by: default avatarArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
parent 338b9bb3
...@@ -127,7 +127,7 @@ static int vtbl_check(const struct ubi_device *ubi, ...@@ -127,7 +127,7 @@ static int vtbl_check(const struct ubi_device *ubi,
const struct ubi_vtbl_record *vtbl) const struct ubi_vtbl_record *vtbl)
{ {
int i, n, reserved_pebs, alignment, data_pad, vol_type, name_len; int i, n, reserved_pebs, alignment, data_pad, vol_type, name_len;
int upd_marker; int upd_marker, err;
uint32_t crc; uint32_t crc;
const char *name; const char *name;
...@@ -153,7 +153,7 @@ static int vtbl_check(const struct ubi_device *ubi, ...@@ -153,7 +153,7 @@ static int vtbl_check(const struct ubi_device *ubi,
if (reserved_pebs == 0) { if (reserved_pebs == 0) {
if (memcmp(&vtbl[i], &empty_vtbl_record, if (memcmp(&vtbl[i], &empty_vtbl_record,
UBI_VTBL_RECORD_SIZE)) { UBI_VTBL_RECORD_SIZE)) {
dbg_err("bad empty record"); err = 2;
goto bad; goto bad;
} }
continue; continue;
...@@ -161,56 +161,57 @@ static int vtbl_check(const struct ubi_device *ubi, ...@@ -161,56 +161,57 @@ static int vtbl_check(const struct ubi_device *ubi,
if (reserved_pebs < 0 || alignment < 0 || data_pad < 0 || if (reserved_pebs < 0 || alignment < 0 || data_pad < 0 ||
name_len < 0) { name_len < 0) {
dbg_err("negative values"); err = 3;
goto bad; goto bad;
} }
if (alignment > ubi->leb_size || alignment == 0) { if (alignment > ubi->leb_size || alignment == 0) {
dbg_err("bad alignment"); err = 4;
goto bad; goto bad;
} }
n = alignment % ubi->min_io_size; n = alignment % ubi->min_io_size;
if (alignment != 1 && n) { if (alignment != 1 && n) {
dbg_err("alignment is not multiple of min I/O unit"); err = 5;
goto bad; goto bad;
} }
n = ubi->leb_size % alignment; n = ubi->leb_size % alignment;
if (data_pad != n) { if (data_pad != n) {
dbg_err("bad data_pad, has to be %d", n); dbg_err("bad data_pad, has to be %d", n);
err = 6;
goto bad; goto bad;
} }
if (vol_type != UBI_VID_DYNAMIC && vol_type != UBI_VID_STATIC) { if (vol_type != UBI_VID_DYNAMIC && vol_type != UBI_VID_STATIC) {
dbg_err("bad vol_type"); err = 7;
goto bad; goto bad;
} }
if (upd_marker != 0 && upd_marker != 1) { if (upd_marker != 0 && upd_marker != 1) {
dbg_err("bad upd_marker"); err = 8;
goto bad; goto bad;
} }
if (reserved_pebs > ubi->good_peb_count) { if (reserved_pebs > ubi->good_peb_count) {
dbg_err("too large reserved_pebs, good PEBs %d", dbg_err("too large reserved_pebs, good PEBs %d",
ubi->good_peb_count); ubi->good_peb_count);
err = 9;
goto bad; goto bad;
} }
if (name_len > UBI_VOL_NAME_MAX) { if (name_len > UBI_VOL_NAME_MAX) {
dbg_err("too long volume name, max %d", err = 10;
UBI_VOL_NAME_MAX);
goto bad; goto bad;
} }
if (name[0] == '\0') { if (name[0] == '\0') {
dbg_err("NULL volume name"); err = 11;
goto bad; goto bad;
} }
if (name_len != strnlen(name, name_len + 1)) { if (name_len != strnlen(name, name_len + 1)) {
dbg_err("bad name_len"); err = 12;
goto bad; goto bad;
} }
} }
...@@ -235,7 +236,7 @@ static int vtbl_check(const struct ubi_device *ubi, ...@@ -235,7 +236,7 @@ static int vtbl_check(const struct ubi_device *ubi,
return 0; return 0;
bad: bad:
ubi_err("volume table check failed, record %d", i); ubi_err("volume table check failed: record %d, error %d", i, err);
ubi_dbg_dump_vtbl_record(&vtbl[i], i); ubi_dbg_dump_vtbl_record(&vtbl[i], i);
return -EINVAL; return -EINVAL;
} }
...@@ -620,30 +621,32 @@ static int init_volumes(struct ubi_device *ubi, const struct ubi_scan_info *si, ...@@ -620,30 +621,32 @@ static int init_volumes(struct ubi_device *ubi, const struct ubi_scan_info *si,
static int check_sv(const struct ubi_volume *vol, static int check_sv(const struct ubi_volume *vol,
const struct ubi_scan_volume *sv) const struct ubi_scan_volume *sv)
{ {
int err;
if (sv->highest_lnum >= vol->reserved_pebs) { if (sv->highest_lnum >= vol->reserved_pebs) {
dbg_err("bad highest_lnum"); err = 1;
goto bad; goto bad;
} }
if (sv->leb_count > vol->reserved_pebs) { if (sv->leb_count > vol->reserved_pebs) {
dbg_err("bad leb_count"); err = 2;
goto bad; goto bad;
} }
if (sv->vol_type != vol->vol_type) { if (sv->vol_type != vol->vol_type) {
dbg_err("bad vol_type"); err = 3;
goto bad; goto bad;
} }
if (sv->used_ebs > vol->reserved_pebs) { if (sv->used_ebs > vol->reserved_pebs) {
dbg_err("bad used_ebs"); err = 4;
goto bad; goto bad;
} }
if (sv->data_pad != vol->data_pad) { if (sv->data_pad != vol->data_pad) {
dbg_err("bad data_pad"); err = 5;
goto bad; goto bad;
} }
return 0; return 0;
bad: bad:
ubi_err("bad scanning information"); ubi_err("bad scanning information, error %d", err);
ubi_dbg_dump_sv(sv); ubi_dbg_dump_sv(sv);
ubi_dbg_dump_vol_info(vol); ubi_dbg_dump_vol_info(vol);
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment