aboutsummaryrefslogtreecommitdiff
path: root/ubi-utils
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2017-03-15 11:26:38 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2017-03-15 12:10:34 +0100
commita2eeedb0a7af1d8ebe8593cb9a9bb994d2854e63 (patch)
tree5f35234f3608c22bf2d545e57afde732ad58b86d /ubi-utils
parent4dab9bed1033f797ef9b482c77342fe3fe26d0be (diff)
Fix libmtd behaviour if MTD is not present on the system
The documentation of libmtd_open says, if it returns NULL and errno is zero, MTD is not present. However, the current version always returns a libmtd_t object. The function internally checks, if it can access the MTD sysfs files and, if not, sets a flag to use the procfs fallback. This patch adds an additional check to libmtd_open, to test if the MTD procfs file can be read and fails with errno cleared if it does not exist. Furhtermore, mtd_get_info is documented to fail with errno set to ENODEV if MTD is not present. First of all, this was broken in the original version. It was implemented to specification for the sysfs code path, but if MTD is not present, that won't be executed, because of the flag set by libmtd_open. This makes the check not only redundant, but masks an actual error (the sysfs paths suddenly not being readable anymore). The legacy path that was used if the sysfs files are not avaible fails with ENOENT if it cannot read the procfs file. With the above changes in addition, we don't have a libmtd_t object if neither sysfs nor procfs is readable, so this error status no longer makes sense. This patch removes the documentation on the ENODEV errno, and makes sure that mtd_get_info always returns with apropriate errno on failure. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'ubi-utils')
-rw-r--r--ubi-utils/mtdinfo.c5
-rw-r--r--ubi-utils/ubiformat.c2
2 files changed, 1 insertions, 6 deletions
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;
}