]> www.infradead.org Git - mtd-utils.git/commitdiff
Remove unused and broken mtd_write_img function from libmtd
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Thu, 25 Aug 2016 11:41:50 +0000 (13:41 +0200)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Thu, 17 Nov 2016 10:36:55 +0000 (11:36 +0100)
The function _tries_ to support short reads but doesn't adjust the
pointer into the buffer. If a short read happens, we scrambles the
flash contents. Interrupted reads aren't handled. Short or
interrupted writes aren't handled at all. Either a write succeeds
writing the entire buffer or the function gives up.

During an attempt at fixing it, it was discovered, that no mtd-utils
program uses this function. Furthermore, its highly specific nature
makes it more of a "feature looking for use case".

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Signed-off-by: Richard Weinberger <richard@nod.at>
include/libmtd.h
lib/libmtd.c

index a78c8cb5cdea36e990ef9f974b89c11b7316c8a5..a6ff050bede17570f363928803c4c12be003ff37 100644 (file)
@@ -319,21 +319,6 @@ int mtd_read_oob(libmtd_t desc, const struct mtd_dev_info *mtd, int fd,
 int mtd_write_oob(libmtd_t desc, const struct mtd_dev_info *mtd, int fd,
                  uint64_t start, uint64_t length, void *data);
 
-/**
- * mtd_write_img - write a file to MTD device.
- * @mtd: MTD device description object
- * @fd: MTD device node file descriptor
- * @eb: eraseblock to write to
- * @offs: offset withing the eraseblock to write to
- * @img_name: the file to write
- *
- * This function writes an image @img_name the MTD device defined by @mtd. @eb
- * and @offs are the starting eraseblock and offset on the MTD device. Returns
- * %0 in case of success and %-1 in case of failure.
- */
-int mtd_write_img(const struct mtd_dev_info *mtd, int fd, int eb, int offs,
-                 const char *img_name);
-
 /**
  * mtd_probe_node - test MTD node.
  * @desc: MTD library descriptor
index 6ced2562b179b7c4949ed6263d3d1102693abab9..1d162c7c378f2368a895e830a6ca319998389650 100644 (file)
@@ -1279,103 +1279,6 @@ int mtd_write_oob(libmtd_t desc, const struct mtd_dev_info *mtd, int fd,
                         MEMWRITEOOB64, MEMWRITEOOB);
 }
 
-int mtd_write_img(const struct mtd_dev_info *mtd, int fd, int eb, int offs,
-                 const char *img_name)
-{
-       int tmp, ret, in_fd, len, written = 0;
-       off_t seek;
-       struct stat st;
-       char *buf;
-
-       ret = mtd_valid_erase_block(mtd, eb);
-       if (ret)
-               return ret;
-
-       if (offs < 0 || offs >= mtd->eb_size) {
-               errmsg("bad offset %d, mtd%d eraseblock size is %d",
-                      offs, mtd->mtd_num, mtd->eb_size);
-               errno = EINVAL;
-               return -1;
-       }
-       if (offs % mtd->subpage_size) {
-               errmsg("write offset %d is not aligned to mtd%d min. I/O size %d",
-                      offs, mtd->mtd_num, mtd->subpage_size);
-               errno = EINVAL;
-               return -1;
-       }
-
-       in_fd = open(img_name, O_RDONLY | O_CLOEXEC);
-       if (in_fd == -1)
-               return sys_errmsg("cannot open \"%s\"", img_name);
-
-       if (fstat(in_fd, &st)) {
-               sys_errmsg("cannot stat %s", img_name);
-               goto out_close;
-       }
-
-       len = st.st_size;
-       if (len % mtd->subpage_size) {
-               errmsg("size of \"%s\" is %d byte, which is not aligned to "
-                      "mtd%d min. I/O size %d", img_name, len, mtd->mtd_num,
-                      mtd->subpage_size);
-               errno = EINVAL;
-               goto out_close;
-       }
-       tmp = (offs + len + mtd->eb_size - 1) / mtd->eb_size;
-       if (eb + tmp > mtd->eb_cnt) {
-               errmsg("\"%s\" image size is %d bytes, mtd%d size is %d "
-                      "eraseblocks, the image does not fit if we write it "
-                      "starting from eraseblock %d, offset %d",
-                      img_name, len, mtd->mtd_num, mtd->eb_cnt, eb, offs);
-               errno = EINVAL;
-               goto out_close;
-       }
-
-       /* Seek to the beginning of the eraseblock */
-       seek = (off_t)eb * mtd->eb_size + offs;
-       if (lseek(fd, seek, SEEK_SET) != seek) {
-               sys_errmsg("cannot seek mtd%d to offset %"PRIdoff_t,
-                           mtd->mtd_num, seek);
-               goto out_close;
-       }
-
-       buf = xmalloc(mtd->eb_size);
-
-       while (written < len) {
-               int rd = 0;
-
-               do {
-                       ret = read(in_fd, buf, mtd->eb_size - offs - rd);
-                       if (ret == -1) {
-                               sys_errmsg("cannot read \"%s\"", img_name);
-                               goto out_free;
-                       }
-                       rd += ret;
-               } while (ret && rd < mtd->eb_size - offs);
-
-               ret = write(fd, buf, rd);
-               if (ret != rd) {
-                       sys_errmsg("cannot write %d bytes to mtd%d (eraseblock %d, offset %d)",
-                                  len, mtd->mtd_num, eb, offs);
-                       goto out_free;
-               }
-
-               offs = 0;
-               eb += 1;
-               written += rd;
-       }
-
-       free(buf);
-       close(in_fd);
-       return 0;
-
-out_free:
-       free(buf);
-out_close:
-       close(in_fd);
-       return -1;
-}
-
 int mtd_probe_node(libmtd_t desc, const char *node)
 {
        struct stat st;