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.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'lib/libmtd.c') 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; -- cgit v1.2.3