All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] pull: tests fixes and couple blkid changes
@ 2017-03-19 10:10 Sami Kerola
  2017-03-19 10:10 ` [PATCH 1/5] libsmartcols: fix test variable shadowing Sami Kerola
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Sami Kerola @ 2017-03-19 10:10 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

Hello,

Fixes to tests are similar what is done to other code to get rid of various
warnings.  It is safe to say these will not be the last warning fixes ever,
as static analyers will get better in catching new problems, and without
doubt sometimes regressions creep in or completely new code is introduced.

Second subject matter is the last blkid changes I want to propose (for now),
both making the code more similar with rest of the code in this project.

----------------------------------------------------------------
The following changes since commit 999448d86609cef27a481c6e0ed9006b27f19558:
  tests: refresh lscpu tests (2017-03-15 11:49:22 +0100)
are available in the git repository at:
  git://github.com/kerolasa/lelux-utiliteetit.git 2017wk11
for you to fetch changes up to 59b94cc0c5125ecb29f32235a168989a5c2b2f82:
  blkid: add control struct (2017-03-17 21:22:26 +0000)
----------------------------------------------------------------

Sami Kerola (5):
  libsmartcols: fix test variable shadowing
  tests: do not use plain 0 as NULL [smatch scan]
  tests: add static keyword where needed [smatch scan]
  blkid: simplify version option handling
  blkid: add control struct

 lib/colors.c                    |  10 +--
 lib/cpuset.c                    |   8 +-
 libfdisk/samples/mkpart.c       |   8 +-
 libmount/src/context.c          |   2 +-
 libmount/src/lock.c             |   2 +-
 libsmartcols/samples/fromfile.c |  34 ++++----
 libsmartcols/samples/title.c    |   6 +-
 libsmartcols/samples/tree.c     |  20 ++---
 misc-utils/blkid.c              | 181 ++++++++++++++++++++--------------------
 misc-utils/test_uuidd.c         |  10 +--
 tests/helpers/test_byteswap.c   |   6 +-
 tests/helpers/test_pathnames.c  |   2 +-
 12 files changed, 144 insertions(+), 145 deletions(-)

-- 
2.12.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] libsmartcols: fix test variable shadowing
  2017-03-19 10:10 [PATCH 0/5] pull: tests fixes and couple blkid changes Sami Kerola
@ 2017-03-19 10:10 ` Sami Kerola
  2017-03-19 10:10 ` [PATCH 2/5] tests: do not use plain 0 as NULL [smatch scan] Sami Kerola
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Sami Kerola @ 2017-03-19 10:10 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

libsmartcols/samples/fromfile.c:57:16: warning: declaration of 'flags'
shadows a global declaration [-Wshadow]
libsmartcols/samples/fromfile.c:29:33: note: shadowed declaration is here
libsmartcols/samples/fromfile.c:101:8: warning: declaration of 'flags'
shadows a global declaration [-Wshadow]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 libsmartcols/samples/fromfile.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/libsmartcols/samples/fromfile.c b/libsmartcols/samples/fromfile.c
index 4c9fca468..1a90e2d4b 100644
--- a/libsmartcols/samples/fromfile.c
+++ b/libsmartcols/samples/fromfile.c
@@ -54,12 +54,12 @@ static long name_to_flag(const char *name, size_t namesz)
 
 static int parse_column_flags(char *str)
 {
-	unsigned long flags = 0;
+	unsigned long num_flags = 0;
 
-	if (string_to_bitmask(str, &flags, name_to_flag))
+	if (string_to_bitmask(str, &num_flags, name_to_flag))
 		err(EXIT_FAILURE, "failed to parse column flags");
 
-	return flags;
+	return num_flags;
 }
 
 static struct libscols_column *parse_column(FILE *f)
@@ -98,8 +98,8 @@ static struct libscols_column *parse_column(FILE *f)
 		}
 		case 2: /* FLAGS */
 		{
-			int flags = parse_column_flags(line);
-			if (scols_column_set_flags(cl, flags))
+			int num_flags = parse_column_flags(line);
+			if (scols_column_set_flags(cl, num_flags))
 				goto fail;
 			if (strcmp(line, "wrapnl") == 0) {
 				scols_column_set_wrapfunc(cl,
-- 
2.12.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/5] tests: do not use plain 0 as NULL [smatch scan]
  2017-03-19 10:10 [PATCH 0/5] pull: tests fixes and couple blkid changes Sami Kerola
  2017-03-19 10:10 ` [PATCH 1/5] libsmartcols: fix test variable shadowing Sami Kerola
@ 2017-03-19 10:10 ` Sami Kerola
  2017-03-19 10:10 ` [PATCH 3/5] tests: add static keyword where needed " Sami Kerola
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Sami Kerola @ 2017-03-19 10:10 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

Likewise commit 87918040658f2fa9b1bf78f1f8f4f5c065a2e3a3.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 lib/colors.c                    | 10 +++++-----
 lib/cpuset.c                    |  8 ++++----
 libfdisk/samples/mkpart.c       |  8 ++++----
 libsmartcols/samples/fromfile.c | 24 ++++++++++++------------
 libsmartcols/samples/title.c    |  6 +++---
 libsmartcols/samples/tree.c     | 20 ++++++++++----------
 misc-utils/test_uuidd.c         |  2 +-
 7 files changed, 39 insertions(+), 39 deletions(-)

diff --git a/lib/colors.c b/lib/colors.c
index dda617057..b2742e4e9 100644
--- a/lib/colors.c
+++ b/lib/colors.c
@@ -830,11 +830,11 @@ int colormode_or_err(const char *str, const char *errmsg)
 int main(int argc, char *argv[])
 {
 	static const struct option longopts[] = {
-		{ "mode",	required_argument, 0, 'm' },
-		{ "color",	required_argument, 0, 'c' },
-		{ "color-scheme", required_argument, 0, 'C' },
-		{ "name",	required_argument, 0, 'n' },
-		{ NULL, 0, 0, 0 }
+		{ "mode",	required_argument, NULL, 'm' },
+		{ "color",	required_argument, NULL, 'c' },
+		{ "color-scheme", required_argument, NULL, 'C' },
+		{ "name",	required_argument, NULL, 'n' },
+		{ NULL, 0, NULL, 0 }
 	};
 	int c, mode = UL_COLORMODE_UNDEF;	/* default */
 	const char *color = "red", *name = NULL, *color_scheme = NULL;
diff --git a/lib/cpuset.c b/lib/cpuset.c
index 89cd0f14c..fbe99e2a5 100644
--- a/lib/cpuset.c
+++ b/lib/cpuset.c
@@ -333,10 +333,10 @@ int main(int argc, char *argv[])
 	int ncpus = 2048, rc, c;
 
 	static const struct option longopts[] = {
-	    { "ncpus", 1, 0, 'n' },
-	    { "mask",  1, 0, 'm' },
-	    { "range", 1, 0, 'r' },
-	    { NULL,    0, 0, 0 }
+	    { "ncpus", 1, NULL, 'n' },
+	    { "mask",  1, NULL, 'm' },
+	    { "range", 1, NULL, 'r' },
+	    { NULL,    0, NULL, 0 }
 	};
 
 	while ((c = getopt_long(argc, argv, "n:m:r:", longopts, NULL)) != -1) {
diff --git a/libfdisk/samples/mkpart.c b/libfdisk/samples/mkpart.c
index dc476dbe9..4ca3ed35d 100644
--- a/libfdisk/samples/mkpart.c
+++ b/libfdisk/samples/mkpart.c
@@ -55,10 +55,10 @@ int main(int argc, char *argv[])
 	unsigned int sectorsize;
 
 	static const struct option longopts[] = {
-		{ "label",  required_argument, 0, 'x' },
-		{ "device", required_argument, 0, 'd' },
-		{ "help",   no_argument, 0, 'h' },
-		{ NULL, 0, 0, 0 },
+		{ "label",  required_argument, NULL, 'x' },
+		{ "device", required_argument, NULL, 'd' },
+		{ "help",   no_argument, NULL, 'h' },
+		{ NULL, 0, NULL, 0 },
 	};
 
 	setlocale(LC_ALL, "");	/* just to have enable UTF8 chars */
diff --git a/libsmartcols/samples/fromfile.c b/libsmartcols/samples/fromfile.c
index 1a90e2d4b..674f01206 100644
--- a/libsmartcols/samples/fromfile.c
+++ b/libsmartcols/samples/fromfile.c
@@ -222,18 +222,18 @@ int main(int argc, char *argv[])
 	int parent_col = -1, id_col = -1;
 
 	static const struct option longopts[] = {
-		{ "maxout", 0, 0, 'm' },
-		{ "column", 1, 0, 'c' },
-		{ "nlines", 1, 0, 'n' },
-		{ "width",  1, 0, 'w' },
-		{ "tree-parent-column", 1, 0, 'p' },
-		{ "tree-id-column",	1, 0, 'i' },
-		{ "json",   0, 0, 'J' },
-		{ "raw",    0, 0, 'r' },
-		{ "export", 0, 0, 'E' },
-		{ "colsep",  1, 0, 'C' },
-		{ "help",   0, 0, 'h' },
-		{ NULL, 0, 0, 0 },
+		{ "maxout", 0, NULL, 'm' },
+		{ "column", 1, NULL, 'c' },
+		{ "nlines", 1, NULL, 'n' },
+		{ "width",  1, NULL, 'w' },
+		{ "tree-parent-column", 1, NULL, 'p' },
+		{ "tree-id-column",	1, NULL, 'i' },
+		{ "json",   0, NULL, 'J' },
+		{ "raw",    0, NULL, 'r' },
+		{ "export", 0, NULL, 'E' },
+		{ "colsep",  1, NULL, 'C' },
+		{ "help",   0, NULL, 'h' },
+		{ NULL, 0, NULL, 0 },
 	};
 
 	static const ul_excl_t excl[] = {       /* rows and cols in ASCII order */
diff --git a/libsmartcols/samples/title.c b/libsmartcols/samples/title.c
index 852316095..2d33b563a 100644
--- a/libsmartcols/samples/title.c
+++ b/libsmartcols/samples/title.c
@@ -60,9 +60,9 @@ int main(int argc, char *argv[])
 	int c;
 
 	static const struct option longopts[] = {
-		{ "maxout", 0, 0, 'm' },
-		{ "width",  1, 0, 'w' },
-		{ NULL, 0, 0, 0 },
+		{ "maxout", 0, NULL, 'm' },
+		{ "width",  1, NULL, 'w' },
+		{ NULL, 0, NULL, 0 },
 	};
 
 	setlocale(LC_ALL, "");	/* just to have enable UTF8 chars */
diff --git a/libsmartcols/samples/tree.c b/libsmartcols/samples/tree.c
index c809b2d85..fcb175135 100644
--- a/libsmartcols/samples/tree.c
+++ b/libsmartcols/samples/tree.c
@@ -162,16 +162,16 @@ int main(int argc, char *argv[])
 
 
 	static const struct option longopts[] = {
-		{ "ascii",	0, 0, 'i' },
-		{ "csv",        0, 0, 'c' },
-		{ "list",       0, 0, 'l' },
-		{ "noheadings",	0, 0, 'n' },
-		{ "pairs",      0, 0, 'p' },
-		{ "json",       0, 0, 'J' },
-		{ "raw",        0, 0, 'r' },
-		{ "range-start",1, 0, 'S' },
-		{ "range-end",  1, 0, 'E' },
-		{ NULL, 0, 0, 0 },
+		{ "ascii",	0, NULL, 'i' },
+		{ "csv",        0, NULL, 'c' },
+		{ "list",       0, NULL, 'l' },
+		{ "noheadings",	0, NULL, 'n' },
+		{ "pairs",      0, NULL, 'p' },
+		{ "json",       0, NULL, 'J' },
+		{ "raw",        0, NULL, 'r' },
+		{ "range-start",1, NULL, 'S' },
+		{ "range-end",  1, NULL, 'E' },
+		{ NULL, 0, NULL, 0 },
 	};
 
 	setlocale(LC_ALL, "");	/* just to have enable UTF8 chars */
diff --git a/misc-utils/test_uuidd.c b/misc-utils/test_uuidd.c
index 13a9880b1..d590f9632 100644
--- a/misc-utils/test_uuidd.c
+++ b/misc-utils/test_uuidd.c
@@ -146,7 +146,7 @@ static void *create_uuids(thread_t *th)
 		obj->pid = th->proc->pid;
 		obj->idx = th->index + i;;
 	}
-	return 0;
+	return NULL;
 }
 
 static void *thread_body(void *arg)
-- 
2.12.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/5] tests: add static keyword where needed [smatch scan]
  2017-03-19 10:10 [PATCH 0/5] pull: tests fixes and couple blkid changes Sami Kerola
  2017-03-19 10:10 ` [PATCH 1/5] libsmartcols: fix test variable shadowing Sami Kerola
  2017-03-19 10:10 ` [PATCH 2/5] tests: do not use plain 0 as NULL [smatch scan] Sami Kerola
@ 2017-03-19 10:10 ` Sami Kerola
  2017-03-19 10:10 ` [PATCH 4/5] blkid: simplify version option handling Sami Kerola
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Sami Kerola @ 2017-03-19 10:10 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 libmount/src/context.c         | 2 +-
 libmount/src/lock.c            | 2 +-
 misc-utils/test_uuidd.c        | 8 ++++----
 tests/helpers/test_byteswap.c  | 6 +++---
 tests/helpers/test_pathnames.c | 2 +-
 5 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/libmount/src/context.c b/libmount/src/context.c
index 44282c07b..e731749b4 100644
--- a/libmount/src/context.c
+++ b/libmount/src/context.c
@@ -2414,7 +2414,7 @@ int mnt_context_wait_for_children(struct libmnt_context *cxt,
 
 #ifdef TEST_PROGRAM
 
-struct libmnt_lock *lock;
+static struct libmnt_lock *lock;
 
 static void lock_fallback(void)
 {
diff --git a/libmount/src/lock.c b/libmount/src/lock.c
index c3cd226f4..06eff1344 100644
--- a/libmount/src/lock.c
+++ b/libmount/src/lock.c
@@ -560,7 +560,7 @@ void mnt_unlock_file(struct libmnt_lock *ml)
 
 #ifdef TEST_PROGRAM
 
-struct libmnt_lock *lock;
+static struct libmnt_lock *lock;
 
 /*
  * read number from @filename, increment the number and
diff --git a/misc-utils/test_uuidd.c b/misc-utils/test_uuidd.c
index d590f9632..66a9f2d3b 100644
--- a/misc-utils/test_uuidd.c
+++ b/misc-utils/test_uuidd.c
@@ -41,10 +41,10 @@
 
 #define LOG(level,args) if (loglev >= level) { fprintf args; }
 
-size_t nprocesses = 4;
-size_t nthreads = 4;
-size_t nobjects = 4096;
-size_t loglev = 1;
+static size_t nprocesses = 4;
+static size_t nthreads = 4;
+static size_t nobjects = 4096;
+static size_t loglev = 1;
 
 struct processentry {
 	pid_t		pid;
diff --git a/tests/helpers/test_byteswap.c b/tests/helpers/test_byteswap.c
index 0b996e09b..1b98f7697 100644
--- a/tests/helpers/test_byteswap.c
+++ b/tests/helpers/test_byteswap.c
@@ -19,7 +19,7 @@
 
 #include "bitops.h"
 
-uint16_t ary16[] = {
+static uint16_t ary16[] = {
 	0x0001, 0x0100,
 	0x1234, 0x3412,
 	0xff00, 0x00ff,
@@ -28,7 +28,7 @@ uint16_t ary16[] = {
 	0x0000, 0x0000
 	};
 
-uint32_t ary32[] = {
+static uint32_t ary32[] = {
 	0x00000001, 0x01000000,
 	0x80000000, 0x00000080,
 	0x12345678, 0x78563412,
@@ -38,7 +38,7 @@ uint32_t ary32[] = {
 	0x00000000, 0x00000000
 	};
 
-uint64_t ary64[] = {
+static uint64_t ary64[] = {
 	0x0000000000000001, 0x0100000000000000,
 	0x8000000000000000, 0x0000000000000080,
 	0x1234567812345678, 0x7856341278563412,
diff --git a/tests/helpers/test_pathnames.c b/tests/helpers/test_pathnames.c
index d5cdad829..2368641f1 100644
--- a/tests/helpers/test_pathnames.c
+++ b/tests/helpers/test_pathnames.c
@@ -29,7 +29,7 @@ struct hlpPath
 
 #define DEF_HLPPATH(_p)		{ #_p, _p }
 
-struct hlpPath paths[] =
+static struct hlpPath paths[] =
 {
 	DEF_HLPPATH(_PATH_DEFPATH),
 	DEF_HLPPATH(_PATH_DEFPATH_ROOT),
-- 
2.12.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/5] blkid: simplify version option handling
  2017-03-19 10:10 [PATCH 0/5] pull: tests fixes and couple blkid changes Sami Kerola
                   ` (2 preceding siblings ...)
  2017-03-19 10:10 ` [PATCH 3/5] tests: add static keyword where needed " Sami Kerola
@ 2017-03-19 10:10 ` Sami Kerola
  2017-03-19 10:10 ` [PATCH 5/5] blkid: add control struct Sami Kerola
  2017-03-24 11:09 ` [PATCH 0/5] pull: tests fixes and couple blkid changes Karel Zak
  5 siblings, 0 replies; 7+ messages in thread
From: Sami Kerola @ 2017-03-19 10:10 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 misc-utils/blkid.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c
index cc29b5c6c..eb2ea0735 100644
--- a/misc-utils/blkid.c
+++ b/misc-utils/blkid.c
@@ -640,7 +640,6 @@ int main(int argc, char **argv)
 	char **fltr_type = NULL;
 	int fltr_flag = BLKID_FLTR_ONLYIN;
 	unsigned int numdev = 0, numtag = 0;
-	int version = 0;
 	int err = BLKID_EXIT_OTHER;
 	unsigned int i;
 	int output_format = 0;
@@ -757,8 +756,8 @@ int main(int argc, char **argv)
 			break;
 		case 'V':
 		case 'v':
-			version = 1;
-			break;
+			print_version(stdout);
+			goto exit;
 		case 'w':
 			/* ignore - backward compatibility */
 			break;
@@ -778,11 +777,6 @@ int main(int argc, char **argv)
 			devices[numdev++] = argv[optind++];
 	}
 
-	if (version) {
-		print_version(stdout);
-		goto exit;
-	}
-
 	/* convert LABEL/UUID lookup to evaluate request */
 	if (lookup && output_format == OUTPUT_DEVICE_ONLY && search_type &&
 	    (!strcmp(search_type, "LABEL") || !strcmp(search_type, "UUID"))) {
-- 
2.12.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/5] blkid: add control struct
  2017-03-19 10:10 [PATCH 0/5] pull: tests fixes and couple blkid changes Sami Kerola
                   ` (3 preceding siblings ...)
  2017-03-19 10:10 ` [PATCH 4/5] blkid: simplify version option handling Sami Kerola
@ 2017-03-19 10:10 ` Sami Kerola
  2017-03-24 11:09 ` [PATCH 0/5] pull: tests fixes and couple blkid changes Karel Zak
  5 siblings, 0 replies; 7+ messages in thread
From: Sami Kerola @ 2017-03-19 10:10 UTC (permalink / raw)
  To: util-linux; +Cc: Sami Kerola

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 misc-utils/blkid.c | 171 +++++++++++++++++++++++++++--------------------------
 1 file changed, 88 insertions(+), 83 deletions(-)

diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c
index eb2ea0735..2f36fac3a 100644
--- a/misc-utils/blkid.c
+++ b/misc-utils/blkid.c
@@ -19,15 +19,13 @@
 #include <errno.h>
 #include <getopt.h>
 
+#define OUTPUT_FULL		(1 << 0)
 #define OUTPUT_VALUE_ONLY	(1 << 1)
 #define OUTPUT_DEVICE_ONLY	(1 << 2)
 #define OUTPUT_PRETTY_LIST	(1 << 3)		/* deprecated */
 #define OUTPUT_UDEV_LIST	(1 << 4)		/* deprecated */
 #define OUTPUT_EXPORT_LIST	(1 << 5)
 
-#define LOWPROBE_TOPOLOGY	(1 << 1)
-#define LOWPROBE_SUPERBLOCKS	(1 << 2)
-
 #define BLKID_EXIT_NOTFOUND	2	/* token or device not found */
 #define BLKID_EXIT_OTHER	4	/* bad usage or other error */
 #define BLKID_EXIT_AMBIVAL	8	/* ambivalent low-level probing detected */
@@ -47,7 +45,20 @@
 #include "ttyutils.h"
 #include "xalloc.h"
 
-static int raw_chars;
+struct blkid_control {
+	int output;
+	uintmax_t offset;
+	uintmax_t size;
+	char *show[128];
+	unsigned int
+		eval:1,
+		gc:1,
+		lookup:1,
+		lowprobe:1,
+		lowprobe_superblocks:1,
+		lowprobe_topology:1,
+		raw_chars:1;
+};
 
 static void print_version(FILE *out)
 {
@@ -102,7 +113,8 @@ static void usage(int error)
  *
  * If 'esc' is defined then escape all chars from esc by \.
  */
-static void safe_print(const char *cp, int len, const char *esc)
+static void safe_print(const struct blkid_control *ctl, const char *cp, int len,
+		       const char *esc)
 {
 	unsigned char	ch;
 
@@ -111,7 +123,7 @@ static void safe_print(const char *cp, int len, const char *esc)
 
 	while (len--) {
 		ch = *cp++;
-		if (!raw_chars) {
+		if (!ctl->raw_chars) {
 			if (ch >= 128) {
 				fputs("M-", stdout);
 				ch -= 128;
@@ -284,22 +296,23 @@ static int has_item(char *ary[], const char *item)
 	return 0;
 }
 
-static void print_value(int output, int num, const char *devname,
-			const char *value, const char *name, size_t valsz)
+static void print_value(const struct blkid_control *ctl, int num,
+			const char *devname, const char *value,
+			const char *name, size_t valsz)
 {
-	if (output & OUTPUT_VALUE_ONLY) {
+	if (ctl->output & OUTPUT_VALUE_ONLY) {
 		fputs(value, stdout);
 		fputc('\n', stdout);
 
-	} else if (output & OUTPUT_UDEV_LIST) {
+	} else if (ctl->output & OUTPUT_UDEV_LIST) {
 		print_udev_format(name, value);
 
-	} else if (output & OUTPUT_EXPORT_LIST) {
+	} else if (ctl->output & OUTPUT_EXPORT_LIST) {
 		if (num == 1 && devname)
 			printf("DEVNAME=%s\n", devname);
 		fputs(name, stdout);
 		fputs("=", stdout);
-		safe_print(value, valsz, " \\\"'$`<>");
+		safe_print(ctl, value, valsz, " \\\"'$`<>");
 		fputs("\n", stdout);
 
 	} else {
@@ -308,12 +321,12 @@ static void print_value(int output, int num, const char *devname,
 		fputs(" ", stdout);
 		fputs(name, stdout);
 		fputs("=\"", stdout);
-		safe_print(value, valsz, "\"\\");
+		safe_print(ctl, value, valsz, "\"\\");
 		fputs("\"", stdout);
 	}
 }
 
-static void print_tags(blkid_dev dev, char *show[], int output)
+static void print_tags(const struct blkid_control *ctl, blkid_dev dev)
 {
 	blkid_tag_iterate	iter;
 	const char		*type, *value, *devname;
@@ -323,34 +336,34 @@ static void print_tags(blkid_dev dev, char *show[], int output)
 	if (!dev)
 		return;
 
-	if (output & OUTPUT_PRETTY_LIST) {
+	if (ctl->output & OUTPUT_PRETTY_LIST) {
 		pretty_print_dev(dev);
 		return;
 	}
 
 	devname = blkid_dev_devname(dev);
 
-	if (output & OUTPUT_DEVICE_ONLY) {
+	if (ctl->output & OUTPUT_DEVICE_ONLY) {
 		printf("%s\n", devname);
 		return;
 	}
 
 	iter = blkid_tag_iterate_begin(dev);
 	while (blkid_tag_next(iter, &type, &value) == 0) {
-		if (show[0] && !has_item(show, type))
+		if (ctl->show[0] && !has_item(ctl->show, type))
 			continue;
 
 		if (num == 1 && !first &&
-		    (output & (OUTPUT_UDEV_LIST | OUTPUT_EXPORT_LIST)))
+		    (ctl->output & (OUTPUT_UDEV_LIST | OUTPUT_EXPORT_LIST)))
 			/* add extra line between output from more devices */
 			fputc('\n', stdout);
 
-		print_value(output, num++, devname, value, type, strlen(value));
+		print_value(ctl, num++, devname, value, type, strlen(value));
 	}
 	blkid_tag_iterate_end(iter);
 
 	if (num > 1) {
-		if (!(output & (OUTPUT_VALUE_ONLY | OUTPUT_UDEV_LIST |
+		if (!(ctl->output & (OUTPUT_VALUE_ONLY | OUTPUT_UDEV_LIST |
 						OUTPUT_EXPORT_LIST)))
 			printf("\n");
 		first = 0;
@@ -474,8 +487,7 @@ static int lowprobe_topology(blkid_probe pr)
 }
 
 static int lowprobe_device(blkid_probe pr, const char *devname,
-			int chain, char *show[], int output,
-			uint64_t offset, uint64_t size)
+			   struct blkid_control *ctl)
 {
 	const char *data;
 	const char *name;
@@ -490,12 +502,12 @@ static int lowprobe_device(blkid_probe pr, const char *devname,
 		warn(_("error: %s"), devname);
 		return BLKID_EXIT_NOTFOUND;
 	}
-	if (blkid_probe_set_device(pr, fd, offset, size))
+	if (blkid_probe_set_device(pr, fd, ctl->offset, ctl->size))
 		goto done;
 
-	if (chain & LOWPROBE_TOPOLOGY)
+	if (ctl->lowprobe_topology)
 		rc = lowprobe_topology(pr);
-	if (rc >= 0 && (chain & LOWPROBE_SUPERBLOCKS))
+	if (rc >= 0 && ctl->lowprobe_superblocks)
 		rc = lowprobe_superblocks(pr);
 	if (rc < 0)
 		goto done;
@@ -503,11 +515,11 @@ static int lowprobe_device(blkid_probe pr, const char *devname,
 	if (!rc)
 		nvals = blkid_probe_numof_values(pr);
 
-	if (nvals && !first && output & (OUTPUT_UDEV_LIST | OUTPUT_EXPORT_LIST))
+	if (nvals && !first && ctl->output & (OUTPUT_UDEV_LIST | OUTPUT_EXPORT_LIST))
 		/* add extra line between output from devices */
 		fputc('\n', stdout);
 
-	if (nvals && (output & OUTPUT_DEVICE_ONLY)) {
+	if (nvals && (ctl->output & OUTPUT_DEVICE_ONLY)) {
 		printf("%s\n", devname);
 		goto done;
 	}
@@ -515,20 +527,21 @@ static int lowprobe_device(blkid_probe pr, const char *devname,
 	for (n = 0; n < nvals; n++) {
 		if (blkid_probe_get_value(pr, n, &name, &data, &len))
 			continue;
-		if (show[0] && !has_item(show, name))
+		if (ctl->show[0] && !has_item(ctl->show, name))
 			continue;
 		len = strnlen((char *) data, len);
-		print_value(output, num++, devname, (char *) data, name, len);
+		print_value(ctl, num++, devname, (char *) data, name, len);
 	}
 
 	if (first)
 		first = 0;
-	if (nvals >= 1 && !(output & (OUTPUT_VALUE_ONLY |
+
+	if (nvals >= 1 && !(ctl->output & (OUTPUT_VALUE_ONLY |
 					OUTPUT_UDEV_LIST | OUTPUT_EXPORT_LIST)))
 		printf("\n");
 done:
 	if (rc == -2) {
-		if (output & OUTPUT_UDEV_LIST)
+		if (ctl->output & OUTPUT_UDEV_LIST)
 			print_udev_ambivalent(pr);
 		else
 			warnx(_("%s: ambivalent result (probably more "
@@ -631,9 +644,9 @@ static void free_types_list(char *list[])
 
 int main(int argc, char **argv)
 {
+	struct blkid_control ctl = { .output = OUTPUT_FULL, 0 };
 	blkid_cache cache = NULL;
 	char **devices = NULL;
-	char *show[128] = { NULL, };
 	char *search_type = NULL, *search_value = NULL;
 	char *read = NULL;
 	int fltr_usage = 0;
@@ -642,10 +655,7 @@ int main(int argc, char **argv)
 	unsigned int numdev = 0, numtag = 0;
 	int err = BLKID_EXIT_OTHER;
 	unsigned int i;
-	int output_format = 0;
-	int lookup = 0, gc = 0, lowprobe = 0, eval = 0;
 	int c;
-	uintmax_t offset = 0, size = 0;
 
 	static const ul_excl_t excl[] = {       /* rows and cols in ASCII order */
 		{ 'n','u' },
@@ -653,7 +663,6 @@ int main(int argc, char **argv)
 	};
 	int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
 
-	show[0] = NULL;
 	setlocale(LC_ALL, "");
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
@@ -666,16 +675,13 @@ int main(int argc, char **argv)
 
 		switch (c) {
 		case 'c':
-			if (optarg && !*optarg)
-				read = NULL;
-			else
-				read = optarg;
+			read = optarg;
 			break;
 		case 'd':
-			raw_chars = 1;
+			ctl.raw_chars = 1;
 			break;
 		case 'L':
-			eval++;
+			ctl.eval = 1;
 			search_value = xstrdup(optarg);
 			search_type = xstrdup("LABEL");
 			break;
@@ -686,18 +692,18 @@ int main(int argc, char **argv)
 			fltr_usage = list_to_usage(optarg, &fltr_flag);
 			break;
 		case 'U':
-			eval++;
+			ctl.eval = 1;
 			search_value = xstrdup(optarg);
 			search_type = xstrdup("UUID");
 			break;
 		case 'i':
-			lowprobe |= LOWPROBE_TOPOLOGY;
+			ctl.lowprobe_topology = 1;
 			break;
 		case 'l':
-			lookup++;
+			ctl.lookup = 1;
 			break;
 		case 'g':
-			gc = 1;
+			ctl.gc = 1;
 			break;
 		case 'k':
 		{
@@ -710,36 +716,35 @@ int main(int argc, char **argv)
 		}
 		case 'o':
 			if (!strcmp(optarg, "value"))
-				output_format = OUTPUT_VALUE_ONLY;
+				ctl.output = OUTPUT_VALUE_ONLY;
 			else if (!strcmp(optarg, "device"))
-				output_format = OUTPUT_DEVICE_ONLY;
+				ctl.output = OUTPUT_DEVICE_ONLY;
 			else if (!strcmp(optarg, "list"))
-				output_format = OUTPUT_PRETTY_LIST;	/* deprecated */
+				ctl.output = OUTPUT_PRETTY_LIST;	/* deprecated */
 			else if (!strcmp(optarg, "udev"))
-				output_format = OUTPUT_UDEV_LIST;
+				ctl.output = OUTPUT_UDEV_LIST;
 			else if (!strcmp(optarg, "export"))
-				output_format = OUTPUT_EXPORT_LIST;
+				ctl.output = OUTPUT_EXPORT_LIST;
 			else if (!strcmp(optarg, "full"))
-				output_format = 0;
+				ctl.output = 0;
 			else
 				errx(BLKID_EXIT_OTHER, _("unsupported output format %s"), optarg);
 			break;
 		case 'O':
-			offset = strtosize_or_err(optarg, _("invalid offset argument"));
+			ctl.offset = strtosize_or_err(optarg, _("invalid offset argument"));
 			break;
 		case 'p':
-			lowprobe |= LOWPROBE_SUPERBLOCKS;
+			ctl.lowprobe_superblocks = 1;
 			break;
 		case 's':
-			if (numtag + 1 >= sizeof(show) / sizeof(*show)) {
+			if (numtag + 1 >= sizeof(ctl.show) / sizeof(*ctl.show)) {
 				warnx(_("Too many tags specified"));
 				errtryh(err);
 			}
-			show[numtag++] = optarg;
-			show[numtag] = NULL;
+			ctl.show[numtag++] = optarg;
 			break;
 		case 'S':
-			size = strtosize_or_err(optarg, _("invalid size argument"));
+			ctl.size = strtosize_or_err(optarg, _("invalid size argument"));
 			break;
 		case 't':
 			if (search_type) {
@@ -769,6 +774,8 @@ int main(int argc, char **argv)
 		}
 	}
 
+	if (ctl.lowprobe_topology || ctl.lowprobe_superblocks)
+		ctl.lowprobe = 1;
 
 	/* The rest of the args are device names */
 	if (optind < argc) {
@@ -778,31 +785,31 @@ int main(int argc, char **argv)
 	}
 
 	/* convert LABEL/UUID lookup to evaluate request */
-	if (lookup && output_format == OUTPUT_DEVICE_ONLY && search_type &&
+	if (ctl.lookup && ctl.output == OUTPUT_DEVICE_ONLY && search_type &&
 	    (!strcmp(search_type, "LABEL") || !strcmp(search_type, "UUID"))) {
-		eval++;
-		lookup = 0;
+		ctl.eval = 1;
+		ctl.lookup = 0;
 	}
 
-	if (!lowprobe && !eval && blkid_get_cache(&cache, read) < 0)
+	if (!ctl.lowprobe && !ctl.eval && blkid_get_cache(&cache, read) < 0)
 		goto exit;
 
-	if (gc) {
+	if (ctl.gc) {
 		blkid_gc_cache(cache);
 		err = 0;
 		goto exit;
 	}
 	err = BLKID_EXIT_NOTFOUND;
 
-	if (eval == 0 && (output_format & OUTPUT_PRETTY_LIST)) {
-		if (lowprobe)
+	if (ctl.eval == 0 && (ctl.output & OUTPUT_PRETTY_LIST)) {
+		if (ctl.lowprobe)
 			errx(BLKID_EXIT_OTHER,
 			     _("The low-level probing mode does not "
 			       "support 'list' output format"));
 		pretty_print_dev(NULL);
 	}
 
-	if (lowprobe) {
+	if (ctl.lowprobe) {
 		/*
 		 * Low-level API
 		 */
@@ -814,38 +821,36 @@ int main(int argc, char **argv)
 			       "requires a device"));
 
 		/* automatically enable 'export' format for I/O Limits */
-		if (!output_format  && (lowprobe & LOWPROBE_TOPOLOGY))
-			output_format = OUTPUT_EXPORT_LIST;
+		if (!ctl.output  && ctl.lowprobe_topology)
+			ctl.output = OUTPUT_EXPORT_LIST;
 
 		pr = blkid_new_probe();
 		if (!pr)
 			goto exit;
 
-		if (lowprobe & LOWPROBE_SUPERBLOCKS) {
+		if (ctl.lowprobe_superblocks) {
 			blkid_probe_set_superblocks_flags(pr,
 				BLKID_SUBLKS_LABEL | BLKID_SUBLKS_UUID |
 				BLKID_SUBLKS_TYPE | BLKID_SUBLKS_SECTYPE |
 				BLKID_SUBLKS_USAGE | BLKID_SUBLKS_VERSION);
 
-			if (fltr_usage && blkid_probe_filter_superblocks_usage(
-						pr, fltr_flag, fltr_usage))
+
+			if (fltr_usage &&
+			    blkid_probe_filter_superblocks_usage(pr, fltr_flag, fltr_usage))
 				goto exit;
 
-			else if (fltr_type && blkid_probe_filter_superblocks_type(
-						pr, fltr_flag, fltr_type))
+			else if (fltr_type &&
+				 blkid_probe_filter_superblocks_type(pr, fltr_flag, fltr_type))
 				goto exit;
 		}
 
 		for (i = 0; i < numdev; i++) {
-			err = lowprobe_device(pr, devices[i], lowprobe, show,
-					output_format,
-					(uint64_t) offset,
-					(uint64_t) size);
+			err = lowprobe_device(pr, devices[i], &ctl);
 			if (err)
 				break;
 		}
 		blkid_free_probe(pr);
-	} else if (eval) {
+	} else if (ctl.eval) {
 		/*
 		 * Evaluate API
 		 */
@@ -854,7 +859,7 @@ int main(int argc, char **argv)
 			err = 0;
 			printf("%s\n", res);
 		}
-	} else if (lookup) {
+	} else if (ctl.lookup) {
 		/*
 		 * Classic (cache based) API
 		 */
@@ -870,7 +875,7 @@ int main(int argc, char **argv)
 
 		if ((dev = blkid_find_dev_with_tag(cache, search_type,
 						   search_value))) {
-			print_tags(dev, show, output_format);
+			print_tags(&ctl, dev);
 			err = 0;
 		}
 	/* If we didn't specify a single device, show all available devices */
@@ -886,7 +891,7 @@ int main(int argc, char **argv)
 			dev = blkid_verify(cache, dev);
 			if (!dev)
 				continue;
-			print_tags(dev, show, output_format);
+			print_tags(&ctl, dev);
 			err = 0;
 		}
 		blkid_dev_iterate_end(iter);
@@ -900,7 +905,7 @@ int main(int argc, char **argv)
 			    !blkid_dev_has_tag(dev, search_type,
 					       search_value))
 				continue;
-			print_tags(dev, show, output_format);
+			print_tags(&ctl, dev);
 			err = 0;
 		}
 	}
@@ -909,7 +914,7 @@ exit:
 	free(search_type);
 	free(search_value);
 	free_types_list(fltr_type);
-	if (!lowprobe && !eval)
+	if (!ctl.lowprobe && !ctl.eval)
 		blkid_put_cache(cache);
 	free(devices);
 	return err;
-- 
2.12.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/5] pull: tests fixes and couple blkid changes
  2017-03-19 10:10 [PATCH 0/5] pull: tests fixes and couple blkid changes Sami Kerola
                   ` (4 preceding siblings ...)
  2017-03-19 10:10 ` [PATCH 5/5] blkid: add control struct Sami Kerola
@ 2017-03-24 11:09 ` Karel Zak
  5 siblings, 0 replies; 7+ messages in thread
From: Karel Zak @ 2017-03-24 11:09 UTC (permalink / raw)
  To: Sami Kerola; +Cc: util-linux

On Sun, Mar 19, 2017 at 10:10:40AM +0000, Sami Kerola wrote:
>  lib/colors.c                    |  10 +--
>  lib/cpuset.c                    |   8 +-
>  libfdisk/samples/mkpart.c       |   8 +-
>  libmount/src/context.c          |   2 +-
>  libmount/src/lock.c             |   2 +-
>  libsmartcols/samples/fromfile.c |  34 ++++----
>  libsmartcols/samples/title.c    |   6 +-
>  libsmartcols/samples/tree.c     |  20 ++---
>  misc-utils/blkid.c              | 181 ++++++++++++++++++++--------------------
>  misc-utils/test_uuidd.c         |  10 +--
>  tests/helpers/test_byteswap.c   |   6 +-
>  tests/helpers/test_pathnames.c  |   2 +-
>  12 files changed, 144 insertions(+), 145 deletions(-)

Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-03-24 11:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-19 10:10 [PATCH 0/5] pull: tests fixes and couple blkid changes Sami Kerola
2017-03-19 10:10 ` [PATCH 1/5] libsmartcols: fix test variable shadowing Sami Kerola
2017-03-19 10:10 ` [PATCH 2/5] tests: do not use plain 0 as NULL [smatch scan] Sami Kerola
2017-03-19 10:10 ` [PATCH 3/5] tests: add static keyword where needed " Sami Kerola
2017-03-19 10:10 ` [PATCH 4/5] blkid: simplify version option handling Sami Kerola
2017-03-19 10:10 ` [PATCH 5/5] blkid: add control struct Sami Kerola
2017-03-24 11:09 ` [PATCH 0/5] pull: tests fixes and couple blkid changes Karel Zak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.