From: Artem Bityutskiy <dedekind1@gmail.com>
To: Mike Frysinger <vapier@gentoo.org>
Cc: linux-mtd@lists.infradead.org
Subject: Re: [PATCH v2] libmtd: add helper funcs for getting regioninfo and locked info
Date: Wed, 08 Jun 2011 15:27:43 +0300 [thread overview]
Message-ID: <1307536063.31223.67.camel@localhost> (raw)
In-Reply-To: <1307533966.31223.66.camel@localhost>
On Wed, 2011-06-08 at 14:52 +0300, Artem Bityutskiy wrote:
> On Tue, 2011-06-07 at 11:28 -0400, Mike Frysinger wrote:
> > This extends the libmtd with the helper functions:
> > mtd_regioninfo: interface to MEMGETREGIONINFO
> > mtd_islocked: interface to MEMISLOCKED
> >
> > Users of these functions will follow shortly ...
> >
> > Signed-off-by: Mike Frysinger <vapier@gentoo.org>
>
> Pushed with a small tweak, thanks!
>
> > +int mtd_islocked(const struct mtd_dev_info *mtd, int fd, int eb)
> > +{
> > + int ret;
> > + erase_info_t ei;
> > +
> > + ei.start = eb * mtd->eb_size;
> > + ei.length = mtd->eb_size;
> > +
> > + ret = ioctl(fd, MEMISLOCKED, &ei);
> > + if (ret < 0)
> > + return mtd_ioctl_error(mtd, eb, "MEMISLOCKED");
> > +
>
> I've removed this error message - if we fail, better return an error
> code silently. At least your next patch is built a way that it will keep
> iterating and executing this function.
>
> We might as well print an error message if (!ENOTTY && !ENOTSUPP), but I
> did not do this. I expect you to send a correction patch if you do not
> like this :-)
I've just pushed a correction patch on top of this:
>From 92a06994b7c3f146cbdb770b30780e32f021118f Mon Sep 17 00:00:00 2001
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Date: Wed, 8 Jun 2011 15:30:14 +0300
Subject: [PATCH] libmtd: improve mtd_islocked interface
This patch first of all, re-names 'mtd_islocked()' into 'mtd_is_locked()' since
this seems to be the name Mike wanted, and it looks a bit nicer.
This patch also makes 'mtd_is_locked()' print an error message if it fails. I'm
not sure if it is good idea for a library to do so, but all functions do this,
so it certainly _not_ a good idea to be inconsistent.
However, for the special case, when the the "is locked" ioctl is not supported
or is not valid for this device, we do not print an error message and return
ENOTSUPP error code.
Thus, the user can distinguish between real errors and non-fatal "not
supported" cases.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
include/libmtd.h | 8 +++++---
lib/libmtd.c | 13 +++++++++++--
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/include/libmtd.h b/include/libmtd.h
index 7275246..9efccbc 100644
--- a/include/libmtd.h
+++ b/include/libmtd.h
@@ -190,16 +190,18 @@ int mtd_erase(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb);
int mtd_regioninfo(int fd, int regidx, struct region_info_user *reginfo);
/**
- * mtd_islocked - see if the specified eraseblock is locked.
+ * mtd_is_locked - see if the specified eraseblock is locked.
* @mtd: MTD device description object
* @fd: MTD device node file descriptor
* @eb: eraseblock to check
*
* This function checks to see if eraseblock @eb of MTD device described
* by @fd is locked. Returns %0 if it is unlocked, %1 if it is locked, and
- * %-1 in case of failure.
+ * %-1 in case of failure. If the ioctl is not supported (support was added in
+ * Linux kernel 2.6.36) or this particular device does not support it, errno is
+ * set to @ENOTSUPP.
*/
-int mtd_islocked(const struct mtd_dev_info *mtd, int fd, int eb);
+int mtd_is_locked(const struct mtd_dev_info *mtd, int fd, int eb);
/**
* mtd_torture - torture an eraseblock.
diff --git a/lib/libmtd.c b/lib/libmtd.c
index 2573cc7..c34874e 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -900,14 +900,23 @@ int mtd_regioninfo(int fd, int regidx, struct region_info_user *reginfo)
return 0;
}
-int mtd_islocked(const struct mtd_dev_info *mtd, int fd, int eb)
+int mtd_is_locked(const struct mtd_dev_info *mtd, int fd, int eb)
{
+ int ret;
erase_info_t ei;
ei.start = eb * mtd->eb_size;
ei.length = mtd->eb_size;
- return ioctl(fd, MEMISLOCKED, &ei);
+ ret = ioctl(fd, MEMISLOCKED, &ei);
+ if (ret < 0) {
+ if (errno != ENOTTY && errno != EOPNOTSUPP)
+ return mtd_ioctl_error(mtd, eb, "MEMISLOCKED");
+ else
+ errno = EOPNOTSUPP;
+ }
+
+ return ret;
}
/* Patterns to write to a physical eraseblock when torturing it */
--
1.7.2.3
--
Best Regards,
Artem Bityutskiy (Артём Битюцкий)
next prev parent reply other threads:[~2011-06-08 12:32 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-07 6:19 [PATCH 1/6] jffs2: make lzo optional at build time Mike Frysinger
2011-06-07 6:19 ` [PATCH 2/6] mtdinfo: send help/version info to stdout Mike Frysinger
2011-06-07 6:36 ` Artem Bityutskiy
2011-06-07 15:00 ` Mike Frysinger
2011-06-08 11:10 ` Artem Bityutskiy
2011-06-07 8:40 ` Florian Fainelli
2011-06-07 15:02 ` [PATCH v2] ubi-utils: " Mike Frysinger
2011-06-08 11:13 ` Artem Bityutskiy
2011-06-07 6:19 ` [PATCH 3/6] libmtd: use O_CLOEXEC Mike Frysinger
2011-06-07 6:45 ` Artem Bityutskiy
2011-06-07 6:19 ` [PATCH 4/6] libmtd: add helper funcs for getting fds, regioninfo, and locked info Mike Frysinger
2011-06-07 6:50 ` Artem Bityutskiy
2011-06-07 6:56 ` Artem Bityutskiy
2011-06-07 7:04 ` Mike Frysinger
2011-06-07 7:30 ` Artem Bityutskiy
2011-06-07 15:28 ` [PATCH v2] libmtd: add helper funcs for getting regioninfo " Mike Frysinger
2011-06-07 15:52 ` [PATCH v3] " Mike Frysinger
2011-06-08 11:47 ` Artem Bityutskiy
2011-06-08 18:10 ` Mike Frysinger
2011-06-08 11:52 ` [PATCH v2] " Artem Bityutskiy
2011-06-08 12:27 ` Artem Bityutskiy [this message]
2011-06-08 18:12 ` Mike Frysinger
2011-06-07 6:19 ` [PATCH 5/6] mtdinfo: add regioninfo/sectormap display Mike Frysinger
2011-06-07 7:41 ` Artem Bityutskiy
2011-06-07 15:31 ` Mike Frysinger
2011-06-08 13:41 ` Artem Bityutskiy
2011-06-08 18:14 ` Mike Frysinger
2011-06-07 15:53 ` [PATCH v2] mtdinfo: add regioninfo/eraseblock map display Mike Frysinger
2011-06-08 13:35 ` Artem Bityutskiy
2011-06-08 18:26 ` Mike Frysinger
2011-06-08 19:02 ` [PATCH v3] " Mike Frysinger
2011-06-08 19:11 ` [PATCH v4] " Mike Frysinger
2011-06-09 6:25 ` Artem Bityutskiy
2011-06-07 6:19 ` [PATCH 6/6] flash_info: punt in favor of mtdinfo Mike Frysinger
2011-06-07 7:43 ` Artem Bityutskiy
2011-06-07 15:11 ` [PATCH v2] flash_info: deprecate Mike Frysinger
2011-06-08 11:15 ` Artem Bityutskiy
2011-06-07 6:34 ` [PATCH 1/6] jffs2: make lzo optional at build time Artem Bityutskiy
2011-06-07 6:59 ` Mike Frysinger
2011-06-07 7:20 ` Artem Bityutskiy
2011-06-07 7:16 ` Artem Bityutskiy
2011-06-07 15:16 ` Mike Frysinger
2011-06-08 11:28 ` Artem Bityutskiy
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=1307536063.31223.67.camel@localhost \
--to=dedekind1@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=vapier@gentoo.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).