diff options
author | Brian Norris <computersforpeace@gmail.com> | 2012-01-27 10:30:45 -0800 |
---|---|---|
committer | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2012-02-02 13:23:39 +0200 |
commit | de3f8789d9e54b2e0e45197a693ad87ebf3bab60 (patch) | |
tree | 7a39b15d5e6d3dfdcfce5ac8a28bf847358c7d3f /lib | |
parent | fb3281d740b4d222746e5e366732d414038c951e (diff) |
libmtd: add `mtd_dev_present()' library function
Will be used for `mtdinfo --all'
Artem: add a temporary stub for pre-2.6.30 kernels.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libmtd.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/libmtd.c b/lib/libmtd.c index c6e5b20..888d118 100644 --- a/lib/libmtd.c +++ b/lib/libmtd.c @@ -713,10 +713,22 @@ 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; - struct stat st; struct libmtd *lib = (struct libmtd *)desc; memset(mtd, 0, sizeof(struct mtd_dev_info)); @@ -724,15 +736,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)) |