]> www.infradead.org Git - mtd-utils.git/commitdiff
Merge rest of ubiutils-common into libmtd common
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Thu, 1 Sep 2016 13:27:38 +0000 (15:27 +0200)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Thu, 17 Nov 2016 10:36:56 +0000 (11:36 +0100)
This patch moves the remaining 3 functions from ubiutils-common.{c,h}
into libmtd common.{c,h}.

The functions are only generic utility functions that other mtd-utils
programs may also find usefull and every program that uses libubi links
against libmtd anyway so there is no real reason for keeping around a
seperate ubiutils-common with only generic helper functions.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
12 files changed:
include/common.h
lib/Makemodule.am
lib/common.c [moved from ubi-utils/ubiutils-common.c with 89% similarity]
ubi-utils/Makemodule.am
ubi-utils/include/ubiutils-common.h [deleted file]
ubi-utils/mtdinfo.c
ubi-utils/ubiattach.c
ubi-utils/ubiformat.c
ubi-utils/ubimkvol.c
ubi-utils/ubinfo.c
ubi-utils/ubinize.c
ubi-utils/ubirsvol.c

index 11e19895410781f1bb9a06927c3623c6bb24bde9..4f0bb9bb8fb6cbec5fc79b2320ce619b3eb4a4b8 100644 (file)
@@ -220,6 +220,10 @@ do { \
 
 #include "xalloc.h"
 
+long long util_get_bytes(const char *str);
+void util_print_bytes(long long bytes, int bracket);
+int util_srand(void);
+
 #ifdef __cplusplus
 }
 #endif
index b30a8aabe157e4333715977c617b50d75796f0f5..694a151d43c5861e59681179524c95eae4bad046 100644 (file)
@@ -1,6 +1,7 @@
 libmtd_a_SOURCES = \
        lib/libmtd.c \
        lib/libfec.c \
+       lib/common.c \
        lib/libcrc32.c \
        lib/libmtd_legacy.c \
        lib/libmtd_int.h
similarity index 89%
rename from ubi-utils/ubiutils-common.c
rename to lib/common.c
index 563678596c2dcc48344af2b0e70d8dc830d1c047..69b03b3ed06c5c685d1d8fb5be29b5ed5ffddfab 100644 (file)
  */
 
 /*
- * This file contains various common stuff used by UBI utilities.
+ * This file contains various common stuff.
  *
  * Authors: Artem Bityutskiy
  *          Adrian Hunter
  */
 
-#define PROGRAM_NAME "ubiutils"
+#define PROGRAM_NAME "mtd-utils"
 
 #include <sys/time.h>
 #include <sys/types.h>
@@ -62,7 +62,7 @@ static int get_multiplier(const char *str)
 }
 
 /**
- * ubiutils_get_bytes - convert a string containing amount of bytes into an
+ * util_get_bytes - convert a string containing amount of bytes into an
  * integer
  * @str: string to convert
  *
@@ -70,7 +70,7 @@ static int get_multiplier(const char *str)
  * size specifiers. Returns positive amount of bytes in case of success and %-1
  * in case of failure.
  */
-long long ubiutils_get_bytes(const char *str)
+long long util_get_bytes(const char *str)
 {
        char *endp;
        long long bytes = strtoull(str, &endp, 0);
@@ -95,7 +95,7 @@ long long ubiutils_get_bytes(const char *str)
 }
 
 /**
- * ubiutils_print_bytes - print bytes.
+ * util_print_bytes - print bytes.
  * @bytes: variable to print
  * @bracket: whether brackets have to be put or not
  *
@@ -104,7 +104,7 @@ long long ubiutils_get_bytes(const char *str)
  * amount of Kilobytes, Megabytes, or Gigabytes, depending on how big @bytes
  * is.
  */
-void ubiutils_print_bytes(long long bytes, int bracket)
+void util_print_bytes(long long bytes, int bracket)
 {
        const char *p;
 
@@ -129,14 +129,14 @@ void ubiutils_print_bytes(long long bytes, int bracket)
 }
 
 /**
- * ubiutils_srand - randomly seed the standard pseudo-random generator.
+ * util_srand - randomly seed the standard pseudo-random generator.
  *
  * This helper function seeds the standard libc pseudo-random generator with a
  * more or less random value to make sure the 'rand()' call does not return the
  * same sequence every time UBI utilities run. Returns zero in case of success
  * and a %-1 in case of error.
  */
-int ubiutils_srand(void)
+int util_srand(void)
 {
        struct timeval tv;
        struct timezone tz;
index dc68f3878327a2fb5b53b8856f4aba0b938a166a..f1c50df97743776dae8200abcd0ca41f3bf71639 100644 (file)
@@ -1,4 +1,4 @@
-libubi_a_SOURCES = ubi-utils/libubi.c ubi-utils/ubiutils-common.c ubi-utils/libubi_int.h
+libubi_a_SOURCES = ubi-utils/libubi.c ubi-utils/libubi_int.h
 libubi_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/ubi-utils/include
 
 libubigen_a_SOURCES = ubi-utils/libubigen.c
diff --git a/ubi-utils/include/ubiutils-common.h b/ubi-utils/include/ubiutils-common.h
deleted file mode 100644 (file)
index 99c18f7..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (c) Artem Bityutskiy, 2007, 2008
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef __UBI_UTILS_COMMON_H__
-#define __UBI_UTILS_COMMON_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-long long ubiutils_get_bytes(const char *str);
-void ubiutils_print_bytes(long long bytes, int bracket);
-int ubiutils_srand(void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* !__UBI_UTILS_COMMON_H__ */
index a86abd1542b410dbafd77e30814908f69f8aff7e..11e59c1c61ca6c2ed327cc58fd4981c2ec469412 100644 (file)
@@ -34,7 +34,6 @@
 #include <libubigen.h>
 #include <libmtd.h>
 #include "common.h"
-#include "ubiutils-common.h"
 
 /* The variables below are set by command line arguments */
 struct args {
@@ -172,7 +171,7 @@ static void print_ubi_info(const struct mtd_info *mtd_info,
        printf("Default UBI VID header offset:  %d\n", ui.vid_hdr_offs);
        printf("Default UBI data offset:        %d\n", ui.data_offs);
        printf("Default UBI LEB size:           ");
-       ubiutils_print_bytes(ui.leb_size, 0);
+       util_print_bytes(ui.leb_size, 0);
        printf("\n");
        printf("Maximum UBI volumes count:      %d\n", ui.max_volumes);
 }
@@ -306,10 +305,10 @@ static int print_dev_info(libmtd_t libmtd, const struct mtd_info *mtd_info, int
        printf("Name:                           %s\n", mtd.name);
        printf("Type:                           %s\n", mtd.type_str);
        printf("Eraseblock size:                ");
-       ubiutils_print_bytes(mtd.eb_size, 0);
+       util_print_bytes(mtd.eb_size, 0);
        printf("\n");
        printf("Amount of eraseblocks:          %d (", mtd.eb_cnt);
-       ubiutils_print_bytes(mtd.size, 0);
+       util_print_bytes(mtd.size, 0);
        printf(")\n");
        printf("Minimum input/output unit size: %d %s\n",
               mtd.min_io_size, mtd.min_io_size > 1 ? "bytes" : "byte");
index a7c62d08645dfc9d908372b48ea6cb7badf25b32..09f85af8d082b7af5e0aace9c0c0341a4fbcd0d4 100644 (file)
@@ -31,7 +31,6 @@
 
 #include <libubi.h>
 #include "common.h"
-#include "ubiutils-common.h"
 
 #define DEFAULT_CTRL_DEV "/dev/ubi_ctrl"
 
@@ -238,11 +237,11 @@ int main(int argc, char * const argv[])
        }
 
        printf("UBI device number %d, total %d LEBs (", dev_info.dev_num, dev_info.total_lebs);
-       ubiutils_print_bytes(dev_info.total_bytes, 0);
+       util_print_bytes(dev_info.total_bytes, 0);
        printf("), available %d LEBs (", dev_info.avail_lebs);
-       ubiutils_print_bytes(dev_info.avail_bytes, 0);
+       util_print_bytes(dev_info.avail_bytes, 0);
        printf("), LEB size ");
-       ubiutils_print_bytes(dev_info.leb_size, 1);
+       util_print_bytes(dev_info.leb_size, 1);
        printf("\n");
 
        libubi_close(libubi);
index 21409ca695fb7c0c03725c69913415c8297cfcc5..68906f241ee042e5be00ee6f8e18fc0e4e3de88e 100644 (file)
@@ -45,7 +45,6 @@
 #include <mtd_swab.h>
 #include <crc32.h>
 #include "common.h"
-#include "ubiutils-common.h"
 
 /* The variables below are set by command line arguments */
 struct args {
@@ -130,7 +129,7 @@ static const struct option long_options[] = {
 
 static int parse_opt(int argc, char * const argv[])
 {
-       ubiutils_srand();
+       util_srand();
        args.image_seq = rand();
 
        while (1) {
@@ -143,7 +142,7 @@ static int parse_opt(int argc, char * const argv[])
 
                switch (key) {
                case 's':
-                       args.subpage_size = ubiutils_get_bytes(optarg);
+                       args.subpage_size = util_get_bytes(optarg);
                        if (args.subpage_size <= 0)
                                return errmsg("bad sub-page size: \"%s\"", optarg);
                        if (!is_power_of_2(args.subpage_size))
@@ -170,7 +169,7 @@ static int parse_opt(int argc, char * const argv[])
                        break;
 
                case 'S':
-                       args.image_sz = ubiutils_get_bytes(optarg);
+                       args.image_sz = util_get_bytes(optarg);
                        if (args.image_sz <= 0)
                                return errmsg("bad image-size: \"%s\"", optarg);
                        break;
@@ -791,9 +790,9 @@ int main(int argc, char * const argv[])
 
        if (!args.quiet) {
                normsg_cont("mtd%d (%s), size ", mtd.mtd_num, mtd.type_str);
-               ubiutils_print_bytes(mtd.size, 1);
+               util_print_bytes(mtd.size, 1);
                printf(", %d eraseblocks of ", mtd.eb_cnt);
-               ubiutils_print_bytes(mtd.eb_size, 1);
+               util_print_bytes(mtd.eb_size, 1);
                printf(", min. I/O size %d bytes\n", mtd.min_io_size);
        }
 
index 7c2a2345b8b47b81a3310dacb4f15ba8aab6345d..fdbc67ffb781178e59b9ab6f82f03c0dbf62d45f 100644 (file)
@@ -33,7 +33,6 @@
 
 #include <libubi.h>
 #include "common.h"
-#include "ubiutils-common.h"
 
 /* The variables below are set by command line arguments */
 struct args {
@@ -137,7 +136,7 @@ static int parse_opt(int argc, char * const argv[])
                        break;
 
                case 's':
-                       args.bytes = ubiutils_get_bytes(optarg);
+                       args.bytes = util_get_bytes(optarg);
                        if (args.bytes <= 0)
                                return errmsg("bad volume size: \"%s\"", optarg);
                        break;
@@ -278,9 +277,9 @@ int main(int argc, char * const argv[])
        }
 
        printf("Volume ID %d, size %d LEBs (", vol_info.vol_id, vol_info.rsvd_lebs);
-       ubiutils_print_bytes(vol_info.rsvd_bytes, 0);
+       util_print_bytes(vol_info.rsvd_bytes, 0);
        printf("), LEB size ");
-       ubiutils_print_bytes(vol_info.leb_size, 1);
+       util_print_bytes(vol_info.leb_size, 1);
        printf(", %s, name \"%s\", alignment %d\n",
               req.vol_type == UBI_DYNAMIC_VOLUME ? "dynamic" : "static",
               vol_info.name, vol_info.alignment);
index cb88f53c444f5b30b8c797944d863c9528c043a0..82d4f18623ffe81408fe56e9a631432c59aa2cdd 100644 (file)
@@ -31,7 +31,6 @@
 
 #include <libubi.h>
 #include "common.h"
-#include "ubiutils-common.h"
 
 /* The variables below are set by command line arguments */
 struct args {
@@ -211,12 +210,12 @@ static int print_vol_info(libubi_t libubi, int dev_num, int vol_id)
        printf("Alignment:   %d\n", vol_info.alignment);
 
        printf("Size:        %d LEBs (", vol_info.rsvd_lebs);
-       ubiutils_print_bytes(vol_info.rsvd_bytes, 0);
+       util_print_bytes(vol_info.rsvd_bytes, 0);
        printf(")\n");
 
        if (vol_info.type == UBI_STATIC_VOLUME) {
                printf("Data bytes:  ");
-               ubiutils_print_bytes(vol_info.data_bytes, 1);
+               util_print_bytes(vol_info.data_bytes, 1);
                printf("\n");
        }
        printf("State:       %s\n", vol_info.corrupted ? "corrupted" : "OK");
@@ -240,15 +239,15 @@ static int print_dev_info(libubi_t libubi, int dev_num, int all)
        printf("ubi%d\n", dev_info.dev_num);
        printf("Volumes count:                           %d\n", dev_info.vol_count);
        printf("Logical eraseblock size:                 ");
-       ubiutils_print_bytes(dev_info.leb_size, 0);
+       util_print_bytes(dev_info.leb_size, 0);
        printf("\n");
 
        printf("Total amount of logical eraseblocks:     %d (", dev_info.total_lebs);
-       ubiutils_print_bytes(dev_info.total_bytes, 0);
+       util_print_bytes(dev_info.total_bytes, 0);
        printf(")\n");
 
        printf("Amount of available logical eraseblocks: %d (", dev_info.avail_lebs);
-       ubiutils_print_bytes(dev_info.avail_bytes, 0);
+       util_print_bytes(dev_info.avail_bytes, 0);
        printf(")\n");
 
        printf("Maximum count of volumes                 %d\n", dev_info.max_vol_count);
index b5ebadc45175a4de5a941fd8f247bfdb5e515398..c85ff9b22c584bdec0a71cff3cf0456f9aca637b 100644 (file)
@@ -37,7 +37,6 @@
 #include <libiniparser.h>
 #include <libubi.h>
 #include "common.h"
-#include "ubiutils-common.h"
 
 static const char optionsstr[] =
 "-o, --output=<file name>     output file name\n"
@@ -110,7 +109,7 @@ static struct args args = {
 
 static int parse_opt(int argc, char * const argv[])
 {
-       ubiutils_srand();
+       util_srand();
        args.image_seq = rand();
 
        while (1) {
@@ -131,13 +130,13 @@ static int parse_opt(int argc, char * const argv[])
                        break;
 
                case 'p':
-                       args.peb_size = ubiutils_get_bytes(optarg);
+                       args.peb_size = util_get_bytes(optarg);
                        if (args.peb_size <= 0)
                                return errmsg("bad physical eraseblock size: \"%s\"", optarg);
                        break;
 
                case 'm':
-                       args.min_io_size = ubiutils_get_bytes(optarg);
+                       args.min_io_size = util_get_bytes(optarg);
                        if (args.min_io_size <= 0)
                                return errmsg("bad min. I/O unit size: \"%s\"", optarg);
                        if (!is_power_of_2(args.min_io_size))
@@ -145,7 +144,7 @@ static int parse_opt(int argc, char * const argv[])
                        break;
 
                case 's':
-                       args.subpage_size = ubiutils_get_bytes(optarg);
+                       args.subpage_size = util_get_bytes(optarg);
                        if (args.subpage_size <= 0)
                                return errmsg("bad sub-page size: \"%s\"", optarg);
                        if (!is_power_of_2(args.subpage_size))
@@ -324,7 +323,7 @@ static int read_section(const struct ubigen_info *ui, const char *sname,
        sprintf(buf, "%s:vol_size", sname);
        p = iniparser_getstring(args.dict, buf, NULL);
        if (p) {
-               vi->bytes = ubiutils_get_bytes(p);
+               vi->bytes = util_get_bytes(p);
                if (vi->bytes <= 0)
                        return errmsg("bad \"vol_size\" key value \"%s\" (section \"%s\")",
                                      p, sname);
@@ -353,7 +352,7 @@ static int read_section(const struct ubigen_info *ui, const char *sname,
 
                normsg_cont("volume size was not specified in section \"%s\", assume"
                            " minimum to fit image \"%s\"", sname, *img);
-               ubiutils_print_bytes(vi->bytes, 1);
+               util_print_bytes(vi->bytes, 1);
                printf("\n");
        }
 
index c46906085e237df60a0da11cb5c2089a275744a8..69a4ea14ff8dc88d12021ccb04be504898a324eb 100644 (file)
@@ -33,7 +33,6 @@
 
 #include <libubi.h>
 #include "common.h"
-#include "ubiutils-common.h"
 
 /* The variables below are set by command line arguments */
 struct args {
@@ -114,7 +113,7 @@ static int parse_opt(int argc, char * const argv[])
 
                switch (key) {
                case 's':
-                       args.bytes = ubiutils_get_bytes(optarg);
+                       args.bytes = util_get_bytes(optarg);
                        if (args.bytes <= 0)
                                return errmsg("bad volume size: \"%s\"", optarg);
                        break;