diff options
-rw-r--r-- | include/libmtd.h | 3 | ||||
-rw-r--r-- | lib/libmtd.c | 12 | ||||
-rw-r--r-- | lib/libmtd_int.h | 1 | ||||
-rw-r--r-- | lib/libmtd_legacy.c | 18 | ||||
-rw-r--r-- | ubi-utils/mtdinfo.c | 5 | ||||
-rw-r--r-- | ubi-utils/ubiformat.c | 2 |
6 files changed, 27 insertions, 14 deletions
diff --git a/include/libmtd.h b/include/libmtd.h index f9f3164..db85fb4 100644 --- a/include/libmtd.h +++ b/include/libmtd.h @@ -120,8 +120,7 @@ int mtd_dev_present(libmtd_t desc, int mtd_num); * @info: the MTD device information is returned here * * This function fills the passed @info object with general MTD information and - * returns %0 in case of success and %-1 in case of failure. If MTD subsystem is - * not present in the system, errno is set to @ENODEV. + * returns %0 in case of success and %-1 in case of failure. */ int mtd_get_info(libmtd_t desc, struct mtd_info *info); diff --git a/lib/libmtd.c b/lib/libmtd.c index 8bc532f..a50f18a 100644 --- a/lib/libmtd.c +++ b/lib/libmtd.c @@ -578,6 +578,11 @@ libmtd_t libmtd_open(void) free(lib->sysfs_mtd); free(lib->mtd_name); lib->mtd_name = lib->mtd = lib->sysfs_mtd = NULL; + + if (!legacy_procfs_is_supported()) { + free(lib); + lib = NULL; + } return lib; } @@ -676,13 +681,8 @@ int mtd_get_info(libmtd_t desc, struct mtd_info *info) * devices are present. */ sysfs_mtd = opendir(lib->sysfs_mtd); - if (!sysfs_mtd) { - if (errno == ENOENT) { - errno = ENODEV; - return -1; - } + if (!sysfs_mtd) return sys_errmsg("cannot open \"%s\"", lib->sysfs_mtd); - } info->lowest_mtd_num = INT_MAX; while (1) { diff --git a/lib/libmtd_int.h b/lib/libmtd_int.h index db2f1cf..03b0863 100644 --- a/lib/libmtd_int.h +++ b/lib/libmtd_int.h @@ -98,6 +98,7 @@ struct libmtd unsigned int offs64_ioctls:2; }; +int legacy_procfs_is_supported(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); diff --git a/lib/libmtd_legacy.c b/lib/libmtd_legacy.c index ba8eade..46f51fd 100644 --- a/lib/libmtd_legacy.c +++ b/lib/libmtd_legacy.c @@ -146,6 +146,24 @@ static int proc_parse_next(struct proc_parse_info *pi) } /** + * legacy_procfs_is_supported - legacy version of 'sysfs_is_supported()'. + * + * Check if we can access the procfs files for the MTD subsystem. + */ +int legacy_procfs_is_supported(void) +{ + if (access(MTD_PROC_FILE, R_OK) != 0) { + if (errno == ENOENT) { + errno = 0; + } else { + sys_errmsg("cannot read \"%s\"", MTD_PROC_FILE); + } + return 0; + } + return 1; +} + +/** * legacy_dev_presentl - legacy version of 'mtd_dev_present()'. * @info: the MTD device information is returned here * diff --git a/ubi-utils/mtdinfo.c b/ubi-utils/mtdinfo.c index 11e59c1..0606ab0 100644 --- a/ubi-utils/mtdinfo.c +++ b/ubi-utils/mtdinfo.c @@ -407,11 +407,8 @@ int main(int argc, char * const argv[]) } err = mtd_get_info(libmtd, &mtd_info); - if (err) { - if (errno == ENODEV) - return errmsg("MTD is not present"); + if (err) return sys_errmsg("cannot get MTD information"); - } if (!args.all && args.node) { int mtdn; diff --git a/ubi-utils/ubiformat.c b/ubi-utils/ubiformat.c index 68906f2..896fe20 100644 --- a/ubi-utils/ubiformat.c +++ b/ubi-utils/ubiformat.c @@ -698,8 +698,6 @@ int main(int argc, char * const argv[]) err = mtd_get_info(libmtd, &mtd_info); if (err) { - if (errno == ENODEV) - errmsg("MTD is not present"); sys_errmsg("cannot get MTD information"); goto out_close_mtd; } |