From: Artem Bityutskiy <dedekind1@gmail.com>
To: Brian Foster <brian.foster@maxim-ic.com>
Cc: Brian Norris <computersforpeace@gmail.com>,
"linux-mtd@lists.infradead.org" <linux-mtd@lists.infradead.org>
Subject: Re: [PATCH 1/2] libmtd: add `mtd_dev_present()' library function
Date: Fri, 03 Feb 2012 11:17:24 +0200 [thread overview]
Message-ID: <1328260644.13362.1.camel@sauron.fi.intel.com> (raw)
In-Reply-To: <201202021420.18252.brian.foster@maxim-ic.com>
[-- Attachment #1: Type: text/plain, Size: 4272 bytes --]
On Thu, 2012-02-02 at 14:20 +0100, Brian Foster wrote:
> On Thursday 02 February 2012 12:33:24 Artem Bityutskiy wrote:
> > On Fri, 2012-01-27 at 10:30 -0800, Brian Norris wrote:
> > > +int mtd_dev_present(libmtd_t desc, int mtd_num) { [ ... ]
> >
> > This will only work for relatively newer kernels where MTD has sysfs
> > support (2.6.30+). Older kernels have no MTD sysfs support and the sysfs
> > file you are stat()'ing won't exist, so this function will always return
> > an error.
>
> This is a very plausible concern: Our older system
> is mostly deployed with 2.6.26(or even older) kernel,
> albeit a 2.6.30 option exists. It has multiple MTD
> devices, albeit due to the usage/configuration (and
> maybe the use of older mtd-utils?) I suspect the bug
> has never been observed.
>
> Our latest system uses 2.6.36, and is where the original
> UBI-related bug was observed.
Ok, I've just prepared the below patch. Compile-tested only. Anyone
volunteers to verify?
From d3e5e0a2aeb61dbd99c41c11e1c268510a4334c2 Mon Sep 17 00:00:00 2001
From: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Date: Fri, 3 Feb 2012 09:15:31 +0200
Subject: [PATCH] limbtd: implement mtd_dev_present for old kernels
Implement the 'legacy_dev_present()' function which will check whether an MTD
device is present by scanning the /proc/mtd file when the MTD subsystem does
not support sysfs (the case for pre-2.6.30 kernels).
This patch also moves the 'mtd_dev_present()' function to a slightly more
logical position.
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
---
lib/libmtd.c | 25 ++++++++++++-------------
lib/libmtd_int.h | 1 +
lib/libmtd_legacy.c | 25 +++++++++++++++++++++++++
3 files changed, 38 insertions(+), 13 deletions(-)
diff --git a/lib/libmtd.c b/lib/libmtd.c
index 888d118..ecf182f 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -641,6 +641,18 @@ void libmtd_close(libmtd_t desc)
free(lib);
}
+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];
+
+ if (!lib->sysfs_supported)
+ return legacy_dev_present(mtd_num);
+
+ sprintf(file, lib->mtd, mtd_num);
+ return !stat(file, &st);
+}
+
int mtd_get_info(libmtd_t desc, struct mtd_info *info)
{
DIR *sysfs_mtd;
@@ -713,19 +725,6 @@ 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];
-
- if (!lib->sysfs_supported)
- /* TODO: add legacy_dev_present() function */
- return 1;
-
- 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;
diff --git a/lib/libmtd_int.h b/lib/libmtd_int.h
index bb48d35..7913e67 100644
--- a/lib/libmtd_int.h
+++ b/lib/libmtd_int.h
@@ -95,6 +95,7 @@ struct libmtd
};
int legacy_libmtd_open(void);
+int legacy_dev_present(int mtd_num);
int legacy_mtd_get_info(struct mtd_info *info);
int legacy_get_dev_info(const char *node, struct mtd_dev_info *mtd);
int legacy_get_dev_info1(int dev_num, struct mtd_dev_info *mtd);
diff --git a/lib/libmtd_legacy.c b/lib/libmtd_legacy.c
index d6c3938..d3f1672 100644
--- a/lib/libmtd_legacy.c
+++ b/lib/libmtd_legacy.c
@@ -170,6 +170,31 @@ int legacy_libmtd_open(void)
}
/**
+ * legacy_dev_presentl - legacy version of 'mtd_dev_present()'.
+ * @info: the MTD device information is returned here
+ *
+ * When the kernel does not provide sysfs files for the MTD subsystem,
+ * fall-back to parsing the /proc/mtd file to determine whether an mtd device
+ * number @mtd_num is present.
+ */
+int legacy_dev_present(int mtd_num)
+{
+ int ret;
+ struct proc_parse_info pi;
+
+ ret = proc_parse_start(&pi);
+ if (ret)
+ return -1;
+
+ while (proc_parse_next(&pi)) {
+ if (pi.mtd_num == mtd_num)
+ return 1;
+ }
+
+ return 0;
+}
+
+/**
* legacy_mtd_get_info - legacy version of 'mtd_get_info()'.
* @info: the MTD device information is returned here
*
--
1.7.9
--
Best Regards,
Artem Bityutskiy
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
next prev parent reply other threads:[~2012-02-03 9:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-27 18:30 [PATCH 1/2] libmtd: add `mtd_dev_present()' library function Brian Norris
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 [this message]
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=1328260644.13362.1.camel@sauron.fi.intel.com \
--to=dedekind1@gmail.com \
--cc=brian.foster@maxim-ic.com \
--cc=computersforpeace@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 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.