*
* This function tests whether @node is a UBI device or volume node and returns
* %1 if this is an UBI device node, %2 if this is a volume node, and %-1 if
- * this is not an UBI node or if an error occurred (the latter is indicated by
- * a non-zero errno).
+ * this is not an UBI device or volume node (errno is ENODEV in this case) or
+ * if an error occurred.
*/
int ubi_probe_node(libubi_t desc, const char *node);
* @info: pointer to the &struct ubi_dev_info object to fill
*
* This function fills the passed @info object with UBI device information and
- * returns %0 in case of success and %-1 in case of failure.
+ * returns %0 in case of success and %-1 in case of failure. If the UBI device
+ * corresponding to @node does not exist, errno is set to @ENODEV.
*/
int ubi_get_dev_info(libubi_t desc, const char *node,
struct ubi_dev_info *info);
* @info: pointer to the &struct ubi_dev_info object to fill
*
* This function is identical to 'ubi_get_dev_info()' except that it accepts UBI
- * device number, not UBI character device.
+ * device number, not UBI character device. If the UBI device @dev_num does not
+ * exist, errno is set to @ENODEV.
*/
int ubi_get_dev_info1(libubi_t desc, int dev_num, struct ubi_dev_info *info);
* @info: pointer to the &struct ubi_vol_info object to fill
*
* This function fills the passed @info object with UBI volume information and
- * returns %0 in case of success and %-1 in case of failure.
+ * returns %0 in case of success and %-1 in case of failure. If the UBI volume
+ * corresponding to @node does not exist, errno is set to @ENODEV.
*/
int ubi_get_vol_info(libubi_t desc, const char *node,
struct ubi_vol_info *info);
* @info: pointer to the &struct ubi_vol_info object to fill
*
* This function is identical to 'ubi_get_vol_info()' except that it accepts UBI
- * volume ID, not UBI volume character device.
+ * volume ID, not UBI volume character device. If the UBI device @dev_num does
+ * not exist, or if the UBI volume @vol_id does not exist, errno is set to
+ * @ENODEV.
*/
int ubi_get_vol_info1(libubi_t desc, int dev_num, int vol_id,
struct ubi_vol_info *info);
* ubi_get_vol_info1_nm - get UBI volume information by volume name.
* @desc: UBI library descriptor
* @dev_num: UBI device number
- * @vol_id: ID of the UBI volume to fetch information about
+ * @name: name of the UBI volume to fetch information about
* @info: pointer to the &struct ubi_vol_info object to fill
*
* This function is identical to 'ubi_get_vol_info()' except that it accepts UBI
- * volume name, not UBI volume ID.
+ * volume name, not UBI volume ID. If the UBI device @dev_num does not exist,
+ * or if the UBI volume @name does not exist, errno is set to @ENODEV.
*/
int ubi_get_vol_info1_nm(libubi_t desc, int dev_num, const char *name,
struct ubi_vol_info *info);
/* 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;
}
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;
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;
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;
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;
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;
}
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);
}
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;
}
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;
}
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;
}