diff options
Diffstat (limited to 'ubi-utils/src')
-rw-r--r-- | ubi-utils/src/libubi.c | 47 | ||||
-rw-r--r-- | ubi-utils/src/ubimkvol.c | 5 | ||||
-rw-r--r-- | ubi-utils/src/ubinfo.c | 4 | ||||
-rw-r--r-- | ubi-utils/src/ubirename.c | 5 | ||||
-rw-r--r-- | ubi-utils/src/ubirmvol.c | 5 | ||||
-rw-r--r-- | ubi-utils/src/ubiupdatevol.c | 5 |
6 files changed, 57 insertions, 14 deletions
diff --git a/ubi-utils/src/libubi.c b/ubi-utils/src/libubi.c index d4b29b9..067f17e 100644 --- a/ubi-utils/src/libubi.c +++ b/ubi-utils/src/libubi.c @@ -787,17 +787,15 @@ int ubi_probe_node(libubi_t desc, const char *node) /* This is supposdely an UBI volume device node */ sprintf(file, lib->ubi_vol, i, minor - 1); fd = open(file, O_RDONLY); - if (fd == -1) { - sys_errmsg("cannot open \"%s\"", node); - return -1; - } + if (fd == -1) + goto out_not_ubi; return 2; out_not_ubi: errmsg("\"%s\" has major:minor %d:%d, but this does not correspond to " - "any UBI device or volume", node, major, minor); - errno = 0; + "any existing UBI device or volume", node, major, minor); + errno = ENODEV; return -1; } @@ -1002,6 +1000,22 @@ int ubi_leb_change_start(libubi_t desc, int fd, int lnum, int bytes, int dtype) return 0; } +/** + * dev_present - check whether an UBI device is present. + * @lib: libubi descriptor + * @dev_num: UBI device number to check + * + * This function returns %1 if UBI device is present and %0 if not. + */ +static int dev_present(struct libubi *lib, int dev_num) +{ + struct stat st; + char file[strlen(lib->ubi_dev) + 50]; + + sprintf(file, lib->ubi_dev, dev_num); + return !stat(file, &st); +} + int ubi_get_dev_info1(libubi_t desc, int dev_num, struct ubi_dev_info *info) { DIR *sysfs_ubi; @@ -1011,6 +1025,11 @@ int ubi_get_dev_info1(libubi_t desc, int dev_num, struct ubi_dev_info *info) memset(info, '\0', sizeof(struct ubi_dev_info)); info->dev_num = dev_num; + if (!dev_present(lib, dev_num)) { + errno = ENODEV; + return -1; + } + sysfs_ubi = opendir(lib->sysfs_ubi); if (!sysfs_ubi) return -1; @@ -1085,9 +1104,15 @@ out_close: int ubi_get_dev_info(libubi_t desc, const char *node, struct ubi_dev_info *info) { - int dev_num; + int err, dev_num; struct libubi *lib = (struct libubi *)desc; + err = ubi_probe_node(desc, node); + if (err != 1) { + errno = ENODEV; + return -1; + } + if (dev_node2num(lib, node, &dev_num)) return -1; @@ -1155,9 +1180,15 @@ int ubi_get_vol_info1(libubi_t desc, int dev_num, int vol_id, int ubi_get_vol_info(libubi_t desc, const char *node, struct ubi_vol_info *info) { - int vol_id, dev_num; + int err, vol_id, dev_num; struct libubi *lib = (struct libubi *)desc; + err = ubi_probe_node(desc, node); + if (err != 2) { + errno = ENODEV; + return -1; + } + if (vol_node2nums(lib, node, &dev_num, &vol_id)) return -1; diff --git a/ubi-utils/src/ubimkvol.c b/ubi-utils/src/ubimkvol.c index dba7133..b5805a4 100644 --- a/ubi-utils/src/ubimkvol.c +++ b/ubi-utils/src/ubimkvol.c @@ -251,7 +251,10 @@ int main(int argc, char * const argv[]) args.node); goto out_libubi; } else if (err < 0) { - errmsg("\"%s\" is not an UBI device node", args.node); + if (errno == ENODEV) + errmsg("\"%s\" is not an UBI device node", args.node); + else + sys_errmsg("error while probing \"%s\"", args.node); goto out_libubi; } diff --git a/ubi-utils/src/ubinfo.c b/ubi-utils/src/ubinfo.c index 025ac62..036ed6c 100644 --- a/ubi-utils/src/ubinfo.c +++ b/ubi-utils/src/ubinfo.c @@ -142,8 +142,8 @@ static int translate_dev(libubi_t libubi, const char *node) err = ubi_probe_node(libubi, node); if (err == -1) { - if (errno) - return errmsg("unrecognized device node \"%s\"", node); + if (errno != ENODEV) + return sys_errmsg("error while probing \"%s\"", node); return errmsg("\"%s\" does not correspond to any UBI device or volume", node); } diff --git a/ubi-utils/src/ubirename.c b/ubi-utils/src/ubirename.c index 08b3cd5..00c53e4 100644 --- a/ubi-utils/src/ubirename.c +++ b/ubi-utils/src/ubirename.c @@ -105,7 +105,10 @@ int main(int argc, char * const argv[]) node); goto out_libubi; } else if (err < 0) { - errmsg("\"%s\" is not an UBI device node", node); + if (errno == ENODEV) + errmsg("\"%s\" is not an UBI device node", node); + else + sys_errmsg("error while probing \"%s\"", node); goto out_libubi; } diff --git a/ubi-utils/src/ubirmvol.c b/ubi-utils/src/ubirmvol.c index 17aece4..f7a3820 100644 --- a/ubi-utils/src/ubirmvol.c +++ b/ubi-utils/src/ubirmvol.c @@ -193,7 +193,10 @@ int main(int argc, char * const argv[]) args.node); goto out_libubi; } else if (err < 0) { - errmsg("\"%s\" is not an UBI device node", args.node); + if (errno == ENODEV) + errmsg("\"%s\" is not an UBI device node", args.node); + else + sys_errmsg("error while probing \"%s\"", args.node); goto out_libubi; } diff --git a/ubi-utils/src/ubiupdatevol.c b/ubi-utils/src/ubiupdatevol.c index b160461..df424d2 100644 --- a/ubi-utils/src/ubiupdatevol.c +++ b/ubi-utils/src/ubiupdatevol.c @@ -331,7 +331,10 @@ int main(int argc, char * const argv[]) args.node); goto out_libubi; } else if (err < 0) { - errmsg("\"%s\" is not an UBI volume node", args.node); + if (errno == ENODEV) + errmsg("\"%s\" is not an UBI volume node", args.node); + else + sys_errmsg("error while probing \"%s\"", args.node); goto out_libubi; } |