]> www.infradead.org Git - mtd-utils.git/commitdiff
libubi: improve libubi_open interface
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Wed, 22 Apr 2009 11:32:08 +0000 (14:32 +0300)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Wed, 22 Apr 2009 14:27:54 +0000 (17:27 +0300)
Remove the not very nice @required parameter, and add a
possibility to distinguish between real errors and
a situation when UBI is not present.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
ubi-utils/include/libubi.h
ubi-utils/src/libubi.c
ubi-utils/src/ubiattach.c
ubi-utils/src/ubidetach.c
ubi-utils/src/ubimkvol.c
ubi-utils/src/ubinfo.c
ubi-utils/src/ubirename.c
ubi-utils/src/ubirmvol.c
ubi-utils/src/ubiupdatevol.c

index 71a78a37369c60409cacf4199ea18baa1cc6402d..bc3404cbbbaba1986f65c853bcb5d9b3f8ab98b5 100644 (file)
@@ -170,13 +170,13 @@ struct ubi_vol_info
 
 /**
  * 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.
index f456a1d7e6982c67be6f70bbe5ee81318fd72b56..d4b29b995e1801c7827f9a4c16df9f41e14bdec1 100644 (file)
@@ -507,7 +507,7 @@ int mtd_num2ubi_dev(libubi_t desc, int mtd_num, int *dev_num)
        return -1;
 }
 
-libubi_t libubi_open(int required)
+libubi_t libubi_open(void)
 {
        int fd, version;
        struct libubi *lib;
@@ -531,9 +531,7 @@ libubi_t libubi_open(int required)
        /* 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;
        }
 
@@ -945,6 +943,7 @@ int ubi_rnvols(libubi_t desc, const char *node, struct ubi_rnvol_req *rnvol)
 {
        int fd, ret;
 
+       desc = desc;
        fd = open(node, O_RDONLY);
        if (fd == -1)
                return -1;
index 1f726204f7cb2d3851c7d52819529f74395f17ce..a935b4211a3381b377787653ffb9cfc503424216 100644 (file)
@@ -153,9 +153,12 @@ int main(int argc, char * const argv[])
        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.
index 50670d05b8215f5fe552412f3972e512567dd4b4..83584cde6c03aeeaa69847e5b1cc9f20e3d8382b 100644 (file)
@@ -139,9 +139,12 @@ int main(int argc, char * const argv[])
        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.
index 8d6029a66cf79a471b08de163edd7a6965febb1b..dba713331cc25141049535cf4df6b16ec3e1a012 100644 (file)
@@ -238,9 +238,12 @@ int main(int argc, char * const argv[])
        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) {
index 085691fae97635522f5d8c4b16843ea24066590c..025ac62ab53f592092a946ced99b8378ff09478f 100644 (file)
@@ -364,9 +364,12 @@ int main(int argc, char * const argv[])
        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) {
                /*
index 14331b6f715ed318752e0527346e94f8ff83df68..08b3cd5b7c7a42597759493ec60603a10d4c2995 100644 (file)
@@ -92,9 +92,12 @@ int main(int argc, char * const argv[])
        }
 
        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) {
index edb1b7994261c36863029d1f29604d23e6c3967b..17aece4e6771b3e6ddba94e9e7f916b87839d9f2 100644 (file)
@@ -180,9 +180,12 @@ int main(int argc, char * const argv[])
        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) {
index a1e5a300a5748f576bfbfddf6a83d81c6e3086b2..b16046112f17e91b5f747f3ce179fe1ac26c469a 100644 (file)
@@ -316,9 +316,12 @@ int main(int argc, char * const argv[])
        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;
        }