diff options
-rw-r--r-- | drivers/mtd/ubi/eba.c | 13 | ||||
-rw-r--r-- | drivers/mtd/ubi/kapi.c | 45 | ||||
-rw-r--r-- | include/linux/mtd/ubi.h | 1 |
3 files changed, 54 insertions, 5 deletions
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c index 85f50c83cf42..c87db07bcd0c 100644 --- a/drivers/mtd/ubi/eba.c +++ b/drivers/mtd/ubi/eba.c | |||
@@ -656,11 +656,14 @@ retry: | |||
656 | goto write_error; | 656 | goto write_error; |
657 | } | 657 | } |
658 | 658 | ||
659 | err = ubi_io_write_data(ubi, buf, pnum, offset, len); | 659 | if (len) { |
660 | if (err) { | 660 | err = ubi_io_write_data(ubi, buf, pnum, offset, len); |
661 | ubi_warn("failed to write %d bytes at offset %d of LEB %d:%d, " | 661 | if (err) { |
662 | "PEB %d", len, offset, vol_id, lnum, pnum); | 662 | ubi_warn("failed to write %d bytes at offset %d of " |
663 | goto write_error; | 663 | "LEB %d:%d, PEB %d", len, offset, vol_id, |
664 | lnum, pnum); | ||
665 | goto write_error; | ||
666 | } | ||
664 | } | 667 | } |
665 | 668 | ||
666 | vol->eba_tbl[lnum] = pnum; | 669 | vol->eba_tbl[lnum] = pnum; |
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c index 03c774f41549..e1ef802a03a7 100644 --- a/drivers/mtd/ubi/kapi.c +++ b/drivers/mtd/ubi/kapi.c | |||
@@ -547,6 +547,51 @@ int ubi_leb_unmap(struct ubi_volume_desc *desc, int lnum) | |||
547 | EXPORT_SYMBOL_GPL(ubi_leb_unmap); | 547 | EXPORT_SYMBOL_GPL(ubi_leb_unmap); |
548 | 548 | ||
549 | /** | 549 | /** |
550 | * ubi_leb_map - map logical erasblock to a physical eraseblock. | ||
551 | * @desc: volume descriptor | ||
552 | * @lnum: logical eraseblock number | ||
553 | * @dtype: expected data type | ||
554 | * | ||
555 | * This function maps an un-mapped logical eraseblock @lnum to a physical | ||
556 | * eraseblock. This means, that after a successfull invocation of this | ||
557 | * function the logical eraseblock @lnum will be empty (contain only %0xFF | ||
558 | * bytes) and be mapped to a physical eraseblock, even if an unclean reboot | ||
559 | * happens. | ||
560 | * | ||
561 | * This function returns zero in case of success, %-EBADF if the volume is | ||
562 | * damaged because of an interrupted update, %-EBADMSG if the logical | ||
563 | * eraseblock is already mapped, and other negative error codes in case of | ||
564 | * other failures. | ||
565 | */ | ||
566 | int ubi_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype) | ||
567 | { | ||
568 | struct ubi_volume *vol = desc->vol; | ||
569 | struct ubi_device *ubi = vol->ubi; | ||
570 | int vol_id = vol->vol_id; | ||
571 | |||
572 | dbg_msg("unmap LEB %d:%d", vol_id, lnum); | ||
573 | |||
574 | if (desc->mode == UBI_READONLY || vol->vol_type == UBI_STATIC_VOLUME) | ||
575 | return -EROFS; | ||
576 | |||
577 | if (lnum < 0 || lnum >= vol->reserved_pebs) | ||
578 | return -EINVAL; | ||
579 | |||
580 | if (dtype != UBI_LONGTERM && dtype != UBI_SHORTTERM && | ||
581 | dtype != UBI_UNKNOWN) | ||
582 | return -EINVAL; | ||
583 | |||
584 | if (vol->upd_marker) | ||
585 | return -EBADF; | ||
586 | |||
587 | if (vol->eba_tbl[lnum] >= 0) | ||
588 | return -EBADMSG; | ||
589 | |||
590 | return ubi_eba_write_leb(ubi, vol_id, lnum, NULL, 0, 0, dtype); | ||
591 | } | ||
592 | EXPORT_SYMBOL_GPL(ubi_leb_map); | ||
593 | |||
594 | /** | ||
550 | * ubi_is_mapped - check if logical eraseblock is mapped. | 595 | * ubi_is_mapped - check if logical eraseblock is mapped. |
551 | * @desc: volume descriptor | 596 | * @desc: volume descriptor |
552 | * @lnum: logical eraseblock number | 597 | * @lnum: logical eraseblock number |
diff --git a/include/linux/mtd/ubi.h b/include/linux/mtd/ubi.h index 3d967b6b120a..c4abe0351225 100644 --- a/include/linux/mtd/ubi.h +++ b/include/linux/mtd/ubi.h | |||
@@ -167,6 +167,7 @@ int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf, | |||
167 | int len, int dtype); | 167 | int len, int dtype); |
168 | int ubi_leb_erase(struct ubi_volume_desc *desc, int lnum); | 168 | int ubi_leb_erase(struct ubi_volume_desc *desc, int lnum); |
169 | int ubi_leb_unmap(struct ubi_volume_desc *desc, int lnum); | 169 | int ubi_leb_unmap(struct ubi_volume_desc *desc, int lnum); |
170 | int ubi_leb_map(struct ubi_volume_desc *desc, int lnum, int dtype); | ||
170 | int ubi_is_mapped(struct ubi_volume_desc *desc, int lnum); | 171 | int ubi_is_mapped(struct ubi_volume_desc *desc, int lnum); |
171 | 172 | ||
172 | /* | 173 | /* |