From: Brian Norris <computersforpeace@gmail.com>
To: <linux-mtd@lists.infradead.org>
Cc: Brian Foster <brian.foster@maxim-ic.com>,
Brian Norris <computersforpeace@gmail.com>,
Artem Bityutskiy <dedekind1@gmail.com>
Subject: [PATCH 1/2] libmtd: add `mtd_dev_present()' library function
Date: Fri, 27 Jan 2012 10:30:45 -0800 [thread overview]
Message-ID: <1327689046-1450-1-git-send-email-computersforpeace@gmail.com> (raw)
Will be used for `mtdinfo --all'
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
---
include/libmtd.h | 9 +++++++++
lib/libmtd.c | 22 ++++++++++++----------
2 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/include/libmtd.h b/include/libmtd.h
index 07c304a..a78c8cb 100644
--- a/include/libmtd.h
+++ b/include/libmtd.h
@@ -106,6 +106,15 @@ libmtd_t libmtd_open(void);
void libmtd_close(libmtd_t desc);
/**
+ * mtd_dev_present - check whether a MTD device is present.
+ * @desc: MTD library descriptor
+ * @mtd_num: MTD device number to check
+ *
+ * This function returns %1 if MTD device is present and %0 if not.
+ */
+int mtd_dev_present(libmtd_t desc, int mtd_num);
+
+/**
* mtd_get_info - get general MTD information.
* @desc: MTD library descriptor
* @info: the MTD device information is returned here
diff --git a/lib/libmtd.c b/lib/libmtd.c
index c6e5b20..9786e83 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -713,10 +713,18 @@ out_close:
return -1;
}
+int mtd_dev_present(libmtd_t desc, int mtd_num) {
+ struct stat st;
+ struct libmtd *lib = (struct libmtd *)desc;
+ char file[strlen(lib->mtd) + 10];
+
+ sprintf(file, lib->mtd, mtd_num);
+ return !stat(file, &st);
+}
+
int mtd_get_dev_info1(libmtd_t desc, int mtd_num, struct mtd_dev_info *mtd)
{
int ret;
- struct stat st;
struct libmtd *lib = (struct libmtd *)desc;
memset(mtd, 0, sizeof(struct mtd_dev_info));
@@ -724,15 +732,9 @@ int mtd_get_dev_info1(libmtd_t desc, int mtd_num, struct mtd_dev_info *mtd)
if (!lib->sysfs_supported)
return legacy_get_dev_info1(mtd_num, mtd);
- else {
- char file[strlen(lib->mtd) + 10];
-
- sprintf(file, lib->mtd, mtd_num);
- if (stat(file, &st)) {
- if (errno == ENOENT)
- errno = ENODEV;
- return -1;
- }
+ else if (!mtd_dev_present(desc, mtd_num)) {
+ errno = ENODEV;
+ return -1;
}
if (dev_get_major(lib, mtd_num, &mtd->major, &mtd->minor))
--
1.7.5.4
next reply other threads:[~2012-01-27 18:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-27 18:30 Brian Norris [this message]
2012-01-27 18:30 ` [PATCH 2/2] mtdinfo: fix `--all' for non-consecutive device numbers Brian Norris
2012-01-27 18:32 ` Brian Norris
2012-02-02 11:33 ` [PATCH 1/2] libmtd: add `mtd_dev_present()' library function Artem Bityutskiy
2012-02-02 13:20 ` Brian Foster
2012-02-03 9:17 ` Artem Bityutskiy
2012-02-08 21:28 ` Brian Norris
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=1327689046-1450-1-git-send-email-computersforpeace@gmail.com \
--to=computersforpeace@gmail.com \
--cc=brian.foster@maxim-ic.com \
--cc=dedekind1@gmail.com \
--cc=linux-mtd@lists.infradead.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