All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Brian Norris" <computersforpeace@gmail.com>
To: "Artem Bityutskiy" <dedekind1@gmail.com>
Cc: b35362@freescale.com, Brian Norris <computersforpeace@gmail.com>,
	linux-mtd@lists.infradead.org,
	Mike Frysinger <vapier.adi@gmail.com>
Subject: [PATCH 05/10] libmtd: support MEMWRITE ioctl
Date: Wed, 31 Aug 2011 13:00:34 -0700	[thread overview]
Message-ID: <1314820839-7107-6-git-send-email-computersforpeace@gmail.com> (raw)
In-Reply-To: <1314820839-7107-1-git-send-email-computersforpeace@gmail.com>

`mtd_write()' now will first attempt to use MEMWRITE. Then, if that
doesn't exist, it will attempt to fall back to old methods for writing
OOB and/or page data.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
 lib/libmtd.c |   39 +++++++++++++++++++++++++++++++--------
 1 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/lib/libmtd.c b/lib/libmtd.c
index 746ea69..d47b307 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -1077,6 +1077,7 @@ int mtd_write(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb,
 {
 	int ret;
 	off_t seek;
+	struct mtd_write_req ops;
 
 	ret = mtd_valid_erase_block(mtd, eb);
 	if (ret)
@@ -1101,16 +1102,38 @@ int mtd_write(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb,
 		return -1;
 	}
 
-	/* Seek to the beginning of the eraseblock */
+	/* Calculate seek address */
 	seek = (off_t)eb * mtd->eb_size + offs;
-	if (lseek(fd, seek, SEEK_SET) != seek)
-		return sys_errmsg("cannot seek mtd%d to offset %llu",
-				  mtd->mtd_num, (unsigned long long)seek);
 
-	ret = write(fd, data, len);
-	if (ret != len)
-		return sys_errmsg("cannot write %d bytes to mtd%d (eraseblock %d, offset %d)",
-				  len, mtd->mtd_num, eb, offs);
+	ops.start = seek;
+	ops.len = len;
+	ops.ooblen = ooblen;
+	ops.usr_data = (uint64_t)(unsigned long)data;
+	ops.usr_oob = (uint64_t)(unsigned long)oob;
+	ops.mode = mode;
+
+	ret = ioctl(fd, MEMWRITE, &ops);
+	if (ret == 0)
+		return 0;
+	else if (errno != ENOTTY)
+		return mtd_ioctl_error(mtd, eb, "MEMWRITE");
+
+	/* Fall back to old methods if necessary */
+	if (oob) {
+		if (mtd_write_oob(desc, mtd, fd, seek, ooblen, oob) < 0)
+			return sys_errmsg("cannot write to OOB");
+	}
+	if (data) {
+		/* Seek to the beginning of the eraseblock */
+		if (lseek(fd, seek, SEEK_SET) != seek)
+			return sys_errmsg("cannot seek mtd%d to offset %llu",
+					mtd->mtd_num, (unsigned long long)seek);
+		ret = write(fd, data, len);
+		if (ret != len)
+			return sys_errmsg("cannot write %d bytes to mtd%d "
+					  "(eraseblock %d, offset %d)",
+					  len, mtd->mtd_num, eb, offs);
+	}
 
 	return 0;
 }
-- 
1.7.5.4

  parent reply	other threads:[~2011-08-31 20:02 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-31 20:00 [PATCH 00/10] nandwrite: cleanup, support ioctl(MEMWRITE) Brian Norris
2011-08-31 20:00 ` [PATCH 01/10] nandwrite: trivial variable move Brian Norris
2011-09-11 13:00   ` Artem Bityutskiy
2011-08-31 20:00 ` [PATCH 02/10] mtd-utils: update mtd-abi.h Brian Norris
2011-09-09 17:11   ` [PATCH v2 " Brian Norris
2011-08-31 20:00 ` [PATCH 03/10] nandwrite: consolidate buffer usage Brian Norris
2011-09-11 13:07   ` Artem Bityutskiy
2011-09-14  5:15   ` Mike Frysinger
2011-09-14 18:22     ` Brian Norris
2011-09-18  2:53       ` Mike Frysinger
2011-09-19 18:50         ` Brian Norris
2011-08-31 20:00 ` [PATCH 04/10] libmtd: modify `mtd_write' to cover OOB writes Brian Norris
2011-08-31 20:00 ` Brian Norris [this message]
2011-08-31 20:00 ` [PATCH 06/10] nandwrite: merge `mtd_write_oob' and `mtd_write' calls Brian Norris
2011-08-31 20:00 ` [PATCH 07/10] mtdutils: move OOB auto-layout into libmtd's mtd_write Brian Norris
2011-08-31 20:00 ` [PATCH 08/10] nandwrite: kill `--raw' option Brian Norris
2011-08-31 20:00 ` [PATCH 09/10] nandwrite: re-implement `--autoplace' option Brian Norris
2011-08-31 20:00 ` [PATCH 10/10] nandwrite: use common.h "errmsg" functions Brian Norris
2011-09-11 13:06 ` [PATCH 00/10] nandwrite: cleanup, support ioctl(MEMWRITE) Artem Bityutskiy
2011-09-14  5:17 ` Mike Frysinger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1314820839-7107-6-git-send-email-computersforpeace@gmail.com \
    --to=computersforpeace@gmail.com \
    --cc=b35362@freescale.com \
    --cc=dedekind1@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=vapier.adi@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.