From eded3cd0a52252f677ceacd1fbcae13be3d55e8f Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Thu, 9 Feb 2012 10:13:29 -0800 Subject: 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 --- lib/libmtd_legacy.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib/libmtd_legacy.c') 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 @@ -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 -- cgit v1.2.3