]> www.infradead.org Git - mtd-utils.git/commitdiff
limbtd: implement mtd_dev_present for old kernels
authorArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Thu, 9 Feb 2012 18:13:29 +0000 (10:13 -0800)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Tue, 14 Feb 2012 09:00:09 +0000 (11:00 +0200)
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
lib/libmtd_int.h
lib/libmtd_legacy.c

index 888d11892405a1cd4249429fb767f08b523295d1..ecf182f7ff2a4fa684d39fab4025402bdd9b3f47 100644 (file)
@@ -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;
index bb48d35340c06ef821e448e3f5001c73d4874215..7913e676cd7e0c47ec5b05ead33fd7875d7fa084 100644 (file)
@@ -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);
index d6c3938336ed6277d6fdb51a5cef5cf855948eeb..d3f16727aae38210e0f685e7d1504a289a769811 100644 (file)
@@ -169,6 +169,31 @@ int legacy_libmtd_open(void)
        return 0;
 }
 
+/**
+ * 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