/**
* libubi_open - open UBI library.
- * @required: if non-zero, libubi will print an error messages if this UBI is
- * not present in the system
*
* This function initializes and opens the UBI library and returns UBI library
- * descriptor in case of success and %NULL in case of failure.
+ * descriptor in case of success and %NULL in case of failure. In case of
+ * failure, errno contains the error code or zero if UBI is not present in the
+ * system.
*/
-libubi_t libubi_open(int required);
+libubi_t libubi_open(void);
/**
* libubi_close - close UBI library.
return -1;
}
-libubi_t libubi_open(int required)
+libubi_t libubi_open(void)
{
int fd, version;
struct libubi *lib;
/* Make sure UBI is present */
fd = open(lib->sysfs_ubi, O_RDONLY);
if (fd == -1) {
- if (required)
- errmsg("cannot open \"%s\", UBI does not seem to "
- "exist in system", lib->sysfs_ubi);
+ errno = 0;
goto out_error;
}
{
int fd, ret;
+ desc = desc;
fd = open(node, O_RDONLY);
if (fd == -1)
return -1;
if (err)
return -1;
- libubi = libubi_open(1);
- if (libubi == NULL)
+ libubi = libubi_open();
+ if (!libubi) {
+ if (errno == 0)
+ return errmsg("UBI is not present in the system");
return sys_errmsg("cannot open libubi");
+ }
/*
* Make sure the kernel is fresh enough and this feature is supported.
if (err)
return -1;
- libubi = libubi_open(1);
- if (libubi == NULL)
+ libubi = libubi_open();
+ if (!libubi) {
+ if (errno == 0)
+ return errmsg("UBI is not present in the system");
return sys_errmsg("cannot open libubi");
+ }
/*
* Make sure the kernel is fresh enough and this feature is supported.
if (err)
return err;
- libubi = libubi_open(1);
- if (!libubi)
+ libubi = libubi_open();
+ if (!libubi) {
+ if (errno == 0)
+ return errmsg("UBI is not present in the system");
return sys_errmsg("cannot open libubi");
+ }
err = ubi_probe_node(libubi, args.node);
if (err == 2) {
if (err)
return -1;
- libubi = libubi_open(1);
- if (libubi == NULL)
+ libubi = libubi_open();
+ if (!libubi) {
+ if (errno == 0)
+ return errmsg("UBI is not present in the system");
return sys_errmsg("cannot open libubi");
+ }
if (args.node) {
/*
}
node = argv[1];
- libubi = libubi_open(1);
- if (!libubi)
+ libubi = libubi_open();
+ if (!libubi) {
+ if (errno == 0)
+ return errmsg("UBI is not present in the system");
return sys_errmsg("cannot open libubi");
+ }
err = ubi_probe_node(libubi, node);
if (err == 2) {
if (err)
return -1;
- libubi = libubi_open(1);
- if (libubi == NULL)
+ libubi = libubi_open();
+ if (!libubi) {
+ if (errno == 0)
+ return errmsg("UBI is not present in the system");
return sys_errmsg("cannot open libubi");
+ }
err = ubi_probe_node(libubi, args.node);
if (err == 2) {
if (err)
return -1;
- libubi = libubi_open(1);
- if (libubi == NULL) {
- sys_errmsg("cannot open libubi");
+ libubi = libubi_open();
+ if (!libubi) {
+ if (errno == 0)
+ errmsg("UBI is not present in the system");
+ else
+ sys_errmsg("cannot open libubi");
goto out_libubi;
}